summaryrefslogtreecommitdiffstats
path: root/tqtinterface/qt4/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tqtinterface/qt4/src/kernel')
-rwxr-xr-xtqtinterface/qt4/src/kernel/makepsheader.pl93
-rw-r--r--tqtinterface/qt4/src/kernel/qpsprinter.ps805
-rw-r--r--tqtinterface/qt4/src/kernel/qt_compat.pri27
-rw-r--r--tqtinterface/qt4/src/kernel/qt_gfx.pri155
-rw-r--r--tqtinterface/qt4/src/kernel/qt_kernel.pri261
-rw-r--r--tqtinterface/qt4/src/kernel/qt_x11.pri20
-rw-r--r--tqtinterface/qt4/src/kernel/tq1xcompatibility.h49
-rw-r--r--tqtinterface/qt4/src/kernel/tqabstractlayout.cpp2108
-rw-r--r--tqtinterface/qt4/src/kernel/tqabstractlayout.h54
-rw-r--r--tqtinterface/qt4/src/kernel/tqaccel.cpp2098
-rw-r--r--tqtinterface/qt4/src/kernel/tqaccel.h238
-rw-r--r--tqtinterface/qt4/src/kernel/tqaccessible.cpp719
-rw-r--r--tqtinterface/qt4/src/kernel/tqaccessible.h295
-rw-r--r--tqtinterface/qt4/src/kernel/tqapplication.cpp5499
-rw-r--r--tqtinterface/qt4/src/kernel/tqapplication.cpp~5499
-rw-r--r--tqtinterface/qt4/src/kernel/tqapplication.h724
-rw-r--r--tqtinterface/qt4/src/kernel/tqapplication.h~724
-rw-r--r--tqtinterface/qt4/src/kernel/tqapplication_p.h95
-rw-r--r--tqtinterface/qt4/src/kernel/tqapplication_x11.cpp8984
-rw-r--r--tqtinterface/qt4/src/kernel/tqasyncimageio.cpp1316
-rw-r--r--tqtinterface/qt4/src/kernel/tqasyncimageio.h111
-rw-r--r--tqtinterface/qt4/src/kernel/tqasyncio.cpp360
-rw-r--r--tqtinterface/qt4/src/kernel/tqasyncio.h121
-rw-r--r--tqtinterface/qt4/src/kernel/tqbitmap.cpp435
-rw-r--r--tqtinterface/qt4/src/kernel/tqbitmap.h114
-rw-r--r--tqtinterface/qt4/src/kernel/tqbrush.h141
-rw-r--r--tqtinterface/qt4/src/kernel/tqclipboard.cpp754
-rw-r--r--tqtinterface/qt4/src/kernel/tqclipboard.h168
-rw-r--r--tqtinterface/qt4/src/kernel/tqclipboard_x11.cpp2020
-rw-r--r--tqtinterface/qt4/src/kernel/tqcolor.cpp1174
-rw-r--r--tqtinterface/qt4/src/kernel/tqcolor.h348
-rw-r--r--tqtinterface/qt4/src/kernel/tqcolor_p.cpp802
-rw-r--r--tqtinterface/qt4/src/kernel/tqcolor_p.h66
-rw-r--r--tqtinterface/qt4/src/kernel/tqcolor_x11.cpp1336
-rw-r--r--tqtinterface/qt4/src/kernel/tqconnection.cpp94
-rw-r--r--tqtinterface/qt4/src/kernel/tqconnection.h78
-rw-r--r--tqtinterface/qt4/src/kernel/tqcursor.cpp292
-rw-r--r--tqtinterface/qt4/src/kernel/tqcursor.h188
-rw-r--r--tqtinterface/qt4/src/kernel/tqcursor_x11.cpp1013
-rw-r--r--tqtinterface/qt4/src/kernel/tqdesktopwidget.h141
-rw-r--r--tqtinterface/qt4/src/kernel/tqdesktopwidget_x11.cpp335
-rw-r--r--tqtinterface/qt4/src/kernel/tqdnd_x11.cpp1765
-rw-r--r--tqtinterface/qt4/src/kernel/tqdragobject.cpp3378
-rw-r--r--tqtinterface/qt4/src/kernel/tqdragobject.h508
-rw-r--r--tqtinterface/qt4/src/kernel/tqdrawutil.cpp957
-rw-r--r--tqtinterface/qt4/src/kernel/tqdrawutil.h128
-rw-r--r--tqtinterface/qt4/src/kernel/tqdropsite.cpp81
-rw-r--r--tqtinterface/qt4/src/kernel/tqdropsite.h59
-rw-r--r--tqtinterface/qt4/src/kernel/tqevent.cpp2708
-rw-r--r--tqtinterface/qt4/src/kernel/tqevent.h952
-rw-r--r--tqtinterface/qt4/src/kernel/tqeventloop.cpp394
-rw-r--r--tqtinterface/qt4/src/kernel/tqeventloop.h123
-rw-r--r--tqtinterface/qt4/src/kernel/tqeventloop_p.h150
-rw-r--r--tqtinterface/qt4/src/kernel/tqeventloop_unix.cpp587
-rw-r--r--tqtinterface/qt4/src/kernel/tqeventloop_x11.cpp417
-rw-r--r--tqtinterface/qt4/src/kernel/tqfocusdata.cpp141
-rw-r--r--tqtinterface/qt4/src/kernel/tqfocusdata.h70
-rw-r--r--tqtinterface/qt4/src/kernel/tqfont.cpp3376
-rw-r--r--tqtinterface/qt4/src/kernel/tqfont.h524
-rw-r--r--tqtinterface/qt4/src/kernel/tqfont_x11.cpp747
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontdata_p.h278
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontdatabase.cpp2505
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontdatabase.h306
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontdatabase_x11.cpp2008
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontengine_p.h642
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontengine_x11.cpp2752
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontinfo.h111
-rw-r--r--tqtinterface/qt4/src/kernel/tqfontmetrics.h138
-rw-r--r--tqtinterface/qt4/src/kernel/tqgif.h61
-rw-r--r--tqtinterface/qt4/src/kernel/tqgplugin.cpp72
-rw-r--r--tqtinterface/qt4/src/kernel/tqgplugin.h146
-rw-r--r--tqtinterface/qt4/src/kernel/tqguardedptr.cpp226
-rw-r--r--tqtinterface/qt4/src/kernel/tqguardedptr.h145
-rw-r--r--tqtinterface/qt4/src/kernel/tqiconset.cpp949
-rw-r--r--tqtinterface/qt4/src/kernel/tqiconset.h132
-rw-r--r--tqtinterface/qt4/src/kernel/tqimage.cpp9526
-rw-r--r--tqtinterface/qt4/src/kernel/tqimage.h695
-rw-r--r--tqtinterface/qt4/src/kernel/tqimageformatinterface_p.h81
-rw-r--r--tqtinterface/qt4/src/kernel/tqimageformatplugin.cpp184
-rw-r--r--tqtinterface/qt4/src/kernel/tqimageformatplugin.h67
-rw-r--r--tqtinterface/qt4/src/kernel/tqinputcontext_p.h127
-rw-r--r--tqtinterface/qt4/src/kernel/tqinputcontext_x11.cpp535
-rw-r--r--tqtinterface/qt4/src/kernel/tqinternal.cpp785
-rw-r--r--tqtinterface/qt4/src/kernel/tqinternal_p.h213
-rw-r--r--tqtinterface/qt4/src/kernel/tqjpegio.cpp599
-rw-r--r--tqtinterface/qt4/src/kernel/tqjpegio.h52
-rw-r--r--tqtinterface/qt4/src/kernel/tqkeycode.h50
-rw-r--r--tqtinterface/qt4/src/kernel/tqkeysequence.cpp731
-rw-r--r--tqtinterface/qt4/src/kernel/tqkeysequence.h109
-rw-r--r--tqtinterface/qt4/src/kernel/tqlayout.cpp4056
-rw-r--r--tqtinterface/qt4/src/kernel/tqlayout.h1146
-rw-r--r--tqtinterface/qt4/src/kernel/tqlayoutengine.cpp322
-rw-r--r--tqtinterface/qt4/src/kernel/tqlayoutengine_p.h129
-rw-r--r--tqtinterface/qt4/src/kernel/tqlocalfs.cpp407
-rw-r--r--tqtinterface/qt4/src/kernel/tqlocalfs.h75
-rw-r--r--tqtinterface/qt4/src/kernel/tqlock.cpp297
-rw-r--r--tqtinterface/qt4/src/kernel/tqlock_p.h99
-rw-r--r--tqtinterface/qt4/src/kernel/tqmetaobject.cpp1792
-rw-r--r--tqtinterface/qt4/src/kernel/tqmetaobject.cpp~1792
-rw-r--r--tqtinterface/qt4/src/kernel/tqmetaobject.h404
-rw-r--r--tqtinterface/qt4/src/kernel/tqmetaobject.h~403
-rw-r--r--tqtinterface/qt4/src/kernel/tqmime.cpp1158
-rw-r--r--tqtinterface/qt4/src/kernel/tqmime.h312
-rw-r--r--tqtinterface/qt4/src/kernel/tqmngio.cpp464
-rw-r--r--tqtinterface/qt4/src/kernel/tqmngio.h53
-rw-r--r--tqtinterface/qt4/src/kernel/tqmotifdnd_x11.cpp978
-rw-r--r--tqtinterface/qt4/src/kernel/tqmovie.cpp1082
-rw-r--r--tqtinterface/qt4/src/kernel/tqmovie.h123
-rw-r--r--tqtinterface/qt4/src/kernel/tqnamespace.h1159
-rw-r--r--tqtinterface/qt4/src/kernel/tqnetworkprotocol.cpp1265
-rw-r--r--tqtinterface/qt4/src/kernel/tqnetworkprotocol.h246
-rw-r--r--tqtinterface/qt4/src/kernel/tqobject.cpp3666
-rw-r--r--tqtinterface/qt4/src/kernel/tqobject.h417
-rw-r--r--tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.cpp172
-rw-r--r--tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.h69
-rw-r--r--tqtinterface/qt4/src/kernel/tqobjectdefs.h277
-rw-r--r--tqtinterface/qt4/src/kernel/tqobjectdict.h66
-rw-r--r--tqtinterface/qt4/src/kernel/tqobjectlist.h92
-rw-r--r--tqtinterface/qt4/src/kernel/tqpaintdevice.h688
-rw-r--r--tqtinterface/qt4/src/kernel/tqpaintdevice_x11.cpp1746
-rw-r--r--tqtinterface/qt4/src/kernel/tqpaintdevicedefs.h48
-rw-r--r--tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.cpp304
-rw-r--r--tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.h181
-rw-r--r--tqtinterface/qt4/src/kernel/tqpainter.cpp5382
-rw-r--r--tqtinterface/qt4/src/kernel/tqpainter.cpp~5161
-rw-r--r--tqtinterface/qt4/src/kernel/tqpainter.h1019
-rw-r--r--tqtinterface/qt4/src/kernel/tqpainter.h~993
-rw-r--r--tqtinterface/qt4/src/kernel/tqpainter_p.h66
-rw-r--r--tqtinterface/qt4/src/kernel/tqpainter_x11.cpp3348
-rw-r--r--tqtinterface/qt4/src/kernel/tqpalette.cpp1348
-rw-r--r--tqtinterface/qt4/src/kernel/tqpalette.h295
-rw-r--r--tqtinterface/qt4/src/kernel/tqpen.h132
-rw-r--r--tqtinterface/qt4/src/kernel/tqpicture.cpp1235
-rw-r--r--tqtinterface/qt4/src/kernel/tqpicture.h144
-rw-r--r--tqtinterface/qt4/src/kernel/tqpixmap.cpp1882
-rw-r--r--tqtinterface/qt4/src/kernel/tqpixmap.h496
-rw-r--r--tqtinterface/qt4/src/kernel/tqpixmap_x11.cpp2155
-rw-r--r--tqtinterface/qt4/src/kernel/tqpixmapcache.cpp336
-rw-r--r--tqtinterface/qt4/src/kernel/tqpixmapcache.h63
-rw-r--r--tqtinterface/qt4/src/kernel/tqpngio.cpp1250
-rw-r--r--tqtinterface/qt4/src/kernel/tqpngio.h107
-rw-r--r--tqtinterface/qt4/src/kernel/tqpoint.cpp448
-rw-r--r--tqtinterface/qt4/src/kernel/tqpoint.h253
-rw-r--r--tqtinterface/qt4/src/kernel/tqpointarray.cpp1311
-rw-r--r--tqtinterface/qt4/src/kernel/tqpointarray.h195
-rw-r--r--tqtinterface/qt4/src/kernel/tqpolygonscanner.cpp937
-rw-r--r--tqtinterface/qt4/src/kernel/tqpolygonscanner.h61
-rw-r--r--tqtinterface/qt4/src/kernel/tqprinter.cpp1198
-rwxr-xr-xtqtinterface/qt4/src/kernel/tqprinter.h335
-rw-r--r--tqtinterface/qt4/src/kernel/tqprinter_p.h59
-rw-r--r--tqtinterface/qt4/src/kernel/tqprinter_unix.cpp853
-rw-r--r--tqtinterface/qt4/src/kernel/tqprocess.cpp806
-rw-r--r--tqtinterface/qt4/src/kernel/tqprocess.h179
-rw-r--r--tqtinterface/qt4/src/kernel/tqprocess_unix.cpp1410
-rw-r--r--tqtinterface/qt4/src/kernel/tqpsprinter.cpp6595
-rw-r--r--tqtinterface/qt4/src/kernel/tqpsprinter_p.h98
-rw-r--r--tqtinterface/qt4/src/kernel/tqrect.cpp1010
-rw-r--r--tqtinterface/qt4/src/kernel/tqrect.h328
-rw-r--r--tqtinterface/qt4/src/kernel/tqregion.cpp398
-rw-r--r--tqtinterface/qt4/src/kernel/tqregion.h227
-rw-r--r--tqtinterface/qt4/src/kernel/tqregion_x11.cpp2908
-rw-r--r--tqtinterface/qt4/src/kernel/tqrichtext.cpp16615
-rw-r--r--tqtinterface/qt4/src/kernel/tqrichtext_p.cpp1283
-rw-r--r--tqtinterface/qt4/src/kernel/tqrichtext_p.h4300
-rw-r--r--tqtinterface/qt4/src/kernel/tqscriptengine.cpp1630
-rw-r--r--tqtinterface/qt4/src/kernel/tqscriptengine_p.h91
-rw-r--r--tqtinterface/qt4/src/kernel/tqscriptengine_x11.cpp3752
-rw-r--r--tqtinterface/qt4/src/kernel/tqsession.h47
-rw-r--r--tqtinterface/qt4/src/kernel/tqsessionmanager.h168
-rw-r--r--tqtinterface/qt4/src/kernel/tqsharedmemory_p.cpp169
-rw-r--r--tqtinterface/qt4/src/kernel/tqsharedmemory_p.h95
-rw-r--r--tqtinterface/qt4/src/kernel/tqsignal.cpp493
-rw-r--r--tqtinterface/qt4/src/kernel/tqsignal.h154
-rw-r--r--tqtinterface/qt4/src/kernel/tqsignalmapper.cpp183
-rw-r--r--tqtinterface/qt4/src/kernel/tqsignalmapper.h79
-rw-r--r--tqtinterface/qt4/src/kernel/tqsignalslotimp.h97
-rw-r--r--tqtinterface/qt4/src/kernel/tqsimplerichtext.cpp851
-rw-r--r--tqtinterface/qt4/src/kernel/tqsimplerichtext.h234
-rw-r--r--tqtinterface/qt4/src/kernel/tqsize.cpp437
-rw-r--r--tqtinterface/qt4/src/kernel/tqsize.h318
-rw-r--r--tqtinterface/qt4/src/kernel/tqsizegrip.cpp286
-rw-r--r--tqtinterface/qt4/src/kernel/tqsizegrip.h75
-rw-r--r--tqtinterface/qt4/src/kernel/tqsizepolicy.h194
-rw-r--r--tqtinterface/qt4/src/kernel/tqsocketnotifier.cpp270
-rw-r--r--tqtinterface/qt4/src/kernel/tqsocketnotifier.h114
-rw-r--r--tqtinterface/qt4/src/kernel/tqsound.cpp316
-rw-r--r--tqtinterface/qt4/src/kernel/tqsound.h126
-rw-r--r--tqtinterface/qt4/src/kernel/tqsound_x11.cpp284
-rw-r--r--tqtinterface/qt4/src/kernel/tqstyle.cpp2186
-rw-r--r--tqtinterface/qt4/src/kernel/tqstyle.h1278
-rw-r--r--tqtinterface/qt4/src/kernel/tqstylesheet.cpp1623
-rw-r--r--tqtinterface/qt4/src/kernel/tqstylesheet.h256
-rw-r--r--tqtinterface/qt4/src/kernel/tqt.h379
-rw-r--r--tqtinterface/qt4/src/kernel/tqt_pch.h57
-rw-r--r--tqtinterface/qt4/src/kernel/tqt_x11_p.h275
-rw-r--r--tqtinterface/qt4/src/kernel/tqtaddons_x11.cpp144
-rw-r--r--tqtinterface/qt4/src/kernel/tqtextengine.cpp1186
-rw-r--r--tqtinterface/qt4/src/kernel/tqtextengine_p.h467
-rw-r--r--tqtinterface/qt4/src/kernel/tqtextengine_unix.cpp127
-rw-r--r--tqtinterface/qt4/src/kernel/tqtextlayout.cpp818
-rw-r--r--tqtinterface/qt4/src/kernel/tqtextlayout_p.h300
-rw-r--r--tqtinterface/qt4/src/kernel/tqtglobaldefines.h502
-rw-r--r--tqtinterface/qt4/src/kernel/tqtglobalsettings.h7
-rw-r--r--tqtinterface/qt4/src/kernel/tqthread.cpp241
-rw-r--r--tqtinterface/qt4/src/kernel/tqthread.h130
-rw-r--r--tqtinterface/qt4/src/kernel/tqthread_unix.cpp474
-rw-r--r--tqtinterface/qt4/src/kernel/tqtimer.cpp350
-rw-r--r--tqtinterface/qt4/src/kernel/tqtimer.h92
-rw-r--r--tqtinterface/qt4/src/kernel/tqtranslator.cpp2438
-rw-r--r--tqtinterface/qt4/src/kernel/tqtranslator.h281
-rw-r--r--tqtinterface/qt4/src/kernel/tqucomextra.cpp177
-rw-r--r--tqtinterface/qt4/src/kernel/tqucomextra_p.h109
-rw-r--r--tqtinterface/qt4/src/kernel/tqurl.cpp1345
-rw-r--r--tqtinterface/qt4/src/kernel/tqurl.h130
-rw-r--r--tqtinterface/qt4/src/kernel/tqurlinfo.cpp761
-rw-r--r--tqtinterface/qt4/src/kernel/tqurlinfo.h144
-rw-r--r--tqtinterface/qt4/src/kernel/tqurloperator.cpp1226
-rw-r--r--tqtinterface/qt4/src/kernel/tqurloperator.h130
-rw-r--r--tqtinterface/qt4/src/kernel/tqvariant.cpp4972
-rw-r--r--tqtinterface/qt4/src/kernel/tqvariant.cpp.new4858
-rw-r--r--tqtinterface/qt4/src/kernel/tqvariant.h642
-rw-r--r--tqtinterface/qt4/src/kernel/tqvfbhdr.h71
-rw-r--r--tqtinterface/qt4/src/kernel/tqwidget.cpp8728
-rw-r--r--tqtinterface/qt4/src/kernel/tqwidget.h1547
-rw-r--r--tqtinterface/qt4/src/kernel/tqwidget_p.h64
-rw-r--r--tqtinterface/qt4/src/kernel/tqwidget_x11.cpp2980
-rw-r--r--tqtinterface/qt4/src/kernel/tqwidgetcreate_x11.cpp74
-rw-r--r--tqtinterface/qt4/src/kernel/tqwidgetintdict.h75
-rw-r--r--tqtinterface/qt4/src/kernel/tqwidgetlist.h67
-rw-r--r--tqtinterface/qt4/src/kernel/tqwindow.cpp39
-rw-r--r--tqtinterface/qt4/src/kernel/tqwindow.h46
-rw-r--r--tqtinterface/qt4/src/kernel/tqwindowdefs.h197
-rw-r--r--tqtinterface/qt4/src/kernel/tqwmatrix.cpp1204
-rw-r--r--tqtinterface/qt4/src/kernel/tqwmatrix.cpp~1204
-rw-r--r--tqtinterface/qt4/src/kernel/tqwmatrix.h194
-rw-r--r--tqtinterface/qt4/src/kernel/tqwmatrix.h~193
236 files changed, 229102 insertions, 0 deletions
diff --git a/tqtinterface/qt4/src/kernel/makepsheader.pl b/tqtinterface/qt4/src/kernel/makepsheader.pl
new file mode 100755
index 0000000..b842e14
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/makepsheader.pl
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+open(INPUT, 'qpsprinter.ps')
+ or die "Can't open qpsprinter.ps";
+
+$dontcompress = 1;
+while(<INPUT>) {
+ $line = $_;
+ chomp $line;
+ if ( /ENDUNCOMPRESS/ ) {
+ $dontcompress = 0;
+ }
+ $line =~ s/%.*$//;
+ $line = $line;
+ if ( $dontcompress eq 1 ) {
+ push(@uncompressed, $line);
+ } else {
+ push(@lines, $line);
+ }
+# print "$line\n";
+}
+
+$uc = join(" ", @uncompressed);
+$uc =~ s,\t+, ,g;
+$uc=~ s, +, ,g;
+
+$h = join(" ", @lines);
+$h =~ s,\t+, ,g;
+$h =~ s, +, ,g;
+$h = $h.' ';
+
+# now compress as much as possible
+$h =~ s/ def / d /g;
+$h =~ s/ bind def / D /g;
+$h =~ s/ dup dup / d2 /g;
+$h =~ s/ exch d / ED /g;
+$h =~ s/ lineto / LT /g;
+$h =~ s/ moveto / MT /g;
+$h =~ s/ stroke / S /g;
+$h =~ s/ setfont / F /g;
+$h =~ s/ setlinewidth / SW /g;
+$h =~ s/ closepath / CP /g;
+$h =~ s/ rlineto / RL /g;
+$h =~ s/ newpath / NP /g;
+$h =~ s/ currentmatrix / CM /g;
+$h =~ s/ setmatrix / SM /g;
+$h =~ s/ translate / TR /g;
+$h =~ s/ setdash / SD /g;
+$h =~ s/ aload pop setrgbcolor / SC /g;
+$h =~ s/ currentfile read pop / CR /g;
+$h =~ s/ index / i /g;
+$h =~ s/ bitshift / bs /g;
+$h =~ s/ setcolorspace / scs /g;
+$h =~ s/ dict dup begin / DB /g;
+$h =~ s/ end d / DE /g;
+$h =~ s/ ifelse / ie /g;
+$h =~ s/ astore pop / sp /g;
+
+# add the uncompressed part of the header before
+$h = $uc.' '.$h;
+
+
+
+#print $h;
+
+# wordwrap at col 76
+@head = split(' ', $h);
+$line = shift @head;
+while( @head ) {
+ $token = shift @head;
+ chomp $token;
+# print "\nl=$l, len=$len, token=$token.";
+ $newline = $line.' '.$token;
+ $newline =~ s, /,/,g;
+ $newline =~ s, \{,\{,g;
+ $newline =~ s, \},\},g;
+ $newline =~ s, \[,\[,g;
+ $newline =~ s, \],\],g;
+ $newline =~ s,\{ ,\{,g;
+ $newline =~ s,\} ,\},g;
+ $newline =~ s,\[ ,\[,g;
+ $newline =~ s,\] ,\],g;
+ if ( length( $newline ) > 76 ) {
+# print "\nline=$line\n";
+ $header = $header."\n\"".$line."\\n\"";
+ $newline = $token;
+ }
+ $line = $newline;
+}
+$header = $header."\n\"".$line."\\n\"";
+
+
+print $header;
diff --git a/tqtinterface/qt4/src/kernel/qpsprinter.ps b/tqtinterface/qt4/src/kernel/qpsprinter.ps
new file mode 100644
index 0000000..b38868f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/qpsprinter.ps
@@ -0,0 +1,805 @@
+% the postscript header we use for our qpsprinter in uncompressed and commented form.
+% use the makepsheader perl script to generate a compressed version of this header
+% you can then paste into qpsprinter.cpp
+%
+% some compression of the code is done by the makepsheader script, so we don't need to
+% write too criptically here.
+
+/d /def load def
+/D {bind d} bind d
+/d2 {dup dup} D
+/B {0 d2} D
+/W {255 d2} D
+/ED {exch d} D
+/D0 {0 ED} D
+/LT {lineto} D
+/MT {moveto} D
+/S {stroke} D
+/F {setfont} D
+/SW {setlinewidth} D
+/CP {closepath} D
+/RL {rlineto} D
+/NP {newpath} D
+/CM {currentmatrix} D
+/SM {setmatrix} D
+/TR {translate} D
+/SD {setdash} D
+/SC {aload pop setrgbcolor} D
+/CR {currentfile read pop} D
+/i {index} D
+/bs {bitshift} D
+/scs {setcolorspace} D
+/DB {dict dup begin} D
+/DE {end d} D
+/ie {ifelse} D
+/sp {astore pop} D
+
+% ENDUNCOMPRESSED: Warning: leave this line in.
+% Everything before this line will be left untouched by the compression
+
+
+
+/BSt 0 d % brush style
+/LWi 1 d % line width
+/PSt 1 d % pen style
+/Cx 0 d % current x position
+/Cy 0 d % current y position
+/WFi false d % winding fill
+/OMo false d % opaque mode (not transtqparent)
+
+/BCol [ 1 1 1 ] d % brush color
+/PCol [ 0 0 0 ] d % pen color
+/BkCol [ 1 1 1 ] d % background color
+/BDArr [ % Brush dense patterns
+ 0.94
+ 0.88
+ 0.63
+ 0.50
+ 0.37
+ 0.12
+ 0.06
+] d
+/defM matrix d
+
+/nS 0 d % number of saved painter states
+
+% LArr for the Pen styles is defined in emitHeader because of scaling
+
+% GPS: GetPenStyle
+% Returns the line pattern (from pen style PSt).
+%
+% bool GPS pattern
+% true : returns draw pattern
+% false: returns fill pattern
+/GPS {
+ PSt 1 ge PSt 5 le and % valid pen pattern?
+ {
+ { LArr PSt 1 sub 2 mul get } % draw pattern
+ { LArr PSt 2 mul 1 sub get } ifelse % opaque pattern
+ }
+ { [] } ifelse % out of range => solid line
+} D
+
+% QS: QtStroke
+% draw and fill current path
+%
+% - QS -
+/QS { % stroke command
+ PSt 0 ne % != NO_PEN
+ {
+ gsave
+ LWi SW % set line width
+ true GPS 0 setdash S % draw line pattern
+ OMo PSt 1 ne and % opaque mode and not solid line?
+ {
+ BkCol SC
+ false GPS dup 0 get setdash S % fill in opaque pattern
+ } if
+ grestore
+ } if
+} D
+
+
+
+
+%% The following operations are used to read compressed data from the file
+%% Until now this is only used for image compression
+
+% read 28 bits and leave them on tos
+%
+% - r28 num
+/r28 {
+ % skip past whitespace and read one character
+ { currentfile read pop
+ dup 32 gt { exit } if
+ pop
+ } loop
+ % read three more
+ 3 {
+ currentfile read pop
+ } repeat
+ % make an accumulator
+ 0
+ % for each character, shift the accumulator and add in the character
+ 4 {
+ 7 bitshift exch
+ dup 128 gt { 84 sub } if 42 sub 127 and
+ add
+ } repeat
+} D
+
+/rA 0 d % accumulator
+/rL 0 d % bits left
+
+% takes number of bits, leaves number
+%
+% num rB num
+/rB {
+ rL 0 eq {
+ % if we have nothing, let's get something
+ /rA r28 d
+ /rL 28 d
+ } if
+ dup rL gt {
+ % if we don't have enough, take what we have and get more
+ rA exch rL sub rL exch
+ /rA 0 d /rL 0 d
+ rB exch bitshift add
+ } {
+ % else take some of what we have
+ dup rA 16#fffffff 3 -1 roll bitshift not and exch
+ % ... and update rL and rA
+ dup rL exch sub /rL ED
+ neg rA exch bitshift /rA ED
+ } ifelse
+} D
+
+% uncompresses image data from currentfile until the string on the
+% stack is full; leaves the string there.
+% assumes that nothing could conceivably go wrong, ie. the compressed data has
+% to be in the correct format and the length of the string has to be exactly right
+% to hold the compressed data
+%
+% string uc string
+%
+%%% Warning: if you change the method here, change the table in qpsprinter.cpp:compress()!
+/uc {
+ /rL 0 d
+ 0
+ { % string pos
+ dup 2 index length ge { exit } if
+ 1 rB
+ 1 eq { % compressed
+ 3 rB % string pos bits
+ dup 3 ge {
+ 1 add dup rB % string pos bits extra
+ 1 index 5 ge {
+ 1 index 6 ge {
+ 1 index 7 ge {
+ 1 index 8 ge {
+ 128 add
+ } if
+ 64 add
+ } if
+ 32 add
+ } if
+ 16 add
+ } if
+ 3 add
+ exch pop
+ } if
+ 3 add
+ % string pos length
+ exch 10 rB 1 add
+ % string length pos dist
+ {
+ dup 3 index lt {
+ dup
+ } {
+ 2 index
+ } ifelse % string length pos dist length-this-time
+ 4 index 3 index 3 index sub 2 index getinterval
+ 5 index 4 index 3 -1 roll putinterval
+ dup 4 -1 roll add 3 1 roll
+ 4 -1 roll exch sub
+ dup 0 eq { exit } if
+ 3 1 roll
+ } loop % string pos dist length
+ pop pop
+ } { % uncompressed
+ 3 rB 1 add
+ {
+ 2 copy 8 rB put 1 add
+ } repeat
+ } ifelse
+ } loop
+ pop
+} D
+
+%% image drawing routines
+
+/sl D0 % ### is this needed ?
+
+% defines for QCI
+/QCIgray D0 /QCIcolor D0 /QCIindex D0
+
+% this method prints color images if colorimage is available, otherwise
+% converts the string to a grayscale image and uses the reular postscript image
+% operator for printing.
+% Arguments are the same as for the image operator:
+%
+% width height bits/sample matrix datasrc QCI -
+/QCI {
+ /colorimage where {
+ pop
+ false 3 colorimage
+ }{ % the hard way, based on PD code by John Walker <kelvin@autodesk.com>
+ exec /QCIcolor ED
+ /QCIgray QCIcolor length 3 idiv string d
+ 0 1 QCIcolor length 3 idiv 1 sub
+ { /QCIindex ED
+ /x QCIindex 3 mul d
+ QCIgray QCIindex
+ QCIcolor x get 0.30 mul
+ QCIcolor x 1 add get 0.59 mul
+ QCIcolor x 2 add get 0.11 mul
+ add add cvi
+ put
+ } for
+ QCIgray image
+ } ifelse
+} D
+
+% general image drawing routine, used from the postscript driver
+%
+% Draws images with and without tqmask with 1, 8 and 24(rgb) bits depth.
+%
+% width height matrix image 1|8|24 tqmask|false x y di
+%
+% width and height specify the width/height of the image,
+% matrix a transformation matrix, image a procedure holding the image data
+% (same for tqmask) and x/y an additional translation.
+%
+% ### should move the translation into the matrix!!!
+/di
+{
+ gsave
+ translate
+ 1 index 1 eq { % bitmap
+ false eq { % no tqmask, draw solid background
+ pop
+ true 3 1 roll % width height false matrix image
+ 4 index
+ 4 index
+ false
+ 4 index
+ 4 index
+ imagetqmask
+ BkCol SC
+ imagetqmask
+ } {
+ pop
+ false 3 1 roll % width height false matrix image
+ imagetqmask
+ } ifelse
+ } {
+ dup false ne {
+ % have a tqmask, see if we can use it
+ /languagelevel where {
+ pop
+ languagelevel 3 ge
+ } { false } ifelse
+ } {
+ false
+ } ifelse
+
+ {
+ % languagelevel3, we can use image tqmask and dicts
+
+ % store the image tqmask
+ /ma exch d
+ % select colorspace according to 8|24 bit depth and set the decode array /dc
+ 8 eq {
+ /dc [0 1] d
+ /DeviceGray
+ } {
+ /dc [0 1 0 1 0 1] d
+ /DeviceRGB
+ } ifelse
+ setcolorspace
+ % the image data
+ /im exch d
+ % transformation matrix
+ /mt exch d
+ % width and height
+ /h exch def
+ /w exch def
+ % the image dict
+ /id
+ 7 dict dup begin
+ /ImageType 1 d
+ /Width w d
+ /Height h d
+ /ImageMatrix mt d
+ /DataSource im d
+ /BitsPerComponent 8 d
+ /Decode dc d
+ end d
+ % the tqmask dictionary
+ /md
+ 7 dict dup begin
+ /ImageType 1 d
+ /Width w d
+ /Height h d
+ /ImageMatrix mt d
+ /DataSource ma d
+ /BitsPerComponent 1 d
+ /Decode [0 1] d
+ end d
+ % and the combined image dict
+ 4 dict dup begin
+ /ImageType 3 d
+ /DataDict id d
+ /MaskDict md d
+ /InterleaveType 3 d
+ end
+ image
+ } {
+ pop % no tqmask or can't use it, get rid of it
+ 8 % width height image 8|24 8 matrix
+ 4 1 roll
+ 8 eq { % grayscale
+ image
+ } { %color
+ QCI
+ } ifelse
+ } ifelse
+ } ifelse
+ grestore
+} d
+
+
+
+
+/BF { % brush fill
+ gsave
+ BSt 1 eq % solid brush?
+ {
+ BCol SC
+ WFi { fill } { eofill } ifelse
+ } if
+ BSt 2 ge BSt 8 le and % dense pattern?
+ {
+ BDArr BSt 2 sub get /sc ED
+ % the following line scales the brush color according to the pattern. the higher the pattern the lighter the color.
+ BCol
+ {
+ 1. exch sub sc mul 1. exch sub
+ } forall
+ 3 array astore
+ SC
+ WFi { fill } { eofill } ifelse
+ } if
+ BSt 9 ge BSt 14 le and % brush pattern?
+ {
+ WFi { clip } { eoclip } ifelse
+ defM SM
+ pathbbox % left upper right lower
+ 3 index 3 index translate
+ 4 2 roll % right lower left upper
+ 3 2 roll % right left upper lower
+ exch % left right lower upper
+ sub /h ED
+ sub /w ED
+ OMo {
+ NP
+ 0 0 MT
+ 0 h RL
+ w 0 RL
+ 0 h neg RL
+ CP
+ BkCol SC
+ fill
+ } if
+ BCol SC
+ 0.3 SW
+ NP
+ BSt 9 eq BSt 11 eq or % horiz or cross pattern
+ { 0 4 h
+ { dup 0 exch MT w exch LT } for
+ } if
+ BSt 10 eq BSt 11 eq or % vert or cross pattern
+ { 0 4 w
+ { dup 0 MT h LT } for
+ } if
+ BSt 12 eq BSt 14 eq or % F-diag or diag cross
+ { w h gt
+ { 0 6 w h add
+ { dup 0 MT h sub h LT } for
+ } { 0 6 w h add
+ { dup 0 exch MT w sub w exch LT } for
+ } ifelse
+ } if
+ BSt 13 eq BSt 14 eq or % B-diag or diag cross
+ { w h gt
+ { 0 6 w h add
+ { dup h MT h sub 0 LT } for
+ } { 0 6 w h add
+ { dup w exch MT w sub 0 exch LT } for
+ } ifelse
+ } if
+ S
+ } if
+ BSt 24 eq % CustomPattern
+
+ {
+ } if
+ grestore
+} D
+
+% for arc
+/mat matrix d
+/ang1 D0 /ang2 D0
+/w D0 /h D0
+/x D0 /y D0
+
+/ARC { % Generic ARC function [ X Y W H ang1 ang2 ]
+ /ang2 ED /ang1 ED /h ED /w ED /y ED /x ED
+ mat CM pop
+ x w 2 div add y h 2 div add TR
+ 1 h w div neg scale
+ ang2 0 ge
+ {0 0 w 2 div ang1 ang1 ang2 add arc }
+ {0 0 w 2 div ang1 ang1 ang2 add arcn} ifelse
+ mat SM
+} D
+
+/C D0
+
+/P { % PdcDrawPoint [x y]
+ NP
+ MT
+ 0.5 0.5 rmoveto
+ 0 -1 RL
+ -1 0 RL
+ 0 1 RL
+ CP
+ fill
+} D
+
+/M { % PdcMoveTo [x y]
+ /Cy ED /Cx ED
+} D
+
+/L { % PdcLineTo [x y]
+ NP
+ Cx Cy MT
+ /Cy ED /Cx ED
+ Cx Cy LT
+ QS
+} D
+
+/DL { % PdcDrawLine [x1 y1 x0 y0]
+ NP
+ MT
+ LT
+ QS
+} D
+
+/HL { % PdcDrawLine [x1 y x0]
+ 1 index DL
+} D
+
+/VL { % PdcDrawLine [x y1 y0]
+ 2 index exch DL
+} D
+
+/R { % PdcDrawRect [x y w h]
+ /h ED /w ED /y ED /x ED
+ NP
+ x y MT
+ 0 h RL
+ w 0 RL
+ 0 h neg RL
+ CP
+ BF
+ QS
+} D
+
+/ACR { % add clip rect
+ /h ED /w ED /y ED /x ED
+ x y MT
+ 0 h RL
+ w 0 RL
+ 0 h neg RL
+ CP
+} D
+
+/xr D0 /yr D0
+/rx D0 /ry D0 /rx2 D0 /ry2 D0
+
+/RR { % PdcDrawRoundRect [x y w h xr yr]
+ /yr ED /xr ED /h ED /w ED /y ED /x ED
+ xr 0 le yr 0 le or
+ {x y w h R} % Do rect if one of rounding values is less than 0.
+ {xr 100 ge yr 100 ge or
+ {x y w h E} % Do ellipse if both rounding values are larger than 100
+ {
+ /rx xr w mul 200 div d
+ /ry yr h mul 200 div d
+ /rx2 rx 2 mul d
+ /ry2 ry 2 mul d
+ NP
+ x rx add y MT
+ x y rx2 ry2 180 -90
+ x y h add ry2 sub rx2 ry2 270 -90
+ x w add rx2 sub y h add ry2 sub rx2 ry2 0 -90
+ x w add rx2 sub y rx2 ry2 90 -90
+ ARC ARC ARC ARC
+ CP
+ BF
+ QS
+ } ifelse
+ } ifelse
+} D
+
+/E { % PdcDrawEllipse [x y w h]
+ /h ED /w ED /y ED /x ED
+ mat CM pop
+ x w 2 div add y h 2 div add translate
+ 1 h w div scale
+ NP
+ 0 0 w 2 div 0 360 arc
+ mat SM
+ BF
+ QS
+} D
+
+/A { % PdcDrawArc [x y w h ang1 ang2]
+ 16 div exch 16 div exch
+ NP
+ ARC
+ QS
+} D
+
+/PIE { % PdcDrawPie [x y w h ang1 ang2]
+ /ang2 ED /ang1 ED /h ED /w ED /y ED /x ED
+ NP
+ x w 2 div add y h 2 div add MT
+ x y w h ang1 16 div ang2 16 div ARC
+ CP
+ BF
+ QS
+} D
+
+/CH { % PdcDrawChord [x y w h ang1 ang2]
+ 16 div exch 16 div exch
+ NP
+ ARC
+ CP
+ BF
+ QS
+} D
+
+/BZ { % PdcDrawCubicBezier [4 points]
+ curveto
+ QS
+} D
+
+/CRGB { % Compute RGB [R G B] => R/255 G/255 B/255
+ 255 div 3 1 roll
+ 255 div 3 1 roll
+ 255 div 3 1 roll
+} D
+
+
+/BC { % PdcSetBkColor [R G B]
+ CRGB
+ BkCol astore pop
+} D
+
+/BR { % PdcSetBrush [style R G B]
+ CRGB
+ BCol astore pop
+ /BSt ED
+} D
+
+/WB { % set white solid brush
+ 1 W BR
+} D
+
+/NB { % set nobrush
+ 0 B BR
+} D
+
+/PE { % PdcSetPen [style width R G B Cap Join]
+ setlinejoin setlinecap
+ CRGB
+ PCol astore pop
+ /LWi ED
+ /PSt ED
+ LWi 0 eq { 0.25 /LWi ED } if % ### 3.0 remove this line
+ PCol SC
+} D
+
+/P1 { % PdcSetPen [R G B]
+ 1 0 5 2 roll 0 0 PE
+} D
+
+/ST { % SET TRANSFORM [matrix]
+ defM setmatrix
+ concat
+} D
+
+%% Font handling
+
+% the next three commands are for defining fonts. The first one
+% tries to tqfind the most suitable printer font out of a fontlist.
+% if encoding is false the default one will be used.
+/MF { % newname encoding fontlist
+ % this function tries to tqfind a suitable postscript font.
+ % We try quite hard not to get courier for a
+ % proportional font. The following takes an array of fonts.
+ % The algorithm will take the first font that
+ % gives a match (defined as not resulting in a courier font).
+ % each entry in the table is an array of the form [ /Fontname x-stretch slant ]
+ % x-strtch can be used to stretch/squeeze the font in x direction.
+ % This gives better results when eg substituting helvetica for arial
+ % slant is an optional slant. 0 is non slanted, 0.2 is a typical value for a syntetic oblique.
+ % encoding can be either an encoding vector of false if the default font encoding is requested.
+ true exch true exch % push a dummy on the stack,
+ { % so the loop over the array will leave a font in any case when exiting.
+ exch pop exch pop % (dummy | oldfont) (dummy | fontdict) fontarray
+ dup 0 get dup tqfindfont % get the fontname from the array and load it
+ dup /FontName get % see if the font exists
+ 3 -1 roll eq { % see if fontname and the one provided are equal
+ exit
+ } if
+ } forall
+ exch % font fontarray
+
+ % newname encoding font fontarray defines a postscript font
+ dup
+ 1 get /fxscale exch def % define scale, sland and encoding
+ 2 get /fslant exch def
+ exch /fencoding exch def
+ [ fxscale 0 fslant 1 0 0 ] makefont % transform font accordingly
+ fencoding false eq { % check if we have an encoding and use it if available
+ } {
+ dup maxlength dict begin % copy font
+ {
+ 1 index /FID ne % don't copy FID, as it's not allowed in PS Level 1
+ {def}{pop pop}ifelse
+ } forall
+ /Encoding fencoding def % tqreplace encoding
+ currentdict
+ end
+ } ifelse
+ definefont pop
+} D
+
+% an embedded font. This is used for the base fonts of the composite font used later on.
+/MFEmb { % newname encoding fontname
+ tqfindfont dup length dict
+ begin
+ {
+ 1 index /FID ne
+ {d}{pop pop}ifelse
+ } forall
+ /Encoding ED currentdict
+ end
+ definefont pop
+} D
+
+% DF: define font
+% used to get a scaled version of an already loaded font
+%
+% newname pointsize fontmame DF -
+/DF {
+ tqfindfont
+ % get the fontsize on top of the stack and define font matrix
+ /fs 3 -1 roll d [ fs 0 0 fs -1 mul 0 0 ]
+ makefont
+ d
+} D
+
+/ty 0 d
+/Y {
+ /ty ED
+} D
+
+/Tl { % draw underline/strikeout line: () w x y lw ->Tl-> () w x
+ gsave
+ setlinewidth
+ NP 1 index exch MT
+ 1 index 0 rlineto stroke
+ grestore
+} D
+
+/XYT { % [string [x/y displacement array] width x]
+ ty MT % pops x
+
+ /xyshow where { % interpreter has xyshow
+ pop pop
+ xyshow
+ } { % use ashow
+ exch pop % string cwidth
+ 1 index % string cwidth string
+ dup length 2 div exch % string cwidth length string !have to divide by 2 since we use tqunicode!
+ stringwidth pop % string cwidth length pwidth
+ 3 -1 roll % string length pwidth cwidth
+ exch sub exch div % string extraperchar
+ exch 0 exch % extraperchar 0 string
+ ashow
+ } ifelse
+} D
+
+/AT {
+ ty MT % pops x
+ 1 index % string cwidth string
+ dup length 2 div exch % string cwidth length string !have to divide by 2 since we use tqunicode!
+ stringwidth pop % string cwidth length pwidth
+ 3 -1 roll % string length pwidth cwidth
+ exch sub exch div % string extraperchar
+ exch 0 exch % extraperchar 0 string
+ ashow
+} D
+
+%% start of page
+/QI {
+ /C save d
+ pageinit
+ /Cx 0 d % reset current x position
+ /Cy 0 d % reset current y position
+ /OMo false d
+} D
+
+%% end of page
+/QP { % show page
+ C restore
+ showpage
+} D
+
+% merges one key value pair into the page tqdevice dict
+%
+% key value SPD -
+/SPD {
+ /setpagetqdevice where {
+ 1 dict dup begin 3 1 roll def end
+ setpagetqdevice
+ } { pop pop } ifelse
+} D
+
+/SV { % Save painter state
+ BSt LWi PSt Cx Cy WFi OMo BCol PCol BkCol
+ /nS nS 1 add d
+ gsave
+} D
+
+/RS { % Restore painter state
+ nS 0 gt
+ { grestore
+ /BkCol ED /PCol ED /BCol ED /OMo ED /WFi ED
+ /Cy ED /Cx ED /PSt ED /LWi ED /BSt ED
+ /nS nS 1 sub d
+ } if
+} D
+
+/CLSTART { % clipping start
+ /clipTmp matrix CM d % save current matrix
+ defM SM % Page default matrix
+ NP
+} D
+
+/CLEND { % clipping end
+ clip
+ NP
+ clipTmp SM % restore the current matrix
+} D
+
+/CLO { % clipping off
+ grestore % restore top of page state
+ gsave % save it back again
+ defM SM % set coordsys (defensive progr.)
+} D
+
diff --git a/tqtinterface/qt4/src/kernel/qt_compat.pri b/tqtinterface/qt4/src/kernel/qt_compat.pri
new file mode 100644
index 0000000..b716832
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/qt_compat.pri
@@ -0,0 +1,27 @@
+# Qt compatibility
+
+# scratch pad for internal development
+# hack these for your build like
+# internal {
+# CONFIG += blah
+# }
+
+##########################################################
+
+# mac hac fu
+!embedded:!x11:mac {
+ #never
+ CONFIG -= nas x11 x11sm
+ #CONFIG += sqlcrap
+ sql:sqlcrap {
+ sql-drivers += postgres
+ INCLUDEPATH+=/Users/sam/postgresql-7.0.2/src/include \
+ /Users/sam/postgresql-7.0.2/src/interfaces/libpq
+ LIBS += -L/Users/sam/postgresql-7.0.2/src/interfaces/libpq
+ }
+}
+
+attic {
+ SOURCES += attic/tqttableview.cpp
+ HEADERS += attic/tqttableview.h
+}
diff --git a/tqtinterface/qt4/src/kernel/qt_gfx.pri b/tqtinterface/qt4/src/kernel/qt_gfx.pri
new file mode 100644
index 0000000..0240ff4
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/qt_gfx.pri
@@ -0,0 +1,155 @@
+# Qt graphics
+
+#mng support
+HEADERS += $$KERNEL_H/tqmngio.h
+SOURCES += $$KERNEL_CPP/tqmngio.cpp
+mng {
+ system-mng {
+ win32:LIBS += libmng.lib
+ unix:LIBS += -lmng
+ } else {
+ INCLUDEPATH += 3rdparty/libmng
+ SOURCES += 3rdparty/libmng/libmng_callback_xs.c \
+ 3rdparty/libmng/libmng_chunk_io.c \
+ 3rdparty/libmng/libmng_chunk_prc.c \
+ 3rdparty/libmng/libmng_chunk_xs.c \
+ 3rdparty/libmng/libmng_cms.c \
+ 3rdparty/libmng/libmng_display.c \
+ 3rdparty/libmng/libmng_dither.c \
+ 3rdparty/libmng/libmng_error.c \
+ 3rdparty/libmng/libmng_filter.c \
+ 3rdparty/libmng/libmng_hlapi.c \
+ 3rdparty/libmng/libmng_jpeg.c \
+ 3rdparty/libmng/libmng_object_prc.c \
+ 3rdparty/libmng/libmng_pixels.c \
+ 3rdparty/libmng/libmng_prop_xs.c \
+ 3rdparty/libmng/libmng_read.c \
+ 3rdparty/libmng/libmng_trace.c \
+ 3rdparty/libmng/libmng_write.c \
+ 3rdparty/libmng/libmng_zlib.c
+ }
+ no-jpeg {
+ message(Use of mng requires support for jpeg)
+ CONFIG += jpeg
+ } else:!jpeg {
+ message(Use of mng requires support for jpeg)
+ CONFIG += jpeg
+ }
+}
+else:DEFINES += TQT_NO_IMAGEIO_MNG
+
+#jpeg support..
+HEADERS += $$KERNEL_H/tqjpegio.h
+SOURCES += $$KERNEL_CPP/tqjpegio.cpp
+jpeg {
+ system-jpeg {
+ unix:LIBS += -ljpeg
+ win32:LIBS += libjpeg.lib
+ } else {
+ INCLUDEPATH += 3rdparty/libjpeg
+ SOURCES += 3rdparty/libjpeg/jcapimin.c \
+ 3rdparty/libjpeg/jcapistd.c \
+ 3rdparty/libjpeg/jccoefct.c \
+ 3rdparty/libjpeg/jccolor.c \
+ 3rdparty/libjpeg/jcdctmgr.c \
+ 3rdparty/libjpeg/jchuff.c \
+ 3rdparty/libjpeg/jcinit.c \
+ 3rdparty/libjpeg/jcmainct.c \
+ 3rdparty/libjpeg/jcmarker.c \
+ 3rdparty/libjpeg/jcmaster.c \
+ 3rdparty/libjpeg/jcomapi.c \
+ 3rdparty/libjpeg/jcparam.c \
+ 3rdparty/libjpeg/jcphuff.c \
+ 3rdparty/libjpeg/jcprepct.c \
+ 3rdparty/libjpeg/jcsample.c \
+ 3rdparty/libjpeg/jctrans.c \
+ 3rdparty/libjpeg/jdapimin.c \
+ 3rdparty/libjpeg/jdapistd.c \
+ 3rdparty/libjpeg/jdatadst.c \
+ 3rdparty/libjpeg/jdatasrc.c \
+ 3rdparty/libjpeg/jdcoefct.c \
+ 3rdparty/libjpeg/jdcolor.c \
+ 3rdparty/libjpeg/jddctmgr.c \
+ 3rdparty/libjpeg/jdhuff.c \
+ 3rdparty/libjpeg/jdinput.c \
+ 3rdparty/libjpeg/jdmainct.c \
+ 3rdparty/libjpeg/jdmarker.c \
+ 3rdparty/libjpeg/jdmaster.c \
+ 3rdparty/libjpeg/jdmerge.c \
+ 3rdparty/libjpeg/jdphuff.c \
+ 3rdparty/libjpeg/jdpostct.c \
+ 3rdparty/libjpeg/jdsample.c \
+ 3rdparty/libjpeg/jdtrans.c \
+ 3rdparty/libjpeg/jerror.c \
+ 3rdparty/libjpeg/jfdctflt.c \
+ 3rdparty/libjpeg/jfdctfst.c \
+ 3rdparty/libjpeg/jfdctint.c \
+ 3rdparty/libjpeg/jidctflt.c \
+ 3rdparty/libjpeg/jidctfst.c \
+ 3rdparty/libjpeg/jidctint.c \
+ 3rdparty/libjpeg/jidctred.c \
+ 3rdparty/libjpeg/jmemmgr.c \
+ 3rdparty/libjpeg/jquant1.c \
+ 3rdparty/libjpeg/jquant2.c \
+ 3rdparty/libjpeg/jutils.c \
+ 3rdparty/libjpeg/jmemnobs.c
+ }
+}
+else:DEFINES += TQT_NO_IMAGEIO_JPEG
+
+#png support
+HEADERS+=$$KERNEL_H/tqpngio.h
+SOURCES+=$$KERNEL_CPP/tqpngio.cpp
+png {
+ system-png {
+ unix:LIBS += -lpng
+ win32:LIBS += libpng.lib
+ } else {
+ INCLUDEPATH += 3rdparty/libpng
+ SOURCES += 3rdparty/libpng/png.c \
+ 3rdparty/libpng/pngerror.c \
+ 3rdparty/libpng/pngget.c \
+ 3rdparty/libpng/pngmem.c \
+ 3rdparty/libpng/pngpread.c \
+ 3rdparty/libpng/pngread.c \
+ 3rdparty/libpng/pngrio.c \
+ 3rdparty/libpng/pngrtran.c \
+ 3rdparty/libpng/pngrutil.c \
+ 3rdparty/libpng/pngset.c \
+ 3rdparty/libpng/pngtrans.c \
+ 3rdparty/libpng/pngwio.c \
+ 3rdparty/libpng/pngwrite.c \
+ 3rdparty/libpng/pngwtran.c \
+ 3rdparty/libpng/pngwutil.c
+ }
+}
+else:DEFINES += TQT_NO_IMAGEIO_PNG
+
+#zlib support
+zlib {
+ INCLUDEPATH += 3rdparty/zlib
+ SOURCES += 3rdparty/zlib/adler32.c \
+ 3rdparty/zlib/compress.c \
+ 3rdparty/zlib/crc32.c \
+ 3rdparty/zlib/deflate.c \
+ 3rdparty/zlib/gzio.c \
+ 3rdparty/zlib/inffast.c \
+ 3rdparty/zlib/inflate.c \
+ 3rdparty/zlib/inftrees.c \
+ 3rdparty/zlib/trees.c \
+ 3rdparty/zlib/uncompr.c \
+ 3rdparty/zlib/zutil.c
+}
+!no-zlib:!zlib {
+ unix:LIBS += -lz
+ win32:LIBS += libz.lib
+}
+
+unix:xftfreetype {
+ INCLUDEPATH += 3rdparty/opentype
+ SOURCES += 3rdparty/opentype/ftxopentype.c
+}
+
+#use Qt gif
+gif:DEFINES += TQT_BUILTIN_GIF_READER=1
+
diff --git a/tqtinterface/qt4/src/kernel/qt_kernel.pri b/tqtinterface/qt4/src/kernel/qt_kernel.pri
new file mode 100644
index 0000000..aa76de0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/qt_kernel.pri
@@ -0,0 +1,261 @@
+# Qt kernel module
+
+kernel {
+ KERNEL_P = kernel
+ HEADERS += $$KERNEL_H/tqabstractlayout.h \
+ $$KERNEL_H/tqaccel.h \
+ $$KERNEL_P/tqucomextra_p.h \
+ $$KERNEL_H/tqapplication.h \
+ $$KERNEL_P/tqapplication_p.h \
+ $$KERNEL_H/tqasyncimageio.h \
+ $$KERNEL_H/tqasyncio.h \
+ $$KERNEL_H/tqbitmap.h \
+ $$KERNEL_H/tqbrush.h \
+ $$KERNEL_H/tqclipboard.h \
+ $$KERNEL_H/tqcolor.h \
+ $$KERNEL_P/tqcolor_p.h \
+ $$KERNEL_H/tqconnection.h \
+ $$KERNEL_H/tqcursor.h \
+ $$KERNEL_H/tqdesktopwidget.h \
+ $$KERNEL_H/tqdragobject.h \
+ $$KERNEL_H/tqdrawutil.h \
+ $$KERNEL_H/tqdropsite.h \
+ $$KERNEL_H/tqevent.h \
+ $$KERNEL_H/tqeventloop.h\
+ $$KERNEL_P/tqeventloop_p.h \
+ $$KERNEL_H/tqfocusdata.h \
+ $$KERNEL_H/tqfont.h \
+ $$KERNEL_P/tqfontdata_p.h \
+ $$KERNEL_H/tqfontinfo.h \
+ $$KERNEL_H/tqfontmetrics.h \
+ $$KERNEL_H/tqguardedptr.h \
+ $$KERNEL_H/tqgif.h \
+ $$KERNEL_H/tqiconset.h \
+ $$KERNEL_H/tqimage.h \
+ $$KERNEL_P/tqimageformatinterface_p.h \
+ $$KERNEL_H/tqimageformatplugin.h \
+ $$KERNEL_P/tqinputcontext_p.h \
+ $$KERNEL_H/tqkeycode.h \
+ $$KERNEL_H/tqkeysequence.h \
+ $$KERNEL_H/tqlayout.h \
+ $$KERNEL_P/tqlayoutengine_p.h \
+ $$KERNEL_H/tqtranslator.h \
+ $$KERNEL_H/tqmetaobject.h \
+ $$KERNEL_H/tqmime.h \
+ $$KERNEL_H/tqmovie.h \
+ $$KERNEL_H/tqnamespace.h \
+ $$KERNEL_H/tqnetworkprotocol.h \
+ $$KERNEL_H/tqobject.h \
+ $$KERNEL_H/tqobjectcleanuphandler.h \
+ $$KERNEL_H/tqobjectdefs.h \
+ $$KERNEL_H/tqobjectdict.h \
+ $$KERNEL_H/tqobjectlist.h \
+ $$KERNEL_H/tqpaintdevice.h \
+ $$KERNEL_H/tqpaintdevicedefs.h \
+ $$KERNEL_H/tqpainter.h \
+ $$KERNEL_P/tqpainter_p.h \
+ $$KERNEL_H/tqpalette.h \
+ $$KERNEL_H/tqpaintdevicemetrics.h \
+ $$KERNEL_H/tqpen.h \
+ $$KERNEL_H/tqpicture.h \
+ $$KERNEL_H/tqpixmap.h \
+ $$KERNEL_H/tqpixmapcache.h \
+ $$KERNEL_H/tqpointarray.h \
+ $$KERNEL_H/tqpoint.h \
+ $$KERNEL_H/tqpolygonscanner.h \
+ $$KERNEL_H/tqprinter.h \
+ $$KERNEL_H/tqprocess.h \
+ $$KERNEL_H/tqrect.h \
+ $$KERNEL_H/tqregion.h \
+ $$KERNEL_H/tqsessionmanager.h \
+ $$KERNEL_H/tqsignal.h \
+ $$KERNEL_H/tqsignalmapper.h \
+ $$KERNEL_H/tqsignalslotimp.h \
+ $$KERNEL_H/tqsize.h \
+ $$KERNEL_H/tqsizegrip.h \
+ $$KERNEL_H/tqsizepolicy.h \
+ $$KERNEL_H/tqsocketnotifier.h \
+ $$KERNEL_H/tqsound.h \
+ $$KERNEL_H/tqstyle.h \
+ $$KERNEL_H/tqstylesheet.h \
+ $$KERNEL_H/tqthread.h \
+ $$KERNEL_H/tqtimer.h \
+ $$KERNEL_H/tqurl.h \
+ $$KERNEL_H/tqlocalfs.h \
+ $$KERNEL_H/tqurloperator.h \
+ $$KERNEL_H/tqurlinfo.h \
+ $$KERNEL_H/tqwidget.h \
+ $$KERNEL_H/tqwidgetintdict.h \
+ $$KERNEL_H/tqwidgetlist.h \
+ $$KERNEL_H/tqwindowdefs.h \
+ $$KERNEL_H/tqwmatrix.h \
+ $$KERNEL_H/tqvariant.h \
+ $$KERNEL_P/tqrichtext_p.h \
+ $$KERNEL_P/tqinternal_p.h \
+ $$KERNEL_H/tqgplugin.h \
+ $$KERNEL_H/tqsimplerichtext.h \
+ $$KERNEL_CPP/tqscriptengine_p.h \
+ $$KERNEL_CPP/tqtextengine_p.h \
+ $$KERNEL_CPP/tqfontengine_p.h \
+ $$KERNEL_CPP/tqtextlayout_p.h
+
+ win32:SOURCES += $$KERNEL_CPP/tqapplication_win.cpp \
+ $$KERNEL_CPP/tqclipboard_win.cpp \
+ $$KERNEL_CPP/tqcolor_win.cpp \
+ $$KERNEL_CPP/tqcursor_win.cpp \
+ $$KERNEL_CPP/tqdesktopwidget_win.cpp \
+ $$KERNEL_CPP/tqdnd_win.cpp \
+ $$KERNEL_CPP/tqeventloop_win.cpp \
+ $$KERNEL_CPP/tqfont_win.cpp \
+ $$KERNEL_CPP/tqinputcontext_win.cpp \
+ $$KERNEL_CPP/tqmime_win.cpp \
+ $$KERNEL_CPP/tqpixmap_win.cpp \
+ $$KERNEL_CPP/tqprinter_win.cpp \
+ $$KERNEL_CPP/tqprocess_win.cpp \
+ $$KERNEL_CPP/tqpaintdevice_win.cpp \
+ $$KERNEL_CPP/tqpainter_win.cpp \
+ $$KERNEL_CPP/tqregion_win.cpp \
+ $$KERNEL_CPP/tqsound_win.cpp \
+ $$KERNEL_CPP/tqthread_win.cpp \
+ $$KERNEL_CPP/tqwidget_win.cpp \
+ $$KERNEL_CPP/tqole_win.c \
+ $$KERNEL_CPP/tqfontengine_win.cpp
+
+ unix:x11 {
+ SOURCES += $$KERNEL_CPP/tqapplication_x11.cpp \
+ $$KERNEL_CPP/tqclipboard_x11.cpp \
+ $$KERNEL_CPP/tqcolor_x11.cpp \
+ $$KERNEL_CPP/tqcursor_x11.cpp \
+ $$KERNEL_CPP/tqdnd_x11.cpp \
+ $$KERNEL_CPP/tqdesktopwidget_x11.cpp \
+ $$KERNEL_CPP/tqeventloop_x11.cpp \
+ $$KERNEL_CPP/tqfont_x11.cpp \
+ $$KERNEL_CPP/tqinputcontext_x11.cpp \
+ $$KERNEL_CPP/tqmotifdnd_x11.cpp \
+ $$KERNEL_CPP/tqpixmap_x11.cpp \
+ $$KERNEL_CPP/tqpaintdevice_x11.cpp \
+ $$KERNEL_CPP/tqpainter_x11.cpp \
+ $$KERNEL_CPP/tqregion_x11.cpp \
+ $$KERNEL_CPP/tqsound_x11.cpp \
+ $$KERNEL_CPP/tqwidget_x11.cpp \
+ $$KERNEL_CPP/tqwidgetcreate_x11.cpp \
+ $$KERNEL_CPP/tqfontengine_x11.cpp
+ }
+
+ !x11:mac {
+ exists(qsound_mac.cpp):SOURCES += $$KERNEL_CPP/tqsound_mac.cpp
+ else:SOURCES += $$KERNEL_CPP/tqsound_qws.cpp
+ }
+ !embedded:!x11:mac {
+ SOURCES += $$KERNEL_CPP/tqapplication_mac.cpp \
+ $$KERNEL_CPP/tqclipboard_mac.cpp \
+ $$KERNEL_CPP/tqcolor_mac.cpp \
+ $$KERNEL_CPP/tqcursor_mac.cpp \
+ $$KERNEL_CPP/tqmime_mac.cpp \
+ $$KERNEL_CPP/tqdnd_mac.cpp \
+ $$KERNEL_CPP/tqdesktopwidget_mac.cpp \
+ $$KERNEL_CPP/tqpixmap_mac.cpp \
+ $$KERNEL_CPP/tqprinter_mac.cpp \
+ $$KERNEL_CPP/tqpaintdevice_mac.cpp \
+ $$KERNEL_CPP/tqpainter_mac.cpp \
+ $$KERNEL_CPP/tqregion_mac.cpp \
+ $$KERNEL_CPP/tqwidget_mac.cpp \
+ $$KERNEL_CPP/tqeventloop_mac.cpp \
+ $$KERNEL_CPP/tqfont_mac.cpp \
+ $$KERNEL_CPP/tqfontengine_mac.cpp
+ DEFINES += QMAC_ONE_PIXEL_LOCK
+ } else:unix {
+ SOURCES += $$KERNEL_CPP/tqprinter_unix.cpp \
+ $$KERNEL_CPP/tqpsprinter.cpp \
+ $$KERNEL_CPP/tqeventloop_unix.cpp
+ }
+ unix:SOURCES += $$KERNEL_CPP/tqprocess_unix.cpp \
+ $$KERNEL_CPP/tqthread_unix.cpp
+
+ SOURCES += $$KERNEL_CPP/tqabstractlayout.cpp \
+ $$KERNEL_CPP/tqucomextra.cpp \
+ $$KERNEL_CPP/tqaccel.cpp \
+ $$KERNEL_CPP/tqapplication.cpp \
+ $$KERNEL_CPP/tqasyncimageio.cpp \
+ $$KERNEL_CPP/tqasyncio.cpp \
+ $$KERNEL_CPP/tqbitmap.cpp \
+ $$KERNEL_CPP/tqclipboard.cpp \
+ $$KERNEL_CPP/tqcolor.cpp \
+ $$KERNEL_CPP/tqcolor_p.cpp \
+ $$KERNEL_CPP/tqconnection.cpp \
+ $$KERNEL_CPP/tqcursor.cpp \
+ $$KERNEL_CPP/tqdragobject.cpp \
+ $$KERNEL_CPP/tqdrawutil.cpp \
+ $$KERNEL_CPP/tqdropsite.cpp \
+ $$KERNEL_CPP/tqevent.cpp \
+ $$KERNEL_CPP/tqeventloop.cpp \
+ $$KERNEL_CPP/tqfocusdata.cpp \
+ $$KERNEL_CPP/tqfont.cpp \
+ $$KERNEL_CPP/tqfontdatabase.cpp \
+ $$KERNEL_CPP/tqguardedptr.cpp \
+ $$KERNEL_CPP/tqiconset.cpp \
+ $$KERNEL_CPP/tqimage.cpp \
+ $$KERNEL_CPP/tqimageformatplugin.cpp \
+ $$KERNEL_CPP/tqkeysequence.cpp \
+ $$KERNEL_CPP/tqlayout.cpp \
+ $$KERNEL_CPP/tqlayoutengine.cpp \
+ $$KERNEL_CPP/tqtranslator.cpp \
+ $$KERNEL_CPP/tqmetaobject.cpp \
+ $$KERNEL_CPP/tqmime.cpp \
+ $$KERNEL_CPP/tqmovie.cpp \
+ $$KERNEL_CPP/tqnetworkprotocol.cpp \
+ $$KERNEL_CPP/tqobject.cpp \
+ $$KERNEL_CPP/tqobjectcleanuphandler.cpp \
+ $$KERNEL_CPP/tqpainter.cpp \
+ $$KERNEL_CPP/tqpalette.cpp \
+ $$KERNEL_CPP/tqpaintdevicemetrics.cpp \
+ $$KERNEL_CPP/tqpicture.cpp \
+ $$KERNEL_CPP/tqpixmap.cpp \
+ $$KERNEL_CPP/tqpixmapcache.cpp \
+ $$KERNEL_CPP/tqpointarray.cpp \
+ $$KERNEL_CPP/tqpoint.cpp \
+ $$KERNEL_CPP/tqpolygonscanner.cpp \
+ $$KERNEL_CPP/tqprinter.cpp \
+ $$KERNEL_CPP/tqprocess.cpp \
+ $$KERNEL_CPP/tqrect.cpp \
+ $$KERNEL_CPP/tqregion.cpp \
+ $$KERNEL_CPP/tqsignal.cpp \
+ $$KERNEL_CPP/tqsignalmapper.cpp \
+ $$KERNEL_CPP/tqsize.cpp \
+ $$KERNEL_CPP/tqsizegrip.cpp \
+ $$KERNEL_CPP/tqstyle.cpp \
+ $$KERNEL_CPP/tqsocketnotifier.cpp \
+ $$KERNEL_CPP/tqsound.cpp \
+ $$KERNEL_CPP/tqstylesheet.cpp \
+ $$KERNEL_CPP/tqthread.cpp \
+ $$KERNEL_CPP/tqtimer.cpp \
+ $$KERNEL_CPP/tqurl.cpp \
+ $$KERNEL_CPP/tqlocalfs.cpp \
+ $$KERNEL_CPP/tqurloperator.cpp \
+ $$KERNEL_CPP/tqurlinfo.cpp \
+ $$KERNEL_CPP/tqwidget.cpp \
+ $$KERNEL_CPP/tqwmatrix.cpp \
+ $$KERNEL_CPP/tqvariant.cpp \
+ $$KERNEL_CPP/tqrichtext.cpp \
+ $$KERNEL_CPP/tqinternal.cpp \
+ $$KERNEL_CPP/tqrichtext_p.cpp \
+ $$KERNEL_CPP/tqgplugin.cpp \
+ $$KERNEL_CPP/tqsimplerichtext.cpp \
+ $$KERNEL_CPP/tqscriptengine.cpp \
+ $$KERNEL_CPP/tqtextlayout.cpp \
+ $$KERNEL_CPP/tqtextengine.cpp
+
+ unix:HEADERS += $$KERNEL_P/tqpsprinter_p.h \
+ $$KERNEL_H/tqfontdatabase.h
+
+ embedded:SOURCES += $$KERNEL_CPP/tqsharedmemory_p.cpp \
+ $$KERNEL_CPP/tqfontengine_qws.cpp
+
+ accessibility {
+ HEADERS += $$KERNEL_H/tqaccessible.h
+ SOURCES += $$KERNEL_CPP/tqaccessible.cpp
+
+ !embedded:!x11:mac:SOURCES += $$KERNEL_CPP/tqaccessible_mac.cpp
+ else:win32:SOURCES += $$KERNEL_CPP/tqaccessible_win.cpp
+ }
+}
diff --git a/tqtinterface/qt4/src/kernel/qt_x11.pri b/tqtinterface/qt4/src/kernel/qt_x11.pri
new file mode 100644
index 0000000..d437261
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/qt_x11.pri
@@ -0,0 +1,20 @@
+unix {
+ !xinerama:DEFINES += TQT_NO_XINERAMA
+ !xtqshape:DEFINES += TQT_NO_SHAPE
+ !xcursor:DEFINES += TQT_NO_XCURSOR
+ !xrandr:DEFINES += TQT_NO_XRANDR
+ !xrender:DEFINES += TQT_NO_XRENDER
+ !xftfreetype:DEFINES += TQT_NO_XFTFREETYPE
+ !xkb:DEFINES += TQT_NO_XKB
+ xft2header:DEFINES+=TQT_USE_XFT2_HEADER
+
+ SOURCES += $$KERNEL_CPP/tqtaddons_x11.cpp
+ PRECOMPILED_HEADER = kernel/tqt_pch.h
+}
+
+nas {
+ DEFINES += TQT_NAS_SUPPORT
+ LIBS += -laudio -lXt
+}
+
+!x11sm:DEFINES += TQT_NO_SM_SUPPORT
diff --git a/tqtinterface/qt4/src/kernel/tq1xcompatibility.h b/tqtinterface/qt4/src/kernel/tq1xcompatibility.h
new file mode 100644
index 0000000..dcf3595
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tq1xcompatibility.h
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Various macros etc. to ease porting from TQt 1.x to 2.0. THIS FILE
+** WILL CHANGE OR DISAPPEAR IN THE NEXT VERSION OF TQt.
+**
+** Created : 980824
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef Q1XCOMPATIBILITY_H
+#define Q1XCOMPATIBILITY_H
+
+#error "Compatibility with TQt 1.x is no longer guaranteed. Please"
+#error "update your code (for example using qt20fix script). We"
+#error "apologize for any inconvenience."
+
+#endif // Q1XCOMPATIBILITY_H
diff --git a/tqtinterface/qt4/src/kernel/tqabstractlayout.cpp b/tqtinterface/qt4/src/kernel/tqabstractlayout.cpp
new file mode 100644
index 0000000..4c15ee2
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqabstractlayout.cpp
@@ -0,0 +1,2108 @@
+/****************************************************************************
+**
+** Implementation of the abstract tqlayout base class
+**
+** Created : 960416
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqlayout.h"
+
+#ifndef TQT_NO_LAYOUT
+#include "tqapplication.h"
+#include "tqlayoutengine_p.h"
+#include "tqmenubar.h"
+#include "tqtoolbar.h"
+
+#ifdef USE_QT4
+
+/*!
+ Sets the value returned by supportsMargin(). If \a b is TRUE,
+ margin() handling is implemented by the subclass. If \a b is
+ FALSE (the default), TQLayout will add margin() around top-level
+ layouts.
+
+ If \a b is TRUE, margin handling needs to be implemented in
+ setGeometry(), tqmaximumSize(), tqminimumSize(), tqsizeHint() and
+ heightForWidth().
+
+ \sa supportsMargin()
+*/
+void TQLayout::setSupportsMargin( bool b )
+{
+ printf("[FIXME] void TQLayout::setSupportsMargin( bool b ) unimplemented!\n\r");
+}
+
+/*!
+ Removes and deletes all items in this tqlayout.
+*/
+void TQLayout::deleteAllItems()
+{
+ TQLayoutIterator it = iterator();
+ TQLayoutItem *l;
+ while ( (l = it.takeCurrent()) )
+ delete l;
+}
+
+#else // USE_QT4
+
+static int menuBarHeightForWidth( TQMenuBar *menubar, int w )
+{
+#ifndef TQT_NO_MENUBAR
+ if ( menubar && !menubar->isHidden() && !menubar->isTopLevel() )
+ return menubar->heightForWidth( TQMAX(w, menubar->minimumWidth()) );
+ else
+#endif
+ return 0;
+}
+
+#endif // USE_QT4
+
+/*!
+ \class TQLayoutItem
+ \ingroup appearance
+ \ingroup geomanagement
+ \brief The TQLayoutItem class provides an abstract item that a
+ TQLayout manipulates.
+
+ This is used by custom layouts.
+
+ Pure virtual functions are provided to return information about
+ the tqlayout, including, tqsizeHint(), tqminimumSize(), tqmaximumSize()
+ and expandingDirections().
+
+ The tqlayout's tqgeometry can be set and retrieved with setGeometry()
+ and tqgeometry(), and its tqalignment with tqsetAlignment() and
+ tqalignment().
+
+ isEmpty() returns whether the tqlayout is empty. iterator() returns
+ an iterator for the tqlayout's tqchildren. If the concrete item is a
+ TQWidget, it can be retrieved using widget(). Similarly for
+ tqlayout() and tqspacerItem().
+
+ \sa TQLayout
+*/
+
+/*!
+ \class TQSpacerItem
+ \ingroup appearance
+ \ingroup geomanagement
+ \brief The TQSpacerItem class provides blank space in a tqlayout.
+
+ This class is used by custom layouts.
+
+ \sa TQLayout TQLayout::tqspacerItem()
+*/
+
+/*!
+ \class TQWidgetItem
+ \ingroup appearance
+ \ingroup geomanagement
+ \brief The TQWidgetItem class is a tqlayout item that represents a widget.
+
+ This is used by custom layouts.
+
+ \sa TQLayout TQLayout::widget()
+*/
+
+/*!
+ \fn TQLayoutItem::TQLayoutItem( int tqalignment )
+
+ Constructs a tqlayout item with an \a tqalignment that is a bitwise OR
+ of the \l{TQt::AlignmentFlags}. Not all subclasses support
+ tqalignment.
+*/
+
+/*!
+ \fn int TQLayoutItem::tqalignment() const
+
+ Returns the tqalignment of this item.
+*/
+
+/*!
+ Sets the tqalignment of this item to \a a, which is a bitwise OR of
+ the \l{TQt::AlignmentFlags}. Not all subclasses support tqalignment.
+*/
+// void TQLayoutItem::tqsetAlignment( int a )
+// {
+// align = (Qt::AlignmentFlag)a;
+// }
+
+/*!
+ \fn TQSize TQLayoutItem::tqmaximumSize() const
+
+ Implemented in subclasses to return the maximum size of this item.
+*/
+
+/*!
+ \fn TQSize TQLayoutItem::tqminimumSize() const
+
+ Implemented in subclasses to return the minimum size of this item.
+*/
+
+/*!
+ \fn TQSize TQLayoutItem::tqsizeHint() const
+
+ Implemented in subclasses to return the preferred size of this item.
+*/
+
+/*!
+ \fn TQ_SPExpandData TQLayoutItem::expandingDirections() const
+
+ Implemented in subclasses to return the direction(s) this item
+ "wants" to expand in (if any).
+*/
+
+/*!
+ \fn void TQLayoutItem::setGeometry( const TQRect &r )
+
+ Implemented in subclasses to set this item's tqgeometry to \a r.
+*/
+
+/*!
+ \fn TQRect TQLayoutItem::tqgeometry() const
+
+ Returns the rectangle covered by this tqlayout item.
+*/
+
+/*!
+ \fn virtual bool TQLayoutItem::isEmpty() const
+
+ Implemented in subclasses to return whether this item is empty,
+ i.e. whether it tqcontains any widgets.
+*/
+
+/*!
+ \fn TQSpacerItem::TQSpacerItem( int w, int h, TQSizePolicy::SizeType hData, TQSizePolicy::SizeType vData )
+
+ Constructs a spacer item with preferred width \a w, preferred
+ height \a h, horizontal size policy \a hData and vertical size
+ policy \a vData.
+
+ The default values provide a gap that is able to stretch if
+ nothing else wants the space.
+*/
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ Changes this spacer item to have preferred width \a w, preferred
+ height \a h, horizontal size policy \a hData and vertical size
+ policy \a vData.
+
+ The default values provide a gap that is able to stretch if
+ nothing else wants the space.
+*/
+void TQSpacerItem::changeSize( int w, int h, TQSizePolicy::SizeType hData,
+ TQSizePolicy::SizeType vData )
+{
+ width = w;
+ height = h;
+ sizeP = TQSizePolicy( hData, vData );
+}
+
+#endif // USE_QT4
+
+/*!
+ \fn TQWidgetItem::TQWidgetItem (TQWidget * w)
+
+ Creates an item containing widget \a w.
+*/
+
+/*!
+ Destroys the TQLayoutItem.
+*/
+// TQLayoutItem::~TQLayoutItem()
+// {
+// }
+
+/*!
+ Invalidates any cached information in this tqlayout item.
+*/
+// void TQLayoutItem::tqinvalidate()
+// {
+// }
+
+/*!
+ If this item is a TQLayout, it is returned as a TQLayout; otherwise
+ 0 is returned. This function provides type-safe casting.
+*/
+// TQLayout * TQLayoutItem::tqlayout()
+// {
+// return 0;
+// }
+
+/*!
+ If this item is a TQSpacerItem, it is returned as a TQSpacerItem;
+ otherwise 0 is returned. This function provides type-safe casting.
+*/
+// TQSpacerItem * TQLayoutItem::tqspacerItem()
+// {
+// return 0;
+// }
+
+/*!
+ \reimp
+*/
+// TQLayout * TQLayout::tqlayout()
+// {
+// return this;
+// }
+
+/*!
+ \reimp
+*/
+TQSpacerItem * TQSpacerItem::tqspacerItem()
+{
+ return this;
+}
+
+/*!
+ If this item is a TQWidget, it is returned as a TQWidget; otherwise
+ 0 is returned. This function provides type-safe casting.
+*/
+// TQWidget * TQLayoutItem::widget()
+// {
+// return 0;
+// }
+
+/*!
+ Returns the widget managed by this item.
+*/
+TQWidget * TQWidgetItem::widget()
+{
+ return wid;
+}
+
+/*!
+ Returns TRUE if this tqlayout's preferred height depends on its
+ width; otherwise returns FALSE. The default implementation returns
+ FALSE.
+
+ Reimplement this function in tqlayout managers that support height
+ for width.
+
+ \sa heightForWidth(), TQWidget::heightForWidth()
+*/
+// bool TQLayoutItem::hasHeightForWidth() const
+// {
+// return FALSE;
+// }
+
+/*!
+ Returns an iterator over this item's TQLayoutItem tqchildren. The
+ default implementation returns an empty iterator.
+
+ Reimplement this function in subclasses that can have tqchildren.
+*/
+// TQLayoutIterator TQLayoutItem::iterator()
+// {
+// return TQLayoutIterator( 0 );
+// }
+
+/*!
+ Returns the preferred height for this tqlayout item, given the width
+ \a w.
+
+ The default implementation returns -1, indicating that the
+ preferred height is independent of the width of the item. Using
+ the function hasHeightForWidth() will typically be much faster
+ than calling this function and testing for -1.
+
+ Reimplement this function in tqlayout managers that support height
+ for width. A typical implementation will look like this:
+ \code
+ int MyLayout::heightForWidth( int w ) const
+ {
+ if ( cache_dirty || cached_width != w ) {
+ // not all C++ compilers support "mutable"
+ MyLayout *that = (MyLayout*)this;
+ int h = calculateHeightForWidth( w );
+ that->cached_hfw = h;
+ return h;
+ }
+ return cached_hfw;
+ }
+ \endcode
+
+ Caching is strongly recommended; without it tqlayout will take
+ exponential time.
+
+ \sa hasHeightForWidth()
+*/
+// int TQLayoutItem::heightForWidth( int /* w */ ) const
+// {
+// return -1;
+// }
+
+#ifdef USE_QT4
+
+/*!
+ Stores the spacer item's rect \a r so that it can be returned by
+ tqgeometry().
+*/
+void TQSpacerItem::setGeometry( const TQRect &r )
+{
+ QSpacerItem::setGeometry(r);
+}
+
+#else // USE_QT4
+
+/*!
+ Stores the spacer item's rect \a r so that it can be returned by
+ tqgeometry().
+*/
+void TQSpacerItem::setGeometry( const TQRect &r )
+{
+ rect = r;
+}
+
+#endif // USE_QT4
+
+/*!
+ Sets the tqgeometry of this item's widget to be contained within
+ rect \a r, taking tqalignment and maximum size into account.
+*/
+void TQWidgetItem::setGeometry( const TQRect &r )
+{
+ TQSize s = r.size().boundedTo( tqSmartMaxSize( this ) );
+ int x = r.x();
+ int y = r.y();
+ if ( align & (TQt::AlignHorizontal_Mask | TQt::AlignVertical_Mask) ) {
+ TQSize pref = wid->tqsizeHint().expandedTo( wid->tqminimumSize() ); //###
+ if ( align & TQt::AlignHorizontal_Mask )
+ s.setWidth( TQMIN( s.width(), pref.width() ) );
+ if ( align & TQt::AlignVertical_Mask ) {
+ if ( hasHeightForWidth() )
+ s.setHeight( TQMIN( s.height(), heightForWidth(s.width()) ) );
+ else
+ s.setHeight( TQMIN( s.height(), pref.height() ) );
+ }
+ }
+ int alignHoriz = TQApplication::horizontalAlignment( align );
+ if ( alignHoriz & TQt::AlignRight )
+ x = x + ( r.width() - s.width() );
+ else if ( !(alignHoriz & TQt::AlignLeft) )
+ x = x + ( r.width() - s.width() ) / 2;
+
+ if ( align & TQt::AlignBottom )
+ y = y + ( r.height() - s.height() );
+ else if ( !(align & TQt::AlignTop) )
+ y = y + ( r.height() - s.height() ) / 2;
+
+ if ( !isEmpty() ) {
+ wid->setGeometry( x, y, s.width(), s.height() );
+ }
+}
+
+#ifdef USE_QT4
+
+/*!
+ \reimp
+*/
+TQRect TQSpacerItem::tqgeometry() const
+{
+ return QSpacerItem::geometry();
+}
+
+#else // USE_QT4
+
+/*!
+ \reimp
+*/
+TQRect TQSpacerItem::tqgeometry() const
+{
+ return rect;
+}
+
+#endif // USE_QT4
+
+/*!
+ \reimp
+*/
+TQRect TQWidgetItem::tqgeometry() const
+{
+ return wid->tqgeometry();
+}
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ \reimp
+*/
+TQRect TQLayout::tqgeometry() const
+{
+ return rect;
+}
+
+#endif // USE_QT4
+
+/*!
+ \reimp
+*/
+bool TQWidgetItem::hasHeightForWidth() const
+{
+ if ( isEmpty() )
+ return FALSE;
+ if ( wid->tqlayout() )
+ return wid->tqlayout()->hasHeightForWidth();
+ return wid->sizePolicy().hasHeightForWidth();
+}
+
+/*!
+ \reimp
+*/
+int TQWidgetItem::heightForWidth( int w ) const
+{
+ if ( isEmpty() )
+ return -1;
+ int hfw;
+ if ( wid->tqlayout() )
+ hfw = wid->tqlayout()->totalHeightForWidth( w );
+ else
+ hfw = wid->heightForWidth( w );
+
+ if ( hfw > wid->maximumHeight() )
+ hfw = wid->maximumHeight();
+ if ( hfw < wid->minimumHeight() )
+ hfw = wid->minimumHeight();
+ if ( hfw < 1 )
+ hfw = 1;
+ return hfw;
+}
+
+#ifdef USE_QT4
+
+/*!
+ Returns the direction in which this spacer item will expand.
+
+ \sa TQ_SPExpandData
+*/
+TQ_SPExpandData TQSpacerItem::expandingDirections() const
+{
+ return QSpacerItem::expandingDirections();
+}
+
+#else // USE_QT4
+
+/*!
+ Returns the direction in which this spacer item will expand.
+
+ \sa TQ_SPExpandData
+*/
+TQ_SPExpandData TQSpacerItem::expandingDirections() const
+{
+ return sizeP.expandingDirections();
+}
+
+#endif
+
+/*!
+ Returns whether this item's widget can make use of more space than
+ tqsizeHint(). A value of \c Vertical or \c Horizontal means that it wants
+ to grow in only one dimension, whereas \c BothDirections means that
+ it wants to grow in both dimensions and \c NoDirection means that
+ it doesn't want to grow at all.
+*/
+TQ_SPExpandData TQWidgetItem::expandingDirections() const
+{
+ if ( isEmpty() )
+ return (TQ_SPExpandData)TQSizePolicy::NoDirection;
+
+ int e = TQT_TQSIZEPOLICY_OBJECT(wid->sizePolicy()).expandingDirections();
+ /*
+ If the tqlayout is expanding, we make the widget expanding, even if
+ its own size policy isn't expanding. This behavior should be
+ reconsidered in TQt 4.0. (###)
+ */
+#ifdef USE_QT4
+ if ( wid->layout() ) {
+ if ( TQT_TQSIZEPOLICY_OBJECT(wid->sizePolicy()).mayGrowHorizontally()
+ && (wid->layout()->expandingDirections() & TQSizePolicy::Horizontally) )
+ e |= TQSizePolicy::Horizontally;
+ if ( TQT_TQSIZEPOLICY_OBJECT(wid->sizePolicy()).mayGrowVertically()
+ && (wid->layout()->expandingDirections() & TQSizePolicy::Vertically) )
+ e |= TQSizePolicy::Vertically;
+ }
+#else // USE_QT4
+ if ( wid->tqlayout() ) {
+ if ( TQT_TQSIZEPOLICY_OBJECT(wid->sizePolicy()).mayGrowHorizontally()
+ && (wid->tqlayout()->expandingDirections() & TQSizePolicy::Horizontally) )
+ e |= TQSizePolicy::Horizontally;
+ if ( TQT_TQSIZEPOLICY_OBJECT(wid->sizePolicy()).mayGrowVertically()
+ && (wid->tqlayout()->expandingDirections() & TQSizePolicy::Vertically) )
+ e |= TQSizePolicy::Vertically;
+ }
+#endif // USE_QT4
+
+ if ( align & TQt::AlignHorizontal_Mask )
+ e &= ~TQSizePolicy::Horizontally;
+ if ( align & TQt::AlignVertical_Mask)
+ e &= ~TQSizePolicy::Vertically;
+
+// [FIXME]
+// For some reason, the above (commented out) code causes a weird crash that currupts the stack or heap, making debugging extremely difficult
+// printf("[WARNING] TQ_SPExpandData TQWidgetItem::expandingDirections() const partially implemented\n\r");
+
+ return (TQ_SPExpandData)e;
+}
+
+#ifdef USE_QT4
+
+/*!
+ Returns the minimum size of this spacer item.
+*/
+TQSize TQSpacerItem::tqminimumSize() const
+{
+
+ return QSpacerItem::minimumSize();
+}
+
+#else // USE_QT4
+
+/*!
+ Returns the minimum size of this spacer item.
+*/
+TQSize TQSpacerItem::tqminimumSize() const
+{
+ return TQSize( sizeP.mayShrinkHorizontally() ? 0 : width,
+ sizeP.mayShrinkVertically() ? 0 : height );
+}
+
+#endif // USE_QT4
+
+/*!
+ Returns the minimum size of this item.
+*/
+TQSize TQWidgetItem::tqminimumSize() const
+{
+ if ( isEmpty() )
+ return TQSize( 0, 0 );
+ return tqSmartMinSize( this );
+}
+
+#ifdef USE_QT4
+
+/*!
+ Returns the maximum size of this spacer item.
+*/
+TQSize TQSpacerItem::tqmaximumSize() const
+{
+ return QSpacerItem::maximumSize();
+}
+
+#else // USE_QT4
+
+/*!
+ Returns the maximum size of this spacer item.
+*/
+TQSize TQSpacerItem::tqmaximumSize() const
+{
+ return TQSize( sizeP.mayGrowHorizontally() ? TQLAYOUTSIZE_MAX : width,
+ sizeP.mayGrowVertically() ? TQLAYOUTSIZE_MAX : height );
+}
+
+#endif // USE_QT4
+
+/*!
+ Returns the maximum size of this item.
+*/
+TQSize TQWidgetItem::tqmaximumSize() const
+{
+ if ( isEmpty() ) {
+ return TQSize( 0, 0 );
+ } else {
+ return tqSmartMaxSize( this, align );
+ }
+}
+
+#ifdef USE_QT4
+
+/*!
+ Returns the preferred size of this spacer item.
+*/
+TQSize TQSpacerItem::tqsizeHint() const
+{
+ return QSpacerItem::sizeHint();
+}
+
+
+#else // USE_QT4
+
+/*!
+ Returns the preferred size of this spacer item.
+*/
+TQSize TQSpacerItem::tqsizeHint() const
+{
+ return TQSize( width, height );
+}
+
+#endif
+
+/*!
+ Returns the preferred size of this item.
+*/
+TQSize TQWidgetItem::tqsizeHint() const
+{
+ TQSize s;
+ if ( isEmpty() ) {
+ s = TQSize( 0, 0 );
+ } else {
+ s = wid->tqsizeHint();
+ if ( TQT_TQSIZEPOLICY_OBJECT(wid->sizePolicy()).horData() == TQSizePolicy::Ignored )
+ s.setWidth( 1 );
+ if ( TQT_TQSIZEPOLICY_OBJECT(wid->sizePolicy()).verData() == TQSizePolicy::Ignored )
+ s.setHeight( 1 );
+ s = s.boundedTo( wid->tqmaximumSize() )
+ .expandedTo( wid->tqminimumSize() ).expandedTo( TQSize(1, 1) );
+ }
+ return s;
+}
+
+/*!
+ Returns TRUE because a spacer item never tqcontains widgets.
+*/
+bool TQSpacerItem::isEmpty() const
+{
+ return TRUE;
+}
+
+/*!
+ Returns TRUE if the widget has been hidden; otherwise returns
+ FALSE.
+*/
+bool TQWidgetItem::isEmpty() const
+{
+ return wid->isHidden() || wid->isTopLevel();
+}
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ \class TQLayout
+ \brief The TQLayout class is the base class of tqgeometry managers.
+
+ \ingroup appearance
+ \ingroup geomanagement
+
+ This is an abstract base class inherited by the concrete classes,
+ TQBoxLayout and TQGridLayout.
+
+ For users of TQLayout subclasses or of TQMainWindow there is seldom
+ any need to use the basic functions provided by TQLayout, such as
+ \l setResizeMode() or setMenuBar(). See the \link tqlayout.html tqlayout
+ overview page \endlink for more information.
+
+ To make your own tqlayout manager, subclass TQGLayoutIterator and
+ implement the functions addItem(), tqsizeHint(), setGeometry(), and
+ iterator(). You should also implement tqminimumSize() to ensure your
+ tqlayout isn't resized to zero size if there is too little space. To
+ support tqchildren whose heights depend on their widths, implement
+ hasHeightForWidth() and heightForWidth(). See the \link
+ customtqlayout.html custom tqlayout page \endlink for an in-depth
+ description.
+
+ Geometry management stops when the tqlayout manager is deleted.
+*/
+
+/*!
+ Constructs a new top-level TQLayout called \a name, with main
+ widget \a tqparent. \a tqparent may not be 0.
+
+ The \a margin is the number of pixels between the edge of the
+ widget and the managed tqchildren. The \a spacing sets the value of
+ spacing(), which gives the spacing between the managed widgets. If
+ \a spacing is -1 (the default), spacing is set to the value of \a
+ margin.
+
+ There can be only one top-level tqlayout for a widget. It is
+ returned by TQWidget::tqlayout()
+*/
+TQLayout::TQLayout( QWidget *tqparent, int margin, int spacing, const char *name )
+ : TQObject( tqparent, name )
+{
+ init();
+ if ( tqparent ) {
+ if ( tqparent->tqlayout() ) {
+ qWarning( "TQLayout \"%s\" added to %s \"%s\", which already has a"
+ " tqlayout", TQObject::name(), tqparent->className(),
+ tqparent->name() );
+ tqparent->removeChild( this );
+ } else {
+ topLevel = TRUE;
+ tqparent->installEventFilter( this );
+ setWidgetLayout( tqparent, this );
+ }
+ }
+ outsideBorder = margin;
+ if ( spacing < 0 )
+ insideSpacing = margin;
+ else
+ insideSpacing = spacing;
+}
+
+void TQLayout::init()
+{
+ insideSpacing = 0;
+ outsideBorder = 0;
+ topLevel = FALSE;
+ enabled = TRUE;
+ autoNewChild = FALSE;
+ frozen = FALSE;
+ activated = FALSE;
+ marginImpl = FALSE;
+ autoMinimum = FALSE;
+ autoResizeMode = TRUE;
+ extraData = 0;
+#ifndef TQT_NO_MENUBAR
+ menubar = 0;
+#endif
+}
+
+/*!
+ Constructs a new child TQLayout called \a name, and places it
+ inside \a parentLayout by using the default placement defined by
+ addItem().
+
+ If \a spacing is -1, this TQLayout inherits \a parentLayout's
+ spacing(), otherwise the value of \a spacing is used.
+*/
+TQLayout::TQLayout( QLayout *parentLayout, int spacing, const char *name )
+ : TQObject( parentLayout, name )
+
+{
+ init();
+ insideSpacing = spacing < 0 ? parentLayout->insideSpacing : spacing;
+ parentLayout->addItem( this );
+}
+
+/*!
+ Constructs a new child TQLayout called \a name. If \a spacing is
+ -1, this TQLayout inherits its tqparent's spacing(); otherwise the
+ value of \a spacing is used.
+
+ This tqlayout has to be inserted into another tqlayout before tqgeometry
+ management will work.
+*/
+TQLayout::TQLayout( int spacing, const char *name )
+ : TQObject( 0, name )
+{
+ init();
+ insideSpacing = spacing;
+}
+
+/*!
+ \fn void TQLayout::addItem( TQLayoutItem *item )
+
+ Implemented in subclasses to add an \a item. How it is added is
+ specific to each subclass.
+
+ The ownership of \a item is transferred to the tqlayout, and it's
+ the tqlayout's responsibility to delete it.
+*/
+
+/*!
+ \fn TQLayoutIterator TQLayout::iterator()
+
+ Implemented in subclasses to return an iterator that iterates over
+ this tqlayout's tqchildren.
+
+ A typical implementation will be:
+ \code
+ TQLayoutIterator MyLayout::iterator()
+ {
+ TQGLayoutIterator *i = new MyLayoutIterator( internal_data );
+ return TQLayoutIterator( i );
+ }
+ \endcode
+ where MyLayoutIterator is a subclass of TQGLayoutIterator.
+*/
+
+/*!
+ \fn void TQLayout::add( TQWidget *w )
+
+ Adds widget \a w to this tqlayout in a manner specific to the
+ tqlayout. This function uses addItem().
+*/
+
+/*!
+ \fn TQMenuBar* TQLayout::menuBar () const
+
+ Returns the menu bar set for this tqlayout, or 0 if no menu bar is
+ set.
+*/
+
+/*!
+ \fn bool TQLayout::isTopLevel () const
+
+ Returns TRUE if this tqlayout is a top-level tqlayout, i.e. not a
+ child of another tqlayout; otherwise returns FALSE.
+*/
+
+/*!
+ \property TQLayout::margin
+ \brief the width of the outside border of the tqlayout
+
+ For some tqlayout classes this property has an effect only on
+ top-level layouts; TQBoxLayout and TQGridLayout support margins for
+ child layouts. The default value is 0.
+
+ \sa spacing
+*/
+
+/*!
+ \property TQLayout::spacing
+ \brief the spacing between widgets inside the tqlayout
+
+ The default value is -1, which signifies that the tqlayout's spacing
+ should not override the widget's spacing.
+
+ \sa margin
+*/
+void TQLayout::setMargin( int margin )
+{
+ outsideBorder = margin;
+ tqinvalidate();
+ if ( mainWidget() ) {
+ TQEvent *lh = new TQEvent( TQEvent::LayoutHint );
+ TQApplication::postEvent( mainWidget(), lh );
+ }
+}
+
+void TQLayout::setSpacing( int spacing )
+{
+ insideSpacing = spacing;
+ if ( spacing >= 0 )
+ propagateSpacing( this );
+ tqinvalidate();
+ if ( mainWidget() ) {
+ TQEvent *lh = new TQEvent( TQEvent::LayoutHint );
+ TQApplication::postEvent( mainWidget(), lh );
+ }
+}
+
+/*!
+ Returns the main widget (tqparent widget) of this tqlayout, or 0 if
+ this tqlayout is a sub-tqlayout that is not yet inserted.
+*/
+TQWidget *TQLayout::mainWidget()
+{
+ if ( !topLevel ) {
+ if ( tqparent() ) {
+ TQLayout *parentLayout = ::tqqt_cast<TQLayout*>(tqparent());
+ TQ_ASSERT(parentLayout);
+ return parentLayout->mainWidget();
+ } else {
+ return 0;
+ }
+ } else {
+ TQ_ASSERT(tqparent() && tqparent()->isWidgetType());
+ return (TQWidget*)tqparent();
+ }
+}
+
+/*!
+ Returns TRUE if this tqlayout is empty. The default implementation
+ returns FALSE.
+*/
+bool TQLayout::isEmpty() const
+{
+ return FALSE; //### should check
+}
+
+/*!
+ Sets widget \a w's tqlayout to tqlayout \a l.
+*/
+void TQLayout::setWidgetLayout( TQWidget *w, TQLayout *l )
+{
+ w->setLayout( l );
+}
+
+/*!
+ This function is reimplemented in subclasses to perform tqlayout.
+
+ The default implementation maintains the tqgeometry() information
+ given by rect \a r. Reimplementors must call this function.
+*/
+void TQLayout::setGeometry( const TQRect &r )
+{
+ rect = r;
+}
+
+/*!
+ Invalidates cached information. Reimplementations must call this.
+*/
+void TQLayout::tqinvalidate()
+{
+ rect = TQRect();
+}
+
+static bool removeWidgetRecursively( TQLayoutItem *lay, TQWidget *w )
+{
+ bool didSomething = FALSE;
+ TQLayoutIterator it = lay->iterator();
+ TQLayoutItem *child;
+ while ( (child = it.current()) != 0 ) {
+ if ( child->widget() == w ) {
+ it.deleteCurrent();
+ lay->tqinvalidate(); // maybe redundant
+ didSomething = TRUE;
+ } else if ( removeWidgetRecursively(child, w) ) {
+ lay->tqinvalidate(); // maybe redundant
+ didSomething = TRUE;
+ } else {
+ ++it;
+ }
+ }
+ return didSomething;
+}
+
+/*!
+ \reimp
+ Performs child widget tqlayout when the tqparent widget is resized.
+ Also handles removal of widgets and child layouts. \a e is the
+ event the occurred on object \a o.
+*/
+bool TQLayout::eventFilter( TQObject *o, TQEvent *e )
+{
+ if ( !enabled )
+ return FALSE;
+
+ if ( !o->isWidgetType() )
+ return FALSE;
+
+ switch ( e->type() ) {
+ case TQEvent::Resize:
+ if ( activated ) {
+ TQResizeEvent *r = (TQResizeEvent *)e;
+ int mbh = 0;
+#ifndef TQT_NO_MENUBAR
+ mbh = menuBarHeightForWidth( menubar, r->size().width() );
+#endif
+ int b = marginImpl ? 0 : outsideBorder;
+ setGeometry( TQRect( b, mbh + b, r->size().width() - 2 * b,
+ r->size().height() - mbh - 2 * b ) );
+ } else {
+ activate();
+ }
+ break;
+ case TQEvent::ChildRemoved:
+ {
+ TQChildEvent *c = (TQChildEvent *)e;
+ if ( c->child()->isWidgetType() ) {
+ TQWidget *w = (TQWidget *)c->child();
+#ifndef TQT_NO_MENUBAR
+ if ( w == menubar )
+ menubar = 0;
+#endif
+ if ( removeWidgetRecursively( this, w ) ) {
+ TQEvent *lh = new TQEvent( TQEvent::LayoutHint );
+ TQApplication::postEvent( o, lh );
+ }
+ }
+ }
+ break;
+ case TQEvent::ChildInserted:
+ if ( topLevel && autoNewChild ) {
+ TQChildEvent *c = (TQChildEvent *)e;
+ if ( c->child()->isWidgetType() ) {
+ TQWidget *w = (TQWidget *)c->child();
+ if ( !w->isTopLevel() ) {
+#if !defined(TQT_NO_MENUBAR) && !defined(TQT_NO_TOOLBAR)
+ if ( ::tqqt_cast<TQMenuBar*>(w) && !::tqqt_cast<TQToolBar*>(w->parentWidget()) )
+ menubar = (TQMenuBar *)w;
+ else
+#endif
+ addItem( new TQWidgetItem( w ) );
+ TQEvent *lh = new TQEvent( TQEvent::LayoutHint );
+ TQApplication::postEvent( o, lh );
+ }
+ }
+ }
+ break;
+ case TQEvent::LayoutHint:
+ activate();
+ break;
+ default:
+ break;
+ }
+ return TQObject::eventFilter( o, e );
+}
+
+/*!
+ \reimp
+*/
+void TQLayout::childEvent( TQChildEvent *e )
+{
+ if ( !enabled )
+ return;
+
+ if ( e->type() == TQEvent::ChildRemoved ) {
+ TQChildEvent *c = (TQChildEvent*)e;
+ TQLayoutIterator it = iterator();
+ TQLayoutItem *item;
+ while ( (item = it.current() ) ) {
+ if ( item == (TQLayout*)c->child() ) {
+ it.takeCurrent();
+ tqinvalidate();
+ break;
+ } else {
+ ++it;
+ }
+ }
+ }
+}
+
+/*!
+ \internal
+ Also takes margin() and menu bar into account.
+*/
+int TQLayout::totalHeightForWidth( int w ) const
+{
+ if ( topLevel ) {
+ TQWidget *mw = (TQWidget*)tqparent();
+ if ( mw && !mw->testWState(WState_Polished) ) {
+ mw->polish();
+ }
+ }
+ int b = ( topLevel && !marginImpl ) ? 2 * outsideBorder : 0;
+ int h = heightForWidth( w - b ) + b;
+#ifndef TQT_NO_MENUBAR
+ h += menuBarHeightForWidth( menubar, w );
+#endif
+ return h;
+}
+
+/*!
+ \internal
+ Also takes margin() and menu bar into account.
+*/
+TQSize TQLayout::totalMinimumSize() const
+{
+ if ( topLevel ) {
+ TQWidget *mw = (TQWidget*)tqparent();
+ if ( mw && !mw->testWState(WState_Polished) )
+ mw->polish();
+ }
+ int b = ( topLevel && !marginImpl ) ? 2 * outsideBorder : 0;
+
+ TQSize s = tqminimumSize();
+ int h = b;
+#ifndef TQT_NO_MENUBAR
+ h += menuBarHeightForWidth( menubar, s.width() );
+#endif
+ return s + TQSize( b, h );
+}
+
+/*!
+ \internal
+ Also takes margin() and menu bar into account.
+*/
+TQSize TQLayout::totalSizeHint() const
+{
+ if ( topLevel ) {
+ TQWidget *mw = (TQWidget*)tqparent();
+ if ( mw && !mw->testWState(WState_Polished) )
+ mw->polish();
+ }
+ int b = ( topLevel && !marginImpl ) ? 2 * outsideBorder : 0;
+
+ TQSize s = tqsizeHint();
+ if ( hasHeightForWidth() )
+ s.setHeight( heightForWidth(s.width()) );
+ int h = b;
+#ifndef TQT_NO_MENUBAR
+ h += menuBarHeightForWidth( menubar, s.width() );
+#endif
+ return s + TQSize( b, h );
+}
+
+/*!
+ \internal
+ Also takes margin() and menu bar into account.
+*/
+TQSize TQLayout::totalMaximumSize() const
+{
+ if ( topLevel ) {
+ TQWidget *mw = (TQWidget*)tqparent();
+ if ( mw && !mw->testWState(WState_Polished) ) {
+ mw->polish();
+ }
+ }
+ int b = ( topLevel && !marginImpl ) ? 2 * outsideBorder : 0;
+
+ TQSize s = tqmaximumSize();
+ int h = b;
+#ifndef TQT_NO_MENUBAR
+ h += menuBarHeightForWidth( menubar, s.width() );
+#endif
+
+ if ( isTopLevel() )
+ s = TQSize( TQMIN( s.width() + b, TQLAYOUTSIZE_MAX ),
+ TQMIN( s.height() + h, TQLAYOUTSIZE_MAX ) );
+ return s;
+}
+
+/*!
+ \internal
+ Destroys the tqlayout, deleting all child layouts.
+ Geometry management stops when a top-level tqlayout is deleted.
+
+ The tqlayout classes will probably be fatally confused if you delete
+ a subtqlayout.
+*/
+TQLayout::~TQLayout()
+{
+ /*
+ This function may be called during the TQObject destructor,
+ when the tqparent no longer is a TQWidget.
+ */
+ if ( isTopLevel() && tqparent() && tqparent()->isWidgetType() &&
+ ((TQWidget*)tqparent())->tqlayout() == this )
+ setWidgetLayout( (TQWidget*)tqparent(), 0 );
+}
+
+/*!
+ Removes and deletes all items in this tqlayout.
+*/
+void TQLayout::deleteAllItems()
+{
+ TQLayoutIterator it = iterator();
+ TQLayoutItem *l;
+ while ( (l = it.takeCurrent()) )
+ delete l;
+}
+
+/*!
+ This function is called from addLayout() functions in subclasses
+ to add tqlayout \a l as a sub-tqlayout.
+*/
+void TQLayout::addChildLayout( TQLayout *l )
+{
+ if ( l->tqparent() ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQLayout::addChildLayout: tqlayout already has a tqparent" );
+#endif
+ return;
+ }
+ insertChild( l );
+ if ( l->insideSpacing < 0 ) {
+ l->insideSpacing = insideSpacing;
+ propagateSpacing( l );
+ }
+}
+
+/*! \fn int TQLayout::defaultBorder() const
+
+ \internal
+*/
+
+/*! \fn void TQLayout::freeze()
+
+ \internal
+*/
+
+/*!
+ \internal
+ Fixes the size of the main widget and distributes the available
+ space to the child widgets. For widgets which should not be
+ resizable, but where a TQLayout subclass is used to set up the initial
+ tqgeometry.
+
+ As a special case, freeze(0, 0) is equivalent to setResizeMode(Fixed).
+*/
+void TQLayout::freeze( int w, int h )
+{
+ if ( w <= 0 || h <= 0 ) {
+ setResizeMode( Fixed );
+ } else {
+ setResizeMode( FreeResize ); // tqlayout will not change min/max size
+ mainWidget()->setFixedSize( w, h );
+ }
+}
+
+#ifndef TQT_NO_MENUBAR
+
+/*!
+ Makes the tqgeometry manager take account of the menu bar \a w. All
+ child widgets are placed below the bottom edge of the menu bar.
+
+ A menu bar does its own tqgeometry management: never do addWidget()
+ on a TQMenuBar.
+*/
+void TQLayout::setMenuBar( TQMenuBar *w )
+{
+ menubar = w;
+}
+
+#endif
+
+/*!
+ Returns the minimum size of this tqlayout. This is the smallest size
+ that the tqlayout can have while still respecting the
+ specifications. Does not include what's needed by margin() or
+ menuBar().
+
+ The default implementation allows unlimited resizing.
+*/
+TQSize TQLayout::tqminimumSize() const
+{
+ return TQSize( 0, 0 );
+}
+
+/*!
+ Returns the maximum size of this tqlayout. This is the largest size
+ that the tqlayout can have while still respecting the
+ specifications. Does not include what's needed by margin() or
+ menuBar().
+
+ The default implementation allows unlimited resizing.
+*/
+TQSize TQLayout::tqmaximumSize() const
+{
+ return TQSize( TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX );
+}
+
+/*!
+ Returns whether this tqlayout can make use of more space than
+ tqsizeHint(). A value of \c Vertical or \c Horizontal means that it wants
+ to grow in only one dimension, whereas \c BothDirections means that
+ it wants to grow in both dimensions.
+
+ The default implementation returns \c BothDirections.
+*/
+TQ_SPExpandData TQLayout::expandingDirections() const
+{
+ return TQSizePolicy::BothDirections;
+}
+
+static void invalidateRecursive( TQLayoutItem *lay )
+{
+ lay->tqinvalidate();
+ TQLayoutIterator it = lay->iterator();
+ TQLayoutItem *child;
+ while ( (child = it.current()) != 0 ) {
+ invalidateRecursive( child );
+ ++it;
+ }
+}
+
+/*!
+ Redoes the tqlayout for mainWidget(). You should generally not need
+ to call this because it is automatically called at the most
+ appropriate times.
+
+ However, if you set up a TQLayout for a visible widget without
+ resizing that widget, you will need to call this function in order
+ to lay it out.
+
+ \sa TQWidget::updateGeometry()
+*/
+bool TQLayout::activate()
+{
+ invalidateRecursive( this );
+ if ( !topLevel )
+ return FALSE;
+
+ TQWidget *mw = mainWidget();
+ if (!mw) {
+#if defined( TQT_CHECK_NULL )
+ qWarning( "TQLayout::activate: %s \"%s\" does not have a main widget",
+ TQObject::className(), TQObject::name() );
+#endif
+ return FALSE;
+ }
+ activated = TRUE;
+ TQSize s = mw->size();
+ TQSize ms;
+ int mbh = 0;
+#ifndef TQT_NO_MENUBAR
+ mbh = menuBarHeightForWidth( menubar, s.width() );
+#endif
+ int b = marginImpl ? 0 : outsideBorder;
+ setGeometry(TQRect(b, mbh + b, s.width() - 2 * b, s.height() - mbh - 2 * b));
+ if ( frozen ) {
+ // will trigger resize
+ mw->setFixedSize( totalSizeHint() );
+ } else if ( autoMinimum ) {
+ ms = totalMinimumSize();
+ } else if ( autoResizeMode && topLevel && mw->isTopLevel() ) {
+ ms = totalMinimumSize();
+ if ( hasHeightForWidth() ) {
+ int h;
+ int mmbh = menuBarHeightForWidth( menubar, ms.width() );
+ // ### 4.0: remove this 'if' when minimumHeightForWidth() is virtual
+ if ( inherits("TQBoxLayout") )
+ h = ((TQBoxLayout *) this)->minimumHeightForWidth( ms.width() );
+ else if ( inherits("TQGridLayout") )
+ h = ((TQGridLayout *) this)->minimumHeightForWidth( ms.width() );
+ else
+ h = heightForWidth( ms.width() );
+ if ( h + mmbh > ms.height() )
+#if 1
+ //old behaviour:
+ ms = TQSize( 0, 0 );
+#else
+ //better, but too big a change for a patch release in a stable branch:
+ ms.setHeight( 0 );
+#endif
+ }
+ }
+
+ if (ms.isValid())
+ mw->setMinimumSize( ms );
+
+ // ideally only if tqsizeHint() or sizePolicy() has changed
+ mw->updateGeometry();
+ return TRUE;
+}
+
+#endif // USE_QT4
+
+/*!
+ \class TQSizePolicy
+ \brief The TQSizePolicy class is a tqlayout attribute describing horizontal
+ and vertical resizing policy.
+
+ \ingroup appearance
+ \ingroup geomanagement
+
+ The size policy of a widget is an expression of its willingness to
+ be resized in various ways.
+
+ Widgets that reimplement TQWidget::sizePolicy() return a TQSizePolicy
+ that describes the horizontal and vertical resizing policy they
+ prefer when being laid out. Only \link #interesting one of the
+ constructors\endlink is of interest in most applications.
+
+ TQSizePolicy tqcontains two independent SizeType objects; one describes
+ the widgets's horizontal size policy, and the other describes its
+ vertical size policy. It also tqcontains a flag to indicate whether the
+ height and width of its preferred size are related.
+
+ The horizontal and vertical \l{SizeType}s are set in the usual constructor
+ and can be queried using a variety of functions.
+
+ The hasHeightForWidth() flag indicates whether the widget's tqsizeHint()
+ is width-dependent (such as a word-wrapping label) or not.
+
+ \sa TQSizePolicy::SizeType
+*/
+
+/*!
+ \enum TQSizePolicy::SizeType
+
+ The per-dimension sizing types used when constructing a
+ TQSizePolicy are:
+
+ \value Fixed The TQWidget::tqsizeHint() is the only acceptable
+ alternative, so the widget can never grow or shrink (e.g. the
+ vertical direction of a push button).
+
+ \value Minimum The tqsizeHint() is minimal, and sufficient. The
+ widget can be expanded, but there is no advantage to it being
+ larger (e.g. the horizontal direction of a push button).
+ It cannot be smaller than the size provided by tqsizeHint().
+
+ \value Maximum The tqsizeHint() is a maximum. The widget can be
+ shrunk any amount without detriment if other widgets need the
+ space (e.g. a separator line).
+ It cannot be larger than the size provided by tqsizeHint().
+
+ \value Preferred The tqsizeHint() is best, but the widget can be
+ shrunk and still be useful. The widget can be expanded, but there
+ is no advantage to it being larger than tqsizeHint() (the default
+ TQWidget policy).
+
+ \value Expanding The tqsizeHint() is a sensible size, but the
+ widget can be shrunk and still be useful. The widget can make use
+ of extra space, so it should get as much space as possible (e.g.
+ the horizontal direction of a slider).
+
+ \value MinimumExpanding The tqsizeHint() is minimal, and sufficient.
+ The widget can make use of extra space, so it should get as much
+ space as possible (e.g. the horizontal direction of a slider).
+
+ \value Ignored the tqsizeHint() is ignored. The widget will get as
+ much space as possible.
+*/
+
+/*!
+ \enum TQ_SPExpandData
+
+ This enum type describes in which directions a widget can make use
+ of extra space. There are four possible values:
+
+ \value NoDirection the widget cannot make use of extra space in
+ any direction.
+
+ \value Horizontally the widget can usefully be wider than the
+ tqsizeHint().
+
+ \value Vertically the widget can usefully be taller than the
+ tqsizeHint().
+
+ \value BothDirections the widget can usefully be both wider and
+ taller than the tqsizeHint().
+*/
+
+/*!
+ \fn TQSizePolicy::TQSizePolicy()
+
+ Constructs a minimally initialized TQSizePolicy.
+*/
+
+/*!
+ \fn TQSizePolicy::TQSizePolicy( SizeType hor, SizeType ver, bool hfw )
+
+ \target interesting
+ This is the constructor normally used to return a value in the
+ overridden \l TQWidget::sizePolicy() function of a TQWidget
+ subclass.
+
+ It constructs a TQSizePolicy with independent horizontal and
+ vertical sizing types, \a hor and \a ver respectively. These \link
+ TQSizePolicy::SizeType sizing types\endlink affect how the widget
+ is treated by the \link TQLayout tqlayout engine\endlink.
+
+ If \a hfw is TRUE, the preferred height of the widget is dependent
+ on the width of the widget (for example, a TQLabel with line
+ wrapping).
+
+ \sa horData() verData() hasHeightForWidth()
+*/
+
+/*!
+ \fn TQSizePolicy::TQSizePolicy( SizeType hor, SizeType ver, uchar horStretch, uchar verStretch, bool hfw )
+
+ Constructs a TQSizePolicy with independent horizontal and vertical
+ sizing types \a hor and \a ver, and stretch factors \a horStretch
+ and \a verStretch.
+
+ If \a hfw is TRUE, the preferred height of the widget is dependent on the
+ width of the widget.
+
+ \sa horStretch() verStretch()
+*/
+
+/*!
+ \fn TQSizePolicy::SizeType TQSizePolicy::horData() const
+
+ Returns the horizontal component of the size policy.
+
+ \sa setHorData() verData() horStretch()
+*/
+
+/*!
+ \fn TQSizePolicy::SizeType TQSizePolicy::verData() const
+
+ Returns the vertical component of the size policy.
+
+ \sa setVerData() horData() verStretch()
+*/
+
+/*!
+ \fn bool TQSizePolicy::mayShrinkHorizontally() const
+
+ Returns TRUE if the widget can sensibly be narrower than its
+ tqsizeHint(); otherwise returns FALSE.
+
+ \sa mayShrinkVertically() mayGrowHorizontally()
+*/
+
+/*!
+ \fn bool TQSizePolicy::mayShrinkVertically() const
+
+ Returns TRUE if the widget can sensibly be shorter than its
+ tqsizeHint(); otherwise returns FALSE.
+
+ \sa mayShrinkHorizontally() mayGrowVertically()
+*/
+
+/*!
+ \fn bool TQSizePolicy::mayGrowHorizontally() const
+
+ Returns TRUE if the widget can sensibly be wider than its
+ tqsizeHint(); otherwise returns FALSE.
+
+ \sa mayGrowVertically() mayShrinkHorizontally()
+*/
+
+/*!
+ \fn bool TQSizePolicy::mayGrowVertically() const
+
+ Returns TRUE if the widget can sensibly be taller than its
+ tqsizeHint(); otherwise returns FALSE.
+
+ \sa mayGrowHorizontally() mayShrinkVertically()
+*/
+
+/*!
+ \fn TQ_SPExpandData TQSizePolicy::expandingDirections() const
+
+ Returns whether this tqlayout can make use of more space than
+ tqsizeHint(). A value of \c Vertical or \c Horizontal means that it wants
+ to grow in only one dimension, whereas \c BothDirections means that
+ it wants to grow in both dimensions.
+
+ \sa mayShrinkHorizontally() mayGrowHorizontally()
+ mayShrinkVertically() mayGrowVertically()
+*/
+
+/*!
+ \fn void TQSizePolicy::setHorData( SizeType d )
+
+ Sets the horizontal component of the size policy to size type \a
+ d.
+
+ \sa horData() setVerData()
+*/
+
+/*!
+ \fn void TQSizePolicy::setVerData( SizeType d )
+
+ Sets the vertical component of the size policy to size type \a d.
+
+ \sa verData() setHorData()
+*/
+
+/*!
+ \fn bool TQSizePolicy::hasHeightForWidth() const
+
+ Returns TRUE if the widget's preferred height depends on its
+ width; otherwise returns FALSE.
+
+ \sa setHeightForWidth()
+*/
+
+/*!
+ \fn void TQSizePolicy::setHeightForWidth( bool b )
+
+ Sets the hasHeightForWidth() flag to \a b.
+
+ \sa hasHeightForWidth()
+*/
+
+/*!
+ \fn uint TQSizePolicy::horStretch() const
+
+ Returns the horizontal stretch factor of the size policy.
+
+ \sa setHorStretch() verStretch()
+*/
+
+/*!
+ \fn uint TQSizePolicy::verStretch() const
+
+ Returns the vertical stretch factor of the size policy.
+
+ \sa setVerStretch() horStretch()
+*/
+
+/*!
+ \fn void TQSizePolicy::setHorStretch( uchar sf )
+
+ Sets the horizontal stretch factor of the size policy to \a sf.
+
+ \sa horStretch() setVerStretch()
+*/
+
+/*!
+ \fn void TQSizePolicy::setVerStretch( uchar sf )
+
+ Sets the vertical stretch factor of the size policy to \a sf.
+
+ \sa verStretch() setHorStretch()
+*/
+
+/*!
+ \fn void TQSizePolicy::transpose()
+
+ Swaps the horizontal and vertical policies and stretches.
+*/
+
+
+/*!
+ \fn bool TQSizePolicy::operator==( const TQSizePolicy &s ) const
+
+ Returns TRUE if this policy is equal to \a s; otherwise returns
+ FALSE.
+
+ \sa operator!=()
+*/
+
+/*!
+ \fn bool TQSizePolicy::operator!=( const TQSizePolicy &s ) const
+
+ Returns TRUE if this policy is different from \a s; otherwise
+ returns FALSE.
+
+ \sa operator==()
+*/
+
+/*!
+ \class TQGLayoutIterator
+ \brief The TQGLayoutIterator class is an abstract base class of internal tqlayout iterators.
+
+ \ingroup appearance
+ \ingroup geomanagement
+
+ (This class is \e not OpenGL related, it just happens to start with
+ the letters TQGL...)
+
+ Subclass this class to create a custom tqlayout. The functions that
+ must be implemented are next(), current(), and takeCurrent().
+
+ The TQGLayoutIterator implements the functionality of
+ TQLayoutIterator. Each subclass of TQLayout needs a
+ TQGLayoutIterator subclass.
+*/
+
+/*!
+ \fn TQLayoutItem *TQGLayoutIterator::next()
+
+ Implemented in subclasses to move the iterator to the next item
+ and return that item, or 0 if there is no next item.
+*/
+
+/*!
+ \fn TQLayoutItem *TQGLayoutIterator::current()
+
+ Implemented in subclasses to return the current item, or 0 if
+ there is no current item.
+*/
+
+/*!
+ \fn TQLayoutItem *TQGLayoutIterator::takeCurrent()
+
+ Implemented in subclasses. The function must remove the current
+ item from the tqlayout without deleting it, move the iterator to the
+ next item and return the removed item, or 0 if no item was
+ removed.
+*/
+
+/*!
+ Destroys the iterator
+*/
+TQGLayoutIterator::~TQGLayoutIterator()
+{
+}
+
+/*!
+ \class TQLayoutIterator
+ \brief The TQLayoutIterator class provides iterators over TQLayoutItem.
+
+ \ingroup appearance
+ \ingroup geomanagement
+
+ Use TQLayoutItem::iterator() to create an iterator over a tqlayout.
+
+ TQLayoutIterator uses \e explicit sharing with a reference count.
+ If an iterator is copied and one of the copies is modified, both
+ iterators will be modified.
+
+ A TQLayoutIterator is not protected against changes in its tqlayout. If
+ the tqlayout is modified or deleted the iterator will become invalid.
+ It is not possible to test for validity. It is safe to delete an
+ invalid tqlayout; any other access may lead to an illegal memory
+ reference and the abnormal termination of the program.
+
+ Calling takeCurrent() or deleteCurrent() leaves the iterator in a
+ valid state, but may tqinvalidate any other iterators that access the
+ same tqlayout.
+
+ The following code will draw a rectangle for each tqlayout item in
+ the tqlayout structure of the widget.
+ \code
+ static void paintLayout( TQPainter *p, TQLayoutItem *lay )
+ {
+ TQLayoutIterator it = lay->iterator();
+ TQLayoutItem *child;
+ while ( (child = it.current()) != 0 ) {
+ paintLayout( p, child );
+ ++it;
+ }
+ p->drawRect( lay->tqgeometry() );
+ }
+ void ExampleWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p( this );
+ if ( tqlayout() )
+ paintLayout( &p, tqlayout() );
+ }
+ \endcode
+
+ All the functionality of TQLayoutIterator is implemented by
+ subclasses of \l TQGLayoutIterator. TQLayoutIterator itself is not
+ designed to be subclassed.
+*/
+
+/*!
+ \fn TQLayoutIterator::TQLayoutIterator( TQGLayoutIterator *gi )
+
+ Constructs an iterator based on \a gi. The constructed iterator
+ takes ownership of \a gi and will delete it.
+
+ This constructor is provided for tqlayout implementors. Application
+ programmers should use TQLayoutItem::iterator() to create an
+ iterator over a tqlayout.
+*/
+
+/*!
+ \fn TQLayoutIterator::TQLayoutIterator( const TQLayoutIterator &i )
+
+ Creates a shallow copy of \a i, i.e. if the copy is modified, then
+ the original will also be modified.
+*/
+
+/*!
+ \fn TQLayoutIterator::~TQLayoutIterator()
+
+ Destroys the iterator.
+*/
+
+/*!
+ \fn TQLayoutIterator &TQLayoutIterator::operator=( const TQLayoutIterator &i )
+
+ Assigns \a i to this iterator and returns a reference to this
+ iterator.
+*/
+
+/*!
+ \fn TQLayoutItem *TQLayoutIterator::operator++()
+
+ Moves the iterator to the next child item and returns that item,
+ or 0 if there is no such item.
+*/
+
+/*!
+ \fn TQLayoutItem *TQLayoutIterator::current()
+
+ Returns the current item, or 0 if there is no current item.
+*/
+
+/*!
+ \fn TQLayoutItem *TQLayoutIterator::takeCurrent()
+
+ Removes the current child item from the tqlayout without deleting
+ it, and moves the iterator to the next item. Returns the removed
+ item, or 0 if there was no item to be removed. This iterator will
+ still be valid, but any other iterator over the same tqlayout may
+ become invalid.
+*/
+
+/*!
+ \fn void TQLayoutIterator::deleteCurrent()
+
+ Removes and deletes the current child item from the tqlayout and
+ moves the iterator to the next item. This iterator will still be
+ valid, but any other iterator over the same tqlayout may become
+ invalid.
+*/
+
+/*!
+ \enum TQLayout::ResizeMode
+
+ The possible values are:
+
+ \value Auto If the main widget is a top-level widget with no
+ height-for-width (hasHeightForWidth()), this is
+ the same as \c Minimium; otherwise, this is the
+ same as \c FreeResize.
+ \value Fixed The main widget's size is set to tqsizeHint(); it
+ cannot be resized at all.
+ \value Minimum The main widget's minimum size is set to
+ tqminimumSize(); it cannot be smaller.
+ \value FreeResize The widget is not constrained.
+*/
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ \property TQLayout::resizeMode
+ \brief the resize mode of the tqlayout
+
+ The default mode is \c Auto.
+
+ \sa TQLayout::ResizeMode
+*/
+
+void TQLayout::setResizeMode( ResizeMode mode )
+{
+ if ( mode == resizeMode() )
+ return;
+
+ switch ( mode ) {
+ case Auto:
+ frozen = FALSE;
+ autoMinimum = FALSE;
+ autoResizeMode = TRUE;
+ break;
+ case Fixed:
+ frozen = TRUE;
+ autoMinimum = FALSE;
+ autoResizeMode = FALSE;
+ break;
+ case FreeResize:
+ frozen = FALSE;
+ autoMinimum = FALSE;
+ autoResizeMode = FALSE;
+ break;
+ case Minimum:
+ frozen = FALSE;
+ autoMinimum = TRUE;
+ autoResizeMode = FALSE;
+ }
+ if ( mainWidget() && mainWidget()->isVisible() )
+ activate();
+}
+
+TQLayout::ResizeMode TQLayout::resizeMode() const
+{
+ return ( autoResizeMode ? Auto :
+ (frozen ? Fixed : (autoMinimum ? Minimum : FreeResize)) );
+}
+
+/*!
+ \fn bool TQLayout::autoAdd() const
+
+ Returns TRUE if this tqlayout automatically grabs all new
+ mainWidget()'s new tqchildren and adds them as defined by addItem();
+ otherwise returns FALSE. This has effect only for top-level
+ layouts, i.e. layouts that are direct tqchildren of their
+ mainWidget().
+
+ autoAdd() is disabled by default.
+
+ Note that a top-level tqlayout is not necessarily associated with
+ the top-level widget.
+
+ \sa setAutoAdd()
+*/
+
+/*!
+ If \a b is TRUE, auto-add is enabled; otherwise auto-add is
+ disabled.
+
+ \warning If auto-add is enabled, you cannot set stretch factors
+ on the child widgets until the widgets are actually inserted in
+ the tqlayout (after control returned to the event loop). We
+ therefore recommend that you avoid the auto-add feature in new
+ programs.
+
+ \sa autoAdd()
+*/
+void TQLayout::setAutoAdd( bool b )
+{
+ autoNewChild = b;
+}
+
+/*!
+ \fn bool TQLayout::supportsMargin() const
+
+ Returns TRUE if this tqlayout supports \l TQLayout::margin on
+ non-top-level layouts; otherwise returns FALSE.
+
+ \sa margin
+*/
+
+/*!
+ Sets the value returned by supportsMargin(). If \a b is TRUE,
+ margin() handling is implemented by the subclass. If \a b is
+ FALSE (the default), TQLayout will add margin() around top-level
+ layouts.
+
+ If \a b is TRUE, margin handling needs to be implemented in
+ setGeometry(), tqmaximumSize(), tqminimumSize(), tqsizeHint() and
+ heightForWidth().
+
+ \sa supportsMargin()
+*/
+void TQLayout::setSupportsMargin( bool b )
+{
+ marginImpl = b;
+}
+
+/*!
+ Returns the rectangle that should be covered when the tqgeometry of
+ this tqlayout is set to \a r, provided that this tqlayout supports
+ tqsetAlignment().
+
+ The result is derived from tqsizeHint() and expandingDirections(). It is never
+ larger than \a r.
+*/
+TQRect TQLayout::alignmentRect( const TQRect &r ) const
+{
+ TQSize s = tqsizeHint();
+ int a = tqalignment();
+
+ /*
+ This is a hack to obtain the real maximum size, not
+ TQSize(TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX), the value consistently
+ returned by TQLayoutItems that have an tqalignment.
+ */
+ TQLayout *that = (TQLayout *) this;
+ that->tqsetAlignment( 0 );
+ TQSize ms = tqmaximumSize();
+ that->tqsetAlignment( a );
+
+ if ( (expandingDirections() & TQSizePolicy::Horizontally) ||
+ !(a & TQt::AlignHorizontal_Mask ) ) {
+ s.setWidth( TQMIN(r.width(), ms.width()) );
+ }
+ if ( (expandingDirections() & TQSizePolicy::Vertically) ||
+ !(a & TQt::AlignVertical_Mask) ) {
+ s.setHeight( TQMIN(r.height(), ms.height()) );
+ } else if ( hasHeightForWidth() ) {
+ int hfw = heightForWidth( s.width() );
+ if ( hfw < s.height() )
+ s.setHeight( TQMIN(hfw, ms.height()) );
+ }
+
+ int x = r.x();
+ int y = r.y();
+
+ if ( a & TQt::AlignBottom )
+ y += ( r.height() - s.height() );
+ else if ( !(a & TQt::AlignTop) )
+ y += ( r.height() - s.height() ) / 2;
+
+ a = TQApplication::horizontalAlignment( a );
+ if ( a & TQt::AlignRight )
+ x += ( r.width() - s.width() );
+ else if ( !(a & TQt::AlignLeft) )
+ x += ( r.width() - s.width() ) / 2;
+
+ return TQRect( x, y, s.width(), s.height() );
+}
+
+/*!
+ Removes the widget \a widget from the tqlayout. After this call, it
+ is the caller's responsibility to give the widget a reasonable
+ tqgeometry or to put the widget back into a tqlayout.
+
+ \sa removeItem(), TQWidget::setGeometry(), add()
+*/
+void TQLayout::remove( TQWidget *widget )
+{
+ TQLayoutIterator it = iterator();
+ TQLayoutItem *child;
+ while ( (child = it.current()) != 0 ) {
+ if ( child->widget() == widget ) {
+ it.deleteCurrent();
+ tqinvalidate(); // maybe redundant
+ TQApplication::postEvent( mainWidget(),
+ new TQEvent(TQEvent::LayoutHint) );
+ } else {
+ ++it;
+ }
+ }
+}
+
+/*!
+ Removes the tqlayout item \a item from the tqlayout. It is the
+ caller's responsibility to delete the item.
+
+ Notice that \a item can be a tqlayout (since TQLayout inherits
+ TQLayoutItem).
+
+ \sa remove(), addItem()
+*/
+void TQLayout::removeItem( TQLayoutItem *item )
+{
+ TQLayoutIterator it = iterator();
+ TQLayoutItem *child;
+ while ( (child = it.current()) != 0 ) {
+ if ( child == item ) {
+ it.takeCurrent();
+ tqinvalidate(); // maybe redundant
+ TQApplication::postEvent( mainWidget(),
+ new TQEvent(TQEvent::LayoutHint) );
+ } else {
+ ++it;
+ }
+ }
+}
+
+/*!
+ Enables this tqlayout if \a enable is TRUE, otherwise disables it.
+
+ An enabled tqlayout adjusts dynamically to changes; a disabled
+ tqlayout acts as if it did not exist.
+
+ By default all layouts are enabled.
+
+ \sa isEnabled()
+*/
+void TQLayout::setEnabled( bool enable )
+{
+ enabled = enable;
+}
+
+/*!
+ Returns TRUE if the tqlayout is enabled; otherwise returns FALSE.
+
+ \sa setEnabled()
+*/
+bool TQLayout::isEnabled() const
+{
+ return enabled;
+}
+
+void TQLayout::propagateSpacing( TQLayout *tqparent )
+{
+ TQLayoutIterator it = tqparent->iterator();
+ TQLayoutItem *child;
+ while ( (child = it.current()) ) {
+ TQLayout *childLayout = child->tqlayout();
+ if ( childLayout && childLayout->insideSpacing < 0 ) {
+ childLayout->insideSpacing = tqparent->insideSpacing;
+ propagateSpacing( childLayout );
+ }
+ ++it;
+ }
+}
+
+#endif // USE_QT4
+
+#endif // TQT_NO_LAYOUT
diff --git a/tqtinterface/qt4/src/kernel/tqabstractlayout.h b/tqtinterface/qt4/src/kernel/tqabstractlayout.h
new file mode 100644
index 0000000..4ae84f6
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqabstractlayout.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Definition of tqlayout classes
+**
+** Created : 960416
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQABSTRACTLAYOUT_H
+#define TQABSTRACTLAYOUT_H
+
+/*
+ This header is provided for source compatibility only.
+*/
+
+#ifndef TQT_H
+#ifndef TQT_NO_COMPAT
+#include "tqlayout.h"
+#endif
+#endif // TQT_H
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqaccel.cpp b/tqtinterface/qt4/src/kernel/tqaccel.cpp
new file mode 100644
index 0000000..fd47345
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqaccel.cpp
@@ -0,0 +1,2098 @@
+#include "tqtglobaldefines.h"
+
+#if 0
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqaccel.h"
+
+#include "tqsignal.h"
+#include "Qt/qapplication.h"
+#include "Qt/qwidget.h"
+#include "tqptrlist.h"
+#include "Qt/qwhatsthis.h"
+#include "Qt/qpointer.h"
+#include "Qt/qstatusbar.h"
+#include "Qt/qdockwidget.h"
+#include "Qt/qevent.h"
+#include "Qt/qkeysequence.h"
+// #include "private/qapplication_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt;
+
+/*!
+ \class TQAccel
+ \brief The TQAccel class handles keyboard accelerator and shortcut keys.
+
+ \compat
+
+ A keyboard accelerator triggers an action when a certain key
+ combination is pressed. The accelerator handles all keyboard
+ activity for all the children of one top-level widget, so it is
+ not affected by the keyboard focus.
+
+ In most cases, you will not need to use this class directly. Use
+ the QAction class to create actions with accelerators that can be
+ used in both menus and toolbars. If you're only interested in
+ menus use Q3MenuData::insertItem() or Q3MenuData::setAccel() to make
+ accelerators for operations that are also available on menus. Many
+ widgets automatically generate accelerators, such as QAbstractButton,
+ QGroupBox, QLabel (with QLabel::setBuddy()), QMenuBar, and QTabBar.
+ Example:
+ \snippet doc/src/snippets/code/src_qt3support_other_q3accel.cpp 0
+
+ A TQAccel tqcontains a list of accelerator items that can be
+ manipulated using insertItem(), removeItem(), clear(), key() and
+ findKey().
+
+ Each accelerator item consists of an identifier and a \l
+ QKeySequence. A single key sequence consists of a keyboard code
+ combined with modifiers (Qt::SHIFT, Qt::CTRL, Qt::ALT, or
+ Qt::UNICODE_ACCEL). For example, Qt::CTRL + Qt::Key_P could be a shortcut
+ for printing a document. As an alternative, use Qt::UNICODE_ACCEL with the
+ tqunicode code point of the character. For example, Qt::UNICODE_ACCEL
+ + 'A' gives the same accelerator as Qt::Key_A.
+
+ When an accelerator key is pressed, the accelerator sends out the
+ signal activated() with a number that identifies this particular
+ accelerator item. Accelerator items can also be individually
+ connected, so that two different keys will activate two different
+ Q_SLOTS (see connectItem() and disconnectItem()).
+
+ The activated() signal is \e not emitted when two or more
+ accelerators match the same key. Instead, the first matching
+ accelerator sends out the activatedAmbiguously() signal. By
+ pressing the key multiple times, users can navigate between all
+ matching accelerators. Some standard controls like QPushButton and
+ QCheckBox connect the activatedAmbiguously() signal to the
+ harmless setFocus() slot, whereas activated() is connected to a
+ slot invoking the button's action. Most controls, like QLabel and
+ QTabBar, treat activated() and activatedAmbiguously() as
+ equivalent.
+
+ Use setEnabled() to enable or disable all the items in an
+ accelerator, or setItemEnabled() to enable or disable individual
+ items. An item is active only when both the TQAccel and the item
+ itself are enabled.
+
+ The function setWhatsThis() specifies a help text that appears
+ when the user presses an accelerator key in What's This mode.
+
+ The accelerator will be deleted when \e parent is deleted,
+ and will consume relevant key events until then.
+
+ Please note that the accelerator
+ \snippet doc/src/snippets/code/src_qt3support_other_q3accel.cpp 1
+ can be triggered with both the 'M' key, and with Shift+M,
+ unless a second accelerator is defined for the Shift+M
+ combination.
+
+
+ Example:
+ \snippet doc/src/snippets/code/src_qt3support_other_q3accel.cpp 2
+
+ \sa QKeyEvent QWidget::keyPressEvent()
+ QAbstractButton::setAccel() QLabel::setBuddy() QKeySequence
+*/
+
+
+struct TQAccelItem { // internal accelerator item
+ TQAccelItem(const QKeySequence &k, int i)
+ { key=k; id=i; enabled=true; signal=0; }
+ ~TQAccelItem() { delete signal; }
+ int id;
+ QKeySequence key;
+ bool enabled;
+ TQSignal *signal;
+ QString whatsthis;
+};
+
+
+typedef TQPtrList<TQAccelItem> TQAccelList; // internal accelerator list
+
+class TQAccelPrivate {
+public:
+ TQAccelPrivate(TQAccel* p);
+ ~TQAccelPrivate();
+ TQAccelList aitems;
+ bool enabled;
+ QPointer<QWidget> watch;
+ bool ignorewhatsthis;
+ TQAccel* parent;
+
+ void activate(TQAccelItem* item);
+ void activateAmbiguously(TQAccelItem* item);
+};
+
+class TQAccelManager {
+public:
+ static TQAccelManager* self() { return self_ptr ? self_ptr : new TQAccelManager; }
+ void registerAccel(TQAccelPrivate* a) { accels.append(a); }
+ void unregisterAccel(TQAccelPrivate* a) { accels.removeRef(a); if (accels.isEmpty()) delete this; }
+ bool tryAccelEvent(QWidget* w, QKeyEvent* e);
+ bool dispatchAccelEvent(QWidget* w, QKeyEvent* e);
+ bool tryComposeUnicode(QWidget* w, QKeyEvent* e);
+
+private:
+ TQAccelManager()
+ : currentState(QKeySequence::NoMatch), clash(-1), metaComposeUnicode(false),composedUnicode(0)
+ { setFuncPtr(); self_ptr = this; }
+ ~TQAccelManager() { self_ptr = 0; }
+ void setFuncPtr();
+
+ bool correctSubWindow(QWidget *w, TQAccelPrivate* d);
+ QKeySequence::SequenceMatch match(QKeyEvent* e, TQAccelItem* item, QKeySequence& temp);
+ int translateModifiers(ButtonState state);
+
+ TQPtrList<TQAccelPrivate> accels;
+ static TQAccelManager* self_ptr;
+ QKeySequence::SequenceMatch currentState;
+ QKeySequence intermediate;
+ int clash;
+ bool metaComposeUnicode;
+ int composedUnicode;
+};
+TQAccelManager* TQAccelManager::self_ptr = 0;
+
+bool Q_COMPAT_EXPORT qt_tryAccelEvent(QWidget* w, QKeyEvent* e){
+ return TQAccelManager::self()->tryAccelEvent(w, e);
+}
+
+bool Q_COMPAT_EXPORT qt_dispatchAccelEvent(QWidget* w, QKeyEvent* e){
+ return TQAccelManager::self()->dispatchAccelEvent(w, e);
+}
+
+bool Q_COMPAT_EXPORT qt_tryComposeUnicode(QWidget* w, QKeyEvent* e){
+ return TQAccelManager::self()->tryComposeUnicode(w, e);
+}
+
+void TQAccelManager::setFuncPtr() {
+ if (qApp->d_func()->qt_compat_used)
+ return;
+ QApplicationPrivate *data = static_cast<QApplicationPrivate*>(qApp->d_ptr.data());
+ data->qt_tryAccelEvent = qt_tryAccelEvent;
+ data->qt_tryComposeUnicode = qt_tryComposeUnicode;
+ data->qt_dispatchAccelEvent = qt_dispatchAccelEvent;
+ data->qt_compat_used = true;
+}
+
+#ifdef Q_WS_MAC
+static bool qt_accel_no_shortcuts = true;
+#else
+static bool qt_accel_no_shortcuts = false;
+#endif
+void Q_COMPAT_EXPORT qt_set_accel_auto_shortcuts(bool b) { qt_accel_no_shortcuts = b; }
+
+/*
+ \internal
+ Returns true if the accel is in the current subwindow, else false.
+*/
+bool TQAccelManager::correctSubWindow(QWidget* w, TQAccelPrivate* d) {
+#if !defined (Q_OS_MACX)
+ if (!d->watch || !d->watch->isVisible() || !d->watch->isEnabled())
+#else
+ if (!d->watch || (!d->watch->isVisible() && !d->watch->inherits("QMenuBar")) || !d->watch->isEnabled())
+#endif
+ return false;
+ QWidget* tlw = w->window();
+ QWidget* wtlw = d->watch->window();
+
+ /* if we live in a floating dock window, keep our parent's
+ * accelerators working */
+#ifndef QT_NO_MAINWINDOW
+ if ((tlw->windowType() == Qt::Dialog) && tlw->parentWidget() && qobject_cast<QDockWidget*>(tlw))
+ return tlw->parentWidget()->window() == wtlw;
+
+ if (wtlw != tlw)
+ return false;
+#endif
+ /* if we live in a MDI subwindow, ignore the event if we are
+ not the active document window */
+ QWidget* sw = d->watch;
+ while (sw && sw->windowType() != Qt::SubWindow)
+ sw = sw->parentWidget(true);
+ if (sw) { // we are in a subwindow indeed
+ QWidget* fw = w;
+ while (fw && fw != sw)
+ fw = fw->parentWidget(true);
+ if (fw != sw) // focus widget not in our subwindow
+ return false;
+ }
+ return true;
+}
+
+inline int TQAccelManager::translateModifiers(ButtonState state)
+{
+ int result = 0;
+ if (state & ShiftButton)
+ result |= SHIFT;
+ if (state & ControlButton)
+ result |= CTRL;
+ if (state & MetaButton)
+ result |= META;
+ if (state & AltButton)
+ result |= ALT;
+ return result;
+}
+
+/*
+ \internal
+ Matches the current intermediate key sequence + the latest
+ keyevent, with and AccelItem. Returns Identical,
+ PartialMatch or NoMatch, and fills \a temp with the
+ resulting key sequence.
+*/
+QKeySequence::SequenceMatch TQAccelManager::match(QKeyEvent *e, TQAccelItem* item, QKeySequence& temp)
+{
+ QKeySequence::SequenceMatch result = QKeySequence::NoMatch;
+ int index = intermediate.count();
+ temp = intermediate;
+
+ int modifier = translateModifiers(e->state());
+
+ if (e->key() && e->key() != Key_unknown) {
+ int key = e->key() | modifier;
+ if (e->key() == Key_BackTab) {
+ /*
+ In QApplication, we map shift+tab to shift+backtab.
+ This code here reverts the mapping in a way that keeps
+ backtab and shift+tab accelerators working, in that
+ order, meaning backtab has priority.*/
+ key &= ~SHIFT;
+
+ temp.setKey(key, index);
+ if (QKeySequence::NoMatch != (result = temp.matches(item->key)))
+ return result;
+ if (e->state() & ShiftButton)
+ key |= SHIFT;
+ key = Key_Tab | (key & MODIFIER_MASK);
+ temp.setKey(key, index);
+ if (QKeySequence::NoMatch != (result = temp.matches(item->key)))
+ return result;
+ } else {
+ temp.setKey(key, index);
+ if (QKeySequence::NoMatch != (result = temp.matches(item->key)))
+ return result;
+ }
+
+ if (key == Key_BackTab) {
+ if (e->state() & ShiftButton)
+ key |= SHIFT;
+ temp.setKey(key, index);
+ if (QKeySequence::NoMatch != (result = temp.matches(item->key)))
+ return result;
+ }
+ }
+ if (!e->text().isEmpty()) {
+ temp.setKey((int)e->text()[0].tqunicode() | UNICODE_ACCEL | modifier, index);
+ result = temp.matches(item->key);
+ }
+ return result;
+}
+
+bool TQAccelManager::tryAccelEvent(QWidget* w, QKeyEvent* e)
+{
+ if (QKeySequence::NoMatch == currentState) {
+ e->t = QEvent::AccelOverride;
+ e->ignore();
+ QApplication::sendSpontaneousEvent(w, e);
+ if (e->isAccepted())
+ return false;
+ }
+ e->t = QEvent::Accel;
+ e->ignore();
+ QApplication::sendSpontaneousEvent(w, e);
+ return e->isAccepted();
+}
+
+bool TQAccelManager::tryComposeUnicode(QWidget* w, QKeyEvent* e)
+{
+ if (metaComposeUnicode) {
+ int value = e->key() - Key_0;
+ // Ignore acceloverrides so we don't trigger
+ // accels on keypad when Meta compose is on
+ if ((e->type() == QEvent::AccelOverride) &&
+ (e->state() == Qt::Keypad + Qt::MetaButton)) {
+ e->accept();
+ // Meta compose start/continue
+ } else if ((e->type() == QEvent::KeyPress) &&
+ (e->state() == Qt::Keypad + Qt::MetaButton)) {
+ if (value >= 0 && value <= 9) {
+ composedUnicode *= 10;
+ composedUnicode += value;
+ return true;
+ } else {
+ // Composing interrupted, dispatch!
+ if (composedUnicode) {
+ QChar ch(composedUnicode);
+ QString s(ch);
+ QKeyEvent kep(QEvent::KeyPress, 0, ch.row() ? 0 : ch.cell(), 0, s);
+ QKeyEvent ker(QEvent::KeyRelease, 0, ch.row() ? 0 : ch.cell(), 0, s);
+ QApplication::sendEvent(w, &kep);
+ QApplication::sendEvent(w, &ker);
+ }
+ composedUnicode = 0;
+ return true;
+ }
+ // Meta compose end, dispatch
+ } else if ((e->type() == QEvent::KeyRelease) &&
+ (e->key() == Key_Meta) &&
+ (composedUnicode != 0)) {
+ if ((composedUnicode > 0) &&
+ (composedUnicode < 0xFFFE)) {
+ QChar ch(composedUnicode);
+ QString s(ch);
+ QKeyEvent kep(QEvent::KeyPress, 0, ch.row() ? 0 : ch.cell(), 0, s);
+ QKeyEvent ker(QEvent::KeyRelease, 0, ch.row() ? 0 : ch.cell(), 0, s);
+ QApplication::sendEvent(w, &kep);
+ QApplication::sendEvent(w, &ker);
+ }
+ composedUnicode = 0;
+ return true;
+ }
+ }
+ return false;
+}
+
+/*
+ \internal
+ Checks for possible accelerators, if no widget
+ ate the keypres, or we are in the middle of a
+ partial key sequence.
+*/
+bool TQAccelManager::dispatchAccelEvent(QWidget* w, QKeyEvent* e)
+{
+#ifndef QT_NO_STATUSBAR
+ // Needs to be declared and used here because of "goto doclash"
+ QStatusBar* mainStatusBar = 0;
+#endif
+
+ // Modifiers can NOT be accelerators...
+ if (e->key() >= Key_Shift &&
+ e->key() <= Key_Alt)
+ return false;
+
+ QKeySequence::SequenceMatch result = QKeySequence::NoMatch;
+ QKeySequence tocheck, partial;
+ TQAccelPrivate* accel = 0;
+ TQAccelItem* item = 0;
+ TQAccelPrivate* firstaccel = 0;
+ TQAccelItem* firstitem = 0;
+ TQAccelPrivate* lastaccel = 0;
+ TQAccelItem* lastitem = 0;
+
+ QKeyEvent pe = *e;
+ int n = -1;
+ int hasShift = (e->state()&Qt::ShiftButton)?1:0;
+ bool identicalDisabled = false;
+ bool matchFound = false;
+ do {
+ accel = accels.first();
+ matchFound = false;
+ while (accel) {
+ if (correctSubWindow(w, accel)) {
+ if (accel->enabled) {
+ item = accel->aitems.last();
+ while(item) {
+ if (QKeySequence::Identical == (result = match(&pe, item, tocheck))) {
+ if (item->enabled) {
+ if (!firstaccel) {
+ firstaccel = accel;
+ firstitem = item;
+ }
+ lastaccel = accel;
+ lastitem = item;
+ n++;
+ matchFound = true;
+ if (n > QMAX(clash,0))
+ goto doclash;
+ } else {
+ identicalDisabled = true;
+ }
+ }
+ if (item->enabled && QKeySequence::PartialMatch == result) {
+ partial = tocheck;
+ matchFound = true;
+ }
+ item = accel->aitems.prev();
+ }
+ } else {
+ item = accel->aitems.last();
+ while(item) {
+ if (QKeySequence::Identical == match(&pe, item, tocheck))
+ identicalDisabled = true;
+ item = accel->aitems.prev();
+ }
+ }
+ }
+ accel = accels.next();
+ }
+ pe = QKeyEvent(QEvent::Accel, pe.key(), pe.ascii(), pe.state()&~Qt::ShiftButton, pe.text());
+ } while (hasShift-- && !matchFound && !identicalDisabled);
+
+#ifndef QT_NO_STATUSBAR
+ mainStatusBar = (QStatusBar*) w->window()->child(0, "QStatusBar");
+#endif
+ if (n < 0) { // no match found
+ currentState = partial.count() ? QKeySequence::PartialMatch : QKeySequence::NoMatch;
+#ifndef QT_NO_STATUSBAR
+ // Only display message if we are, or were, in a partial match
+ if (mainStatusBar && (QKeySequence::PartialMatch == currentState || intermediate.count())) {
+ if (currentState == QKeySequence::PartialMatch) {
+ mainStatusBar->showMessage((QString)partial + QLatin1String(", ..."));
+ } else if (!identicalDisabled) {
+ QString message = TQAccel::tr("%1, %2 not defined").
+ arg((QString)intermediate).
+ arg(QKeySequence::encodeString(e->key() | translateModifiers(e->state())));
+ mainStatusBar->showMessage(message, 2000);
+ // Since we're a NoMatch, reset the clash count
+ clash = -1;
+ } else {
+ mainStatusBar->clearMessage();
+ }
+ }
+#endif
+
+ bool eatKey = (QKeySequence::PartialMatch == currentState || intermediate.count());
+ intermediate = partial;
+ if (eatKey)
+ e->accept();
+ return eatKey;
+ } else if (n == 0) { // found exactly one match
+ clash = -1; // reset
+#ifndef QT_NO_STATUSBAR
+ if (currentState == QKeySequence::PartialMatch && mainStatusBar)
+ mainStatusBar->clearMessage();
+#endif
+ currentState = QKeySequence::NoMatch; // Free sequence keylock
+ intermediate = QKeySequence();
+ lastaccel->activate(lastitem);
+ e->accept();
+ return true;
+ }
+
+ doclash: // found more than one match
+#ifndef QT_NO_STATUSBAR
+ if (!mainStatusBar) // if "goto doclash", we need to get status bar again.
+ mainStatusBar = (QStatusBar*) w->window()->child(0, "QStatusBar");
+#endif
+
+ QString message = TQAccel::tr("Ambiguous %1 not handled").arg((QString)tocheck);
+ if (clash >= 0 && n > clash) { // pick next match
+ intermediate = QKeySequence();
+ currentState = QKeySequence::NoMatch; // Free sequence keylock
+ clash++;
+#ifndef QT_NO_STATUSBAR
+ if (mainStatusBar &&
+ !lastitem->signal &&
+ !(lastaccel->parent->tqreceivers(SIGNAL(activatedAmbiguously(int)))))
+ mainStatusBar->showMessage(message, 2000);
+#endif
+ lastaccel->activateAmbiguously(lastitem);
+ } else { // start (or wrap) with the first matching
+ intermediate = QKeySequence();
+ currentState = QKeySequence::NoMatch; // Free sequence keylock
+ clash = 0;
+#ifndef QT_NO_STATUSBAR
+ if (mainStatusBar &&
+ !firstitem->signal &&
+ !(firstaccel->parent->tqreceivers(SIGNAL(activatedAmbiguously(int)))))
+ mainStatusBar->showMessage(message, 2000);
+#endif
+ firstaccel->activateAmbiguously(firstitem);
+ }
+ e->accept();
+ return true;
+}
+
+TQAccelPrivate::TQAccelPrivate(TQAccel* p)
+ : parent(p)
+{
+ TQAccelManager::self()->registerAccel(this);
+ aitems.setAutoDelete(true);
+ ignorewhatsthis = false;
+}
+
+TQAccelPrivate::~TQAccelPrivate()
+{
+ TQAccelManager::self()->unregisterAccel(this);
+}
+
+static TQAccelItem *find_id(TQAccelList &list, int id)
+{
+ register TQAccelItem *item = list.first();
+ while (item && item->id != id)
+ item = list.next();
+ return item;
+}
+
+static TQAccelItem *find_key(TQAccelList &list, const QKeySequence &key)
+{
+ register TQAccelItem *item = list.first();
+ while (item && !(item->key == key))
+ item = list.next();
+ return item;
+}
+
+/*!
+ Constructs a TQAccel object called \a name, with parent \a parent.
+ The accelerator operates on \a parent.
+*/
+
+TQAccel::TQAccel(QWidget *parent, const char *name)
+ : TQT_BASE_OBJECT_NAME(parent, name)
+{
+ d = new TQAccelPrivate(this);
+ d->enabled = true;
+ d->watch = parent;
+#if defined(QT_CHECK_NULL)
+ if (!d->watch)
+ qWarning("TQAccel: An accelerator must have a parent or a watch widget");
+#endif
+}
+
+/*!
+ Constructs a TQAccel object called \a name, that operates on \a
+ watch, and is a child of \a parent.
+
+ This constructor is not needed for normal application programming.
+*/
+TQAccel::TQAccel(QWidget* watch, TQT_BASE_OBJECT_NAME *parent, const char *name)
+ : TQT_BASE_OBJECT_NAME(parent, name)
+{
+ d = new TQAccelPrivate(this);
+ d->enabled = true;
+ d->watch = watch;
+#if defined(QT_CHECK_NULL)
+ if (!d->watch)
+ qWarning("TQAccel: An accelerator must have a parent or a watch widget");
+#endif
+}
+
+/*!
+ Destroys the accelerator object and frees all allocated resources.
+*/
+
+TQAccel::~TQAccel()
+{
+ delete d;
+}
+
+
+/*!
+ \fn void TQAccel::activated(int id)
+
+ This signal is emitted when the user types the shortcut's key
+ sequence. \a id is a number that identifies this particular
+ accelerator item.
+
+ \sa activatedAmbiguously()
+*/
+
+/*!
+ \fn void TQAccel::activatedAmbiguously(int id)
+
+ This signal is emitted when the user types a shortcut key
+ sequence that is ambiguous. For example, if one key sequence is a
+ "prefix" for another and the user types these keys it isn't clear
+ if they want the shorter key sequence, or if they're about to
+ type more to complete the longer key sequence. \a id is a number
+ that identifies this particular accelerator item.
+
+ \sa activated()
+*/
+
+/*!
+ Returns true if the accelerator is enabled; otherwise returns
+ false.
+
+ \sa setEnabled(), isItemEnabled()
+*/
+
+bool TQAccel::isEnabled() const
+{
+ return d->enabled;
+}
+
+
+/*!
+ Enables the accelerator if \a enable is true, or disables it if \a
+ enable is false.
+
+ Individual keys can also be enabled or disabled using
+ setItemEnabled(). To work, a key must be an enabled item in an
+ enabled TQAccel.
+
+ \sa isEnabled(), setItemEnabled()
+*/
+
+void TQAccel::setEnabled(bool enable)
+{
+ d->enabled = enable;
+}
+
+
+/*!
+ Returns the number of accelerator items in this accelerator.
+*/
+
+uint TQAccel::count() const
+{
+ return d->aitems.count();
+}
+
+
+static int get_seq_id()
+{
+ static int seq_no = -2; // -1 is used as return value in findKey()
+ return seq_no--;
+}
+
+/*!
+ Inserts an accelerator item and returns the item's identifier.
+
+ \a key is a key code and an optional combination of SHIFT, CTRL
+ and ALT. \a id is the accelerator item id.
+
+ If \a id is negative, then the item will be assigned a unique
+ negative identifier less than -1.
+
+ \snippet doc/src/snippets/code/src_qt3support_other_q3accel.cpp 3
+*/
+
+int TQAccel::insertItem(const QKeySequence& key, int id)
+{
+ if (id == -1)
+ id = get_seq_id();
+ d->aitems.insert(0, new TQAccelItem(key,id));
+ return id;
+}
+
+/*!
+ Removes the accelerator item with the identifier \a id.
+*/
+
+void TQAccel::removeItem(int id)
+{
+ if (find_id(d->aitems, id))
+ d->aitems.remove();
+}
+
+
+/*!
+ Removes all accelerator items.
+*/
+
+void TQAccel::clear()
+{
+ d->aitems.clear();
+}
+
+
+/*!
+ Returns the key sequence of the accelerator item with identifier
+ \a id, or an invalid key sequence (0) if the id cannot be found.
+*/
+
+QKeySequence TQAccel::key(int id)
+{
+ TQAccelItem *item = find_id(d->aitems, id);
+ return item ? item->key : QKeySequence(0);
+}
+
+
+/*!
+ Returns the identifier of the accelerator item with the key code
+ \a key, or -1 if the item cannot be found.
+*/
+
+int TQAccel::findKey(const QKeySequence& key) const
+{
+ TQAccelItem *item = find_key(d->aitems, key);
+ return item ? item->id : -1;
+}
+
+
+/*!
+ Returns true if the accelerator item with the identifier \a id is
+ enabled. Returns false if the item is disabled or cannot be found.
+
+ \sa setItemEnabled(), isEnabled()
+*/
+
+bool TQAccel::isItemEnabled(int id) const
+{
+ TQAccelItem *item = find_id(d->aitems, id);
+ return item ? item->enabled : false;
+}
+
+
+/*!
+ Enables the accelerator item with the identifier \a id if \a
+ enable is true, and disables item \a id if \a enable is false.
+
+ To work, an item must be enabled and be in an enabled TQAccel.
+
+ \sa isItemEnabled(), isEnabled()
+*/
+
+void TQAccel::setItemEnabled(int id, bool enable)
+{
+ TQAccelItem *item = find_id(d->aitems, id);
+ if (item)
+ item->enabled = enable;
+}
+
+
+/*!
+ Connects the accelerator item \a id to the slot \a member of \a
+ receiver. Returns true if the connection is successful.
+
+ \snippet doc/src/snippets/code/src_qt3support_other_q3accel.cpp 4
+
+ Of course, you can also send a signal as \a member.
+
+ Normally accelerators are connected to Q_SLOTS which then receive
+ the \c activated(int id) signal with the id of the accelerator
+ item that was activated. If you choose to connect a specific
+ accelerator item using this function, the \c activated() signal is
+ emitted if the associated key sequence is pressed but no \c
+ activated(int id) signal is emitted.
+
+ \sa disconnectItem(), TQT_BASE_OBJECT_NAME::connect()
+*/
+
+bool TQAccel::connectItem(int id, const TQT_BASE_OBJECT_NAME *receiver, const char *member)
+{
+ TQAccelItem *item = find_id(d->aitems, id);
+ if (item) {
+ if (!item->signal) {
+ item->signal = new TQSignal;
+ Q_CHECK_PTR(item->signal);
+ }
+ return item->signal->connect(receiver, member);
+ }
+ return false;
+}
+
+/*!
+ Disconnects the accelerator item identified by \a id from
+ the function called \a member in the \a receiver object.
+ Returns true if the connection existed and the disconnect
+ was successful.
+
+ \sa connectItem(), TQT_BASE_OBJECT_NAME::disconnect()
+*/
+
+bool TQAccel::disconnectItem(int id, const TQT_BASE_OBJECT_NAME *receiver,
+ const char *member)
+{
+ TQAccelItem *item = find_id(d->aitems, id);
+ if (item && item->signal)
+ return item->signal->disconnect(receiver, member);
+ return false;
+}
+
+void TQAccelPrivate::activate(TQAccelItem* item)
+{
+#ifndef QT_NO_WHATSTHIS
+ if (QWhatsThis::inWhatsThisMode() && !ignorewhatsthis) {
+ QWhatsThis::showText(QCursor::pos(), item->whatsthis);
+ return;
+ }
+#endif
+ if (item->signal)
+ item->signal->activate();
+ else
+ emit parent->activated(item->id);
+}
+
+void TQAccelPrivate::activateAmbiguously(TQAccelItem* item)
+{
+ if (item->signal)
+ item->signal->activate();
+ else
+ emit parent->activatedAmbiguously(item->id);
+}
+
+
+/*!
+ Returns the shortcut key sequence for \a str, or an invalid key
+ sequence (0) if \a str has no shortcut sequence.
+
+ For example, shortcutKey("E&xit") returns QKeySequence(Qt::ALT +
+ Qt::Key_X), shortcutKey("&Quit") returns QKeySequence(Qt::ALT +
+ Qt::Key_Q), and shortcutKey("Quit") returns QKeySequence().
+*/
+
+QKeySequence TQAccel::shortcutKey(const QString &str)
+{
+ if(qt_accel_no_shortcuts)
+ return QKeySequence();
+
+ int p = 0;
+ while (p >= 0) {
+ p = str.find(QLatin1Char('&'), p) + 1;
+ if (p <= 0 || p >= (int)str.length())
+ return 0;
+ if (str[p] != QLatin1Char('&')) {
+ QChar c = str[p];
+ if (c.isPrint()) {
+ char ltr = c.upper().latin1();
+ if (ltr >= (char)Key_A && ltr <= (char)Key_Z)
+ c = QLatin1Char(ltr);
+ else
+ c = c.lower();
+ return QKeySequence(c.tqunicode() + ALT + UNICODE_ACCEL);
+ }
+ }
+ p++;
+ }
+ return QKeySequence();
+}
+
+/*! \obsolete
+
+ Creates an accelerator string for the key \a k.
+ For instance CTRL+Key_O gives "Ctrl+O". The "Ctrl" etc.
+ are translated (using TQT_BASE_OBJECT_NAME::tr()) in the "TQAccel" context.
+
+ The function is superfluous. Cast the QKeySequence \a k to a
+ QString for the same effect.
+*/
+QString TQAccel::keyToString(QKeySequence k)
+{
+ return (QString) k;
+}
+
+/*!\obsolete
+
+ Returns an accelerator code for the string \a s. For example
+ "Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl",
+ "Shift", "Alt" are recognized, as well as their translated
+ equivalents in the "TQAccel" context (using TQT_BASE_OBJECT_NAME::tr()). Returns 0
+ if \a s is not recognized.
+
+ This function is typically used with \link TQT_BASE_OBJECT_NAME::tr() tr
+ \endlink(), so that accelerator keys can be tqreplaced in
+ translations:
+
+ \snippet doc/src/snippets/code/src_qt3support_other_q3accel.cpp 5
+
+ Notice the "File|Open" translator comment. It is by no means
+ necessary, but it provides some context for the human translator.
+
+ The function is superfluous. Construct a QKeySequence from the
+ string \a s for the same effect.
+
+ \sa TQT_BASE_OBJECT_NAME::tr(), {Internationalization with Qt}
+*/
+QKeySequence TQAccel::stringToKey(const QString & s)
+{
+ return QKeySequence(s);
+}
+
+
+/*!
+ Sets a What's This help text for the accelerator item \a id to \a
+ text.
+
+ The text will be shown when the application is in What's This mode
+ and the user hits the accelerator key.
+
+ To set What's This help on a menu item (with or without an
+ accelerator key), use Q3MenuData::setWhatsThis().
+
+ \sa whatsThis(), QWhatsThis::inWhatsThisMode(), QAction::setWhatsThis()
+*/
+void TQAccel::setWhatsThis(int id, const QString& text)
+{
+ TQAccelItem *item = find_id(d->aitems, id);
+ if (item)
+ item->whatsthis = text;
+}
+
+/*!
+ Returns the What's This help text for the specified item \a id or
+ an empty string if no text has been specified.
+
+ \sa setWhatsThis()
+*/
+QString TQAccel::whatsThis(int id) const
+{
+
+ TQAccelItem *item = find_id(d->aitems, id);
+ return item? item->whatsthis : QString();
+}
+
+/*!\internal */
+void TQAccel::setIgnoreWhatsThis(bool b)
+{
+ d->ignorewhatsthis = b;
+}
+
+/*!\internal */
+bool TQAccel::ignoreWhatsThis() const
+{
+ return d->ignorewhatsthis;
+}
+
+/*!
+ \fn void TQAccel::repairEventFilter()
+ \internal
+*/
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of TQAccel class
+**
+** Created : 950419
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqaccel.h"
+
+#ifndef TQT_NO_ACCEL
+
+#include "tqsignal.h"
+#include "tqapplication.h"
+#include "tqwidget.h"
+#include "tqptrlist.h"
+#include "tqwhatsthis.h"
+#include "tqguardedptr.h"
+#include "tqstatusbar.h"
+#include "tqdockwindow.h"
+#include "tqsignalslotimp.h"
+/*!
+ \class TQAccel tqaccel.h
+ \brief The TQAccel class handles keyboard accelerator and shortcut keys.
+
+ \ingroup misc
+
+ A keyboard accelerator triggers an action when a certain key
+ combination is pressed. The accelerator handles all keyboard
+ activity for all the tqchildren of one top-level widget, so it is
+ not affected by the keyboard focus.
+
+ In most cases, you will not need to use this class directly. Use
+ the TQAction class to create actions with accelerators that can be
+ used in both menus and toolbars. If you're only interested in
+ menus use TQMenuData::insertItem() or TQMenuData::setAccel() to make
+ accelerators for operations that are also available on menus. Many
+ widgets automatically generate accelerators, such as TQButton,
+ TQGroupBox, TQLabel (with TQLabel::setBuddy()), TQMenuBar and TQTabBar.
+ Example:
+ \code
+ TQPushButton p( "&Exit", tqparent ); // automatic shortcut ALT+Key_E
+ TQPopupMenu *fileMenu = new fileMenu( tqparent );
+ fileMenu->insertItem( "Undo", tqparent, TQT_SLOT(undo()), CTRL+Key_Z );
+ \endcode
+
+ A TQAccel tqcontains a list of accelerator items that can be
+ manipulated using insertItem(), removeItem(), clear(), key() and
+ tqfindKey().
+
+ Each accelerator item consists of an identifier and a \l
+ TQKeySequence. A single key sequence consists of a keyboard code
+ combined with modifiers (\c SHIFT, \c CTRL, \c ALT or \c
+ UNICODE_ACCEL). For example, \c{CTRL + Key_P} could be a shortcut
+ for printing a document. The key codes are listed in \c
+ tqnamespace.h. As an alternative, use \c UNICODE_ACCEL with the
+ tqunicode code point of the character. For example, \c{UNICODE_ACCEL
+ + 'A'} gives the same accelerator as \c Key_A.
+
+ When an accelerator key is pressed, the accelerator sends out the
+ signal activated() with a number that identifies this particular
+ accelerator item. Accelerator items can also be individually
+ connected, so that two different keys will activate two different
+ Q_SLOTS (see connectItem() and disconnectItem()).
+
+ The activated() signal is \e not emitted when two or more
+ accelerators match the same key. Instead, the first matching
+ accelerator sends out the activatedAmbiguously() signal. By
+ pressing the key multiple times, users can navigate between all
+ matching accelerators. Some standard controls like TQPushButton and
+ TQCheckBox connect the activatedAmbiguously() signal to the
+ harmless setFocus() slot, whereas activated() is connected to a
+ slot invoking the button's action. Most controls, like TQLabel and
+ TQTabBar, treat activated() and activatedAmbiguously() as
+ equivalent.
+
+ Use setEnabled() to enable or disable all the items in an
+ accelerator, or setItemEnabled() to enable or disable individual
+ items. An item is active only when both the TQAccel and the item
+ itself are enabled.
+
+ The function setWhatsThis() specifies a help text that appears
+ when the user presses an accelerator key in What's This mode.
+
+ The accelerator will be deleted when \e tqparent is deleted,
+ and will consume relevant key events until then.
+
+ Please note that the accelerator
+ \code
+ accelerator->insertItem( TQKeySequence("M") );
+ \endcode
+ can be triggered with both the 'M' key, and with Shift+M,
+ unless a second accelerator is defined for the Shift+M
+ combination.
+
+
+ Example:
+ \code
+ TQAccel *a = new TQAccel( myWindow ); // create accels for myWindow
+ a->connectItem( a->insertItem(Key_P+CTRL), // adds Ctrl+P accelerator
+ myWindow, // connected to myWindow's
+ TQT_SLOT(printDoc()) ); // printDoc() slot
+ \endcode
+
+ \sa TQKeyEvent TQWidget::keyPressEvent() TQMenuData::setAccel()
+ TQButton::setAccel() TQLabel::setBuddy() TQKeySequence
+ \link guibooks.html#fowler GUI Design Handbook: Keyboard Shortcuts \endlink.
+*/
+
+
+struct TQAccelItem { // internal accelerator item
+ TQAccelItem( const TQKeySequence &k, int i )
+ { key=k; id=i; enabled=TRUE; signal=0; }
+ ~TQAccelItem() { delete signal; }
+ int id;
+ TQKeySequence key;
+ bool enabled;
+ TQSignal *signal;
+ TQString whatsthis;
+};
+
+
+typedef TQPtrList<TQAccelItem> TQAccelList; // internal accelerator list
+
+class TQAccelPrivate : public TQt {
+public:
+ TQAccelPrivate( TQAccel* p );
+ ~TQAccelPrivate();
+ TQAccelList aitems;
+ bool enabled;
+ TQGuardedPtr<TQWidget> watch;
+ bool ignorewhatsthis;
+ TQAccel* tqparent;
+
+ void activate( TQAccelItem* item );
+ void activateAmbiguously( TQAccelItem* item );
+};
+
+class TQAccelManager : public TQt {
+public:
+ static TQAccelManager* self() { return self_ptr ? self_ptr : new TQAccelManager; }
+ void registerAccel( TQAccelPrivate* a ) { accels.append( a ); }
+ void unregisterAccel( TQAccelPrivate* a ) { accels.removeRef( a ); if ( accels.isEmpty() ) delete this; }
+ bool tryAccelEvent( TQWidget* w, TQKeyEvent* e );
+ bool dispatchAccelEvent( TQWidget* w, TQKeyEvent* e );
+ bool tryComposeUnicode( TQWidget* w, TQKeyEvent* e );
+
+private:
+ TQAccelManager():currentState(TQt::NoMatch), clash(-1) { self_ptr = this; }
+ ~TQAccelManager() { self_ptr = 0; }
+
+ bool correctSubWindow( TQWidget *w, TQAccelPrivate* d );
+ SequenceMatch match( TQKeyEvent* e, TQAccelItem* item, TQKeySequence& temp );
+ int translateModifiers( ButtonState state );
+
+ TQPtrList<TQAccelPrivate> accels;
+ static TQAccelManager* self_ptr;
+ TQt::SequenceMatch currentState;
+ TQKeySequence intermediate;
+ int clash;
+};
+TQAccelManager* TQAccelManager::self_ptr = 0;
+
+bool TQ_EXPORT qt_tryAccelEvent( TQWidget* w, TQKeyEvent* e){
+ return TQAccelManager::self()->tryAccelEvent( w, e );
+}
+
+bool TQ_EXPORT qt_dispatchAccelEvent( TQWidget* w, TQKeyEvent* e){
+ return TQAccelManager::self()->dispatchAccelEvent( w, e );
+}
+
+bool TQ_EXPORT qt_tryComposeUnicode( TQWidget* w, TQKeyEvent* e){
+ return TQAccelManager::self()->tryComposeUnicode( w, e );
+}
+
+#ifdef TQ_WS_MAC
+static bool qt_accel_no_shortcuts = TRUE;
+#else
+static bool qt_accel_no_shortcuts = FALSE;
+#endif
+void TQ_EXPORT qt_setAccelAutoShortcuts(bool b) { qt_accel_no_shortcuts = b; }
+
+/*
+ \internal
+ Returns TRUE if the accel is in the current subwindow, else FALSE.
+*/
+bool TQAccelManager::correctSubWindow( TQWidget* w, TQAccelPrivate* d ) {
+#if !defined ( TQ_OS_MACX )
+ if ( !d->watch || !d->watch->isVisible() || !d->watch->isEnabled() )
+#else
+ if ( !d->watch || (!d->watch->isVisible() && !d->watch->inherits( "TQMenuBar" )) || !d->watch->isEnabled() )
+#endif
+ return FALSE;
+ TQWidget* tlw = w->tqtopLevelWidget();
+ TQWidget* wtlw = d->watch->tqtopLevelWidget();
+
+ /* if we live in a floating dock window, keep our tqparent's
+ * accelerators working */
+#ifndef TQT_NO_MAINWINDOW
+ if ( tlw->isDialog() && tlw->parentWidget() && ::tqqt_cast<TQDockWindow*>(tlw) ) // [FIXME] Can I safely use the TQT_TQOBJECT macro here?
+ return tlw->parentWidget()->tqtopLevelWidget() == wtlw;
+
+ if ( wtlw != tlw )
+ return FALSE;
+#endif
+ /* if we live in a MDI subwindow, ignore the event if we are
+ not the active document window */
+ TQWidget* sw = d->watch;
+ while ( sw && !sw->testWFlags( WSubWindow ) )
+ sw = sw->parentWidget( TRUE );
+ if ( sw ) { // we are in a subwindow indeed
+ TQWidget* fw = w;
+ while ( fw && fw != sw )
+ fw = fw->parentWidget( TRUE );
+ if ( fw != sw ) // focus widget not in our subwindow
+ return FALSE;
+ }
+ return TRUE;
+}
+
+inline int TQAccelManager::translateModifiers( ButtonState state )
+{
+ int result = 0;
+ if ( state & ShiftButton )
+ result |= SHIFT;
+ if ( state & ControlButton )
+ result |= CTRL;
+ if ( state & MetaButton )
+ result |= META;
+ if ( state & AltButton )
+ result |= ALT;
+ return result;
+}
+
+/*
+ \internal
+ Matches the current intermediate key sequence + the latest
+ keyevent, with and AccelItem. Returns Identical,
+ PartialMatch or NoMatch, and fills \a temp with the
+ resulting key sequence.
+*/
+TQt::SequenceMatch TQAccelManager::match( TQKeyEvent *e, TQAccelItem* item, TQKeySequence& temp )
+{
+ SequenceMatch result = TQt::NoMatch;
+ int index = intermediate.count();
+ temp = intermediate;
+
+ int modifier = translateModifiers( e->state() );
+
+ if ( e->key() && e->key() != Key_unknown) {
+ int key = e->key() | modifier;
+ if ( e->key() == Key_BackTab ) {
+ /*
+ In TQApplication, we map shift+tab to shift+backtab.
+ This code here reverts the mapping in a way that keeps
+ backtab and shift+tab accelerators working, in that
+ order, meaning backtab has priority.*/
+ key &= ~SHIFT;
+
+ temp.setKey( key, index );
+ if ( TQt::NoMatch != (result = temp.matches( item->key )) )
+ return result;
+ if ( e->state() & ShiftButton )
+ key |= SHIFT;
+ key = Key_Tab | ( key & MODIFIER_MASK );
+ temp.setKey( key, index );
+ if ( TQt::NoMatch != (result = temp.matches( item->key )) )
+ return result;
+ } else {
+ temp.setKey( key, index );
+ if ( TQt::NoMatch != (result = temp.matches( item->key )) )
+ return result;
+ }
+
+ if ( key == Key_BackTab ) {
+ if ( e->state() & ShiftButton )
+ key |= SHIFT;
+ temp.setKey( key, index );
+ if ( TQt::NoMatch != (result = temp.matches( item->key )) )
+ return result;
+ }
+ }
+ if ( !e->text().isEmpty() ) {
+ temp.setKey( (int)e->text()[0].unicode() | UNICODE_ACCEL | modifier, index );
+ result = temp.matches( item->key );
+ }
+ return result;
+}
+
+bool TQAccelManager::tryAccelEvent( TQWidget* w, TQKeyEvent* e )
+{
+ if ( TQt::NoMatch == currentState ) {
+ e->t = TQEvent::AccelOverride;
+ e->ignore();
+ TQAccel::sendSpontaneousKeyEvent( TQT_TQOBJECT(w), e );
+ if ( e->isAccepted() )
+ return FALSE;
+ }
+ e->t = TQEvent::Accel;
+ e->ignore();
+ TQAccel::sendSpontaneousKeyEvent( TQT_TQOBJECT(w), e );
+ return e->isAccepted();
+}
+
+bool TQAccelManager::tryComposeUnicode( TQWidget* w, TQKeyEvent* e )
+{
+ if ( TQApplication::metaComposeUnicode ) {
+ int value = e->key() - Key_0;
+ // Ignore acceloverrides so we don't trigger
+ // accels on keypad when Meta compose is on
+ if ( (e->type() == TQEvent::AccelOverride) &&
+ (e->state() == TQt::Keypad + TQt::MetaButton) ) {
+ e->accept();
+ // Meta compose start/continue
+ } else if ( (e->type() == TQEvent::KeyPress) &&
+ (e->state() == TQt::Keypad + TQt::MetaButton) ) {
+ if ( value >= 0 && value <= 9 ) {
+ TQApplication::composedUnicode *= 10;
+ TQApplication::composedUnicode += value;
+ return TRUE;
+ } else {
+ // Composing interrupted, dispatch!
+ if ( TQApplication::composedUnicode ) {
+ TQChar ch( TQApplication::composedUnicode );
+ TQString s( ch );
+ TQKeyEvent kep( TQEvent::KeyPress, 0, ch.row() ? 0 : ch.cell(), 0, s );
+ TQKeyEvent ker( TQEvent::KeyRelease, 0, ch.row() ? 0 : ch.cell(), 0, s );
+ TQApplication::sendEvent( w, &kep );
+ TQApplication::sendEvent( w, &ker );
+ }
+ TQApplication::composedUnicode = 0;
+ return TRUE;
+ }
+ // Meta compose end, dispatch
+ } else if ( (e->type() == TQEvent::KeyRelease) &&
+ (e->key() == Key_Meta) &&
+ (TQApplication::composedUnicode != 0) ) {
+ if ( (TQApplication::composedUnicode > 0) &&
+ (TQApplication::composedUnicode < 0xFFFE) ) {
+ TQChar ch( TQApplication::composedUnicode );
+ TQString s( ch );
+ TQKeyEvent kep( TQEvent::KeyPress, 0, ch.row() ? 0 : ch.cell(), 0, s );
+ TQKeyEvent ker( TQEvent::KeyRelease, 0, ch.row() ? 0 : ch.cell(), 0, s );
+ TQApplication::sendEvent( w, &kep );
+ TQApplication::sendEvent( w, &ker );
+ }
+ TQApplication::composedUnicode = 0;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*
+ \internal
+ Checks for possible accelerators, if no widget
+ ate the keypres, or we are in the middle of a
+ partial key sequence.
+*/
+bool TQAccelManager::dispatchAccelEvent( TQWidget* w, TQKeyEvent* e )
+{
+#ifndef TQT_NO_STATUSBAR
+ // Needs to be declared and used here because of "goto doclash"
+ TQStatusBar* maintqStatusBar = 0;
+#endif
+
+ // Modifiers can NOT be accelerators...
+ if ( e->key() >= Key_Shift &&
+ e->key() <= Key_Alt )
+ return FALSE;
+
+ SequenceMatch result = TQt::NoMatch;
+ TQKeySequence tocheck, partial;
+ TQAccelPrivate* accel = 0;
+ TQAccelItem* item = 0;
+ TQAccelPrivate* firstaccel = 0;
+ TQAccelItem* firstitem = 0;
+ TQAccelPrivate* lastaccel = 0;
+ TQAccelItem* lastitem = 0;
+
+ TQKeyEvent pe = *e;
+ int n = -1;
+ int hasShift = (e->state()&ShiftButton)?1:0;
+ bool identicalDisabled = FALSE;
+ bool matchFound = FALSE;
+ do {
+ accel = accels.first();
+ matchFound = FALSE;
+ while ( accel ) {
+ if ( correctSubWindow( w, accel ) ) {
+ if ( accel->enabled ) {
+ item = accel->aitems.last();
+ while( item ) {
+ if ( TQt::Identical == (result = match( &pe, item, tocheck )) ) {
+ if ( item->enabled ) {
+ if ( !firstaccel ) {
+ firstaccel = accel;
+ firstitem = item;
+ }
+ lastaccel = accel;
+ lastitem = item;
+ n++;
+ matchFound = TRUE;
+ if ( n > TQMAX(clash,0) )
+ goto doclash;
+ } else {
+ identicalDisabled = TRUE;
+ }
+ }
+ if ( item->enabled && TQt::PartialMatch == result ) {
+ partial = tocheck;
+ matchFound = TRUE;
+ }
+ item = accel->aitems.prev();
+ }
+ } else {
+ item = accel->aitems.last();
+ while( item ) {
+ if ( TQt::Identical == match( &pe, item, tocheck ) )
+ identicalDisabled = TRUE;
+ item = accel->aitems.prev();
+ }
+ }
+ }
+ accel = accels.next();
+ }
+ pe = TQKeyEvent( TQEvent::Accel, pe.key(), pe.ascii(), pe.state()&~ShiftButton, pe.text() );
+ } while ( hasShift-- && !matchFound && !identicalDisabled );
+
+#ifndef TQT_NO_STATUSBAR
+ maintqStatusBar = (TQStatusBar*) w->tqtopLevelWidget()->child( 0, "TQStatusBar" );
+#endif
+ if ( n < 0 ) { // no match found
+ currentState = partial.count() ? PartialMatch : NoMatch;
+#ifndef TQT_NO_STATUSBAR
+ // Only display message if we are, or were, in a partial match
+ if ( maintqStatusBar && (PartialMatch == currentState || intermediate.count() ) ) {
+ if ( currentState == TQt::PartialMatch ) {
+ maintqStatusBar->message( (TQString)partial + ", ...", 0 );
+ } else if (!identicalDisabled) {
+ TQString message = TQAccel::tr("%1, %2 not defined").
+ arg( (TQString)intermediate ).
+ arg( TQKeySequence::encodeString( e->key() | translateModifiers(e->state()) ) );
+ maintqStatusBar->message( message, 2000 );
+ // Since we're a NoMatch, reset the clash count
+ clash = -1;
+ } else {
+ maintqStatusBar->clear();
+ }
+ }
+#endif
+
+ bool eatKey = (PartialMatch == currentState || intermediate.count() );
+ intermediate = partial;
+ if ( eatKey )
+ e->accept();
+ return eatKey;
+ } else if ( n == 0 ) { // found exactly one match
+ clash = -1; // reset
+#ifndef TQT_NO_STATUSBAR
+ if ( currentState == TQt::PartialMatch && maintqStatusBar )
+ maintqStatusBar->clear();
+#endif
+ currentState = TQt::NoMatch; // Free sequence keylock
+ intermediate = TQKeySequence();
+ lastaccel->activate( lastitem );
+ e->accept();
+ return TRUE;
+ }
+
+ doclash: // found more than one match
+#ifndef TQT_NO_STATUSBAR
+ if ( !maintqStatusBar ) // if "goto doclash", we need to get statusbar again.
+ maintqStatusBar = (TQStatusBar*) w->tqtopLevelWidget()->child( 0, "TQStatusBar" );
+#endif
+
+ TQString message = TQAccel::tr( "Ambiguous \"%1\" not handled" ).arg( (TQString)tocheck );
+ if ( clash >= 0 && n > clash ) { // pick next match
+ intermediate = TQKeySequence();
+ currentState = TQt::NoMatch; // Free sequence keylock
+ clash++;
+#ifndef TQT_NO_STATUSBAR
+ if ( maintqStatusBar &&
+ !lastitem->signal &&
+ !(lastaccel->tqparent->tqreceivers( "activatedAmbiguously(int)" )) )
+ maintqStatusBar->message( message, 2000 );
+#endif
+ lastaccel->activateAmbiguously( lastitem );
+ } else { // start (or wrap) with the first matching
+ intermediate = TQKeySequence();
+ currentState = TQt::NoMatch; // Free sequence keylock
+ clash = 0;
+#ifndef TQT_NO_STATUSBAR
+ if ( maintqStatusBar &&
+ !firstitem->signal &&
+ !(firstaccel->tqparent->tqreceivers( "activatedAmbiguously(int)" )) )
+ maintqStatusBar->message( message, 2000 );
+#endif
+ firstaccel->activateAmbiguously( firstitem );
+ }
+ e->accept();
+ return TRUE;
+}
+
+TQAccelPrivate::TQAccelPrivate( TQAccel* p )
+ : tqparent( p )
+{
+ TQAccelManager::self()->registerAccel( this );
+ aitems.setAutoDelete( TRUE );
+ ignorewhatsthis = FALSE;
+}
+
+TQAccelPrivate::~TQAccelPrivate()
+{
+ TQAccelManager::self()->unregisterAccel( this );
+}
+
+static TQAccelItem *tqfind_id( TQAccelList &list, int id )
+{
+ register TQAccelItem *item = list.first();
+ while ( item && item->id != id )
+ item = list.next();
+ return item;
+}
+
+static TQAccelItem *tqfind_key( TQAccelList &list, const TQKeySequence &key )
+{
+ register TQAccelItem *item = list.first();
+ while ( item && !( item->key == key ) )
+ item = list.next();
+ return item;
+}
+
+/*!
+ Constructs a TQAccel object called \a name, with tqparent \a tqparent.
+ The accelerator operates on \a tqparent.
+*/
+
+TQAccel::TQAccel( TQWidget *tqparent, const char *name )
+ : TQObject( TQT_TQOBJECT(tqparent), name )
+{
+ d = new TQAccelPrivate( this );
+ d->enabled = TRUE;
+ d->watch = tqparent;
+#if defined(TQT_CHECK_NULL)
+ if ( !d->watch )
+ qWarning( "TQAccel: An accelerator must have a tqparent or a watch widget" );
+#endif
+}
+
+/*!
+ Constructs a TQAccel object called \a name, that operates on \a
+ watch, and is a child of \a tqparent.
+
+ This constructor is not needed for normal application programming.
+*/
+TQAccel::TQAccel( TQWidget* watch, TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name )
+{
+ d = new TQAccelPrivate( this );
+ d->enabled = TRUE;
+ d->watch = watch;
+#if defined(TQT_CHECK_NULL)
+ if ( !d->watch )
+ qWarning( "TQAccel: An accelerator must have a tqparent or a watch widget" );
+#endif
+}
+
+/*!
+ Constructs a TQAccel object called \a name, that operates on \a
+ watch, and is a child of \a tqparent.
+
+ This constructor is not needed for normal application programming.
+*/
+TQAccel::TQAccel( TQWidget* watch, TQWidget *tqparent, const char *name )
+ : TQObject( TQT_TQOBJECT(tqparent), name )
+{
+ d = new TQAccelPrivate( this );
+ d->enabled = TRUE;
+ d->watch = watch;
+#if defined(TQT_CHECK_NULL)
+ if ( !d->watch )
+ qWarning( "TQAccel: An accelerator must have a tqparent or a watch widget" );
+#endif
+}
+
+/*!
+ Destroys the accelerator object and frees all allocated resources.
+*/
+
+TQAccel::~TQAccel()
+{
+ delete d;
+}
+
+
+/*!
+ \fn void TQAccel::activated( int id )
+
+ This signal is emitted when an accelerator key is pressed. \a id
+ is a number that identifies this particular accelerator item.
+
+ \sa activatedAmbiguously()
+*/
+
+/*!
+ \fn void TQAccel::activatedAmbiguously( int id )
+
+ This signal is emitted when an accelerator key is pressed. \a id
+ is a number that identifies this particular accelerator item.
+
+ \sa activated()
+*/
+
+
+/*!
+ Returns TRUE if the accelerator is enabled; otherwise returns
+ FALSE.
+
+ \sa setEnabled(), isItemEnabled()
+*/
+
+bool TQAccel::isEnabled() const
+{
+ return d->enabled;
+}
+
+
+/*!
+ Enables the accelerator if \a enable is TRUE, or disables it if \a
+ enable is FALSE.
+
+ Individual keys can also be enabled or disabled using
+ setItemEnabled(). To work, a key must be an enabled item in an
+ enabled TQAccel.
+
+ \sa isEnabled(), setItemEnabled()
+*/
+
+void TQAccel::setEnabled( bool enable )
+{
+ d->enabled = enable;
+}
+
+
+/*!
+ Returns the number of accelerator items in this accelerator.
+*/
+
+uint TQAccel::count() const
+{
+ return d->aitems.count();
+}
+
+
+static int get_seq_id()
+{
+ static int seq_no = -2; // -1 is used as return value in tqfindKey()
+ return seq_no--;
+}
+
+/*!
+ Inserts an accelerator item and returns the item's identifier.
+
+ \a key is a key code and an optional combination of SHIFT, CTRL
+ and ALT. \a id is the accelerator item id.
+
+ If \a id is negative, then the item will be assigned a unique
+ negative identifier less than -1.
+
+ \code
+ TQAccel *a = new TQAccel( myWindow ); // create accels for myWindow
+ a->insertItem( CTRL + Key_P, 200 ); // Ctrl+P, e.g. to print document
+ a->insertItem( ALT + Key_X, 201 ); // Alt+X, e.g. to quit
+ a->insertItem( UNICODE_ACCEL + 'q', 202 ); // Unicode 'q', e.g. to quit
+ a->insertItem( Key_D ); // gets a unique negative id < -1
+ a->insertItem( CTRL + SHIFT + Key_P ); // gets a unique negative id < -1
+ \endcode
+*/
+
+int TQAccel::insertItem( const TQKeySequence& key, int id )
+{
+ if ( id == -1 )
+ id = get_seq_id();
+ d->aitems.insert( 0, new TQAccelItem(key,id) );
+ return id;
+}
+
+/*!
+ Removes the accelerator item with the identifier \a id.
+*/
+
+void TQAccel::removeItem( int id )
+{
+ if ( tqfind_id( d->aitems, id) )
+ d->aitems.remove();
+}
+
+
+/*!
+ Removes all accelerator items.
+*/
+
+void TQAccel::clear()
+{
+ d->aitems.clear();
+}
+
+
+/*!
+ Returns the key sequence of the accelerator item with identifier
+ \a id, or an invalid key sequence (0) if the id cannot be found.
+*/
+
+TQKeySequence TQAccel::key( int id )
+{
+ TQAccelItem *item = tqfind_id( d->aitems, id);
+ return item ? item->key : TQKeySequence( 0 );
+}
+
+
+/*!
+ Returns the identifier of the accelerator item with the key code
+ \a key, or -1 if the item cannot be found.
+*/
+
+int TQAccel::tqfindKey( const TQKeySequence& key ) const
+{
+ TQAccelItem *item = tqfind_key( d->aitems, key );
+ return item ? item->id : -1;
+}
+
+
+/*!
+ Returns TRUE if the accelerator item with the identifier \a id is
+ enabled. Returns FALSE if the item is disabled or cannot be found.
+
+ \sa setItemEnabled(), isEnabled()
+*/
+
+bool TQAccel::isItemEnabled( int id ) const
+{
+ TQAccelItem *item = tqfind_id( d->aitems, id);
+ return item ? item->enabled : FALSE;
+}
+
+
+/*!
+ Enables the accelerator item with the identifier \a id if \a
+ enable is TRUE, and disables item \a id if \a enable is FALSE.
+
+ To work, an item must be enabled and be in an enabled TQAccel.
+
+ \sa isItemEnabled(), isEnabled()
+*/
+
+void TQAccel::setItemEnabled( int id, bool enable )
+{
+ TQAccelItem *item = tqfind_id( d->aitems, id);
+ if ( item )
+ item->enabled = enable;
+}
+
+
+/*!
+ Connects the accelerator item \a id to the slot \a member of \a
+ receiver.
+
+ \code
+ a->connectItem( 201, mainView, TQT_SLOT(quit()) );
+ \endcode
+
+ Of course, you can also send a signal as \a member.
+
+ Normally accelerators are connected to Q_SLOTS which then receive
+ the \c activated(int id) signal with the id of the accelerator
+ item that was activated. If you choose to connect a specific
+ accelerator item using this function, the \c activated() signal is
+ emitted if the associated key sequence is pressed but no \c
+ activated(int id) signal is emitted.
+
+ \sa disconnectItem()
+*/
+
+bool TQAccel::connectItem( int id, const TQT_BASE_OBJECT_NAME *receiver, const char *member )
+{
+ TQAccelItem *item = tqfind_id( d->aitems, id);
+ if ( item ) {
+ if ( !item->signal ) {
+ item->signal = new TQSignal;
+ TQ_CHECK_PTR( item->signal );
+ }
+ return item->signal->connect( receiver, member );
+ }
+ return FALSE;
+}
+
+/*!
+ Disconnects an accelerator item with id \a id from the function
+ called \a member in the \a receiver object.
+
+ \sa connectItem()
+*/
+
+bool TQAccel::disconnectItem( int id, const TQT_BASE_OBJECT_NAME *receiver,
+ const char *member )
+{
+ TQAccelItem *item = tqfind_id( d->aitems, id);
+ if ( item && item->signal )
+ return item->signal->disconnect( receiver, member );
+ return FALSE;
+}
+
+void TQAccelPrivate::activate( TQAccelItem* item )
+{
+#ifndef TQT_NO_WHATSTHIS
+ if ( TQWhatsThis::inWhatsThisMode() && !ignorewhatsthis ) {
+ TQWhatsThis::leaveWhatsThisMode( item->whatsthis );
+ return;
+ }
+#endif
+ if ( item->signal )
+ item->signal->activate();
+ else
+ emit tqparent->activated( item->id );
+}
+
+void TQAccelPrivate::activateAmbiguously( TQAccelItem* item )
+{
+ if ( item->signal )
+ item->signal->activate();
+ else
+ emit tqparent->activatedAmbiguously( item->id );
+}
+
+
+/*!
+ Returns the shortcut key sequence for \a str, or an invalid key
+ sequence (0) if \a str has no shortcut sequence.
+
+ For example, shortcutKey("E&amp;xit") returns ALT+Key_X,
+ shortcutKey("&amp;Quit") returns ALT+Key_Q and shortcutKey("Quit")
+ returns 0. (In code that does not inherit the TQt namespace class,
+ you must write e.g. TQt::ALT+TQt::Key_Q.)
+
+ We provide a \link accelerators.html list of common accelerators
+ \endlink in English. At the time of writing, Microsoft and Open
+ Group do not appear to have issued equivalent recommendations for
+ other languages.
+*/
+
+TQKeySequence TQAccel::shortcutKey( const TQString &str )
+{
+ if(qt_accel_no_shortcuts)
+ return TQKeySequence();
+
+ int p = 0;
+ while ( p >= 0 ) {
+ p = str.tqfind( '&', p ) + 1;
+ if ( p <= 0 || p >= (int)str.length() )
+ return 0;
+ if ( str[p] != '&' ) {
+ TQChar c = str[p];
+ if ( c.isPrint() ) {
+ char ltr = c.upper().latin1();
+ if ( ltr >= (char)Qt::Key_A && ltr <= (char)Qt::Key_Z )
+ c = ltr;
+ else
+ c = c.lower();
+ return TQKeySequence( c.tqunicode() + Qt::ALT + Qt::UNICODE_ACCEL );
+ }
+ }
+ p++;
+ }
+ return TQKeySequence();
+}
+
+/*! \obsolete
+
+ Creates an accelerator string for the key \a k.
+ For instance CTRL+Key_O gives "Ctrl+O". The "Ctrl" etc.
+ are translated (using TQObject::tr()) in the "TQAccel" context.
+
+ The function is superfluous. Cast the TQKeySequence \a k to a
+ TQString for the same effect.
+*/
+TQString TQAccel::keyToString( TQKeySequence k )
+{
+ return (TQString) k;
+}
+
+/*!\obsolete
+
+ Returns an accelerator code for the string \a s. For example
+ "Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl",
+ "Shift", "Alt" are recognized, as well as their translated
+ equivalents in the "TQAccel" context (using TQObject::tr()). Returns 0
+ if \a s is not recognized.
+
+ This function is typically used with \link TQObject::tr() tr
+ \endlink(), so that accelerator keys can be tqreplaced in
+ translations:
+
+ \code
+ TQPopupMenu *file = new TQPopupMenu( this );
+ file->insertItem( p1, tr("&Open..."), this, TQT_SLOT(open()),
+ TQAccel::stringToKey(tr("Ctrl+O", "File|Open")) );
+ \endcode
+
+ Notice the \c "File|Open" translator comment. It is by no means
+ necessary, but it provides some context for the human translator.
+
+
+ The function is superfluous. Construct a TQKeySequence from the
+ string \a s for the same effect.
+
+ \sa TQObject::tr()
+ \link i18n.html Internationalization with TQt \endlink
+*/
+TQKeySequence TQAccel::stringToKey( const TQString & s )
+{
+ return TQKeySequence( s );
+}
+
+
+/*!
+ Sets a What's This help text for the accelerator item \a id to \a
+ text.
+
+ The text will be shown when the application is in What's This mode
+ and the user hits the accelerator key.
+
+ To set What's This help on a menu item (with or without an
+ accelerator key), use TQMenuData::setWhatsThis().
+
+ \sa whatsThis(), TQWhatsThis::inWhatsThisMode(),
+ TQMenuData::setWhatsThis(), TQAction::setWhatsThis()
+*/
+void TQAccel::setWhatsThis( int id, const TQString& text )
+{
+
+ TQAccelItem *item = tqfind_id( d->aitems, id);
+ if ( item )
+ item->whatsthis = text;
+}
+
+/*!
+ Returns the What's This help text for the specified item \a id or
+ TQString::null if no text has been specified.
+
+ \sa setWhatsThis()
+*/
+TQString TQAccel::whatsThis( int id ) const
+{
+
+ TQAccelItem *item = tqfind_id( d->aitems, id);
+ return item? item->whatsthis : TQString::null;
+}
+
+/*!\internal */
+void TQAccel::setIgnoreWhatsThis( bool b)
+{
+ d->ignorewhatsthis = b;
+}
+
+/*!\internal */
+bool TQAccel::ignoreWhatsThis() const
+{
+ return d->ignorewhatsthis;
+}
+
+
+/*!
+
+\page accelerators.html
+
+\title Standard Accelerator Keys
+
+Applications invariably need to define accelerator keys for actions.
+TQt fully supports accelerators, for example with \l TQAccel::shortcutKey().
+
+Here are Microsoft's recommendations for accelerator keys, with
+comments about the Open Group's recommendations where they exist
+and differ. For most commands, the Open Group either has no advice or
+agrees with Microsoft.
+
+The emboldened letter plus Alt is Microsoft's recommended choice, and
+we recommend supporting it. For an Apply button, for example, we
+recommend TQButton::setText( \link TQWidget::tr() tr \endlink("&amp;Apply") );
+
+If you have conflicting commands (e.g. About and Apply buttons in the
+same dialog), you must decide for yourself.
+
+\list
+\i <b><u>A</u></b>bout
+\i Always on <b><u>T</u></b>op
+\i <b><u>A</u></b>pply
+\i <b><u>B</u></b>ack
+\i <b><u>B</u></b>rowse
+\i <b><u>C</u></b>lose (CDE: Alt+F4; Alt+F4 is "close window" in Windows)
+\i <b><u>C</u></b>opy (CDE: Ctrl+C, Ctrl+Insert)
+\i <b><u>C</u></b>opy Here
+\i Create <b><u>S</u></b>hortcut
+\i Create <b><u>S</u></b>hortcut Here
+\i Cu<b><u>t</u></b>
+\i <b><u>D</u></b>elete
+\i <b><u>E</u></b>dit
+\i <b><u>E</u></b>xit (CDE: E<b><u>x</u></b>it)
+\i <b><u>E</u></b>xplore
+\i <b><u>F</u></b>ile
+\i <b><u>F</u></b>ind
+\i <b><u>H</u></b>elp
+\i Help <b><u>T</u></b>opics
+\i <b><u>H</u></b>ide
+\i <b><u>I</u></b>nsert
+\i Insert <b><u>O</u></b>bject
+\i <b><u>L</u></b>ink Here
+\i Ma<b><u>x</u></b>imize
+\i Mi<b><u>n</u></b>imize
+\i <b><u>M</u></b>ove
+\i <b><u>M</u></b>ove Here
+\i <b><u>N</u></b>ew
+\i <b><u>N</u></b>ext
+\i <b><u>N</u></b>o
+\i <b><u>O</u></b>pen
+\i Open <b><u>W</u></b>ith
+\i Page Set<b><u>u</u></b>p
+\i <b><u>P</u></b>aste
+\i Paste <b><u>L</u></b>ink
+\i Paste <b><u>S</u></b>hortcut
+\i Paste <b><u>S</u></b>pecial
+\i <b><u>P</u></b>ause
+\i <b><u>P</u></b>lay
+\i <b><u>P</u></b>rint
+\i <b><u>P</u></b>rint Here
+\i P<b><u>r</u></b>operties
+\i <b><u>Q</u></b>uick View
+\i <b><u>R</u></b>edo (CDE: Ctrl+Y, Shift+Alt+Backspace)
+\i <b><u>R</u></b>epeat
+\i <b><u>R</u></b>estore
+\i <b><u>R</u></b>esume
+\i <b><u>R</u></b>etry
+\i <b><u>R</u></b>un
+\i <b><u>S</u></b>ave
+\i Save <b><u>A</u></b>s
+\i Select <b><u>A</u></b>ll
+\i Se<b><u>n</u></b>d To
+\i <b><u>S</u></b>how
+\i <b><u>S</u></b>ize
+\i S<b><u>p</u></b>lit
+\i <b><u>S</u></b>top
+\i <b><u>U</u></b>ndo (CDE: Ctrl+Z or Alt+Backspace)
+\i <b><u>V</u></b>iew
+\i <b><u>W</u></b>hat's This?
+\i <b><u>W</u></b>indow
+\i <b><u>Y</u></b>es
+\endlist
+
+There are also a lot of other keys and actions (that use other
+modifier keys than Alt). See the Microsoft and The Open Group
+documentation for details.
+
+The \link http://www.amazon.com/exec/obidos/ASIN/0735605661/trolltech/t
+Microsoft book \endlink has ISBN 0735605661. The corresponding Open Group
+book is very hard to tqfind, rather expensive and we cannot recommend
+it. However, if you really want it, OGPubs@opengroup.org might be able
+to help. Ask them for ISBN 1859121047.
+
+*/
+
+/*! \obsolete serves no purpose anymore */
+void TQAccel::repairEventFilter() {}
+/*! \obsolete serves no purpose anymore */
+bool TQAccel::eventFilter( TQObject *, TQEvent * ) { return FALSE; }
+#endif // TQT_NO_ACCEL
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqaccel.h b/tqtinterface/qt4/src/kernel/tqaccel.h
new file mode 100644
index 0000000..d60a3b8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqaccel.h
@@ -0,0 +1,238 @@
+#include "tqtglobaldefines.h"
+
+#if 0
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TQACCEL_H
+#define TQACCEL_H
+
+#include <QtCore/qobject.h>
+#include <QtGui/qkeysequence.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Qt3SupportLight)
+
+class TQAccelPrivate;
+
+class Q_COMPAT_EXPORT TQAccel : public TQT_BASE_OBJECT_NAME // accelerator class
+{
+ Q_OBJECT
+public:
+ TQAccel( QWidget *parent, const char *name=0 );
+ TQAccel( QWidget* watch, TQT_BASE_OBJECT_NAME *parent, const char *name=0 );
+ ~TQAccel();
+
+ bool isEnabled() const;
+ void setEnabled( bool );
+
+ uint count() const;
+
+ int insertItem( const QKeySequence& key, int id=-1);
+ void removeItem( int id );
+ void clear();
+
+ QKeySequence key( int id );
+ int findKey( const QKeySequence& key ) const;
+
+ bool isItemEnabled( int id ) const;
+ void setItemEnabled( int id, bool enable );
+
+ bool connectItem( int id, const TQT_BASE_OBJECT_NAME *receiver, const char* member );
+ bool disconnectItem( int id, const TQT_BASE_OBJECT_NAME *receiver, const char* member );
+
+ void repairEventFilter() {}
+
+ void setWhatsThis( int id, const QString& );
+ QString whatsThis( int id ) const;
+ void setIgnoreWhatsThis( bool );
+ bool ignoreWhatsThis() const;
+
+ static QKeySequence shortcutKey( const QString & );
+ static QString keyToString(QKeySequence k );
+ static QKeySequence stringToKey( const QString & );
+
+Q_SIGNALS:
+ void activated( int id );
+ void activatedAmbiguously( int id );
+
+private:
+ TQAccelPrivate * d;
+
+private:
+ Q_DISABLE_COPY(TQAccel)
+ friend class TQAccelPrivate;
+ friend class TQAccelManager;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // TQACCEL_H
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Definition of TQAccel class
+**
+** Created : 950419
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQACCEL_H
+#define TQACCEL_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqkeysequence.h"
+#include "tqapplication.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_ACCEL
+
+class TQAccelPrivate;
+
+class TQ_EXPORT TQAccel : public TQObject // accelerator class
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQAccel( TQWidget *tqparent, const char *name=0 );
+ TQAccel( TQWidget* watch, TQObject *tqparent, const char *name=0 );
+ TQAccel( TQWidget* watch, TQWidget *tqparent, const char *name=0 );
+ ~TQAccel();
+
+ bool isEnabled() const;
+ void setEnabled( bool );
+
+ uint count() const;
+
+ int insertItem( const TQKeySequence& key, int id=-1);
+ void removeItem( int id );
+ void clear();
+
+ TQKeySequence key( int id );
+ int tqfindKey( const TQKeySequence& key ) const;
+
+ bool isItemEnabled( int id ) const;
+ void setItemEnabled( int id, bool enable );
+
+ bool connectItem( int id, const TQT_BASE_OBJECT_NAME *receiver, const char* member );
+ bool disconnectItem( int id, const TQT_BASE_OBJECT_NAME *receiver, const char* member );
+
+ void repairEventFilter();
+
+ void setWhatsThis( int id, const TQString& );
+ TQString whatsThis( int id ) const;
+ void setIgnoreWhatsThis( bool );
+ bool ignoreWhatsThis() const;
+
+ static TQKeySequence shortcutKey( const TQString & );
+ static TQString keyToString(TQKeySequence k );
+ static TQKeySequence stringToKey( const TQString & );
+
+Q_SIGNALS:
+ void activated( int id );
+ void activatedAmbiguously( int id );
+
+protected:
+ bool eventFilter( TQObject *, TQEvent * );
+
+private:
+ TQAccelPrivate * d;
+
+private:
+#if defined(TQ_DISABLE_COPY)
+ TQAccel( const TQAccel & );
+ TQAccel &operator=( const TQAccel & );
+#endif
+ friend class TQAccelPrivate;
+ friend class TQAccelManager;
+
+public:
+ static bool sendSpontaneousKeyEvent( TQObject *receiver, TQKeyEvent *event );
+};
+
+inline bool TQAccel::sendSpontaneousKeyEvent( TQObject *receiver, TQKeyEvent *event )
+{ return tqApp ? tqApp->notify( receiver, event ) : FALSE; }
+
+#endif // TQT_NO_ACCEL
+#endif // TQACCEL_H
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqaccessible.cpp b/tqtinterface/qt4/src/kernel/tqaccessible.cpp
new file mode 100644
index 0000000..ba19cf7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqaccessible.cpp
@@ -0,0 +1,719 @@
+/****************************************************************************
+**
+** Implementation of TQAccessible and TQAccessibleObject classes
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqaccessible.h"
+
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+
+#include "tqptrdict.h"
+#include "tqmetaobject.h"
+#include <private/tqpluginmanager_p.h>
+#include "tqapplication.h"
+#include <stdlib.h>
+
+/*!
+ \class TQAccessible tqaccessible.h
+ \brief The TQAccessible class provides enums and static functions
+ relating to accessibility.
+
+ \ingroup misc
+
+ Accessibility clients use implementations of the
+ TQAccessibleInterface to read the information an accessible object
+ exposes, or to call functions to manipulate the accessible object.
+
+\omit
+ TQt provides implementations of the TQAccessibleInterface for most
+ widget classes in a plugin. This plugin is located in the \e
+ accessibility subdirectory of the plugins installation directory.
+ The default installation directory for plugins is \c INSTALL/plugins,
+ where \c INSTALL is the directory where TQt was installed. Calling
+ queryAccessibleInterface( TQObject *object, TQAccessibleInterface
+ **iface ) will ask all plugins located in this directory for an
+ implementation that exposes the information for objects of the
+ class of \e object.
+
+ To make a TQt application accessible you have to distribute the
+ accessibility plugin provded with TQt together with your
+ application. Simply add the plugins created in
+ INSTALL/plugins/accessibility to your distribution process. Use \l
+ TQApplication::addLibraryPath() to specify a plugin directory for
+ your application, and copy the files into an \e accessibility
+ subdirectory of one of those plugin directories. TQt's
+ accessibility framework will load the plugins upon request and use
+ the implementations provided to expose an object's accessibility
+ information.
+\endomit
+
+ See the \link plugins-howto.html plugin documentation \endlink for
+ more details about how to redistribute TQt plugins.
+*/
+
+/*!
+ \enum TQAccessible::State
+
+ This enum type defines bitflags that can be combined to indicate
+ the state of the accessible object. The values are:
+
+ \value Normal
+ \value Unavailable
+ \value Selected
+ \value Focused
+ \value Pressed
+ \value Checked
+ \value Mixed
+ \value ReadOnly
+ \value HotTracked
+ \value Default
+ \value Expanded
+ \value Collapsed
+ \value Busy
+ \value Floating
+ \value Marqueed
+ \value Animated
+ \value Invisible
+ \value Offscreen
+ \value Sizeable
+ \value Moveable
+ \value SelfVoicing
+ \value Focusable
+ \value Selectable
+ \value Linked
+ \value Traversed
+ \value MultiSelectable
+ \value ExtSelectable
+ \value AlertLow
+ \value AlertMedium
+ \value AlertHigh
+ \value Protected
+ \value Valid
+*/
+
+/*!
+ \enum TQAccessible::Event
+
+ This enum type defines event types when the state of the
+ accessible object has changed. The event types are:
+
+ \value SoundPlayed
+ \value Alert
+ \value ForegroundChanged
+ \value MenuStart
+ \value MenuEnd
+ \value PopupMenuStart
+ \value PopupMenuEnd
+ \value ContextHelpStart
+ \value ContextHelpEnd
+ \value DragDropStart
+ \value DragDropEnd
+ \value DialogStart
+ \value DialogEnd
+ \value ScrollingStart
+ \value ScrollingEnd
+ \value ObjectCreated
+ \value ObjectDestroyed
+ \value ObjectShow
+ \value ObjectHide
+ \value ObjectReorder
+ \value Focus
+ \value Selection
+ \value SelectionAdd
+ \value SelectionRemove
+ \value SelectionWithin
+ \value StateChanged
+ \value LocationChanged
+ \value NameChanged
+ \value DescriptionChanged
+ \value ValueChanged
+ \value ParentChanged
+ \value HelpChanged
+ \value DefaultActionChanged
+ \value AcceleratorChanged
+ \value MenuCommand
+*/
+
+/*!
+ \enum TQAccessible::Role
+
+ This enum defines a number of roles an accessible object can have.
+ The roles are:
+
+ \value NoRole
+ \value TitleBar
+ \value MenuBar
+ \value ScrollBar
+ \value Grip
+ \value Sound
+ \value Cursor
+ \value Caret
+ \value AlertMessage
+ \value Window
+ \value Client
+ \value PopupMenu
+ \value MenuItem
+ \value ToolTip
+ \value Application
+ \value Document
+ \value Pane
+ \value Chart
+ \value Dialog
+ \value Border
+ \value Grouping
+ \value Separator
+ \value ToolBar
+ \value tqStatusBar
+ \value Table
+ \value ColumnHeader
+ \value RowHeader
+ \value Column
+ \value Row
+ \value Cell
+ \value Link
+ \value HelpBalloon
+ \value Character
+ \value List
+ \value ListItem
+ \value Outline
+ \value OutlineItem
+ \value PageTab
+ \value PropertyPage
+ \value Indicator
+ \value Graphic
+ \value StaticText
+ \value EditableText
+ \value PushButton
+ \value CheckBox
+ \value RadioButton
+ \value ComboBox
+ \value DropLest
+ \value ProgressBar
+ \value Dial
+ \value HotkeyField
+ \value Slider
+ \value SpinBox
+ \value Diagram
+ \value Animation
+ \value Equation
+ \value ButtonDropDown
+ \value ButtonMenu
+ \value ButtonDropGrid
+ \value Whitespace
+ \value PageTabList
+ \value Clock
+*/
+
+/*!
+ \enum TQAccessible::NavDirection
+
+ This enum specifies which item to move to when navigating.
+
+ \value NavUp sibling above
+ \value NavDown sibling below
+ \value NavLeft left sibling
+ \value NavRight right sibling
+ \value NavNext next sibling
+ \value NavPrevious previous sibling
+ \value NavFirstChild first child
+ \value NavLastChild last child
+ \value NavFocusChild child with focus
+*/
+
+/*!
+ \enum TQAccessible::Text
+
+ This enum specifies string information that an accessible object
+ returns.
+
+ \value Name The name of the object
+ \value Description A short text describing the object
+ \value Value The value of the object
+ \value Help A longer text giving information about how
+ to use the object
+ \value DefaultAction The default method to interact with the object
+ \value Accelerator The keyboard shortcut that executes the
+ default action
+*/
+
+/*!
+ \fn static void TQAccessible::updateAccessibility( TQObject *object, int control, Event reason )
+
+ Notifies accessibility clients about a change in \a object's
+ accessibility information.
+
+ \a reason specifies the cause of the change, for example,
+ ValueChange when the position of a slider has been changed. \a
+ control is the ID of the child element that has changed. When \a
+ control is 0, the object itself has changed.
+
+ Call this function whenever the state of your accessible object or
+ one of it's sub-elements has been changed either programmatically
+ (e.g. by calling TQLabel::setText()) or by user interaction.
+
+ If there are no accessibility tools listening to this event, the
+ performance penalty for calling this function is minor, but if determining
+ the parameters of the call is expensive you can use isActive() to
+ avoid unnecessary performance penalties if no client is listening.
+*/
+
+static TQPluginManager<TQAccessibleFactoryInterface> *qAccessibleManager = 0;
+
+class AccessibleCache : public TQObject, public TQPtrDict<TQAccessibleInterface>
+{
+ TQ_OBJECT
+public:
+ AccessibleCache()
+ : TQPtrDict<TQAccessibleInterface>(73)
+ {
+ }
+
+ void addObject(TQObject *object, TQAccessibleInterface *iface)
+ {
+ insert(object, iface);
+ connect(object, TQT_SIGNAL(destroyed(TQObject*)), this, TQT_SLOT(removeObject(TQObject*)));
+ }
+
+public Q_SLOTS:
+ void removeObject(TQObject *object);
+};
+
+#include "tqaccessible.tqmoc"
+
+static AccessibleCache *qAccessibleInterface = 0;
+static bool cleanupAdded = FALSE;
+
+static void qAccessibleCleanup()
+{
+ if ( qAccessibleInterface && qAccessibleInterface->count() && qAccessibleManager )
+ qAccessibleManager->setAutoUnload( FALSE );
+
+ delete qAccessibleInterface;
+ qAccessibleInterface = 0;
+ delete qAccessibleManager;
+ qAccessibleManager = 0;
+}
+
+#ifdef TQ_WS_MAC
+TQObject *TQAccessible::queryAccessibleObject(TQAccessibleInterface *o)
+{
+ if(qAccessibleInterface) {
+ for(TQPtrDictIterator<TQAccessibleInterface> it(*qAccessibleInterface); it.current(); ++it) {
+ if(it.current() == o)
+ return (TQObject*)it.currentKey();
+ }
+ }
+ return NULL;
+}
+#endif
+
+void AccessibleCache::removeObject(TQObject *object)
+{
+ if (!object)
+ return;
+
+ remove(object);
+ if (!count()) {
+ delete this;
+ qAccessibleInterface = 0;
+ }
+}
+
+
+/*!
+ Sets \a iface to point to the implementation of the
+ TQAccessibleInterface for \a object, and returns \c TQS_OK if
+ successfull, or sets \a iface to 0 and returns \c TQE_NOCOMPONENT if
+ no accessibility implementation for \a object exists.
+
+ The function uses the \link TQObject::className() classname
+ \endlink of \a object to tqfind a suitable implementation. If no
+ implementation for the object's class is available the function
+ tries to tqfind an implementation for the object's tqparent class.
+
+ This function is called to answer an accessibility client's
+ request for object information. You should never need to call this
+ function yourself.
+*/
+TQRESULT TQAccessible::queryAccessibleInterface( TQObject *object, TQAccessibleInterface **iface )
+{
+ *iface = 0;
+ if ( !object )
+ return TQE_INVALIDARG;
+
+ if ( qAccessibleInterface ) {
+ *iface = qAccessibleInterface->tqfind( object );
+ if ( *iface ) {
+ (*iface)->addRef();
+ return TQS_OK;
+ }
+ }
+
+ if ( !qAccessibleManager ) {
+ qAccessibleManager = new TQPluginManager<TQAccessibleFactoryInterface>( IID_TQAccessibleFactory, TQApplication::libraryPaths(), "/accessible" );
+ if ( !cleanupAdded ) {
+ qAddPostRoutine( qAccessibleCleanup );
+ cleanupAdded = TRUE;
+ }
+ }
+
+ TQInterfacePtr<TQAccessibleFactoryInterface> factory = 0;
+ TQMetaObject *mo = object->tqmetaObject();
+ while ( mo ) {
+ qAccessibleManager->queryInterface( mo->className(), &factory );
+ if ( factory )
+ break;
+ mo = mo->superClass();
+ }
+ if ( factory )
+ return factory->createAccessibleInterface( mo->className(), object, iface );
+
+ return TQE_NOCOMPONENT;
+}
+
+/*!
+ Returns TRUE if an accessibility implementation has been requested,
+ during the runtime of the application, otherwise returns FALSE.
+
+ Use this function to prevent potentially expensive notifications via
+ updateAccessibility().
+
+ \omit
+ TQListView uses this function to prevent index-lookups for item based
+ notifications.
+ \endomit
+*/
+bool TQAccessible::isActive()
+{
+ return qAccessibleManager != 0;
+}
+
+/*!
+ \class TQAccessibleInterface tqaccessible.h
+ \brief The TQAccessibleInterface class defines an interface that exposes information about accessible objects.
+
+ \ingroup misc
+*/
+
+/*!
+ \fn bool TQAccessibleInterface::isValid() const
+
+ Returns TRUE if all the data necessary to use this interface
+ implementation is valid (e.g. all pointers are non-null),
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn int TQAccessibleInterface::childCount() const
+
+ Returns the number of tqchildren that belong to this object. A child
+ can provide accessibility information on it's own (e.g. a child
+ widget), or be a sub-element of this accessible object.
+
+ All objects provide this information.
+
+ \sa queryChild()
+*/
+
+/*!
+ \fn TQRESULT TQAccessibleInterface::queryChild( int control, TQAccessibleInterface **iface ) const
+
+ Sets \a iface to point to the implementation of the
+ TQAccessibleInterface for the child specified with \a control. If
+ the child doesn't provide accessibility information on it's own,
+ the value of \a iface is set to 0. For those elements, this
+ object is responsible for exposing the child's properties.
+
+ All objects provide this information.
+
+ \sa childCount(), queryParent()
+*/
+
+/*!
+ \fn TQRESULT TQAccessibleInterface::queryParent( TQAccessibleInterface **iface ) const
+
+ Sets \a iface to point to the implementation of the
+ TQAccessibleInterface for the tqparent object, or to 0 if there is
+ no such implementation or object.
+
+ All objects provide this information.
+
+ \sa queryChild()
+*/
+
+/*!
+ \fn int TQAccessibleInterface::controlAt( int x, int y ) const
+
+ Returns the ID of the child that tqcontains the screen coordinates
+ (\a x, \a y). This function returns 0 if the point is positioned
+ on the object itself. If the tested point is outside the
+ boundaries of the object this function returns -1.
+
+ All visual objects provide this information.
+*/
+
+/*!
+ \fn TQRect TQAccessibleInterface::rect( int control ) const
+
+ Returns the location of the child specified with \a control in
+ screen coordinates. This function returns the location of the
+ object itself if \a control is 0.
+
+ All visual objects provide this information.
+*/
+
+/*!
+ \fn int TQAccessibleInterface::navigate( NavDirection direction, int startControl ) const
+
+ This function traverses to another object, or to a sub-element of
+ the current object. \a direction specifies in which direction to
+ navigate, and \a startControl specifies the start point of the
+ navigation, which is either 0 if the navigation starts at the
+ object itself, or an ID of one of the object's sub-elements.
+
+ The function returns the ID of the sub-element located in the \a
+ direction specified. If there is nothing in the navigated \a
+ direction, this function returns -1.
+
+ All objects support navigation.
+*/
+
+/*!
+ \fn TQString TQAccessibleInterface::text( Text t, int control ) const
+
+ Returns a string property \a t of the child object specified by \a
+ control, or the string property of the object itself if \a control
+ is 0.
+
+ The \e Name is a string used by clients to identify, tqfind or
+ announce an accessible object for the user. All objects must have
+ a name that is unique within their container.
+
+ An accessible object's \e Description provides textual information
+ about an object's visual appearance. The description is primarily
+ used to provide greater context for low-vision or blind users, but
+ is also used for context searching or other applications. Not all
+ objects have a description. An "OK" button would not need a
+ description, but a toolbutton that shows a picture of a smiley
+ would.
+
+ The \e Value of an accessible object represents visual information
+ contained by the object, e.g. the text in a line edit. Usually,
+ the value can be modified by the user. Not all objects have a
+ value, e.g. static text labels don't, and some objects have a
+ state that already is the value, e.g. toggle buttons.
+
+ The \e Help text provides information about the function and
+ usage of an accessible object. Not all objects provide this
+ information.
+
+ An accessible object's \e DefaultAction describes the object's
+ primary method of manipulation, and should be a verb or a short
+ phrase, e.g. "Press" for a button.
+
+ The accelerator is a keyboard shortcut that activates the default
+ action of the object. A keyboard shortcut is the underlined
+ character in the text of a menu, menu item or control, and is
+ either the character itself, or a combination of this character
+ and a modifier key like ALT, CTRL or SHIFT. Command controls like
+ tool buttons also have shortcut keys and usually display them in
+ their tooltip.
+
+ \sa role(), state(), selection()
+*/
+
+/*!
+ \fn void TQAccessibleInterface::setText( Text t, int control, const TQString &text )
+
+ Sets the text property \a t of the child object \a control to \a
+ text. If \a control is 0, the text property of the object itself
+ is set.
+*/
+
+/*!
+ \fn TQAccessible::Role TQAccessibleInterface::role( int control ) const
+
+ Returns the role of the object if \a control is 0, or the role of
+ the object's sub-element with ID \a control. The role of an object
+ is usually static. All accessible objects have a role.
+
+ \sa text(), state(), selection()
+*/
+
+/*!
+ \fn TQAccessible::State TQAccessibleInterface::state( int control ) const
+
+ Returns the current state of the object if \a control is 0, or the
+ state of the object's sub-element element with ID \a control. All
+ objects have a state.
+
+ \sa text(), role(), selection()
+*/
+
+/*!
+ \fn TQMemArray<int> TQAccessibleInterface::selection() const
+
+ Returns the list of all the element IDs that are selected.
+
+ \sa text(), role(), state()
+*/
+
+/*!
+ \fn bool TQAccessibleInterface::doDefaultAction( int control )
+
+ Calling this function performs the default action of the child
+ object specified by \a control, or the default action of the
+ object itself if \a control is 0.
+*/
+
+/*!
+ \fn bool TQAccessibleInterface::setFocus( int control )
+
+ Gives the focus to the child object specified by \a control, or to
+ the object itself if \a control is 0.
+
+ Returns TRUE if the focus could be set; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQAccessibleInterface::setSelected( int control, bool on, bool extend )
+
+ Sets the selection of the child object with ID \a control to \a
+ on. If \a extend is TRUE, all child elements between the focused
+ item and the specified child object have their selection set to \a
+ on.
+
+ Returns TRUE if the selection could be set; otherwise returns
+ FALSE.
+
+ \sa setFocus(), clearSelection()
+*/
+
+/*!
+ \fn void TQAccessibleInterface::clearSelection()
+
+ Removes any selection from the object.
+
+ \sa setSelected()
+*/
+
+
+
+/*!
+ \class TQAccessibleObject tqaccessible.h
+ \brief The TQAccessibleObject class implements parts of the
+ TQAccessibleInterface for TQObjects.
+
+ \ingroup misc
+
+ This class is mainly provided for convenience. All subclasses of
+ the TQAccessibleInterface should use this class as the base class.
+*/
+
+/*!
+ Creates a TQAccessibleObject for \a object.
+*/
+TQAccessibleObject::TQAccessibleObject( TQObject *object )
+: object_(object)
+{
+ if ( !qAccessibleInterface ) {
+ qAccessibleInterface = new AccessibleCache;
+ if ( !cleanupAdded ) {
+ qAddPostRoutine( qAccessibleCleanup );
+ cleanupAdded = TRUE;
+ }
+ }
+
+ qAccessibleInterface->addObject(object, this);
+}
+
+/*!
+ Destroys the TQAccessibleObject.
+
+ This only happens when a call to release() decrements the internal
+ reference counter to zero.
+*/
+TQAccessibleObject::~TQAccessibleObject()
+{
+ if ( qAccessibleInterface ) {
+ qAccessibleInterface->removeObject(object_);
+ if ( !qAccessibleInterface->count() ) {
+ delete qAccessibleInterface;
+ qAccessibleInterface = 0;
+ }
+ }
+}
+
+/*!
+ \reimp
+*/
+TQRESULT TQAccessibleObject::queryInterface( const TQUuid &uuid, TQUnknownInterface **iface )
+{
+ *iface = 0;
+ if ( uuid == IID_TQAccessible )
+ *iface = (TQAccessibleInterface*)this;
+ else if ( uuid == IID_TQUnknown )
+ *iface = (TQUnknownInterface*)this;
+ else
+ return TQE_NOINTERFACE;
+
+ (*iface)->addRef();
+ return TQS_OK;
+}
+
+/*!
+ Returns the TQObject for which this TQAccessibleInterface
+ implementation provides information. Use isValid() to make sure
+ the object pointer is safe to use.
+*/
+TQObject *TQAccessibleObject::object() const
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( !isValid() )
+ qWarning( "TQAccessibleInterface is invalid. Crash pending..." );
+#endif
+ return object_;
+}
+
+/*!
+ \reimp
+*/
+bool TQAccessibleObject::isValid() const
+{
+ return !object_.isNull();
+}
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqaccessible.h b/tqtinterface/qt4/src/kernel/tqaccessible.h
new file mode 100644
index 0000000..c476743
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqaccessible.h
@@ -0,0 +1,295 @@
+/****************************************************************************
+**
+** Definition of TQAccessible and TQAccessibleObject classes
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQACCESSIBLE_H
+#define TQACCESSIBLE_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include <private/tqcom_p.h>
+#include "tqrect.h"
+#include "tqguardedptr.h"
+#include "tqmemarray.h"
+#endif // TQT_H
+
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+
+struct TQAccessibleInterface;
+
+class TQ_EXPORT TQAccessible
+{
+private:
+#ifdef TQ_WS_MAC
+ static TQMAC_PASCAL OStqStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *);
+ static TQObject *queryAccessibleObject(TQAccessibleInterface *);
+#endif
+public:
+ enum Event {
+ SoundPlayed = 0x0001,
+ Alert = 0x0002,
+ ForegroundChanged = 0x0003,
+ MenuStart = 0x0004,
+ MenuEnd = 0x0005,
+ PopupMenuStart = 0x0006,
+ PopupMenuEnd = 0x0007,
+ ContextHelpStart = 0x000C,
+ ContextHelpEnd = 0x000D,
+ DragDropStart = 0x000E,
+ DragDropEnd = 0x000F,
+ DialogStart = 0x0010,
+ DialogEnd = 0x0011,
+ ScrollingStart = 0x0012,
+ ScrollingEnd = 0x0013,
+
+ MenuCommand = 0x0018,
+
+ ObjectCreated = 0x8000,
+ ObjectDestroyed = 0x8001,
+ ObjectShow = 0x8002,
+ ObjectHide = 0x8003,
+ ObjectReorder = 0x8004,
+ Focus = 0x8005,
+ Selection = 0x8006,
+ SelectionAdd = 0x8007,
+ SelectionRemove = 0x8008,
+ SelectionWithin = 0x8009,
+ StateChanged = 0x800A,
+ LocationChanged = 0x800B,
+ NameChanged = 0x800C,
+ DescriptionChanged = 0x800D,
+ ValueChanged = 0x800E,
+ ParentChanged = 0x800F,
+ HelpChanged = 0x80A0,
+ DefaultActionChanged= 0x80B0,
+ AcceleratorChanged = 0x80C0
+ };
+
+ enum State {
+ Normal = 0x00000000,
+ Unavailable = 0x00000001,
+ Selected = 0x00000002,
+ Focused = 0x00000004,
+ Pressed = 0x00000008,
+ Checked = 0x00000010,
+ Mixed = 0x00000020,
+ ReadOnly = 0x00000040,
+ HotTracked = 0x00000080,
+ Default = 0x00000100,
+ Expanded = 0x00000200,
+ Collapsed = 0x00000400,
+ Busy = 0x00000800,
+ Floating = 0x00001000,
+ Marqueed = 0x00002000,
+ Animated = 0x00004000,
+ Invisible = 0x00008000,
+ Offscreen = 0x00010000,
+ Sizeable = 0x00020000,
+ Moveable = 0x00040000,
+ SelfVoicing = 0x00080000,
+ Focusable = 0x00100000,
+ Selectable = 0x00200000,
+ Linked = 0x00400000,
+ Traversed = 0x00800000,
+ MultiSelectable = 0x01000000,
+ ExtSelectable = 0x02000000,
+ AlertLow = 0x04000000,
+ AlertMedium = 0x08000000,
+ AlertHigh = 0x10000000,
+ Protected = 0x20000000,
+ Valid = 0x3fffffff
+ };
+
+ enum Role {
+ NoRole = 0x00000000,
+ TitleBar = 0x00000001,
+ MenuBar = 0x00000002,
+ ScrollBar = 0x00000003,
+ Grip = 0x00000004,
+ Sound = 0x00000005,
+ Cursor = 0x00000006,
+ Caret = 0x00000007,
+ AlertMessage = 0x00000008,
+ Window = 0x00000009,
+ Client = 0x0000000A,
+ PopupMenu = 0x0000000B,
+ MenuItem = 0x0000000C,
+ ToolTip = 0x0000000D,
+ Application = 0x0000000E,
+ Document = 0x0000000F,
+ Pane = 0x00000010,
+ Chart = 0x00000011,
+ Dialog = 0x00000012,
+ Border = 0x00000013,
+ Grouping = 0x00000014,
+ Separator = 0x00000015,
+ ToolBar = 0x00000016,
+ tqStatusBar = 0x00000017,
+ Table = 0x00000018,
+ ColumnHeader = 0x00000019,
+ RowHeader = 0x0000001A,
+ Column = 0x0000001B,
+ Row = 0x0000001C,
+ Cell = 0x0000001D,
+ Link = 0x0000001E,
+ HelpBalloon = 0x0000001F,
+ Character = 0x00000020,
+ List = 0x00000021,
+ ListItem = 0x00000022,
+ Outline = 0x00000023,
+ OutlineItem = 0x00000024,
+ PageTab = 0x00000025,
+ PropertyPage = 0x00000026,
+ Indicator = 0x00000027,
+ Graphic = 0x00000028,
+ StaticText = 0x00000029,
+ EditableText = 0x0000002A, // Editable, selectable, etc.
+ PushButton = 0x0000002B,
+ CheckBox = 0x0000002C,
+ RadioButton = 0x0000002D,
+ ComboBox = 0x0000002E,
+ DropLest = 0x0000002F,
+ ProgressBar = 0x00000030,
+ Dial = 0x00000031,
+ HotkeyField = 0x00000032,
+ Slider = 0x00000033,
+ SpinBox = 0x00000034,
+ Diagram = 0x00000035,
+ Animation = 0x00000036,
+ Equation = 0x00000037,
+ ButtonDropDown = 0x00000038,
+ ButtonMenu = 0x00000039,
+ ButtonDropGrid = 0x0000003A,
+ Whitespace = 0x0000003B,
+ PageTabList = 0x0000003C,
+ Clock = 0x0000003D
+ };
+
+ enum NavDirection {
+ NavUp = 0x00000001,
+ NavDown = 0x00000002,
+ NavLeft = 0x00000003,
+ NavRight = 0x00000004,
+ NavNext = 0x00000005,
+ NavPrevious = 0x00000006,
+ NavFirstChild = 0x00000007,
+ NavLastChild = 0x00000008,
+ NavFocusChild = 0x00000009
+ };
+
+ enum Text {
+ Name = 0,
+ Description,
+ Value,
+ Help,
+ Accelerator,
+ DefaultAction
+ };
+
+ static TQRESULT queryAccessibleInterface( TQObject *, TQAccessibleInterface ** );
+ static void updateAccessibility( TQObject *, int who, Event reason );
+ static bool isActive();
+
+ static void initialize();
+ static void cleanup();
+};
+
+// {EC86CB9C-5DA0-4c43-A739-13EBDF1C6B14}
+#define IID_TQAccessible TQUuid( 0xec86cb9c, 0x5da0, 0x4c43, 0xa7, 0x39, 0x13, 0xeb, 0xdf, 0x1c, 0x6b, 0x14 )
+
+struct TQ_EXPORT TQAccessibleInterface : public TQAccessible, public TQUnknownInterface
+{
+ // check for valid pointers
+ virtual bool isValid() const = 0;
+
+ // hierarchy
+ virtual int childCount() const = 0;
+ virtual TQRESULT queryChild( int control, TQAccessibleInterface** ) const = 0;
+ virtual TQRESULT queryParent( TQAccessibleInterface** ) const = 0;
+
+ // navigation
+ virtual int controlAt( int x, int y ) const = 0;
+ virtual TQRect rect( int control ) const = 0;
+ virtual int navigate( NavDirection direction, int startControl ) const = 0;
+
+ // properties and state
+ virtual TQString text( Text t, int control ) const = 0;
+ virtual void setText( Text t, int control, const TQString &text ) = 0;
+ virtual Role role( int control ) const = 0;
+ virtual State state( int control ) const = 0;
+ virtual TQMemArray<int> selection() const = 0;
+
+ // methods
+ virtual bool doDefaultAction( int control ) = 0;
+ virtual bool setFocus( int control ) = 0;
+ virtual bool setSelected( int control, bool on, bool extend ) = 0;
+ virtual void clearSelection() = 0;
+};
+
+// {49F4C6A7-412F-41DE-9E24-648843421FD3}
+#ifndef IID_TQAccessibleFactory
+#define IID_TQAccessibleFactory TQUuid( 0x49f4c6a7, 0x412f, 0x41de, 0x9e, 0x24, 0x64, 0x88, 0x43, 0x42, 0x1f, 0xd3 )
+#endif
+
+struct TQ_EXPORT TQAccessibleFactoryInterface : public TQAccessible, public TQFeatureListInterface
+{
+ virtual TQRESULT createAccessibleInterface( const TQString &, TQObject *, TQAccessibleInterface** ) = 0;
+};
+
+class TQ_EXPORT TQAccessibleObject : public TQObject, public TQAccessibleInterface
+{
+public:
+ TQAccessibleObject( TQObject *object );
+ virtual ~TQAccessibleObject();
+
+ TQRESULT queryInterface( const TQUuid &, TQUnknownInterface** );
+ TQ_REFCOUNT
+
+ bool isValid() const;
+
+protected:
+ TQObject *object() const;
+
+private:
+ TQGuardedPtr<TQObject> object_;
+};
+
+#define TQ_DEFINED_TQACCESSIBLE_OBJECT
+#include "tqwinexport.h"
+#endif //TQT_ACCESSIBILITY_SUPPORT
+
+#endif //TQACCESSIBLE_H
diff --git a/tqtinterface/qt4/src/kernel/tqapplication.cpp b/tqtinterface/qt4/src/kernel/tqapplication.cpp
new file mode 100644
index 0000000..af193c9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqapplication.cpp
@@ -0,0 +1,5499 @@
+/****************************************************************************
+**
+** Implementation of TQApplication class
+**
+** Created : 931107
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqobjectlist.h"
+#include "tqapplication.h"
+#include "tqeventloop.h"
+#include "tqeventloop_p.h"
+#include "tqwidget.h"
+#include "tqwidgetlist.h"
+#include "tqwidgetintdict.h"
+#include "tqptrdict.h"
+#include "tqcleanuphandler.h"
+
+#include "tqtranslator.h"
+#include "tqtextcodec.h"
+#include "tqsessionmanager.h"
+#include "tqdragobject.h"
+#include "tqclipboard.h"
+#include "tqcursor.h"
+#include "tqstyle.h"
+#include "tqstylefactory.h"
+#include "tqfile.h"
+#include "tqmessagebox.h"
+#include "tqdir.h"
+#include "tqfileinfo.h"
+#ifdef TQ_WS_WIN
+#include "tqinputcontext_p.h"
+#endif
+#include "tqfontdata_p.h"
+
+#if defined(TQT_THREAD_SUPPORT)
+# include "tqmutex.h"
+# include "tqthread.h"
+#endif // TQT_THREAD_SUPPORT
+
+#include <stdlib.h>
+
+#ifdef truncate
+# undef truncate
+#endif
+
+#ifdef USE_QT4
+
+TQApplication *tqAppReal; // global application object
+TQStyle *TQApplication::app_style = 0; // default application style
+bool qt_explicit_app_style = FALSE; // style explicitly set by programmer
+QWidget* TQApplication::current_app_main_widget = 0; // current main widget
+
+int TQApplication::app_cspec = TQApplication::NormalColor; // color mode (obsolete)
+
+TQWidgetList * qt_modal_stack=0; // stack of modal widgets
+
+#ifndef TQT_NO_PALETTE
+TQPalette *TQApplication::app_pal = 0; // default application palette
+#endif
+// TQFont *TQApplication::app_font = 0; // default application font
+bool qt_app_has_font = FALSE;
+
+bool qt_is_gui_used;
+bool TQ_EXPORT qt_resolve_symlinks = TRUE;
+bool TQ_EXPORT qt_tab_all_widgets = TRUE;
+
+#if defined(TQ_WS_X11)
+extern void qt_init( Display* dpy, TQt::HANDLE, TQt::HANDLE );
+#endif
+extern void qt_init( int *argcptr, char **argv, TQApplication::Type );
+
+#ifndef TQT_NO_CLIPBOARD
+TQClipboard *tqt_clipboard = 0; // global clipboard object
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+TQMutex *TQApplication::qt_mutex = 0;
+static TQMutex *postevent_mutex = 0;
+static TQt::HANDLE qt_application_thread_id = 0;
+TQ_EXPORT TQt::HANDLE qt_get_application_thread_id()
+{
+ return qt_application_thread_id;
+}
+#endif // TQT_THREAD_SUPPORT
+
+
+#ifdef TQT_THREAD_SUPPORT
+ #define TQAPPLICATION_MUTEX_INIT \
+ qt_mutex = new TQMutex( TRUE ); \
+ postevent_mutex = new TQMutex( TRUE ); \
+ qt_application_thread_id = TQThread::currentThread();
+#else // TQT_THREAD_SUPPORT
+ #define TQAPPLICATION_MUTEX_INIT
+#endif // TQT_THREAD_SUPPORT
+
+TQWidgetList TQApplication::tqt_all_widgets_list;
+
+TQApplication::TQApplication( int &argc, char **argv ) : QApplication( argc, argv )
+{
+ bool GUIenabled = true;
+ TQAPPLICATION_GUI_CONDITIONAL_VAR_INIT
+ TQAPPLICATION_XORG_CONDITIONAL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled ) : QApplication( argc, argv, GUIenabled )
+{
+ TQAPPLICATION_GUI_CONDITIONAL_VAR_INIT
+ TQAPPLICATION_XORG_CONDITIONAL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+TQApplication::TQApplication( int &argc, char **argv, Type t ) : QApplication( argc, argv, t )
+{
+ TQAPPLICATION_GUI_VAR_INIT
+ TQAPPLICATION_XORG_PARTIAL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+#if defined(TQ_WS_X11)
+TQApplication::TQApplication( Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap ) : QApplication( dpy, visual, cmap )
+{
+ TQAPPLICATION_GUI_VAR_INIT
+ TQAPPLICATION_XORG_FULL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+TQApplication::TQApplication( Display *dpy, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap ) : QApplication( dpy, argc, argv, visual, cmap )
+{
+ TQAPPLICATION_GUI_VAR_INIT
+ TQAPPLICATION_XORG_FULL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+#endif
+
+// Qt4 session manager interconnect
+void TQApplication::commitData( QSessionManager& sm ) {
+ commitData(TQT_TQSESSIONMANAGER_OBJECT(sm));
+}
+void TQApplication::saveState( QSessionManager& sm ) {
+ saveState(TQT_TQSESSIONMANAGER_OBJECT(sm));
+}
+
+#ifndef TQT_NO_TRANSLATION
+
+bool qt_detectRTLLanguage()
+{
+ return TQApplication::tr( "TQT_LAYOUT_DIRECTION",
+ "Translate this string to the string 'LTR' in left-to-right"
+ " languages or to 'RTL' in right-to-left languages (such as Hebrew"
+ " and Arabic) to get proper widget tqlayout." ) == "RTL";
+}
+
+#endif // TQT_NO_TRANSLATION
+
+TQEventLoop* TQApplication::eventloop;
+TQPtrList<QEventLoop> TQApplication::tqt_event_loop_stack;
+int TQApplication::composedUnicode;
+bool TQApplication::metaComposeUnicode;
+
+// static TQEventLoop eventLoop_private; // Will this actually work, or do I need to call exec or something?
+//
+// TQEventLoop *TQApplication::eventLoop()
+// {
+// return &eventLoop_private;
+// }
+
+TQEventLoop *TQApplication::eventLoop() {
+ if ( !eventloop )
+ (void) new TQEventLoop( TQT_TQOBJECT(tqApp), "default event loop" );
+ return eventloop;
+}
+
+/*!
+
+ Wakes up the GUI thread.
+
+ \sa guiThreadAwake() \link threads.html Thread Support in TQt\endlink
+*/
+void TQApplication::wakeUpGuiThread()
+{
+ eventLoop()->wakeUp();
+}
+
+#ifdef TQT_THREAD_SUPPORT
+void TQApplication::lock() {
+ qt_mutex->lock();
+}
+
+void TQApplication::unlock(bool wakeUpGui) {
+ qt_mutex->unlock();
+
+ if (wakeUpGui)
+ wakeUpGuiThread();
+}
+
+bool TQApplication::locked() {
+ return qt_mutex->locked();
+}
+
+bool TQApplication::tryLock() {
+ return qt_mutex->tryLock();
+}
+#endif // TQT_THREAD_SUPPORT
+
+#ifndef TQT_NO_PALETTE
+TQPalette *qt_std_pal = 0;
+
+void qt_create_std_palette()
+{
+ if ( qt_std_pal )
+ delete qt_std_pal;
+
+ TQColor standardLightGray( 192, 192, 192 );
+ TQColor light( 255, 255, 255 );
+ TQColor dark( standardLightGray.dark( 150 ) );
+ TQColorGroup std_act( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ TQColorGroup std_dis( TQt::darkGray, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::darkGray, std_act.background() );
+ TQColorGroup std_inact( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ qt_std_pal = new TQPalette( std_act, std_dis, std_inact );
+}
+
+static void qt_fix_tooltips()
+{
+ // No resources for this yet (unlike on Windows).
+ TQColorGroup cg( TQt::black, TQColor(255,255,220),
+ TQColor(96,96,96), TQt::black, TQt::black,
+ TQt::black, TQColor(255,255,220) );
+ TQPalette pal( cg, cg, cg );
+ TQApplication::tqsetPalette( pal, TRUE, "TQTipLabel");
+}
+#endif
+
+// [FIXME] This needs to somehow connect to the Qt4 style mechanism
+// Possibly on calls to setStyle the Qt4 setStyle must also be called for the same style?
+
+static TQString *qt_style_override = 0;
+
+TQStyle& TQApplication::tqstyle()
+{
+#ifndef TQT_NO_STYLE
+ if ( app_style )
+ return *app_style;
+ if ( !qt_is_gui_used )
+ qFatal( "No style available in non-gui applications!" );
+
+#if defined(TQ_WS_X11)
+// if(!qt_style_override)
+// x11_initialize_style(); // run-time search for default style
+#endif
+ if ( !app_style ) {
+// // Compile-time search for default style
+// //
+ TQString style;
+ if ( qt_style_override ) {
+ style = *qt_style_override;
+ delete qt_style_override;
+ qt_style_override = 0;
+ } else {
+// # if defined(TQ_WS_WIN) && defined(TQ_OS_TEMP)
+// style = "PocketPC";
+// #elif defined(TQ_WS_WIN)
+// if ( qWinVersion() >= TQt::WV_XP && qWinVersion() < TQt::WV_NT_based )
+// style = "WindowsXP";
+// else
+// style = "Windows"; // default styles for Windows
+// #elif defined(TQ_WS_X11) && defined(TQ_OS_SOLARIS)
+// style = "CDE"; // default style for X11 on Solaris
+// #elif defined(TQ_WS_X11) && defined(TQ_OS_IRIX)
+// style = "SGI"; // default style for X11 on IRIX
+// #elif defined(TQ_WS_X11)
+ style = "Motif"; // default style for X11
+// #elif defined(TQ_WS_MAC)
+// style = "Macintosh"; // default style for all Mac's
+// #elif defined(TQ_WS_TQWS)
+// style = "Compact"; // default style for small tqdevices
+// #endif
+ }
+ app_style = TQStyleFactory::create( style );
+ if ( !app_style && // platform default style not available, try alternatives
+ !(app_style = TQStyleFactory::create( "Windows" ) ) &&
+ !(app_style = TQStyleFactory::create( "Platinum" ) ) &&
+ !(app_style = TQStyleFactory::create( "MotifPlus" ) ) &&
+ !(app_style = TQStyleFactory::create( "Motif" ) ) &&
+ !(app_style = TQStyleFactory::create( "CDE" ) ) &&
+ !(app_style = TQStyleFactory::create( "Aqua" ) ) &&
+ !(app_style = TQStyleFactory::create( "SGI" ) ) &&
+ !(app_style = TQStyleFactory::create( "Compact" ) )
+#ifndef TQT_NO_STRINGLIST
+ && !(app_style = TQStyleFactory::create( TQStyleFactory::keys()[0] ) )
+#endif
+ )
+ qFatal( "No %s style available!", style.latin1() );
+ }
+
+// TQPalette app_pal_copy ( *app_pal );
+// app_style->polish( *app_pal );
+
+// if ( is_app_running && !is_app_closing && (*app_pal != app_pal_copy) ) {
+// TQEvent e( TQEvent::ApplicationPaletteChange );
+// TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+// register TQWidget *w;
+// while ( (w=it.current()) ) { // for all widgets...
+// ++it;
+// sendEvent( w, &e );
+// }
+// }
+
+ app_style->polish( tqApp );
+#endif
+ return *app_style;
+}
+
+/*!
+ Enters the main event loop and waits until exit() is called or the
+ main widget is destroyed, and returns the value that was set to
+ exit() (which is 0 if exit() is called via quit()).
+
+ It is necessary to call this function to start event handling. The
+ main event loop receives events from the window system and
+ dispatches these to the application widgets.
+
+ Generally speaking, no user interaction can take place before
+ calling exec(). As a special case, modal widgets like TQMessageBox
+ can be used before calling exec(), because modal widgets call
+ exec() to start a local event loop.
+
+ To make your application perform idle processing, i.e. executing a
+ special function whenever there are no pending events, use a
+ TQTimer with 0 timeout. More advanced idle processing schemes can
+ be achieved using processEvents().
+
+ \sa quit(), exit(), processEvents(), setMainWidget()
+*/
+int TQApplication::exec()
+{
+ return eventLoop()->exec();
+}
+
+/*!
+ Sets the application's GUI style to \a style. Ownership of the style
+ object is transferred to TQApplication, so TQApplication will delete
+ the style object on application exit or when a new style is set.
+
+ Example usage:
+ \code
+ TQApplication::setStyle( new TQWindowsStyle );
+ \endcode
+
+ When switching application styles, the color palette is set back to
+ the initial colors or the system defaults. This is necessary since
+ certain styles have to adapt the color palette to be fully
+ style-guide compliant.
+
+ \sa style(), TQStyle, setPalette(), desktopSettingsAware()
+*/
+void TQApplication::setStyle( TQStyle *style )
+{
+ TQStyle* old = app_style;
+ app_style = style;
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ delete old;
+ return;
+ }
+
+ // clean up the old style
+ if (old) {
+// if ( is_app_running && !is_app_closing ) {
+// TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+// register TQWidget *w;
+// while ( (w=it.current()) ) { // for all widgets...
+// ++it;
+// if ( !w->testWFlags(WType_Desktop) && // except desktop
+// w->testWState(WState_Polished) ) { // has been polished
+// old->unPolish(w);
+// }
+// }
+// }
+// old->unPolish( tqApp );
+ }
+
+ // take care of possible palette requirements of certain gui
+ // styles. Do it before polishing the application since the style
+ // might call TQApplication::setStyle() itself
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+ TQPalette tmpPal = *qt_std_pal;
+ tqsetPalette( tmpPal, TRUE );
+
+ // initialize the application with the new style
+ app_style->polish( tqApp );
+
+ // re-polish existing widgets if necessary
+ if (old) {
+// if ( is_app_running && !is_app_closing ) {
+// TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+// register TQWidget *w;
+// while ( (w=it.current()) ) { // for all widgets...
+// ++it;
+// if ( !w->testWFlags(WType_Desktop) ) { // except desktop
+// if ( w->testWState(WState_Polished) )
+// app_style->polish(w); // repolish
+// w->styleChange( *old );
+// if ( w->isVisible() ){
+// w->update();
+// }
+// }
+// }
+// }
+ delete old;
+ }
+}
+
+/*!
+ \overload
+
+ Requests a TQStyle object for \a style from the TQStyleFactory.
+
+ The string must be one of the TQStyleFactory::keys(), typically one
+ of "windows", "motif", "cde", "motifplus", "platinum", "sgi" and
+ "compact". Depending on the platform, "windowsxp", "aqua" or
+ "macintosh" may be available.
+
+ A later call to the TQApplication constructor will override the
+ requested style when a "-style" option is passed in as a commandline
+ parameter.
+
+ Returns 0 if an unknown \a style is passed, otherwise the TQStyle object
+ returned is set as the application's GUI style.
+*/
+TQStyle* TQApplication::setStyle( const TQString& style )
+{
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ if(qt_style_override)
+ *qt_style_override = style;
+ else
+ qt_style_override = new TQString(style);
+ return 0;
+ }
+ TQStyle *s = TQStyleFactory::create( style );
+ if ( !s )
+ return 0;
+
+ setStyle( s );
+ return s;
+}
+
+TQWidget *TQApplication::mainWidget()
+{
+ return TQT_TQWIDGET(current_app_main_widget);
+}
+
+const char *TQApplication::tqname() const {
+ if (dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQApplication::tqname() on an object without a constructed TQApplication object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+const char *TQApplication::name() const {
+ if (dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQApplication::name() on an object without a constructed TQApplication object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+/*!\internal
+
+ Called from qapplication_<platform>.cpp, returns TRUE
+ if the widget should accept the event.
+ */
+TQ_EXPORT bool qt_tryModalHelper( TQWidget *widget, TQWidget **rettop ) {
+ TQWidget *modal=0, *top=TQT_TQWIDGET(TQApplication::activeModalWidget());
+ if ( rettop ) *rettop = top;
+
+ if ( tqApp->activePopupWidget() )
+ return TRUE;
+
+#ifdef TQ_WS_MACX
+ top = qt_tryModalHelperMac( top );
+ if ( rettop ) *rettop = top;
+#endif
+
+ TQWidget* groupLeader = widget;
+ widget = widget->tqtopLevelWidget();
+
+ if ( widget->testWFlags(TQt::WShowModal) ) // widget is modal
+ modal = widget;
+ if ( !top || modal == top ) // don't block event
+ return TRUE;
+
+ TQWidget * p = widget->parentWidget(); // Check if the active modal widget is a tqparent of our widget
+ while ( p ) {
+ if ( p == top )
+ return TRUE;
+ p = p->parentWidget();
+ }
+
+ while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) )
+ groupLeader = groupLeader->parentWidget();
+
+// [FIXME]
+printf("[WARNING] bool qt_tryModalHelper partially implemented\n\r");
+// if ( groupLeader ) {
+// // Does groupLeader have a child in qt_modal_stack?
+// bool unrelated = TRUE;
+// modal = qt_modal_stack->first();
+// while (modal && unrelated) {
+// TQWidget* p = modal->parentWidget();
+// while ( p && p != groupLeader && !p->testWFlags( TQt::WGroupLeader) ) {
+// p = p->parentWidget();
+// }
+// modal = qt_modal_stack->next();
+// if ( p == groupLeader ) unrelated = FALSE;
+// }
+//
+// if ( unrelated )
+// return TRUE; // don't block event
+// }
+
+ return FALSE;
+}
+
+/*!\internal
+
+ Creates the proper Enter/Leave event when widget \a enter is entered
+ and widget \a leave is left.
+ */
+TQ_EXPORT void qt_dispatchEnterLeave( TQWidget* enter, TQWidget* leave ) {
+#if 0
+ if ( leave ) {
+ TQEvent e( TQEvent::Leave );
+ TQApplication::sendEvent( leave, & e );
+ }
+ if ( enter ) {
+ TQEvent e( TQEvent::Enter );
+ TQApplication::sendEvent( enter, & e );
+ }
+ return;
+#endif
+
+ TQWidget* w ;
+ if ( !enter && !leave )
+ return;
+ TQWidgetList leaveList;
+ TQWidgetList enterList;
+
+ bool sameWindow = leave && enter && leave->tqtopLevelWidget() == enter->tqtopLevelWidget();
+ if ( leave && !sameWindow ) {
+ w = leave;
+ do {
+ leaveList.append( w );
+ } while ( (w = w->parentWidget( TRUE ) ) );
+ }
+ if ( enter && !sameWindow ) {
+ w = enter;
+ do {
+ enterList.prepend( w );
+ } while ( (w = w->parentWidget(TRUE) ) );
+ }
+ if ( sameWindow ) {
+ int enterDepth = 0;
+ int leaveDepth = 0;
+ w = enter;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ enterDepth++;
+ w = leave;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ leaveDepth++;
+ TQWidget* wenter = enter;
+ TQWidget* wleave = leave;
+ while ( enterDepth > leaveDepth ) {
+ wenter = wenter->parentWidget();
+ enterDepth--;
+ }
+ while ( leaveDepth > enterDepth ) {
+ wleave = wleave->parentWidget();
+ leaveDepth--;
+ }
+ while ( !wenter->isTopLevel() && wenter != wleave ) {
+ wenter = wenter->parentWidget();
+ wleave = wleave->parentWidget();
+ }
+
+ w = leave;
+ while ( w != wleave ) {
+ leaveList.append( w );
+ w = w->parentWidget();
+ }
+ w = enter;
+ while ( w != wenter ) {
+ enterList.prepend( w );
+ w = w->parentWidget();
+ }
+ }
+
+ TQEvent leaveEvent( TQEvent::Leave );
+ for ( w = leaveList.first(); w; w = leaveList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &leaveEvent );
+ }
+ TQEvent enterEvent( TQEvent::Enter );
+ for ( w = enterList.first(); w; w = enterList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &enterEvent );
+ }
+}
+
+#ifndef TQT_NO_CLIPBOARD
+/*!
+ Returns a pointer to the application global clipboard.
+*/
+TQClipboard *TQApplication::tqclipboard()
+{
+ if ( tqt_clipboard == 0 ) {
+ tqt_clipboard = new TQClipboard;
+ TQ_CHECK_PTR( tqt_clipboard );
+ }
+ return tqt_clipboard;
+}
+#endif // TQT_NO_CLIPBOARD
+
+/*!
+ \fn void TQApplication::commitData( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the TQSessionManager wants the
+ application to commit all its data.
+
+ Usually this means saving all open files, after getting
+ permission from the user. Furthermore you may want to provide a means
+ by which the user can cancel the shutdown.
+
+ Note that you should not exit the application within this function.
+ Instead, the session manager may or may not do this afterwards,
+ depending on the context.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details and example
+ usage.
+
+ The default implementation requests interaction and sends a close
+ event to all visible top level widgets. If any event was
+ rejected, the shutdown is canceled.
+
+ \sa isSessionRestored(), sessionId(), saveState(), \link session.html the Session Management overview\endlink
+*/
+#ifndef TQT_NO_SESSIONMANAGER
+void TQApplication::commitData( TQSessionManager& sm )
+{
+
+ if ( sm.allowsInteraction() ) {
+ TQWidgetList done;
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ bool cancelled = FALSE;
+ TQWidget* w = list->first();
+ while ( !cancelled && w ) {
+ if ( !w->isHidden() ) {
+ TQCloseEvent e;
+ sendEvent( w, &e );
+ cancelled = !e.isAccepted();
+ if ( !cancelled )
+ done.append( w );
+ delete list; // one never knows...
+ list = TQApplication::tqtopLevelWidgets();
+ w = list->first();
+ } else {
+ w = list->next();
+ }
+ while ( w && done.tqcontainsRef( w ) )
+ w = list->next();
+ }
+ delete list;
+ if ( cancelled )
+ sm.cancel();
+ }
+}
+
+
+/*!
+ \fn void TQApplication::saveState( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the
+ \link TQSessionManager session manager \endlink wants the application
+ to preserve its state for a future session.
+
+ For example, a text editor would create a temporary file that
+ includes the current contents of its edit buffers, the location of
+ the cursor and other aspects of the current editing session.
+
+ Note that you should never exit the application within this
+ function. Instead, the session manager may or may not do this
+ afterwards, depending on the context. Futhermore, most session
+ managers will very likely request a saved state immediately after
+ the application has been started. This permits the session manager
+ to learn about the application's restart policy.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details.
+
+ \sa isSessionRestored(), sessionId(), commitData(), \link session.html the Session Management overview\endlink
+*/
+
+void TQApplication::saveState( TQSessionManager& /* sm */ )
+{
+}
+#endif //TQT_NO_SESSIONMANAGER
+
+#if 1 /* OBSOLETE */
+
+TQApplication::ColorMode TQApplication::colorMode()
+{
+ return (TQApplication::ColorMode)app_cspec;
+}
+
+void TQApplication::setColorMode( TQApplication::ColorMode mode )
+{
+ printf("[WARNING] TQApplication::setColorMode() does nothing!\n\r");
+ app_cspec = mode;
+}
+#endif
+
+/*!
+ Initialization of the appearance of the widget \a w \e before it is first
+ shown.
+
+ Usually widgets call this automatically when they are polished. It
+ may be used to do some style-based central customization of widgets.
+
+ Note that you are not limited to the public functions of TQWidget.
+ Instead, based on meta information like TQObject::className() you are
+ able to customize any kind of widget.
+
+ \sa TQStyle::polish(), TQWidget::polish(), setPalette(), setFont()
+*/
+
+void TQApplication::polish( QWidget *w )
+{
+#ifndef TQT_NO_STYLE
+ TQT_TQWIDGET(w)->tqstyle().polish( TQT_TQWIDGET(w) );
+#endif
+}
+
+void TQApplication::exit_loop() { // Does not exit in Qt4
+ printf("[WARNING] No runtime validation is performed within TQApplication::exit_loop; this may cause odd/obscure problems\n\r");
+// QThreadData *data = QThreadData::current();
+// if (!data->eventLoops.isEmpty())
+// data->eventLoops.top()->exit();
+ QEventLoop* eventLoop = tqt_event_loop_stack.getLast();
+ if (eventLoop) {
+ eventLoop->exit();
+ }
+ else {
+ printf("[WARNING] An attempt was made to exit a nonexistant event loop!\n\r");
+ }
+}
+int TQApplication::enter_loop() { // Does not exit in Qt4
+ printf("[WARNING] No runtime validation is performed within TQApplication::enter_loop; this may cause odd/obscure problems\n\r");
+ QEventLoop* eventLoop = new QEventLoop();
+ tqt_event_loop_stack.append(eventLoop);
+ int returnCode = eventLoop->exec(); // This blocks until either QEventLoop::exit is called or the loop terminates normally
+ tqt_event_loop_stack.remove(eventLoop);
+ delete eventLoop;
+ return returnCode;
+}
+
+TQMetaObject *TQApplication::tqmetaObject() const {
+ return TQT_TQOBJECT_CONST(this)->tqmetaObject();
+}
+
+void TQApplication::processOneEvent() {
+ processEvents(QEventLoop::WaitForMoreEvents);
+}
+
+void TQApplication::tqprocessEvents() {
+ return processEvents();
+}
+
+void TQApplication::tqprocessEvents( int maxtime ) {
+ return processEvents(QEventLoop::AllEvents, maxtime);
+}
+
+/*!
+ \obsolete
+
+ Returns the current loop level.
+
+ Use TQApplication::eventLoop()->loopLevel() instead.
+
+*/
+int TQApplication::loopLevel() const
+{
+ return eventLoop()->loopLevel();
+}
+
+bool TQApplication::hasGlobalMouseTracking()
+{
+ printf("[WARNING] TQApplication::hasGlobalMouseTracking unimplemented!\n\r");
+ return true;
+}
+
+void TQApplication::setGlobalMouseTracking( bool enable )
+{
+ printf("[WARNING] TQApplication::setGlobalMouseTracking unimplemented!\n\r");
+}
+
+#if defined(TQ_WS_X11)
+void TQApplication::create_xim() {
+ printf("[WARNING] static void TQApplication::create_xim() unimplemented\n\r"); // [FIXME]
+}
+
+void TQApplication::close_xim() {
+ printf("[WARNING] static void TQApplication::close_xim() unimplemented\n\r"); // [FIXME]
+}
+
+bool TQApplication::x11_apply_settings() {
+ printf("[WARNING] static bool TQApplication::x11_apply_settings() unimplemented\n\r");
+ return false; // [FIXME]
+}
+#endif
+
+#ifndef TQT_NO_TEXTCODEC
+void TQApplication::setDefaultCodec( TQTextCodec * ) {
+ printf("[WARNING] void TQApplication::setDefaultCodec( TQTextCodec * ) unimplemented\n\r"); // [FIXME]
+}
+
+TQTextCodec* TQApplication::defaultCodec() const
+{
+// return TQTextCodec::codecForTr();
+
+ printf("[WARNING] TQTextCodec* TQApplication::defaultCodec unimplemented\n\r"); // [FIXME]
+// return TQTextCodec();
+}
+#endif
+
+TQWidgetList *TQApplication::tqallWidgets() {
+ QWidgetList ql = allWidgets();
+ tqt_all_widgets_list.clear();
+ for (int i = 0; i < ql.size(); ++i) tqt_all_widgets_list.append(TQT_TQWIDGET(ql.at(i)));
+ return &tqt_all_widgets_list;
+}
+
+TQStringList TQApplication::libraryPaths() {
+ return TQT_TQSTRINGLIST_OBJECT(QApplication::libraryPaths());
+}
+
+void TQApplication::tqsetLibraryPaths( const QStringList &qsl ) {
+ setLibraryPaths(qsl);
+}
+
+TQWidgetList *TQApplication::tqtopLevelWidgets() {
+ // The end user of the list is expected to delete it, so create it with new...
+ TQWidgetList *tqwl = new TQWidgetList();
+ foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ tqwl->append(static_cast<TQWidget*>(widget));
+ }
+ return tqwl;
+
+}
+
+TQDesktopWidget *TQApplication::desktop() {
+ return static_cast<TQDesktopWidget*>(QApplication::desktop());
+}
+
+const QColor &TQApplication::winStyleHighlightColor() {
+ return palette().color(QPalette::Active, QPalette::Highlight);
+}
+
+void TQApplication::setWinStyleHighlightColor( const QColor c ) {
+ TQPalette p( tqpalette() );
+ p.setColor( TQColorGroup::Highlight, c );
+ tqsetPalette( p, TRUE);
+}
+
+void TQApplication::tqsetPalette(const QPalette &pal, bool, const char* className) {
+ setPalette(pal, className);
+}
+
+void TQApplication::tqsetFont(const QFont &font, bool, const char* className) {
+ setFont(font, className);
+}
+
+void TQApplication::setReverseLayout(bool b) {
+ setLayoutDirection(b?Qt::RightToLeft:Qt::LeftToRight);
+}
+
+bool TQApplication::reverseLayout() {
+ return layoutDirection() == Qt::RightToLeft;
+}
+
+TQPalette TQApplication::tqpalette( const TQWidget* w ) {
+ return palette( w );
+}
+
+#ifndef TQT_NO_CURSOR
+//void TQApplication::setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE ) {
+// TQ_UNUSED(tqreplace);
+// QApplication::setOverrideCursor( cur );
+// }
+
+void TQApplication::setOverrideCursor( const QCursor &cur, bool tqreplace ) {
+ TQ_UNUSED(tqreplace);
+ printf("[FIXME] TQApplication::setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE ) unimplemented\n\r");
+}
+#endif
+
+void TQApplication::sendPostedEvents( QObject *receiver, int event_type ) {
+ QApplication::sendPostedEvents(receiver, event_type);
+ if (event_type == TQEvent::LayoutHint) {
+ QApplication::sendPostedEvents(receiver, TQEvent::LayoutRequest);; // This one eats LayoutRequest/LayoutHint events for breakfast
+ }
+}
+
+void TQApplication::sendPostedEvents() {
+ QApplication::sendPostedEvents();
+}
+
+TQWidget *TQApplication::tqfocusWidget() const {
+ return static_cast<TQWidget*>(focusWidget());
+}
+
+TQWidget *TQApplication::widgetAt( const TQPoint &p, bool child ) {
+ TQ_UNUSED(child);
+ return static_cast<TQWidget*>(QApplication::widgetAt( p ));
+}
+
+TQWidget *TQApplication::widgetAt( int x, int y, bool child ) {
+ TQ_UNUSED(child);
+ return static_cast<TQWidget*>(QApplication::widgetAt( QPoint(x, y) ));
+}
+
+int TQApplication::horizontalAlignment( int align ) {
+ return QStyle::visualAlignment(layoutDirection(), (Qt::Alignment)align);
+}
+
+void TQApplication::flushX() {
+ flush();
+}
+
+const char *TQApplication::name(const char *defaultName) const {
+ TQString s = objectName();
+ return s.isEmpty()?defaultName:s.latin1();
+}
+
+void TQApplication::setName(const char *aName) {
+ TQT_TQOBJECT(this)->setName(aName);
+}
+
+/*!
+ Displays a simple message box about TQt. The message includes the
+ version number of TQt being used by the application.
+
+ This is useful for inclusion in the Help menu of an application.
+ See the examples/menu/menu.cpp example.
+
+ This function is a convenience slot for TQMessageBox::aboutTQt().
+*/
+void TQApplication::aboutTQt()
+{
+#ifndef TQT_NO_MESSAGEBOX
+ TQMessageBox::aboutTQt( mainWidget() );
+#endif // TQT_NO_MESSAGEBOX
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQApplication tqapplication.h
+ \brief The TQApplication class manages the GUI application's control
+ flow and main settings.
+
+ \ingroup application
+ \mainclass
+
+ It tqcontains the main event loop, where all events from the window
+ system and other sources are processed and dispatched. It also
+ handles the application's initialization and finalization, and
+ provides session management. It also handles most system-wide and
+ application-wide settings.
+
+ For any GUI application that uses TQt, there is precisely one
+ TQApplication object, no matter whether the application has 0, 1, 2
+ or more windows at any time.
+
+ The TQApplication object is accessible through the global pointer \c
+ tqApp. Its main areas of responsibility are:
+ \list
+
+ \i It initializes the application with the user's desktop settings
+ such as palette(), font() and doubleClickInterval(). It keeps track
+ of these properties in case the user changes the desktop globally, for
+ example through some kind of control panel.
+
+ \i It performs event handling, meaning that it receives events
+ from the underlying window system and dispatches them to the relevant
+ widgets. By using sendEvent() and postEvent() you can send your own
+ events to widgets.
+
+ \i It parses common command line arguments and sets its internal
+ state accordingly. See the \link TQApplication::TQApplication()
+ constructor documentation\endlink below for more details about this.
+
+ \i It defines the application's look and feel, which is
+ encapsulated in a TQStyle object. This can be changed at runtime
+ with setStyle().
+
+ \i It specifies how the application is to allocate colors.
+ See setColorSpec() for details.
+
+ \i It provides localization of strings that are visible to the user
+ via translate().
+
+ \i It provides some magical objects like the desktop() and the
+ clipboard().
+
+ \i It knows about the application's windows. You can ask which
+ widget is at a certain position using widgetAt(), get a list of
+ tqtopLevelWidgets() and closeAllWindows(), etc.
+
+ \i It manages the application's mouse cursor handling,
+ see setOverrideCursor() and setGlobalMouseTracking().
+
+ \i On the X window system, it provides functions to flush and sync
+ the communication stream, see flushX() and syncX().
+
+ \i It provides support for sophisticated \link
+ session.html session management \endlink. This makes it possible
+ for applications to terminate gracefully when the user logs out, to
+ cancel a shutdown process if termination isn't possible and even to
+ preserve the entire application's state for a future session. See
+ isSessionRestored(), sessionId() and commitData() and saveState()
+ for details.
+
+ \endlist
+
+ The <a href="simple-application.html">Application walk-through
+ example</a> tqcontains a typical complete main() that does the usual
+ things with TQApplication.
+
+ Since the TQApplication object does so much initialization, it
+ <b>must</b> be created before any other objects related to the user
+ interface are created.
+
+ Since it also deals with common command line arguments, it is
+ usually a good idea to create it \e before any interpretation or
+ modification of \c argv is done in the application itself. (Note
+ also that for X11, setMainWidget() may change the main widget
+ according to the \c -tqgeometry option. To preserve this
+ functionality, you must set your defaults before setMainWidget() and
+ any overrides after.)
+
+ \table
+ \header \i21 Groups of functions
+ \row
+ \i System settings
+ \i
+ desktopSettingsAware(),
+ setDesktopSettingsAware(),
+ cursorFlashTime(),
+ setCursorFlashTime(),
+ doubleClickInterval(),
+ setDoubleClickInterval(),
+ wheelScrollLines(),
+ setWheelScrollLines(),
+ palette(),
+ setPalette(),
+ font(),
+ setFont(),
+ fontMetrics().
+
+ \row
+ \i Event handling
+ \i
+ exec(),
+ processEvents(),
+ enter_loop(),
+ exit_loop(),
+ exit(),
+ quit().
+ sendEvent(),
+ postEvent(),
+ sendPostedEvents(),
+ removePostedEvents(),
+ hasPendingEvents(),
+ notify(),
+ macEventFilter(),
+ qwsEventFilter(),
+ x11EventFilter(),
+ x11ProcessEvent(),
+ winEventFilter().
+
+ \row
+ \i GUI Styles
+ \i
+ style(),
+ setStyle(),
+ polish().
+
+ \row
+ \i Color usage
+ \i
+ colorSpec(),
+ setColorSpec(),
+ qwsSetCustomColors().
+
+ \row
+ \i Text handling
+ \i
+ installTranslator(),
+ removeTranslator()
+ translate().
+
+ \row
+ \i Widgets
+ \i
+ mainWidget(),
+ setMainWidget(),
+ allWidgets(),
+ tqtopLevelWidgets(),
+ desktop(),
+ activePopupWidget(),
+ activeModalWidget(),
+ clipboard(),
+ tqfocusWidget(),
+ winFocus(),
+ activeWindow(),
+ widgetAt().
+
+ \row
+ \i Advanced cursor handling
+ \i
+ hasGlobalMouseTracking(),
+ setGlobalMouseTracking(),
+ overrideCursor(),
+ setOverrideCursor(),
+ restoreOverrideCursor().
+
+ \row
+ \i X Window System synchronization
+ \i
+ flushX(),
+ syncX().
+
+ \row
+ \i Session management
+ \i
+ isSessionRestored(),
+ sessionId(),
+ commitData(),
+ saveState().
+
+ \row
+ \i Threading
+ \i
+ lock(), unlock(), locked(), tryLock(),
+ wakeUpGuiThread()
+
+ \row
+ \i Miscellaneous
+ \i
+ closeAllWindows(),
+ startingUp(),
+ closingDown(),
+ type().
+ \endtable
+
+ \e {Non-GUI programs:} While TQt is not optimized or
+ designed for writing non-GUI programs, it's possible to use
+ \link tools.html some of its classes \endlink without creating a
+ TQApplication. This can be useful if you wish to share code between
+ a non-GUI server and a GUI client.
+
+ \headerfile tqnamespace.h
+ \headerfile tqwindowdefs.h
+ \headerfile tqglobal.h
+*/
+
+/*! \enum TQt::HANDLE
+ \internal
+*/
+
+/*!
+ \enum TQApplication::Type
+
+ \value Tty a console application
+ \value GuiClient a GUI client application
+ \value GuiServer a GUI server application
+*/
+
+/*!
+ \enum TQApplication::ColorSpec
+
+ \value NormalColor the default color allocation policy
+ \value CustomColor the same as NormalColor for X11; allocates colors
+ to a palette on demand under Windows
+ \value ManyColor the right choice for applications that use thousands of
+ colors
+
+ See setColorSpec() for full details.
+*/
+
+/*
+ The qt_init() and qt_cleanup() functions are implemented in the
+ qapplication_xyz.cpp file.
+*/
+
+void qt_init( int *, char **, TQApplication::Type );
+void qt_cleanup();
+#if defined(TQ_WS_X11)
+void qt_init( Display* dpy, TQt::HANDLE, TQt::HANDLE );
+#endif
+TQ_EXPORT bool qt_tryModalHelper( TQWidget *widget, TQWidget **rettop );
+
+TQApplication *tqApp = 0; // global application object
+
+TQStyle *TQApplication::app_style = 0; // default application style
+bool qt_explicit_app_style = FALSE; // style explicitly set by programmer
+
+int TQApplication::app_cspec = TQApplication::NormalColor;
+#ifndef TQT_NO_PALETTE
+TQPalette *TQApplication::app_pal = 0; // default application palette
+#endif
+TQFont *TQApplication::app_font = 0; // default application font
+bool qt_app_has_font = FALSE;
+#ifndef TQT_NO_CURSOR
+TQCursor *TQApplication::app_cursor = 0; // default application cursor
+#endif
+int TQApplication::app_tracking = 0; // global mouse tracking
+bool TQApplication::is_app_running = FALSE; // app starting up if FALSE
+bool TQApplication::is_app_closing = FALSE; // app closing down if TRUE
+int TQApplication::loop_level = 0; // event loop level
+TQWidget *TQApplication::main_widget = 0; // main application widget
+TQWidget *TQApplication::focus_widget = 0; // has keyboard input focus
+TQWidget *TQApplication::active_window = 0; // toplevel with keyboard focus
+bool TQApplication::obey_desktop_settings = TRUE; // use winsys resources
+int TQApplication::cursor_flash_time = 1000; // text caret flash time
+int TQApplication::mouse_double_click_time = 400; // mouse dbl click limit
+#ifndef TQT_NO_WHEELEVENT
+int TQApplication::wheel_scroll_lines = 3; // number of lines to scroll
+#endif
+bool qt_is_gui_used;
+bool TQ_EXPORT qt_resolve_symlinks = TRUE;
+bool TQ_EXPORT qt_tab_all_widgets = TRUE;
+TQRect qt_maxWindowRect;
+static int drag_time = 500;
+static int drag_distance = 4;
+static bool reverse_tqlayout = FALSE;
+TQSize TQApplication::app_strut = TQSize( 0,0 ); // no default application strut
+bool TQApplication::animate_ui = TRUE;
+bool TQApplication::animate_menu = FALSE;
+bool TQApplication::fade_menu = FALSE;
+bool TQApplication::animate_combo = FALSE;
+bool TQApplication::animate_tooltip = FALSE;
+bool TQApplication::fade_tooltip = FALSE;
+bool TQApplication::animate_toolbox = FALSE;
+bool TQApplication::widgetCount = FALSE;
+TQApplication::Type qt_appType=TQApplication::Tty;
+#ifndef TQT_NO_COMPONENT
+TQStringList *TQApplication::app_libpaths = 0;
+#endif
+bool TQApplication::metaComposeUnicode = FALSE;
+int TQApplication::composedUnicode = 0;
+
+#ifdef TQT_THREAD_SUPPORT
+TQMutex *TQApplication::qt_mutex = 0;
+static TQMutex *postevent_mutex = 0;
+static TQt::HANDLE qt_application_thread_id = 0;
+TQ_EXPORT TQt::HANDLE qt_get_application_thread_id()
+{
+ return qt_application_thread_id;
+}
+#endif // TQT_THREAD_SUPPORT
+
+TQEventLoop *TQApplication::eventloop = 0; // application event loop
+
+#ifndef TQT_NO_ACCEL
+extern bool qt_dispatchAccelEvent( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp
+extern bool qt_tryComposeUnicode( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp
+#endif
+
+#if defined(TQT_TABLET_SUPPORT)
+bool chokeMouse = FALSE;
+#endif
+
+void qt_setMaxWindowRect(const TQRect& r)
+{
+ qt_maxWindowRect = r;
+ // Re-resize any maximized windows
+ TQWidgetList* l = TQApplication::tqtopLevelWidgets();
+ if ( l ) {
+ TQWidget *w = l->first();
+ while ( w ) {
+ if ( w->isVisible() && w->isMaximized() )
+ {
+ w->showNormal(); //#### flicker
+ w->showMaximized();
+ }
+ w = l->next();
+ }
+ delete l;
+ }
+}
+
+typedef void (*VFPTR)();
+typedef TQValueList<VFPTR> TQVFuncList;
+static TQVFuncList *postRList = 0; // list of post routines
+
+/*!
+ \relates TQApplication
+
+ Adds a global routine that will be called from the TQApplication
+ destructor. This function is normally used to add cleanup routines
+ for program-wide functionality.
+
+ The function given by \a p should take no arguments and return
+ nothing, like this:
+ \code
+ static int *global_ptr = 0;
+
+ static void cleanup_ptr()
+ {
+ delete [] global_ptr;
+ global_ptr = 0;
+ }
+
+ void init_ptr()
+ {
+ global_ptr = new int[100]; // allocate data
+ qAddPostRoutine( cleanup_ptr ); // delete later
+ }
+ \endcode
+
+ Note that for an application- or module-wide cleanup,
+ qAddPostRoutine() is often not suitable. People have a tendency to
+ make such modules dynamically loaded, and then unload those modules
+ long before the TQApplication destructor is called, for example.
+
+ For modules and libraries, using a reference-counted initialization
+ manager or TQt' tqparent-child delete mechanism may be better. Here is
+ an example of a private class which uses the tqparent-child mechanism
+ to call a cleanup function at the right time:
+
+ \code
+ class MyPrivateInitStuff: public TQObject {
+ private:
+ MyPrivateInitStuff( TQObject * tqparent ): TQObject( tqparent) {
+ // initialization goes here
+ }
+ MyPrivateInitStuff * p;
+
+ public:
+ static MyPrivateInitStuff * initStuff( TQObject * tqparent ) {
+ if ( !p )
+ p = new MyPrivateInitStuff( tqparent );
+ return p;
+ }
+
+ ~MyPrivateInitStuff() {
+ // cleanup (the "post routine") goes here
+ }
+ }
+ \endcode
+
+ By selecting the right tqparent widget/object, this can often be made
+ to clean up the module's data at the exact right moment.
+*/
+
+TQ_EXPORT void qAddPostRoutine( TQtCleanUpFunction p)
+{
+ if ( !postRList ) {
+ postRList = new TQVFuncList;
+ TQ_CHECK_PTR( postRList );
+ }
+ postRList->prepend( p );
+}
+
+
+TQ_EXPORT void qRemovePostRoutine( TQtCleanUpFunction p )
+{
+ if ( !postRList ) return;
+ TQVFuncList::Iterator it = postRList->begin();
+ while ( it != postRList->end() ) {
+ if ( *it == p ) {
+ postRList->remove( it );
+ it = postRList->begin();
+ } else {
+ ++it;
+ }
+ }
+}
+
+// Default application palettes and fonts (per widget type)
+TQAsciiDict<TQPalette> *TQApplication::app_palettes = 0;
+TQAsciiDict<TQFont> *TQApplication::app_fonts = 0;
+
+#ifndef TQT_NO_SESSIONMANAGER
+TQString *TQApplication::session_key = 0; // ## session key. Should be a member in 4.0
+#endif
+TQWidgetList *TQApplication::popupWidgets = 0; // has keyboard input focus
+
+TQDesktopWidget *qt_desktopWidget = 0; // root window widgets
+#ifndef TQT_NO_CLIPBOARD
+TQClipboard *qt_clipboard = 0; // global clipboard object
+#endif
+TQWidgetList * qt_modal_stack=0; // stack of modal widgets
+
+// Definitions for posted events
+struct TQPostEvent {
+ TQPostEvent( TQObject *r, TQEvent *e ): receiver( r ), event( e ) {}
+ ~TQPostEvent() { delete event; }
+ TQObject *receiver;
+ TQEvent *event;
+};
+
+class TQ_EXPORT TQPostEventList : public TQPtrList<TQPostEvent>
+{
+public:
+ TQPostEventList() : TQPtrList<TQPostEvent>() {}
+ TQPostEventList( const TQPostEventList &list ) : TQPtrList<TQPostEvent>(list) {}
+ ~TQPostEventList() { clear(); }
+ TQPostEventList &operator=(const TQPostEventList &list)
+ { return (TQPostEventList&)TQPtrList<TQPostEvent>::operator=(list); }
+};
+class TQ_EXPORT TQPostEventListIt : public TQPtrListIterator<TQPostEvent>
+{
+public:
+ TQPostEventListIt( const TQPostEventList &l ) : TQPtrListIterator<TQPostEvent>(l) {}
+ TQPostEventListIt &operator=(const TQPostEventListIt &i)
+{ return (TQPostEventListIt&)TQPtrListIterator<TQPostEvent>::operator=(i); }
+};
+
+static TQPostEventList *globalPostedEvents = 0; // list of posted events
+
+uint qGlobalPostedEventsCount()
+{
+ if (!globalPostedEvents)
+ return 0;
+ return globalPostedEvents->count();
+}
+
+static TQSingleCleanupHandler<TQPostEventList> qapp_cleanup_events;
+
+#ifndef TQT_NO_PALETTE
+TQPalette *qt_std_pal = 0;
+
+void qt_create_std_palette()
+{
+ if ( qt_std_pal )
+ delete qt_std_pal;
+
+ TQColor standardLightGray( 192, 192, 192 );
+ TQColor light( 255, 255, 255 );
+ TQColor dark( standardLightGray.dark( 150 ) );
+ TQColorGroup std_act( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ TQColorGroup std_dis( TQt::darkGray, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::darkGray, std_act.background() );
+ TQColorGroup std_inact( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ qt_std_pal = new TQPalette( std_act, std_dis, std_inact );
+}
+
+static void qt_fix_tooltips()
+{
+ // No resources for this yet (unlike on Windows).
+ TQColorGroup cg( TQt::black, TQColor(255,255,220),
+ TQColor(96,96,96), TQt::black, TQt::black,
+ TQt::black, TQColor(255,255,220) );
+ TQPalette pal( cg, cg, cg );
+ TQApplication::setPalette( pal, TRUE, "TQTipLabel");
+}
+#endif
+
+void TQApplication::process_cmdline( int* argcptr, char ** argv )
+{
+ // process platform-indep command line
+ if ( !qt_is_gui_used || !*argcptr)
+ return;
+
+ int argc = *argcptr;
+ int i, j;
+
+ j = 1;
+ for ( i=1; i<argc; i++ ) {
+ if ( argv[i] && *argv[i] != '-' ) {
+ argv[j++] = argv[i];
+ continue;
+ }
+ TQCString arg = argv[i];
+ TQCString s;
+ if ( arg == "-qdevel" || arg == "-qdebug") {
+ // obsolete argument
+ } else if ( arg.tqfind( "-style=", 0, FALSE ) != -1 ) {
+ s = arg.right( arg.length() - 7 );
+ } else if ( qstrcmp(arg,"-style") == 0 && i < argc-1 ) {
+ s = argv[++i];
+ s = s.lower();
+#ifndef TQT_NO_SESSIONMANAGER
+ } else if ( qstrcmp(arg,"-session") == 0 && i < argc-1 ) {
+ TQCString s = argv[++i];
+ if ( !s.isEmpty() ) {
+ session_id = TQString::tqfromLatin1( s );
+ int p = session_id.tqfind( '_' );
+ if ( p >= 0 ) {
+ if ( !session_key )
+ session_key = new TQString;
+ *session_key = session_id.mid( p +1 );
+ session_id = session_id.left( p );
+ }
+ is_session_restored = TRUE;
+ }
+#endif
+ } else if ( qstrcmp(arg, "-reverse") == 0 ) {
+ setReverseLayout( TRUE );
+ } else if ( qstrcmp(arg, "-widgetcount") == 0 ) {
+ widgetCount = TRUE;;
+ } else {
+ argv[j++] = argv[i];
+ }
+#ifndef TQT_NO_STYLE
+ if ( !s.isEmpty() ) {
+ setStyle( s );
+ }
+#endif
+ }
+
+ if(j < argc) {
+#ifdef TQ_WS_MACX
+ static char* empty = "\0";
+ argv[j] = empty;
+#else
+ argv[j] = 0;
+#endif
+ *argcptr = j;
+ }
+}
+
+/*!
+ Initializes the window system and constructs an application object
+ with \a argc command line arguments in \a argv.
+
+ The global \c tqApp pointer refers to this application object. Only
+ one application object should be created.
+
+ This application object must be constructed before any \link
+ TQPaintDevice paint tqdevices\endlink (including widgets, pixmaps, bitmaps
+ etc.).
+
+ Note that \a argc and \a argv might be changed. TQt removes command
+ line arguments that it recognizes. The modified \a argc and \a argv
+ can also be accessed later with \c tqApp->argc() and \c tqApp->argv().
+ The documentation for argv() tqcontains a detailed description of how
+ to process command line arguments.
+
+ TQt debugging options (not available if TQt was compiled with the
+ TQT_NO_DEBUG flag defined):
+ \list
+ \i -nograb, tells TQt that it must never grab the mouse or the keyboard.
+ \i -dograb (only under X11), running under a debugger can cause
+ an implicit -nograb, use -dograb to override.
+ \i -sync (only under X11), switches to synchronous mode for
+ debugging.
+ \endlist
+
+ See \link debug.html Debugging Techniques \endlink for a more
+ detailed explanation.
+
+ All TQt programs automatically support the following command line options:
+ \list
+ \i -reverse causes text to be formatted for right-to-left languages
+ rather than in the usual left-to-right direction.
+ \i -style= \e style, sets the application GUI style. Possible values
+ are \c motif, \c windows, and \c platinum. If you compiled TQt
+ with additional styles or have additional styles as plugins these
+ will be available to the \c -style command line option.
+ \i -style \e style, is the same as listed above.
+ \i -session= \e session, restores the application from an earlier
+ \link session.html session \endlink.
+ \i -session \e session, is the same as listed above.
+ \i -widgetcount, prints debug message at the end about number of widgets left
+ undestroyed and maximum number of widgets existed at the same time
+ \endlist
+
+ The X11 version of TQt also supports some traditional X11
+ command line options:
+ \list
+ \i -display \e display, sets the X display (default is $DISPLAY).
+ \i -tqgeometry \e tqgeometry, sets the client tqgeometry of the
+ \link setMainWidget() main widget\endlink.
+ \i -fn or \c -font \e font, defines the application font. The
+ font should be specified using an X logical font description.
+ \i -bg or \c -background \e color, sets the default background color
+ and an application palette (light and dark shades are calculated).
+ \i -fg or \c -foreground \e color, sets the default foreground color.
+ \i -btn or \c -button \e color, sets the default button color.
+ \i -name \e name, sets the application name.
+ \i -title \e title, sets the application title (caption).
+ \i -visual \c TrueColor, forces the application to use a TrueColor visual
+ on an 8-bit display.
+ \i -ncols \e count, limits the number of colors allocated in the
+ color cube on an 8-bit display, if the application is using the
+ \c TQApplication::ManyColor color specification. If \e count is
+ 216 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green,
+ and 6 of blue); for other values, a cube
+ approximately proportional to a 2x3x1 cube is used.
+ \i -cmap, causes the application to install a private color map
+ on an 8-bit display.
+ \endlist
+
+ \sa argc(), argv()
+*/
+
+//######### BINARY COMPATIBILITY constructor
+TQApplication::TQApplication( int &argc, char **argv )
+{
+ construct( argc, argv, GuiClient );
+}
+
+
+/*!
+ Constructs an application object with \a argc command line arguments
+ in \a argv. If \a GUIenabled is TRUE, a GUI application is
+ constructed, otherwise a non-GUI (console) application is created.
+
+ Set \a GUIenabled to FALSE for programs without a graphical user
+ interface that should be able to run without a window system.
+
+ On X11, the window system is initialized if \a GUIenabled is TRUE.
+ If \a GUIenabled is FALSE, the application does not connect to the
+ X-server.
+ On Windows and Macintosh, currently the window system is always
+ initialized, regardless of the value of GUIenabled. This may change in
+ future versions of TQt.
+
+ The following example shows how to create an application that
+ uses a graphical interface when available.
+ \code
+ int main( int argc, char **argv )
+ {
+#ifdef TQ_WS_X11
+ bool useGUI = getenv( "DISPLAY" ) != 0;
+#else
+ bool useGUI = TRUE;
+#endif
+ TQApplication app(argc, argv, useGUI);
+
+ if ( useGUI ) {
+ //start GUI version
+ ...
+ } else {
+ //start non-GUI version
+ ...
+ }
+ return app.exec();
+ }
+\endcode
+*/
+
+TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled )
+{
+ construct( argc, argv, GUIenabled ? GuiClient : Tty );
+}
+
+/*!
+ Constructs an application object with \a argc command line arguments
+ in \a argv.
+
+ For TQt/Embedded, passing \c TQApplication::GuiServer for \a type
+ makes this application the server (equivalent to running with the
+ -qws option).
+*/
+TQApplication::TQApplication( int &argc, char **argv, Type type )
+{
+ construct( argc, argv, type );
+}
+
+TQ_EXPORT void qt_ucm_initialize( TQApplication *theApp )
+{
+ if ( tqApp )
+ return;
+ int argc = theApp->argc();
+ char **argv = theApp->argv();
+ theApp->construct( argc, argv, tqApp->type() );
+
+ TQ_ASSERT( tqApp == theApp );
+}
+
+void TQApplication::construct( int &argc, char **argv, Type type )
+{
+ qt_appType = type;
+ qt_is_gui_used = (type != Tty);
+ init_precmdline();
+ static const char *empty = "";
+ if ( argc == 0 || argv == 0 ) {
+ argc = 0;
+ argv = (char **)&empty; // ouch! careful with TQApplication::argv()!
+ }
+ app_argc = argc;
+ app_argv = argv;
+
+ qt_init( &argc, argv, type ); // Must be called before initialize()
+ process_cmdline( &argc, argv );
+ initialize( argc, argv );
+ if ( qt_is_gui_used )
+ qt_maxWindowRect = desktop()->rect();
+ if ( eventloop )
+ eventloop->appStartingUp();
+}
+
+/*!
+ Returns the type of application, Tty, GuiClient or GuiServer.
+*/
+
+TQApplication::Type TQApplication::type() const
+{
+ return qt_appType;
+}
+
+#if defined(TQ_WS_X11)
+/*!
+ Create an application, given an already open display \a dpy. If \a
+ visual and \a colormap are non-zero, the application will use those as
+ the default Visual and Colormap contexts.
+
+ \warning TQt only supports TrueColor visuals at depths higher than 8
+ bits-per-pixel.
+
+ This is available only on X11.
+*/
+
+TQApplication::TQApplication( Display* dpy, HANDLE visual, HANDLE colormap )
+{
+ static int aargc = 1;
+ // ### a string literal is a cont char*
+ // ### using it as a char* is wrong and could lead to segfaults
+ // ### if aargv is modified someday
+ static char *aargv[] = { (char*)"unknown", 0 };
+
+ app_argc = aargc;
+ app_argv = aargv;
+
+ qt_appType = GuiClient;
+ qt_is_gui_used = TRUE;
+ qt_appType = GuiClient;
+ init_precmdline();
+ // ... no command line.
+
+ if ( ! dpy ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQApplication: invalid Display* argument." );
+#endif // TQT_CHECK_STATE
+
+ qt_init( &aargc, aargv, GuiClient );
+ } else {
+ qt_init( dpy, visual, colormap );
+ }
+
+ initialize( aargc, aargv );
+
+ if ( qt_is_gui_used )
+ qt_maxWindowRect = desktop()->rect();
+ if ( eventloop )
+ eventloop->appStartingUp();
+}
+
+/*!
+ Create an application, given an already open display \a dpy and using
+ \a argc command line arguments in \a argv. If \a
+ visual and \a colormap are non-zero, the application will use those as
+ the default Visual and Colormap contexts.
+
+ \warning TQt only supports TrueColor visuals at depths higher than 8
+ bits-per-pixel.
+
+ This is available only on X11.
+
+*/
+TQApplication::TQApplication(Display *dpy, int argc, char **argv,
+ HANDLE visual, HANDLE colormap)
+{
+ qt_appType = GuiClient;
+ qt_is_gui_used = TRUE;
+ qt_appType = GuiClient;
+ init_precmdline();
+
+ app_argc = argc;
+ app_argv = argv;
+
+ if ( ! dpy ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQApplication: invalid Display* argument." );
+#endif // TQT_CHECK_STATE
+
+ qt_init( &argc, argv, GuiClient );
+ } else {
+ qt_init(dpy, visual, colormap);
+ }
+
+ process_cmdline( &argc, argv );
+ initialize(argc, argv);
+
+ if ( qt_is_gui_used )
+ qt_maxWindowRect = desktop()->rect();
+ if ( eventloop )
+ eventloop->appStartingUp();
+}
+
+
+#endif // TQ_WS_X11
+
+
+void TQApplication::init_precmdline()
+{
+ translators = 0;
+ is_app_closing = FALSE;
+#ifndef TQT_NO_SESSIONMANAGER
+ is_session_restored = FALSE;
+#endif
+#if defined(TQT_CHECK_STATE)
+ if ( tqApp )
+ qWarning( "TQApplication: There should be max one application object" );
+#endif
+ tqApp = (TQApplication*)this;
+}
+
+/*!
+ Initializes the TQApplication object, called from the constructors.
+*/
+
+void TQApplication::initialize( int argc, char **argv )
+{
+#ifdef TQT_THREAD_SUPPORT
+ qt_mutex = new TQMutex( TRUE );
+ postevent_mutex = new TQMutex( TRUE );
+ qt_application_thread_id = TQThread::currentThread();
+#endif // TQT_THREAD_SUPPORT
+
+ app_argc = argc;
+ app_argv = argv;
+ quit_now = FALSE;
+ quit_code = 0;
+ TQWidget::createMapper(); // create widget mapper
+#ifndef TQT_NO_PALETTE
+ (void) palette(); // trigger creation of application palette
+#endif
+ is_app_running = TRUE; // no longer starting up
+
+#ifndef TQT_NO_SESSIONMANAGER
+ // connect to the session manager
+ if ( !session_key )
+ session_key = new TQString;
+ session_manager = new TQSessionManager( tqApp, session_id, *session_key );
+#endif
+
+}
+
+
+/*****************************************************************************
+ Functions returning the active popup and modal widgets.
+ *****************************************************************************/
+
+/*!
+ Returns the active popup widget.
+
+ A popup widget is a special top level widget that sets the \c
+ WType_Popup widget flag, e.g. the TQPopupMenu widget. When the
+ application opens a popup widget, all events are sent to the popup.
+ Normal widgets and modal widgets cannot be accessed before the popup
+ widget is closed.
+
+ Only other popup widgets may be opened when a popup widget is shown.
+ The popup widgets are organized in a stack. This function returns
+ the active popup widget at the top of the stack.
+
+ \sa activeModalWidget(), tqtopLevelWidgets()
+*/
+
+TQWidget *TQApplication::activePopupWidget()
+{
+ return popupWidgets ? popupWidgets->getLast() : 0;
+}
+
+
+/*!
+ Returns the active modal widget.
+
+ A modal widget is a special top level widget which is a subclass of
+ TQDialog that specifies the modal parameter of the constructor as
+ TRUE. A modal widget must be closed before the user can continue
+ with other parts of the program.
+
+ Modal widgets are organized in a stack. This function returns
+ the active modal widget at the top of the stack.
+
+ \sa activePopupWidget(), tqtopLevelWidgets()
+*/
+
+TQWidget *TQApplication::activeModalWidget()
+{
+ return qt_modal_stack ? qt_modal_stack->getFirst() : 0;
+}
+
+/*!
+ Cleans up any window system resources that were allocated by this
+ application. Sets the global variable \c tqApp to 0.
+*/
+
+TQApplication::~TQApplication()
+{
+#ifndef TQT_NO_CLIPBOARD
+ // flush clipboard contents
+ if ( qt_clipboard ) {
+ TQCustomEvent event( TQEvent::Clipboard );
+ TQApplication::sendEvent( qt_clipboard, &event );
+ }
+#endif
+
+ if ( eventloop )
+ eventloop->appClosingDown();
+ if ( postRList ) {
+ TQVFuncList::Iterator it = postRList->begin();
+ while ( it != postRList->end() ) { // call post routines
+ (**it)();
+ postRList->remove( it );
+ it = postRList->begin();
+ }
+ delete postRList;
+ postRList = 0;
+ }
+
+ TQObject *tipmanager = child( "toolTipManager", "TQTipManager", FALSE );
+ delete tipmanager;
+
+ delete qt_desktopWidget;
+ qt_desktopWidget = 0;
+ is_app_closing = TRUE;
+
+#ifndef TQT_NO_CLIPBOARD
+ delete qt_clipboard;
+ qt_clipboard = 0;
+#endif
+ TQWidget::destroyMapper();
+#ifndef TQT_NO_PALETTE
+ delete qt_std_pal;
+ qt_std_pal = 0;
+ delete app_pal;
+ app_pal = 0;
+ delete app_palettes;
+ app_palettes = 0;
+#endif
+ delete app_font;
+ app_font = 0;
+ delete app_fonts;
+ app_fonts = 0;
+#ifndef TQT_NO_STYLE
+ delete app_style;
+ app_style = 0;
+#endif
+#ifndef TQT_NO_CURSOR
+ delete app_cursor;
+ app_cursor = 0;
+#endif
+#ifndef TQT_NO_TRANSLATION
+ delete translators;
+#endif
+
+#ifndef TQT_NO_DRAGANDDROP
+ extern TQDragManager *qt_dnd_manager;
+ delete qt_dnd_manager;
+#endif
+
+ qt_cleanup();
+
+#ifndef TQT_NO_COMPONENT
+ delete app_libpaths;
+ app_libpaths = 0;
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+ delete qt_mutex;
+ qt_mutex = 0;
+ delete postevent_mutex;
+ postevent_mutex = 0;
+#endif // TQT_THREAD_SUPPORT
+
+ if( tqApp == this ) {
+ if ( postedEvents )
+ removePostedEvents( this );
+ tqApp = 0;
+ }
+ is_app_running = FALSE;
+
+ if ( widgetCount ) {
+ qDebug( "Widgets left: %i Max widgets: %i \n", TQWidget::instanceCounter, TQWidget::maxInstances );
+ }
+#ifndef TQT_NO_SESSIONMANAGER
+ delete session_manager;
+ session_manager = 0;
+ delete session_key;
+ session_key = 0;
+#endif //TQT_NO_SESSIONMANAGER
+
+ qt_explicit_app_style = FALSE;
+ qt_app_has_font = FALSE;
+ app_tracking = 0;
+ obey_desktop_settings = TRUE;
+ cursor_flash_time = 1000;
+ mouse_double_click_time = 400;
+#ifndef TQT_NO_WHEELEVENT
+ wheel_scroll_lines = 3;
+#endif
+ drag_time = 500;
+ drag_distance = 4;
+ reverse_tqlayout = FALSE;
+ app_strut = TQSize( 0, 0 );
+ animate_ui = TRUE;
+ animate_menu = FALSE;
+ fade_menu = FALSE;
+ animate_combo = FALSE;
+ animate_tooltip = FALSE;
+ fade_tooltip = FALSE;
+ widgetCount = FALSE;
+}
+
+
+/*!
+ \fn int TQApplication::argc() const
+
+ Returns the number of command line arguments.
+
+ The documentation for argv() describes how to process command line
+ arguments.
+
+ \sa argv(), TQApplication::TQApplication()
+*/
+
+/*!
+ \fn char **TQApplication::argv() const
+
+ Returns the command line argument vector.
+
+ \c argv()[0] is the program name, \c argv()[1] is the first
+ argument and \c argv()[argc()-1] is the last argument.
+
+ A TQApplication object is constructed by passing \e argc and \e
+ argv from the \c main() function. Some of the arguments may be
+ recognized as TQt options and removed from the argument vector. For
+ example, the X11 version of TQt knows about \c -display, \c -font
+ and a few more options.
+
+ Example:
+ \code
+ // showargs.cpp - displays program arguments in a list box
+
+ #include <tqapplication.h>
+ #include <tqlistbox.h>
+
+ int main( int argc, char **argv )
+ {
+ TQApplication a( argc, argv );
+ TQListBox b;
+ a.setMainWidget( &b );
+ for ( int i = 0; i < a.argc(); i++ ) // a.argc() == argc
+ b.insertItem( a.argv()[i] ); // a.argv()[i] == argv[i]
+ b.show();
+ return a.exec();
+ }
+ \endcode
+
+ If you run \c{showargs -display unix:0 -font 9x15bold hello world}
+ under X11, the list box tqcontains the three strings "showargs",
+ "hello" and "world".
+
+ TQt provides a global pointer, \c tqApp, that points to the
+ TQApplication object, and through which you can access argc() and
+ argv() in functions other than main().
+
+ \sa argc(), TQApplication::TQApplication()
+*/
+
+/*!
+ \fn void TQApplication::setArgs( int argc, char **argv )
+ \internal
+*/
+
+
+#ifndef TQT_NO_STYLE
+
+static TQString *qt_style_override = 0;
+
+/*!
+ Returns the application's style object.
+
+ \sa setStyle(), TQStyle
+*/
+TQStyle& TQApplication::tqstyle()
+{
+#ifndef TQT_NO_STYLE
+ if ( app_style )
+ return *app_style;
+ if ( !qt_is_gui_used )
+ qFatal( "No style available in non-gui applications!" );
+
+#if defined(TQ_WS_X11)
+ if(!qt_style_override)
+ x11_initialize_style(); // run-time search for default style
+#endif
+ if ( !app_style ) {
+ // Compile-time search for default style
+ //
+ TQString style;
+ if ( qt_style_override ) {
+ style = *qt_style_override;
+ delete qt_style_override;
+ qt_style_override = 0;
+ } else {
+# if defined(TQ_WS_WIN) && defined(TQ_OS_TEMP)
+ style = "PocketPC";
+#elif defined(TQ_WS_WIN)
+ if ( qWinVersion() >= TQt::WV_XP && qWinVersion() < TQt::WV_NT_based )
+ style = "WindowsXP";
+ else
+ style = "Windows"; // default styles for Windows
+#elif defined(TQ_WS_X11) && defined(TQ_OS_SOLARIS)
+ style = "CDE"; // default style for X11 on Solaris
+#elif defined(TQ_WS_X11) && defined(TQ_OS_IRIX)
+ style = "SGI"; // default style for X11 on IRIX
+#elif defined(TQ_WS_X11)
+ style = "Motif"; // default style for X11
+#elif defined(TQ_WS_MAC)
+ style = "Macintosh"; // default style for all Mac's
+#elif defined(TQ_WS_TQWS)
+ style = "Compact"; // default style for small tqdevices
+#endif
+ }
+ app_style = TQStyleFactory::create( style );
+ if ( !app_style && // platform default style not available, try alternatives
+ !(app_style = TQStyleFactory::create( "Windows" ) ) &&
+ !(app_style = TQStyleFactory::create( "Platinum" ) ) &&
+ !(app_style = TQStyleFactory::create( "MotifPlus" ) ) &&
+ !(app_style = TQStyleFactory::create( "Motif" ) ) &&
+ !(app_style = TQStyleFactory::create( "CDE" ) ) &&
+ !(app_style = TQStyleFactory::create( "Aqua" ) ) &&
+ !(app_style = TQStyleFactory::create( "SGI" ) ) &&
+ !(app_style = TQStyleFactory::create( "Compact" ) )
+#ifndef TQT_NO_STRINGLIST
+ && !(app_style = TQStyleFactory::create( TQStyleFactory::keys()[0] ) )
+#endif
+ )
+ qFatal( "No %s style available!", style.latin1() );
+ }
+
+ TQPalette app_pal_copy ( *app_pal );
+ app_style->polish( *app_pal );
+
+ if ( is_app_running && !is_app_closing && (*app_pal != app_pal_copy) ) {
+ TQEvent e( TQEvent::ApplicationPaletteChange );
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ sendEvent( w, &e );
+ }
+ }
+
+ app_style->polish( tqApp );
+#endif
+ return *app_style;
+}
+
+/*!
+ Sets the application's GUI style to \a style. Ownership of the style
+ object is transferred to TQApplication, so TQApplication will delete
+ the style object on application exit or when a new style is set.
+
+ Example usage:
+ \code
+ TQApplication::setStyle( new TQWindowsStyle );
+ \endcode
+
+ When switching application styles, the color palette is set back to
+ the initial colors or the system defaults. This is necessary since
+ certain styles have to adapt the color palette to be fully
+ style-guide compliant.
+
+ \sa style(), TQStyle, setPalette(), desktopSettingsAware()
+*/
+void TQApplication::setStyle( TQStyle *style )
+{
+ TQStyle* old = app_style;
+ app_style = style;
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ delete old;
+ return;
+ }
+
+ // clean up the old style
+ if (old) {
+ if ( is_app_running && !is_app_closing ) {
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( !w->testWFlags(WType_Desktop) && // except desktop
+ w->testWState(WState_Polished) ) { // has been polished
+ old->unPolish(w);
+ }
+ }
+ }
+ old->unPolish( tqApp );
+ }
+
+ // take care of possible palette requirements of certain gui
+ // styles. Do it before polishing the application since the style
+ // might call TQApplication::setStyle() itself
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+ TQPalette tmpPal = *qt_std_pal;
+ setPalette( tmpPal, TRUE );
+
+ // initialize the application with the new style
+ app_style->polish( tqApp );
+
+ // re-polish existing widgets if necessary
+ if (old) {
+ if ( is_app_running && !is_app_closing ) {
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( !w->testWFlags(WType_Desktop) ) { // except desktop
+ if ( w->testWState(WState_Polished) )
+ app_style->polish(w); // repolish
+ w->styleChange( *old );
+ if ( w->isVisible() ){
+ w->update();
+ }
+ }
+ }
+ }
+ delete old;
+ }
+}
+
+/*!
+ \overload
+
+ Requests a TQStyle object for \a style from the TQStyleFactory.
+
+ The string must be one of the TQStyleFactory::keys(), typically one
+ of "windows", "motif", "cde", "motifplus", "platinum", "sgi" and
+ "compact". Depending on the platform, "windowsxp", "aqua" or
+ "macintosh" may be available.
+
+ A later call to the TQApplication constructor will override the
+ requested style when a "-style" option is passed in as a commandline
+ parameter.
+
+ Returns 0 if an unknown \a style is passed, otherwise the TQStyle object
+ returned is set as the application's GUI style.
+*/
+TQStyle* TQApplication::setStyle( const TQString& style )
+{
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ if(qt_style_override)
+ *qt_style_override = style;
+ else
+ qt_style_override = new TQString(style);
+ return 0;
+ }
+ TQStyle *s = TQStyleFactory::create( style );
+ if ( !s )
+ return 0;
+
+ setStyle( s );
+ return s;
+}
+
+#endif
+
+
+#if 1 /* OBSOLETE */
+
+TQApplication::ColorMode TQApplication::colorMode()
+{
+ return (TQApplication::ColorMode)app_cspec;
+}
+
+void TQApplication::setColorMode( TQApplication::ColorMode mode )
+{
+ app_cspec = mode;
+}
+#endif
+
+
+/*!
+ Returns the color specification.
+ \sa TQApplication::setColorSpec()
+ */
+
+int TQApplication::colorSpec()
+{
+ return app_cspec;
+}
+
+/*!
+ Sets the color specification for the application to \a spec.
+
+ The color specification controls how the application allocates colors
+ when run on a display with a limited amount of colors, e.g. 8 bit / 256
+ color displays.
+
+ The color specification must be set before you create the TQApplication
+ object.
+
+ The options are:
+ \list
+ \i TQApplication::NormalColor.
+ This is the default color allocation strategy. Use this option if
+ your application uses buttons, menus, texts and pixmaps with few
+ colors. With this option, the application uses system global
+ colors. This works fine for most applications under X11, but on
+ Windows machines it may cause dithering of non-standard colors.
+ \i TQApplication::CustomColor.
+ Use this option if your application needs a small number of custom
+ colors. On X11, this option is the same as NormalColor. On Windows, TQt
+ creates a Windows palette, and allocates colors to it on demand.
+ \i TQApplication::ManyColor.
+ Use this option if your application is very color hungry
+ (e.g. it requires thousands of colors).
+ Under X11 the effect is:
+ \list
+ \i For 256-color displays which have at best a 256 color true color
+ visual, the default visual is used, and colors are allocated
+ from a color cube. The color cube is the 6x6x6 (216 color) "Web
+ palette"<sup>*</sup>, but the number of colors can be changed
+ by the \e -ncols option. The user can force the application to
+ use the true color visual with the \link
+ TQApplication::TQApplication() -visual \endlink option.
+ \i For 256-color displays which have a true color visual with more
+ than 256 colors, use that visual. Silicon Graphics X servers
+ have this feature, for example. They provide an 8 bit visual
+ by default but can deliver true color when asked.
+ \endlist
+ On Windows, TQt creates a Windows palette, and fills it with a color cube.
+ \endlist
+
+ Be aware that the CustomColor and ManyColor choices may lead to colormap
+ flashing: The foreground application gets (most) of the available
+ colors, while the background windows will look less attractive.
+
+ Example:
+ \code
+ int main( int argc, char **argv )
+ {
+ TQApplication::setColorSpec( TQApplication::ManyColor );
+ TQApplication a( argc, argv );
+ ...
+ }
+ \endcode
+
+ TQColor provides more functionality for controlling color allocation and
+ freeing up certain colors. See TQColor::enterAllocContext() for more
+ information.
+
+ To check what mode you end up with, call TQColor::numBitPlanes() once
+ the TQApplication object exists. A value greater than 8 (typically
+ 16, 24 or 32) means true color.
+
+ <sup>*</sup> The color cube used by TQt has 216 colors whose red,
+ green, and blue components always have one of the following values:
+ 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF.
+
+ \sa colorSpec(), TQColor::numBitPlanes(), TQColor::enterAllocContext() */
+
+void TQApplication::setColorSpec( int spec )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( tqApp ) {
+ qWarning( "TQApplication::setColorSpec: This function must be "
+ "called before the TQApplication object is created" );
+ }
+#endif
+ app_cspec = spec;
+}
+
+/*!
+ \fn TQSize TQApplication::globalStrut()
+
+ Returns the application's global strut.
+
+ The strut is a size object whose dimensions are the minimum that any
+ GUI element that the user can interact with should have. For example
+ no button should be resized to be smaller than the global strut size.
+
+ \sa setGlobalStrut()
+*/
+
+/*!
+ Sets the application's global strut to \a strut.
+
+ The strut is a size object whose dimensions are the minimum that any
+ GUI element that the user can interact with should have. For example
+ no button should be resized to be smaller than the global strut size.
+
+ The strut size should be considered when reimplementing GUI controls
+ that may be used on touch-screens or similar IO-tqdevices.
+
+ Example:
+ \code
+ TQSize& WidgetClass::tqsizeHint() const
+ {
+ return TQSize( 80, 25 ).expandedTo( TQApplication::globalStrut() );
+ }
+ \endcode
+
+ \sa globalStrut()
+*/
+
+void TQApplication::setGlobalStrut( const TQSize& strut )
+{
+ app_strut = strut;
+}
+
+#if defined( TQ_WS_WIN ) || defined( TQ_WS_MAC )
+extern const char *tqAppFileName();
+#endif
+
+#ifndef TQT_NO_DIR
+#ifndef TQ_WS_WIN
+static TQString resolveSymlinks( const TQString& path, int depth = 0 )
+{
+ bool foundLink = FALSE;
+ TQString linkTarget;
+ TQString part = path;
+ int slashPos = path.length();
+
+ // too deep; we give up
+ if ( depth == 128 )
+ return TQString::null;
+
+ do {
+ part = part.left( slashPos );
+ TQFileInfo fileInfo( part );
+ if ( fileInfo.isSymLink() ) {
+ foundLink = TRUE;
+ linkTarget = fileInfo.readLink();
+ break;
+ }
+ } while ( (slashPos = part.tqfindRev('/')) != -1 );
+
+ if ( foundLink ) {
+ TQString path2;
+ if ( linkTarget[0] == '/' ) {
+ path2 = linkTarget;
+ if ( slashPos < (int) path.length() )
+ path2 += "/" + path.right( path.length() - slashPos - 1 );
+ } else {
+ TQString relPath;
+ relPath = part.left( part.tqfindRev('/') + 1 ) + linkTarget;
+ if ( slashPos < (int) path.length() ) {
+ if ( !linkTarget.endsWith( "/" ) )
+ relPath += "/";
+ relPath += path.right( path.length() - slashPos - 1 );
+ }
+ path2 = TQDir::current().absFilePath( relPath );
+ }
+ path2 = TQDir::cleanDirPath( path2 );
+ return resolveSymlinks( path2, depth + 1 );
+ } else {
+ return path;
+ }
+}
+#endif // TQ_WS_WIN
+
+/*!
+ Returns the directory that tqcontains the application executable.
+
+ For example, if you have installed TQt in the \c{C:\Trolltech\TQt}
+ directory, and you run the \c{demo} example, this function will
+ return "C:/Trolltech/TQt/examples/demo".
+
+ On Mac OS X this will point to the directory actually containing the
+ executable, which may be inside of an application bundle (if the
+ application is bundled).
+
+ \warning On Unix, this function assumes that argv[0] tqcontains the file
+ name of the executable (which it normally does). It also assumes that
+ the current directory hasn't been changed by the application.
+
+ \sa applicationFilePath()
+*/
+TQString TQApplication::applicationDirPath()
+{
+ return TQFileInfo( applicationFilePath() ).dirPath();
+}
+
+/*!
+ Returns the file path of the application executable.
+
+ For example, if you have installed TQt in the \c{C:\Trolltech\TQt}
+ directory, and you run the \c{demo} example, this function will
+ return "C:/Trolltech/TQt/examples/demo/demo.exe".
+
+ \warning On Unix, this function assumes that argv[0] tqcontains the file
+ name of the executable (which it normally does). It also assumes that
+ the current directory hasn't been changed by the application.
+
+ \sa applicationDirPath()
+*/
+TQString TQApplication::applicationFilePath()
+{
+#if defined( TQ_WS_WIN )
+ TQFileInfo filePath;
+ TQT_WA({
+ WCHAR module_name[256];
+ GetModuleFileNameW(0, module_name, sizeof(module_name));
+ filePath = TQString::fromUcs2((const unsigned short *)module_name);
+ }, {
+ char module_name[256];
+ GetModuleFileNameA(0, module_name, sizeof(module_name));
+ filePath = TQString::fromLocal8Bit(module_name);
+ });
+
+ return filePath.filePath();
+#elif defined( TQ_WS_MAC )
+ return TQDir::cleanDirPath( TQFile::decodeName( tqAppFileName() ) );
+#else
+ TQString argv0 = TQFile::decodeName( argv()[0] );
+ TQString absPath;
+
+ if ( argv0[0] == '/' ) {
+ /*
+ If argv0 starts with a slash, it is already an absolute
+ file path.
+ */
+ absPath = argv0;
+ } else if ( argv0.tqfind('/') != -1 ) {
+ /*
+ If argv0 tqcontains one or more slashes, it is a file path
+ relative to the current directory.
+ */
+ absPath = TQDir::current().absFilePath( argv0 );
+ } else {
+ /*
+ Otherwise, the file path has to be determined using the
+ PATH environment variable.
+ */
+ char *pEnv = getenv( "PATH" );
+ TQStringList paths( TQStringList::split(TQChar(':'), pEnv) );
+ TQStringList::const_iterator p = paths.begin();
+ while ( p != paths.end() ) {
+ TQString candidate = TQDir::current().absFilePath( *p + "/" + argv0 );
+ if ( TQFile::exists(candidate) ) {
+ absPath = candidate;
+ break;
+ }
+ ++p;
+ }
+ }
+
+ absPath = TQDir::cleanDirPath( absPath );
+ if ( TQFile::exists(absPath) ) {
+ return resolveSymlinks( absPath );
+ } else {
+ return TQString::null;
+ }
+#endif
+}
+#endif // TQT_NO_DIR
+
+#ifndef TQT_NO_COMPONENT
+
+/*!
+ Returns a list of paths that the application will search when
+ dynamically loading libraries.
+ The installation directory for plugins is the only entry if no
+ paths have been set. The default installation directory for plugins
+ is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was
+ installed. The directory of the application executable (NOT the
+ working directory) is also added to the plugin paths.
+
+ If you want to iterate over the list, you should iterate over a
+ copy, e.g.
+ \code
+ TQStringList list = app.libraryPaths();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ See the \link plugins-howto.html plugins documentation\endlink for a
+ description of how the library paths are used.
+
+ \sa tqsetLibraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary
+*/
+TQStringList TQApplication::libraryPaths()
+{
+ if ( !app_libpaths ) {
+ app_libpaths = new TQStringList;
+ TQString installPathPlugins = TQString::fromLocal8Bit(qInstallPathPlugins());
+ if ( TQFile::exists(installPathPlugins) ) {
+#ifdef TQ_WS_WIN
+ installPathPlugins.tqreplace('\\', '/');
+#endif
+ app_libpaths->append(installPathPlugins);
+ }
+
+ TQString app_location;
+ if (tqApp)
+ app_location = tqApp->applicationFilePath();
+#ifdef TQ_WS_WIN
+ else {
+ app_location = TQString(tqAppFileName());
+ app_location.tqreplace('\\', '/');
+ }
+#endif
+ if (!app_location.isEmpty()) {
+ app_location.truncate( app_location.tqfindRev( '/' ) );
+ if ( app_location != qInstallPathPlugins() && TQFile::exists( app_location ) )
+ app_libpaths->append( app_location );
+ }
+ }
+ return *app_libpaths;
+}
+
+
+/*!
+ Sets the list of directories to search when loading libraries to \a paths.
+ All existing paths will be deleted and the path list will consist of the
+ paths given in \a paths.
+
+ \sa libraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary
+ */
+void TQApplication::tqsetLibraryPaths( const TQStringList &paths )
+{
+ delete app_libpaths;
+ app_libpaths = new TQStringList( paths );
+}
+
+/*!
+ Append \a path to the end of the library path list. If \a path is
+ empty or already in the path list, the path list is not changed.
+
+ The default path list consists of a single entry, the installation
+ directory for plugins. The default installation directory for plugins
+ is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was
+ installed.
+
+ \sa removeLibraryPath(), libraryPaths(), tqsetLibraryPaths()
+ */
+void TQApplication::addLibraryPath( const TQString &path )
+{
+ if ( path.isEmpty() )
+ return;
+
+ // make sure that library paths is initialized
+ libraryPaths();
+
+ if ( !app_libpaths->tqcontains( path ) )
+ app_libpaths->prepend( path );
+}
+
+/*!
+ Removes \a path from the library path list. If \a path is empty or not
+ in the path list, the list is not changed.
+
+ \sa addLibraryPath(), libraryPaths(), tqsetLibraryPaths()
+*/
+void TQApplication::removeLibraryPath( const TQString &path )
+{
+ if ( path.isEmpty() )
+ return;
+
+ // make sure that library paths is initialized
+ libraryPaths();
+
+ if ( app_libpaths->tqcontains( path ) )
+ app_libpaths->remove( path );
+}
+#endif //TQT_NO_COMPONENT
+
+/*!
+ Returns the application palette.
+
+ If a widget is passed in \a w, the default palette for the
+ widget's class is returned. This may or may not be the application
+ palette. In most cases there isn't a special palette for certain
+ types of widgets, but one notable exception is the popup menu under
+ Windows, if the user has defined a special background color for
+ menus in the display settings.
+
+ \sa setPalette(), TQWidget::palette()
+*/
+#ifndef TQT_NO_PALETTE
+TQPalette TQApplication::palette(const TQWidget* w)
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !tqApp )
+ qWarning( "TQApplication::palette: This function can only be "
+ "called after the TQApplication object has been created" );
+#endif
+ if ( !app_pal ) {
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+ app_pal = new TQPalette( *qt_std_pal );
+ qt_fix_tooltips();
+ }
+
+ if ( w && app_palettes ) {
+ TQPalette* wp = app_palettes->tqfind( w->className() );
+ if ( wp )
+ return *wp;
+ TQAsciiDictIterator<TQPalette> it( *app_palettes );
+ const char* name;
+ while ( (name=it.currentKey()) != 0 ) {
+ if ( w->inherits( name ) )
+ return *it.current();
+ ++it;
+ }
+ }
+ return *app_pal;
+}
+
+/*!
+ Changes the default application palette to \a palette. If \a
+ informWidgets is TRUE, then existing widgets are informed about the
+ change and may adjust themselves to the new application
+ setting. If \a informWidgets is FALSE, the change only affects newly
+ created widgets.
+
+ If \a className is passed, the change applies only to widgets that
+ inherit \a className (as reported by TQObject::inherits()). If
+ \a className is left 0, the change affects all widgets, thus overriding
+ any previously set class specific palettes.
+
+ The palette may be changed according to the current GUI style in
+ TQStyle::polish().
+
+ \sa TQWidget::setPalette(), palette(), TQStyle::polish()
+*/
+
+void TQApplication::setPalette( const TQPalette &palette, bool informWidgets,
+ const char* className )
+{
+ TQPalette pal = palette;
+ TQPalette *oldpal = 0;
+#ifndef TQT_NO_STYLE
+ if ( !startingUp() ) // on startup this has been done already
+ tqApp->style().polish( pal ); // NB: non-const reference
+#endif
+ bool all = FALSE;
+ if ( !className ) {
+ if ( !app_pal ) {
+ app_pal = new TQPalette( pal );
+ TQ_CHECK_PTR( app_pal );
+ } else {
+ *app_pal = pal;
+ }
+ all = app_palettes != 0;
+ delete app_palettes;
+ app_palettes = 0;
+ qt_fix_tooltips();
+ } else {
+ if ( !app_palettes ) {
+ app_palettes = new TQAsciiDict<TQPalette>;
+ TQ_CHECK_PTR( app_palettes );
+ app_palettes->setAutoDelete( TRUE );
+ }
+ oldpal = app_palettes->tqfind( className );
+ app_palettes->insert( className, new TQPalette( pal ) );
+ }
+ if ( informWidgets && is_app_running && !is_app_closing ) {
+ if ( !oldpal || ( *oldpal != pal ) ) {
+ TQEvent e( TQEvent::ApplicationPaletteChange );
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class
+ sendEvent( w, &e );
+ }
+ }
+ }
+}
+
+#endif // TQT_NO_PALETTE
+
+/*!
+ Returns the default font for the widget \a w, or the default
+ application font if \a w is 0.
+
+ \sa setFont(), fontMetrics(), TQWidget::font()
+*/
+
+TQFont TQApplication::font( const TQWidget *w )
+{
+ if ( w && app_fonts ) {
+ TQFont* wf = app_fonts->tqfind( w->className() );
+ if ( wf )
+ return *wf;
+ TQAsciiDictIterator<TQFont> it( *app_fonts );
+ const char* name;
+ while ( (name=it.currentKey()) != 0 ) {
+ if ( w->inherits( name ) )
+ return *it.current();
+ ++it;
+ }
+ }
+ if ( !app_font ) {
+ app_font = new TQFont( "Helvetica" );
+ TQ_CHECK_PTR( app_font );
+ }
+ return *app_font;
+}
+
+/*! Changes the default application font to \a font. If \a
+ informWidgets is TRUE, then existing widgets are informed about the
+ change and may adjust themselves to the new application
+ setting. If \a informWidgets is FALSE, the change only affects newly
+ created widgets. If \a className is passed, the change applies only
+ to classes that inherit \a className (as reported by
+ TQObject::inherits()).
+
+ On application start-up, the default font depends on the window
+ system. It can vary depending on both the window system version and
+ the locale. This function lets you override the default font; but
+ overriding may be a bad idea because, for example, some locales need
+ extra-large fonts to support their special characters.
+
+ \sa font(), fontMetrics(), TQWidget::setFont()
+*/
+
+void TQApplication::setFont( const TQFont &font, bool informWidgets,
+ const char* className )
+{
+ bool all = FALSE;
+ if ( !className ) {
+ qt_app_has_font = TRUE;
+ if ( !app_font ) {
+ app_font = new TQFont( font );
+ TQ_CHECK_PTR( app_font );
+ } else {
+ *app_font = font;
+ }
+
+ // make sure the application font is complete
+ app_font->detach();
+ app_font->d->tqmask = TQFontPrivate::Complete;
+
+ all = app_fonts != 0;
+ delete app_fonts;
+ app_fonts = 0;
+ } else {
+ if (!app_fonts){
+ app_fonts = new TQAsciiDict<TQFont>;
+ TQ_CHECK_PTR( app_fonts );
+ app_fonts->setAutoDelete( TRUE );
+ }
+ TQFont* fnt = new TQFont(font);
+ TQ_CHECK_PTR( fnt );
+ app_fonts->insert(className, fnt);
+ }
+ if ( informWidgets && is_app_running && !is_app_closing ) {
+ TQEvent e( TQEvent::ApplicationFontChange );
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class
+ sendEvent( w, &e );
+ }
+ }
+}
+
+
+/*!
+ Initialization of the appearance of the widget \a w \e before it is first
+ shown.
+
+ Usually widgets call this automatically when they are polished. It
+ may be used to do some style-based central customization of widgets.
+
+ Note that you are not limited to the public functions of TQWidget.
+ Instead, based on meta information like TQObject::className() you are
+ able to customize any kind of widget.
+
+ \sa TQStyle::polish(), TQWidget::polish(), setPalette(), setFont()
+*/
+
+void TQApplication::polish( TQWidget *w )
+{
+#ifndef TQT_NO_STYLE
+ w->style().polish( w );
+#endif
+}
+
+
+/*!
+ Returns a list of the top level widgets in the application.
+
+ The list is created using \c new and must be deleted by the caller.
+
+ The list is empty (TQPtrList::isEmpty()) if there are no top level
+ widgets.
+
+ Note that some of the top level widgets may be hidden, for example
+ the tooltip if no tooltip is currently shown.
+
+ Example:
+ \code
+ // Show all hidden top level widgets.
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ TQWidgetListIt it( *list ); // iterate over the widgets
+ TQWidget * w;
+ while ( (w=it.current()) != 0 ) { // for each top level widget...
+ ++it;
+ if ( !w->isVisible() )
+ w->show();
+ }
+ delete list; // delete the list, not the widgets
+ \endcode
+
+ \warning Delete the list as soon you have finished using it.
+ The widgets in the list may be deleted by someone else at any time.
+
+ \sa allWidgets(), TQWidget::isTopLevel(), TQWidget::isVisible(),
+ TQPtrList::isEmpty()
+*/
+
+TQWidgetList *TQApplication::tqtopLevelWidgets()
+{
+ return TQWidget::tlwList();
+}
+
+/*!
+ Returns a list of all the widgets in the application.
+
+ The list is created using \c new and must be deleted by the caller.
+
+ The list is empty (TQPtrList::isEmpty()) if there are no widgets.
+
+ Note that some of the widgets may be hidden.
+
+ Example that updates all widgets:
+ \code
+ TQWidgetList *list = TQApplication::allWidgets();
+ TQWidgetListIt it( *list ); // iterate over the widgets
+ TQWidget * w;
+ while ( (w=it.current()) != 0 ) { // for each widget...
+ ++it;
+ w->update();
+ }
+ delete list; // delete the list, not the widgets
+ \endcode
+
+ The TQWidgetList class is defined in the \c tqwidgetlist.h header
+ file.
+
+ \warning Delete the list as soon as you have finished using it.
+ The widgets in the list may be deleted by someone else at any time.
+
+ \sa tqtopLevelWidgets(), TQWidget::isVisible(), TQPtrList::isEmpty(),
+*/
+
+TQWidgetList *TQApplication::allWidgets()
+{
+ return TQWidget::wList();
+}
+
+/*!
+ \fn TQWidget *TQApplication::tqfocusWidget() const
+
+ Returns the application widget that has the keyboard input focus, or
+ 0 if no widget in this application has the focus.
+
+ \sa TQWidget::setFocus(), TQWidget::hasFocus(), activeWindow()
+*/
+
+/*!
+ \fn TQWidget *TQApplication::activeWindow() const
+
+ Returns the application top-level window that has the keyboard input
+ focus, or 0 if no application window has the focus. Note that
+ there might be an activeWindow() even if there is no tqfocusWidget(),
+ for example if no widget in that window accepts key events.
+
+ \sa TQWidget::setFocus(), TQWidget::hasFocus(), tqfocusWidget()
+*/
+
+/*!
+ Returns display (screen) font metrics for the application font.
+
+ \sa font(), setFont(), TQWidget::fontMetrics(), TQPainter::fontMetrics()
+*/
+
+TQFontMetrics TQApplication::fontMetrics()
+{
+ return desktop()->fontMetrics();
+}
+
+
+
+/*!
+ Tells the application to exit with return code 0 (success).
+ Equivalent to calling TQApplication::exit( 0 ).
+
+ It's common to connect the lastWindowClosed() signal to quit(), and
+ you also often connect e.g. TQButton::clicked() or Q_SIGNALS in
+ TQAction, TQPopupMenu or TQMenuBar to it.
+
+ Example:
+ \code
+ TQPushButton *quitButton = new TQPushButton( "Quit" );
+ connect( quitButton, TQT_SIGNAL(clicked()), tqApp, TQT_SLOT(quit()) );
+ \endcode
+
+ \sa exit() aboutToQuit() lastWindowClosed() TQAction
+*/
+
+void TQApplication::quit()
+{
+ TQApplication::exit( 0 );
+}
+
+
+/*!
+ Closes all top-level windows.
+
+ This function is particularly useful for applications with many
+ top-level windows. It could, for example, be connected to a "Quit"
+ entry in the file menu as shown in the following code example:
+
+ \code
+ // the "Quit" menu entry should try to close all windows
+ TQPopupMenu* file = new TQPopupMenu( this );
+ file->insertItem( "&Quit", tqApp, TQT_SLOT(closeAllWindows()), CTRL+Key_Q );
+
+ // when the last window is closed, the application should quit
+ connect( tqApp, TQT_SIGNAL( lastWindowClosed() ), tqApp, TQT_SLOT( quit() ) );
+ \endcode
+
+ The windows are closed in random order, until one window does not
+ accept the close event.
+
+ \sa TQWidget::close(), TQWidget::closeEvent(), lastWindowClosed(),
+ quit(), tqtopLevelWidgets(), TQWidget::isTopLevel()
+
+ */
+void TQApplication::closeAllWindows()
+{
+ bool did_close = TRUE;
+ TQWidget *w;
+ while((w = activeModalWidget()) && did_close) {
+ if(w->isHidden())
+ break;
+ did_close = w->close();
+ }
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ for ( w = list->first(); did_close && w; ) {
+ if ( !w->isHidden() ) {
+ did_close = w->close();
+ delete list;
+ list = TQApplication::tqtopLevelWidgets();
+ w = list->first();
+ } else {
+ w = list->next();
+ }
+ }
+ delete list;
+}
+
+/*!
+ Displays a simple message box about TQt. The message includes the
+ version number of TQt being used by the application.
+
+ This is useful for inclusion in the Help menu of an application.
+ See the examples/menu/menu.cpp example.
+
+ This function is a convenience slot for TQMessageBox::aboutTQt().
+*/
+void TQApplication::aboutTQt()
+{
+#ifndef TQT_NO_MESSAGEBOX
+ TQMessageBox::aboutTQt( mainWidget() );
+#endif // TQT_NO_MESSAGEBOX
+}
+
+
+/*!
+ \fn void TQApplication::lastWindowClosed()
+
+ This signal is emitted when the user has closed the last
+ top level window.
+
+ The signal is very useful when your application has many top level
+ widgets but no main widget. You can then connect it to the quit()
+ slot.
+
+ For convenience, this signal is \e not emitted for transient top level
+ widgets such as popup menus and dialogs.
+
+ \sa mainWidget(), tqtopLevelWidgets(), TQWidget::isTopLevel(), TQWidget::close()
+*/
+
+/*!
+ \fn void TQApplication::aboutToQuit()
+
+ This signal is emitted when the application is about to quit the
+ main event loop, e.g. when the event loop level drops to zero.
+ This may happen either after a call to quit() from inside the
+ application or when the users shuts down the entire desktop session.
+
+ The signal is particularly useful if your application has to do some
+ last-second cleanup. Note that no user interaction is possible in
+ this state.
+
+ \sa quit()
+*/
+
+
+/*!
+ \fn void TQApplication::guiThreadAwake()
+
+ This signal is emitted after the event loop returns from a function
+ that could block.
+
+ \sa wakeUpGuiThread()
+*/
+
+
+/*!
+ \fn bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event )
+
+ Sends event \a event directly to receiver \a receiver, using the
+ notify() function. Returns the value that was returned from the event
+ handler.
+
+ The event is \e not deleted when the event has been sent. The normal
+ approach is to create the event on the stack, e.g.
+ \code
+ TQMouseEvent me( TQEvent::MouseButtonPress, pos, 0, 0 );
+ TQApplication::sendEvent( mainWindow, &me );
+ \endcode
+ If you create the event on the heap you must delete it.
+
+ \sa postEvent(), notify()
+*/
+
+/*!
+ Sends event \a e to \a receiver: \a {receiver}->event(\a e).
+ Returns the value that is returned from the receiver's event handler.
+
+ For certain types of events (e.g. mouse and key events),
+ the event will be propagated to the receiver's tqparent and so on up to
+ the top-level object if the receiver is not interested in the event
+ (i.e., it returns FALSE).
+
+ There are five different ways that events can be processed;
+ reimplementing this virtual function is just one of them. All five
+ approaches are listed below:
+ \list 1
+ \i Reimplementing this function. This is very powerful, providing
+ complete control; but only one subclass can be tqApp.
+
+ \i Installing an event filter on tqApp. Such an event filter is able
+ to process all events for all widgets, so it's just as powerful as
+ reimplementing notify(); furthermore, it's possible to have more
+ than one application-global event filter. Global event filters even
+ see mouse events for \link TQWidget::isEnabled() disabled
+ widgets, \endlink and if \link setGlobalMouseTracking() global mouse
+ tracking \endlink is enabled, as well as mouse move events for all
+ widgets.
+
+ \i Reimplementing TQObject::event() (as TQWidget does). If you do
+ this you get Tab key presses, and you get to see the events before
+ any widget-specific event filters.
+
+ \i Installing an event filter on the object. Such an event filter
+ gets all the events except Tab and Shift-Tab key presses.
+
+ \i Reimplementing paintEvent(), mousePressEvent() and so
+ on. This is the commonest, easiest and least powerful way.
+ \endlist
+
+ \sa TQObject::event(), installEventFilter()
+*/
+
+bool TQApplication::notify( TQObject *receiver, TQEvent *e )
+{
+ // no events are delivered after ~TQApplication() has started
+ if ( is_app_closing )
+ return FALSE;
+
+ if ( receiver == 0 ) { // serious error
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQApplication::notify: Unexpected null receiver" );
+#endif
+ return FALSE;
+ }
+
+ if ( e->type() == TQEvent::ChildRemoved && receiver->postedEvents && globalPostedEvents) {
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ // the TQObject destructor calls TQObject::removeChild, which calls
+ // TQApplication::sendEvent() directly. this can happen while the event
+ // loop is in the middle of posting events, and when we get here, we may
+ // not have any more posted events for this object.
+ if ( receiver->postedEvents ) {
+ // if this is a child remove event and the child insert
+ // hasn't been dispatched yet, kill that insert
+ TQPostEventList * l = receiver->postedEvents;
+ TQObject * c = ((TQChildEvent*)e)->child();
+ TQPostEvent * pe;
+ l->first();
+ while( ( pe = l->current()) != 0 ) {
+ if ( pe->event && pe->receiver == receiver &&
+ pe->event->type() == TQEvent::ChildInserted &&
+ ((TQChildEvent*)pe->event)->child() == c ) {
+ pe->event->posted = FALSE;
+ delete pe->event;
+ pe->event = 0;
+ l->remove();
+ continue;
+ }
+ l->next();
+ }
+ }
+ }
+
+ bool res = FALSE;
+ if ( !receiver->isWidgetType() )
+ res = internalNotify( receiver, e );
+ else switch ( e->type() ) {
+#ifndef TQT_NO_ACCEL
+ case TQEvent::Accel:
+ {
+ TQKeyEvent* key = (TQKeyEvent*) e;
+ res = internalNotify( receiver, e );
+
+ if ( !res && !key->isAccepted() )
+ res = qt_dispatchAccelEvent( (TQWidget*)receiver, key );
+
+ // next lines are for compatibility with TQt <= 3.0.x: old
+ // TQAccel was listening on toplevel widgets
+ if ( !res && !key->isAccepted() && !((TQWidget*)receiver)->isTopLevel() )
+ res = internalNotify( ((TQWidget*)receiver)->tqtopLevelWidget(), e );
+ }
+ break;
+#endif //TQT_NO_ACCEL
+ case TQEvent::KeyPress:
+ case TQEvent::KeyRelease:
+ case TQEvent::AccelOverride:
+ {
+ TQWidget* w = (TQWidget*)receiver;
+ TQKeyEvent* key = (TQKeyEvent*) e;
+#ifndef TQT_NO_ACCEL
+ if ( qt_tryComposeUnicode( w, key ) )
+ break;
+#endif
+ bool def = key->isAccepted();
+ while ( w ) {
+ if ( def )
+ key->accept();
+ else
+ key->ignore();
+ res = internalNotify( w, e );
+ if ( res || key->isAccepted() )
+ break;
+ w = w->parentWidget( TRUE );
+ }
+ }
+ break;
+ case TQEvent::MouseButtonPress:
+ if ( e->spontaneous() ) {
+ TQWidget* fw = (TQWidget*)receiver;
+ while ( fw->focusProxy() )
+ fw = fw->focusProxy();
+ if ( fw->isEnabled() && fw->focusPolicy() & TQWidget::ClickFocus ) {
+ TQFocusEvent::setReason( TQFocusEvent::Mouse);
+ fw->setFocus();
+ TQFocusEvent::resetReason();
+ }
+ }
+ // fall through intended
+ case TQEvent::MouseButtonRelease:
+ case TQEvent::MouseButtonDblClick:
+ case TQEvent::MouseMove:
+ {
+ TQWidget* w = (TQWidget*)receiver;
+ TQMouseEvent* mouse = (TQMouseEvent*) e;
+ TQPoint relpos = mouse->pos();
+ while ( w ) {
+ TQMouseEvent me(mouse->type(), relpos, mouse->globalPos(), mouse->button(), mouse->state());
+ me.spont = mouse->spontaneous();
+ res = internalNotify( w, w == receiver ? mouse : &me );
+ e->spont = FALSE;
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ mouse->accept();
+ else
+ mouse->ignore();
+ }
+ break;
+#ifndef TQT_NO_WHEELEVENT
+ case TQEvent::Wheel:
+ {
+ if ( e->spontaneous() ) {
+ TQWidget* fw = (TQWidget*)receiver;
+ while ( fw->focusProxy() )
+ fw = fw->focusProxy();
+ if ( fw->isEnabled() && (fw->focusPolicy() & TQWidget::WheelFocus) == TQWidget::WheelFocus ) {
+ TQFocusEvent::setReason( TQFocusEvent::Mouse);
+ fw->setFocus();
+ TQFocusEvent::resetReason();
+ }
+ }
+
+ TQWidget* w = (TQWidget*)receiver;
+ TQWheelEvent* wheel = (TQWheelEvent*) e;
+ TQPoint relpos = wheel->pos();
+ while ( w ) {
+ TQWheelEvent we(relpos, wheel->globalPos(), wheel->delta(), wheel->state(), wheel->orientation());
+ we.spont = wheel->spontaneous();
+ res = internalNotify( w, w == receiver ? wheel : &we );
+ e->spont = FALSE;
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ wheel->accept();
+ else
+ wheel->ignore();
+ }
+ break;
+#endif
+ case TQEvent::ContextMenu:
+ {
+ TQWidget* w = (TQWidget*)receiver;
+ TQContextMenuEvent *context = (TQContextMenuEvent*) e;
+ TQPoint relpos = context->pos();
+ while ( w ) {
+ TQContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->state());
+ ce.spont = e->spontaneous();
+ res = internalNotify( w, w == receiver ? context : &ce );
+ e->spont = FALSE;
+
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ context->accept();
+ else
+ context->ignore();
+ }
+ break;
+#if defined (TQT_TABLET_SUPPORT)
+ case TQEvent::TabletMove:
+ case TQEvent::TabletPress:
+ case TQEvent::TabletRelease:
+ {
+ TQWidget *w = (TQWidget*)receiver;
+ TQTabletEvent *tablet = (TQTabletEvent*)e;
+ TQPoint relpos = tablet->pos();
+ while ( w ) {
+ TQTabletEvent te(tablet->pos(), tablet->globalPos(), tablet->tqdevice(),
+ tablet->pressure(), tablet->xTilt(), tablet->yTilt(),
+ tablet->uniqueId());
+ te.spont = e->spontaneous();
+ res = internalNotify( w, w == receiver ? tablet : &te );
+ e->spont = FALSE;
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ tablet->accept();
+ else
+ tablet->ignore();
+ chokeMouse = tablet->isAccepted();
+ }
+ break;
+#endif
+ default:
+ res = internalNotify( receiver, e );
+ break;
+ }
+
+ return res;
+}
+
+/*!\reimp
+
+*/
+bool TQApplication::event( TQEvent *e )
+{
+ if(e->type() == TQEvent::Close) {
+ TQCloseEvent *ce = (TQCloseEvent*)e;
+ ce->accept();
+ closeAllWindows();
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ for(TQWidget *w = list->first(); w; w = list->next()) {
+ if ( !w->isHidden() && !w->isDesktop() && !w->isPopup() &&
+ (!w->isDialog() || !w->parentWidget())) {
+ ce->ignore();
+ break;
+ }
+ }
+ if(ce->isAccepted())
+ return TRUE;
+ } else if (e->type() == TQEvent::Quit) {
+ quit();
+ return TRUE;
+ }
+ return TQObject::event(e);
+}
+
+/*!\internal
+
+ Helper function called by notify()
+ */
+bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e)
+{
+ if ( eventFilters ) {
+ TQObjectListIt it( *eventFilters );
+ register TQObject *obj;
+ while ( (obj=it.current()) != 0 ) { // send to all filters
+ ++it; // until one returns TRUE
+ if ( obj->eventFilter(receiver,e) )
+ return TRUE;
+ }
+ }
+
+ bool consumed = FALSE;
+ bool handled = FALSE;
+ if ( receiver->isWidgetType() ) {
+ TQWidget *widget = (TQWidget*)receiver;
+
+ // toggle HasMouse widget state on enter and leave
+ if ( e->type() == TQEvent::Enter || e->type() == TQEvent::DragEnter )
+ widget->setWState( WState_HasMouse );
+ else if ( e->type() == TQEvent::Leave || e->type() == TQEvent::DragLeave )
+ widget->clearWState( WState_HasMouse );
+
+ // throw away any mouse-tracking-only mouse events
+ if ( e->type() == TQEvent::MouseMove &&
+ (((TQMouseEvent*)e)->state()&TQMouseEvent::MouseButtonMask) == 0 &&
+ !widget->hasMouseTracking() ) {
+ handled = TRUE;
+ consumed = TRUE;
+ } else if ( !widget->isEnabled() ) { // throw away mouse events to disabled widgets
+ switch(e->type()) {
+ case TQEvent::MouseButtonPress:
+ case TQEvent::MouseButtonRelease:
+ case TQEvent::MouseButtonDblClick:
+ case TQEvent::MouseMove:
+ ( (TQMouseEvent*) e)->ignore();
+ handled = TRUE;
+ consumed = TRUE;
+ break;
+#ifndef TQT_NO_DRAGANDDROP
+ case TQEvent::DragEnter:
+ case TQEvent::DragMove:
+ ( (TQDragMoveEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+
+ case TQEvent::DragLeave:
+ case TQEvent::DragResponse:
+ handled = TRUE;
+ break;
+
+ case TQEvent::Drop:
+ ( (TQDropEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+#endif
+#ifndef TQT_NO_WHEELEVENT
+ case TQEvent::Wheel:
+ ( (TQWheelEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+#endif
+ case TQEvent::ContextMenu:
+ ( (TQContextMenuEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+ default:
+ break;
+ }
+ }
+
+ }
+
+ if (!handled)
+ consumed = receiver->event( e );
+ e->spont = FALSE;
+ return consumed;
+}
+
+/*!
+ Returns TRUE if an application object has not been created yet;
+ otherwise returns FALSE.
+
+ \sa closingDown()
+*/
+
+bool TQApplication::startingUp()
+{
+ return !is_app_running;
+}
+
+/*!
+ Returns TRUE if the application objects are being destroyed;
+ otherwise returns FALSE.
+
+ \sa startingUp()
+*/
+
+bool TQApplication::closingDown()
+{
+ return is_app_closing;
+}
+
+
+/*!
+ Processes pending events, for 3 seconds or until there are no more
+ events to process, whichever is shorter.
+
+ You can call this function occasionally when your program is busy
+ performing a long operation (e.g. copying a file).
+
+ \sa exec(), TQTimer, TQEventLoop::processEvents()
+*/
+
+void TQApplication::processEvents()
+{
+ processEvents( 3000 );
+}
+
+/*!
+ \overload
+
+ Processes pending events for \a maxtime milliseconds or until
+ there are no more events to process, whichever is shorter.
+
+ You can call this function occasionally when you program is busy
+ doing a long operation (e.g. copying a file).
+
+ \sa exec(), TQTimer, TQEventLoop::processEvents()
+*/
+void TQApplication::processEvents( int maxtime )
+{
+ eventLoop()->processEvents( TQEventLoop::AllEvents, maxtime );
+}
+
+/*! \obsolete
+ Waits for an event to occur, processes it, then returns.
+
+ This function is useful for adapting TQt to situations where the
+ event processing must be grafted onto existing program loops.
+
+ Using this function in new applications may be an indication of design
+ problems.
+
+ \sa processEvents(), exec(), TQTimer
+*/
+
+void TQApplication::processOneEvent()
+{
+ eventLoop()->processEvents( TQEventLoop::AllEvents |
+ TQEventLoop::WaitForMore );
+}
+
+/*****************************************************************************
+ Main event loop wrappers
+ *****************************************************************************/
+
+/*!
+ Returns the application event loop. This function will return
+ zero if called during and after destroying TQApplication.
+
+ To create your own instance of TQEventLoop or TQEventLoop subclass create
+ it before you create the TQApplication object.
+
+ \sa TQEventLoop
+*/
+TQEventLoop *TQApplication::eventLoop()
+{
+ if ( !eventloop && !is_app_closing )
+ (void) new TQEventLoop( tqApp, "default event loop" );
+ return eventloop;
+}
+
+
+/*!
+ Enters the main event loop and waits until exit() is called or the
+ main widget is destroyed, and returns the value that was set to
+ exit() (which is 0 if exit() is called via quit()).
+
+ It is necessary to call this function to start event handling. The
+ main event loop receives events from the window system and
+ dispatches these to the application widgets.
+
+ Generally speaking, no user interaction can take place before
+ calling exec(). As a special case, modal widgets like TQMessageBox
+ can be used before calling exec(), because modal widgets call
+ exec() to start a local event loop.
+
+ To make your application perform idle processing, i.e. executing a
+ special function whenever there are no pending events, use a
+ TQTimer with 0 timeout. More advanced idle processing schemes can
+ be achieved using processEvents().
+
+ \sa quit(), exit(), processEvents(), setMainWidget()
+*/
+int TQApplication::exec()
+{
+ return eventLoop()->exec();
+}
+
+/*!
+ Tells the application to exit with a return code.
+
+ After this function has been called, the application leaves the main
+ event loop and returns from the call to exec(). The exec() function
+ returns \a retcode.
+
+ By convention, a \a retcode of 0 means success, and any non-zero
+ value indicates an error.
+
+ Note that unlike the C library function of the same name, this
+ function \e does return to the caller -- it is event processing that
+ stops.
+
+ \sa quit(), exec()
+*/
+void TQApplication::exit( int retcode )
+{
+ tqApp->eventLoop()->exit( retcode );
+}
+
+/*!
+ \obsolete
+
+ This function enters the main event loop (recursively). Do not call
+ it unless you really know what you are doing.
+
+ Use TQApplication::eventLoop()->enterLoop() instead.
+
+*/
+int TQApplication::enter_loop()
+{
+ return eventLoop()->enterLoop();
+}
+
+/*!
+ \obsolete
+
+ This function exits from a recursive call to the main event loop.
+ Do not call it unless you are an expert.
+
+ Use TQApplication::eventLoop()->exitLoop() instead.
+
+*/
+void TQApplication::exit_loop()
+{
+ eventLoop()->exitLoop();
+}
+
+/*!
+ \obsolete
+
+ Returns the current loop level.
+
+ Use TQApplication::eventLoop()->loopLevel() instead.
+
+*/
+int TQApplication::loopLevel() const
+{
+ return eventLoop()->loopLevel();
+}
+
+/*!
+
+ Wakes up the GUI thread.
+
+ \sa guiThreadAwake() \link threads.html Thread Support in TQt\endlink
+*/
+void TQApplication::wakeUpGuiThread()
+{
+ eventLoop()->wakeUp();
+}
+
+/*!
+ This function returns TRUE if there are pending events; otherwise
+ returns FALSE. Pending events can be either from the window system
+ or posted events using TQApplication::postEvent().
+*/
+bool TQApplication::hasPendingEvents()
+{
+ return eventLoop()->hasPendingEvents();
+}
+
+#if !defined(TQ_WS_X11)
+
+// The doc and X implementation of these functions is in qapplication_x11.cpp
+
+void TQApplication::flushX() {} // do nothing
+
+void TQApplication::syncX() {} // do nothing
+
+#endif
+
+/*!
+ \fn void TQApplication::setWinStyleHighlightColor( const TQColor & )
+ \obsolete
+
+ Sets the color used to mark selections in windows style for all widgets
+ in the application. Will tqrepaint all widgets if the color is changed.
+
+ The default color is \c darkBlue.
+ \sa winStyleHighlightColor()
+*/
+
+/*!
+ \fn const TQColor& TQApplication::winStyleHighlightColor()
+ \obsolete
+
+ Returns the color used to mark selections in windows style.
+
+ \sa setWinStyleHighlightColor()
+*/
+
+/*!
+ Returns the version of the Windows operating system that is running:
+
+ \list
+ \i TQt::WV_95 - Windows 95
+ \i TQt::WV_98 - Windows 98
+ \i TQt::WV_Me - Windows Me
+ \i TQt::WV_NT - Windows NT 4.x
+ \i TQt::WV_2000 - Windows 2000 (NT5)
+ \i TQt::WV_XP - Windows XP
+ \i TQt::WV_2003 - Windows Server 2003 family
+ \i TQt::WV_CE - Windows CE
+ \i TQt::WV_CENET - Windows CE.NET
+ \endlist
+
+ Note that this function is implemented for the Windows version
+ of TQt only.
+*/
+
+#if defined(TQ_OS_CYGWIN)
+TQt::WindowsVersion TQApplication::winVersion()
+{
+ return qt_winver;
+}
+#endif
+
+#ifndef TQT_NO_TRANSLATION
+
+bool qt_detectRTLLanguage()
+{
+ return TQApplication::tr( "TQT_LAYOUT_DIRECTION",
+ "Translate this string to the string 'LTR' in left-to-right"
+ " languages or to 'RTL' in right-to-left languages (such as Hebrew"
+ " and Arabic) to get proper widget tqlayout." ) == "RTL";
+}
+
+/*!
+ Adds the message file \a mf to the list of message files to be used
+ for translations.
+
+ Multiple message files can be installed. Translations are searched
+ for in the last installed message file, then the one from last, and
+ so on, back to the first installed message file. The search stops as
+ soon as a matching translation is found.
+
+ \sa removeTranslator() translate() TQTranslator::load()
+*/
+
+void TQApplication::installTranslator( TQTranslator * mf )
+{
+ if ( !mf )
+ return;
+ if ( !translators )
+ translators = new TQValueList<TQTranslator*>;
+
+ translators->prepend( mf );
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ if ( mf->isEmpty() )
+ return;
+#endif
+
+ // hook to set the tqlayout direction of dialogs
+ setReverseLayout( qt_detectRTLLanguage() );
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ if (!w->isDesktop())
+ postEvent( w, new TQEvent( TQEvent::LanguageChange ) );
+ }
+ delete list;
+}
+
+/*!
+ Removes the message file \a mf from the list of message files used by
+ this application. (It does not delete the message file from the file
+ system.)
+
+ \sa installTranslator() translate(), TQObject::tr()
+*/
+
+void TQApplication::removeTranslator( TQTranslator * mf )
+{
+ if ( !translators || !mf )
+ return;
+
+ if ( translators->remove( mf ) && ! tqApp->closingDown() ) {
+ setReverseLayout( qt_detectRTLLanguage() );
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ postEvent( w, new TQEvent( TQEvent::LanguageChange ) );
+ }
+ delete list;
+ }
+}
+
+#ifndef TQT_NO_TEXTCODEC
+/*! \obsolete
+ This is the same as TQTextCodec::setCodecForTr().
+*/
+void TQApplication::setDefaultCodec( TQTextCodec* codec )
+{
+ TQTextCodec::setCodecForTr( codec );
+}
+
+/*! \obsolete
+ Returns TQTextCodec::codecForTr().
+*/
+TQTextCodec* TQApplication::defaultCodec() const
+{
+ return TQTextCodec::codecForTr();
+}
+#endif //TQT_NO_TEXTCODEC
+
+/*! \enum TQApplication::Encoding
+
+ This enum type defines the 8-bit encoding of character string
+ arguments to translate():
+
+ \value DefaultCodec - the encoding specified by
+ TQTextCodec::codecForTr() (Latin-1 if none has been set)
+ \value UnicodeUTF8 - UTF-8
+
+ \sa TQObject::tr(), TQObject::trUtf8(), TQString::fromUtf8()
+*/
+
+/*! \reentrant
+ Returns the translation text for \a sourceText, by querying the
+ installed messages files. The message files are searched from the most
+ recently installed message file back to the first installed message
+ file.
+
+ TQObject::tr() and TQObject::trUtf8() provide this functionality more
+ conveniently.
+
+ \a context is typically a class name (e.g., "MyDialog") and
+ \a sourceText is either English text or a short identifying text, if
+ the output text will be very long (as for help texts).
+
+ \a comment is a disambiguating comment, for when the same \a
+ sourceText is used in different roles within the same context. By
+ default, it is null. \a encoding indicates the 8-bit encoding of
+ character stings
+
+ See the \l TQTranslator documentation for more information about
+ contexts and comments.
+
+ If none of the message files contain a translation for \a
+ sourceText in \a context, this function returns a TQString
+ equivalent of \a sourceText. The encoding of \a sourceText is
+ specified by \e encoding; it defaults to \c DefaultCodec.
+
+ This function is not virtual. You can use alternative translation
+ techniques by subclassing \l TQTranslator.
+
+ \warning This method is reentrant only if all translators are
+ installed \e before calling this method. Installing or removing
+ translators while performing translations is not supported. Doing
+ so will most likely result in crashes or other undesirable behavior.
+
+ \sa TQObject::tr() installTranslator() defaultCodec()
+*/
+
+TQString TQApplication::translate( const char * context, const char * sourceText,
+ const char * comment, Encoding encoding ) const
+{
+ if ( !sourceText )
+ return TQString::null;
+
+ if ( translators ) {
+ TQValueList<TQTranslator*>::iterator it;
+ TQTranslator * mf;
+ TQString result;
+ for ( it = translators->begin(); it != translators->end(); ++it ) {
+ mf = *it;
+ result = mf->tqfindMessage( context, sourceText, comment ).translation();
+ if ( !result.isNull() )
+ return result;
+ }
+ }
+#ifndef TQT_NO_TEXTCODEC
+ if ( encoding == UnicodeUTF8 )
+ return TQString::fromUtf8( sourceText );
+ else if ( TQTextCodec::codecForTr() != 0 )
+ return TQTextCodec::codecForTr()->toUnicode( sourceText );
+ else
+#endif
+ return TQString::tqfromLatin1( sourceText );
+}
+
+#endif
+
+/*****************************************************************************
+ TQApplication management of posted events
+ *****************************************************************************/
+
+//see also notify(), which does the removal of ChildInserted when ChildRemoved.
+
+/*!
+ Adds the event \a event with the object \a receiver as the receiver of the
+ event, to an event queue and returns immediately.
+
+ The event must be allocated on the heap since the post event queue
+ will take ownership of the event and delete it once it has been posted.
+
+ When control returns to the main event loop, all events that are
+ stored in the queue will be sent using the notify() function.
+
+ \threadsafe
+
+ \sa sendEvent(), notify()
+*/
+
+void TQApplication::postEvent( TQObject *receiver, TQEvent *event )
+{
+ if ( receiver == 0 ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQApplication::postEvent: Unexpected null receiver" );
+#endif
+ delete event;
+ return;
+ }
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ if ( !globalPostedEvents ) { // create list
+ globalPostedEvents = new TQPostEventList;
+ TQ_CHECK_PTR( globalPostedEvents );
+ globalPostedEvents->setAutoDelete( TRUE );
+ qapp_cleanup_events.set( &globalPostedEvents );
+ }
+
+ if ( !receiver->postedEvents )
+ receiver->postedEvents = new TQPostEventList;
+ TQPostEventList * l = receiver->postedEvents;
+
+ // if this is one of the compressible events, do compression
+ if ( event->type() == TQEvent::Paint ||
+ event->type() == TQEvent::LayoutHint ||
+ event->type() == TQEvent::Resize ||
+ event->type() == TQEvent::Move ||
+ event->type() == TQEvent::LanguageChange ) {
+ l->first();
+ TQPostEvent * cur = 0;
+ for ( ;; ) {
+ while ( (cur=l->current()) != 0 &&
+ ( cur->receiver != receiver ||
+ cur->event == 0 ||
+ cur->event->type() != event->type() ) )
+ l->next();
+ if ( l->current() != 0 ) {
+ if ( cur->event->type() == TQEvent::Paint ) {
+ TQPaintEvent * p = (TQPaintEvent*)(cur->event);
+ if ( p->erase != ((TQPaintEvent*)event)->erase ) {
+ l->next();
+ continue;
+ }
+ p->reg = p->reg.unite( ((TQPaintEvent *)event)->reg );
+ p->rec = p->rec.unite( ((TQPaintEvent *)event)->rec );
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::LayoutHint ) {
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::Resize ) {
+ ((TQResizeEvent *)(cur->event))->s = ((TQResizeEvent *)event)->s;
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::Move ) {
+ ((TQMoveEvent *)(cur->event))->p = ((TQMoveEvent *)event)->p;
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::LanguageChange ) {
+ delete event;
+ return;
+ }
+ }
+ break;
+ };
+ }
+
+ // if no compression could be done, just append something
+ event->posted = TRUE;
+ TQPostEvent * pe = new TQPostEvent( receiver, event );
+ l->append( pe );
+ globalPostedEvents->append( pe );
+
+ if (eventloop)
+ eventloop->wakeUp();
+}
+
+
+/*! \overload
+
+ Dispatches all posted events, i.e. empties the event queue.
+*/
+void TQApplication::sendPostedEvents()
+{
+ sendPostedEvents( 0, 0 );
+}
+
+
+
+/*!
+ Immediately dispatches all events which have been previously queued
+ with TQApplication::postEvent() and which are for the object \a receiver
+ and have the event type \a event_type.
+
+ Note that events from the window system are \e not dispatched by this
+ function, but by processEvents().
+
+ If \a receiver is null, the events of \a event_type are sent for all
+ objects. If \a event_type is 0, all the events are sent for \a receiver.
+*/
+
+void TQApplication::sendPostedEvents( TQObject *receiver, int event_type )
+{
+ // Make sure the object hierarchy is stable before processing events
+ // to avoid endless loops
+ if ( receiver == 0 && event_type == 0 )
+ sendPostedEvents( 0, TQEvent::ChildInserted );
+
+ if ( !globalPostedEvents || ( receiver && !receiver->postedEvents ) )
+ return;
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif
+
+ bool sent = TRUE;
+ while ( sent ) {
+ sent = FALSE;
+
+ if ( !globalPostedEvents || ( receiver && !receiver->postedEvents ) )
+ return;
+
+ // if we have a receiver, use the local list. Otherwise, use the
+ // global list
+ TQPostEventList * l = receiver ? receiver->postedEvents : globalPostedEvents;
+
+ // okay. here is the tricky loop. be careful about optimizing
+ // this, it looks the way it does for good reasons.
+ TQPostEventListIt it( *l );
+ TQPostEvent *pe;
+ while ( (pe=it.current()) != 0 ) {
+ ++it;
+ if ( pe->event // hasn't been sent yet
+ && ( receiver == 0 // we send to all tqreceivers
+ || receiver == pe->receiver ) // we send to THAT receiver
+ && ( event_type == 0 // we send all types
+ || event_type == pe->event->type() ) ) { // we send THAT type
+ // first, we diddle the event so that we can deliver
+ // it, and that noone will try to touch it later.
+ pe->event->posted = FALSE;
+ TQEvent * e = pe->event;
+ TQObject * r = pe->receiver;
+ pe->event = 0;
+
+ // next, update the data structure so that we're ready
+ // for the next event.
+
+ // look for the local list, and take whatever we're
+ // delivering out of it. r->postedEvents maybe *l
+ if ( r->postedEvents ) {
+ r->postedEvents->removeRef( pe );
+ // if possible, get rid of that list. this is not
+ // ideal - we will create and delete a list for
+ // each update() call. it would be better if we'd
+ // leave the list empty here, and delete it
+ // somewhere else if it isn't being used.
+ if ( r->postedEvents->isEmpty() ) {
+ delete r->postedEvents;
+ r->postedEvents = 0;
+ }
+ }
+
+#ifdef TQT_THREAD_SUPPORT
+ if ( locker.mutex() ) locker.mutex()->unlock();
+#endif // TQT_THREAD_SUPPORT
+ // after all that work, it's time to deliver the event.
+ if ( e->type() == TQEvent::Paint && r->isWidgetType() ) {
+ TQWidget * w = (TQWidget*)r;
+ TQPaintEvent * p = (TQPaintEvent*)e;
+ if ( w->isVisible() )
+ w->tqrepaint( p->reg, p->erase );
+ } else {
+ sent = TRUE;
+ TQApplication::sendEvent( r, e );
+ }
+#ifdef TQT_THREAD_SUPPORT
+ if ( locker.mutex() ) locker.mutex()->lock();
+#endif // TQT_THREAD_SUPPORT
+
+ delete e;
+ // careful when adding anything below this point - the
+ // sendEvent() call might tqinvalidate any invariants this
+ // function depends on.
+ }
+ }
+
+ // clear the global list, i.e. remove everything that was
+ // delivered.
+ if ( l == globalPostedEvents ) {
+ globalPostedEvents->first();
+ while( (pe=globalPostedEvents->current()) != 0 ) {
+ if ( pe->event )
+ globalPostedEvents->next();
+ else
+ globalPostedEvents->remove();
+ }
+ }
+ }
+}
+
+/*!
+ Removes all events posted using postEvent() for \a receiver.
+
+ The events are \e not dispatched, instead they are removed from the
+ queue. You should never need to call this function. If you do call it,
+ be aware that killing events may cause \a receiver to break one or
+ more invariants.
+
+ \threadsafe
+*/
+
+void TQApplication::removePostedEvents( TQObject *receiver )
+{
+ if ( !receiver )
+ return;
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ // the TQObject destructor calls this function directly. this can
+ // happen while the event loop is in the middle of posting events,
+ // and when we get here, we may not have any more posted events
+ // for this object.
+ if ( !receiver->postedEvents )
+ return;
+
+ // iterate over the object-specifc list and delete the events.
+ // leave the TQPostEvent objects; they'll be deleted by
+ // sendPostedEvents().
+ TQPostEventList * l = receiver->postedEvents;
+ receiver->postedEvents = 0;
+ l->first();
+ TQPostEvent * pe;
+ while( (pe=l->current()) != 0 ) {
+ if ( pe->event ) {
+ pe->event->posted = FALSE;
+ delete pe->event;
+ pe->event = 0;
+ }
+ l->remove();
+ }
+ delete l;
+}
+
+
+/*!
+ Removes \a event from the queue of posted events, and emits a
+ warning message if appropriate.
+
+ \warning This function can be \e really slow. Avoid using it, if
+ possible.
+
+ \threadsafe
+*/
+
+void TQApplication::removePostedEvent( TQEvent * event )
+{
+ if ( !event || !event->posted )
+ return;
+
+ if ( !globalPostedEvents ) {
+#if defined(TQT_DEBUG)
+ qDebug( "TQApplication::removePostedEvent: %p %d is posted: impossible",
+ (void*)event, event->type() );
+ return;
+#endif
+ }
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ TQPostEventListIt it( *globalPostedEvents );
+ TQPostEvent * pe;
+ while( (pe = it.current()) != 0 ) {
+ ++it;
+ if ( pe->event == event ) {
+#if defined(TQT_DEBUG)
+ const char *n;
+ switch ( event->type() ) {
+ case TQEvent::Timer:
+ n = "Timer";
+ break;
+ case TQEvent::MouseButtonPress:
+ n = "MouseButtonPress";
+ break;
+ case TQEvent::MouseButtonRelease:
+ n = "MouseButtonRelease";
+ break;
+ case TQEvent::MouseButtonDblClick:
+ n = "MouseButtonDblClick";
+ break;
+ case TQEvent::MouseMove:
+ n = "MouseMove";
+ break;
+#ifndef TQT_NO_WHEELEVENT
+ case TQEvent::Wheel:
+ n = "Wheel";
+ break;
+#endif
+ case TQEvent::KeyPress:
+ n = "KeyPress";
+ break;
+ case TQEvent::KeyRelease:
+ n = "KeyRelease";
+ break;
+ case TQEvent::FocusIn:
+ n = "FocusIn";
+ break;
+ case TQEvent::FocusOut:
+ n = "FocusOut";
+ break;
+ case TQEvent::Enter:
+ n = "Enter";
+ break;
+ case TQEvent::Leave:
+ n = "Leave";
+ break;
+ case TQEvent::Paint:
+ n = "Paint";
+ break;
+ case TQEvent::Move:
+ n = "Move";
+ break;
+ case TQEvent::Resize:
+ n = "Resize";
+ break;
+ case TQEvent::Create:
+ n = "Create";
+ break;
+ case TQEvent::Destroy:
+ n = "Destroy";
+ break;
+ case TQEvent::Close:
+ n = "Close";
+ break;
+ case TQEvent::Quit:
+ n = "Quit";
+ break;
+ default:
+ n = "<other>";
+ break;
+ }
+ qWarning("TQEvent: Warning: %s event deleted while posted to %s %s",
+ n,
+ pe->receiver ? pe->receiver->className() : "null",
+ pe->receiver ? pe->receiver->name() : "object" );
+ // note the beautiful uglehack if !pe->receiver :)
+#endif
+ event->posted = FALSE;
+ delete pe->event;
+ pe->event = 0;
+ return;
+ }
+ }
+}
+
+/*!\internal
+
+ Sets the active window in reaction to a system event. Call this
+ from the platform specific event handlers.
+
+ It sets the activeWindow() and tqfocusWidget() attributes and sends
+ proper WindowActivate/WindowDeactivate and FocusIn/FocusOut events
+ to all appropriate widgets.
+
+ \sa activeWindow()
+ */
+void TQApplication::setActiveWindow( TQWidget* act )
+{
+ TQWidget* window = act?act->tqtopLevelWidget():0;
+
+ if ( active_window == window )
+ return;
+
+ // first the activation/deactivation events
+ if ( active_window ) {
+ TQWidgetList deacts;
+#ifndef TQT_NO_STYLE
+ if ( style().tqstyleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) {
+ TQWidgetList *list = tqtopLevelWidgets();
+ if ( list ) {
+ for ( TQWidget *w = list->first(); w; w = list->next() ) {
+ if ( w->isVisible() && w->isActiveWindow() )
+ deacts.append(w);
+ }
+ delete list;
+ }
+ } else
+#endif
+ deacts.append(active_window);
+ active_window = 0;
+ TQEvent e( TQEvent::WindowDeactivate );
+ for(TQWidget *w = deacts.first(); w; w = deacts.next())
+ TQApplication::sendSpontaneousEvent( w, &e );
+ }
+
+ active_window = window;
+ if ( active_window ) {
+ TQEvent e( TQEvent::WindowActivate );
+ TQWidgetList acts;
+#ifndef TQT_NO_STYLE
+ if ( style().tqstyleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) {
+ TQWidgetList *list = tqtopLevelWidgets();
+ if ( list ) {
+ for ( TQWidget *w = list->first(); w; w = list->next() ) {
+ if ( w->isVisible() && w->isActiveWindow() )
+ acts.append(w);
+ }
+ delete list;
+ }
+ } else
+#endif
+ acts.append(active_window);
+ for(TQWidget *w = acts.first(); w; w = acts.next())
+ TQApplication::sendSpontaneousEvent( w, &e );
+ }
+
+ // then focus events
+ TQFocusEvent::setReason( TQFocusEvent::ActiveWindow );
+ if ( !active_window && focus_widget ) {
+ TQFocusEvent out( TQEvent::FocusOut );
+ TQWidget *tmp = focus_widget;
+ focus_widget = 0;
+#ifdef TQ_WS_WIN
+ TQInputContext::accept( tmp );
+#endif
+ TQApplication::sendSpontaneousEvent( tmp, &out );
+ } else if ( active_window ) {
+ TQWidget *w = active_window->tqfocusWidget();
+ if ( w && w->focusPolicy() != TQWidget::NoFocus )
+ w->setFocus();
+ else
+ active_window->focusNextPrevChild( TRUE );
+ }
+ TQFocusEvent::resetReason();
+}
+
+
+/*!\internal
+
+ Creates the proper Enter/Leave event when widget \a enter is entered
+ and widget \a leave is left.
+ */
+TQ_EXPORT void qt_dispatchEnterLeave( TQWidget* enter, TQWidget* leave ) {
+#if 0
+ if ( leave ) {
+ TQEvent e( TQEvent::Leave );
+ TQApplication::sendEvent( leave, & e );
+ }
+ if ( enter ) {
+ TQEvent e( TQEvent::Enter );
+ TQApplication::sendEvent( enter, & e );
+ }
+ return;
+#endif
+
+ TQWidget* w ;
+ if ( !enter && !leave )
+ return;
+ TQWidgetList leaveList;
+ TQWidgetList enterList;
+
+ bool sameWindow = leave && enter && leave->tqtopLevelWidget() == enter->tqtopLevelWidget();
+ if ( leave && !sameWindow ) {
+ w = leave;
+ do {
+ leaveList.append( w );
+ } while ( (w = w->parentWidget( TRUE ) ) );
+ }
+ if ( enter && !sameWindow ) {
+ w = enter;
+ do {
+ enterList.prepend( w );
+ } while ( (w = w->parentWidget(TRUE) ) );
+ }
+ if ( sameWindow ) {
+ int enterDepth = 0;
+ int leaveDepth = 0;
+ w = enter;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ enterDepth++;
+ w = leave;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ leaveDepth++;
+ TQWidget* wenter = enter;
+ TQWidget* wleave = leave;
+ while ( enterDepth > leaveDepth ) {
+ wenter = wenter->parentWidget();
+ enterDepth--;
+ }
+ while ( leaveDepth > enterDepth ) {
+ wleave = wleave->parentWidget();
+ leaveDepth--;
+ }
+ while ( !wenter->isTopLevel() && wenter != wleave ) {
+ wenter = wenter->parentWidget();
+ wleave = wleave->parentWidget();
+ }
+
+ w = leave;
+ while ( w != wleave ) {
+ leaveList.append( w );
+ w = w->parentWidget();
+ }
+ w = enter;
+ while ( w != wenter ) {
+ enterList.prepend( w );
+ w = w->parentWidget();
+ }
+ }
+
+ TQEvent leaveEvent( TQEvent::Leave );
+ for ( w = leaveList.first(); w; w = leaveList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &leaveEvent );
+ }
+ TQEvent enterEvent( TQEvent::Enter );
+ for ( w = enterList.first(); w; w = enterList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &enterEvent );
+ }
+}
+
+
+#ifdef TQ_WS_MACX
+extern TQWidget *qt_tryModalHelperMac( TQWidget * top ); //qapplication_mac.cpp
+#endif
+
+
+/*!\internal
+
+ Called from qapplication_<platform>.cpp, returns TRUE
+ if the widget should accept the event.
+ */
+TQ_EXPORT bool qt_tryModalHelper( TQWidget *widget, TQWidget **rettop ) {
+ TQWidget *modal=0, *top=TQApplication::activeModalWidget();
+ if ( rettop ) *rettop = top;
+
+ if ( tqApp->activePopupWidget() )
+ return TRUE;
+
+#ifdef TQ_WS_MACX
+ top = qt_tryModalHelperMac( top );
+ if ( rettop ) *rettop = top;
+#endif
+
+ TQWidget* groupLeader = widget;
+ widget = widget->tqtopLevelWidget();
+
+ if ( widget->testWFlags(TQt::WShowModal) ) // widget is modal
+ modal = widget;
+ if ( !top || modal == top ) // don't block event
+ return TRUE;
+
+ TQWidget * p = widget->parentWidget(); // Check if the active modal widget is a tqparent of our widget
+ while ( p ) {
+ if ( p == top )
+ return TRUE;
+ p = p->parentWidget();
+ }
+
+ while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) )
+ groupLeader = groupLeader->parentWidget();
+
+ if ( groupLeader ) {
+ // Does groupLeader have a child in qt_modal_stack?
+ bool unrelated = TRUE;
+ modal = qt_modal_stack->first();
+ while (modal && unrelated) {
+ TQWidget* p = modal->parentWidget();
+ while ( p && p != groupLeader && !p->testWFlags( TQt::WGroupLeader) ) {
+ p = p->parentWidget();
+ }
+ modal = qt_modal_stack->next();
+ if ( p == groupLeader ) unrelated = FALSE;
+ }
+
+ if ( unrelated )
+ return TRUE; // don't block event
+ }
+ return FALSE;
+}
+
+
+/*!
+ Returns the desktop widget (also called the root window).
+
+ The desktop widget is useful for obtaining the size of the screen.
+ It may also be possible to draw on the desktop. We recommend against
+ assuming that it's possible to draw on the desktop, since this does
+ not work on all operating systems.
+
+ \code
+ TQDesktopWidget *d = TQApplication::desktop();
+ int w = d->width(); // returns desktop width
+ int h = d->height(); // returns desktop height
+ \endcode
+*/
+
+TQDesktopWidget *TQApplication::desktop()
+{
+ if ( !qt_desktopWidget || // not created yet
+ !qt_desktopWidget->isDesktop() ) { // reparented away
+ qt_desktopWidget = new TQDesktopWidget();
+ TQ_CHECK_PTR( qt_desktopWidget );
+ }
+ return qt_desktopWidget;
+}
+
+#ifndef TQT_NO_CLIPBOARD
+/*!
+ Returns a pointer to the application global clipboard.
+*/
+TQClipboard *TQApplication::clipboard()
+{
+ if ( qt_clipboard == 0 ) {
+ qt_clipboard = new TQClipboard;
+ TQ_CHECK_PTR( qt_clipboard );
+ }
+ return qt_clipboard;
+}
+#endif // TQT_NO_CLIPBOARD
+
+/*!
+ By default, TQt will try to use the current standard colors, fonts
+ etc., from the underlying window system's desktop settings,
+ and use them for all relevant widgets. This behavior can be switched off
+ by calling this function with \a on set to FALSE.
+
+ This static function must be called before creating the TQApplication
+ object, like this:
+
+ \code
+ int main( int argc, char** argv ) {
+ TQApplication::setDesktopSettingsAware( FALSE ); // I know better than the user
+ TQApplication myApp( argc, argv ); // Use default fonts & colors
+ ...
+ }
+ \endcode
+
+ \sa desktopSettingsAware()
+*/
+
+void TQApplication::setDesktopSettingsAware( bool on )
+{
+ obey_desktop_settings = on;
+}
+
+/*!
+ Returns the value set by setDesktopSettingsAware(); by default TRUE.
+
+ \sa setDesktopSettingsAware()
+*/
+
+bool TQApplication::desktopSettingsAware()
+{
+ return obey_desktop_settings;
+}
+
+/*! \fn void TQApplication::lock()
+
+ Lock the TQt Library Mutex. If another thread has already locked the
+ mutex, the calling thread will block until the other thread has
+ unlocked the mutex.
+
+ \sa unlock() locked() \link threads.html Thread Support in TQt\endlink
+*/
+
+
+/*! \fn void TQApplication::unlock(bool wakeUpGui)
+
+ Unlock the TQt Library Mutex. If \a wakeUpGui is TRUE (the default),
+ then the GUI thread will be woken with TQApplication::wakeUpGuiThread().
+
+ \sa lock(), locked() \link threads.html Thread Support in TQt\endlink
+*/
+
+
+/*! \fn bool TQApplication::locked()
+
+ Returns TRUE if the TQt Library Mutex is locked by a different thread;
+ otherwise returns FALSE.
+
+ \warning Due to different implementations of recursive mutexes on
+ the supported platforms, calling this function from the same thread
+ that previously locked the mutex will give undefined results.
+
+ \sa lock() unlock() \link threads.html Thread Support in TQt\endlink
+*/
+
+/*! \fn bool TQApplication::tryLock()
+
+ Attempts to lock the TQt Library Mutex, and returns immediately. If
+ the lock was obtained, this function returns TRUE. If another thread
+ has locked the mutex, this function returns FALSE, instead of
+ waiting for the lock to become available.
+
+ The mutex must be unlocked with unlock() before another thread can
+ successfully lock it.
+
+ \sa lock(), unlock() \link threads.html Thread Support in TQt\endlink
+*/
+
+#if defined(TQT_THREAD_SUPPORT)
+void TQApplication::lock()
+{
+ qt_mutex->lock();
+}
+
+void TQApplication::unlock(bool wakeUpGui)
+{
+ qt_mutex->unlock();
+
+ if (wakeUpGui)
+ wakeUpGuiThread();
+}
+
+bool TQApplication::locked()
+{
+ return qt_mutex->locked();
+}
+
+bool TQApplication::tryLock()
+{
+ return qt_mutex->tryLock();
+}
+#endif
+
+
+/*!
+ \fn bool TQApplication::isSessionRestored() const
+
+ Returns TRUE if the application has been restored from an earlier
+ \link session.html session\endlink; otherwise returns FALSE.
+
+ \sa sessionId(), commitData(), saveState()
+*/
+
+
+/*!
+ \fn TQString TQApplication::sessionId() const
+
+ Returns the current \link session.html session's\endlink identifier.
+
+ If the application has been restored from an earlier session, this
+ identifier is the same as it was in that previous session.
+
+ The session identifier is guaranteed to be unique both for different
+ applications and for different instances of the same application.
+
+ \sa isSessionRestored(), sessionKey(), commitData(), saveState()
+ */
+
+/*!
+ \fn TQString TQApplication::sessionKey() const
+
+ Returns the session key in the current \link session.html
+ session\endlink.
+
+ If the application has been restored from an earlier session, this
+ key is the same as it was when the previous session ended.
+
+ The session key changes with every call of commitData() or
+ saveState().
+
+ \sa isSessionRestored(), sessionId(), commitData(), saveState()
+ */
+
+
+/*!
+ \fn void TQApplication::commitData( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the TQSessionManager wants the
+ application to commit all its data.
+
+ Usually this means saving all open files, after getting
+ permission from the user. Furthermore you may want to provide a means
+ by which the user can cancel the shutdown.
+
+ Note that you should not exit the application within this function.
+ Instead, the session manager may or may not do this afterwards,
+ depending on the context.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details and example
+ usage.
+
+ The default implementation requests interaction and sends a close
+ event to all visible top level widgets. If any event was
+ rejected, the shutdown is canceled.
+
+ \sa isSessionRestored(), sessionId(), saveState(), \link session.html the Session Management overview\endlink
+*/
+#ifndef TQT_NO_SESSIONMANAGER
+void TQApplication::commitData( TQSessionManager& sm )
+{
+
+ if ( sm.allowsInteraction() ) {
+ TQWidgetList done;
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ bool cancelled = FALSE;
+ TQWidget* w = list->first();
+ while ( !cancelled && w ) {
+ if ( !w->isHidden() ) {
+ TQCloseEvent e;
+ sendEvent( w, &e );
+ cancelled = !e.isAccepted();
+ if ( !cancelled )
+ done.append( w );
+ delete list; // one never knows...
+ list = TQApplication::tqtopLevelWidgets();
+ w = list->first();
+ } else {
+ w = list->next();
+ }
+ while ( w && done.tqcontainsRef( w ) )
+ w = list->next();
+ }
+ delete list;
+ if ( cancelled )
+ sm.cancel();
+ }
+}
+
+
+/*!
+ \fn void TQApplication::saveState( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the
+ \link TQSessionManager session manager \endlink wants the application
+ to preserve its state for a future session.
+
+ For example, a text editor would create a temporary file that
+ includes the current contents of its edit buffers, the location of
+ the cursor and other aspects of the current editing session.
+
+ Note that you should never exit the application within this
+ function. Instead, the session manager may or may not do this
+ afterwards, depending on the context. Futhermore, most session
+ managers will very likely request a saved state immediately after
+ the application has been started. This permits the session manager
+ to learn about the application's restart policy.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details.
+
+ \sa isSessionRestored(), sessionId(), commitData(), \link session.html the Session Management overview\endlink
+*/
+
+void TQApplication::saveState( TQSessionManager& /* sm */ )
+{
+}
+#endif //TQT_NO_SESSIONMANAGER
+/*!
+ Sets the time after which a drag should start to \a ms ms.
+
+ \sa startDragTime()
+*/
+
+void TQApplication::setStartDragTime( int ms )
+{
+ drag_time = ms;
+}
+
+/*!
+ If you support drag and drop in you application and a drag should
+ start after a mouse click and after a certain time elapsed, you
+ should use the value which this method returns as the delay (in ms).
+
+ TQt also uses this delay internally, e.g. in TQTextEdit and TQLineEdit,
+ for starting a drag.
+
+ The default value is 500 ms.
+
+ \sa setStartDragTime(), startDragDistance()
+*/
+
+int TQApplication::startDragTime()
+{
+ return drag_time;
+}
+
+/*!
+ Sets the distance after which a drag should start to \a l pixels.
+
+ \sa startDragDistance()
+*/
+
+void TQApplication::setStartDragDistance( int l )
+{
+ drag_distance = l;
+}
+
+/*!
+ If you support drag and drop in you application and a drag should
+ start after a mouse click and after moving the mouse a certain
+ distance, you should use the value which this method returns as the
+ distance.
+
+ For example, if the mouse position of the click is stored in \c
+ startPos and the current position (e.g. in the mouse move event) is
+ \c currPos, you can tqfind out if a drag should be started with code
+ like this:
+ \code
+ if ( ( startPos - currPos ).manhattanLength() >
+ TQApplication::startDragDistance() )
+ startTheDrag();
+ \endcode
+
+ TQt uses this value internally, e.g. in TQFileDialog.
+
+ The default value is 4 pixels.
+
+ \sa setStartDragDistance(), startDragTime(), TQPoint::manhattanLength()
+*/
+
+int TQApplication::startDragDistance()
+{
+ return drag_distance;
+}
+
+/*!
+ If \a b is TRUE, all dialogs and widgets will be laid out in a
+ mirrored fashion, as required by right to left languages such as
+ Arabic and Hebrew. If \a b is FALSE, dialogs and widgets are laid
+ out left to right.
+
+ Changing this flag in runtime does not cause a retqlayout of already
+ instantiated widgets.
+
+ \sa reverseLayout()
+*/
+void TQApplication::setReverseLayout( bool b )
+{
+ if ( reverse_tqlayout == b )
+ return;
+
+ reverse_tqlayout = b;
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ postEvent( w, new TQEvent( TQEvent::LayoutDirectionChange ) );
+ }
+ delete list;
+}
+
+/*!
+ Returns TRUE if all dialogs and widgets will be laid out in a
+ mirrored (right to left) fashion. Returns FALSE if dialogs and
+ widgets will be laid out left to right.
+
+ \sa setReverseLayout()
+*/
+bool TQApplication::reverseLayout()
+{
+ return reverse_tqlayout;
+}
+
+
+/*!
+ \class TQSessionManager tqsessionmanager.h
+ \brief The TQSessionManager class provides access to the session manager.
+
+ \ingroup application
+ \ingroup environment
+
+ The session manager is responsible for session management, most
+ importantly for interruption and resumption. A "session" is a kind
+ of record of the state of the system, e.g. which applications were
+ run at start up and which applications are currently running. The
+ session manager is used to save the session, e.g. when the machine
+ is shut down; and to restore a session, e.g. when the machine is
+ started up. Use TQSettings to save and restore an individual
+ application's settings, e.g. window positions, recently used files,
+ etc.
+
+ TQSessionManager provides an interface between the application and
+ the session manager so that the program can work well with the
+ session manager. In TQt, session management requests for action
+ are handled by the two virtual functions TQApplication::commitData()
+ and TQApplication::saveState(). Both provide a reference to
+ a session manager object as argument, to allow the application
+ to communicate with the session manager.
+
+ During a session management action (i.e. within commitData() and
+ saveState()), no user interaction is possible \e unless the
+ application got explicit permission from the session manager. You
+ ask for permission by calling allowsInteraction() or, if it's really
+ urgent, allowsErrorInteraction(). TQt does not enforce this, but the
+ session manager may.
+
+ You can try to abort the shutdown process by calling cancel(). The
+ default commitData() function does this if some top-level window
+ rejected its closeEvent().
+
+ For sophisticated session managers provided on Unix/X11, TQSessionManager
+ offers further possibilites to fine-tune an application's session
+ management behavior: setRestartCommand(), setDiscardCommand(),
+ setRestartHint(), setProperty(), requestPhase2(). See the respective
+ function descriptions for further details.
+*/
+
+/*! \enum TQSessionManager::RestartHint
+
+ This enum type defines the circumstances under which this
+ application wants to be restarted by the session manager. The
+ current values are
+
+ \value RestartIfRunning if the application is still running when
+ the session is shut down, it wants to be restarted at the start of
+ the next session.
+
+ \value RestartAnyway the application wants to be started at the
+ start of the next session, no matter what. (This is useful for
+ utilities that run just after startup and then quit.)
+
+ \value RestartImmediately the application wants to be started
+ immediately whenever it is not running.
+
+ \value RestartNever the application does not want to be restarted
+ automatically.
+
+ The default hint is \c RestartIfRunning.
+*/
+
+
+/*!
+ \fn TQString TQSessionManager::sessionId() const
+
+ Returns the identifier of the current session.
+
+ If the application has been restored from an earlier session, this
+ identifier is the same as it was in that earlier session.
+
+ \sa sessionKey(), TQApplication::sessionId()
+ */
+
+/*!
+ \fn TQString TQSessionManager::sessionKey() const
+
+ Returns the session key in the current session.
+
+ If the application has been restored from an earlier session, this
+ key is the same as it was when the previous session ended.
+
+ The session key changes with every call of commitData() or
+ saveState().
+
+ \sa sessionId(), TQApplication::sessionKey()
+ */
+
+// ### Note: This function is undocumented, since it is #ifdef'd.
+
+/*!
+ \fn void* TQSessionManager::handle() const
+
+ X11 only: returns a handle to the current \c SmcConnection.
+*/
+
+
+/*!
+ \fn bool TQSessionManager::allowsInteraction()
+
+ Asks the session manager for permission to interact with the
+ user. Returns TRUE if interaction is permitted; otherwise
+ returns FALSE.
+
+ The rationale behind this mechanism is to make it possible to
+ synchronize user interaction during a shutdown. Advanced session
+ managers may ask all applications simultaneously to commit their
+ data, resulting in a much faster shutdown.
+
+ When the interaction is completed we strongly recommend releasing the
+ user interaction semaphore with a call to release(). This way, other
+ applications may get the chance to interact with the user while your
+ application is still busy saving data. (The semaphore is implicitly
+ released when the application exits.)
+
+ If the user decides to cancel the shutdown process during the
+ interaction phase, you must tell the session manager that this has
+ happened by calling cancel().
+
+ Here's an example of how an application's TQApplication::commitData()
+ might be implemented:
+
+\code
+void MyApplication::commitData( TQSessionManager& sm ) {
+ if ( sm.allowsInteraction() ) {
+ switch ( TQMessageBox::warning(
+ yourMainWindow,
+ tr("Application Name"),
+ tr("Save changes to document Foo?"),
+ tr("&Yes"),
+ tr("&No"),
+ tr("Cancel"),
+ 0, 2) ) {
+ case 0: // yes
+ sm.release();
+ // save document here; if saving fails, call sm.cancel()
+ break;
+ case 1: // continue without saving
+ break;
+ default: // cancel
+ sm.cancel();
+ break;
+ }
+ } else {
+ // we did not get permission to interact, then
+ // do something reasonable instead.
+ }
+}
+\endcode
+
+ If an error occurred within the application while saving its data,
+ you may want to try allowsErrorInteraction() instead.
+
+ \sa TQApplication::commitData(), release(), cancel()
+*/
+
+
+/*!
+ \fn bool TQSessionManager::allowsErrorInteraction()
+
+ This is similar to allowsInteraction(), but also tells the session
+ manager that an error occurred. Session managers may give error
+ interaction request higher priority, which means that it is more likely
+ that an error interaction is permitted. However, you are still not
+ guaranteed that the session manager will allow interaction.
+
+ \sa allowsInteraction(), release(), cancel()
+*/
+
+/*!
+ \fn void TQSessionManager::release()
+
+ Releases the session manager's interaction semaphore after an
+ interaction phase.
+
+ \sa allowsInteraction(), allowsErrorInteraction()
+*/
+
+/*!
+ \fn void TQSessionManager::cancel()
+
+ Tells the session manager to cancel the shutdown process. Applications
+ should not call this function without first asking the user.
+
+ \sa allowsInteraction(), allowsErrorInteraction()
+
+*/
+
+/*!
+ \fn void TQSessionManager::setRestartHint( RestartHint hint )
+
+ Sets the application's restart hint to \a hint. On application
+ startup the hint is set to \c RestartIfRunning.
+
+ Note that these flags are only hints, a session manager may or may
+ not respect them.
+
+ We recommend setting the restart hint in TQApplication::saveState()
+ because most session managers perform a checkpoint shortly after an
+ application's startup.
+
+ \sa restartHint()
+*/
+
+/*!
+ \fn TQSessionManager::RestartHint TQSessionManager::restartHint() const
+
+ Returns the application's current restart hint. The default is
+ \c RestartIfRunning.
+
+ \sa setRestartHint()
+*/
+
+/*!
+ \fn void TQSessionManager::setRestartCommand( const TQStringList& command )
+
+ If the session manager is capable of restoring sessions it will
+ execute \a command in order to restore the application. The command
+ defaults to
+
+ \code
+ appname -session id
+ \endcode
+
+ The \c -session option is mandatory; otherwise TQApplication cannot
+ tell whether it has been restored or what the current session
+ identifier is. See TQApplication::isSessionRestored() and
+ TQApplication::sessionId() for details.
+
+ If your application is very simple, it may be possible to store the
+ entire application state in additional command line options. This
+ is usually a very bad idea because command lines are often limited
+ to a few hundred bytes. Instead, use TQSettings, or temporary files
+ or a database for this purpose. By marking the data with the unique
+ sessionId(), you will be able to restore the application in a future
+ session.
+
+ \sa restartCommand(), setDiscardCommand(), setRestartHint()
+*/
+
+/*!
+ \fn TQStringList TQSessionManager::restartCommand() const
+
+ Returns the currently set restart command.
+
+ Note that if you want to iterate over the list, you should
+ iterate over a copy, e.g.
+ \code
+ TQStringList list = mySession.restartCommand();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa setRestartCommand(), restartHint()
+*/
+
+/*!
+ \fn void TQSessionManager::setDiscardCommand( const TQStringList& )
+
+ \sa discardCommand(), setRestartCommand()
+*/
+
+
+/*!
+ \fn TQStringList TQSessionManager::discardCommand() const
+
+ Returns the currently set discard command.
+
+ Note that if you want to iterate over the list, you should
+ iterate over a copy, e.g.
+ \code
+ TQStringList list = mySession.discardCommand();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa setDiscardCommand(), restartCommand(), setRestartCommand()
+*/
+
+/*!
+ \overload void TQSessionManager::setManagerProperty( const TQString& name,
+ const TQString& value )
+
+ Low-level write access to the application's identification and state
+ records are kept in the session manager.
+
+ The property called \a name has its value set to the string \a value.
+*/
+
+/*!
+ \fn void TQSessionManager::setManagerProperty( const TQString& name,
+ const TQStringList& value )
+
+ Low-level write access to the application's identification and state
+ record are kept in the session manager.
+
+ The property called \a name has its value set to the string list \a value.
+*/
+
+/*!
+ \fn bool TQSessionManager::isPhase2() const
+
+ Returns TRUE if the session manager is currently performing a second
+ session management phase; otherwise returns FALSE.
+
+ \sa requestPhase2()
+*/
+
+/*!
+ \fn void TQSessionManager::requestPhase2()
+
+ Requests a second session management phase for the application. The
+ application may then return immediately from the
+ TQApplication::commitData() or TQApplication::saveState() function,
+ and they will be called again once most or all other applications have
+ finished their session management.
+
+ The two phases are useful for applications such as the X11 window manager
+ that need to store information about another application's windows
+ and therefore have to wait until these applications have completed their
+ respective session management tasks.
+
+ Note that if another application has requested a second phase it
+ may get called before, simultaneously with, or after your
+ application's second phase.
+
+ \sa isPhase2()
+*/
+
+/*!
+ \fn int TQApplication::horizontalAlignment( int align )
+
+ Strips out vertical tqalignment flags and transforms an
+ tqalignment \a align of AlignAuto into AlignLeft or
+ AlignRight according to the language used. The other horizontal
+ tqalignment flags are left untouched.
+*/
+
+
+/*****************************************************************************
+ Stubbed session management support
+ *****************************************************************************/
+#ifndef TQT_NO_SESSIONMANAGER
+#if defined( TQT_NO_SM_SUPPORT ) || defined( TQ_WS_WIN ) || defined( TQ_WS_MAC ) || defined( TQ_WS_TQWS )
+
+class TQSessionManagerData
+{
+public:
+ TQStringList restartCommand;
+ TQStringList discardCommand;
+ TQString sessionId;
+ TQString sessionKey;
+ TQSessionManager::RestartHint restartHint;
+};
+
+TQSessionManager* qt_session_manager_self = 0;
+TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString &key )
+ : TQObject( app, "qt_sessionmanager" )
+{
+ qt_session_manager_self = this;
+ d = new TQSessionManagerData;
+#if defined(TQ_WS_WIN) && !defined(TQ_OS_TEMP)
+ wchar_t guidstr[40];
+ GUID guid;
+ CoCreateGuid( &guid );
+ StringFromGUID2(guid, guidstr, 40);
+ id = TQString::fromUcs2((ushort*)guidstr);
+ CoCreateGuid( &guid );
+ StringFromGUID2(guid, guidstr, 40);
+ key = TQString::fromUcs2((ushort*)guidstr);
+#endif
+ d->sessionId = id;
+ d->sessionKey = key;
+ d->restartHint = RestartIfRunning;
+}
+
+TQSessionManager::~TQSessionManager()
+{
+ delete d;
+ qt_session_manager_self = 0;
+}
+
+TQString TQSessionManager::sessionId() const
+{
+ return d->sessionId;
+}
+
+TQString TQSessionManager::sessionKey() const
+{
+ return d->sessionKey;
+}
+
+
+#if defined(TQ_WS_X11) || defined(TQ_WS_MAC)
+void* TQSessionManager::handle() const
+{
+ return 0;
+}
+#endif
+
+#if !defined(TQ_WS_WIN)
+bool TQSessionManager::allowsInteraction()
+{
+ return TRUE;
+}
+
+bool TQSessionManager::allowsErrorInteraction()
+{
+ return TRUE;
+}
+void TQSessionManager::release()
+{
+}
+
+void TQSessionManager::cancel()
+{
+}
+#endif
+
+
+void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint)
+{
+ d->restartHint = hint;
+}
+
+TQSessionManager::RestartHint TQSessionManager::restartHint() const
+{
+ return d->restartHint;
+}
+
+void TQSessionManager::setRestartCommand( const TQStringList& command)
+{
+ d->restartCommand = command;
+}
+
+TQStringList TQSessionManager::restartCommand() const
+{
+ return d->restartCommand;
+}
+
+void TQSessionManager::setDiscardCommand( const TQStringList& command)
+{
+ d->discardCommand = command;
+}
+
+TQStringList TQSessionManager::discardCommand() const
+{
+ return d->discardCommand;
+}
+
+void TQSessionManager::setManagerProperty( const TQString&, const TQString&)
+{
+}
+
+void TQSessionManager::setManagerProperty( const TQString&, const TQStringList& )
+{
+}
+
+bool TQSessionManager::isPhase2() const
+{
+ return FALSE;
+}
+
+void TQSessionManager::requestPhase2()
+{
+}
+
+#endif // TQT_NO_SM_SUPPORT
+#endif //TQT_NO_SESSIONMANAGER
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqapplication.cpp~ b/tqtinterface/qt4/src/kernel/tqapplication.cpp~
new file mode 100644
index 0000000..ff60776
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqapplication.cpp~
@@ -0,0 +1,5499 @@
+/****************************************************************************
+**
+** Implementation of TQApplication class
+**
+** Created : 931107
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqobjectlist.h"
+#include "tqapplication.h"
+#include "tqeventloop.h"
+#include "tqeventloop_p.h"
+#include "tqwidget.h"
+#include "tqwidgetlist.h"
+#include "tqwidgetintdict.h"
+#include "tqptrdict.h"
+#include "tqcleanuphandler.h"
+
+#include "tqtranslator.h"
+#include "tqtextcodec.h"
+#include "tqsessionmanager.h"
+#include "tqdragobject.h"
+#include "tqclipboard.h"
+#include "tqcursor.h"
+#include "tqstyle.h"
+#include "tqstylefactory.h"
+#include "tqfile.h"
+#include "tqmessagebox.h"
+#include "tqdir.h"
+#include "tqfileinfo.h"
+#ifdef TQ_WS_WIN
+#include "tqinputcontext_p.h"
+#endif
+#include "tqfontdata_p.h"
+
+#if defined(TQT_THREAD_SUPPORT)
+# include "tqmutex.h"
+# include "tqthread.h"
+#endif // TQT_THREAD_SUPPORT
+
+#include <stdlib.h>
+
+#ifdef truncate
+# undef truncate
+#endif
+
+#ifdef USE_QT4
+
+TQApplication *tqAppReal; // global application object
+TQStyle *TQApplication::app_style = 0; // default application style
+bool qt_explicit_app_style = FALSE; // style explicitly set by programmer
+QWidget* TQApplication::current_app_main_widget = 0; // current main widget
+
+int TQApplication::app_cspec = TQApplication::NormalColor; // color mode (obsolete)
+
+TQWidgetList * qt_modal_stack=0; // stack of modal widgets
+
+#ifndef TQT_NO_PALETTE
+TQPalette *TQApplication::app_pal = 0; // default application palette
+#endif
+// TQFont *TQApplication::app_font = 0; // default application font
+bool qt_app_has_font = FALSE;
+
+bool qt_is_gui_used;
+bool TQ_EXPORT qt_resolve_symlinks = TRUE;
+bool TQ_EXPORT qt_tab_all_widgets = TRUE;
+
+#if defined(TQ_WS_X11)
+extern void qt_init( Display* dpy, TQt::HANDLE, TQt::HANDLE );
+#endif
+extern void qt_init( int *argcptr, char **argv, TQApplication::Type );
+
+#ifndef TQT_NO_CLIPBOARD
+TQClipboard *tqt_clipboard = 0; // global clipboard object
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+TQMutex *TQApplication::qt_mutex = 0;
+static TQMutex *postevent_mutex = 0;
+static TQt::HANDLE qt_application_thread_id = 0;
+TQ_EXPORT TQt::HANDLE qt_get_application_thread_id()
+{
+ return qt_application_thread_id;
+}
+#endif // TQT_THREAD_SUPPORT
+
+
+#ifdef TQT_THREAD_SUPPORT
+ #define TQAPPLICATION_MUTEX_INIT \
+ qt_mutex = new TQMutex( TRUE ); \
+ postevent_mutex = new TQMutex( TRUE ); \
+ qt_application_thread_id = TQThread::currentThread();
+#else // TQT_THREAD_SUPPORT
+ #define TQAPPLICATION_MUTEX_INIT
+#endif // TQT_THREAD_SUPPORT
+
+TQWidgetList TQApplication::tqt_all_widgets_list;
+
+TQApplication::TQApplication( int &argc, char **argv ) : QApplication( argc, argv )
+{
+ bool GUIenabled = true;
+ TQAPPLICATION_GUI_CONDITIONAL_VAR_INIT
+ TQAPPLICATION_XORG_CONDITIONAL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled ) : QApplication( argc, argv, GUIenabled )
+{
+ TQAPPLICATION_GUI_CONDITIONAL_VAR_INIT
+ TQAPPLICATION_XORG_CONDITIONAL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+TQApplication::TQApplication( int &argc, char **argv, Type t ) : QApplication( argc, argv, t )
+{
+ TQAPPLICATION_GUI_VAR_INIT
+ TQAPPLICATION_XORG_PARTIAL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+#if defined(TQ_WS_X11)
+TQApplication::TQApplication( Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap ) : QApplication( dpy, visual, cmap )
+{
+ TQAPPLICATION_GUI_VAR_INIT
+ TQAPPLICATION_XORG_FULL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+TQApplication::TQApplication( Display *dpy, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap ) : QApplication( dpy, argc, argv, visual, cmap )
+{
+ TQAPPLICATION_GUI_VAR_INIT
+ TQAPPLICATION_XORG_FULL_INIT
+ TQAPPLICATION_MUTEX_INIT
+ TQAPPLICATION_REGISTER_TQ_DATATYPES
+}
+#endif
+
+// Qt4 session manager interconnect
+void TQApplication::commitData( QSessionManager& sm ) {
+ commitData(TQT_TQSESSIONMANAGER_OBJECT(sm));
+}
+void TQApplication::saveState( QSessionManager& sm ) {
+ saveState(TQT_TQSESSIONMANAGER_OBJECT(sm));
+}
+
+#ifndef TQT_NO_TRANSLATION
+
+bool qt_detectRTLLanguage()
+{
+ return TQApplication::tr( "TQT_LAYOUT_DIRECTION",
+ "Translate this string to the string 'LTR' in left-to-right"
+ " languages or to 'RTL' in right-to-left languages (such as Hebrew"
+ " and Arabic) to get proper widget tqlayout." ) == "RTL";
+}
+
+#endif // TQT_NO_TRANSLATION
+
+TQEventLoop* TQApplication::eventloop;
+TQPtrList<QEventLoop> TQApplication::tqt_event_loop_stack;
+int TQApplication::composedUnicode;
+bool TQApplication::metaComposeUnicode;
+
+// static TQEventLoop eventLoop_private; // Will this actually work, or do I need to call exec or something?
+//
+// TQEventLoop *TQApplication::eventLoop()
+// {
+// return &eventLoop_private;
+// }
+
+TQEventLoop *TQApplication::eventLoop() {
+ if ( !eventloop )
+ (void) new TQEventLoop( TQT_TQOBJECT(tqApp), "default event loop" );
+ return eventloop;
+}
+
+/*!
+
+ Wakes up the GUI thread.
+
+ \sa guiThreadAwake() \link threads.html Thread Support in TQt\endlink
+*/
+void TQApplication::wakeUpGuiThread()
+{
+ eventLoop()->wakeUp();
+}
+
+#ifdef TQT_THREAD_SUPPORT
+void TQApplication::lock() {
+ qt_mutex->lock();
+}
+
+void TQApplication::unlock(bool wakeUpGui) {
+ qt_mutex->unlock();
+
+ if (wakeUpGui)
+ wakeUpGuiThread();
+}
+
+bool TQApplication::locked() {
+ return qt_mutex->locked();
+}
+
+bool TQApplication::tryLock() {
+ return qt_mutex->tryLock();
+}
+#endif // TQT_THREAD_SUPPORT
+
+#ifndef TQT_NO_PALETTE
+TQPalette *qt_std_pal = 0;
+
+void qt_create_std_palette()
+{
+ if ( qt_std_pal )
+ delete qt_std_pal;
+
+ TQColor standardLightGray( 192, 192, 192 );
+ TQColor light( 255, 255, 255 );
+ TQColor dark( standardLightGray.dark( 150 ) );
+ TQColorGroup std_act( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ TQColorGroup std_dis( TQt::darkGray, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::darkGray, std_act.background() );
+ TQColorGroup std_inact( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ qt_std_pal = new TQPalette( std_act, std_dis, std_inact );
+}
+
+static void qt_fix_tooltips()
+{
+ // No resources for this yet (unlike on Windows).
+ TQColorGroup cg( TQt::black, TQColor(255,255,220),
+ TQColor(96,96,96), TQt::black, TQt::black,
+ TQt::black, TQColor(255,255,220) );
+ TQPalette pal( cg, cg, cg );
+ TQApplication::tqsetPalette( pal, TRUE, "TQTipLabel");
+}
+#endif
+
+// [FIXME] This needs to somehow connect to the Qt4 style mechanism
+// Possibly on calls to setStyle the Qt4 setStyle must also be called for the same style?
+
+static TQString *qt_style_override = 0;
+
+TQStyle& TQApplication::tqstyle()
+{
+#ifndef TQT_NO_STYLE
+ if ( app_style )
+ return *app_style;
+ if ( !qt_is_gui_used )
+ qFatal( "No style available in non-gui applications!" );
+
+#if defined(TQ_WS_X11)
+// if(!qt_style_override)
+// x11_initialize_style(); // run-time search for default style
+#endif
+ if ( !app_style ) {
+// // Compile-time search for default style
+// //
+ TQString style;
+ if ( qt_style_override ) {
+ style = *qt_style_override;
+ delete qt_style_override;
+ qt_style_override = 0;
+ } else {
+// # if defined(TQ_WS_WIN) && defined(TQ_OS_TEMP)
+// style = "PocketPC";
+// #elif defined(TQ_WS_WIN)
+// if ( qWinVersion() >= TQt::WV_XP && qWinVersion() < TQt::WV_NT_based )
+// style = "WindowsXP";
+// else
+// style = "Windows"; // default styles for Windows
+// #elif defined(TQ_WS_X11) && defined(TQ_OS_SOLARIS)
+// style = "CDE"; // default style for X11 on Solaris
+// #elif defined(TQ_WS_X11) && defined(TQ_OS_IRIX)
+// style = "SGI"; // default style for X11 on IRIX
+// #elif defined(TQ_WS_X11)
+ style = "Motif"; // default style for X11
+// #elif defined(TQ_WS_MAC)
+// style = "Macintosh"; // default style for all Mac's
+// #elif defined(TQ_WS_TQWS)
+// style = "Compact"; // default style for small tqdevices
+// #endif
+ }
+ app_style = TQStyleFactory::create( style );
+ if ( !app_style && // platform default style not available, try alternatives
+ !(app_style = TQStyleFactory::create( "Windows" ) ) &&
+ !(app_style = TQStyleFactory::create( "Platinum" ) ) &&
+ !(app_style = TQStyleFactory::create( "MotifPlus" ) ) &&
+ !(app_style = TQStyleFactory::create( "Motif" ) ) &&
+ !(app_style = TQStyleFactory::create( "CDE" ) ) &&
+ !(app_style = TQStyleFactory::create( "Aqua" ) ) &&
+ !(app_style = TQStyleFactory::create( "SGI" ) ) &&
+ !(app_style = TQStyleFactory::create( "Compact" ) )
+#ifndef TQT_NO_STRINGLIST
+ && !(app_style = TQStyleFactory::create( TQStyleFactory::keys()[0] ) )
+#endif
+ )
+ qFatal( "No %s style available!", style.latin1() );
+ }
+
+// TQPalette app_pal_copy ( *app_pal );
+// app_style->polish( *app_pal );
+
+// if ( is_app_running && !is_app_closing && (*app_pal != app_pal_copy) ) {
+// TQEvent e( TQEvent::ApplicationPaletteChange );
+// TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+// register TQWidget *w;
+// while ( (w=it.current()) ) { // for all widgets...
+// ++it;
+// sendEvent( w, &e );
+// }
+// }
+
+ app_style->polish( tqApp );
+#endif
+ return *app_style;
+}
+
+/*!
+ Enters the main event loop and waits until exit() is called or the
+ main widget is destroyed, and returns the value that was set to
+ exit() (which is 0 if exit() is called via quit()).
+
+ It is necessary to call this function to start event handling. The
+ main event loop receives events from the window system and
+ dispatches these to the application widgets.
+
+ Generally speaking, no user interaction can take place before
+ calling exec(). As a special case, modal widgets like TQMessageBox
+ can be used before calling exec(), because modal widgets call
+ exec() to start a local event loop.
+
+ To make your application perform idle processing, i.e. executing a
+ special function whenever there are no pending events, use a
+ TQTimer with 0 timeout. More advanced idle processing schemes can
+ be achieved using processEvents().
+
+ \sa quit(), exit(), processEvents(), setMainWidget()
+*/
+int TQApplication::exec()
+{
+ return eventLoop()->exec();
+}
+
+/*!
+ Sets the application's GUI style to \a style. Ownership of the style
+ object is transferred to TQApplication, so TQApplication will delete
+ the style object on application exit or when a new style is set.
+
+ Example usage:
+ \code
+ TQApplication::setStyle( new TQWindowsStyle );
+ \endcode
+
+ When switching application styles, the color palette is set back to
+ the initial colors or the system defaults. This is necessary since
+ certain styles have to adapt the color palette to be fully
+ style-guide compliant.
+
+ \sa style(), TQStyle, setPalette(), desktopSettingsAware()
+*/
+void TQApplication::setStyle( TQStyle *style )
+{
+ TQStyle* old = app_style;
+ app_style = style;
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ delete old;
+ return;
+ }
+
+ // clean up the old style
+ if (old) {
+// if ( is_app_running && !is_app_closing ) {
+// TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+// register TQWidget *w;
+// while ( (w=it.current()) ) { // for all widgets...
+// ++it;
+// if ( !w->testWFlags(WType_Desktop) && // except desktop
+// w->testWState(WState_Polished) ) { // has been polished
+// old->unPolish(w);
+// }
+// }
+// }
+// old->unPolish( tqApp );
+ }
+
+ // take care of possible palette requirements of certain gui
+ // styles. Do it before polishing the application since the style
+ // might call TQApplication::setStyle() itself
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+ TQPalette tmpPal = *qt_std_pal;
+ tqsetPalette( tmpPal, TRUE );
+
+ // initialize the application with the new style
+ app_style->polish( tqApp );
+
+ // re-polish existing widgets if necessary
+ if (old) {
+// if ( is_app_running && !is_app_closing ) {
+// TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+// register TQWidget *w;
+// while ( (w=it.current()) ) { // for all widgets...
+// ++it;
+// if ( !w->testWFlags(WType_Desktop) ) { // except desktop
+// if ( w->testWState(WState_Polished) )
+// app_style->polish(w); // repolish
+// w->styleChange( *old );
+// if ( w->isVisible() ){
+// w->update();
+// }
+// }
+// }
+// }
+ delete old;
+ }
+}
+
+/*!
+ \overload
+
+ Requests a TQStyle object for \a style from the TQStyleFactory.
+
+ The string must be one of the TQStyleFactory::keys(), typically one
+ of "windows", "motif", "cde", "motifplus", "platinum", "sgi" and
+ "compact". Depending on the platform, "windowsxp", "aqua" or
+ "macintosh" may be available.
+
+ A later call to the TQApplication constructor will override the
+ requested style when a "-style" option is passed in as a commandline
+ parameter.
+
+ Returns 0 if an unknown \a style is passed, otherwise the TQStyle object
+ returned is set as the application's GUI style.
+*/
+TQStyle* TQApplication::setStyle( const TQString& style )
+{
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ if(qt_style_override)
+ *qt_style_override = style;
+ else
+ qt_style_override = new TQString(style);
+ return 0;
+ }
+ TQStyle *s = TQStyleFactory::create( style );
+ if ( !s )
+ return 0;
+
+ setStyle( s );
+ return s;
+}
+
+TQWidget *TQApplication::mainWidget()
+{
+ return TQT_TQWIDGET(current_app_main_widget);
+}
+
+const char *TQApplication::tqname() const {
+ if (dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQApplication::tqname() on an object without a constructed TQApplication object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+const char *TQApplication::name() const {
+ if (dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQApplication::name() on an object without a constructed TQApplication object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+/*!\internal
+
+ Called from qapplication_<platform>.cpp, returns TRUE
+ if the widget should accept the event.
+ */
+TQ_EXPORT bool qt_tryModalHelper( TQWidget *widget, TQWidget **rettop ) {
+ TQWidget *modal=0, *top=TQT_TQWIDGET(TQApplication::activeModalWidget());
+ if ( rettop ) *rettop = top;
+
+ if ( tqApp->activePopupWidget() )
+ return TRUE;
+
+#ifdef TQ_WS_MACX
+ top = qt_tryModalHelperMac( top );
+ if ( rettop ) *rettop = top;
+#endif
+
+ TQWidget* groupLeader = widget;
+ widget = widget->tqtopLevelWidget();
+
+ if ( widget->testWFlags(TQt::WShowModal) ) // widget is modal
+ modal = widget;
+ if ( !top || modal == top ) // don't block event
+ return TRUE;
+
+ TQWidget * p = widget->parentWidget(); // Check if the active modal widget is a tqparent of our widget
+ while ( p ) {
+ if ( p == top )
+ return TRUE;
+ p = p->parentWidget();
+ }
+
+ while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) )
+ groupLeader = groupLeader->parentWidget();
+
+// [FIXME]
+printf("[WARNING] bool qt_tryModalHelper partially implemented\n\r");
+// if ( groupLeader ) {
+// // Does groupLeader have a child in qt_modal_stack?
+// bool unrelated = TRUE;
+// modal = qt_modal_stack->first();
+// while (modal && unrelated) {
+// TQWidget* p = modal->parentWidget();
+// while ( p && p != groupLeader && !p->testWFlags( TQt::WGroupLeader) ) {
+// p = p->parentWidget();
+// }
+// modal = qt_modal_stack->next();
+// if ( p == groupLeader ) unrelated = FALSE;
+// }
+//
+// if ( unrelated )
+// return TRUE; // don't block event
+// }
+
+ return FALSE;
+}
+
+/*!\internal
+
+ Creates the proper Enter/Leave event when widget \a enter is entered
+ and widget \a leave is left.
+ */
+TQ_EXPORT void qt_dispatchEnterLeave( TQWidget* enter, TQWidget* leave ) {
+#if 0
+ if ( leave ) {
+ TQEvent e( TQEvent::Leave );
+ TQApplication::sendEvent( leave, & e );
+ }
+ if ( enter ) {
+ TQEvent e( TQEvent::Enter );
+ TQApplication::sendEvent( enter, & e );
+ }
+ return;
+#endif
+
+ TQWidget* w ;
+ if ( !enter && !leave )
+ return;
+ TQWidgetList leaveList;
+ TQWidgetList enterList;
+
+ bool sameWindow = leave && enter && leave->tqtopLevelWidget() == enter->tqtopLevelWidget();
+ if ( leave && !sameWindow ) {
+ w = leave;
+ do {
+ leaveList.append( w );
+ } while ( (w = w->parentWidget( TRUE ) ) );
+ }
+ if ( enter && !sameWindow ) {
+ w = enter;
+ do {
+ enterList.prepend( w );
+ } while ( (w = w->parentWidget(TRUE) ) );
+ }
+ if ( sameWindow ) {
+ int enterDepth = 0;
+ int leaveDepth = 0;
+ w = enter;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ enterDepth++;
+ w = leave;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ leaveDepth++;
+ TQWidget* wenter = enter;
+ TQWidget* wleave = leave;
+ while ( enterDepth > leaveDepth ) {
+ wenter = wenter->parentWidget();
+ enterDepth--;
+ }
+ while ( leaveDepth > enterDepth ) {
+ wleave = wleave->parentWidget();
+ leaveDepth--;
+ }
+ while ( !wenter->isTopLevel() && wenter != wleave ) {
+ wenter = wenter->parentWidget();
+ wleave = wleave->parentWidget();
+ }
+
+ w = leave;
+ while ( w != wleave ) {
+ leaveList.append( w );
+ w = w->parentWidget();
+ }
+ w = enter;
+ while ( w != wenter ) {
+ enterList.prepend( w );
+ w = w->parentWidget();
+ }
+ }
+
+ TQEvent leaveEvent( TQEvent::Leave );
+ for ( w = leaveList.first(); w; w = leaveList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &leaveEvent );
+ }
+ TQEvent enterEvent( TQEvent::Enter );
+ for ( w = enterList.first(); w; w = enterList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &enterEvent );
+ }
+}
+
+#ifndef TQT_NO_CLIPBOARD
+/*!
+ Returns a pointer to the application global clipboard.
+*/
+TQClipboard *TQApplication::tqclipboard()
+{
+ if ( tqt_clipboard == 0 ) {
+ tqt_clipboard = new TQClipboard;
+ TQ_CHECK_PTR( tqt_clipboard );
+ }
+ return tqt_clipboard;
+}
+#endif // TQT_NO_CLIPBOARD
+
+/*!
+ \fn void TQApplication::commitData( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the TQSessionManager wants the
+ application to commit all its data.
+
+ Usually this means saving all open files, after getting
+ permission from the user. Furthermore you may want to provide a means
+ by which the user can cancel the shutdown.
+
+ Note that you should not exit the application within this function.
+ Instead, the session manager may or may not do this afterwards,
+ depending on the context.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details and example
+ usage.
+
+ The default implementation requests interaction and sends a close
+ event to all visible top level widgets. If any event was
+ rejected, the shutdown is canceled.
+
+ \sa isSessionRestored(), sessionId(), saveState(), \link session.html the Session Management overview\endlink
+*/
+#ifndef TQT_NO_SESSIONMANAGER
+void TQApplication::commitData( TQSessionManager& sm )
+{
+
+ if ( sm.allowsInteraction() ) {
+ TQWidgetList done;
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ bool cancelled = FALSE;
+ TQWidget* w = list->first();
+ while ( !cancelled && w ) {
+ if ( !w->isHidden() ) {
+ TQCloseEvent e;
+ sendEvent( w, &e );
+ cancelled = !e.isAccepted();
+ if ( !cancelled )
+ done.append( w );
+ delete list; // one never knows...
+ list = TQApplication::tqtopLevelWidgets();
+ w = list->first();
+ } else {
+ w = list->next();
+ }
+ while ( w && done.tqcontainsRef( w ) )
+ w = list->next();
+ }
+ delete list;
+ if ( cancelled )
+ sm.cancel();
+ }
+}
+
+
+/*!
+ \fn void TQApplication::saveState( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the
+ \link TQSessionManager session manager \endlink wants the application
+ to preserve its state for a future session.
+
+ For example, a text editor would create a temporary file that
+ includes the current contents of its edit buffers, the location of
+ the cursor and other aspects of the current editing session.
+
+ Note that you should never exit the application within this
+ function. Instead, the session manager may or may not do this
+ afterwards, depending on the context. Futhermore, most session
+ managers will very likely request a saved state immediately after
+ the application has been started. This permits the session manager
+ to learn about the application's restart policy.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details.
+
+ \sa isSessionRestored(), sessionId(), commitData(), \link session.html the Session Management overview\endlink
+*/
+
+void TQApplication::saveState( TQSessionManager& /* sm */ )
+{
+}
+#endif //TQT_NO_SESSIONMANAGER
+
+#if 1 /* OBSOLETE */
+
+TQApplication::ColorMode TQApplication::colorMode()
+{
+ return (TQApplication::ColorMode)app_cspec;
+}
+
+void TQApplication::setColorMode( TQApplication::ColorMode mode )
+{
+ printf("[WARNING] TQApplication::setColorMode() does nothing!\n\r");
+ app_cspec = mode;
+}
+#endif
+
+/*!
+ Initialization of the appearance of the widget \a w \e before it is first
+ shown.
+
+ Usually widgets call this automatically when they are polished. It
+ may be used to do some style-based central customization of widgets.
+
+ Note that you are not limited to the public functions of TQWidget.
+ Instead, based on meta information like TQObject::className() you are
+ able to customize any kind of widget.
+
+ \sa TQStyle::polish(), TQWidget::polish(), setPalette(), setFont()
+*/
+
+void TQApplication::polish( QWidget *w )
+{
+#ifndef TQT_NO_STYLE
+ TQT_TQWIDGET(w)->tqstyle().polish( w );
+#endif
+}
+
+void TQApplication::exit_loop() { // Does not exit in Qt4
+ printf("[WARNING] No runtime validation is performed within TQApplication::exit_loop; this may cause odd/obscure problems\n\r");
+// QThreadData *data = QThreadData::current();
+// if (!data->eventLoops.isEmpty())
+// data->eventLoops.top()->exit();
+ QEventLoop* eventLoop = tqt_event_loop_stack.getLast();
+ if (eventLoop) {
+ eventLoop->exit();
+ }
+ else {
+ printf("[WARNING] An attempt was made to exit a nonexistant event loop!\n\r");
+ }
+}
+int TQApplication::enter_loop() { // Does not exit in Qt4
+ printf("[WARNING] No runtime validation is performed within TQApplication::enter_loop; this may cause odd/obscure problems\n\r");
+ QEventLoop* eventLoop = new QEventLoop();
+ tqt_event_loop_stack.append(eventLoop);
+ int returnCode = eventLoop->exec(); // This blocks until either QEventLoop::exit is called or the loop terminates normally
+ tqt_event_loop_stack.remove(eventLoop);
+ delete eventLoop;
+ return returnCode;
+}
+
+TQMetaObject *TQApplication::tqmetaObject() const {
+ return TQT_TQOBJECT_CONST(this)->tqmetaObject();
+}
+
+void TQApplication::processOneEvent() {
+ processEvents(QEventLoop::WaitForMoreEvents);
+}
+
+void TQApplication::tqprocessEvents() {
+ return processEvents();
+}
+
+void TQApplication::tqprocessEvents( int maxtime ) {
+ return processEvents(QEventLoop::AllEvents, maxtime);
+}
+
+/*!
+ \obsolete
+
+ Returns the current loop level.
+
+ Use TQApplication::eventLoop()->loopLevel() instead.
+
+*/
+int TQApplication::loopLevel() const
+{
+ return eventLoop()->loopLevel();
+}
+
+bool TQApplication::hasGlobalMouseTracking()
+{
+ printf("[WARNING] TQApplication::hasGlobalMouseTracking unimplemented!\n\r");
+ return true;
+}
+
+void TQApplication::setGlobalMouseTracking( bool enable )
+{
+ printf("[WARNING] TQApplication::setGlobalMouseTracking unimplemented!\n\r");
+}
+
+#if defined(TQ_WS_X11)
+void TQApplication::create_xim() {
+ printf("[WARNING] static void TQApplication::create_xim() unimplemented\n\r"); // [FIXME]
+}
+
+void TQApplication::close_xim() {
+ printf("[WARNING] static void TQApplication::close_xim() unimplemented\n\r"); // [FIXME]
+}
+
+bool TQApplication::x11_apply_settings() {
+ printf("[WARNING] static bool TQApplication::x11_apply_settings() unimplemented\n\r");
+ return false; // [FIXME]
+}
+#endif
+
+#ifndef TQT_NO_TEXTCODEC
+void TQApplication::setDefaultCodec( TQTextCodec * ) {
+ printf("[WARNING] void TQApplication::setDefaultCodec( TQTextCodec * ) unimplemented\n\r"); // [FIXME]
+}
+
+TQTextCodec* TQApplication::defaultCodec() const
+{
+// return TQTextCodec::codecForTr();
+
+ printf("[WARNING] TQTextCodec* TQApplication::defaultCodec unimplemented\n\r"); // [FIXME]
+// return TQTextCodec();
+}
+#endif
+
+TQWidgetList *TQApplication::tqallWidgets() {
+ QWidgetList ql = allWidgets();
+ tqt_all_widgets_list.clear();
+ for (int i = 0; i < ql.size(); ++i) tqt_all_widgets_list.append(TQT_TQWIDGET(ql.at(i)));
+ return &tqt_all_widgets_list;
+}
+
+TQStringList TQApplication::libraryPaths() {
+ return TQT_TQSTRINGLIST_OBJECT(QApplication::libraryPaths());
+}
+
+void TQApplication::tqsetLibraryPaths( const QStringList &qsl ) {
+ setLibraryPaths(qsl);
+}
+
+TQWidgetList *TQApplication::tqtopLevelWidgets() {
+ // The end user of the list is expected to delete it, so create it with new...
+ TQWidgetList *tqwl = new TQWidgetList();
+ foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ tqwl->append(static_cast<TQWidget*>(widget));
+ }
+ return tqwl;
+
+}
+
+TQDesktopWidget *TQApplication::desktop() {
+ return static_cast<TQDesktopWidget*>(QApplication::desktop());
+}
+
+const QColor &TQApplication::winStyleHighlightColor() {
+ return palette().color(QPalette::Active, QPalette::Highlight);
+}
+
+void TQApplication::setWinStyleHighlightColor( const QColor c ) {
+ TQPalette p( tqpalette() );
+ p.setColor( TQColorGroup::Highlight, c );
+ tqsetPalette( p, TRUE);
+}
+
+void TQApplication::tqsetPalette(const QPalette &pal, bool, const char* className) {
+ setPalette(pal, className);
+}
+
+void TQApplication::tqsetFont(const QFont &font, bool, const char* className) {
+ setFont(font, className);
+}
+
+void TQApplication::setReverseLayout(bool b) {
+ setLayoutDirection(b?Qt::RightToLeft:Qt::LeftToRight);
+}
+
+bool TQApplication::reverseLayout() {
+ return layoutDirection() == Qt::RightToLeft;
+}
+
+TQPalette TQApplication::tqpalette( const TQWidget*w ) {
+ return palette( w );
+}
+
+#ifndef TQT_NO_CURSOR
+//void TQApplication::setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE ) {
+// TQ_UNUSED(tqreplace);
+// QApplication::setOverrideCursor( cur );
+// }
+
+void TQApplication::setOverrideCursor( const QCursor &cur, bool tqreplace ) {
+ TQ_UNUSED(tqreplace);
+ printf("[FIXME] TQApplication::setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE ) unimplemented\n\r");
+}
+#endif
+
+void TQApplication::sendPostedEvents( QObject *receiver, int event_type ) {
+ QApplication::sendPostedEvents(receiver, event_type);
+ if (event_type == TQEvent::LayoutHint) {
+ QApplication::sendPostedEvents(receiver, TQEvent::LayoutRequest);; // This one eats LayoutRequest/LayoutHint events for breakfast
+ }
+}
+
+void TQApplication::sendPostedEvents() {
+ QApplication::sendPostedEvents();
+}
+
+TQWidget *TQApplication::tqfocusWidget() const {
+ return static_cast<TQWidget*>(focusWidget());
+}
+
+TQWidget *TQApplication::widgetAt( const TQPoint &p, bool child ) {
+ TQ_UNUSED(child);
+ return static_cast<TQWidget*>(QApplication::widgetAt( p ));
+}
+
+TQWidget *TQApplication::widgetAt( int x, int y, bool child ) {
+ TQ_UNUSED(child);
+ return static_cast<TQWidget*>(QApplication::widgetAt( QPoint(x, y) ));
+}
+
+int TQApplication::horizontalAlignment( int align ) {
+ return QStyle::visualAlignment(layoutDirection(), (Qt::Alignment)align);
+}
+
+void TQApplication::flushX() {
+ flush();
+}
+
+const char *TQApplication::name(const char *defaultName) const {
+ TQString s = objectName();
+ return s.isEmpty()?defaultName:s.latin1();
+}
+
+void TQApplication::setName(const char *aName) {
+ TQT_TQOBJECT(this)->setName(aName);
+}
+
+/*!
+ Displays a simple message box about TQt. The message includes the
+ version number of TQt being used by the application.
+
+ This is useful for inclusion in the Help menu of an application.
+ See the examples/menu/menu.cpp example.
+
+ This function is a convenience slot for TQMessageBox::aboutTQt().
+*/
+void TQApplication::aboutTQt()
+{
+#ifndef TQT_NO_MESSAGEBOX
+ TQMessageBox::aboutTQt( mainWidget() );
+#endif // TQT_NO_MESSAGEBOX
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQApplication tqapplication.h
+ \brief The TQApplication class manages the GUI application's control
+ flow and main settings.
+
+ \ingroup application
+ \mainclass
+
+ It tqcontains the main event loop, where all events from the window
+ system and other sources are processed and dispatched. It also
+ handles the application's initialization and finalization, and
+ provides session management. It also handles most system-wide and
+ application-wide settings.
+
+ For any GUI application that uses TQt, there is precisely one
+ TQApplication object, no matter whether the application has 0, 1, 2
+ or more windows at any time.
+
+ The TQApplication object is accessible through the global pointer \c
+ tqApp. Its main areas of responsibility are:
+ \list
+
+ \i It initializes the application with the user's desktop settings
+ such as palette(), font() and doubleClickInterval(). It keeps track
+ of these properties in case the user changes the desktop globally, for
+ example through some kind of control panel.
+
+ \i It performs event handling, meaning that it receives events
+ from the underlying window system and dispatches them to the relevant
+ widgets. By using sendEvent() and postEvent() you can send your own
+ events to widgets.
+
+ \i It parses common command line arguments and sets its internal
+ state accordingly. See the \link TQApplication::TQApplication()
+ constructor documentation\endlink below for more details about this.
+
+ \i It defines the application's look and feel, which is
+ encapsulated in a TQStyle object. This can be changed at runtime
+ with setStyle().
+
+ \i It specifies how the application is to allocate colors.
+ See setColorSpec() for details.
+
+ \i It provides localization of strings that are visible to the user
+ via translate().
+
+ \i It provides some magical objects like the desktop() and the
+ clipboard().
+
+ \i It knows about the application's windows. You can ask which
+ widget is at a certain position using widgetAt(), get a list of
+ tqtopLevelWidgets() and closeAllWindows(), etc.
+
+ \i It manages the application's mouse cursor handling,
+ see setOverrideCursor() and setGlobalMouseTracking().
+
+ \i On the X window system, it provides functions to flush and sync
+ the communication stream, see flushX() and syncX().
+
+ \i It provides support for sophisticated \link
+ session.html session management \endlink. This makes it possible
+ for applications to terminate gracefully when the user logs out, to
+ cancel a shutdown process if termination isn't possible and even to
+ preserve the entire application's state for a future session. See
+ isSessionRestored(), sessionId() and commitData() and saveState()
+ for details.
+
+ \endlist
+
+ The <a href="simple-application.html">Application walk-through
+ example</a> tqcontains a typical complete main() that does the usual
+ things with TQApplication.
+
+ Since the TQApplication object does so much initialization, it
+ <b>must</b> be created before any other objects related to the user
+ interface are created.
+
+ Since it also deals with common command line arguments, it is
+ usually a good idea to create it \e before any interpretation or
+ modification of \c argv is done in the application itself. (Note
+ also that for X11, setMainWidget() may change the main widget
+ according to the \c -tqgeometry option. To preserve this
+ functionality, you must set your defaults before setMainWidget() and
+ any overrides after.)
+
+ \table
+ \header \i21 Groups of functions
+ \row
+ \i System settings
+ \i
+ desktopSettingsAware(),
+ setDesktopSettingsAware(),
+ cursorFlashTime(),
+ setCursorFlashTime(),
+ doubleClickInterval(),
+ setDoubleClickInterval(),
+ wheelScrollLines(),
+ setWheelScrollLines(),
+ palette(),
+ setPalette(),
+ font(),
+ setFont(),
+ fontMetrics().
+
+ \row
+ \i Event handling
+ \i
+ exec(),
+ processEvents(),
+ enter_loop(),
+ exit_loop(),
+ exit(),
+ quit().
+ sendEvent(),
+ postEvent(),
+ sendPostedEvents(),
+ removePostedEvents(),
+ hasPendingEvents(),
+ notify(),
+ macEventFilter(),
+ qwsEventFilter(),
+ x11EventFilter(),
+ x11ProcessEvent(),
+ winEventFilter().
+
+ \row
+ \i GUI Styles
+ \i
+ style(),
+ setStyle(),
+ polish().
+
+ \row
+ \i Color usage
+ \i
+ colorSpec(),
+ setColorSpec(),
+ qwsSetCustomColors().
+
+ \row
+ \i Text handling
+ \i
+ installTranslator(),
+ removeTranslator()
+ translate().
+
+ \row
+ \i Widgets
+ \i
+ mainWidget(),
+ setMainWidget(),
+ allWidgets(),
+ tqtopLevelWidgets(),
+ desktop(),
+ activePopupWidget(),
+ activeModalWidget(),
+ clipboard(),
+ tqfocusWidget(),
+ winFocus(),
+ activeWindow(),
+ widgetAt().
+
+ \row
+ \i Advanced cursor handling
+ \i
+ hasGlobalMouseTracking(),
+ setGlobalMouseTracking(),
+ overrideCursor(),
+ setOverrideCursor(),
+ restoreOverrideCursor().
+
+ \row
+ \i X Window System synchronization
+ \i
+ flushX(),
+ syncX().
+
+ \row
+ \i Session management
+ \i
+ isSessionRestored(),
+ sessionId(),
+ commitData(),
+ saveState().
+
+ \row
+ \i Threading
+ \i
+ lock(), unlock(), locked(), tryLock(),
+ wakeUpGuiThread()
+
+ \row
+ \i Miscellaneous
+ \i
+ closeAllWindows(),
+ startingUp(),
+ closingDown(),
+ type().
+ \endtable
+
+ \e {Non-GUI programs:} While TQt is not optimized or
+ designed for writing non-GUI programs, it's possible to use
+ \link tools.html some of its classes \endlink without creating a
+ TQApplication. This can be useful if you wish to share code between
+ a non-GUI server and a GUI client.
+
+ \headerfile tqnamespace.h
+ \headerfile tqwindowdefs.h
+ \headerfile tqglobal.h
+*/
+
+/*! \enum TQt::HANDLE
+ \internal
+*/
+
+/*!
+ \enum TQApplication::Type
+
+ \value Tty a console application
+ \value GuiClient a GUI client application
+ \value GuiServer a GUI server application
+*/
+
+/*!
+ \enum TQApplication::ColorSpec
+
+ \value NormalColor the default color allocation policy
+ \value CustomColor the same as NormalColor for X11; allocates colors
+ to a palette on demand under Windows
+ \value ManyColor the right choice for applications that use thousands of
+ colors
+
+ See setColorSpec() for full details.
+*/
+
+/*
+ The qt_init() and qt_cleanup() functions are implemented in the
+ qapplication_xyz.cpp file.
+*/
+
+void qt_init( int *, char **, TQApplication::Type );
+void qt_cleanup();
+#if defined(TQ_WS_X11)
+void qt_init( Display* dpy, TQt::HANDLE, TQt::HANDLE );
+#endif
+TQ_EXPORT bool qt_tryModalHelper( TQWidget *widget, TQWidget **rettop );
+
+TQApplication *tqApp = 0; // global application object
+
+TQStyle *TQApplication::app_style = 0; // default application style
+bool qt_explicit_app_style = FALSE; // style explicitly set by programmer
+
+int TQApplication::app_cspec = TQApplication::NormalColor;
+#ifndef TQT_NO_PALETTE
+TQPalette *TQApplication::app_pal = 0; // default application palette
+#endif
+TQFont *TQApplication::app_font = 0; // default application font
+bool qt_app_has_font = FALSE;
+#ifndef TQT_NO_CURSOR
+TQCursor *TQApplication::app_cursor = 0; // default application cursor
+#endif
+int TQApplication::app_tracking = 0; // global mouse tracking
+bool TQApplication::is_app_running = FALSE; // app starting up if FALSE
+bool TQApplication::is_app_closing = FALSE; // app closing down if TRUE
+int TQApplication::loop_level = 0; // event loop level
+TQWidget *TQApplication::main_widget = 0; // main application widget
+TQWidget *TQApplication::focus_widget = 0; // has keyboard input focus
+TQWidget *TQApplication::active_window = 0; // toplevel with keyboard focus
+bool TQApplication::obey_desktop_settings = TRUE; // use winsys resources
+int TQApplication::cursor_flash_time = 1000; // text caret flash time
+int TQApplication::mouse_double_click_time = 400; // mouse dbl click limit
+#ifndef TQT_NO_WHEELEVENT
+int TQApplication::wheel_scroll_lines = 3; // number of lines to scroll
+#endif
+bool qt_is_gui_used;
+bool TQ_EXPORT qt_resolve_symlinks = TRUE;
+bool TQ_EXPORT qt_tab_all_widgets = TRUE;
+TQRect qt_maxWindowRect;
+static int drag_time = 500;
+static int drag_distance = 4;
+static bool reverse_tqlayout = FALSE;
+TQSize TQApplication::app_strut = TQSize( 0,0 ); // no default application strut
+bool TQApplication::animate_ui = TRUE;
+bool TQApplication::animate_menu = FALSE;
+bool TQApplication::fade_menu = FALSE;
+bool TQApplication::animate_combo = FALSE;
+bool TQApplication::animate_tooltip = FALSE;
+bool TQApplication::fade_tooltip = FALSE;
+bool TQApplication::animate_toolbox = FALSE;
+bool TQApplication::widgetCount = FALSE;
+TQApplication::Type qt_appType=TQApplication::Tty;
+#ifndef TQT_NO_COMPONENT
+TQStringList *TQApplication::app_libpaths = 0;
+#endif
+bool TQApplication::metaComposeUnicode = FALSE;
+int TQApplication::composedUnicode = 0;
+
+#ifdef TQT_THREAD_SUPPORT
+TQMutex *TQApplication::qt_mutex = 0;
+static TQMutex *postevent_mutex = 0;
+static TQt::HANDLE qt_application_thread_id = 0;
+TQ_EXPORT TQt::HANDLE qt_get_application_thread_id()
+{
+ return qt_application_thread_id;
+}
+#endif // TQT_THREAD_SUPPORT
+
+TQEventLoop *TQApplication::eventloop = 0; // application event loop
+
+#ifndef TQT_NO_ACCEL
+extern bool qt_dispatchAccelEvent( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp
+extern bool qt_tryComposeUnicode( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp
+#endif
+
+#if defined(TQT_TABLET_SUPPORT)
+bool chokeMouse = FALSE;
+#endif
+
+void qt_setMaxWindowRect(const TQRect& r)
+{
+ qt_maxWindowRect = r;
+ // Re-resize any maximized windows
+ TQWidgetList* l = TQApplication::tqtopLevelWidgets();
+ if ( l ) {
+ TQWidget *w = l->first();
+ while ( w ) {
+ if ( w->isVisible() && w->isMaximized() )
+ {
+ w->showNormal(); //#### flicker
+ w->showMaximized();
+ }
+ w = l->next();
+ }
+ delete l;
+ }
+}
+
+typedef void (*VFPTR)();
+typedef TQValueList<VFPTR> TQVFuncList;
+static TQVFuncList *postRList = 0; // list of post routines
+
+/*!
+ \relates TQApplication
+
+ Adds a global routine that will be called from the TQApplication
+ destructor. This function is normally used to add cleanup routines
+ for program-wide functionality.
+
+ The function given by \a p should take no arguments and return
+ nothing, like this:
+ \code
+ static int *global_ptr = 0;
+
+ static void cleanup_ptr()
+ {
+ delete [] global_ptr;
+ global_ptr = 0;
+ }
+
+ void init_ptr()
+ {
+ global_ptr = new int[100]; // allocate data
+ qAddPostRoutine( cleanup_ptr ); // delete later
+ }
+ \endcode
+
+ Note that for an application- or module-wide cleanup,
+ qAddPostRoutine() is often not suitable. People have a tendency to
+ make such modules dynamically loaded, and then unload those modules
+ long before the TQApplication destructor is called, for example.
+
+ For modules and libraries, using a reference-counted initialization
+ manager or TQt' tqparent-child delete mechanism may be better. Here is
+ an example of a private class which uses the tqparent-child mechanism
+ to call a cleanup function at the right time:
+
+ \code
+ class MyPrivateInitStuff: public TQObject {
+ private:
+ MyPrivateInitStuff( TQObject * tqparent ): TQObject( tqparent) {
+ // initialization goes here
+ }
+ MyPrivateInitStuff * p;
+
+ public:
+ static MyPrivateInitStuff * initStuff( TQObject * tqparent ) {
+ if ( !p )
+ p = new MyPrivateInitStuff( tqparent );
+ return p;
+ }
+
+ ~MyPrivateInitStuff() {
+ // cleanup (the "post routine") goes here
+ }
+ }
+ \endcode
+
+ By selecting the right tqparent widget/object, this can often be made
+ to clean up the module's data at the exact right moment.
+*/
+
+TQ_EXPORT void qAddPostRoutine( TQtCleanUpFunction p)
+{
+ if ( !postRList ) {
+ postRList = new TQVFuncList;
+ TQ_CHECK_PTR( postRList );
+ }
+ postRList->prepend( p );
+}
+
+
+TQ_EXPORT void qRemovePostRoutine( TQtCleanUpFunction p )
+{
+ if ( !postRList ) return;
+ TQVFuncList::Iterator it = postRList->begin();
+ while ( it != postRList->end() ) {
+ if ( *it == p ) {
+ postRList->remove( it );
+ it = postRList->begin();
+ } else {
+ ++it;
+ }
+ }
+}
+
+// Default application palettes and fonts (per widget type)
+TQAsciiDict<TQPalette> *TQApplication::app_palettes = 0;
+TQAsciiDict<TQFont> *TQApplication::app_fonts = 0;
+
+#ifndef TQT_NO_SESSIONMANAGER
+TQString *TQApplication::session_key = 0; // ## session key. Should be a member in 4.0
+#endif
+TQWidgetList *TQApplication::popupWidgets = 0; // has keyboard input focus
+
+TQDesktopWidget *qt_desktopWidget = 0; // root window widgets
+#ifndef TQT_NO_CLIPBOARD
+TQClipboard *qt_clipboard = 0; // global clipboard object
+#endif
+TQWidgetList * qt_modal_stack=0; // stack of modal widgets
+
+// Definitions for posted events
+struct TQPostEvent {
+ TQPostEvent( TQObject *r, TQEvent *e ): receiver( r ), event( e ) {}
+ ~TQPostEvent() { delete event; }
+ TQObject *receiver;
+ TQEvent *event;
+};
+
+class TQ_EXPORT TQPostEventList : public TQPtrList<TQPostEvent>
+{
+public:
+ TQPostEventList() : TQPtrList<TQPostEvent>() {}
+ TQPostEventList( const TQPostEventList &list ) : TQPtrList<TQPostEvent>(list) {}
+ ~TQPostEventList() { clear(); }
+ TQPostEventList &operator=(const TQPostEventList &list)
+ { return (TQPostEventList&)TQPtrList<TQPostEvent>::operator=(list); }
+};
+class TQ_EXPORT TQPostEventListIt : public TQPtrListIterator<TQPostEvent>
+{
+public:
+ TQPostEventListIt( const TQPostEventList &l ) : TQPtrListIterator<TQPostEvent>(l) {}
+ TQPostEventListIt &operator=(const TQPostEventListIt &i)
+{ return (TQPostEventListIt&)TQPtrListIterator<TQPostEvent>::operator=(i); }
+};
+
+static TQPostEventList *globalPostedEvents = 0; // list of posted events
+
+uint qGlobalPostedEventsCount()
+{
+ if (!globalPostedEvents)
+ return 0;
+ return globalPostedEvents->count();
+}
+
+static TQSingleCleanupHandler<TQPostEventList> qapp_cleanup_events;
+
+#ifndef TQT_NO_PALETTE
+TQPalette *qt_std_pal = 0;
+
+void qt_create_std_palette()
+{
+ if ( qt_std_pal )
+ delete qt_std_pal;
+
+ TQColor standardLightGray( 192, 192, 192 );
+ TQColor light( 255, 255, 255 );
+ TQColor dark( standardLightGray.dark( 150 ) );
+ TQColorGroup std_act( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ TQColorGroup std_dis( TQt::darkGray, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::darkGray, std_act.background() );
+ TQColorGroup std_inact( TQt::black, standardLightGray,
+ light, dark, TQt::gray,
+ TQt::black, TQt::white );
+ qt_std_pal = new TQPalette( std_act, std_dis, std_inact );
+}
+
+static void qt_fix_tooltips()
+{
+ // No resources for this yet (unlike on Windows).
+ TQColorGroup cg( TQt::black, TQColor(255,255,220),
+ TQColor(96,96,96), TQt::black, TQt::black,
+ TQt::black, TQColor(255,255,220) );
+ TQPalette pal( cg, cg, cg );
+ TQApplication::setPalette( pal, TRUE, "TQTipLabel");
+}
+#endif
+
+void TQApplication::process_cmdline( int* argcptr, char ** argv )
+{
+ // process platform-indep command line
+ if ( !qt_is_gui_used || !*argcptr)
+ return;
+
+ int argc = *argcptr;
+ int i, j;
+
+ j = 1;
+ for ( i=1; i<argc; i++ ) {
+ if ( argv[i] && *argv[i] != '-' ) {
+ argv[j++] = argv[i];
+ continue;
+ }
+ TQCString arg = argv[i];
+ TQCString s;
+ if ( arg == "-qdevel" || arg == "-qdebug") {
+ // obsolete argument
+ } else if ( arg.tqfind( "-style=", 0, FALSE ) != -1 ) {
+ s = arg.right( arg.length() - 7 );
+ } else if ( qstrcmp(arg,"-style") == 0 && i < argc-1 ) {
+ s = argv[++i];
+ s = s.lower();
+#ifndef TQT_NO_SESSIONMANAGER
+ } else if ( qstrcmp(arg,"-session") == 0 && i < argc-1 ) {
+ TQCString s = argv[++i];
+ if ( !s.isEmpty() ) {
+ session_id = TQString::tqfromLatin1( s );
+ int p = session_id.tqfind( '_' );
+ if ( p >= 0 ) {
+ if ( !session_key )
+ session_key = new TQString;
+ *session_key = session_id.mid( p +1 );
+ session_id = session_id.left( p );
+ }
+ is_session_restored = TRUE;
+ }
+#endif
+ } else if ( qstrcmp(arg, "-reverse") == 0 ) {
+ setReverseLayout( TRUE );
+ } else if ( qstrcmp(arg, "-widgetcount") == 0 ) {
+ widgetCount = TRUE;;
+ } else {
+ argv[j++] = argv[i];
+ }
+#ifndef TQT_NO_STYLE
+ if ( !s.isEmpty() ) {
+ setStyle( s );
+ }
+#endif
+ }
+
+ if(j < argc) {
+#ifdef TQ_WS_MACX
+ static char* empty = "\0";
+ argv[j] = empty;
+#else
+ argv[j] = 0;
+#endif
+ *argcptr = j;
+ }
+}
+
+/*!
+ Initializes the window system and constructs an application object
+ with \a argc command line arguments in \a argv.
+
+ The global \c tqApp pointer refers to this application object. Only
+ one application object should be created.
+
+ This application object must be constructed before any \link
+ TQPaintDevice paint tqdevices\endlink (including widgets, pixmaps, bitmaps
+ etc.).
+
+ Note that \a argc and \a argv might be changed. TQt removes command
+ line arguments that it recognizes. The modified \a argc and \a argv
+ can also be accessed later with \c tqApp->argc() and \c tqApp->argv().
+ The documentation for argv() tqcontains a detailed description of how
+ to process command line arguments.
+
+ TQt debugging options (not available if TQt was compiled with the
+ TQT_NO_DEBUG flag defined):
+ \list
+ \i -nograb, tells TQt that it must never grab the mouse or the keyboard.
+ \i -dograb (only under X11), running under a debugger can cause
+ an implicit -nograb, use -dograb to override.
+ \i -sync (only under X11), switches to synchronous mode for
+ debugging.
+ \endlist
+
+ See \link debug.html Debugging Techniques \endlink for a more
+ detailed explanation.
+
+ All TQt programs automatically support the following command line options:
+ \list
+ \i -reverse causes text to be formatted for right-to-left languages
+ rather than in the usual left-to-right direction.
+ \i -style= \e style, sets the application GUI style. Possible values
+ are \c motif, \c windows, and \c platinum. If you compiled TQt
+ with additional styles or have additional styles as plugins these
+ will be available to the \c -style command line option.
+ \i -style \e style, is the same as listed above.
+ \i -session= \e session, restores the application from an earlier
+ \link session.html session \endlink.
+ \i -session \e session, is the same as listed above.
+ \i -widgetcount, prints debug message at the end about number of widgets left
+ undestroyed and maximum number of widgets existed at the same time
+ \endlist
+
+ The X11 version of TQt also supports some traditional X11
+ command line options:
+ \list
+ \i -display \e display, sets the X display (default is $DISPLAY).
+ \i -tqgeometry \e tqgeometry, sets the client tqgeometry of the
+ \link setMainWidget() main widget\endlink.
+ \i -fn or \c -font \e font, defines the application font. The
+ font should be specified using an X logical font description.
+ \i -bg or \c -background \e color, sets the default background color
+ and an application palette (light and dark shades are calculated).
+ \i -fg or \c -foreground \e color, sets the default foreground color.
+ \i -btn or \c -button \e color, sets the default button color.
+ \i -name \e name, sets the application name.
+ \i -title \e title, sets the application title (caption).
+ \i -visual \c TrueColor, forces the application to use a TrueColor visual
+ on an 8-bit display.
+ \i -ncols \e count, limits the number of colors allocated in the
+ color cube on an 8-bit display, if the application is using the
+ \c TQApplication::ManyColor color specification. If \e count is
+ 216 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green,
+ and 6 of blue); for other values, a cube
+ approximately proportional to a 2x3x1 cube is used.
+ \i -cmap, causes the application to install a private color map
+ on an 8-bit display.
+ \endlist
+
+ \sa argc(), argv()
+*/
+
+//######### BINARY COMPATIBILITY constructor
+TQApplication::TQApplication( int &argc, char **argv )
+{
+ construct( argc, argv, GuiClient );
+}
+
+
+/*!
+ Constructs an application object with \a argc command line arguments
+ in \a argv. If \a GUIenabled is TRUE, a GUI application is
+ constructed, otherwise a non-GUI (console) application is created.
+
+ Set \a GUIenabled to FALSE for programs without a graphical user
+ interface that should be able to run without a window system.
+
+ On X11, the window system is initialized if \a GUIenabled is TRUE.
+ If \a GUIenabled is FALSE, the application does not connect to the
+ X-server.
+ On Windows and Macintosh, currently the window system is always
+ initialized, regardless of the value of GUIenabled. This may change in
+ future versions of TQt.
+
+ The following example shows how to create an application that
+ uses a graphical interface when available.
+ \code
+ int main( int argc, char **argv )
+ {
+#ifdef TQ_WS_X11
+ bool useGUI = getenv( "DISPLAY" ) != 0;
+#else
+ bool useGUI = TRUE;
+#endif
+ TQApplication app(argc, argv, useGUI);
+
+ if ( useGUI ) {
+ //start GUI version
+ ...
+ } else {
+ //start non-GUI version
+ ...
+ }
+ return app.exec();
+ }
+\endcode
+*/
+
+TQApplication::TQApplication( int &argc, char **argv, bool GUIenabled )
+{
+ construct( argc, argv, GUIenabled ? GuiClient : Tty );
+}
+
+/*!
+ Constructs an application object with \a argc command line arguments
+ in \a argv.
+
+ For TQt/Embedded, passing \c TQApplication::GuiServer for \a type
+ makes this application the server (equivalent to running with the
+ -qws option).
+*/
+TQApplication::TQApplication( int &argc, char **argv, Type type )
+{
+ construct( argc, argv, type );
+}
+
+TQ_EXPORT void qt_ucm_initialize( TQApplication *theApp )
+{
+ if ( tqApp )
+ return;
+ int argc = theApp->argc();
+ char **argv = theApp->argv();
+ theApp->construct( argc, argv, tqApp->type() );
+
+ TQ_ASSERT( tqApp == theApp );
+}
+
+void TQApplication::construct( int &argc, char **argv, Type type )
+{
+ qt_appType = type;
+ qt_is_gui_used = (type != Tty);
+ init_precmdline();
+ static const char *empty = "";
+ if ( argc == 0 || argv == 0 ) {
+ argc = 0;
+ argv = (char **)&empty; // ouch! careful with TQApplication::argv()!
+ }
+ app_argc = argc;
+ app_argv = argv;
+
+ qt_init( &argc, argv, type ); // Must be called before initialize()
+ process_cmdline( &argc, argv );
+ initialize( argc, argv );
+ if ( qt_is_gui_used )
+ qt_maxWindowRect = desktop()->rect();
+ if ( eventloop )
+ eventloop->appStartingUp();
+}
+
+/*!
+ Returns the type of application, Tty, GuiClient or GuiServer.
+*/
+
+TQApplication::Type TQApplication::type() const
+{
+ return qt_appType;
+}
+
+#if defined(TQ_WS_X11)
+/*!
+ Create an application, given an already open display \a dpy. If \a
+ visual and \a colormap are non-zero, the application will use those as
+ the default Visual and Colormap contexts.
+
+ \warning TQt only supports TrueColor visuals at depths higher than 8
+ bits-per-pixel.
+
+ This is available only on X11.
+*/
+
+TQApplication::TQApplication( Display* dpy, HANDLE visual, HANDLE colormap )
+{
+ static int aargc = 1;
+ // ### a string literal is a cont char*
+ // ### using it as a char* is wrong and could lead to segfaults
+ // ### if aargv is modified someday
+ static char *aargv[] = { (char*)"unknown", 0 };
+
+ app_argc = aargc;
+ app_argv = aargv;
+
+ qt_appType = GuiClient;
+ qt_is_gui_used = TRUE;
+ qt_appType = GuiClient;
+ init_precmdline();
+ // ... no command line.
+
+ if ( ! dpy ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQApplication: invalid Display* argument." );
+#endif // TQT_CHECK_STATE
+
+ qt_init( &aargc, aargv, GuiClient );
+ } else {
+ qt_init( dpy, visual, colormap );
+ }
+
+ initialize( aargc, aargv );
+
+ if ( qt_is_gui_used )
+ qt_maxWindowRect = desktop()->rect();
+ if ( eventloop )
+ eventloop->appStartingUp();
+}
+
+/*!
+ Create an application, given an already open display \a dpy and using
+ \a argc command line arguments in \a argv. If \a
+ visual and \a colormap are non-zero, the application will use those as
+ the default Visual and Colormap contexts.
+
+ \warning TQt only supports TrueColor visuals at depths higher than 8
+ bits-per-pixel.
+
+ This is available only on X11.
+
+*/
+TQApplication::TQApplication(Display *dpy, int argc, char **argv,
+ HANDLE visual, HANDLE colormap)
+{
+ qt_appType = GuiClient;
+ qt_is_gui_used = TRUE;
+ qt_appType = GuiClient;
+ init_precmdline();
+
+ app_argc = argc;
+ app_argv = argv;
+
+ if ( ! dpy ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQApplication: invalid Display* argument." );
+#endif // TQT_CHECK_STATE
+
+ qt_init( &argc, argv, GuiClient );
+ } else {
+ qt_init(dpy, visual, colormap);
+ }
+
+ process_cmdline( &argc, argv );
+ initialize(argc, argv);
+
+ if ( qt_is_gui_used )
+ qt_maxWindowRect = desktop()->rect();
+ if ( eventloop )
+ eventloop->appStartingUp();
+}
+
+
+#endif // TQ_WS_X11
+
+
+void TQApplication::init_precmdline()
+{
+ translators = 0;
+ is_app_closing = FALSE;
+#ifndef TQT_NO_SESSIONMANAGER
+ is_session_restored = FALSE;
+#endif
+#if defined(TQT_CHECK_STATE)
+ if ( tqApp )
+ qWarning( "TQApplication: There should be max one application object" );
+#endif
+ tqApp = (TQApplication*)this;
+}
+
+/*!
+ Initializes the TQApplication object, called from the constructors.
+*/
+
+void TQApplication::initialize( int argc, char **argv )
+{
+#ifdef TQT_THREAD_SUPPORT
+ qt_mutex = new TQMutex( TRUE );
+ postevent_mutex = new TQMutex( TRUE );
+ qt_application_thread_id = TQThread::currentThread();
+#endif // TQT_THREAD_SUPPORT
+
+ app_argc = argc;
+ app_argv = argv;
+ quit_now = FALSE;
+ quit_code = 0;
+ TQWidget::createMapper(); // create widget mapper
+#ifndef TQT_NO_PALETTE
+ (void) palette(); // trigger creation of application palette
+#endif
+ is_app_running = TRUE; // no longer starting up
+
+#ifndef TQT_NO_SESSIONMANAGER
+ // connect to the session manager
+ if ( !session_key )
+ session_key = new TQString;
+ session_manager = new TQSessionManager( tqApp, session_id, *session_key );
+#endif
+
+}
+
+
+/*****************************************************************************
+ Functions returning the active popup and modal widgets.
+ *****************************************************************************/
+
+/*!
+ Returns the active popup widget.
+
+ A popup widget is a special top level widget that sets the \c
+ WType_Popup widget flag, e.g. the TQPopupMenu widget. When the
+ application opens a popup widget, all events are sent to the popup.
+ Normal widgets and modal widgets cannot be accessed before the popup
+ widget is closed.
+
+ Only other popup widgets may be opened when a popup widget is shown.
+ The popup widgets are organized in a stack. This function returns
+ the active popup widget at the top of the stack.
+
+ \sa activeModalWidget(), tqtopLevelWidgets()
+*/
+
+TQWidget *TQApplication::activePopupWidget()
+{
+ return popupWidgets ? popupWidgets->getLast() : 0;
+}
+
+
+/*!
+ Returns the active modal widget.
+
+ A modal widget is a special top level widget which is a subclass of
+ TQDialog that specifies the modal parameter of the constructor as
+ TRUE. A modal widget must be closed before the user can continue
+ with other parts of the program.
+
+ Modal widgets are organized in a stack. This function returns
+ the active modal widget at the top of the stack.
+
+ \sa activePopupWidget(), tqtopLevelWidgets()
+*/
+
+TQWidget *TQApplication::activeModalWidget()
+{
+ return qt_modal_stack ? qt_modal_stack->getFirst() : 0;
+}
+
+/*!
+ Cleans up any window system resources that were allocated by this
+ application. Sets the global variable \c tqApp to 0.
+*/
+
+TQApplication::~TQApplication()
+{
+#ifndef TQT_NO_CLIPBOARD
+ // flush clipboard contents
+ if ( qt_clipboard ) {
+ TQCustomEvent event( TQEvent::Clipboard );
+ TQApplication::sendEvent( qt_clipboard, &event );
+ }
+#endif
+
+ if ( eventloop )
+ eventloop->appClosingDown();
+ if ( postRList ) {
+ TQVFuncList::Iterator it = postRList->begin();
+ while ( it != postRList->end() ) { // call post routines
+ (**it)();
+ postRList->remove( it );
+ it = postRList->begin();
+ }
+ delete postRList;
+ postRList = 0;
+ }
+
+ TQObject *tipmanager = child( "toolTipManager", "TQTipManager", FALSE );
+ delete tipmanager;
+
+ delete qt_desktopWidget;
+ qt_desktopWidget = 0;
+ is_app_closing = TRUE;
+
+#ifndef TQT_NO_CLIPBOARD
+ delete qt_clipboard;
+ qt_clipboard = 0;
+#endif
+ TQWidget::destroyMapper();
+#ifndef TQT_NO_PALETTE
+ delete qt_std_pal;
+ qt_std_pal = 0;
+ delete app_pal;
+ app_pal = 0;
+ delete app_palettes;
+ app_palettes = 0;
+#endif
+ delete app_font;
+ app_font = 0;
+ delete app_fonts;
+ app_fonts = 0;
+#ifndef TQT_NO_STYLE
+ delete app_style;
+ app_style = 0;
+#endif
+#ifndef TQT_NO_CURSOR
+ delete app_cursor;
+ app_cursor = 0;
+#endif
+#ifndef TQT_NO_TRANSLATION
+ delete translators;
+#endif
+
+#ifndef TQT_NO_DRAGANDDROP
+ extern TQDragManager *qt_dnd_manager;
+ delete qt_dnd_manager;
+#endif
+
+ qt_cleanup();
+
+#ifndef TQT_NO_COMPONENT
+ delete app_libpaths;
+ app_libpaths = 0;
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+ delete qt_mutex;
+ qt_mutex = 0;
+ delete postevent_mutex;
+ postevent_mutex = 0;
+#endif // TQT_THREAD_SUPPORT
+
+ if( tqApp == this ) {
+ if ( postedEvents )
+ removePostedEvents( this );
+ tqApp = 0;
+ }
+ is_app_running = FALSE;
+
+ if ( widgetCount ) {
+ qDebug( "Widgets left: %i Max widgets: %i \n", TQWidget::instanceCounter, TQWidget::maxInstances );
+ }
+#ifndef TQT_NO_SESSIONMANAGER
+ delete session_manager;
+ session_manager = 0;
+ delete session_key;
+ session_key = 0;
+#endif //TQT_NO_SESSIONMANAGER
+
+ qt_explicit_app_style = FALSE;
+ qt_app_has_font = FALSE;
+ app_tracking = 0;
+ obey_desktop_settings = TRUE;
+ cursor_flash_time = 1000;
+ mouse_double_click_time = 400;
+#ifndef TQT_NO_WHEELEVENT
+ wheel_scroll_lines = 3;
+#endif
+ drag_time = 500;
+ drag_distance = 4;
+ reverse_tqlayout = FALSE;
+ app_strut = TQSize( 0, 0 );
+ animate_ui = TRUE;
+ animate_menu = FALSE;
+ fade_menu = FALSE;
+ animate_combo = FALSE;
+ animate_tooltip = FALSE;
+ fade_tooltip = FALSE;
+ widgetCount = FALSE;
+}
+
+
+/*!
+ \fn int TQApplication::argc() const
+
+ Returns the number of command line arguments.
+
+ The documentation for argv() describes how to process command line
+ arguments.
+
+ \sa argv(), TQApplication::TQApplication()
+*/
+
+/*!
+ \fn char **TQApplication::argv() const
+
+ Returns the command line argument vector.
+
+ \c argv()[0] is the program name, \c argv()[1] is the first
+ argument and \c argv()[argc()-1] is the last argument.
+
+ A TQApplication object is constructed by passing \e argc and \e
+ argv from the \c main() function. Some of the arguments may be
+ recognized as TQt options and removed from the argument vector. For
+ example, the X11 version of TQt knows about \c -display, \c -font
+ and a few more options.
+
+ Example:
+ \code
+ // showargs.cpp - displays program arguments in a list box
+
+ #include <tqapplication.h>
+ #include <tqlistbox.h>
+
+ int main( int argc, char **argv )
+ {
+ TQApplication a( argc, argv );
+ TQListBox b;
+ a.setMainWidget( &b );
+ for ( int i = 0; i < a.argc(); i++ ) // a.argc() == argc
+ b.insertItem( a.argv()[i] ); // a.argv()[i] == argv[i]
+ b.show();
+ return a.exec();
+ }
+ \endcode
+
+ If you run \c{showargs -display unix:0 -font 9x15bold hello world}
+ under X11, the list box tqcontains the three strings "showargs",
+ "hello" and "world".
+
+ TQt provides a global pointer, \c tqApp, that points to the
+ TQApplication object, and through which you can access argc() and
+ argv() in functions other than main().
+
+ \sa argc(), TQApplication::TQApplication()
+*/
+
+/*!
+ \fn void TQApplication::setArgs( int argc, char **argv )
+ \internal
+*/
+
+
+#ifndef TQT_NO_STYLE
+
+static TQString *qt_style_override = 0;
+
+/*!
+ Returns the application's style object.
+
+ \sa setStyle(), TQStyle
+*/
+TQStyle& TQApplication::tqstyle()
+{
+#ifndef TQT_NO_STYLE
+ if ( app_style )
+ return *app_style;
+ if ( !qt_is_gui_used )
+ qFatal( "No style available in non-gui applications!" );
+
+#if defined(TQ_WS_X11)
+ if(!qt_style_override)
+ x11_initialize_style(); // run-time search for default style
+#endif
+ if ( !app_style ) {
+ // Compile-time search for default style
+ //
+ TQString style;
+ if ( qt_style_override ) {
+ style = *qt_style_override;
+ delete qt_style_override;
+ qt_style_override = 0;
+ } else {
+# if defined(TQ_WS_WIN) && defined(TQ_OS_TEMP)
+ style = "PocketPC";
+#elif defined(TQ_WS_WIN)
+ if ( qWinVersion() >= TQt::WV_XP && qWinVersion() < TQt::WV_NT_based )
+ style = "WindowsXP";
+ else
+ style = "Windows"; // default styles for Windows
+#elif defined(TQ_WS_X11) && defined(TQ_OS_SOLARIS)
+ style = "CDE"; // default style for X11 on Solaris
+#elif defined(TQ_WS_X11) && defined(TQ_OS_IRIX)
+ style = "SGI"; // default style for X11 on IRIX
+#elif defined(TQ_WS_X11)
+ style = "Motif"; // default style for X11
+#elif defined(TQ_WS_MAC)
+ style = "Macintosh"; // default style for all Mac's
+#elif defined(TQ_WS_TQWS)
+ style = "Compact"; // default style for small tqdevices
+#endif
+ }
+ app_style = TQStyleFactory::create( style );
+ if ( !app_style && // platform default style not available, try alternatives
+ !(app_style = TQStyleFactory::create( "Windows" ) ) &&
+ !(app_style = TQStyleFactory::create( "Platinum" ) ) &&
+ !(app_style = TQStyleFactory::create( "MotifPlus" ) ) &&
+ !(app_style = TQStyleFactory::create( "Motif" ) ) &&
+ !(app_style = TQStyleFactory::create( "CDE" ) ) &&
+ !(app_style = TQStyleFactory::create( "Aqua" ) ) &&
+ !(app_style = TQStyleFactory::create( "SGI" ) ) &&
+ !(app_style = TQStyleFactory::create( "Compact" ) )
+#ifndef TQT_NO_STRINGLIST
+ && !(app_style = TQStyleFactory::create( TQStyleFactory::keys()[0] ) )
+#endif
+ )
+ qFatal( "No %s style available!", style.latin1() );
+ }
+
+ TQPalette app_pal_copy ( *app_pal );
+ app_style->polish( *app_pal );
+
+ if ( is_app_running && !is_app_closing && (*app_pal != app_pal_copy) ) {
+ TQEvent e( TQEvent::ApplicationPaletteChange );
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ sendEvent( w, &e );
+ }
+ }
+
+ app_style->polish( tqApp );
+#endif
+ return *app_style;
+}
+
+/*!
+ Sets the application's GUI style to \a style. Ownership of the style
+ object is transferred to TQApplication, so TQApplication will delete
+ the style object on application exit or when a new style is set.
+
+ Example usage:
+ \code
+ TQApplication::setStyle( new TQWindowsStyle );
+ \endcode
+
+ When switching application styles, the color palette is set back to
+ the initial colors or the system defaults. This is necessary since
+ certain styles have to adapt the color palette to be fully
+ style-guide compliant.
+
+ \sa style(), TQStyle, setPalette(), desktopSettingsAware()
+*/
+void TQApplication::setStyle( TQStyle *style )
+{
+ TQStyle* old = app_style;
+ app_style = style;
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ delete old;
+ return;
+ }
+
+ // clean up the old style
+ if (old) {
+ if ( is_app_running && !is_app_closing ) {
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( !w->testWFlags(WType_Desktop) && // except desktop
+ w->testWState(WState_Polished) ) { // has been polished
+ old->unPolish(w);
+ }
+ }
+ }
+ old->unPolish( tqApp );
+ }
+
+ // take care of possible palette requirements of certain gui
+ // styles. Do it before polishing the application since the style
+ // might call TQApplication::setStyle() itself
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+ TQPalette tmpPal = *qt_std_pal;
+ setPalette( tmpPal, TRUE );
+
+ // initialize the application with the new style
+ app_style->polish( tqApp );
+
+ // re-polish existing widgets if necessary
+ if (old) {
+ if ( is_app_running && !is_app_closing ) {
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( !w->testWFlags(WType_Desktop) ) { // except desktop
+ if ( w->testWState(WState_Polished) )
+ app_style->polish(w); // repolish
+ w->styleChange( *old );
+ if ( w->isVisible() ){
+ w->update();
+ }
+ }
+ }
+ }
+ delete old;
+ }
+}
+
+/*!
+ \overload
+
+ Requests a TQStyle object for \a style from the TQStyleFactory.
+
+ The string must be one of the TQStyleFactory::keys(), typically one
+ of "windows", "motif", "cde", "motifplus", "platinum", "sgi" and
+ "compact". Depending on the platform, "windowsxp", "aqua" or
+ "macintosh" may be available.
+
+ A later call to the TQApplication constructor will override the
+ requested style when a "-style" option is passed in as a commandline
+ parameter.
+
+ Returns 0 if an unknown \a style is passed, otherwise the TQStyle object
+ returned is set as the application's GUI style.
+*/
+TQStyle* TQApplication::setStyle( const TQString& style )
+{
+#ifdef TQ_WS_X11
+ qt_explicit_app_style = TRUE;
+#endif // TQ_WS_X11
+
+ if ( startingUp() ) {
+ if(qt_style_override)
+ *qt_style_override = style;
+ else
+ qt_style_override = new TQString(style);
+ return 0;
+ }
+ TQStyle *s = TQStyleFactory::create( style );
+ if ( !s )
+ return 0;
+
+ setStyle( s );
+ return s;
+}
+
+#endif
+
+
+#if 1 /* OBSOLETE */
+
+TQApplication::ColorMode TQApplication::colorMode()
+{
+ return (TQApplication::ColorMode)app_cspec;
+}
+
+void TQApplication::setColorMode( TQApplication::ColorMode mode )
+{
+ app_cspec = mode;
+}
+#endif
+
+
+/*!
+ Returns the color specification.
+ \sa TQApplication::setColorSpec()
+ */
+
+int TQApplication::colorSpec()
+{
+ return app_cspec;
+}
+
+/*!
+ Sets the color specification for the application to \a spec.
+
+ The color specification controls how the application allocates colors
+ when run on a display with a limited amount of colors, e.g. 8 bit / 256
+ color displays.
+
+ The color specification must be set before you create the TQApplication
+ object.
+
+ The options are:
+ \list
+ \i TQApplication::NormalColor.
+ This is the default color allocation strategy. Use this option if
+ your application uses buttons, menus, texts and pixmaps with few
+ colors. With this option, the application uses system global
+ colors. This works fine for most applications under X11, but on
+ Windows machines it may cause dithering of non-standard colors.
+ \i TQApplication::CustomColor.
+ Use this option if your application needs a small number of custom
+ colors. On X11, this option is the same as NormalColor. On Windows, TQt
+ creates a Windows palette, and allocates colors to it on demand.
+ \i TQApplication::ManyColor.
+ Use this option if your application is very color hungry
+ (e.g. it requires thousands of colors).
+ Under X11 the effect is:
+ \list
+ \i For 256-color displays which have at best a 256 color true color
+ visual, the default visual is used, and colors are allocated
+ from a color cube. The color cube is the 6x6x6 (216 color) "Web
+ palette"<sup>*</sup>, but the number of colors can be changed
+ by the \e -ncols option. The user can force the application to
+ use the true color visual with the \link
+ TQApplication::TQApplication() -visual \endlink option.
+ \i For 256-color displays which have a true color visual with more
+ than 256 colors, use that visual. Silicon Graphics X servers
+ have this feature, for example. They provide an 8 bit visual
+ by default but can deliver true color when asked.
+ \endlist
+ On Windows, TQt creates a Windows palette, and fills it with a color cube.
+ \endlist
+
+ Be aware that the CustomColor and ManyColor choices may lead to colormap
+ flashing: The foreground application gets (most) of the available
+ colors, while the background windows will look less attractive.
+
+ Example:
+ \code
+ int main( int argc, char **argv )
+ {
+ TQApplication::setColorSpec( TQApplication::ManyColor );
+ TQApplication a( argc, argv );
+ ...
+ }
+ \endcode
+
+ TQColor provides more functionality for controlling color allocation and
+ freeing up certain colors. See TQColor::enterAllocContext() for more
+ information.
+
+ To check what mode you end up with, call TQColor::numBitPlanes() once
+ the TQApplication object exists. A value greater than 8 (typically
+ 16, 24 or 32) means true color.
+
+ <sup>*</sup> The color cube used by TQt has 216 colors whose red,
+ green, and blue components always have one of the following values:
+ 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF.
+
+ \sa colorSpec(), TQColor::numBitPlanes(), TQColor::enterAllocContext() */
+
+void TQApplication::setColorSpec( int spec )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( tqApp ) {
+ qWarning( "TQApplication::setColorSpec: This function must be "
+ "called before the TQApplication object is created" );
+ }
+#endif
+ app_cspec = spec;
+}
+
+/*!
+ \fn TQSize TQApplication::globalStrut()
+
+ Returns the application's global strut.
+
+ The strut is a size object whose dimensions are the minimum that any
+ GUI element that the user can interact with should have. For example
+ no button should be resized to be smaller than the global strut size.
+
+ \sa setGlobalStrut()
+*/
+
+/*!
+ Sets the application's global strut to \a strut.
+
+ The strut is a size object whose dimensions are the minimum that any
+ GUI element that the user can interact with should have. For example
+ no button should be resized to be smaller than the global strut size.
+
+ The strut size should be considered when reimplementing GUI controls
+ that may be used on touch-screens or similar IO-tqdevices.
+
+ Example:
+ \code
+ TQSize& WidgetClass::tqsizeHint() const
+ {
+ return TQSize( 80, 25 ).expandedTo( TQApplication::globalStrut() );
+ }
+ \endcode
+
+ \sa globalStrut()
+*/
+
+void TQApplication::setGlobalStrut( const TQSize& strut )
+{
+ app_strut = strut;
+}
+
+#if defined( TQ_WS_WIN ) || defined( TQ_WS_MAC )
+extern const char *tqAppFileName();
+#endif
+
+#ifndef TQT_NO_DIR
+#ifndef TQ_WS_WIN
+static TQString resolveSymlinks( const TQString& path, int depth = 0 )
+{
+ bool foundLink = FALSE;
+ TQString linkTarget;
+ TQString part = path;
+ int slashPos = path.length();
+
+ // too deep; we give up
+ if ( depth == 128 )
+ return TQString::null;
+
+ do {
+ part = part.left( slashPos );
+ TQFileInfo fileInfo( part );
+ if ( fileInfo.isSymLink() ) {
+ foundLink = TRUE;
+ linkTarget = fileInfo.readLink();
+ break;
+ }
+ } while ( (slashPos = part.tqfindRev('/')) != -1 );
+
+ if ( foundLink ) {
+ TQString path2;
+ if ( linkTarget[0] == '/' ) {
+ path2 = linkTarget;
+ if ( slashPos < (int) path.length() )
+ path2 += "/" + path.right( path.length() - slashPos - 1 );
+ } else {
+ TQString relPath;
+ relPath = part.left( part.tqfindRev('/') + 1 ) + linkTarget;
+ if ( slashPos < (int) path.length() ) {
+ if ( !linkTarget.endsWith( "/" ) )
+ relPath += "/";
+ relPath += path.right( path.length() - slashPos - 1 );
+ }
+ path2 = TQDir::current().absFilePath( relPath );
+ }
+ path2 = TQDir::cleanDirPath( path2 );
+ return resolveSymlinks( path2, depth + 1 );
+ } else {
+ return path;
+ }
+}
+#endif // TQ_WS_WIN
+
+/*!
+ Returns the directory that tqcontains the application executable.
+
+ For example, if you have installed TQt in the \c{C:\Trolltech\TQt}
+ directory, and you run the \c{demo} example, this function will
+ return "C:/Trolltech/TQt/examples/demo".
+
+ On Mac OS X this will point to the directory actually containing the
+ executable, which may be inside of an application bundle (if the
+ application is bundled).
+
+ \warning On Unix, this function assumes that argv[0] tqcontains the file
+ name of the executable (which it normally does). It also assumes that
+ the current directory hasn't been changed by the application.
+
+ \sa applicationFilePath()
+*/
+TQString TQApplication::applicationDirPath()
+{
+ return TQFileInfo( applicationFilePath() ).dirPath();
+}
+
+/*!
+ Returns the file path of the application executable.
+
+ For example, if you have installed TQt in the \c{C:\Trolltech\TQt}
+ directory, and you run the \c{demo} example, this function will
+ return "C:/Trolltech/TQt/examples/demo/demo.exe".
+
+ \warning On Unix, this function assumes that argv[0] tqcontains the file
+ name of the executable (which it normally does). It also assumes that
+ the current directory hasn't been changed by the application.
+
+ \sa applicationDirPath()
+*/
+TQString TQApplication::applicationFilePath()
+{
+#if defined( TQ_WS_WIN )
+ TQFileInfo filePath;
+ TQT_WA({
+ WCHAR module_name[256];
+ GetModuleFileNameW(0, module_name, sizeof(module_name));
+ filePath = TQString::fromUcs2((const unsigned short *)module_name);
+ }, {
+ char module_name[256];
+ GetModuleFileNameA(0, module_name, sizeof(module_name));
+ filePath = TQString::fromLocal8Bit(module_name);
+ });
+
+ return filePath.filePath();
+#elif defined( TQ_WS_MAC )
+ return TQDir::cleanDirPath( TQFile::decodeName( tqAppFileName() ) );
+#else
+ TQString argv0 = TQFile::decodeName( argv()[0] );
+ TQString absPath;
+
+ if ( argv0[0] == '/' ) {
+ /*
+ If argv0 starts with a slash, it is already an absolute
+ file path.
+ */
+ absPath = argv0;
+ } else if ( argv0.tqfind('/') != -1 ) {
+ /*
+ If argv0 tqcontains one or more slashes, it is a file path
+ relative to the current directory.
+ */
+ absPath = TQDir::current().absFilePath( argv0 );
+ } else {
+ /*
+ Otherwise, the file path has to be determined using the
+ PATH environment variable.
+ */
+ char *pEnv = getenv( "PATH" );
+ TQStringList paths( TQStringList::split(TQChar(':'), pEnv) );
+ TQStringList::const_iterator p = paths.begin();
+ while ( p != paths.end() ) {
+ TQString candidate = TQDir::current().absFilePath( *p + "/" + argv0 );
+ if ( TQFile::exists(candidate) ) {
+ absPath = candidate;
+ break;
+ }
+ ++p;
+ }
+ }
+
+ absPath = TQDir::cleanDirPath( absPath );
+ if ( TQFile::exists(absPath) ) {
+ return resolveSymlinks( absPath );
+ } else {
+ return TQString::null;
+ }
+#endif
+}
+#endif // TQT_NO_DIR
+
+#ifndef TQT_NO_COMPONENT
+
+/*!
+ Returns a list of paths that the application will search when
+ dynamically loading libraries.
+ The installation directory for plugins is the only entry if no
+ paths have been set. The default installation directory for plugins
+ is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was
+ installed. The directory of the application executable (NOT the
+ working directory) is also added to the plugin paths.
+
+ If you want to iterate over the list, you should iterate over a
+ copy, e.g.
+ \code
+ TQStringList list = app.libraryPaths();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ See the \link plugins-howto.html plugins documentation\endlink for a
+ description of how the library paths are used.
+
+ \sa tqsetLibraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary
+*/
+TQStringList TQApplication::libraryPaths()
+{
+ if ( !app_libpaths ) {
+ app_libpaths = new TQStringList;
+ TQString installPathPlugins = TQString::fromLocal8Bit(qInstallPathPlugins());
+ if ( TQFile::exists(installPathPlugins) ) {
+#ifdef TQ_WS_WIN
+ installPathPlugins.tqreplace('\\', '/');
+#endif
+ app_libpaths->append(installPathPlugins);
+ }
+
+ TQString app_location;
+ if (tqApp)
+ app_location = tqApp->applicationFilePath();
+#ifdef TQ_WS_WIN
+ else {
+ app_location = TQString(tqAppFileName());
+ app_location.tqreplace('\\', '/');
+ }
+#endif
+ if (!app_location.isEmpty()) {
+ app_location.truncate( app_location.tqfindRev( '/' ) );
+ if ( app_location != qInstallPathPlugins() && TQFile::exists( app_location ) )
+ app_libpaths->append( app_location );
+ }
+ }
+ return *app_libpaths;
+}
+
+
+/*!
+ Sets the list of directories to search when loading libraries to \a paths.
+ All existing paths will be deleted and the path list will consist of the
+ paths given in \a paths.
+
+ \sa libraryPaths(), addLibraryPath(), removeLibraryPath(), TQLibrary
+ */
+void TQApplication::tqsetLibraryPaths( const TQStringList &paths )
+{
+ delete app_libpaths;
+ app_libpaths = new TQStringList( paths );
+}
+
+/*!
+ Append \a path to the end of the library path list. If \a path is
+ empty or already in the path list, the path list is not changed.
+
+ The default path list consists of a single entry, the installation
+ directory for plugins. The default installation directory for plugins
+ is \c INSTALL/plugins, where \c INSTALL is the directory where TQt was
+ installed.
+
+ \sa removeLibraryPath(), libraryPaths(), tqsetLibraryPaths()
+ */
+void TQApplication::addLibraryPath( const TQString &path )
+{
+ if ( path.isEmpty() )
+ return;
+
+ // make sure that library paths is initialized
+ libraryPaths();
+
+ if ( !app_libpaths->tqcontains( path ) )
+ app_libpaths->prepend( path );
+}
+
+/*!
+ Removes \a path from the library path list. If \a path is empty or not
+ in the path list, the list is not changed.
+
+ \sa addLibraryPath(), libraryPaths(), tqsetLibraryPaths()
+*/
+void TQApplication::removeLibraryPath( const TQString &path )
+{
+ if ( path.isEmpty() )
+ return;
+
+ // make sure that library paths is initialized
+ libraryPaths();
+
+ if ( app_libpaths->tqcontains( path ) )
+ app_libpaths->remove( path );
+}
+#endif //TQT_NO_COMPONENT
+
+/*!
+ Returns the application palette.
+
+ If a widget is passed in \a w, the default palette for the
+ widget's class is returned. This may or may not be the application
+ palette. In most cases there isn't a special palette for certain
+ types of widgets, but one notable exception is the popup menu under
+ Windows, if the user has defined a special background color for
+ menus in the display settings.
+
+ \sa setPalette(), TQWidget::palette()
+*/
+#ifndef TQT_NO_PALETTE
+TQPalette TQApplication::palette(const TQWidget* w)
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !tqApp )
+ qWarning( "TQApplication::palette: This function can only be "
+ "called after the TQApplication object has been created" );
+#endif
+ if ( !app_pal ) {
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+ app_pal = new TQPalette( *qt_std_pal );
+ qt_fix_tooltips();
+ }
+
+ if ( w && app_palettes ) {
+ TQPalette* wp = app_palettes->tqfind( w->className() );
+ if ( wp )
+ return *wp;
+ TQAsciiDictIterator<TQPalette> it( *app_palettes );
+ const char* name;
+ while ( (name=it.currentKey()) != 0 ) {
+ if ( w->inherits( name ) )
+ return *it.current();
+ ++it;
+ }
+ }
+ return *app_pal;
+}
+
+/*!
+ Changes the default application palette to \a palette. If \a
+ informWidgets is TRUE, then existing widgets are informed about the
+ change and may adjust themselves to the new application
+ setting. If \a informWidgets is FALSE, the change only affects newly
+ created widgets.
+
+ If \a className is passed, the change applies only to widgets that
+ inherit \a className (as reported by TQObject::inherits()). If
+ \a className is left 0, the change affects all widgets, thus overriding
+ any previously set class specific palettes.
+
+ The palette may be changed according to the current GUI style in
+ TQStyle::polish().
+
+ \sa TQWidget::setPalette(), palette(), TQStyle::polish()
+*/
+
+void TQApplication::setPalette( const TQPalette &palette, bool informWidgets,
+ const char* className )
+{
+ TQPalette pal = palette;
+ TQPalette *oldpal = 0;
+#ifndef TQT_NO_STYLE
+ if ( !startingUp() ) // on startup this has been done already
+ tqApp->style().polish( pal ); // NB: non-const reference
+#endif
+ bool all = FALSE;
+ if ( !className ) {
+ if ( !app_pal ) {
+ app_pal = new TQPalette( pal );
+ TQ_CHECK_PTR( app_pal );
+ } else {
+ *app_pal = pal;
+ }
+ all = app_palettes != 0;
+ delete app_palettes;
+ app_palettes = 0;
+ qt_fix_tooltips();
+ } else {
+ if ( !app_palettes ) {
+ app_palettes = new TQAsciiDict<TQPalette>;
+ TQ_CHECK_PTR( app_palettes );
+ app_palettes->setAutoDelete( TRUE );
+ }
+ oldpal = app_palettes->tqfind( className );
+ app_palettes->insert( className, new TQPalette( pal ) );
+ }
+ if ( informWidgets && is_app_running && !is_app_closing ) {
+ if ( !oldpal || ( *oldpal != pal ) ) {
+ TQEvent e( TQEvent::ApplicationPaletteChange );
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class
+ sendEvent( w, &e );
+ }
+ }
+ }
+}
+
+#endif // TQT_NO_PALETTE
+
+/*!
+ Returns the default font for the widget \a w, or the default
+ application font if \a w is 0.
+
+ \sa setFont(), fontMetrics(), TQWidget::font()
+*/
+
+TQFont TQApplication::font( const TQWidget *w )
+{
+ if ( w && app_fonts ) {
+ TQFont* wf = app_fonts->tqfind( w->className() );
+ if ( wf )
+ return *wf;
+ TQAsciiDictIterator<TQFont> it( *app_fonts );
+ const char* name;
+ while ( (name=it.currentKey()) != 0 ) {
+ if ( w->inherits( name ) )
+ return *it.current();
+ ++it;
+ }
+ }
+ if ( !app_font ) {
+ app_font = new TQFont( "Helvetica" );
+ TQ_CHECK_PTR( app_font );
+ }
+ return *app_font;
+}
+
+/*! Changes the default application font to \a font. If \a
+ informWidgets is TRUE, then existing widgets are informed about the
+ change and may adjust themselves to the new application
+ setting. If \a informWidgets is FALSE, the change only affects newly
+ created widgets. If \a className is passed, the change applies only
+ to classes that inherit \a className (as reported by
+ TQObject::inherits()).
+
+ On application start-up, the default font depends on the window
+ system. It can vary depending on both the window system version and
+ the locale. This function lets you override the default font; but
+ overriding may be a bad idea because, for example, some locales need
+ extra-large fonts to support their special characters.
+
+ \sa font(), fontMetrics(), TQWidget::setFont()
+*/
+
+void TQApplication::setFont( const TQFont &font, bool informWidgets,
+ const char* className )
+{
+ bool all = FALSE;
+ if ( !className ) {
+ qt_app_has_font = TRUE;
+ if ( !app_font ) {
+ app_font = new TQFont( font );
+ TQ_CHECK_PTR( app_font );
+ } else {
+ *app_font = font;
+ }
+
+ // make sure the application font is complete
+ app_font->detach();
+ app_font->d->tqmask = TQFontPrivate::Complete;
+
+ all = app_fonts != 0;
+ delete app_fonts;
+ app_fonts = 0;
+ } else {
+ if (!app_fonts){
+ app_fonts = new TQAsciiDict<TQFont>;
+ TQ_CHECK_PTR( app_fonts );
+ app_fonts->setAutoDelete( TRUE );
+ }
+ TQFont* fnt = new TQFont(font);
+ TQ_CHECK_PTR( fnt );
+ app_fonts->insert(className, fnt);
+ }
+ if ( informWidgets && is_app_running && !is_app_closing ) {
+ TQEvent e( TQEvent::ApplicationFontChange );
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets...
+ ++it;
+ if ( all || (!className && w->isTopLevel() ) || w->inherits(className) ) // matching class
+ sendEvent( w, &e );
+ }
+ }
+}
+
+
+/*!
+ Initialization of the appearance of the widget \a w \e before it is first
+ shown.
+
+ Usually widgets call this automatically when they are polished. It
+ may be used to do some style-based central customization of widgets.
+
+ Note that you are not limited to the public functions of TQWidget.
+ Instead, based on meta information like TQObject::className() you are
+ able to customize any kind of widget.
+
+ \sa TQStyle::polish(), TQWidget::polish(), setPalette(), setFont()
+*/
+
+void TQApplication::polish( TQWidget *w )
+{
+#ifndef TQT_NO_STYLE
+ w->style().polish( w );
+#endif
+}
+
+
+/*!
+ Returns a list of the top level widgets in the application.
+
+ The list is created using \c new and must be deleted by the caller.
+
+ The list is empty (TQPtrList::isEmpty()) if there are no top level
+ widgets.
+
+ Note that some of the top level widgets may be hidden, for example
+ the tooltip if no tooltip is currently shown.
+
+ Example:
+ \code
+ // Show all hidden top level widgets.
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ TQWidgetListIt it( *list ); // iterate over the widgets
+ TQWidget * w;
+ while ( (w=it.current()) != 0 ) { // for each top level widget...
+ ++it;
+ if ( !w->isVisible() )
+ w->show();
+ }
+ delete list; // delete the list, not the widgets
+ \endcode
+
+ \warning Delete the list as soon you have finished using it.
+ The widgets in the list may be deleted by someone else at any time.
+
+ \sa allWidgets(), TQWidget::isTopLevel(), TQWidget::isVisible(),
+ TQPtrList::isEmpty()
+*/
+
+TQWidgetList *TQApplication::tqtopLevelWidgets()
+{
+ return TQWidget::tlwList();
+}
+
+/*!
+ Returns a list of all the widgets in the application.
+
+ The list is created using \c new and must be deleted by the caller.
+
+ The list is empty (TQPtrList::isEmpty()) if there are no widgets.
+
+ Note that some of the widgets may be hidden.
+
+ Example that updates all widgets:
+ \code
+ TQWidgetList *list = TQApplication::allWidgets();
+ TQWidgetListIt it( *list ); // iterate over the widgets
+ TQWidget * w;
+ while ( (w=it.current()) != 0 ) { // for each widget...
+ ++it;
+ w->update();
+ }
+ delete list; // delete the list, not the widgets
+ \endcode
+
+ The TQWidgetList class is defined in the \c tqwidgetlist.h header
+ file.
+
+ \warning Delete the list as soon as you have finished using it.
+ The widgets in the list may be deleted by someone else at any time.
+
+ \sa tqtopLevelWidgets(), TQWidget::isVisible(), TQPtrList::isEmpty(),
+*/
+
+TQWidgetList *TQApplication::allWidgets()
+{
+ return TQWidget::wList();
+}
+
+/*!
+ \fn TQWidget *TQApplication::tqfocusWidget() const
+
+ Returns the application widget that has the keyboard input focus, or
+ 0 if no widget in this application has the focus.
+
+ \sa TQWidget::setFocus(), TQWidget::hasFocus(), activeWindow()
+*/
+
+/*!
+ \fn TQWidget *TQApplication::activeWindow() const
+
+ Returns the application top-level window that has the keyboard input
+ focus, or 0 if no application window has the focus. Note that
+ there might be an activeWindow() even if there is no tqfocusWidget(),
+ for example if no widget in that window accepts key events.
+
+ \sa TQWidget::setFocus(), TQWidget::hasFocus(), tqfocusWidget()
+*/
+
+/*!
+ Returns display (screen) font metrics for the application font.
+
+ \sa font(), setFont(), TQWidget::fontMetrics(), TQPainter::fontMetrics()
+*/
+
+TQFontMetrics TQApplication::fontMetrics()
+{
+ return desktop()->fontMetrics();
+}
+
+
+
+/*!
+ Tells the application to exit with return code 0 (success).
+ Equivalent to calling TQApplication::exit( 0 ).
+
+ It's common to connect the lastWindowClosed() signal to quit(), and
+ you also often connect e.g. TQButton::clicked() or Q_SIGNALS in
+ TQAction, TQPopupMenu or TQMenuBar to it.
+
+ Example:
+ \code
+ TQPushButton *quitButton = new TQPushButton( "Quit" );
+ connect( quitButton, TQT_SIGNAL(clicked()), tqApp, TQT_SLOT(quit()) );
+ \endcode
+
+ \sa exit() aboutToQuit() lastWindowClosed() TQAction
+*/
+
+void TQApplication::quit()
+{
+ TQApplication::exit( 0 );
+}
+
+
+/*!
+ Closes all top-level windows.
+
+ This function is particularly useful for applications with many
+ top-level windows. It could, for example, be connected to a "Quit"
+ entry in the file menu as shown in the following code example:
+
+ \code
+ // the "Quit" menu entry should try to close all windows
+ TQPopupMenu* file = new TQPopupMenu( this );
+ file->insertItem( "&Quit", tqApp, TQT_SLOT(closeAllWindows()), CTRL+Key_Q );
+
+ // when the last window is closed, the application should quit
+ connect( tqApp, TQT_SIGNAL( lastWindowClosed() ), tqApp, TQT_SLOT( quit() ) );
+ \endcode
+
+ The windows are closed in random order, until one window does not
+ accept the close event.
+
+ \sa TQWidget::close(), TQWidget::closeEvent(), lastWindowClosed(),
+ quit(), tqtopLevelWidgets(), TQWidget::isTopLevel()
+
+ */
+void TQApplication::closeAllWindows()
+{
+ bool did_close = TRUE;
+ TQWidget *w;
+ while((w = activeModalWidget()) && did_close) {
+ if(w->isHidden())
+ break;
+ did_close = w->close();
+ }
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ for ( w = list->first(); did_close && w; ) {
+ if ( !w->isHidden() ) {
+ did_close = w->close();
+ delete list;
+ list = TQApplication::tqtopLevelWidgets();
+ w = list->first();
+ } else {
+ w = list->next();
+ }
+ }
+ delete list;
+}
+
+/*!
+ Displays a simple message box about TQt. The message includes the
+ version number of TQt being used by the application.
+
+ This is useful for inclusion in the Help menu of an application.
+ See the examples/menu/menu.cpp example.
+
+ This function is a convenience slot for TQMessageBox::aboutTQt().
+*/
+void TQApplication::aboutTQt()
+{
+#ifndef TQT_NO_MESSAGEBOX
+ TQMessageBox::aboutTQt( mainWidget() );
+#endif // TQT_NO_MESSAGEBOX
+}
+
+
+/*!
+ \fn void TQApplication::lastWindowClosed()
+
+ This signal is emitted when the user has closed the last
+ top level window.
+
+ The signal is very useful when your application has many top level
+ widgets but no main widget. You can then connect it to the quit()
+ slot.
+
+ For convenience, this signal is \e not emitted for transient top level
+ widgets such as popup menus and dialogs.
+
+ \sa mainWidget(), tqtopLevelWidgets(), TQWidget::isTopLevel(), TQWidget::close()
+*/
+
+/*!
+ \fn void TQApplication::aboutToQuit()
+
+ This signal is emitted when the application is about to quit the
+ main event loop, e.g. when the event loop level drops to zero.
+ This may happen either after a call to quit() from inside the
+ application or when the users shuts down the entire desktop session.
+
+ The signal is particularly useful if your application has to do some
+ last-second cleanup. Note that no user interaction is possible in
+ this state.
+
+ \sa quit()
+*/
+
+
+/*!
+ \fn void TQApplication::guiThreadAwake()
+
+ This signal is emitted after the event loop returns from a function
+ that could block.
+
+ \sa wakeUpGuiThread()
+*/
+
+
+/*!
+ \fn bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event )
+
+ Sends event \a event directly to receiver \a receiver, using the
+ notify() function. Returns the value that was returned from the event
+ handler.
+
+ The event is \e not deleted when the event has been sent. The normal
+ approach is to create the event on the stack, e.g.
+ \code
+ TQMouseEvent me( TQEvent::MouseButtonPress, pos, 0, 0 );
+ TQApplication::sendEvent( mainWindow, &me );
+ \endcode
+ If you create the event on the heap you must delete it.
+
+ \sa postEvent(), notify()
+*/
+
+/*!
+ Sends event \a e to \a receiver: \a {receiver}->event(\a e).
+ Returns the value that is returned from the receiver's event handler.
+
+ For certain types of events (e.g. mouse and key events),
+ the event will be propagated to the receiver's tqparent and so on up to
+ the top-level object if the receiver is not interested in the event
+ (i.e., it returns FALSE).
+
+ There are five different ways that events can be processed;
+ reimplementing this virtual function is just one of them. All five
+ approaches are listed below:
+ \list 1
+ \i Reimplementing this function. This is very powerful, providing
+ complete control; but only one subclass can be tqApp.
+
+ \i Installing an event filter on tqApp. Such an event filter is able
+ to process all events for all widgets, so it's just as powerful as
+ reimplementing notify(); furthermore, it's possible to have more
+ than one application-global event filter. Global event filters even
+ see mouse events for \link TQWidget::isEnabled() disabled
+ widgets, \endlink and if \link setGlobalMouseTracking() global mouse
+ tracking \endlink is enabled, as well as mouse move events for all
+ widgets.
+
+ \i Reimplementing TQObject::event() (as TQWidget does). If you do
+ this you get Tab key presses, and you get to see the events before
+ any widget-specific event filters.
+
+ \i Installing an event filter on the object. Such an event filter
+ gets all the events except Tab and Shift-Tab key presses.
+
+ \i Reimplementing paintEvent(), mousePressEvent() and so
+ on. This is the commonest, easiest and least powerful way.
+ \endlist
+
+ \sa TQObject::event(), installEventFilter()
+*/
+
+bool TQApplication::notify( TQObject *receiver, TQEvent *e )
+{
+ // no events are delivered after ~TQApplication() has started
+ if ( is_app_closing )
+ return FALSE;
+
+ if ( receiver == 0 ) { // serious error
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQApplication::notify: Unexpected null receiver" );
+#endif
+ return FALSE;
+ }
+
+ if ( e->type() == TQEvent::ChildRemoved && receiver->postedEvents && globalPostedEvents) {
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ // the TQObject destructor calls TQObject::removeChild, which calls
+ // TQApplication::sendEvent() directly. this can happen while the event
+ // loop is in the middle of posting events, and when we get here, we may
+ // not have any more posted events for this object.
+ if ( receiver->postedEvents ) {
+ // if this is a child remove event and the child insert
+ // hasn't been dispatched yet, kill that insert
+ TQPostEventList * l = receiver->postedEvents;
+ TQObject * c = ((TQChildEvent*)e)->child();
+ TQPostEvent * pe;
+ l->first();
+ while( ( pe = l->current()) != 0 ) {
+ if ( pe->event && pe->receiver == receiver &&
+ pe->event->type() == TQEvent::ChildInserted &&
+ ((TQChildEvent*)pe->event)->child() == c ) {
+ pe->event->posted = FALSE;
+ delete pe->event;
+ pe->event = 0;
+ l->remove();
+ continue;
+ }
+ l->next();
+ }
+ }
+ }
+
+ bool res = FALSE;
+ if ( !receiver->isWidgetType() )
+ res = internalNotify( receiver, e );
+ else switch ( e->type() ) {
+#ifndef TQT_NO_ACCEL
+ case TQEvent::Accel:
+ {
+ TQKeyEvent* key = (TQKeyEvent*) e;
+ res = internalNotify( receiver, e );
+
+ if ( !res && !key->isAccepted() )
+ res = qt_dispatchAccelEvent( (TQWidget*)receiver, key );
+
+ // next lines are for compatibility with TQt <= 3.0.x: old
+ // TQAccel was listening on toplevel widgets
+ if ( !res && !key->isAccepted() && !((TQWidget*)receiver)->isTopLevel() )
+ res = internalNotify( ((TQWidget*)receiver)->tqtopLevelWidget(), e );
+ }
+ break;
+#endif //TQT_NO_ACCEL
+ case TQEvent::KeyPress:
+ case TQEvent::KeyRelease:
+ case TQEvent::AccelOverride:
+ {
+ TQWidget* w = (TQWidget*)receiver;
+ TQKeyEvent* key = (TQKeyEvent*) e;
+#ifndef TQT_NO_ACCEL
+ if ( qt_tryComposeUnicode( w, key ) )
+ break;
+#endif
+ bool def = key->isAccepted();
+ while ( w ) {
+ if ( def )
+ key->accept();
+ else
+ key->ignore();
+ res = internalNotify( w, e );
+ if ( res || key->isAccepted() )
+ break;
+ w = w->parentWidget( TRUE );
+ }
+ }
+ break;
+ case TQEvent::MouseButtonPress:
+ if ( e->spontaneous() ) {
+ TQWidget* fw = (TQWidget*)receiver;
+ while ( fw->focusProxy() )
+ fw = fw->focusProxy();
+ if ( fw->isEnabled() && fw->focusPolicy() & TQWidget::ClickFocus ) {
+ TQFocusEvent::setReason( TQFocusEvent::Mouse);
+ fw->setFocus();
+ TQFocusEvent::resetReason();
+ }
+ }
+ // fall through intended
+ case TQEvent::MouseButtonRelease:
+ case TQEvent::MouseButtonDblClick:
+ case TQEvent::MouseMove:
+ {
+ TQWidget* w = (TQWidget*)receiver;
+ TQMouseEvent* mouse = (TQMouseEvent*) e;
+ TQPoint relpos = mouse->pos();
+ while ( w ) {
+ TQMouseEvent me(mouse->type(), relpos, mouse->globalPos(), mouse->button(), mouse->state());
+ me.spont = mouse->spontaneous();
+ res = internalNotify( w, w == receiver ? mouse : &me );
+ e->spont = FALSE;
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ mouse->accept();
+ else
+ mouse->ignore();
+ }
+ break;
+#ifndef TQT_NO_WHEELEVENT
+ case TQEvent::Wheel:
+ {
+ if ( e->spontaneous() ) {
+ TQWidget* fw = (TQWidget*)receiver;
+ while ( fw->focusProxy() )
+ fw = fw->focusProxy();
+ if ( fw->isEnabled() && (fw->focusPolicy() & TQWidget::WheelFocus) == TQWidget::WheelFocus ) {
+ TQFocusEvent::setReason( TQFocusEvent::Mouse);
+ fw->setFocus();
+ TQFocusEvent::resetReason();
+ }
+ }
+
+ TQWidget* w = (TQWidget*)receiver;
+ TQWheelEvent* wheel = (TQWheelEvent*) e;
+ TQPoint relpos = wheel->pos();
+ while ( w ) {
+ TQWheelEvent we(relpos, wheel->globalPos(), wheel->delta(), wheel->state(), wheel->orientation());
+ we.spont = wheel->spontaneous();
+ res = internalNotify( w, w == receiver ? wheel : &we );
+ e->spont = FALSE;
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ wheel->accept();
+ else
+ wheel->ignore();
+ }
+ break;
+#endif
+ case TQEvent::ContextMenu:
+ {
+ TQWidget* w = (TQWidget*)receiver;
+ TQContextMenuEvent *context = (TQContextMenuEvent*) e;
+ TQPoint relpos = context->pos();
+ while ( w ) {
+ TQContextMenuEvent ce(context->reason(), relpos, context->globalPos(), context->state());
+ ce.spont = e->spontaneous();
+ res = internalNotify( w, w == receiver ? context : &ce );
+ e->spont = FALSE;
+
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ context->accept();
+ else
+ context->ignore();
+ }
+ break;
+#if defined (TQT_TABLET_SUPPORT)
+ case TQEvent::TabletMove:
+ case TQEvent::TabletPress:
+ case TQEvent::TabletRelease:
+ {
+ TQWidget *w = (TQWidget*)receiver;
+ TQTabletEvent *tablet = (TQTabletEvent*)e;
+ TQPoint relpos = tablet->pos();
+ while ( w ) {
+ TQTabletEvent te(tablet->pos(), tablet->globalPos(), tablet->tqdevice(),
+ tablet->pressure(), tablet->xTilt(), tablet->yTilt(),
+ tablet->uniqueId());
+ te.spont = e->spontaneous();
+ res = internalNotify( w, w == receiver ? tablet : &te );
+ e->spont = FALSE;
+ if (res || w->isTopLevel() || w->testWFlags(WNoMousePropagation))
+ break;
+
+ relpos += w->pos();
+ w = w->parentWidget();
+ }
+ if ( res )
+ tablet->accept();
+ else
+ tablet->ignore();
+ chokeMouse = tablet->isAccepted();
+ }
+ break;
+#endif
+ default:
+ res = internalNotify( receiver, e );
+ break;
+ }
+
+ return res;
+}
+
+/*!\reimp
+
+*/
+bool TQApplication::event( TQEvent *e )
+{
+ if(e->type() == TQEvent::Close) {
+ TQCloseEvent *ce = (TQCloseEvent*)e;
+ ce->accept();
+ closeAllWindows();
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ for(TQWidget *w = list->first(); w; w = list->next()) {
+ if ( !w->isHidden() && !w->isDesktop() && !w->isPopup() &&
+ (!w->isDialog() || !w->parentWidget())) {
+ ce->ignore();
+ break;
+ }
+ }
+ if(ce->isAccepted())
+ return TRUE;
+ } else if (e->type() == TQEvent::Quit) {
+ quit();
+ return TRUE;
+ }
+ return TQObject::event(e);
+}
+
+/*!\internal
+
+ Helper function called by notify()
+ */
+bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e)
+{
+ if ( eventFilters ) {
+ TQObjectListIt it( *eventFilters );
+ register TQObject *obj;
+ while ( (obj=it.current()) != 0 ) { // send to all filters
+ ++it; // until one returns TRUE
+ if ( obj->eventFilter(receiver,e) )
+ return TRUE;
+ }
+ }
+
+ bool consumed = FALSE;
+ bool handled = FALSE;
+ if ( receiver->isWidgetType() ) {
+ TQWidget *widget = (TQWidget*)receiver;
+
+ // toggle HasMouse widget state on enter and leave
+ if ( e->type() == TQEvent::Enter || e->type() == TQEvent::DragEnter )
+ widget->setWState( WState_HasMouse );
+ else if ( e->type() == TQEvent::Leave || e->type() == TQEvent::DragLeave )
+ widget->clearWState( WState_HasMouse );
+
+ // throw away any mouse-tracking-only mouse events
+ if ( e->type() == TQEvent::MouseMove &&
+ (((TQMouseEvent*)e)->state()&TQMouseEvent::MouseButtonMask) == 0 &&
+ !widget->hasMouseTracking() ) {
+ handled = TRUE;
+ consumed = TRUE;
+ } else if ( !widget->isEnabled() ) { // throw away mouse events to disabled widgets
+ switch(e->type()) {
+ case TQEvent::MouseButtonPress:
+ case TQEvent::MouseButtonRelease:
+ case TQEvent::MouseButtonDblClick:
+ case TQEvent::MouseMove:
+ ( (TQMouseEvent*) e)->ignore();
+ handled = TRUE;
+ consumed = TRUE;
+ break;
+#ifndef TQT_NO_DRAGANDDROP
+ case TQEvent::DragEnter:
+ case TQEvent::DragMove:
+ ( (TQDragMoveEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+
+ case TQEvent::DragLeave:
+ case TQEvent::DragResponse:
+ handled = TRUE;
+ break;
+
+ case TQEvent::Drop:
+ ( (TQDropEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+#endif
+#ifndef TQT_NO_WHEELEVENT
+ case TQEvent::Wheel:
+ ( (TQWheelEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+#endif
+ case TQEvent::ContextMenu:
+ ( (TQContextMenuEvent*) e)->ignore();
+ handled = TRUE;
+ break;
+ default:
+ break;
+ }
+ }
+
+ }
+
+ if (!handled)
+ consumed = receiver->event( e );
+ e->spont = FALSE;
+ return consumed;
+}
+
+/*!
+ Returns TRUE if an application object has not been created yet;
+ otherwise returns FALSE.
+
+ \sa closingDown()
+*/
+
+bool TQApplication::startingUp()
+{
+ return !is_app_running;
+}
+
+/*!
+ Returns TRUE if the application objects are being destroyed;
+ otherwise returns FALSE.
+
+ \sa startingUp()
+*/
+
+bool TQApplication::closingDown()
+{
+ return is_app_closing;
+}
+
+
+/*!
+ Processes pending events, for 3 seconds or until there are no more
+ events to process, whichever is shorter.
+
+ You can call this function occasionally when your program is busy
+ performing a long operation (e.g. copying a file).
+
+ \sa exec(), TQTimer, TQEventLoop::processEvents()
+*/
+
+void TQApplication::processEvents()
+{
+ processEvents( 3000 );
+}
+
+/*!
+ \overload
+
+ Processes pending events for \a maxtime milliseconds or until
+ there are no more events to process, whichever is shorter.
+
+ You can call this function occasionally when you program is busy
+ doing a long operation (e.g. copying a file).
+
+ \sa exec(), TQTimer, TQEventLoop::processEvents()
+*/
+void TQApplication::processEvents( int maxtime )
+{
+ eventLoop()->processEvents( TQEventLoop::AllEvents, maxtime );
+}
+
+/*! \obsolete
+ Waits for an event to occur, processes it, then returns.
+
+ This function is useful for adapting TQt to situations where the
+ event processing must be grafted onto existing program loops.
+
+ Using this function in new applications may be an indication of design
+ problems.
+
+ \sa processEvents(), exec(), TQTimer
+*/
+
+void TQApplication::processOneEvent()
+{
+ eventLoop()->processEvents( TQEventLoop::AllEvents |
+ TQEventLoop::WaitForMore );
+}
+
+/*****************************************************************************
+ Main event loop wrappers
+ *****************************************************************************/
+
+/*!
+ Returns the application event loop. This function will return
+ zero if called during and after destroying TQApplication.
+
+ To create your own instance of TQEventLoop or TQEventLoop subclass create
+ it before you create the TQApplication object.
+
+ \sa TQEventLoop
+*/
+TQEventLoop *TQApplication::eventLoop()
+{
+ if ( !eventloop && !is_app_closing )
+ (void) new TQEventLoop( tqApp, "default event loop" );
+ return eventloop;
+}
+
+
+/*!
+ Enters the main event loop and waits until exit() is called or the
+ main widget is destroyed, and returns the value that was set to
+ exit() (which is 0 if exit() is called via quit()).
+
+ It is necessary to call this function to start event handling. The
+ main event loop receives events from the window system and
+ dispatches these to the application widgets.
+
+ Generally speaking, no user interaction can take place before
+ calling exec(). As a special case, modal widgets like TQMessageBox
+ can be used before calling exec(), because modal widgets call
+ exec() to start a local event loop.
+
+ To make your application perform idle processing, i.e. executing a
+ special function whenever there are no pending events, use a
+ TQTimer with 0 timeout. More advanced idle processing schemes can
+ be achieved using processEvents().
+
+ \sa quit(), exit(), processEvents(), setMainWidget()
+*/
+int TQApplication::exec()
+{
+ return eventLoop()->exec();
+}
+
+/*!
+ Tells the application to exit with a return code.
+
+ After this function has been called, the application leaves the main
+ event loop and returns from the call to exec(). The exec() function
+ returns \a retcode.
+
+ By convention, a \a retcode of 0 means success, and any non-zero
+ value indicates an error.
+
+ Note that unlike the C library function of the same name, this
+ function \e does return to the caller -- it is event processing that
+ stops.
+
+ \sa quit(), exec()
+*/
+void TQApplication::exit( int retcode )
+{
+ tqApp->eventLoop()->exit( retcode );
+}
+
+/*!
+ \obsolete
+
+ This function enters the main event loop (recursively). Do not call
+ it unless you really know what you are doing.
+
+ Use TQApplication::eventLoop()->enterLoop() instead.
+
+*/
+int TQApplication::enter_loop()
+{
+ return eventLoop()->enterLoop();
+}
+
+/*!
+ \obsolete
+
+ This function exits from a recursive call to the main event loop.
+ Do not call it unless you are an expert.
+
+ Use TQApplication::eventLoop()->exitLoop() instead.
+
+*/
+void TQApplication::exit_loop()
+{
+ eventLoop()->exitLoop();
+}
+
+/*!
+ \obsolete
+
+ Returns the current loop level.
+
+ Use TQApplication::eventLoop()->loopLevel() instead.
+
+*/
+int TQApplication::loopLevel() const
+{
+ return eventLoop()->loopLevel();
+}
+
+/*!
+
+ Wakes up the GUI thread.
+
+ \sa guiThreadAwake() \link threads.html Thread Support in TQt\endlink
+*/
+void TQApplication::wakeUpGuiThread()
+{
+ eventLoop()->wakeUp();
+}
+
+/*!
+ This function returns TRUE if there are pending events; otherwise
+ returns FALSE. Pending events can be either from the window system
+ or posted events using TQApplication::postEvent().
+*/
+bool TQApplication::hasPendingEvents()
+{
+ return eventLoop()->hasPendingEvents();
+}
+
+#if !defined(TQ_WS_X11)
+
+// The doc and X implementation of these functions is in qapplication_x11.cpp
+
+void TQApplication::flushX() {} // do nothing
+
+void TQApplication::syncX() {} // do nothing
+
+#endif
+
+/*!
+ \fn void TQApplication::setWinStyleHighlightColor( const TQColor & )
+ \obsolete
+
+ Sets the color used to mark selections in windows style for all widgets
+ in the application. Will tqrepaint all widgets if the color is changed.
+
+ The default color is \c darkBlue.
+ \sa winStyleHighlightColor()
+*/
+
+/*!
+ \fn const TQColor& TQApplication::winStyleHighlightColor()
+ \obsolete
+
+ Returns the color used to mark selections in windows style.
+
+ \sa setWinStyleHighlightColor()
+*/
+
+/*!
+ Returns the version of the Windows operating system that is running:
+
+ \list
+ \i TQt::WV_95 - Windows 95
+ \i TQt::WV_98 - Windows 98
+ \i TQt::WV_Me - Windows Me
+ \i TQt::WV_NT - Windows NT 4.x
+ \i TQt::WV_2000 - Windows 2000 (NT5)
+ \i TQt::WV_XP - Windows XP
+ \i TQt::WV_2003 - Windows Server 2003 family
+ \i TQt::WV_CE - Windows CE
+ \i TQt::WV_CENET - Windows CE.NET
+ \endlist
+
+ Note that this function is implemented for the Windows version
+ of TQt only.
+*/
+
+#if defined(TQ_OS_CYGWIN)
+TQt::WindowsVersion TQApplication::winVersion()
+{
+ return qt_winver;
+}
+#endif
+
+#ifndef TQT_NO_TRANSLATION
+
+bool qt_detectRTLLanguage()
+{
+ return TQApplication::tr( "TQT_LAYOUT_DIRECTION",
+ "Translate this string to the string 'LTR' in left-to-right"
+ " languages or to 'RTL' in right-to-left languages (such as Hebrew"
+ " and Arabic) to get proper widget tqlayout." ) == "RTL";
+}
+
+/*!
+ Adds the message file \a mf to the list of message files to be used
+ for translations.
+
+ Multiple message files can be installed. Translations are searched
+ for in the last installed message file, then the one from last, and
+ so on, back to the first installed message file. The search stops as
+ soon as a matching translation is found.
+
+ \sa removeTranslator() translate() TQTranslator::load()
+*/
+
+void TQApplication::installTranslator( TQTranslator * mf )
+{
+ if ( !mf )
+ return;
+ if ( !translators )
+ translators = new TQValueList<TQTranslator*>;
+
+ translators->prepend( mf );
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ if ( mf->isEmpty() )
+ return;
+#endif
+
+ // hook to set the tqlayout direction of dialogs
+ setReverseLayout( qt_detectRTLLanguage() );
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ if (!w->isDesktop())
+ postEvent( w, new TQEvent( TQEvent::LanguageChange ) );
+ }
+ delete list;
+}
+
+/*!
+ Removes the message file \a mf from the list of message files used by
+ this application. (It does not delete the message file from the file
+ system.)
+
+ \sa installTranslator() translate(), TQObject::tr()
+*/
+
+void TQApplication::removeTranslator( TQTranslator * mf )
+{
+ if ( !translators || !mf )
+ return;
+
+ if ( translators->remove( mf ) && ! tqApp->closingDown() ) {
+ setReverseLayout( qt_detectRTLLanguage() );
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ postEvent( w, new TQEvent( TQEvent::LanguageChange ) );
+ }
+ delete list;
+ }
+}
+
+#ifndef TQT_NO_TEXTCODEC
+/*! \obsolete
+ This is the same as TQTextCodec::setCodecForTr().
+*/
+void TQApplication::setDefaultCodec( TQTextCodec* codec )
+{
+ TQTextCodec::setCodecForTr( codec );
+}
+
+/*! \obsolete
+ Returns TQTextCodec::codecForTr().
+*/
+TQTextCodec* TQApplication::defaultCodec() const
+{
+ return TQTextCodec::codecForTr();
+}
+#endif //TQT_NO_TEXTCODEC
+
+/*! \enum TQApplication::Encoding
+
+ This enum type defines the 8-bit encoding of character string
+ arguments to translate():
+
+ \value DefaultCodec - the encoding specified by
+ TQTextCodec::codecForTr() (Latin-1 if none has been set)
+ \value UnicodeUTF8 - UTF-8
+
+ \sa TQObject::tr(), TQObject::trUtf8(), TQString::fromUtf8()
+*/
+
+/*! \reentrant
+ Returns the translation text for \a sourceText, by querying the
+ installed messages files. The message files are searched from the most
+ recently installed message file back to the first installed message
+ file.
+
+ TQObject::tr() and TQObject::trUtf8() provide this functionality more
+ conveniently.
+
+ \a context is typically a class name (e.g., "MyDialog") and
+ \a sourceText is either English text or a short identifying text, if
+ the output text will be very long (as for help texts).
+
+ \a comment is a disambiguating comment, for when the same \a
+ sourceText is used in different roles within the same context. By
+ default, it is null. \a encoding indicates the 8-bit encoding of
+ character stings
+
+ See the \l TQTranslator documentation for more information about
+ contexts and comments.
+
+ If none of the message files contain a translation for \a
+ sourceText in \a context, this function returns a TQString
+ equivalent of \a sourceText. The encoding of \a sourceText is
+ specified by \e encoding; it defaults to \c DefaultCodec.
+
+ This function is not virtual. You can use alternative translation
+ techniques by subclassing \l TQTranslator.
+
+ \warning This method is reentrant only if all translators are
+ installed \e before calling this method. Installing or removing
+ translators while performing translations is not supported. Doing
+ so will most likely result in crashes or other undesirable behavior.
+
+ \sa TQObject::tr() installTranslator() defaultCodec()
+*/
+
+TQString TQApplication::translate( const char * context, const char * sourceText,
+ const char * comment, Encoding encoding ) const
+{
+ if ( !sourceText )
+ return TQString::null;
+
+ if ( translators ) {
+ TQValueList<TQTranslator*>::iterator it;
+ TQTranslator * mf;
+ TQString result;
+ for ( it = translators->begin(); it != translators->end(); ++it ) {
+ mf = *it;
+ result = mf->tqfindMessage( context, sourceText, comment ).translation();
+ if ( !result.isNull() )
+ return result;
+ }
+ }
+#ifndef TQT_NO_TEXTCODEC
+ if ( encoding == UnicodeUTF8 )
+ return TQString::fromUtf8( sourceText );
+ else if ( TQTextCodec::codecForTr() != 0 )
+ return TQTextCodec::codecForTr()->toUnicode( sourceText );
+ else
+#endif
+ return TQString::tqfromLatin1( sourceText );
+}
+
+#endif
+
+/*****************************************************************************
+ TQApplication management of posted events
+ *****************************************************************************/
+
+//see also notify(), which does the removal of ChildInserted when ChildRemoved.
+
+/*!
+ Adds the event \a event with the object \a receiver as the receiver of the
+ event, to an event queue and returns immediately.
+
+ The event must be allocated on the heap since the post event queue
+ will take ownership of the event and delete it once it has been posted.
+
+ When control returns to the main event loop, all events that are
+ stored in the queue will be sent using the notify() function.
+
+ \threadsafe
+
+ \sa sendEvent(), notify()
+*/
+
+void TQApplication::postEvent( TQObject *receiver, TQEvent *event )
+{
+ if ( receiver == 0 ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQApplication::postEvent: Unexpected null receiver" );
+#endif
+ delete event;
+ return;
+ }
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ if ( !globalPostedEvents ) { // create list
+ globalPostedEvents = new TQPostEventList;
+ TQ_CHECK_PTR( globalPostedEvents );
+ globalPostedEvents->setAutoDelete( TRUE );
+ qapp_cleanup_events.set( &globalPostedEvents );
+ }
+
+ if ( !receiver->postedEvents )
+ receiver->postedEvents = new TQPostEventList;
+ TQPostEventList * l = receiver->postedEvents;
+
+ // if this is one of the compressible events, do compression
+ if ( event->type() == TQEvent::Paint ||
+ event->type() == TQEvent::LayoutHint ||
+ event->type() == TQEvent::Resize ||
+ event->type() == TQEvent::Move ||
+ event->type() == TQEvent::LanguageChange ) {
+ l->first();
+ TQPostEvent * cur = 0;
+ for ( ;; ) {
+ while ( (cur=l->current()) != 0 &&
+ ( cur->receiver != receiver ||
+ cur->event == 0 ||
+ cur->event->type() != event->type() ) )
+ l->next();
+ if ( l->current() != 0 ) {
+ if ( cur->event->type() == TQEvent::Paint ) {
+ TQPaintEvent * p = (TQPaintEvent*)(cur->event);
+ if ( p->erase != ((TQPaintEvent*)event)->erase ) {
+ l->next();
+ continue;
+ }
+ p->reg = p->reg.unite( ((TQPaintEvent *)event)->reg );
+ p->rec = p->rec.unite( ((TQPaintEvent *)event)->rec );
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::LayoutHint ) {
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::Resize ) {
+ ((TQResizeEvent *)(cur->event))->s = ((TQResizeEvent *)event)->s;
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::Move ) {
+ ((TQMoveEvent *)(cur->event))->p = ((TQMoveEvent *)event)->p;
+ delete event;
+ return;
+ } else if ( cur->event->type() == TQEvent::LanguageChange ) {
+ delete event;
+ return;
+ }
+ }
+ break;
+ };
+ }
+
+ // if no compression could be done, just append something
+ event->posted = TRUE;
+ TQPostEvent * pe = new TQPostEvent( receiver, event );
+ l->append( pe );
+ globalPostedEvents->append( pe );
+
+ if (eventloop)
+ eventloop->wakeUp();
+}
+
+
+/*! \overload
+
+ Dispatches all posted events, i.e. empties the event queue.
+*/
+void TQApplication::sendPostedEvents()
+{
+ sendPostedEvents( 0, 0 );
+}
+
+
+
+/*!
+ Immediately dispatches all events which have been previously queued
+ with TQApplication::postEvent() and which are for the object \a receiver
+ and have the event type \a event_type.
+
+ Note that events from the window system are \e not dispatched by this
+ function, but by processEvents().
+
+ If \a receiver is null, the events of \a event_type are sent for all
+ objects. If \a event_type is 0, all the events are sent for \a receiver.
+*/
+
+void TQApplication::sendPostedEvents( TQObject *receiver, int event_type )
+{
+ // Make sure the object hierarchy is stable before processing events
+ // to avoid endless loops
+ if ( receiver == 0 && event_type == 0 )
+ sendPostedEvents( 0, TQEvent::ChildInserted );
+
+ if ( !globalPostedEvents || ( receiver && !receiver->postedEvents ) )
+ return;
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif
+
+ bool sent = TRUE;
+ while ( sent ) {
+ sent = FALSE;
+
+ if ( !globalPostedEvents || ( receiver && !receiver->postedEvents ) )
+ return;
+
+ // if we have a receiver, use the local list. Otherwise, use the
+ // global list
+ TQPostEventList * l = receiver ? receiver->postedEvents : globalPostedEvents;
+
+ // okay. here is the tricky loop. be careful about optimizing
+ // this, it looks the way it does for good reasons.
+ TQPostEventListIt it( *l );
+ TQPostEvent *pe;
+ while ( (pe=it.current()) != 0 ) {
+ ++it;
+ if ( pe->event // hasn't been sent yet
+ && ( receiver == 0 // we send to all tqreceivers
+ || receiver == pe->receiver ) // we send to THAT receiver
+ && ( event_type == 0 // we send all types
+ || event_type == pe->event->type() ) ) { // we send THAT type
+ // first, we diddle the event so that we can deliver
+ // it, and that noone will try to touch it later.
+ pe->event->posted = FALSE;
+ TQEvent * e = pe->event;
+ TQObject * r = pe->receiver;
+ pe->event = 0;
+
+ // next, update the data structure so that we're ready
+ // for the next event.
+
+ // look for the local list, and take whatever we're
+ // delivering out of it. r->postedEvents maybe *l
+ if ( r->postedEvents ) {
+ r->postedEvents->removeRef( pe );
+ // if possible, get rid of that list. this is not
+ // ideal - we will create and delete a list for
+ // each update() call. it would be better if we'd
+ // leave the list empty here, and delete it
+ // somewhere else if it isn't being used.
+ if ( r->postedEvents->isEmpty() ) {
+ delete r->postedEvents;
+ r->postedEvents = 0;
+ }
+ }
+
+#ifdef TQT_THREAD_SUPPORT
+ if ( locker.mutex() ) locker.mutex()->unlock();
+#endif // TQT_THREAD_SUPPORT
+ // after all that work, it's time to deliver the event.
+ if ( e->type() == TQEvent::Paint && r->isWidgetType() ) {
+ TQWidget * w = (TQWidget*)r;
+ TQPaintEvent * p = (TQPaintEvent*)e;
+ if ( w->isVisible() )
+ w->tqrepaint( p->reg, p->erase );
+ } else {
+ sent = TRUE;
+ TQApplication::sendEvent( r, e );
+ }
+#ifdef TQT_THREAD_SUPPORT
+ if ( locker.mutex() ) locker.mutex()->lock();
+#endif // TQT_THREAD_SUPPORT
+
+ delete e;
+ // careful when adding anything below this point - the
+ // sendEvent() call might tqinvalidate any invariants this
+ // function depends on.
+ }
+ }
+
+ // clear the global list, i.e. remove everything that was
+ // delivered.
+ if ( l == globalPostedEvents ) {
+ globalPostedEvents->first();
+ while( (pe=globalPostedEvents->current()) != 0 ) {
+ if ( pe->event )
+ globalPostedEvents->next();
+ else
+ globalPostedEvents->remove();
+ }
+ }
+ }
+}
+
+/*!
+ Removes all events posted using postEvent() for \a receiver.
+
+ The events are \e not dispatched, instead they are removed from the
+ queue. You should never need to call this function. If you do call it,
+ be aware that killing events may cause \a receiver to break one or
+ more invariants.
+
+ \threadsafe
+*/
+
+void TQApplication::removePostedEvents( TQObject *receiver )
+{
+ if ( !receiver )
+ return;
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ // the TQObject destructor calls this function directly. this can
+ // happen while the event loop is in the middle of posting events,
+ // and when we get here, we may not have any more posted events
+ // for this object.
+ if ( !receiver->postedEvents )
+ return;
+
+ // iterate over the object-specifc list and delete the events.
+ // leave the TQPostEvent objects; they'll be deleted by
+ // sendPostedEvents().
+ TQPostEventList * l = receiver->postedEvents;
+ receiver->postedEvents = 0;
+ l->first();
+ TQPostEvent * pe;
+ while( (pe=l->current()) != 0 ) {
+ if ( pe->event ) {
+ pe->event->posted = FALSE;
+ delete pe->event;
+ pe->event = 0;
+ }
+ l->remove();
+ }
+ delete l;
+}
+
+
+/*!
+ Removes \a event from the queue of posted events, and emits a
+ warning message if appropriate.
+
+ \warning This function can be \e really slow. Avoid using it, if
+ possible.
+
+ \threadsafe
+*/
+
+void TQApplication::removePostedEvent( TQEvent * event )
+{
+ if ( !event || !event->posted )
+ return;
+
+ if ( !globalPostedEvents ) {
+#if defined(TQT_DEBUG)
+ qDebug( "TQApplication::removePostedEvent: %p %d is posted: impossible",
+ (void*)event, event->type() );
+ return;
+#endif
+ }
+
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( postevent_mutex );
+#endif // TQT_THREAD_SUPPORT
+
+ TQPostEventListIt it( *globalPostedEvents );
+ TQPostEvent * pe;
+ while( (pe = it.current()) != 0 ) {
+ ++it;
+ if ( pe->event == event ) {
+#if defined(TQT_DEBUG)
+ const char *n;
+ switch ( event->type() ) {
+ case TQEvent::Timer:
+ n = "Timer";
+ break;
+ case TQEvent::MouseButtonPress:
+ n = "MouseButtonPress";
+ break;
+ case TQEvent::MouseButtonRelease:
+ n = "MouseButtonRelease";
+ break;
+ case TQEvent::MouseButtonDblClick:
+ n = "MouseButtonDblClick";
+ break;
+ case TQEvent::MouseMove:
+ n = "MouseMove";
+ break;
+#ifndef TQT_NO_WHEELEVENT
+ case TQEvent::Wheel:
+ n = "Wheel";
+ break;
+#endif
+ case TQEvent::KeyPress:
+ n = "KeyPress";
+ break;
+ case TQEvent::KeyRelease:
+ n = "KeyRelease";
+ break;
+ case TQEvent::FocusIn:
+ n = "FocusIn";
+ break;
+ case TQEvent::FocusOut:
+ n = "FocusOut";
+ break;
+ case TQEvent::Enter:
+ n = "Enter";
+ break;
+ case TQEvent::Leave:
+ n = "Leave";
+ break;
+ case TQEvent::Paint:
+ n = "Paint";
+ break;
+ case TQEvent::Move:
+ n = "Move";
+ break;
+ case TQEvent::Resize:
+ n = "Resize";
+ break;
+ case TQEvent::Create:
+ n = "Create";
+ break;
+ case TQEvent::Destroy:
+ n = "Destroy";
+ break;
+ case TQEvent::Close:
+ n = "Close";
+ break;
+ case TQEvent::Quit:
+ n = "Quit";
+ break;
+ default:
+ n = "<other>";
+ break;
+ }
+ qWarning("TQEvent: Warning: %s event deleted while posted to %s %s",
+ n,
+ pe->receiver ? pe->receiver->className() : "null",
+ pe->receiver ? pe->receiver->name() : "object" );
+ // note the beautiful uglehack if !pe->receiver :)
+#endif
+ event->posted = FALSE;
+ delete pe->event;
+ pe->event = 0;
+ return;
+ }
+ }
+}
+
+/*!\internal
+
+ Sets the active window in reaction to a system event. Call this
+ from the platform specific event handlers.
+
+ It sets the activeWindow() and tqfocusWidget() attributes and sends
+ proper WindowActivate/WindowDeactivate and FocusIn/FocusOut events
+ to all appropriate widgets.
+
+ \sa activeWindow()
+ */
+void TQApplication::setActiveWindow( TQWidget* act )
+{
+ TQWidget* window = act?act->tqtopLevelWidget():0;
+
+ if ( active_window == window )
+ return;
+
+ // first the activation/deactivation events
+ if ( active_window ) {
+ TQWidgetList deacts;
+#ifndef TQT_NO_STYLE
+ if ( style().tqstyleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) {
+ TQWidgetList *list = tqtopLevelWidgets();
+ if ( list ) {
+ for ( TQWidget *w = list->first(); w; w = list->next() ) {
+ if ( w->isVisible() && w->isActiveWindow() )
+ deacts.append(w);
+ }
+ delete list;
+ }
+ } else
+#endif
+ deacts.append(active_window);
+ active_window = 0;
+ TQEvent e( TQEvent::WindowDeactivate );
+ for(TQWidget *w = deacts.first(); w; w = deacts.next())
+ TQApplication::sendSpontaneousEvent( w, &e );
+ }
+
+ active_window = window;
+ if ( active_window ) {
+ TQEvent e( TQEvent::WindowActivate );
+ TQWidgetList acts;
+#ifndef TQT_NO_STYLE
+ if ( style().tqstyleHint(TQStyle::SH_Widget_ShareActivation, active_window ) ) {
+ TQWidgetList *list = tqtopLevelWidgets();
+ if ( list ) {
+ for ( TQWidget *w = list->first(); w; w = list->next() ) {
+ if ( w->isVisible() && w->isActiveWindow() )
+ acts.append(w);
+ }
+ delete list;
+ }
+ } else
+#endif
+ acts.append(active_window);
+ for(TQWidget *w = acts.first(); w; w = acts.next())
+ TQApplication::sendSpontaneousEvent( w, &e );
+ }
+
+ // then focus events
+ TQFocusEvent::setReason( TQFocusEvent::ActiveWindow );
+ if ( !active_window && focus_widget ) {
+ TQFocusEvent out( TQEvent::FocusOut );
+ TQWidget *tmp = focus_widget;
+ focus_widget = 0;
+#ifdef TQ_WS_WIN
+ TQInputContext::accept( tmp );
+#endif
+ TQApplication::sendSpontaneousEvent( tmp, &out );
+ } else if ( active_window ) {
+ TQWidget *w = active_window->tqfocusWidget();
+ if ( w && w->focusPolicy() != TQWidget::NoFocus )
+ w->setFocus();
+ else
+ active_window->focusNextPrevChild( TRUE );
+ }
+ TQFocusEvent::resetReason();
+}
+
+
+/*!\internal
+
+ Creates the proper Enter/Leave event when widget \a enter is entered
+ and widget \a leave is left.
+ */
+TQ_EXPORT void qt_dispatchEnterLeave( TQWidget* enter, TQWidget* leave ) {
+#if 0
+ if ( leave ) {
+ TQEvent e( TQEvent::Leave );
+ TQApplication::sendEvent( leave, & e );
+ }
+ if ( enter ) {
+ TQEvent e( TQEvent::Enter );
+ TQApplication::sendEvent( enter, & e );
+ }
+ return;
+#endif
+
+ TQWidget* w ;
+ if ( !enter && !leave )
+ return;
+ TQWidgetList leaveList;
+ TQWidgetList enterList;
+
+ bool sameWindow = leave && enter && leave->tqtopLevelWidget() == enter->tqtopLevelWidget();
+ if ( leave && !sameWindow ) {
+ w = leave;
+ do {
+ leaveList.append( w );
+ } while ( (w = w->parentWidget( TRUE ) ) );
+ }
+ if ( enter && !sameWindow ) {
+ w = enter;
+ do {
+ enterList.prepend( w );
+ } while ( (w = w->parentWidget(TRUE) ) );
+ }
+ if ( sameWindow ) {
+ int enterDepth = 0;
+ int leaveDepth = 0;
+ w = enter;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ enterDepth++;
+ w = leave;
+ while ( ( w = w->parentWidget( TRUE ) ) )
+ leaveDepth++;
+ TQWidget* wenter = enter;
+ TQWidget* wleave = leave;
+ while ( enterDepth > leaveDepth ) {
+ wenter = wenter->parentWidget();
+ enterDepth--;
+ }
+ while ( leaveDepth > enterDepth ) {
+ wleave = wleave->parentWidget();
+ leaveDepth--;
+ }
+ while ( !wenter->isTopLevel() && wenter != wleave ) {
+ wenter = wenter->parentWidget();
+ wleave = wleave->parentWidget();
+ }
+
+ w = leave;
+ while ( w != wleave ) {
+ leaveList.append( w );
+ w = w->parentWidget();
+ }
+ w = enter;
+ while ( w != wenter ) {
+ enterList.prepend( w );
+ w = w->parentWidget();
+ }
+ }
+
+ TQEvent leaveEvent( TQEvent::Leave );
+ for ( w = leaveList.first(); w; w = leaveList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &leaveEvent );
+ }
+ TQEvent enterEvent( TQEvent::Enter );
+ for ( w = enterList.first(); w; w = enterList.next() ) {
+ if ( !tqApp->activeModalWidget() || qt_tryModalHelper( w, 0 ))
+ TQApplication::sendEvent( w, &enterEvent );
+ }
+}
+
+
+#ifdef TQ_WS_MACX
+extern TQWidget *qt_tryModalHelperMac( TQWidget * top ); //qapplication_mac.cpp
+#endif
+
+
+/*!\internal
+
+ Called from qapplication_<platform>.cpp, returns TRUE
+ if the widget should accept the event.
+ */
+TQ_EXPORT bool qt_tryModalHelper( TQWidget *widget, TQWidget **rettop ) {
+ TQWidget *modal=0, *top=TQApplication::activeModalWidget();
+ if ( rettop ) *rettop = top;
+
+ if ( tqApp->activePopupWidget() )
+ return TRUE;
+
+#ifdef TQ_WS_MACX
+ top = qt_tryModalHelperMac( top );
+ if ( rettop ) *rettop = top;
+#endif
+
+ TQWidget* groupLeader = widget;
+ widget = widget->tqtopLevelWidget();
+
+ if ( widget->testWFlags(TQt::WShowModal) ) // widget is modal
+ modal = widget;
+ if ( !top || modal == top ) // don't block event
+ return TRUE;
+
+ TQWidget * p = widget->parentWidget(); // Check if the active modal widget is a tqparent of our widget
+ while ( p ) {
+ if ( p == top )
+ return TRUE;
+ p = p->parentWidget();
+ }
+
+ while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader ) )
+ groupLeader = groupLeader->parentWidget();
+
+ if ( groupLeader ) {
+ // Does groupLeader have a child in qt_modal_stack?
+ bool unrelated = TRUE;
+ modal = qt_modal_stack->first();
+ while (modal && unrelated) {
+ TQWidget* p = modal->parentWidget();
+ while ( p && p != groupLeader && !p->testWFlags( TQt::WGroupLeader) ) {
+ p = p->parentWidget();
+ }
+ modal = qt_modal_stack->next();
+ if ( p == groupLeader ) unrelated = FALSE;
+ }
+
+ if ( unrelated )
+ return TRUE; // don't block event
+ }
+ return FALSE;
+}
+
+
+/*!
+ Returns the desktop widget (also called the root window).
+
+ The desktop widget is useful for obtaining the size of the screen.
+ It may also be possible to draw on the desktop. We recommend against
+ assuming that it's possible to draw on the desktop, since this does
+ not work on all operating systems.
+
+ \code
+ TQDesktopWidget *d = TQApplication::desktop();
+ int w = d->width(); // returns desktop width
+ int h = d->height(); // returns desktop height
+ \endcode
+*/
+
+TQDesktopWidget *TQApplication::desktop()
+{
+ if ( !qt_desktopWidget || // not created yet
+ !qt_desktopWidget->isDesktop() ) { // reparented away
+ qt_desktopWidget = new TQDesktopWidget();
+ TQ_CHECK_PTR( qt_desktopWidget );
+ }
+ return qt_desktopWidget;
+}
+
+#ifndef TQT_NO_CLIPBOARD
+/*!
+ Returns a pointer to the application global clipboard.
+*/
+TQClipboard *TQApplication::clipboard()
+{
+ if ( qt_clipboard == 0 ) {
+ qt_clipboard = new TQClipboard;
+ TQ_CHECK_PTR( qt_clipboard );
+ }
+ return qt_clipboard;
+}
+#endif // TQT_NO_CLIPBOARD
+
+/*!
+ By default, TQt will try to use the current standard colors, fonts
+ etc., from the underlying window system's desktop settings,
+ and use them for all relevant widgets. This behavior can be switched off
+ by calling this function with \a on set to FALSE.
+
+ This static function must be called before creating the TQApplication
+ object, like this:
+
+ \code
+ int main( int argc, char** argv ) {
+ TQApplication::setDesktopSettingsAware( FALSE ); // I know better than the user
+ TQApplication myApp( argc, argv ); // Use default fonts & colors
+ ...
+ }
+ \endcode
+
+ \sa desktopSettingsAware()
+*/
+
+void TQApplication::setDesktopSettingsAware( bool on )
+{
+ obey_desktop_settings = on;
+}
+
+/*!
+ Returns the value set by setDesktopSettingsAware(); by default TRUE.
+
+ \sa setDesktopSettingsAware()
+*/
+
+bool TQApplication::desktopSettingsAware()
+{
+ return obey_desktop_settings;
+}
+
+/*! \fn void TQApplication::lock()
+
+ Lock the TQt Library Mutex. If another thread has already locked the
+ mutex, the calling thread will block until the other thread has
+ unlocked the mutex.
+
+ \sa unlock() locked() \link threads.html Thread Support in TQt\endlink
+*/
+
+
+/*! \fn void TQApplication::unlock(bool wakeUpGui)
+
+ Unlock the TQt Library Mutex. If \a wakeUpGui is TRUE (the default),
+ then the GUI thread will be woken with TQApplication::wakeUpGuiThread().
+
+ \sa lock(), locked() \link threads.html Thread Support in TQt\endlink
+*/
+
+
+/*! \fn bool TQApplication::locked()
+
+ Returns TRUE if the TQt Library Mutex is locked by a different thread;
+ otherwise returns FALSE.
+
+ \warning Due to different implementations of recursive mutexes on
+ the supported platforms, calling this function from the same thread
+ that previously locked the mutex will give undefined results.
+
+ \sa lock() unlock() \link threads.html Thread Support in TQt\endlink
+*/
+
+/*! \fn bool TQApplication::tryLock()
+
+ Attempts to lock the TQt Library Mutex, and returns immediately. If
+ the lock was obtained, this function returns TRUE. If another thread
+ has locked the mutex, this function returns FALSE, instead of
+ waiting for the lock to become available.
+
+ The mutex must be unlocked with unlock() before another thread can
+ successfully lock it.
+
+ \sa lock(), unlock() \link threads.html Thread Support in TQt\endlink
+*/
+
+#if defined(TQT_THREAD_SUPPORT)
+void TQApplication::lock()
+{
+ qt_mutex->lock();
+}
+
+void TQApplication::unlock(bool wakeUpGui)
+{
+ qt_mutex->unlock();
+
+ if (wakeUpGui)
+ wakeUpGuiThread();
+}
+
+bool TQApplication::locked()
+{
+ return qt_mutex->locked();
+}
+
+bool TQApplication::tryLock()
+{
+ return qt_mutex->tryLock();
+}
+#endif
+
+
+/*!
+ \fn bool TQApplication::isSessionRestored() const
+
+ Returns TRUE if the application has been restored from an earlier
+ \link session.html session\endlink; otherwise returns FALSE.
+
+ \sa sessionId(), commitData(), saveState()
+*/
+
+
+/*!
+ \fn TQString TQApplication::sessionId() const
+
+ Returns the current \link session.html session's\endlink identifier.
+
+ If the application has been restored from an earlier session, this
+ identifier is the same as it was in that previous session.
+
+ The session identifier is guaranteed to be unique both for different
+ applications and for different instances of the same application.
+
+ \sa isSessionRestored(), sessionKey(), commitData(), saveState()
+ */
+
+/*!
+ \fn TQString TQApplication::sessionKey() const
+
+ Returns the session key in the current \link session.html
+ session\endlink.
+
+ If the application has been restored from an earlier session, this
+ key is the same as it was when the previous session ended.
+
+ The session key changes with every call of commitData() or
+ saveState().
+
+ \sa isSessionRestored(), sessionId(), commitData(), saveState()
+ */
+
+
+/*!
+ \fn void TQApplication::commitData( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the TQSessionManager wants the
+ application to commit all its data.
+
+ Usually this means saving all open files, after getting
+ permission from the user. Furthermore you may want to provide a means
+ by which the user can cancel the shutdown.
+
+ Note that you should not exit the application within this function.
+ Instead, the session manager may or may not do this afterwards,
+ depending on the context.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details and example
+ usage.
+
+ The default implementation requests interaction and sends a close
+ event to all visible top level widgets. If any event was
+ rejected, the shutdown is canceled.
+
+ \sa isSessionRestored(), sessionId(), saveState(), \link session.html the Session Management overview\endlink
+*/
+#ifndef TQT_NO_SESSIONMANAGER
+void TQApplication::commitData( TQSessionManager& sm )
+{
+
+ if ( sm.allowsInteraction() ) {
+ TQWidgetList done;
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ bool cancelled = FALSE;
+ TQWidget* w = list->first();
+ while ( !cancelled && w ) {
+ if ( !w->isHidden() ) {
+ TQCloseEvent e;
+ sendEvent( w, &e );
+ cancelled = !e.isAccepted();
+ if ( !cancelled )
+ done.append( w );
+ delete list; // one never knows...
+ list = TQApplication::tqtopLevelWidgets();
+ w = list->first();
+ } else {
+ w = list->next();
+ }
+ while ( w && done.tqcontainsRef( w ) )
+ w = list->next();
+ }
+ delete list;
+ if ( cancelled )
+ sm.cancel();
+ }
+}
+
+
+/*!
+ \fn void TQApplication::saveState( TQSessionManager& sm )
+
+ This function deals with \link session.html session
+ management\endlink. It is invoked when the
+ \link TQSessionManager session manager \endlink wants the application
+ to preserve its state for a future session.
+
+ For example, a text editor would create a temporary file that
+ includes the current contents of its edit buffers, the location of
+ the cursor and other aspects of the current editing session.
+
+ Note that you should never exit the application within this
+ function. Instead, the session manager may or may not do this
+ afterwards, depending on the context. Futhermore, most session
+ managers will very likely request a saved state immediately after
+ the application has been started. This permits the session manager
+ to learn about the application's restart policy.
+
+ \warning Within this function, no user interaction is possible, \e
+ unless you ask the session manager \a sm for explicit permission.
+ See TQSessionManager::allowsInteraction() and
+ TQSessionManager::allowsErrorInteraction() for details.
+
+ \sa isSessionRestored(), sessionId(), commitData(), \link session.html the Session Management overview\endlink
+*/
+
+void TQApplication::saveState( TQSessionManager& /* sm */ )
+{
+}
+#endif //TQT_NO_SESSIONMANAGER
+/*!
+ Sets the time after which a drag should start to \a ms ms.
+
+ \sa startDragTime()
+*/
+
+void TQApplication::setStartDragTime( int ms )
+{
+ drag_time = ms;
+}
+
+/*!
+ If you support drag and drop in you application and a drag should
+ start after a mouse click and after a certain time elapsed, you
+ should use the value which this method returns as the delay (in ms).
+
+ TQt also uses this delay internally, e.g. in TQTextEdit and TQLineEdit,
+ for starting a drag.
+
+ The default value is 500 ms.
+
+ \sa setStartDragTime(), startDragDistance()
+*/
+
+int TQApplication::startDragTime()
+{
+ return drag_time;
+}
+
+/*!
+ Sets the distance after which a drag should start to \a l pixels.
+
+ \sa startDragDistance()
+*/
+
+void TQApplication::setStartDragDistance( int l )
+{
+ drag_distance = l;
+}
+
+/*!
+ If you support drag and drop in you application and a drag should
+ start after a mouse click and after moving the mouse a certain
+ distance, you should use the value which this method returns as the
+ distance.
+
+ For example, if the mouse position of the click is stored in \c
+ startPos and the current position (e.g. in the mouse move event) is
+ \c currPos, you can tqfind out if a drag should be started with code
+ like this:
+ \code
+ if ( ( startPos - currPos ).manhattanLength() >
+ TQApplication::startDragDistance() )
+ startTheDrag();
+ \endcode
+
+ TQt uses this value internally, e.g. in TQFileDialog.
+
+ The default value is 4 pixels.
+
+ \sa setStartDragDistance(), startDragTime(), TQPoint::manhattanLength()
+*/
+
+int TQApplication::startDragDistance()
+{
+ return drag_distance;
+}
+
+/*!
+ If \a b is TRUE, all dialogs and widgets will be laid out in a
+ mirrored fashion, as required by right to left languages such as
+ Arabic and Hebrew. If \a b is FALSE, dialogs and widgets are laid
+ out left to right.
+
+ Changing this flag in runtime does not cause a retqlayout of already
+ instantiated widgets.
+
+ \sa reverseLayout()
+*/
+void TQApplication::setReverseLayout( bool b )
+{
+ if ( reverse_tqlayout == b )
+ return;
+
+ reverse_tqlayout = b;
+
+ TQWidgetList *list = tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ postEvent( w, new TQEvent( TQEvent::LayoutDirectionChange ) );
+ }
+ delete list;
+}
+
+/*!
+ Returns TRUE if all dialogs and widgets will be laid out in a
+ mirrored (right to left) fashion. Returns FALSE if dialogs and
+ widgets will be laid out left to right.
+
+ \sa setReverseLayout()
+*/
+bool TQApplication::reverseLayout()
+{
+ return reverse_tqlayout;
+}
+
+
+/*!
+ \class TQSessionManager tqsessionmanager.h
+ \brief The TQSessionManager class provides access to the session manager.
+
+ \ingroup application
+ \ingroup environment
+
+ The session manager is responsible for session management, most
+ importantly for interruption and resumption. A "session" is a kind
+ of record of the state of the system, e.g. which applications were
+ run at start up and which applications are currently running. The
+ session manager is used to save the session, e.g. when the machine
+ is shut down; and to restore a session, e.g. when the machine is
+ started up. Use TQSettings to save and restore an individual
+ application's settings, e.g. window positions, recently used files,
+ etc.
+
+ TQSessionManager provides an interface between the application and
+ the session manager so that the program can work well with the
+ session manager. In TQt, session management requests for action
+ are handled by the two virtual functions TQApplication::commitData()
+ and TQApplication::saveState(). Both provide a reference to
+ a session manager object as argument, to allow the application
+ to communicate with the session manager.
+
+ During a session management action (i.e. within commitData() and
+ saveState()), no user interaction is possible \e unless the
+ application got explicit permission from the session manager. You
+ ask for permission by calling allowsInteraction() or, if it's really
+ urgent, allowsErrorInteraction(). TQt does not enforce this, but the
+ session manager may.
+
+ You can try to abort the shutdown process by calling cancel(). The
+ default commitData() function does this if some top-level window
+ rejected its closeEvent().
+
+ For sophisticated session managers provided on Unix/X11, TQSessionManager
+ offers further possibilites to fine-tune an application's session
+ management behavior: setRestartCommand(), setDiscardCommand(),
+ setRestartHint(), setProperty(), requestPhase2(). See the respective
+ function descriptions for further details.
+*/
+
+/*! \enum TQSessionManager::RestartHint
+
+ This enum type defines the circumstances under which this
+ application wants to be restarted by the session manager. The
+ current values are
+
+ \value RestartIfRunning if the application is still running when
+ the session is shut down, it wants to be restarted at the start of
+ the next session.
+
+ \value RestartAnyway the application wants to be started at the
+ start of the next session, no matter what. (This is useful for
+ utilities that run just after startup and then quit.)
+
+ \value RestartImmediately the application wants to be started
+ immediately whenever it is not running.
+
+ \value RestartNever the application does not want to be restarted
+ automatically.
+
+ The default hint is \c RestartIfRunning.
+*/
+
+
+/*!
+ \fn TQString TQSessionManager::sessionId() const
+
+ Returns the identifier of the current session.
+
+ If the application has been restored from an earlier session, this
+ identifier is the same as it was in that earlier session.
+
+ \sa sessionKey(), TQApplication::sessionId()
+ */
+
+/*!
+ \fn TQString TQSessionManager::sessionKey() const
+
+ Returns the session key in the current session.
+
+ If the application has been restored from an earlier session, this
+ key is the same as it was when the previous session ended.
+
+ The session key changes with every call of commitData() or
+ saveState().
+
+ \sa sessionId(), TQApplication::sessionKey()
+ */
+
+// ### Note: This function is undocumented, since it is #ifdef'd.
+
+/*!
+ \fn void* TQSessionManager::handle() const
+
+ X11 only: returns a handle to the current \c SmcConnection.
+*/
+
+
+/*!
+ \fn bool TQSessionManager::allowsInteraction()
+
+ Asks the session manager for permission to interact with the
+ user. Returns TRUE if interaction is permitted; otherwise
+ returns FALSE.
+
+ The rationale behind this mechanism is to make it possible to
+ synchronize user interaction during a shutdown. Advanced session
+ managers may ask all applications simultaneously to commit their
+ data, resulting in a much faster shutdown.
+
+ When the interaction is completed we strongly recommend releasing the
+ user interaction semaphore with a call to release(). This way, other
+ applications may get the chance to interact with the user while your
+ application is still busy saving data. (The semaphore is implicitly
+ released when the application exits.)
+
+ If the user decides to cancel the shutdown process during the
+ interaction phase, you must tell the session manager that this has
+ happened by calling cancel().
+
+ Here's an example of how an application's TQApplication::commitData()
+ might be implemented:
+
+\code
+void MyApplication::commitData( TQSessionManager& sm ) {
+ if ( sm.allowsInteraction() ) {
+ switch ( TQMessageBox::warning(
+ yourMainWindow,
+ tr("Application Name"),
+ tr("Save changes to document Foo?"),
+ tr("&Yes"),
+ tr("&No"),
+ tr("Cancel"),
+ 0, 2) ) {
+ case 0: // yes
+ sm.release();
+ // save document here; if saving fails, call sm.cancel()
+ break;
+ case 1: // continue without saving
+ break;
+ default: // cancel
+ sm.cancel();
+ break;
+ }
+ } else {
+ // we did not get permission to interact, then
+ // do something reasonable instead.
+ }
+}
+\endcode
+
+ If an error occurred within the application while saving its data,
+ you may want to try allowsErrorInteraction() instead.
+
+ \sa TQApplication::commitData(), release(), cancel()
+*/
+
+
+/*!
+ \fn bool TQSessionManager::allowsErrorInteraction()
+
+ This is similar to allowsInteraction(), but also tells the session
+ manager that an error occurred. Session managers may give error
+ interaction request higher priority, which means that it is more likely
+ that an error interaction is permitted. However, you are still not
+ guaranteed that the session manager will allow interaction.
+
+ \sa allowsInteraction(), release(), cancel()
+*/
+
+/*!
+ \fn void TQSessionManager::release()
+
+ Releases the session manager's interaction semaphore after an
+ interaction phase.
+
+ \sa allowsInteraction(), allowsErrorInteraction()
+*/
+
+/*!
+ \fn void TQSessionManager::cancel()
+
+ Tells the session manager to cancel the shutdown process. Applications
+ should not call this function without first asking the user.
+
+ \sa allowsInteraction(), allowsErrorInteraction()
+
+*/
+
+/*!
+ \fn void TQSessionManager::setRestartHint( RestartHint hint )
+
+ Sets the application's restart hint to \a hint. On application
+ startup the hint is set to \c RestartIfRunning.
+
+ Note that these flags are only hints, a session manager may or may
+ not respect them.
+
+ We recommend setting the restart hint in TQApplication::saveState()
+ because most session managers perform a checkpoint shortly after an
+ application's startup.
+
+ \sa restartHint()
+*/
+
+/*!
+ \fn TQSessionManager::RestartHint TQSessionManager::restartHint() const
+
+ Returns the application's current restart hint. The default is
+ \c RestartIfRunning.
+
+ \sa setRestartHint()
+*/
+
+/*!
+ \fn void TQSessionManager::setRestartCommand( const TQStringList& command )
+
+ If the session manager is capable of restoring sessions it will
+ execute \a command in order to restore the application. The command
+ defaults to
+
+ \code
+ appname -session id
+ \endcode
+
+ The \c -session option is mandatory; otherwise TQApplication cannot
+ tell whether it has been restored or what the current session
+ identifier is. See TQApplication::isSessionRestored() and
+ TQApplication::sessionId() for details.
+
+ If your application is very simple, it may be possible to store the
+ entire application state in additional command line options. This
+ is usually a very bad idea because command lines are often limited
+ to a few hundred bytes. Instead, use TQSettings, or temporary files
+ or a database for this purpose. By marking the data with the unique
+ sessionId(), you will be able to restore the application in a future
+ session.
+
+ \sa restartCommand(), setDiscardCommand(), setRestartHint()
+*/
+
+/*!
+ \fn TQStringList TQSessionManager::restartCommand() const
+
+ Returns the currently set restart command.
+
+ Note that if you want to iterate over the list, you should
+ iterate over a copy, e.g.
+ \code
+ TQStringList list = mySession.restartCommand();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa setRestartCommand(), restartHint()
+*/
+
+/*!
+ \fn void TQSessionManager::setDiscardCommand( const TQStringList& )
+
+ \sa discardCommand(), setRestartCommand()
+*/
+
+
+/*!
+ \fn TQStringList TQSessionManager::discardCommand() const
+
+ Returns the currently set discard command.
+
+ Note that if you want to iterate over the list, you should
+ iterate over a copy, e.g.
+ \code
+ TQStringList list = mySession.discardCommand();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa setDiscardCommand(), restartCommand(), setRestartCommand()
+*/
+
+/*!
+ \overload void TQSessionManager::setManagerProperty( const TQString& name,
+ const TQString& value )
+
+ Low-level write access to the application's identification and state
+ records are kept in the session manager.
+
+ The property called \a name has its value set to the string \a value.
+*/
+
+/*!
+ \fn void TQSessionManager::setManagerProperty( const TQString& name,
+ const TQStringList& value )
+
+ Low-level write access to the application's identification and state
+ record are kept in the session manager.
+
+ The property called \a name has its value set to the string list \a value.
+*/
+
+/*!
+ \fn bool TQSessionManager::isPhase2() const
+
+ Returns TRUE if the session manager is currently performing a second
+ session management phase; otherwise returns FALSE.
+
+ \sa requestPhase2()
+*/
+
+/*!
+ \fn void TQSessionManager::requestPhase2()
+
+ Requests a second session management phase for the application. The
+ application may then return immediately from the
+ TQApplication::commitData() or TQApplication::saveState() function,
+ and they will be called again once most or all other applications have
+ finished their session management.
+
+ The two phases are useful for applications such as the X11 window manager
+ that need to store information about another application's windows
+ and therefore have to wait until these applications have completed their
+ respective session management tasks.
+
+ Note that if another application has requested a second phase it
+ may get called before, simultaneously with, or after your
+ application's second phase.
+
+ \sa isPhase2()
+*/
+
+/*!
+ \fn int TQApplication::horizontalAlignment( int align )
+
+ Strips out vertical tqalignment flags and transforms an
+ tqalignment \a align of AlignAuto into AlignLeft or
+ AlignRight according to the language used. The other horizontal
+ tqalignment flags are left untouched.
+*/
+
+
+/*****************************************************************************
+ Stubbed session management support
+ *****************************************************************************/
+#ifndef TQT_NO_SESSIONMANAGER
+#if defined( TQT_NO_SM_SUPPORT ) || defined( TQ_WS_WIN ) || defined( TQ_WS_MAC ) || defined( TQ_WS_TQWS )
+
+class TQSessionManagerData
+{
+public:
+ TQStringList restartCommand;
+ TQStringList discardCommand;
+ TQString sessionId;
+ TQString sessionKey;
+ TQSessionManager::RestartHint restartHint;
+};
+
+TQSessionManager* qt_session_manager_self = 0;
+TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString &key )
+ : TQObject( app, "qt_sessionmanager" )
+{
+ qt_session_manager_self = this;
+ d = new TQSessionManagerData;
+#if defined(TQ_WS_WIN) && !defined(TQ_OS_TEMP)
+ wchar_t guidstr[40];
+ GUID guid;
+ CoCreateGuid( &guid );
+ StringFromGUID2(guid, guidstr, 40);
+ id = TQString::fromUcs2((ushort*)guidstr);
+ CoCreateGuid( &guid );
+ StringFromGUID2(guid, guidstr, 40);
+ key = TQString::fromUcs2((ushort*)guidstr);
+#endif
+ d->sessionId = id;
+ d->sessionKey = key;
+ d->restartHint = RestartIfRunning;
+}
+
+TQSessionManager::~TQSessionManager()
+{
+ delete d;
+ qt_session_manager_self = 0;
+}
+
+TQString TQSessionManager::sessionId() const
+{
+ return d->sessionId;
+}
+
+TQString TQSessionManager::sessionKey() const
+{
+ return d->sessionKey;
+}
+
+
+#if defined(TQ_WS_X11) || defined(TQ_WS_MAC)
+void* TQSessionManager::handle() const
+{
+ return 0;
+}
+#endif
+
+#if !defined(TQ_WS_WIN)
+bool TQSessionManager::allowsInteraction()
+{
+ return TRUE;
+}
+
+bool TQSessionManager::allowsErrorInteraction()
+{
+ return TRUE;
+}
+void TQSessionManager::release()
+{
+}
+
+void TQSessionManager::cancel()
+{
+}
+#endif
+
+
+void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint)
+{
+ d->restartHint = hint;
+}
+
+TQSessionManager::RestartHint TQSessionManager::restartHint() const
+{
+ return d->restartHint;
+}
+
+void TQSessionManager::setRestartCommand( const TQStringList& command)
+{
+ d->restartCommand = command;
+}
+
+TQStringList TQSessionManager::restartCommand() const
+{
+ return d->restartCommand;
+}
+
+void TQSessionManager::setDiscardCommand( const TQStringList& command)
+{
+ d->discardCommand = command;
+}
+
+TQStringList TQSessionManager::discardCommand() const
+{
+ return d->discardCommand;
+}
+
+void TQSessionManager::setManagerProperty( const TQString&, const TQString&)
+{
+}
+
+void TQSessionManager::setManagerProperty( const TQString&, const TQStringList& )
+{
+}
+
+bool TQSessionManager::isPhase2() const
+{
+ return FALSE;
+}
+
+void TQSessionManager::requestPhase2()
+{
+}
+
+#endif // TQT_NO_SM_SUPPORT
+#endif //TQT_NO_SESSIONMANAGER
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqapplication.h b/tqtinterface/qt4/src/kernel/tqapplication.h
new file mode 100644
index 0000000..2be7c02
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqapplication.h
@@ -0,0 +1,724 @@
+/****************************************************************************
+**
+** Definition of TQApplication class
+**
+** Created : 931107
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQAPPLICATION_H
+#define TQAPPLICATION_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqdesktopwidget.h"
+#include "tqasciidict.h"
+#include "tqpalette.h"
+#include "tqtranslator.h"
+#include "tqstrlist.h"
+#include "tqstringlist.h"
+#include "tqwidgetlist.h"
+#include "tqclipboard.h"
+#include "tqcursor.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include "private/qt4_qapplication_p.h"
+#include <Qt/qapplication.h>
+#include <Qt/qstyle.h>
+
+#endif // USE_QT4
+
+class TQSessionManager;
+class TQStyle;
+class TQTranslator;
+class TQEventLoop;
+#if defined(TQ_WS_TQWS)
+class TQWSDecoration;
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+class TQMutex;
+#endif // TQT_THREAD_SUPPORT
+
+#ifdef USE_QT4
+
+#define TQAPPLICATION_GUI_VAR_INIT if (( QApplication::type() != QApplication::GuiClient ) && ( QApplication::type() != QApplication::GuiServer )) { qt_is_gui_used = FALSE; } else { qt_is_gui_used = TRUE; } tqAppReal = static_cast<TQApplication*>(qApp);
+#define TQAPPLICATION_GUI_CONDITIONAL_VAR_INIT if (GUIenabled == false) { qt_is_gui_used = FALSE; } else { qt_is_gui_used = TRUE; } tqAppReal = static_cast<TQApplication*>(qApp);
+#define TQAPPLICATION_XORG_FULL_INIT if (qt_is_gui_used == true) { qt_init( dpy, visual, cmap ); }
+#define TQAPPLICATION_XORG_PARTIAL_INIT qt_init( &argc, argv, t );
+#define TQAPPLICATION_XORG_CONDITIONAL_INIT if (GUIenabled == true) { qt_init( &argc, argv, QApplication::GuiClient ); }
+#define TQAPPLICATION_REGISTER_TQ_DATATYPES qRegisterMetaType<TQChar>("TQChar"); \
+ qRegisterMetaType<TQString>("TQString"); \
+ qRegisterMetaType<TQColor>("TQColor");
+
+class TQApplication;
+extern TQ_EXPORT TQApplication *tqAppReal; // global application object
+#define tqApp tqAppReal
+
+class TQ_EXPORT TQApplication : public QApplication, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQApplication( int &argc, char **argv );
+ TQApplication( int &argc, char **argv, bool GUIenabled );
+ TQApplication( int &argc, char **argv, Type t );
+#if defined(TQ_WS_X11)
+ TQApplication( Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0 );
+ TQApplication( Display *dpy, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0 );
+#endif
+
+#ifndef Q_QDOC
+ enum ColorMode { NormalColors, CustomColors };
+ static ColorMode colorMode();
+ static void setColorMode( TQApplication::ColorMode );
+#endif
+
+ int exec();
+
+ const char *tqname() const;
+ const char *name() const;
+ const char *name(const char *defaultName) const;
+ void setName(const char *aName);
+
+ virtual void commitData( TQSessionManager& sm );
+ virtual void saveState( TQSessionManager& sm );
+
+ // Qt4 session manager interconnect
+ virtual void commitData( QSessionManager& sm );
+ virtual void saveState( QSessionManager& sm );
+
+ static void exit_loop();
+ static int enter_loop();
+ static void processOneEvent();
+ void tqprocessEvents();
+ void tqprocessEvents( int maxtime );
+ int loopLevel() const;
+ static void flushX();
+ TQWidget *tqfocusWidget() const;
+ static TQWidget *widgetAt( const TQPoint &p, bool child=FALSE );
+ static TQWidget *widgetAt( int x, int y, bool child=FALSE );
+ static int horizontalAlignment( int align );
+
+ static void sendPostedEvents( QObject *receiver, int event_type );
+ static void sendPostedEvents();
+
+#ifndef TQT_NO_CURSOR
+// static void setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE );
+ static void setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE );
+#endif
+
+ static void setReverseLayout(bool b);
+ static bool reverseLayout();
+
+ static TQPalette tqpalette( const TQWidget*w = 0 );
+
+ static TQWidgetList *tqtopLevelWidgets();
+
+ static TQEventLoop *eventLoop();
+
+ static TQStyle &tqstyle();
+ static void setStyle( TQStyle* );
+ static TQStyle* setStyle( const TQString& );
+
+ static TQDesktopWidget *desktop();
+ static const QColor &winStyleHighlightColor();
+ static void tqsetPalette(const QPalette &pal, bool informWidgets=FALSE, const char* className = 0);
+ static void tqsetFont(const QFont &font, bool informWidgets=FALSE, const char* className = 0);
+ static void setWinStyleHighlightColor( const QColor c );
+#ifndef TQT_NO_CLIPBOARD
+// static inline TQClipboard *tqclipboard() { return TQT_TQCLIPBOARD(clipboard()); }
+ static TQClipboard *tqclipboard();
+#endif
+
+ static TQStringList libraryPaths();
+ static void tqsetLibraryPaths( const QStringList &qsl );
+// inline static void tqsetLibraryPaths( const TQStringList &tqsl ) { setLibraryPaths(static_cast<const QStringList*>(&tqsl)); }
+
+ static TQWidgetList *tqallWidgets();
+
+ virtual void polish( QWidget * );
+
+ TQMetaObject *tqmetaObject() const;
+
+ static bool hasGlobalMouseTracking();
+ static void setGlobalMouseTracking( bool enable );
+
+Q_SIGNALS:
+ void guiThreadAwake(); // Does not exist in Qt4; therefore will never be triggered
+
+public:
+ TQWidget *mainWidget();
+ void setMainWidget(QWidget *);
+
+ // [FIXME]
+#if defined(TQ_WS_X11)
+ static void create_xim();
+ static void close_xim();
+ static bool x11_apply_settings();
+#endif
+#ifndef TQT_NO_TRANSLATION
+#ifndef TQT_NO_TEXTCODEC
+ void setDefaultCodec( TQTextCodec * );
+ TQTextCodec* defaultCodec() const;
+#endif
+// void installTranslator( TQTranslator * );
+// void removeTranslator( TQTranslator * );
+#endif
+
+ void wakeUpGuiThread();
+#ifdef TQT_THREAD_SUPPORT
+ void lock();
+ void unlock(bool wakeUpGui = TRUE);
+ bool locked();
+ bool tryLock();
+#endif
+
+public slots:
+ void aboutTQt();
+
+private:
+ static TQEventLoop* eventloop; // Will this work as-is or do I need code behind it?
+ static int app_cspec;
+ static TQStyle *app_style;
+#ifndef TQT_NO_PALETTE
+ static TQPalette *app_pal;
+#endif
+ static TQPtrList<QEventLoop> tqt_event_loop_stack;
+ static TQWidgetList tqt_all_widgets_list;
+ static QWidget* current_app_main_widget;
+ mutable TQString static_object_name;
+ friend class TQWidget;
+ friend class TQETWidget;
+ friend class TQDialog;
+ friend class TQAccelManager;
+ friend class TQEvent;
+ friend class TQTranslator;
+ friend class TQEventLoop;
+ friend TQ_EXPORT void qt_ucm_initialize( TQApplication * );
+#if defined(TQ_WS_WIN)
+ friend bool qt_sendSpontaneousEvent( TQObject*, TQEvent* );
+#endif
+#if defined(TQ_WS_TQWS)
+ friend class TQInputContext;
+#endif
+
+ friend void qt_init(int *, char **, TQApplication::Type);
+
+#ifdef TQT_THREAD_SUPPORT
+ static TQMutex *qt_mutex;
+#endif // TQT_THREAD_SUPPORT
+
+public:
+ static int composedUnicode; // Value, meta-composed character
+ static bool metaComposeUnicode;
+
+protected:
+ inline bool event(QEvent *e) { TQT_TQOBJECT_CHILDEVENT_REQUIRED_HANDLER(e) return QApplication::event(e); }
+};
+
+#else // USE_QT4
+
+class TQApplication;
+extern TQ_EXPORT TQApplication *tqApp; // global application object
+
+
+class TQ_EXPORT TQApplication : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQApplication( int &argc, char **argv );
+ TQApplication( int &argc, char **argv, bool GUIenabled );
+ enum Type { Tty, GuiClient, GuiServer };
+ TQApplication( int &argc, char **argv, Type );
+#if defined(TQ_WS_X11)
+ TQApplication( Display* dpy, HANDLE visual = 0, HANDLE cmap = 0 );
+ TQApplication( Display *dpy, int argc, char **argv,
+ HANDLE visual = 0, HANDLE cmap= 0 );
+#endif
+ virtual ~TQApplication();
+
+ int argc() const;
+ char **argv() const;
+
+ Type type() const;
+
+#ifndef TQT_NO_STYLE
+ static TQStyle &tqstyle();
+ static void setStyle( TQStyle* );
+ static TQStyle* setStyle( const TQString& );
+#endif
+#ifndef TQ_TQDOC
+ enum ColorMode { NormalColors, CustomColors };
+ static ColorMode colorMode();
+ static void setColorMode( TQApplication::ColorMode );
+#endif
+
+ enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
+ static int colorSpec();
+ static void setColorSpec( int );
+#ifndef TQT_NO_CURSOR
+ static TQCursor *overrideCursor();
+ static void setOverrideCursor( const TQCursor &, bool tqreplace=FALSE );
+ static void restoreOverrideCursor();
+#endif
+ static bool hasGlobalMouseTracking();
+ static void setGlobalMouseTracking( bool enable );
+#ifndef TQT_NO_PALETTE
+ static TQPalette palette( const TQWidget* = 0 );
+ static void setPalette( const TQPalette &, bool informWidgets=FALSE,
+ const char* className = 0 );
+#endif
+ static TQFont font( const TQWidget* = 0 );
+ static void setFont( const TQFont &, bool informWidgets=FALSE,
+ const char* className = 0 );
+ static TQFontMetrics fontMetrics();
+
+ TQWidget *mainWidget() const;
+ virtual void setMainWidget( TQWidget * );
+ virtual void polish( TQWidget * );
+
+ static TQWidgetList *allWidgets();
+ static TQWidgetList *tqtopLevelWidgets();
+
+ static TQDesktopWidget *desktop();
+
+ static TQWidget *activePopupWidget();
+ static TQWidget *activeModalWidget();
+#ifndef TQT_NO_CLIPBOARD
+ static TQClipboard *clipboard();
+#endif
+ TQWidget *tqfocusWidget() const;
+ TQWidget *activeWindow() const;
+
+ static TQWidget *widgetAt( int x, int y, bool child=FALSE );
+ static TQWidget *widgetAt( const TQPoint &, bool child=FALSE );
+
+ static TQEventLoop *eventLoop();
+
+ int exec();
+ void processEvents();
+ void processEvents( int maxtime );
+ void processOneEvent();
+ bool hasPendingEvents();
+ int enter_loop();
+ void exit_loop();
+ int loopLevel() const;
+ static void exit( int retcode=0 );
+
+ static bool sendEvent( TQObject *receiver, TQEvent *event );
+ static void postEvent( TQObject *receiver, TQEvent *event );
+ static void sendPostedEvents( TQObject *receiver, int event_type );
+ static void sendPostedEvents();
+
+ static void removePostedEvents( TQObject *receiver );
+
+ virtual bool notify( TQObject *, TQEvent * );
+
+ static bool startingUp();
+ static bool closingDown();
+
+ static void flushX();
+ static void flush();
+ static void syncX();
+
+ static void beep();
+
+#ifndef TQT_NO_TRANSLATION
+# ifndef TQT_NO_TEXTCODEC
+ void setDefaultCodec( TQTextCodec * );
+ TQTextCodec* defaultCodec() const;
+# endif
+ void installTranslator( TQTranslator * );
+ void removeTranslator( TQTranslator * );
+#endif
+ enum Encoding { DefaultCodec, UnicodeUTF8 };
+ TQString translate( const char * context,
+ const char * key,
+ const char * comment = 0,
+ Encoding encoding = DefaultCodec ) const;
+#ifndef TQT_NO_DIR
+ TQString applicationDirPath();
+ TQString applicationFilePath();
+#endif
+#ifndef TQT_NO_PALETTE
+ // obsolete functions
+ static void setWinStyleHighlightColor( const TQColor &c ) {
+ TQPalette p( palette() );
+ p.setColor( TQColorGroup::Highlight, c );
+ setPalette( p, TRUE);
+ }
+ static const TQColor &winStyleHighlightColor() {
+ return palette().active().highlight();
+ }
+#endif
+ static void setDesktopSettingsAware( bool );
+ static bool desktopSettingsAware();
+
+ static void setCursorFlashTime( int );
+ static int cursorFlashTime();
+
+ static void setDoubleClickInterval( int );
+ static int doubleClickInterval();
+#ifndef TQT_NO_WHEELEVENT
+ static void setWheelScrollLines( int );
+ static int wheelScrollLines();
+#endif
+ static void setGlobalStrut( const TQSize & );
+ static TQSize globalStrut();
+
+#ifndef TQT_NO_COMPONENT
+ static void tqsetLibraryPaths( const TQStringList & );
+ static TQStringList libraryPaths();
+ static void addLibraryPath( const TQString & );
+ static void removeLibraryPath( const TQString & );
+#endif // TQT_NO_COMPONENT
+ static void setStartDragTime( int ms );
+ static int startDragTime();
+ static void setStartDragDistance( int l );
+ static int startDragDistance();
+
+ static void setReverseLayout( bool b );
+ static bool reverseLayout();
+
+ static int horizontalAlignment( int align );
+
+ static bool isEffectEnabled( TQt::UIEffect );
+ static void setEffectEnabled( TQt::UIEffect, bool enable = TRUE );
+
+#if defined(TQ_WS_MAC)
+ virtual bool macEventFilter( EventHandlerCallRef, EventRef );
+#endif
+#if defined(TQ_WS_WIN)
+ virtual bool winEventFilter( MSG * );
+#endif
+#if defined(TQ_WS_X11)
+ virtual bool x11EventFilter( XEvent * );
+ virtual int x11ClientMessage( TQWidget*, XEvent*, bool passive_only);
+ int x11ProcessEvent( XEvent* );
+#endif
+#if defined(TQ_WS_TQWS)
+ virtual bool qwsEventFilter( TQWSEvent * );
+ int qwsProcessEvent( TQWSEvent* );
+ void qwsSetCustomColors( TQRgb *colortable, int start, int numColors );
+/*!
+ \internal
+ Returns true if the process is GUI server
+*/
+ bool qwsIsGUIServer();
+#ifndef TQT_NO_TQWS_MANAGER
+ static TQWSDecoration &qwsDecoration();
+ static void qwsSetDecoration( TQWSDecoration *);
+#endif
+#endif
+
+#if defined(TQ_OS_WIN32) || defined(TQ_OS_CYGWIN)
+ static WindowsVersion winVersion();
+#elif defined(TQ_OS_MAC)
+ static MacintoshVersion macVersion();
+#endif
+#if defined(TQ_WS_WIN)
+ void winFocus( TQWidget *, bool );
+ static void winMouseButtonUp();
+#endif
+
+#ifndef TQT_NO_SESSIONMANAGER
+ // session management
+ bool isSessionRestored() const;
+ TQString sessionId() const;
+ TQString sessionKey() const;
+ virtual void commitData( TQSessionManager& sm );
+ virtual void saveState( TQSessionManager& sm );
+#endif
+#if defined(TQ_WS_X11)
+ static void create_xim();
+ static void close_xim();
+ static bool x11_apply_settings();
+#endif
+ void wakeUpGuiThread();
+#if defined(TQT_THREAD_SUPPORT)
+ void lock();
+ void unlock(bool wakeUpGui = TRUE);
+ bool locked();
+ bool tryLock();
+#endif
+
+Q_SIGNALS:
+ void lastWindowClosed();
+ void aboutToQuit();
+ void guiThreadAwake();
+
+public Q_SLOTS:
+ void quit();
+ void closeAllWindows();
+ void aboutTQt();
+
+#if defined(TQ_WS_TQWS)
+protected:
+ void setArgs(int, char **);
+#endif
+
+protected:
+ bool event(TQEvent *);
+
+private:
+ void construct( int &argc, char **argv, Type );
+ void initialize( int, char ** );
+ void init_precmdline();
+ void process_cmdline( int* argcptr, char ** argv );
+ bool internalNotify( TQObject *, TQEvent * );
+#if defined(TQ_WS_TQWS)
+ static TQWidget *tqfindChildWidget( const TQWidget *p, const TQPoint &pos );
+ static TQWidget *tqfindWidget( const TQObjectList&, const TQPoint &, bool rec );
+#endif
+
+#if defined(TQ_WS_MAC)
+ bool do_mouse_down(Point *, bool *);
+ static TQMAC_PASCAL OStqStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *);
+ static TQMAC_PASCAL OStqStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long);
+ static TQMAC_PASCAL void qt_context_timer_callbk(EventLoopTimerRef, void *);
+ static TQMAC_PASCAL void qt_select_timer_callbk(EventLoopTimerRef, void *);
+ static bool qt_mac_apply_settings();
+ friend class TQMacInputMethod;
+ friend TQMAC_PASCAL OStqStatus qt_window_event(EventHandlerCallRef, EventRef, void *);
+ friend void qt_mac_update_os_settings();
+ friend bool qt_set_socket_handler( int, int, TQObject *, bool);
+ friend void qt_mac_destroy_widget(TQWidget *);
+ friend void qt_init(int *, char **, TQApplication::Type);
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+ static TQMutex *qt_mutex;
+#endif // TQT_THREAD_SUPPORT
+
+ int app_argc;
+ char **app_argv;
+ bool quit_now;
+ int quit_code;
+ static TQStyle *app_style;
+ static int app_cspec;
+#ifndef TQT_NO_PALETTE
+ static TQPalette *app_pal;
+#endif
+ static TQFont *app_font;
+#ifndef TQT_NO_CURSOR
+ static TQCursor *app_cursor;
+#endif
+ static TQEventLoop* eventloop;
+ static int app_tracking;
+ static bool is_app_running;
+ static bool is_app_closing;
+ static bool app_exit_loop;
+ static int loop_level;
+ static TQWidget *main_widget;
+ static TQWidget *focus_widget;
+ static TQWidget *active_window;
+ static bool obey_desktop_settings;
+ static int cursor_flash_time;
+ static int mouse_double_click_time;
+ static int wheel_scroll_lines;
+ static int composedUnicode; // Value, meta-composed character
+
+ static bool animate_ui;
+ static bool animate_menu;
+ static bool animate_tooltip;
+ static bool animate_combo;
+ static bool fade_menu;
+ static bool fade_tooltip;
+ static bool animate_toolbox;
+ static bool widgetCount; // Coupled with -widgetcount switch
+ static bool metaComposeUnicode;
+
+ TQValueList<TQTranslator*> *translators;
+#ifndef TQT_NO_SESSIONMANAGER
+ TQSessionManager *session_manager;
+ TQString session_id;
+ static TQString* session_key;
+ bool is_session_restored;
+#endif
+#if defined(TQ_WS_X11) && !defined (TQT_NO_STYLE )
+ static void x11_initialize_style();
+#endif
+
+ static TQSize app_strut;
+#ifndef TQT_NO_COMPONENT
+ static TQStringList *app_libpaths;
+#endif
+ static TQAsciiDict<TQPalette> *app_palettes;
+ static TQAsciiDict<TQFont> *app_fonts;
+
+ static TQWidgetList *popupWidgets;
+ bool inPopupMode() const;
+ void closePopup( TQWidget *popup );
+ void openPopup( TQWidget *popup );
+ void setActiveWindow( TQWidget* act );
+
+ static bool sendSpontaneousEvent( TQObject *receiver, TQEvent *event );
+ static void removePostedEvent( TQEvent * );
+
+ friend class TQWidget;
+ friend class TQETWidget;
+ friend class TQDialog;
+ friend class TQAccelManager;
+ friend class TQEvent;
+ friend class TQTranslator;
+ friend class TQEventLoop;
+ friend TQ_EXPORT void qt_ucm_initialize( TQApplication * );
+#if defined(TQ_WS_WIN)
+ friend bool qt_sendSpontaneousEvent( TQObject*, TQEvent* );
+#endif
+#if defined(TQ_WS_TQWS)
+ friend class TQInputContext;
+#endif
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQApplication( const TQApplication & );
+ TQApplication &operator=( const TQApplication & );
+#endif
+};
+
+inline int TQApplication::argc() const
+{
+ return app_argc;
+}
+
+inline char **TQApplication::argv() const
+{
+ return app_argv;
+}
+
+#if defined(TQ_WS_TQWS)
+inline void TQApplication::setArgs(int c, char **v)
+{
+ app_argc = c;
+ app_argv = v;
+}
+#endif
+
+#ifndef TQT_NO_CURSOR
+inline TQCursor *TQApplication::overrideCursor()
+{
+ return app_cursor;
+}
+#endif
+inline bool TQApplication::hasGlobalMouseTracking()
+{
+ return app_tracking > 0;
+}
+
+inline TQWidget *TQApplication::mainWidget() const
+{
+ return main_widget;
+}
+
+inline TQWidget *TQApplication::tqfocusWidget() const
+{
+ return focus_widget;
+}
+
+inline TQWidget *TQApplication::activeWindow() const
+{
+ return active_window;
+}
+
+inline TQWidget *TQApplication::widgetAt( const TQPoint &p, bool child )
+{
+ return widgetAt( p.x(), p.y(), child );
+}
+
+inline bool TQApplication::inPopupMode() const
+{
+ return popupWidgets != 0;
+}
+#ifndef TQT_NO_SESSIONMANAGER
+inline bool TQApplication::isSessionRestored() const
+{
+ return is_session_restored;
+}
+
+inline TQString TQApplication::sessionId() const
+{
+ return session_id;
+}
+
+inline TQString TQApplication::sessionKey() const
+{
+ return session_key ? *session_key : TQString::null;
+}
+#endif
+inline TQSize TQApplication::globalStrut()
+{
+ return app_strut;
+}
+
+inline bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event )
+{ if ( event ) event->spont = FALSE; return tqApp ? tqApp->notify( receiver, event ) : FALSE; }
+
+inline bool TQApplication::sendSpontaneousEvent( TQObject *receiver, TQEvent *event )
+{ if ( event ) event->spont = TRUE; return tqApp ? tqApp->notify( receiver, event ) : FALSE; }
+
+#ifdef TQT_NO_TRANSLATION
+// Simple versions
+inline TQString TQApplication::translate( const char *, const char *sourceText,
+ const char *, Encoding encoding ) const
+{
+#ifndef TQT_NO_TEXTCODEC
+ if ( encoding == UnicodeUTF8 )
+ return TQString::fromUtf8( sourceText );
+ else
+#endif
+ return TQString::tqfromLatin1( sourceText );
+}
+#endif
+
+inline int TQApplication::horizontalAlignment( int align )
+{
+ align &= AlignHorizontal_Mask;
+ if ( align == AlignAuto ) {
+ if ( reverseLayout() )
+ align = AlignRight;
+ else
+ align = AlignLeft;
+ }
+ return align;
+}
+
+#endif // TQAPPLICATION_H
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqapplication.h~ b/tqtinterface/qt4/src/kernel/tqapplication.h~
new file mode 100644
index 0000000..44acad5
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqapplication.h~
@@ -0,0 +1,724 @@
+/****************************************************************************
+**
+** Definition of TQApplication class
+**
+** Created : 931107
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQAPPLICATION_H
+#define TQAPPLICATION_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqdesktopwidget.h"
+#include "tqasciidict.h"
+#include "tqpalette.h"
+#include "tqtranslator.h"
+#include "tqstrlist.h"
+#include "tqstringlist.h"
+#include "tqwidgetlist.h"
+#include "tqclipboard.h"
+#include "tqcursor.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include "private/qt4_qapplication_p.h"
+#include <Qt/qapplication.h>
+#include <Qt/qstyle.h>
+
+#endif // USE_QT4
+
+class TQSessionManager;
+class TQStyle;
+class TQTranslator;
+class TQEventLoop;
+#if defined(TQ_WS_TQWS)
+class TQWSDecoration;
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+class TQMutex;
+#endif // TQT_THREAD_SUPPORT
+
+#ifdef USE_QT4
+
+#define TQAPPLICATION_GUI_VAR_INIT if (( QApplication::type() != QApplication::GuiClient ) && ( QApplication::type() != QApplication::GuiServer )) { qt_is_gui_used = FALSE; } else { qt_is_gui_used = TRUE; } tqAppReal = static_cast<TQApplication*>(qApp);
+#define TQAPPLICATION_GUI_CONDITIONAL_VAR_INIT if (GUIenabled == false) { qt_is_gui_used = FALSE; } else { qt_is_gui_used = TRUE; } tqAppReal = static_cast<TQApplication*>(qApp);
+#define TQAPPLICATION_XORG_FULL_INIT if (qt_is_gui_used == true) { qt_init( dpy, visual, cmap ); }
+#define TQAPPLICATION_XORG_PARTIAL_INIT qt_init( &argc, argv, t );
+#define TQAPPLICATION_XORG_CONDITIONAL_INIT if (GUIenabled == true) { qt_init( &argc, argv, QApplication::GuiClient ); }
+#define TQAPPLICATION_REGISTER_TQ_DATATYPES qRegisterMetaType<TQChar>("TQChar"); \
+ qRegisterMetaType<TQString>("TQString"); \
+ qRegisterMetaType<TQColor>("TQColor");
+
+class TQApplication;
+extern TQ_EXPORT TQApplication *tqAppReal; // global application object
+#define tqApp tqAppReal
+
+class TQ_EXPORT TQApplication : public QApplication, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQApplication( int &argc, char **argv );
+ TQApplication( int &argc, char **argv, bool GUIenabled );
+ TQApplication( int &argc, char **argv, Type t );
+#if defined(TQ_WS_X11)
+ TQApplication( Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0 );
+ TQApplication( Display *dpy, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0 );
+#endif
+
+#ifndef Q_QDOC
+ enum ColorMode { NormalColors, CustomColors };
+ static ColorMode colorMode();
+ static void setColorMode( TQApplication::ColorMode );
+#endif
+
+ int exec();
+
+ const char *tqname() const;
+ const char *name() const;
+ const char *name(const char *defaultName) const;
+ void setName(const char *aName);
+
+ virtual void commitData( TQSessionManager& sm );
+ virtual void saveState( TQSessionManager& sm );
+
+ // Qt4 session manager interconnect
+ virtual void commitData( QSessionManager& sm );
+ virtual void saveState( QSessionManager& sm );
+
+ static void exit_loop();
+ static int enter_loop();
+ static void processOneEvent();
+ void tqprocessEvents();
+ void tqprocessEvents( int maxtime );
+ int loopLevel() const;
+ static void flushX();
+ TQWidget *tqfocusWidget() const;
+ static TQWidget *widgetAt( const TQPoint &p, bool child=FALSE );
+ static TQWidget *widgetAt( int x, int y, bool child=FALSE );
+ static int horizontalAlignment( int align );
+
+ inline static void sendPostedEvents( QObject *receiver, int event_type );
+ inline static void sendPostedEvents();
+
+#ifndef TQT_NO_CURSOR
+// static void setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE );
+ static void setOverrideCursor( const QCursor &cur, bool tqreplace=FALSE );
+#endif
+
+ static void setReverseLayout(bool b);
+ static bool reverseLayout();
+
+ static TQPalette tqpalette( const TQWidget*w = 0 );
+
+ static TQWidgetList *tqtopLevelWidgets();
+
+ static TQEventLoop *eventLoop();
+
+ static TQStyle &tqstyle();
+ static void setStyle( TQStyle* );
+ static TQStyle* setStyle( const TQString& );
+
+ static TQDesktopWidget *desktop();
+ static const QColor &winStyleHighlightColor();
+ static void tqsetPalette(const QPalette &pal, bool informWidgets=FALSE, const char* className = 0);
+ static void tqsetFont(const QFont &font, bool informWidgets=FALSE, const char* className = 0);
+ static void setWinStyleHighlightColor( const QColor c );
+#ifndef TQT_NO_CLIPBOARD
+// static inline TQClipboard *tqclipboard() { return TQT_TQCLIPBOARD(clipboard()); }
+ static TQClipboard *tqclipboard();
+#endif
+
+ static TQStringList libraryPaths();
+ static void tqsetLibraryPaths( const QStringList &qsl );
+// inline static void tqsetLibraryPaths( const TQStringList &tqsl ) { setLibraryPaths(static_cast<const QStringList*>(&tqsl)); }
+
+ static TQWidgetList *tqallWidgets();
+
+ virtual void polish( QWidget * );
+
+ TQMetaObject *tqmetaObject() const;
+
+ static bool hasGlobalMouseTracking();
+ static void setGlobalMouseTracking( bool enable );
+
+Q_SIGNALS:
+ void guiThreadAwake(); // Does not exist in Qt4; therefore will never be triggered
+
+public:
+ TQWidget *mainWidget();
+ void setMainWidget(QWidget *);
+
+ // [FIXME]
+#if defined(TQ_WS_X11)
+ static void create_xim();
+ static void close_xim();
+ static bool x11_apply_settings();
+#endif
+#ifndef TQT_NO_TRANSLATION
+#ifndef TQT_NO_TEXTCODEC
+ void setDefaultCodec( TQTextCodec * );
+ TQTextCodec* defaultCodec() const;
+#endif
+// void installTranslator( TQTranslator * );
+// void removeTranslator( TQTranslator * );
+#endif
+
+ void wakeUpGuiThread();
+#ifdef TQT_THREAD_SUPPORT
+ void lock();
+ void unlock(bool wakeUpGui = TRUE);
+ bool locked();
+ bool tryLock();
+#endif
+
+public slots:
+ void aboutTQt();
+
+private:
+ static TQEventLoop* eventloop; // Will this work as-is or do I need code behind it?
+ static int app_cspec;
+ static TQStyle *app_style;
+#ifndef TQT_NO_PALETTE
+ static TQPalette *app_pal;
+#endif
+ static TQPtrList<QEventLoop> tqt_event_loop_stack;
+ static TQWidgetList tqt_all_widgets_list;
+ static QWidget* current_app_main_widget;
+ mutable TQString static_object_name;
+ friend class TQWidget;
+ friend class TQETWidget;
+ friend class TQDialog;
+ friend class TQAccelManager;
+ friend class TQEvent;
+ friend class TQTranslator;
+ friend class TQEventLoop;
+ friend TQ_EXPORT void qt_ucm_initialize( TQApplication * );
+#if defined(TQ_WS_WIN)
+ friend bool qt_sendSpontaneousEvent( TQObject*, TQEvent* );
+#endif
+#if defined(TQ_WS_TQWS)
+ friend class TQInputContext;
+#endif
+
+ friend void qt_init(int *, char **, TQApplication::Type);
+
+#ifdef TQT_THREAD_SUPPORT
+ static TQMutex *qt_mutex;
+#endif // TQT_THREAD_SUPPORT
+
+public:
+ static int composedUnicode; // Value, meta-composed character
+ static bool metaComposeUnicode;
+
+protected:
+ inline bool event(QEvent *e) { TQT_TQOBJECT_CHILDEVENT_REQUIRED_HANDLER(e) return QApplication::event(e); }
+};
+
+#else // USE_QT4
+
+class TQApplication;
+extern TQ_EXPORT TQApplication *tqApp; // global application object
+
+
+class TQ_EXPORT TQApplication : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQApplication( int &argc, char **argv );
+ TQApplication( int &argc, char **argv, bool GUIenabled );
+ enum Type { Tty, GuiClient, GuiServer };
+ TQApplication( int &argc, char **argv, Type );
+#if defined(TQ_WS_X11)
+ TQApplication( Display* dpy, HANDLE visual = 0, HANDLE cmap = 0 );
+ TQApplication( Display *dpy, int argc, char **argv,
+ HANDLE visual = 0, HANDLE cmap= 0 );
+#endif
+ virtual ~TQApplication();
+
+ int argc() const;
+ char **argv() const;
+
+ Type type() const;
+
+#ifndef TQT_NO_STYLE
+ static TQStyle &tqstyle();
+ static void setStyle( TQStyle* );
+ static TQStyle* setStyle( const TQString& );
+#endif
+#ifndef TQ_TQDOC
+ enum ColorMode { NormalColors, CustomColors };
+ static ColorMode colorMode();
+ static void setColorMode( TQApplication::ColorMode );
+#endif
+
+ enum ColorSpec { NormalColor=0, CustomColor=1, ManyColor=2 };
+ static int colorSpec();
+ static void setColorSpec( int );
+#ifndef TQT_NO_CURSOR
+ static TQCursor *overrideCursor();
+ static void setOverrideCursor( const TQCursor &, bool tqreplace=FALSE );
+ static void restoreOverrideCursor();
+#endif
+ static bool hasGlobalMouseTracking();
+ static void setGlobalMouseTracking( bool enable );
+#ifndef TQT_NO_PALETTE
+ static TQPalette palette( const TQWidget* = 0 );
+ static void setPalette( const TQPalette &, bool informWidgets=FALSE,
+ const char* className = 0 );
+#endif
+ static TQFont font( const TQWidget* = 0 );
+ static void setFont( const TQFont &, bool informWidgets=FALSE,
+ const char* className = 0 );
+ static TQFontMetrics fontMetrics();
+
+ TQWidget *mainWidget() const;
+ virtual void setMainWidget( TQWidget * );
+ virtual void polish( TQWidget * );
+
+ static TQWidgetList *allWidgets();
+ static TQWidgetList *tqtopLevelWidgets();
+
+ static TQDesktopWidget *desktop();
+
+ static TQWidget *activePopupWidget();
+ static TQWidget *activeModalWidget();
+#ifndef TQT_NO_CLIPBOARD
+ static TQClipboard *clipboard();
+#endif
+ TQWidget *tqfocusWidget() const;
+ TQWidget *activeWindow() const;
+
+ static TQWidget *widgetAt( int x, int y, bool child=FALSE );
+ static TQWidget *widgetAt( const TQPoint &, bool child=FALSE );
+
+ static TQEventLoop *eventLoop();
+
+ int exec();
+ void processEvents();
+ void processEvents( int maxtime );
+ void processOneEvent();
+ bool hasPendingEvents();
+ int enter_loop();
+ void exit_loop();
+ int loopLevel() const;
+ static void exit( int retcode=0 );
+
+ static bool sendEvent( TQObject *receiver, TQEvent *event );
+ static void postEvent( TQObject *receiver, TQEvent *event );
+ static void sendPostedEvents( TQObject *receiver, int event_type );
+ static void sendPostedEvents();
+
+ static void removePostedEvents( TQObject *receiver );
+
+ virtual bool notify( TQObject *, TQEvent * );
+
+ static bool startingUp();
+ static bool closingDown();
+
+ static void flushX();
+ static void flush();
+ static void syncX();
+
+ static void beep();
+
+#ifndef TQT_NO_TRANSLATION
+# ifndef TQT_NO_TEXTCODEC
+ void setDefaultCodec( TQTextCodec * );
+ TQTextCodec* defaultCodec() const;
+# endif
+ void installTranslator( TQTranslator * );
+ void removeTranslator( TQTranslator * );
+#endif
+ enum Encoding { DefaultCodec, UnicodeUTF8 };
+ TQString translate( const char * context,
+ const char * key,
+ const char * comment = 0,
+ Encoding encoding = DefaultCodec ) const;
+#ifndef TQT_NO_DIR
+ TQString applicationDirPath();
+ TQString applicationFilePath();
+#endif
+#ifndef TQT_NO_PALETTE
+ // obsolete functions
+ static void setWinStyleHighlightColor( const TQColor &c ) {
+ TQPalette p( palette() );
+ p.setColor( TQColorGroup::Highlight, c );
+ setPalette( p, TRUE);
+ }
+ static const TQColor &winStyleHighlightColor() {
+ return palette().active().highlight();
+ }
+#endif
+ static void setDesktopSettingsAware( bool );
+ static bool desktopSettingsAware();
+
+ static void setCursorFlashTime( int );
+ static int cursorFlashTime();
+
+ static void setDoubleClickInterval( int );
+ static int doubleClickInterval();
+#ifndef TQT_NO_WHEELEVENT
+ static void setWheelScrollLines( int );
+ static int wheelScrollLines();
+#endif
+ static void setGlobalStrut( const TQSize & );
+ static TQSize globalStrut();
+
+#ifndef TQT_NO_COMPONENT
+ static void tqsetLibraryPaths( const TQStringList & );
+ static TQStringList libraryPaths();
+ static void addLibraryPath( const TQString & );
+ static void removeLibraryPath( const TQString & );
+#endif // TQT_NO_COMPONENT
+ static void setStartDragTime( int ms );
+ static int startDragTime();
+ static void setStartDragDistance( int l );
+ static int startDragDistance();
+
+ static void setReverseLayout( bool b );
+ static bool reverseLayout();
+
+ static int horizontalAlignment( int align );
+
+ static bool isEffectEnabled( TQt::UIEffect );
+ static void setEffectEnabled( TQt::UIEffect, bool enable = TRUE );
+
+#if defined(TQ_WS_MAC)
+ virtual bool macEventFilter( EventHandlerCallRef, EventRef );
+#endif
+#if defined(TQ_WS_WIN)
+ virtual bool winEventFilter( MSG * );
+#endif
+#if defined(TQ_WS_X11)
+ virtual bool x11EventFilter( XEvent * );
+ virtual int x11ClientMessage( TQWidget*, XEvent*, bool passive_only);
+ int x11ProcessEvent( XEvent* );
+#endif
+#if defined(TQ_WS_TQWS)
+ virtual bool qwsEventFilter( TQWSEvent * );
+ int qwsProcessEvent( TQWSEvent* );
+ void qwsSetCustomColors( TQRgb *colortable, int start, int numColors );
+/*!
+ \internal
+ Returns true if the process is GUI server
+*/
+ bool qwsIsGUIServer();
+#ifndef TQT_NO_TQWS_MANAGER
+ static TQWSDecoration &qwsDecoration();
+ static void qwsSetDecoration( TQWSDecoration *);
+#endif
+#endif
+
+#if defined(TQ_OS_WIN32) || defined(TQ_OS_CYGWIN)
+ static WindowsVersion winVersion();
+#elif defined(TQ_OS_MAC)
+ static MacintoshVersion macVersion();
+#endif
+#if defined(TQ_WS_WIN)
+ void winFocus( TQWidget *, bool );
+ static void winMouseButtonUp();
+#endif
+
+#ifndef TQT_NO_SESSIONMANAGER
+ // session management
+ bool isSessionRestored() const;
+ TQString sessionId() const;
+ TQString sessionKey() const;
+ virtual void commitData( TQSessionManager& sm );
+ virtual void saveState( TQSessionManager& sm );
+#endif
+#if defined(TQ_WS_X11)
+ static void create_xim();
+ static void close_xim();
+ static bool x11_apply_settings();
+#endif
+ void wakeUpGuiThread();
+#if defined(TQT_THREAD_SUPPORT)
+ void lock();
+ void unlock(bool wakeUpGui = TRUE);
+ bool locked();
+ bool tryLock();
+#endif
+
+Q_SIGNALS:
+ void lastWindowClosed();
+ void aboutToQuit();
+ void guiThreadAwake();
+
+public Q_SLOTS:
+ void quit();
+ void closeAllWindows();
+ void aboutTQt();
+
+#if defined(TQ_WS_TQWS)
+protected:
+ void setArgs(int, char **);
+#endif
+
+protected:
+ bool event(TQEvent *);
+
+private:
+ void construct( int &argc, char **argv, Type );
+ void initialize( int, char ** );
+ void init_precmdline();
+ void process_cmdline( int* argcptr, char ** argv );
+ bool internalNotify( TQObject *, TQEvent * );
+#if defined(TQ_WS_TQWS)
+ static TQWidget *tqfindChildWidget( const TQWidget *p, const TQPoint &pos );
+ static TQWidget *tqfindWidget( const TQObjectList&, const TQPoint &, bool rec );
+#endif
+
+#if defined(TQ_WS_MAC)
+ bool do_mouse_down(Point *, bool *);
+ static TQMAC_PASCAL OStqStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *);
+ static TQMAC_PASCAL OStqStatus globalAppleEventProcessor(const AppleEvent *, AppleEvent *, long);
+ static TQMAC_PASCAL void qt_context_timer_callbk(EventLoopTimerRef, void *);
+ static TQMAC_PASCAL void qt_select_timer_callbk(EventLoopTimerRef, void *);
+ static bool qt_mac_apply_settings();
+ friend class TQMacInputMethod;
+ friend TQMAC_PASCAL OStqStatus qt_window_event(EventHandlerCallRef, EventRef, void *);
+ friend void qt_mac_update_os_settings();
+ friend bool qt_set_socket_handler( int, int, TQObject *, bool);
+ friend void qt_mac_destroy_widget(TQWidget *);
+ friend void qt_init(int *, char **, TQApplication::Type);
+#endif
+
+#ifdef TQT_THREAD_SUPPORT
+ static TQMutex *qt_mutex;
+#endif // TQT_THREAD_SUPPORT
+
+ int app_argc;
+ char **app_argv;
+ bool quit_now;
+ int quit_code;
+ static TQStyle *app_style;
+ static int app_cspec;
+#ifndef TQT_NO_PALETTE
+ static TQPalette *app_pal;
+#endif
+ static TQFont *app_font;
+#ifndef TQT_NO_CURSOR
+ static TQCursor *app_cursor;
+#endif
+ static TQEventLoop* eventloop;
+ static int app_tracking;
+ static bool is_app_running;
+ static bool is_app_closing;
+ static bool app_exit_loop;
+ static int loop_level;
+ static TQWidget *main_widget;
+ static TQWidget *focus_widget;
+ static TQWidget *active_window;
+ static bool obey_desktop_settings;
+ static int cursor_flash_time;
+ static int mouse_double_click_time;
+ static int wheel_scroll_lines;
+ static int composedUnicode; // Value, meta-composed character
+
+ static bool animate_ui;
+ static bool animate_menu;
+ static bool animate_tooltip;
+ static bool animate_combo;
+ static bool fade_menu;
+ static bool fade_tooltip;
+ static bool animate_toolbox;
+ static bool widgetCount; // Coupled with -widgetcount switch
+ static bool metaComposeUnicode;
+
+ TQValueList<TQTranslator*> *translators;
+#ifndef TQT_NO_SESSIONMANAGER
+ TQSessionManager *session_manager;
+ TQString session_id;
+ static TQString* session_key;
+ bool is_session_restored;
+#endif
+#if defined(TQ_WS_X11) && !defined (TQT_NO_STYLE )
+ static void x11_initialize_style();
+#endif
+
+ static TQSize app_strut;
+#ifndef TQT_NO_COMPONENT
+ static TQStringList *app_libpaths;
+#endif
+ static TQAsciiDict<TQPalette> *app_palettes;
+ static TQAsciiDict<TQFont> *app_fonts;
+
+ static TQWidgetList *popupWidgets;
+ bool inPopupMode() const;
+ void closePopup( TQWidget *popup );
+ void openPopup( TQWidget *popup );
+ void setActiveWindow( TQWidget* act );
+
+ static bool sendSpontaneousEvent( TQObject *receiver, TQEvent *event );
+ static void removePostedEvent( TQEvent * );
+
+ friend class TQWidget;
+ friend class TQETWidget;
+ friend class TQDialog;
+ friend class TQAccelManager;
+ friend class TQEvent;
+ friend class TQTranslator;
+ friend class TQEventLoop;
+ friend TQ_EXPORT void qt_ucm_initialize( TQApplication * );
+#if defined(TQ_WS_WIN)
+ friend bool qt_sendSpontaneousEvent( TQObject*, TQEvent* );
+#endif
+#if defined(TQ_WS_TQWS)
+ friend class TQInputContext;
+#endif
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQApplication( const TQApplication & );
+ TQApplication &operator=( const TQApplication & );
+#endif
+};
+
+inline int TQApplication::argc() const
+{
+ return app_argc;
+}
+
+inline char **TQApplication::argv() const
+{
+ return app_argv;
+}
+
+#if defined(TQ_WS_TQWS)
+inline void TQApplication::setArgs(int c, char **v)
+{
+ app_argc = c;
+ app_argv = v;
+}
+#endif
+
+#ifndef TQT_NO_CURSOR
+inline TQCursor *TQApplication::overrideCursor()
+{
+ return app_cursor;
+}
+#endif
+inline bool TQApplication::hasGlobalMouseTracking()
+{
+ return app_tracking > 0;
+}
+
+inline TQWidget *TQApplication::mainWidget() const
+{
+ return main_widget;
+}
+
+inline TQWidget *TQApplication::tqfocusWidget() const
+{
+ return focus_widget;
+}
+
+inline TQWidget *TQApplication::activeWindow() const
+{
+ return active_window;
+}
+
+inline TQWidget *TQApplication::widgetAt( const TQPoint &p, bool child )
+{
+ return widgetAt( p.x(), p.y(), child );
+}
+
+inline bool TQApplication::inPopupMode() const
+{
+ return popupWidgets != 0;
+}
+#ifndef TQT_NO_SESSIONMANAGER
+inline bool TQApplication::isSessionRestored() const
+{
+ return is_session_restored;
+}
+
+inline TQString TQApplication::sessionId() const
+{
+ return session_id;
+}
+
+inline TQString TQApplication::sessionKey() const
+{
+ return session_key ? *session_key : TQString::null;
+}
+#endif
+inline TQSize TQApplication::globalStrut()
+{
+ return app_strut;
+}
+
+inline bool TQApplication::sendEvent( TQObject *receiver, TQEvent *event )
+{ if ( event ) event->spont = FALSE; return tqApp ? tqApp->notify( receiver, event ) : FALSE; }
+
+inline bool TQApplication::sendSpontaneousEvent( TQObject *receiver, TQEvent *event )
+{ if ( event ) event->spont = TRUE; return tqApp ? tqApp->notify( receiver, event ) : FALSE; }
+
+#ifdef TQT_NO_TRANSLATION
+// Simple versions
+inline TQString TQApplication::translate( const char *, const char *sourceText,
+ const char *, Encoding encoding ) const
+{
+#ifndef TQT_NO_TEXTCODEC
+ if ( encoding == UnicodeUTF8 )
+ return TQString::fromUtf8( sourceText );
+ else
+#endif
+ return TQString::tqfromLatin1( sourceText );
+}
+#endif
+
+inline int TQApplication::horizontalAlignment( int align )
+{
+ align &= AlignHorizontal_Mask;
+ if ( align == AlignAuto ) {
+ if ( reverseLayout() )
+ align = AlignRight;
+ else
+ align = AlignLeft;
+ }
+ return align;
+}
+
+#endif // TQAPPLICATION_H
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqapplication_p.h b/tqtinterface/qt4/src/kernel/tqapplication_p.h
new file mode 100644
index 0000000..cbedae7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqapplication_p.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Definition of some TQt private functions.
+**
+** Created : 000228
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQAPPLICATION_P_H
+#define TQAPPLICATION_P_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
+// and many other. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#endif // TQT_H
+
+class TQWidget;
+class TQObject;
+class TQClipboard;
+class TQKeyEvent;
+class TQMouseEvent;
+class TQWheelEvent;
+
+extern TQ_EXPORT bool qt_modal_state();
+extern TQ_EXPORT void qt_enter_modal( TQWidget* );
+extern TQ_EXPORT void qt_leave_modal( TQWidget* );
+
+extern bool qt_is_gui_used;
+#ifndef TQT_NO_CLIPBOARD
+extern TQClipboard *qt_clipboard;
+#endif
+
+#if defined (TQ_OS_WIN32) || defined (TQ_OS_CYGWIN)
+extern TQt::WindowsVersion qt_winver;
+const int TQT_TABLET_NPACKETQSIZE = 128;
+# ifdef TQ_OS_TEMP
+ extern DWORD qt_cever;
+# endif
+#elif defined (TQ_OS_MAC)
+extern TQt::MacintoshVersion qt_macver;
+#endif
+
+#if defined (TQ_WS_X11)
+extern int qt_ncols_option;
+#endif
+
+
+extern void qt_dispatchEnterLeave( TQWidget*, TQWidget* );
+extern bool qt_tryModalHelper( TQWidget *, TQWidget ** = 0 );
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqapplication_x11.cpp b/tqtinterface/qt4/src/kernel/tqapplication_x11.cpp
new file mode 100644
index 0000000..48616bf
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqapplication_x11.cpp
@@ -0,0 +1,8984 @@
+/****************************************************************************
+**
+** Implementation of X11 startup routines and event handling
+**
+** Created : 931029
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+// ### 4.0: examine TQ_EXPORT's below. The respective symbols had all
+// been in use (e.g. in the KDE wm ) before the introduction of a version
+// map. One might want to turn some of them into propert public API and
+// provide a proper alternative for others. See also the exports in
+// qapplication_win.cpp which suggest a unification.
+
+// ### needed for solaris-g++ in beta5
+#define TQT_CLEAN_NAMESPACE
+
+#include "tqplatformdefs.h"
+
+// POSIX Large File Support redefines open -> open64
+#if defined(open)
+# undef open
+#endif
+
+// Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED.
+#if defined(connect)
+# undef connect
+#endif
+
+// POSIX Large File Support redefines truncate -> truncate64
+#if defined(truncate)
+# undef truncate
+#endif
+
+#include "tqapplication.h"
+#include "tqapplication_p.h"
+#include "tqcolor_p.h"
+#include "tqcursor.h"
+#include "tqwidget.h"
+#include "tqwidget_p.h"
+#include "tqobjectlist.h"
+#include "tqwidgetlist.h"
+#include "tqwidgetintdict.h"
+#include "tqbitarray.h"
+#include "tqpainter.h"
+#include "tqpixmapcache.h"
+#include "tqdatetime.h"
+#include "tqtextcodec.h"
+#include "tqdatastream.h"
+#include "tqbuffer.h"
+#include "tqsocketnotifier.h"
+#include "tqsessionmanager.h"
+#include "tqvaluelist.h"
+#include "tqdict.h"
+#include "tqguardedptr.h"
+#include "tqclipboard.h"
+#include "tqwhatsthis.h" // ######## dependency
+#include "tqsettings.h"
+#include "tqstylefactory.h"
+#include "tqfileinfo.h"
+
+// Input method stuff - UNFINISHED
+#include "tqinputcontext_p.h"
+#include "tqinternal_p.h" // shared double buffer cleanup
+
+#if defined(TQT_THREAD_SUPPORT)
+# include "tqthread.h"
+#endif
+
+#if defined(TQT_DEBUG) && defined(TQ_OS_LINUX)
+# include "tqfile.h"
+#endif
+
+#include "tqt_x11_p.h"
+
+#if !defined(TQT_NO_XFTFREETYPE)
+// XFree86 4.0.3 implementation is missing XftInitFtLibrary forward
+extern "C" Bool XftInitFtLibrary(void);
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <locale.h>
+
+//#define X_NOT_BROKEN
+#ifdef X_NOT_BROKEN
+// Some X libraries are built with setlocale #defined to _Xsetlocale,
+// even though library users are then built WITHOUT such a definition.
+// This creates a problem - TQt might setlocale() one value, but then
+// X looks and doesn't see the value TQt set. The solution here is to
+// implement _Xsetlocale just in case X calls it - redirecting it to
+// the real libC version.
+//
+# ifndef setlocale
+extern "C" char *_Xsetlocale(int category, const char *locale);
+char *_Xsetlocale(int category, const char *locale)
+{
+ //qDebug("_Xsetlocale(%d,%s),category,locale");
+ return setlocale(category,locale);
+}
+# endif // setlocale
+#endif // X_NOT_BROKEN
+
+
+// resolve the conflict between X11's FocusIn and TQEvent::FocusIn
+const int XFocusOut = FocusOut;
+const int XFocusIn = FocusIn;
+#undef FocusOut
+#undef FocusIn
+
+const int XKeyPress = KeyPress;
+const int XKeyRelease = KeyRelease;
+#undef KeyPress
+#undef KeyRelease
+
+
+// Fix old X libraries
+#ifndef XK_KP_Home
+#define XK_KP_Home 0xFF95
+#endif
+#ifndef XK_KP_Left
+#define XK_KP_Left 0xFF96
+#endif
+#ifndef XK_KP_Up
+#define XK_KP_Up 0xFF97
+#endif
+#ifndef XK_KP_Right
+#define XK_KP_Right 0xFF98
+#endif
+#ifndef XK_KP_Down
+#define XK_KP_Down 0xFF99
+#endif
+#ifndef XK_KP_Prior
+#define XK_KP_Prior 0xFF9A
+#endif
+#ifndef XK_KP_Next
+#define XK_KP_Next 0xFF9B
+#endif
+#ifndef XK_KP_End
+#define XK_KP_End 0xFF9C
+#endif
+#ifndef XK_KP_Insert
+#define XK_KP_Insert 0xFF9E
+#endif
+#ifndef XK_KP_Delete
+#define XK_KP_Delete 0xFF9F
+#endif
+
+#ifdef USE_QT4
+
+/*****************************************************************************
+ Internal variables and functions
+ *****************************************************************************/
+static const char *appName; // application name
+static const char *appClass; // application class
+static const char *appFont = 0; // application font
+static const char *appBGCol = 0; // application bg color
+static const char *appFGCol = 0; // application fg color
+static const char *appBTNCol = 0; // application btn color
+static const char *mwGeometry = 0; // main widget tqgeometry
+static const char *mwTitle = 0; // main widget title
+//Ming-Che 10/10
+static char *ximServer = 0; // XIM Server will connect to
+static bool mwIconic = FALSE; // main widget iconified
+//Ming-Che 10/10
+static bool noxim = FALSE; // connect to xim or not
+// static Display *appDpy = 0; // X11 application display
+static char *appDpyName = 0; // X11 display name
+static bool appForeignDpy = FALSE; // we didn't create display
+static bool appSync = FALSE; // X11 synchronization
+#if defined(TQT_DEBUG)
+static bool appNoGrab = FALSE; // X11 grabbing enabled
+static bool appDoGrab = FALSE; // X11 grabbing override (gdb)
+#endif
+// static int appScreen; // X11 screen number
+static int appScreenCount; // X11 screen count
+static bool app_save_rootinfo = FALSE; // save root info
+static bool app_do_modal = FALSE; // modal mode
+static Window curWin = 0; // current window
+
+static GC* app_gc_ro = 0; // read-only GC
+static GC* app_gc_tmp = 0; // temporary GC
+static GC* app_gc_ro_m = 0; // read-only GC (monochrome)
+static GC* app_gc_tmp_m = 0; // temporary GC (monochrome)
+// symbols needed by extern TQXEmbed class
+TQ_EXPORT Atom qt_wm_protocols = 0; // window manager protocols
+TQ_EXPORT Atom qt_wm_delete_window = 0; // delete window protocol
+TQ_EXPORT Atom qt_wm_take_focus = 0; // take focus window protocol
+
+Atom qt_qt_scrolldone = 0; // scroll synchronization
+Atom qt_net_wm_context_help = 0; // context help
+Atom qt_net_wm_ping = 0; // _NET_WM_PING protocol
+
+static Atom qt_xsetroot_id = 0;
+Atom qt_xa_clipboard = 0;
+Atom qt_selection_property = 0;
+Atom qt_clipboard_sentinel = 0;
+Atom qt_selection_sentinel = 0;
+TQ_EXPORT Atom qt_wm_state = 0;
+Atom qt_wm_change_state = 0;
+static Atom qt_settings_timestamp = 0; // TQt >=3 settings timestamp
+static Atom qt_input_encoding = 0; // TQt desktop properties
+static Atom qt_resource_manager = 0; // X11 Resource manager
+Atom qt_sizegrip = 0; // sizegrip
+Atom qt_wm_client_leader = 0;
+TQ_EXPORT Atom qt_window_role = 0;
+TQ_EXPORT Atom qt_sm_client_id = 0;
+Atom qt_xa_motif_wm_hints = 0;
+Atom qt_cde_running = 0;
+Atom qt_kwin_running = 0;
+Atom qt_kwm_running = 0;
+Atom qt_gbackground_properties = 0;
+Atom qt_x_incr = 0;
+Atom qt_utf8_string = 0;
+
+// detect broken window managers
+Atom qt_sgi_desks_manager = 0;
+bool qt_broken_wm = FALSE;
+static void qt_detect_broken_window_manager();
+
+// NET WM support
+Atom qt_net_supported = 0;
+Atom qt_net_wm_name = 0;
+Atom qt_net_wm_icon_name = 0;
+Atom qt_net_virtual_roots = 0;
+Atom qt_net_workarea = 0;
+Atom qt_net_wm_state = 0;
+Atom qt_net_wm_state_modal = 0;
+Atom qt_net_wm_state_max_v = 0;
+Atom qt_net_wm_state_max_h = 0;
+Atom qt_net_wm_state_fullscreen = 0;
+Atom qt_net_wm_state_above = 0;
+Atom qt_net_wm_window_type = 0;
+Atom qt_net_wm_window_type_normal = 0;
+Atom qt_net_wm_window_type_dialog = 0;
+Atom qt_net_wm_window_type_toolbar = 0;
+Atom qt_net_wm_window_type_menu = 0;
+Atom qt_net_wm_window_type_utility = 0;
+Atom qt_net_wm_window_type_splash = 0;
+Atom qt_net_wm_window_type_override = 0; // KDE extension
+Atom qt_net_wm_frame_strut = 0; // KDE extension
+Atom qt_net_wm_state_stays_on_top = 0; // KDE extension
+Atom qt_net_wm_pid = 0;
+Atom qt_net_wm_user_time = 0;
+// Enlightenment support
+Atom qt_enlightenment_desktop = 0;
+
+// window managers list of supported "stuff"
+Atom *qt_net_supported_list = 0;
+// list of virtual root windows
+Window *qt_net_virtual_root_list = 0;
+
+
+
+// client leader window
+Window qt_x11_wm_client_leader = 0;
+
+// function to update the workarea of the screen - in qdesktopwidget_x11.cpp
+extern void qt_desktopwidget_update_workarea();
+
+// current focus model
+static const int FocusModel_Unknown = -1;
+static const int FocusModel_Other = 0;
+static const int FocusModel_PointerRoot = 1;
+static int qt_focus_model = -1;
+
+#ifndef TQT_NO_XRANDR
+// TRUE if TQt is compiled w/ XRandR support and XRandR exists on the connected
+// Display
+bool qt_use_xrandr = FALSE;
+static int xrandr_eventbase;
+#endif
+
+// TRUE if TQt is compiled w/ XRender support and XRender exists on the connected
+// Display
+TQ_EXPORT bool qt_use_xrender = FALSE;
+
+// modifier masks for alt/meta - detected when the application starts
+static long qt_alt_mask = 0;
+static long qt_meta_mask = 0;
+// modifier tqmask to remove mode switch from modifiers that have alt/meta set
+// this problem manifests itself on HP/UX 10.20 at least, and without it
+// modifiers do not work at all...
+static long qt_mode_switch_remove_mask = 0;
+
+// flags for extensions for special Languages, currently only for RTL languages
+static bool qt_use_rtl_extensions = FALSE;
+bool qt_hebrew_keyboard_hack = FALSE;
+
+static Window mouseActWindow = 0; // window where mouse is
+static int mouseButtonPressed = 0; // last mouse button pressed
+static int mouseButtonState = 0; // mouse button state
+static Time mouseButtonPressTime = 0; // when was a button pressed
+static short mouseXPos, mouseYPos; // mouse pres position in act window
+static short mouseGlobalXPos, mouseGlobalYPos; // global mouse press position
+
+extern TQWidgetList *qt_modal_stack; // stack of modal widgets
+static bool ignoreNextMouseReleaseEvent = FALSE; // ignore the next mouse release
+ // event if return from a modal
+ // widget
+
+static TQWidget *popupButtonFocus = 0;
+static TQWidget *popupOfPopupButtonFocus = 0;
+static bool popupCloseDownMode = FALSE;
+static bool popupGrabOk;
+
+static bool sm_blockUserInput = FALSE; // session management
+
+int qt_xfocusout_grab_counter = 0;
+
+#if defined (TQT_TABLET_SUPPORT)
+// since XInput event classes aren't created until we actually open an XInput
+// tqdevice, here is a static list that we will use later on...
+const int INVALID_EVENT = -1;
+const int TOTAL_XINPUT_EVENTS = 7;
+
+XDevice *devStylus = NULL;
+XDevice *devEraser = NULL;
+XEventClass event_list_stylus[TOTAL_XINPUT_EVENTS];
+XEventClass event_list_eraser[TOTAL_XINPUT_EVENTS];
+
+int qt_curr_events_stylus = 0;
+int qt_curr_events_eraser = 0;
+
+// well, luckily we only need to do this once.
+static int xinput_motion = INVALID_EVENT;
+static int xinput_key_press = INVALID_EVENT;
+static int xinput_key_release = INVALID_EVENT;
+static int xinput_button_press = INVALID_EVENT;
+static int xinput_button_release = INVALID_EVENT;
+
+// making this assumption on XFree86, since we can only use 1 tqdevice,
+// the pressure for the eraser and the stylus should be the same, if they aren't
+// well, they certainly have a strange pen then...
+static int max_pressure;
+extern bool chokeMouse;
+#endif
+
+// last timestamp read from TQSettings
+static uint appliedstamp = 0;
+
+
+typedef int (*QX11EventFilter) (XEvent*);
+QX11EventFilter qt_set_x11_event_filter(QX11EventFilter filter);
+
+static QX11EventFilter qt_x11_event_filter = 0;
+TQ_EXPORT QX11EventFilter qt_set_x11_event_filter(QX11EventFilter filter)
+{
+ QX11EventFilter old_filter = qt_x11_event_filter;
+ qt_x11_event_filter = filter;
+ return old_filter;
+}
+static bool qt_x11EventFilter( XEvent* ev )
+{
+ if ( qt_x11_event_filter && qt_x11_event_filter( ev ) )
+ return TRUE;
+ return tqApp->x11EventFilter( ev );
+}
+
+#if !defined(TQT_NO_XIM)
+XIM qt_xim = 0;
+XIMStyle qt_xim_style = 0;
+static XIMStyle xim_default_style = XIMPreeditCallbacks | XIMStatusNothing;
+static XIMStyle xim_preferred_style = 0;
+#endif
+
+static int composingKeycode=0;
+static TQTextCodec * input_mapper = 0;
+
+extern bool qt_check_clipboard_sentinel(); //def in qclipboard_x11.cpp
+extern bool qt_check_selection_sentinel(); //def in qclipboard_x11.cpp
+
+static void qt_save_rootinfo();
+bool qt_try_modal( TQWidget *, XEvent * );
+
+int qt_ncols_option = 216; // used in qcolor_x11.cpp
+int qt_visual_option = -1;
+bool qt_cmap_option = FALSE;
+TQWidget *qt_button_down = 0; // widget got last button-down
+
+extern bool qt_tryAccelEvent( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp
+
+struct TQScrollInProgress {
+ static long serial;
+ TQScrollInProgress( TQWidget* w, int x, int y ) :
+ id( serial++ ), scrolled_widget( w ), dx( x ), dy( y ) {}
+ long id;
+ TQWidget* scrolled_widget;
+ int dx, dy;
+};
+long TQScrollInProgress::serial=0;
+static TQPtrList<TQScrollInProgress> *sip_list = 0;
+
+
+// stuff in qt_xdnd.cpp
+// setup
+extern void qt_xdnd_setup();
+// x event handling
+extern void qt_handle_xdnd_enter( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_position( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_status( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_leave( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_drop( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_finished( TQWidget *, const XEvent *, bool );
+extern void qt_xdnd_handle_selection_request( const XSelectionRequestEvent * );
+extern bool qt_xdnd_handle_badwindow();
+
+extern void qt_motifdnd_handle_msg( TQWidget *, const XEvent *, bool );
+extern void qt_x11_motifdnd_init();
+
+// client message atoms
+extern Atom qt_xdnd_enter;
+extern Atom qt_xdnd_position;
+extern Atom qt_xdnd_status;
+extern Atom qt_xdnd_leave;
+extern Atom qt_xdnd_drop;
+extern Atom qt_xdnd_finished;
+// xdnd selection atom
+extern Atom qt_xdnd_selection;
+extern bool qt_xdnd_dragging;
+
+// gui or non-gui from qapplication.cpp
+extern bool qt_is_gui_used;
+extern bool qt_app_has_font;
+
+static bool qt_x11_cmdline_font = false;
+
+
+extern bool qt_resolve_symlinks; // from qapplication.cpp
+
+// Paint event clipping magic
+extern void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region);
+extern void qt_clear_paintevent_clipping();
+
+
+// Palette handling
+extern TQPalette *qt_std_pal;
+extern void qt_create_std_palette();
+
+void qt_x11_intern_atom( const char *, Atom * );
+
+static TQPtrList<TQWidget>* deferred_map_list = 0;
+static void qt_deferred_map_cleanup()
+{
+ delete deferred_map_list;
+ deferred_map_list = 0;
+}
+void qt_deferred_map_add( TQWidget* w)
+{
+ if ( !deferred_map_list ) {
+ deferred_map_list = new TQPtrList<TQWidget>;
+ qAddPostRoutine( qt_deferred_map_cleanup );
+ }
+ deferred_map_list->append( w );
+}
+void qt_deferred_map_take( TQWidget* w )
+{
+ if (deferred_map_list ) {
+ deferred_map_list->remove( w );
+ }
+}
+bool qt_deferred_map_tqcontains( TQWidget* w )
+{
+ if (!deferred_map_list)
+ return FALSE;
+ else
+ return deferred_map_list->tqcontains( w );
+}
+
+/*****************************************************************************
+ Default X error handlers
+ *****************************************************************************/
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static bool x11_ignore_badwindow;
+static bool x11_badwindow;
+
+ // starts to ignore bad window errors from X
+void qt_ignore_badwindow()
+{
+ x11_ignore_badwindow = TRUE;
+ x11_badwindow = FALSE;
+}
+
+ // ends ignoring bad window errors and returns whether an error
+ // had happen.
+bool qt_badwindow()
+{
+ x11_ignore_badwindow = FALSE;
+ return x11_badwindow;
+}
+
+static int (*original_x_errhandler)( Display *dpy, XErrorEvent * );
+static int (*original_xio_errhandler)( Display *dpy );
+
+static int qt_x_errhandler( Display *dpy, XErrorEvent *err )
+{
+ if ( err->error_code == BadWindow ) {
+ x11_badwindow = TRUE;
+ if ( err->request_code == 25 /* X_SendEvent */ &&
+ qt_xdnd_handle_badwindow() )
+ return 0;
+ if ( x11_ignore_badwindow )
+ return 0;
+ } else if ( err->error_code == BadMatch &&
+ err->request_code == 42 /* X_SetInputFocus */ ) {
+ return 0;
+ }
+
+ char errstr[256];
+ XGetErrorText( dpy, err->error_code, errstr, 256 );
+ qWarning( "X Error: %s %d\n"
+ " Major opcode: %d\n"
+ " Minor opcode: %d\n"
+ " Resource id: 0x%lx",
+ errstr, err->error_code,
+ err->request_code,
+ err->minor_code,
+ err->resourceid );
+
+ // ### we really should distinguish between severe, non-severe and
+ // ### application specific errors
+
+ return 0;
+}
+
+
+static int qt_xio_errhandler( Display * )
+{
+ qWarning( "%s: Fatal IO error: client killed", appName );
+ tqApp = 0;
+ exit( 1 );
+ //### give the application a chance for a proper shutdown instead,
+ //### exit(1) doesn't help.
+ return 0;
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+// Memory leak: if the app exits before qt_init_internal(), this dict
+// isn't released correctly.
+static TQAsciiDict<Atom> *atoms_to_be_created = 0;
+static bool create_atoms_now = 0;
+
+/*****************************************************************************
+ qt_x11_intern_atom() - efficiently interns an atom, now or later.
+
+ If the application is being initialized, this function stores the
+ adddress of the atom and qt_init_internal will do the actual work
+ quickly. If the application is running, the atom is created here.
+
+ Neither argument may point to temporary variables.
+ *****************************************************************************/
+
+void qt_x11_intern_atom( const char *name, Atom *result)
+{
+ if ( !name || !result || *result )
+ return;
+
+ if ( create_atoms_now ) {
+ *result = XInternAtom( QX11Info::display(), name, False );
+ } else {
+ if ( !atoms_to_be_created ) {
+ atoms_to_be_created = new TQAsciiDict<Atom>;
+ atoms_to_be_created->setAutoDelete( FALSE );
+ }
+ atoms_to_be_created->insert( name, result );
+ *result = 0;
+ }
+}
+
+
+static void qt_x11_process_intern_atoms()
+{
+ if ( atoms_to_be_created ) {
+#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 6)
+ int i = atoms_to_be_created->count();
+ Atom * res = (Atom *)malloc( i * sizeof( Atom ) );
+ Atom ** resp = (Atom **)malloc( i * sizeof( Atom* ) );
+ char ** names = (char **)malloc( i * sizeof(const char*));
+
+ i = 0;
+ TQAsciiDictIterator<Atom> it( *atoms_to_be_created );
+ while( it.current() ) {
+ res[i] = 0;
+ resp[i] = it.current();
+ names[i] = qstrdup(it.currentKey());
+ i++;
+ ++it;
+ }
+ XInternAtoms( QX11Info::display(), names, i, False, res );
+ while( i ) {
+ i--;
+ delete [] names[i];
+ if ( res[i] && resp[i] )
+ *(resp[i]) = res[i];
+ }
+ free( res );
+ free( resp );
+ free( names );
+#else
+ TQAsciiDictIterator<Atom> it( *atoms_to_be_created );
+ Atom * result;
+ const char * name;
+ while( (result = it.current()) != 0 ) {
+ name = it.currentKey();
+ ++it;
+ *result = XInternAtom( QX11Info::display(), name, False );
+ }
+#endif
+ delete atoms_to_be_created;
+ atoms_to_be_created = 0;
+ create_atoms_now = TRUE;
+ }
+}
+
+Display *qt_xdisplay() // get current X display
+{
+// return appDpy;
+ return QX11Info::display();
+}
+
+int qt_xscreen() // get current X screen
+{
+ return QX11Info::appScreen();
+}
+
+void applyX11SpecificCommandLineArguments(QWidget *main_widget)
+{
+ static bool beenHereDoneThat = false;
+ if (beenHereDoneThat)
+ return;
+ beenHereDoneThat = true;
+ if (!main_widget->testAttribute(Qt::WA_WState_Created)) {
+ printf("[WARNING] Attempted to set uncreated main widget!\n\r");
+ return;
+ }
+ Q_ASSERT(main_widget->testAttribute(Qt::WA_WState_Created));
+ if (mwTitle) {
+ XStoreName(qt_xdisplay(), main_widget->effectiveWinId(), (char*)mwTitle);
+ QByteArray net_wm_name = QString::fromLocal8Bit(mwTitle).toUtf8();
+ XChangeProperty(qt_xdisplay(), main_widget->effectiveWinId(), qt_net_wm_name, qt_utf8_string, 8,
+ PropModeReplace, (unsigned char *)net_wm_name.data(), net_wm_name.size());
+ }
+ if (mwGeometry) { // parse geometry
+ int x, y;
+ int w, h;
+ int m = XParseGeometry((char*)mwGeometry, &x, &y, (uint*)&w, (uint*)&h);
+ QSize minSize = main_widget->minimumSize();
+ QSize maxSize = main_widget->maximumSize();
+ if ((m & XValue) == 0)
+ x = main_widget->geometry().x();
+ if ((m & YValue) == 0)
+ y = main_widget->geometry().y();
+ if ((m & WidthValue) == 0)
+ w = main_widget->width();
+ if ((m & HeightValue) == 0)
+ h = main_widget->height();
+ w = qMin(w,maxSize.width());
+ h = qMin(h,maxSize.height());
+ w = qMax(w,minSize.width());
+ h = qMax(h,minSize.height());
+ if ((m & XNegative)) {
+ x = QApplication::desktop()->width() + x - w;
+ }
+ if ((m & YNegative)) {
+ y = QApplication::desktop()->height() + y - h;
+ }
+ main_widget->setGeometry(x, y, w, h);
+ }
+}
+
+void TQApplication::setMainWidget(QWidget *mainWidget)
+{
+// #ifndef QT_NO_DEBUG
+// if (mainWidget && mainWidget->parentWidget() && mainWidget->isWindow())
+// qWarning("QApplication::setMainWidget: New main widget (%s/%s) "
+// "has a parent",
+// mainWidget->metaObject()->className(), mainWidget->objectName().toLocal8Bit().constData());
+// #endif
+// if (mainWidget)
+// mainWidget->d_func()->createWinId();
+// QApplicationPrivate::main_widget = mainWidget;
+// if (QApplicationPrivate::main_widget) // give WM command line
+// QApplicationPrivate::applyX11SpecificCommandLineArguments(QApplicationPrivate::main_widget);
+
+ if (mainWidget)
+ mainWidget->effectiveWinId();
+ current_app_main_widget = mainWidget;
+ if (current_app_main_widget) // give WM command line
+ applyX11SpecificCommandLineArguments(current_app_main_widget);
+
+ // Is this needed?
+ connect(mainWidget, SIGNAL(destroyed(QObject*)), this, SLOT(quit()));
+}
+
+// ************************************************************************
+// X Input Method support
+// ************************************************************************
+
+#if !defined(TQT_NO_XIM)
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif // TQ_C_CALLBACKS
+
+#ifdef USE_X11R6_XIM
+ static void xim_create_callback(XIM /*im*/,
+ XPointer /*client_data*/,
+ XPointer /*call_data*/)
+ {
+ // qDebug("xim_create_callback");
+ TQApplication::create_xim();
+ }
+
+ static void xim_destroy_callback(XIM /*im*/,
+ XPointer /*client_data*/,
+ XPointer /*call_data*/)
+ {
+ // qDebug("xim_destroy_callback");
+ TQApplication::close_xim();
+ XRegisterIMInstantiateCallback(QX11Info::display(), 0, 0, 0,
+ (XIMProc) xim_create_callback, 0);
+ }
+
+#endif // USE_X11R6_XIM
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif // TQ_C_CALLBACKS
+
+#endif // TQT_NO_XIM
+
+// read the _TQT_INPUT_ENCODING property and apply the settings to
+// the application
+static void qt_set_input_encoding()
+{
+ Atom type;
+ int format;
+ ulong nitems, after = 1;
+ const char *data;
+
+ int e = XGetWindowProperty( QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_input_encoding, 0, 1024,
+ False, XA_STRING, &type, &format, &nitems,
+ &after, (unsigned char**)&data );
+ if ( e != Success || !nitems || type == None ) {
+ // Always use the locale codec, since we have no examples of non-local
+ // XIMs, and since we cannot get a sensible answer about the encoding
+ // from the XIM.
+ input_mapper = TQTextCodec::codecForLocale();
+
+ } else {
+ if ( !qstricmp( data, "locale" ) )
+ input_mapper = TQTextCodec::codecForLocale();
+ else
+ input_mapper = TQTextCodec::codecForName( data );
+ // make sure we have an input codec
+ if( !input_mapper )
+ input_mapper = TQTextCodec::codecForName( "ISO 8859-1" );
+ }
+ if ( input_mapper->mibEnum() == 11 ) // 8859-8
+ input_mapper = TQTextCodec::codecForName( "ISO 8859-8-I");
+ if( data )
+ XFree( (char *)data );
+}
+
+bool qt_net_supports(Atom atom)
+{
+ if (! qt_net_supported_list)
+ return FALSE;
+
+ bool supported = FALSE;
+ int i = 0;
+ while (qt_net_supported_list[i] != 0) {
+ if (qt_net_supported_list[i++] == atom) {
+ supported = TRUE;
+ break;
+ }
+ }
+
+ return supported;
+}
+
+// update the virtual roots array
+void qt_get_net_virtual_roots()
+{
+ if (qt_net_virtual_root_list)
+ delete [] qt_net_virtual_root_list;
+ qt_net_virtual_root_list = 0;
+
+ if (! qt_net_supports(qt_net_virtual_roots))
+ return;
+
+ Atom type;
+ int format;
+ long offset = 0;
+ unsigned long nitems, after;
+ unsigned char *data;
+
+ int e = XGetWindowProperty(QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_net_virtual_roots, 0, 0,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+ if (data)
+ XFree(data);
+
+ if (e == Success && type == XA_ATOM && format == 32) {
+ TQBuffer ts;
+ ts.open(IO_WriteOnly);
+
+ while (after > 0) {
+ XGetWindowProperty(QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_net_virtual_roots, offset, 1024,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+
+ if (type == XA_ATOM && format == 32) {
+ TQT_TQIODEVICE_OBJECT(ts).writeBlock((const char *) data, nitems * 4);
+ offset += nitems;
+ } else
+ after = 0;
+ if (data)
+ XFree(data);
+ }
+
+ // compute nitems
+ TQByteArray buffer(TQT_TQBYTEARRAY_OBJECT(ts.buffer()));
+ nitems = buffer.size() / sizeof(Window);
+ qt_net_virtual_root_list = new Window[nitems + 1];
+ Window *a = (Window *) buffer.data();
+ uint i;
+ for (i = 0; i < nitems; i++)
+ qt_net_virtual_root_list[i] = a[i];
+ qt_net_virtual_root_list[nitems] = 0;
+ }
+}
+
+/*
+ Returns a truecolor visual (if there is one). 8-bit TrueColor visuals
+ are ignored, unless the user has explicitly requested -visual TrueColor.
+ The SGI X server usually has an 8 bit default visual, but the application
+ can also ask for a truecolor visual. This is what we do if
+ TQApplication::colorSpec() is TQApplication::ManyColor.
+*/
+
+static Visual *tqfind_truecolor_visual( Display *dpy, int scr, int *depth, int *ncols )
+{
+ XVisualInfo *vi, rvi;
+ int best=0, n, i;
+ rvi.c_class = TrueColor;
+ rvi.screen = scr;
+ vi = XGetVisualInfo( dpy, VisualClassMask | VisualScreenMask,
+ &rvi, &n );
+ if ( vi ) {
+ for ( i=0; i<n; i++ ) {
+ if ( vi[i].depth > vi[best].depth )
+ best = i;
+ }
+ }
+ Visual *v = DefaultVisual(dpy,scr);
+ if ( !vi || (vi[best].visualid == XVisualIDFromVisual(v)) ||
+ (vi[best].depth <= 8 && qt_visual_option != TrueColor) )
+ {
+ *depth = DefaultDepth(dpy,scr);
+ *ncols = DisplayCells(dpy,scr);
+ } else {
+ v = vi[best].visual;
+ *depth = vi[best].depth;
+ *ncols = vi[best].colormap_size;
+ }
+ if ( vi )
+ XFree( (char *)vi );
+ return v;
+}
+
+// update the supported array
+void qt_get_net_supported()
+{
+ Atom type;
+ int format;
+ long offset = 0;
+ unsigned long nitems, after;
+ unsigned char *data = 0;
+
+ int e = XGetWindowProperty(QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_net_supported, 0, 0,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+ if (data)
+ XFree(data);
+
+ if (qt_net_supported_list)
+ delete [] qt_net_supported_list;
+ qt_net_supported_list = 0;
+
+ if (e == Success && type == XA_ATOM && format == 32) {
+ TQBuffer ts;
+ ts.open(IO_WriteOnly);
+
+ while (after > 0) {
+ XGetWindowProperty(QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_net_supported, offset, 1024,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+
+ if (type == XA_ATOM && format == 32) {
+ TQT_TQIODEVICE_OBJECT(ts).writeBlock((const char *) data, nitems * sizeof(long));
+ offset += nitems;
+ } else
+ after = 0;
+ if (data)
+ XFree(data);
+ }
+
+ // compute nitems
+ TQByteArray buffer(TQT_TQBYTEARRAY_OBJECT(ts.buffer()));
+ nitems = buffer.size() / sizeof(Atom);
+ qt_net_supported_list = new Atom[nitems + 1];
+ Atom *a = (Atom *) buffer.data();
+ uint i;
+ for (i = 0; i < nitems; i++)
+ qt_net_supported_list[i] = a[i];
+ qt_net_supported_list[nitems] = 0;
+ }
+}
+
+// set font, foreground and background from x11 resources. The
+// arguments may override the resource settings.
+static void qt_set_x11_resources( const char* font = 0, const char* fg = 0,
+ const char* bg = 0, const char* button = 0 )
+{
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+
+ TQCString resFont, resFG, resBG, resEF, sysFont;
+
+ TQApplication::setEffectEnabled( Qt::UI_General, FALSE);
+ TQApplication::setEffectEnabled( Qt::UI_AnimateMenu, FALSE);
+ TQApplication::setEffectEnabled( Qt::UI_FadeMenu, FALSE);
+ TQApplication::setEffectEnabled( Qt::UI_AnimateCombo, FALSE );
+ TQApplication::setEffectEnabled( Qt::UI_AnimateTooltip, FALSE );
+ TQApplication::setEffectEnabled( Qt::UI_FadeTooltip, FALSE );
+ TQApplication::setEffectEnabled( Qt::UI_AnimateToolBox, FALSE );
+
+ if ( TQApplication::desktopSettingsAware() && !TQApplication::x11_apply_settings() ) {
+ int format;
+ ulong nitems, after = 1;
+ TQCString res;
+ long offset = 0;
+ Atom type = None;
+
+ while (after > 0) {
+ uchar *data;
+ XGetWindowProperty( QX11Info::display(), TQPaintDevice::x11AppRootWindow( 0 ),
+ qt_resource_manager,
+ offset, 8192, False, AnyPropertyType,
+ &type, &format, &nitems, &after,
+ &data );
+ res += (char*)data;
+ offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048
+ if ( data )
+ XFree( (char *)data );
+ }
+
+ TQCString key, value;
+ int l = 0, r;
+ TQCString apn = appName;
+ TQCString apc = appClass;
+ int apnl = apn.length();
+ int apcl = apc.length();
+ int resl = res.length();
+
+ while (l < resl) {
+ r = res.tqfind( '\n', l );
+ if ( r < 0 )
+ r = resl;
+ while ( isspace((uchar) res[l]) )
+ l++;
+ bool mine = FALSE;
+ if ( res[l] == '*' &&
+ (res[l+1] == 'f' || res[l+1] == 'b' || res[l+1] == 'g' ||
+ res[l+1] == 'F' || res[l+1] == 'B' || res[l+1] == 'G' ||
+ res[l+1] == 's' || res[l+1] == 'S' ) ) {
+ // OPTIMIZED, since we only want "*[fbgs].."
+
+ TQCString item = res.mid( l, r - l ).simplifyWhiteSpace();
+ int i = item.tqfind( ":" );
+ key = item.left( i ).stripWhiteSpace().mid(1).lower();
+ value = item.right( item.length() - i - 1 ).stripWhiteSpace();
+ mine = TRUE;
+ } else if ( res[l] == appName[0] || (appClass && res[l] == appClass[0]) ) {
+ if (res.mid(l,apnl) == apn && (res[l+apnl] == '.' || res[l+apnl] == '*')) {
+ TQCString item = res.mid( l, r - l ).simplifyWhiteSpace();
+ int i = item.tqfind( ":" );
+ key = item.left( i ).stripWhiteSpace().mid(apnl+1).lower();
+ value = item.right( item.length() - i - 1 ).stripWhiteSpace();
+ mine = TRUE;
+ } else if (res.mid(l,apcl) == apc && (res[l+apcl] == '.' || res[l+apcl] == '*')) {
+ TQCString item = res.mid( l, r - l ).simplifyWhiteSpace();
+ int i = item.tqfind( ":" );
+ key = item.left( i ).stripWhiteSpace().mid(apcl+1).lower();
+ value = item.right( item.length() - i - 1 ).stripWhiteSpace();
+ mine = TRUE;
+ }
+ }
+
+ if ( mine ) {
+ if ( !font && key == "systemfont")
+ sysFont = value.left( value.tqfindRev(':') ).copy();
+ if ( !font && key == "font")
+ resFont = value.copy();
+ else if ( !fg && key == "foreground" )
+ resFG = value.copy();
+ else if ( !bg && key == "background")
+ resBG = value.copy();
+ else if ( key == "guieffects")
+ resEF = value.copy();
+ // NOTE: if you add more, change the [fbg] stuff above
+ }
+
+ l = r + 1;
+ }
+ }
+ if ( !sysFont.isEmpty() )
+ resFont = sysFont;
+ if ( resFont.isEmpty() )
+ resFont = font;
+ if ( resFG.isEmpty() )
+ resFG = fg;
+ if ( resBG.isEmpty() )
+ resBG = bg;
+// // [FIXME]
+// if ( (!qt_app_has_font || qt_x11_cmdline_font) && !resFont.isEmpty() ) { // set application font
+// TQFont fnt;
+// fnt.setRawName( resFont );
+//
+// // the font we get may actually be an alias for another font,
+// // so we reset the application font to the real font info.
+// if ( ! fnt.exactMatch() ) {
+// TQFontInfo fontinfo( fnt );
+// fnt.setFamily( fontinfo.family() );
+// fnt.setRawMode( fontinfo.rawMode() );
+//
+// if ( ! fnt.rawMode() ) {
+// fnt.setItalic( fontinfo.italic() );
+// fnt.setWeight( fontinfo.weight() );
+// fnt.setUnderline( fontinfo.underline() );
+// fnt.setStrikeOut( fontinfo.strikeOut() );
+// fnt.setStyleHint( fontinfo.tqstyleHint() );
+//
+// if ( fnt.pointSize() <= 0 && fnt.pixelSize() <= 0 )
+// // size is all wrong... fix it
+// fnt.setPointSize( (int) ( ( fontinfo.pixelSize() * 72. /
+// (float) TQPaintDevice::x11AppDpiY() ) +
+// 0.5 ) );
+// }
+// }
+//
+// if ( fnt != TQApplication::font() ) {
+// TQApplication::setFont( fnt, TRUE );
+// }
+// }
+
+ if ( button || !resBG.isEmpty() || !resFG.isEmpty() ) {// set app colors
+ TQColor btn;
+ TQColor bg;
+ TQColor fg;
+ if ( !resBG.isEmpty() )
+ bg = TQColor(TQString(resBG));
+ else
+ bg = qt_std_pal->active().background();
+ if ( !resFG.isEmpty() )
+ fg = TQColor(TQString(resFG));
+ else
+ fg = qt_std_pal->active().foreground();
+ if ( button )
+ btn = TQColor( button );
+ else if ( !resBG.isEmpty() )
+ btn = bg;
+ else
+ btn = qt_std_pal->active().button();
+
+ int h,s,v;
+ fg.hsv(&h,&s,&v);
+ TQColor base = TQt::white;
+ bool bright_mode = FALSE;
+ if (v >= 255-50) {
+ base = btn.dark(150);
+ bright_mode = TRUE;
+ }
+
+ TQColorGroup cg( fg, btn, btn.light(),
+ btn.dark(), btn.dark(150), fg, TQt::white, base, bg );
+ if (bright_mode) {
+ cg.setColor( TQColorGroup::HighlightedText, base );
+ cg.setColor( TQColorGroup::Highlight, TQt::white );
+ } else {
+ cg.setColor( TQColorGroup::HighlightedText, TQt::white );
+ cg.setColor( TQColorGroup::Highlight, TQt::darkBlue );
+ }
+ TQColor disabled( (fg.red()+btn.red())/2,
+ (fg.green()+btn.green())/2,
+ (fg.blue()+btn.blue())/2);
+ TQColorGroup dcg( disabled, btn, btn.light( 125 ), btn.dark(), btn.dark(150),
+ disabled, TQt::white, TQt::white, bg );
+ if (bright_mode) {
+ dcg.setColor( TQColorGroup::HighlightedText, base );
+ dcg.setColor( TQColorGroup::Highlight, TQt::white );
+ } else {
+ dcg.setColor( TQColorGroup::HighlightedText, TQt::white );
+ dcg.setColor( TQColorGroup::Highlight, TQt::darkBlue );
+ }
+ TQPalette pal( cg, dcg, cg );
+ if ( pal != *qt_std_pal && pal != TQApplication::palette() )
+ TQApplication::tqsetPalette( pal, TRUE );
+ *qt_std_pal = pal;
+ }
+
+ if ( !resEF.isEmpty() ) {
+ TQStringList effects = TQStringList::split(" ",resEF);
+ TQApplication::setEffectEnabled( Qt::UI_General, effects.tqcontains("general") );
+ TQApplication::setEffectEnabled( Qt::UI_AnimateMenu, effects.tqcontains("animatemenu") );
+ TQApplication::setEffectEnabled( Qt::UI_FadeMenu, effects.tqcontains("fademenu") );
+ TQApplication::setEffectEnabled( Qt::UI_AnimateCombo, effects.tqcontains("animatecombo") );
+ TQApplication::setEffectEnabled( Qt::UI_AnimateTooltip, effects.tqcontains("animatetooltip") );
+ TQApplication::setEffectEnabled( Qt::UI_FadeTooltip, effects.tqcontains("fadetooltip") );
+ TQApplication::setEffectEnabled( Qt::UI_AnimateToolBox, effects.tqcontains("animatetoolbox") );
+ }
+}
+
+static void qt_detect_broken_window_manager()
+{
+ Atom type;
+ int format;
+ ulong nitems, after;
+ uchar *data = 0;
+
+ // look for SGI's 4Dwm
+ int e = XGetWindowProperty(QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_sgi_desks_manager, 0, 1, False, XA_WINDOW,
+ &type, &format, &nitems, &after, &data);
+ if (data)
+ XFree(data);
+
+ if (e == Success && type == XA_WINDOW && format == 32 && nitems == 1 && after == 0) {
+ // detected SGI 4Dwm
+ qt_broken_wm = TRUE;
+ }
+}
+
+static GC create_gc( int scrn, bool monochrome )
+{
+ GC gc;
+ if ( monochrome ) {
+ Pixmap pm = XCreatePixmap( QX11Info::display(), RootWindow( QX11Info::display(), scrn ), 8, 8, 1 );
+ gc = XCreateGC( QX11Info::display(), pm, 0, 0 );
+ XFreePixmap( QX11Info::display(), pm );
+ } else {
+ if ( TQPaintDevice::x11AppDefaultVisual( scrn ) ) {
+ gc = XCreateGC( QX11Info::display(), RootWindow( QX11Info::display(), scrn ), 0, 0 );
+ } else {
+ Window w;
+ XSetWindowAttributes a;
+ a.background_pixel = TQt::black.pixel( scrn );
+ a.border_pixel = TQt::black.pixel( scrn );
+ a.colormap = TQPaintDevice::x11AppColormap( scrn );
+ w = XCreateWindow( QX11Info::display(), RootWindow( QX11Info::display(), scrn ), 0, 0, 100, 100,
+ 0, TQPaintDevice::x11AppDepth( scrn ), InputOutput,
+ (Visual*)TQPaintDevice::x11AppVisual( scrn ),
+ CWBackPixel|CWBorderPixel|CWColormap, &a );
+ gc = XCreateGC( QX11Info::display(), w, 0, 0 );
+ XDestroyWindow( QX11Info::display(), w );
+ }
+ }
+ XSetGraphicsExposures( QX11Info::display(), gc, False );
+ return gc;
+}
+
+GC qt_xget_temp_gc( int scrn, bool monochrome ) // get temporary GC
+{
+ if ( scrn < 0 || scrn >= appScreenCount ) {
+ qDebug("invalid screen (tmp) %d %d", scrn, appScreenCount );
+ TQWidget* bla = 0;
+ bla->setName("hello");
+ }
+ GC gc;
+ if ( monochrome ) {
+ if ( !app_gc_tmp_m ) // create GC for bitmap
+ memset( (app_gc_tmp_m = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) );
+ if ( !app_gc_tmp_m[scrn] )
+ app_gc_tmp_m[scrn] = create_gc( scrn, TRUE );
+ gc = app_gc_tmp_m[scrn];
+ } else { // create standard GC
+ if ( !app_gc_tmp )
+ memset( (app_gc_tmp = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) );
+ if ( !app_gc_tmp[scrn] )
+ app_gc_tmp[scrn] = create_gc( scrn, FALSE );
+ gc = app_gc_tmp[scrn];
+ }
+ return gc;
+}
+
+// ### REMOVE 4.0
+WId qt_xrootwin() // get X root window
+{
+ return TQPaintDevice::x11AppRootWindow();
+}
+
+WId qt_xrootwin( int scrn ) // get X root window for screen
+{
+ return TQPaintDevice::x11AppRootWindow( scrn );
+}
+
+bool qt_try_modal( TQWidget *widget, XEvent *event )
+{
+ if (qt_xdnd_dragging) {
+ // allow mouse events while DnD is active
+ switch (event->type) {
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ return TRUE;
+ default:
+ break;
+ }
+ }
+
+ if ( qt_tryModalHelper( widget ) )
+ return TRUE;
+
+ bool block_event = FALSE;
+ switch ( event->type ) {
+ case ButtonPress: // disallow mouse/key events
+ case ButtonRelease:
+ case MotionNotify:
+ case XKeyPress:
+ case XKeyRelease:
+ case EnterNotify:
+ case LeaveNotify:
+ case ClientMessage:
+ block_event = TRUE;
+ break;
+ default:
+ break;
+ }
+
+ return !block_event;
+}
+
+/*****************************************************************************
+ Platform specific global and internal functions
+ *****************************************************************************/
+
+void qt_save_rootinfo() // save new root info
+{
+ Atom type;
+ int format;
+ unsigned long length, after;
+ uchar *data;
+
+ if ( qt_xsetroot_id ) { // kill old pixmap
+ if ( XGetWindowProperty( QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_xsetroot_id, 0, 1,
+ True, AnyPropertyType, &type, &format,
+ &length, &after, &data ) == Success ) {
+ if ( type == XA_PIXMAP && format == 32 && length == 1 &&
+ after == 0 && data ) {
+ XKillClient( QX11Info::display(), *((Pixmap*)data) );
+ }
+ Pixmap dummy = XCreatePixmap( QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ 1, 1, 1 );
+ XChangeProperty( QX11Info::display(), TQPaintDevice::x11AppRootWindow(),
+ qt_xsetroot_id, XA_PIXMAP, 32,
+ PropModeReplace, (uchar *)&dummy, 1 );
+ XSetCloseDownMode( QX11Info::display(), RetainPermanent );
+ }
+ }
+ if ( data )
+ XFree( (char *)data );
+}
+
+/*****************************************************************************
+ qt_init() - initializes TQt for X11
+ *****************************************************************************/
+
+#define XK_MISCELLANY
+#define XK_LATIN1
+#include <X11/keysymdef.h>
+
+// ### This should be static but it isn't because of the friend declaration
+// ### in tqpaintdevice.h which then should have a static too but can't have
+// ### it because "storage class specifiers invalid in friend function
+// ### declarations" :-) Ideas anyone?
+void qt_init_internal( int *argcptr, char **argv,
+ Display *display, TQt::HANDLE visual, TQt::HANDLE colormap )
+{
+ setlocale( LC_ALL, "" ); // use correct char set mapping
+ setlocale( LC_NUMERIC, "C" ); // make sprintf()/scanf() work
+
+ if ( display ) {
+ // TQt part of other application
+
+ appForeignDpy = TRUE;
+// appDpy = display;
+
+ // Set application name and class
+ appName = qstrdup( "TQt-subapplication" );
+ char *app_class = 0;
+ if (argv) {
+ const char* p = strrchr( argv[0], '/' );
+ app_class = qstrdup(p ? p + 1 : argv[0]);
+ if (app_class[0])
+ app_class[0] = toupper(app_class[0]);
+ }
+ appClass = app_class;
+
+ // Install default error handlers
+ original_x_errhandler = XSetErrorHandler( qt_x_errhandler );
+ original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler );
+ } else {
+ // TQt controls everything (default)
+
+ int argc = *argcptr;
+ int j;
+
+ // Install default error handlers
+ original_x_errhandler = XSetErrorHandler( qt_x_errhandler );
+ original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler );
+
+ // Set application name and class
+ char *app_class = 0;
+ if (argv) {
+ const char *p = strrchr( argv[0], '/' );
+ appName = p ? p + 1 : argv[0];
+ app_class = qstrdup(appName);
+ if (app_class[0])
+ app_class[0] = toupper(app_class[0]);
+ }
+ appClass = app_class;
+
+ // Get command line params
+ j = argc ? 1 : 0;
+ for ( int i=1; i<argc; i++ ) {
+ if ( argv[i] && *argv[i] != '-' ) {
+ argv[j++] = argv[i];
+ continue;
+ }
+ TQCString arg = argv[i];
+ if ( arg == "-display" ) {
+ if ( ++i < argc )
+ appDpyName = argv[i];
+ } else if ( arg == "-fn" || arg == "-font" ) {
+ if ( ++i < argc ) {
+ appFont = argv[i];
+ qt_x11_cmdline_font = true;
+ }
+ } else if ( arg == "-bg" || arg == "-background" ) {
+ if ( ++i < argc )
+ appBGCol = argv[i];
+ } else if ( arg == "-btn" || arg == "-button" ) {
+ if ( ++i < argc )
+ appBTNCol = argv[i];
+ } else if ( arg == "-fg" || arg == "-foreground" ) {
+ if ( ++i < argc )
+ appFGCol = argv[i];
+ } else if ( arg == "-name" ) {
+ if ( ++i < argc )
+ appName = argv[i];
+ } else if ( arg == "-title" ) {
+ if ( ++i < argc )
+ mwTitle = argv[i];
+ } else if ( arg == "-tqgeometry" ) {
+ if ( ++i < argc )
+ mwGeometry = argv[i];
+ //Ming-Che 10/10
+ } else if ( arg == "-im" ) {
+ if ( ++i < argc )
+ ximServer = argv[i];
+ } else if ( arg == "-noxim" ) {
+ noxim=TRUE;
+ //
+ } else if ( arg == "-iconic" ) {
+ mwIconic = !mwIconic;
+ } else if ( arg == "-ncols" ) { // xv and netscape use this name
+ if ( ++i < argc )
+ qt_ncols_option = TQMAX(0,atoi(argv[i]));
+ } else if ( arg == "-visual" ) { // xv and netscape use this name
+ if ( ++i < argc ) {
+ TQCString s = TQCString(argv[i]).lower();
+ if ( s == "truecolor" ) {
+ qt_visual_option = TrueColor;
+ } else {
+ // ### Should we honor any others?
+ }
+ }
+#ifndef TQT_NO_XIM
+ } else if ( arg == "-inputstyle" ) {
+ if ( ++i < argc ) {
+ TQCString s = TQCString(argv[i]).lower();
+ if ( s == "onthespot" )
+ xim_preferred_style = XIMPreeditCallbacks |
+ XIMStatusNothing;
+ else if ( s == "overthespot" )
+ xim_preferred_style = XIMPreeditPosition |
+ XIMStatusNothing;
+ else if ( s == "offthespot" )
+ xim_preferred_style = XIMPreeditArea |
+ XIMStatusArea;
+ else if ( s == "root" )
+ xim_preferred_style = XIMPreeditNothing |
+ XIMStatusNothing;
+ }
+#endif
+ } else if ( arg == "-cmap" ) { // xv uses this name
+ qt_cmap_option = TRUE;
+ }
+#if defined(TQT_DEBUG)
+ else if ( arg == "-sync" )
+ appSync = !appSync;
+ else if ( arg == "-nograb" )
+ appNoGrab = !appNoGrab;
+ else if ( arg == "-dograb" )
+ appDoGrab = !appDoGrab;
+#endif
+ else
+ argv[j++] = argv[i];
+ }
+
+ *argcptr = j;
+
+#if defined(TQT_DEBUG) && defined(TQ_OS_LINUX)
+ if ( !appNoGrab && !appDoGrab ) {
+ TQCString s;
+ s.sprintf( "/proc/%d/cmdline", getppid() );
+ TQFile f( s );
+ if ( f.open( IO_ReadOnly ) ) {
+ s.truncate( 0 );
+ int c;
+ while ( (c = TQT_TQIODEVICE_OBJECT(f).getch()) > 0 ) {
+ if ( c == '/' )
+ s.truncate( 0 );
+ else
+ s += (char)c;
+ }
+ if ( s == "gdb" ) {
+ appNoGrab = TRUE;
+ qDebug( "TQt: gdb: -nograb added to command-line options.\n"
+ "\t Use the -dograb option to enforce grabbing." );
+ }
+ f.close();
+ }
+ }
+#endif
+ // Connect to X server
+
+ if( qt_is_gui_used ) {
+// if ( ( appDpy = XOpenDisplay(appDpyName) ) == 0 ) {
+// qWarning( "%s: cannot connect to X server %s", appName,
+// XDisplayName(appDpyName) );
+// tqApp = 0;
+// exit( 1 );
+// }
+
+ if ( appSync ) // if "-sync" argument
+ XSynchronize( QX11Info::display(), TRUE );
+ }
+ }
+ // Common code, regardless of whether display is foreign.
+
+ // Get X parameters
+
+ if( qt_is_gui_used ) {
+// appScreen = DefaultScreen(QX11Info::display());
+ appScreenCount = ScreenCount(QX11Info::display());
+
+ TQPaintDevice::x_appdisplay = QX11Info::display();
+ TQPaintDevice::x_appscreen = QX11Info::appScreen();
+
+ // allocate the arrays for the TQPaintDevice data
+ TQPaintDevice::x_appdepth_arr = new int[ appScreenCount ];
+ TQPaintDevice::x_appcells_arr = new int[ appScreenCount ];
+ TQPaintDevice::x_approotwindow_arr = new TQt::HANDLE[ appScreenCount ];
+ TQPaintDevice::x_appcolormap_arr = new TQt::HANDLE[ appScreenCount ];
+ TQPaintDevice::x_appdefcolormap_arr = new bool[ appScreenCount ];
+ TQPaintDevice::x_appvisual_arr = new void*[ appScreenCount ];
+ TQPaintDevice::x_appdefvisual_arr = new bool[ appScreenCount ];
+ TQ_CHECK_PTR( TQPaintDevice::x_appdepth_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appcells_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_approotwindow_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appcolormap_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appdefcolormap_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appvisual_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appdefvisual_arr );
+
+ int screen;
+ TQString serverVendor( ServerVendor( QX11Info::display()) );
+ if (serverVendor.tqcontains("XFree86") && VendorRelease(QX11Info::display()) < 40300000)
+ qt_hebrew_keyboard_hack = TRUE;
+
+ for ( screen = 0; screen < appScreenCount; ++screen ) {
+ TQPaintDevice::x_appdepth_arr[ screen ] = DefaultDepth(QX11Info::display(), screen);
+ TQPaintDevice::x_appcells_arr[ screen ] = DisplayCells(QX11Info::display(), screen);
+ TQPaintDevice::x_approotwindow_arr[ screen ] = RootWindow(QX11Info::display(), screen);
+
+ // setup the visual and colormap for each screen
+ Visual *vis = 0;
+ if ( visual && screen == QX11Info::appScreen() ) {
+ // use the provided visual on the default screen only
+ vis = (Visual *) visual;
+
+ // figure out the depth of the visual we are using
+ XVisualInfo *vi, rvi;
+ int n;
+ rvi.visualid = XVisualIDFromVisual(vis);
+ rvi.screen = screen;
+ vi = XGetVisualInfo( QX11Info::display(), VisualIDMask | VisualScreenMask, &rvi, &n );
+ if (vi) {
+ TQPaintDevice::x_appdepth_arr[ screen ] = vi->depth;
+ TQPaintDevice::x_appcells_arr[ screen ] = vi->visual->map_entries;
+ TQPaintDevice::x_appvisual_arr[ screen ] = vi->visual;
+ TQPaintDevice::x_appdefvisual_arr[ screen ] = FALSE;
+ XFree(vi);
+ } else {
+ // couldn't get info about the visual, use the default instead
+ vis = 0;
+ }
+ }
+
+ if (!vis) {
+ // use the default visual
+ vis = DefaultVisual(QX11Info::display(), screen);
+ TQPaintDevice::x_appdefvisual_arr[ screen ] = TRUE;
+
+ if ( qt_visual_option == TrueColor ||
+ TQApplication::colorSpec() == TQApplication::ManyColor ) {
+ // tqfind custom visual
+
+ int d, c;
+ vis = tqfind_truecolor_visual( QX11Info::display(), screen, &d, &c );
+ TQPaintDevice::x_appdepth_arr[ screen ] = d;
+ TQPaintDevice::x_appcells_arr[ screen ] = c;
+
+ TQPaintDevice::x_appvisual_arr[ screen ] = vis;
+ TQPaintDevice::x_appdefvisual_arr[ screen ] =
+ (XVisualIDFromVisual(vis) ==
+ XVisualIDFromVisual(DefaultVisual(QX11Info::display(), screen)));
+ }
+
+ TQPaintDevice::x_appvisual_arr[ screen ] = vis;
+ }
+
+ // we assume that 8bpp == pseudocolor, but this is not
+ // always the case (according to the X server), so we need
+ // to make sure that our internal data is setup in a way
+ // that is compatible with our assumptions
+ if ( vis->c_class == TrueColor &&
+ TQPaintDevice::x_appdepth_arr[ screen ] == 8 &&
+ TQPaintDevice::x_appcells_arr[ screen ] == 8 )
+ TQPaintDevice::x_appcells_arr[ screen ] = 256;
+
+ if ( colormap && screen == QX11Info::appScreen() ) {
+ // use the provided colormap for the default screen only
+ TQPaintDevice::x_appcolormap_arr[ screen ] = colormap;
+ TQPaintDevice::x_appdefcolormap_arr[ screen ] = FALSE;
+ } else {
+ if ( vis->c_class == TrueColor ) {
+ TQPaintDevice::x_appdefcolormap_arr[ screen ] =
+ TQPaintDevice::x_appdefvisual_arr[ screen ];
+ } else {
+ TQPaintDevice::x_appdefcolormap_arr[ screen ] =
+ !qt_cmap_option && TQPaintDevice::x_appdefvisual_arr[ screen ];
+ }
+
+ if ( TQPaintDevice::x_appdefcolormap_arr[ screen ] ) {
+ // use default colormap
+ XStandardColormap *stdcmap;
+ VisualID vid =
+ XVisualIDFromVisual((Visual *)
+ TQPaintDevice::x_appvisual_arr[ screen ]);
+ int i, count;
+
+ TQPaintDevice::x_appcolormap_arr[ screen ] = 0;
+
+ if ( ! serverVendor.tqcontains( "Hewlett-Packard" ) ) {
+ // on HPUX 10.20 local displays, the RGB_DEFAULT_MAP colormap
+ // doesn't give us correct colors. Why this happens, I have
+ // no clue, so we disable this for HPUX
+ if (XGetRGBColormaps(QX11Info::display(),
+ TQPaintDevice::x11AppRootWindow( screen ),
+ &stdcmap, &count, XA_RGB_DEFAULT_MAP)) {
+ i = 0;
+ while (i < count &&
+ TQPaintDevice::x_appcolormap_arr[ screen ] == 0) {
+ if (stdcmap[i].visualid == vid) {
+ TQPaintDevice::x_appcolormap_arr[ screen ] =
+ stdcmap[i].colormap;
+ }
+ i++;
+ }
+
+ XFree( (char *)stdcmap );
+ }
+ }
+
+ if (TQPaintDevice::x_appcolormap_arr[ screen ] == 0) {
+ TQPaintDevice::x_appcolormap_arr[ screen ] =
+ DefaultColormap(QX11Info::display(), screen);
+ }
+ } else {
+ // create a custom colormap
+ TQPaintDevice::x_appcolormap_arr[ screen ] =
+ XCreateColormap(QX11Info::display(), TQPaintDevice::x11AppRootWindow( screen ),
+ vis, AllocNone);
+ }
+ }
+ }
+
+ // Set X painttqdevice parameters for the default screen
+ TQPaintDevice::x_appdepth = TQPaintDevice::x_appdepth_arr[ QX11Info::appScreen() ];
+ TQPaintDevice::x_appcells = TQPaintDevice::x_appcells_arr[ QX11Info::appScreen() ];
+ TQPaintDevice::x_approotwindow = TQPaintDevice::x_approotwindow_arr[ QX11Info::appScreen() ];
+ TQPaintDevice::x_appcolormap = TQPaintDevice::x_appcolormap_arr[ QX11Info::appScreen() ];
+ TQPaintDevice::x_appdefcolormap = TQPaintDevice::x_appdefcolormap_arr[ QX11Info::appScreen() ];
+ TQPaintDevice::x_appvisual = TQPaintDevice::x_appvisual_arr[ QX11Info::appScreen() ];
+ TQPaintDevice::x_appdefvisual = TQPaintDevice::x_appdefvisual_arr[ QX11Info::appScreen() ];
+
+ // Support protocols
+
+ qt_x11_intern_atom( "WM_PROTOCOLS", &qt_wm_protocols );
+ qt_x11_intern_atom( "WM_DELETE_WINDOW", &qt_wm_delete_window );
+ qt_x11_intern_atom( "WM_STATE", &qt_wm_state );
+ qt_x11_intern_atom( "WM_CHANGE_STATE", &qt_wm_change_state );
+ qt_x11_intern_atom( "WM_TAKE_FOCUS", &qt_wm_take_focus );
+ qt_x11_intern_atom( "WM_CLIENT_LEADER", &qt_wm_client_leader);
+ qt_x11_intern_atom( "WM_WINDOW_ROLE", &qt_window_role);
+ qt_x11_intern_atom( "SM_CLIENT_ID", &qt_sm_client_id);
+ qt_x11_intern_atom( "CLIPBOARD", &qt_xa_clipboard );
+ qt_x11_intern_atom( "RESOURCE_MANAGER", &qt_resource_manager );
+ qt_x11_intern_atom( "INCR", &qt_x_incr );
+ qt_x11_intern_atom( "_XSETROOT_ID", &qt_xsetroot_id );
+ qt_x11_intern_atom( "_TQT_SELECTION", &qt_selection_property );
+ qt_x11_intern_atom( "_TQT_CLIPBOARD_SENTINEL", &qt_clipboard_sentinel );
+ qt_x11_intern_atom( "_TQT_SELECTION_SENTINEL", &qt_selection_sentinel );
+ qt_x11_intern_atom( "_TQT_SCROLL_DONE", &qt_qt_scrolldone );
+ qt_x11_intern_atom( "_TQT_INPUT_ENCODING", &qt_input_encoding );
+ qt_x11_intern_atom( "_TQT_SIZEGRIP", &qt_sizegrip );
+ qt_x11_intern_atom( "_NET_WM_CONTEXT_HELP", &qt_net_wm_context_help );
+ qt_x11_intern_atom( "_NET_WM_PING", &qt_net_wm_ping );
+ qt_x11_intern_atom( "_MOTIF_WM_HINTS", &qt_xa_motif_wm_hints );
+ qt_x11_intern_atom( "DTWM_IS_RUNNING", &qt_cde_running );
+ qt_x11_intern_atom( "KWIN_RUNNING", &qt_kwin_running );
+ qt_x11_intern_atom( "KWM_RUNNING", &qt_kwm_running );
+ qt_x11_intern_atom( "GNOME_BACKGROUND_PROPERTIES", &qt_gbackground_properties );
+
+ TQString atomname("_TQT_SETTINGS_TIMESTAMP_");
+ atomname += XDisplayName(appDpyName);
+ qt_x11_intern_atom( atomname.latin1(), &qt_settings_timestamp );
+
+ qt_x11_intern_atom( "_NET_SUPPORTED", &qt_net_supported );
+ qt_x11_intern_atom( "_NET_VIRTUAL_ROOTS", &qt_net_virtual_roots );
+ qt_x11_intern_atom( "_NET_WORKAREA", &qt_net_workarea );
+ qt_x11_intern_atom( "_NET_WM_STATE", &qt_net_wm_state );
+ qt_x11_intern_atom( "_NET_WM_STATE_MODAL", &qt_net_wm_state_modal );
+ qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_VERT", &qt_net_wm_state_max_v );
+ qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_HORZ", &qt_net_wm_state_max_h );
+ qt_x11_intern_atom( "_NET_WM_STATE_FULLSCREEN", &qt_net_wm_state_fullscreen );
+ qt_x11_intern_atom( "_NET_WM_STATE_ABOVE", &qt_net_wm_state_above );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE", &qt_net_wm_window_type );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_NORMAL", &qt_net_wm_window_type_normal );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DIALOG", &qt_net_wm_window_type_dialog );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_TOOLBAR", &qt_net_wm_window_type_toolbar );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_MENU", &qt_net_wm_window_type_menu );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_UTILITY", &qt_net_wm_window_type_utility );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_SPLASH", &qt_net_wm_window_type_splash );
+ qt_x11_intern_atom( "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", &qt_net_wm_window_type_override );
+ qt_x11_intern_atom( "_KDE_NET_WM_FRAME_STRUT", &qt_net_wm_frame_strut );
+ qt_x11_intern_atom( "_NET_WM_STATE_STAYS_ON_TOP",
+ &qt_net_wm_state_stays_on_top );
+ qt_x11_intern_atom( "_NET_WM_PID", &qt_net_wm_pid );
+ qt_x11_intern_atom( "_NET_WM_USER_TIME", &qt_net_wm_user_time );
+ qt_x11_intern_atom( "ENLIGHTENMENT_DESKTOP", &qt_enlightenment_desktop );
+ qt_x11_intern_atom( "_NET_WM_NAME", &qt_net_wm_name );
+ qt_x11_intern_atom( "_NET_WM_ICON_NAME", &qt_net_wm_icon_name );
+ qt_x11_intern_atom( "UTF8_STRING", &qt_utf8_string );
+ qt_x11_intern_atom( "_SGI_DESKS_MANAGER", &qt_sgi_desks_manager );
+
+ qt_xdnd_setup();
+ qt_x11_motifdnd_init();
+
+ // Finally create all atoms
+ qt_x11_process_intern_atoms();
+
+ // look for broken window managers
+ qt_detect_broken_window_manager();
+
+ // initialize NET lists
+ qt_get_net_supported();
+ qt_get_net_virtual_roots();
+
+// #ifndef TQT_NO_XRANDR
+// // See if XRandR is supported on the connected display
+// int xrandr_errorbase;
+// TQ_UNUSED( xrandr_eventbase );
+// if ( XRRQueryExtension( QX11Info::display(), &xrandr_eventbase, &xrandr_errorbase ) ) {
+// // XRandR is supported
+// qt_use_xrandr = TRUE;
+// }
+// #endif // TQT_NO_XRANDR
+
+#ifndef TQT_NO_XRENDER
+ // See if XRender is supported on the connected display
+ int xrender_eventbase, xrender_errorbase;
+ if (XRenderQueryExtension(QX11Info::display(), &xrender_eventbase, &xrender_errorbase)) {
+ // XRender is supported, let's see if we have a PictFormat for the
+ // default visual
+ XRenderPictFormat *format =
+ XRenderFindVisualFormat(QX11Info::display(),
+ (Visual *) TQPaintDevice::x_appvisual);
+ qt_use_xrender = (format != 0) && (TQPaintDevice::x_appdepth != 8);
+ }
+#endif // TQT_NO_XRENDER
+
+#ifndef TQT_NO_XKB
+ // If XKB is detected, set the GrabsUseXKBState option so input method
+ // compositions continue to work (ie. deadkeys)
+ unsigned int state = XkbPCF_GrabsUseXKBStateMask;
+ (void) XkbSetPerClientControls(QX11Info::display(), state, &state);
+#endif
+
+// #if !defined(TQT_NO_XFTFREETYPE)
+// // defined in qfont_x11.cpp
+// extern bool qt_has_xft;
+// #ifndef TQT_XFT2
+// if (!qt_use_xrender)
+// qt_has_xft = FALSE;
+// else
+// #endif
+// qt_has_xft = XftInit(0) && XftInitFtLibrary();
+//
+// if (qt_has_xft) {
+// char *dpi_str = XGetDefault(QX11Info::display(), "Xft", "dpi");
+// if (dpi_str) {
+// // use a custom DPI
+// char *end = 0;
+// int dpi = strtol(dpi_str, &end, 0);
+// if (dpi_str != end) {
+// for (int s = 0; s < ScreenCount(QX11Info::display()); ++s) {
+// TQPaintDevice::x11SetAppDpiX(dpi, s);
+// TQPaintDevice::x11SetAppDpiY(dpi, s);
+// }
+// }
+// }
+// }
+// #endif // TQT_NO_XFTFREETYPE
+
+ // look at the modifier mapping, and get the correct masks for alt/meta
+ // tqfind the alt/meta masks
+ XModifierKeymap *map = XGetModifierMapping(QX11Info::display());
+ if (map) {
+ int i, maskIndex = 0, mapIndex = 0;
+ for (maskIndex = 0; maskIndex < 8; maskIndex++) {
+ for (i = 0; i < map->max_keypermod; i++) {
+ if (map->modifiermap[mapIndex]) {
+ KeySym sym =
+ XKeycodeToKeysym(QX11Info::display(), map->modifiermap[mapIndex], 0);
+ if ( qt_alt_mask == 0 &&
+ ( sym == XK_Alt_L || sym == XK_Alt_R ) ) {
+ qt_alt_mask = 1 << maskIndex;
+ }
+ if ( qt_meta_mask == 0 &&
+ (sym == XK_Meta_L || sym == XK_Meta_R ) ) {
+ qt_meta_mask = 1 << maskIndex;
+ }
+ }
+ mapIndex++;
+ }
+ }
+
+ // not look for mode_switch in qt_alt_mask and qt_meta_mask - if it is
+ // present in one or both, then we set qt_mode_switch_remove_mask.
+ // see TQETWidget::translateKeyEventInternal for an explanation
+ // of why this is needed
+ mapIndex = 0;
+ for ( maskIndex = 0; maskIndex < 8; maskIndex++ ) {
+ if ( qt_alt_mask != ( 1 << maskIndex ) &&
+ qt_meta_mask != ( 1 << maskIndex ) ) {
+ for ( i = 0; i < map->max_keypermod; i++ )
+ mapIndex++;
+ continue;
+ }
+
+ for ( i = 0; i < map->max_keypermod; i++ ) {
+ if ( map->modifiermap[ mapIndex ] ) {
+ KeySym sym =
+ XKeycodeToKeysym( QX11Info::display(), map->modifiermap[ mapIndex ], 0 );
+ if ( sym == XK_Mode_switch ) {
+ qt_mode_switch_remove_mask |= 1 << maskIndex;
+ }
+ }
+ mapIndex++;
+ }
+ }
+
+ XFreeModifiermap(map);
+ } else {
+ // assume defaults
+ qt_alt_mask = Mod1Mask;
+ qt_meta_mask = Mod4Mask;
+ qt_mode_switch_remove_mask = 0;
+ }
+
+ // Misc. initialization
+
+ TQColor::initialize();
+ TQFont::initialize();
+ TQCursor::initialize();
+ TQPainter::initialize();
+ }
+
+#if defined(TQT_THREAD_SUPPORT)
+ TQThread::initialize();
+#endif
+
+ if( qt_is_gui_used ) {
+ TQT_TQOBJECT(tqApp)->setName( appName );
+
+ int screen;
+ for ( screen = 0; screen < appScreenCount; ++screen ) {
+ XSelectInput( QX11Info::display(), TQPaintDevice::x11AppRootWindow( screen ),
+ KeymapStateMask | EnterWindowMask | LeaveWindowMask |
+ PropertyChangeMask );
+
+// #ifndef TQT_NO_XRANDR
+// if (qt_use_xrandr)
+// XRRSelectInput( QX11Info::display(), TQPaintDevice::x11AppRootWindow( screen ), True );
+// #endif // TQT_NO_XRANDR
+ }
+ }
+
+ if ( qt_is_gui_used ) {
+ qt_set_input_encoding();
+
+ qt_set_x11_resources( appFont, appFGCol, appBGCol, appBTNCol);
+
+ // be smart about the size of the default font. most X servers have helvetica
+ // 12 point available at 2 resolutions:
+ // 75dpi (12 pixels) and 100dpi (17 pixels).
+ // At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17
+ // pixel font is a closer match than a 12 pixel font
+ int ptsz =
+ (int) ( ( ( TQPaintDevice::x11AppDpiY() >= 95 ? 17. : 12. ) *
+ 72. / (float) TQPaintDevice::x11AppDpiY() ) + 0.5 );
+
+ if ( !qt_app_has_font && !qt_x11_cmdline_font ) {
+ TQFont f( "Helvetica", ptsz );
+ TQApplication::setFont( f );
+ }
+
+#ifndef TQT_NO_XIM
+ if ( ! xim_preferred_style ) // no configured input style, use the default
+ xim_preferred_style = xim_default_style;
+
+ qt_xim = 0;
+ TQString ximServerName(ximServer);
+ if (ximServer)
+ ximServerName.prepend("@im=");
+ else
+ ximServerName = "";
+
+ if ( !XSupportsLocale() )
+ qWarning("TQt: Locales not supported on X server");
+
+#ifdef USE_X11R6_XIM
+ else if ( XSetLocaleModifiers (ximServerName.ascii()) == 0 )
+ qWarning( "TQt: Cannot set locale modifiers: %s",
+ ximServerName.ascii());
+ else if (! noxim)
+ XRegisterIMInstantiateCallback(QX11Info::display(), 0, 0, 0,
+ (XIMProc) xim_create_callback, 0);
+#else // !USE_X11R6_XIM
+ else if ( XSetLocaleModifiers ("") == 0 )
+ qWarning("TQt: Cannot set locale modifiers");
+ else if (! noxim)
+ TQApplication::create_xim();
+#endif // USE_X11R6_XIM
+#endif // TQT_NO_XIM
+
+#if defined (TQT_TABLET_SUPPORT)
+ int ndev,
+ i,
+ j;
+ bool gotStylus,
+ gotEraser;
+ XDeviceInfo *tqdevices, *devs;
+ XInputClassInfo *ip;
+ XAnyClassPtr any;
+ XValuatorInfoPtr v;
+ XAxisInfoPtr a;
+ XDevice *dev;
+ XEventClass *ev_class;
+ int curr_event_count;
+
+#if !defined(TQ_OS_IRIX)
+ // XFree86 divides a stylus and eraser into 2 tqdevices, so we must do for both...
+ const TQString XFREENAMESTYLUS = "stylus";
+ const TQString XFREENAMEPEN = "pen";
+ const TQString XFREENAMEERASER = "eraser";
+#endif
+
+ tqdevices = XListInputDevices( QX11Info::display(), &ndev);
+ if ( tqdevices == NULL ) {
+ qWarning( "Failed to get list of tqdevices" );
+ ndev = -1;
+ }
+ dev = NULL;
+ for ( devs = tqdevices, i = 0; i < ndev; i++, devs++ ) {
+ gotEraser = FALSE;
+#if defined(TQ_OS_IRIX)
+
+ gotStylus = ( !strncmp(devs->name,
+ WACOM_NAME, sizeof(WACOM_NAME) - 1) );
+#else
+ TQString devName = devs->name;
+ devName = devName.lower();
+ gotStylus = ( devName.startsWith(XFREENAMEPEN)
+ || devName.startsWith(XFREENAMESTYLUS) );
+ if ( !gotStylus )
+ gotEraser = devName.startsWith( XFREENAMEERASER );
+
+#endif
+ if ( gotStylus || gotEraser ) {
+ // I only wanted to do this once, so wrap pointers around these
+ curr_event_count = 0;
+
+ if ( gotStylus ) {
+ devStylus = XOpenDevice( QX11Info::display(), devs->id );
+ dev = devStylus;
+ ev_class = event_list_stylus;
+ } else if ( gotEraser ) {
+ devEraser = XOpenDevice( QX11Info::display(), devs->id );
+ dev = devEraser;
+ ev_class = event_list_eraser;
+ }
+ if ( dev == NULL ) {
+ qWarning( "Failed to open tqdevice" );
+ } else {
+ if ( dev->num_classes > 0 ) {
+ for ( ip = dev->classes, j = 0; j < devs->num_classes;
+ ip++, j++ ) {
+ switch ( ip->input_class ) {
+ case KeyClass:
+ DeviceKeyPress( dev, xinput_key_press,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ DeviceKeyRelease( dev, xinput_key_release,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ break;
+ case ButtonClass:
+ DeviceButtonPress( dev, xinput_button_press,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ DeviceButtonRelease( dev, xinput_button_release,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ break;
+ case ValuatorClass:
+ // I'm only going to be interested in motion when the
+ // stylus is already down anyway!
+ DeviceMotionNotify( dev, xinput_motion,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ // get the min/max value for pressure!
+ any = (XAnyClassPtr) ( devs->inputclassinfo );
+ if ( dev == devStylus ) {
+ qt_curr_events_stylus = curr_event_count;
+ for (j = 0; j < devs->num_classes; j++) {
+ if ( any->c_class == ValuatorClass ) {
+ v = (XValuatorInfoPtr) any;
+ a = (XAxisInfoPtr) ((char *) v +
+ sizeof (XValuatorInfo));
+#if defined (TQ_OS_IRIX)
+ max_pressure = a[WAC_PRESSURE_I].max_value;
+#else
+ max_pressure = a[2].max_value;
+#endif
+ // got the max pressure no need to go further...
+ break;
+ }
+ any = (XAnyClassPtr) ((char *) any + any->length);
+ }
+ } else {
+ qt_curr_events_eraser = curr_event_count;
+ }
+ // at this point we are assuming there is only one
+ // wacom tqdevice...
+#if defined (TQ_OS_IRIX)
+ if ( devStylus != NULL ) {
+#else
+ if ( devStylus != NULL && devEraser != NULL ) {
+#endif
+ break;
+ }
+ }
+ } // end for loop
+ XFreeDeviceList( tqdevices );
+#endif // TQT_TABLET_SUPPORT
+
+ } else {
+ // read some non-GUI settings when not using the X server...
+
+ if ( TQApplication::desktopSettingsAware() ) {
+ TQSettings settings;
+
+ // read library (ie. plugin) path list
+ TQString libpathkey = TQString("/qt/%1.%2/libraryPath")
+ .arg( TQT_VERSION >> 16 )
+ .arg( (TQT_VERSION & 0xff00 ) >> 8 );
+ TQStringList pathlist =
+ settings.readListEntry(libpathkey, ':');
+ if (! pathlist.isEmpty()) {
+ TQStringList::ConstIterator it = pathlist.begin();
+ while (it != pathlist.end())
+ TQApplication::addLibraryPath(*it++);
+ }
+
+ TQString defaultcodec = settings.readEntry("/qt/defaultCodec", "none");
+ if (defaultcodec != "none") {
+ TQTextCodec *codec = TQTextCodec::codecForName(defaultcodec);
+ if (codec)
+ tqApp->setDefaultCodec(codec);
+ }
+
+ qt_resolve_symlinks =
+ settings.readBoolEntry("/qt/resolveSymlinks", TRUE);
+ }
+ }
+ }
+
+void qt_init( int *argcptr, char **argv, TQApplication::Type )
+{
+ qt_init_internal( argcptr, argv, 0, 0, 0 );
+}
+
+void qt_init( Display *display, TQt::HANDLE visual, TQt::HANDLE colormap )
+{
+ qt_init_internal( 0, 0, display, visual, colormap );
+}
+
+/*****************************************************************************
+ qt_cleanup() - cleans up when the application is finished
+ *****************************************************************************/
+
+void qt_cleanup()
+{
+ appliedstamp = 0;
+
+ if ( app_save_rootinfo ) // root window must keep state
+ qt_save_rootinfo();
+
+ if ( qt_is_gui_used ) {
+ TQPixmapCache::clear();
+ TQPainter::cleanup();
+ TQCursor::cleanup();
+ TQFont::cleanup();
+ TQColor::cleanup();
+ TQSharedDoubleBuffer::cleanup();
+ }
+#if defined(TQT_THREAD_SUPPORT)
+ TQThread::cleanup();
+#endif
+
+#if defined (TQT_TABLET_SUPPORT)
+ if ( devStylus != NULL )
+ XCloseDevice( QX11Info::display(), devStylus );
+ if ( devEraser != NULL )
+ XCloseDevice( QX11Info::display(), devEraser );
+#endif
+
+#if !defined(TQT_NO_XIM)
+ if ( qt_xim )
+ TQApplication::close_xim();
+#endif
+
+ if ( qt_is_gui_used ) {
+ int screen;
+ for ( screen = 0; screen < appScreenCount; screen++ ) {
+ if ( ! TQPaintDevice::x11AppDefaultColormap( screen ) )
+ XFreeColormap( TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppColormap( screen ) );
+ }
+ }
+
+#define TQT_CLEANUP_GC(g) if (g) { for (int i=0;i<appScreenCount;i++){if(g[i])XFreeGC(QX11Info::display(),g[i]);} delete [] g; g = 0; }
+ TQT_CLEANUP_GC(app_gc_ro);
+ TQT_CLEANUP_GC(app_gc_ro_m);
+ TQT_CLEANUP_GC(app_gc_tmp);
+ TQT_CLEANUP_GC(app_gc_tmp_m);
+#undef TQT_CLEANUP_GC
+
+ delete sip_list;
+ sip_list = 0;
+
+ // Reset the error handlers
+ XSetErrorHandler( original_x_errhandler );
+ XSetIOErrorHandler( original_xio_errhandler );
+
+ if ( qt_is_gui_used && !appForeignDpy )
+ XCloseDisplay( QX11Info::display() ); // close X display
+// appDpy = 0;
+
+ qt_x11_wm_client_leader = 0;
+
+ if ( TQPaintDevice::x_appdepth_arr )
+ delete [] TQPaintDevice::x_appdepth_arr;
+ if ( TQPaintDevice::x_appcells_arr )
+ delete [] TQPaintDevice::x_appcells_arr;
+ if ( TQPaintDevice::x_appcolormap_arr )
+ delete []TQPaintDevice::x_appcolormap_arr;
+ if ( TQPaintDevice::x_appdefcolormap_arr )
+ delete [] TQPaintDevice::x_appdefcolormap_arr;
+ if ( TQPaintDevice::x_appvisual_arr )
+ delete [] TQPaintDevice::x_appvisual_arr;
+ if ( TQPaintDevice::x_appdefvisual_arr )
+ delete [] TQPaintDevice::x_appdefvisual_arr;
+
+ if ( appForeignDpy ) {
+ delete [] (char *)appName;
+ appName = 0;
+ delete [] (char *)appClass;
+ appClass = 0;
+ }
+
+ if (qt_net_supported_list)
+ delete [] qt_net_supported_list;
+ qt_net_supported_list = 0;
+
+ if (qt_net_virtual_root_list)
+ delete [] qt_net_virtual_root_list;
+ qt_net_virtual_root_list = 0;
+}
+
+const char *tqAppName() // get application name
+{
+ return appName;
+}
+
+const char *tqAppClass() // get application class
+{
+ return appClass;
+}
+
+// /*****************************************************************************
+// Session management support
+// *****************************************************************************/
+//
+// #ifndef TQT_NO_SM_SUPPORT
+//
+// #include <X11/SM/SMlib.h>
+//
+// class TQSessionManagerData
+// {
+// public:
+// TQSessionManagerData( TQSessionManager* mgr, TQString& id, TQString& key )
+// : sm( mgr ), sessionId( id ), sessionKey( key ) {}
+// TQSessionManager* sm;
+// TQStringList restartCommand;
+// TQStringList discardCommand;
+// TQString& sessionId;
+// TQString& sessionKey;
+// TQSessionManager::RestartHint restartHint;
+// };
+//
+// class TQSmSocketReceiver : public TQObject
+// {
+// Q_OBJECT
+// TQ_OBJECT
+// public:
+// TQSmSocketReceiver( int socket )
+// : TQObject(0,0)
+// {
+// TQSocketNotifier* sn = new TQSocketNotifier( socket, TQSocketNotifier::Read, this );
+// connect( sn, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( socketActivated(int) ) );
+// }
+//
+// public Q_SLOTS:
+// void socketActivated(int);
+// };
+//
+//
+// static SmcConn smcConnection = 0;
+// static bool sm_interactionActive;
+// static bool sm_smActive;
+// static int sm_interactStyle;
+// static int sm_saveType;
+// static bool sm_cancel;
+// // static bool sm_waitingForPhase2; ### never used?!?
+// static bool sm_waitingForInteraction;
+// static bool sm_isshutdown;
+// // static bool sm_shouldbefast; ### never used?!?
+// static bool sm_phase2;
+// static bool sm_in_phase2;
+//
+// static TQSmSocketReceiver* sm_receiver = 0;
+//
+// static void resetSmState();
+// static void sm_setProperty( const char* name, const char* type,
+// int num_vals, SmPropValue* vals);
+// static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData,
+// int saveType, Bool shutdown , int interactStyle, Bool fast);
+// static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData ) ;
+// static void sm_dieCallback( SmcConn smcConn, SmPointer clientData ) ;
+// static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer clientData );
+// static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer clientData );
+// static void sm_interactCallback( SmcConn smcConn, SmPointer clientData );
+// static void sm_performSaveYourself( TQSessionManagerData* );
+//
+// static void resetSmState()
+// {
+// // sm_waitingForPhase2 = FALSE; ### never used?!?
+// sm_waitingForInteraction = FALSE;
+// sm_interactionActive = FALSE;
+// sm_interactStyle = SmInteractStyleNone;
+// sm_smActive = FALSE;
+// sm_blockUserInput = FALSE;
+// sm_isshutdown = FALSE;
+// // sm_shouldbefast = FALSE; ### never used?!?
+// sm_phase2 = FALSE;
+// sm_in_phase2 = FALSE;
+// }
+//
+//
+// // theoretically it's possible to set several properties at once. For
+// // simplicity, however, we do just one property at a time
+// static void sm_setProperty( const char* name, const char* type,
+// int num_vals, SmPropValue* vals)
+// {
+// if (num_vals ) {
+// SmProp prop;
+// prop.name = (char*)name;
+// prop.type = (char*)type;
+// prop.num_vals = num_vals;
+// prop.vals = vals;
+//
+// SmProp* props[1];
+// props[0] = &prop;
+// SmcSetProperties( smcConnection, 1, props );
+// }
+// else {
+// char* names[1];
+// names[0] = (char*) name;
+// SmcDeleteProperties( smcConnection, 1, names );
+// }
+// }
+//
+// static void sm_setProperty( const TQString& name, const TQString& value)
+// {
+// SmPropValue prop;
+// prop.length = value.length();
+// prop.value = (SmPointer) value.latin1();
+// sm_setProperty( name.latin1(), SmARRAY8, 1, &prop );
+// }
+//
+// static void sm_setProperty( const TQString& name, const TQStringList& value)
+// {
+// SmPropValue *prop = new SmPropValue[ value.count() ];
+// int count = 0;
+// for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) {
+// prop[ count ].length = (*it).length();
+// prop[ count ].value = (char*)(*it).latin1();
+// ++count;
+// }
+// sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop );
+// delete [] prop;
+// }
+//
+//
+// // workaround for broken libsm, see below
+// struct TQT_smcConn {
+// unsigned int save_yourself_in_progress : 1;
+// unsigned int shutdown_in_progress : 1;
+// };
+//
+// static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData,
+// int saveType, Bool shutdown , int interactStyle, Bool /*fast*/)
+// {
+// if (smcConn != smcConnection )
+// return;
+// sm_cancel = FALSE;
+// sm_smActive = TRUE;
+// sm_isshutdown = shutdown;
+// sm_saveType = saveType;
+// sm_interactStyle = interactStyle;
+// // sm_shouldbefast = fast; ### never used?!?
+//
+// // ugly workaround for broken libSM. libSM should do that _before_
+// // actually invoking the callback in sm_process.c
+// ( (TQT_smcConn*)smcConn )->save_yourself_in_progress = TRUE;
+// if ( sm_isshutdown )
+// ( (TQT_smcConn*)smcConn )->shutdown_in_progress = TRUE;
+//
+// sm_performSaveYourself( (TQSessionManagerData*) clientData );
+// if ( !sm_isshutdown ) // we cannot expect a confirmation message in that case
+// resetSmState();
+// }
+//
+// static void sm_performSaveYourself( TQSessionManagerData* smd )
+// {
+// if ( sm_isshutdown )
+// sm_blockUserInput = TRUE;
+//
+// TQSessionManager* sm = smd->sm;
+//
+// // generate a new session key
+// timeval tv;
+// gettimeofday( &tv, 0 );
+// smd->sessionKey = TQString::number( tv.tv_sec ) + "_" + TQString::number(tv.tv_usec);
+//
+// // tell the session manager about our program in best POSIX style
+// sm_setProperty( SmProgram, TQString( tqApp->argv()[0] ) );
+// // tell the session manager about our user as well.
+// struct passwd* entry = getpwuid( geteuid() );
+// if ( entry )
+// sm_setProperty( SmUserID, TQString::tqfromLatin1( entry->pw_name ) );
+//
+// // generate a restart and discard command that makes sense
+// TQStringList restart;
+// restart << tqApp->argv()[0] << "-session" << smd->sessionId + "_" + smd->sessionKey;
+// if (qstricmp(tqAppName(), tqAppClass()) != 0)
+// restart << "-name" << tqAppName();
+// sm->setRestartCommand( restart );
+// TQStringList discard;
+// sm->setDiscardCommand( discard );
+//
+// switch ( sm_saveType ) {
+// case SmSaveBoth:
+// tqApp->commitData( *sm );
+// if ( sm_isshutdown && sm_cancel)
+// break; // we cancelled the shutdown, no need to save state
+// // fall through
+// case SmSaveLocal:
+// tqApp->saveState( *sm );
+// break;
+// case SmSaveGlobal:
+// tqApp->commitData( *sm );
+// break;
+// default:
+// break;
+// }
+//
+// if ( sm_phase2 && !sm_in_phase2 ) {
+// SmcRequestSaveYourselfPhase2( smcConnection, sm_saveYourselfPhase2Callback, (SmPointer*) smd );
+// sm_blockUserInput = FALSE;
+// }
+// else {
+// // close eventual interaction monitors and cancel the
+// // shutdown, if required. Note that we can only cancel when
+// // performing a shutdown, it does not work for checkpoints
+// if ( sm_interactionActive ) {
+// SmcInteractDone( smcConnection, sm_isshutdown && sm_cancel);
+// sm_interactionActive = FALSE;
+// }
+// else if ( sm_cancel && sm_isshutdown ) {
+// if ( sm->allowsErrorInteraction() ) {
+// SmcInteractDone( smcConnection, True );
+// sm_interactionActive = FALSE;
+// }
+// }
+//
+// // set restart and discard command in session manager
+// sm_setProperty( SmRestartCommand, sm->restartCommand() );
+// sm_setProperty( SmDiscardCommand, sm->discardCommand() );
+//
+// // set the restart hint
+// SmPropValue prop;
+// prop.length = sizeof( int );
+// int value = sm->restartHint();
+// prop.value = (SmPointer) &value;
+// sm_setProperty( SmRestartStyleHint, SmCARD8, 1, &prop );
+//
+// // we are done
+// SmcSaveYourselfDone( smcConnection, !sm_cancel );
+// }
+// }
+//
+// static void sm_dieCallback( SmcConn smcConn, SmPointer /* clientData */)
+// {
+// if (smcConn != smcConnection )
+// return;
+// resetSmState();
+// TQEvent quitEvent(TQEvent::Quit);
+// TQApplication::sendEvent(tqApp, &quitEvent);
+// }
+//
+// static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer /* clientData */)
+// {
+// if (smcConn != smcConnection )
+// return;
+// if ( sm_waitingForInteraction )
+// tqApp->exit_loop();
+// resetSmState();
+// }
+//
+// static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer /*clientData */)
+// {
+// if (smcConn != smcConnection )
+// return;
+// resetSmState();
+// }
+//
+// static void sm_interactCallback( SmcConn smcConn, SmPointer /* clientData */ )
+// {
+// if (smcConn != smcConnection )
+// return;
+// if ( sm_waitingForInteraction )
+// tqApp->exit_loop();
+// }
+//
+// static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData )
+// {
+// if (smcConn != smcConnection )
+// return;
+// sm_in_phase2 = TRUE;
+// sm_performSaveYourself( (TQSessionManagerData*) clientData );
+// }
+//
+//
+// void TQSmSocketReceiver::socketActivated(int)
+// {
+// IceProcessMessages( SmcGetIceConnection( smcConnection ), 0, 0);
+// }
+//
+//
+// #undef Bool
+// #include "tqapplication_x11.tqmoc"
+//
+// TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString& key )
+// : TQObject( app, "session manager" )
+// {
+// d = new TQSessionManagerData( this, id, key );
+// d->restartHint = RestartIfRunning;
+//
+// resetSmState();
+// char cerror[256];
+// char* myId = 0;
+// char* prevId = (char*)id.latin1(); // we know what we are doing
+//
+// SmcCallbacks cb;
+// cb.save_yourself.callback = sm_saveYourselfCallback;
+// cb.save_yourself.client_data = (SmPointer) d;
+// cb.die.callback = sm_dieCallback;
+// cb.die.client_data = (SmPointer) d;
+// cb.save_complete.callback = sm_saveCompleteCallback;
+// cb.save_complete.client_data = (SmPointer) d;
+// cb.shutdown_cancelled.callback = sm_shutdownCancelledCallback;
+// cb.shutdown_cancelled.client_data = (SmPointer) d;
+//
+// // avoid showing a warning message below
+// const char* session_manager = getenv("SESSION_MANAGER");
+// if ( !session_manager || !session_manager[0] )
+// return;
+//
+// smcConnection = SmcOpenConnection( 0, 0, 1, 0,
+// SmcSaveYourselfProcMask |
+// SmcDieProcMask |
+// SmcSaveCompleteProcMask |
+// SmcShutdownCancelledProcMask,
+// &cb,
+// prevId,
+// &myId,
+// 256, cerror );
+//
+// id = TQString::tqfromLatin1( myId );
+// ::free( myId ); // it was allocated by C
+//
+// TQString error = cerror;
+// if (!smcConnection ) {
+// qWarning("Session management error: %s", error.latin1() );
+// }
+// else {
+// sm_receiver = new TQSmSocketReceiver( IceConnectionNumber( SmcGetIceConnection( smcConnection ) ) );
+// }
+// }
+//
+// TQSessionManager::~TQSessionManager()
+// {
+// if ( smcConnection )
+// SmcCloseConnection( smcConnection, 0, 0 );
+// smcConnection = 0;
+// delete sm_receiver;
+// delete d;
+// }
+//
+// TQString TQSessionManager::sessionId() const
+// {
+// return d->sessionId;
+// }
+//
+// TQString TQSessionManager::sessionKey() const
+// {
+// return d->sessionKey;
+// }
+//
+//
+// void* TQSessionManager::handle() const
+// {
+// return (void*) smcConnection;
+// }
+//
+//
+// bool TQSessionManager::allowsInteraction()
+// {
+// if ( sm_interactionActive )
+// return TRUE;
+//
+// if ( sm_waitingForInteraction )
+// return FALSE;
+//
+// if ( sm_interactStyle == SmInteractStyleAny ) {
+// sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogNormal,
+// sm_interactCallback, (SmPointer*) this );
+// }
+// if ( sm_waitingForInteraction ) {
+// tqApp->enter_loop();
+// sm_waitingForInteraction = FALSE;
+// if ( sm_smActive ) { // not cancelled
+// sm_interactionActive = TRUE;
+// sm_blockUserInput = FALSE;
+// return TRUE;
+// }
+// }
+// return FALSE;
+// }
+//
+// bool TQSessionManager::allowsErrorInteraction()
+// {
+// if ( sm_interactionActive )
+// return TRUE;
+//
+// if ( sm_waitingForInteraction )
+// return FALSE;
+//
+// if ( sm_interactStyle == SmInteractStyleAny || sm_interactStyle == SmInteractStyleErrors ) {
+// sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogError,
+// sm_interactCallback, (SmPointer*) this );
+// }
+// if ( sm_waitingForInteraction ) {
+// tqApp->enter_loop();
+// sm_waitingForInteraction = FALSE;
+// if ( sm_smActive ) { // not cancelled
+// sm_interactionActive = TRUE;
+// sm_blockUserInput = FALSE;
+// return TRUE;
+// }
+// }
+// return FALSE;
+// }
+//
+// void TQSessionManager::release()
+// {
+// if ( sm_interactionActive ) {
+// SmcInteractDone( smcConnection, False );
+// sm_interactionActive = FALSE;
+// if ( sm_smActive && sm_isshutdown )
+// sm_blockUserInput = TRUE;
+// }
+// }
+//
+// void TQSessionManager::cancel()
+// {
+// sm_cancel = TRUE;
+// }
+//
+// void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint)
+// {
+// d->restartHint = hint;
+// }
+//
+// TQSessionManager::RestartHint TQSessionManager::restartHint() const
+// {
+// return d->restartHint;
+// }
+//
+// void TQSessionManager::setRestartCommand( const TQStringList& command)
+// {
+// d->restartCommand = command;
+// }
+//
+// TQStringList TQSessionManager::restartCommand() const
+// {
+// return d->restartCommand;
+// }
+//
+// void TQSessionManager::setDiscardCommand( const TQStringList& command)
+// {
+// d->discardCommand = command;
+// }
+//
+// TQStringList TQSessionManager::discardCommand() const
+// {
+// return d->discardCommand;
+// }
+//
+// void TQSessionManager::setManagerProperty( const TQString& name, const TQString& value)
+// {
+// SmPropValue prop;
+// prop.length = value.length();
+// prop.value = (SmPointer) value.utf8().data();
+// sm_setProperty( name.latin1(), SmARRAY8, 1, &prop );
+// }
+//
+// void TQSessionManager::setManagerProperty( const TQString& name, const TQStringList& value)
+// {
+// SmPropValue *prop = new SmPropValue[ value.count() ];
+// int count = 0;
+// for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) {
+// prop[ count ].length = (*it).length();
+// prop[ count ].value = (char*)(*it).utf8().data();
+// ++count;
+// }
+// sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop );
+// delete [] prop;
+// }
+//
+// bool TQSessionManager::isPhase2() const
+// {
+// return sm_in_phase2;
+// }
+//
+// void TQSessionManager::requestPhase2()
+// {
+// sm_phase2 = TRUE;
+// }
+//
+// #endif // TQT_NO_SM_SUPPORT
+
+void qt_enter_modal( TQWidget *widget )
+{
+ if ( !qt_modal_stack ) { // create modal stack
+ qt_modal_stack = new TQWidgetList;
+ TQ_CHECK_PTR( qt_modal_stack );
+ }
+ if (widget->parentWidget()) {
+ TQEvent e(TQEvent::WindowBlocked);
+ TQApplication::sendEvent(widget->parentWidget(), &e);
+ }
+
+ qt_dispatchEnterLeave( 0, TQWidget::tqfind((WId)curWin) );
+ qt_modal_stack->insert( 0, widget );
+ app_do_modal = TRUE;
+ curWin = 0;
+ ignoreNextMouseReleaseEvent = FALSE;
+}
+
+
+void qt_leave_modal( TQWidget *widget )
+{
+ if ( qt_modal_stack && qt_modal_stack->removeRef(widget) ) {
+ if ( qt_modal_stack->isEmpty() ) {
+ delete qt_modal_stack;
+ qt_modal_stack = 0;
+ TQPoint p( TQCursor::pos() );
+ TQWidget* w = TQApplication::widgetAt( p.x(), p.y(), TRUE );
+ qt_dispatchEnterLeave( w, TQWidget::tqfind( curWin ) ); // send synthetic enter event
+ curWin = w? w->winId() : 0;
+ }
+ }
+ app_do_modal = qt_modal_stack != 0;
+ ignoreNextMouseReleaseEvent = TRUE;
+
+ if (widget->parentWidget()) {
+ TQEvent e(TQEvent::WindowUnblocked);
+ TQApplication::sendEvent(widget->parentWidget(), &e);
+ }
+}
+
+#else // USE_QT4
+
+/*****************************************************************************
+ Internal variables and functions
+ *****************************************************************************/
+static const char *appName; // application name
+static const char *appClass; // application class
+static const char *appFont = 0; // application font
+static const char *appBGCol = 0; // application bg color
+static const char *appFGCol = 0; // application fg color
+static const char *appBTNCol = 0; // application btn color
+static const char *mwGeometry = 0; // main widget tqgeometry
+static const char *mwTitle = 0; // main widget title
+//Ming-Che 10/10
+static char *ximServer = 0; // XIM Server will connect to
+static bool mwIconic = FALSE; // main widget iconified
+//Ming-Che 10/10
+static bool noxim = FALSE; // connect to xim or not
+static Display *appDpy = 0; // X11 application display
+static char *appDpyName = 0; // X11 display name
+static bool appForeignDpy = FALSE; // we didn't create display
+static bool appSync = FALSE; // X11 synchronization
+#if defined(TQT_DEBUG)
+static bool appNoGrab = FALSE; // X11 grabbing enabled
+static bool appDoGrab = FALSE; // X11 grabbing override (gdb)
+#endif
+static int appScreen; // X11 screen number
+static int appScreenCount; // X11 screen count
+static bool app_save_rootinfo = FALSE; // save root info
+static bool app_do_modal = FALSE; // modal mode
+static Window curWin = 0; // current window
+
+static GC* app_gc_ro = 0; // read-only GC
+static GC* app_gc_tmp = 0; // temporary GC
+static GC* app_gc_ro_m = 0; // read-only GC (monochrome)
+static GC* app_gc_tmp_m = 0; // temporary GC (monochrome)
+// symbols needed by extern TQXEmbed class
+TQ_EXPORT Atom qt_wm_protocols = 0; // window manager protocols
+TQ_EXPORT Atom qt_wm_delete_window = 0; // delete window protocol
+TQ_EXPORT Atom qt_wm_take_focus = 0; // take focus window protocol
+
+Atom qt_qt_scrolldone = 0; // scroll synchronization
+Atom qt_net_wm_context_help = 0; // context help
+Atom qt_net_wm_ping = 0; // _NET_WM_PING protocol
+
+static Atom qt_xsetroot_id = 0;
+Atom qt_xa_clipboard = 0;
+Atom qt_selection_property = 0;
+Atom qt_clipboard_sentinel = 0;
+Atom qt_selection_sentinel = 0;
+TQ_EXPORT Atom qt_wm_state = 0;
+Atom qt_wm_change_state = 0;
+static Atom qt_settings_timestamp = 0; // TQt >=3 settings timestamp
+static Atom qt_input_encoding = 0; // TQt desktop properties
+static Atom qt_resource_manager = 0; // X11 Resource manager
+Atom qt_sizegrip = 0; // sizegrip
+Atom qt_wm_client_leader = 0;
+TQ_EXPORT Atom qt_window_role = 0;
+TQ_EXPORT Atom qt_sm_client_id = 0;
+Atom qt_xa_motif_wm_hints = 0;
+Atom qt_cde_running = 0;
+Atom qt_kwin_running = 0;
+Atom qt_kwm_running = 0;
+Atom qt_gbackground_properties = 0;
+Atom qt_x_incr = 0;
+Atom qt_utf8_string = 0;
+
+// detect broken window managers
+Atom qt_sgi_desks_manager = 0;
+bool qt_broken_wm = FALSE;
+static void qt_detect_broken_window_manager();
+
+// NET WM support
+Atom qt_net_supported = 0;
+Atom qt_net_wm_name = 0;
+Atom qt_net_wm_icon_name = 0;
+Atom qt_net_virtual_roots = 0;
+Atom qt_net_workarea = 0;
+Atom qt_net_wm_state = 0;
+Atom qt_net_wm_state_modal = 0;
+Atom qt_net_wm_state_max_v = 0;
+Atom qt_net_wm_state_max_h = 0;
+Atom qt_net_wm_state_fullscreen = 0;
+Atom qt_net_wm_state_above = 0;
+Atom qt_net_wm_window_type = 0;
+Atom qt_net_wm_window_type_normal = 0;
+Atom qt_net_wm_window_type_dialog = 0;
+Atom qt_net_wm_window_type_toolbar = 0;
+Atom qt_net_wm_window_type_menu = 0;
+Atom qt_net_wm_window_type_utility = 0;
+Atom qt_net_wm_window_type_splash = 0;
+Atom qt_net_wm_window_type_override = 0; // KDE extension
+Atom qt_net_wm_frame_strut = 0; // KDE extension
+Atom qt_net_wm_state_stays_on_top = 0; // KDE extension
+Atom qt_net_wm_pid = 0;
+Atom qt_net_wm_user_time = 0;
+// Enlightenment support
+Atom qt_enlightenment_desktop = 0;
+
+// window managers list of supported "stuff"
+Atom *qt_net_supported_list = 0;
+// list of virtual root windows
+Window *qt_net_virtual_root_list = 0;
+
+
+
+// client leader window
+Window qt_x11_wm_client_leader = 0;
+
+// function to update the workarea of the screen - in qdesktopwidget_x11.cpp
+extern void qt_desktopwidget_update_workarea();
+
+// current focus model
+static const int FocusModel_Unknown = -1;
+static const int FocusModel_Other = 0;
+static const int FocusModel_PointerRoot = 1;
+static int qt_focus_model = -1;
+
+#ifndef TQT_NO_XRANDR
+// TRUE if TQt is compiled w/ XRandR support and XRandR exists on the connected
+// Display
+bool qt_use_xrandr = FALSE;
+static int xrandr_eventbase;
+#endif
+
+// TRUE if TQt is compiled w/ XRender support and XRender exists on the connected
+// Display
+TQ_EXPORT bool qt_use_xrender = FALSE;
+
+// modifier masks for alt/meta - detected when the application starts
+static long qt_alt_mask = 0;
+static long qt_meta_mask = 0;
+// modifier tqmask to remove mode switch from modifiers that have alt/meta set
+// this problem manifests itself on HP/UX 10.20 at least, and without it
+// modifiers do not work at all...
+static long qt_mode_switch_remove_mask = 0;
+
+// flags for extensions for special Languages, currently only for RTL languages
+static bool qt_use_rtl_extensions = FALSE;
+bool qt_hebrew_keyboard_hack = FALSE;
+
+static Window mouseActWindow = 0; // window where mouse is
+static int mouseButtonPressed = 0; // last mouse button pressed
+static int mouseButtonState = 0; // mouse button state
+static Time mouseButtonPressTime = 0; // when was a button pressed
+static short mouseXPos, mouseYPos; // mouse pres position in act window
+static short mouseGlobalXPos, mouseGlobalYPos; // global mouse press position
+
+extern TQWidgetList *qt_modal_stack; // stack of modal widgets
+static bool ignoreNextMouseReleaseEvent = FALSE; // ignore the next mouse release
+ // event if return from a modal
+ // widget
+
+static TQWidget *popupButtonFocus = 0;
+static TQWidget *popupOfPopupButtonFocus = 0;
+static bool popupCloseDownMode = FALSE;
+static bool popupGrabOk;
+
+static bool sm_blockUserInput = FALSE; // session management
+
+int qt_xfocusout_grab_counter = 0;
+
+#if defined (TQT_TABLET_SUPPORT)
+// since XInput event classes aren't created until we actually open an XInput
+// tqdevice, here is a static list that we will use later on...
+const int INVALID_EVENT = -1;
+const int TOTAL_XINPUT_EVENTS = 7;
+
+XDevice *devStylus = NULL;
+XDevice *devEraser = NULL;
+XEventClass event_list_stylus[TOTAL_XINPUT_EVENTS];
+XEventClass event_list_eraser[TOTAL_XINPUT_EVENTS];
+
+int qt_curr_events_stylus = 0;
+int qt_curr_events_eraser = 0;
+
+// well, luckily we only need to do this once.
+static int xinput_motion = INVALID_EVENT;
+static int xinput_key_press = INVALID_EVENT;
+static int xinput_key_release = INVALID_EVENT;
+static int xinput_button_press = INVALID_EVENT;
+static int xinput_button_release = INVALID_EVENT;
+
+// making this assumption on XFree86, since we can only use 1 tqdevice,
+// the pressure for the eraser and the stylus should be the same, if they aren't
+// well, they certainly have a strange pen then...
+static int max_pressure;
+extern bool chokeMouse;
+#endif
+
+// last timestamp read from TQSettings
+static uint appliedstamp = 0;
+
+
+typedef int (*QX11EventFilter) (XEvent*);
+QX11EventFilter qt_set_x11_event_filter(QX11EventFilter filter);
+
+static QX11EventFilter qt_x11_event_filter = 0;
+TQ_EXPORT QX11EventFilter qt_set_x11_event_filter(QX11EventFilter filter)
+{
+ QX11EventFilter old_filter = qt_x11_event_filter;
+ qt_x11_event_filter = filter;
+ return old_filter;
+}
+static bool qt_x11EventFilter( XEvent* ev )
+{
+ if ( qt_x11_event_filter && qt_x11_event_filter( ev ) )
+ return TRUE;
+ return tqApp->x11EventFilter( ev );
+}
+
+
+
+
+
+#if !defined(TQT_NO_XIM)
+XIM qt_xim = 0;
+XIMStyle qt_xim_style = 0;
+static XIMStyle xim_default_style = XIMPreeditCallbacks | XIMStatusNothing;
+static XIMStyle xim_preferred_style = 0;
+#endif
+
+static int composingKeycode=0;
+static TQTextCodec * input_mapper = 0;
+
+extern bool qt_check_clipboard_sentinel(); //def in qclipboard_x11.cpp
+extern bool qt_check_selection_sentinel(); //def in qclipboard_x11.cpp
+
+static void qt_save_rootinfo();
+bool qt_try_modal( TQWidget *, XEvent * );
+
+int qt_ncols_option = 216; // used in qcolor_x11.cpp
+int qt_visual_option = -1;
+bool qt_cmap_option = FALSE;
+TQWidget *qt_button_down = 0; // widget got last button-down
+
+extern bool qt_tryAccelEvent( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp
+
+struct TQScrollInProgress {
+ static long serial;
+ TQScrollInProgress( TQWidget* w, int x, int y ) :
+ id( serial++ ), scrolled_widget( w ), dx( x ), dy( y ) {}
+ long id;
+ TQWidget* scrolled_widget;
+ int dx, dy;
+};
+long TQScrollInProgress::serial=0;
+static TQPtrList<TQScrollInProgress> *sip_list = 0;
+
+
+// stuff in qt_xdnd.cpp
+// setup
+extern void qt_xdnd_setup();
+// x event handling
+extern void qt_handle_xdnd_enter( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_position( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_status( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_leave( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_drop( TQWidget *, const XEvent *, bool );
+extern void qt_handle_xdnd_finished( TQWidget *, const XEvent *, bool );
+extern void qt_xdnd_handle_selection_request( const XSelectionRequestEvent * );
+extern bool qt_xdnd_handle_badwindow();
+
+extern void qt_motifdnd_handle_msg( TQWidget *, const XEvent *, bool );
+extern void qt_x11_motifdnd_init();
+
+// client message atoms
+extern Atom qt_xdnd_enter;
+extern Atom qt_xdnd_position;
+extern Atom qt_xdnd_status;
+extern Atom qt_xdnd_leave;
+extern Atom qt_xdnd_drop;
+extern Atom qt_xdnd_finished;
+// xdnd selection atom
+extern Atom qt_xdnd_selection;
+extern bool qt_xdnd_dragging;
+
+// gui or non-gui from qapplication.cpp
+extern bool qt_is_gui_used;
+extern bool qt_app_has_font;
+
+static bool qt_x11_cmdline_font = false;
+
+
+extern bool qt_resolve_symlinks; // from qapplication.cpp
+
+// Paint event clipping magic
+extern void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region);
+extern void qt_clear_paintevent_clipping();
+
+
+// Palette handling
+extern TQPalette *qt_std_pal;
+extern void qt_create_std_palette();
+
+void qt_x11_intern_atom( const char *, Atom * );
+
+static TQPtrList<TQWidget>* deferred_map_list = 0;
+static void qt_deferred_map_cleanup()
+{
+ delete deferred_map_list;
+ deferred_map_list = 0;
+}
+void qt_deferred_map_add( TQWidget* w)
+{
+ if ( !deferred_map_list ) {
+ deferred_map_list = new TQPtrList<TQWidget>;
+ qAddPostRoutine( qt_deferred_map_cleanup );
+ }
+ deferred_map_list->append( w );
+}
+void qt_deferred_map_take( TQWidget* w )
+{
+ if (deferred_map_list ) {
+ deferred_map_list->remove( w );
+ }
+}
+bool qt_deferred_map_tqcontains( TQWidget* w )
+{
+ if (!deferred_map_list)
+ return FALSE;
+ else
+ return deferred_map_list->tqcontains( w );
+}
+
+
+class TQETWidget : public TQWidget // event translator widget
+{
+public:
+ void setWState( WFlags f ) { TQWidget::setWState(f); }
+ void clearWState( WFlags f ) { TQWidget::clearWState(f); }
+ void setWFlags( WFlags f ) { TQWidget::setWFlags(f); }
+ void clearWFlags( WFlags f ) { TQWidget::clearWFlags(f); }
+ bool translateMouseEvent( const XEvent * );
+ bool translateKeyEventInternal( const XEvent *, int& count, TQString& text, int& state, char& ascii, int &code,
+ TQEvent::Type &type, bool willRepeat=FALSE );
+ bool translateKeyEvent( const XEvent *, bool grab );
+ bool translatePaintEvent( const XEvent * );
+ bool translateConfigEvent( const XEvent * );
+ bool translateCloseEvent( const XEvent * );
+ bool translateScrollDoneEvent( const XEvent * );
+ bool translateWheelEvent( int global_x, int global_y, int delta, int state, Orientation orient );
+#if defined (TQT_TABLET_SUPPORT)
+ bool translateXinputEvent( const XEvent* );
+#endif
+ bool translatePropertyEvent(const XEvent *);
+};
+
+
+
+
+// ************************************************************************
+// X Input Method support
+// ************************************************************************
+
+#if !defined(TQT_NO_XIM)
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif // TQ_C_CALLBACKS
+
+#ifdef USE_X11R6_XIM
+ static void xim_create_callback(XIM /*im*/,
+ XPointer /*client_data*/,
+ XPointer /*call_data*/)
+ {
+ // qDebug("xim_create_callback");
+ TQApplication::create_xim();
+ }
+
+ static void xim_destroy_callback(XIM /*im*/,
+ XPointer /*client_data*/,
+ XPointer /*call_data*/)
+ {
+ // qDebug("xim_destroy_callback");
+ TQApplication::close_xim();
+ XRegisterIMInstantiateCallback(appDpy, 0, 0, 0,
+ (XIMProc) xim_create_callback, 0);
+ }
+
+#endif // USE_X11R6_XIM
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif // TQ_C_CALLBACKS
+
+#endif // TQT_NO_XIM
+
+
+/*! \internal
+ Creates the application input method.
+ */
+void TQApplication::create_xim()
+{
+#ifndef TQT_NO_XIM
+ qt_xim = XOpenIM( appDpy, 0, 0, 0 );
+ if ( qt_xim ) {
+
+#ifdef USE_X11R6_XIM
+ XIMCallback destroy;
+ destroy.callback = (XIMProc) xim_destroy_callback;
+ destroy.client_data = 0;
+ if ( XSetIMValues( qt_xim, XNDestroyCallback, &destroy, (char *) 0 ) != 0 )
+ qWarning( "Xlib dosn't support destroy callback");
+#endif // USE_X11R6_XIM
+
+ XIMStyles *styles = 0;
+ XGetIMValues(qt_xim, XNQueryInputStyle, &styles, (char *) 0, (char *) 0);
+ if ( styles ) {
+ int i;
+ for ( i = 0; !qt_xim_style && i < styles->count_styles; i++ ) {
+ if ( styles->supported_styles[i] == xim_preferred_style ) {
+ qt_xim_style = xim_preferred_style;
+ break;
+ }
+ }
+ // if the preferred input style couldn't be found, look for
+ // Nothing
+ for ( i = 0; !qt_xim_style && i < styles->count_styles; i++ ) {
+ if ( styles->supported_styles[i] == (XIMPreeditNothing |
+ XIMStatusNothing) ) {
+ qt_xim_style = XIMPreeditNothing | XIMStatusNothing;
+ break;
+ }
+ }
+ // ... and failing that, None.
+ for ( i = 0; !qt_xim_style && i < styles->count_styles; i++ ) {
+ if ( styles->supported_styles[i] == (XIMPreeditNone |
+ XIMStatusNone) ) {
+ qt_xim_style = XIMPreeditNone | XIMStatusNone;
+ break;
+ }
+ }
+
+ // qDebug("TQApplication: using im style %lx", qt_xim_style);
+ XFree( (char *)styles );
+ }
+
+ if ( qt_xim_style ) {
+
+#ifdef USE_X11R6_XIM
+ XUnregisterIMInstantiateCallback(appDpy, 0, 0, 0,
+ (XIMProc) xim_create_callback, 0);
+#endif // USE_X11R6_XIM
+
+ TQWidgetList *list= tqApp->tqtopLevelWidgets();
+ TQWidgetListIt it(*list);
+ TQWidget * w;
+ while( (w=it.current()) != 0 ) {
+ ++it;
+ w->createTLSysExtra();
+ }
+ delete list;
+ } else {
+ // Give up
+ qWarning( "No supported input style found."
+ " See InputMethod documentation.");
+ close_xim();
+ }
+ }
+#endif // TQT_NO_XIM
+}
+
+
+/*! \internal
+ Closes the application input method.
+*/
+void TQApplication::close_xim()
+{
+#ifndef TQT_NO_XIM
+ // Calling XCloseIM gives a Purify FMR error
+ // XCloseIM( qt_xim );
+ // We prefer a less serious memory leak
+
+ qt_xim = 0;
+ TQWidgetList *list = tqApp->tqtopLevelWidgets();
+ TQWidgetListIt it(*list);
+ while(it.current()) {
+ it.current()->destroyInputContext();
+ ++it;
+ }
+ delete list;
+#endif // TQT_NO_XIM
+}
+
+
+/*****************************************************************************
+ Default X error handlers
+ *****************************************************************************/
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static bool x11_ignore_badwindow;
+static bool x11_badwindow;
+
+ // starts to ignore bad window errors from X
+void qt_ignore_badwindow()
+{
+ x11_ignore_badwindow = TRUE;
+ x11_badwindow = FALSE;
+}
+
+ // ends ignoring bad window errors and returns whether an error
+ // had happen.
+bool qt_badwindow()
+{
+ x11_ignore_badwindow = FALSE;
+ return x11_badwindow;
+}
+
+static int (*original_x_errhandler)( Display *dpy, XErrorEvent * );
+static int (*original_xio_errhandler)( Display *dpy );
+
+static int qt_x_errhandler( Display *dpy, XErrorEvent *err )
+{
+ if ( err->error_code == BadWindow ) {
+ x11_badwindow = TRUE;
+ if ( err->request_code == 25 /* X_SendEvent */ &&
+ qt_xdnd_handle_badwindow() )
+ return 0;
+ if ( x11_ignore_badwindow )
+ return 0;
+ } else if ( err->error_code == BadMatch &&
+ err->request_code == 42 /* X_SetInputFocus */ ) {
+ return 0;
+ }
+
+ char errstr[256];
+ XGetErrorText( dpy, err->error_code, errstr, 256 );
+ qWarning( "X Error: %s %d\n"
+ " Major opcode: %d\n"
+ " Minor opcode: %d\n"
+ " Resource id: 0x%lx",
+ errstr, err->error_code,
+ err->request_code,
+ err->minor_code,
+ err->resourceid );
+
+ // ### we really should distinguish between severe, non-severe and
+ // ### application specific errors
+
+ return 0;
+}
+
+
+static int qt_xio_errhandler( Display * )
+{
+ qWarning( "%s: Fatal IO error: client killed", appName );
+ tqApp = 0;
+ exit( 1 );
+ //### give the application a chance for a proper shutdown instead,
+ //### exit(1) doesn't help.
+ return 0;
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+// Memory leak: if the app exits before qt_init_internal(), this dict
+// isn't released correctly.
+static TQAsciiDict<Atom> *atoms_to_be_created = 0;
+static bool create_atoms_now = 0;
+
+/*****************************************************************************
+ qt_x11_intern_atom() - efficiently interns an atom, now or later.
+
+ If the application is being initialized, this function stores the
+ adddress of the atom and qt_init_internal will do the actual work
+ quickly. If the application is running, the atom is created here.
+
+ Neither argument may point to temporary variables.
+ *****************************************************************************/
+
+void qt_x11_intern_atom( const char *name, Atom *result)
+{
+ if ( !name || !result || *result )
+ return;
+
+ if ( create_atoms_now ) {
+ *result = XInternAtom( appDpy, name, False );
+ } else {
+ if ( !atoms_to_be_created ) {
+ atoms_to_be_created = new TQAsciiDict<Atom>;
+ atoms_to_be_created->setAutoDelete( FALSE );
+ }
+ atoms_to_be_created->insert( name, result );
+ *result = 0;
+ }
+}
+
+
+static void qt_x11_process_intern_atoms()
+{
+ if ( atoms_to_be_created ) {
+#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 6)
+ int i = atoms_to_be_created->count();
+ Atom * res = (Atom *)malloc( i * sizeof( Atom ) );
+ Atom ** resp = (Atom **)malloc( i * sizeof( Atom* ) );
+ char ** names = (char **)malloc( i * sizeof(const char*));
+
+ i = 0;
+ TQAsciiDictIterator<Atom> it( *atoms_to_be_created );
+ while( it.current() ) {
+ res[i] = 0;
+ resp[i] = it.current();
+ names[i] = qstrdup(it.currentKey());
+ i++;
+ ++it;
+ }
+ XInternAtoms( appDpy, names, i, False, res );
+ while( i ) {
+ i--;
+ delete [] names[i];
+ if ( res[i] && resp[i] )
+ *(resp[i]) = res[i];
+ }
+ free( res );
+ free( resp );
+ free( names );
+#else
+ TQAsciiDictIterator<Atom> it( *atoms_to_be_created );
+ Atom * result;
+ const char * name;
+ while( (result = it.current()) != 0 ) {
+ name = it.currentKey();
+ ++it;
+ *result = XInternAtom( appDpy, name, False );
+ }
+#endif
+ delete atoms_to_be_created;
+ atoms_to_be_created = 0;
+ create_atoms_now = TRUE;
+ }
+}
+
+
+/*! \internal
+ apply the settings to the application
+*/
+bool TQApplication::x11_apply_settings()
+{
+ if (! qt_std_pal)
+ qt_create_std_palette();
+
+ Atom type;
+ int format;
+ long offset = 0;
+ unsigned long nitems, after = 1;
+ unsigned char *data = 0;
+ TQDateTime timestamp, settingsstamp;
+ bool update_timestamp = FALSE;
+
+ if (XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ),
+ qt_settings_timestamp, 0, 0,
+ False, AnyPropertyType, &type, &format, &nitems,
+ &after, &data) == Success && format == 8) {
+ if (data)
+ XFree(data);
+
+ TQBuffer ts;
+ ts.open(IO_WriteOnly);
+
+ while (after > 0) {
+ XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ),
+ qt_settings_timestamp,
+ offset, 1024, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &data);
+ if (format == 8) {
+ ts.writeBlock((const char *) data, nitems);
+ offset += nitems / 4;
+ }
+
+ XFree(data);
+ }
+
+ TQDataStream d(ts.buffer(), IO_ReadOnly);
+ d >> timestamp;
+ }
+
+ TQSettings settings;
+ settingsstamp = settings.lastModificationTime( "/qt/font" );
+ if (! settingsstamp.isValid())
+ return FALSE;
+
+ if ( appliedstamp && appliedstamp == settingsstamp.toTime_t() )
+ return TRUE;
+ appliedstamp = settingsstamp.toTime_t();
+
+ if (! timestamp.isValid() || settingsstamp > timestamp)
+ update_timestamp = TRUE;
+
+ /*
+ TQt settings. This is now they are written into the datastream.
+
+ /qt/Palette/ * - TQPalette
+ /qt/font - TQFont
+ /qt/libraryPath - TQStringList
+ /qt/style - TQString
+ /qt/doubleClickInterval - int
+ /qt/cursorFlashTime - int
+ /qt/wheelScrollLines - int
+ /qt/colorSpec - TQString
+ /qt/defaultCodec - TQString
+ /qt/globalStrut - TQSize
+ /qt/GUIEffects - TQStringList
+ /qt/Font Substitutions/ * - TQStringList
+ /qt/Font Substitutions/... - TQStringList
+ */
+
+ TQString str;
+ TQStringList strlist;
+ int i, num;
+ TQPalette pal(TQApplication::palette());
+ strlist = settings.readListEntry("/qt/Palette/active");
+ if (strlist.count() == TQColorGroup::NColorRoles) {
+ for (i = 0; i < TQColorGroup::NColorRoles; i++)
+ pal.setColor(TQPalette::Active, (TQColorGroup::ColorRole) i,
+ TQColor(strlist[i]));
+ }
+ strlist = settings.readListEntry("/qt/Palette/inactive");
+ if (strlist.count() == TQColorGroup::NColorRoles) {
+ for (i = 0; i < TQColorGroup::NColorRoles; i++)
+ pal.setColor(TQPalette::Inactive, (TQColorGroup::ColorRole) i,
+ TQColor(strlist[i]));
+ }
+ strlist = settings.readListEntry("/qt/Palette/disabled");
+ if (strlist.count() == TQColorGroup::NColorRoles) {
+ for (i = 0; i < TQColorGroup::NColorRoles; i++)
+ pal.setColor(TQPalette::Disabled, (TQColorGroup::ColorRole) i,
+ TQColor(strlist[i]));
+ }
+
+ // workaround for KDE 3.0, which messes up the buttonText value of
+ // the disabled palette in TQSettings
+ if ( pal.disabled().buttonText() == pal.active().buttonText() ) {
+ pal.setColor( TQPalette::Disabled, TQColorGroup::ButtonText,
+ pal.disabled().foreground() );
+ }
+
+ if (pal != *qt_std_pal && pal != TQApplication::palette()) {
+ TQApplication::setPalette(pal, TRUE);
+ *qt_std_pal = pal;
+ }
+
+ TQFont font(TQApplication::font());
+ if ( !qt_app_has_font && !qt_x11_cmdline_font ) {
+ // read new font
+ str = settings.readEntry("/qt/font");
+ if (! str.isNull() && ! str.isEmpty()) {
+ font.fromString(str);
+
+ if (font != TQApplication::font())
+ TQApplication::setFont(font, TRUE);
+ }
+ }
+
+ // read library (ie. plugin) path list
+ TQString libpathkey =
+ TQString("/qt/%1.%2/libraryPath").arg( TQT_VERSION >> 16 ).arg( (TQT_VERSION & 0xff00 ) >> 8 );
+ TQStringList pathlist = settings.readListEntry(libpathkey, ':');
+ if (! pathlist.isEmpty()) {
+ TQStringList::ConstIterator it = pathlist.begin();
+ while (it != pathlist.end())
+ TQApplication::addLibraryPath(*it++);
+ }
+
+ // read new TQStyle
+ extern bool qt_explicit_app_style; // defined in qapplication.cpp
+ TQString stylename = settings.readEntry( "/qt/style" );
+ if ( !stylename.isEmpty() && !qt_explicit_app_style ) {
+ TQApplication::setStyle( stylename );
+ // took the style from the user settings, so mark the explicit flag FALSE
+ qt_explicit_app_style = FALSE;
+ }
+
+ num =
+ settings.readNumEntry("/qt/doubleClickInterval",
+ TQApplication::doubleClickInterval());
+ TQApplication::setDoubleClickInterval(num);
+
+ num =
+ settings.readNumEntry("/qt/cursorFlashTime",
+ TQApplication::cursorFlashTime());
+ TQApplication::setCursorFlashTime(num);
+
+ num =
+ settings.readNumEntry("/qt/wheelScrollLines",
+ TQApplication::wheelScrollLines());
+ TQApplication::setWheelScrollLines(num);
+
+ TQString colorspec = settings.readEntry("/qt/colorSpec", "default");
+ if (colorspec == "normal")
+ TQApplication::setColorSpec(TQApplication::NormalColor);
+ else if (colorspec == "custom")
+ TQApplication::setColorSpec(TQApplication::CustomColor);
+ else if (colorspec == "many")
+ TQApplication::setColorSpec(TQApplication::ManyColor);
+ else if (colorspec != "default")
+ colorspec = "default";
+
+ TQString defaultcodec = settings.readEntry("/qt/defaultCodec", "none");
+ if (defaultcodec != "none") {
+ TQTextCodec *codec = TQTextCodec::codecForName(defaultcodec);
+ if (codec)
+ tqApp->setDefaultCodec(codec);
+ }
+
+ TQStringList strut = settings.readListEntry("/qt/globalStrut");
+ if (! strut.isEmpty()) {
+ if (strut.count() == 2) {
+ TQSize sz(strut[0].toUInt(), strut[1].toUInt());
+
+ if (sz.isValid())
+ TQApplication::setGlobalStrut(sz);
+ }
+ }
+
+ TQStringList effects = settings.readListEntry("/qt/GUIEffects");
+
+ TQApplication::setEffectEnabled( TQt::UI_General, effects.tqcontains("general") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, effects.tqcontains("animatemenu") );
+ TQApplication::setEffectEnabled( TQt::UI_FadeMenu, effects.tqcontains("fademenu") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, effects.tqcontains("animatecombo") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, effects.tqcontains("animatetooltip") );
+ TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, effects.tqcontains("fadetooltip") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, effects.tqcontains("animatetoolbox") );
+
+ TQStringList fontsubs =
+ settings.entryList("/qt/Font Substitutions");
+ if (!fontsubs.isEmpty()) {
+ TQStringList subs;
+ TQString fam, skey;
+ TQStringList::Iterator it = fontsubs.begin();
+ while (it != fontsubs.end()) {
+ fam = (*it++);
+ skey = "/qt/Font Substitutions/" + fam;
+ subs = settings.readListEntry(skey);
+ TQFont::insertSubstitutions(fam, subs);
+ }
+ }
+
+ qt_broken_wm =
+ settings.readBoolEntry("/qt/brokenWindowManager", qt_broken_wm);
+
+ qt_resolve_symlinks =
+ settings.readBoolEntry("/qt/resolveSymlinks", TRUE);
+
+ qt_use_rtl_extensions =
+ settings.readBoolEntry("/qt/useRtlExtensions", FALSE);
+
+#ifndef TQT_NO_XIM
+ if (xim_preferred_style == 0) {
+ TQString ximInputStyle =
+ settings.readEntry( "/qt/XIMInputStyle",
+ TQObject::trUtf8( "On The Spot" ) ).lower();
+ if ( ximInputStyle == "on the spot" )
+ xim_preferred_style = XIMPreeditCallbacks | XIMStatusNothing;
+ else if ( ximInputStyle == "over the spot" )
+ xim_preferred_style = XIMPreeditPosition | XIMStatusNothing;
+ else if ( ximInputStyle == "off the spot" )
+ xim_preferred_style = XIMPreeditArea | XIMStatusArea;
+ else if ( ximInputStyle == "root" )
+ xim_preferred_style = XIMPreeditNothing | XIMStatusNothing;
+ }
+#endif
+
+ if (update_timestamp) {
+ TQBuffer stamp;
+ TQDataStream s(stamp.buffer(), IO_WriteOnly);
+ s << settingsstamp;
+
+ XChangeProperty(appDpy, TQPaintDevice::x11AppRootWindow( 0 ),
+ qt_settings_timestamp, qt_settings_timestamp, 8,
+ PropModeReplace, (unsigned char *) stamp.buffer().data(),
+ stamp.buffer().size());
+ }
+
+ return TRUE;
+}
+
+
+// read the _TQT_INPUT_ENCODING property and apply the settings to
+// the application
+static void qt_set_input_encoding()
+{
+ Atom type;
+ int format;
+ ulong nitems, after = 1;
+ const char *data;
+
+ int e = XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_input_encoding, 0, 1024,
+ False, XA_STRING, &type, &format, &nitems,
+ &after, (unsigned char**)&data );
+ if ( e != Success || !nitems || type == None ) {
+ // Always use the locale codec, since we have no examples of non-local
+ // XIMs, and since we cannot get a sensible answer about the encoding
+ // from the XIM.
+ input_mapper = TQTextCodec::codecForLocale();
+
+ } else {
+ if ( !qstricmp( data, "locale" ) )
+ input_mapper = TQTextCodec::codecForLocale();
+ else
+ input_mapper = TQTextCodec::codecForName( data );
+ // make sure we have an input codec
+ if( !input_mapper )
+ input_mapper = TQTextCodec::codecForName( "ISO 8859-1" );
+ }
+ if ( input_mapper->mibEnum() == 11 ) // 8859-8
+ input_mapper = TQTextCodec::codecForName( "ISO 8859-8-I");
+ if( data )
+ XFree( (char *)data );
+}
+
+// set font, foreground and background from x11 resources. The
+// arguments may override the resource settings.
+static void qt_set_x11_resources( const char* font = 0, const char* fg = 0,
+ const char* bg = 0, const char* button = 0 )
+{
+ if ( !qt_std_pal )
+ qt_create_std_palette();
+
+ TQCString resFont, resFG, resBG, resEF, sysFont;
+
+ TQApplication::setEffectEnabled( TQt::UI_General, FALSE);
+ TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, FALSE);
+ TQApplication::setEffectEnabled( TQt::UI_FadeMenu, FALSE);
+ TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, FALSE );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, FALSE );
+ TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, FALSE );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, FALSE );
+
+ if ( TQApplication::desktopSettingsAware() && !TQApplication::x11_apply_settings() ) {
+ int format;
+ ulong nitems, after = 1;
+ TQCString res;
+ long offset = 0;
+ Atom type = None;
+
+ while (after > 0) {
+ uchar *data;
+ XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow( 0 ),
+ qt_resource_manager,
+ offset, 8192, False, AnyPropertyType,
+ &type, &format, &nitems, &after,
+ &data );
+ res += (char*)data;
+ offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048
+ if ( data )
+ XFree( (char *)data );
+ }
+
+ TQCString key, value;
+ int l = 0, r;
+ TQCString apn = appName;
+ TQCString apc = appClass;
+ int apnl = apn.length();
+ int apcl = apc.length();
+ int resl = res.length();
+
+ while (l < resl) {
+ r = res.tqfind( '\n', l );
+ if ( r < 0 )
+ r = resl;
+ while ( isspace((uchar) res[l]) )
+ l++;
+ bool mine = FALSE;
+ if ( res[l] == '*' &&
+ (res[l+1] == 'f' || res[l+1] == 'b' || res[l+1] == 'g' ||
+ res[l+1] == 'F' || res[l+1] == 'B' || res[l+1] == 'G' ||
+ res[l+1] == 's' || res[l+1] == 'S' ) ) {
+ // OPTIMIZED, since we only want "*[fbgs].."
+
+ TQCString item = res.mid( l, r - l ).simplifyWhiteSpace();
+ int i = item.tqfind( ":" );
+ key = item.left( i ).stripWhiteSpace().mid(1).lower();
+ value = item.right( item.length() - i - 1 ).stripWhiteSpace();
+ mine = TRUE;
+ } else if ( res[l] == appName[0] || (appClass && res[l] == appClass[0]) ) {
+ if (res.mid(l,apnl) == apn && (res[l+apnl] == '.' || res[l+apnl] == '*')) {
+ TQCString item = res.mid( l, r - l ).simplifyWhiteSpace();
+ int i = item.tqfind( ":" );
+ key = item.left( i ).stripWhiteSpace().mid(apnl+1).lower();
+ value = item.right( item.length() - i - 1 ).stripWhiteSpace();
+ mine = TRUE;
+ } else if (res.mid(l,apcl) == apc && (res[l+apcl] == '.' || res[l+apcl] == '*')) {
+ TQCString item = res.mid( l, r - l ).simplifyWhiteSpace();
+ int i = item.tqfind( ":" );
+ key = item.left( i ).stripWhiteSpace().mid(apcl+1).lower();
+ value = item.right( item.length() - i - 1 ).stripWhiteSpace();
+ mine = TRUE;
+ }
+ }
+
+ if ( mine ) {
+ if ( !font && key == "systemfont")
+ sysFont = value.left( value.tqfindRev(':') ).copy();
+ if ( !font && key == "font")
+ resFont = value.copy();
+ else if ( !fg && key == "foreground" )
+ resFG = value.copy();
+ else if ( !bg && key == "background")
+ resBG = value.copy();
+ else if ( key == "guieffects")
+ resEF = value.copy();
+ // NOTE: if you add more, change the [fbg] stuff above
+ }
+
+ l = r + 1;
+ }
+ }
+ if ( !sysFont.isEmpty() )
+ resFont = sysFont;
+ if ( resFont.isEmpty() )
+ resFont = font;
+ if ( resFG.isEmpty() )
+ resFG = fg;
+ if ( resBG.isEmpty() )
+ resBG = bg;
+ if ( (!qt_app_has_font || qt_x11_cmdline_font) && !resFont.isEmpty() ) { // set application font
+ TQFont fnt;
+ fnt.setRawName( resFont );
+
+ // the font we get may actually be an alias for another font,
+ // so we reset the application font to the real font info.
+ if ( ! fnt.exactMatch() ) {
+ TQFontInfo fontinfo( fnt );
+ fnt.setFamily( fontinfo.family() );
+ fnt.setRawMode( fontinfo.rawMode() );
+
+ if ( ! fnt.rawMode() ) {
+ fnt.setItalic( fontinfo.italic() );
+ fnt.setWeight( fontinfo.weight() );
+ fnt.setUnderline( fontinfo.underline() );
+ fnt.setStrikeOut( fontinfo.strikeOut() );
+ fnt.setStyleHint( fontinfo.tqstyleHint() );
+
+ if ( fnt.pointSize() <= 0 && fnt.pixelSize() <= 0 )
+ // size is all wrong... fix it
+ fnt.setPointSize( (int) ( ( fontinfo.pixelSize() * 72. /
+ (float) TQPaintDevice::x11AppDpiY() ) +
+ 0.5 ) );
+ }
+ }
+
+ if ( fnt != TQApplication::font() ) {
+ TQApplication::setFont( fnt, TRUE );
+ }
+ }
+
+ if ( button || !resBG.isEmpty() || !resFG.isEmpty() ) {// set app colors
+ TQColor btn;
+ TQColor bg;
+ TQColor fg;
+ if ( !resBG.isEmpty() )
+ bg = TQColor(TQString(resBG));
+ else
+ bg = qt_std_pal->active().background();
+ if ( !resFG.isEmpty() )
+ fg = TQColor(TQString(resFG));
+ else
+ fg = qt_std_pal->active().foreground();
+ if ( button )
+ btn = TQColor( button );
+ else if ( !resBG.isEmpty() )
+ btn = bg;
+ else
+ btn = qt_std_pal->active().button();
+
+ int h,s,v;
+ fg.hsv(&h,&s,&v);
+ TQColor base = TQt::white;
+ bool bright_mode = FALSE;
+ if (v >= 255-50) {
+ base = btn.dark(150);
+ bright_mode = TRUE;
+ }
+
+ TQColorGroup cg( fg, btn, btn.light(),
+ btn.dark(), btn.dark(150), fg, TQt::white, base, bg );
+ if (bright_mode) {
+ cg.setColor( TQColorGroup::HighlightedText, base );
+ cg.setColor( TQColorGroup::Highlight, TQt::white );
+ } else {
+ cg.setColor( TQColorGroup::HighlightedText, TQt::white );
+ cg.setColor( TQColorGroup::Highlight, TQt::darkBlue );
+ }
+ TQColor disabled( (fg.red()+btn.red())/2,
+ (fg.green()+btn.green())/2,
+ (fg.blue()+btn.blue())/2);
+ TQColorGroup dcg( disabled, btn, btn.light( 125 ), btn.dark(), btn.dark(150),
+ disabled, TQt::white, TQt::white, bg );
+ if (bright_mode) {
+ dcg.setColor( TQColorGroup::HighlightedText, base );
+ dcg.setColor( TQColorGroup::Highlight, TQt::white );
+ } else {
+ dcg.setColor( TQColorGroup::HighlightedText, TQt::white );
+ dcg.setColor( TQColorGroup::Highlight, TQt::darkBlue );
+ }
+ TQPalette pal( cg, dcg, cg );
+ if ( pal != *qt_std_pal && pal != TQApplication::palette() )
+ TQApplication::setPalette( pal, TRUE );
+ *qt_std_pal = pal;
+ }
+
+ if ( !resEF.isEmpty() ) {
+ TQStringList effects = TQStringList::split(" ",resEF);
+ TQApplication::setEffectEnabled( TQt::UI_General, effects.tqcontains("general") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, effects.tqcontains("animatemenu") );
+ TQApplication::setEffectEnabled( TQt::UI_FadeMenu, effects.tqcontains("fademenu") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, effects.tqcontains("animatecombo") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, effects.tqcontains("animatetooltip") );
+ TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, effects.tqcontains("fadetooltip") );
+ TQApplication::setEffectEnabled( TQt::UI_AnimateToolBox, effects.tqcontains("animatetoolbox") );
+ }
+}
+
+
+static void qt_detect_broken_window_manager()
+{
+ Atom type;
+ int format;
+ ulong nitems, after;
+ uchar *data = 0;
+
+ // look for SGI's 4Dwm
+ int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_sgi_desks_manager, 0, 1, False, XA_WINDOW,
+ &type, &format, &nitems, &after, &data);
+ if (data)
+ XFree(data);
+
+ if (e == Success && type == XA_WINDOW && format == 32 && nitems == 1 && after == 0) {
+ // detected SGI 4Dwm
+ qt_broken_wm = TRUE;
+ }
+}
+
+
+// update the supported array
+void qt_get_net_supported()
+{
+ Atom type;
+ int format;
+ long offset = 0;
+ unsigned long nitems, after;
+ unsigned char *data = 0;
+
+ int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_net_supported, 0, 0,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+ if (data)
+ XFree(data);
+
+ if (qt_net_supported_list)
+ delete [] qt_net_supported_list;
+ qt_net_supported_list = 0;
+
+ if (e == Success && type == XA_ATOM && format == 32) {
+ TQBuffer ts;
+ ts.open(IO_WriteOnly);
+
+ while (after > 0) {
+ XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_net_supported, offset, 1024,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+
+ if (type == XA_ATOM && format == 32) {
+ ts.writeBlock((const char *) data, nitems * sizeof(long));
+ offset += nitems;
+ } else
+ after = 0;
+ if (data)
+ XFree(data);
+ }
+
+ // compute nitems
+ TQByteArray buffer(ts.buffer());
+ nitems = buffer.size() / sizeof(Atom);
+ qt_net_supported_list = new Atom[nitems + 1];
+ Atom *a = (Atom *) buffer.data();
+ uint i;
+ for (i = 0; i < nitems; i++)
+ qt_net_supported_list[i] = a[i];
+ qt_net_supported_list[nitems] = 0;
+ }
+}
+
+
+bool qt_net_supports(Atom atom)
+{
+ if (! qt_net_supported_list)
+ return FALSE;
+
+ bool supported = FALSE;
+ int i = 0;
+ while (qt_net_supported_list[i] != 0) {
+ if (qt_net_supported_list[i++] == atom) {
+ supported = TRUE;
+ break;
+ }
+ }
+
+ return supported;
+}
+
+
+// update the virtual roots array
+void qt_get_net_virtual_roots()
+{
+ if (qt_net_virtual_root_list)
+ delete [] qt_net_virtual_root_list;
+ qt_net_virtual_root_list = 0;
+
+ if (! qt_net_supports(qt_net_virtual_roots))
+ return;
+
+ Atom type;
+ int format;
+ long offset = 0;
+ unsigned long nitems, after;
+ unsigned char *data;
+
+ int e = XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_net_virtual_roots, 0, 0,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+ if (data)
+ XFree(data);
+
+ if (e == Success && type == XA_ATOM && format == 32) {
+ TQBuffer ts;
+ ts.open(IO_WriteOnly);
+
+ while (after > 0) {
+ XGetWindowProperty(appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_net_virtual_roots, offset, 1024,
+ False, XA_ATOM, &type, &format, &nitems, &after, &data);
+
+ if (type == XA_ATOM && format == 32) {
+ ts.writeBlock((const char *) data, nitems * 4);
+ offset += nitems;
+ } else
+ after = 0;
+ if (data)
+ XFree(data);
+ }
+
+ // compute nitems
+ TQByteArray buffer(ts.buffer());
+ nitems = buffer.size() / sizeof(Window);
+ qt_net_virtual_root_list = new Window[nitems + 1];
+ Window *a = (Window *) buffer.data();
+ uint i;
+ for (i = 0; i < nitems; i++)
+ qt_net_virtual_root_list[i] = a[i];
+ qt_net_virtual_root_list[nitems] = 0;
+ }
+}
+
+void qt_x11_create_wm_client_leader()
+{
+ if ( qt_x11_wm_client_leader ) return;
+
+ qt_x11_wm_client_leader =
+ XCreateSimpleWindow( TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppRootWindow(),
+ 0, 0, 1, 1, 0, 0, 0 );
+
+ // set client leader property to itself
+ XChangeProperty( TQPaintDevice::x11AppDisplay(),
+ qt_x11_wm_client_leader, qt_wm_client_leader,
+ XA_WINDOW, 32, PropModeReplace,
+ (unsigned char *)&qt_x11_wm_client_leader, 1 );
+
+ // If we are session managed, inform the window manager about it
+ TQCString session = tqApp->sessionId().latin1();
+ if ( !session.isEmpty() ) {
+ XChangeProperty( TQPaintDevice::x11AppDisplay(),
+ qt_x11_wm_client_leader, qt_sm_client_id,
+ XA_STRING, 8, PropModeReplace,
+ (unsigned char *)session.data(), session.length() );
+ }
+}
+
+static void qt_net_update_user_time(TQWidget *tlw)
+{
+ Time my_tqx_user_time = GET_QT_X_USER_TIME();
+ XChangeProperty(TQPaintDevice::x11AppDisplay(), tlw->winId(), qt_net_wm_user_time, XA_CARDINAL,
+ 32, PropModeReplace, (unsigned char *) &my_tqx_user_time, 1);
+ SET_QT_X_USER_TIME(my_tqx_user_time);
+}
+
+static void qt_check_focus_model()
+{
+ Window fw = None;
+ int unused;
+ XGetInputFocus( appDpy, &fw, &unused );
+ if ( fw == PointerRoot )
+ qt_focus_model = FocusModel_PointerRoot;
+ else
+ qt_focus_model = FocusModel_Other;
+}
+
+
+/*
+ Returns a truecolor visual (if there is one). 8-bit TrueColor visuals
+ are ignored, unless the user has explicitly requested -visual TrueColor.
+ The SGI X server usually has an 8 bit default visual, but the application
+ can also ask for a truecolor visual. This is what we do if
+ TQApplication::colorSpec() is TQApplication::ManyColor.
+*/
+
+static Visual *tqfind_truecolor_visual( Display *dpy, int scr, int *depth, int *ncols )
+{
+ XVisualInfo *vi, rvi;
+ int best=0, n, i;
+ rvi.c_class = TrueColor;
+ rvi.screen = scr;
+ vi = XGetVisualInfo( dpy, VisualClassMask | VisualScreenMask,
+ &rvi, &n );
+ if ( vi ) {
+ for ( i=0; i<n; i++ ) {
+ if ( vi[i].depth > vi[best].depth )
+ best = i;
+ }
+ }
+ Visual *v = DefaultVisual(dpy,scr);
+ if ( !vi || (vi[best].visualid == XVisualIDFromVisual(v)) ||
+ (vi[best].depth <= 8 && qt_visual_option != TrueColor) )
+ {
+ *depth = DefaultDepth(dpy,scr);
+ *ncols = DisplayCells(dpy,scr);
+ } else {
+ v = vi[best].visual;
+ *depth = vi[best].depth;
+ *ncols = vi[best].colormap_size;
+ }
+ if ( vi )
+ XFree( (char *)vi );
+ return v;
+}
+
+
+/*****************************************************************************
+ qt_init() - initializes TQt for X11
+ *****************************************************************************/
+
+#define XK_MISCELLANY
+#define XK_LATIN1
+#include <X11/keysymdef.h>
+
+// ### This should be static but it isn't because of the friend declaration
+// ### in tqpaintdevice.h which then should have a static too but can't have
+// ### it because "storage class specifiers invalid in friend function
+// ### declarations" :-) Ideas anyone?
+void qt_init_internal( int *argcptr, char **argv,
+ Display *display, TQt::HANDLE visual, TQt::HANDLE colormap )
+{
+ setlocale( LC_ALL, "" ); // use correct char set mapping
+ setlocale( LC_NUMERIC, "C" ); // make sprintf()/scanf() work
+
+ if ( display ) {
+ // TQt part of other application
+
+ appForeignDpy = TRUE;
+ appDpy = display;
+
+ // Set application name and class
+ appName = qstrdup( "TQt-subapplication" );
+ char *app_class = 0;
+ if (argv) {
+ const char* p = strrchr( argv[0], '/' );
+ app_class = qstrdup(p ? p + 1 : argv[0]);
+ if (app_class[0])
+ app_class[0] = toupper(app_class[0]);
+ }
+ appClass = app_class;
+
+ // Install default error handlers
+ original_x_errhandler = XSetErrorHandler( qt_x_errhandler );
+ original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler );
+ } else {
+ // TQt controls everything (default)
+
+ int argc = *argcptr;
+ int j;
+
+ // Install default error handlers
+ original_x_errhandler = XSetErrorHandler( qt_x_errhandler );
+ original_xio_errhandler = XSetIOErrorHandler( qt_xio_errhandler );
+
+ // Set application name and class
+ char *app_class = 0;
+ if (argv) {
+ const char *p = strrchr( argv[0], '/' );
+ appName = p ? p + 1 : argv[0];
+ app_class = qstrdup(appName);
+ if (app_class[0])
+ app_class[0] = toupper(app_class[0]);
+ }
+ appClass = app_class;
+
+ // Get command line params
+ j = argc ? 1 : 0;
+ for ( int i=1; i<argc; i++ ) {
+ if ( argv[i] && *argv[i] != '-' ) {
+ argv[j++] = argv[i];
+ continue;
+ }
+ TQCString arg = argv[i];
+ if ( arg == "-display" ) {
+ if ( ++i < argc )
+ appDpyName = argv[i];
+ } else if ( arg == "-fn" || arg == "-font" ) {
+ if ( ++i < argc ) {
+ appFont = argv[i];
+ qt_x11_cmdline_font = true;
+ }
+ } else if ( arg == "-bg" || arg == "-background" ) {
+ if ( ++i < argc )
+ appBGCol = argv[i];
+ } else if ( arg == "-btn" || arg == "-button" ) {
+ if ( ++i < argc )
+ appBTNCol = argv[i];
+ } else if ( arg == "-fg" || arg == "-foreground" ) {
+ if ( ++i < argc )
+ appFGCol = argv[i];
+ } else if ( arg == "-name" ) {
+ if ( ++i < argc )
+ appName = argv[i];
+ } else if ( arg == "-title" ) {
+ if ( ++i < argc )
+ mwTitle = argv[i];
+ } else if ( arg == "-tqgeometry" ) {
+ if ( ++i < argc )
+ mwGeometry = argv[i];
+ //Ming-Che 10/10
+ } else if ( arg == "-im" ) {
+ if ( ++i < argc )
+ ximServer = argv[i];
+ } else if ( arg == "-noxim" ) {
+ noxim=TRUE;
+ //
+ } else if ( arg == "-iconic" ) {
+ mwIconic = !mwIconic;
+ } else if ( arg == "-ncols" ) { // xv and netscape use this name
+ if ( ++i < argc )
+ qt_ncols_option = TQMAX(0,atoi(argv[i]));
+ } else if ( arg == "-visual" ) { // xv and netscape use this name
+ if ( ++i < argc ) {
+ TQCString s = TQCString(argv[i]).lower();
+ if ( s == "truecolor" ) {
+ qt_visual_option = TrueColor;
+ } else {
+ // ### Should we honor any others?
+ }
+ }
+#ifndef TQT_NO_XIM
+ } else if ( arg == "-inputstyle" ) {
+ if ( ++i < argc ) {
+ TQCString s = TQCString(argv[i]).lower();
+ if ( s == "onthespot" )
+ xim_preferred_style = XIMPreeditCallbacks |
+ XIMStatusNothing;
+ else if ( s == "overthespot" )
+ xim_preferred_style = XIMPreeditPosition |
+ XIMStatusNothing;
+ else if ( s == "offthespot" )
+ xim_preferred_style = XIMPreeditArea |
+ XIMStatusArea;
+ else if ( s == "root" )
+ xim_preferred_style = XIMPreeditNothing |
+ XIMStatusNothing;
+ }
+#endif
+ } else if ( arg == "-cmap" ) { // xv uses this name
+ qt_cmap_option = TRUE;
+ }
+#if defined(TQT_DEBUG)
+ else if ( arg == "-sync" )
+ appSync = !appSync;
+ else if ( arg == "-nograb" )
+ appNoGrab = !appNoGrab;
+ else if ( arg == "-dograb" )
+ appDoGrab = !appDoGrab;
+#endif
+ else
+ argv[j++] = argv[i];
+ }
+
+ *argcptr = j;
+
+#if defined(TQT_DEBUG) && defined(TQ_OS_LINUX)
+ if ( !appNoGrab && !appDoGrab ) {
+ TQCString s;
+ s.sprintf( "/proc/%d/cmdline", getppid() );
+ TQFile f( s );
+ if ( f.open( IO_ReadOnly ) ) {
+ s.truncate( 0 );
+ int c;
+ while ( (c = f.getch()) > 0 ) {
+ if ( c == '/' )
+ s.truncate( 0 );
+ else
+ s += (char)c;
+ }
+ if ( s == "gdb" ) {
+ appNoGrab = TRUE;
+ qDebug( "TQt: gdb: -nograb added to command-line options.\n"
+ "\t Use the -dograb option to enforce grabbing." );
+ }
+ f.close();
+ }
+ }
+#endif
+ // Connect to X server
+
+ if( qt_is_gui_used ) {
+ if ( ( appDpy = XOpenDisplay(appDpyName) ) == 0 ) {
+ qWarning( "%s: cannot connect to X server %s", appName,
+ XDisplayName(appDpyName) );
+ tqApp = 0;
+ exit( 1 );
+ }
+
+ if ( appSync ) // if "-sync" argument
+ XSynchronize( appDpy, TRUE );
+ }
+ }
+ // Common code, regardless of whether display is foreign.
+
+ // Get X parameters
+
+ if( qt_is_gui_used ) {
+ appScreen = DefaultScreen(appDpy);
+ appScreenCount = ScreenCount(appDpy);
+
+ TQPaintDevice::x_appdisplay = appDpy;
+ TQPaintDevice::x_appscreen = appScreen;
+
+ // allocate the arrays for the TQPaintDevice data
+ TQPaintDevice::x_appdepth_arr = new int[ appScreenCount ];
+ TQPaintDevice::x_appcells_arr = new int[ appScreenCount ];
+ TQPaintDevice::x_approotwindow_arr = new TQt::HANDLE[ appScreenCount ];
+ TQPaintDevice::x_appcolormap_arr = new TQt::HANDLE[ appScreenCount ];
+ TQPaintDevice::x_appdefcolormap_arr = new bool[ appScreenCount ];
+ TQPaintDevice::x_appvisual_arr = new void*[ appScreenCount ];
+ TQPaintDevice::x_appdefvisual_arr = new bool[ appScreenCount ];
+ TQ_CHECK_PTR( TQPaintDevice::x_appdepth_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appcells_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_approotwindow_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appcolormap_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appdefcolormap_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appvisual_arr );
+ TQ_CHECK_PTR( TQPaintDevice::x_appdefvisual_arr );
+
+ int screen;
+ TQString serverVendor( ServerVendor( appDpy) );
+ if (serverVendor.tqcontains("XFree86") && VendorRelease(appDpy) < 40300000)
+ qt_hebrew_keyboard_hack = TRUE;
+
+ for ( screen = 0; screen < appScreenCount; ++screen ) {
+ TQPaintDevice::x_appdepth_arr[ screen ] = DefaultDepth(appDpy, screen);
+ TQPaintDevice::x_appcells_arr[ screen ] = DisplayCells(appDpy, screen);
+ TQPaintDevice::x_approotwindow_arr[ screen ] = RootWindow(appDpy, screen);
+
+ // setup the visual and colormap for each screen
+ Visual *vis = 0;
+ if ( visual && screen == appScreen ) {
+ // use the provided visual on the default screen only
+ vis = (Visual *) visual;
+
+ // figure out the depth of the visual we are using
+ XVisualInfo *vi, rvi;
+ int n;
+ rvi.visualid = XVisualIDFromVisual(vis);
+ rvi.screen = screen;
+ vi = XGetVisualInfo( appDpy, VisualIDMask | VisualScreenMask, &rvi, &n );
+ if (vi) {
+ TQPaintDevice::x_appdepth_arr[ screen ] = vi->depth;
+ TQPaintDevice::x_appcells_arr[ screen ] = vi->visual->map_entries;
+ TQPaintDevice::x_appvisual_arr[ screen ] = vi->visual;
+ TQPaintDevice::x_appdefvisual_arr[ screen ] = FALSE;
+ XFree(vi);
+ } else {
+ // couldn't get info about the visual, use the default instead
+ vis = 0;
+ }
+ }
+
+ if (!vis) {
+ // use the default visual
+ vis = DefaultVisual(appDpy, screen);
+ TQPaintDevice::x_appdefvisual_arr[ screen ] = TRUE;
+
+ if ( qt_visual_option == TrueColor ||
+ TQApplication::colorSpec() == TQApplication::ManyColor ) {
+ // tqfind custom visual
+
+ int d, c;
+ vis = tqfind_truecolor_visual( appDpy, screen, &d, &c );
+ TQPaintDevice::x_appdepth_arr[ screen ] = d;
+ TQPaintDevice::x_appcells_arr[ screen ] = c;
+
+ TQPaintDevice::x_appvisual_arr[ screen ] = vis;
+ TQPaintDevice::x_appdefvisual_arr[ screen ] =
+ (XVisualIDFromVisual(vis) ==
+ XVisualIDFromVisual(DefaultVisual(appDpy, screen)));
+ }
+
+ TQPaintDevice::x_appvisual_arr[ screen ] = vis;
+ }
+
+ // we assume that 8bpp == pseudocolor, but this is not
+ // always the case (according to the X server), so we need
+ // to make sure that our internal data is setup in a way
+ // that is compatible with our assumptions
+ if ( vis->c_class == TrueColor &&
+ TQPaintDevice::x_appdepth_arr[ screen ] == 8 &&
+ TQPaintDevice::x_appcells_arr[ screen ] == 8 )
+ TQPaintDevice::x_appcells_arr[ screen ] = 256;
+
+ if ( colormap && screen == appScreen ) {
+ // use the provided colormap for the default screen only
+ TQPaintDevice::x_appcolormap_arr[ screen ] = colormap;
+ TQPaintDevice::x_appdefcolormap_arr[ screen ] = FALSE;
+ } else {
+ if ( vis->c_class == TrueColor ) {
+ TQPaintDevice::x_appdefcolormap_arr[ screen ] =
+ TQPaintDevice::x_appdefvisual_arr[ screen ];
+ } else {
+ TQPaintDevice::x_appdefcolormap_arr[ screen ] =
+ !qt_cmap_option && TQPaintDevice::x_appdefvisual_arr[ screen ];
+ }
+
+ if ( TQPaintDevice::x_appdefcolormap_arr[ screen ] ) {
+ // use default colormap
+ XStandardColormap *stdcmap;
+ VisualID vid =
+ XVisualIDFromVisual((Visual *)
+ TQPaintDevice::x_appvisual_arr[ screen ]);
+ int i, count;
+
+ TQPaintDevice::x_appcolormap_arr[ screen ] = 0;
+
+ if ( ! serverVendor.tqcontains( "Hewlett-Packard" ) ) {
+ // on HPUX 10.20 local displays, the RGB_DEFAULT_MAP colormap
+ // doesn't give us correct colors. Why this happens, I have
+ // no clue, so we disable this for HPUX
+ if (XGetRGBColormaps(appDpy,
+ TQPaintDevice::x11AppRootWindow( screen ),
+ &stdcmap, &count, XA_RGB_DEFAULT_MAP)) {
+ i = 0;
+ while (i < count &&
+ TQPaintDevice::x_appcolormap_arr[ screen ] == 0) {
+ if (stdcmap[i].visualid == vid) {
+ TQPaintDevice::x_appcolormap_arr[ screen ] =
+ stdcmap[i].colormap;
+ }
+ i++;
+ }
+
+ XFree( (char *)stdcmap );
+ }
+ }
+
+ if (TQPaintDevice::x_appcolormap_arr[ screen ] == 0) {
+ TQPaintDevice::x_appcolormap_arr[ screen ] =
+ DefaultColormap(appDpy, screen);
+ }
+ } else {
+ // create a custom colormap
+ TQPaintDevice::x_appcolormap_arr[ screen ] =
+ XCreateColormap(appDpy, TQPaintDevice::x11AppRootWindow( screen ),
+ vis, AllocNone);
+ }
+ }
+ }
+
+ // Set X painttqdevice parameters for the default screen
+ TQPaintDevice::x_appdepth = TQPaintDevice::x_appdepth_arr[ appScreen ];
+ TQPaintDevice::x_appcells = TQPaintDevice::x_appcells_arr[ appScreen ];
+ TQPaintDevice::x_approotwindow = TQPaintDevice::x_approotwindow_arr[ appScreen ];
+ TQPaintDevice::x_appcolormap = TQPaintDevice::x_appcolormap_arr[ appScreen ];
+ TQPaintDevice::x_appdefcolormap = TQPaintDevice::x_appdefcolormap_arr[ appScreen ];
+ TQPaintDevice::x_appvisual = TQPaintDevice::x_appvisual_arr[ appScreen ];
+ TQPaintDevice::x_appdefvisual = TQPaintDevice::x_appdefvisual_arr[ appScreen ];
+
+ // Support protocols
+
+ qt_x11_intern_atom( "WM_PROTOCOLS", &qt_wm_protocols );
+ qt_x11_intern_atom( "WM_DELETE_WINDOW", &qt_wm_delete_window );
+ qt_x11_intern_atom( "WM_STATE", &qt_wm_state );
+ qt_x11_intern_atom( "WM_CHANGE_STATE", &qt_wm_change_state );
+ qt_x11_intern_atom( "WM_TAKE_FOCUS", &qt_wm_take_focus );
+ qt_x11_intern_atom( "WM_CLIENT_LEADER", &qt_wm_client_leader);
+ qt_x11_intern_atom( "WM_WINDOW_ROLE", &qt_window_role);
+ qt_x11_intern_atom( "SM_CLIENT_ID", &qt_sm_client_id);
+ qt_x11_intern_atom( "CLIPBOARD", &qt_xa_clipboard );
+ qt_x11_intern_atom( "RESOURCE_MANAGER", &qt_resource_manager );
+ qt_x11_intern_atom( "INCR", &qt_x_incr );
+ qt_x11_intern_atom( "_XSETROOT_ID", &qt_xsetroot_id );
+ qt_x11_intern_atom( "_TQT_SELECTION", &qt_selection_property );
+ qt_x11_intern_atom( "_TQT_CLIPBOARD_SENTINEL", &qt_clipboard_sentinel );
+ qt_x11_intern_atom( "_TQT_SELECTION_SENTINEL", &qt_selection_sentinel );
+ qt_x11_intern_atom( "_TQT_SCROLL_DONE", &qt_qt_scrolldone );
+ qt_x11_intern_atom( "_TQT_INPUT_ENCODING", &qt_input_encoding );
+ qt_x11_intern_atom( "_TQT_SIZEGRIP", &qt_sizegrip );
+ qt_x11_intern_atom( "_NET_WM_CONTEXT_HELP", &qt_net_wm_context_help );
+ qt_x11_intern_atom( "_NET_WM_PING", &qt_net_wm_ping );
+ qt_x11_intern_atom( "_MOTIF_WM_HINTS", &qt_xa_motif_wm_hints );
+ qt_x11_intern_atom( "DTWM_IS_RUNNING", &qt_cde_running );
+ qt_x11_intern_atom( "KWIN_RUNNING", &qt_kwin_running );
+ qt_x11_intern_atom( "KWM_RUNNING", &qt_kwm_running );
+ qt_x11_intern_atom( "GNOME_BACKGROUND_PROPERTIES", &qt_gbackground_properties );
+
+ TQString atomname("_TQT_SETTINGS_TIMESTAMP_");
+ atomname += XDisplayName(appDpyName);
+ qt_x11_intern_atom( atomname.latin1(), &qt_settings_timestamp );
+
+ qt_x11_intern_atom( "_NET_SUPPORTED", &qt_net_supported );
+ qt_x11_intern_atom( "_NET_VIRTUAL_ROOTS", &qt_net_virtual_roots );
+ qt_x11_intern_atom( "_NET_WORKAREA", &qt_net_workarea );
+ qt_x11_intern_atom( "_NET_WM_STATE", &qt_net_wm_state );
+ qt_x11_intern_atom( "_NET_WM_STATE_MODAL", &qt_net_wm_state_modal );
+ qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_VERT", &qt_net_wm_state_max_v );
+ qt_x11_intern_atom( "_NET_WM_STATE_MAXIMIZED_HORZ", &qt_net_wm_state_max_h );
+ qt_x11_intern_atom( "_NET_WM_STATE_FULLSCREEN", &qt_net_wm_state_fullscreen );
+ qt_x11_intern_atom( "_NET_WM_STATE_ABOVE", &qt_net_wm_state_above );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE", &qt_net_wm_window_type );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_NORMAL", &qt_net_wm_window_type_normal );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_DIALOG", &qt_net_wm_window_type_dialog );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_TOOLBAR", &qt_net_wm_window_type_toolbar );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_MENU", &qt_net_wm_window_type_menu );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_UTILITY", &qt_net_wm_window_type_utility );
+ qt_x11_intern_atom( "_NET_WM_WINDOW_TYPE_SPLASH", &qt_net_wm_window_type_splash );
+ qt_x11_intern_atom( "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", &qt_net_wm_window_type_override );
+ qt_x11_intern_atom( "_KDE_NET_WM_FRAME_STRUT", &qt_net_wm_frame_strut );
+ qt_x11_intern_atom( "_NET_WM_STATE_STAYS_ON_TOP",
+ &qt_net_wm_state_stays_on_top );
+ qt_x11_intern_atom( "_NET_WM_PID", &qt_net_wm_pid );
+ qt_x11_intern_atom( "_NET_WM_USER_TIME", &qt_net_wm_user_time );
+ qt_x11_intern_atom( "ENLIGHTENMENT_DESKTOP", &qt_enlightenment_desktop );
+ qt_x11_intern_atom( "_NET_WM_NAME", &qt_net_wm_name );
+ qt_x11_intern_atom( "_NET_WM_ICON_NAME", &qt_net_wm_icon_name );
+ qt_x11_intern_atom( "UTF8_STRING", &qt_utf8_string );
+ qt_x11_intern_atom( "_SGI_DESKS_MANAGER", &qt_sgi_desks_manager );
+
+ qt_xdnd_setup();
+ qt_x11_motifdnd_init();
+
+ // Finally create all atoms
+ qt_x11_process_intern_atoms();
+
+ // look for broken window managers
+ qt_detect_broken_window_manager();
+
+ // initialize NET lists
+ qt_get_net_supported();
+ qt_get_net_virtual_roots();
+
+#ifndef TQT_NO_XRANDR
+ // See if XRandR is supported on the connected display
+ int xrandr_errorbase;
+ TQ_UNUSED( xrandr_eventbase );
+ if ( XRRQueryExtension( appDpy, &xrandr_eventbase, &xrandr_errorbase ) ) {
+ // XRandR is supported
+ qt_use_xrandr = TRUE;
+ }
+#endif // TQT_NO_XRANDR
+
+#ifndef TQT_NO_XRENDER
+ // See if XRender is supported on the connected display
+ int xrender_eventbase, xrender_errorbase;
+ if (XRenderQueryExtension(appDpy, &xrender_eventbase, &xrender_errorbase)) {
+ // XRender is supported, let's see if we have a PictFormat for the
+ // default visual
+ XRenderPictFormat *format =
+ XRenderFindVisualFormat(appDpy,
+ (Visual *) TQPaintDevice::x_appvisual);
+ qt_use_xrender = (format != 0) && (TQPaintDevice::x_appdepth != 8);
+ }
+#endif // TQT_NO_XRENDER
+
+#ifndef TQT_NO_XKB
+ // If XKB is detected, set the GrabsUseXKBState option so input method
+ // compositions continue to work (ie. deadkeys)
+ unsigned int state = XkbPCF_GrabsUseXKBStateMask;
+ (void) XkbSetPerClientControls(appDpy, state, &state);
+#endif
+
+#if !defined(TQT_NO_XFTFREETYPE)
+ // defined in qfont_x11.cpp
+ extern bool qt_has_xft;
+#ifndef TQT_XFT2
+ if (!qt_use_xrender)
+ qt_has_xft = FALSE;
+ else
+#endif
+ qt_has_xft = XftInit(0) && XftInitFtLibrary();
+
+ if (qt_has_xft) {
+ char *dpi_str = XGetDefault(appDpy, "Xft", "dpi");
+ if (dpi_str) {
+ // use a custom DPI
+ char *end = 0;
+ int dpi = strtol(dpi_str, &end, 0);
+ if (dpi_str != end) {
+ for (int s = 0; s < ScreenCount(appDpy); ++s) {
+ TQPaintDevice::x11SetAppDpiX(dpi, s);
+ TQPaintDevice::x11SetAppDpiY(dpi, s);
+ }
+ }
+ }
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ // look at the modifier mapping, and get the correct masks for alt/meta
+ // tqfind the alt/meta masks
+ XModifierKeymap *map = XGetModifierMapping(appDpy);
+ if (map) {
+ int i, maskIndex = 0, mapIndex = 0;
+ for (maskIndex = 0; maskIndex < 8; maskIndex++) {
+ for (i = 0; i < map->max_keypermod; i++) {
+ if (map->modifiermap[mapIndex]) {
+ KeySym sym =
+ XKeycodeToKeysym(appDpy, map->modifiermap[mapIndex], 0);
+ if ( qt_alt_mask == 0 &&
+ ( sym == XK_Alt_L || sym == XK_Alt_R ) ) {
+ qt_alt_mask = 1 << maskIndex;
+ }
+ if ( qt_meta_mask == 0 &&
+ (sym == XK_Meta_L || sym == XK_Meta_R ) ) {
+ qt_meta_mask = 1 << maskIndex;
+ }
+ }
+ mapIndex++;
+ }
+ }
+
+ // not look for mode_switch in qt_alt_mask and qt_meta_mask - if it is
+ // present in one or both, then we set qt_mode_switch_remove_mask.
+ // see TQETWidget::translateKeyEventInternal for an explanation
+ // of why this is needed
+ mapIndex = 0;
+ for ( maskIndex = 0; maskIndex < 8; maskIndex++ ) {
+ if ( qt_alt_mask != ( 1 << maskIndex ) &&
+ qt_meta_mask != ( 1 << maskIndex ) ) {
+ for ( i = 0; i < map->max_keypermod; i++ )
+ mapIndex++;
+ continue;
+ }
+
+ for ( i = 0; i < map->max_keypermod; i++ ) {
+ if ( map->modifiermap[ mapIndex ] ) {
+ KeySym sym =
+ XKeycodeToKeysym( appDpy, map->modifiermap[ mapIndex ], 0 );
+ if ( sym == XK_Mode_switch ) {
+ qt_mode_switch_remove_mask |= 1 << maskIndex;
+ }
+ }
+ mapIndex++;
+ }
+ }
+
+ XFreeModifiermap(map);
+ } else {
+ // assume defaults
+ qt_alt_mask = Mod1Mask;
+ qt_meta_mask = Mod4Mask;
+ qt_mode_switch_remove_mask = 0;
+ }
+
+ // Misc. initialization
+
+ TQColor::initialize();
+ TQFont::initialize();
+ TQCursor::initialize();
+ TQPainter::initialize();
+ }
+
+#if defined(TQT_THREAD_SUPPORT)
+ TQThread::initialize();
+#endif
+
+ if( qt_is_gui_used ) {
+ tqApp->setName( appName );
+
+ int screen;
+ for ( screen = 0; screen < appScreenCount; ++screen ) {
+ XSelectInput( appDpy, TQPaintDevice::x11AppRootWindow( screen ),
+ KeymapStateMask | EnterWindowMask | LeaveWindowMask |
+ PropertyChangeMask );
+
+#ifndef TQT_NO_XRANDR
+ if (qt_use_xrandr)
+ XRRSelectInput( appDpy, TQPaintDevice::x11AppRootWindow( screen ), True );
+#endif // TQT_NO_XRANDR
+ }
+ }
+
+ if ( qt_is_gui_used ) {
+ qt_set_input_encoding();
+
+ qt_set_x11_resources( appFont, appFGCol, appBGCol, appBTNCol);
+
+ // be smart about the size of the default font. most X servers have helvetica
+ // 12 point available at 2 resolutions:
+ // 75dpi (12 pixels) and 100dpi (17 pixels).
+ // At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17
+ // pixel font is a closer match than a 12 pixel font
+ int ptsz =
+ (int) ( ( ( TQPaintDevice::x11AppDpiY() >= 95 ? 17. : 12. ) *
+ 72. / (float) TQPaintDevice::x11AppDpiY() ) + 0.5 );
+
+ if ( !qt_app_has_font && !qt_x11_cmdline_font ) {
+ TQFont f( "Helvetica", ptsz );
+ TQApplication::setFont( f );
+ }
+
+#ifndef TQT_NO_XIM
+ if ( ! xim_preferred_style ) // no configured input style, use the default
+ xim_preferred_style = xim_default_style;
+
+ qt_xim = 0;
+ TQString ximServerName(ximServer);
+ if (ximServer)
+ ximServerName.prepend("@im=");
+ else
+ ximServerName = "";
+
+ if ( !XSupportsLocale() )
+ qWarning("TQt: Locales not supported on X server");
+
+#ifdef USE_X11R6_XIM
+ else if ( XSetLocaleModifiers (ximServerName.ascii()) == 0 )
+ qWarning( "TQt: Cannot set locale modifiers: %s",
+ ximServerName.ascii());
+ else if (! noxim)
+ XRegisterIMInstantiateCallback(appDpy, 0, 0, 0,
+ (XIMProc) xim_create_callback, 0);
+#else // !USE_X11R6_XIM
+ else if ( XSetLocaleModifiers ("") == 0 )
+ qWarning("TQt: Cannot set locale modifiers");
+ else if (! noxim)
+ TQApplication::create_xim();
+#endif // USE_X11R6_XIM
+#endif // TQT_NO_XIM
+
+#if defined (TQT_TABLET_SUPPORT)
+ int ndev,
+ i,
+ j;
+ bool gotStylus,
+ gotEraser;
+ XDeviceInfo *tqdevices, *devs;
+ XInputClassInfo *ip;
+ XAnyClassPtr any;
+ XValuatorInfoPtr v;
+ XAxisInfoPtr a;
+ XDevice *dev;
+ XEventClass *ev_class;
+ int curr_event_count;
+
+#if !defined(TQ_OS_IRIX)
+ // XFree86 divides a stylus and eraser into 2 tqdevices, so we must do for both...
+ const TQString XFREENAMESTYLUS = "stylus";
+ const TQString XFREENAMEPEN = "pen";
+ const TQString XFREENAMEERASER = "eraser";
+#endif
+
+ tqdevices = XListInputDevices( appDpy, &ndev);
+ if ( tqdevices == NULL ) {
+ qWarning( "Failed to get list of tqdevices" );
+ ndev = -1;
+ }
+ dev = NULL;
+ for ( devs = tqdevices, i = 0; i < ndev; i++, devs++ ) {
+ gotEraser = FALSE;
+#if defined(TQ_OS_IRIX)
+
+ gotStylus = ( !strncmp(devs->name,
+ WACOM_NAME, sizeof(WACOM_NAME) - 1) );
+#else
+ TQString devName = devs->name;
+ devName = devName.lower();
+ gotStylus = ( devName.startsWith(XFREENAMEPEN)
+ || devName.startsWith(XFREENAMESTYLUS) );
+ if ( !gotStylus )
+ gotEraser = devName.startsWith( XFREENAMEERASER );
+
+#endif
+ if ( gotStylus || gotEraser ) {
+ // I only wanted to do this once, so wrap pointers around these
+ curr_event_count = 0;
+
+ if ( gotStylus ) {
+ devStylus = XOpenDevice( appDpy, devs->id );
+ dev = devStylus;
+ ev_class = event_list_stylus;
+ } else if ( gotEraser ) {
+ devEraser = XOpenDevice( appDpy, devs->id );
+ dev = devEraser;
+ ev_class = event_list_eraser;
+ }
+ if ( dev == NULL ) {
+ qWarning( "Failed to open tqdevice" );
+ } else {
+ if ( dev->num_classes > 0 ) {
+ for ( ip = dev->classes, j = 0; j < devs->num_classes;
+ ip++, j++ ) {
+ switch ( ip->input_class ) {
+ case KeyClass:
+ DeviceKeyPress( dev, xinput_key_press,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ DeviceKeyRelease( dev, xinput_key_release,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ break;
+ case ButtonClass:
+ DeviceButtonPress( dev, xinput_button_press,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ DeviceButtonRelease( dev, xinput_button_release,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ break;
+ case ValuatorClass:
+ // I'm only going to be interested in motion when the
+ // stylus is already down anyway!
+ DeviceMotionNotify( dev, xinput_motion,
+ ev_class[curr_event_count] );
+ curr_event_count++;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ // get the min/max value for pressure!
+ any = (XAnyClassPtr) ( devs->inputclassinfo );
+ if ( dev == devStylus ) {
+ qt_curr_events_stylus = curr_event_count;
+ for (j = 0; j < devs->num_classes; j++) {
+ if ( any->c_class == ValuatorClass ) {
+ v = (XValuatorInfoPtr) any;
+ a = (XAxisInfoPtr) ((char *) v +
+ sizeof (XValuatorInfo));
+#if defined (TQ_OS_IRIX)
+ max_pressure = a[WAC_PRESSURE_I].max_value;
+#else
+ max_pressure = a[2].max_value;
+#endif
+ // got the max pressure no need to go further...
+ break;
+ }
+ any = (XAnyClassPtr) ((char *) any + any->length);
+ }
+ } else {
+ qt_curr_events_eraser = curr_event_count;
+ }
+ // at this point we are assuming there is only one
+ // wacom tqdevice...
+#if defined (TQ_OS_IRIX)
+ if ( devStylus != NULL ) {
+#else
+ if ( devStylus != NULL && devEraser != NULL ) {
+#endif
+ break;
+ }
+ }
+ } // end for loop
+ XFreeDeviceList( tqdevices );
+#endif // TQT_TABLET_SUPPORT
+
+ } else {
+ // read some non-GUI settings when not using the X server...
+
+ if ( TQApplication::desktopSettingsAware() ) {
+ TQSettings settings;
+
+ // read library (ie. plugin) path list
+ TQString libpathkey = TQString("/qt/%1.%2/libraryPath")
+ .arg( TQT_VERSION >> 16 )
+ .arg( (TQT_VERSION & 0xff00 ) >> 8 );
+ TQStringList pathlist =
+ settings.readListEntry(libpathkey, ':');
+ if (! pathlist.isEmpty()) {
+ TQStringList::ConstIterator it = pathlist.begin();
+ while (it != pathlist.end())
+ TQApplication::addLibraryPath(*it++);
+ }
+
+ TQString defaultcodec = settings.readEntry("/qt/defaultCodec", "none");
+ if (defaultcodec != "none") {
+ TQTextCodec *codec = TQTextCodec::codecForName(defaultcodec);
+ if (codec)
+ tqApp->setDefaultCodec(codec);
+ }
+
+ qt_resolve_symlinks =
+ settings.readBoolEntry("/qt/resolveSymlinks", TRUE);
+ }
+ }
+ }
+
+
+#ifndef TQT_NO_STYLE
+ // run-time search for default style
+void TQApplication::x11_initialize_style()
+{
+ Atom type;
+ int format;
+ unsigned long length, after;
+ uchar *data;
+ if ( !app_style &&
+ XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_kwin_running,
+ 0, 1, False, AnyPropertyType, &type, &format, &length,
+ &after, &data ) == Success && length ) {
+ if ( data ) XFree( (char *)data );
+ // kwin is there. check if KDE's styles are available,
+ // otherwise use windows style
+ if ( (app_style = TQStyleFactory::create("highcolor") ) == 0 )
+ app_style = TQStyleFactory::create("windows");
+ }
+ if ( !app_style &&
+ XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_kwm_running,
+ 0, 1, False, AnyPropertyType, &type, &format, &length,
+ &after, &data ) == Success && length ) {
+ if ( data ) XFree( (char *)data );
+ app_style = TQStyleFactory::create("windows");
+ }
+ if ( !app_style &&
+ XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(), qt_cde_running,
+ 0, 1, False, AnyPropertyType, &type, &format, &length,
+ &after, &data ) == Success && length ) {
+ // DTWM is running, meaning most likely CDE is running...
+ if ( data ) XFree( (char *) data );
+ app_style = TQStyleFactory::create( "cde" );
+ }
+ // maybe another desktop?
+ if ( !app_style &&
+ XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_gbackground_properties, 0, 1, False, AnyPropertyType,
+ &type, &format, &length, &after, &data ) == Success &&
+ length ) {
+ if ( data ) XFree( (char *)data );
+ // default to MotifPlus with hovering
+ app_style = TQStyleFactory::create("motifplus" );
+ }
+}
+#endif
+
+void qt_init( int *argcptr, char **argv, TQApplication::Type )
+{
+ qt_init_internal( argcptr, argv, 0, 0, 0 );
+}
+
+void qt_init( Display *display, TQt::HANDLE visual, TQt::HANDLE colormap )
+{
+ qt_init_internal( 0, 0, display, visual, colormap );
+}
+
+
+/*****************************************************************************
+ qt_cleanup() - cleans up when the application is finished
+ *****************************************************************************/
+
+void qt_cleanup()
+{
+ appliedstamp = 0;
+
+ if ( app_save_rootinfo ) // root window must keep state
+ qt_save_rootinfo();
+
+ if ( qt_is_gui_used ) {
+ TQPixmapCache::clear();
+ TQPainter::cleanup();
+ TQCursor::cleanup();
+ TQFont::cleanup();
+ TQColor::cleanup();
+ TQSharedDoubleBuffer::cleanup();
+ }
+#if defined(TQT_THREAD_SUPPORT)
+ TQThread::cleanup();
+#endif
+
+#if defined (TQT_TABLET_SUPPORT)
+ if ( devStylus != NULL )
+ XCloseDevice( appDpy, devStylus );
+ if ( devEraser != NULL )
+ XCloseDevice( appDpy, devEraser );
+#endif
+
+#if !defined(TQT_NO_XIM)
+ if ( qt_xim )
+ TQApplication::close_xim();
+#endif
+
+ if ( qt_is_gui_used ) {
+ int screen;
+ for ( screen = 0; screen < appScreenCount; screen++ ) {
+ if ( ! TQPaintDevice::x11AppDefaultColormap( screen ) )
+ XFreeColormap( TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppColormap( screen ) );
+ }
+ }
+
+#define TQT_CLEANUP_GC(g) if (g) { for (int i=0;i<appScreenCount;i++){if(g[i])XFreeGC(appDpy,g[i]);} delete [] g; g = 0; }
+ TQT_CLEANUP_GC(app_gc_ro);
+ TQT_CLEANUP_GC(app_gc_ro_m);
+ TQT_CLEANUP_GC(app_gc_tmp);
+ TQT_CLEANUP_GC(app_gc_tmp_m);
+#undef TQT_CLEANUP_GC
+
+ delete sip_list;
+ sip_list = 0;
+
+ // Reset the error handlers
+ XSetErrorHandler( original_x_errhandler );
+ XSetIOErrorHandler( original_xio_errhandler );
+
+ if ( qt_is_gui_used && !appForeignDpy )
+ XCloseDisplay( appDpy ); // close X display
+ appDpy = 0;
+
+ qt_x11_wm_client_leader = 0;
+
+ if ( TQPaintDevice::x_appdepth_arr )
+ delete [] TQPaintDevice::x_appdepth_arr;
+ if ( TQPaintDevice::x_appcells_arr )
+ delete [] TQPaintDevice::x_appcells_arr;
+ if ( TQPaintDevice::x_appcolormap_arr )
+ delete []TQPaintDevice::x_appcolormap_arr;
+ if ( TQPaintDevice::x_appdefcolormap_arr )
+ delete [] TQPaintDevice::x_appdefcolormap_arr;
+ if ( TQPaintDevice::x_appvisual_arr )
+ delete [] TQPaintDevice::x_appvisual_arr;
+ if ( TQPaintDevice::x_appdefvisual_arr )
+ delete [] TQPaintDevice::x_appdefvisual_arr;
+
+ if ( appForeignDpy ) {
+ delete [] (char *)appName;
+ appName = 0;
+ delete [] (char *)appClass;
+ appClass = 0;
+ }
+
+ if (qt_net_supported_list)
+ delete [] qt_net_supported_list;
+ qt_net_supported_list = 0;
+
+ if (qt_net_virtual_root_list)
+ delete [] qt_net_virtual_root_list;
+ qt_net_virtual_root_list = 0;
+}
+
+
+/*****************************************************************************
+ Platform specific global and internal functions
+ *****************************************************************************/
+
+void qt_save_rootinfo() // save new root info
+{
+ Atom type;
+ int format;
+ unsigned long length, after;
+ uchar *data;
+
+ if ( qt_xsetroot_id ) { // kill old pixmap
+ if ( XGetWindowProperty( appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_xsetroot_id, 0, 1,
+ True, AnyPropertyType, &type, &format,
+ &length, &after, &data ) == Success ) {
+ if ( type == XA_PIXMAP && format == 32 && length == 1 &&
+ after == 0 && data ) {
+ XKillClient( appDpy, *((Pixmap*)data) );
+ }
+ Pixmap dummy = XCreatePixmap( appDpy, TQPaintDevice::x11AppRootWindow(),
+ 1, 1, 1 );
+ XChangeProperty( appDpy, TQPaintDevice::x11AppRootWindow(),
+ qt_xsetroot_id, XA_PIXMAP, 32,
+ PropModeReplace, (uchar *)&dummy, 1 );
+ XSetCloseDownMode( appDpy, RetainPermanent );
+ }
+ }
+ if ( data )
+ XFree( (char *)data );
+}
+
+void qt_updated_rootinfo()
+{
+ app_save_rootinfo = TRUE;
+}
+
+bool qt_wstate_iconified( WId winid )
+{
+ Atom type;
+ int format;
+ unsigned long length, after;
+ uchar *data;
+ int r = XGetWindowProperty( appDpy, winid, qt_wm_state, 0, 2,
+ False, AnyPropertyType, &type, &format,
+ &length, &after, &data );
+ bool iconic = FALSE;
+ if ( r == Success && data && format == 32 ) {
+ // TQ_UINT32 *wstate = (TQ_UINT32*)data;
+ unsigned long *wstate = (unsigned long *) data;
+ iconic = (*wstate == IconicState );
+ XFree( (char *)data );
+ }
+ return iconic;
+}
+
+const char *tqAppName() // get application name
+{
+ return appName;
+}
+
+const char *tqAppClass() // get application class
+{
+ return appClass;
+}
+
+Display *qt_xdisplay() // get current X display
+{
+ return appDpy;
+}
+
+int qt_xscreen() // get current X screen
+{
+ return appScreen;
+}
+
+// ### REMOVE 4.0
+WId qt_xrootwin() // get X root window
+{
+ return TQPaintDevice::x11AppRootWindow();
+}
+
+WId qt_xrootwin( int scrn ) // get X root window for screen
+{
+ return TQPaintDevice::x11AppRootWindow( scrn );
+}
+
+bool qt_nograb() // application no-grab option
+{
+#if defined(TQT_DEBUG)
+ return appNoGrab;
+#else
+ return FALSE;
+#endif
+}
+
+static GC create_gc( int scrn, bool monochrome )
+{
+ GC gc;
+ if ( monochrome ) {
+ Pixmap pm = XCreatePixmap( appDpy, RootWindow( appDpy, scrn ), 8, 8, 1 );
+ gc = XCreateGC( appDpy, pm, 0, 0 );
+ XFreePixmap( appDpy, pm );
+ } else {
+ if ( TQPaintDevice::x11AppDefaultVisual( scrn ) ) {
+ gc = XCreateGC( appDpy, RootWindow( appDpy, scrn ), 0, 0 );
+ } else {
+ Window w;
+ XSetWindowAttributes a;
+ a.background_pixel = TQt::black.pixel( scrn );
+ a.border_pixel = TQt::black.pixel( scrn );
+ a.colormap = TQPaintDevice::x11AppColormap( scrn );
+ w = XCreateWindow( appDpy, RootWindow( appDpy, scrn ), 0, 0, 100, 100,
+ 0, TQPaintDevice::x11AppDepth( scrn ), InputOutput,
+ (Visual*)TQPaintDevice::x11AppVisual( scrn ),
+ CWBackPixel|CWBorderPixel|CWColormap, &a );
+ gc = XCreateGC( appDpy, w, 0, 0 );
+ XDestroyWindow( appDpy, w );
+ }
+ }
+ XSetGraphicsExposures( appDpy, gc, False );
+ return gc;
+}
+
+GC qt_xget_readonly_gc( int scrn, bool monochrome ) // get read-only GC
+{
+ if ( scrn < 0 || scrn >= appScreenCount ) {
+ qDebug("invalid screen %d %d", scrn, appScreenCount );
+ TQWidget* bla = 0;
+ bla->setName("hello");
+ }
+ GC gc;
+ if ( monochrome ) {
+ if ( !app_gc_ro_m ) // create GC for bitmap
+ memset( (app_gc_ro_m = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) );
+ if ( !app_gc_ro_m[scrn] )
+ app_gc_ro_m[scrn] = create_gc( scrn, TRUE );
+ gc = app_gc_ro_m[scrn];
+ } else { // create standard GC
+ if ( !app_gc_ro )
+ memset( (app_gc_ro = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) );
+ if ( !app_gc_ro[scrn] )
+ app_gc_ro[scrn] = create_gc( scrn, FALSE );
+ gc = app_gc_ro[scrn];
+ }
+ return gc;
+}
+
+GC qt_xget_temp_gc( int scrn, bool monochrome ) // get temporary GC
+{
+ if ( scrn < 0 || scrn >= appScreenCount ) {
+ qDebug("invalid screen (tmp) %d %d", scrn, appScreenCount );
+ TQWidget* bla = 0;
+ bla->setName("hello");
+ }
+ GC gc;
+ if ( monochrome ) {
+ if ( !app_gc_tmp_m ) // create GC for bitmap
+ memset( (app_gc_tmp_m = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) );
+ if ( !app_gc_tmp_m[scrn] )
+ app_gc_tmp_m[scrn] = create_gc( scrn, TRUE );
+ gc = app_gc_tmp_m[scrn];
+ } else { // create standard GC
+ if ( !app_gc_tmp )
+ memset( (app_gc_tmp = new GC[appScreenCount]), 0, appScreenCount * sizeof( GC ) );
+ if ( !app_gc_tmp[scrn] )
+ app_gc_tmp[scrn] = create_gc( scrn, FALSE );
+ gc = app_gc_tmp[scrn];
+ }
+ return gc;
+}
+
+
+/*****************************************************************************
+ Platform specific TQApplication members
+ *****************************************************************************/
+
+/*!
+ \fn TQWidget *TQApplication::mainWidget() const
+
+ Returns the main application widget, or 0 if there is no main
+ widget.
+
+ \sa setMainWidget()
+*/
+
+/*!
+ Sets the application's main widget to \a mainWidget.
+
+ In most respects the main widget is like any other widget, except
+ that if it is closed, the application exits. Note that
+ TQApplication does \e not take ownership of the \a mainWidget, so
+ if you create your main widget on the heap you must delete it
+ yourself.
+
+ You need not have a main widget; connecting lastWindowClosed() to
+ quit() is an alternative.
+
+ For X11, this function also resizes and moves the main widget
+ according to the \e -tqgeometry command-line option, so you should
+ set the default tqgeometry (using \l TQWidget::setGeometry()) before
+ calling setMainWidget().
+
+ \sa mainWidget(), exec(), quit()
+*/
+
+void TQApplication::setMainWidget( TQWidget *mainWidget )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( mainWidget && mainWidget->parentWidget() &&
+ ! mainWidget->parentWidget()->isDesktop() )
+ qWarning( "TQApplication::setMainWidget(): New main widget (%s/%s) "
+ "has a tqparent!",
+ mainWidget->className(), mainWidget->name() );
+#endif
+ main_widget = mainWidget;
+ if ( main_widget ) { // give WM command line
+ XSetWMProperties( main_widget->x11Display(), main_widget->winId(),
+ 0, 0, app_argv, app_argc, 0, 0, 0 );
+ if ( mwTitle )
+ XStoreName( main_widget->x11Display(), main_widget->winId(), (char*)mwTitle );
+ if ( mwGeometry ) { // parse tqgeometry
+ int x, y;
+ int w, h;
+ int m = XParseGeometry( (char*)mwGeometry, &x, &y, (uint*)&w, (uint*)&h );
+ TQSize minSize = main_widget->tqminimumSize();
+ TQSize maxSize = main_widget->tqmaximumSize();
+ if ( (m & XValue) == 0 )
+ x = main_widget->tqgeometry().x();
+ if ( (m & YValue) == 0 )
+ y = main_widget->tqgeometry().y();
+ if ( (m & WidthValue) == 0 )
+ w = main_widget->width();
+ if ( (m & HeightValue) == 0 )
+ h = main_widget->height();
+ w = TQMIN(w,maxSize.width());
+ h = TQMIN(h,maxSize.height());
+ w = TQMAX(w,minSize.width());
+ h = TQMAX(h,minSize.height());
+ if ( (m & XNegative) ) {
+ x = desktop()->width() + x - w;
+ qt_widget_tlw_gravity = NorthEastGravity;
+ }
+ if ( (m & YNegative) ) {
+ y = desktop()->height() + y - h;
+ qt_widget_tlw_gravity = (m & XNegative) ? SouthEastGravity : SouthWestGravity;
+ }
+ main_widget->setGeometry( x, y, w, h );
+ }
+ }
+}
+
+#ifndef TQT_NO_CURSOR
+
+/*****************************************************************************
+ TQApplication cursor stack
+ *****************************************************************************/
+
+extern void qt_x11_enforce_cursor( TQWidget * w );
+
+typedef TQPtrList<TQCursor> TQCursorList;
+
+static TQCursorList *cursorStack = 0;
+
+/*!
+ \fn TQCursor *TQApplication::overrideCursor()
+
+ Returns the active application override cursor.
+
+ This function returns 0 if no application cursor has been defined
+ (i.e. the internal cursor stack is empty).
+
+ \sa setOverrideCursor(), restoreOverrideCursor()
+*/
+
+/*!
+ Sets the application override cursor to \a cursor.
+
+ Application override cursors are intended for showing the user
+ that the application is in a special state, for example during an
+ operation that might take some time.
+
+ This cursor will be displayed in all the application's widgets
+ until restoreOverrideCursor() or another setOverrideCursor() is
+ called.
+
+ Application cursors are stored on an internal stack.
+ setOverrideCursor() pushes the cursor onto the stack, and
+ restoreOverrideCursor() pops the active cursor off the stack.
+ Every setOverrideCursor() must eventually be followed by a
+ corresponding restoreOverrideCursor(), otherwise the stack will
+ never be emptied.
+
+ If \a tqreplace is TRUE, the new cursor will tqreplace the last
+ override cursor (the stack keeps its depth). If \a tqreplace is
+ FALSE, the new stack is pushed onto the top of the stack.
+
+ Example:
+ \code
+ TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) );
+ calculateHugeMandelbrot(); // lunch time...
+ TQApplication::restoreOverrideCursor();
+ \endcode
+
+ \sa overrideCursor(), restoreOverrideCursor(), TQWidget::setCursor()
+*/
+
+void TQApplication::setOverrideCursor( const TQCursor &cursor, bool tqreplace )
+{
+ if ( !cursorStack ) {
+ cursorStack = new TQCursorList;
+ TQ_CHECK_PTR( cursorStack );
+ cursorStack->setAutoDelete( TRUE );
+ }
+ app_cursor = new TQCursor( cursor );
+ TQ_CHECK_PTR( app_cursor );
+ if ( tqreplace )
+ cursorStack->removeLast();
+ cursorStack->append( app_cursor );
+
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // for all widgets that have
+ if ( w->testWState( WState_OwnCursor ) )
+ qt_x11_enforce_cursor( w );
+ ++it;
+ }
+ XFlush( appDpy ); // make X execute it NOW
+}
+
+/*!
+ Undoes the last setOverrideCursor().
+
+ If setOverrideCursor() has been called twice, calling
+ restoreOverrideCursor() will activate the first cursor set.
+ Calling this function a second time restores the original widgets'
+ cursors.
+
+ \sa setOverrideCursor(), overrideCursor().
+*/
+
+void TQApplication::restoreOverrideCursor()
+{
+ if ( !cursorStack ) // no cursor stack
+ return;
+ cursorStack->removeLast();
+ app_cursor = cursorStack->last();
+ if ( TQWidget::wmapper() != 0 && !closingDown() ) {
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // set back to original cursors
+ if ( w->testWState( WState_OwnCursor ) )
+ qt_x11_enforce_cursor( w );
+ ++it;
+ }
+ XFlush( appDpy );
+ }
+ if ( !app_cursor ) {
+ delete cursorStack;
+ cursorStack = 0;
+ }
+}
+
+#endif
+
+/*!
+ \fn bool TQApplication::hasGlobalMouseTracking()
+
+ Returns TRUE if global mouse tracking is enabled; otherwise
+ returns FALSE.
+
+ \sa setGlobalMouseTracking()
+*/
+
+/*!
+ Enables global mouse tracking if \a enable is TRUE, or disables it
+ if \a enable is FALSE.
+
+ Enabling global mouse tracking makes it possible for widget event
+ filters or application event filters to get all mouse move events,
+ even when no button is depressed. This is useful for special GUI
+ elements, e.g. tooltips.
+
+ Global mouse tracking does not affect widgets and their
+ mouseMoveEvent(). For a widget to get mouse move events when no
+ button is depressed, it must do TQWidget::setMouseTracking(TRUE).
+
+ This function uses an internal counter. Each
+ setGlobalMouseTracking(TRUE) must have a corresponding
+ setGlobalMouseTracking(FALSE):
+ \code
+ // at this point global mouse tracking is off
+ TQApplication::setGlobalMouseTracking( TRUE );
+ TQApplication::setGlobalMouseTracking( TRUE );
+ TQApplication::setGlobalMouseTracking( FALSE );
+ // at this point it's still on
+ TQApplication::setGlobalMouseTracking( FALSE );
+ // but now it's off
+ \endcode
+
+ \sa hasGlobalMouseTracking(), TQWidget::hasMouseTracking()
+*/
+
+void TQApplication::setGlobalMouseTracking( bool enable )
+{
+ bool tellAllWidgets;
+ if ( enable ) {
+ tellAllWidgets = (++app_tracking == 1);
+ } else {
+ tellAllWidgets = (--app_tracking == 0);
+ }
+ if ( tellAllWidgets ) {
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)TQWidget::wmapper()) );
+ register TQWidget *w;
+ while ( (w=it.current()) ) {
+ if ( app_tracking > 0 ) { // switch on
+ if ( !w->testWState(WState_MouseTracking) ) {
+ w->setMouseTracking( TRUE );
+ w->clearWState( WState_MouseTracking );
+ }
+ } else { // switch off
+ if ( !w->testWState(WState_MouseTracking) ) {
+ w->setWState( WState_MouseTracking );
+ w->setMouseTracking( FALSE );
+ }
+ }
+ ++it;
+ }
+ }
+}
+
+
+/*****************************************************************************
+ Routines to tqfind a TQt widget from a screen position
+ *****************************************************************************/
+
+Window qt_x11_tqfindClientWindow( Window win, Atom property, bool leaf )
+{
+ Atom type = None;
+ int format, i;
+ ulong nitems, after;
+ uchar *data;
+ Window root, tqparent, target=0, *tqchildren=0;
+ uint ntqchildren;
+ if ( XGetWindowProperty( appDpy, win, property, 0, 0, FALSE, AnyPropertyType,
+ &type, &format, &nitems, &after, &data ) == Success ) {
+ if ( data )
+ XFree( (char *)data );
+ if ( type )
+ return win;
+ }
+ if ( !XQueryTree(appDpy,win,&root,&tqparent,&tqchildren,&ntqchildren) ) {
+ if ( tqchildren )
+ XFree( (char *)tqchildren );
+ return 0;
+ }
+ for ( i=ntqchildren-1; !target && i >= 0; i-- )
+ target = qt_x11_tqfindClientWindow( tqchildren[i], property, leaf );
+ if ( tqchildren )
+ XFree( (char *)tqchildren );
+ return target;
+}
+
+
+/*!
+ Returns a pointer to the widget at global screen position \a
+ (x, y), or 0 if there is no TQt widget there.
+
+ If \a child is FALSE and there is a child widget at position \a
+ (x, y), the top-level widget containing it is returned. If \a child
+ is TRUE the child widget at position \a (x, y) is returned.
+
+ This function is normally rather slow.
+
+ \sa TQCursor::pos(), TQWidget::grabMouse(), TQWidget::grabKeyboard()
+*/
+
+TQWidget *TQApplication::widgetAt( int x, int y, bool child )
+{
+ int screen = TQCursor::x11Screen();
+ int lx, ly;
+
+ Window target;
+ if ( !XTranslateCoordinates(appDpy,
+ TQPaintDevice::x11AppRootWindow(screen),
+ TQPaintDevice::x11AppRootWindow(screen),
+ x, y, &lx, &ly, &target) ) {
+ return 0;
+ }
+ if ( !target || target == TQPaintDevice::x11AppRootWindow(screen) )
+ return 0;
+ TQWidget *w, *c;
+ w = TQWidget::tqfind( (WId)target );
+
+ if ( !w ) {
+ qt_ignore_badwindow();
+ target = qt_x11_tqfindClientWindow( target, qt_wm_state, TRUE );
+ if (qt_badwindow() )
+ return 0;
+ w = TQWidget::tqfind( (WId)target );
+#if 0
+ if ( !w ) {
+ // Perhaps the widgets at (x,y) is inside a foreign application?
+ // Search all toplevel widgets to see if one is within target
+ TQWidgetList *list = tqtopLevelWidgets();
+ TQWidget *widget = list->first();
+ while ( widget && !w ) {
+ Window ctarget = target;
+ if ( widget->isVisible() && !widget->isDesktop() ) {
+ Window wid = widget->winId();
+ while ( ctarget && !w ) {
+ XTranslateCoordinates(appDpy,
+ TQPaintDevice::x11AppRootWindow(screen),
+ ctarget, x, y, &lx, &ly, &ctarget);
+ if ( ctarget == wid ) {
+ // Found
+ w = widget;
+ XTranslateCoordinates(appDpy,
+ TQPaintDevice::x11AppRootWindow(screen),
+ ctarget, x, y, &lx, &ly, &ctarget);
+ }
+ }
+ }
+ widget = list->next();
+ }
+ delete list;
+ }
+#endif
+ }
+ if ( child && w ) {
+ if ( (c = w->tqchildAt( w->mapFromGlobal(TQPoint(x, y ) ) ) ) )
+ return c;
+ }
+ return w;
+}
+
+/*!
+ \overload TQWidget *TQApplication::widgetAt( const TQPoint &pos, bool child )
+
+ Returns a pointer to the widget at global screen position \a pos,
+ or 0 if there is no TQt widget there.
+
+ If \a child is FALSE and there is a child widget at position \a
+ pos, the top-level widget containing it is returned. If \a child
+ is TRUE the child widget at position \a pos is returned.
+*/
+
+
+/*!
+ Flushes the X event queue in the X11 implementation. This normally
+ returns almost immediately. Does nothing on other platforms.
+
+ \sa syncX()
+*/
+
+void TQApplication::flushX()
+{
+ if ( appDpy )
+ XFlush( appDpy );
+}
+
+/*!
+ Flushes the window system specific event queues.
+
+ If you are doing graphical changes inside a loop that does not
+ return to the event loop on asynchronous window systems like X11
+ or double buffered window systems like MacOS X, and you want to
+ visualize these changes immediately (e.g. Splash Screens), call
+ this function.
+
+ \sa flushX() sendPostedEvents() TQPainter::flush()
+*/
+
+void TQApplication::flush()
+{
+ flushX();
+}
+
+/*!
+ Synchronizes with the X server in the X11 implementation. This
+ normally takes some time. Does nothing on other platforms.
+
+ \sa flushX()
+*/
+
+void TQApplication::syncX()
+{
+ if ( appDpy )
+ XSync( appDpy, False ); // don't discard events
+}
+
+
+/*!
+ Sounds the bell, using the default volume and sound.
+*/
+
+void TQApplication::beep()
+{
+ if ( appDpy )
+ XBell( appDpy, 0 );
+}
+
+
+
+/*****************************************************************************
+ Special lookup functions for windows that have been reparented recently
+ *****************************************************************************/
+
+static TQWidgetIntDict *wPRmapper = 0; // alternative widget mapper
+
+void qPRCreate( const TQWidget *widget, Window oldwin )
+{ // TQWidget::reparent mechanism
+ if ( !wPRmapper ) {
+ wPRmapper = new TQWidgetIntDict;
+ TQ_CHECK_PTR( wPRmapper );
+ }
+ wPRmapper->insert( (long)oldwin, widget ); // add old window to mapper
+ TQETWidget *w = (TQETWidget *)widget;
+ w->setWState( TQt::WState_Reparented ); // set reparented flag
+}
+
+void qPRCleanup( TQWidget *widget )
+{
+ TQETWidget *etw = (TQETWidget *)widget;
+ if ( !(wPRmapper && etw->testWState(TQt::WState_Reparented)) )
+ return; // not a reparented widget
+ TQWidgetIntDictIt it(*wPRmapper);
+ TQWidget *w;
+ while ( (w=it.current()) ) {
+ int key = it.currentKey();
+ ++it;
+ if ( w == etw ) { // found widget
+ etw->clearWState( TQt::WState_Reparented ); // clear flag
+ wPRmapper->remove( key );// old window no longer needed
+ if ( wPRmapper->count() == 0 ) { // became empty
+ delete wPRmapper; // then reset alt mapper
+ wPRmapper = 0;
+ return;
+ }
+ }
+ }
+}
+
+static TQETWidget *qPRFindWidget( Window oldwin )
+{
+ return wPRmapper ? (TQETWidget*)wPRmapper->tqfind((long)oldwin) : 0;
+}
+
+/*!
+ \internal
+*/
+int TQApplication::x11ClientMessage(TQWidget* w, XEvent* event, bool passive_only)
+{
+ TQETWidget *widget = (TQETWidget*)w;
+ if ( event->xclient.format == 32 && event->xclient.message_type ) {
+ if ( event->xclient.message_type == qt_wm_protocols ) {
+ Atom a = event->xclient.data.l[0];
+ if ( a == qt_wm_delete_window ) {
+ if ( passive_only ) return 0;
+ widget->translateCloseEvent(event);
+ }
+ else if ( a == qt_wm_take_focus ) {
+ TQWidget * amw = activeModalWidget();
+ if ( (ulong) event->xclient.data.l[1] > GET_QT_X_TIME() )
+ GET_QT_X_TIME() = event->xclient.data.l[1];
+ if ( amw && amw != widget ) {
+ TQWidget* groupLeader = widget;
+ while ( groupLeader && !groupLeader->testWFlags( TQt::WGroupLeader )
+ && groupLeader != amw )
+ groupLeader = groupLeader->parentWidget();
+ if ( !groupLeader ) {
+ TQWidget *p = amw->parentWidget();
+ while (p && p != widget)
+ p = p->parentWidget();
+ if (!p || !qt_net_supported_list)
+ amw->raise(); // help broken window managers
+ amw->setActiveWindow();
+ }
+ }
+#ifndef TQT_NO_WHATSTHIS
+ } else if ( a == qt_net_wm_context_help ) {
+ TQWhatsThis::enterWhatsThisMode();
+#endif // TQT_NO_WHATSTHIS
+ } else if ( a == qt_net_wm_ping ) {
+ // avoid send/reply loops
+ Window root = TQPaintDevice::x11AppRootWindow( w->x11Screen() );
+ if (event->xclient.window != root) {
+ event->xclient.window = root;
+ XSendEvent( event->xclient.display, event->xclient.window,
+ False, SubstructureNotifyMask|SubstructureRedirectMask, event );
+ }
+ }
+ } else if ( event->xclient.message_type == qt_qt_scrolldone ) {
+ widget->translateScrollDoneEvent(event);
+ } else if ( event->xclient.message_type == qt_xdnd_position ) {
+ qt_handle_xdnd_position( widget, event, passive_only );
+ } else if ( event->xclient.message_type == qt_xdnd_enter ) {
+ qt_handle_xdnd_enter( widget, event, passive_only );
+ } else if ( event->xclient.message_type == qt_xdnd_status ) {
+ qt_handle_xdnd_status( widget, event, passive_only );
+ } else if ( event->xclient.message_type == qt_xdnd_leave ) {
+ qt_handle_xdnd_leave( widget, event, passive_only );
+ } else if ( event->xclient.message_type == qt_xdnd_drop ) {
+ qt_handle_xdnd_drop( widget, event, passive_only );
+ } else if ( event->xclient.message_type == qt_xdnd_finished ) {
+ qt_handle_xdnd_finished( widget, event, passive_only );
+ } else {
+ if ( passive_only ) return 0;
+ // All other are interactions
+ }
+ } else {
+ qt_motifdnd_handle_msg( widget, event, passive_only );
+ }
+
+ return 0;
+}
+
+/*!
+ This function does the core processing of individual X
+ \a{event}s, normally by dispatching TQt events to the right
+ destination.
+
+ It returns 1 if the event was consumed by special handling, 0 if
+ the \a event was consumed by normal handling, and -1 if the \a
+ event was for an unrecognized widget.
+
+ \sa x11EventFilter()
+*/
+int TQApplication::x11ProcessEvent( XEvent* event )
+{
+ switch ( event->type ) {
+ case ButtonPress:
+ ignoreNextMouseReleaseEvent = FALSE;
+ SET_QT_X_USER_TIME(event->xbutton.time);
+ // fallthrough intended
+ case ButtonRelease:
+ SET_QT_X_TIME(event->xbutton.time);
+ break;
+ case MotionNotify:
+ SET_QT_X_TIME(event->xmotion.time);
+ break;
+ case XKeyPress:
+ SET_QT_X_USER_TIME(event->xkey.time);
+ // fallthrough intended
+ case XKeyRelease:
+ SET_QT_X_TIME(event->xkey.time);
+ break;
+ case PropertyNotify:
+ SET_QT_X_TIME(event->xproperty.time);
+ break;
+ case EnterNotify:
+ case LeaveNotify:
+ SET_QT_X_TIME(event->xcrossing.time);
+ break;
+ case SelectionClear:
+ SET_QT_X_TIME(event->xselectionclear.time);
+ break;
+ default:
+ break;
+ }
+
+ TQETWidget *widget = (TQETWidget*)TQWidget::tqfind( (WId)event->xany.window );
+
+ if ( wPRmapper ) { // just did a widget reparent?
+ if ( widget == 0 ) { // not in std widget mapper
+ switch ( event->type ) { // only for mouse/key events
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ case XKeyPress:
+ case XKeyRelease:
+ widget = qPRFindWidget( event->xany.window );
+ break;
+ }
+ }
+ else if ( widget->testWState(WState_Reparented) )
+ qPRCleanup( widget ); // remove from alt mapper
+ }
+
+ TQETWidget *keywidget=0;
+ bool grabbed=FALSE;
+ if ( event->type==XKeyPress || event->type==XKeyRelease ) {
+ keywidget = (TQETWidget*)TQWidget::keyboardGrabber();
+ if ( keywidget ) {
+ grabbed = TRUE;
+ } else {
+ if ( focus_widget )
+ keywidget = (TQETWidget*)focus_widget;
+ if ( !keywidget ) {
+ if ( inPopupMode() ) // no focus widget, see if we have a popup
+ keywidget = (TQETWidget*) activePopupWidget();
+ else if ( widget )
+ keywidget = (TQETWidget*)widget->tqtopLevelWidget();
+ }
+ }
+ }
+
+ int xkey_keycode = event->xkey.keycode;
+ if ( XFilterEvent( event,
+ keywidget ? keywidget->tqtopLevelWidget()->winId() : None ) ) {
+ if ( keywidget )
+ composingKeycode = xkey_keycode; // ### not documented in xlib
+
+#ifndef TQT_NO_XIM
+ if ( event->type != XKeyPress || ! (qt_xim_style & XIMPreeditCallbacks) )
+ return 1;
+
+ /*
+ * The Solaris htt input method will transform a ClientMessage
+ * event into a filtered KeyPress event, in which case our
+ * keywidget is still zero.
+ */
+ if ( ! keywidget ) {
+ keywidget = (TQETWidget*)TQWidget::keyboardGrabber();
+ if ( keywidget ) {
+ grabbed = TRUE;
+ } else {
+ if ( focus_widget )
+ keywidget = (TQETWidget*)focus_widget;
+ if ( !keywidget ) {
+ if ( inPopupMode() ) // no focus widget, see if we have a popup
+ keywidget = (TQETWidget*) activePopupWidget();
+ else if ( widget )
+ keywidget = (TQETWidget*)widget->tqtopLevelWidget();
+ }
+ }
+ }
+
+ /*
+ if the composition string has been emptied, we need to send
+ an IMEnd event. however, we have no way to tell if the user
+ has cancelled input, or if the user has accepted the
+ composition.
+
+ so, we have to look for the next keypress and see if it is
+ the 'commit' key press (keycode == 0). if it is, we deliver
+ an IMEnd event with the final text, otherwise we deliver an
+ IMEnd with empty text (meaning the user has cancelled the
+ input).
+ */
+ TQInputContext *qic =
+ (TQInputContext *) keywidget->tqtopLevelWidget()->topData()->xic;
+ extern bool qt_compose_emptied; // qinputcontext_x11.cpp
+ if ( qic && qic->composing && qic->tqfocusWidget && qt_compose_emptied ) {
+ XEvent event2;
+ bool found = FALSE;
+ if ( XCheckTypedEvent( TQPaintDevice::x11AppDisplay(),
+ XKeyPress, &event2 ) ) {
+ if ( event2.xkey.keycode == 0 ) {
+ // found a key event with the 'commit' string
+ found = TRUE;
+ XPutBackEvent( TQPaintDevice::x11AppDisplay(), &event2 );
+ }
+ }
+
+ if ( !found ) {
+ // no key event, so the user must have cancelled the composition
+ TQIMEvent endevent( TQEvent::IMEnd, TQString::null, -1 );
+ TQApplication::sendEvent( qic->tqfocusWidget, &endevent );
+
+ qic->tqfocusWidget = 0;
+ }
+
+ qt_compose_emptied = FALSE;
+ }
+#endif // TQT_NO_XIM
+
+ return 1;
+ }
+
+ if ( qt_x11EventFilter(event) ) // send through app filter
+ return 1;
+
+ if ( event->type == MappingNotify ) { // keyboard mapping changed
+ XRefreshKeyboardMapping( &event->xmapping );
+ return 0;
+ }
+
+ if ( event->type == PropertyNotify ) { // some properties changed
+ if ( event->xproperty.window == TQPaintDevice::x11AppRootWindow( 0 ) ) {
+ // root properties for the first screen
+ if ( event->xproperty.atom == qt_clipboard_sentinel ) {
+ if (qt_check_clipboard_sentinel() )
+ emit clipboard()->dataChanged();
+ } else if ( event->xproperty.atom == qt_selection_sentinel ) {
+ if (qt_check_selection_sentinel() )
+ emit clipboard()->selectionChanged();
+ } else if ( obey_desktop_settings ) {
+ if ( event->xproperty.atom == qt_resource_manager )
+ qt_set_x11_resources();
+ else if ( event->xproperty.atom == qt_settings_timestamp )
+ TQApplication::x11_apply_settings();
+ }
+ }
+ if ( event->xproperty.window == TQPaintDevice::x11AppRootWindow() ) {
+ // root properties for the default screen
+ if ( event->xproperty.atom == qt_input_encoding ) {
+ qt_set_input_encoding();
+ } else if ( event->xproperty.atom == qt_net_supported ) {
+ qt_get_net_supported();
+ } else if ( event->xproperty.atom == qt_net_virtual_roots ) {
+ qt_get_net_virtual_roots();
+ } else if ( event->xproperty.atom == qt_net_workarea ) {
+ qt_desktopwidget_update_workarea();
+ }
+ } else if ( widget ) {
+ widget->translatePropertyEvent(event);
+ } else {
+ return -1; // don't know this window
+ }
+ return 0;
+ }
+
+ if ( !widget ) { // don't know this windows
+ TQWidget* popup = TQApplication::activePopupWidget();
+ if ( popup ) {
+
+ /*
+ That is more than suboptimal. The real solution should
+ do some keyevent and buttonevent translation, so that
+ the popup still continues to work as the user expects.
+ Unfortunately this translation is currently only
+ possible with a known widget. I'll change that soon
+ (Matthias).
+ */
+
+ // Danger - make sure we don't lock the server
+ switch ( event->type ) {
+ case ButtonPress:
+ case ButtonRelease:
+ case XKeyPress:
+ case XKeyRelease:
+ do {
+ popup->close();
+ } while ( (popup = tqApp->activePopupWidget()) );
+ return 1;
+ }
+ }
+ return -1;
+ }
+
+ if ( event->type == XKeyPress || event->type == XKeyRelease )
+ widget = keywidget; // send XKeyEvents through keywidget->x11Event()
+
+ if ( app_do_modal ) // modal event handling
+ if ( !qt_try_modal(widget, event) ) {
+ if ( event->type == ClientMessage )
+ x11ClientMessage( widget, event, TRUE );
+ return 1;
+ }
+
+
+ if ( widget->x11Event(event) ) // send through widget filter
+ return 1;
+#if defined (TQT_TABLET_SUPPORT)
+ if ( event->type == xinput_motion ||
+ event->type == xinput_button_release ||
+ event->type == xinput_button_press ) {
+ widget->translateXinputEvent( event );
+ return 0;
+ }
+#endif
+
+#ifndef TQT_NO_XRANDR
+ if (event->type == xrandr_eventbase + RRScreenChangeNotify) {
+ // update Xlib internals with the latest screen configuration
+ XRRUpdateConfiguration(event);
+
+ // update the size for desktop widget
+ int scr = XRRRootToScreen( appDpy, event->xany.window );
+ TQWidget *w = desktop()->screen( scr );
+ TQSize oldSize( w->size() );
+ w->crect.setWidth( DisplayWidth( appDpy, scr ) );
+ w->crect.setHeight( DisplayHeight( appDpy, scr ) );
+ if ( w->size() != oldSize ) {
+ TQResizeEvent e( w->size(), oldSize );
+ TQApplication::sendEvent( w, &e );
+ emit desktop()->resized( scr );
+ }
+ }
+#endif // TQT_NO_XRANDR
+
+ switch ( event->type ) {
+
+ case ButtonRelease: // mouse event
+ if ( ignoreNextMouseReleaseEvent ) {
+ ignoreNextMouseReleaseEvent = FALSE;
+ break;
+ }
+ // fall through intended
+ case ButtonPress:
+ if (event->xbutton.root != RootWindow(widget->x11Display(), widget->x11Screen())
+ && ! qt_xdnd_dragging) {
+ while ( activePopupWidget() )
+ activePopupWidget()->close();
+ return 1;
+ }
+ if (event->type == ButtonPress)
+ qt_net_update_user_time(widget->tqtopLevelWidget());
+ // fall through intended
+ case MotionNotify:
+#if defined(TQT_TABLET_SUPPORT)
+ if ( !chokeMouse ) {
+#endif
+ widget->translateMouseEvent( event );
+#if defined(TQT_TABLET_SUPPORT)
+ } else {
+ chokeMouse = FALSE;
+ }
+#endif
+ break;
+
+ case XKeyPress: // keyboard event
+ qt_net_update_user_time(widget->tqtopLevelWidget());
+ // fallthrough intended
+ case XKeyRelease:
+ {
+ if ( keywidget && keywidget->isEnabled() ) { // should always exist
+#ifndef TQT_NO_XIM
+ TQInputContext *qic =
+ (TQInputContext *) keywidget->tqtopLevelWidget()->topData()->xic;
+
+ if ((qt_xim_style & XIMPreeditCallbacks) && event->xkey.keycode == 0 &&
+ qic && qic->composing && qic->tqfocusWidget) {
+ // input method has sent us a commit string
+ TQCString data(513);
+ KeySym sym; // unused
+ Status status; // unused
+ TQString text;
+ int count = qic->lookupString( &(event->xkey), data,
+ &sym, &status );
+ if ( count > 0 )
+ text = input_mapper->toUnicode( data, count );
+
+ // qDebug( "sending IMEnd with %d chars", text.length() );
+ TQIMEvent endevent( TQEvent::IMEnd, text, -1 );
+ TQApplication::sendEvent( qic->tqfocusWidget, &endevent );
+
+ qic->tqfocusWidget = 0;
+ qic->text = TQString::null;
+ } else
+#endif // !TQT_NO_XIM
+ {
+ // qDebug( "sending key event" );
+ keywidget->translateKeyEvent( event, grabbed );
+ }
+ }
+ break;
+ }
+
+ case GraphicsExpose:
+ case Expose: // paint event
+ widget->translatePaintEvent( event );
+ break;
+
+ case ConfigureNotify: // window move/resize event
+ if ( event->xconfigure.event == event->xconfigure.window )
+ widget->translateConfigEvent( event );
+ break;
+
+ case XFocusIn: { // got focus
+ if ( widget->isDesktop() )
+ break;
+ if ( inPopupMode() ) // some delayed focus event to ignore
+ break;
+ if ( !widget->isTopLevel() )
+ break;
+ if ( event->xfocus.detail != NotifyAncestor &&
+ event->xfocus.detail != NotifyInferior &&
+ event->xfocus.detail != NotifyNonlinear )
+ break;
+ widget->createInputContext();
+ setActiveWindow( widget );
+ if ( qt_focus_model == FocusModel_PointerRoot ) {
+ // We got real input focus from somewhere, but we were in PointerRoot
+ // mode, so we don't trust this event. Check the focus model to make
+ // sure we know what focus mode we are using...
+ qt_check_focus_model();
+ }
+ }
+ break;
+
+ case XFocusOut: // lost focus
+ if ( widget->isDesktop() )
+ break;
+ if ( !widget->isTopLevel() )
+ break;
+ if ( event->xfocus.mode == NotifyGrab )
+ qt_xfocusout_grab_counter++;
+ if ( event->xfocus.mode != NotifyNormal )
+ break;
+ if ( event->xfocus.detail != NotifyAncestor &&
+ event->xfocus.detail != NotifyNonlinearVirtual &&
+ event->xfocus.detail != NotifyNonlinear )
+ break;
+ if ( !inPopupMode() && widget == active_window )
+ setActiveWindow( 0 );
+ break;
+
+ case EnterNotify: { // enter window
+ if ( TQWidget::mouseGrabber() && widget != TQWidget::mouseGrabber() )
+ break;
+ if ( inPopupMode() && widget->tqtopLevelWidget() != activePopupWidget() )
+ break;
+ if ( event->xcrossing.mode != NotifyNormal ||
+ event->xcrossing.detail == NotifyVirtual ||
+ event->xcrossing.detail == NotifyNonlinearVirtual )
+ break;
+ if ( event->xcrossing.focus &&
+ !widget->isDesktop() && !widget->isActiveWindow() ) {
+ if ( qt_focus_model == FocusModel_Unknown ) // check focus model
+ qt_check_focus_model();
+ if ( qt_focus_model == FocusModel_PointerRoot ) // PointerRoot mode
+ setActiveWindow( widget );
+ }
+ qt_dispatchEnterLeave( widget, TQWidget::tqfind( curWin ) );
+ curWin = widget->winId();
+ widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it
+ }
+ break;
+
+ case LeaveNotify: { // leave window
+ if ( TQWidget::mouseGrabber() && widget != TQWidget::mouseGrabber() )
+ break;
+ if ( curWin && widget->winId() != curWin )
+ break;
+ if ( event->xcrossing.mode != NotifyNormal )
+ break;
+ if ( !widget->isDesktop() )
+ widget->translateMouseEvent( event ); //we don't get MotionNotify, emulate it
+
+ TQWidget* enter = 0;
+ XEvent ev;
+ while ( XCheckMaskEvent( widget->x11Display(), EnterWindowMask | LeaveWindowMask , &ev )
+ && !qt_x11EventFilter( &ev )) {
+ TQWidget* event_widget = TQWidget::tqfind( ev.xcrossing.window );
+ if( event_widget && event_widget->x11Event( &ev ) )
+ break;
+ if ( ev.type == LeaveNotify && ev.xcrossing.mode == NotifyNormal ){
+ enter = event_widget;
+ XPutBackEvent( widget->x11Display(), &ev );
+ break;
+ }
+ if ( ev.xcrossing.mode != NotifyNormal ||
+ ev.xcrossing.detail == NotifyVirtual ||
+ ev.xcrossing.detail == NotifyNonlinearVirtual )
+ continue;
+ enter = event_widget;
+ if ( ev.xcrossing.focus &&
+ enter && !enter->isDesktop() && !enter->isActiveWindow() ) {
+ if ( qt_focus_model == FocusModel_Unknown ) // check focus model
+ qt_check_focus_model();
+ if ( qt_focus_model == FocusModel_PointerRoot ) // PointerRoot mode
+ setActiveWindow( enter );
+ }
+ break;
+ }
+
+ if ( ( ! enter || enter->isDesktop() ) &&
+ event->xcrossing.focus && widget == active_window &&
+ qt_focus_model == FocusModel_PointerRoot // PointerRoot mode
+ ) {
+ setActiveWindow( 0 );
+ }
+
+ if ( !curWin )
+ qt_dispatchEnterLeave( widget, 0 );
+
+ qt_dispatchEnterLeave( enter, widget );
+ curWin = enter ? enter->winId() : 0;
+ }
+ break;
+
+ case UnmapNotify: // window hidden
+ if ( widget->isTopLevel() && widget->isShown() ) {
+ widget->topData()->spont_unmapped = 1;
+ TQHideEvent e;
+ TQApplication::sendSpontaneousEvent( widget, &e );
+ widget->hideChildren( TRUE );
+ }
+ break;
+
+ case MapNotify: // window shown
+ if ( widget->isTopLevel() &&
+ widget->topData()->spont_unmapped ) {
+ widget->topData()->spont_unmapped = 0;
+ widget->showChildren( TRUE );
+ TQShowEvent e;
+ TQApplication::sendSpontaneousEvent( widget, &e );
+ }
+ break;
+
+ case ClientMessage: // client message
+ return x11ClientMessage(widget,event,False);
+
+ case ReparentNotify: // window manager reparents
+ while ( XCheckTypedWindowEvent( widget->x11Display(),
+ widget->winId(),
+ ReparentNotify,
+ event ) )
+ ; // skip old reparent events
+ if ( event->xreparent.tqparent == TQPaintDevice::x11AppRootWindow() ) {
+ if ( widget->isTopLevel() ) {
+ widget->topData()->parentWinId = event->xreparent.tqparent;
+ if ( qt_deferred_map_tqcontains( widget ) ) {
+ qt_deferred_map_take( widget );
+ XMapWindow( appDpy, widget->winId() );
+ }
+ }
+ } else
+ // store the tqparent. Useful for many things, embedding for instance.
+ widget->topData()->parentWinId = event->xreparent.tqparent;
+ if ( widget->isTopLevel() ) {
+ // the widget frame strut should also be invalidated
+ widget->topData()->fleft = widget->topData()->fright =
+ widget->topData()->ftop = widget->topData()->fbottom = 0;
+
+ if ( qt_focus_model != FocusModel_Unknown ) {
+ // toplevel reparented...
+ TQWidget *newtqparent = TQWidget::tqfind( event->xreparent.tqparent );
+ if ( ! newtqparent || newtqparent->isDesktop() ) {
+ // we dont' know about the new tqparent (or we've been
+ // reparented to root), perhaps a window manager
+ // has been (re)started? reset the focus model to unknown
+ qt_focus_model = FocusModel_Unknown;
+ }
+ }
+ }
+ break;
+
+ case SelectionRequest: {
+ XSelectionRequestEvent *req = &event->xselectionrequest;
+ if (! req)
+ break;
+
+ if ( qt_xdnd_selection && req->selection == qt_xdnd_selection ) {
+ qt_xdnd_handle_selection_request( req );
+
+ } else if (qt_clipboard) {
+ TQCustomEvent e( TQEvent::Clipboard, event );
+ TQApplication::sendSpontaneousEvent( qt_clipboard, &e );
+ }
+ break;
+ }
+ case SelectionClear: {
+ XSelectionClearEvent *req = &event->xselectionclear;
+ // don't deliver dnd events to the clipboard, it gets confused
+ if (! req || qt_xdnd_selection && req->selection == qt_xdnd_selection)
+ break;
+
+ if (qt_clipboard) {
+ TQCustomEvent e( TQEvent::Clipboard, event );
+ TQApplication::sendSpontaneousEvent( qt_clipboard, &e );
+ }
+ break;
+ }
+
+ case SelectionNotify: {
+ XSelectionEvent *req = &event->xselection;
+ // don't deliver dnd events to the clipboard, it gets confused
+ if (! req || qt_xdnd_selection && req->selection == qt_xdnd_selection)
+ break;
+
+ if (qt_clipboard) {
+ TQCustomEvent e( TQEvent::Clipboard, event );
+ TQApplication::sendSpontaneousEvent( qt_clipboard, &e );
+ }
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+/*!
+ This virtual function is only implemented under X11.
+
+ If you create an application that inherits TQApplication and
+ reimplement this function, you get direct access to all X events
+ that the are received from the X server.
+
+ Return TRUE if you want to stop the event from being processed.
+ Return FALSE for normal event dispatching.
+
+ \sa x11ProcessEvent()
+*/
+
+bool TQApplication::x11EventFilter( XEvent * )
+{
+ return FALSE;
+}
+
+
+
+/*****************************************************************************
+ Modal widgets; Since Xlib has little support for this we roll our own
+ modal widget mechanism.
+ A modal widget without a tqparent becomes application-modal.
+ A modal widget with a tqparent becomes modal to its tqparent and grandparents..
+
+ qt_enter_modal()
+ Enters modal state
+ Arguments:
+ TQWidget *widget A modal widget
+
+ qt_leave_modal()
+ Leaves modal state for a widget
+ Arguments:
+ TQWidget *widget A modal widget
+ *****************************************************************************/
+
+bool qt_modal_state()
+{
+ return app_do_modal;
+}
+
+void qt_enter_modal( TQWidget *widget )
+{
+ if ( !qt_modal_stack ) { // create modal stack
+ qt_modal_stack = new TQWidgetList;
+ TQ_CHECK_PTR( qt_modal_stack );
+ }
+ if (widget->parentWidget()) {
+ TQEvent e(TQEvent::WindowBlocked);
+ TQApplication::sendEvent(widget->parentWidget(), &e);
+ }
+
+ qt_dispatchEnterLeave( 0, TQWidget::tqfind((WId)curWin) );
+ qt_modal_stack->insert( 0, widget );
+ app_do_modal = TRUE;
+ curWin = 0;
+ ignoreNextMouseReleaseEvent = FALSE;
+}
+
+
+void qt_leave_modal( TQWidget *widget )
+{
+ if ( qt_modal_stack && qt_modal_stack->removeRef(widget) ) {
+ if ( qt_modal_stack->isEmpty() ) {
+ delete qt_modal_stack;
+ qt_modal_stack = 0;
+ TQPoint p( TQCursor::pos() );
+ TQWidget* w = TQApplication::widgetAt( p.x(), p.y(), TRUE );
+ qt_dispatchEnterLeave( w, TQWidget::tqfind( curWin ) ); // send synthetic enter event
+ curWin = w? w->winId() : 0;
+ }
+ }
+ app_do_modal = qt_modal_stack != 0;
+ ignoreNextMouseReleaseEvent = TRUE;
+
+ if (widget->parentWidget()) {
+ TQEvent e(TQEvent::WindowUnblocked);
+ TQApplication::sendEvent(widget->parentWidget(), &e);
+ }
+}
+
+
+bool qt_try_modal( TQWidget *widget, XEvent *event )
+{
+ if (qt_xdnd_dragging) {
+ // allow mouse events while DnD is active
+ switch (event->type) {
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ return TRUE;
+ default:
+ break;
+ }
+ }
+
+ if ( qt_tryModalHelper( widget ) )
+ return TRUE;
+
+ bool block_event = FALSE;
+ switch ( event->type ) {
+ case ButtonPress: // disallow mouse/key events
+ case ButtonRelease:
+ case MotionNotify:
+ case XKeyPress:
+ case XKeyRelease:
+ case EnterNotify:
+ case LeaveNotify:
+ case ClientMessage:
+ block_event = TRUE;
+ break;
+ default:
+ break;
+ }
+
+ return !block_event;
+}
+
+
+/*****************************************************************************
+ Popup widget mechanism
+
+ openPopup()
+ Adds a widget to the list of popup widgets
+ Arguments:
+ TQWidget *widget The popup widget to be added
+
+ closePopup()
+ Removes a widget from the list of popup widgets
+ Arguments:
+ TQWidget *widget The popup widget to be removed
+ *****************************************************************************/
+
+
+static int openPopupCount = 0;
+void TQApplication::openPopup( TQWidget *popup )
+{
+ openPopupCount++;
+ if ( !popupWidgets ) { // create list
+ popupWidgets = new TQWidgetList;
+ TQ_CHECK_PTR( popupWidgets );
+ }
+ popupWidgets->append( popup ); // add to end of list
+
+ if ( popupWidgets->count() == 1 && !qt_nograb() ){ // grab mouse/keyboard
+ int r = XGrabKeyboard( popup->x11Display(), popup->winId(), FALSE,
+ GrabModeSync, GrabModeAsync, CurrentTime );
+ if ( (popupGrabOk = (r == GrabSuccess)) ) {
+ r = XGrabPointer( popup->x11Display(), popup->winId(), TRUE,
+ (uint)(ButtonPressMask | ButtonReleaseMask |
+ ButtonMotionMask | EnterWindowMask |
+ LeaveWindowMask | PointerMotionMask),
+ GrabModeSync, GrabModeAsync,
+ None, None, CurrentTime );
+
+ if ( (popupGrabOk = (r == GrabSuccess)) )
+ XAllowEvents( popup->x11Display(), SyncPointer, CurrentTime );
+ else
+ XUngrabKeyboard( popup->x11Display(), CurrentTime );
+ }
+ } else if ( popupGrabOk ) {
+ XAllowEvents( popup->x11Display(), SyncPointer, CurrentTime );
+ }
+
+ // popups are not focus-handled by the window system (the first
+ // popup grabbed the keyboard), so we have to do that manually: A
+ // new popup gets the focus
+ TQFocusEvent::setReason( TQFocusEvent::Popup );
+ if ( popup->tqfocusWidget())
+ popup->tqfocusWidget()->setFocus();
+ else
+ popup->setFocus();
+ TQFocusEvent::resetReason();
+}
+
+void TQApplication::closePopup( TQWidget *popup )
+{
+ if ( !popupWidgets )
+ return;
+ popupWidgets->removeRef( popup );
+ if (popup == popupOfPopupButtonFocus) {
+ popupButtonFocus = 0;
+ popupOfPopupButtonFocus = 0;
+ }
+ if ( popupWidgets->count() == 0 ) { // this was the last popup
+ popupCloseDownMode = TRUE; // control mouse events
+ delete popupWidgets;
+ popupWidgets = 0;
+ if ( !qt_nograb() && popupGrabOk ) { // grabbing not disabled
+ if ( mouseButtonState != 0
+ || popup->tqgeometry(). tqcontains(TQPoint(mouseGlobalXPos, mouseGlobalYPos) ) )
+ { // mouse release event or inside
+ XAllowEvents( popup->x11Display(), AsyncPointer,
+ CurrentTime );
+ } else { // mouse press event
+ mouseButtonPressTime -= 10000; // avoid double click
+ XAllowEvents( popup->x11Display(), ReplayPointer,CurrentTime );
+ }
+ XUngrabPointer( popup->x11Display(), CurrentTime );
+ XFlush( popup->x11Display() );
+ }
+ if ( active_window ) {
+ TQFocusEvent::setReason( TQFocusEvent::Popup );
+ if ( active_window->tqfocusWidget() )
+ active_window->tqfocusWidget()->setFocus();
+ else
+ active_window->setFocus();
+ TQFocusEvent::resetReason();
+ }
+ } else {
+ // popups are not focus-handled by the window system (the
+ // first popup grabbed the keyboard), so we have to do that
+ // manually: A popup was closed, so the previous popup gets
+ // the focus.
+ TQFocusEvent::setReason( TQFocusEvent::Popup );
+ TQWidget* aw = popupWidgets->getLast();
+ if (aw->tqfocusWidget())
+ aw->tqfocusWidget()->setFocus();
+ else
+ aw->setFocus();
+ TQFocusEvent::resetReason();
+ if ( popupWidgets->count() == 1 && !qt_nograb() ){ // grab mouse/keyboard
+ int r = XGrabKeyboard( aw->x11Display(), aw->winId(), FALSE,
+ GrabModeSync, GrabModeAsync, CurrentTime );
+ if ( (popupGrabOk = (r == GrabSuccess)) ) {
+ r = XGrabPointer( aw->x11Display(), aw->winId(), TRUE,
+ (uint)(ButtonPressMask | ButtonReleaseMask |
+ ButtonMotionMask | EnterWindowMask |
+ LeaveWindowMask | PointerMotionMask),
+ GrabModeSync, GrabModeAsync,
+ None, None, CurrentTime );
+
+ if ( (popupGrabOk = (r == GrabSuccess)) )
+ XAllowEvents( aw->x11Display(), SyncPointer, CurrentTime );
+ }
+ }
+ }
+}
+
+/*****************************************************************************
+ Event translation; translates X11 events to TQt events
+ *****************************************************************************/
+
+//
+// Mouse event translation
+//
+// Xlib doesn't give mouse double click events, so we generate them by
+// comparing window, time and position between two mouse press events.
+//
+
+//
+// Keyboard event translation
+//
+
+static int translateButtonState( int s )
+{
+ int bst = 0;
+ if ( s & Button1Mask )
+ bst |= TQt::LeftButton;
+ if ( s & Button2Mask )
+ bst |= TQt::MidButton;
+ if ( s & Button3Mask )
+ bst |= TQt::RightButton;
+ if ( s & ShiftMask )
+ bst |= TQt::ShiftButton;
+ if ( s & ControlMask )
+ bst |= TQt::ControlButton;
+ if ( s & qt_alt_mask )
+ bst |= TQt::AltButton;
+ if ( s & qt_meta_mask )
+ bst |= TQt::MetaButton;
+ return bst;
+}
+
+bool TQETWidget::translateMouseEvent( const XEvent *event )
+{
+ static bool manualGrab = FALSE;
+ TQEvent::Type type; // event parameters
+ TQPoint pos;
+ TQPoint globalPos;
+ int button = 0;
+ int state;
+ XEvent nextEvent;
+
+ if ( sm_blockUserInput ) // block user interaction during session management
+ return TRUE;
+
+ static int x_root_save = -1, y_root_save = -1;
+
+ if ( event->type == MotionNotify ) { // mouse move
+ if (event->xmotion.root != RootWindow(appDpy, x11Screen()) &&
+ ! qt_xdnd_dragging )
+ return FALSE;
+
+ XMotionEvent lastMotion = event->xmotion;
+ while( XPending( appDpy ) ) { // compres mouse moves
+ XNextEvent( appDpy, &nextEvent );
+ if ( nextEvent.type == ConfigureNotify
+ || nextEvent.type == PropertyNotify
+ || nextEvent.type == Expose
+ || nextEvent.type == NoExpose ) {
+ tqApp->x11ProcessEvent( &nextEvent );
+ continue;
+ } else if ( nextEvent.type != MotionNotify ||
+ nextEvent.xmotion.window != event->xmotion.window ||
+ nextEvent.xmotion.state != event->xmotion.state ) {
+ XPutBackEvent( appDpy, &nextEvent );
+ break;
+ }
+ if ( !qt_x11EventFilter(&nextEvent)
+ && !x11Event( &nextEvent ) ) // send event through filter
+ lastMotion = nextEvent.xmotion;
+ else
+ break;
+ }
+ type = TQEvent::MouseMove;
+ pos.rx() = lastMotion.x;
+ pos.ry() = lastMotion.y;
+ globalPos.rx() = lastMotion.x_root;
+ globalPos.ry() = lastMotion.y_root;
+ state = translateButtonState( lastMotion.state );
+ if ( qt_button_down && (state & (LeftButton |
+ MidButton |
+ RightButton ) ) == 0 )
+ qt_button_down = 0;
+
+ // throw away mouse move events that are sent multiple times to the same
+ // position
+ bool throw_away = FALSE;
+ if ( x_root_save == globalPos.x() &&
+ y_root_save == globalPos.y() )
+ throw_away = TRUE;
+ x_root_save = globalPos.x();
+ y_root_save = globalPos.y();
+ if ( throw_away )
+ return TRUE;
+ } else if ( event->type == EnterNotify || event->type == LeaveNotify) {
+ XEvent *xevent = (XEvent *)event;
+ //unsigned int xstate = event->xcrossing.state;
+ type = TQEvent::MouseMove;
+ pos.rx() = xevent->xcrossing.x;
+ pos.ry() = xevent->xcrossing.y;
+ globalPos.rx() = xevent->xcrossing.x_root;
+ globalPos.ry() = xevent->xcrossing.y_root;
+ state = translateButtonState( xevent->xcrossing.state );
+ if ( qt_button_down && (state & (LeftButton |
+ MidButton |
+ RightButton ) ) == 0 )
+ qt_button_down = 0;
+ if ( !qt_button_down )
+ state = state & ~(LeftButton | MidButton | RightButton );
+ } else { // button press or release
+ pos.rx() = event->xbutton.x;
+ pos.ry() = event->xbutton.y;
+ globalPos.rx() = event->xbutton.x_root;
+ globalPos.ry() = event->xbutton.y_root;
+ state = translateButtonState( event->xbutton.state );
+ switch ( event->xbutton.button ) {
+ case Button1: button = LeftButton; break;
+ case Button2: button = MidButton; break;
+ case Button3: button = RightButton; break;
+ case Button4:
+ case Button5:
+ case 6:
+ case 7:
+ // the fancy mouse wheel.
+
+ // take care about grabbing. We do this here since it
+ // is clear that we return anyway
+ if ( tqApp->inPopupMode() && popupGrabOk )
+ XAllowEvents( x11Display(), SyncPointer, CurrentTime );
+
+ // We are only interested in ButtonPress.
+ if (event->type == ButtonPress ){
+
+ // compress wheel events (the X Server will simply
+ // send a button press for each single notch,
+ // regardless whether the application can catch up
+ // or not)
+ int delta = 1;
+ XEvent xevent;
+ while ( XCheckTypedWindowEvent(x11Display(),winId(),
+ ButtonPress,&xevent) ){
+ if (xevent.xbutton.button != event->xbutton.button){
+ XPutBackEvent(x11Display(), &xevent);
+ break;
+ }
+ delta++;
+ }
+
+ // the delta is defined as multiples of
+ // WHEEL_DELTA, which is set to 120. Future wheels
+ // may offer a finer-resolution. A positive delta
+ // indicates forward rotation, a negative one
+ // backward rotation respectively.
+ int btn = event->xbutton.button;
+ delta *= 120 * ( (btn == Button4 || btn == 6) ? 1 : -1 );
+ bool hor = ( (btn == Button4 || btn == Button5) && (state&AltButton) ||
+ (btn == 6 || btn == 7) );
+ translateWheelEvent( globalPos.x(), globalPos.y(), delta, state, (hor)?Horizontal:Vertical );
+ }
+ return TRUE;
+ }
+ if ( event->type == ButtonPress ) { // mouse button pressed
+#if defined(TQ_OS_IRIX) && defined(TQT_TABLET_SUPPORT)
+ XEvent myEv;
+ if ( XCheckTypedEvent( appDpy, xinput_button_press, &myEv ) ) {
+ if ( translateXinputEvent( &myEv ) ) {
+ //Spontaneous event sent. Check if we need to continue.
+ if ( chokeMouse ) {
+ chokeMouse = FALSE;
+ return FALSE;
+ }
+ }
+ }
+#endif
+ qt_button_down = tqchildAt( pos ); //magic for masked widgets
+ if ( !qt_button_down || !qt_button_down->testWFlags(WMouseNoMask) )
+ qt_button_down = this;
+ if ( mouseActWindow == event->xbutton.window &&
+ mouseButtonPressed == button &&
+ (long)event->xbutton.time -(long)mouseButtonPressTime
+ < TQApplication::doubleClickInterval() &&
+ TQABS(event->xbutton.x - mouseXPos) < 5 &&
+ TQABS(event->xbutton.y - mouseYPos) < 5 ) {
+ type = TQEvent::MouseButtonDblClick;
+ mouseButtonPressTime -= 2000; // no double-click next time
+ } else {
+ type = TQEvent::MouseButtonPress;
+ mouseButtonPressTime = event->xbutton.time;
+ }
+ mouseButtonPressed = button; // save event params for
+ mouseXPos = pos.x(); // future double click tests
+ mouseYPos = pos.y();
+ mouseGlobalXPos = globalPos.x();
+ mouseGlobalYPos = globalPos.y();
+ } else { // mouse button released
+#if defined(TQ_OS_IRIX) && defined(TQT_TABLET_SUPPORT)
+ XEvent myEv;
+ if ( XCheckTypedEvent( appDpy, xinput_button_release, &myEv ) ) {
+ if ( translateXinputEvent( &myEv ) ) {
+ //Spontaneous event sent. Check if we need to continue.
+ if ( chokeMouse ) {
+ chokeMouse = FALSE;
+ return FALSE;
+ }
+ }
+ }
+#endif
+ if ( manualGrab ) { // release manual grab
+ manualGrab = FALSE;
+ XUngrabPointer( x11Display(), CurrentTime );
+ XFlush( x11Display() );
+ }
+
+ type = TQEvent::MouseButtonRelease;
+ }
+ }
+ mouseActWindow = winId(); // save some event params
+ mouseButtonState = state;
+ if ( type == 0 ) // don't send event
+ return FALSE;
+
+ if ( tqApp->inPopupMode() ) { // in popup mode
+ TQWidget *popup = tqApp->activePopupWidget();
+ if ( popup != this ) {
+ if ( testWFlags(WType_Popup) && rect().tqcontains(pos) )
+ popup = this;
+ else // send to last popup
+ pos = popup->mapFromGlobal( globalPos );
+ }
+ bool releaseAfter = FALSE;
+ TQWidget *popupChild = popup->tqchildAt( pos );
+ TQWidget *popupTarget = popupChild ? popupChild : popup;
+
+ if (popup != popupOfPopupButtonFocus){
+ popupButtonFocus = 0;
+ popupOfPopupButtonFocus = 0;
+ }
+
+ if ( !popupTarget->isEnabled() ) {
+ if ( popupGrabOk )
+ XAllowEvents( x11Display(), SyncPointer, CurrentTime );
+ }
+
+ switch ( type ) {
+ case TQEvent::MouseButtonPress:
+ case TQEvent::MouseButtonDblClick:
+ popupButtonFocus = popupChild;
+ popupOfPopupButtonFocus = popup;
+ break;
+ case TQEvent::MouseButtonRelease:
+ releaseAfter = TRUE;
+ break;
+ default:
+ break; // nothing for mouse move
+ }
+
+ Display* dpy = x11Display(); // store display, send() may destroy us
+
+
+ int oldOpenPopupCount = openPopupCount;
+
+ if ( popupButtonFocus ) {
+ TQMouseEvent e( type, popupButtonFocus->mapFromGlobal(globalPos),
+ globalPos, button, state );
+ TQApplication::sendSpontaneousEvent( popupButtonFocus, &e );
+ if ( releaseAfter ) {
+ popupButtonFocus = 0;
+ popupOfPopupButtonFocus = 0;
+ }
+ } else if ( popupChild ) {
+ TQMouseEvent e( type, popupChild->mapFromGlobal(globalPos),
+ globalPos, button, state );
+ TQApplication::sendSpontaneousEvent( popupChild, &e );
+ } else {
+ TQMouseEvent e( type, pos, globalPos, button, state );
+ TQApplication::sendSpontaneousEvent( popup, &e );
+ }
+
+ if ( type == TQEvent::MouseButtonPress && button == RightButton && ( openPopupCount == oldOpenPopupCount ) ) {
+ TQWidget *popupEvent = popup;
+ if(popupButtonFocus)
+ popupEvent = popupButtonFocus;
+ else if(popupChild)
+ popupEvent = popupChild;
+ TQContextMenuEvent e( TQContextMenuEvent::Mouse, pos, globalPos, state );
+ TQApplication::sendSpontaneousEvent( popupEvent, &e );
+ }
+
+ if ( releaseAfter )
+ qt_button_down = 0;
+
+ if ( tqApp->inPopupMode() ) { // still in popup mode
+ if ( popupGrabOk )
+ XAllowEvents( dpy, SyncPointer, CurrentTime );
+ } else {
+ if ( type != TQEvent::MouseButtonRelease && state != 0 &&
+ TQWidget::tqfind((WId)mouseActWindow) ) {
+ manualGrab = TRUE; // need to manually grab
+ XGrabPointer( dpy, mouseActWindow, False,
+ (uint)(ButtonPressMask | ButtonReleaseMask |
+ ButtonMotionMask |
+ EnterWindowMask | LeaveWindowMask),
+ GrabModeAsync, GrabModeAsync,
+ None, None, CurrentTime );
+ }
+ }
+
+ } else {
+ TQWidget *widget = this;
+ TQWidget *w = TQWidget::mouseGrabber();
+ if ( !w )
+ w = qt_button_down;
+ if ( w && w != this ) {
+ widget = w;
+ pos = w->mapFromGlobal( globalPos );
+ }
+
+ if ( popupCloseDownMode ) {
+ popupCloseDownMode = FALSE;
+ if ( testWFlags(WType_Popup) ) // ignore replayed event
+ return TRUE;
+ }
+
+ if ( type == TQEvent::MouseButtonRelease &&
+ (state & (~button) & ( LeftButton |
+ MidButton |
+ RightButton)) == 0 ) {
+ qt_button_down = 0;
+ }
+
+ int oldOpenPopupCount = openPopupCount;
+
+ TQMouseEvent e( type, pos, globalPos, button, state );
+ TQApplication::sendSpontaneousEvent( widget, &e );
+
+ if ( type == TQEvent::MouseButtonPress && button == RightButton && ( openPopupCount == oldOpenPopupCount ) ) {
+ TQContextMenuEvent e( TQContextMenuEvent::Mouse, pos, globalPos, state );
+ TQApplication::sendSpontaneousEvent( widget, &e );
+ }
+ }
+ return TRUE;
+}
+
+
+//
+// Wheel event translation
+//
+bool TQETWidget::translateWheelEvent( int global_x, int global_y, int delta, int state, Orientation orient )
+{
+ // send the event to the widget or its ancestors
+ {
+ TQWidget* popup = tqApp->activePopupWidget();
+ if ( popup && tqtopLevelWidget() != popup )
+ popup->close();
+ TQWheelEvent e( mapFromGlobal(TQPoint( global_x, global_y)),
+ TQPoint(global_x, global_y), delta, state, orient );
+ if ( TQApplication::sendSpontaneousEvent( this, &e ) )
+ return TRUE;
+ }
+
+ // send the event to the widget that has the focus or its ancestors, if different
+ TQWidget *w = this;
+ if ( w != tqApp->tqfocusWidget() && ( w = tqApp->tqfocusWidget() ) ) {
+ TQWidget* popup = tqApp->activePopupWidget();
+ if ( popup && w != popup )
+ popup->hide();
+ TQWheelEvent e( mapFromGlobal(TQPoint( global_x, global_y)),
+ TQPoint(global_x, global_y), delta, state, orient );
+ if ( TQApplication::sendSpontaneousEvent( w, &e ) )
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+//
+// XInput Translation Event
+//
+#if defined (TQT_TABLET_SUPPORT)
+bool TQETWidget::translateXinputEvent( const XEvent *ev )
+{
+#if defined (TQ_OS_IRIX)
+ // Wacom has put defines in their wacom.h file so it would be quite wise
+ // to use them, need to think of a decent way of not using
+ // it when it doesn't exist...
+ XDeviceState *s;
+ XInputClass *iClass;
+ XValuatorState *vs;
+ int j;
+#endif
+ TQWidget *w = this;
+ TQPoint global,
+ curr;
+ static int pressure = 0;
+ static int xTilt = 0,
+ yTilt = 0;
+ int tqdeviceType = TQTabletEvent::NoDevice;
+ TQPair<int, int> tId;
+ XEvent xinputMotionEvent;
+ XEvent mouseMotionEvent;
+ XDevice *dev;
+ const XDeviceMotionEvent *motion = 0;
+ XDeviceButtonEvent *button = 0;
+ TQEvent::Type t;
+
+ if ( ev->type == xinput_motion ) {
+ motion = (const XDeviceMotionEvent*)ev;
+ for (;;) {
+ if (!XCheckTypedWindowEvent(x11Display(), winId(), MotionNotify, &mouseMotionEvent))
+ break;
+ if (!XCheckTypedWindowEvent(x11Display(), winId(), xinput_motion, &xinputMotionEvent)) {
+ XPutBackEvent(x11Display(), &mouseMotionEvent);
+ break;
+ }
+ if (mouseMotionEvent.xmotion.time != motion->time) {
+ XPutBackEvent(x11Display(), &mouseMotionEvent);
+ XPutBackEvent(x11Display(), &xinputMotionEvent);
+ break;
+ }
+ motion = ((const XDeviceMotionEvent*)&xinputMotionEvent);
+ }
+ t = TQEvent::TabletMove;
+ curr = TQPoint( motion->x, motion->y );
+ } else {
+ if ( ev->type == xinput_button_press ) {
+ t = TQEvent::TabletPress;
+ } else {
+ t = TQEvent::TabletRelease;
+ }
+ button = (XDeviceButtonEvent*)ev;
+/*
+ qDebug( "\n\nXInput Button Event" );
+ qDebug( "serial:\t%d", button->serial );
+ qDebug( "send_event:\t%d", button->send_event );
+ qDebug( "display:\t%p", button->display );
+ qDebug( "window:\t%d", button->window );
+ qDebug( "tqdeviceID:\t%d", button->tqdeviceid );
+ qDebug( "root:\t%d", button->root );
+ qDebug( "subwindot:\t%d", button->subwindow );
+ qDebug( "x:\t%d", button->x );
+ qDebug( "y:\t%d", button->y );
+ qDebug( "x_root:\t%d", button->x_root );
+ qDebug( "y_root:\t%d", button->y_root );
+ qDebug( "state:\t%d", button->state );
+ qDebug( "button:\t%d", button->button );
+ qDebug( "same_screen:\t%d", button->same_screen );
+ qDebug( "time:\t%d", button->time );
+*/
+ curr = TQPoint( button->x, button->y );
+ }
+#if defined(TQ_OS_IRIX)
+ // default...
+ dev = devStylus;
+#else
+ if ( ev->type == xinput_motion ) {
+ if ( motion->tqdeviceid == devStylus->tqdevice_id ) {
+ dev = devStylus;
+ tqdeviceType = TQTabletEvent::Stylus;
+ } else if ( motion->tqdeviceid == devEraser->tqdevice_id ) {
+ dev = devEraser;
+ tqdeviceType = TQTabletEvent::Eraser;
+ }
+ } else {
+ if ( button->tqdeviceid == devStylus->tqdevice_id ) {
+ dev = devStylus;
+ tqdeviceType = TQTabletEvent::Stylus;
+ } else if ( button->tqdeviceid == devEraser->tqdevice_id ) {
+ dev = devEraser;
+ tqdeviceType = TQTabletEvent::Eraser;
+ }
+ }
+#endif
+
+ const int PRESSURE_LEVELS = 255;
+ // we got the maximum pressure at start time, since various tablets have
+ // varying levels of distinguishing pressure changes, let's standardize and
+ // scale everything to 256 different levels...
+ static int scaleFactor = -1;
+ if ( scaleFactor == -1 ) {
+ if ( max_pressure > PRESSURE_LEVELS )
+ scaleFactor = max_pressure / PRESSURE_LEVELS;
+ else
+ scaleFactor = PRESSURE_LEVELS / max_pressure;
+ }
+#if defined (TQ_OS_IRIX)
+ s = XQueryDeviceState( appDpy, dev );
+ if ( s == NULL )
+ return FALSE;
+ iClass = s->data;
+ for ( j = 0; j < s->num_classes; j++ ) {
+ if ( iClass->c_class == ValuatorClass ) {
+ vs = (XValuatorState *)iClass;
+ // figure out what tqdevice we have, based on bitmasking...
+ if ( vs->valuators[WAC_TRANSDUCER_I]
+ & WAC_TRANSDUCER_PROX_MSK ) {
+ switch ( vs->valuators[WAC_TRANSDUCER_I]
+ & WAC_TRANSDUCER_MSK ) {
+ case WAC_PUCK_ID:
+ tqdeviceType = TQTabletEvent::Puck;
+ break;
+ case WAC_STYLUS_ID:
+ tqdeviceType = TQTabletEvent::Stylus;
+ break;
+ case WAC_ERASER_ID:
+ tqdeviceType = TQTabletEvent::Eraser;
+ break;
+ }
+ // Get a Unique Id for the tqdevice, Wacom gives us this ability
+ tId.first = vs->valuators[WAC_TRANSDUCER_I] & WAC_TRANSDUCER_ID_MSK;
+ tId.second = vs->valuators[WAC_SERIAL_NUM_I];
+ } else
+ tqdeviceType = TQTabletEvent::NoDevice;
+ // apparently Wacom needs a cast for the +/- values to make sense
+ xTilt = short(vs->valuators[WAC_XTILT_I]);
+ yTilt = short(vs->valuators[WAC_YTILT_I]);
+ if ( max_pressure > PRESSURE_LEVELS )
+ pressure = vs->valuators[WAC_PRESSURE_I] / scaleFactor;
+ else
+ pressure = vs->valuators[WAC_PRESSURE_I] * scaleFactor;
+ global = TQPoint( vs->valuators[WAC_XCOORD_I],
+ vs->valuators[WAC_YCOORD_I] );
+ break;
+ }
+ iClass = (XInputClass*)((char*)iClass + iClass->length);
+ }
+ XFreeDeviceState( s );
+#else
+ if ( motion ) {
+ xTilt = short(motion->axis_data[3]);
+ yTilt = short(motion->axis_data[4]);
+ if ( max_pressure > PRESSURE_LEVELS )
+ pressure = motion->axis_data[2] / scaleFactor;
+ else
+ pressure = motion->axis_data[2] * scaleFactor;
+ global = TQPoint( motion->axis_data[0], motion->axis_data[1] );
+ } else {
+ xTilt = short(button->axis_data[3]);
+ yTilt = short(button->axis_data[4]);
+ if ( max_pressure > PRESSURE_LEVELS )
+ pressure = button->axis_data[2] / scaleFactor;
+ else
+ pressure = button->axis_data[2] * scaleFactor;
+ global = TQPoint( button->axis_data[0], button->axis_data[1] );
+ }
+ // The only way to get these Ids is to scan the XFree86 log, which I'm not going to do.
+ tId.first = tId.second = -1;
+#endif
+
+ TQTabletEvent e( t, curr, global, tqdeviceType, pressure, xTilt, yTilt, tId );
+ TQApplication::sendSpontaneousEvent( w, &e );
+ return TRUE;
+}
+#endif
+
+bool TQETWidget::translatePropertyEvent(const XEvent *event)
+{
+ if (!isTopLevel()) return TRUE;
+
+ Atom ret;
+ int format, e;
+ unsigned char *data = 0;
+ unsigned long nitems, after;
+
+ if (event->xproperty.atom == qt_net_wm_frame_strut) {
+ topData()->fleft = topData()->fright = topData()->ftop = topData()->fbottom = 0;
+ fstrut_dirty = 1;
+
+ if (event->xproperty.state == PropertyNewValue) {
+ e = XGetWindowProperty(appDpy, event->xproperty.window, qt_net_wm_frame_strut,
+ 0, 4, // struts are 4 longs
+ False, XA_CARDINAL, &ret, &format, &nitems, &after, &data);
+
+ if (e == Success && ret == XA_CARDINAL &&
+ format == 32 && nitems == 4) {
+ long *strut = (long *) data;
+ topData()->fleft = strut[0];
+ topData()->fright = strut[1];
+ topData()->ftop = strut[2];
+ topData()->fbottom = strut[3];
+ fstrut_dirty = 0;
+ }
+ }
+ } else if (event->xproperty.atom == qt_net_wm_state) {
+ bool max = FALSE;
+ bool full = FALSE;
+
+ if (event->xproperty.state == PropertyNewValue) {
+ // using length of 1024 should be safe for all current and
+ // possible NET states...
+ e = XGetWindowProperty(appDpy, event->xproperty.window, qt_net_wm_state, 0, 1024,
+ False, XA_ATOM, &ret, &format, &nitems, &after, &data);
+
+ if (e == Success && ret == XA_ATOM && format == 32 && nitems > 0) {
+ Atom *states = (Atom *) data;
+
+ unsigned long i;
+ for (i = 0; i < nitems; i++) {
+ if (states[i] == qt_net_wm_state_max_v || states[i] == qt_net_wm_state_max_h)
+ max = TRUE;
+ else if (states[i] == qt_net_wm_state_fullscreen)
+ full = TRUE;
+ }
+ }
+ }
+
+ bool send_event = FALSE;
+
+ if (qt_net_supports(qt_net_wm_state_max_v)
+ && qt_net_supports(qt_net_wm_state_max_h)) {
+ if (max && !isMaximized()) {
+ setWState(WState_Maximized);
+ send_event = TRUE;
+ } else if (!max && isMaximized()) {
+ clearWState(WState_Maximized);
+ send_event = TRUE;
+ }
+ }
+
+ if (qt_net_supports(qt_net_wm_state_fullscreen)) {
+ if (full && !isFullScreen()) {
+ setWState(WState_FullScreen);
+ send_event = TRUE;
+ } else if (!full && isFullScreen()) {
+ clearWState(WState_FullScreen);
+ send_event = TRUE;
+ }
+ }
+
+ if (send_event) {
+ TQEvent e(TQEvent::WindowStateChange);
+ TQApplication::sendSpontaneousEvent(this, &e);
+ }
+ } else if (event->xproperty.atom == qt_wm_state) {
+ // the widget frame strut should also be invalidated
+ topData()->fleft = topData()->fright = topData()->ftop = topData()->fbottom = 0;
+ fstrut_dirty = 1;
+
+ if (event->xproperty.state == PropertyDelete) {
+ // the window manager has removed the WM State property,
+ // so it is now in the withdrawn state (ICCCM 4.1.3.1) and
+ // we are free to reuse this window
+ topData()->parentWinId = 0;
+ // map the window if we were waiting for a transition to
+ // withdrawn
+ if ( qt_deferred_map_tqcontains( this ) ) {
+ qt_deferred_map_take( this );
+ XMapWindow( appDpy, winId() );
+ }
+ } else if (topData()->parentWinId != TQPaintDevice::x11AppRootWindow(x11Screen())) {
+ // the window manager has changed the WM State property...
+ // we are wanting to see if we are withdrawn so that we
+ // can reuse this window... we only do this check *IF* we
+ // haven't been reparented to root - (the parentWinId !=
+ // TQPaintDevice::x11AppRootWindow(x11Screen())) check
+ // above
+
+ e = XGetWindowProperty(appDpy, winId(), qt_wm_state, 0, 2, False, qt_wm_state,
+ &ret, &format, &nitems, &after, &data );
+
+ if (e == Success && ret == qt_wm_state && format == 32 && nitems > 0) {
+ long *state = (long *) data;
+ switch (state[0]) {
+ case WithdrawnState:
+ // if we are in the withdrawn state, we are free
+ // to reuse this window provided we remove the
+ // WM_STATE property (ICCCM 4.1.3.1)
+ XDeleteProperty(appDpy, winId(), qt_wm_state);
+
+ // set the tqparent id to zero, so that show() will
+ // work again
+ topData()->parentWinId = 0;
+ // map the window if we were waiting for a
+ // transition to withdrawn
+ if ( qt_deferred_map_tqcontains( this ) ) {
+ qt_deferred_map_take( this );
+ XMapWindow( appDpy, winId() );
+ }
+ break;
+
+ case IconicState:
+ if (!isMinimized()) {
+ // window was minimized
+ setWState(WState_Minimized);
+ TQEvent e(TQEvent::WindowStateChange);
+ TQApplication::sendSpontaneousEvent(this, &e);
+ }
+ break;
+
+ default:
+ if (isMinimized()) {
+ // window was un-minimized
+ clearWState(WState_Minimized);
+ TQEvent e(TQEvent::WindowStateChange);
+ TQApplication::sendSpontaneousEvent(this, &e);
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ if (data)
+ XFree(data);
+
+ return TRUE;
+}
+
+#ifndef XK_ISO_Left_Tab
+#define XK_ISO_Left_Tab 0xFE20
+#endif
+
+// the next lines are taken from XFree > 4.0 (X11/XF86keysyms.h), defining some special
+// multimedia keys. They are included here as not every system has them.
+#define XF86XK_Standby 0x1008FF10
+#define XF86XK_AudioLowerVolume 0x1008FF11
+#define XF86XK_AudioMute 0x1008FF12
+#define XF86XK_AudioRaiseVolume 0x1008FF13
+#define XF86XK_AudioPlay 0x1008FF14
+#define XF86XK_AudioStop 0x1008FF15
+#define XF86XK_AudioPrev 0x1008FF16
+#define XF86XK_AudioNext 0x1008FF17
+#define XF86XK_HomePage 0x1008FF18
+#define XF86XK_Calculator 0x1008FF1D
+#define XF86XK_Mail 0x1008FF19
+#define XF86XK_Start 0x1008FF1A
+#define XF86XK_Search 0x1008FF1B
+#define XF86XK_AudioRecord 0x1008FF1C
+#define XF86XK_Back 0x1008FF26
+#define XF86XK_Forward 0x1008FF27
+#define XF86XK_Stop 0x1008FF28
+#define XF86XK_Refresh 0x1008FF29
+#define XF86XK_Favorites 0x1008FF30
+#define XF86XK_AudioPause 0x1008FF31
+#define XF86XK_AudioMedia 0x1008FF32
+#define XF86XK_MyComputer 0x1008FF33
+#define XF86XK_OpenURL 0x1008FF38
+#define XF86XK_Launch0 0x1008FF40
+#define XF86XK_Launch1 0x1008FF41
+#define XF86XK_Launch2 0x1008FF42
+#define XF86XK_Launch3 0x1008FF43
+#define XF86XK_Launch4 0x1008FF44
+#define XF86XK_Launch5 0x1008FF45
+#define XF86XK_Launch6 0x1008FF46
+#define XF86XK_Launch7 0x1008FF47
+#define XF86XK_Launch8 0x1008FF48
+#define XF86XK_Launch9 0x1008FF49
+#define XF86XK_LaunchA 0x1008FF4A
+#define XF86XK_LaunchB 0x1008FF4B
+#define XF86XK_LaunchC 0x1008FF4C
+#define XF86XK_LaunchD 0x1008FF4D
+#define XF86XK_LaunchE 0x1008FF4E
+#define XF86XK_LaunchF 0x1008FF4F
+// end of XF86keysyms.h
+
+
+
+static const KeySym KeyTbl[] = { // keyboard mapping table
+ XK_Escape, TQt::Key_Escape, // misc keys
+ XK_Tab, TQt::Key_Tab,
+ XK_ISO_Left_Tab, TQt::Key_Backtab,
+ XK_BackSpace, TQt::Key_Backspace,
+ XK_Return, TQt::Key_Return,
+ XK_Insert, TQt::Key_Insert,
+ XK_KP_Insert, TQt::Key_Insert,
+ XK_Delete, TQt::Key_Delete,
+ XK_KP_Delete, TQt::Key_Delete,
+ XK_Clear, TQt::Key_Delete,
+ XK_Pause, TQt::Key_Pause,
+ XK_Print, TQt::Key_Print,
+ XK_KP_Begin, TQt::Key_Clear,
+ 0x1005FF60, TQt::Key_SysReq, // hardcoded Sun SysReq
+ 0x1007ff00, TQt::Key_SysReq, // hardcoded X386 SysReq
+ XK_Home, TQt::Key_Home, // cursor movement
+ XK_End, TQt::Key_End,
+ XK_Left, TQt::Key_Left,
+ XK_Up, TQt::Key_Up,
+ XK_Right, TQt::Key_Right,
+ XK_Down, TQt::Key_Down,
+ XK_Prior, TQt::Key_Prior,
+ XK_Next, TQt::Key_Next,
+ XK_KP_Home, TQt::Key_Home,
+ XK_KP_End, TQt::Key_End,
+ XK_KP_Left, TQt::Key_Left,
+ XK_KP_Up, TQt::Key_Up,
+ XK_KP_Right, TQt::Key_Right,
+ XK_KP_Down, TQt::Key_Down,
+ XK_KP_Prior, TQt::Key_Prior,
+ XK_KP_Next, TQt::Key_Next,
+ XK_Shift_L, TQt::Key_Shift, // modifiers
+ XK_Shift_R, TQt::Key_Shift,
+ XK_Shift_Lock, TQt::Key_Shift,
+ XK_Control_L, TQt::Key_Control,
+ XK_Control_R, TQt::Key_Control,
+ XK_Meta_L, TQt::Key_Meta,
+ XK_Meta_R, TQt::Key_Meta,
+ XK_Alt_L, TQt::Key_Alt,
+ XK_Alt_R, TQt::Key_Alt,
+ XK_Caps_Lock, TQt::Key_CapsLock,
+ XK_Num_Lock, TQt::Key_NumLock,
+ XK_Scroll_Lock, TQt::Key_ScrollLock,
+ XK_KP_Space, TQt::Key_Space, // numeric keypad
+ XK_KP_Tab, TQt::Key_Tab,
+ XK_KP_Enter, TQt::Key_Enter,
+ XK_KP_Equal, TQt::Key_Equal,
+ XK_KP_Multiply, TQt::Key_Asterisk,
+ XK_KP_Add, TQt::Key_Plus,
+ XK_KP_Separator, TQt::Key_Comma,
+ XK_KP_Subtract, TQt::Key_Minus,
+ XK_KP_Decimal, TQt::Key_Period,
+ XK_KP_Divide, TQt::Key_Slash,
+ XK_Super_L, TQt::Key_Super_L,
+ XK_Super_R, TQt::Key_Super_R,
+ XK_Menu, TQt::Key_Menu,
+ XK_Hyper_L, TQt::Key_Hyper_L,
+ XK_Hyper_R, TQt::Key_Hyper_R,
+ XK_Help, TQt::Key_Help,
+ 0x1000FF74, TQt::Key_BackTab, // hardcoded HP backtab
+ 0x1005FF10, TQt::Key_F11, // hardcoded Sun F36 (labeled F11)
+ 0x1005FF11, TQt::Key_F12, // hardcoded Sun F37 (labeled F12)
+
+ // Special multimedia keys
+ // currently only tested with MS internet keyboard
+
+ // browsing keys
+ XF86XK_Back, TQt::Key_Back,
+ XF86XK_Forward, TQt::Key_Forward,
+ XF86XK_Stop, TQt::Key_Stop,
+ XF86XK_Refresh, TQt::Key_Refresh,
+ XF86XK_Favorites, TQt::Key_Favorites,
+ XF86XK_AudioMedia, TQt::Key_LaunchMedia,
+ XF86XK_OpenURL, TQt::Key_OpenUrl,
+ XF86XK_HomePage, TQt::Key_HomePage,
+ XF86XK_Search, TQt::Key_Search,
+
+ // media keys
+ XF86XK_AudioLowerVolume, TQt::Key_VolumeDown,
+ XF86XK_AudioMute, TQt::Key_VolumeMute,
+ XF86XK_AudioRaiseVolume, TQt::Key_VolumeUp,
+ XF86XK_AudioPlay, TQt::Key_MediaPlay,
+ XF86XK_AudioStop, TQt::Key_MediaStop,
+ XF86XK_AudioPrev, TQt::Key_MediaPrev,
+ XF86XK_AudioNext, TQt::Key_MediaNext,
+ XF86XK_AudioRecord, TQt::Key_MediaRecord,
+
+ // launch keys
+ XF86XK_Mail, TQt::Key_LaunchMail,
+ XF86XK_MyComputer, TQt::Key_Launch0,
+ XF86XK_Calculator, TQt::Key_Launch1,
+ XF86XK_Standby, TQt::Key_Standby,
+
+ XF86XK_Launch0, TQt::Key_Launch2,
+ XF86XK_Launch1, TQt::Key_Launch3,
+ XF86XK_Launch2, TQt::Key_Launch4,
+ XF86XK_Launch3, TQt::Key_Launch5,
+ XF86XK_Launch4, TQt::Key_Launch6,
+ XF86XK_Launch5, TQt::Key_Launch7,
+ XF86XK_Launch6, TQt::Key_Launch8,
+ XF86XK_Launch7, TQt::Key_Launch9,
+ XF86XK_Launch8, TQt::Key_LaunchA,
+ XF86XK_Launch9, TQt::Key_LaunchB,
+ XF86XK_LaunchA, TQt::Key_LaunchC,
+ XF86XK_LaunchB, TQt::Key_LaunchD,
+ XF86XK_LaunchC, TQt::Key_LaunchE,
+ XF86XK_LaunchD, TQt::Key_LaunchF,
+
+ 0, 0
+};
+
+
+static TQIntDict<void> *keyDict = 0;
+static TQIntDict<void> *textDict = 0;
+
+static void deleteKeyDicts()
+{
+ if ( keyDict )
+ delete keyDict;
+ keyDict = 0;
+ if ( textDict )
+ delete textDict;
+ textDict = 0;
+}
+
+#if !defined(TQT_NO_XIM)
+static const unsigned short katakanaKeysymsToUnicode[] = {
+ 0x0000, 0x3002, 0x300C, 0x300D, 0x3001, 0x30FB, 0x30F2, 0x30A1,
+ 0x30A3, 0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3,
+ 0x30FC, 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD,
+ 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD,
+ 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC,
+ 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, 0x30DE,
+ 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9,
+ 0x30EA, 0x30EB, 0x30EC, 0x30ED, 0x30EF, 0x30F3, 0x309B, 0x309C
+};
+
+static const unsigned short cyrillicKeysymsToUnicode[] = {
+ 0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457,
+ 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0000, 0x045e, 0x045f,
+ 0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407,
+ 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x0000, 0x040e, 0x040f,
+ 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433,
+ 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e,
+ 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432,
+ 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a,
+ 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
+ 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e,
+ 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
+ 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a
+};
+
+static const unsigned short greekKeysymsToUnicode[] = {
+ 0x0000, 0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c,
+ 0x038e, 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015,
+ 0x0000, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc,
+ 0x03cd, 0x03cb, 0x03b0, 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
+ 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f,
+ 0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
+ 0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
+ 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
+ 0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7,
+ 0x03c8, 0x03c9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
+};
+
+static const unsigned short technicalKeysymsToUnicode[] = {
+ 0x0000, 0x23B7, 0x250C, 0x2500, 0x2320, 0x2321, 0x2502, 0x23A1,
+ 0x23A3, 0x23A4, 0x23A6, 0x239B, 0x239D, 0x239E, 0x23A0, 0x23A8,
+ 0x23AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x2264, 0x2260, 0x2265, 0x222B,
+ 0x2234, 0x221D, 0x221E, 0x0000, 0x0000, 0x2207, 0x0000, 0x0000,
+ 0x223C, 0x2243, 0x0000, 0x0000, 0x0000, 0x21D4, 0x21D2, 0x2261,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x221A, 0x0000,
+ 0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222A, 0x2227, 0x2228,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x2190, 0x2191, 0x2192, 0x2193, 0x0000
+};
+
+static const unsigned short specialKeysymsToUnicode[] = {
+ 0x25C6, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x0000, 0x0000,
+ 0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0x23BA,
+ 0x23BB, 0x2500, 0x23BC, 0x23BD, 0x251C, 0x2524, 0x2534, 0x252C,
+ 0x2502, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
+};
+
+static const unsigned short publishingKeysymsToUnicode[] = {
+ 0x0000, 0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009,
+ 0x200a, 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025,
+ 0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a,
+ 0x2105, 0x0000, 0x0000, 0x2012, 0x2329, 0x0000, 0x232a, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000,
+ 0x0000, 0x2122, 0x2613, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25af,
+ 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x0000, 0x2032, 0x2033,
+ 0x0000, 0x271d, 0x0000, 0x25ac, 0x25c0, 0x25b6, 0x25cf, 0x25ae,
+ 0x25e6, 0x25ab, 0x25ad, 0x25b3, 0x25bd, 0x2606, 0x2022, 0x25aa,
+ 0x25b2, 0x25bc, 0x261c, 0x261e, 0x2663, 0x2666, 0x2665, 0x0000,
+ 0x2720, 0x2020, 0x2021, 0x2713, 0x2717, 0x266f, 0x266d, 0x2642,
+ 0x2640, 0x260e, 0x2315, 0x2117, 0x2038, 0x201a, 0x201e, 0x0000
+};
+
+static const unsigned short aplKeysymsToUnicode[] = {
+ 0x0000, 0x0000, 0x0000, 0x003c, 0x0000, 0x0000, 0x003e, 0x0000,
+ 0x2228, 0x2227, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x00af, 0x0000, 0x22a5, 0x2229, 0x230a, 0x0000, 0x005f, 0x0000,
+ 0x0000, 0x0000, 0x2218, 0x0000, 0x2395, 0x0000, 0x22a4, 0x25cb,
+ 0x0000, 0x0000, 0x0000, 0x2308, 0x0000, 0x0000, 0x222a, 0x0000,
+ 0x2283, 0x0000, 0x2282, 0x0000, 0x22a2, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x22a3, 0x0000, 0x0000, 0x0000
+};
+
+static const unsigned short koreanKeysymsToUnicode[] = {
+ 0x0000, 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137,
+ 0x3138, 0x3139, 0x313a, 0x313b, 0x313c, 0x313d, 0x313e, 0x313f,
+ 0x3140, 0x3141, 0x3142, 0x3143, 0x3144, 0x3145, 0x3146, 0x3147,
+ 0x3148, 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e, 0x314f,
+ 0x3150, 0x3151, 0x3152, 0x3153, 0x3154, 0x3155, 0x3156, 0x3157,
+ 0x3158, 0x3159, 0x315a, 0x315b, 0x315c, 0x315d, 0x315e, 0x315f,
+ 0x3160, 0x3161, 0x3162, 0x3163, 0x11a8, 0x11a9, 0x11aa, 0x11ab,
+ 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3,
+ 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb,
+ 0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x316d,
+ 0x3171, 0x3178, 0x317f, 0x3181, 0x3184, 0x3186, 0x318d, 0x318e,
+ 0x11eb, 0x11f0, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9
+};
+
+
+static TQChar keysymToUnicode(unsigned char byte3, unsigned char byte4)
+{
+ if ( byte3 == 0x04 ) {
+ // katakana
+ if ( byte4 > 0xa0 && byte4 < 0xe0 )
+ return TQChar( katakanaKeysymsToUnicode[byte4 - 0xa0] );
+ else if ( byte4 == 0x7e )
+ return TQChar( 0x203e ); // Overline
+ } else if ( byte3 == 0x06 ) {
+ // russian, use lookup table
+ if ( byte4 > 0xa0 )
+ return TQChar( cyrillicKeysymsToUnicode[byte4 - 0xa0] );
+ } else if ( byte3 == 0x07 ) {
+ // greek
+ if ( byte4 > 0xa0 )
+ return TQChar( greekKeysymsToUnicode[byte4 - 0xa0] );
+ } else if ( byte3 == 0x08 ) {
+ // technical
+ if ( byte4 > 0xa0 )
+ return TQChar( technicalKeysymsToUnicode[byte4 - 0xa0] );
+ } else if ( byte3 == 0x09 ) {
+ // special
+ if ( byte4 >= 0xe0 )
+ return TQChar( specialKeysymsToUnicode[byte4 - 0xe0] );
+ } else if ( byte3 == 0x0a ) {
+ // publishing
+ if ( byte4 > 0xa0 )
+ return TQChar( publishingKeysymsToUnicode[byte4 - 0xa0] );
+ } else if ( byte3 == 0x0b ) {
+ // APL
+ if ( byte4 > 0xa0 )
+ return TQChar( aplKeysymsToUnicode[byte4 - 0xa0] );
+ } else if ( byte3 == 0x0e ) {
+ // Korean
+ if ( byte4 > 0xa0 )
+ return TQChar( koreanKeysymsToUnicode[byte4 - 0xa0] );
+ }
+ return TQChar(0x0);
+}
+#endif
+
+
+bool TQETWidget::translateKeyEventInternal( const XEvent *event, int& count,
+ TQString& text,
+ int& state,
+ char& ascii, int& code, TQEvent::Type &type, bool willRepeat )
+{
+ TQTextCodec *mapper = input_mapper;
+ // some XmbLookupString implementations don't return buffer overflow correctly,
+ // so we increase the input buffer to allow for long strings...
+ // 256 chars * 2 bytes + 1 null-term == 513 bytes
+ TQCString chars(513);
+ TQChar converted;
+ KeySym key = 0;
+
+ if ( !keyDict ) {
+ keyDict = new TQIntDict<void>( 13 );
+ keyDict->setAutoDelete( FALSE );
+ textDict = new TQIntDict<void>( 13 );
+ textDict->setAutoDelete( FALSE );
+ qAddPostRoutine( deleteKeyDicts );
+ }
+
+ TQWidget* tlw = tqtopLevelWidget();
+
+ XKeyEvent xkeyevent = event->xkey;
+
+ // save the modifier state, we will use the keystate uint later by passing
+ // it to translateButtonState
+ uint keystate = event->xkey.state;
+ // remove the modifiers where mode_switch exists... HPUX machines seem
+ // to have alt *AND* mode_switch both in Mod1Mask, which causes
+ // XLookupString to return things like '�' (aring) for ALT-A. This
+ // completely breaks modifiers. If we remove the modifier for Mode_switch,
+ // then things work correctly...
+ xkeyevent.state &= ~qt_mode_switch_remove_mask;
+
+ type = (event->type == XKeyPress)
+ ? TQEvent::KeyPress : TQEvent::KeyRelease;
+#if defined(TQT_NO_XIM)
+
+ count = XLookupString( &xkeyevent, chars.data(), chars.size(), &key, 0 );
+
+ if ( count == 1 )
+ ascii = chars[0];
+
+#else
+ // Implementation for X11R5 and newer, using XIM
+
+ int keycode = event->xkey.keycode;
+ Status status;
+
+ if ( type == TQEvent::KeyPress ) {
+ bool mb=FALSE;
+ if ( qt_xim ) {
+ TQTLWExtra* xd = tlw->topData();
+ TQInputContext *qic = (TQInputContext *) xd->xic;
+ if ( qic ) {
+ mb=TRUE;
+ count = qic->lookupString(&xkeyevent, chars, &key, &status);
+ }
+ }
+ if ( !mb ) {
+ count = XLookupString( &xkeyevent,
+ chars.data(), chars.size(), &key, 0 );
+ }
+ if ( count && !keycode ) {
+ keycode = composingKeycode;
+ composingKeycode = 0;
+ }
+ if ( key )
+ keyDict->tqreplace( keycode, (void*)key );
+ // all keysyms smaller than that are actally keys that can be mapped
+ // to tqunicode chars
+ if ( count == 0 && key < 0xff00 ) {
+ unsigned char byte3 = (unsigned char )(key >> 8);
+ int mib = -1;
+ switch( byte3 ) {
+ case 0: // Latin 1
+ case 1: // Latin 2
+ case 2: //latin 3
+ case 3: // latin4
+ mib = byte3 + 4; break;
+ case 5: // arabic
+ mib = 82; break;
+ case 12: // Hebrew
+ mib = 85; break;
+ case 13: // Thai
+ mib = 2259; break;
+ case 4: // kana
+ case 6: // cyrillic
+ case 7: // greek
+ case 8: // technical, no mapping here at the moment
+ case 9: // Special
+ case 10: // Publishing
+ case 11: // APL
+ case 14: // Korean, no mapping
+ mib = -1; // manual conversion
+ mapper = 0;
+ converted = keysymToUnicode( byte3, key & 0xff );
+ case 0x20:
+ // currency symbols
+ if ( key >= 0x20a0 && key <= 0x20ac ) {
+ mib = -1; // manual conversion
+ mapper = 0;
+ converted = (uint)key;
+ }
+ break;
+ default:
+ break;
+ }
+ if ( mib != -1 ) {
+ mapper = TQTextCodec::codecForMib( mib );
+ chars[0] = (unsigned char) (key & 0xff); // get only the fourth bit for conversion later
+ count++;
+ }
+ } else if ( key >= 0x1000000 && key <= 0x100ffff ) {
+ converted = (ushort) (key - 0x1000000);
+ mapper = 0;
+ }
+ if ( count < (int)chars.size()-1 )
+ chars[count] = '\0';
+ if ( count == 1 ) {
+ ascii = chars[0];
+ // +256 so we can store all eight-bit codes, including ascii 0,
+ // and independent of whether char is signed or not.
+ textDict->tqreplace( keycode, (void*)(long)(256+ascii) );
+ }
+ tlw = 0;
+ } else {
+ key = (int)(long)keyDict->tqfind( keycode );
+ if ( key )
+ if( !willRepeat ) // Take out key of dictionary only if this call.
+ keyDict->take( keycode );
+ long s = (long)textDict->tqfind( keycode );
+ if ( s ) {
+ textDict->take( keycode );
+ ascii = (char)(s-256);
+ }
+ }
+#endif // !TQT_NO_XIM
+
+ state = translateButtonState( keystate );
+
+ static int directionKeyEvent = 0;
+ if ( qt_use_rtl_extensions && type == TQEvent::KeyRelease ) {
+ if (directionKeyEvent == Key_Direction_R || directionKeyEvent == Key_Direction_L ) {
+ type = TQEvent::KeyPress;
+ code = directionKeyEvent;
+ chars[0] = 0;
+ directionKeyEvent = 0;
+ return TRUE;
+ } else {
+ directionKeyEvent = 0;
+ }
+ }
+
+ // Watch for keypresses and if its a key belonging to the Ctrl-Shift
+ // direction-changing accel, remember it.
+ // We keep track of those keys instead of using the event's state
+ // (to figure out whether the Ctrl modifier is held while Shift is pressed,
+ // or Shift is held while Ctrl is pressed) since the 'state' doesn't tell
+ // us whether the modifier held is Left or Right.
+ if (qt_use_rtl_extensions && type == TQEvent::KeyPress)
+ if (key == XK_Control_L || key == XK_Control_R || key == XK_Shift_L || key == XK_Shift_R) {
+ if (!directionKeyEvent)
+ directionKeyEvent = key;
+ } else {
+ // this can no longer be a direction-changing accel.
+ // if any other key was pressed.
+ directionKeyEvent = Key_Space;
+ }
+
+ // Commentary in X11/keysymdef says that X codes match ASCII, so it
+ // is safe to use the locale functions to process X codes in ISO8859-1.
+ //
+ // This is mainly for compatibility - applications should not use the
+ // TQt keycodes between 128 and 255, but should rather use the
+ // TQKeyEvent::text().
+ //
+ if ( key < 128 || (key < 256 && (!input_mapper || input_mapper->mibEnum()==4)) ) {
+ code = isprint((int)key) ? toupper((int)key) : 0; // upper-case key, if known
+ } else if ( key >= XK_F1 && key <= XK_F35 ) {
+ code = Key_F1 + ((int)key - XK_F1); // function keys
+ } else if ( key >= XK_KP_0 && key <= XK_KP_9) {
+ code = Key_0 + ((int)key - XK_KP_0); // numeric keypad keys
+ state |= Keypad;
+ } else {
+ int i = 0; // any other keys
+ while ( KeyTbl[i] ) {
+ if ( key == KeyTbl[i] ) {
+ code = (int)KeyTbl[i+1];
+ break;
+ }
+ i += 2;
+ }
+ switch ( key ) {
+ case XK_KP_Insert:
+ case XK_KP_Delete:
+ case XK_KP_Home:
+ case XK_KP_End:
+ case XK_KP_Left:
+ case XK_KP_Up:
+ case XK_KP_Right:
+ case XK_KP_Down:
+ case XK_KP_Prior:
+ case XK_KP_Next:
+ case XK_KP_Space:
+ case XK_KP_Tab:
+ case XK_KP_Enter:
+ case XK_KP_Equal:
+ case XK_KP_Multiply:
+ case XK_KP_Add:
+ case XK_KP_Separator:
+ case XK_KP_Subtract:
+ case XK_KP_Decimal:
+ case XK_KP_Divide:
+ state |= Keypad;
+ break;
+ default:
+ break;
+ }
+
+ if ( code == Key_Tab &&
+ (state & ShiftButton) == ShiftButton ) {
+ // map shift+tab to shift+backtab, TQAccel knows about it
+ // and will handle it.
+ code = Key_Backtab;
+ chars[0] = 0;
+ }
+
+ if ( qt_use_rtl_extensions && type == TQEvent::KeyPress ) {
+ if ( directionKeyEvent ) {
+ if ( key == XK_Shift_L && directionKeyEvent == XK_Control_L ||
+ key == XK_Control_L && directionKeyEvent == XK_Shift_L ) {
+ directionKeyEvent = Key_Direction_L;
+ } else if ( key == XK_Shift_R && directionKeyEvent == XK_Control_R ||
+ key == XK_Control_R && directionKeyEvent == XK_Shift_R ) {
+ directionKeyEvent = Key_Direction_R;
+ }
+ }
+ else if ( directionKeyEvent == Key_Direction_L || directionKeyEvent == Key_Direction_R ) {
+ directionKeyEvent = Key_Space; // invalid
+ }
+ }
+ }
+
+#if 0
+#ifndef TQ_EE
+ static int c = 0;
+ extern void qt_dialog_default_key();
+#define TQ_EE(x) c = (c == x || (!c && x == 0x1000) )? x+1 : 0
+ if ( tlw && state == '0' ) {
+ switch ( code ) {
+ case 0x4f: TQ_EE(Key_Backtab); break;
+ case 0x52: TQ_EE(Key_Tab); break;
+ case 0x54: TQ_EE(Key_Escape); break;
+ case 0x4c:
+ if (c == Key_Return )
+ qt_dialog_default_key();
+ else
+ TQ_EE(Key_Backspace);
+ break;
+ }
+ }
+#undef TQ_EE
+#endif
+#endif
+
+ // convert chars (8bit) to text (tqunicode).
+ if ( mapper )
+ text = mapper->toUnicode(chars,count);
+ else if ( !mapper && converted.tqunicode() != 0x0 )
+ text = converted;
+ else
+ text = chars;
+ return TRUE;
+}
+
+
+struct qt_auto_repeat_data
+{
+ // match the window and keycode with timestamp delta of 10ms
+ Window window;
+ KeyCode keycode;
+ Time timestamp;
+
+ // queue scanner state
+ bool release;
+ bool error;
+};
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static Bool qt_keypress_scanner(Display *, XEvent *event, XPointer arg)
+{
+ if (event->type != XKeyPress && event->type != XKeyRelease)
+ return FALSE;
+
+ qt_auto_repeat_data *d = (qt_auto_repeat_data *) arg;
+ if (d->error ||
+ event->xkey.window != d->window ||
+ event->xkey.keycode != d->keycode)
+ return FALSE;
+
+ if (event->type == XKeyPress) {
+ d->error = (! d->release || event->xkey.time - d->timestamp > 10);
+ return (! d->error);
+ }
+
+ // must be XKeyRelease event
+ if (d->release) {
+ // found a second release
+ d->error = TRUE;
+ return FALSE;
+ }
+
+ // found a single release
+ d->release = TRUE;
+ d->timestamp = event->xkey.time;
+
+ return FALSE;
+}
+
+static Bool qt_keyrelease_scanner(Display *, XEvent *event, XPointer arg)
+{
+ const qt_auto_repeat_data *d = (const qt_auto_repeat_data *) arg;
+ return (event->type == XKeyRelease &&
+ event->xkey.window == d->window &&
+ event->xkey.keycode == d->keycode);
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+bool TQETWidget::translateKeyEvent( const XEvent *event, bool grab )
+{
+ int code = -1;
+ int count = 0;
+ int state;
+ char ascii = 0;
+
+ if ( sm_blockUserInput ) // block user interaction during session management
+ return TRUE;
+
+ Display *dpy = x11Display();
+
+ if ( !isEnabled() )
+ return TRUE;
+
+ TQEvent::Type type;
+ bool autor = FALSE;
+ TQString text;
+
+ translateKeyEventInternal( event, count, text, state, ascii, code, type,
+ qt_mode_switch_remove_mask != 0 );
+
+ static uint curr_autorep = 0;
+ // was this the last auto-repeater?
+ qt_auto_repeat_data auto_repeat_data;
+ auto_repeat_data.window = event->xkey.window;
+ auto_repeat_data.keycode = event->xkey.keycode;
+ auto_repeat_data.timestamp = event->xkey.time;
+
+ if ( event->type == XKeyPress ) {
+ if ( curr_autorep == event->xkey.keycode ) {
+ autor = TRUE;
+ curr_autorep = 0;
+ }
+ } else {
+ // look ahead for auto-repeat
+ XEvent nextpress;
+
+ auto_repeat_data.release = TRUE;
+ auto_repeat_data.error = FALSE;
+ if (XCheckIfEvent(dpy, &nextpress, &qt_keypress_scanner,
+ (XPointer) &auto_repeat_data)) {
+ autor = TRUE;
+
+ // Put it back... we COULD send the event now and not need
+ // the static curr_autorep variable.
+ XPutBackEvent(dpy,&nextpress);
+ }
+ curr_autorep = autor ? event->xkey.keycode : 0;
+ }
+
+ // process accelerators before doing key compression
+ if ( type == TQEvent::KeyPress && !grab ) {
+ // send accel events if the keyboard is not grabbed
+ TQKeyEvent a( type, code, ascii, state, text, autor,
+ TQMAX( TQMAX(count,1), int(text.length())) );
+ if ( qt_tryAccelEvent( this, &a ) )
+ return TRUE;
+ }
+
+ long save = 0;
+ if ( qt_mode_switch_remove_mask != 0 ) {
+ save = qt_mode_switch_remove_mask;
+ qt_mode_switch_remove_mask = 0;
+
+ // translate the key event again, but this time apply any Mode_switch
+ // modifiers
+ translateKeyEventInternal( event, count, text, state, ascii, code, type );
+ }
+
+ // compress keys
+ if ( !text.isEmpty() && testWState(WState_CompressKeys) &&
+ // do not compress keys if the key event we just got above matches
+ // one of the key ranges used to compute stopCompression
+ ! ( ( code >= Key_Escape && code <= Key_SysReq ) ||
+ ( code >= Key_Home && code <= Key_Next ) ||
+ ( code >= Key_Super_L && code <= Key_Direction_R ) ||
+ ( ( code == 0 ) && ( ascii == '\n' ) ) ) ) {
+ // the widget wants key compression so it gets it
+ int codeIntern = -1;
+ int countIntern = 0;
+ int stateIntern;
+ char asciiIntern = 0;
+ XEvent evRelease;
+ XEvent evPress;
+
+ // sync the event queue, this makes key compress work better
+ XSync( dpy, FALSE );
+
+ for (;;) {
+ TQString textIntern;
+ if ( !XCheckTypedWindowEvent(dpy,event->xkey.window,
+ XKeyRelease,&evRelease) )
+ break;
+ if ( !XCheckTypedWindowEvent(dpy,event->xkey.window,
+ XKeyPress,&evPress) ) {
+ XPutBackEvent(dpy, &evRelease);
+ break;
+ }
+ TQEvent::Type t;
+ translateKeyEventInternal( &evPress, countIntern, textIntern,
+ stateIntern, asciiIntern, codeIntern, t );
+ // use stopCompression to stop key compression for the following
+ // key event ranges:
+ bool stopCompression =
+ // 1) misc keys
+ ( codeIntern >= Key_Escape && codeIntern <= Key_SysReq ) ||
+ // 2) cursor movement
+ ( codeIntern >= Key_Home && codeIntern <= Key_Next ) ||
+ // 3) extra keys
+ ( codeIntern >= Key_Super_L && codeIntern <= Key_Direction_R ) ||
+ // 4) something that a) doesn't translate to text or b) translates
+ // to newline text
+ ((codeIntern == 0) && (asciiIntern == '\n'));
+ if (stateIntern == state && !textIntern.isEmpty() && !stopCompression) {
+ text += textIntern;
+ count += countIntern;
+ } else {
+ XPutBackEvent(dpy, &evPress);
+ XPutBackEvent(dpy, &evRelease);
+ break;
+ }
+ }
+ }
+
+ if ( save != 0 )
+ qt_mode_switch_remove_mask = save;
+
+ // autorepeat compression makes sense for all widgets (Windows
+ // does it automatically .... )
+ if ( event->type == XKeyPress && text.length() <= 1 ) {
+ XEvent dummy;
+
+ for (;;) {
+ auto_repeat_data.release = FALSE;
+ auto_repeat_data.error = FALSE;
+ if (! XCheckIfEvent(dpy, &dummy, &qt_keypress_scanner,
+ (XPointer) &auto_repeat_data))
+ break;
+ if (! XCheckIfEvent(dpy, &dummy, &qt_keyrelease_scanner,
+ (XPointer) &auto_repeat_data))
+ break;
+
+ count++;
+ if (!text.isEmpty())
+ text += text[0];
+ }
+ }
+
+ if (code == 0 && ascii == '\n') {
+ code = Key_Return;
+ ascii = '\r';
+ text = "\r";
+ }
+
+ // try the menukey first
+ if ( type == TQEvent::KeyPress && code == TQt::Key_Menu ) {
+ TQContextMenuEvent e( TQContextMenuEvent::Keyboard, TQPoint( 5, 5 ), mapToGlobal( TQPoint( 5, 5 ) ), 0 );
+ TQApplication::sendSpontaneousEvent( this, &e );
+ if( e.isAccepted() )
+ return TRUE;
+ }
+
+ TQKeyEvent e( type, code, ascii, state, text, autor,
+ TQMAX(TQMAX(count,1), int(text.length())) );
+ return TQApplication::sendSpontaneousEvent( this, &e );
+}
+
+
+//
+// Paint event translation
+//
+// When receiving many expose events, we compress them (union of all expose
+// rectangles) into one event which is sent to the widget.
+
+struct PaintEventInfo {
+ Window window;
+};
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static Bool isPaintOrScrollDoneEvent( Display *, XEvent *ev, XPointer a )
+{
+ PaintEventInfo *info = (PaintEventInfo *)a;
+ if ( ev->type == Expose || ev->type == GraphicsExpose
+ || ev->type == ClientMessage
+ && ev->xclient.message_type == qt_qt_scrolldone )
+ {
+ if ( ev->xexpose.window == info->window )
+ return True;
+ }
+ return False;
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+// declared above: static TQPtrList<TQScrollInProgress> *sip_list = 0;
+
+void qt_insert_sip( TQWidget* scrolled_widget, int dx, int dy )
+{
+ if ( !sip_list ) {
+ sip_list = new TQPtrList<TQScrollInProgress>;
+ sip_list->setAutoDelete( TRUE );
+ }
+
+ TQScrollInProgress* sip = new TQScrollInProgress( scrolled_widget, dx, dy );
+ sip_list->append( sip );
+
+ XClientMessageEvent client_message;
+ client_message.type = ClientMessage;
+ client_message.window = scrolled_widget->winId();
+ client_message.format = 32;
+ client_message.message_type = qt_qt_scrolldone;
+ client_message.data.l[0] = sip->id;
+
+ XSendEvent( appDpy, scrolled_widget->winId(), False, NoEventMask,
+ (XEvent*)&client_message );
+}
+
+int qt_sip_count( TQWidget* scrolled_widget )
+{
+ if ( !sip_list )
+ return 0;
+
+ int sips=0;
+
+ for (TQScrollInProgress* sip = sip_list->first();
+ sip; sip=sip_list->next())
+ {
+ if ( sip->scrolled_widget == scrolled_widget )
+ sips++;
+ }
+
+ return sips;
+}
+
+static
+bool translateBySips( TQWidget* that, TQRect& paintRect )
+{
+ if ( sip_list ) {
+ int dx=0, dy=0;
+ int sips=0;
+ for (TQScrollInProgress* sip = sip_list->first();
+ sip; sip=sip_list->next())
+ {
+ if ( sip->scrolled_widget == that ) {
+ if ( sips ) {
+ dx += sip->dx;
+ dy += sip->dy;
+ }
+ sips++;
+ }
+ }
+ if ( sips > 1 ) {
+ paintRect.moveBy( dx, dy );
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool TQETWidget::translatePaintEvent( const XEvent *event )
+{
+ setWState( WState_Exposed );
+ TQRect paintRect( event->xexpose.x, event->xexpose.y,
+ event->xexpose.width, event->xexpose.height );
+ bool merging_okay = !testWFlags(WPaintClever);
+ XEvent xevent;
+ PaintEventInfo info;
+ info.window = winId();
+ bool should_clip = translateBySips( this, paintRect );
+
+ TQRegion paintRegion( paintRect );
+
+ if ( merging_okay ) {
+ // WARNING: this is O(number_of_events * number_of_matching_events)
+ while ( XCheckIfEvent(x11Display(),&xevent,isPaintOrScrollDoneEvent,
+ (XPointer)&info) &&
+ !qt_x11EventFilter(&xevent) &&
+ !x11Event( &xevent ) ) // send event through filter
+ {
+ if ( xevent.type == Expose || xevent.type == GraphicsExpose ) {
+ TQRect exposure(xevent.xexpose.x,
+ xevent.xexpose.y,
+ xevent.xexpose.width,
+ xevent.xexpose.height);
+ if ( translateBySips( this, exposure ) )
+ should_clip = TRUE;
+ paintRegion = paintRegion.unite( exposure );
+ } else {
+ translateScrollDoneEvent( &xevent );
+ }
+ }
+ }
+
+ if ( should_clip ) {
+ paintRegion = paintRegion.intersect( rect() );
+ if ( paintRegion.isEmpty() )
+ return TRUE;
+ }
+
+ TQPaintEvent e( paintRegion );
+ setWState( WState_InPaintEvent );
+ if ( !isTopLevel() && backgroundOrigin() != WidgetOrigin )
+ erase( paintRegion );
+ qt_set_paintevent_clipping( this, paintRegion );
+ TQApplication::sendSpontaneousEvent( this, &e );
+ qt_clear_paintevent_clipping();
+ clearWState( WState_InPaintEvent );
+ return TRUE;
+}
+
+//
+// Scroll-done event translation.
+//
+
+bool TQETWidget::translateScrollDoneEvent( const XEvent *event )
+{
+ if ( !sip_list ) return FALSE;
+
+ long id = event->xclient.data.l[0];
+
+ // Remove any scroll-in-progress record for the given id.
+ for (TQScrollInProgress* sip = sip_list->first(); sip; sip=sip_list->next()) {
+ if ( sip->id == id ) {
+ sip_list->remove( sip_list->current() );
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+//
+// ConfigureNotify (window move and resize) event translation
+
+bool TQETWidget::translateConfigEvent( const XEvent *event )
+{
+ // config pending is only set on resize, see qwidget_x11.cpp, internalSetGeometry()
+ bool was_resize = testWState( WState_ConfigPending );
+
+ clearWState(WState_ConfigPending);
+
+ if ( isTopLevel() ) {
+ TQPoint newCPos( tqgeometry().topLeft() );
+ TQSize newSize( event->xconfigure.width, event->xconfigure.height );
+
+ bool trust = (topData()->parentWinId == None ||
+ topData()->parentWinId == TQPaintDevice::x11AppRootWindow());
+
+ if (event->xconfigure.send_event || trust ) {
+ // if a ConfigureNotify comes from a real sendevent request, we can
+ // trust its values.
+ newCPos.rx() = event->xconfigure.x + event->xconfigure.border_width;
+ newCPos.ry() = event->xconfigure.y + event->xconfigure.border_width;
+ }
+
+ if ( isVisible() )
+ TQApplication::syncX();
+
+ if (! extra || extra->compress_events) {
+ // ConfigureNotify compression for faster opaque resizing
+ XEvent otherEvent;
+ while ( XCheckTypedWindowEvent( x11Display(), winId(), ConfigureNotify,
+ &otherEvent ) ) {
+ if ( qt_x11EventFilter( &otherEvent ) )
+ continue;
+
+ if (x11Event( &otherEvent ) )
+ continue;
+
+ if ( otherEvent.xconfigure.event != otherEvent.xconfigure.window )
+ continue;
+
+ newSize.setWidth( otherEvent.xconfigure.width );
+ newSize.setHeight( otherEvent.xconfigure.height );
+
+ if ( otherEvent.xconfigure.send_event || trust ) {
+ newCPos.rx() = otherEvent.xconfigure.x +
+ otherEvent.xconfigure.border_width;
+ newCPos.ry() = otherEvent.xconfigure.y +
+ otherEvent.xconfigure.border_width;
+ }
+ }
+ }
+
+ TQRect cr ( tqgeometry() );
+ if ( newSize != cr.size() ) { // size changed
+ was_resize = TRUE;
+ TQSize oldSize = size();
+ cr.setSize( newSize );
+ crect = cr;
+
+ if ( isVisible() ) {
+ TQResizeEvent e( newSize, oldSize );
+ TQApplication::sendSpontaneousEvent( this, &e );
+ } else {
+ TQResizeEvent * e = new TQResizeEvent( newSize, oldSize );
+ TQApplication::postEvent( this, e );
+ }
+ }
+
+ if ( newCPos != cr.topLeft() ) { // compare with cpos (exluding frame)
+ TQPoint oldPos = tqgeometry().topLeft();
+ cr.moveTopLeft( newCPos );
+ crect = cr;
+ if ( isVisible() ) {
+ TQMoveEvent e( newCPos, oldPos ); // pos (including frame), not cpos
+ TQApplication::sendSpontaneousEvent( this, &e );
+ } else {
+ TQMoveEvent * e = new TQMoveEvent( newCPos, oldPos );
+ TQApplication::postEvent( this, e );
+ }
+ }
+ } else {
+ XEvent xevent;
+ while ( XCheckTypedWindowEvent(x11Display(),winId(), ConfigureNotify,&xevent) &&
+ !qt_x11EventFilter(&xevent) &&
+ !x11Event( &xevent ) ) // send event through filter
+ ;
+ }
+
+ bool transbg = backgroundOrigin() != WidgetOrigin;
+ // we ignore NorthWestGravity at the moment for reversed tqlayout
+ if ( transbg ||
+ (!testWFlags( WStaticContents ) &&
+ testWState( WState_Exposed ) && was_resize ) ||
+ TQApplication::reverseLayout() ) {
+ // remove unnecessary paint events from the queue
+ XEvent xevent;
+ while ( XCheckTypedWindowEvent( x11Display(), winId(), Expose, &xevent ) &&
+ ! qt_x11EventFilter( &xevent ) &&
+ ! x11Event( &xevent ) ) // send event through filter
+ ;
+ tqrepaint( !testWFlags(WResizeNoErase) || transbg );
+ }
+
+ return TRUE;
+}
+
+
+//
+// Close window event translation.
+//
+bool TQETWidget::translateCloseEvent( const XEvent * )
+{
+ return close(FALSE);
+}
+
+
+/*!
+ Sets the text cursor's flash (blink) time to \a msecs
+ milliseconds. The flash time is the time required to display,
+ invert and restore the caret display. Usually the text cursor is
+ displayed for \a msecs/2 milliseconds, then hidden for \a msecs/2
+ milliseconds, but this may vary.
+
+ Note that on Microsoft Windows, calling this function sets the
+ cursor flash time for all windows.
+
+ \sa cursorFlashTime()
+*/
+void TQApplication::setCursorFlashTime( int msecs )
+{
+ cursor_flash_time = msecs;
+}
+
+
+/*!
+ Returns the text cursor's flash (blink) time in milliseconds. The
+ flash time is the time required to display, invert and restore the
+ caret display.
+
+ The default value on X11 is 1000 milliseconds. On Windows, the
+ control panel value is used.
+
+ Widgets should not cache this value since it may be changed at any
+ time by the user changing the global desktop settings.
+
+ \sa setCursorFlashTime()
+*/
+int TQApplication::cursorFlashTime()
+{
+ return cursor_flash_time;
+}
+
+/*!
+ Sets the time limit that distinguishes a double click from two
+ consecutive mouse clicks to \a ms milliseconds.
+
+ Note that on Microsoft Windows, calling this function sets the
+ double click interval for all windows.
+
+ \sa doubleClickInterval()
+*/
+
+void TQApplication::setDoubleClickInterval( int ms )
+{
+ mouse_double_click_time = ms;
+}
+
+
+/*!
+ Returns the maximum duration for a double click.
+
+ The default value on X11 is 400 milliseconds. On Windows, the
+ control panel value is used.
+
+ \sa setDoubleClickInterval()
+*/
+
+int TQApplication::doubleClickInterval()
+{
+ return mouse_double_click_time;
+}
+
+
+/*!
+ Sets the number of lines to scroll when the mouse wheel is rotated
+ to \a n.
+
+ If this number exceeds the number of visible lines in a certain
+ widget, the widget should interpret the scroll operation as a
+ single page up / page down operation instead.
+
+ \sa wheelScrollLines()
+*/
+void TQApplication::setWheelScrollLines( int n )
+{
+ wheel_scroll_lines = n;
+}
+
+/*!
+ Returns the number of lines to scroll when the mouse wheel is
+ rotated.
+
+ \sa setWheelScrollLines()
+*/
+int TQApplication::wheelScrollLines()
+{
+ return wheel_scroll_lines;
+}
+
+/*!
+ Enables the UI effect \a effect if \a enable is TRUE, otherwise
+ the effect will not be used.
+
+ Note: All effects are disabled on screens running at less than
+ 16-bit color depth.
+
+ \sa isEffectEnabled(), TQt::UIEffect, setDesktopSettingsAware()
+*/
+void TQApplication::setEffectEnabled( TQt::UIEffect effect, bool enable )
+{
+ switch (effect) {
+ case UI_AnimateMenu:
+ if ( enable ) fade_menu = FALSE;
+ animate_menu = enable;
+ break;
+ case UI_FadeMenu:
+ if ( enable )
+ animate_menu = TRUE;
+ fade_menu = enable;
+ break;
+ case UI_AnimateCombo:
+ animate_combo = enable;
+ break;
+ case UI_AnimateTooltip:
+ if ( enable ) fade_tooltip = FALSE;
+ animate_tooltip = enable;
+ break;
+ case UI_FadeTooltip:
+ if ( enable )
+ animate_tooltip = TRUE;
+ fade_tooltip = enable;
+ break;
+ case UI_AnimateToolBox:
+ animate_toolbox = enable;
+ break;
+ default:
+ animate_ui = enable;
+ break;
+ }
+}
+
+/*!
+ Returns TRUE if \a effect is enabled; otherwise returns FALSE.
+
+ By default, TQt will try to use the desktop settings. Call
+ setDesktopSettingsAware(FALSE) to prevent this.
+
+ Note: All effects are disabled on screens running at less than
+ 16-bit color depth.
+
+ \sa setEffectEnabled(), TQt::UIEffect
+*/
+bool TQApplication::isEffectEnabled( TQt::UIEffect effect )
+{
+ if ( TQColor::numBitPlanes() < 16 || !animate_ui )
+ return FALSE;
+
+ switch( effect ) {
+ case UI_AnimateMenu:
+ return animate_menu;
+ case UI_FadeMenu:
+ return fade_menu;
+ case UI_AnimateCombo:
+ return animate_combo;
+ case UI_AnimateTooltip:
+ return animate_tooltip;
+ case UI_FadeTooltip:
+ return fade_tooltip;
+ case UI_AnimateToolBox:
+ return animate_toolbox;
+ default:
+ return animate_ui;
+ }
+}
+
+/*****************************************************************************
+ Session management support
+ *****************************************************************************/
+
+#ifndef TQT_NO_SM_SUPPORT
+
+#include <X11/SM/SMlib.h>
+
+class TQSessionManagerData
+{
+public:
+ TQSessionManagerData( TQSessionManager* mgr, TQString& id, TQString& key )
+ : sm( mgr ), sessionId( id ), sessionKey( key ) {}
+ TQSessionManager* sm;
+ TQStringList restartCommand;
+ TQStringList discardCommand;
+ TQString& sessionId;
+ TQString& sessionKey;
+ TQSessionManager::RestartHint restartHint;
+};
+
+class TQSmSocketReceiver : public TQObject
+{
+ TQ_OBJECT
+public:
+ TQSmSocketReceiver( int socket )
+ : TQObject(0,0)
+ {
+ TQSocketNotifier* sn = new TQSocketNotifier( socket, TQSocketNotifier::Read, this );
+ connect( sn, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( socketActivated(int) ) );
+ }
+
+public Q_SLOTS:
+ void socketActivated(int);
+};
+
+
+static SmcConn smcConnection = 0;
+static bool sm_interactionActive;
+static bool sm_smActive;
+static int sm_interactStyle;
+static int sm_saveType;
+static bool sm_cancel;
+// static bool sm_waitingForPhase2; ### never used?!?
+static bool sm_waitingForInteraction;
+static bool sm_isshutdown;
+// static bool sm_shouldbefast; ### never used?!?
+static bool sm_phase2;
+static bool sm_in_phase2;
+
+static TQSmSocketReceiver* sm_receiver = 0;
+
+static void resetSmState();
+static void sm_setProperty( const char* name, const char* type,
+ int num_vals, SmPropValue* vals);
+static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData,
+ int saveType, Bool shutdown , int interactStyle, Bool fast);
+static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData ) ;
+static void sm_dieCallback( SmcConn smcConn, SmPointer clientData ) ;
+static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer clientData );
+static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer clientData );
+static void sm_interactCallback( SmcConn smcConn, SmPointer clientData );
+static void sm_performSaveYourself( TQSessionManagerData* );
+
+static void resetSmState()
+{
+// sm_waitingForPhase2 = FALSE; ### never used?!?
+ sm_waitingForInteraction = FALSE;
+ sm_interactionActive = FALSE;
+ sm_interactStyle = SmInteractStyleNone;
+ sm_smActive = FALSE;
+ sm_blockUserInput = FALSE;
+ sm_isshutdown = FALSE;
+// sm_shouldbefast = FALSE; ### never used?!?
+ sm_phase2 = FALSE;
+ sm_in_phase2 = FALSE;
+}
+
+
+// theoretically it's possible to set several properties at once. For
+// simplicity, however, we do just one property at a time
+static void sm_setProperty( const char* name, const char* type,
+ int num_vals, SmPropValue* vals)
+{
+ if (num_vals ) {
+ SmProp prop;
+ prop.name = (char*)name;
+ prop.type = (char*)type;
+ prop.num_vals = num_vals;
+ prop.vals = vals;
+
+ SmProp* props[1];
+ props[0] = &prop;
+ SmcSetProperties( smcConnection, 1, props );
+ }
+ else {
+ char* names[1];
+ names[0] = (char*) name;
+ SmcDeleteProperties( smcConnection, 1, names );
+ }
+}
+
+static void sm_setProperty( const TQString& name, const TQString& value)
+{
+ SmPropValue prop;
+ prop.length = value.length();
+ prop.value = (SmPointer) value.latin1();
+ sm_setProperty( name.latin1(), SmARRAY8, 1, &prop );
+}
+
+static void sm_setProperty( const TQString& name, const TQStringList& value)
+{
+ SmPropValue *prop = new SmPropValue[ value.count() ];
+ int count = 0;
+ for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) {
+ prop[ count ].length = (*it).length();
+ prop[ count ].value = (char*)(*it).latin1();
+ ++count;
+ }
+ sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop );
+ delete [] prop;
+}
+
+
+// workaround for broken libsm, see below
+struct TQT_smcConn {
+ unsigned int save_yourself_in_progress : 1;
+ unsigned int shutdown_in_progress : 1;
+};
+
+static void sm_saveYourselfCallback( SmcConn smcConn, SmPointer clientData,
+ int saveType, Bool shutdown , int interactStyle, Bool /*fast*/)
+{
+ if (smcConn != smcConnection )
+ return;
+ sm_cancel = FALSE;
+ sm_smActive = TRUE;
+ sm_isshutdown = shutdown;
+ sm_saveType = saveType;
+ sm_interactStyle = interactStyle;
+// sm_shouldbefast = fast; ### never used?!?
+
+ // ugly workaround for broken libSM. libSM should do that _before_
+ // actually invoking the callback in sm_process.c
+ ( (TQT_smcConn*)smcConn )->save_yourself_in_progress = TRUE;
+ if ( sm_isshutdown )
+ ( (TQT_smcConn*)smcConn )->shutdown_in_progress = TRUE;
+
+ sm_performSaveYourself( (TQSessionManagerData*) clientData );
+ if ( !sm_isshutdown ) // we cannot expect a confirmation message in that case
+ resetSmState();
+}
+
+static void sm_performSaveYourself( TQSessionManagerData* smd )
+{
+ if ( sm_isshutdown )
+ sm_blockUserInput = TRUE;
+
+ TQSessionManager* sm = smd->sm;
+
+ // generate a new session key
+ timeval tv;
+ gettimeofday( &tv, 0 );
+ smd->sessionKey = TQString::number( tv.tv_sec ) + "_" + TQString::number(tv.tv_usec);
+
+ // tell the session manager about our program in best POSIX style
+ sm_setProperty( SmProgram, TQString( tqApp->argv()[0] ) );
+ // tell the session manager about our user as well.
+ struct passwd* entry = getpwuid( geteuid() );
+ if ( entry )
+ sm_setProperty( SmUserID, TQString::tqfromLatin1( entry->pw_name ) );
+
+ // generate a restart and discard command that makes sense
+ TQStringList restart;
+ restart << tqApp->argv()[0] << "-session" << smd->sessionId + "_" + smd->sessionKey;
+ if (qstricmp(tqAppName(), tqAppClass()) != 0)
+ restart << "-name" << tqAppName();
+ sm->setRestartCommand( restart );
+ TQStringList discard;
+ sm->setDiscardCommand( discard );
+
+ switch ( sm_saveType ) {
+ case SmSaveBoth:
+ tqApp->commitData( *sm );
+ if ( sm_isshutdown && sm_cancel)
+ break; // we cancelled the shutdown, no need to save state
+ // fall through
+ case SmSaveLocal:
+ tqApp->saveState( *sm );
+ break;
+ case SmSaveGlobal:
+ tqApp->commitData( *sm );
+ break;
+ default:
+ break;
+ }
+
+ if ( sm_phase2 && !sm_in_phase2 ) {
+ SmcRequestSaveYourselfPhase2( smcConnection, sm_saveYourselfPhase2Callback, (SmPointer*) smd );
+ sm_blockUserInput = FALSE;
+ }
+ else {
+ // close eventual interaction monitors and cancel the
+ // shutdown, if required. Note that we can only cancel when
+ // performing a shutdown, it does not work for checkpoints
+ if ( sm_interactionActive ) {
+ SmcInteractDone( smcConnection, sm_isshutdown && sm_cancel);
+ sm_interactionActive = FALSE;
+ }
+ else if ( sm_cancel && sm_isshutdown ) {
+ if ( sm->allowsErrorInteraction() ) {
+ SmcInteractDone( smcConnection, True );
+ sm_interactionActive = FALSE;
+ }
+ }
+
+ // set restart and discard command in session manager
+ sm_setProperty( SmRestartCommand, sm->restartCommand() );
+ sm_setProperty( SmDiscardCommand, sm->discardCommand() );
+
+ // set the restart hint
+ SmPropValue prop;
+ prop.length = sizeof( int );
+ int value = sm->restartHint();
+ prop.value = (SmPointer) &value;
+ sm_setProperty( SmRestartStyleHint, SmCARD8, 1, &prop );
+
+ // we are done
+ SmcSaveYourselfDone( smcConnection, !sm_cancel );
+ }
+}
+
+static void sm_dieCallback( SmcConn smcConn, SmPointer /* clientData */)
+{
+ if (smcConn != smcConnection )
+ return;
+ resetSmState();
+ TQEvent quitEvent(TQEvent::Quit);
+ TQApplication::sendEvent(tqApp, &quitEvent);
+}
+
+static void sm_shutdownCancelledCallback( SmcConn smcConn, SmPointer /* clientData */)
+{
+ if (smcConn != smcConnection )
+ return;
+ if ( sm_waitingForInteraction )
+ tqApp->exit_loop();
+ resetSmState();
+}
+
+static void sm_saveCompleteCallback( SmcConn smcConn, SmPointer /*clientData */)
+{
+ if (smcConn != smcConnection )
+ return;
+ resetSmState();
+}
+
+static void sm_interactCallback( SmcConn smcConn, SmPointer /* clientData */ )
+{
+ if (smcConn != smcConnection )
+ return;
+ if ( sm_waitingForInteraction )
+ tqApp->exit_loop();
+}
+
+static void sm_saveYourselfPhase2Callback( SmcConn smcConn, SmPointer clientData )
+{
+ if (smcConn != smcConnection )
+ return;
+ sm_in_phase2 = TRUE;
+ sm_performSaveYourself( (TQSessionManagerData*) clientData );
+}
+
+
+void TQSmSocketReceiver::socketActivated(int)
+{
+ IceProcessMessages( SmcGetIceConnection( smcConnection ), 0, 0);
+}
+
+
+#undef Bool
+#include "tqapplication_x11.tqmoc"
+
+TQSessionManager::TQSessionManager( TQApplication * app, TQString &id, TQString& key )
+ : TQObject( app, "session manager" )
+{
+ d = new TQSessionManagerData( this, id, key );
+ d->restartHint = RestartIfRunning;
+
+ resetSmState();
+ char cerror[256];
+ char* myId = 0;
+ char* prevId = (char*)id.latin1(); // we know what we are doing
+
+ SmcCallbacks cb;
+ cb.save_yourself.callback = sm_saveYourselfCallback;
+ cb.save_yourself.client_data = (SmPointer) d;
+ cb.die.callback = sm_dieCallback;
+ cb.die.client_data = (SmPointer) d;
+ cb.save_complete.callback = sm_saveCompleteCallback;
+ cb.save_complete.client_data = (SmPointer) d;
+ cb.shutdown_cancelled.callback = sm_shutdownCancelledCallback;
+ cb.shutdown_cancelled.client_data = (SmPointer) d;
+
+ // avoid showing a warning message below
+ const char* session_manager = getenv("SESSION_MANAGER");
+ if ( !session_manager || !session_manager[0] )
+ return;
+
+ smcConnection = SmcOpenConnection( 0, 0, 1, 0,
+ SmcSaveYourselfProcMask |
+ SmcDieProcMask |
+ SmcSaveCompleteProcMask |
+ SmcShutdownCancelledProcMask,
+ &cb,
+ prevId,
+ &myId,
+ 256, cerror );
+
+ id = TQString::tqfromLatin1( myId );
+ ::free( myId ); // it was allocated by C
+
+ TQString error = cerror;
+ if (!smcConnection ) {
+ qWarning("Session management error: %s", error.latin1() );
+ }
+ else {
+ sm_receiver = new TQSmSocketReceiver( IceConnectionNumber( SmcGetIceConnection( smcConnection ) ) );
+ }
+}
+
+TQSessionManager::~TQSessionManager()
+{
+ if ( smcConnection )
+ SmcCloseConnection( smcConnection, 0, 0 );
+ smcConnection = 0;
+ delete sm_receiver;
+ delete d;
+}
+
+TQString TQSessionManager::sessionId() const
+{
+ return d->sessionId;
+}
+
+TQString TQSessionManager::sessionKey() const
+{
+ return d->sessionKey;
+}
+
+
+void* TQSessionManager::handle() const
+{
+ return (void*) smcConnection;
+}
+
+
+bool TQSessionManager::allowsInteraction()
+{
+ if ( sm_interactionActive )
+ return TRUE;
+
+ if ( sm_waitingForInteraction )
+ return FALSE;
+
+ if ( sm_interactStyle == SmInteractStyleAny ) {
+ sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogNormal,
+ sm_interactCallback, (SmPointer*) this );
+ }
+ if ( sm_waitingForInteraction ) {
+ tqApp->enter_loop();
+ sm_waitingForInteraction = FALSE;
+ if ( sm_smActive ) { // not cancelled
+ sm_interactionActive = TRUE;
+ sm_blockUserInput = FALSE;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool TQSessionManager::allowsErrorInteraction()
+{
+ if ( sm_interactionActive )
+ return TRUE;
+
+ if ( sm_waitingForInteraction )
+ return FALSE;
+
+ if ( sm_interactStyle == SmInteractStyleAny || sm_interactStyle == SmInteractStyleErrors ) {
+ sm_waitingForInteraction = SmcInteractRequest( smcConnection, SmDialogError,
+ sm_interactCallback, (SmPointer*) this );
+ }
+ if ( sm_waitingForInteraction ) {
+ tqApp->enter_loop();
+ sm_waitingForInteraction = FALSE;
+ if ( sm_smActive ) { // not cancelled
+ sm_interactionActive = TRUE;
+ sm_blockUserInput = FALSE;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void TQSessionManager::release()
+{
+ if ( sm_interactionActive ) {
+ SmcInteractDone( smcConnection, False );
+ sm_interactionActive = FALSE;
+ if ( sm_smActive && sm_isshutdown )
+ sm_blockUserInput = TRUE;
+ }
+}
+
+void TQSessionManager::cancel()
+{
+ sm_cancel = TRUE;
+}
+
+void TQSessionManager::setRestartHint( TQSessionManager::RestartHint hint)
+{
+ d->restartHint = hint;
+}
+
+TQSessionManager::RestartHint TQSessionManager::restartHint() const
+{
+ return d->restartHint;
+}
+
+void TQSessionManager::setRestartCommand( const TQStringList& command)
+{
+ d->restartCommand = command;
+}
+
+TQStringList TQSessionManager::restartCommand() const
+{
+ return d->restartCommand;
+}
+
+void TQSessionManager::setDiscardCommand( const TQStringList& command)
+{
+ d->discardCommand = command;
+}
+
+TQStringList TQSessionManager::discardCommand() const
+{
+ return d->discardCommand;
+}
+
+void TQSessionManager::setManagerProperty( const TQString& name, const TQString& value)
+{
+ SmPropValue prop;
+ prop.length = value.length();
+ prop.value = (SmPointer) value.utf8().data();
+ sm_setProperty( name.latin1(), SmARRAY8, 1, &prop );
+}
+
+void TQSessionManager::setManagerProperty( const TQString& name, const TQStringList& value)
+{
+ SmPropValue *prop = new SmPropValue[ value.count() ];
+ int count = 0;
+ for ( TQStringList::ConstIterator it = value.begin(); it != value.end(); ++it ) {
+ prop[ count ].length = (*it).length();
+ prop[ count ].value = (char*)(*it).utf8().data();
+ ++count;
+ }
+ sm_setProperty( name.latin1(), SmLISTofARRAY8, count, prop );
+ delete [] prop;
+}
+
+bool TQSessionManager::isPhase2() const
+{
+ return sm_in_phase2;
+}
+
+void TQSessionManager::requestPhase2()
+{
+ sm_phase2 = TRUE;
+}
+
+
+#endif // TQT_NO_SM_SUPPORT
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqasyncimageio.cpp b/tqtinterface/qt4/src/kernel/tqasyncimageio.cpp
new file mode 100644
index 0000000..508002f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqasyncimageio.cpp
@@ -0,0 +1,1316 @@
+/****************************************************************************
+**
+** Implementation of asynchronous image/movie loading classes
+**
+** Created : 970617
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqasyncimageio.h"
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+
+#include "tqptrlist.h"
+#include "tqgif.h"
+#include <stdlib.h>
+
+// #ifdef USE_QT4
+#if 0
+// [FIXME]
+void qt_init_image_handlers() { printf("[WARNING] void qt_init_image_handlers() unimplemented\n\r"); }
+void qt_init_image_plugins() { printf("[WARNING] void qt_init_image_plugins() unimplemented\n\r"); }
+#else // USE_QT4
+extern void qt_init_image_handlers();
+extern void qt_init_image_plugins();
+#endif // USE_QT4
+
+#define TQ_TRANSPARENT 0x00ffffff
+
+/*!
+ \class TQImageConsumer tqasyncimageio.h
+ \brief The TQImageConsumer class is an abstraction used by TQImageDecoder.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup multimedia
+
+ The TQMovie class, or TQLabel::setMovie(), are easy to use and for
+ most situations do what you want with regards animated images.
+
+ A TQImageConsumer consumes information about changes to the TQImage
+ maintained by a TQImageDecoder. Think of the TQImage as the model or
+ source of the image data, with the TQImageConsumer as a view of
+ that data and the TQImageDecoder being the controller that
+ orchestrates the relationship between the model and the view.
+
+ You'd use the TQImageConsumer class, for example, if you were
+ implementing a web browser with your own image loaders.
+
+ \sa TQImageDecoder
+*/
+
+/*!
+ \fn void TQImageConsumer::changed(const TQRect&)
+
+ Called when the given area of the image has changed.
+*/
+
+/*!
+ \fn void TQImageConsumer::end()
+
+ Called when all the data from all the frames has been decoded and
+ revealed as changed().
+*/
+
+/*!
+ \fn void TQImageConsumer::frameDone()
+
+ One of the two frameDone() functions will be called when a frame
+ of an animated image has ended and been revealed as changed().
+
+ When this function is called, the current image should be
+ displayed.
+
+ The decoder will not make any further changes to the image until
+ the next call to TQImageFormat::decode().
+*/
+
+/*!
+ \overload void TQImageConsumer::frameDone( const TQPoint& offset, const TQRect& rect )
+
+ One of the two frameDone() functions will be called when a frame
+ of an animated image has ended and been revealed as changed().
+
+ When this function is called, the area \a rect in the current
+ image should be moved by \a offset and displayed.
+
+ The decoder will not make any further changes to the image until
+ the next call to TQImageFormat::decode().
+*/
+
+/*!
+ \fn void TQImageConsumer::setLooping(int n)
+
+ Called to indicate that the sequence of frames in the image
+ should be repeated \a n times, including the sequence during
+ decoding.
+
+ \list
+ \i 0 = Forever
+ \i 1 = Only display frames the first time through
+ \i 2 = Repeat once after first pass through images
+ \i etc.
+ \endlist
+
+ To make the TQImageDecoder do this, just delete it and pass the
+ information to it again for decoding (setLooping() will be called
+ again, of course, but that can be ignored), or keep copies of the
+ changed areas at the ends of frames.
+*/
+
+/*!
+ \fn void TQImageConsumer::setFramePeriod(int milliseconds)
+
+ Notes that the frame about to be decoded should not be displayed
+ until the given number of \a milliseconds after the time that this
+ function is called. Of course, the image may not have been
+ decoded by then, in which case the frame should not be displayed
+ until it is complete. A value of -1 (the assumed default)
+ indicates that the image should be displayed even while it is only
+ partially loaded.
+*/
+
+/*!
+ \fn void TQImageConsumer::setSize(int, int)
+
+ This function is called as soon as the size of the image has been
+ determined.
+*/
+
+
+/*!
+ \class TQImageDecoder tqasyncimageio.h
+ \brief The TQImageDecoder class is an incremental image decoder for all supported image formats.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup multimedia
+
+ New formats are installed by creating objects of class
+ TQImageFormatType; the TQMovie class can be used for all installed
+ incremental image formats. TQImageDecoder is only useful for
+ creating new ways of feeding data to an TQImageConsumer.
+
+ A TQImageDecoder is a machine that decodes images. It takes encoded
+ image data via its decode() method and expresses its decoding by
+ supplying information to a TQImageConsumer. It implements its
+ decoding by using a TQImageFormat created by one of the
+ currently-existing TQImageFormatType factory objects.
+
+ TQImageFormatType and TQImageFormat are the classes that you might
+ need to implement support for additional image formats.
+
+ \legalese
+
+ TQt supports GIF reading if it is configured that way during
+ installation (see tqgif.h). If it is, we are required to state that
+ "The Graphics Interchange Format(c) is the Copyright property of
+ CompuServe Incorporated. GIF(sm) is a Service Mark property of
+ CompuServe Incorporated."
+
+ \warning If you are in a country that recognizes software patents
+ and in which Unisys holds a patent on LZW compression and/or
+ decompression and you want to use GIF, Unisys may require you to
+ license that technology. Such countries include Canada, Japan,
+ the USA, France, Germany, Italy and the UK.
+
+ GIF support may be removed completely in a future version of TQt.
+ We recommend using the MNG or PNG format.
+*/
+
+static const int max_header = 32;
+
+
+
+
+
+// See tqgif.h for important information regarding this option
+#if defined(TQT_BUILTIN_GIF_READER) && TQT_BUILTIN_GIF_READER == 1
+class TQGIFFormat : public TQImageFormat {
+public:
+ TQGIFFormat();
+ virtual ~TQGIFFormat();
+
+ int decode(TQImage& img, TQImageConsumer* consumer,
+ const uchar* buffer, int length);
+
+private:
+ void fillRect(TQImage&, int x, int y, int w, int h, TQRgb col);
+ TQRgb color( uchar index ) const;
+
+ // GIF specific stuff
+ TQRgb* globalcmap;
+ TQRgb* localcmap;
+ TQImage backingstore;
+ unsigned char hold[16];
+ bool gif89;
+ int count;
+ int ccount;
+ int expectcount;
+ enum State {
+ Header,
+ LogicalScreenDescriptor,
+ GlobalColorMap,
+ LocalColorMap,
+ Introducer,
+ ImageDescriptor,
+ TableImageLZWSize,
+ ImageDataBlockSize,
+ ImageDataBlock,
+ ExtensionLabel,
+ GraphicControlExtension,
+ ApplicationExtension,
+ NetscapeExtensionBlockSize,
+ NetscapeExtensionBlock,
+ SkipBlockSize,
+ SkipBlock,
+ Done,
+ Error
+ } state;
+ int gncols;
+ int lncols;
+ int ncols;
+ int lzwsize;
+ bool lcmap;
+ int swidth, sheight;
+ int width, height;
+ int left, top, right, bottom;
+ enum Disposal { NoDisposal, DoNotChange, RestoreBackground, RestoreImage };
+ Disposal disposal;
+ bool disposed;
+ int trans_index;
+ bool gcmap;
+ int bgcol;
+ int interlace;
+ int accum;
+ int bitcount;
+
+ enum { max_lzw_bits=12 }; // (poor-compiler's static const int)
+
+ int code_size, clear_code, end_code, max_code_size, max_code;
+ int firstcode, oldcode, incode;
+ short table[2][1<< max_lzw_bits];
+ short stack[(1<<(max_lzw_bits))*2];
+ short *sp;
+ bool needfirst;
+ int x, y;
+ int frame;
+ bool out_of_bounds;
+ bool digress;
+ void nextY(TQImage& img, TQImageConsumer* consumer);
+ void disposePrevious( TQImage& img, TQImageConsumer* consumer );
+};
+
+class TQGIFFormatType : public TQImageFormatType
+{
+ TQImageFormat* decoderFor(const uchar* buffer, int length);
+ const char* formatName() const;
+};
+
+#endif
+
+
+class TQImageDecoderPrivate
+{
+public:
+ TQImageDecoderPrivate()
+ {
+ count = 0;
+ }
+
+ static void cleanup();
+
+ static void ensureFactories()
+ {
+ if ( !factories ) {
+ factories = new TQPtrList<TQImageFormatType>;
+// See tqgif.h for important information regarding this option
+#if defined(TQT_BUILTIN_GIF_READER) && TQT_BUILTIN_GIF_READER == 1
+ gif_decoder_factory = new TQGIFFormatType;
+#endif
+ qt_init_image_handlers();
+ qAddPostRoutine( cleanup );
+ }
+ }
+
+ static TQPtrList<TQImageFormatType> * factories;
+
+// See tqgif.h for important information regarding this option
+#if defined(TQT_BUILTIN_GIF_READER) && TQT_BUILTIN_GIF_READER == 1
+ static TQGIFFormatType * gif_decoder_factory;
+#endif
+
+ uchar header[max_header];
+ int count;
+};
+
+TQPtrList<TQImageFormatType> * TQImageDecoderPrivate::factories = 0;
+// See tqgif.h for important information regarding this option
+#if defined(TQT_BUILTIN_GIF_READER) && TQT_BUILTIN_GIF_READER == 1
+TQGIFFormatType * TQImageDecoderPrivate::gif_decoder_factory = 0;
+#endif
+
+
+void TQImageDecoderPrivate::cleanup()
+{
+ delete factories;
+ factories = 0;
+// See tqgif.h for important information regarding this option
+#if defined(TQT_BUILTIN_GIF_READER) && TQT_BUILTIN_GIF_READER == 1
+ delete gif_decoder_factory;
+ gif_decoder_factory = 0;
+#endif
+}
+
+
+/*!
+ Constructs a TQImageDecoder that will send change information to
+ the TQImageConsumer \a c.
+*/
+TQImageDecoder::TQImageDecoder(TQImageConsumer* c)
+{
+ qt_init_image_handlers();
+ d = new TQImageDecoderPrivate;
+ TQ_CHECK_PTR(d);
+ consumer = c;
+ actual_decoder = 0;
+}
+
+/*!
+ Destroys a TQImageDecoder. The image it built is destroyed. The
+ decoder built by the factory for the file format is destroyed. The
+ consumer for which it decoded the image is \e not destroyed.
+*/
+TQImageDecoder::~TQImageDecoder()
+{
+ delete d;
+ delete actual_decoder;
+}
+
+/*!
+ \fn const TQImage& TQImageDecoder::image()
+
+ Returns the image currently being decoded.
+*/
+
+static bool plugins_loaded = FALSE;
+
+/*!
+ Call this function to decode some data into image changes. The
+ data in \a buffer will be decoded, sending change information to
+ the TQImageConsumer of this TQImageDecoder until one of the change
+ functions of the consumer returns FALSE. The length of the data is
+ given in \a length.
+
+ Returns the number of bytes consumed: 0 if consumption is
+ complete, and -1 if decoding fails due to invalid data.
+*/
+int TQImageDecoder::decode(const uchar* buffer, int length)
+{
+ if (!actual_decoder) {
+ int i=0;
+
+ while (i < length && d->count < max_header)
+ d->header[d->count++] = buffer[i++];
+
+ TQImageDecoderPrivate::ensureFactories();
+
+ for (TQImageFormatType* f = TQImageDecoderPrivate::factories->first();
+ f && !actual_decoder;
+ f = TQImageDecoderPrivate::factories->next())
+ {
+ actual_decoder = f->decoderFor(d->header, d->count);
+ }
+ if ( !actual_decoder && !plugins_loaded) {
+ qt_init_image_plugins();
+ plugins_loaded = TRUE;
+
+ for (TQImageFormatType* f = TQImageDecoderPrivate::factories->first();
+ f && !actual_decoder;
+ f = TQImageDecoderPrivate::factories->next())
+ {
+ actual_decoder = f->decoderFor(d->header, d->count);
+ }
+ }
+
+ if (!actual_decoder) {
+ if ( d->count < max_header ) {
+ // not enough info yet
+ return i;
+ } else {
+ // failure - nothing matches max_header bytes
+ return -1;
+ }
+ }
+ }
+ return actual_decoder->decode(img, consumer, buffer, length);
+}
+
+/*!
+ Returns a TQImageFormatType by name. This might be used when the
+ user needs to force data to be interpreted as being in a certain
+ format. \a name is one of the formats listed by
+ TQImageDecoder::inputFormats(). Note that you will still need to
+ supply decodable data to result->decoderFor() before you can begin
+ decoding the data.
+*/
+TQImageFormatType* TQImageDecoder::format( const char* name )
+{
+ TQImageDecoderPrivate::ensureFactories();
+ qt_init_image_plugins();
+
+ for (TQImageFormatType* f = TQImageDecoderPrivate::factories->first();
+ f;
+ f = TQImageDecoderPrivate::factories->next())
+ {
+ if ( qstricmp(name,f->formatName())==0 )
+ return f;
+ }
+ return 0;
+}
+
+/*!
+ Call this function to tqfind the name of the format of the given
+ header. The returned string is statically allocated. The function
+ will look at the first \a length characters in the \a buffer.
+
+ Returns 0 if the format is not recognized.
+*/
+const char* TQImageDecoder::formatName(const uchar* buffer, int length)
+{
+ TQImageDecoderPrivate::ensureFactories();
+
+ const char* name = 0;
+ for (TQImageFormatType* f = TQImageDecoderPrivate::factories->first();
+ f && !name;
+ f = TQImageDecoderPrivate::factories->next())
+ {
+ TQImageFormat *decoder = f->decoderFor(buffer, length);
+ if (decoder) {
+ name = f->formatName();
+ delete decoder;
+ }
+ }
+ if ( !name && !plugins_loaded) {
+ qt_init_image_plugins();
+ plugins_loaded = TRUE;
+ for (TQImageFormatType* f = TQImageDecoderPrivate::factories->first();
+ f && !name;
+ f = TQImageDecoderPrivate::factories->next())
+ {
+ TQImageFormat *decoder = f->decoderFor(buffer, length);
+ if (decoder) {
+ name = f->formatName();
+ delete decoder;
+ }
+ }
+ }
+
+ return name;
+}
+
+/*!
+ Returns a sorted list of formats for which asynchronous loading is
+ supported.
+*/
+TQStrList TQImageDecoder::inputFormats()
+{
+ TQImageDecoderPrivate::ensureFactories();
+ qt_init_image_plugins();
+
+ TQStrList result;
+
+ for (TQImageFormatType* f = TQImageDecoderPrivate::factories->first();
+ f;
+ f = TQImageDecoderPrivate::factories->next())
+ {
+ if ( !result.tqcontains( f->formatName() ) ) {
+ result.inSort( f->formatName() );
+ }
+ }
+
+ return result;
+}
+
+/*!
+ Registers the new TQImageFormatType \a f. This is not needed in
+ application code because factories call this themselves.
+*/
+void TQImageDecoder::registerDecoderFactory(TQImageFormatType* f)
+{
+ TQImageDecoderPrivate::ensureFactories();
+
+ TQImageDecoderPrivate::factories->insert(0,f);
+}
+
+/*!
+ Unregisters the TQImageFormatType \a f. This is not needed in
+ application code because factories call this themselves.
+*/
+void TQImageDecoder::unregisterDecoderFactory(TQImageFormatType* f)
+{
+ if ( !TQImageDecoderPrivate::factories )
+ return;
+
+ TQImageDecoderPrivate::factories->remove(f);
+}
+
+/*!
+ \class TQImageFormat tqasyncimageio.h
+ \brief The TQImageFormat class is an incremental image decoder for a specific image format.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup multimedia
+
+ By making a derived class of TQImageFormatType, which in turn
+ creates objects that are a subclass of TQImageFormat, you can add
+ support for more incremental image formats, allowing such formats
+ to be sources for a TQMovie or for the first frame of the image
+ stream to be loaded as a TQImage or TQPixmap.
+
+ Your new subclass must reimplement the decode() function in order
+ to process your new format.
+
+ New TQImageFormat objects are generated by new TQImageFormatType
+ factories.
+*/
+
+/*!
+ Destroys the object.
+
+ \internal
+ More importantly, destroys derived classes.
+*/
+TQImageFormat::~TQImageFormat()
+{
+}
+
+/*!
+ \fn int TQImageFormat::decode(TQImage& img, TQImageConsumer* consumer, const uchar* buffer, int length)
+
+ New subclasses must reimplement this method.
+
+ It should decode some or all of the bytes from \a buffer into \a
+ img, calling the methods of \a consumer as the decoding proceeds
+ to inform that consumer of changes to the image. The length of the
+ data is given in \a length. The consumer may be 0, in which case
+ the function should just process the data into \a img without
+ telling any consumer about the changes. Note that the decoder must
+ store enough state to be able to continue in subsequent calls to
+ this method - this is the essence of the incremental image
+ loading.
+
+ The function should return without processing all the data if it
+ reaches the end of a frame in the input.
+
+ The function must return the number of bytes it has processed.
+*/
+
+/*!
+ \class TQImageFormatType tqasyncimageio.h
+ \brief The TQImageFormatType class is a factory that makes TQImageFormat objects.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup multimedia
+
+ Whereas the TQImageIO class allows for \e complete loading of
+ images, TQImageFormatType allows for \e incremental loading of
+ images.
+
+ New image file formats are installed by creating objects of
+ derived classes of TQImageFormatType. They must implement
+ decoderFor() and formatName().
+
+ TQImageFormatType is a very simple class. Its only task is to
+ recognize image data in some format and make a new object,
+ subclassed from TQImageFormat, which can decode that format.
+
+ The factories for formats built into TQt are automatically defined
+ before any other factory is initialized. If two factories would
+ recognize an image format, the factory created last will override
+ the earlier one; you can thus override current and future built-in
+ formats.
+*/
+
+/*!
+ \fn virtual TQImageFormat* TQImageFormatType::decoderFor(const uchar* buffer, int length)
+
+ Returns a decoder for decoding an image that starts with the bytes
+ in \a buffer. The length of the data is given in \a length. This
+ function should only return a decoder if it is certain that the
+ decoder applies to data with the given header. Returns 0 if there
+ is insufficient data in the header to make a positive
+ identification or if the data is not recognized.
+*/
+
+/*!
+ \fn virtual const char* TQImageFormatType::formatName() const
+
+ Returns the name of the format supported by decoders from this
+ factory. The string is statically allocated.
+*/
+
+/*!
+ Constructs a factory. It automatically registers itself with
+ TQImageDecoder.
+*/
+TQImageFormatType::TQImageFormatType()
+{
+ TQImageDecoder::registerDecoderFactory(this);
+}
+
+/*!
+ Destroys a factory. It automatically unregisters itself from
+ TQImageDecoder.
+*/
+TQImageFormatType::~TQImageFormatType()
+{
+ TQImageDecoder::unregisterDecoderFactory(this);
+}
+
+
+/*!
+ Returns TRUE if TQt was compiled with built-in GIF reading support;
+ otherwise returns FALSE.
+*/
+bool qt_builtin_gif_reader()
+{
+#if defined(TQT_BUILTIN_GIF_READER)
+ return TQT_BUILTIN_GIF_READER == 1;
+#else
+ return 0;
+#endif
+}
+
+// See tqgif.h for important information regarding this option
+#if defined(TQT_BUILTIN_GIF_READER) && TQT_BUILTIN_GIF_READER == 1
+
+/* -- NOTDOC
+ \class TQGIFFormat tqasyncimageio.h
+ \brief Incremental image decoder for GIF image format.
+
+ \ingroup images
+ \ingroup graphics
+
+ This subclass of TQImageFormat decodes GIF format images,
+ including animated GIFs. Internally in
+*/
+
+/*!
+ Constructs a TQGIFFormat.
+*/
+TQGIFFormat::TQGIFFormat()
+{
+ globalcmap = 0;
+ localcmap = 0;
+ lncols = 0;
+ gncols = 0;
+ disposal = NoDisposal;
+ out_of_bounds = FALSE;
+ disposed = TRUE;
+ frame = -1;
+ state = Header;
+ count = 0;
+ lcmap = FALSE;
+}
+
+/*!
+ Destroys a TQGIFFormat.
+*/
+TQGIFFormat::~TQGIFFormat()
+{
+ if (globalcmap) delete[] globalcmap;
+ if ( localcmap ) delete[] localcmap;
+}
+
+
+/* -- NOTDOC
+ \class TQGIFFormatType tqasyncimageio.h
+ \brief Incremental image decoder for GIF image format.
+
+ \ingroup images
+ \ingroup graphics
+
+ This subclass of TQImageFormatType recognizes GIF
+ format images, creating a TQGIFFormat when required. An instance
+ of this class is created automatically before any other factories,
+ so you should have no need for such objects.
+*/
+
+TQImageFormat* TQGIFFormatType::decoderFor(
+ const uchar* buffer, int length)
+{
+ if (length < 6) return 0;
+ if (buffer[0]=='G'
+ && buffer[1]=='I'
+ && buffer[2]=='F'
+ && buffer[3]=='8'
+ && (buffer[4]=='9' || buffer[4]=='7')
+ && buffer[5]=='a')
+ return new TQGIFFormat;
+ return 0;
+}
+
+const char* TQGIFFormatType::formatName() const
+{
+ return "GIF";
+}
+
+
+void TQGIFFormat::disposePrevious( TQImage& img, TQImageConsumer* consumer )
+{
+ if ( out_of_bounds ) // flush anything that survived
+ consumer->changed(TQRect(0,0,swidth,sheight));
+
+ // Handle disposal of previous image before processing next one
+
+ if ( disposed ) return;
+
+ int l = TQMIN(swidth-1,left);
+ int r = TQMIN(swidth-1,right);
+ int t = TQMIN(sheight-1,top);
+ int b = TQMIN(sheight-1,bottom);
+
+ switch (disposal) {
+ case NoDisposal:
+ break;
+ case DoNotChange:
+ break;
+ case RestoreBackground:
+ if (trans_index>=0) {
+ // Easy: we use the transtqparent color
+ fillRect(img, l, t, r-l+1, b-t+1, TQ_TRANSPARENT);
+ } else if (bgcol>=0) {
+ // Easy: we use the bgcol given
+ fillRect(img, l, t, r-l+1, b-t+1, color(bgcol));
+ } else {
+ // Impossible: We don't know of a bgcol - use pixel 0
+ TQRgb** line = (TQRgb **)img.jumpTable();
+ fillRect(img, l, t, r-l+1, b-t+1, line[0][0]);
+ }
+ if (consumer)
+ consumer->changed(TQRect(l, t, r-l+1, b-t+1));
+ break;
+ case RestoreImage: {
+ if ( frame >= 0 ) {
+ TQRgb** line = (TQRgb **)img.jumpTable();
+ for (int ln=t; ln<=b; ln++) {
+ memcpy(line[ln]+l,
+ backingstore.scanLine(ln-t),
+ (r-l+1)*sizeof(TQRgb) );
+ }
+ consumer->changed(TQRect(l, t, r-l+1, b-t+1));
+ }
+ }
+ }
+ disposal = NoDisposal; // Until an extension says otherwise.
+
+ disposed = TRUE;
+}
+
+/*!
+ This function decodes some data into image changes.
+
+ Returns the number of bytes consumed.
+*/
+int TQGIFFormat::decode(TQImage& img, TQImageConsumer* consumer,
+ const uchar* buffer, int length)
+{
+ // We are required to state that
+ // "The Graphics Interchange Format(c) is the Copyright property of
+ // CompuServe Incorporated. GIF(sm) is a Service Mark property of
+ // CompuServe Incorporated."
+
+#define LM(l, m) (((m)<<8)|l)
+ digress = FALSE;
+ int initial = length;
+ TQRgb** line = (TQRgb **)img.jumpTable();
+ while (!digress && length) {
+ length--;
+ unsigned char ch=*buffer++;
+ switch (state) {
+ case Header:
+ hold[count++]=ch;
+ if (count==6) {
+ // Header
+ gif89=(hold[3]!='8' || hold[4]!='7');
+ state=LogicalScreenDescriptor;
+ count=0;
+ }
+ break;
+ case LogicalScreenDescriptor:
+ hold[count++]=ch;
+ if (count==7) {
+ // Logical Screen Descriptor
+ swidth=LM(hold[0], hold[1]);
+ sheight=LM(hold[2], hold[3]);
+ gcmap=!!(hold[4]&0x80);
+ //UNUSED: bpchan=(((hold[4]&0x70)>>3)+1);
+ //UNUSED: gcmsortflag=!!(hold[4]&0x08);
+ gncols=2<<(hold[4]&0x7);
+ bgcol=(gcmap) ? hold[5] : -1;
+ //aspect=hold[6] ? double(hold[6]+15)/64.0 : 1.0;
+
+ trans_index = -1;
+ count=0;
+ ncols=gncols;
+ if (gcmap) {
+ ccount=0;
+ state=GlobalColorMap;
+ globalcmap = new TQRgb[gncols+1]; // +1 for trans_index
+ globalcmap[gncols] = TQ_TRANSPARENT;
+ } else {
+ state=Introducer;
+ }
+ }
+ break;
+ case GlobalColorMap: case LocalColorMap:
+ hold[count++]=ch;
+ if (count==3) {
+ TQRgb rgb = tqRgb(hold[0], hold[1], hold[2]);
+ if ( state == LocalColorMap ) {
+ if ( ccount < lncols )
+ localcmap[ccount] = rgb;
+ } else {
+ globalcmap[ccount] = rgb;
+ }
+ if (++ccount >= ncols) {
+ if ( state == LocalColorMap )
+ state=TableImageLZWSize;
+ else
+ state=Introducer;
+ }
+ count=0;
+ }
+ break;
+ case Introducer:
+ hold[count++]=ch;
+ switch (ch) {
+ case ',':
+ state=ImageDescriptor;
+ break;
+ case '!':
+ state=ExtensionLabel;
+ break;
+ case ';':
+ if (consumer) {
+ if ( out_of_bounds ) // flush anything that survived
+ consumer->changed(TQRect(0,0,swidth,sheight));
+ consumer->end();
+ }
+ state=Done;
+ break;
+ default:
+ digress=TRUE;
+ // Unexpected Introducer - ignore block
+ state=Error;
+ }
+ break;
+ case ImageDescriptor:
+ hold[count++]=ch;
+ if (count==10) {
+ int newleft=LM(hold[1], hold[2]);
+ int newtop=LM(hold[3], hold[4]);
+ int newwidth=LM(hold[5], hold[6]);
+ int newheight=LM(hold[7], hold[8]);
+
+ // disbelieve ridiculous logical screen sizes,
+ // unless the image frames are also large.
+ if ( swidth/10 > TQMAX(newwidth,200) )
+ swidth = -1;
+ if ( sheight/10 > TQMAX(newheight,200) )
+ sheight = -1;
+
+ if ( swidth <= 0 )
+ swidth = newleft + newwidth;
+ if ( sheight <= 0 )
+ sheight = newtop + newheight;
+
+ if (img.isNull()) {
+ img.create(swidth, sheight, 32);
+ memset( img.bits(), 0, img.numBytes() );
+ if (consumer) consumer->setSize(swidth, sheight);
+ }
+ img.setAlphaBuffer(trans_index >= 0);
+ line = (TQRgb **)img.jumpTable();
+
+ disposePrevious( img, consumer );
+ disposed = FALSE;
+
+ left = newleft;
+ top = newtop;
+ width = newwidth;
+ height = newheight;
+
+ right=TQMAX( 0, TQMIN(left+width, swidth)-1);
+ bottom=TQMAX(0, TQMIN(top+height, sheight)-1);
+ lcmap=!!(hold[9]&0x80);
+ interlace=!!(hold[9]&0x40);
+ //bool lcmsortflag=!!(hold[9]&0x20);
+ lncols=lcmap ? (2<<(hold[9]&0x7)) : 0;
+ if (lncols) {
+ if ( localcmap )
+ delete [] localcmap;
+ localcmap = new TQRgb[lncols+1];
+ localcmap[lncols] = TQ_TRANSPARENT;
+ ncols = lncols;
+ } else {
+ ncols = gncols;
+ }
+ frame++;
+ if ( frame == 0 ) {
+ if ( left || top || width<swidth || height<sheight ) {
+ // Not full-size image - erase with bg or transtqparent
+ if ( trans_index >= 0 ) {
+ fillRect(img, 0, 0, swidth, sheight, color(trans_index));
+ if (consumer) consumer->changed(TQRect(0,0,swidth,sheight));
+ } else if ( bgcol>=0 ) {
+ fillRect(img, 0, 0, swidth, sheight, color(bgcol));
+ if (consumer) consumer->changed(TQRect(0,0,swidth,sheight));
+ }
+ }
+ }
+
+ if ( disposal == RestoreImage ) {
+ int l = TQMIN(swidth-1,left);
+ int r = TQMIN(swidth-1,right);
+ int t = TQMIN(sheight-1,top);
+ int b = TQMIN(sheight-1,bottom);
+ int w = r-l+1;
+ int h = b-t+1;
+
+ if (backingstore.width() < w
+ || backingstore.height() < h) {
+ // We just use the backing store as a byte array
+ backingstore.create( TQMAX(backingstore.width(), w),
+ TQMAX(backingstore.height(), h),
+ 32);
+ memset( img.bits(), 0, img.numBytes() );
+ }
+ for (int ln=0; ln<h; ln++) {
+ memcpy(backingstore.scanLine(ln),
+ line[t+ln]+l, w*sizeof(TQRgb));
+ }
+ }
+
+ count=0;
+ if (lcmap) {
+ ccount=0;
+ state=LocalColorMap;
+ } else {
+ state=TableImageLZWSize;
+ }
+ x = left;
+ y = top;
+ accum = 0;
+ bitcount = 0;
+ sp = stack;
+ firstcode = oldcode = 0;
+ needfirst = FALSE;
+ out_of_bounds = left>=swidth || y>=sheight;
+ }
+ break;
+ case TableImageLZWSize: {
+ lzwsize=ch;
+ if ( lzwsize > max_lzw_bits ) {
+ state=Error;
+ } else {
+ code_size=lzwsize+1;
+ clear_code=1<<lzwsize;
+ end_code=clear_code+1;
+ max_code_size=2*clear_code;
+ max_code=clear_code+2;
+ int i;
+ for (i=0; i<clear_code && i<(1<<max_lzw_bits); i++) {
+ table[0][i]=0;
+ table[1][i]=i;
+ }
+ for (i=clear_code; i<(1<<max_lzw_bits); i++) {
+ table[0][i]=table[1][i]=0;
+ }
+ state=ImageDataBlockSize;
+ }
+ count=0;
+ break;
+ } case ImageDataBlockSize:
+ expectcount=ch;
+ if (expectcount) {
+ state=ImageDataBlock;
+ } else {
+ if (consumer) {
+ consumer->frameDone();
+ digress = TRUE;
+ }
+
+ state=Introducer;
+ }
+ break;
+ case ImageDataBlock:
+ count++;
+ accum|=(ch<<bitcount);
+ bitcount+=8;
+ while (bitcount>=code_size && state==ImageDataBlock) {
+ int code=accum&((1<<code_size)-1);
+ bitcount-=code_size;
+ accum>>=code_size;
+
+ if (code==clear_code) {
+ if (!needfirst) {
+ int i;
+ code_size=lzwsize+1;
+ max_code_size=2*clear_code;
+ max_code=clear_code+2;
+ for (i=0; i<clear_code; i++) {
+ table[0][i]=0;
+ table[1][i]=i;
+ }
+ for (i=clear_code; i<(1<<max_lzw_bits); i++) {
+ table[0][i]=table[1][i]=0;
+ }
+ }
+ needfirst=TRUE;
+ } else if (code==end_code) {
+ bitcount = -32768;
+ // Left the block end arrive
+ } else {
+ if (needfirst) {
+ firstcode=oldcode=code;
+ if (!out_of_bounds && line && firstcode!=trans_index)
+ line[y][x] = color(firstcode);
+ x++;
+ if (x>=swidth) out_of_bounds = TRUE;
+ needfirst=FALSE;
+ if (x>=left+width) {
+ x=left;
+ out_of_bounds = left>=swidth || y>=sheight;
+ nextY(img,consumer);
+ }
+ } else {
+ incode=code;
+ if (code>=max_code) {
+ *sp++=firstcode;
+ code=oldcode;
+ }
+ while (code>=clear_code) {
+ *sp++=table[1][code];
+ if (code==table[0][code]) {
+ state=Error;
+ break;
+ }
+ if (sp-stack>=(1<<(max_lzw_bits))*2) {
+ state=Error;
+ break;
+ }
+ code=table[0][code];
+ }
+ *sp++=firstcode=table[1][code];
+ code=max_code;
+ if (code<(1<<max_lzw_bits)) {
+ table[0][code]=oldcode;
+ table[1][code]=firstcode;
+ max_code++;
+ if ((max_code>=max_code_size)
+ && (max_code_size<(1<<max_lzw_bits)))
+ {
+ max_code_size*=2;
+ code_size++;
+ }
+ }
+ oldcode=incode;
+ while (sp>stack) {
+ --sp;
+ if (!out_of_bounds && line && *sp!=trans_index)
+ line[y][x] = color(*sp);
+ x++;
+ if (x>=swidth) out_of_bounds = TRUE;
+ if (x>=left+width) {
+ x=left;
+ out_of_bounds = left>=swidth || y>=sheight;
+ nextY(img,consumer);
+ }
+ }
+ }
+ }
+ }
+ if (count==expectcount) {
+ count=0;
+ state=ImageDataBlockSize;
+ }
+ break;
+ case ExtensionLabel:
+ switch (ch) {
+ case 0xf9:
+ state=GraphicControlExtension;
+ break;
+ case 0xff:
+ state=ApplicationExtension;
+ break;
+#if 0
+ case 0xfe:
+ state=CommentExtension;
+ break;
+ case 0x01:
+ break;
+#endif
+ default:
+ state=SkipBlockSize;
+ }
+ count=0;
+ break;
+ case ApplicationExtension:
+ if (count<11) hold[count]=ch;
+ count++;
+ if (count==hold[0]+1) {
+ if (tqstrncmp((char*)(hold+1), "NETSCAPE", 8)==0) {
+ // Looping extension
+ state=NetscapeExtensionBlockSize;
+ } else {
+ state=SkipBlockSize;
+ }
+ count=0;
+ }
+ break;
+ case NetscapeExtensionBlockSize:
+ expectcount=ch;
+ count=0;
+ if (expectcount) state=NetscapeExtensionBlock;
+ else state=Introducer;
+ break;
+ case NetscapeExtensionBlock:
+ if (count<3) hold[count]=ch;
+ count++;
+ if (count==expectcount) {
+ int loop = hold[0]+hold[1]*256;
+ if (consumer) consumer->setLooping(loop);
+ state=SkipBlockSize; // Ignore further blocks
+ }
+ break;
+ case GraphicControlExtension:
+ if (count<5) hold[count]=ch;
+ count++;
+ if (count==hold[0]+1) {
+ disposePrevious( img, consumer );
+ disposal=Disposal((hold[1]>>2)&0x7);
+ //UNUSED: waitforuser=!!((hold[1]>>1)&0x1);
+ int delay=count>3 ? LM(hold[2], hold[3]) : 1;
+ // IE and mozilla use a minimum delay of 10. With the minumum delay of 10
+ // we are compatible to them and avoid huge loads on the app and xserver.
+ if ( delay < 10 )
+ delay = 10;
+
+ bool havetrans=hold[1]&0x1;
+ trans_index = havetrans ? hold[4] : -1;
+
+ if (consumer) consumer->setFramePeriod(delay*10);
+ count=0;
+ state=SkipBlockSize;
+ }
+ break;
+ case SkipBlockSize:
+ expectcount=ch;
+ count=0;
+ if (expectcount) state=SkipBlock;
+ else state=Introducer;
+ break;
+ case SkipBlock:
+ count++;
+ if (count==expectcount) state=SkipBlockSize;
+ break;
+ case Done:
+ digress=TRUE;
+ /* Netscape ignores the junk, so we do too.
+ length++; // Unget
+ state=Error; // More calls to this is an error
+ */
+ break;
+ case Error:
+ return -1; // Called again after done.
+ }
+ }
+ return initial-length;
+}
+
+void TQGIFFormat::fillRect(TQImage& img, int col, int row, int w, int h, TQRgb color)
+{
+ if (w>0) {
+ TQRgb** line = (TQRgb **)img.jumpTable() + row;
+ for (int j=0; j<h; j++) {
+ for ( int i=0; i<w; i++ ) {
+ *(line[j]+col+i) = color;
+ }
+ }
+ }
+}
+
+void TQGIFFormat::nextY(TQImage& img, TQImageConsumer* consumer)
+{
+ int my;
+ switch (interlace) {
+ case 0:
+ // Non-interlaced
+ if (consumer && !out_of_bounds)
+ consumer->changed(TQRect(left, y, right-left+1, 1));
+ y++;
+ break;
+ case 1:
+ {
+ int i;
+ my = TQMIN(7, bottom-y);
+ if ( trans_index < 0 ) // Don't dup with transparency
+ for (i=1; i<=my; i++)
+ memcpy(img.scanLine(y+i)+left, img.scanLine(y)+left,
+ (right-left+1)*sizeof(TQRgb));
+ if (consumer && !out_of_bounds)
+ consumer->changed(TQRect(left, y, right-left+1, my+1));
+ y+=8;
+ if (y>bottom) {
+ interlace++; y=top+4;
+ if (y > bottom) { // for really broken GIFs with bottom < 5
+ interlace=2;
+ y = top + 2;
+ if (y > bottom) { // for really broken GIF with bottom < 3
+ interlace = 0;
+ y = top + 1;
+ }
+ }
+ }
+ } break;
+ case 2:
+ {
+ int i;
+ my = TQMIN(3, bottom-y);
+ if ( trans_index < 0 ) // Don't dup with transparency
+ for (i=1; i<=my; i++)
+ memcpy(img.scanLine(y+i)+left, img.scanLine(y)+left,
+ (right-left+1)*sizeof(TQRgb));
+ if (consumer && !out_of_bounds)
+ consumer->changed(TQRect(left, y, right-left+1, my+1));
+ y+=8;
+ if (y>bottom) {
+ interlace++; y=top+2;
+ if (y > bottom) { // for really broken GIF with bottom < 3
+ interlace = 3;
+ y = top + 1;
+ }
+ }
+ } break;
+ case 3:
+ {
+ int i;
+ my = TQMIN(1, bottom-y);
+ if ( trans_index < 0 ) // Don't dup with transparency
+ for (i=1; i<=my; i++)
+ memcpy(img.scanLine(y+i)+left, img.scanLine(y)+left,
+ (right-left+1)*sizeof(TQRgb));
+ if (consumer && !out_of_bounds)
+ consumer->changed(TQRect(left, y, right-left+1, my+1));
+ y+=4;
+ if (y>bottom) { interlace++; y=top+1; }
+ } break;
+ case 4:
+ if (consumer && !out_of_bounds)
+ consumer->changed(TQRect(left, y, right-left+1, 1));
+ y+=2;
+ }
+
+ // Consume bogus extra lines
+ if (y >= sheight) out_of_bounds=TRUE; //y=bottom;
+}
+
+TQRgb TQGIFFormat::color( uchar index ) const
+{
+ if ( index == trans_index || index > ncols )
+ return TQ_TRANSPARENT;
+ TQRgb *map = lcmap ? localcmap : globalcmap;
+ return map ? map[index] : 0;
+}
+
+
+
+#endif // TQT_BUILTIN_GIF_READER
+
+#endif // TQT_NO_ASYNC_IMAGE_IO
diff --git a/tqtinterface/qt4/src/kernel/tqasyncimageio.h b/tqtinterface/qt4/src/kernel/tqasyncimageio.h
new file mode 100644
index 0000000..75e1f60
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqasyncimageio.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Definition of asynchronous image/movie loading classes
+**
+** Created : 970617
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQASYNCIMAGEIO_H
+#define TQASYNCIMAGEIO_H
+
+#ifndef TQT_H
+#include "tqimage.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+
+#if __GNUC__ - 0 > 3
+#pragma GCC system_header
+#endif
+
+class TQ_EXPORT TQImageConsumer {
+public:
+ virtual void end()=0;
+
+ // Change transfer type 1.
+ virtual void changed( const TQRect& ) = 0;
+ virtual void frameDone() = 0;
+
+ // Change transfer type 2.
+ virtual void frameDone( const TQPoint&, const TQRect& ) = 0;
+
+ virtual void setLooping( int ) = 0;
+ virtual void setFramePeriod( int ) = 0;
+ virtual void setSize( int, int ) = 0;
+};
+
+class TQ_EXPORT TQImageFormat {
+public:
+ virtual ~TQImageFormat();
+ virtual int decode( TQImage& img, TQImageConsumer* consumer,
+ const uchar* buffer, int length ) = 0;
+};
+
+class TQ_EXPORT TQImageFormatType {
+public:
+ virtual ~TQImageFormatType();
+ virtual TQImageFormat* decoderFor( const uchar* buffer, int length ) = 0;
+ virtual const char* formatName() const = 0;
+protected:
+ TQImageFormatType();
+};
+
+class TQImageDecoderPrivate;
+class TQ_EXPORT TQImageDecoder {
+public:
+ TQImageDecoder( TQImageConsumer* c );
+ ~TQImageDecoder();
+
+ const TQImage& image() { return img; }
+ int decode( const uchar* buffer, int length );
+
+ static const char* formatName( const uchar* buffer, int length );
+ static TQImageFormatType* format( const char* name ); // direct use - no decode()
+
+ static TQStrList inputFormats();
+ static void registerDecoderFactory( TQImageFormatType* );
+ static void unregisterDecoderFactory( TQImageFormatType* );
+
+private:
+ TQImageFormat* actual_decoder;
+ TQImageConsumer* consumer;
+ TQImage img;
+ TQImageDecoderPrivate *d;
+};
+
+#endif // TQT_NO_ASYNC_IMAGE_IO
+
+#endif // TQASYNCIMAGEIO_H
diff --git a/tqtinterface/qt4/src/kernel/tqasyncio.cpp b/tqtinterface/qt4/src/kernel/tqasyncio.cpp
new file mode 100644
index 0000000..ee479e0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqasyncio.cpp
@@ -0,0 +1,360 @@
+/****************************************************************************
+**
+** Implementation of asynchronous I/O classes
+**
+** Created : 970617
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqasyncio.h"
+#include "tqiodevice.h"
+#include <stdlib.h>
+
+#ifndef TQT_NO_ASYNC_IO
+
+/*!
+ \class TQAsyncIO tqasyncio.h
+ \obsolete
+ \brief The TQAsyncIO class encapsulates I/O asynchronicity.
+
+ The TQt classes for asynchronous input/output provide a simple
+ mechanism to allow large files or slow data sources to be processed
+ without using large amounts of memory or blocking the user interface.
+
+ This facility is used in TQt to drive animated images. See TQImageConsumer.
+*/
+
+
+/*!
+ Destroys the async IO object.
+*/
+TQAsyncIO::~TQAsyncIO()
+{
+}
+
+/*!
+ Ensures that only one object, \a obj and function, \a member, can
+ respond to changes in readiness.
+*/
+void TQAsyncIO::connect(TQObject* obj, const char *member)
+{
+ signal.disconnect(0, 0);
+ signal.connect(obj, member);
+}
+
+/*!
+ Derived classes should call this when they change from being
+ unready to ready.
+*/
+void TQAsyncIO::ready()
+{
+ signal.activate();
+}
+
+
+
+/*!
+ \class TQDataSink tqasyncio.h
+ \obsolete
+ \brief The TQDataSink class is an asynchronous consumer of data.
+
+ A data sink is an object which receives data from some source in an
+ asynchronous manner. This means that at some time not determined by
+ the data sink, blocks of data are given to it from processing. The
+ data sink is able to limit the maximum size of such blocks which it
+ is currently able to process.
+
+ \sa TQAsyncIO, TQDataSource, TQDataPump
+*/
+
+/*!
+ \fn int TQDataSink::readyToReceive()
+
+ The data sink should return a value indicating how much data it is ready
+ to consume. This may be 0.
+*/
+
+/*!
+ This should be called whenever readyToReceive() might have become non-zero.
+ It is merely calls TQAsyncIO::ready() if readyToReceive() is non-zero.
+*/
+void TQDataSink::maybeReady()
+{
+ if (readyToReceive()) ready();
+}
+
+/*!
+ \fn void TQDataSink::receive(const uchar*, int count)
+
+ This function is called to provide data for the data sink. The \a count
+ will be no more than the amount indicated by the most recent call to
+ readyToReceive(). The sink must use all the provided data.
+*/
+
+/*!
+ \fn void TQDataSink::eof()
+
+ This function will be called when no more data is available for
+ processing.
+*/
+
+
+/*!
+ \class TQDataSource tqasyncio.h
+ \obsolete
+ \brief The TQDataSource class is an asynchronous producer of data.
+
+ A data source is an object which provides data from some source in an
+ asynchronous manner. This means that at some time not determined by
+ the data source, blocks of data will be taken from it for processing.
+ The data source is able to limit the maximum size of such blocks which
+ it is currently able to provide.
+
+ \sa TQAsyncIO, TQDataSink, TQDataPump
+*/
+
+/*!
+ \fn int TQDataSource::readyToSend()
+
+ The data source should return a value indicating how much data it is ready
+ to provide. This may be 0. If the data source knows it will never be
+ able to provide any more data (until after a rewind()), it may return -1.
+*/
+
+/*!
+ This should be called whenever readyToSend() might have become non-zero.
+ It is merely calls TQAsyncIO::ready() if readyToSend() is non-zero.
+*/
+void TQDataSource::maybeReady()
+{
+ if (readyToSend()) ready();
+}
+
+/*!
+ \fn void TQDataSource::sendTo(TQDataSink*, int count)
+
+ This function is called to extract data from the source, by sending
+ it to the given data sink. The \a count will be no more than the amount
+ indicated by the most recent call to readyToSend(). The source must
+ use all the provided data, and the sink will be prepared to accept at
+ least this much data.
+*/
+
+/*!
+ This function should return TRUE if the data source can be rewound.
+
+ The default returns FALSE.
+*/
+bool TQDataSource::rewindable() const
+{
+ return FALSE;
+}
+
+/*!
+ If this function is called with \a on set to TRUE, and rewindable()
+ is TRUE, then the data source must take measures to allow the rewind()
+ function to subsequently operate as described. If rewindable() is FALSE,
+ the function should call TQDataSource::enableRewind(), which aborts with
+ a qFatal() error.
+
+ For example, a network connection may choose to use a disk cache
+ of input only if rewinding is enabled before the first buffer-full of
+ data is discarded, returning FALSE in rewindable() if that first buffer
+ is discarded.
+*/
+void TQDataSource::enableRewind( bool /* on */ )
+{
+ qFatal( "Attempted to make unrewindable TQDataSource rewindable" );
+}
+
+/*!
+ This function rewinds the data source. This may only be called if
+ enableRewind(TRUE) has been previously called.
+*/
+void TQDataSource::rewind()
+{
+ qFatal("Attempted to rewind unrewindable TQDataSource");
+}
+
+/*!
+ \class TQIODeviceSource tqasyncio.h
+ \obsolete
+ \brief The TQIODeviceSource class is a TQDataSource that draws data from a TQIODevice.
+
+ This class encapsulates retrieving data from a TQIODevice (such as a TQFile).
+*/
+
+/*!
+ Constructs a TQIODeviceSource from the TQIODevice \a tqdevice. The TQIODevice
+ \e must be dynamically allocated, becomes owned by the TQIODeviceSource,
+ and will be deleted when the TQIODeviceSource is destroyed. \a buffer_size
+ determines the size of buffering to use between asynchronous operations.
+ The higher the \a buffer_size, the more efficient, but the less interleaved
+ the operation will be with other processing.
+*/
+TQIODeviceSource::TQIODeviceSource(TQIODevice* tqdevice, int buffer_size) :
+ buf_size(buffer_size),
+ buffer(new uchar[buf_size]),
+ iod(tqdevice),
+ rew(FALSE)
+{
+}
+
+/*!
+ Destroys the TQIODeviceSource, deleting the TQIODevice from which it was
+ constructed.
+*/
+TQIODeviceSource::~TQIODeviceSource()
+{
+ delete iod;
+ delete [] buffer;
+}
+
+/*!
+ Ready until end-of-file.
+*/
+int TQIODeviceSource::readyToSend()
+{
+ if ( iod->status() != IO_Ok || !(iod->state() & IO_Open) )
+ return -1;
+
+ int n = TQMIN((uint)buf_size, iod->size()-iod->at()); // ### not 64-bit safe
+ // ### not large file safe
+ return n ? n : -1;
+}
+
+/*!
+ Reads a block of data and sends up to \a n bytes to the \a sink.
+*/
+void TQIODeviceSource::sendTo(TQDataSink* sink, int n)
+{
+ iod->readBlock((char*)buffer, n);
+ sink->receive(buffer, n);
+}
+
+/*!
+ All TQIODeviceSource's are rewindable.
+*/
+bool TQIODeviceSource::rewindable() const
+{
+ return TRUE;
+}
+
+/*!
+ If \a on is set to TRUE then rewinding is enabled.
+ No special action is taken. If \a on is set to
+ FALSE then rewinding is disabled.
+*/
+void TQIODeviceSource::enableRewind(bool on)
+{
+ rew = on;
+}
+
+/*!
+ Calls reset() on the TQIODevice.
+*/
+void TQIODeviceSource::rewind()
+{
+ if (!rew) {
+ TQDataSource::rewind();
+ } else {
+ iod->reset();
+ ready();
+ }
+}
+
+
+/*!
+ \class TQDataPump tqasyncio.h
+ \obsolete
+ \brief The TQDataPump class moves data from a TQDataSource to a TQDataSink during event processing.
+
+ For a TQDataSource to provide data to a TQDataSink, a controller must exist
+ to examine the TQDataSource::readyToSend() and TQDataSink::readyToReceive()
+ methods and respond to the TQASyncIO::activate() signal of the source and
+ sink. One very useful way to do this is interleaved with other event
+ processing. TQDataPump provides this - create a pipe between a source
+ and a sink, and data will be moved during subsequent event processing.
+
+ Note that each source can only provide data to one sink and each sink
+ can only receive data from one source (although it is quite possible
+ to write a multiplexing sink that is multiple sources).
+*/
+
+/*!
+ Constructs a TQDataPump to move data from a given \a data_source
+ to a given \a data_sink.
+*/
+TQDataPump::TQDataPump(TQDataSource* data_source, TQDataSink* data_sink) :
+ source(data_source), sink(data_sink)
+{
+ source->connect(this, TQT_SLOT(kickStart()));
+ sink->connect(this, TQT_SLOT(kickStart()));
+ connect(&timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(tryToPump()));
+ timer.start(0, TRUE);
+}
+
+void TQDataPump::kickStart()
+{
+ if (!timer.isActive()) {
+ interval = 0;
+ timer.start(0, TRUE);
+ }
+}
+
+void TQDataPump::tryToPump()
+{
+ int supply, demand;
+
+ supply = source->readyToSend();
+ demand = sink->readyToReceive();
+ if (demand <= 0) {
+ return;
+ }
+ interval = 0;
+ if (supply < 0) {
+ // All done (until source Q_SIGNALS change in readiness)
+ sink->eof();
+ return;
+ }
+ if (!supply)
+ return;
+ source->sendTo(sink, TQMIN(supply, demand));
+
+ timer.start(0, TRUE);
+}
+
+#endif // TQT_NO_ASYNC_IO
+
diff --git a/tqtinterface/qt4/src/kernel/tqasyncio.h b/tqtinterface/qt4/src/kernel/tqasyncio.h
new file mode 100644
index 0000000..76176a5
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqasyncio.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Definition of asynchronous I/O classes
+**
+** Created : 970617
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQASYNCIO_H
+#define TQASYNCIO_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqsignal.h"
+#include "tqtimer.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_ASYNC_IO
+
+class TQIODevice;
+
+class TQ_EXPORT TQAsyncIO {
+public:
+ virtual ~TQAsyncIO();
+ void connect(TQObject*, const char *member);
+
+protected:
+ void ready();
+
+private:
+ TQSignal signal;
+};
+
+class TQ_EXPORT TQDataSink : public TQAsyncIO {
+public:
+ // Call this to know how much I can take.
+ virtual int readyToReceive()=0;
+ virtual void receive(const uchar*, int count)=0;
+ virtual void eof()=0;
+ void maybeReady();
+};
+
+class TQ_EXPORT TQDataSource : public TQAsyncIO {
+public:
+ virtual int readyToSend()=0; // returns -1 when never any more ready
+ virtual void sendTo(TQDataSink*, int count)=0;
+ void maybeReady();
+
+ virtual bool rewindable() const;
+ virtual void enableRewind(bool);
+ virtual void rewind();
+};
+
+class TQ_EXPORT TQIODeviceSource : public TQDataSource {
+ const int buf_size;
+ uchar *buffer;
+ TQIODevice* iod;
+ bool rew;
+
+public:
+ TQIODeviceSource(TQIODevice*, int bufsize=4096);
+ ~TQIODeviceSource();
+
+ int readyToSend();
+ void sendTo(TQDataSink* sink, int n);
+ bool rewindable() const;
+ void enableRewind(bool on);
+ void rewind();
+};
+
+class TQ_EXPORT TQDataPump : public TQObject {
+ Q_OBJECT
+ TQ_OBJECT
+ int interval;
+ TQTimer timer;
+ TQDataSource* source;
+ TQDataSink* sink;
+
+public:
+ TQDataPump(TQDataSource*, TQDataSink*);
+
+private Q_SLOTS:
+ void kickStart();
+ void tryToPump();
+};
+
+#endif // TQT_NO_ASYNC_IO
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqbitmap.cpp b/tqtinterface/qt4/src/kernel/tqbitmap.cpp
new file mode 100644
index 0000000..3e2ee39
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqbitmap.cpp
@@ -0,0 +1,435 @@
+/****************************************************************************
+**
+** Implementation of TQBitmap class
+**
+** Created : 941020
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqbitmap.h"
+#include "tqimage.h"
+
+#ifdef USE_QT4
+
+TQBitmap::TQBitmap() : QBitmap() {
+}
+
+TQBitmap::TQBitmap( int w, int h, bool clear, TQPixmap::Optimization o ) : QBitmap( w, h ) {
+ TQ_UNUSED(o);
+ if (clear)
+ QBitmap::clear();
+}
+
+TQBitmap::TQBitmap( const QSize &s, bool clear, TQPixmap::Optimization o ) : QBitmap( s ) {
+ TQ_UNUSED(o);
+ if (clear)
+ QBitmap::clear();
+}
+
+TQBitmap::TQBitmap( int w, int h, const uchar *bits, bool isXbitmap ) : QBitmap( QBitmap::fromData ( QSize(w, h), bits, (isXbitmap)?QImage::Format_MonoLSB:QImage::Format_Mono ) ) {
+}
+
+TQBitmap::TQBitmap( const QSize &s, const uchar *bits, bool isXbitmap ) : QBitmap( QBitmap::fromData ( s, bits, (isXbitmap)?QImage::Format_MonoLSB:QImage::Format_Mono ) ) {
+}
+
+TQBitmap::TQBitmap( const QBitmap &b ) : QBitmap( b ) {
+}
+
+#ifndef TQT_NO_IMAGEIO
+TQBitmap::TQBitmap( const QString &fileName, const char *format ) : QBitmap( fileName, format ) {
+}
+#endif
+
+QImage TQBitmap::convertToImage() const {
+ return toImage();
+}
+
+bool TQBitmap::convertFromImage(const QImage &img, int flags) {
+ return QPixmap::convertFromImage(img, (Qt::ImageConversionFlag)flags);
+}
+
+TQBitmap TQBitmap::xForm(const QMatrix &matrix) const {
+ return transformed(QTransform(matrix));
+}
+
+void TQBitmap::resize(const QSize &s) {
+ resize_helper(s);
+}
+
+void TQBitmap::resize(int width, int height) {
+ resize_helper(QSize(width, height));
+}
+
+// void TQBitmap::resize_helper(const QSize &s)
+// {
+// int w = s.width();
+// int h = s.height();
+// if (w < 1 || h < 1) {
+// *this = TQBitmap();
+// return;
+// }
+//
+// *this = TQBitmap(copy(0, 0, w, h));
+// }
+
+void TQBitmap::resize_helper(const QSize s)
+{
+ int w = s.width();
+ int h = s.height();
+
+ if (w < 1 || h < 1) {
+ *this = TQBitmap();
+ return;
+ }
+
+ if (size() == s)
+ return;
+
+ TQBitmap pm(QSize(w, h));
+ if (!isNull()) {
+ // Copy old bitmap
+ pm.fill(Qt::color0);
+ QPainter p(&pm);
+ p.setBrush(Qt::color1);
+ p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h));
+ p.end();
+ }
+
+ // Mask too....
+ if (!mask().isNull()) {
+ TQBitmap m = mask();
+ if (m.size() != QSize(w,h)) {
+ TQBitmap pmr(QSize(w, h));
+ pmr.fill(Qt::color0);
+ QPainter pr(&pmr);
+ pr.setBrush(Qt::color1);
+ pr.drawPixmap(0, 0, m, 0, 0, qMin(m.width(), w), qMin(m.height(), h));
+ pr.end();
+ pm.setMask(pmr);
+ }
+ else {
+ pm.setMask(m);
+ }
+ }
+
+ // [FIXME]
+ // Note that the Xorg pixmap and/or gc (if any) is not created via the above process
+ // Therefore resize is more of a copy operation than a true resize
+ #warning TQPixmap::resize() partially implemented
+
+ *this = pm;
+}
+
+// This is the only correct way to return a pointer to an object returned by another function
+const TQBitmap *TQBitmap::tqmask() const {
+ const QBitmap& ptrRef = mask();
+ if (ptrRef.isNull() == true) {
+ return 0;
+ }
+ return static_cast<const TQBitmap*>(&ptrRef);
+}
+
+TQBitmap TQBitmap::operator=( const TQPixmap &pixmap )
+{
+ return TQBitmap(QBitmap::operator=(pixmap));
+}
+
+TQBitmap &TQBitmap::operator=( const TQImage &image )
+{
+ convertFromImage( image );
+ return *this;
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQBitmap tqbitmap.h
+ \brief The TQBitmap class provides monochrome (1-bit depth) pixmaps.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+
+ The TQBitmap class is a monochrome off-screen paint tqdevice used
+ mainly for creating custom TQCursor and TQBrush objects, in
+ TQPixmap::setMask() and for TQRegion.
+
+ A TQBitmap is a TQPixmap with a \link TQPixmap::depth() depth\endlink
+ of 1. If a pixmap with a depth greater than 1 is assigned to a
+ bitmap, the bitmap will be dithered automatically. A TQBitmap is
+ guaranteed to always have the depth 1, unless it is
+ TQPixmap::isNull() which has depth 0.
+
+ When drawing in a TQBitmap (or TQPixmap with depth 1), we recommend
+ using the TQColor objects \c TQt::color0 and \c TQt::color1.
+ Painting with \c color0 sets the bitmap bits to 0, and painting
+ with \c color1 sets the bits to 1. For a bitmap, 0-bits indicate
+ background (or transtqparent) and 1-bits indicate foreground (or
+ opaque). Using the \c black and \c white TQColor objects make no
+ sense because the TQColor::pixel() value is not necessarily 0 for
+ black and 1 for white.
+
+ The TQBitmap can be transformed (translated, scaled, sheared or
+ rotated) using xForm().
+
+ Just like the TQPixmap class, TQBitmap is optimized by the use of
+ \link shclass.html implicit sharing\endlink, so it is very
+ efficient to pass TQBitmap objects as arguments.
+
+ \sa TQPixmap, TQPainter::drawPixmap(), bitBlt(), \link shclass.html Shared Classes\endlink
+*/
+
+
+/*!
+ Constructs a null bitmap.
+
+ \sa TQPixmap::isNull()
+*/
+
+TQBitmap::TQBitmap()
+{
+ data->bitmap = TRUE;
+}
+
+
+/*!
+ Constructs a bitmap with width \a w and height \a h.
+
+ The contents of the bitmap is uninitialized if \a clear is FALSE;
+ otherwise it is filled with pixel value 0 (the TQColor \c
+ TQt::color0).
+
+ The optional \a optimization argument specifies the optimization
+ setting for the bitmap. The default optimization should be used in
+ most cases. Games and other pixmap-intensive applications may
+ benefit from setting this argument; see \l{TQPixmap::Optimization}.
+
+ \sa TQPixmap::setOptimization(), TQPixmap::setDefaultOptimization()
+*/
+
+TQBitmap::TQBitmap( int w, int h, bool clear,
+ TQPixmap::Optimization optimization )
+ : TQPixmap( w, h, 1, optimization )
+{
+ data->bitmap = TRUE;
+ if ( clear )
+ fill( TQt::color0 );
+}
+
+
+/*!
+ \overload
+
+ Constructs a bitmap with the size \a size.
+
+ The contents of the bitmap is uninitialized if \a clear is FALSE;
+ otherwise it is filled with pixel value 0 (the TQColor \c
+ TQt::color0).
+
+ The optional \a optimization argument specifies the optimization
+ setting for the bitmap. The default optimization should be used in
+ most cases. Games and other pixmap-intensive applications may
+ benefit from setting this argument; see \l{TQPixmap::Optimization}.
+*/
+
+TQBitmap::TQBitmap( const TQSize &size, bool clear,
+ TQPixmap::Optimization optimization )
+ : TQPixmap( size, 1, optimization )
+{
+ data->bitmap = TRUE;
+ if ( clear )
+ fill( TQt::color0 );
+}
+
+
+/*!
+ Constructs a bitmap with width \a w and height \a h and sets the
+ contents to \a bits.
+
+ The \a isXbitmap flag should be TRUE if \a bits was generated by
+ the X11 bitmap program. The X bitmap bit order is little endian.
+ The TQImage documentation discusses bit order of monochrome images.
+
+ Example (creates an arrow bitmap):
+ \code
+ uchar arrow_bits[] = { 0x3f, 0x1f, 0x0f, 0x1f, 0x3b, 0x71, 0xe0, 0xc0 };
+ TQBitmap bm( 8, 8, arrow_bits, TRUE );
+ \endcode
+*/
+
+TQBitmap::TQBitmap( int w, int h, const uchar *bits, bool isXbitmap )
+ : TQPixmap( w, h, bits, isXbitmap )
+{
+ data->bitmap = TRUE;
+}
+
+
+/*!
+ \overload
+
+ Constructs a bitmap with the size \a size and sets the contents to
+ \a bits.
+
+ The \a isXbitmap flag should be TRUE if \a bits was generated by
+ the X11 bitmap program. The X bitmap bit order is little endian.
+ The TQImage documentation discusses bit order of monochrome images.
+*/
+
+TQBitmap::TQBitmap( const TQSize &size, const uchar *bits, bool isXbitmap )
+ : TQPixmap( size.width(), size.height(), bits, isXbitmap )
+{
+ data->bitmap = TRUE;
+}
+
+
+/*!
+ Constructs a bitmap that is a copy of \a bitmap.
+*/
+
+TQBitmap::TQBitmap( const TQBitmap &bitmap )
+ : TQPixmap( bitmap )
+{
+}
+
+#ifndef TQT_NO_IMAGEIO
+/*!
+ Constructs a bitmap from the file \a fileName. If the file does
+ not exist or is of an unknown format, the bitmap becomes a null
+ bitmap.
+
+ The parameters \a fileName and \a format are passed on to
+ TQPixmap::load(). Dithering will be performed if the file format
+ uses more than 1 bit per pixel.
+
+ \sa TQPixmap::isNull(), TQPixmap::load(), TQPixmap::loadFromData(),
+ TQPixmap::save(), TQPixmap::imageFormat()
+*/
+
+TQBitmap::TQBitmap( const TQString& fileName, const char *format )
+ : TQPixmap() // Will set bitmap to null bitmap, explicit call for clarity
+{
+ data->bitmap = TRUE;
+ load( fileName, format, Mono );
+}
+#endif
+
+/*!
+ Assigns the bitmap \a bitmap to this bitmap and returns a
+ reference to this bitmap.
+*/
+
+TQBitmap &TQBitmap::operator=( const TQBitmap &bitmap )
+{
+ TQPixmap::operator=(bitmap);
+#if defined(TQT_CHECK_STATE)
+ TQ_ASSERT( data->bitmap );
+#endif
+ return *this;
+}
+
+
+/*!
+ \overload
+
+ Assigns the pixmap \a pixmap to this bitmap and returns a
+ reference to this bitmap.
+
+ Dithering will be performed if the pixmap has a TQPixmap::depth()
+ greater than 1.
+*/
+
+TQBitmap &TQBitmap::operator=( const TQPixmap &pixmap )
+{
+ if ( pixmap.isNull() ) { // a null pixmap
+ TQBitmap bm( 0, 0, FALSE, pixmap.optimization() );
+ TQBitmap::operator=(bm);
+ } else if ( pixmap.depth() == 1 ) { // 1-bit pixmap
+ if ( pixmap.isTQBitmap() ) { // another TQBitmap
+ TQPixmap::operator=(pixmap); // shallow assignment
+ } else { // not a TQBitmap, but 1-bit
+ TQBitmap bm( pixmap.size(), FALSE, pixmap.optimization() );
+ bitBlt( &bm, 0,0, &pixmap, 0,0,pixmap.width(),pixmap.height() );
+ TQBitmap::operator=(bm);
+ }
+ } else { // n-bit depth pixmap
+ TQImage image;
+ image = pixmap; // convert pixmap to image
+ *this = image; // will dither image
+ }
+ return *this;
+}
+
+
+/*!
+ \overload
+
+ Converts the image \a image to a bitmap and assigns the result to
+ this bitmap. Returns a reference to the bitmap.
+
+ Dithering will be performed if the image has a TQImage::depth()
+ greater than 1.
+*/
+
+TQBitmap &TQBitmap::operator=( const TQImage &image )
+{
+ convertFromImage( image );
+ return *this;
+}
+
+
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+/*!
+ Returns a transformed copy of this bitmap by using \a matrix.
+
+ This function does exactly the same as TQPixmap::xForm(), except
+ that it returns a TQBitmap instead of a TQPixmap.
+
+ \sa TQPixmap::xForm()
+*/
+
+TQBitmap TQBitmap::xForm( const TQWMatrix &matrix ) const
+{
+ TQPixmap pm = TQPixmap::xForm( matrix );
+ TQBitmap bm;
+ // Here we fake the pixmap to think it's a TQBitmap. With this trick,
+ // the TQBitmap::operator=(const TQPixmap&) will just refer the
+ // pm.data and we do not need to perform a bitBlt.
+ pm.data->bitmap = TRUE;
+ bm = pm;
+ return bm;
+}
+#endif // TQT_NO_TRANSFORMATIONS
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqbitmap.h b/tqtinterface/qt4/src/kernel/tqbitmap.h
new file mode 100644
index 0000000..e4a2fd9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqbitmap.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Definition of TQBitmap class
+**
+** Created : 941020
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQBITMAP_H
+#define TQBITMAP_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpixmap.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qbitmap.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQBitmap : public QBitmap, virtual public TQt
+{
+public:
+ TQBitmap();
+ TQBitmap( int w, int h, bool clear = FALSE, TQPixmap::Optimization o=TQPixmap::DefaultOptim );
+ TQBitmap( const QSize &s, bool clear = FALSE, TQPixmap::Optimization o=TQPixmap::DefaultOptim );
+ TQBitmap( int w, int h, const uchar *bits, bool isXbitmap=FALSE );
+ TQBitmap( const QSize &s, const uchar *bits, bool isXbitmap=FALSE );
+ TQBitmap( const QBitmap &b );
+#ifndef TQT_NO_IMAGEIO
+ TQBitmap( const QString &fileName, const char *format=0 );
+#endif
+// TQBitmap &operator=( const TQBitmap & );
+ TQBitmap operator=( const TQPixmap & );
+ TQBitmap &operator=( const TQImage & );
+
+ QImage convertToImage() const;
+
+ bool convertFromImage(const QImage &img, int flags = Qt::AutoColor);
+ TQBitmap xForm(const QMatrix &matrix) const;
+ const TQBitmap *tqmask() const;
+
+private:
+ void resize_helper(const QSize s);
+public:
+ void resize(const QSize &s);
+ void resize(int width, int height);
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQBitmap : public TQPixmap
+{
+public:
+ TQBitmap();
+ TQBitmap( int w, int h, bool clear = FALSE,
+ TQPixmap::Optimization = TQPixmap::DefaultOptim );
+ TQBitmap( const TQSize &, bool clear = FALSE,
+ TQPixmap::Optimization = TQPixmap::DefaultOptim );
+ TQBitmap( int w, int h, const uchar *bits, bool isXbitmap=FALSE );
+ TQBitmap( const TQSize &, const uchar *bits, bool isXbitmap=FALSE );
+ TQBitmap( const TQBitmap & );
+#ifndef TQT_NO_IMAGEIO
+ TQBitmap( const TQString &fileName, const char *format=0 );
+#endif
+ TQBitmap &operator=( const TQBitmap & );
+ TQBitmap &operator=( const TQPixmap & );
+ TQBitmap &operator=( const TQImage & );
+
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ TQBitmap xForm( const TQWMatrix & ) const;
+#endif
+};
+
+#endif // USE_QT4
+
+#endif // TQBITMAP_H
diff --git a/tqtinterface/qt4/src/kernel/tqbrush.h b/tqtinterface/qt4/src/kernel/tqbrush.h
new file mode 100644
index 0000000..ea5268f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqbrush.h
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Definition of TQBrush class
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQBRUSH_H
+#define TQBRUSH_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqcolor.h"
+#include "tqshared.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include "tqpixmap.h"
+#include <Qt/qbrush.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQBrush : public QBrush, virtual public TQt
+{
+public:
+ TQBrush() : QBrush() {}
+ TQBrush( Qt::BrushStyle bs ) : QBrush( bs ) {}
+ TQBrush( const QColor &qc, Qt::BrushStyle bs=Qt::SolidPattern ) : QBrush( qc, bs ) {}
+ TQBrush( const QColor &qc, TQt::BrushStyle bs ) : QBrush( qc, (Qt::BrushStyle)bs ) {}
+ TQBrush( const QColor &qc, const QPixmap &qp ) : QBrush( qc, qp ) {}
+ TQBrush( const QBrush &qb ) : QBrush( qb ) {}
+
+ TQBrush(Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern) : QBrush( color, bs ) {}
+ TQBrush(Qt::GlobalColor color, TQt::BrushStyle bs) : QBrush( color, (Qt::BrushStyle)bs ) {}
+ TQBrush(Qt::GlobalColor color, const QPixmap &pixmap) : QBrush( color, pixmap ) {}
+
+ TQBrush(const QPixmap &pixmap) : QBrush( pixmap ) {}
+ TQBrush(const QImage &image) : QBrush( image ) {}
+ TQBrush(const QGradient &gradient) : QBrush( gradient ) {}
+
+ inline operator const QColor&() const;
+ TQPixmap *pixmap() const { return const_cast<TQPixmap*>(&TQT_TQPIXMAP_OBJECT(texture())); }
+ inline void setPixmap(const QPixmap &pixmap) { setTexture(pixmap); }
+
+ // Interoperability
+ static const TQBrush& convertFromQBrush( QBrush& qbr );
+
+ using QBrush::operator=;
+};
+
+// Interoperability
+inline static const TQBrush& convertFromQBrush( const QBrush& qbr ) {
+ return (*static_cast<const TQBrush*>(&qbr));
+}
+
+#else // USE_QT4
+
+class TQ_EXPORT TQBrush: public TQt
+{
+friend class TQPainter;
+public:
+ TQBrush();
+ TQBrush( BrushStyle );
+ TQBrush( const TQColor &, BrushStyle=SolidPattern );
+ TQBrush( const TQColor &, const TQPixmap & );
+ TQBrush( const TQBrush & );
+ ~TQBrush();
+ TQBrush &operator=( const TQBrush & );
+
+ BrushStyle style() const { return data->style; }
+ void setStyle( BrushStyle );
+ const TQColor &color()const { return data->color; }
+ void setColor( const TQColor & );
+ TQPixmap *pixmap() const { return data->pixmap; }
+ void setPixmap( const TQPixmap & );
+
+ bool operator==( const TQBrush &p ) const;
+ bool operator!=( const TQBrush &b ) const
+ { return !(operator==(b)); }
+
+private:
+ TQBrush copy() const;
+ void detach();
+ void init( const TQColor &, BrushStyle );
+ struct TQBrushData : public TQShared { // brush data
+ BrushStyle style;
+ TQColor color;
+ TQPixmap *pixmap;
+ } *data;
+};
+
+
+/*****************************************************************************
+ TQBrush stream functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQBrush & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQBrush & );
+#endif
+
+#endif // USE_QT4
+
+#endif // TQBRUSH_H
diff --git a/tqtinterface/qt4/src/kernel/tqclipboard.cpp b/tqtinterface/qt4/src/kernel/tqclipboard.cpp
new file mode 100644
index 0000000..9c7a318
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqclipboard.cpp
@@ -0,0 +1,754 @@
+/****************************************************************************
+**
+** Implementation of TQClipboard class
+**
+** Created : 960430
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqclipboard.h"
+
+#ifndef TQT_NO_CLIPBOARD
+
+#include "tqapplication.h"
+#include "tqapplication_p.h"
+#include "tqdragobject.h"
+#include "tqpixmap.h"
+
+// #ifdef USE_QT4
+#if 0
+
+#include "Qt/qbuffer.h"
+
+static TQClipboardPrivate *tqt_tqclipboard_tqcbp = 0;
+
+class TQMimeDataWrapper : public QMimeSource
+{
+public:
+ TQMimeDataWrapper() {}
+
+ const char* format(int n) const;
+ QByteArray encodedData(const char*) const;
+
+ mutable QList<QByteArray> formats;
+ const QMimeData *data;
+};
+
+const char* TQMimeDataWrapper::format(int n) const
+{
+ if (formats.isEmpty()) {
+ QStringList fmts = data->formats();
+ for (int i = 0; i < fmts.size(); ++i)
+ formats.append(fmts.at(i).toLatin1());
+ }
+ if (n < 0 || n >= formats.size())
+ return 0;
+ return formats.at(n).data();
+}
+
+QByteArray TQMimeDataWrapper::encodedData(const char *format) const
+{
+ if (QLatin1String(format) != QLatin1String("application/x-qt-image")){
+ return data->data(QLatin1String(format));
+ } else{
+ QVariant variant = data->imageData();
+ QImage img = qVariantValue<QImage>(variant);
+ QByteArray ba;
+ QBuffer buffer(&ba);
+ buffer.open(QIODevice::WriteOnly);
+ img.save(&buffer, "PNG");
+ return ba;
+ }
+}
+
+class TQMimeSourceWrapper : public QMimeData
+{
+public:
+ TQMimeSourceWrapper(QClipboard::Mode m);
+ ~TQMimeSourceWrapper();
+
+ bool hasFormat(const QString &mimetype) const;
+ QStringList formats() const;
+
+protected:
+ QVariant retrieveData(const QString &mimetype, QVariant::Type) const;
+private:
+ QClipboard::Mode mode;
+ QMimeSource *source;
+};
+
+QVariant TQMimeSourceWrapper::retrieveData(const QString &mimetype, QVariant::Type) const
+{
+ if (source == 0) {
+ printf("[WARNING] TQMimeSourceWrapper::retrieveData source==0 [check tqt_tqclipboard_tqcbp->compat_data[mode] assignment]\n\r");
+ return QString();
+ }
+ return source->encodedData(mimetype.toLatin1());
+}
+
+bool TQMimeSourceWrapper::hasFormat(const QString &mimetype) const
+{
+ if (source == 0) {
+ printf("[WARNING] TQMimeSourceWrapper::hasFormat source==0 [check tqt_tqclipboard_tqcbp->compat_data[mode] assignment]\n\r");
+ return false;
+ }
+ return source->provides(mimetype.toLatin1());
+}
+
+QStringList TQMimeSourceWrapper::formats() const
+{
+ QStringList fmts;
+ int i = 0;
+ const char *fmt;
+ if (source == 0) {
+ printf("[WARNING] TQMimeSourceWrapper::formats source==0 [check tqt_tqclipboard_tqcbp->compat_data[mode] assignment]\n\r");
+ return QStringList();
+ }
+ while ((fmt = source->format(i))) {
+ fmts.append(QLatin1String(fmt));
+ ++i;
+ }
+ return fmts;
+}
+
+class TQClipboardPrivate
+{
+public:
+ TQClipboardPrivate() {
+ for (int i = 0; i <= QClipboard::LastMode; ++i) {
+ compat_data[i] = 0;
+ wrapper[i] = new TQMimeDataWrapper();
+ }
+ }
+ ~TQClipboardPrivate() {
+ for (int i = 0; i <= QClipboard::LastMode; ++i) {
+ delete wrapper[i];
+ delete compat_data[i];
+ }
+ }
+
+ mutable TQMimeDataWrapper *wrapper[QClipboard::LastMode + 1];
+ mutable QMimeSource *compat_data[QClipboard::LastMode + 1];
+};
+
+inline TQMimeSourceWrapper::TQMimeSourceWrapper(QClipboard::Mode m)
+ : QMimeData()
+{
+ if (tqt_tqclipboard_tqcbp == 0) {
+ tqt_tqclipboard_tqcbp = new TQClipboardPrivate();
+ }
+
+ mode = m;
+ source = tqt_tqclipboard_tqcbp->compat_data[mode];
+}
+
+inline TQMimeSourceWrapper::~TQMimeSourceWrapper()
+{
+ if (tqt_tqclipboard_tqcbp->compat_data[mode] == source)
+ tqt_tqclipboard_tqcbp->compat_data[mode] = 0;
+ if (source != 0) delete source;
+}
+
+TQMimeSource *TQClipboard::data(Mode mode) const
+{
+// Q_D(const QClipboard);
+
+// if (supportsMode(mode) == false)
+// return 0;
+//
+// if (d->compat_data[mode])
+// return d->compat_data[mode];
+//
+// d->wrapper[mode]->data = mimeData(mode);
+// return d->wrapper[mode];
+
+ // Separate TQt implementation follows
+
+ if (tqt_tqclipboard_tqcbp == 0) {
+ tqt_tqclipboard_tqcbp = new TQClipboardPrivate();
+ }
+
+ tqt_tqclipboard_tqcbp->wrapper[mode]->data = mimeData(mode);
+ return TQT_TQMIMESOURCE(tqt_tqclipboard_tqcbp->wrapper[mode]);
+}
+
+
+/*!
+ \fn void QClipboard::setData(QMimeSource *src, Mode mode)
+ \compat
+
+ Use setMimeData() instead.
+*/
+void TQClipboard::setData(QMimeSource *source, Mode mode)
+{
+// Q_D(QClipboard);
+
+// if (supportsMode(mode) == false)
+// return;
+//
+// d->compat_data[mode] = source;
+// setMimeData(new TQMimeSourceWrapper(d, mode), mode);
+
+ // Separate TQt implementation follows
+
+ if (tqt_tqclipboard_tqcbp == 0) {
+ tqt_tqclipboard_tqcbp = new TQClipboardPrivate();
+ }
+
+ setMimeData(new TQMimeSourceWrapper(mode), mode);
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQClipboard tqclipboard.h
+ \brief The TQClipboard class provides access to the window system clipboard.
+
+ \ingroup io
+ \ingroup environment
+ \mainclass
+
+ The clipboard offers a simple mechanism to copy and paste data
+ between applications.
+
+ TQClipboard supports the same data types that TQDragObject does, and
+ uses similar mechanisms. For advanced clipboard usage
+ read \link dnd.html the drag-and-drop documentation\endlink.
+
+ There is a single TQClipboard object in an application, and you can
+ access it using TQApplication::clipboard().
+
+ Example:
+ \code
+ TQClipboard *cb = TQApplication::clipboard();
+
+ // Copy text from the clipboard (paste)
+ TQString text = cb->text(TQClipboard::Clipboard);
+ if ( !text.isNull() )
+ qDebug( "The clipboard tqcontains: " + text );
+
+ // Copy text into the clipboard
+ cb->setText( "This text can be pasted by other programs",
+ TQClipboard::Clipboard );
+ \endcode
+
+ TQClipboard features some convenience functions to access common data
+ types: setText() allows the exchange of Unicode text and
+ setPixmap() and setImage() allows the exchange of TQPixmaps
+ and TQImages between applications. The setData() function is the
+ ultimate in flexibility: it allows you to add any TQMimeSource into the
+ clipboard. There are corresponding getters for each of these, e.g.
+ text(), image() and pixmap().
+
+ You can clear the clipboard by calling clear().
+
+
+ \section1 Platform Specific Information
+
+ \section2 X11
+
+ \list
+
+ \i The X11 Window System has the concept of a separate selection
+ and clipboard. When text is selected, it is immediately available
+ as the global mouse selection. The global mouse selection may
+ later be copied to the clipboard. By convention, the middle mouse
+ button is used to paste the global mouse selection.
+
+ \i X11 also has the concept of ownership; if you change the
+ selection within a window, X11 will only notify the owner and the
+ previous owner of the change, i.e. it will not notify all
+ applications that the selection or clipboard data changed.
+
+ \i Lastly, the X11 clipboard is event driven, i.e. the clipboard
+ will not function properly if the event loop is not running.
+ Similarly, it is recommended that the contents of the clipboard
+ are stored or retrieved in direct response to user-input events,
+ e.g. mouse button or key presses and releases. You should not
+ store or retrieve the clipboard contents in response to timer or
+ non-user-input events.
+
+ \endlist
+
+ \section2 Windows
+
+ \list
+
+ \i Microsoft Windows does not support the global mouse selection;
+ it only supports the global clipboard, e.g. Windows only adds text
+ to the clipboard when an explicit copy or cut is made.
+
+ \i Windows does not have the concept of ownership; the clipboard
+ is a fully global resource so all applications are notified of
+ changes.
+
+ \endlist
+
+ See the multiclip example in the \e{TQt Designer} examples
+ directory for an example of a multiplatform clipboard application
+ that also demonstrates selection handling.
+*/
+
+
+/*!
+ \internal
+
+ Constructs a clipboard object.
+
+ Do not call this function.
+
+ Call TQApplication::clipboard() instead to get a pointer to the
+ application's global clipboard object.
+
+ There is only one clipboard in the window system, and creating
+ more than one object to represent it is almost certainly an error.
+*/
+
+TQClipboard::TQClipboard( TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name )
+{
+ // nothing
+}
+
+#ifndef TQ_WS_WIN32
+/*!
+ \internal
+
+ Destroys the clipboard.
+
+ You should never delete the clipboard. TQApplication will do this
+ when the application terminates.
+*/
+TQClipboard::~TQClipboard()
+{
+}
+#endif
+
+/*!
+ \fn void TQClipboard::dataChanged()
+
+ This signal is emitted when the clipboard data is changed.
+*/
+
+/*!
+ \fn void TQClipboard::selectionChanged()
+
+ This signal is emitted when the selection is changed. This only
+ applies to windowing systems that support selections, e.g. X11.
+ Windows doesn't support selections.
+*/
+
+/*! \enum TQClipboard::Mode
+ \keyword clipboard mode
+
+ This enum type is used to control which part of the system clipboard is
+ used by TQClipboard::data(), TQClipboard::setData() and related functions.
+
+ \value Clipboard indicates that data should be stored and retrieved from
+ the global clipboard.
+
+ \value Selection indicates that data should be stored and retrieved from
+ the global mouse selection.
+
+ \e Note: Support for \c Selection is provided only on systems with a
+ global mouse selection (e.g. X11).
+
+ \sa TQClipboard::supportsSelection()
+*/
+
+
+/*****************************************************************************
+ TQApplication member functions related to TQClipboard.
+ *****************************************************************************/
+
+#ifndef TQT_NO_MIMECLIPBOARD
+// text handling is done directly in qclipboard_qws, for now
+
+/*!
+ \overload
+
+ Returns the clipboard text in subtype \a subtype, or a null string
+ if the clipboard does not contain any text. If \a subtype is null,
+ any subtype is acceptable, and \a subtype is set to the chosen
+ subtype.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ text is retrieved from the global clipboard. If \a mode is
+ TQClipboard::Selection, the text is retrieved from the global
+ mouse selection.
+
+ Common values for \a subtype are "plain" and "html".
+
+ \sa setText(), data(), TQString::operator!()
+*/
+TQString TQClipboard::text( TQCString &subtype, Mode mode ) const
+{
+ TQString r;
+ TQTextDrag::decode( data( mode ) ,r, subtype );
+ return r;
+}
+
+/*!
+ \overload
+
+ Returns the clipboard text in subtype \a subtype, or a null string
+ if the clipboard does not contain any text. This function uses the
+ TQClipboard::text() function which takes a TQClipboard::Mode
+ argument. The value of the mode argument is determined by the
+ return value of selectionModeEnabled(). If selectionModeEnabled()
+ returns TRUE, the mode argument is TQClipboard::Selection,
+ otherwise the mode argument is TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+TQString TQClipboard::text( TQCString& subtype ) const
+{
+ return text( subtype, selectionModeEnabled() ? Selection : Clipboard );
+}
+
+/*!
+ Returns the clipboard text as plain text, or a null string if the
+ clipboard does not contain any text.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ text is retrieved from the global clipboard. If \a mode is
+ TQClipboard::Selection, the text is retrieved from the global
+ mouse selection.
+
+ \sa setText(), data(), TQString::operator!()
+*/
+TQString TQClipboard::text( Mode mode ) const
+{
+ TQCString subtype = "plain";
+ return text( subtype, mode );
+}
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::text() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+
+TQString TQClipboard::text() const
+{
+ return text( selectionModeEnabled() ? Selection : Clipboard );
+}
+
+ /*!
+ Copies \a text into the clipboard as plain text.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ text is stored in the global clipboard. If \a mode is
+ TQClipboard::Selection, the text is stored in the global
+ mouse selection.
+
+ \sa text(), setData()
+*/
+
+void TQClipboard::setText( const TQString &text, Mode mode )
+{
+ setData( new TQTextDrag(text), mode );
+}
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::setText() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+void TQClipboard::setText( const TQString &text )
+{
+ setText( text, selectionModeEnabled() ? Selection : Clipboard );
+}
+
+/*!
+ Returns the clipboard image, or returns a null image if the
+ clipboard does not contain an image or if it tqcontains an image in
+ an unsupported image format.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ image is retrieved from the global clipboard. If \a mode is
+ TQClipboard::Selection, the image is retrieved from the global
+ mouse selection.
+
+ \sa setImage() pixmap() data(), TQImage::isNull()
+*/
+TQImage TQClipboard::image( Mode mode ) const
+{
+ TQImage r;
+ TQImageDrag::decode( data( mode ), r );
+ return r;
+}
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::image() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+TQImage TQClipboard::image() const
+{
+ return image( selectionModeEnabled() ? Selection : Clipboard );
+}
+
+/*!
+ Copies \a image into the clipboard.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ image is stored in the global clipboard. If \a mode is
+ TQClipboard::Selection, the data is stored in the global
+ mouse selection.
+
+ This is shorthand for:
+ \code
+ setData( new TQImageDrag(image), mode )
+ \endcode
+
+ \sa image(), setPixmap() setData()
+*/
+void TQClipboard::setImage( const TQImage &image, Mode mode )
+{
+ setData( new TQImageDrag( image ), mode );
+}
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::setImage() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+void TQClipboard::setImage( const TQImage &image )
+{
+ setImage( image, selectionModeEnabled() ? Selection : Clipboard );
+}
+
+/*!
+ Returns the clipboard pixmap, or null if the clipboard does not
+ contain a pixmap. Note that this can lose information. For
+ example, if the image is 24-bit and the display is 8-bit, the
+ result is converted to 8 bits, and if the image has an alpha
+ channel, the result just has a tqmask.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ pixmap is retrieved from the global clipboard. If \a mode is
+ TQClipboard::Selection, the pixmap is retrieved from the global
+ mouse selection.
+
+ \sa setPixmap() image() data() TQPixmap::convertFromImage().
+*/
+TQPixmap TQClipboard::pixmap( Mode mode ) const
+{
+ TQPixmap r;
+ TQImageDrag::decode( data( mode ), r );
+ return r;
+}
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::pixmap() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+TQPixmap TQClipboard::pixmap() const
+{
+ return pixmap( selectionModeEnabled() ? Selection : Clipboard );
+}
+
+/*!
+ Copies \a pixmap into the clipboard. Note that this is slower
+ than setImage() because it needs to convert the TQPixmap to a
+ TQImage first.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ pixmap is stored in the global clipboard. If \a mode is
+ TQClipboard::Selection, the pixmap is stored in the global
+ mouse selection.
+
+ \sa pixmap() setImage() setData()
+*/
+void TQClipboard::setPixmap( const TQPixmap &pixmap, Mode mode )
+{
+ // *could* just use the handle, but that is X hackery, MIME is better.
+ setData( new TQImageDrag( pixmap.convertToImage() ), mode );
+}
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::setPixmap() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+void TQClipboard::setPixmap( const TQPixmap &pixmap )
+{
+ setPixmap( pixmap, selectionModeEnabled() ? Selection : Clipboard );
+}
+
+
+/*! \fn TQMimeSource *TQClipboard::data( Mode mode ) const
+ Returns a reference to a TQMimeSource representation of the current
+ clipboard data.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ data is retrieved from the global clipboard. If \a mode is
+ TQClipboard::Selection, the data is retrieved from the global
+ mouse selection.
+
+ \sa setData()
+*/
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::data() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+TQMimeSource *TQClipboard::data() const
+{
+ return data( selectionModeEnabled() ? Selection : Clipboard );
+}
+
+/*! \fn void TQClipboard::setData( TQMimeSource *src, Mode mode )
+ Sets the clipboard data to \a src. Ownership of the data is
+ transferred to the clipboard. If you want to remove the data
+ either call clear() or call setData() again with new data.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, the
+ data is retrieved from the global clipboard. If \a mode is
+ TQClipboard::Selection, the data is retrieved from the global
+ mouse selection.
+
+ The TQDragObject subclasses are reasonable objects to put into the
+ clipboard (but do not try to call TQDragObject::drag() on the same
+ object). Any TQDragObject placed in the clipboard should have a
+ tqparent of 0. Do not put TQDragMoveEvent or TQDropEvent subclasses in
+ the clipboard, as they do not belong to the event handler which
+ receives them.
+
+ The setText(), setImage() and setPixmap() functions are simpler
+ wrappers for setting text, image and pixmap data respectively.
+
+ \sa data()
+*/
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::setData() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is
+ TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+void TQClipboard::setData( TQMimeSource *src )
+{
+ setData( src, selectionModeEnabled() ? Selection : Clipboard );
+}
+
+/*! \fn void TQClipboard::clear( Mode mode )
+ Clear the clipboard contents.
+
+ The \a mode argument is used to control which part of the system
+ clipboard is used. If \a mode is TQClipboard::Clipboard, this
+ function clears the the global clipboard contents. If \a mode is
+ TQClipboard::Selection, this function clears the global mouse
+ selection contents.
+
+ \sa TQClipboard::Mode, supportsSelection()
+*/
+
+/*!
+ \overload
+
+ This function uses the TQClipboard::clear() function which takes
+ a TQClipboard::Mode argument. The value of the mode argument is
+ determined by the return value of selectionModeEnabled().
+ If selectionModeEnabled() returns TRUE, the mode argument is
+ TQClipboard::Selection, otherwise the mode argument is TQClipboard::Clipboard.
+*/
+// ### remove 4.0
+void TQClipboard::clear()
+{
+ clear( selectionModeEnabled() ? Selection : Clipboard );
+}
+
+#endif // TQT_NO_MIMECLIPBOARD
+#endif // TQT_NO_CLIPBOARD
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqclipboard.h b/tqtinterface/qt4/src/kernel/tqclipboard.h
new file mode 100644
index 0000000..8e49f8d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqclipboard.h
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Definition of TQClipboard class
+**
+** Created : 960430
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQCLIPBOARD_H
+#define TQCLIPBOARD_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_CLIPBOARD
+
+#ifdef USE_QT4
+
+#include <Qt/qclipboard.h>
+
+#endif
+
+// #ifdef USE_QT4
+#if 0
+
+class TQClipboardPrivate;
+
+// extern TQClipboardPrivate *tqt_tqclipboard_tqcbp;
+
+class TQ_EXPORT TQClipboard : public QClipboard, virtual public TQt
+{
+public:
+// TQClipboard( TQT_BASE_OBJECT_NAME *tqparent=0, const char *name=0 ) : QClipboard( tqparent ) { setObjectName(QString::fromAscii(name)); }
+
+ TQMimeSource *data(Mode mode = Clipboard) const;
+ void setData(QMimeSource*, Mode mode = Clipboard);
+ TQString tqtext( TQCString& subtype, Mode mode ) const { TQString str = TQString(subtype); return QClipboard::text(str, (Mode)mode); }
+
+ #warning FIXME TQClipboard::setSelectionMode() and friends have no effect!
+ void setSelectionMode(bool enable);
+ bool selectionModeEnabled() const;
+};
+
+#else // USE_QT4
+
+class TQMimeSource;
+
+class TQ_EXPORT TQClipboard : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+private:
+ TQClipboard( TQObject *tqparent=0, const char *name=0 );
+ ~TQClipboard();
+
+public:
+ enum Mode { Clipboard, Selection };
+
+ void clear( Mode mode ); // ### default arg = Clipboard in 4.0
+ void clear(); // ### remove 4.0
+
+ bool supportsSelection() const;
+ bool ownsSelection() const;
+ bool ownsClipboard() const;
+
+ void setSelectionMode(bool enable); // ### remove 4.0
+ bool selectionModeEnabled() const; // ### remove 4.0
+
+ // ### default arg mode = Clipboard in 4.0 for all of these
+ TQString text( Mode mode ) const;
+ TQString text( TQCString& subtype, Mode mode ) const;
+ void setText( const TQString &, Mode mode );
+
+#ifndef TQT_NO_MIMECLIPBOARD
+ TQMimeSource *data( Mode mode ) const;
+ void setData( TQMimeSource*, Mode mode );
+
+ TQImage image( Mode mode ) const;
+ TQPixmap pixmap( Mode mode ) const;
+ void setImage( const TQImage &, Mode mode );
+ void setPixmap( const TQPixmap &, Mode mode );
+#endif
+
+ // ### remove all of these in 4.0
+ TQString text() const;
+ TQString text(TQCString& subtype) const;
+ void setText( const TQString &);
+
+#ifndef TQT_NO_MIMECLIPBOARD
+ TQMimeSource *data() const;
+ void setData( TQMimeSource* );
+
+ TQImage image() const;
+ TQPixmap pixmap() const;
+ void setImage( const TQImage & );
+ void setPixmap( const TQPixmap & );
+#endif
+
+Q_SIGNALS:
+ void selectionChanged();
+ void dataChanged();
+
+private Q_SLOTS:
+ void ownerDestroyed();
+
+protected:
+ void connectNotify( const char * );
+ bool event( TQEvent * );
+
+ friend class TQApplication;
+ friend class TQBaseApplication;
+ friend class TQDragManager;
+ friend class TQMimeSource;
+
+private:
+#if defined(TQ_WS_MAC)
+ void loadScrap(bool convert);
+ void saveScrap();
+#endif
+
+ // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQClipboard( const TQClipboard & );
+ TQClipboard &operator=( const TQClipboard & );
+#endif
+};
+
+#endif // USE_QT4
+
+#endif // TQT_NO_CLIPBOARD
+
+#endif // TQCLIPBOARD_H \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqclipboard_x11.cpp b/tqtinterface/qt4/src/kernel/tqclipboard_x11.cpp
new file mode 100644
index 0000000..14e7f08
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqclipboard_x11.cpp
@@ -0,0 +1,2020 @@
+/****************************************************************************
+**
+** Implementation of TQClipboard class for X11
+**
+** Created : 960430
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+// #define TQCLIPBOARD_DEBUG
+// #define TQCLIPBOARD_DEBUG_VERBOSE
+
+#ifdef TQCLIPBOARD_DEBUG
+# define TQDEBUG qDebug
+#else
+# define TQDEBUG if (FALSE) qDebug
+#endif
+
+#ifdef TQCLIPBOARD_DEBUG_VERBOSE
+# define VTQDEBUG qDebug
+#else
+# define VTQDEBUG if (FALSE) qDebug
+#endif
+
+#include "tqplatformdefs.h"
+
+// POSIX Large File Support redefines open -> open64
+#if defined(open)
+# undef open
+#endif
+
+#include "tqclipboard.h"
+
+#ifndef TQT_NO_CLIPBOARD
+
+#include "tqapplication.h"
+#include "tqeventloop.h"
+#include "tqbitmap.h"
+#include "tqdatetime.h"
+#include "tqdragobject.h"
+#include "tqbuffer.h"
+#include "tqtextcodec.h"
+#include "tqvaluelist.h"
+#include "tqmap.h"
+#include "tqt_x11_p.h"
+#include "tqapplication_p.h"
+
+// #ifdef USE_QT4
+#if 0
+
+/*****************************************************************************
+ Internal TQClipboard functions for X11.
+ *****************************************************************************/
+
+// from qapplication_x11.cpp
+typedef int (*QX11EventFilter) (XEvent*);
+extern QX11EventFilter qt_set_x11_event_filter (QX11EventFilter filter);
+
+extern Time qt_x_incr; // def. in qapplication_x11.cpp
+extern Atom qt_xa_clipboard;
+extern Atom qt_selection_property;
+extern Atom qt_clipboard_sentinel;
+extern Atom qt_selection_sentinel;
+extern Atom qt_utf8_string;
+
+// from qdnd_x11.cpp
+extern Atom* qt_xdnd_str_to_atom( const char *mimeType );
+extern const char* qt_xdnd_atom_to_str( Atom );
+
+
+static int clipboard_timeout = 5000; // 5s timeout on clipboard operations
+
+static TQWidget * owner = 0;
+static TQWidget *requestor = 0;
+static bool inSelectionMode_obsolete = FALSE; // ### remove 4.0
+static bool timer_event_clear = FALSE;
+static int timer_id = 0;
+
+static int pending_timer_id = 0;
+static bool pending_clipboard_changed = FALSE;
+static bool pending_selection_changed = FALSE;
+
+
+// event capture mechanism for qt_xclb_wait_for_event
+static bool waiting_for_data = FALSE;
+static bool has_captured_event = FALSE;
+static Window capture_event_win = None;
+static int capture_event_type = -1;
+static XEvent captured_event;
+
+// event filter function... captures interesting events while
+// qt_xclb_wait_for_event is running the event loop
+static int qt_xclb_event_filter(XEvent *event)
+{
+ if (event->xany.type == capture_event_type &&
+ event->xany.window == capture_event_win) {
+ VTQDEBUG( "TQClipboard: event_filter(): caught event type %d", event->type );
+ has_captured_event = TRUE;
+ captured_event = *event;
+ return 1;
+ }
+
+ return 0;
+}
+
+static Bool checkForClipboardEvents(Display *, XEvent *e, XPointer)
+{
+ return ((e->type == SelectionRequest && (e->xselectionrequest.selection == XA_PRIMARY
+ || e->xselectionrequest.selection == qt_xa_clipboard))
+ || (e->type == SelectionClear && (e->xselectionclear.selection == XA_PRIMARY
+ || e->xselectionclear.selection == qt_xa_clipboard)));
+}
+
+bool qt_xclb_wait_for_event( Display *dpy, Window win, int type, XEvent *event,
+ int timeout )
+{
+ TQTime started = TQTime::currentTime();
+ TQTime now = started;
+
+ if (tqApp->eventLoop()->inherits("TQMotif")) { // yes yes, evil hack, we know
+ if ( waiting_for_data )
+ qFatal( "TQClipboard: internal error, qt_xclb_wait_for_event recursed" );
+
+ waiting_for_data = TRUE;
+ has_captured_event = FALSE;
+ capture_event_win = win;
+ capture_event_type = type;
+
+ QX11EventFilter old_event_filter = qt_set_x11_event_filter(qt_xclb_event_filter);
+
+ do {
+ if ( XCheckTypedWindowEvent(dpy,win,type,event) ) {
+ waiting_for_data = FALSE;
+ qt_set_x11_event_filter(old_event_filter);
+ return TRUE;
+ }
+
+ now = TQTime::currentTime();
+ if ( started > now ) // crossed midnight
+ started = now;
+
+ // 0x08 == ExcludeTimers for X11 only
+ tqApp->eventLoop()->processEvents( TQEventLoop::ExcludeUserInput |
+ TQEventLoop::ExcludeSocketNotifiers |
+ TQEventLoop::WaitForMore | 0x08 );
+
+ if ( has_captured_event ) {
+ waiting_for_data = FALSE;
+ *event = captured_event;
+ qt_set_x11_event_filter(old_event_filter);
+ return TRUE;
+ }
+ } while ( started.msecsTo(now) < timeout );
+
+ waiting_for_data = FALSE;
+ qt_set_x11_event_filter(old_event_filter);
+
+ return FALSE;
+ }
+
+ bool flushed = FALSE;
+ do {
+ if ( XCheckTypedWindowEvent(dpy,win,type,event) )
+ return TRUE;
+
+ // process other clipboard events, since someone is probably requesting data from us
+ XEvent e;
+ if (XCheckIfEvent(dpy, &e, checkForClipboardEvents, 0))
+ tqApp->x11ProcessEvent(&e);
+
+ now = TQTime::currentTime();
+ if ( started > now ) // crossed midnight
+ started = now;
+
+ if(!flushed) {
+ XFlush( dpy );
+ flushed = TRUE;
+ }
+
+ // sleep 50ms, so we don't use up CPU cycles all the time.
+ struct timeval usleep_tv;
+ usleep_tv.tv_sec = 0;
+ usleep_tv.tv_usec = 50000;
+ select(0, 0, 0, 0, &usleep_tv);
+ } while ( started.msecsTo(now) < timeout );
+
+ return FALSE;
+}
+
+static inline int maxSelectionIncr( Display *dpy )
+{ return XMaxRequestSize(dpy) > 65536 ? 65536*4 : XMaxRequestSize(dpy)*4 - 100; }
+
+// uglyhack: externed into qt_xdnd.cpp. qt is really not designed for
+// single-platform, multi-purpose blocks of code...
+bool qt_xclb_read_property( Display *dpy, Window win, Atom property,
+ bool deleteProperty,
+ TQByteArray *buffer, int *size, Atom *type,
+ int *format, bool nullterm )
+{
+ int maxsize = maxSelectionIncr(dpy);
+ ulong bytes_left; // bytes_after
+ ulong length; // nitems
+ uchar *data;
+ Atom dummy_type;
+ int dummy_format;
+ int r;
+
+ if ( !type ) // allow null args
+ type = &dummy_type;
+ if ( !format )
+ format = &dummy_format;
+
+ // Don't read anything, just get the size of the property data
+ r = XGetWindowProperty( dpy, win, property, 0, 0, False,
+ AnyPropertyType, type, format,
+ &length, &bytes_left, &data );
+ if (r != Success || (type && *type == None)) {
+ buffer->resize( 0 );
+ return FALSE;
+ }
+ XFree( (char*)data );
+
+ int offset = 0, buffer_offset = 0, format_inc = 1, proplen = bytes_left;
+
+ VTQDEBUG("TQClipboard: read_property(): initial property length: %d", proplen);
+
+ switch (*format) {
+ case 8:
+ default:
+ format_inc = sizeof(char) / 1;
+ break;
+
+ case 16:
+ format_inc = sizeof(short) / 2;
+ proplen *= sizeof(short) / 2;
+ break;
+
+ case 32:
+ format_inc = sizeof(long) / 4;
+ proplen *= sizeof(long) / 4;
+ break;
+ }
+
+ bool ok = buffer->tqresize( proplen + (nullterm ? 1 : 0) );
+
+ VTQDEBUG("TQClipboard: read_property(): buffer resized to %d", buffer->size());
+
+ if ( ok ) {
+ // could allocate buffer
+
+ while ( bytes_left ) {
+ // more to read...
+
+ r = XGetWindowProperty( dpy, win, property, offset, maxsize/4,
+ False, AnyPropertyType, type, format,
+ &length, &bytes_left, &data );
+ if (r != Success || (type && *type == None))
+ break;
+
+ offset += length / (32 / *format);
+ length *= format_inc * (*format) / 8;
+
+ // Here we check if we get a buffer overflow and tries to
+ // recover -- this shouldn't normally happen, but it doesn't
+ // hurt to be defensive
+ if (buffer_offset + length > buffer->size()) {
+ length = buffer->size() - buffer_offset;
+
+ // escape loop
+ bytes_left = 0;
+ }
+
+ memcpy(buffer->data() + buffer_offset, data, length);
+ buffer_offset += length;
+
+ XFree( (char*)data );
+ }
+
+ static Atom xa_compound_text = *qt_xdnd_str_to_atom( "COMPOUND_TEXT" );
+ if ( *format == 8 && *type == xa_compound_text ) {
+ // convert COMPOUND_TEXT to a multibyte string
+ XTextProperty textprop;
+ textprop.encoding = *type;
+ textprop.format = *format;
+ textprop.nitems = length;
+ textprop.value = (unsigned char *) buffer->data();
+
+ char **list_ret = 0;
+ int count;
+ if ( XmbTextPropertyToTextList( dpy, &textprop, &list_ret,
+ &count ) == Success &&
+ count && list_ret ) {
+ offset = strlen( list_ret[0] );
+ buffer->resize( offset + ( nullterm ? 1 : 0 ) );
+ memcpy( buffer->data(), list_ret[0], offset );
+ }
+ if (list_ret) XFreeStringList(list_ret);
+ }
+
+ // zero-terminate (for text)
+ if (nullterm)
+ buffer->tqat(buffer_offset) = '\0';
+ }
+
+ // correct size, not 0-term.
+ if ( size )
+ *size = buffer_offset;
+
+ VTQDEBUG("TQClipboard: read_property(): buffer size %d, buffer offset %d, offset %d",
+ buffer->size(), buffer_offset, offset);
+
+ if ( deleteProperty )
+ XDeleteProperty( dpy, win, property );
+
+ XFlush( dpy );
+
+ return ok;
+}
+
+// this is externed into qt_xdnd.cpp too.
+TQByteArray qt_xclb_read_incremental_property( Display *dpy, Window win,
+ Atom property, int nbytes,
+ bool nullterm )
+{
+ XEvent event;
+
+ TQByteArray buf;
+ TQByteArray tmp_buf;
+ bool alloc_error = FALSE;
+ int length;
+ int offset = 0;
+
+ if ( nbytes > 0 ) {
+ // Reserve buffer + zero-terminator (for text data)
+ // We want to complete the INCR transfer even if we cannot
+ // allocate more memory
+ alloc_error = !buf.tqresize(nbytes+1);
+ }
+
+ for (;;) {
+ XFlush( dpy );
+ if ( !qt_xclb_wait_for_event(dpy,win,PropertyNotify,&event,clipboard_timeout) )
+ break;
+ if ( event.xproperty.atom != property ||
+ event.xproperty.state != PropertyNewValue )
+ continue;
+ if ( qt_xclb_read_property(dpy, win, property, TRUE, &tmp_buf,
+ &length,0, 0, FALSE) ) {
+ if ( length == 0 ) { // no more data, we're done
+ if ( nullterm ) {
+ buf.resize( offset+1 );
+ buf.tqat( offset ) = '\0';
+ } else {
+ buf.resize(offset);
+ }
+ return buf;
+ } else if ( !alloc_error ) {
+ if ( offset+length > (int)buf.size() ) {
+ if ( !buf.tqresize(offset+length+65535) ) {
+ alloc_error = TRUE;
+ length = buf.size() - offset;
+ }
+ }
+ memcpy( buf.data()+offset, tmp_buf.data(), length );
+ tmp_buf.resize( 0 );
+ offset += length;
+ }
+ } else {
+ break;
+ }
+ }
+
+ // timed out ... create a new requestor window, otherwise the requestor
+ // could consider next request to be still part of this timed out request
+ delete requestor;
+ requestor = new TQWidget( 0, "internal clipboard requestor" );
+
+ return TQByteArray();
+}
+
+/*! \obsolete
+
+ Use the TQClipboard::data(), TQClipboard::setData() and related functions
+ which take a TQClipboard::Mode argument.
+
+ Sets the clipboard selection mode. If \a enable is TRUE, then
+ subsequent calls to TQClipboard::setData() and other functions
+ which put data into the clipboard will put the data into the mouse
+ selection, otherwise the data will be put into the clipboard.
+
+ \sa supportsSelection(), selectionModeEnabled()
+*/
+void TQClipboard::setSelectionMode(bool enable)
+{ inSelectionMode_obsolete = enable; }
+
+
+/*! \obsolete
+
+ Use the TQClipboard::data(), TQClipboard::setData() and related functions
+ which take a TQClipboard::Mode argument.
+
+ Returns the selection mode.
+
+ \sa setSelectionMode(), supportsSelection()
+*/
+bool TQClipboard::selectionModeEnabled() const
+{ return inSelectionMode_obsolete; }
+
+#else // USE_QT4
+
+
+// REVISED: arnt
+
+/*****************************************************************************
+ Internal TQClipboard functions for X11.
+ *****************************************************************************/
+
+// from qapplication_x11.cpp
+typedef int (*QX11EventFilter) (XEvent*);
+extern QX11EventFilter qt_set_x11_event_filter (QX11EventFilter filter);
+
+extern Time qt_x_incr; // def. in qapplication_x11.cpp
+extern Atom qt_xa_clipboard;
+extern Atom qt_selection_property;
+extern Atom qt_clipboard_sentinel;
+extern Atom qt_selection_sentinel;
+extern Atom qt_utf8_string;
+
+// from qdnd_x11.cpp
+extern Atom* qt_xdnd_str_to_atom( const char *mimeType );
+extern const char* qt_xdnd_atom_to_str( Atom );
+
+
+static int clipboard_timeout = 5000; // 5s timeout on clipboard operations
+
+static TQWidget * owner = 0;
+static TQWidget *requestor = 0;
+static bool inSelectionMode_obsolete = FALSE; // ### remove 4.0
+static bool timer_event_clear = FALSE;
+static int timer_id = 0;
+
+static int pending_timer_id = 0;
+static bool pending_clipboard_changed = FALSE;
+static bool pending_selection_changed = FALSE;
+
+
+// event capture mechanism for qt_xclb_wait_for_event
+static bool waiting_for_data = FALSE;
+static bool has_captured_event = FALSE;
+static Window capture_event_win = None;
+static int capture_event_type = -1;
+static XEvent captured_event;
+
+class TQClipboardWatcher; // forward decl
+static TQClipboardWatcher *selection_watcher = 0;
+static TQClipboardWatcher *clipboard_watcher = 0;
+
+static void cleanup()
+{
+ delete owner;
+ delete requestor;
+ owner = 0;
+ requestor = 0;
+}
+
+static
+void setupOwner()
+{
+ if ( owner )
+ return;
+ owner = new TQWidget( 0, "internal clipboard owner" );
+ requestor = new TQWidget(0, "internal clipboard requestor");
+ qAddPostRoutine( cleanup );
+}
+
+static
+int sizeof_format(int format)
+{
+ int sz;
+ switch (format) {
+ default:
+ case 8: sz = sizeof( char); break;
+ case 16: sz = sizeof(short); break;
+ case 32: sz = sizeof( long); break;
+ }
+ return sz;
+}
+
+class TQClipboardWatcher : public TQMimeSource {
+public:
+ TQClipboardWatcher( TQClipboard::Mode mode );
+ ~TQClipboardWatcher();
+ bool empty() const;
+ const char* format( int n ) const;
+ TQByteArray tqencodedData( const char* fmt ) const;
+ TQByteArray getDataInFormat(Atom fmtatom) const;
+
+ Atom atom;
+ TQValueList<const char *> formatList;
+};
+
+
+
+class TQClipboardData
+{
+public:
+ TQClipboardData();
+ ~TQClipboardData();
+
+ void setSource(TQMimeSource* s)
+ {
+ clear(TRUE);
+ src = s;
+ }
+
+ TQMimeSource *source() const { return src; }
+
+ void addTransferredPixmap(TQPixmap pm)
+ {
+ /* TODO: queue them */
+ transferred[tindex] = pm;
+ tindex=(tindex+1)%2;
+ }
+ void clearTransfers()
+ {
+ transferred[0] = TQPixmap();
+ transferred[1] = TQPixmap();
+ }
+
+ void clear(bool destruct=TRUE);
+
+ TQMimeSource *src;
+ Time timestamp;
+
+ TQPixmap transferred[2];
+ int tindex;
+};
+
+TQClipboardData::TQClipboardData()
+{
+ src = 0;
+ timestamp = CurrentTime;
+ tindex=0;
+}
+
+TQClipboardData::~TQClipboardData()
+{ clear(); }
+
+void TQClipboardData::clear(bool destruct)
+{
+ if(destruct)
+ delete src;
+ src = 0;
+ timestamp = CurrentTime;
+}
+
+
+static TQClipboardData *internalCbData = 0;
+static TQClipboardData *internalSelData = 0;
+
+static void cleanupClipboardData()
+{
+ delete internalCbData;
+ internalCbData = 0;
+}
+
+static TQClipboardData *clipboardData()
+{
+ if ( internalCbData == 0 ) {
+ internalCbData = new TQClipboardData;
+ TQ_CHECK_PTR( internalCbData );
+ qAddPostRoutine( cleanupClipboardData );
+ }
+ return internalCbData;
+}
+
+void qt_clipboard_cleanup_mime_source(TQMimeSource *src)
+{
+ if(internalCbData && internalCbData->source() == src)
+ internalCbData->clear(FALSE);
+}
+
+static void cleanupSelectionData()
+{
+ delete internalSelData;
+ internalSelData = 0;
+}
+
+static TQClipboardData *selectionData()
+{
+ if (internalSelData == 0) {
+ internalSelData = new TQClipboardData;
+ TQ_CHECK_PTR(internalSelData);
+ qAddPostRoutine(cleanupSelectionData);
+ }
+ return internalSelData;
+}
+
+class TQClipboardINCRTransaction
+{
+public:
+ TQClipboardINCRTransaction(Window w, Atom p, Atom t, int f, TQByteArray d, unsigned int i);
+ ~TQClipboardINCRTransaction(void);
+
+ int x11Event(XEvent *event);
+
+ Window window;
+ Atom property, target;
+ int format;
+ TQByteArray data;
+ unsigned int increment;
+ unsigned int offset;
+};
+
+typedef TQMap<Window,TQClipboardINCRTransaction*> TransactionMap;
+static TransactionMap *transactions = 0;
+static QX11EventFilter prev_x11_event_filter = 0;
+static int incr_timer_id = 0;
+
+static int qt_xclb_transation_event_handler(XEvent *event)
+{
+ TransactionMap::Iterator it = transactions->tqfind(event->xany.window);
+ if (it != transactions->end()) {
+ if ((*it)->x11Event(event) != 0)
+ return 1;
+ }
+ if (prev_x11_event_filter)
+ return prev_x11_event_filter(event);
+ return 0;
+}
+
+/*
+ called when no INCR activity has happened for 'clipboard_timeout'
+ milliseconds... we assume that all unfinished transactions have
+ timed out and remove everything from the transaction map
+*/
+static void qt_xclb_incr_timeout(void)
+{
+ qWarning("TQClipboard: timed out while sending data");
+
+ while (transactions)
+ delete *transactions->begin();
+}
+
+TQClipboardINCRTransaction::TQClipboardINCRTransaction(Window w, Atom p, Atom t, int f,
+ TQByteArray d, unsigned int i)
+ : window(w), property(p), target(t), format(f), data(d), increment(i), offset(0u)
+{
+ TQDEBUG("TQClipboard: sending %d bytes (INCR transaction %p)", d.size(), this);
+
+ XSelectInput(TQPaintDevice::x11AppDisplay(), window, PropertyChangeMask);
+
+ if (! transactions) {
+ VTQDEBUG("TQClipboard: created INCR transaction map");
+ transactions = new TransactionMap;
+ prev_x11_event_filter = qt_set_x11_event_filter(qt_xclb_transation_event_handler);
+
+ incr_timer_id = TQApplication::clipboard()->startTimer(clipboard_timeout);
+ }
+ transactions->insert(window, this);
+}
+
+TQClipboardINCRTransaction::~TQClipboardINCRTransaction(void)
+{
+ VTQDEBUG("TQClipboard: destroyed INCR transacton %p", this);
+
+ XSelectInput(TQPaintDevice::x11AppDisplay(), window, NoEventMask);
+
+ transactions->remove(window);
+ if (transactions->isEmpty()) {
+ VTQDEBUG("TQClipboard: no more INCR transations");
+ delete transactions;
+ transactions = 0;
+ (void)qt_set_x11_event_filter(prev_x11_event_filter);
+
+ if (incr_timer_id != 0) {
+ TQApplication::clipboard()->killTimer(incr_timer_id);
+ incr_timer_id = 0;
+ }
+ }
+}
+
+int TQClipboardINCRTransaction::x11Event(XEvent *event)
+{
+ if (event->type != PropertyNotify
+ || (event->xproperty.state != PropertyDelete
+ || event->xproperty.atom != property))
+ return 0;
+
+ // restart the INCR timer
+ if (incr_timer_id) TQApplication::clipboard()->killTimer(incr_timer_id);
+ incr_timer_id = TQApplication::clipboard()->startTimer(clipboard_timeout);
+
+ unsigned int bytes_left = data.size() - offset;
+ if (bytes_left > 0) {
+ unsigned int xfer = TQMIN(increment, bytes_left);
+ VTQDEBUG("TQClipboard: sending %d bytes, %d remaining (INCR transaction %p)",
+ xfer, bytes_left - xfer, this);
+
+ XChangeProperty(TQPaintDevice::x11AppDisplay(), window, property, target, format,
+ PropModeReplace, (uchar *) data.data() + offset, xfer);
+ offset += xfer;
+ } else {
+ // INCR transaction finished...
+ XChangeProperty(TQPaintDevice::x11AppDisplay(), window, property, target, format,
+ PropModeReplace, (uchar *) data.data(), 0);
+ delete this;
+ }
+
+ return 1;
+}
+
+
+/*****************************************************************************
+ TQClipboard member functions for X11.
+ *****************************************************************************/
+
+
+void TQClipboard::clear( Mode mode )
+{ setData(0, mode); }
+
+
+/*!
+ Returns TRUE if the clipboard supports mouse selection; otherwise
+ returns FALSE.
+*/
+bool TQClipboard::supportsSelection() const
+{ return TRUE; }
+
+
+/*!
+ Returns TRUE if this clipboard object owns the mouse selection
+ data; otherwise returns FALSE.
+*/
+bool TQClipboard::ownsSelection() const
+{ return selectionData()->timestamp != CurrentTime; }
+
+/*!
+ Returns TRUE if this clipboard object owns the clipboard data;
+ otherwise returns FALSE.
+*/
+bool TQClipboard::ownsClipboard() const
+{ return clipboardData()->timestamp != CurrentTime; }
+
+
+/*! \obsolete
+
+ Use the TQClipboard::data(), TQClipboard::setData() and related functions
+ which take a TQClipboard::Mode argument.
+
+ Sets the clipboard selection mode. If \a enable is TRUE, then
+ subsequent calls to TQClipboard::setData() and other functions
+ which put data into the clipboard will put the data into the mouse
+ selection, otherwise the data will be put into the clipboard.
+
+ \sa supportsSelection(), selectionModeEnabled()
+*/
+void TQClipboard::setSelectionMode(bool enable)
+{ inSelectionMode_obsolete = enable; }
+
+
+/*! \obsolete
+
+ Use the TQClipboard::data(), TQClipboard::setData() and related functions
+ which take a TQClipboard::Mode argument.
+
+ Returns the selection mode.
+
+ \sa setSelectionMode(), supportsSelection()
+*/
+bool TQClipboard::selectionModeEnabled() const
+{ return inSelectionMode_obsolete; }
+
+
+// event filter function... captures interesting events while
+// qt_xclb_wait_for_event is running the event loop
+static int qt_xclb_event_filter(XEvent *event)
+{
+ if (event->xany.type == capture_event_type &&
+ event->xany.window == capture_event_win) {
+ VTQDEBUG( "TQClipboard: event_filter(): caught event type %d", event->type );
+ has_captured_event = TRUE;
+ captured_event = *event;
+ return 1;
+ }
+
+ return 0;
+}
+
+static Bool checkForClipboardEvents(Display *, XEvent *e, XPointer)
+{
+ return ((e->type == SelectionRequest && (e->xselectionrequest.selection == XA_PRIMARY
+ || e->xselectionrequest.selection == qt_xa_clipboard))
+ || (e->type == SelectionClear && (e->xselectionclear.selection == XA_PRIMARY
+ || e->xselectionclear.selection == qt_xa_clipboard)));
+}
+
+bool qt_xclb_wait_for_event( Display *dpy, Window win, int type, XEvent *event,
+ int timeout )
+{
+ TQTime started = TQTime::currentTime();
+ TQTime now = started;
+
+ if (tqApp->eventLoop()->inherits("TQMotif")) { // yes yes, evil hack, we know
+ if ( waiting_for_data )
+ qFatal( "TQClipboard: internal error, qt_xclb_wait_for_event recursed" );
+
+ waiting_for_data = TRUE;
+ has_captured_event = FALSE;
+ capture_event_win = win;
+ capture_event_type = type;
+
+ QX11EventFilter old_event_filter = qt_set_x11_event_filter(qt_xclb_event_filter);
+
+ do {
+ if ( XCheckTypedWindowEvent(dpy,win,type,event) ) {
+ waiting_for_data = FALSE;
+ qt_set_x11_event_filter(old_event_filter);
+ return TRUE;
+ }
+
+ now = TQTime::currentTime();
+ if ( started > now ) // crossed midnight
+ started = now;
+
+ // 0x08 == ExcludeTimers for X11 only
+ tqApp->eventLoop()->processEvents( TQEventLoop::ExcludeUserInput |
+ TQEventLoop::ExcludeSocketNotifiers |
+ TQEventLoop::WaitForMore | 0x08 );
+
+ if ( has_captured_event ) {
+ waiting_for_data = FALSE;
+ *event = captured_event;
+ qt_set_x11_event_filter(old_event_filter);
+ return TRUE;
+ }
+ } while ( started.msecsTo(now) < timeout );
+
+ waiting_for_data = FALSE;
+ qt_set_x11_event_filter(old_event_filter);
+
+ return FALSE;
+ }
+
+ bool flushed = FALSE;
+ do {
+ if ( XCheckTypedWindowEvent(dpy,win,type,event) )
+ return TRUE;
+
+ // process other clipboard events, since someone is probably requesting data from us
+ XEvent e;
+ if (XCheckIfEvent(dpy, &e, checkForClipboardEvents, 0))
+ tqApp->x11ProcessEvent(&e);
+
+ now = TQTime::currentTime();
+ if ( started > now ) // crossed midnight
+ started = now;
+
+ if(!flushed) {
+ XFlush( dpy );
+ flushed = TRUE;
+ }
+
+ // sleep 50ms, so we don't use up CPU cycles all the time.
+ struct timeval usleep_tv;
+ usleep_tv.tv_sec = 0;
+ usleep_tv.tv_usec = 50000;
+ select(0, 0, 0, 0, &usleep_tv);
+ } while ( started.msecsTo(now) < timeout );
+
+ return FALSE;
+}
+
+
+static inline int maxSelectionIncr( Display *dpy )
+{ return XMaxRequestSize(dpy) > 65536 ? 65536*4 : XMaxRequestSize(dpy)*4 - 100; }
+
+// uglyhack: externed into qt_xdnd.cpp. qt is really not designed for
+// single-platform, multi-purpose blocks of code...
+bool qt_xclb_read_property( Display *dpy, Window win, Atom property,
+ bool deleteProperty,
+ TQByteArray *buffer, int *size, Atom *type,
+ int *format, bool nullterm )
+{
+ int maxsize = maxSelectionIncr(dpy);
+ ulong bytes_left; // bytes_after
+ ulong length; // nitems
+ uchar *data;
+ Atom dummy_type;
+ int dummy_format;
+ int r;
+
+ if ( !type ) // allow null args
+ type = &dummy_type;
+ if ( !format )
+ format = &dummy_format;
+
+ // Don't read anything, just get the size of the property data
+ r = XGetWindowProperty( dpy, win, property, 0, 0, False,
+ AnyPropertyType, type, format,
+ &length, &bytes_left, &data );
+ if (r != Success || (type && *type == None)) {
+ buffer->resize( 0 );
+ return FALSE;
+ }
+ XFree( (char*)data );
+
+ int offset = 0, buffer_offset = 0, format_inc = 1, proplen = bytes_left;
+
+ VTQDEBUG("TQClipboard: read_property(): initial property length: %d", proplen);
+
+ switch (*format) {
+ case 8:
+ default:
+ format_inc = sizeof(char) / 1;
+ break;
+
+ case 16:
+ format_inc = sizeof(short) / 2;
+ proplen *= sizeof(short) / 2;
+ break;
+
+ case 32:
+ format_inc = sizeof(long) / 4;
+ proplen *= sizeof(long) / 4;
+ break;
+ }
+
+ bool ok = buffer->tqresize( proplen + (nullterm ? 1 : 0) );
+
+ VTQDEBUG("TQClipboard: read_property(): buffer resized to %d", buffer->size());
+
+ if ( ok ) {
+ // could allocate buffer
+
+ while ( bytes_left ) {
+ // more to read...
+
+ r = XGetWindowProperty( dpy, win, property, offset, maxsize/4,
+ False, AnyPropertyType, type, format,
+ &length, &bytes_left, &data );
+ if (r != Success || (type && *type == None))
+ break;
+
+ offset += length / (32 / *format);
+ length *= format_inc * (*format) / 8;
+
+ // Here we check if we get a buffer overflow and tries to
+ // recover -- this shouldn't normally happen, but it doesn't
+ // hurt to be defensive
+ if (buffer_offset + length > buffer->size()) {
+ length = buffer->size() - buffer_offset;
+
+ // escape loop
+ bytes_left = 0;
+ }
+
+ memcpy(buffer->data() + buffer_offset, data, length);
+ buffer_offset += length;
+
+ XFree( (char*)data );
+ }
+
+ static Atom xa_compound_text = *qt_xdnd_str_to_atom( "COMPOUND_TEXT" );
+ if ( *format == 8 && *type == xa_compound_text ) {
+ // convert COMPOUND_TEXT to a multibyte string
+ XTextProperty textprop;
+ textprop.encoding = *type;
+ textprop.format = *format;
+ textprop.nitems = length;
+ textprop.value = (unsigned char *) buffer->data();
+
+ char **list_ret = 0;
+ int count;
+ if ( XmbTextPropertyToTextList( dpy, &textprop, &list_ret,
+ &count ) == Success &&
+ count && list_ret ) {
+ offset = strlen( list_ret[0] );
+ buffer->resize( offset + ( nullterm ? 1 : 0 ) );
+ memcpy( buffer->data(), list_ret[0], offset );
+ }
+ if (list_ret) XFreeStringList(list_ret);
+ }
+
+ // zero-terminate (for text)
+ if (nullterm)
+ buffer->tqat(buffer_offset) = '\0';
+ }
+
+ // correct size, not 0-term.
+ if ( size )
+ *size = buffer_offset;
+
+ VTQDEBUG("TQClipboard: read_property(): buffer size %d, buffer offset %d, offset %d",
+ buffer->size(), buffer_offset, offset);
+
+ if ( deleteProperty )
+ XDeleteProperty( dpy, win, property );
+
+ XFlush( dpy );
+
+ return ok;
+}
+
+
+// this is externed into qt_xdnd.cpp too.
+TQByteArray qt_xclb_read_incremental_property( Display *dpy, Window win,
+ Atom property, int nbytes,
+ bool nullterm )
+{
+ XEvent event;
+
+ TQByteArray buf;
+ TQByteArray tmp_buf;
+ bool alloc_error = FALSE;
+ int length;
+ int offset = 0;
+
+ if ( nbytes > 0 ) {
+ // Reserve buffer + zero-terminator (for text data)
+ // We want to complete the INCR transfer even if we cannot
+ // allocate more memory
+ alloc_error = !buf.tqresize(nbytes+1);
+ }
+
+ for (;;) {
+ XFlush( dpy );
+ if ( !qt_xclb_wait_for_event(dpy,win,PropertyNotify,&event,clipboard_timeout) )
+ break;
+ if ( event.xproperty.atom != property ||
+ event.xproperty.state != PropertyNewValue )
+ continue;
+ if ( qt_xclb_read_property(dpy, win, property, TRUE, &tmp_buf,
+ &length,0, 0, FALSE) ) {
+ if ( length == 0 ) { // no more data, we're done
+ if ( nullterm ) {
+ buf.resize( offset+1 );
+ buf.tqat( offset ) = '\0';
+ } else {
+ buf.resize(offset);
+ }
+ return buf;
+ } else if ( !alloc_error ) {
+ if ( offset+length > (int)buf.size() ) {
+ if ( !buf.tqresize(offset+length+65535) ) {
+ alloc_error = TRUE;
+ length = buf.size() - offset;
+ }
+ }
+ memcpy( buf.data()+offset, tmp_buf.data(), length );
+ tmp_buf.resize( 0 );
+ offset += length;
+ }
+ } else {
+ break;
+ }
+ }
+
+ // timed out ... create a new requestor window, otherwise the requestor
+ // could consider next request to be still part of this timed out request
+ delete requestor;
+ requestor = new TQWidget( 0, "internal clipboard requestor" );
+
+ return TQByteArray();
+}
+
+static Atom send_selection(TQClipboardData *d, Atom target, Window window, Atom property,
+ int format = 0, TQByteArray data = TQByteArray());
+
+static Atom send_targets_selection(TQClipboardData *d, Window window, Atom property)
+{
+ int atoms = 0;
+ while (d->source()->format(atoms)) atoms++;
+ if (d->source()->provides("image/ppm")) atoms++;
+ if (d->source()->provides("image/pbm")) atoms++;
+ if (d->source()->provides("text/plain")) atoms+=4;
+
+ VTQDEBUG("TQClipboard: send_targets_selection(): %d provided types", atoms);
+
+ // for 64 bit cleanness... XChangeProperty expects long* for data with format == 32
+ TQByteArray data((atoms+3) * sizeof(long)); // plus TARGETS, MULTIPLE and TIMESTAMP
+ long *atarget = (long *) data.data();
+
+ const char *fmt;
+ int n = 0;
+ while ((fmt=d->source()->format(n)) && n < atoms)
+ atarget[n++] = *qt_xdnd_str_to_atom(fmt);
+
+ static Atom xa_text = *qt_xdnd_str_to_atom("TEXT");
+ static Atom xa_compound_text = *qt_xdnd_str_to_atom("COMPOUND_TEXT");
+ static Atom xa_targets = *qt_xdnd_str_to_atom("TARGETS");
+ static Atom xa_multiple = *qt_xdnd_str_to_atom("MULTIPLE");
+ static Atom xa_timestamp = *qt_xdnd_str_to_atom("TIMESTAMP");
+
+ if (d->source()->provides("image/ppm"))
+ atarget[n++] = XA_PIXMAP;
+ if (d->source()->provides("image/pbm"))
+ atarget[n++] = XA_BITMAP;
+ if (d->source()->provides("text/plain")) {
+ atarget[n++] = qt_utf8_string;
+ atarget[n++] = xa_text;
+ atarget[n++] = xa_compound_text;
+ atarget[n++] = XA_STRING;
+ }
+
+ atarget[n++] = xa_targets;
+ atarget[n++] = xa_multiple;
+ atarget[n++] = xa_timestamp;
+
+#if defined(TQCLIPBOARD_DEBUG_VERBOSE)
+ for (int index = 0; index < n; index++) {
+ VTQDEBUG(" atom %d: 0x%lx (%s)", index, atarget[index],
+ qt_xdnd_atom_to_str(atarget[index]));
+ }
+#endif
+
+ XChangeProperty(TQPaintDevice::x11AppDisplay(), window, property, XA_ATOM, 32,
+ PropModeReplace, (uchar *) data.data(), n);
+ return property;
+}
+
+static Atom send_string_selection(TQClipboardData *d, Atom target, Window window, Atom property)
+{
+ static Atom xa_text = *qt_xdnd_str_to_atom("TEXT");
+ static Atom xa_compound_text = *qt_xdnd_str_to_atom("COMPOUND_TEXT");
+
+ TQDEBUG("TQClipboard: send_string_selection():\n"
+ " property type %lx\n"
+ " property name '%s'",
+ target, qt_xdnd_atom_to_str(target));
+
+ if (target == xa_text || target == xa_compound_text) {
+ // the ICCCM states that TEXT and COMPOUND_TEXT are in the
+ // encoding of choice, so we choose the encoding of the locale
+ TQByteArray data = d->source()->tqencodedData("text/plain");
+ if(data.tqresize(data.size() + 1))
+ data[int(data.size() - 1)] = '\0';
+ char *list[] = { data.data(), NULL };
+
+ XICCEncodingStyle style =
+ (target == xa_compound_text) ? XCompoundTextStyle : XStdICCTextStyle;
+ XTextProperty textprop;
+ if (list[0] != NULL
+ && XmbTextListToTextProperty(TQPaintDevice::x11AppDisplay(),
+ list, 1, style, &textprop) == Success) {
+ TQDEBUG(" textprop type %lx\n"
+ " textprop name '%s'\n"
+ " format %d\n"
+ " %ld items",
+ textprop.encoding, qt_xdnd_atom_to_str(textprop.encoding),
+ textprop.format, textprop.nitems);
+
+ int sz = sizeof_format(textprop.format);
+ data.duplicate((const char *) textprop.value, textprop.nitems * sz);
+ XFree(textprop.value);
+
+ return send_selection(d, textprop.encoding, window, property, textprop.format, data);
+ }
+
+ return None;
+ }
+
+ Atom xtarget = None;
+ const char *fmt = 0;
+ if (target == XA_STRING
+ || (target == xa_text && TQTextCodec::codecForLocale()->mibEnum() == 4)) {
+ // the ICCCM states that STRING is latin1 plus newline and tab
+ // see section 2.6.2
+ fmt = "text/plain;charset=ISO-8859-1";
+ xtarget = XA_STRING;
+ } else if (target == qt_utf8_string) {
+ // proposed UTF8_STRING conversion type
+ fmt = "text/plain;charset=UTF-8";
+ xtarget = qt_utf8_string;
+ }
+
+ if (xtarget == None) // should not happen
+ return None;
+
+ TQByteArray data = d->source()->tqencodedData(fmt);
+
+ TQDEBUG(" format 8\n %d bytes", data.size());
+
+ return send_selection(d, xtarget, window, property, 8, data);
+}
+
+static Atom send_pixmap_selection(TQClipboardData *d, Atom target, Window window, Atom property)
+{
+ TQPixmap pm;
+
+ if ( target == XA_PIXMAP ) {
+ TQByteArray data = d->source()->tqencodedData("image/ppm");
+ pm.loadFromData(data);
+ } else if ( target == XA_BITMAP ) {
+ TQByteArray data = d->source()->tqencodedData("image/pbm");
+ TQImage img;
+ img.loadFromData(data);
+ if ( img.depth() != 1 )
+ img = img.convertDepth(1);
+ }
+
+ if (pm.isNull()) // should never happen
+ return None;
+
+ Pixmap handle = pm.handle();
+ XChangeProperty(TQPaintDevice::x11AppDisplay(), window, property,
+ target, 32, PropModeReplace, (uchar *) &handle, 1);
+ d->addTransferredPixmap(pm);
+ return property;
+
+}
+
+static Atom send_selection(TQClipboardData *d, Atom target, Window window, Atom property,
+ int format, TQByteArray data)
+{
+ if (format == 0) format = 8;
+
+ if (data.isEmpty()) {
+ const char *fmt = qt_xdnd_atom_to_str(target);
+ TQDEBUG("TQClipboard: send_selection(): converting to type '%s'", fmt);
+ if (fmt && !d->source()->provides(fmt)) // Not a MIME type we can produce
+ return None;
+ data = d->source()->tqencodedData(fmt);
+ }
+
+ TQDEBUG("TQClipboard: send_selection():\n"
+ " property type %lx\n"
+ " property name '%s'\n"
+ " format %d\n"
+ " %d bytes",
+ target, qt_xdnd_atom_to_str(target), format, data.size());
+
+ // don't allow INCR transfers when using MULTIPLE or to
+ // Motif clients (since Motif doesn't support INCR)
+ static Atom motif_clip_temporary = *qt_xdnd_str_to_atom("CLIP_TEMPORARY");
+ bool allow_incr = property != motif_clip_temporary;
+
+ // X_ChangeProperty protocol request is 24 bytes
+ const unsigned int increment = (XMaxRequestSize(TQPaintDevice::x11AppDisplay()) * 4) - 24;
+ if (data.size() > increment && allow_incr) {
+ long bytes = data.size();
+ XChangeProperty(TQPaintDevice::x11AppDisplay(), window, property,
+ qt_x_incr, 32, PropModeReplace, (uchar *) &bytes, 1);
+
+ (void)new TQClipboardINCRTransaction(window, property, target, format, data, increment);
+ return qt_x_incr;
+ }
+
+ // make sure we can perform the XChangeProperty in a single request
+ if (data.size() > increment)
+ return None; // ### perhaps use several XChangeProperty calls w/ PropModeAppend?
+
+ // use a single request to transfer data
+ XChangeProperty(TQPaintDevice::x11AppDisplay(), window, property, target,
+ format, PropModeReplace, (uchar *) data.data(),
+ data.size() / sizeof_format(format));
+ return property;
+}
+
+/*! \internal
+ Internal cleanup for Windows.
+*/
+void TQClipboard::ownerDestroyed()
+{ }
+
+
+/*! \internal
+ Internal optimization for Windows.
+*/
+void TQClipboard::connectNotify( const char * )
+{ }
+
+
+/*! \reimp
+ */
+bool TQClipboard::event( TQEvent *e )
+{
+ if ( e->type() == TQEvent::Timer ) {
+ TQTimerEvent *te = (TQTimerEvent *) e;
+
+ if ( waiting_for_data ) // should never happen
+ return FALSE;
+
+ if (te->timerId() == timer_id) {
+ killTimer(timer_id);
+ timer_id = 0;
+
+ timer_event_clear = TRUE;
+ if ( selection_watcher ) // clear selection
+ selectionData()->clear();
+ if ( clipboard_watcher ) // clear clipboard
+ clipboardData()->clear();
+ timer_event_clear = FALSE;
+
+ return TRUE;
+ } else if ( te->timerId() == pending_timer_id ) {
+ // I hate klipper
+ killTimer( pending_timer_id );
+ pending_timer_id = 0;
+
+ if ( pending_clipboard_changed ) {
+ pending_clipboard_changed = FALSE;
+ clipboardData()->clear();
+ emit dataChanged();
+ }
+ if ( pending_selection_changed ) {
+ pending_selection_changed = FALSE;
+ selectionData()->clear();
+ emit selectionChanged();
+ }
+
+ return TRUE;
+ } else if (te->timerId() == incr_timer_id) {
+ killTimer(incr_timer_id);
+ incr_timer_id = 0;
+
+ qt_xclb_incr_timeout();
+
+ return TRUE;
+ } else {
+ return TQObject::event( e );
+ }
+ } else if ( e->type() != TQEvent::Clipboard ) {
+ return TQObject::event( e );
+ }
+
+ XEvent *xevent = (XEvent *)(((TQCustomEvent *)e)->data());
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+
+ if ( !xevent )
+ return TRUE;
+
+ switch ( xevent->type ) {
+
+ case SelectionClear:
+ // new selection owner
+ if (xevent->xselectionclear.selection == XA_PRIMARY) {
+ TQClipboardData *d = selectionData();
+
+ // ignore the event if it was generated before we gained selection ownership
+ if (d->timestamp != CurrentTime && xevent->xselectionclear.time < d->timestamp)
+ break;
+
+ TQDEBUG("TQClipboard: new selection owner 0x%lx at time %lx (ours %lx)",
+ XGetSelectionOwner(dpy, XA_PRIMARY),
+ xevent->xselectionclear.time, d->timestamp);
+
+ if ( ! waiting_for_data ) {
+ d->clear();
+ emit selectionChanged();
+ } else {
+ pending_selection_changed = TRUE;
+ if ( ! pending_timer_id )
+ pending_timer_id = TQApplication::clipboard()->startTimer( 0 );
+ }
+ } else if (xevent->xselectionclear.selection == qt_xa_clipboard) {
+ TQClipboardData *d = clipboardData();
+
+ // ignore the event if it was generated before we gained selection ownership
+ if (d->timestamp != CurrentTime && xevent->xselectionclear.time < d->timestamp)
+ break;
+
+ TQDEBUG("TQClipboard: new clipboard owner 0x%lx at time %lx (%lx)",
+ XGetSelectionOwner(dpy, qt_xa_clipboard),
+ xevent->xselectionclear.time, d->timestamp);
+
+ if ( ! waiting_for_data ) {
+ d->clear();
+ emit dataChanged();
+ } else {
+ pending_clipboard_changed = TRUE;
+ if ( ! pending_timer_id )
+ pending_timer_id = TQApplication::clipboard()->startTimer( 0 );
+ }
+ } else {
+#ifdef TQT_CHECK_STATE
+ qWarning("TQClipboard: Unknown SelectionClear event received.");
+#endif
+ return FALSE;
+ }
+ break;
+
+ case SelectionNotify:
+ /*
+ Something has delivered data to us, but this was not caught
+ by TQClipboardWatcher::getDataInFormat()
+
+ Just skip the event to prevent Bad Things (tm) from
+ happening later on...
+ */
+ break;
+
+ case SelectionRequest:
+ {
+ // someone wants our data
+ XSelectionRequestEvent *req = &xevent->xselectionrequest;
+
+ if (requestor && req->requestor == requestor->winId())
+ break;
+
+ XEvent event;
+ event.xselection.type = SelectionNotify;
+ event.xselection.display = req->display;
+ event.xselection.requestor = req->requestor;
+ event.xselection.selection = req->selection;
+ event.xselection.target = req->target;
+ event.xselection.property = None;
+ event.xselection.time = req->time;
+
+ TQDEBUG("TQClipboard: SelectionRequest from %lx\n"
+ " selection 0x%lx (%s) target 0x%lx (%s)",
+ req->requestor,
+ req->selection,
+ qt_xdnd_atom_to_str(req->selection),
+ req->target,
+ qt_xdnd_atom_to_str(req->target));
+
+ TQClipboardData *d;
+
+ if ( req->selection == XA_PRIMARY ) {
+ d = selectionData();
+ } else if ( req->selection == qt_xa_clipboard ) {
+ d = clipboardData();
+ } else {
+#ifdef TQT_CHECK_RANGE
+ qWarning("TQClipboard: unknown selection '%lx'", req->selection);
+#endif // TQT_CHECK_RANGE
+
+ XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
+ break;
+ }
+
+ if (! d->source()) {
+#ifdef TQT_CHECK_STATE
+ qWarning("TQClipboard: cannot transfer data, no data available");
+#endif // TQT_CHECK_STATE
+
+ XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
+ break;
+ }
+
+ TQDEBUG("TQClipboard: SelectionRequest at time %lx (ours %lx)",
+ req->time, d->timestamp);
+
+ if (d->timestamp == CurrentTime // we don't own the selection anymore
+ || (req->time != CurrentTime && req->time < d->timestamp)) {
+ TQDEBUG("TQClipboard: SelectionRequest too old");
+ XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
+ break;
+ }
+
+ static Atom xa_text = *qt_xdnd_str_to_atom("TEXT");
+ static Atom xa_compound_text = *qt_xdnd_str_to_atom("COMPOUND_TEXT");
+ static Atom xa_targets = *qt_xdnd_str_to_atom("TARGETS");
+ static Atom xa_multiple = *qt_xdnd_str_to_atom("MULTIPLE");
+ static Atom xa_timestamp = *qt_xdnd_str_to_atom("TIMESTAMP");
+
+ struct AtomPair { Atom target; Atom property; } *multi = 0;
+ Atom multi_type = None;
+ int multi_format = 0;
+ int nmulti = 0;
+ int imulti = -1;
+ bool multi_writeback = FALSE;
+
+ if ( req->target == xa_multiple ) {
+ TQByteArray multi_data;
+ if (req->property == None
+ || !qt_xclb_read_property(dpy, req->requestor, req->property,
+ FALSE, &multi_data, 0, &multi_type, &multi_format, 0)
+ || multi_format != 32) {
+ // MULTIPLE property not formatted correctly
+ XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
+ break;
+ }
+ nmulti = multi_data.size()/sizeof(*multi);
+ multi = new AtomPair[nmulti];
+ memcpy(multi,multi_data.data(),multi_data.size());
+ imulti = 0;
+ }
+
+ for (; imulti < nmulti; ++imulti) {
+ Atom target;
+ Atom property;
+
+ if ( multi ) {
+ target = multi[imulti].target;
+ property = multi[imulti].property;
+ } else {
+ target = req->target;
+ property = req->property;
+ if (property == None) // obsolete client
+ property = target;
+ }
+
+ Atom ret = None;
+ if (target == None || property == None) {
+ ;
+ } else if (target == xa_timestamp) {
+ if (d->timestamp != CurrentTime) {
+ XChangeProperty(dpy, req->requestor, property, xa_timestamp, 32,
+ PropModeReplace, (uchar *) &d->timestamp, 1);
+ ret = property;
+ } else {
+
+#ifdef TQT_CHECK_STATE
+ qWarning("TQClipboard: invalid data timestamp");
+#endif // TQT_CHECK_STATE
+ }
+ } else if (target == xa_targets) {
+ ret = send_targets_selection(d, req->requestor, property);
+ } else if (target == XA_STRING
+ || target == xa_text
+ || target == xa_compound_text
+ || target == qt_utf8_string) {
+ ret = send_string_selection(d, target, req->requestor, property);
+ } else if (target == XA_PIXMAP
+ || target == XA_BITMAP) {
+ ret = send_pixmap_selection(d, target, req->requestor, property);
+ } else {
+ ret = send_selection(d, target, req->requestor, property);
+ }
+
+ if (nmulti > 0) {
+ if (ret == None) {
+ multi[imulti].property = None;
+ multi_writeback = TRUE;
+ }
+ } else {
+ event.xselection.property = ret;
+ break;
+ }
+ }
+
+ if (nmulti > 0) {
+ if (multi_writeback) {
+ // according to ICCCM 2.6.2 says to put None back
+ // into the original property on the requestor window
+ XChangeProperty(dpy, req->requestor, req->property, multi_type, 32,
+ PropModeReplace, (uchar *) multi, nmulti * 2);
+ }
+
+ delete [] multi;
+ event.xselection.property = req->property;
+ }
+
+ // send selection notify to requestor
+ XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
+
+ TQDEBUG("TQClipboard: SelectionNotify to 0x%lx\n"
+ " property 0x%lx (%s)",
+ req->requestor, event.xselection.property,
+ qt_xdnd_atom_to_str(event.xselection.property));
+ }
+ break;
+ }
+
+ return TRUE;
+}
+
+
+
+
+
+
+TQClipboardWatcher::TQClipboardWatcher( TQClipboard::Mode mode )
+{
+ switch ( mode ) {
+ case TQClipboard::Selection:
+ atom = XA_PRIMARY;
+ break;
+
+ case TQClipboard::Clipboard:
+ atom = qt_xa_clipboard;
+ break;
+
+#ifdef TQT_CHECK_RANGE
+ default:
+ qWarning( "TQClipboardWatcher: internal error, unknown clipboard mode" );
+ break;
+#endif // TQT_CHECK_RANGE
+ }
+
+ setupOwner();
+}
+
+TQClipboardWatcher::~TQClipboardWatcher()
+{
+ if( selection_watcher == this )
+ selection_watcher = 0;
+ if( clipboard_watcher == this )
+ clipboard_watcher = 0;
+}
+
+bool TQClipboardWatcher::empty() const
+{
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ Window win = XGetSelectionOwner( dpy, atom );
+
+#ifdef TQT_CHECK_STATE
+ if( win == requestor->winId()) {
+ qWarning( "TQClipboardWatcher::empty: internal error, app owns the selection" );
+ return TRUE;
+ }
+#endif // TQT_CHECK_STATE
+
+ return win == None;
+}
+
+const char* TQClipboardWatcher::format( int n ) const
+{
+ if ( empty() )
+ return 0;
+
+ if (! formatList.count()) {
+ // get the list of targets from the current clipboard owner - we do this
+ // once so that multiple calls to this function don't require multiple
+ // server round trips...
+ static Atom xa_targets = *qt_xdnd_str_to_atom( "TARGETS" );
+
+ TQClipboardWatcher *that = (TQClipboardWatcher *) this;
+ TQByteArray ba = getDataInFormat(xa_targets);
+ if (ba.size() > 0) {
+ Atom *unsorted_target = (Atom *) ba.data();
+ static Atom xa_text = *qt_xdnd_str_to_atom( "TEXT" );
+ static Atom xa_compound_text = *qt_xdnd_str_to_atom( "COMPOUND_TEXT" );
+ int i, size = ba.size() / sizeof(Atom);
+
+ // sort TARGETS to prefer some types over others. some apps
+ // will report XA_STRING before COMPOUND_TEXT, and we want the
+ // latter, not the former (if it is present).
+ Atom* target = new Atom[size+4];
+ memset( target, 0, (size+4) * sizeof(Atom) );
+
+ for ( i = 0; i < size; ++i ) {
+ if ( unsorted_target[i] == qt_utf8_string )
+ target[0] = unsorted_target[i];
+ else if ( unsorted_target[i] == xa_compound_text )
+ target[1] = unsorted_target[i];
+ else if ( unsorted_target[i] == xa_text )
+ target[2] = unsorted_target[i];
+ else if ( unsorted_target[i] == XA_STRING )
+ target[3] = unsorted_target[i];
+ else
+ target[i + 4] = unsorted_target[i];
+ }
+
+ for (i = 0; i < size + 4; ++i) {
+ if ( target[i] == 0 ) continue;
+
+ VTQDEBUG(" format: %s", qt_xdnd_atom_to_str(target[i]));
+
+ if ( target[i] == XA_PIXMAP )
+ that->formatList.append("image/ppm");
+ else if ( target[i] == XA_STRING )
+ that->formatList.append( "text/plain;charset=ISO-8859-1" );
+ else if ( target[i] == qt_utf8_string )
+ that->formatList.append( "text/plain;charset=UTF-8" );
+ else if ( target[i] == xa_text ||
+ target[i] == xa_compound_text )
+ that->formatList.append( "text/plain" );
+ else
+ that->formatList.append(qt_xdnd_atom_to_str(target[i]));
+ }
+ delete []target;
+
+ TQDEBUG("TQClipboardWatcher::format: %d formats available",
+ int(that->formatList.count()));
+ }
+ }
+
+ if (n >= 0 && n < (signed) formatList.count())
+ return formatList[n];
+ if (n == 0)
+ return "text/plain";
+ return 0;
+}
+
+TQByteArray TQClipboardWatcher::tqencodedData( const char* fmt ) const
+{
+ if ( !fmt || empty() )
+ return TQByteArray( 0 );
+
+ TQDEBUG("TQClipboardWatcher::tqencodedData: fetching format '%s'", fmt);
+
+ Atom fmtatom = 0;
+
+ if ( 0==qstricmp(fmt,"text/plain;charset=iso-8859-1") ) {
+ // ICCCM section 2.6.2 says STRING is latin1 text
+ fmtatom = XA_STRING;
+ } else if ( 0==qstricmp(fmt,"text/plain;charset=utf-8") ) {
+ // proprosed UTF8_STRING conversion type
+ fmtatom = *qt_xdnd_str_to_atom( "UTF8_STRING" );
+ } else if ( 0==qstrcmp(fmt,"text/plain") ) {
+ fmtatom = *qt_xdnd_str_to_atom( "COMPOUND_TEXT" );
+ } else if ( 0==qstrcmp(fmt,"image/ppm") ) {
+ fmtatom = XA_PIXMAP;
+ TQByteArray pmd = getDataInFormat(fmtatom);
+ if ( pmd.size() == sizeof(Pixmap) ) {
+ Pixmap xpm = *((Pixmap*)pmd.data());
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ Window r;
+ int x,y;
+ uint w,h,bw,d;
+ if ( ! xpm )
+ return TQByteArray( 0 );
+ XGetGeometry(dpy,xpm, &r,&x,&y,&w,&h,&bw,&d);
+ TQImageIO iio;
+ GC gc = XCreateGC( dpy, xpm, 0, 0 );
+ if ( d == 1 ) {
+ TQBitmap qbm(w,h);
+ XCopyArea(dpy,xpm,qbm.handle(),gc,0,0,w,h,0,0);
+ iio.setFormat("PBMRAW");
+ iio.setImage(qbm.convertToImage());
+ } else {
+ TQPixmap qpm(w,h);
+ XCopyArea(dpy,xpm,qpm.handle(),gc,0,0,w,h,0,0);
+ iio.setFormat("PPMRAW");
+ iio.setImage(qpm.convertToImage());
+ }
+ XFreeGC(dpy,gc);
+ TQBuffer buf;
+ buf.open(IO_WriteOnly);
+ iio.setIODevice(TQT_TQIODEVICE(&buf));
+ iio.write();
+ return buf.buffer();
+ } else {
+ fmtatom = *qt_xdnd_str_to_atom(fmt);
+ }
+ } else {
+ fmtatom = *qt_xdnd_str_to_atom(fmt);
+ }
+ return getDataInFormat(fmtatom);
+}
+
+TQByteArray TQClipboardWatcher::getDataInFormat(Atom fmtatom) const
+{
+ TQByteArray buf;
+
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ Window win = requestor->winId();
+
+ TQDEBUG("TQClipboardWatcher::getDataInFormat: selection '%s' format '%s'",
+ qt_xdnd_atom_to_str(atom), qt_xdnd_atom_to_str(fmtatom));
+
+ XSelectInput(dpy, win, NoEventMask); // don't listen for any events
+
+ XDeleteProperty(dpy, win, qt_selection_property);
+ XConvertSelection(dpy, atom, fmtatom, qt_selection_property, win, GET_QT_X_TIME());
+ XSync(dpy, FALSE);
+
+ VTQDEBUG("TQClipboardWatcher::getDataInFormat: waiting for SelectionNotify event");
+
+ XEvent xevent;
+ if ( !qt_xclb_wait_for_event(dpy,win,SelectionNotify,&xevent,clipboard_timeout) ||
+ xevent.xselection.property == None ) {
+ TQDEBUG("TQClipboardWatcher::getDataInFormat: format not available");
+ return buf;
+ }
+
+ VTQDEBUG("TQClipboardWatcher::getDataInFormat: fetching data...");
+
+ Atom type;
+ XSelectInput(dpy, win, PropertyChangeMask);
+
+ if ( qt_xclb_read_property(dpy,win,qt_selection_property,TRUE,
+ &buf,0,&type,0,FALSE) ) {
+ if ( type == qt_x_incr ) {
+ int nbytes = buf.size() >= 4 ? *((int*)buf.data()) : 0;
+ buf = qt_xclb_read_incremental_property( dpy, win,
+ qt_selection_property,
+ nbytes, FALSE );
+ }
+ }
+
+ XSelectInput(dpy, win, NoEventMask);
+
+ TQDEBUG("TQClipboardWatcher::getDataInFormat: %d bytes received", buf.size());
+
+ return buf;
+}
+
+
+TQMimeSource* TQClipboard::data( Mode mode ) const
+{
+ TQClipboardData *d;
+ switch ( mode ) {
+ case Selection: d = selectionData(); break;
+ case Clipboard: d = clipboardData(); break;
+
+ default:
+#ifdef TQT_CHECK_RANGE
+ qWarning( "TQClipboard::data: invalid mode '%d'", mode );
+#endif // TQT_CHECK_RANGE
+ return 0;
+ }
+
+ if ( ! d->source() && ! timer_event_clear ) {
+ if ( mode == Selection ) {
+ if ( ! selection_watcher )
+ selection_watcher = new TQClipboardWatcher( mode );
+ d->setSource( selection_watcher );
+ } else {
+ if ( ! clipboard_watcher )
+ clipboard_watcher = new TQClipboardWatcher( mode );
+ d->setSource( clipboard_watcher );
+ }
+
+ if (! timer_id) {
+ // start a zero timer - we will clear cached data when the timer
+ // times out, which will be the next time we hit the event loop...
+ // that way, the data is cached long enough for calls within a single
+ // loop/function, but the data doesn't linger around in case the selection
+ // changes
+ TQClipboard *that = ((TQClipboard *) this);
+ timer_id = that->startTimer(0);
+ }
+ }
+
+ return d->source();
+}
+
+
+void TQClipboard::setData( TQMimeSource* src, Mode mode )
+{
+ Atom atom, sentinel_atom;
+ TQClipboardData *d;
+ switch ( mode ) {
+ case Selection:
+ atom = XA_PRIMARY;
+ sentinel_atom = qt_selection_sentinel;
+ d = selectionData();
+ break;
+
+ case Clipboard:
+ atom = qt_xa_clipboard;
+ sentinel_atom = qt_clipboard_sentinel;
+ d = clipboardData();
+ break;
+
+ default:
+#ifdef TQT_CHECK_RANGE
+ qWarning( "TQClipboard::data: invalid mode '%d'", mode );
+#endif // TQT_CHECK_RANGE
+ return;
+ }
+
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ Window newOwner;
+
+ if (! src) { // no data, clear clipboard contents
+ newOwner = None;
+ d->clear();
+ } else {
+ setupOwner();
+
+ newOwner = owner->winId();
+
+ d->setSource(src);
+ d->timestamp = GET_QT_X_TIME();
+ }
+
+ Window prevOwner = XGetSelectionOwner( dpy, atom );
+ // use qt_x_time, since d->timestamp == CurrentTime when clearing
+ XSetSelectionOwner(dpy, atom, newOwner, GET_QT_X_TIME());
+
+ if ( mode == Selection )
+ emit selectionChanged();
+ else
+ emit dataChanged();
+
+ if (XGetSelectionOwner(dpy, atom) != newOwner) {
+#ifdef TQT_CHECK_STATE
+ qWarning("TQClipboard::setData: Cannot set X11 selection owner for %s",
+ qt_xdnd_atom_to_str(atom));
+#endif // TQT_CHECK_STATE
+
+ d->clear();
+ return;
+ }
+
+ // Signal to other TQt processes that the selection has changed
+ Window owners[2];
+ owners[0] = newOwner;
+ owners[1] = prevOwner;
+ XChangeProperty( dpy, TQApplication::desktop()->screen(0)->winId(),
+ sentinel_atom, XA_WINDOW, 32, PropModeReplace,
+ (unsigned char*)&owners, 2 );
+}
+
+
+/*
+ Called by the main event loop in qapplication_x11.cpp when the
+ _TQT_SELECTION_SENTINEL property has been changed (i.e. when some TQt
+ process has performed TQClipboard::setData(). If it returns TRUE, the
+ TQClipBoard dataChanged() signal should be emitted.
+*/
+
+bool qt_check_selection_sentinel()
+{
+ bool doIt = TRUE;
+ if ( owner ) {
+ /*
+ Since the X selection mechanism cannot give any signal when
+ the selection has changed, we emulate it (for TQt processes) here.
+ The notification should be ignored in case of either
+ a) This is the process that did setData (because setData()
+ then has already emitted dataChanged())
+ b) This is the process that owned the selection when dataChanged()
+ was called (because we have then received a SelectionClear event,
+ and have already emitted dataChanged() as a result of that)
+ */
+
+ Window* owners;
+ Atom actualType;
+ int actualFormat;
+ ulong nitems;
+ ulong bytesLeft;
+
+ if (XGetWindowProperty(TQPaintDevice::x11AppDisplay(),
+ TQApplication::desktop()->screen(0)->winId(),
+ qt_selection_sentinel, 0, 2, False, XA_WINDOW,
+ &actualType, &actualFormat, &nitems,
+ &bytesLeft, (unsigned char**)&owners) == Success) {
+ if ( actualType == XA_WINDOW && actualFormat == 32 && nitems == 2 ) {
+ Window win = owner->winId();
+ if ( owners[0] == win || owners[1] == win )
+ doIt = FALSE;
+ }
+
+ XFree( owners );
+ }
+ }
+
+ if (doIt) {
+ if ( waiting_for_data ) {
+ pending_selection_changed = TRUE;
+ if ( ! pending_timer_id )
+ pending_timer_id = TQApplication::clipboard()->startTimer( 0 );
+ doIt = FALSE;
+ } else {
+ selectionData()->clear();
+ }
+ }
+
+ return doIt;
+}
+
+
+bool qt_check_clipboard_sentinel()
+{
+ bool doIt = TRUE;
+ if (owner) {
+ Window *owners;
+ Atom actualType;
+ int actualFormat;
+ unsigned long nitems, bytesLeft;
+
+ if (XGetWindowProperty(TQPaintDevice::x11AppDisplay(),
+ TQApplication::desktop()->screen(0)->winId(),
+ qt_clipboard_sentinel, 0, 2, False, XA_WINDOW,
+ &actualType, &actualFormat, &nitems, &bytesLeft,
+ (unsigned char **) &owners) == Success) {
+ if (actualType == XA_WINDOW && actualFormat == 32 && nitems == 2) {
+ Window win = owner->winId();
+ if (owners[0] == win || owners[1] == win)
+ doIt = FALSE;
+ }
+
+ XFree(owners);
+ }
+ }
+
+ if (doIt) {
+ if ( waiting_for_data ) {
+ pending_clipboard_changed = TRUE;
+ if ( ! pending_timer_id )
+ pending_timer_id = TQApplication::clipboard()->startTimer( 0 );
+ doIt = FALSE;
+ } else {
+ clipboardData()->clear();
+ }
+ }
+
+ return doIt;
+}
+
+#endif // TQT_NO_CLIPBOARD
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqcolor.cpp b/tqtinterface/qt4/src/kernel/tqcolor.cpp
new file mode 100644
index 0000000..f245773
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcolor.cpp
@@ -0,0 +1,1174 @@
+/****************************************************************************
+**
+** Implementation of TQColor class
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqcolor.h"
+#include "tqnamespace.h"
+#include "tqdatastream.h"
+
+#include <stdio.h>
+
+#ifdef USE_QT4
+
+#include "Qt/qcolormap.h"
+
+/*****************************************************************************
+ Global colors
+ *****************************************************************************/
+
+#if defined(TQ_WS_WIN)
+#define COLOR0_PIX 0x00ffffff
+#define COLOR1_PIX 0
+#else
+#define COLOR0_PIX 0
+#define COLOR1_PIX 1
+#endif
+
+#if (defined(TQ_CC_GNU) && defined(TQ_OS_WIN))
+// workaround - bug in mingw
+static TQColor stdcol[19] = {
+ TQColor( 255, 255, 255 ),
+ TQColor( 0, 0, 0 ),
+ TQColor( 0, 0, 0 ),
+ TQColor( 255, 255, 255 ),
+ TQColor( 128, 128, 128 ),
+ TQColor( 160, 160, 164 ),
+ TQColor( 192, 192, 192 ),
+ TQColor( 255, 0, 0 ),
+ TQColor( 0, 255, 0 ),
+ TQColor( 0, 0, 255 ),
+ TQColor( 0, 255, 255 ),
+ TQColor( 255, 0, 255 ),
+ TQColor( 255, 255, 0 ),
+ TQColor( 128, 0, 0 ),
+ TQColor( 0, 128, 0 ),
+ TQColor( 0, 0, 128 ),
+ TQColor( 0, 128, 128 ),
+ TQColor( 128, 0, 128 ),
+ TQColor( 128, 128, 0 ) };
+#else
+ static TQColor stdcol[19];
+#endif
+
+TQT_STATIC_CONST_IMPL TQColor & TQt::color0 = stdcol[0];
+TQT_STATIC_CONST_IMPL TQColor & TQt::color1 = stdcol[1];
+TQT_STATIC_CONST_IMPL TQColor & TQt::black = stdcol[2];
+TQT_STATIC_CONST_IMPL TQColor & TQt::white = stdcol[3];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkGray = stdcol[4];
+TQT_STATIC_CONST_IMPL TQColor & TQt::gray = stdcol[5];
+TQT_STATIC_CONST_IMPL TQColor & TQt::lightGray = stdcol[6];
+TQT_STATIC_CONST_IMPL TQColor & TQt::red = stdcol[7];
+TQT_STATIC_CONST_IMPL TQColor & TQt::green = stdcol[8];
+TQT_STATIC_CONST_IMPL TQColor & TQt::blue = stdcol[9];
+TQT_STATIC_CONST_IMPL TQColor & TQt::cyan = stdcol[10];
+TQT_STATIC_CONST_IMPL TQColor & TQt::magenta = stdcol[11];
+TQT_STATIC_CONST_IMPL TQColor & TQt::yellow = stdcol[12];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkRed = stdcol[13];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkGreen = stdcol[14];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkBlue = stdcol[15];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkCyan = stdcol[16];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkMagenta = stdcol[17];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkYellow = stdcol[18];
+
+/*****************************************************************************
+ TQColor member functions
+ *****************************************************************************/
+
+bool TQColor::color_init = FALSE; // color system not initialized
+bool TQColor::globals_init = FALSE; // global color not initialized
+TQColor::ColorModel TQColor::colormodel = d32;
+
+/*!
+ Returns the pixel value used by the underlying window system to refer to a
+ color.
+
+ Use QColormap::pixel() instead.
+
+ \oldcode
+ QColor myColor;
+ uint pixel = myColor.pixel(screen);
+ \newcode
+ QColormap cmap = QColormap::instance(screen);
+ uint pixel = cmap.pixel(*this);
+ \endcode
+*/
+uint TQColor::pixel(int screen) const
+{
+ QColormap cmap = QColormap::instance(screen);
+ return cmap.pixel(*this);
+}
+
+void TQColor::initGlobalColors()
+{
+ globals_init = TRUE;
+
+// #ifdef TQ_WS_X11
+// // HACK: we need a way to recognize color0 and color1 uniquely, so
+// // that we can use color0 and color1 with fixed pixel values on
+// // all screens
+// stdcol[ 0].d.argb = tqRgba(255, 255, 255, 1);
+// stdcol[ 1].d.argb = tqRgba( 0, 0, 0, 1);
+// #else
+// stdcol[ 0].d.argb = tqRgb(255,255,255);
+// stdcol[ 1].d.argb = 0;
+// #endif // TQ_WS_X11
+// stdcol[ 0].setPixel( COLOR0_PIX );
+// stdcol[ 1].setPixel( COLOR1_PIX );
+ stdcol[ 0] = Qt::color0;
+ stdcol[ 1] = Qt::color1;
+
+ // From the "The Palette Manager: How and Why" by Ron Gery, March 23,
+ // 1992, archived on MSDN:
+ // The Windows system palette is broken up into two sections,
+ // one with fixed colors and one with colors that can be changed
+ // by applications. The system palette predefines 20 entries;
+ // these colors are known as the static or reserved colors and
+ // consist of the 16 colors found in the Windows version 3.0 VGA
+ // driver and 4 additional colors chosen for their visual appeal.
+ // The DEFAULT_PALETTE stock object is, as the name implies, the
+ // default palette selected into a tqdevice context (DC) and consists
+ // of these static colors. Applications can set the remaining 236
+ // colors using the Palette Manager.
+ // The 20 reserved entries have indices in [0,9] and [246,255]. We
+ // reuse 17 of them.
+ stdcol[ 2].setRgb( 0, 0, 0 ); // index 0 black
+ stdcol[ 3].setRgb( 255, 255, 255 ); // index 255 white
+ stdcol[ 4].setRgb( 128, 128, 128 ); // index 248 medium gray
+ stdcol[ 5].setRgb( 160, 160, 164 ); // index 247 light gray
+ stdcol[ 6].setRgb( 192, 192, 192 ); // index 7 light gray
+ stdcol[ 7].setRgb( 255, 0, 0 ); // index 249 red
+ stdcol[ 8].setRgb( 0, 255, 0 ); // index 250 green
+ stdcol[ 9].setRgb( 0, 0, 255 ); // index 252 blue
+ stdcol[10].setRgb( 0, 255, 255 ); // index 254 cyan
+ stdcol[11].setRgb( 255, 0, 255 ); // index 253 magenta
+ stdcol[12].setRgb( 255, 255, 0 ); // index 251 yellow
+ stdcol[13].setRgb( 128, 0, 0 ); // index 1 dark red
+ stdcol[14].setRgb( 0, 128, 0 ); // index 2 dark green
+ stdcol[15].setRgb( 0, 0, 128 ); // index 4 dark blue
+ stdcol[16].setRgb( 0, 128, 128 ); // index 6 dark cyan
+ stdcol[17].setRgb( 128, 0, 128 ); // index 5 dark magenta
+ stdcol[18].setRgb( 128, 128, 0 ); // index 3 dark yellow
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQColor tqcolor.h
+ \brief The TQColor class provides colors based on RGB or HSV values.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup appearance
+
+ A color is normally specified in terms of RGB (red, green and blue)
+ components, but it is also possible to specify HSV (hue, saturation
+ and value) or set a color name (the names are copied from from the
+ X11 color database).
+
+ In addition to the RGB value, a TQColor also has a pixel value and a
+ validity. The pixel value is used by the underlying window system
+ to refer to a color. It can be thought of as an index into the
+ display hardware's color table.
+
+ The validity (isValid()) indicates whether the color is legal at
+ all. For example, a RGB color with RGB values out of range is
+ illegal. For performance reasons, TQColor mostly disregards illegal
+ colors. The result of using an invalid color is unspecified and
+ will usually be surprising.
+
+ There are 19 predefined TQColor objects: \c white, \c black, \c
+ red, \c darkRed, \c green, \c darkGreen, \c blue, \c darkBlue, \c
+ cyan, \c darkCyan, \c magenta, \c darkMagenta, \c yellow, \c
+ darkYellow, \c gray, \c darkGray, \c lightGray, \c color0 and \c
+ color1, accessible as members of the TQt namespace (ie. \c TQt::red).
+
+ \img qt-colors.png TQt Colors
+
+ The colors \c color0 (zero pixel value) and \c color1 (non-zero
+ pixel value) are special colors for drawing in \link TQBitmap
+ bitmaps\endlink. Painting with \c color0 sets the bitmap bits to 0
+ (transtqparent, i.e. background), and painting with \c color1 sets the
+ bits to 1 (opaque, i.e. foreground).
+
+ The TQColor class has an efficient, dynamic color allocation
+ strategy. A color is normally allocated the first time it is used
+ (lazy allocation), that is, whenever the pixel() function is called.
+ The following steps are taken to allocate a color. If, at any point,
+ a suitable color is found then the appropriate pixel value is
+ returned and the subsequent steps are not taken:
+
+ \list 1
+ \i Is the pixel value valid? If it is, just return it; otherwise,
+ allocate a pixel value.
+ \i Check an internal hash table to see if we allocated an equal RGB
+ value earlier. If we did, set the corresponding pixel value for the
+ color and return it.
+ \i Try to allocate the RGB value. If we succeed, we get a pixel value
+ that we save in the internal table with the RGB value.
+ Return the pixel value.
+ \i The color could not be allocated. Find the closest matching
+ color, save it in the internal table, and return it.
+ \endlist
+
+ A color can be set by passing setNamedColor() an RGB string like
+ "#112233", or a color name, e.g. "blue". The names are taken from
+ X11's rgb.txt database but can also be used under Windows. To get
+ a lighter or darker color use light() and dark() respectively.
+ Colors can also be set using setRgb() and setHsv(). The color
+ components can be accessed in one go with rgb() and hsv(), or
+ individually with red(), green() and blue().
+
+ Use maxColors() and numBitPlanes() to determine the maximum number
+ of colors and the number of bit planes supported by the underlying
+ window system,
+
+ If you need to allocate many colors temporarily, for example in an
+ image viewer application, enterAllocContext(), leaveAllocContext() and
+ destroyAllocContext() will prove useful.
+
+ \section1 HSV Colors
+
+ Because many people don't know the HSV color model very well, we'll
+ cover it briefly here.
+
+ The RGB model is hardware-oriented. Its representation is close to
+ what most monitors show. In contrast, HSV represents color in a way
+ more suited to the human perception of color. For example, the
+ relationships "stronger than", "darker than" and "the opposite of"
+ are easily expressed in HSV but are much harder to express in RGB.
+
+ HSV, like RGB, has three components:
+
+ \list
+
+ \i H, for hue, is either 0-359 if the color is chromatic (not
+ gray), or meaningless if it is gray. It represents degrees on the
+ color wheel familiar to most people. Red is 0 (degrees), green is
+ 120 and blue is 240.
+
+ \i S, for saturation, is 0-255, and the bigger it is, the
+ stronger the color is. Grayish colors have saturation near 0; very
+ strong colors have saturation near 255.
+
+ \i V, for value, is 0-255 and represents lightness or brightness
+ of the color. 0 is black; 255 is as far from black as possible.
+
+ \endlist
+
+ Here are some examples: Pure red is H=0, S=255, V=255. A dark red,
+ moving slightly towards the magenta, could be H=350 (equivalent to
+ -10), S=255, V=180. A grayish light red could have H about 0 (say
+ 350-359 or 0-10), S about 50-100, and S=255.
+
+ TQt returns a hue value of -1 for achromatic colors. If you pass a
+ too-big hue value, TQt forces it into range. Hue 360 or 720 is
+ treated as 0; hue 540 is treated as 180.
+
+ \sa TQPalette, TQColorGroup, TQApplication::setColorSpec(),
+ \link http://www.poynton.com/ColorFAQ.html Color FAQ\endlink
+*/
+
+/*****************************************************************************
+ Global colors
+ *****************************************************************************/
+
+#if defined(TQ_WS_WIN)
+#define COLOR0_PIX 0x00ffffff
+#define COLOR1_PIX 0
+#else
+#define COLOR0_PIX 0
+#define COLOR1_PIX 1
+#endif
+
+#if (defined(TQ_CC_GNU) && defined(TQ_OS_WIN))
+// workaround - bug in mingw
+static TQColor stdcol[19] = {
+ TQColor( 255, 255, 255 ),
+ TQColor( 0, 0, 0 ),
+ TQColor( 0, 0, 0 ),
+ TQColor( 255, 255, 255 ),
+ TQColor( 128, 128, 128 ),
+ TQColor( 160, 160, 164 ),
+ TQColor( 192, 192, 192 ),
+ TQColor( 255, 0, 0 ),
+ TQColor( 0, 255, 0 ),
+ TQColor( 0, 0, 255 ),
+ TQColor( 0, 255, 255 ),
+ TQColor( 255, 0, 255 ),
+ TQColor( 255, 255, 0 ),
+ TQColor( 128, 0, 0 ),
+ TQColor( 0, 128, 0 ),
+ TQColor( 0, 0, 128 ),
+ TQColor( 0, 128, 128 ),
+ TQColor( 128, 0, 128 ),
+ TQColor( 128, 128, 0 ) };
+#else
+ static TQColor stdcol[19];
+#endif
+
+TQT_STATIC_CONST_IMPL TQColor & TQt::color0 = stdcol[0];
+TQT_STATIC_CONST_IMPL TQColor & TQt::color1 = stdcol[1];
+TQT_STATIC_CONST_IMPL TQColor & TQt::black = stdcol[2];
+TQT_STATIC_CONST_IMPL TQColor & TQt::white = stdcol[3];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkGray = stdcol[4];
+TQT_STATIC_CONST_IMPL TQColor & TQt::gray = stdcol[5];
+TQT_STATIC_CONST_IMPL TQColor & TQt::lightGray = stdcol[6];
+TQT_STATIC_CONST_IMPL TQColor & TQt::red = stdcol[7];
+TQT_STATIC_CONST_IMPL TQColor & TQt::green = stdcol[8];
+TQT_STATIC_CONST_IMPL TQColor & TQt::blue = stdcol[9];
+TQT_STATIC_CONST_IMPL TQColor & TQt::cyan = stdcol[10];
+TQT_STATIC_CONST_IMPL TQColor & TQt::magenta = stdcol[11];
+TQT_STATIC_CONST_IMPL TQColor & TQt::yellow = stdcol[12];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkRed = stdcol[13];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkGreen = stdcol[14];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkBlue = stdcol[15];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkCyan = stdcol[16];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkMagenta = stdcol[17];
+TQT_STATIC_CONST_IMPL TQColor & TQt::darkYellow = stdcol[18];
+
+
+/*****************************************************************************
+ TQColor member functions
+ *****************************************************************************/
+
+bool TQColor::color_init = FALSE; // color system not initialized
+bool TQColor::globals_init = FALSE; // global color not initialized
+TQColor::ColorModel TQColor::colormodel = d32;
+
+
+TQColor* TQColor::globalColors()
+{
+ return stdcol;
+}
+
+
+/*!
+ Initializes the global colors. This function is called if a global
+ color variable is initialized before the constructors for our
+ global color objects are executed. Without this mechanism,
+ assigning a color might assign an uninitialized value.
+
+ Example:
+ \code
+ TQColor myColor = red; // will initialize red etc.
+
+ int main( int argc, char **argc )
+ {
+ }
+ \endcode
+*/
+
+void TQColor::initGlobalColors()
+{
+ globals_init = TRUE;
+
+ #ifdef TQ_WS_X11
+ // HACK: we need a way to recognize color0 and color1 uniquely, so
+ // that we can use color0 and color1 with fixed pixel values on
+ // all screens
+ stdcol[ 0].d.argb = tqRgba(255, 255, 255, 1);
+ stdcol[ 1].d.argb = tqRgba( 0, 0, 0, 1);
+ #else
+ stdcol[ 0].d.argb = tqRgb(255,255,255);
+ stdcol[ 1].d.argb = 0;
+ #endif // TQ_WS_X11
+ stdcol[ 0].setPixel( COLOR0_PIX );
+ stdcol[ 1].setPixel( COLOR1_PIX );
+
+ // From the "The Palette Manager: How and Why" by Ron Gery, March 23,
+ // 1992, archived on MSDN:
+ // The Windows system palette is broken up into two sections,
+ // one with fixed colors and one with colors that can be changed
+ // by applications. The system palette predefines 20 entries;
+ // these colors are known as the static or reserved colors and
+ // consist of the 16 colors found in the Windows version 3.0 VGA
+ // driver and 4 additional colors chosen for their visual appeal.
+ // The DEFAULT_PALETTE stock object is, as the name implies, the
+ // default palette selected into a tqdevice context (DC) and consists
+ // of these static colors. Applications can set the remaining 236
+ // colors using the Palette Manager.
+ // The 20 reserved entries have indices in [0,9] and [246,255]. We
+ // reuse 17 of them.
+ stdcol[ 2].setRgb( 0, 0, 0 ); // index 0 black
+ stdcol[ 3].setRgb( 255, 255, 255 ); // index 255 white
+ stdcol[ 4].setRgb( 128, 128, 128 ); // index 248 medium gray
+ stdcol[ 5].setRgb( 160, 160, 164 ); // index 247 light gray
+ stdcol[ 6].setRgb( 192, 192, 192 ); // index 7 light gray
+ stdcol[ 7].setRgb( 255, 0, 0 ); // index 249 red
+ stdcol[ 8].setRgb( 0, 255, 0 ); // index 250 green
+ stdcol[ 9].setRgb( 0, 0, 255 ); // index 252 blue
+ stdcol[10].setRgb( 0, 255, 255 ); // index 254 cyan
+ stdcol[11].setRgb( 255, 0, 255 ); // index 253 magenta
+ stdcol[12].setRgb( 255, 255, 0 ); // index 251 yellow
+ stdcol[13].setRgb( 128, 0, 0 ); // index 1 dark red
+ stdcol[14].setRgb( 0, 128, 0 ); // index 2 dark green
+ stdcol[15].setRgb( 0, 0, 128 ); // index 4 dark blue
+ stdcol[16].setRgb( 0, 128, 128 ); // index 6 dark cyan
+ stdcol[17].setRgb( 128, 0, 128 ); // index 5 dark magenta
+ stdcol[18].setRgb( 128, 128, 0 ); // index 3 dark yellow
+}
+
+/*!
+ \enum TQColor::Spec
+
+ The type of color specified, either RGB or HSV, e.g. in the
+ \c{TQColor::TQColor( x, y, z, colorSpec)} constructor.
+
+ \value Rgb
+ \value Hsv
+*/
+
+
+/*!
+ \fn TQColor::TQColor()
+
+ Constructs an invalid color with the RGB value (0, 0, 0). An
+ invalid color is a color that is not properly set up for the
+ underlying window system.
+
+ The alpha value of an invalid color is unspecified.
+
+ \sa isValid()
+*/
+
+
+/*!
+ \fn TQColor::TQColor( int r, int g, int b )
+
+ Constructs a color with the RGB value \a r, \a g, \a b, in the
+ same way as setRgb().
+
+ The color is left invalid if any or the arguments are illegal.
+
+ \sa setRgb()
+*/
+
+
+/*!
+ Constructs a color with the RGB value \a rgb and a custom pixel
+ value \a pixel.
+
+ If \a pixel == 0xffffffff (the default), then the color uses the
+ RGB value in a standard way. If \a pixel is something else, then
+ the pixel value is set directly to \a pixel, skipping the normal
+ allocation procedure.
+*/
+
+TQColor::TQColor( TQRgb rgb, uint pixel )
+{
+ if ( pixel == 0xffffffff ) {
+ setRgb( rgb );
+ } else {
+ d.argb = rgb;
+ setPixel( pixel );
+ }
+}
+
+void TQColor::setPixel( uint pixel )
+{
+ switch ( colormodel ) {
+ case d8:
+ d.d8.direct = TRUE;
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pixel;
+ break;
+ case d32:
+ d.d32.pix = pixel;
+ break;
+ }
+}
+
+
+/*!
+ Constructs a color with the RGB or HSV value \a x, \a y, \a z.
+
+ The arguments are an RGB value if \a colorSpec is TQColor::Rgb. \a
+ x (red), \a y (green), and \a z (blue). All of them must be in the
+ range 0-255.
+
+ The arguments are an HSV value if \a colorSpec is TQColor::Hsv. \a
+ x (hue) must be -1 for achromatic colors and 0-359 for chromatic
+ colors; \a y (saturation) and \a z (value) must both be in the
+ range 0-255.
+
+ \sa setRgb(), setHsv()
+*/
+
+TQColor::TQColor( int x, int y, int z, Spec colorSpec )
+{
+ d.d32.argb = Invalid;
+ d.d32.pix = Dirt;
+ if ( colorSpec == Hsv )
+ setHsv( x, y, z );
+ else
+ setRgb( x, y, z );
+}
+
+
+/*!
+ Constructs a named color in the same way as setNamedColor() using
+ name \a name.
+
+ The color is left invalid if \a name cannot be parsed.
+
+ \sa setNamedColor()
+*/
+
+TQColor::TQColor( const TQString& name )
+{
+ setNamedColor( name );
+}
+
+
+/*!
+ Constructs a named color in the same way as setNamedColor() using
+ name \a name.
+
+ The color is left invalid if \a name cannot be parsed.
+
+ \sa setNamedColor()
+*/
+
+TQColor::TQColor( const char *name )
+{
+ setNamedColor( TQString(name) );
+}
+
+
+
+/*!
+ Constructs a color that is a copy of \a c.
+*/
+
+TQColor::TQColor( const TQColor &c )
+{
+ if ( !globals_init )
+ initGlobalColors();
+ d.argb = c.d.argb;
+ d.d32.pix = c.d.d32.pix;
+}
+
+
+/*!
+ Assigns a copy of the color \a c and returns a reference to this
+ color.
+*/
+
+TQColor &TQColor::operator=( const TQColor &c )
+{
+ if ( !globals_init )
+ initGlobalColors();
+ d.argb = c.d.argb;
+ d.d32.pix = c.d.d32.pix;
+ return *this;
+}
+
+
+/*!
+ \fn bool TQColor::isValid() const
+
+ Returns FALSE if the color is invalid, i.e. it was constructed using the
+ default constructor; otherwise returns TRUE.
+*/
+
+/*!
+ \internal
+*/
+bool TQColor::isDirty() const
+{
+ if ( colormodel == d8 ) {
+ return d.d8.dirty;
+ } else {
+ return d.d32.probablyDirty();
+ }
+}
+
+/*!
+ Returns the name of the color in the format "#RRGGBB", i.e. a "#"
+ character followed by three two-digit hexadecimal numbers.
+
+ \sa setNamedColor()
+*/
+
+TQString TQColor::name() const
+{
+#ifndef TQT_NO_SPRINTF
+ TQString s;
+ s.sprintf( "#%02x%02x%02x", red(), green(), blue() );
+ return s;
+#else
+ char s[20];
+ sprintf( s, "#%02x%02x%02x", red(), green(), blue() );
+ return TQString(s);
+#endif
+}
+
+static int hex2int( TQChar hexchar )
+{
+ int v;
+ if ( hexchar.isDigit() )
+ v = hexchar.digitValue();
+ else if ( hexchar >= 'A' && hexchar <= 'F' )
+ v = hexchar.cell() - 'A' + 10;
+ else if ( hexchar >= 'a' && hexchar <= 'f' )
+ v = hexchar.cell() - 'a' + 10;
+ else
+ v = -1;
+ return v;
+}
+
+
+/*!
+ Sets the RGB value to \a name, which may be in one of these
+ formats:
+ \list
+ \i #RGB (each of R, G and B is a single hex digit)
+ \i #RRGGBB
+ \i #RRRGGGBBB
+ \i #RRRRGGGGBBBB
+ \i A name from the X color database (rgb.txt) (e.g.
+ "steelblue" or "gainsboro"). These color names also work
+ under Windows.
+ \endlist
+
+ The color is invalid if \a name cannot be parsed.
+*/
+
+void TQColor::setNamedColor( const TQString &name )
+{
+ if ( name.isEmpty() ) {
+ d.argb = 0;
+ if ( colormodel == d8 ) {
+ d.d8.invalid = TRUE;
+ } else {
+ d.d32.argb = Invalid;
+ }
+ } else if ( name[0] == '#' ) {
+ const TQChar *p = name.tqunicode()+1;
+ int len = name.length()-1;
+ int r, g, b;
+ if ( len == 12 ) {
+ r = (hex2int(p[0]) << 4) + hex2int(p[1]);
+ g = (hex2int(p[4]) << 4) + hex2int(p[5]);
+ b = (hex2int(p[8]) << 4) + hex2int(p[9]);
+ } else if ( len == 9 ) {
+ r = (hex2int(p[0]) << 4) + hex2int(p[1]);
+ g = (hex2int(p[3]) << 4) + hex2int(p[4]);
+ b = (hex2int(p[6]) << 4) + hex2int(p[7]);
+ } else if ( len == 6 ) {
+ r = (hex2int(p[0]) << 4) + hex2int(p[1]);
+ g = (hex2int(p[2]) << 4) + hex2int(p[3]);
+ b = (hex2int(p[4]) << 4) + hex2int(p[5]);
+ } else if ( len == 3 ) {
+ r = (hex2int(p[0]) << 4) + hex2int(p[0]);
+ g = (hex2int(p[1]) << 4) + hex2int(p[1]);
+ b = (hex2int(p[2]) << 4) + hex2int(p[2]);
+ } else {
+ r = g = b = -1;
+ }
+ if ( (uint)r > 255 || (uint)g > 255 || (uint)b > 255 ) {
+ d.d32.argb = Invalid;
+ d.d32.pix = Dirt;
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQColor::setNamedColor: could not parse color '%s'",
+ name.local8Bit().data() );
+#endif
+ } else {
+ setRgb( r, g, b );
+ }
+ } else {
+ setSystemNamedColor( name );
+ }
+}
+
+
+#undef max
+#undef min
+
+/*!
+ \fn void TQColor::getHsv( int &h, int &s, int &v ) const
+ \obsolete
+*/
+
+/*! \fn void TQColor::getHsv( int *h, int *s, int *v ) const
+
+ Returns the current RGB value as HSV. The contents of the \a h, \a
+ s and \a v pointers are set to the HSV values. If any of the three
+ pointers are null, the function does nothing.
+
+ The hue (which \a h points to) is set to -1 if the color is
+ achromatic.
+
+ \warning Colors are stored internally as RGB values, so getHSv()
+ may return slightly different values to those set by setHsv().
+
+ \sa setHsv(), rgb()
+*/
+
+/*! \obsolete Use getHsv() instead.
+ */
+void TQColor::hsv( int *h, int *s, int *v ) const
+{
+ if ( !h || !s || !v )
+ return;
+ int r = tqRed(d.argb);
+ int g = tqGreen(d.argb);
+ int b = tqBlue(d.argb);
+ uint max = r; // maximum RGB component
+ int whatmax = 0; // r=>0, g=>1, b=>2
+ if ( (uint)g > max ) {
+ max = g;
+ whatmax = 1;
+ }
+ if ( (uint)b > max ) {
+ max = b;
+ whatmax = 2;
+ }
+ uint min = r; // tqfind minimum value
+ if ( (uint)g < min ) min = g;
+ if ( (uint)b < min ) min = b;
+ int delta = max-min;
+ *v = max; // calc value
+ *s = max ? (510*delta+max)/(2*max) : 0;
+ if ( *s == 0 ) {
+ *h = -1; // undefined hue
+ } else {
+ switch ( whatmax ) {
+ case 0: // red is max component
+ if ( g >= b )
+ *h = (120*(g-b)+delta)/(2*delta);
+ else
+ *h = (120*(g-b+delta)+delta)/(2*delta) + 300;
+ break;
+ case 1: // green is max component
+ if ( b > r )
+ *h = 120 + (120*(b-r)+delta)/(2*delta);
+ else
+ *h = 60 + (120*(b-r+delta)+delta)/(2*delta);
+ break;
+ case 2: // blue is max component
+ if ( r > g )
+ *h = 240 + (120*(r-g)+delta)/(2*delta);
+ else
+ *h = 180 + (120*(r-g+delta)+delta)/(2*delta);
+ break;
+ }
+ }
+}
+
+
+/*!
+ Sets a HSV color value. \a h is the hue, \a s is the saturation
+ and \a v is the value of the HSV color.
+
+ If \a s or \a v are not in the range 0-255, or \a h is < -1, the
+ color is not changed.
+
+ \warning Colors are stored internally as RGB values, so getHSv()
+ may return slightly different values to those set by setHsv().
+
+ \sa hsv(), setRgb()
+*/
+
+void TQColor::setHsv( int h, int s, int v )
+{
+ if ( h < -1 || (uint)s > 255 || (uint)v > 255 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQColor::setHsv: HSV parameters out of range" );
+#endif
+ return;
+ }
+ int r=v, g=v, b=v;
+ if ( s == 0 || h == -1 ) { // achromatic case
+ // Ignore
+ } else { // chromatic case
+ if ( (uint)h >= 360 )
+ h %= 360;
+ uint f = h%60;
+ h /= 60;
+ uint p = (uint)(2*v*(255-s)+255)/510;
+ uint q, t;
+ if ( h&1 ) {
+ q = (uint)(2*v*(15300-s*f)+15300)/30600;
+ switch( h ) {
+ case 1: r=(int)q; g=(int)v, b=(int)p; break;
+ case 3: r=(int)p; g=(int)q, b=(int)v; break;
+ case 5: r=(int)v; g=(int)p, b=(int)q; break;
+ }
+ } else {
+ t = (uint)(2*v*(15300-(s*(60-f)))+15300)/30600;
+ switch( h ) {
+ case 0: r=(int)v; g=(int)t, b=(int)p; break;
+ case 2: r=(int)p; g=(int)v, b=(int)t; break;
+ case 4: r=(int)t; g=(int)p, b=(int)v; break;
+ }
+ }
+ }
+ setRgb( r, g, b );
+}
+
+
+/*!
+ \fn TQRgb TQColor::rgb() const
+
+ Returns the RGB value.
+
+ The return type \e TQRgb is equivalent to \c unsigned \c int.
+
+ For an invalid color, the alpha value of the returned color is
+ unspecified.
+
+ \sa setRgb(), hsv(), tqRed(), tqBlue(), tqGreen(), isValid()
+*/
+
+/*! \fn void TQColor::getRgb( int *r, int *g, int *b ) const
+
+ Sets the contents pointed to by \a r, \a g and \a b to the red,
+ green and blue components of the RGB value respectively. The value
+ range for a component is 0..255.
+
+ \sa rgb(), setRgb(), getHsv()
+*/
+
+/*! \obsolete Use getRgb() instead */
+void TQColor::rgb( int *r, int *g, int *b ) const
+{
+ *r = tqRed(d.argb);
+ *g = tqGreen(d.argb);
+ *b = tqBlue(d.argb);
+}
+
+
+/*!
+ Sets the RGB value to \a r, \a g, \a b. The arguments, \a r, \a g
+ and \a b must all be in the range 0..255. If any of them are
+ outside the legal range, the color is not changed.
+
+ \sa rgb(), setHsv()
+*/
+
+void TQColor::setRgb( int r, int g, int b )
+{
+ if ( (uint)r > 255 || (uint)g > 255 || (uint)b > 255 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQColor::setRgb: RGB parameter(s) out of range" );
+#endif
+ return;
+ }
+ d.argb = tqRgb( r, g, b );
+ if ( colormodel == d8 ) {
+ d.d8.invalid = FALSE;
+ d.d8.direct = FALSE;
+ d.d8.dirty = TRUE;
+ } else {
+ d.d32.pix = Dirt;
+ }
+}
+
+
+/*!
+ \overload
+ Sets the RGB value to \a rgb.
+
+ The type \e TQRgb is equivalent to \c unsigned \c int.
+
+ \sa rgb(), setHsv()
+*/
+
+void TQColor::setRgb( TQRgb rgb )
+{
+ d.argb = rgb;
+ if ( colormodel == d8 ) {
+ d.d8.invalid = FALSE;
+ d.d8.direct = FALSE;
+ d.d8.dirty = TRUE;
+ } else {
+ d.d32.pix = Dirt;
+ }
+}
+
+/*!
+ \fn int TQColor::red() const
+
+ Returns the R (red) component of the RGB value.
+*/
+
+
+/*!
+ \fn int TQColor::green() const
+
+ Returns the G (green) component of the RGB value.
+*/
+
+/*!
+ \fn int TQColor::blue() const
+
+ Returns the B (blue) component of the RGB value.
+*/
+
+
+/*!
+ Returns a lighter (or darker) color, but does not change this
+ object.
+
+ Returns a lighter color if \a factor is greater than 100. Setting
+ \a factor to 150 returns a color that is 50% brighter.
+
+ Returns a darker color if \a factor is less than 100. We recommend
+ using dark() for this purpose. If \a factor is 0 or negative, the
+ return value is unspecified.
+
+ (This function converts the current RGB color to HSV, multiplies V
+ by \a factor, and converts the result back to RGB.)
+
+ \sa dark()
+*/
+
+TQColor TQColor::light( int factor ) const
+{
+ if ( factor <= 0 ) // invalid lightness factor
+ return *this;
+ else if ( factor < 100 ) // makes color darker
+ return dark( 10000/factor );
+
+ int h, s, v;
+ hsv( &h, &s, &v );
+ v = (factor*v)/100;
+ if ( v > 255 ) { // overflow
+ s -= v-255; // adjust saturation
+ if ( s < 0 )
+ s = 0;
+ v = 255;
+ }
+ TQColor c;
+ c.setHsv( h, s, v );
+ return c;
+}
+
+
+/*!
+ Returns a darker (or lighter) color, but does not change this
+ object.
+
+ Returns a darker color if \a factor is greater than 100. Setting
+ \a factor to 300 returns a color that has one-third the
+ brightness.
+
+ Returns a lighter color if \a factor is less than 100. We
+ recommend using lighter() for this purpose. If \a factor is 0 or
+ negative, the return value is unspecified.
+
+ (This function converts the current RGB color to HSV, divides V by
+ \a factor and converts back to RGB.)
+
+ \sa light()
+*/
+
+TQColor TQColor::dark( int factor ) const
+{
+ if ( factor <= 0 ) // invalid darkness factor
+ return *this;
+ else if ( factor < 100 ) // makes color lighter
+ return light( 10000/factor );
+ int h, s, v;
+ hsv( &h, &s, &v );
+ v = (v*100)/factor;
+ TQColor c;
+ c.setHsv( h, s, v );
+ return c;
+}
+
+
+/*!
+ \fn bool TQColor::operator==( const TQColor &c ) const
+
+ Returns TRUE if this color has the same RGB value as \a c;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQColor::operator!=( const TQColor &c ) const
+ Returns TRUE if this color has a different RGB value from \a c;
+ otherwise returns FALSE.
+*/
+
+/*!
+ Returns the pixel value.
+
+ This value is used by the underlying window system to refer to a
+ color. It can be thought of as an index into the display
+ hardware's color table, but the value is an arbitrary 32-bit
+ value.
+
+ \sa alloc()
+*/
+uint TQColor::pixel() const
+{
+ if ( isDirty() )
+ return ((TQColor*)this)->alloc();
+ else if ( colormodel == d8 )
+#ifdef TQ_WS_WIN
+ // since d.d8.pix is uchar we have to use the PALETTEINDEX
+ // macro to get the respective palette entry index.
+ return (0x01000000 | (int)(short)(d.d8.pix));
+#else
+ return d.d8.pix;
+#endif
+ else
+ return d.d32.pix;
+}
+
+/*!
+ \fn TQStringList TQColor::colorNames()
+ Returns a TQStringList containing the color names TQt knows about.
+*/
+
+/*****************************************************************************
+ TQColor stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQColor
+ Writes a color object, \a c to the stream, \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQColor &c )
+{
+ TQ_UINT32 p = (TQ_UINT32)c.rgb();
+ if ( s.version() == 1 ) // Swap red and blue
+ p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
+ return s << p;
+}
+
+/*!
+ \relates TQColor
+ Reads a color object, \a c, from the stream, \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQColor &c )
+{
+ TQ_UINT32 p;
+ s >> p;
+ if ( s.version() == 1 ) // Swap red and blue
+ p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00);
+ c.setRgb( p );
+ return s;
+}
+#endif
+
+/*****************************************************************************
+ TQColor global functions (documentation only)
+ *****************************************************************************/
+
+/*!
+ \fn int tqRed( TQRgb rgb )
+ \relates TQColor
+
+ Returns the red component of the RGB triplet \a rgb.
+ \sa tqRgb(), TQColor::red()
+*/
+
+/*!
+ \fn int tqGreen( TQRgb rgb )
+ \relates TQColor
+
+ Returns the green component of the RGB triplet \a rgb.
+ \sa tqRgb(), TQColor::green()
+*/
+
+/*!
+ \fn int tqBlue( TQRgb rgb )
+ \relates TQColor
+
+ Returns the blue component of the RGB triplet \a rgb.
+ \sa tqRgb(), TQColor::blue()
+*/
+
+/*!
+ \fn int tqAlpha( TQRgb rgba )
+ \relates TQColor
+
+ Returns the alpha component of the RGBA quadruplet \a rgba.
+ */
+
+/*!
+ \fn TQRgb tqRgb( int r, int g, int b )
+ \relates TQColor
+
+ Returns the RGB triplet \a (r,g,b).
+
+ The return type TQRgb is equivalent to \c unsigned \c int.
+
+ \sa tqRgba(), tqRed(), tqGreen(), tqBlue()
+*/
+
+/*!
+ \fn TQRgb tqRgba( int r, int g, int b, int a )
+ \relates TQColor
+
+ Returns the RGBA quadruplet \a (r,g,b,a).
+
+ The return type TQRgba is equivalent to \c unsigned \c int.
+
+ \sa tqRgb(), tqRed(), tqGreen(), tqBlue()
+*/
+
+/*!
+ \fn int tqGray( int r, int g, int b )
+ \relates TQColor
+
+ Returns a gray value 0..255 from the (\a r, \a g, \a b) triplet.
+
+ The gray value is calculated using the formula (r*11 + g*16 +
+ b*5)/32.
+*/
+
+/*!
+ \overload int tqGray( tqRgb rgb )
+ \relates TQColor
+
+ Returns a gray value 0..255 from the given \a rgb colour.
+*/
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqcolor.h b/tqtinterface/qt4/src/kernel/tqcolor.h
new file mode 100644
index 0000000..38979a7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcolor.h
@@ -0,0 +1,348 @@
+/****************************************************************************
+**
+** Definition of TQColor class
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQCOLOR_H
+#define TQCOLOR_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqstringlist.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qcolor.h>
+#include <Qt/qmetatype.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+const TQRgb TQRGB_MASK = 0x00ffffff; // masks RGB values
+
+TQ_EXPORT inline int tqRed( TQRgb rgb ) // get red part of RGB
+{ return (int)((rgb >> 16) & 0xff); }
+
+TQ_EXPORT inline int tqGreen( TQRgb rgb ) // get green part of RGB
+{ return (int)((rgb >> 8) & 0xff); }
+
+TQ_EXPORT inline int tqBlue( TQRgb rgb ) // get blue part of RGB
+{ return (int)(rgb & 0xff); }
+
+TQ_EXPORT inline int tqAlpha( TQRgb rgb ) // get alpha part of RGBA
+{ return (int)((rgb >> 24) & 0xff); }
+
+TQ_EXPORT inline TQRgb tqRgb( int r, int g, int b )// set RGB value
+{ return (0xff << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
+
+TQ_EXPORT inline TQRgb tqRgba( int r, int g, int b, int a )// set RGBA value
+{ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
+
+TQ_EXPORT inline int tqGray( int r, int g, int b )// convert R,G,B to gray 0..255
+{ return (r*11+g*16+b*5)/32; }
+
+TQ_EXPORT inline int tqGray( TQRgb rgb ) // convert RGB to gray 0..255
+{ return tqGray( tqRed(rgb), tqGreen(rgb), tqBlue(rgb) ); }
+
+class TQ_EXPORT TQColor : public QColor
+{
+public:
+ TQColor() : QColor() {}
+ TQColor( int r, int g, int b ) : QColor( r, g, b ) {}
+ TQColor( int x, int y, int z, Spec s ) : QColor() { if (s == Hsv) setHsv(x, y, z); else setRgb(x, y, z); }
+ TQColor( QRgb rgb, uint pixel=0xffffffff) : QColor( rgb ) { TQ_UNUSED(pixel); }
+ TQColor( const QString& name ) : QColor( name ) {}
+ TQColor( const char *name ) : QColor( name ) {}
+ TQColor( const QColor &cr ) : QColor( cr ) {}
+
+ inline TQRgb rgb() const { return QColor::rgb(); }
+ inline void rgb(int *r, int *g, int *b) const { getRgb(r, g, b); }
+ inline void hsv( int *h, int *s, int *v ) const { getHsv(h, s, v); }
+ inline void tqgetHsv( int &h, int &s, int &v ) const { getHsv(&h, &s, &v); }
+
+ static int enterAllocContext();
+ static void leaveAllocContext();
+ static int currentAllocContext();
+ static void destroyAllocContext( int );
+
+ inline void setRgba(int r, int g, int b, int a) { setRgb(r, g, b, a); }
+ inline void getRgba(int *r, int *g, int *b, int *a) const { getRgb(r, g, b, a); }
+
+ uint pixel(int screen = -1) const;
+
+ static int numBitPlanes();
+ uint alloc();
+// uint pixel() const;
+#if defined(TQ_WS_X11)
+ // ### in 4.0, make this take a default argument of -1 for default screen?
+ uint alloc( int screen );
+// uint pixel( int screen ) const;
+#endif
+
+ // [FIXME]
+ inline static void initialize() {
+ printf("[FIXME] TQColor static void initialize() partially implemented\n\r");
+ if ( !globals_init )
+ initGlobalColors();
+ }
+ inline static void cleanup() { printf("[WARNING] TQColor static void cleanup() not implemented\n\r"); }
+
+ enum { Dirt = 0x44495254, Invalid = 0x49000000 };
+private:
+ static bool globals_init;
+ static bool color_init;
+ static enum ColorModel { d8, d32 } colormodel;
+ union {
+ TQRgb argb;
+ struct D8 {
+ TQRgb argb;
+ uchar pix;
+ uchar invalid;
+ uchar dirty;
+ uchar direct;
+ } d8;
+ struct D32 {
+ TQRgb argb;
+ uint pix;
+ bool invalid() const { return argb == TQColor::Invalid && pix == TQColor::Dirt; }
+ bool probablyDirty() const { return pix == TQColor::Dirt; }
+ } d32;
+ } d;
+
+ static void initGlobalColors();
+public:
+ // Interoperability
+ static const TQColor& convertFromQColor( QColor& ql );
+};
+
+Q_DECLARE_METATYPE(TQColor)
+
+// Interoperability
+inline static const TQColor& convertFromQColor( const QColor& qs ) {
+ return (*static_cast<const TQColor*>(&qs));
+}
+
+#else // USE_QT4
+
+const TQRgb TQRGB_MASK = 0x00ffffff; // masks RGB values
+
+TQ_EXPORT inline int tqRed( TQRgb rgb ) // get red part of RGB
+{ return (int)((rgb >> 16) & 0xff); }
+
+TQ_EXPORT inline int tqGreen( TQRgb rgb ) // get green part of RGB
+{ return (int)((rgb >> 8) & 0xff); }
+
+TQ_EXPORT inline int tqBlue( TQRgb rgb ) // get blue part of RGB
+{ return (int)(rgb & 0xff); }
+
+TQ_EXPORT inline int tqAlpha( TQRgb rgb ) // get alpha part of RGBA
+{ return (int)((rgb >> 24) & 0xff); }
+
+TQ_EXPORT inline TQRgb tqRgb( int r, int g, int b )// set RGB value
+{ return (0xff << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
+
+TQ_EXPORT inline TQRgb tqRgba( int r, int g, int b, int a )// set RGBA value
+{ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); }
+
+TQ_EXPORT inline int tqGray( int r, int g, int b )// convert R,G,B to gray 0..255
+{ return (r*11+g*16+b*5)/32; }
+
+TQ_EXPORT inline int tqGray( TQRgb rgb ) // convert RGB to gray 0..255
+{ return tqGray( tqRed(rgb), tqGreen(rgb), tqBlue(rgb) ); }
+
+
+class TQ_EXPORT TQColor
+{
+public:
+ enum Spec { Rgb, Hsv };
+
+ TQColor();
+ TQColor( int r, int g, int b );
+ TQColor( int x, int y, int z, Spec );
+ TQColor( TQRgb rgb, uint pixel=0xffffffff);
+ TQColor( const TQString& name );
+ TQColor( const char *name );
+ TQColor( const TQColor & );
+ TQColor &operator=( const TQColor & );
+
+ bool isValid() const;
+ bool isDirty() const;
+ TQString name() const;
+ void setNamedColor( const TQString& name );
+
+ TQRgb rgb() const;
+ void setRgb( int r, int g, int b );
+ void setRgb( TQRgb rgb );
+ void getRgb( int *r, int *g, int *b ) const { rgb( r, g, b ); }
+ void rgb( int *r, int *g, int *b ) const; // obsolete
+
+ int red() const;
+ int green() const;
+ int blue() const;
+
+ void setHsv( int h, int s, int v );
+ void getHsv( int *h, int *s, int *v ) const { hsv( h, s, v ); }
+ void hsv( int *h, int *s, int *v ) const; // obsolete
+ void getHsv( int &h, int &s, int &v ) const { hsv( &h, &s, &v ); } // obsolete
+
+ TQColor light( int f = 150 ) const;
+ TQColor dark( int f = 200 ) const;
+
+ bool operator==( const TQColor &c ) const;
+ bool operator!=( const TQColor &c ) const;
+
+ uint alloc();
+ uint pixel() const;
+
+#if defined(TQ_WS_X11)
+ // ### in 4.0, make this take a default argument of -1 for default screen?
+ uint alloc( int screen );
+ uint pixel( int screen ) const;
+#endif
+
+ static int maxColors();
+ static int numBitPlanes();
+
+ static int enterAllocContext();
+ static void leaveAllocContext();
+ static int currentAllocContext();
+ static void destroyAllocContext( int );
+
+#if defined(TQ_WS_WIN)
+ static const TQRgb* palette( int* numEntries = 0 );
+ static int setPaletteEntries( const TQRgb* entries, int numEntries,
+ int base = -1 );
+ static HPALETTE hPal() { return hpal; }
+ static uint realizePal( TQWidget * );
+#endif
+
+ static void initialize();
+ static void cleanup();
+#ifndef TQT_NO_STRINGLIST
+ static TQStringList colorNames();
+#endif
+ enum { Dirt = 0x44495254, Invalid = 0x49000000 };
+
+private:
+ void setSystemNamedColor( const TQString& name );
+ void setPixel( uint pixel );
+ static void initGlobalColors();
+ static uint argbToPix32(TQRgb);
+ static TQColor* globalColors();
+ static bool color_init;
+ static bool globals_init;
+#if defined(TQ_WS_WIN)
+ static HPALETTE hpal;
+#endif
+ static enum ColorModel { d8, d32 } colormodel;
+ union {
+ TQRgb argb;
+ struct D8 {
+ TQRgb argb;
+ uchar pix;
+ uchar invalid;
+ uchar dirty;
+ uchar direct;
+ } d8;
+ struct D32 {
+ TQRgb argb;
+ uint pix;
+ bool invalid() const { return argb == TQColor::Invalid && pix == TQColor::Dirt; }
+ bool probablyDirty() const { return pix == TQColor::Dirt; }
+ } d32;
+ } d;
+};
+
+
+inline TQColor::TQColor()
+{ d.d32.argb = Invalid; d.d32.pix = Dirt; }
+
+inline TQColor::TQColor( int r, int g, int b )
+{
+ d.d32.argb = Invalid;
+ d.d32.pix = Dirt;
+ setRgb( r, g, b );
+}
+
+inline TQRgb TQColor::rgb() const
+{ return d.argb; }
+
+inline int TQColor::red() const
+{ return tqRed(d.argb); }
+
+inline int TQColor::green() const
+{ return tqGreen(d.argb); }
+
+inline int TQColor::blue() const
+{ return tqBlue(d.argb); }
+
+inline bool TQColor::isValid() const
+{
+ if ( colormodel == d8 )
+ return !d.d8.invalid;
+ else
+ return !d.d32.invalid();
+}
+
+inline bool TQColor::operator==( const TQColor &c ) const
+{
+ return d.argb == c.d.argb && isValid() == c.isValid();
+}
+
+inline bool TQColor::operator!=( const TQColor &c ) const
+{
+ return !operator==(c);
+}
+
+
+/*****************************************************************************
+ TQColor stream functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQColor & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQColor & );
+#endif
+
+#endif // USE_QT4
+
+#endif // TQCOLOR_H
diff --git a/tqtinterface/qt4/src/kernel/tqcolor_p.cpp b/tqtinterface/qt4/src/kernel/tqcolor_p.cpp
new file mode 100644
index 0000000..4f74408
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcolor_p.cpp
@@ -0,0 +1,802 @@
+/****************************************************************************
+**
+** Named color support for non-X platforms.
+** The color names have been borrowed from X.
+**
+** Created : 000228
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqglobal.h"
+#if defined(TQ_CC_BOR)
+// needed for qsort() because of a std namespace problem on Borland
+#include "tqplatformdefs.h"
+#endif
+
+#include "tqcolor.h"
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+#ifndef TQT_NO_COLORNAMES
+
+#include <stdlib.h>
+
+#undef TQRGB
+#define TQRGB(r,g,b) (r*65536 + g*256 + b)
+
+const int rgbTblSize = 657;
+
+static const struct RGBData {
+ uint value;
+ const char *name;
+} rgbTbl[] = {
+ { TQRGB(240,248,255), "aliceblue" },
+ { TQRGB(250,235,215), "antiquewhite" },
+ { TQRGB(255,239,219), "antiquewhite1" },
+ { TQRGB(238,223,204), "antiquewhite2" },
+ { TQRGB(205,192,176), "antiquewhite3" },
+ { TQRGB(139,131,120), "antiquewhite4" },
+ { TQRGB(127,255,212), "aquamarine" },
+ { TQRGB(127,255,212), "aquamarine1" },
+ { TQRGB(118,238,198), "aquamarine2" },
+ { TQRGB(102,205,170), "aquamarine3" },
+ { TQRGB( 69,139,116), "aquamarine4" },
+ { TQRGB(240,255,255), "azure" },
+ { TQRGB(240,255,255), "azure1" },
+ { TQRGB(224,238,238), "azure2" },
+ { TQRGB(193,205,205), "azure3" },
+ { TQRGB(131,139,139), "azure4" },
+ { TQRGB(245,245,220), "beige" },
+ { TQRGB(255,228,196), "bisque" },
+ { TQRGB(255,228,196), "bisque1" },
+ { TQRGB(238,213,183), "bisque2" },
+ { TQRGB(205,183,158), "bisque3" },
+ { TQRGB(139,125,107), "bisque4" },
+ { TQRGB( 0, 0, 0), "black" },
+ { TQRGB(255,235,205), "blanchedalmond" },
+ { TQRGB( 0, 0,255), "blue" },
+ { TQRGB( 0, 0,255), "blue1" },
+ { TQRGB( 0, 0,238), "blue2" },
+ { TQRGB( 0, 0,205), "blue3" },
+ { TQRGB( 0, 0,139), "blue4" },
+ { TQRGB(138, 43,226), "blueviolet" },
+ { TQRGB(165, 42, 42), "brown" },
+ { TQRGB(255, 64, 64), "brown1" },
+ { TQRGB(238, 59, 59), "brown2" },
+ { TQRGB(205, 51, 51), "brown3" },
+ { TQRGB(139, 35, 35), "brown4" },
+ { TQRGB(222,184,135), "burlywood" },
+ { TQRGB(255,211,155), "burlywood1" },
+ { TQRGB(238,197,145), "burlywood2" },
+ { TQRGB(205,170,125), "burlywood3" },
+ { TQRGB(139,115, 85), "burlywood4" },
+ { TQRGB( 95,158,160), "cadetblue" },
+ { TQRGB(152,245,255), "cadetblue1" },
+ { TQRGB(142,229,238), "cadetblue2" },
+ { TQRGB(122,197,205), "cadetblue3" },
+ { TQRGB( 83,134,139), "cadetblue4" },
+ { TQRGB(127,255, 0), "chartreuse" },
+ { TQRGB(127,255, 0), "chartreuse1" },
+ { TQRGB(118,238, 0), "chartreuse2" },
+ { TQRGB(102,205, 0), "chartreuse3" },
+ { TQRGB( 69,139, 0), "chartreuse4" },
+ { TQRGB(210,105, 30), "chocolate" },
+ { TQRGB(255,127, 36), "chocolate1" },
+ { TQRGB(238,118, 33), "chocolate2" },
+ { TQRGB(205,102, 29), "chocolate3" },
+ { TQRGB(139, 69, 19), "chocolate4" },
+ { TQRGB(255,127, 80), "coral" },
+ { TQRGB(255,114, 86), "coral1" },
+ { TQRGB(238,106, 80), "coral2" },
+ { TQRGB(205, 91, 69), "coral3" },
+ { TQRGB(139, 62, 47), "coral4" },
+ { TQRGB(100,149,237), "cornflowerblue" },
+ { TQRGB(255,248,220), "cornsilk" },
+ { TQRGB(255,248,220), "cornsilk1" },
+ { TQRGB(238,232,205), "cornsilk2" },
+ { TQRGB(205,200,177), "cornsilk3" },
+ { TQRGB(139,136,120), "cornsilk4" },
+ { TQRGB( 0,255,255), "cyan" },
+ { TQRGB( 0,255,255), "cyan1" },
+ { TQRGB( 0,238,238), "cyan2" },
+ { TQRGB( 0,205,205), "cyan3" },
+ { TQRGB( 0,139,139), "cyan4" },
+ { TQRGB( 0, 0,139), "darkblue" },
+ { TQRGB( 0,139,139), "darkcyan" },
+ { TQRGB(184,134, 11), "darkgoldenrod" },
+ { TQRGB(255,185, 15), "darkgoldenrod1" },
+ { TQRGB(238,173, 14), "darkgoldenrod2" },
+ { TQRGB(205,149, 12), "darkgoldenrod3" },
+ { TQRGB(139,101, 8), "darkgoldenrod4" },
+ { TQRGB(169,169,169), "darkgray" },
+ { TQRGB( 0,100, 0), "darkgreen" },
+ { TQRGB(169,169,169), "darkgrey" },
+ { TQRGB(189,183,107), "darkkhaki" },
+ { TQRGB(139, 0,139), "darkmagenta" },
+ { TQRGB( 85,107, 47), "darkolivegreen" },
+ { TQRGB(202,255,112), "darkolivegreen1" },
+ { TQRGB(188,238,104), "darkolivegreen2" },
+ { TQRGB(162,205, 90), "darkolivegreen3" },
+ { TQRGB(110,139, 61), "darkolivegreen4" },
+ { TQRGB(255,140, 0), "darkorange" },
+ { TQRGB(255,127, 0), "darkorange1" },
+ { TQRGB(238,118, 0), "darkorange2" },
+ { TQRGB(205,102, 0), "darkorange3" },
+ { TQRGB(139, 69, 0), "darkorange4" },
+ { TQRGB(153, 50,204), "darkorchid" },
+ { TQRGB(191, 62,255), "darkorchid1" },
+ { TQRGB(178, 58,238), "darkorchid2" },
+ { TQRGB(154, 50,205), "darkorchid3" },
+ { TQRGB(104, 34,139), "darkorchid4" },
+ { TQRGB(139, 0, 0), "darkred" },
+ { TQRGB(233,150,122), "darksalmon" },
+ { TQRGB(143,188,143), "darkseagreen" },
+ { TQRGB(193,255,193), "darkseagreen1" },
+ { TQRGB(180,238,180), "darkseagreen2" },
+ { TQRGB(155,205,155), "darkseagreen3" },
+ { TQRGB(105,139,105), "darkseagreen4" },
+ { TQRGB( 72, 61,139), "darkslateblue" },
+ { TQRGB( 47, 79, 79), "darkslategray" },
+ { TQRGB(151,255,255), "darkslategray1" },
+ { TQRGB(141,238,238), "darkslategray2" },
+ { TQRGB(121,205,205), "darkslategray3" },
+ { TQRGB( 82,139,139), "darkslategray4" },
+ { TQRGB( 47, 79, 79), "darkslategrey" },
+ { TQRGB( 0,206,209), "darkturquoise" },
+ { TQRGB(148, 0,211), "darkviolet" },
+ { TQRGB(255, 20,147), "deeppink" },
+ { TQRGB(255, 20,147), "deeppink1" },
+ { TQRGB(238, 18,137), "deeppink2" },
+ { TQRGB(205, 16,118), "deeppink3" },
+ { TQRGB(139, 10, 80), "deeppink4" },
+ { TQRGB( 0,191,255), "deepskyblue" },
+ { TQRGB( 0,191,255), "deepskyblue1" },
+ { TQRGB( 0,178,238), "deepskyblue2" },
+ { TQRGB( 0,154,205), "deepskyblue3" },
+ { TQRGB( 0,104,139), "deepskyblue4" },
+ { TQRGB(105,105,105), "dimgray" },
+ { TQRGB(105,105,105), "dimgrey" },
+ { TQRGB( 30,144,255), "dodgerblue" },
+ { TQRGB( 30,144,255), "dodgerblue1" },
+ { TQRGB( 28,134,238), "dodgerblue2" },
+ { TQRGB( 24,116,205), "dodgerblue3" },
+ { TQRGB( 16, 78,139), "dodgerblue4" },
+ { TQRGB(178, 34, 34), "firebrick" },
+ { TQRGB(255, 48, 48), "firebrick1" },
+ { TQRGB(238, 44, 44), "firebrick2" },
+ { TQRGB(205, 38, 38), "firebrick3" },
+ { TQRGB(139, 26, 26), "firebrick4" },
+ { TQRGB(255,250,240), "floralwhite" },
+ { TQRGB( 34,139, 34), "forestgreen" },
+ { TQRGB(220,220,220), "gainsboro" },
+ { TQRGB(248,248,255), "ghostwhite" },
+ { TQRGB(255,215, 0), "gold" },
+ { TQRGB(255,215, 0), "gold1" },
+ { TQRGB(238,201, 0), "gold2" },
+ { TQRGB(205,173, 0), "gold3" },
+ { TQRGB(139,117, 0), "gold4" },
+ { TQRGB(218,165, 32), "goldenrod" },
+ { TQRGB(255,193, 37), "goldenrod1" },
+ { TQRGB(238,180, 34), "goldenrod2" },
+ { TQRGB(205,155, 29), "goldenrod3" },
+ { TQRGB(139,105, 20), "goldenrod4" },
+ { TQRGB(190,190,190), "gray" },
+ { TQRGB( 0, 0, 0), "gray0" },
+ { TQRGB( 3, 3, 3), "gray1" },
+ { TQRGB( 26, 26, 26), "gray10" },
+ { TQRGB(255,255,255), "gray100" },
+ { TQRGB( 28, 28, 28), "gray11" },
+ { TQRGB( 31, 31, 31), "gray12" },
+ { TQRGB( 33, 33, 33), "gray13" },
+ { TQRGB( 36, 36, 36), "gray14" },
+ { TQRGB( 38, 38, 38), "gray15" },
+ { TQRGB( 41, 41, 41), "gray16" },
+ { TQRGB( 43, 43, 43), "gray17" },
+ { TQRGB( 46, 46, 46), "gray18" },
+ { TQRGB( 48, 48, 48), "gray19" },
+ { TQRGB( 5, 5, 5), "gray2" },
+ { TQRGB( 51, 51, 51), "gray20" },
+ { TQRGB( 54, 54, 54), "gray21" },
+ { TQRGB( 56, 56, 56), "gray22" },
+ { TQRGB( 59, 59, 59), "gray23" },
+ { TQRGB( 61, 61, 61), "gray24" },
+ { TQRGB( 64, 64, 64), "gray25" },
+ { TQRGB( 66, 66, 66), "gray26" },
+ { TQRGB( 69, 69, 69), "gray27" },
+ { TQRGB( 71, 71, 71), "gray28" },
+ { TQRGB( 74, 74, 74), "gray29" },
+ { TQRGB( 8, 8, 8), "gray3" },
+ { TQRGB( 77, 77, 77), "gray30" },
+ { TQRGB( 79, 79, 79), "gray31" },
+ { TQRGB( 82, 82, 82), "gray32" },
+ { TQRGB( 84, 84, 84), "gray33" },
+ { TQRGB( 87, 87, 87), "gray34" },
+ { TQRGB( 89, 89, 89), "gray35" },
+ { TQRGB( 92, 92, 92), "gray36" },
+ { TQRGB( 94, 94, 94), "gray37" },
+ { TQRGB( 97, 97, 97), "gray38" },
+ { TQRGB( 99, 99, 99), "gray39" },
+ { TQRGB( 10, 10, 10), "gray4" },
+ { TQRGB(102,102,102), "gray40" },
+ { TQRGB(105,105,105), "gray41" },
+ { TQRGB(107,107,107), "gray42" },
+ { TQRGB(110,110,110), "gray43" },
+ { TQRGB(112,112,112), "gray44" },
+ { TQRGB(115,115,115), "gray45" },
+ { TQRGB(117,117,117), "gray46" },
+ { TQRGB(120,120,120), "gray47" },
+ { TQRGB(122,122,122), "gray48" },
+ { TQRGB(125,125,125), "gray49" },
+ { TQRGB( 13, 13, 13), "gray5" },
+ { TQRGB(127,127,127), "gray50" },
+ { TQRGB(130,130,130), "gray51" },
+ { TQRGB(133,133,133), "gray52" },
+ { TQRGB(135,135,135), "gray53" },
+ { TQRGB(138,138,138), "gray54" },
+ { TQRGB(140,140,140), "gray55" },
+ { TQRGB(143,143,143), "gray56" },
+ { TQRGB(145,145,145), "gray57" },
+ { TQRGB(148,148,148), "gray58" },
+ { TQRGB(150,150,150), "gray59" },
+ { TQRGB( 15, 15, 15), "gray6" },
+ { TQRGB(153,153,153), "gray60" },
+ { TQRGB(156,156,156), "gray61" },
+ { TQRGB(158,158,158), "gray62" },
+ { TQRGB(161,161,161), "gray63" },
+ { TQRGB(163,163,163), "gray64" },
+ { TQRGB(166,166,166), "gray65" },
+ { TQRGB(168,168,168), "gray66" },
+ { TQRGB(171,171,171), "gray67" },
+ { TQRGB(173,173,173), "gray68" },
+ { TQRGB(176,176,176), "gray69" },
+ { TQRGB( 18, 18, 18), "gray7" },
+ { TQRGB(179,179,179), "gray70" },
+ { TQRGB(181,181,181), "gray71" },
+ { TQRGB(184,184,184), "gray72" },
+ { TQRGB(186,186,186), "gray73" },
+ { TQRGB(189,189,189), "gray74" },
+ { TQRGB(191,191,191), "gray75" },
+ { TQRGB(194,194,194), "gray76" },
+ { TQRGB(196,196,196), "gray77" },
+ { TQRGB(199,199,199), "gray78" },
+ { TQRGB(201,201,201), "gray79" },
+ { TQRGB( 20, 20, 20), "gray8" },
+ { TQRGB(204,204,204), "gray80" },
+ { TQRGB(207,207,207), "gray81" },
+ { TQRGB(209,209,209), "gray82" },
+ { TQRGB(212,212,212), "gray83" },
+ { TQRGB(214,214,214), "gray84" },
+ { TQRGB(217,217,217), "gray85" },
+ { TQRGB(219,219,219), "gray86" },
+ { TQRGB(222,222,222), "gray87" },
+ { TQRGB(224,224,224), "gray88" },
+ { TQRGB(227,227,227), "gray89" },
+ { TQRGB( 23, 23, 23), "gray9" },
+ { TQRGB(229,229,229), "gray90" },
+ { TQRGB(232,232,232), "gray91" },
+ { TQRGB(235,235,235), "gray92" },
+ { TQRGB(237,237,237), "gray93" },
+ { TQRGB(240,240,240), "gray94" },
+ { TQRGB(242,242,242), "gray95" },
+ { TQRGB(245,245,245), "gray96" },
+ { TQRGB(247,247,247), "gray97" },
+ { TQRGB(250,250,250), "gray98" },
+ { TQRGB(252,252,252), "gray99" },
+ { TQRGB( 0,255, 0), "green" },
+ { TQRGB( 0,255, 0), "green1" },
+ { TQRGB( 0,238, 0), "green2" },
+ { TQRGB( 0,205, 0), "green3" },
+ { TQRGB( 0,139, 0), "green4" },
+ { TQRGB(173,255, 47), "greenyellow" },
+ { TQRGB(190,190,190), "grey" },
+ { TQRGB( 0, 0, 0), "grey0" },
+ { TQRGB( 3, 3, 3), "grey1" },
+ { TQRGB( 26, 26, 26), "grey10" },
+ { TQRGB(255,255,255), "grey100" },
+ { TQRGB( 28, 28, 28), "grey11" },
+ { TQRGB( 31, 31, 31), "grey12" },
+ { TQRGB( 33, 33, 33), "grey13" },
+ { TQRGB( 36, 36, 36), "grey14" },
+ { TQRGB( 38, 38, 38), "grey15" },
+ { TQRGB( 41, 41, 41), "grey16" },
+ { TQRGB( 43, 43, 43), "grey17" },
+ { TQRGB( 46, 46, 46), "grey18" },
+ { TQRGB( 48, 48, 48), "grey19" },
+ { TQRGB( 5, 5, 5), "grey2" },
+ { TQRGB( 51, 51, 51), "grey20" },
+ { TQRGB( 54, 54, 54), "grey21" },
+ { TQRGB( 56, 56, 56), "grey22" },
+ { TQRGB( 59, 59, 59), "grey23" },
+ { TQRGB( 61, 61, 61), "grey24" },
+ { TQRGB( 64, 64, 64), "grey25" },
+ { TQRGB( 66, 66, 66), "grey26" },
+ { TQRGB( 69, 69, 69), "grey27" },
+ { TQRGB( 71, 71, 71), "grey28" },
+ { TQRGB( 74, 74, 74), "grey29" },
+ { TQRGB( 8, 8, 8), "grey3" },
+ { TQRGB( 77, 77, 77), "grey30" },
+ { TQRGB( 79, 79, 79), "grey31" },
+ { TQRGB( 82, 82, 82), "grey32" },
+ { TQRGB( 84, 84, 84), "grey33" },
+ { TQRGB( 87, 87, 87), "grey34" },
+ { TQRGB( 89, 89, 89), "grey35" },
+ { TQRGB( 92, 92, 92), "grey36" },
+ { TQRGB( 94, 94, 94), "grey37" },
+ { TQRGB( 97, 97, 97), "grey38" },
+ { TQRGB( 99, 99, 99), "grey39" },
+ { TQRGB( 10, 10, 10), "grey4" },
+ { TQRGB(102,102,102), "grey40" },
+ { TQRGB(105,105,105), "grey41" },
+ { TQRGB(107,107,107), "grey42" },
+ { TQRGB(110,110,110), "grey43" },
+ { TQRGB(112,112,112), "grey44" },
+ { TQRGB(115,115,115), "grey45" },
+ { TQRGB(117,117,117), "grey46" },
+ { TQRGB(120,120,120), "grey47" },
+ { TQRGB(122,122,122), "grey48" },
+ { TQRGB(125,125,125), "grey49" },
+ { TQRGB( 13, 13, 13), "grey5" },
+ { TQRGB(127,127,127), "grey50" },
+ { TQRGB(130,130,130), "grey51" },
+ { TQRGB(133,133,133), "grey52" },
+ { TQRGB(135,135,135), "grey53" },
+ { TQRGB(138,138,138), "grey54" },
+ { TQRGB(140,140,140), "grey55" },
+ { TQRGB(143,143,143), "grey56" },
+ { TQRGB(145,145,145), "grey57" },
+ { TQRGB(148,148,148), "grey58" },
+ { TQRGB(150,150,150), "grey59" },
+ { TQRGB( 15, 15, 15), "grey6" },
+ { TQRGB(153,153,153), "grey60" },
+ { TQRGB(156,156,156), "grey61" },
+ { TQRGB(158,158,158), "grey62" },
+ { TQRGB(161,161,161), "grey63" },
+ { TQRGB(163,163,163), "grey64" },
+ { TQRGB(166,166,166), "grey65" },
+ { TQRGB(168,168,168), "grey66" },
+ { TQRGB(171,171,171), "grey67" },
+ { TQRGB(173,173,173), "grey68" },
+ { TQRGB(176,176,176), "grey69" },
+ { TQRGB( 18, 18, 18), "grey7" },
+ { TQRGB(179,179,179), "grey70" },
+ { TQRGB(181,181,181), "grey71" },
+ { TQRGB(184,184,184), "grey72" },
+ { TQRGB(186,186,186), "grey73" },
+ { TQRGB(189,189,189), "grey74" },
+ { TQRGB(191,191,191), "grey75" },
+ { TQRGB(194,194,194), "grey76" },
+ { TQRGB(196,196,196), "grey77" },
+ { TQRGB(199,199,199), "grey78" },
+ { TQRGB(201,201,201), "grey79" },
+ { TQRGB( 20, 20, 20), "grey8" },
+ { TQRGB(204,204,204), "grey80" },
+ { TQRGB(207,207,207), "grey81" },
+ { TQRGB(209,209,209), "grey82" },
+ { TQRGB(212,212,212), "grey83" },
+ { TQRGB(214,214,214), "grey84" },
+ { TQRGB(217,217,217), "grey85" },
+ { TQRGB(219,219,219), "grey86" },
+ { TQRGB(222,222,222), "grey87" },
+ { TQRGB(224,224,224), "grey88" },
+ { TQRGB(227,227,227), "grey89" },
+ { TQRGB( 23, 23, 23), "grey9" },
+ { TQRGB(229,229,229), "grey90" },
+ { TQRGB(232,232,232), "grey91" },
+ { TQRGB(235,235,235), "grey92" },
+ { TQRGB(237,237,237), "grey93" },
+ { TQRGB(240,240,240), "grey94" },
+ { TQRGB(242,242,242), "grey95" },
+ { TQRGB(245,245,245), "grey96" },
+ { TQRGB(247,247,247), "grey97" },
+ { TQRGB(250,250,250), "grey98" },
+ { TQRGB(252,252,252), "grey99" },
+ { TQRGB(240,255,240), "honeydew" },
+ { TQRGB(240,255,240), "honeydew1" },
+ { TQRGB(224,238,224), "honeydew2" },
+ { TQRGB(193,205,193), "honeydew3" },
+ { TQRGB(131,139,131), "honeydew4" },
+ { TQRGB(255,105,180), "hotpink" },
+ { TQRGB(255,110,180), "hotpink1" },
+ { TQRGB(238,106,167), "hotpink2" },
+ { TQRGB(205, 96,144), "hotpink3" },
+ { TQRGB(139, 58, 98), "hotpink4" },
+ { TQRGB(205, 92, 92), "indianred" },
+ { TQRGB(255,106,106), "indianred1" },
+ { TQRGB(238, 99, 99), "indianred2" },
+ { TQRGB(205, 85, 85), "indianred3" },
+ { TQRGB(139, 58, 58), "indianred4" },
+ { TQRGB(255,255,240), "ivory" },
+ { TQRGB(255,255,240), "ivory1" },
+ { TQRGB(238,238,224), "ivory2" },
+ { TQRGB(205,205,193), "ivory3" },
+ { TQRGB(139,139,131), "ivory4" },
+ { TQRGB(240,230,140), "khaki" },
+ { TQRGB(255,246,143), "khaki1" },
+ { TQRGB(238,230,133), "khaki2" },
+ { TQRGB(205,198,115), "khaki3" },
+ { TQRGB(139,134, 78), "khaki4" },
+ { TQRGB(230,230,250), "lavender" },
+ { TQRGB(255,240,245), "lavenderblush" },
+ { TQRGB(255,240,245), "lavenderblush1" },
+ { TQRGB(238,224,229), "lavenderblush2" },
+ { TQRGB(205,193,197), "lavenderblush3" },
+ { TQRGB(139,131,134), "lavenderblush4" },
+ { TQRGB(124,252, 0), "lawngreen" },
+ { TQRGB(255,250,205), "lemonchiffon" },
+ { TQRGB(255,250,205), "lemonchiffon1" },
+ { TQRGB(238,233,191), "lemonchiffon2" },
+ { TQRGB(205,201,165), "lemonchiffon3" },
+ { TQRGB(139,137,112), "lemonchiffon4" },
+ { TQRGB(173,216,230), "lightblue" },
+ { TQRGB(191,239,255), "lightblue1" },
+ { TQRGB(178,223,238), "lightblue2" },
+ { TQRGB(154,192,205), "lightblue3" },
+ { TQRGB(104,131,139), "lightblue4" },
+ { TQRGB(240,128,128), "lightcoral" },
+ { TQRGB(224,255,255), "lightcyan" },
+ { TQRGB(224,255,255), "lightcyan1" },
+ { TQRGB(209,238,238), "lightcyan2" },
+ { TQRGB(180,205,205), "lightcyan3" },
+ { TQRGB(122,139,139), "lightcyan4" },
+ { TQRGB(238,221,130), "lightgoldenrod" },
+ { TQRGB(255,236,139), "lightgoldenrod1" },
+ { TQRGB(238,220,130), "lightgoldenrod2" },
+ { TQRGB(205,190,112), "lightgoldenrod3" },
+ { TQRGB(139,129, 76), "lightgoldenrod4" },
+ { TQRGB(250,250,210), "lightgoldenrodyellow" },
+ { TQRGB(211,211,211), "lightgray" },
+ { TQRGB(144,238,144), "lightgreen" },
+ { TQRGB(211,211,211), "lightgrey" },
+ { TQRGB(255,182,193), "lightpink" },
+ { TQRGB(255,174,185), "lightpink1" },
+ { TQRGB(238,162,173), "lightpink2" },
+ { TQRGB(205,140,149), "lightpink3" },
+ { TQRGB(139, 95,101), "lightpink4" },
+ { TQRGB(255,160,122), "lightsalmon" },
+ { TQRGB(255,160,122), "lightsalmon1" },
+ { TQRGB(238,149,114), "lightsalmon2" },
+ { TQRGB(205,129, 98), "lightsalmon3" },
+ { TQRGB(139, 87, 66), "lightsalmon4" },
+ { TQRGB( 32,178,170), "lightseagreen" },
+ { TQRGB(135,206,250), "lightskyblue" },
+ { TQRGB(176,226,255), "lightskyblue1" },
+ { TQRGB(164,211,238), "lightskyblue2" },
+ { TQRGB(141,182,205), "lightskyblue3" },
+ { TQRGB( 96,123,139), "lightskyblue4" },
+ { TQRGB(132,112,255), "lightslateblue" },
+ { TQRGB(119,136,153), "lightslategray" },
+ { TQRGB(119,136,153), "lightslategrey" },
+ { TQRGB(176,196,222), "lightsteelblue" },
+ { TQRGB(202,225,255), "lightsteelblue1" },
+ { TQRGB(188,210,238), "lightsteelblue2" },
+ { TQRGB(162,181,205), "lightsteelblue3" },
+ { TQRGB(110,123,139), "lightsteelblue4" },
+ { TQRGB(255,255,224), "lightyellow" },
+ { TQRGB(255,255,224), "lightyellow1" },
+ { TQRGB(238,238,209), "lightyellow2" },
+ { TQRGB(205,205,180), "lightyellow3" },
+ { TQRGB(139,139,122), "lightyellow4" },
+ { TQRGB( 50,205, 50), "limegreen" },
+ { TQRGB(250,240,230), "linen" },
+ { TQRGB(255, 0,255), "magenta" },
+ { TQRGB(255, 0,255), "magenta1" },
+ { TQRGB(238, 0,238), "magenta2" },
+ { TQRGB(205, 0,205), "magenta3" },
+ { TQRGB(139, 0,139), "magenta4" },
+ { TQRGB(176, 48, 96), "maroon" },
+ { TQRGB(255, 52,179), "maroon1" },
+ { TQRGB(238, 48,167), "maroon2" },
+ { TQRGB(205, 41,144), "maroon3" },
+ { TQRGB(139, 28, 98), "maroon4" },
+ { TQRGB(102,205,170), "mediumaquamarine" },
+ { TQRGB( 0, 0,205), "mediumblue" },
+ { TQRGB(186, 85,211), "mediumorchid" },
+ { TQRGB(224,102,255), "mediumorchid1" },
+ { TQRGB(209, 95,238), "mediumorchid2" },
+ { TQRGB(180, 82,205), "mediumorchid3" },
+ { TQRGB(122, 55,139), "mediumorchid4" },
+ { TQRGB(147,112,219), "mediumpurple" },
+ { TQRGB(171,130,255), "mediumpurple1" },
+ { TQRGB(159,121,238), "mediumpurple2" },
+ { TQRGB(137,104,205), "mediumpurple3" },
+ { TQRGB( 93, 71,139), "mediumpurple4" },
+ { TQRGB( 60,179,113), "mediumseagreen" },
+ { TQRGB(123,104,238), "mediumslateblue" },
+ { TQRGB( 0,250,154), "mediumspringgreen" },
+ { TQRGB( 72,209,204), "mediumturquoise" },
+ { TQRGB(199, 21,133), "mediumvioletred" },
+ { TQRGB( 25, 25,112), "midnightblue" },
+ { TQRGB(245,255,250), "mintcream" },
+ { TQRGB(255,228,225), "mistyrose" },
+ { TQRGB(255,228,225), "mistyrose1" },
+ { TQRGB(238,213,210), "mistyrose2" },
+ { TQRGB(205,183,181), "mistyrose3" },
+ { TQRGB(139,125,123), "mistyrose4" },
+ { TQRGB(255,228,181), "tqmoccasin" },
+ { TQRGB(255,222,173), "navajowhite" },
+ { TQRGB(255,222,173), "navajowhite1" },
+ { TQRGB(238,207,161), "navajowhite2" },
+ { TQRGB(205,179,139), "navajowhite3" },
+ { TQRGB(139,121, 94), "navajowhite4" },
+ { TQRGB( 0, 0,128), "navy" },
+ { TQRGB( 0, 0,128), "navyblue" },
+ { TQRGB(253,245,230), "oldlace" },
+ { TQRGB(107,142, 35), "olivedrab" },
+ { TQRGB(192,255, 62), "olivedrab1" },
+ { TQRGB(179,238, 58), "olivedrab2" },
+ { TQRGB(154,205, 50), "olivedrab3" },
+ { TQRGB(105,139, 34), "olivedrab4" },
+ { TQRGB(255,165, 0), "orange" },
+ { TQRGB(255,165, 0), "orange1" },
+ { TQRGB(238,154, 0), "orange2" },
+ { TQRGB(205,133, 0), "orange3" },
+ { TQRGB(139, 90, 0), "orange4" },
+ { TQRGB(255, 69, 0), "orangered" },
+ { TQRGB(255, 69, 0), "orangered1" },
+ { TQRGB(238, 64, 0), "orangered2" },
+ { TQRGB(205, 55, 0), "orangered3" },
+ { TQRGB(139, 37, 0), "orangered4" },
+ { TQRGB(218,112,214), "orchid" },
+ { TQRGB(255,131,250), "orchid1" },
+ { TQRGB(238,122,233), "orchid2" },
+ { TQRGB(205,105,201), "orchid3" },
+ { TQRGB(139, 71,137), "orchid4" },
+ { TQRGB(238,232,170), "palegoldenrod" },
+ { TQRGB(152,251,152), "palegreen" },
+ { TQRGB(154,255,154), "palegreen1" },
+ { TQRGB(144,238,144), "palegreen2" },
+ { TQRGB(124,205,124), "palegreen3" },
+ { TQRGB( 84,139, 84), "palegreen4" },
+ { TQRGB(175,238,238), "paleturquoise" },
+ { TQRGB(187,255,255), "paleturquoise1" },
+ { TQRGB(174,238,238), "paleturquoise2" },
+ { TQRGB(150,205,205), "paleturquoise3" },
+ { TQRGB(102,139,139), "paleturquoise4" },
+ { TQRGB(219,112,147), "palevioletred" },
+ { TQRGB(255,130,171), "palevioletred1" },
+ { TQRGB(238,121,159), "palevioletred2" },
+ { TQRGB(205,104,137), "palevioletred3" },
+ { TQRGB(139, 71, 93), "palevioletred4" },
+ { TQRGB(255,239,213), "papayawhip" },
+ { TQRGB(255,218,185), "peachpuff" },
+ { TQRGB(255,218,185), "peachpuff1" },
+ { TQRGB(238,203,173), "peachpuff2" },
+ { TQRGB(205,175,149), "peachpuff3" },
+ { TQRGB(139,119,101), "peachpuff4" },
+ { TQRGB(205,133, 63), "peru" },
+ { TQRGB(255,192,203), "pink" },
+ { TQRGB(255,181,197), "pink1" },
+ { TQRGB(238,169,184), "pink2" },
+ { TQRGB(205,145,158), "pink3" },
+ { TQRGB(139, 99,108), "pink4" },
+ { TQRGB(221,160,221), "plum" },
+ { TQRGB(255,187,255), "plum1" },
+ { TQRGB(238,174,238), "plum2" },
+ { TQRGB(205,150,205), "plum3" },
+ { TQRGB(139,102,139), "plum4" },
+ { TQRGB(176,224,230), "powderblue" },
+ { TQRGB(160, 32,240), "purple" },
+ { TQRGB(155, 48,255), "purple1" },
+ { TQRGB(145, 44,238), "purple2" },
+ { TQRGB(125, 38,205), "purple3" },
+ { TQRGB( 85, 26,139), "purple4" },
+ { TQRGB(255, 0, 0), "red" },
+ { TQRGB(255, 0, 0), "red1" },
+ { TQRGB(238, 0, 0), "red2" },
+ { TQRGB(205, 0, 0), "red3" },
+ { TQRGB(139, 0, 0), "red4" },
+ { TQRGB(188,143,143), "rosybrown" },
+ { TQRGB(255,193,193), "rosybrown1" },
+ { TQRGB(238,180,180), "rosybrown2" },
+ { TQRGB(205,155,155), "rosybrown3" },
+ { TQRGB(139,105,105), "rosybrown4" },
+ { TQRGB( 65,105,225), "royalblue" },
+ { TQRGB( 72,118,255), "royalblue1" },
+ { TQRGB( 67,110,238), "royalblue2" },
+ { TQRGB( 58, 95,205), "royalblue3" },
+ { TQRGB( 39, 64,139), "royalblue4" },
+ { TQRGB(139, 69, 19), "saddlebrown" },
+ { TQRGB(250,128,114), "salmon" },
+ { TQRGB(255,140,105), "salmon1" },
+ { TQRGB(238,130, 98), "salmon2" },
+ { TQRGB(205,112, 84), "salmon3" },
+ { TQRGB(139, 76, 57), "salmon4" },
+ { TQRGB(244,164, 96), "sandybrown" },
+ { TQRGB( 46,139, 87), "seagreen" },
+ { TQRGB( 84,255,159), "seagreen1" },
+ { TQRGB( 78,238,148), "seagreen2" },
+ { TQRGB( 67,205,128), "seagreen3" },
+ { TQRGB( 46,139, 87), "seagreen4" },
+ { TQRGB(255,245,238), "seashell" },
+ { TQRGB(255,245,238), "seashell1" },
+ { TQRGB(238,229,222), "seashell2" },
+ { TQRGB(205,197,191), "seashell3" },
+ { TQRGB(139,134,130), "seashell4" },
+ { TQRGB(160, 82, 45), "sienna" },
+ { TQRGB(255,130, 71), "sienna1" },
+ { TQRGB(238,121, 66), "sienna2" },
+ { TQRGB(205,104, 57), "sienna3" },
+ { TQRGB(139, 71, 38), "sienna4" },
+ { TQRGB(135,206,235), "skyblue" },
+ { TQRGB(135,206,255), "skyblue1" },
+ { TQRGB(126,192,238), "skyblue2" },
+ { TQRGB(108,166,205), "skyblue3" },
+ { TQRGB( 74,112,139), "skyblue4" },
+ { TQRGB(106, 90,205), "slateblue" },
+ { TQRGB(131,111,255), "slateblue1" },
+ { TQRGB(122,103,238), "slateblue2" },
+ { TQRGB(105, 89,205), "slateblue3" },
+ { TQRGB( 71, 60,139), "slateblue4" },
+ { TQRGB(112,128,144), "slategray" },
+ { TQRGB(198,226,255), "slategray1" },
+ { TQRGB(185,211,238), "slategray2" },
+ { TQRGB(159,182,205), "slategray3" },
+ { TQRGB(108,123,139), "slategray4" },
+ { TQRGB(112,128,144), "slategrey" },
+ { TQRGB(255,250,250), "snow" },
+ { TQRGB(255,250,250), "snow1" },
+ { TQRGB(238,233,233), "snow2" },
+ { TQRGB(205,201,201), "snow3" },
+ { TQRGB(139,137,137), "snow4" },
+ { TQRGB( 0,255,127), "springgreen" },
+ { TQRGB( 0,255,127), "springgreen1" },
+ { TQRGB( 0,238,118), "springgreen2" },
+ { TQRGB( 0,205,102), "springgreen3" },
+ { TQRGB( 0,139, 69), "springgreen4" },
+ { TQRGB( 70,130,180), "steelblue" },
+ { TQRGB( 99,184,255), "steelblue1" },
+ { TQRGB( 92,172,238), "steelblue2" },
+ { TQRGB( 79,148,205), "steelblue3" },
+ { TQRGB( 54,100,139), "steelblue4" },
+ { TQRGB(210,180,140), "tan" },
+ { TQRGB(255,165, 79), "tan1" },
+ { TQRGB(238,154, 73), "tan2" },
+ { TQRGB(205,133, 63), "tan3" },
+ { TQRGB(139, 90, 43), "tan4" },
+ { TQRGB(216,191,216), "thistle" },
+ { TQRGB(255,225,255), "thistle1" },
+ { TQRGB(238,210,238), "thistle2" },
+ { TQRGB(205,181,205), "thistle3" },
+ { TQRGB(139,123,139), "thistle4" },
+ { TQRGB(255, 99, 71), "tomato" },
+ { TQRGB(255, 99, 71), "tomato1" },
+ { TQRGB(238, 92, 66), "tomato2" },
+ { TQRGB(205, 79, 57), "tomato3" },
+ { TQRGB(139, 54, 38), "tomato4" },
+ { TQRGB( 64,224,208), "turquoise" },
+ { TQRGB( 0,245,255), "turquoise1" },
+ { TQRGB( 0,229,238), "turquoise2" },
+ { TQRGB( 0,197,205), "turquoise3" },
+ { TQRGB( 0,134,139), "turquoise4" },
+ { TQRGB(238,130,238), "violet" },
+ { TQRGB(208, 32,144), "violetred" },
+ { TQRGB(255, 62,150), "violetred1" },
+ { TQRGB(238, 58,140), "violetred2" },
+ { TQRGB(205, 50,120), "violetred3" },
+ { TQRGB(139, 34, 82), "violetred4" },
+ { TQRGB(245,222,179), "wheat" },
+ { TQRGB(255,231,186), "wheat1" },
+ { TQRGB(238,216,174), "wheat2" },
+ { TQRGB(205,186,150), "wheat3" },
+ { TQRGB(139,126,102), "wheat4" },
+ { TQRGB(255,255,255), "white" },
+ { TQRGB(245,245,245), "whitesmoke" },
+ { TQRGB(255,255, 0), "yellow" },
+ { TQRGB(255,255, 0), "yellow1" },
+ { TQRGB(238,238, 0), "yellow2" },
+ { TQRGB(205,205, 0), "yellow3" },
+ { TQRGB(139,139, 0), "yellow4" },
+ { TQRGB(154,205, 50), "yellowgreen" } };
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+#ifdef TQ_OS_TEMP
+static int __cdecl rgb_cmp( const void *d1, const void *d2 )
+#else
+static int rgb_cmp( const void *d1, const void *d2 )
+#endif
+{
+ return qstricmp( ((RGBData *)d1)->name, ((RGBData *)d2)->name );
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+bool qt_get_named_rgb( const char *name, TQRgb* rgb )
+{
+ TQ_LONG len = strlen(name)+1;
+ char *name_no_space = (char *)malloc(len);
+ for(TQ_LONG o=0,i=0; i < len; i++) {
+ if(name[i] != '\t' && name[i] != ' ')
+ name_no_space[o++] = name[i];
+ }
+
+ RGBData x;
+ x.name = name_no_space;
+ // Funtion bsearch() is supposed to be
+ // void *bsearch(const void *key, const void *base, ...
+ // So why (char*)? Are there broken bsearch() declarations out there?
+ RGBData *r = (RGBData*)bsearch((char*)&x, (char*)rgbTbl, rgbTblSize,
+ sizeof(RGBData), rgb_cmp);
+ free(name_no_space);
+ if ( r ) {
+ *rgb = r->value;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+uint qt_get_rgb_val( const char *name )
+{
+ TQRgb r = 0;
+ qt_get_named_rgb(name,&r);
+ return r;
+}
+#ifndef TQT_NO_STRINGLIST
+TQStringList TQColor::colorNames()
+{
+ int i = 0;
+ TQStringList lst;
+ for ( i = 0; i < rgbTblSize; i++ )
+ lst << rgbTbl[i].name;
+
+ return lst;
+}
+#endif
+#else
+
+bool qt_get_named_rgb( const char *, TQRgb* )
+{
+ return FALSE;
+}
+
+uint qt_get_rgb_val( const char * )
+{
+ return 0;
+}
+#ifndef TQT_NO_STRINGLIST
+TQStringList TQColor::colorNames()
+{
+ return TQStringList();
+}
+#endif
+#endif // TQT_NO_COLORNAMES
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqcolor_p.h b/tqtinterface/qt4/src/kernel/tqcolor_p.h
new file mode 100644
index 0000000..be9df40
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcolor_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Named color support for non-X platforms.
+** The color names have been borrowed from X.
+**
+** Created : 000228
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQCOLOR_P_H
+#define TQCOLOR_P_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of qmenudata.cpp, qmenubar.cpp, qmenubar.cpp, qpopupmenu.cpp,
+// qmotifstyle.cpp and qwindowssstyle.cpp. This header file may change
+// from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#endif // TQT_H
+
+extern uint qt_get_rgb_val( const char *name );
+extern bool qt_get_named_rgb( const char *, TQRgb* );
+extern void qt_reset_color_avail();
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqcolor_x11.cpp b/tqtinterface/qt4/src/kernel/tqcolor_x11.cpp
new file mode 100644
index 0000000..909ecbb
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcolor_x11.cpp
@@ -0,0 +1,1336 @@
+/****************************************************************************
+**
+** Implementation of TQColor class for X11
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqcolor.h"
+#include "tqcolor_p.h"
+#include "string.h"
+#include "tqpaintdevice.h"
+#include "tqapplication.h"
+#include "tqapplication_p.h"
+#include "tqt_x11_p.h"
+
+#ifdef USE_QT4
+
+#include "tqintdict.h"
+
+static const uint col_std_dict = 419;
+static const uint col_large_dict = 18397;
+
+struct TQColorData {
+ uint pix; // allocated pixel value
+ int context; // allocation context
+};
+
+typedef TQIntDict<TQColorData> TQColorDict;
+typedef TQIntDictIterator<TQColorData> TQColorDictIt;
+
+static int current_alloc_context = 0; // current color alloc context
+
+class TQColorScreenData {
+public:
+ TQColorScreenData()
+ {
+ colorDict = 0;
+ colors_avail = TRUE;
+ g_vis = 0;
+ g_carr = 0;
+ g_carr_fetch = TRUE;
+ g_cells = 0;
+ g_our_alloc = 0;
+ color_reduce = FALSE;
+ }
+
+ TQColorDict *colorDict; // dict of allocated colors
+ bool colors_avail; // X colors available
+ bool g_truecolor; // truecolor visual
+ Visual *g_vis; // visual
+ XColor *g_carr; // color array
+ bool g_carr_fetch; // perform XQueryColors?
+ int g_cells; // number of entries in g_carr
+ bool *g_our_alloc; // our allocated colors
+ uint red_mask , green_mask , blue_mask;
+ int red_shift, green_shift, blue_shift;
+ bool color_reduce;
+ int col_div_r;
+ int col_div_g;
+ int col_div_b;
+};
+
+static int screencount = 0;
+static TQColorScreenData **screendata = 0; // array of screendata pointers
+
+#define MAX_CONTEXTS 16
+static int context_stack[MAX_CONTEXTS];
+static int context_ptr = 0;
+
+static void init_context_stack()
+{
+ static bool did_init = FALSE;
+ if ( !did_init ) {
+ did_init = TRUE;
+ context_stack[0] = current_alloc_context = 0;
+ }
+}
+
+/*
+ This function is called from the event loop. It resets the colors_avail
+ flag so that the application can retry to allocate read-only colors
+ that other applications may have deallocated lately.
+
+ The g_our_alloc and g_carr are global arrays that optimize color
+ approximation when there are no more colors left to allocate.
+*/
+
+void qt_reset_color_avail()
+{
+ int i;
+ for ( i = 0; i < screencount; i++ ) {
+ screendata[i]->colors_avail = TRUE;
+ screendata[i]->g_carr_fetch = TRUE; // do XQueryColors if !colors_avail
+ }
+}
+
+/*!
+ Enters a color allocation context and returns a non-zero unique
+ identifier.
+
+ Color allocation contexts are useful for programs that need to
+ allocate many colors and throw them away later, like image
+ viewers. The allocation context functions work for true color
+ displays as well as for colormap displays, except that
+ TQColor::destroyAllocContext() does nothing for true color.
+
+ Example:
+ \code
+ TQPixmap loadPixmap( TQString fileName )
+ {
+ static int alloc_context = 0;
+ if ( alloc_context )
+ TQColor::destroyAllocContext( alloc_context );
+ alloc_context = TQColor::enterAllocContext();
+ TQPixmap pm( fileName );
+ TQColor::leaveAllocContext();
+ return pm;
+ }
+ \endcode
+
+ The example code loads a pixmap from file. It frees up all colors
+ that were allocated the last time loadPixmap() was called.
+
+ The initial/default context is 0. TQt keeps a list of colors
+ associated with their allocation contexts. You can call
+ destroyAllocContext() to get rid of all colors that were allocated
+ in a specific context.
+
+ Calling enterAllocContext() enters an allocation context. The
+ allocation context lasts until you call leaveAllocContext().
+ TQColor has an internal stack of allocation contexts. Each call to
+ enterAllocContex() must have a corresponding leaveAllocContext().
+
+ \code
+ // context 0 active
+ int c1 = TQColor::enterAllocContext(); // enter context c1
+ // context c1 active
+ int c2 = TQColor::enterAllocContext(); // enter context c2
+ // context c2 active
+ TQColor::leaveAllocContext(); // leave context c2
+ // context c1 active
+ TQColor::leaveAllocContext(); // leave context c1
+ // context 0 active
+ // Now, free all colors that were allocated in context c2
+ TQColor::destroyAllocContext( c2 );
+ \endcode
+
+ You may also want to set the application's color specification.
+ See TQApplication::setColorSpec() for more information.
+
+ \sa leaveAllocContext(), currentAllocContext(), destroyAllocContext(),
+ TQApplication::setColorSpec()
+*/
+
+int TQColor::enterAllocContext()
+{
+ static int context_seq_no = 0;
+ init_context_stack();
+ if ( context_ptr+1 == MAX_CONTEXTS ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQColor::enterAllocContext: Context stack overflow" );
+#endif
+ return 0;
+ }
+ current_alloc_context = context_stack[++context_ptr] = ++context_seq_no;
+ return current_alloc_context;
+}
+
+
+/*!
+ Leaves a color allocation context.
+
+ See enterAllocContext() for a detailed explanation.
+
+ \sa enterAllocContext(), currentAllocContext()
+*/
+
+void TQColor::leaveAllocContext()
+{
+ init_context_stack();
+ if ( context_ptr == 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQColor::leaveAllocContext: Context stack underflow" );
+#endif
+ return;
+ }
+ current_alloc_context = context_stack[--context_ptr];
+}
+
+
+/*!
+ Returns the current color allocation context.
+
+ The default context is 0.
+
+ \sa enterAllocContext(), leaveAllocContext()
+*/
+
+int TQColor::currentAllocContext()
+{
+ return current_alloc_context;
+}
+
+
+/*!
+ Destroys a color allocation context, \e context.
+
+ This function deallocates all colors that were allocated in the
+ specified \a context. If \a context == -1, it frees up all colors
+ that the application has allocated. If \a context == -2, it frees
+ up all colors that the application has allocated, except those in
+ the default context.
+
+ The function does nothing for true color displays.
+
+ \sa enterAllocContext(), alloc()
+*/
+
+void TQColor::destroyAllocContext( int context )
+{
+ init_context_stack();
+ if ( !color_init )
+ return;
+
+ int screen;
+ for ( screen = 0; screen < screencount; ++screen ) {
+ if ( screendata[screen]->g_truecolor )
+ continue;
+
+ ulong pixels[256];
+ bool freeing[256];
+ memset( freeing, FALSE, screendata[screen]->g_cells*sizeof(bool) );
+ TQColorData *d;
+ TQColorDictIt it( *screendata[screen]->colorDict );
+ int i = 0;
+ uint rgbv;
+ while ( (d=it.current()) ) {
+ rgbv = (uint)it.currentKey();
+ if ( (d->context || context==-1) &&
+ (d->context == context || context < 0) ) {
+ if ( !screendata[screen]->g_our_alloc[d->pix] && !freeing[d->pix] ) {
+ // will free this color
+ pixels[i++] = d->pix;
+ freeing[d->pix] = TRUE;
+ }
+ // remove from dict
+ screendata[screen]->colorDict->remove( (long)rgbv );
+ }
+ ++it;
+ }
+ if ( i )
+ XFreeColors( TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppColormap( screen ),
+ pixels, i, 0 );
+ }
+}
+
+/*!
+ Returns the number of color bit planes for the underlying window
+ system.
+
+ The returned value is equal to the default pixmap depth.
+
+ \sa TQPixmap::defaultDepth()
+*/
+
+int TQColor::numBitPlanes()
+{
+ return TQPaintDevice::x11AppDepth();
+}
+
+/*
+ Finds the nearest color.
+*/
+
+static int tqfind_nearest_color( int r, int g, int b, int* mindist_out,
+ TQColorScreenData *sd )
+{
+ int mincol = -1;
+ int mindist = 200000;
+ int rx, gx, bx, dist;
+ XColor *xc = &sd->g_carr[0];
+ for ( int i=0; i<sd->g_cells; i++ ) {
+ rx = r - (xc->red >> 8);
+ gx = g - (xc->green >> 8);
+ bx = b - (xc->blue>> 8);
+ dist = rx*rx + gx*gx + bx*bx; // calculate distance
+ if ( dist < mindist ) { // minimal?
+ mindist = dist;
+ mincol = i;
+ }
+ xc++;
+ }
+ *mindist_out = mindist;
+ return mincol;
+}
+
+/*!
+ \internal
+ Allocates the color on screen \a screen. Only used in X11.
+
+ \sa alloc(), pixel()
+*/
+uint TQColor::alloc( int screen )
+{
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ if ( screen < 0 )
+ screen = TQPaintDevice::x11AppScreen();
+ if ( !color_init )
+ return dpy ? (uint)BlackPixel(dpy, screen) : 0;
+ int r = tqRed(d.argb);
+ int g = tqGreen(d.argb);
+ int b = tqBlue(d.argb);
+ uint pix = 0;
+ TQColorScreenData *sd = screendata[screen];
+ if ( sd->g_truecolor ) { // truecolor: map to pixel
+ r = sd->red_shift > 0 ? r << sd->red_shift : r >> -sd->red_shift;
+ g = sd->green_shift > 0 ? g << sd->green_shift : g >> -sd->green_shift;
+ b = sd->blue_shift > 0 ? b << sd->blue_shift : b >> -sd->blue_shift;
+ pix = (b & sd->blue_mask) | (g & sd->green_mask) | (r & sd->red_mask)
+ | ~(sd->blue_mask | sd->green_mask | sd->red_mask);
+ if ( screen == TQPaintDevice::x11AppScreen() )
+ d.d32.pix = pix;
+ return pix;
+ }
+ TQColorData *c = sd->colorDict->tqfind( (long)(d.argb) );
+ if ( c ) { // found color in dictionary
+ pix = c->pix;
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE; // color ok
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix; // use same pixel value
+ if ( c->context != current_alloc_context ) {
+ c->context = 0; // convert to default context
+ sd->g_our_alloc[pix] = TRUE; // reuse without XAllocColor
+ }
+ }
+ return pix;
+ }
+
+ XColor col;
+ col.red = r << 8;
+ col.green = g << 8;
+ col.blue = b << 8;
+
+ bool try_again = FALSE;
+ bool try_alloc = !sd->color_reduce;
+ int try_count = 0;
+
+ do {
+ // This loop is run until we manage to either allocate or
+ // tqfind an approximate color, it stops after a few iterations.
+
+ try_again = FALSE;
+
+ if ( try_alloc && sd->colors_avail &&
+ XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ),&col) ) {
+ // We could allocate the color
+ pix = (uint) col.pixel;
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.pix = pix;
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ sd->g_carr[d.d8.pix] = col; // update color array
+ if ( current_alloc_context == 0 )
+ sd->g_our_alloc[d.d8.pix] = TRUE; // reuse without XAllocColor
+ }
+ } else {
+ // No available colors, or we did not want to allocate one
+ int i;
+ sd->colors_avail = FALSE; // no more available colors
+ if ( sd->g_carr_fetch ) { // refetch color array
+ sd->g_carr_fetch = FALSE;
+ XQueryColors( dpy, TQPaintDevice::x11AppColormap( screen ), sd->g_carr,
+ sd->g_cells );
+ }
+ int mindist;
+ i = tqfind_nearest_color( r, g, b, &mindist, sd );
+
+ if ( mindist != 0 && !try_alloc ) {
+ // Not an exact match with an existing color
+ int rr = ((r+sd->col_div_r/2)/sd->col_div_r)*sd->col_div_r;
+ int rg = ((g+sd->col_div_g/2)/sd->col_div_g)*sd->col_div_g;
+ int rb = ((b+sd->col_div_b/2)/sd->col_div_b)*sd->col_div_b;
+ int rx = rr - r;
+ int gx = rg - g;
+ int bx = rb - b;
+ int dist = rx*rx + gx*gx + bx*bx; // calculate distance
+ if ( dist < mindist ) {
+ // reduced color is closer - try to alloc it
+ r = rr;
+ g = rg;
+ b = rb;
+ col.red = r << 8;
+ col.green = g << 8;
+ col.blue = b << 8;
+ try_alloc = TRUE;
+ try_again = TRUE;
+ sd->colors_avail = TRUE;
+ continue; // Try alloc reduced color
+ }
+ }
+
+ if ( i == -1 ) { // no nearest color?!
+ int unused, value;
+ hsv(&unused, &unused, &value);
+ if (value < 128) { // dark, use black
+ d.argb = tqRgb(0,0,0);
+ pix = (uint)BlackPixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ } else { // light, use white
+ d.argb = tqRgb(0xff,0xff,0xff);
+ pix = (uint)WhitePixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ }
+ return pix;
+ }
+ if ( sd->g_our_alloc[i] ) { // we've already allocated it
+ ; // i == g_carr[i].pixel
+ } else {
+ // Try to allocate existing color
+ col = sd->g_carr[i];
+ if ( XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ), &col) ) {
+ i = (uint)col.pixel;
+ sd->g_carr[i] = col; // update color array
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ if ( current_alloc_context == 0 )
+ sd->g_our_alloc[i] = TRUE; // only in the default context
+ }
+ } else {
+ // Oops, it's gone again
+ try_count++;
+ try_again = TRUE;
+ sd->colors_avail = TRUE;
+ sd->g_carr_fetch = TRUE;
+ }
+ }
+ if ( !try_again ) { // got it
+ pix = (uint)sd->g_carr[i].pixel;
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix; // allocated X11 color
+ }
+ }
+ }
+
+ } while ( try_again && try_count < 2 );
+
+ if ( try_again ) { // no hope of allocating color
+ int unused, value;
+ hsv(&unused, &unused, &value);
+ if (value < 128) { // dark, use black
+ d.argb = tqRgb(0,0,0);
+ pix = (uint)BlackPixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ } else { // light, use white
+ d.argb = tqRgb(0xff,0xff,0xff);
+ pix = (uint)WhitePixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ }
+ return pix;
+ }
+ // All colors outside context 0 must go into the dictionary
+ bool many = sd->colorDict->count() >= sd->colorDict->size() * 8;
+ if ( many && sd->colorDict->size() == col_std_dict ) {
+ sd->colorDict->resize( col_large_dict );
+ }
+ if ( !many || current_alloc_context != 0 ) {
+ c = new TQColorData; // insert into color dict
+ TQ_CHECK_PTR( c );
+ c->pix = pix;
+ c->context = current_alloc_context;
+ sd->colorDict->insert( (long)d.argb, c ); // store color in dict
+ }
+ return pix;
+}
+
+/*!
+ Allocates the RGB color and returns the pixel value.
+
+ Allocating a color means to obtain a pixel value from the RGB
+ specification. The pixel value is an index into the global color
+ table, but should be considered an arbitrary platform-dependent value.
+
+ The pixel() function calls alloc() if necessary, so in general you
+ don't need to call this function.
+
+ \sa enterAllocContext()
+*/
+// ### 4.0 - remove me?
+uint TQColor::alloc()
+{
+ return alloc( -1 );
+}
+
+#else // USE_QT4
+
+// NOT REVISED
+
+/*****************************************************************************
+ The color dictionary speeds up color allocation significantly for X11.
+ When there are no more colors, TQColor::alloc() will set the colors_avail
+ flag to FALSE and try to tqfind the nearest color.
+ NOTE: From deep within the event loop, the colors_avail flag is reset to
+ TRUE (calls the function qt_reset_color_avail()), because some other
+ application might free its colors, thereby making them available for
+ this TQt application.
+ *****************************************************************************/
+
+#include "tqintdict.h"
+
+struct TQColorData {
+ uint pix; // allocated pixel value
+ int context; // allocation context
+};
+
+typedef TQIntDict<TQColorData> TQColorDict;
+typedef TQIntDictIterator<TQColorData> TQColorDictIt;
+static int current_alloc_context = 0; // current color alloc context
+static const uint col_std_dict = 419;
+static const uint col_large_dict = 18397;
+
+class TQColorScreenData {
+public:
+ TQColorScreenData()
+ {
+ colorDict = 0;
+ colors_avail = TRUE;
+ g_vis = 0;
+ g_carr = 0;
+ g_carr_fetch = TRUE;
+ g_cells = 0;
+ g_our_alloc = 0;
+ color_reduce = FALSE;
+ }
+
+ TQColorDict *colorDict; // dict of allocated colors
+ bool colors_avail; // X colors available
+ bool g_truecolor; // truecolor visual
+ Visual *g_vis; // visual
+ XColor *g_carr; // color array
+ bool g_carr_fetch; // perform XQueryColors?
+ int g_cells; // number of entries in g_carr
+ bool *g_our_alloc; // our allocated colors
+ uint red_mask , green_mask , blue_mask;
+ int red_shift, green_shift, blue_shift;
+ bool color_reduce;
+ int col_div_r;
+ int col_div_g;
+ int col_div_b;
+};
+
+static int screencount = 0;
+static TQColorScreenData **screendata = 0; // array of screendata pointers
+
+
+/*
+ This function is called from the event loop. It resets the colors_avail
+ flag so that the application can retry to allocate read-only colors
+ that other applications may have deallocated lately.
+
+ The g_our_alloc and g_carr are global arrays that optimize color
+ approximation when there are no more colors left to allocate.
+*/
+
+void qt_reset_color_avail()
+{
+ int i;
+ for ( i = 0; i < screencount; i++ ) {
+ screendata[i]->colors_avail = TRUE;
+ screendata[i]->g_carr_fetch = TRUE; // do XQueryColors if !colors_avail
+ }
+}
+
+
+/*
+ Finds the nearest color.
+*/
+
+static int tqfind_nearest_color( int r, int g, int b, int* mindist_out,
+ TQColorScreenData *sd )
+{
+ int mincol = -1;
+ int mindist = 200000;
+ int rx, gx, bx, dist;
+ XColor *xc = &sd->g_carr[0];
+ for ( int i=0; i<sd->g_cells; i++ ) {
+ rx = r - (xc->red >> 8);
+ gx = g - (xc->green >> 8);
+ bx = b - (xc->blue>> 8);
+ dist = rx*rx + gx*gx + bx*bx; // calculate distance
+ if ( dist < mindist ) { // minimal?
+ mindist = dist;
+ mincol = i;
+ }
+ xc++;
+ }
+ *mindist_out = mindist;
+ return mincol;
+}
+
+
+/*****************************************************************************
+ TQColor misc internal functions
+ *****************************************************************************/
+
+static int highest_bit( uint v )
+{
+ int i;
+ uint b = (uint)1 << 31; // get pos of highest bit in v
+ for ( i=31; ((b & v) == 0) && i>=0; i-- )
+ b >>= 1;
+ return i;
+}
+
+
+/*****************************************************************************
+ TQColor static member functions
+ *****************************************************************************/
+
+/*!
+ Returns the maximum number of colors supported by the underlying
+ window system if the window system uses a palette.
+
+ Otherwise returns -1. Use numBitPlanes() to calculate the available
+ colors in that case.
+*/
+
+int TQColor::maxColors()
+{
+ Visual *visual = (Visual *) TQPaintDevice::x11AppVisual();
+ if (visual->c_class & 1)
+ return TQPaintDevice::x11AppCells();
+ return -1;
+}
+
+/*!
+ Returns the number of color bit planes for the underlying window
+ system.
+
+ The returned value is equal to the default pixmap depth.
+
+ \sa TQPixmap::defaultDepth()
+*/
+
+int TQColor::numBitPlanes()
+{
+ return TQPaintDevice::x11AppDepth();
+}
+
+
+/*!
+ Internal initialization required for TQColor.
+ This function is called from the TQApplication constructor.
+
+ \sa cleanup()
+*/
+
+void TQColor::initialize()
+{
+ static const int blackIdx = 2;
+ static const int whiteIdx = 3;
+
+ if ( color_init ) // already initialized
+ return;
+ color_init = TRUE;
+
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ int spec = TQApplication::colorSpec();
+
+ screencount = ScreenCount( dpy );
+ screendata = new TQColorScreenData*[ screencount ];
+
+ int scr;
+ for ( scr = 0; scr < screencount; ++scr ) {
+ screendata[scr] = new TQColorScreenData;
+ screendata[scr]->g_vis = (Visual *) TQPaintDevice::x11AppVisual( scr );
+ screendata[scr]->g_truecolor = screendata[scr]->g_vis->c_class == TrueColor
+ || screendata[scr]->g_vis->c_class == DirectColor;
+
+ int ncols = TQPaintDevice::x11AppCells( scr );
+
+ if ( screendata[scr]->g_truecolor ) {
+ if (scr == DefaultScreen(dpy))
+ colormodel = d32;
+ } else {
+ if (scr == DefaultScreen(dpy))
+ colormodel = d8;
+
+ // Create the g_our_alloc array, which remembers which color pixels
+ // we allocated.
+ screendata[scr]->g_cells = TQMIN(ncols,256);
+ screendata[scr]->g_carr = new XColor[screendata[scr]->g_cells];
+ TQ_CHECK_PTR( screendata[scr]->g_carr );
+ memset( screendata[scr]->g_carr, 0,
+ screendata[scr]->g_cells*sizeof(XColor) );
+ screendata[scr]->g_carr_fetch = TRUE; // run XQueryColors on demand
+ screendata[scr]->g_our_alloc = new bool[screendata[scr]->g_cells];
+ TQ_CHECK_PTR( screendata[scr]->g_our_alloc );
+ memset( screendata[scr]->g_our_alloc, FALSE,
+ screendata[scr]->g_cells*sizeof(bool) );
+ XColor *xc = &screendata[scr]->g_carr[0];
+ for ( int i=0; i<screendata[scr]->g_cells; i++ ) {
+ xc->pixel = i; // g_carr[i] = color i
+ xc++;
+ }
+ }
+
+ int dictsize;
+ if ( screendata[scr]->g_truecolor ) { // truecolor
+ dictsize = 1; // will not need color dict
+ screendata[scr]->red_mask = (uint)screendata[scr]->g_vis->red_mask;
+ screendata[scr]->green_mask = (uint)screendata[scr]->g_vis->green_mask;
+ screendata[scr]->blue_mask = (uint)screendata[scr]->g_vis->blue_mask;
+ screendata[scr]->red_shift =
+ highest_bit( screendata[scr]->red_mask ) - 7;
+ screendata[scr]->green_shift =
+ highest_bit( screendata[scr]->green_mask ) - 7;
+ screendata[scr]->blue_shift =
+ highest_bit( screendata[scr]->blue_mask ) - 7;
+ } else {
+ dictsize = col_std_dict;
+ }
+ screendata[scr]->colorDict = new TQColorDict(dictsize); // create dictionary
+ TQ_CHECK_PTR( screendata[scr]->colorDict );
+
+ if ( spec == (int)TQApplication::ManyColor ) {
+ screendata[scr]->color_reduce = TRUE;
+
+ switch ( qt_ncols_option ) {
+ case 216:
+ // 6:6:6
+ screendata[scr]->col_div_r = screendata[scr]->col_div_g =
+ screendata[scr]->col_div_b = (255/(6-1));
+ break;
+ default: {
+ // 2:3:1 proportions, solved numerically
+ if ( qt_ncols_option > 255 ) qt_ncols_option = 255;
+ if ( qt_ncols_option < 1 ) qt_ncols_option = 1;
+ int nr = 2;
+ int ng = 2;
+ int nb = 2;
+ for (;;) {
+ if ( nb*2 < nr && (nb+1)*nr*ng < qt_ncols_option )
+ nb++;
+ else if ( nr*3 < ng*2 && nb*(nr+1)*ng < qt_ncols_option )
+ nr++;
+ else if ( nb*nr*(ng+1) < qt_ncols_option )
+ ng++;
+ else break;
+ }
+ qt_ncols_option = nr*ng*nb;
+ screendata[scr]->col_div_r = (255/(nr-1));
+ screendata[scr]->col_div_g = (255/(ng-1));
+ screendata[scr]->col_div_b = (255/(nb-1));
+ }
+ }
+ }
+ }
+
+ scr = TQPaintDevice::x11AppScreen();
+
+ // Initialize global color objects
+ if ( TQPaintDevice::x11AppDefaultVisual(scr) &&
+ TQPaintDevice::x11AppDefaultColormap(scr) ) {
+ globalColors()[blackIdx].setPixel((uint) BlackPixel(dpy, scr));
+ globalColors()[whiteIdx].setPixel((uint) WhitePixel(dpy, scr));
+ } else {
+ globalColors()[blackIdx].alloc(scr);
+ globalColors()[whiteIdx].alloc(scr);
+ }
+
+#if 0 /* 0 == allocate colors on demand */
+ setLazyAlloc( FALSE ); // allocate global colors
+ ((TQColor*)(&darkGray))-> alloc();
+ ((TQColor*)(&gray))-> alloc();
+ ((TQColor*)(&lightGray))-> alloc();
+ ((TQColor*)(&::red))-> alloc();
+ ((TQColor*)(&::green))-> alloc();
+ ((TQColor*)(&::blue))-> alloc();
+ ((TQColor*)(&cyan))-> alloc();
+ ((TQColor*)(&magenta))-> alloc();
+ ((TQColor*)(&yellow))-> alloc();
+ ((TQColor*)(&darkRed))-> alloc();
+ ((TQColor*)(&darkGreen))-> alloc();
+ ((TQColor*)(&darkBlue))-> alloc();
+ ((TQColor*)(&darkCyan))-> alloc();
+ ((TQColor*)(&darkMagenta))-> alloc();
+ ((TQColor*)(&darkYellow))-> alloc();
+ setLazyAlloc( TRUE );
+#endif
+}
+
+/*!
+ Internal clean up required for TQColor.
+ This function is called from the TQApplication destructor.
+
+ \sa initialize()
+*/
+
+void TQColor::cleanup()
+{
+ if ( !color_init )
+ return;
+ color_init = FALSE;
+ int scr;
+ for ( scr = 0; scr < screencount; scr++ ) {
+ if ( screendata[scr]->g_carr ) {
+ delete [] screendata[scr]->g_carr;
+ screendata[scr]->g_carr = 0;
+ }
+ if ( screendata[scr]->g_our_alloc ) {
+ delete [] screendata[scr]->g_our_alloc;
+ screendata[scr]->g_our_alloc = 0;
+ }
+ if ( screendata[scr]->colorDict ) {
+ screendata[scr]->colorDict->setAutoDelete( TRUE );
+ screendata[scr]->colorDict->clear();
+ delete screendata[scr]->colorDict;
+ screendata[scr]->colorDict = 0;
+ }
+ delete screendata[scr];
+ screendata[scr] = 0;
+ }
+ delete [] screendata;
+ screendata = 0;
+ screencount = 0;
+}
+
+
+/*****************************************************************************
+ TQColor member functions
+ *****************************************************************************/
+
+/*!
+ \internal
+ Allocates the color on screen \a screen. Only used in X11.
+
+ \sa alloc(), pixel()
+*/
+uint TQColor::alloc( int screen )
+{
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ if ( screen < 0 )
+ screen = TQPaintDevice::x11AppScreen();
+ if ( !color_init )
+ return dpy ? (uint)BlackPixel(dpy, screen) : 0;
+ int r = tqRed(d.argb);
+ int g = tqGreen(d.argb);
+ int b = tqBlue(d.argb);
+ uint pix = 0;
+ TQColorScreenData *sd = screendata[screen];
+ if ( sd->g_truecolor ) { // truecolor: map to pixel
+ r = sd->red_shift > 0 ? r << sd->red_shift : r >> -sd->red_shift;
+ g = sd->green_shift > 0 ? g << sd->green_shift : g >> -sd->green_shift;
+ b = sd->blue_shift > 0 ? b << sd->blue_shift : b >> -sd->blue_shift;
+ pix = (b & sd->blue_mask) | (g & sd->green_mask) | (r & sd->red_mask)
+ | ~(sd->blue_mask | sd->green_mask | sd->red_mask);
+ if ( screen == TQPaintDevice::x11AppScreen() )
+ d.d32.pix = pix;
+ return pix;
+ }
+ TQColorData *c = sd->colorDict->tqfind( (long)(d.argb) );
+ if ( c ) { // found color in dictionary
+ pix = c->pix;
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE; // color ok
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix; // use same pixel value
+ if ( c->context != current_alloc_context ) {
+ c->context = 0; // convert to default context
+ sd->g_our_alloc[pix] = TRUE; // reuse without XAllocColor
+ }
+ }
+ return pix;
+ }
+
+ XColor col;
+ col.red = r << 8;
+ col.green = g << 8;
+ col.blue = b << 8;
+
+ bool try_again = FALSE;
+ bool try_alloc = !sd->color_reduce;
+ int try_count = 0;
+
+ do {
+ // This loop is run until we manage to either allocate or
+ // tqfind an approximate color, it stops after a few iterations.
+
+ try_again = FALSE;
+
+ if ( try_alloc && sd->colors_avail &&
+ XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ),&col) ) {
+ // We could allocate the color
+ pix = (uint) col.pixel;
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.pix = pix;
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ sd->g_carr[d.d8.pix] = col; // update color array
+ if ( current_alloc_context == 0 )
+ sd->g_our_alloc[d.d8.pix] = TRUE; // reuse without XAllocColor
+ }
+ } else {
+ // No available colors, or we did not want to allocate one
+ int i;
+ sd->colors_avail = FALSE; // no more available colors
+ if ( sd->g_carr_fetch ) { // refetch color array
+ sd->g_carr_fetch = FALSE;
+ XQueryColors( dpy, TQPaintDevice::x11AppColormap( screen ), sd->g_carr,
+ sd->g_cells );
+ }
+ int mindist;
+ i = tqfind_nearest_color( r, g, b, &mindist, sd );
+
+ if ( mindist != 0 && !try_alloc ) {
+ // Not an exact match with an existing color
+ int rr = ((r+sd->col_div_r/2)/sd->col_div_r)*sd->col_div_r;
+ int rg = ((g+sd->col_div_g/2)/sd->col_div_g)*sd->col_div_g;
+ int rb = ((b+sd->col_div_b/2)/sd->col_div_b)*sd->col_div_b;
+ int rx = rr - r;
+ int gx = rg - g;
+ int bx = rb - b;
+ int dist = rx*rx + gx*gx + bx*bx; // calculate distance
+ if ( dist < mindist ) {
+ // reduced color is closer - try to alloc it
+ r = rr;
+ g = rg;
+ b = rb;
+ col.red = r << 8;
+ col.green = g << 8;
+ col.blue = b << 8;
+ try_alloc = TRUE;
+ try_again = TRUE;
+ sd->colors_avail = TRUE;
+ continue; // Try alloc reduced color
+ }
+ }
+
+ if ( i == -1 ) { // no nearest color?!
+ int unused, value;
+ hsv(&unused, &unused, &value);
+ if (value < 128) { // dark, use black
+ d.argb = tqRgb(0,0,0);
+ pix = (uint)BlackPixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ } else { // light, use white
+ d.argb = tqRgb(0xff,0xff,0xff);
+ pix = (uint)WhitePixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ }
+ return pix;
+ }
+ if ( sd->g_our_alloc[i] ) { // we've already allocated it
+ ; // i == g_carr[i].pixel
+ } else {
+ // Try to allocate existing color
+ col = sd->g_carr[i];
+ if ( XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ), &col) ) {
+ i = (uint)col.pixel;
+ sd->g_carr[i] = col; // update color array
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ if ( current_alloc_context == 0 )
+ sd->g_our_alloc[i] = TRUE; // only in the default context
+ }
+ } else {
+ // Oops, it's gone again
+ try_count++;
+ try_again = TRUE;
+ sd->colors_avail = TRUE;
+ sd->g_carr_fetch = TRUE;
+ }
+ }
+ if ( !try_again ) { // got it
+ pix = (uint)sd->g_carr[i].pixel;
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix; // allocated X11 color
+ }
+ }
+ }
+
+ } while ( try_again && try_count < 2 );
+
+ if ( try_again ) { // no hope of allocating color
+ int unused, value;
+ hsv(&unused, &unused, &value);
+ if (value < 128) { // dark, use black
+ d.argb = tqRgb(0,0,0);
+ pix = (uint)BlackPixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ } else { // light, use white
+ d.argb = tqRgb(0xff,0xff,0xff);
+ pix = (uint)WhitePixel( dpy, screen );
+ if ( screen == TQPaintDevice::x11AppScreen() ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = FALSE;
+ d.d8.pix = pix;
+ }
+ }
+ return pix;
+ }
+ // All colors outside context 0 must go into the dictionary
+ bool many = sd->colorDict->count() >= sd->colorDict->size() * 8;
+ if ( many && sd->colorDict->size() == col_std_dict ) {
+ sd->colorDict->resize( col_large_dict );
+ }
+ if ( !many || current_alloc_context != 0 ) {
+ c = new TQColorData; // insert into color dict
+ TQ_CHECK_PTR( c );
+ c->pix = pix;
+ c->context = current_alloc_context;
+ sd->colorDict->insert( (long)d.argb, c ); // store color in dict
+ }
+ return pix;
+}
+
+/*!
+ Allocates the RGB color and returns the pixel value.
+
+ Allocating a color means to obtain a pixel value from the RGB
+ specification. The pixel value is an index into the global color
+ table, but should be considered an arbitrary platform-dependent value.
+
+ The pixel() function calls alloc() if necessary, so in general you
+ don't need to call this function.
+
+ \sa enterAllocContext()
+*/
+// ### 4.0 - remove me?
+uint TQColor::alloc()
+{
+ return alloc( -1 );
+}
+
+/*!
+ \overload
+
+ Returns the pixel value for screen \a screen.
+
+ This value is used by the underlying window system to refer to a color.
+ It can be thought of as an index into the display hardware's color table,
+ but the value is an arbitrary 32-bit value.
+
+ \sa alloc()
+*/
+uint TQColor::pixel( int screen ) const
+{
+ if (screen != TQPaintDevice::x11AppScreen() &&
+ // don't allocate color0 or color1, they have fixed pixel
+ // values for all screens
+ d.argb != tqRgba(255, 255, 255, 1) && d.argb != tqRgba(0, 0, 0, 1))
+ return ((TQColor*)this)->alloc( screen );
+ return pixel();
+}
+
+
+void TQColor::setSystemNamedColor( const TQString& name )
+{
+ // setSystemNamedColor should look up rgb values from the built in
+ // color tables first (see qcolor_p.cpp), and failing that, use
+ // the window system's interface for translating names to rgb values...
+ // we do this so that things like uic can load an XPM file with named colors
+ // and convert it to a png without having to use window system functions...
+ d.argb = qt_get_rgb_val( name.latin1() );
+ TQRgb rgb;
+ if ( qt_get_named_rgb( name.latin1(), &rgb ) ) {
+ setRgb( tqRed(rgb), tqGreen(rgb), tqBlue(rgb) );
+ if ( colormodel == d8 ) {
+ d.d8.invalid = FALSE;
+ d.d8.dirty = TRUE;
+ d.d8.pix = 0;
+ } else {
+ alloc();
+ }
+ } else if ( !color_init ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQColor::setSystemNamedColor: Cannot perform this operation "
+ "because TQApplication does not exist" );
+#endif
+ // set color to invalid
+ *this = TQColor();
+ } else {
+ XColor col, hw_col;
+ if ( XLookupColor(TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppColormap(), name.latin1(),
+ &col, &hw_col) ) {
+ setRgb( col.red>>8, col.green>>8, col.blue>>8 );
+ } else {
+ // set color to invalid
+ *this = TQColor();
+ }
+ }
+}
+
+
+#define MAX_CONTEXTS 16
+static int context_stack[MAX_CONTEXTS];
+static int context_ptr = 0;
+
+static void init_context_stack()
+{
+ static bool did_init = FALSE;
+ if ( !did_init ) {
+ did_init = TRUE;
+ context_stack[0] = current_alloc_context = 0;
+ }
+}
+
+
+/*!
+ Enters a color allocation context and returns a non-zero unique
+ identifier.
+
+ Color allocation contexts are useful for programs that need to
+ allocate many colors and throw them away later, like image
+ viewers. The allocation context functions work for true color
+ displays as well as for colormap displays, except that
+ TQColor::destroyAllocContext() does nothing for true color.
+
+ Example:
+ \code
+ TQPixmap loadPixmap( TQString fileName )
+ {
+ static int alloc_context = 0;
+ if ( alloc_context )
+ TQColor::destroyAllocContext( alloc_context );
+ alloc_context = TQColor::enterAllocContext();
+ TQPixmap pm( fileName );
+ TQColor::leaveAllocContext();
+ return pm;
+ }
+ \endcode
+
+ The example code loads a pixmap from file. It frees up all colors
+ that were allocated the last time loadPixmap() was called.
+
+ The initial/default context is 0. TQt keeps a list of colors
+ associated with their allocation contexts. You can call
+ destroyAllocContext() to get rid of all colors that were allocated
+ in a specific context.
+
+ Calling enterAllocContext() enters an allocation context. The
+ allocation context lasts until you call leaveAllocContext().
+ TQColor has an internal stack of allocation contexts. Each call to
+ enterAllocContex() must have a corresponding leaveAllocContext().
+
+ \code
+ // context 0 active
+ int c1 = TQColor::enterAllocContext(); // enter context c1
+ // context c1 active
+ int c2 = TQColor::enterAllocContext(); // enter context c2
+ // context c2 active
+ TQColor::leaveAllocContext(); // leave context c2
+ // context c1 active
+ TQColor::leaveAllocContext(); // leave context c1
+ // context 0 active
+ // Now, free all colors that were allocated in context c2
+ TQColor::destroyAllocContext( c2 );
+ \endcode
+
+ You may also want to set the application's color specification.
+ See TQApplication::setColorSpec() for more information.
+
+ \sa leaveAllocContext(), currentAllocContext(), destroyAllocContext(),
+ TQApplication::setColorSpec()
+*/
+
+int TQColor::enterAllocContext()
+{
+ static int context_seq_no = 0;
+ init_context_stack();
+ if ( context_ptr+1 == MAX_CONTEXTS ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQColor::enterAllocContext: Context stack overflow" );
+#endif
+ return 0;
+ }
+ current_alloc_context = context_stack[++context_ptr] = ++context_seq_no;
+ return current_alloc_context;
+}
+
+
+/*!
+ Leaves a color allocation context.
+
+ See enterAllocContext() for a detailed explanation.
+
+ \sa enterAllocContext(), currentAllocContext()
+*/
+
+void TQColor::leaveAllocContext()
+{
+ init_context_stack();
+ if ( context_ptr == 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQColor::leaveAllocContext: Context stack underflow" );
+#endif
+ return;
+ }
+ current_alloc_context = context_stack[--context_ptr];
+}
+
+
+/*!
+ Returns the current color allocation context.
+
+ The default context is 0.
+
+ \sa enterAllocContext(), leaveAllocContext()
+*/
+
+int TQColor::currentAllocContext()
+{
+ return current_alloc_context;
+}
+
+
+/*!
+ Destroys a color allocation context, \e context.
+
+ This function deallocates all colors that were allocated in the
+ specified \a context. If \a context == -1, it frees up all colors
+ that the application has allocated. If \a context == -2, it frees
+ up all colors that the application has allocated, except those in
+ the default context.
+
+ The function does nothing for true color displays.
+
+ \sa enterAllocContext(), alloc()
+*/
+
+void TQColor::destroyAllocContext( int context )
+{
+ init_context_stack();
+ if ( !color_init )
+ return;
+
+ int screen;
+ for ( screen = 0; screen < screencount; ++screen ) {
+ if ( screendata[screen]->g_truecolor )
+ continue;
+
+ ulong pixels[256];
+ bool freeing[256];
+ memset( freeing, FALSE, screendata[screen]->g_cells*sizeof(bool) );
+ TQColorData *d;
+ TQColorDictIt it( *screendata[screen]->colorDict );
+ int i = 0;
+ uint rgbv;
+ while ( (d=it.current()) ) {
+ rgbv = (uint)it.currentKey();
+ if ( (d->context || context==-1) &&
+ (d->context == context || context < 0) ) {
+ if ( !screendata[screen]->g_our_alloc[d->pix] && !freeing[d->pix] ) {
+ // will free this color
+ pixels[i++] = d->pix;
+ freeing[d->pix] = TRUE;
+ }
+ // remove from dict
+ screendata[screen]->colorDict->remove( (long)rgbv );
+ }
+ ++it;
+ }
+ if ( i )
+ XFreeColors( TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppColormap( screen ),
+ pixels, i, 0 );
+ }
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqconnection.cpp b/tqtinterface/qt4/src/kernel/tqconnection.cpp
new file mode 100644
index 0000000..adffe1b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqconnection.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Implementation of TQConnection class
+**
+** Created : 930417
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqconnection.h"
+
+/*! \class TQConnection tqconnection.h
+ \brief The TQConnection class is an internal class, used in the signal/slot mechanism.
+
+ \internal
+
+ Do not use this class directly in application programs.
+
+ TQObject has a list of TQConnection for each signal that is connected to the
+ outside world.
+*/
+
+TQConnection::TQConnection( const TQObject *object, int member,
+ const char *memberName, int memberType )
+{
+ obj = (TQObject *)object;
+ mbr = member;
+ mbr_name = memberName;
+ mbr_type = memberType;
+ nargs = 0;
+ if ( strstr(memberName,"()") == 0 ) {
+ const char *p = memberName;
+ nargs++;
+ while ( *p ) {
+ if ( *p++ == ',' )
+ nargs++;
+ }
+ }
+}
+
+/*!
+ \fn TQConnection::~TQConnection()
+*/
+
+/*!
+ \fn bool TQConnection::isConnected() const
+*/
+
+/*!
+ \fn TQObject *TQConnection::object() const
+*/
+
+/*!
+ \fn int TQConnection::member() const
+*/
+
+/*!
+ \fn const char *TQConnection::memberName() const
+*/
+
+/*!
+ \fn int TQConnection::numArgs() const
+*/
diff --git a/tqtinterface/qt4/src/kernel/tqconnection.h b/tqtinterface/qt4/src/kernel/tqconnection.h
new file mode 100644
index 0000000..fb62ca8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqconnection.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Definition of TQConnection class
+**
+** Created : 930417
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQCONNECTION_H
+#define TQCONNECTION_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+class TQ_EXPORT TQConnection
+{
+public:
+ TQConnection( const TQObject *, int, const char *memberName, int memberType );
+ ~TQConnection() {}
+
+ bool isConnected() const { return obj != 0; }
+
+ TQObject *object() const { return obj; } // get object/member pointer
+ int member() const { return mbr; }
+ const char *memberName() const { return mbr_name; }
+ int memberType() const { return mbr_type; }
+ int numArgs() const { return nargs; }
+
+private:
+ TQObject *obj; // object connected to
+ int mbr; // member connected to
+ const char *mbr_name;
+ int mbr_type;
+ int nargs;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQConnection( const TQConnection & );
+ TQConnection &operator=( const TQConnection & );
+#endif
+};
+
+#define TQ_DEFINED_TQCONNECTION
+#include "tqwinexport.h"
+#endif // TQCONNECTION_H
diff --git a/tqtinterface/qt4/src/kernel/tqcursor.cpp b/tqtinterface/qt4/src/kernel/tqcursor.cpp
new file mode 100644
index 0000000..16e74cf
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcursor.cpp
@@ -0,0 +1,292 @@
+/****************************************************************************
+**
+** Implementation of TQCursor class
+**
+** Created : 940220
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqcursor.h"
+
+#ifndef TQT_NO_CURSOR
+
+#include "tqbitmap.h"
+#include "tqimage.h"
+#include "tqdatastream.h"
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ \class TQCursor tqcursor.h
+
+ \brief The TQCursor class provides a mouse cursor with an arbitrary
+ tqshape.
+
+ \ingroup appearance
+ \ingroup shared
+
+ This class is mainly used to create mouse cursors that are
+ associated with particular widgets and to get and set the position
+ of the mouse cursor.
+
+ TQt has a number of standard cursor tqshapes, but you can also make
+ custom cursor tqshapes based on a TQBitmap, a tqmask and a hotspot.
+
+ To associate a cursor with a widget, use TQWidget::setCursor(). To
+ associate a cursor with all widgets (normally for a short period
+ of time), use TQApplication::setOverrideCursor().
+
+ To set a cursor tqshape use TQCursor::setShape() or use the TQCursor
+ constructor which takes the tqshape as argument, or you can use one
+ of the predefined cursors defined in the \l tqCursorShape enum.
+
+ If you want to create a cursor with your own bitmap, either use
+ the TQCursor constructor which takes a bitmap and a tqmask or the
+ constructor which takes a pixmap as arguments.
+
+ To set or get the position of the mouse cursor use the static
+ methods TQCursor::pos() and TQCursor::setPos().
+
+ \img cursors.png Cursor Shapes
+
+ \sa TQWidget \link guibooks.html#fowler GUI Design Handbook:
+ Cursors\endlink
+
+ On X11, TQt supports the \link
+ http://www.xfree86.org/4.3.0/Xcursor.3.html Xcursor\endlink
+ library, which allows for full color icon themes. The table below
+ shows the cursor name used for each TQt::tqCursorShape value. If a
+ cursor cannot be found using the name shown below, a standard X11
+ cursor will be used instead. Note: X11 does not provide
+ appropriate cursors for all possible TQt::tqCursorShape values. It
+ is possible that some cursors will be taken from the Xcursor
+ theme, while others will use an internal bitmap cursor.
+
+ \table
+ \header \i TQt::tqCursorShape Values \i Cursor Names
+ \row \i TQt::ArrowCursor \i left_ptr
+ \row \i TQt::UpArrowCursor \i up_arrow
+ \row \i TQt::CrossCursor \i cross
+ \row \i TQt::WaitCursor \i wait
+ \row \i TQt::BusyCursor \i left_ptr_watch
+ \row \i TQt::IbeamCursor \i ibeam
+ \row \i TQt::SizeVerCursor \i size_ver
+ \row \i TQt::SizeHorCursor \i size_hor
+ \row \i TQt::SizeBDiagCursor \i size_bdiag
+ \row \i TQt::SizeFDiagCursor \i size_fdiag
+ \row \i TQt::SizeAllCursor \i size_all
+ \row \i TQt::SplitVCursor \i split_v
+ \row \i TQt::SplitHCursor \i split_h
+ \row \i TQt::PointingHandCursor \i pointing_hand
+ \row \i TQt::ForbiddenCursor \i forbidden
+ \row \i TQt::WhatsThisCursor \i whats_this
+ \endtable
+*/
+
+/*!
+ \enum TQt::tqCursorShape
+
+ This enum type defines the various cursors that can be used.
+
+ \value ArrowCursor standard arrow cursor
+ \value UpArrowCursor upwards arrow
+ \value CrossCursor crosshair
+ \value WaitCursor hourglass/watch
+ \value BusyCursor standard arrow with hourglass/watch
+ \value IbeamCursor ibeam/text entry
+ \value SizeVerCursor vertical resize
+ \value SizeHorCursor horizontal resize
+ \value SizeFDiagCursor diagonal resize (\)
+ \value SizeBDiagCursor diagonal resize (/)
+ \value SizeAllCursor all directions resize
+ \value BlankCursor blank/invisible cursor
+ \value SplitVCursor vertical splitting
+ \value SplitHCursor horizontal splitting
+ \value PointingHandCursor a pointing hand
+ \value ForbiddenCursor a slashed circle
+ \value WhatsThisCursor an arrow with a question mark
+ \value BitmapCursor
+
+ ArrowCursor is the default for widgets in a normal state.
+
+ \img cursors.png Cursor Shapes
+*/
+
+/*****************************************************************************
+ TQCursor stream functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_DATASTREAM
+
+
+/*!
+ \relates TQCursor
+ Writes the cursor \a c to the stream \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQCursor &c )
+{
+ s << (TQ_INT16)c.tqshape(); // write tqshape id to stream
+ if ( c.tqshape() == TQt::BitmapCursor ) { // bitmap cursor
+#if !defined(TQT_NO_IMAGEIO)
+ s << *c.bitmap() << *c.tqmask();
+ s << c.hotSpot();
+#else
+ qWarning("No Image Cursor I/O");
+#endif
+ }
+ return s;
+}
+
+/*!
+ \relates TQCursor
+ Reads a cursor from the stream \a s and sets \a c to the read data.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQCursor &c )
+{
+ TQ_INT16 tqshape;
+ s >> tqshape; // read tqshape id from stream
+ if ( tqshape == TQt::BitmapCursor ) { // read bitmap cursor
+#if !defined(TQT_NO_IMAGEIO)
+ TQBitmap bm, bmm;
+ TQPoint hot;
+ s >> bm >> bmm >> hot;
+ c = TQCursor( bm, bmm, hot.x(), hot.y() );
+#else
+ qWarning("No Image Cursor I/O");
+#endif
+ } else {
+ c.setShape( (int)tqshape ); // create cursor with tqshape
+ }
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+
+
+/*!
+ Constructs a custom pixmap cursor.
+
+ \a pixmap is the image. It is usual to give it a tqmask (set using
+ TQPixmap::setMask()). \a hotX and \a hotY define the cursor's hot
+ spot.
+
+ If \a hotX is negative, it is set to the \c{pixmap().width()/2}.
+ If \a hotY is negative, it is set to the \c{pixmap().height()/2}.
+
+ Valid cursor sizes depend on the display hardware (or the
+ underlying window system). We recommend using 32x32 cursors,
+ because this size is supported on all platforms. Some platforms
+ also support 16x16, 48x48 and 64x64 cursors.
+
+ Currently, only black-and-white pixmaps can be used.
+
+ \sa TQPixmap::TQPixmap(), TQPixmap::setMask()
+*/
+
+TQCursor::TQCursor( const TQPixmap &pixmap, int hotX, int hotY )
+{
+ TQImage img = pixmap.convertToImage().
+ convertDepth( 8, TQt::ThresholdDither|TQt::AvoidDither );
+ TQBitmap bm;
+ bm.convertFromImage( img, TQt::ThresholdDither|TQt::AvoidDither );
+ TQBitmap bmm;
+ if ( bm.tqmask() ) {
+ bmm = *bm.tqmask();
+ TQBitmap nullBm;
+ bm.setMask( nullBm );
+ }
+ else if ( pixmap.tqmask() ) {
+ TQImage mimg = pixmap.tqmask()->convertToImage().
+ convertDepth( 8, TQt::ThresholdDither|TQt::AvoidDither );
+ bmm.convertFromImage( mimg, TQt::ThresholdDither|TQt::AvoidDither );
+ }
+ else {
+ bmm.resize( bm.size() );
+ bmm.fill( TQt::color1 );
+ }
+
+ setBitmap(bm,bmm,hotX,hotY);
+}
+
+
+
+/*!
+ Constructs a custom bitmap cursor.
+
+ \a bitmap and
+ \a tqmask make up the bitmap.
+ \a hotX and
+ \a hotY define the cursor's hot spot.
+
+ If \a hotX is negative, it is set to the \c{bitmap().width()/2}.
+ If \a hotY is negative, it is set to the \c{bitmap().height()/2}.
+
+ The cursor \a bitmap (B) and \a tqmask (M) bits are combined like this:
+ \list
+ \i B=1 and M=1 gives black.
+ \i B=0 and M=1 gives white.
+ \i B=0 and M=0 gives transtqparent.
+ \i B=1 and M=0 gives an undefined result.
+ \endlist
+
+ Use the global TQt color \c color0 to draw 0-pixels and \c color1 to
+ draw 1-pixels in the bitmaps.
+
+ Valid cursor sizes depend on the display hardware (or the
+ underlying window system). We recommend using 32x32 cursors,
+ because this size is supported on all platforms. Some platforms
+ also support 16x16, 48x48 and 64x64 cursors.
+
+ \sa TQBitmap::TQBitmap(), TQBitmap::setMask()
+*/
+
+TQCursor::TQCursor( const TQBitmap &bitmap, const TQBitmap &tqmask,
+ int hotX, int hotY )
+{
+ setBitmap(bitmap,tqmask,hotX,hotY);
+}
+
+#endif // USE_QT4
+
+#endif // TQT_NO_CURSOR
+
+
diff --git a/tqtinterface/qt4/src/kernel/tqcursor.h b/tqtinterface/qt4/src/kernel/tqcursor.h
new file mode 100644
index 0000000..9aa6437
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcursor.h
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Definition of TQCursor class
+**
+** Created : 940219
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQCURSOR_H
+#define TQCURSOR_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpoint.h"
+#include "tqshared.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qcursor.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+struct TQCursorData;
+
+class TQ_EXPORT TQCursor : public QCursor, virtual public TQt
+{
+public:
+ TQCursor() : QCursor() {}
+ TQCursor( int tqshape ) : QCursor( tqshape ) {}
+ TQCursor( Qt::CursorShape shape ) : QCursor( shape ) {}
+ TQCursor( const QBitmap &bitmap, const QBitmap &tqmask, int hotX=-1, int hotY=-1 ) : QCursor( bitmap, tqmask, hotX, hotY ) {}
+ TQCursor( const QPixmap &pixmap, int hotX=-1, int hotY=-1 ) : QCursor( pixmap, hotX, hotY ) {}
+ TQCursor( const QCursor & c ) : QCursor( c ) {}
+
+ inline int tqshape() const { return shape(); }
+
+ static void initialize();
+ static void cleanup();
+
+private:
+ TQCursorData *data;
+};
+
+#else // USE_QT4
+
+/*
+ ### The fake cursor has to go first with old qdoc.
+*/
+#ifdef TQT_NO_CURSOR
+
+class TQ_EXPORT TQCursor : public TQt
+{
+public:
+ static TQPoint pos();
+ static void setPos( int x, int y );
+ static void setPos( const TQPoint & );
+private:
+ TQCursor();
+};
+
+#endif // TQT_NO_CURSOR
+
+#ifndef TQT_NO_CURSOR
+
+struct TQCursorData;
+
+
+class TQ_EXPORT TQCursor : public TQt
+{
+public:
+ TQCursor(); // create default arrow cursor
+ TQCursor( int tqshape );
+ TQCursor( const TQBitmap &bitmap, const TQBitmap &tqmask,
+ int hotX=-1, int hotY=-1 );
+ TQCursor( const TQPixmap &pixmap,
+ int hotX=-1, int hotY=-1 );
+ TQCursor( const TQCursor & );
+ ~TQCursor();
+ TQCursor &operator=( const TQCursor & );
+
+ int tqshape() const;
+ void setShape( int );
+
+ const TQBitmap *bitmap() const;
+ const TQBitmap *tqmask() const;
+ TQPoint hotSpot() const;
+
+#if defined(TQ_WS_WIN)
+ HCURSOR handle() const;
+ TQCursor( HCURSOR );
+#elif defined(TQ_WS_X11)
+ HANDLE handle() const;
+ TQCursor( HANDLE );
+#elif defined(TQ_WS_MAC)
+ HANDLE handle() const;
+#elif defined(TQ_WS_TQWS)
+ HANDLE handle() const;
+#endif
+
+ static TQPoint pos();
+ static void setPos( int x, int y );
+ static void setPos( const TQPoint & );
+
+ static void initialize();
+ static void cleanup();
+
+#if defined(TQ_WS_X11)
+ static int x11Screen();
+#endif
+private:
+ void setBitmap( const TQBitmap &bitmap, const TQBitmap &tqmask,
+ int hotX, int hotY );
+ void update() const;
+ TQCursorData *data;
+ TQCursor *tqfind_cur(int);
+#if defined(TQ_WS_MAC)
+ friend void qt_mac_set_cursor(const TQCursor *c, const Point *p);
+#endif
+};
+
+
+#if !defined(TQT_CLEAN_NAMESPACE)
+// tqCursorShape is defined in X11/X.h
+#ifdef tqCursorShape
+#define X_tqCursorShape tqCursorShape
+#undef tqCursorShape
+#endif
+typedef TQt::tqCursorShape TQtqCursorShape;
+#ifdef X_tqCursorShape
+#define tqCursorShape X_tqCursorShape
+#endif
+#endif
+
+
+/*****************************************************************************
+ TQCursor stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQCursor & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQCursor & );
+#endif
+#endif // TQT_NO_CURSOR
+
+
+inline void TQCursor::setPos( const TQPoint &p )
+{
+ setPos( p.x(), p.y() );
+}
+
+#endif // USE_QT4
+
+#endif // TQCURSOR_H \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqcursor_x11.cpp b/tqtinterface/qt4/src/kernel/tqcursor_x11.cpp
new file mode 100644
index 0000000..36f2504
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqcursor_x11.cpp
@@ -0,0 +1,1013 @@
+/****************************************************************************
+**
+** Implementation of TQCursor class for X11
+**
+** Created : 940219
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqcursor.h"
+#include "tqbitmap.h"
+#include "tqimage.h"
+#include "tqapplication.h"
+#include "tqdatastream.h"
+#include "tqnamespace.h"
+#include "tqt_x11_p.h"
+#include <X11/cursorfont.h>
+
+#ifndef TQT_NO_XCURSOR
+# include <X11/Xcursor/Xcursor.h>
+#endif // TQT_NO_XCURSOR
+
+#ifdef USE_QT4
+
+/*****************************************************************************
+ Global cursors
+ *****************************************************************************/
+
+static TQCursor cursorTable[TQt::LastCursor+1];
+
+static const int arrowCursorIdx = 0;
+
+TQT_STATIC_CONST_IMPL TQCursor & TQt::arrowCursor = cursorTable[0];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::upArrowCursor = cursorTable[1];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::crossCursor = cursorTable[2];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::waitCursor = cursorTable[3];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::ibeamCursor = cursorTable[4];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeVerCursor = cursorTable[5];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeHorCursor = cursorTable[6];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeBDiagCursor = cursorTable[7];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeFDiagCursor = cursorTable[8];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeAllCursor = cursorTable[9];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::blankCursor = cursorTable[10];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::splitVCursor = cursorTable[11];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::splitHCursor = cursorTable[12];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::pointingHandCursor = cursorTable[13];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::forbiddenCursor = cursorTable[14];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::whatsThisCursor = cursorTable[15];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::busyCursor = cursorTable[16];
+
+// TQT_STATIC_CONST TQCursor & arrowCursor = Qt::ArrowCursor;
+// TQT_STATIC_CONST TQCursor & upArrowCursor = Qt::UpArrowCursor;
+// TQT_STATIC_CONST TQCursor & crossCursor = Qt::CrossCursor;
+// TQT_STATIC_CONST TQCursor & waitCursor = Qt::WaitCursor;
+// TQT_STATIC_CONST TQCursor & ibeamCursor = Qt::IBeamCursor;
+// TQT_STATIC_CONST TQCursor & sizeVerCursor = Qt::SizeVerCursor;
+// TQT_STATIC_CONST TQCursor & sizeHorCursor = Qt::SizeHorCursor;
+// TQT_STATIC_CONST TQCursor & sizeBDiagCursor = Qt::SizeBDiagCursor;
+// TQT_STATIC_CONST TQCursor & sizeFDiagCursor = Qt::SizeFDiagCursor;
+// TQT_STATIC_CONST TQCursor & sizeAllCursor = Qt::SizeAllCursor;
+// TQT_STATIC_CONST TQCursor & blankCursor = Qt::BlankCursor;
+// TQT_STATIC_CONST TQCursor & splitVCursor = Qt::SplitVCursor;
+// TQT_STATIC_CONST TQCursor & splitHCursor = Qt::SplitHCursor;
+// TQT_STATIC_CONST TQCursor & pointingHandCursor = Qt::PointingHandCursor;
+// TQT_STATIC_CONST TQCursor & forbiddenCursor = Qt::ForbiddenCursor;
+// TQT_STATIC_CONST TQCursor & whatsThisCursor = Qt::WhatsThisCursor;
+// TQT_STATIC_CONST TQCursor & busyCursor = Qt::BusyCursor;
+
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::arrowCursor = Qt::ArrowCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::upArrowCursor = Qt::UpArrowCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::crossCursor = Qt::CrossCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::waitCursor = Qt::WaitCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::ibeamCursor = Qt::IBeamCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeVerCursor = Qt::SizeVerCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeHorCursor = Qt::SizeHorCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeBDiagCursor = Qt::SizeBDiagCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeFDiagCursor = Qt::SizeFDiagCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeAllCursor = Qt::SizeAllCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::blankCursor = Qt::BlankCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::splitVCursor = Qt::SplitVCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::splitHCursor = Qt::SplitHCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::pointingHandCursor = Qt::PointingHandCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::forbiddenCursor = Qt::ForbiddenCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::whatsThisCursor = Qt::WhatsThisCursor;
+// TQT_STATIC_CONST_IMPL TQCursor & TQt::busyCursor = Qt::BusyCursor;
+
+/*****************************************************************************
+ Internal TQCursorData class
+ *****************************************************************************/
+
+// struct TQCursorData : public TQShared
+// {
+// TQCursorData( int s = 0 );
+// ~TQCursorData();
+// int ctqshape;
+// TQBitmap *bm, *bmm;
+// short hx, hy;
+// XColor fg,bg;
+// Cursor hcurs;
+// Pixmap pm, pmm;
+// };
+//
+// TQCursorData::TQCursorData( int s )
+// {
+// ctqshape = s;
+// hcurs = 0;
+// bm = bmm = 0;
+// hx = hy = 0;
+// pm = pmm = 0;
+// }
+
+// TQCursorData::~TQCursorData()
+// {
+// Display *dpy = TQPaintDevice::x11AppDisplay();
+//
+// // Add in checking for the display too as on HP-UX
+// // we seem to get a core dump as the cursor data is
+// // deleted again from main() on exit...
+// if ( hcurs && dpy )
+// XFreeCursor( dpy, hcurs );
+// if ( pm && dpy )
+// XFreePixmap( dpy, pm );
+// if ( pmm && dpy )
+// XFreePixmap( dpy, pmm );
+// delete bm;
+// delete bmm;
+// }
+
+static bool initialized = FALSE;
+
+/*!
+ Internal function that deinitializes the predefined cursors.
+ This function is called from the TQApplication destructor.
+
+ \sa initialize()
+*/
+void TQCursor::cleanup()
+{
+ if ( !initialized )
+ return;
+
+// int tqshape;
+// for( tqshape = 0; tqshape <= LastCursor; tqshape++ ) {
+// if ( cursorTable[tqshape].data && cursorTable[tqshape].data->deref() )
+// delete cursorTable[tqshape].data;
+// cursorTable[tqshape].data = 0;
+// }
+
+ initialized = FALSE;
+}
+
+
+/*!
+ Internal function that initializes the predefined cursors.
+ This function is called from the TQApplication constructor.
+
+ \sa cleanup()
+*/
+
+void TQCursor::initialize()
+{
+// int tqshape;
+// for( tqshape = 0; tqshape <= LastCursor; tqshape++ )
+// cursorTable[tqshape].data = new TQCursorData( tqshape );
+// initialized = TRUE;
+// qAddPostRoutine( cleanup );
+
+ int tqshape;
+ for( tqshape = 0; tqshape <= TQt::LastCursor; tqshape++ ) {
+ switch(tqshape) {
+ case 0: new(&cursorTable[tqshape]) TQCursor(Qt::ArrowCursor); break;
+ case 1: new(&cursorTable[tqshape]) TQCursor(Qt::UpArrowCursor); break;
+ case 2: new(&cursorTable[tqshape]) TQCursor(Qt::CrossCursor); break;
+ case 3: new(&cursorTable[tqshape]) TQCursor(Qt::WaitCursor); break;
+ case 4: new(&cursorTable[tqshape]) TQCursor(Qt::IBeamCursor); break;
+ case 5: new(&cursorTable[tqshape]) TQCursor(Qt::SizeVerCursor); break;
+ case 6: new(&cursorTable[tqshape]) TQCursor(Qt::SizeHorCursor); break;
+ case 7: new(&cursorTable[tqshape]) TQCursor(Qt::SizeBDiagCursor); break;
+ case 8: new(&cursorTable[tqshape]) TQCursor(Qt::SizeFDiagCursor); break;
+ case 9: new(&cursorTable[tqshape]) TQCursor(Qt::SizeAllCursor); break;
+ case 10: new(&cursorTable[tqshape]) TQCursor(Qt::BlankCursor); break;
+ case 11: new(&cursorTable[tqshape]) TQCursor(Qt::SplitVCursor); break;
+ case 12: new(&cursorTable[tqshape]) TQCursor(Qt::SplitHCursor); break;
+ case 13: new(&cursorTable[tqshape]) TQCursor(Qt::PointingHandCursor); break;
+ case 14: new(&cursorTable[tqshape]) TQCursor(Qt::ForbiddenCursor); break;
+ case 15: new(&cursorTable[tqshape]) TQCursor(Qt::WhatsThisCursor); break;
+ case 16: new(&cursorTable[tqshape]) TQCursor(Qt::BusyCursor); break;
+ case 17: new(&cursorTable[tqshape]) TQCursor(Qt::OpenHandCursor); break;
+ case 18: new(&cursorTable[tqshape]) TQCursor(Qt::ClosedHandCursor); break;
+ case 19: new(&cursorTable[tqshape]) TQCursor(Qt::DragCopyCursor); break;
+ case 20: new(&cursorTable[tqshape]) TQCursor(Qt::DragMoveCursor); break;
+ case 21: new(&cursorTable[tqshape]) TQCursor(Qt::DragLinkCursor); break;
+ }
+ }
+ initialized = TRUE;
+ qAddPostRoutine( cleanup );
+}
+
+#else // USE_QT4
+
+// Define TQT_USE_APPROXIMATE_CURSORS when compiling if you REALLY want to
+// use the ugly X11 cursors.
+
+/*****************************************************************************
+ Internal TQCursorData class
+ *****************************************************************************/
+
+struct TQCursorData : public TQShared
+{
+ TQCursorData( int s = 0 );
+ ~TQCursorData();
+ int ctqshape;
+ TQBitmap *bm, *bmm;
+ short hx, hy;
+ XColor fg,bg;
+ Cursor hcurs;
+ Pixmap pm, pmm;
+};
+
+TQCursorData::TQCursorData( int s )
+{
+ ctqshape = s;
+ hcurs = 0;
+ bm = bmm = 0;
+ hx = hy = 0;
+ pm = pmm = 0;
+}
+
+TQCursorData::~TQCursorData()
+{
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+
+ // Add in checking for the display too as on HP-UX
+ // we seem to get a core dump as the cursor data is
+ // deleted again from main() on exit...
+ if ( hcurs && dpy )
+ XFreeCursor( dpy, hcurs );
+ if ( pm && dpy )
+ XFreePixmap( dpy, pm );
+ if ( pmm && dpy )
+ XFreePixmap( dpy, pmm );
+ delete bm;
+ delete bmm;
+}
+
+
+/*****************************************************************************
+ Global cursors
+ *****************************************************************************/
+
+static TQCursor cursorTable[TQt::LastCursor+1];
+
+static const int arrowCursorIdx = 0;
+
+TQT_STATIC_CONST_IMPL TQCursor & TQt::arrowCursor = cursorTable[0];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::upArrowCursor = cursorTable[1];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::crossCursor = cursorTable[2];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::waitCursor = cursorTable[3];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::ibeamCursor = cursorTable[4];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeVerCursor = cursorTable[5];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeHorCursor = cursorTable[6];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeBDiagCursor = cursorTable[7];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeFDiagCursor = cursorTable[8];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::sizeAllCursor = cursorTable[9];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::blankCursor = cursorTable[10];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::splitVCursor = cursorTable[11];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::splitHCursor = cursorTable[12];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::pointingHandCursor = cursorTable[13];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::forbiddenCursor = cursorTable[14];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::whatsThisCursor = cursorTable[15];
+TQT_STATIC_CONST_IMPL TQCursor & TQt::busyCursor = cursorTable[16];
+
+
+TQCursor *TQCursor::tqfind_cur( int tqshape ) // tqfind predefined cursor
+{
+ return (uint)tqshape <= LastCursor ? &cursorTable[tqshape] : 0;
+}
+
+
+static bool initialized = FALSE;
+
+/*!
+ Internal function that deinitializes the predefined cursors.
+ This function is called from the TQApplication destructor.
+
+ \sa initialize()
+*/
+void TQCursor::cleanup()
+{
+ if ( !initialized )
+ return;
+
+ int tqshape;
+ for( tqshape = 0; tqshape <= LastCursor; tqshape++ ) {
+ if ( cursorTable[tqshape].data && cursorTable[tqshape].data->deref() )
+ delete cursorTable[tqshape].data;
+ cursorTable[tqshape].data = 0;
+ }
+ initialized = FALSE;
+}
+
+
+/*!
+ Internal function that initializes the predefined cursors.
+ This function is called from the TQApplication constructor.
+
+ \sa cleanup()
+*/
+
+void TQCursor::initialize()
+{
+ int tqshape;
+ for( tqshape = 0; tqshape <= LastCursor; tqshape++ )
+ cursorTable[tqshape].data = new TQCursorData( tqshape );
+ initialized = TRUE;
+ qAddPostRoutine( cleanup );
+}
+
+
+/*!
+ Constructs a cursor with the default arrow tqshape.
+*/
+TQCursor::TQCursor()
+{
+ if ( !initialized ) {
+ if ( tqApp->startingUp() ) {
+ data = 0;
+ return;
+ }
+ initialize();
+ }
+ TQCursor* c = &cursorTable[arrowCursorIdx];
+ c->data->ref();
+ data = c->data;
+}
+
+
+
+/*!
+ Constructs a cursor with the specified \a tqshape.
+
+ See \l tqCursorShape for a list of tqshapes.
+
+ \sa setShape()
+*/
+
+TQCursor::TQCursor( int tqshape )
+{
+ if ( !initialized )
+ initialize();
+ TQCursor *c = tqfind_cur( tqshape );
+ if ( !c ) // not found
+ c = &cursorTable[arrowCursorIdx]; // then use arrowCursor
+ c->data->ref();
+ data = c->data;
+}
+
+/*!
+ Constructs a cursor from the window system cursor \a cursor.
+
+ \warning Using this function is not portable. This function is only
+ available on X11 and Windows.
+*/
+TQCursor::TQCursor( HANDLE cursor )
+{
+ if ( !initialized )
+ initialize();
+
+ data = new TQCursorData;
+ TQ_CHECK_PTR( data );
+ data->hcurs = cursor;
+}
+
+
+
+void TQCursor::setBitmap( const TQBitmap &bitmap, const TQBitmap &tqmask,
+ int hotX, int hotY )
+{
+ if ( !initialized )
+ initialize();
+ if ( bitmap.depth() != 1 || tqmask.depth() != 1 ||
+ bitmap.size() != tqmask.size() ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQCursor: Cannot create bitmap cursor; invalid bitmap(s)" );
+#endif
+ TQCursor *c = &cursorTable[arrowCursorIdx];
+ c->data->ref();
+ data = c->data;
+ return;
+ }
+ data = new TQCursorData;
+ TQ_CHECK_PTR( data );
+ data->bm = new TQBitmap( bitmap );
+ data->bmm = new TQBitmap( tqmask );
+ data->hcurs = 0;
+ data->ctqshape = BitmapCursor;
+ data->hx = hotX >= 0 ? hotX : bitmap.width()/2;
+ data->hy = hotY >= 0 ? hotY : bitmap.height()/2;
+ data->fg.red = 0 << 8;
+ data->fg.green = 0 << 8;
+ data->fg.blue = 0 << 8;
+ data->bg.red = 255 << 8;
+ data->bg.green = 255 << 8;
+ data->bg.blue = 255 << 8;
+ update(); // Xcursor's backward compatibility hack needs the cursor to be created
+ // right after the bitmaps are created and filled with data
+}
+
+
+/*!
+ Constructs a copy of the cursor \a c.
+*/
+
+TQCursor::TQCursor( const TQCursor &c )
+{
+ if ( !initialized )
+ initialize();
+ data = c.data; // shallow copy
+ data->ref();
+}
+
+/*!
+ Destroys the cursor.
+*/
+
+TQCursor::~TQCursor()
+{
+ if ( data && data->deref() )
+ delete data;
+}
+
+
+/*!
+ Assigns \a c to this cursor and returns a reference to this
+ cursor.
+*/
+
+TQCursor &TQCursor::operator=( const TQCursor &c )
+{
+ if ( !initialized )
+ initialize();
+ c.data->ref(); // avoid c = c
+ if ( data->deref() )
+ delete data;
+ data = c.data;
+ return *this;
+}
+
+
+/*!
+ Returns the cursor tqshape identifier. The return value is one of
+ the \l tqCursorShape enum values (cast to an int).
+
+ \sa setShape()
+*/
+
+int TQCursor::tqshape() const
+{
+ if ( !initialized )
+ initialize();
+ return data->ctqshape;
+}
+
+/*!
+ Sets the cursor to the tqshape identified by \a tqshape.
+
+ See \l tqCursorShape for the list of cursor tqshapes.
+
+ \sa tqshape()
+*/
+
+void TQCursor::setShape( int tqshape )
+{
+ if ( !initialized )
+ initialize();
+ TQCursor *c = tqfind_cur( tqshape ); // tqfind one of the global ones
+ if ( !c ) // not found
+ c = &cursorTable[arrowCursorIdx]; // then use arrowCursor
+ c->data->ref();
+ if ( data->deref() ) // make shallow copy
+ delete data;
+ data = c->data;
+}
+
+
+/*!
+ Returns the cursor bitmap, or 0 if it is one of the standard
+ cursors.
+*/
+const TQBitmap *TQCursor::bitmap() const
+{
+ if ( !initialized )
+ initialize();
+ return data->bm;
+}
+
+/*!
+ Returns the cursor bitmap tqmask, or 0 if it is one of the standard
+ cursors.
+*/
+
+const TQBitmap *TQCursor::tqmask() const
+{
+ if ( !initialized )
+ initialize();
+ return data->bmm;
+}
+
+/*!
+ Returns the cursor hot spot, or (0, 0) if it is one of the
+ standard cursors.
+*/
+
+TQPoint TQCursor::hotSpot() const
+{
+ if ( !initialized )
+ initialize();
+ return TQPoint( data->hx, data->hy );
+}
+
+
+/*!
+ Returns the window system cursor handle.
+
+ \warning
+ Portable in principle, but if you use it you are probably about to
+ do something non-portable. Be careful.
+*/
+
+TQt::HANDLE TQCursor::handle() const
+{
+ if ( !initialized )
+ initialize();
+ if ( !data->hcurs )
+ update();
+ return data->hcurs;
+}
+
+/*!
+ \fn TQCursor::TQCursor( HCURSOR handle )
+
+ Creates a cursor with the specified window system handle \a
+ handle.
+
+ \warning
+ Portable in principle, but if you use it you are probably about to
+ do something non-portable. Be careful.
+*/
+
+/*!
+ Returns the position of the cursor (hot spot) in global screen
+ coordinates.
+
+ You can call TQWidget::mapFromGlobal() to translate it to widget
+ coordinates.
+
+ \sa setPos(), TQWidget::mapFromGlobal(), TQWidget::mapToGlobal()
+*/
+TQPoint TQCursor::pos()
+{
+ Window root;
+ Window child;
+ int root_x, root_y, win_x, win_y;
+ uint buttons;
+ Display* dpy = TQPaintDevice::x11AppDisplay();
+ for ( int i = 0; i < ScreenCount( dpy ); i++ ) {
+ if ( XQueryPointer( dpy, TQPaintDevice::x11AppRootWindow( i ), &root, &child,
+ &root_x, &root_y, &win_x, &win_y, &buttons ) )
+
+ return TQPoint( root_x, root_y );
+ }
+ return TQPoint();
+}
+
+/*! \internal
+*/
+int TQCursor::x11Screen()
+{
+ Window root;
+ Window child;
+ int root_x, root_y, win_x, win_y;
+ uint buttons;
+ Display* dpy = TQPaintDevice::x11AppDisplay();
+ for ( int i = 0; i < ScreenCount( dpy ); i++ ) {
+ if ( XQueryPointer( dpy, TQPaintDevice::x11AppRootWindow( i ), &root, &child,
+ &root_x, &root_y, &win_x, &win_y, &buttons ) )
+ return i;
+ }
+ return -1;
+}
+
+/*!
+ Moves the cursor (hot spot) to the global screen position (\a x,
+ \a y).
+
+ You can call TQWidget::mapToGlobal() to translate widget
+ coordinates to global screen coordinates.
+
+ \sa pos(), TQWidget::mapFromGlobal(), TQWidget::mapToGlobal()
+*/
+
+void TQCursor::setPos( int x, int y )
+{
+ TQPoint current, target(x, y);
+
+ // this is copied from pos(), since we need the screen number for the correct
+ // root window in the XWarpPointer call
+ Window root;
+ Window child;
+ int root_x, root_y, win_x, win_y;
+ uint buttons;
+ Display* dpy = TQPaintDevice::x11AppDisplay();
+ int screen;
+ for ( screen = 0; screen < ScreenCount( dpy ); screen++ ) {
+ if ( XQueryPointer( dpy, TQPaintDevice::x11AppRootWindow( screen ), &root, &child,
+ &root_x, &root_y, &win_x, &win_y, &buttons ) ) {
+ current = TQPoint( root_x, root_y );
+ break;
+ }
+ }
+
+ if ( screen >= ScreenCount( dpy ) )
+ return;
+
+ // Need to check, since some X servers generate null mouse move
+ // events, causing looping in applications which call setPos() on
+ // every mouse move event.
+ //
+ if ( current == target )
+ return;
+
+ XWarpPointer( TQPaintDevice::x11AppDisplay(), None,
+ TQPaintDevice::x11AppRootWindow( screen ),
+ 0, 0, 0, 0, x, y );
+}
+
+/*!
+ \overload void TQCursor::setPos ( const TQPoint & )
+*/
+
+
+/*!
+ \internal
+
+ Creates the cursor.
+*/
+
+void TQCursor::update() const
+{
+ if ( !initialized )
+ initialize();
+ register TQCursorData *d = data; // cheat const!
+ if ( d->hcurs ) // already loaded
+ return;
+
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ Window rootwin = TQPaintDevice::x11AppRootWindow();
+
+ if ( d->ctqshape == BitmapCursor ) {
+ d->hcurs = XCreatePixmapCursor( dpy, d->bm->handle(), d->bmm->handle(),
+ &d->fg, &d->bg, d->hx, d->hy );
+ return;
+ }
+
+#ifndef TQT_NO_XCURSOR
+ static const char *cursorNames[] = {
+ "left_ptr",
+ "up_arrow",
+ "cross",
+ "wait",
+ "ibeam",
+ "size_ver",
+ "size_hor",
+ "size_bdiag",
+ "size_fdiag",
+ "size_all",
+ "blank",
+ "split_v",
+ "split_h",
+ "pointing_hand",
+ "forbidden",
+ "whats_this",
+ "left_ptr_watch"
+ };
+
+ d->hcurs = XcursorLibraryLoadCursor( dpy, cursorNames[d->ctqshape] );
+ if ( d->hcurs )
+ return;
+#endif // TQT_NO_XCURSOR
+
+ static uchar cur_blank_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+ // Non-standard X11 cursors are created from bitmaps
+
+#ifndef TQT_USE_APPROXIMATE_CURSORS
+ static const uchar cur_ver_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
+ 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xf0, 0x0f,
+ 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 };
+ static const uchar mcur_ver_bits[] = {
+ 0x00, 0x00, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f,
+ 0xfc, 0x7f, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xfc, 0x7f, 0xf8, 0x3f,
+ 0xf0, 0x1f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03 };
+ static const uchar cur_hor_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x30, 0x18,
+ 0x38, 0x38, 0xfc, 0x7f, 0xfc, 0x7f, 0x38, 0x38, 0x30, 0x18, 0x20, 0x08,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar mcur_hor_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x60, 0x0c, 0x70, 0x1c, 0x78, 0x3c,
+ 0xfc, 0x7f, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfc, 0x7f, 0x78, 0x3c,
+ 0x70, 0x1c, 0x60, 0x0c, 0x40, 0x04, 0x00, 0x00 };
+ static const uchar cur_bdiag_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e,
+ 0x00, 0x37, 0x88, 0x23, 0xd8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0xf8, 0x00,
+ 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar mcur_bdiag_bits[] = {
+ 0x00, 0x00, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7f, 0x00, 0x7e, 0x04, 0x7f,
+ 0x8c, 0x7f, 0xdc, 0x77, 0xfc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01,
+ 0xfc, 0x03, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar cur_fdiag_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00,
+ 0xf8, 0x00, 0xd8, 0x01, 0x88, 0x23, 0x00, 0x37, 0x00, 0x3e, 0x00, 0x3c,
+ 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar mcur_fdiag_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00,
+ 0xfc, 0x41, 0xfc, 0x63, 0xdc, 0x77, 0x8c, 0x7f, 0x04, 0x7f, 0x00, 0x7e,
+ 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x7f, 0x00, 0x00 };
+ static const uchar *cursor_bits16[] = {
+ cur_ver_bits, mcur_ver_bits, cur_hor_bits, mcur_hor_bits,
+ cur_bdiag_bits, mcur_bdiag_bits, cur_fdiag_bits, mcur_fdiag_bits,
+ 0, 0, cur_blank_bits, cur_blank_bits };
+
+ static const uchar vsplit_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00,
+ 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
+ 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
+ 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
+ 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
+ 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar vsplitm_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
+ 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
+ 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
+ 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
+ 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
+ 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
+ 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00,
+ 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar hsplit_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
+ 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
+ 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03,
+ 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00,
+ 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
+ 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar hsplitm_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
+ 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00,
+ 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
+ 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00,
+ 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
+ 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar whatsthis_bits[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0xf0, 0x07, 0x00,
+ 0x09, 0x18, 0x0e, 0x00, 0x11, 0x1c, 0x0e, 0x00, 0x21, 0x1c, 0x0e, 0x00,
+ 0x41, 0x1c, 0x0e, 0x00, 0x81, 0x1c, 0x0e, 0x00, 0x01, 0x01, 0x07, 0x00,
+ 0x01, 0x82, 0x03, 0x00, 0xc1, 0xc7, 0x01, 0x00, 0x49, 0xc0, 0x01, 0x00,
+ 0x95, 0xc0, 0x01, 0x00, 0x93, 0xc0, 0x01, 0x00, 0x21, 0x01, 0x00, 0x00,
+ 0x20, 0xc1, 0x01, 0x00, 0x40, 0xc2, 0x01, 0x00, 0x40, 0x02, 0x00, 0x00,
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
+ static const uchar whatsthism_bits[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x07, 0x00, 0x07, 0xf8, 0x0f, 0x00,
+ 0x0f, 0xfc, 0x1f, 0x00, 0x1f, 0x3e, 0x1f, 0x00, 0x3f, 0x3e, 0x1f, 0x00,
+ 0x7f, 0x3e, 0x1f, 0x00, 0xff, 0x3e, 0x1f, 0x00, 0xff, 0x9d, 0x0f, 0x00,
+ 0xff, 0xc3, 0x07, 0x00, 0xff, 0xe7, 0x03, 0x00, 0x7f, 0xe0, 0x03, 0x00,
+ 0xf7, 0xe0, 0x03, 0x00, 0xf3, 0xe0, 0x03, 0x00, 0xe1, 0xe1, 0x03, 0x00,
+ 0xe0, 0xe1, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00,
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
+ static const uchar busy_bits[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
+ 0x09, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
+ 0x41, 0xe0, 0xff, 0x00, 0x81, 0x20, 0x80, 0x00, 0x01, 0xe1, 0xff, 0x00,
+ 0x01, 0x42, 0x40, 0x00, 0xc1, 0x47, 0x40, 0x00, 0x49, 0x40, 0x55, 0x00,
+ 0x95, 0x80, 0x2a, 0x00, 0x93, 0x00, 0x15, 0x00, 0x21, 0x01, 0x0a, 0x00,
+ 0x20, 0x01, 0x11, 0x00, 0x40, 0x82, 0x20, 0x00, 0x40, 0x42, 0x44, 0x00,
+ 0x80, 0x41, 0x4a, 0x00, 0x00, 0x40, 0x55, 0x00, 0x00, 0xe0, 0xff, 0x00,
+ 0x00, 0x20, 0x80, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ static const uchar busym_bits[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
+ 0x0f, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
+ 0x7f, 0xe0, 0xff, 0x00, 0xff, 0xe0, 0xff, 0x00, 0xff, 0xe1, 0xff, 0x00,
+ 0xff, 0xc3, 0x7f, 0x00, 0xff, 0xc7, 0x7f, 0x00, 0x7f, 0xc0, 0x7f, 0x00,
+ 0xf7, 0x80, 0x3f, 0x00, 0xf3, 0x00, 0x1f, 0x00, 0xe1, 0x01, 0x0e, 0x00,
+ 0xe0, 0x01, 0x1f, 0x00, 0xc0, 0x83, 0x3f, 0x00, 0xc0, 0xc3, 0x7f, 0x00,
+ 0x80, 0xc1, 0x7f, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0xe0, 0xff, 0x00,
+ 0x00, 0xe0, 0xff, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ static const uchar * const cursor_bits32[] = {
+ vsplit_bits, vsplitm_bits, hsplit_bits, hsplitm_bits,
+ 0, 0, 0, 0, whatsthis_bits, whatsthism_bits, busy_bits, busym_bits
+ };
+
+ static const uchar forbidden_bits[] = {
+ 0x00,0x00,0x00,0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xf0,0x00,0x38,0xc0,0x01,
+ 0x7c,0x80,0x03,0xec,0x00,0x03,0xce,0x01,0x07,0x86,0x03,0x06,0x06,0x07,0x06,
+ 0x06,0x0e,0x06,0x06,0x1c,0x06,0x0e,0x38,0x07,0x0c,0x70,0x03,0x1c,0xe0,0x03,
+ 0x38,0xc0,0x01,0xf0,0xe0,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00,0x00,0x00,0x00 };
+
+ static const unsigned char forbiddenm_bits[] = {
+ 0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xff,0x00,0xf8,0xff,0x01,0xfc,0xf0,0x03,
+ 0xfe,0xc0,0x07,0xfe,0x81,0x07,0xff,0x83,0x0f,0xcf,0x07,0x0f,0x8f,0x0f,0x0f,
+ 0x0f,0x1f,0x0f,0x0f,0x3e,0x0f,0x1f,0xfc,0x0f,0x1e,0xf8,0x07,0x3e,0xf0,0x07,
+ 0xfc,0xe0,0x03,0xf8,0xff,0x01,0xf0,0xff,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00};
+
+ static const uchar * const cursor_bits20[] = {
+ forbidden_bits, forbiddenm_bits
+ };
+
+ if ( d->ctqshape >= SizeVerCursor && d->ctqshape < SizeAllCursor ||
+ d->ctqshape == BlankCursor ) {
+ XColor bg, fg;
+ bg.red = 255 << 8;
+ bg.green = 255 << 8;
+ bg.blue = 255 << 8;
+ fg.red = 0;
+ fg.green = 0;
+ fg.blue = 0;
+ int i = (d->ctqshape - SizeVerCursor)*2;
+ d->pm = XCreateBitmapFromData( dpy, rootwin, (char *)cursor_bits16[i],
+ 16, 16 );
+ d->pmm = XCreateBitmapFromData( dpy, rootwin, (char *)cursor_bits16[i+1],
+ 16,16);
+ d->hcurs = XCreatePixmapCursor( dpy, d->pm, d->pmm, &fg, &bg, 8, 8 );
+ return;
+ }
+ if ( ( d->ctqshape >= SplitVCursor && d->ctqshape <= SplitHCursor ) ||
+ d->ctqshape == WhatsThisCursor || d->ctqshape == BusyCursor ) {
+ XColor bg, fg;
+ bg.red = 255 << 8;
+ bg.green = 255 << 8;
+ bg.blue = 255 << 8;
+ fg.red = 0;
+ fg.green = 0;
+ fg.blue = 0;
+ int i = (d->ctqshape - SplitVCursor)*2;
+ d->pm = XCreateBitmapFromData( dpy, rootwin, (char *)cursor_bits32[i],
+ 32, 32 );
+ d->pmm = XCreateBitmapFromData( dpy, rootwin, (char *)cursor_bits32[i+1],
+ 32, 32);
+ int hs = ( d->ctqshape == PointingHandCursor ||
+ d->ctqshape == WhatsThisCursor ||
+ d->ctqshape == BusyCursor ) ? 0 : 16;
+ d->hcurs = XCreatePixmapCursor( dpy, d->pm, d->pmm, &fg, &bg, hs, hs );
+ return;
+ }
+ if ( d->ctqshape == ForbiddenCursor ) {
+ XColor bg, fg;
+ bg.red = 255 << 8;
+ bg.green = 255 << 8;
+ bg.blue = 255 << 8;
+ fg.red = 0;
+ fg.green = 0;
+ fg.blue = 0;
+ int i = (d->ctqshape - ForbiddenCursor)*2;
+ d->pm = XCreateBitmapFromData( dpy, rootwin, (char *)cursor_bits20[i],
+ 20, 20 );
+ d->pmm = XCreateBitmapFromData( dpy, rootwin, (char *)cursor_bits20[i+1],
+ 20, 20);
+ d->hcurs = XCreatePixmapCursor( dpy, d->pm, d->pmm, &fg, &bg, 10, 10 );
+ return;
+ }
+#endif /* ! TQT_USE_APPROXIMATE_CURSORS */
+
+ uint sh;
+ switch ( d->ctqshape ) { // map Q cursor to X cursor
+ case ArrowCursor:
+ sh = XC_left_ptr;
+ break;
+ case UpArrowCursor:
+ sh = XC_center_ptr;
+ break;
+ case CrossCursor:
+ sh = XC_crosshair;
+ break;
+ case WaitCursor:
+ sh = XC_watch;
+ break;
+ case IbeamCursor:
+ sh = XC_xterm;
+ break;
+ case SizeAllCursor:
+ sh = XC_fleur;
+ break;
+ case PointingHandCursor:
+ sh = XC_hand2;
+ break;
+#ifdef TQT_USE_APPROXIMATE_CURSORS
+ case SizeBDiagCursor:
+ sh = XC_top_right_corner;
+ break;
+ case SizeFDiagCursor:
+ sh = XC_bottom_right_corner;
+ break;
+ case BlankCursor:
+ XColor bg, fg;
+ bg.red = 255 << 8;
+ bg.green = 255 << 8;
+ bg.blue = 255 << 8;
+ fg.red = 0;
+ fg.green = 0;
+ fg.blue = 0;
+ d->pm = XCreateBitmapFromData( dpy, rootwin,
+ (char *)cur_blank_bits, 16, 16 );
+ d->pmm = XCreateBitmapFromData( dpy, rootwin,
+ (char *)cur_blank_bits, 16,16);
+ d->hcurs = XCreatePixmapCursor( dpy, d->pm, d->pmm, &fg,
+ &bg, 8, 8 );
+ return;
+ break;
+ case SizeVerCursor:
+ case SplitVCursor:
+ sh = XC_sb_v_double_arrow;
+ break;
+ case SizeHorCursor:
+ case SplitHCursor:
+ sh = XC_sb_h_double_arrow;
+ break;
+ case WhatsThisCursor:
+ sh = XC_question_arrow;
+ break;
+ case ForbiddenCursor:
+ sh = XC_circle;
+ break;
+ case BusyCursor:
+ sh = XC_watch;
+ break;
+#endif /* TQT_USE_APPROXIMATE_CURSORS */
+ default:
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQCursor::update: Invalid cursor tqshape %d", d->ctqshape );
+#endif
+ return;
+ }
+ d->hcurs = XCreateFontCursor( dpy, sh );
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqdesktopwidget.h b/tqtinterface/qt4/src/kernel/tqdesktopwidget.h
new file mode 100644
index 0000000..d91a189
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdesktopwidget.h
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Definition of TQDesktopWidget class.
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQDESKTOPWIDGET_H
+#define TQDESKTOPWIDGET_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwidget.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qdesktopwidget.h>
+
+#endif // USE_QT4
+
+class TQApplication;
+class TQDesktopWidgetPrivate; /* Don't touch! */
+
+#ifdef TQT_THREAD_SUPPORT
+class TQMutex;
+#endif // TQT_THREAD_SUPPORT
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQDesktopWidget : public QDesktopWidget, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQDesktopWidget( void ) : QDesktopWidget() {
+ TQT_TQWIDGET_INDEPENDENT_REQUIRED_INITIALIZATION
+ TQT_TQOBJECT_REQUIRED_INITIALIZATION()
+ }
+
+ inline const TQRect tqgeometry() const { return TQT_TQRECT_OBJECT(geometry()); }
+
+ Display * x11Display( void ) { return this->x11Info().display(); }
+ int x11Screen( void ) { return this->x11Info().screen(); }
+
+public Q_SLOTS:
+ void tqt_handle_qt_destroyed(QObject* obj) { emit destroyed(TQT_TQOBJECT(obj)); }
+
+Q_SIGNALS:
+ void destroyed( TQObject* obj );
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQDesktopWidget : public TQWidget
+{
+ TQ_OBJECT
+public:
+ TQDesktopWidget();
+ ~TQDesktopWidget();
+
+ bool isVirtualDesktop() const;
+
+ int numScreens() const;
+ int primaryScreen() const;
+
+ int screenNumber( TQWidget *widget = 0 ) const; // ### 4.0: const TQWidget*
+ int screenNumber( const TQPoint & ) const;
+
+ TQWidget *screen( int screen = -1 );
+
+ const TQRect& screenGeometry( int screen = -1 ) const;
+ const TQRect& screenGeometry( TQWidget *widget ) const
+ { return screenGeometry( screenNumber( widget ) ); }
+ const TQRect& screenGeometry( const TQPoint &point ) const
+ { return screenGeometry( screenNumber( point ) ); }
+
+ const TQRect& availableGeometry( int screen = -1 ) const;
+ const TQRect& availableGeometry( TQWidget *widget ) const
+ { return availableGeometry( screenNumber( widget ) ); }
+ const TQRect& availableGeometry( const TQPoint &point ) const
+ { return availableGeometry( screenNumber( point ) ); }
+
+ void insertChild( TQObject * );
+
+Q_SIGNALS:
+ void resized( int );
+ void workAreaResized( int );
+
+protected:
+ void resizeEvent( TQResizeEvent *e );
+
+private:
+ TQDesktopWidgetPrivate *d;
+
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQDesktopWidget( const TQDesktopWidget & );
+ TQDesktopWidget &operator=( const TQDesktopWidget & );
+#endif
+
+ friend class TQApplication;
+#ifdef TQ_WS_TQWS
+ friend class TQWSDisplay;
+#endif
+};
+
+#endif // USE_QT4
+
+#endif //TQDESKTOPWIDGET_H
diff --git a/tqtinterface/qt4/src/kernel/tqdesktopwidget_x11.cpp b/tqtinterface/qt4/src/kernel/tqdesktopwidget_x11.cpp
new file mode 100644
index 0000000..e2bd9f9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdesktopwidget_x11.cpp
@@ -0,0 +1,335 @@
+/****************************************************************************
+**
+** Implementation of TQDesktopWidget class.
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqdesktopwidget.h"
+#include "tqapplication.h"
+#include "tqobjectlist.h"
+#include "tqt_x11_p.h"
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+// defined in qwidget_x11.cpp
+extern int qt_x11_create_desktop_on_screen;
+
+// defined in qapplication_x11.cpp
+extern Atom qt_net_workarea;
+extern bool qt_net_supports(Atom atom);
+
+// function to update the workarea of the screen
+static bool qt_desktopwidget_workarea_dirty = TRUE;
+void qt_desktopwidget_update_workarea()
+{
+ qt_desktopwidget_workarea_dirty = TRUE;
+}
+
+
+class TQSingleDesktopWidget : public TQWidget
+{
+public:
+ TQSingleDesktopWidget();
+ ~TQSingleDesktopWidget();
+};
+
+TQSingleDesktopWidget::TQSingleDesktopWidget()
+ : TQWidget( 0, "desktop", WType_Desktop )
+{
+}
+
+TQSingleDesktopWidget::~TQSingleDesktopWidget()
+{
+ while ( !childrenListObject().isEmpty() )
+ removeChild( childrenListObject().getFirst() );
+}
+
+
+class TQDesktopWidgetPrivate
+{
+public:
+ TQDesktopWidgetPrivate();
+ ~TQDesktopWidgetPrivate();
+
+ void init();
+
+ bool use_xinerama;
+ int defaultScreen;
+ int screenCount;
+
+ TQWidget **screens;
+ TQRect *rects;
+ TQRect *workareas;
+};
+
+TQDesktopWidgetPrivate::TQDesktopWidgetPrivate()
+ : use_xinerama(FALSE), defaultScreen(0), screenCount(1),
+ screens( 0 ), rects( 0 ), workareas( 0 )
+{
+}
+
+TQDesktopWidgetPrivate::~TQDesktopWidgetPrivate()
+{
+ if ( screens ) {
+ for ( int i = 0; i < screenCount; ++i ) {
+ if (i == defaultScreen) continue;
+ delete screens[i];
+ screens[i] = 0;
+ }
+
+ delete [] screens;
+ }
+
+ if ( rects ) delete [] rects;
+ if ( workareas ) delete [] workareas;
+}
+
+void TQDesktopWidgetPrivate::init()
+{
+ // get the screen count
+#ifndef TQT_NO_XINERAMA
+ XineramaScreenInfo *xinerama_screeninfo = 0;
+ int unused;
+ use_xinerama = (XineramaQueryExtension(TQPaintDevice::x11AppDisplay(),
+ &unused, &unused) &&
+ XineramaIsActive(TQPaintDevice::x11AppDisplay()));
+
+ if (use_xinerama) {
+ xinerama_screeninfo =
+ XineramaQueryScreens(TQPaintDevice::x11AppDisplay(), &screenCount);
+ defaultScreen = 0;
+ } else
+#endif // TQT_NO_XINERAMA
+ {
+ defaultScreen = DefaultScreen(TQPaintDevice::x11AppDisplay());
+ screenCount = ScreenCount(TQPaintDevice::x11AppDisplay());
+ }
+
+ delete [] rects;
+ rects = new TQRect[ screenCount ];
+ delete [] workareas;
+ workareas = new TQRect[ screenCount ];
+
+ // get the tqgeometry of each screen
+ int i, x, y, w, h;
+ for ( i = 0; i < screenCount; i++ ) {
+
+#ifndef TQT_NO_XINERAMA
+ if (use_xinerama) {
+ x = xinerama_screeninfo[i].x_org;
+ y = xinerama_screeninfo[i].y_org;
+ w = xinerama_screeninfo[i].width;
+ h = xinerama_screeninfo[i].height;
+ } else
+#endif // TQT_NO_XINERAMA
+ {
+ x = 0;
+ y = 0;
+ w = WidthOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), i));
+ h = HeightOfScreen(ScreenOfDisplay(TQPaintDevice::x11AppDisplay(), i));
+ }
+
+ rects[i].setRect(x, y, w, h);
+ workareas[i] = TQRect();
+ }
+
+#ifndef TQT_NO_XINERAMA
+ if (xinerama_screeninfo)
+ XFree(xinerama_screeninfo);
+#endif // TQT_NO_XINERAMA
+
+}
+
+// the TQDesktopWidget itself will be created on the default screen
+// as qt_x11_create_desktop_on_screen defaults to -1
+TQDesktopWidget::TQDesktopWidget()
+ : TQWidget( 0, "desktop", WType_Desktop )
+{
+ d = new TQDesktopWidgetPrivate();
+
+ /*
+ we don't call d->init() here, since the initial resize event
+ will end up calling init() a second time, which is inefficient.
+ instead, for the sending of all posted event to the desktop
+ widget (including the initial resize event, which calls
+ d->init()).
+ */
+ TQApplication::sendPostedEvents( this, 0 );
+}
+
+TQDesktopWidget::~TQDesktopWidget()
+{
+ delete d;
+}
+
+bool TQDesktopWidget::isVirtualDesktop() const
+{
+ return d->use_xinerama;
+}
+
+int TQDesktopWidget::primaryScreen() const
+{
+ return d->defaultScreen;
+}
+
+int TQDesktopWidget::numScreens() const
+{
+ return d->screenCount;
+}
+
+TQWidget *TQDesktopWidget::screen( int screen )
+{
+ if (d->use_xinerama)
+ return this;
+
+ if ( screen < 0 || screen >= d->screenCount )
+ screen = d->defaultScreen;
+
+ if ( ! d->screens ) {
+ d->screens = new TQWidget*[ d->screenCount ];
+ memset( d->screens, 0, d->screenCount * sizeof( TQWidget * ) );
+ d->screens[ d->defaultScreen ] = this;
+ }
+
+ if ( ! d->screens[screen] || // not created yet
+ ! d->screens[screen]->isDesktop() ) { // reparented away
+ qt_x11_create_desktop_on_screen = screen;
+ d->screens[screen] = new TQSingleDesktopWidget;
+ qt_x11_create_desktop_on_screen = -1;
+ }
+
+ return d->screens[screen];
+}
+
+const TQRect& TQDesktopWidget::availableGeometry( int screen ) const
+{
+ if ( qt_desktopwidget_workarea_dirty ) {
+ // the workareas are dirty, tqinvalidate them
+ for ( int i = 0; i < d->screenCount; ++i )
+ d->workareas[i] = TQRect();
+ qt_desktopwidget_workarea_dirty = FALSE;
+ }
+
+ if ( screen < 0 || screen >= d->screenCount )
+ screen = d->defaultScreen;
+
+ if ( d->workareas[screen].isValid() )
+ return d->workareas[screen];
+
+ if ( ! isVirtualDesktop() && qt_net_supports( qt_net_workarea ) ) {
+ Atom ret;
+ int format, e;
+ unsigned char *data = 0;
+ unsigned long nitems, after;
+
+ e = XGetWindowProperty( TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppRootWindow( screen ),
+ qt_net_workarea, 0, 4, False, XA_CARDINAL,
+ &ret, &format, &nitems, &after, &data );
+
+ if (e == Success && ret == XA_CARDINAL &&
+ format == 32 && nitems == 4) {
+ long *workarea = (long *) data;
+ d->workareas[screen].setRect( workarea[0], workarea[1],
+ workarea[2], workarea[3] );
+ } else {
+ d->workareas[screen] = screenGeometry(screen);
+ }
+ if ( data )
+ XFree( data );
+ } else {
+ d->workareas[screen] = screenGeometry(screen);
+ }
+
+ return d->workareas[screen];
+}
+
+const TQRect& TQDesktopWidget::screenGeometry( int screen ) const
+{
+ if ( screen < 0 || screen >= d->screenCount )
+ screen = d->defaultScreen;
+
+ return d->rects[ screen ];
+}
+
+int TQDesktopWidget::screenNumber( TQWidget *widget ) const
+{
+ if ( !widget )
+ return d->defaultScreen;
+
+#ifndef TQT_NO_XINERAMA
+ if (d->use_xinerama) {
+ // this is how we do it for xinerama
+ TQRect frame = widget->frameGeometry();
+ if ( !widget->isTopLevel() )
+ frame.moveTopLeft( widget->mapToGlobal( TQPoint( 0, 0 ) ) );
+
+ int maxSize = -1;
+ int maxScreen = -1;
+
+ for ( int i = 0; i < d->screenCount; ++i ) {
+ TQRect sect = d->rects[i].intersect( frame );
+ int size = sect.width() * sect.height();
+ if ( size > maxSize && sect.width() > 0 && sect.height() > 0 ) {
+ maxSize = size;
+ maxScreen = i;
+ }
+ }
+ return maxScreen;
+ }
+#endif // TQT_NO_XINERAMA
+
+ return widget->x11Screen();
+}
+
+int TQDesktopWidget::screenNumber( const TQPoint &point ) const
+{
+ for ( int i = 0; i < d->screenCount; ++i ) {
+ if ( d->rects[i].tqcontains( point ) )
+ return i;
+ }
+ return -1;
+}
+
+void TQDesktopWidget::resizeEvent( TQResizeEvent *event )
+{
+ d->init();
+ qt_desktopwidget_workarea_dirty = TRUE;
+ TQWidget::resizeEvent( event );
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqdnd_x11.cpp b/tqtinterface/qt4/src/kernel/tqdnd_x11.cpp
new file mode 100644
index 0000000..7882349
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdnd_x11.cpp
@@ -0,0 +1,1765 @@
+/****************************************************************************
+**
+** XDND implementation for TQt. See http://www.cco.caltech.edu/~jafl/xdnd/
+**
+** Created : 980320
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+#include "tqapplication.h"
+
+#ifndef TQT_NO_DRAGANDDROP
+
+#include "tqwidget.h"
+#include "tqintdict.h"
+#include "tqdatetime.h"
+#include "tqdict.h"
+#include "tqguardedptr.h"
+#include "tqdragobject.h"
+#include "tqobjectlist.h"
+#include "tqcursor.h"
+
+#include "tqt_x11_p.h"
+
+// conflict resolution
+
+// unused, may be used again later: const int XKeyPress = KeyPress;
+// unused, may be used again later: const int XKeyRelease = KeyRelease;
+#undef KeyPress
+#undef KeyRelease
+
+// this stuff is copied from qapp_x11.cpp
+
+extern void qt_x11_intern_atom( const char *, Atom * );
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+extern void qt_ignore_badwindow();
+extern bool qt_badwindow();
+extern void qt_enter_modal( TQWidget *widget );
+extern void qt_leave_modal( TQWidget *widget );
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+extern Window qt_x11_tqfindClientWindow( Window, Atom, bool );
+extern Atom qt_wm_state;
+
+// this stuff is copied from qclb_x11.cpp
+
+extern bool qt_xclb_wait_for_event( Display *dpy, Window win, int type,
+ XEvent *event, int timeout );
+extern bool qt_xclb_read_property( Display *dpy, Window win, Atom property,
+ bool deleteProperty,
+ TQByteArray *buffer, int *size, Atom *type,
+ int *format, bool nullterm );
+extern TQByteArray qt_xclb_read_incremental_property( Display *dpy, Window win,
+ Atom property,
+ int nbytes, bool nullterm );
+// and all this stuff is copied -into- qapp_x11.cpp
+
+void qt_xdnd_setup();
+void qt_handle_xdnd_enter( TQWidget *, const XEvent *, bool );
+void qt_handle_xdnd_position( TQWidget *, const XEvent *, bool );
+void qt_handle_xdnd_status( TQWidget *, const XEvent *, bool );
+void qt_handle_xdnd_leave( TQWidget *, const XEvent *, bool );
+void qt_handle_xdnd_drop( TQWidget *, const XEvent *, bool );
+void qt_handle_xdnd_finished( TQWidget *, const XEvent *, bool );
+void qt_xdnd_handle_selection_request( const XSelectionRequestEvent * );
+bool qt_xdnd_handle_badwindow();
+// client messages
+Atom qt_xdnd_enter;
+Atom qt_xdnd_position;
+Atom qt_xdnd_status;
+Atom qt_xdnd_leave;
+Atom qt_xdnd_drop;
+Atom qt_xdnd_finished;
+Atom qt_xdnd_type_list;
+const int qt_xdnd_version = 4;
+
+// Actions
+//
+// The Xdnd spec allows for user-defined actions. This could be implemented
+// with a registration process in TQt. WE SHOULD do that later.
+//
+Atom qt_xdnd_action_copy;
+Atom qt_xdnd_action_link;
+Atom qt_xdnd_action_move;
+Atom qt_xdnd_action_private;
+static
+TQDropEvent::Action xdndaction_to_qtaction(Atom atom)
+{
+ if ( atom == qt_xdnd_action_copy || atom == 0 )
+ return TQDropEvent::Copy;
+ if ( atom == qt_xdnd_action_link )
+ return TQDropEvent::Link;
+ if ( atom == qt_xdnd_action_move )
+ return TQDropEvent::Move;
+ return TQDropEvent::Private;
+}
+static
+int qtaction_to_xdndaction(TQDropEvent::Action a)
+{
+ switch ( a ) {
+ case TQDropEvent::Copy:
+ return qt_xdnd_action_copy;
+ case TQDropEvent::Link:
+ return qt_xdnd_action_link;
+ case TQDropEvent::Move:
+ return qt_xdnd_action_move;
+ case TQDropEvent::Private:
+ return qt_xdnd_action_private;
+ default:
+ return qt_xdnd_action_copy;
+ }
+}
+
+// clean up the stuff used.
+static void qt_xdnd_cleanup();
+
+static void qt_xdnd_send_leave();
+
+// XDND selection
+Atom qt_xdnd_selection;
+// other selection
+static Atom qt_selection_property;
+// INCR
+static Atom qt_incr_atom;
+
+// properties for XDND drop sites
+Atom qt_xdnd_aware;
+Atom qt_xdnd_proxy;
+
+// real variables:
+// xid of current drag source
+static Atom qt_xdnd_dragsource_xid = 0;
+
+// the types in this drop. 100 is no good, but at least it's big.
+const int qt_xdnd_max_type = 100;
+static Atom qt_xdnd_types[qt_xdnd_max_type];
+
+static TQIntDict<TQCString> * qt_xdnd_drag_types = 0;
+static TQDict<Atom> * qt_xdnd_atom_numbers = 0;
+
+// timer used when target wants "continuous" move messages (eg. scroll)
+static int heartbeat = -1;
+// rectangle in which the answer will be the same
+static TQRect qt_xdnd_source_sameanswer;
+//static TQRect qt_xdnd_target_sameanswer;
+static bool qt_xdnd_target_answerwas;
+// top-level window we sent position to last.
+static Window qt_xdnd_current_target;
+// window to send events to (always valid if qt_xdnd_current_target)
+static Window qt_xdnd_current_proxy_target;
+// widget we forwarded position to last, and local position
+static TQGuardedPtr<TQWidget> qt_xdnd_current_widget;
+static TQPoint qt_xdnd_current_position;
+// time of this drop, as type Atom to save on casts
+static Atom qt_xdnd_source_current_time;
+// timestamp from the XdndPosition and XdndDrop
+static Time qt_xdnd_target_current_time;
+// screen number containing the pointer... -1 means default
+static int qt_xdnd_current_screen = -1;
+// state of dragging... true if dragging, false if not
+bool qt_xdnd_dragging = FALSE;
+
+// dict of payload data, sorted by type atom
+static TQIntDict<TQByteArray> * qt_xdnd_target_data = 0;
+
+// first drag object, or 0
+static TQDragObject * qt_xdnd_source_object = 0;
+
+// Motif dnd
+extern void qt_motifdnd_enable( TQWidget *, bool );
+extern TQByteArray qt_motifdnd_obtain_data( const char *format );
+extern const char *qt_motifdnd_format( int n );
+
+bool qt_motifdnd_active = FALSE;
+static bool dndCancelled = FALSE;
+
+// Shift/Ctrl handling, and final drop status
+static TQDragObject::DragMode drag_mode;
+static TQDropEvent::Action global_requested_action = TQDropEvent::Copy;
+static TQDropEvent::Action global_accepted_action = TQDropEvent::Copy;
+
+// for embedding only
+static TQWidget* current_embedding_widget = 0;
+static XEvent last_enter_event;
+
+// cursors
+static TQCursor *noDropCursor = 0;
+static TQCursor *moveCursor = 0;
+static TQCursor *copyCursor = 0;
+static TQCursor *linkCursor = 0;
+
+static TQPixmap *defaultPm = 0;
+
+static const int default_pm_hotx = -2;
+static const int default_pm_hoty = -16;
+static const char* const default_pm[] = {
+"13 9 3 1",
+". c None",
+" c #000000",
+"X c #FFFFFF",
+"X X X X X X X",
+" X X X X X X ",
+"X ......... X",
+" X.........X ",
+"X ......... X",
+" X.........X ",
+"X ......... X",
+" X X X X X X ",
+"X X X X X X X"
+};
+
+#define WStyle_Tool Qt::Tool
+#define WStyle_NoBorder Qt::FramelessWindowHint
+
+class TQShapedPixmapWidget : public TQWidget {
+
+public:
+ TQShapedPixmapWidget(int screen = -1) :
+ TQWidget(TQApplication::desktop()->screen( screen ),
+ 0, (Qt::WindowType)(WStyle_Customize | WStyle_Tool | WStyle_NoBorder | WX11BypassWM) )
+ {
+ }
+
+ void setPixmap(TQPixmap pm)
+ {
+ const TQBitmap* mask = pm.tqmask();
+ if ( mask ) {
+ setMask( *mask );
+ } else {
+ clearMask();
+ }
+ resize(pm.width(),pm.height());
+ setErasePixmap(pm);
+ }
+};
+
+static TQShapedPixmapWidget * qt_xdnd_deco = 0;
+
+static TQWidget* desktop_proxy = 0;
+
+class TQExtraWidget : public TQWidget
+{
+public:
+ TQWExtra* extraData() { return TQWidget::extraData(); }
+ TQTLWExtra* topData() { return TQWidget::topData(); }
+};
+
+
+static bool qt_xdnd_enable( TQWidget* w, bool on )
+{
+ if ( on ) {
+ TQWidget * xdnd_widget = 0;
+ if ( w->isDesktop() ) {
+ if ( desktop_proxy ) // *WE* already have one.
+ return FALSE;
+
+ // As per Xdnd4, use XdndProxy
+ XGrabServer( w->x11Display() );
+ Atom type = None;
+ int f;
+ unsigned long n, a;
+ WId *proxy_id_ptr;
+ XGetWindowProperty( w->x11Display(), w->winId(),
+ qt_xdnd_proxy, 0, 1, False,
+ XA_WINDOW, &type, &f,&n,&a,(uchar**)&proxy_id_ptr );
+ WId proxy_id = 0;
+ if ( type == XA_WINDOW && proxy_id_ptr ) {
+ proxy_id = *proxy_id_ptr;
+ XFree(proxy_id_ptr);
+ proxy_id_ptr = 0;
+ // Already exists. Real?
+ qt_ignore_badwindow();
+ XGetWindowProperty( w->x11Display(), proxy_id,
+ qt_xdnd_proxy, 0, 1, False,
+ XA_WINDOW, &type, &f,&n,&a,(uchar**)&proxy_id_ptr );
+ if ( qt_badwindow() || type != XA_WINDOW || !proxy_id_ptr || *proxy_id_ptr != proxy_id ) {
+ // Bogus - we will overwrite.
+ proxy_id = 0;
+ }
+ }
+ if ( proxy_id_ptr )
+ XFree(proxy_id_ptr);
+
+ if ( !proxy_id ) {
+ xdnd_widget = desktop_proxy = new TQWidget;
+ proxy_id = desktop_proxy->winId();
+ XChangeProperty ( w->x11Display(),
+ w->winId(), qt_xdnd_proxy,
+ XA_WINDOW, 32, PropModeReplace,
+ (unsigned char *)&proxy_id, 1 );
+ XChangeProperty ( w->x11Display(),
+ proxy_id, qt_xdnd_proxy,
+ XA_WINDOW, 32, PropModeReplace,
+ (unsigned char *)&proxy_id, 1 );
+ }
+
+ XUngrabServer( w->x11Display() );
+ } else {
+ xdnd_widget = w->tqtopLevelWidget();
+ }
+ if ( xdnd_widget ) {
+ Atom atm = (Atom)qt_xdnd_version;
+ XChangeProperty ( xdnd_widget->x11Display(), xdnd_widget->winId(),
+ qt_xdnd_aware, XA_ATOM, 32, PropModeReplace,
+ (unsigned char *)&atm, 1 );
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ if ( w->isDesktop() ) {
+ XDeleteProperty( w->x11Display(), w->winId(),
+ qt_xdnd_proxy );
+ delete desktop_proxy;
+ desktop_proxy = 0;
+ }
+ return TRUE;
+ }
+}
+
+const char* qt_xdnd_atom_to_str( Atom a )
+{
+ if ( !a ) return 0;
+
+ if ( a == XA_STRING )
+ return "text/plain"; // some Xdnd clients are dumb
+
+ if ( !qt_xdnd_drag_types ) {
+ qt_xdnd_drag_types = new TQIntDict<TQCString>( 17 );
+ qt_xdnd_drag_types->setAutoDelete( TRUE );
+ }
+ TQCString* result;
+ if ( !(result=qt_xdnd_drag_types->tqfind( a )) ) {
+ const char* mimeType = XGetAtomName( TQPaintDevice::x11AppDisplay(), a );
+ if ( !mimeType )
+ return 0; // only happens on protocol error
+ result = new TQCString( mimeType );
+ qt_xdnd_drag_types->insert( (long)a, result );
+ XFree((void*)mimeType);
+ }
+ return *result;
+}
+
+Atom* qt_xdnd_str_to_atom( const char *mimeType )
+{
+ if ( !mimeType || !*mimeType )
+ return 0;
+ if ( !qt_xdnd_atom_numbers ) {
+ qt_xdnd_atom_numbers = new TQDict<Atom>( 17 );
+ qt_xdnd_atom_numbers->setAutoDelete( TRUE );
+ }
+
+ Atom * result;
+ if ( (result = qt_xdnd_atom_numbers->tqfind( mimeType )) )
+ return result;
+
+ result = new Atom;
+ *result = 0;
+ qt_x11_intern_atom( mimeType, result );
+ qt_xdnd_atom_numbers->insert( mimeType, result );
+ qt_xdnd_atom_to_str( *result );
+
+ return result;
+}
+
+
+void qt_xdnd_setup() {
+ // set up protocol atoms
+ qt_x11_intern_atom( "XdndEnter", &qt_xdnd_enter );
+ qt_x11_intern_atom( "XdndPosition", &qt_xdnd_position );
+ qt_x11_intern_atom( "XdndtqStatus", &qt_xdnd_status );
+ qt_x11_intern_atom( "XdndLeave", &qt_xdnd_leave );
+ qt_x11_intern_atom( "XdndDrop", &qt_xdnd_drop );
+ qt_x11_intern_atom( "XdndFinished", &qt_xdnd_finished );
+ qt_x11_intern_atom( "XdndTypeList", &qt_xdnd_type_list );
+
+ qt_x11_intern_atom( "XdndSelection", &qt_xdnd_selection );
+
+ qt_x11_intern_atom( "XdndAware", &qt_xdnd_aware );
+ qt_x11_intern_atom( "XdndProxy", &qt_xdnd_proxy );
+
+
+ qt_x11_intern_atom( "XdndActionCopy", &qt_xdnd_action_copy );
+ qt_x11_intern_atom( "XdndActionLink", &qt_xdnd_action_link );
+ qt_x11_intern_atom( "XdndActionMove", &qt_xdnd_action_move );
+ qt_x11_intern_atom( "XdndActionPrivate", &qt_xdnd_action_private );
+
+ qt_x11_intern_atom( "TQT_SELECTION", &qt_selection_property );
+ qt_x11_intern_atom( "INCR", &qt_incr_atom );
+
+ qAddPostRoutine( qt_xdnd_cleanup );
+}
+
+
+void qt_xdnd_cleanup()
+{
+ delete qt_xdnd_drag_types;
+ qt_xdnd_drag_types = 0;
+ delete qt_xdnd_atom_numbers;
+ qt_xdnd_atom_numbers = 0;
+ delete qt_xdnd_target_data;
+ qt_xdnd_target_data = 0;
+ delete noDropCursor;
+ noDropCursor = 0;
+ delete copyCursor;
+ copyCursor = 0;
+ delete moveCursor;
+ moveCursor = 0;
+ delete linkCursor;
+ linkCursor = 0;
+ delete defaultPm;
+ defaultPm = 0;
+ delete desktop_proxy;
+ desktop_proxy = 0;
+}
+
+
+static TQWidget * tqfind_child( TQWidget * tlw, TQPoint & p )
+{
+ TQWidget * w = tlw;
+
+ p = w->mapFromGlobal( p );
+ bool done = FALSE;
+ while ( !done ) {
+ done = TRUE;
+ if ( ((TQExtraWidget*)w)->extraData() &&
+ ((TQExtraWidget*)w)->extraData()->xDndProxy != 0 )
+ break; // stop searching for widgets under the mouse cursor if found widget is a proxy.
+ if ( !w->childrenListObject().isEmpty() ) {
+ TQObjectListIt it( w->childrenListObject() );
+ it.toLast();
+ TQObject * o;
+ while( (o=it.current()) ) {
+ --it;
+ if ( o->isWidgetType() &&
+ ((TQWidget*)o)->isVisible() &&
+ ((TQWidget*)o)->tqgeometry().contains( p ) &&
+ !((TQWidget*)o)->isTopLevel()) {
+ w = (TQWidget *)o;
+ done = FALSE;
+ p = w->mapFromParent( p );
+ break;
+ }
+ }
+ }
+ }
+ return w;
+}
+
+
+static bool checkEmbedded(TQWidget* w, const XEvent* xe)
+{
+ if (!w)
+ return FALSE;
+
+ if (current_embedding_widget != 0 && current_embedding_widget != w) {
+ qt_xdnd_current_target = ((TQExtraWidget*)current_embedding_widget)->extraData()->xDndProxy;
+ qt_xdnd_current_proxy_target = qt_xdnd_current_target;
+ qt_xdnd_send_leave();
+ qt_xdnd_current_target = 0;
+ qt_xdnd_current_proxy_target = 0;
+ current_embedding_widget = 0;
+ }
+
+ TQWExtra* extra = ((TQExtraWidget*)w)->extraData();
+ if ( extra && extra->xDndProxy != 0 ) {
+
+ if (current_embedding_widget != w) {
+
+ last_enter_event.xany.window = extra->xDndProxy;
+ XSendEvent( TQPaintDevice::x11AppDisplay(), extra->xDndProxy, False, NoEventMask,
+ &last_enter_event );
+ current_embedding_widget = w;
+ }
+
+ ((XEvent*)xe)->xany.window = extra->xDndProxy;
+ XSendEvent( TQPaintDevice::x11AppDisplay(), extra->xDndProxy, False, NoEventMask,
+ (XEvent*)xe );
+ qt_xdnd_current_widget = w;
+ return TRUE;
+ }
+ current_embedding_widget = 0;
+ return FALSE;
+}
+
+void qt_handle_xdnd_enter( TQWidget *, const XEvent * xe, bool /*passive*/ )
+{
+ //if ( !w->neveHadAChildWithDropEventsOn() )
+ //return; // haven't been set up for dnd
+
+ qt_motifdnd_active = FALSE;
+
+ last_enter_event.xclient = xe->xclient;
+
+ qt_xdnd_target_answerwas = FALSE;
+
+ const long *l = xe->xclient.data.l;
+ int version = (int)(((unsigned long)(l[1])) >> 24);
+
+ if ( version > qt_xdnd_version )
+ return;
+
+ qt_xdnd_dragsource_xid = l[0];
+
+ int j = 0;
+ if ( l[1] & 1 ) {
+ // get the types from XdndTypeList
+ Atom type = None;
+ int f;
+ unsigned long n, a;
+ Atom *data;
+ XGetWindowProperty( TQPaintDevice::x11AppDisplay(), qt_xdnd_dragsource_xid,
+ qt_xdnd_type_list, 0,
+ qt_xdnd_max_type, False, XA_ATOM, &type, &f,&n,&a,(uchar**)&data );
+ for ( ; j<qt_xdnd_max_type && j < (int)n; j++ ) {
+ qt_xdnd_types[j] = data[j];
+ }
+ if ( data )
+ XFree( (uchar*)data );
+ } else {
+ // get the types from the message
+ int i;
+ for( i=2; i < 5; i++ ) {
+ qt_xdnd_types[j++] = l[i];
+ }
+ }
+ qt_xdnd_types[j] = 0;
+}
+
+
+
+void qt_handle_xdnd_position( TQWidget *w, const XEvent * xe, bool passive )
+{
+ const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
+
+ TQPoint p( (l[2] & 0xffff0000) >> 16, l[2] & 0x0000ffff );
+ TQWidget * c = tqfind_child( w, p ); // changes p to to c-local coordinates
+
+ if (!passive && checkEmbedded(c, xe))
+ return;
+
+ if ( !c || (!c->acceptDrops() && c->isDesktop()) ) {
+ return;
+ }
+
+ if ( l[0] != qt_xdnd_dragsource_xid ) {
+ //qDebug( "xdnd drag position from unexpected source (%08lx not %08lx)",
+ // l[0], qt_xdnd_dragsource_xid );
+ return;
+ }
+
+ if (l[3] != 0) {
+ // timestamp from the source
+ SET_QT_X_USER_TIME(l[3]);
+ qt_xdnd_target_current_time = l[3];
+ }
+
+ XClientMessageEvent response;
+ response.type = ClientMessage;
+ response.window = qt_xdnd_dragsource_xid;
+ response.format = 32;
+ response.message_type = qt_xdnd_status;
+ response.data.l[0] = w->winId();
+ response.data.l[1] = 0; // flags
+ response.data.l[2] = 0; // x, y
+ response.data.l[3] = 0; // w, h
+ response.data.l[4] = 0; // action
+
+ if ( !passive ) { // otherwise just reject
+ while ( c && !c->acceptDrops() && !c->isTopLevel() ) {
+ p = c->mapToParent( p );
+ c = c->parentWidget();
+ }
+
+ TQRect answerRect( c->mapToGlobal( p ), TQSize( 1,1 ) );
+
+ TQDragMoveEvent me( p );
+ TQDropEvent::Action accepted_action = xdndaction_to_qtaction(l[4]);
+ me.setAction(accepted_action);
+
+ if ( c != qt_xdnd_current_widget ) {
+ qt_xdnd_target_answerwas = FALSE;
+ if ( qt_xdnd_current_widget ) {
+ TQDragLeaveEvent e;
+ TQApplication::sendEvent( qt_xdnd_current_widget, &e );
+ }
+ if ( c->acceptDrops() ) {
+ qt_xdnd_current_widget = c;
+ qt_xdnd_current_position = p;
+
+ TQDragEnterEvent de( p );
+ de.setAction(accepted_action);
+ TQApplication::sendEvent( c, &de );
+ if ( de.isAccepted() ) {
+ me.accept( de.answerRect() );
+ if ( !de.isActionAccepted() ) // only as a copy (move if we del)
+ accepted_action = TQDropEvent::Copy;
+ else
+ me.acceptAction(TRUE);
+ } else {
+ me.ignore( de.answerRect() );
+ }
+ }
+ } else {
+ if ( qt_xdnd_target_answerwas ) {
+ me.accept();
+ me.acceptAction(global_requested_action == global_accepted_action);
+ }
+ }
+
+ if ( !c->acceptDrops() ) {
+ qt_xdnd_current_widget = 0;
+ answerRect = TQRect( p, TQSize( 1, 1 ) );
+ } else if ( xdndaction_to_qtaction(l[4]) < TQDropEvent::Private ) {
+ qt_xdnd_current_widget = c;
+ qt_xdnd_current_position = p;
+
+ TQApplication::sendEvent( c, &me );
+ qt_xdnd_target_answerwas = me.isAccepted();
+ if ( me.isAccepted() ) {
+ response.data.l[1] = 1; // yes
+ if ( !me.isActionAccepted() ) // only as a copy (move if we del)
+ accepted_action = TQDropEvent::Copy;
+ } else {
+ response.data.l[0] = 0;
+ }
+ answerRect = me.answerRect().intersect( c->rect() );
+ } else {
+ response.data.l[0] = 0;
+ answerRect = TQRect( p, TQSize( 1, 1 ) );
+ }
+ answerRect = TQRect( c->mapToGlobal( answerRect.topLeft() ),
+ answerRect.size() );
+
+ if ( answerRect.left() < 0 )
+ answerRect.setLeft( 0 );
+ if ( answerRect.right() > 4096 )
+ answerRect.setRight( 4096 );
+ if ( answerRect.top() < 0 )
+ answerRect.setTop( 0 );
+ if ( answerRect.bottom() > 4096 )
+ answerRect.setBottom( 4096 );
+ if ( answerRect.width() < 0 )
+ answerRect.setWidth( 0 );
+ if ( answerRect.height() < 0 )
+ answerRect.setHeight( 0 );
+
+ response.data.l[2] = (answerRect.x() << 16) + answerRect.y();
+ response.data.l[3] = (answerRect.width() << 16) + answerRect.height();
+ response.data.l[4] = qtaction_to_xdndaction(accepted_action);
+ global_accepted_action = accepted_action;
+ }
+
+ // reset
+ qt_xdnd_target_current_time = CurrentTime;
+
+ TQWidget * source = TQWidget::tqfind( qt_xdnd_dragsource_xid );
+
+ if ( source && source->isDesktop() && !source->acceptDrops() )
+ source = 0;
+
+ if ( source )
+ qt_handle_xdnd_status( source, (const XEvent *)&response, passive );
+ else
+ XSendEvent( TQPaintDevice::x11AppDisplay(), qt_xdnd_dragsource_xid, False,
+ NoEventMask, (XEvent*)&response );
+}
+
+
+void qt_handle_xdnd_status( TQWidget * w, const XEvent * xe, bool /*passive*/ )
+{
+ const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
+ // Messy: TQDragResponseEvent is just a call to TQDragManager function
+ global_accepted_action = xdndaction_to_qtaction(l[4]);
+ TQDragResponseEvent e( (int)(l[1] & 1) );
+ TQApplication::sendEvent( w, &e );
+
+ if ( (int)(l[1] & 2) == 0 ) {
+ TQPoint p( (l[2] & 0xffff0000) >> 16, l[2] & 0x0000ffff );
+ TQSize s( (l[3] & 0xffff0000) >> 16, l[3] & 0x0000ffff );
+ qt_xdnd_source_sameanswer = TQRect( p, s );
+ if ( qt_xdnd_source_sameanswer.isNull() ) {
+ // Application wants "coninutous" move events
+ }
+ } else {
+ qt_xdnd_source_sameanswer = TQRect();
+ }
+}
+
+
+void qt_handle_xdnd_leave( TQWidget *w, const XEvent * xe, bool /*passive*/ )
+{
+ //qDebug( "xdnd leave" );
+ if ( !qt_xdnd_current_widget ||
+ w->tqtopLevelWidget() != qt_xdnd_current_widget->tqtopLevelWidget() ) {
+ return; // sanity
+ }
+
+ if (checkEmbedded(current_embedding_widget, xe)) {
+ current_embedding_widget = 0;
+ qt_xdnd_current_widget = 0;
+ return;
+ }
+
+ const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
+
+ TQDragLeaveEvent e;
+ TQApplication::sendEvent( qt_xdnd_current_widget, &e );
+
+ if ( l[0] != qt_xdnd_dragsource_xid ) {
+ // This often happens - leave other-process window quickly
+ //qDebug( "xdnd drag leave from unexpected source (%08lx not %08lx",
+ //l[0], qt_xdnd_dragsource_xid );
+ qt_xdnd_current_widget = 0;
+ return;
+ }
+
+ qt_xdnd_dragsource_xid = 0;
+ qt_xdnd_types[0] = 0;
+ qt_xdnd_current_widget = 0;
+}
+
+
+void qt_xdnd_send_leave()
+{
+ if ( !qt_xdnd_current_target )
+ return;
+
+ XClientMessageEvent leave;
+ leave.type = ClientMessage;
+ leave.window = qt_xdnd_current_target;
+ leave.format = 32;
+ leave.message_type = qt_xdnd_leave;
+ leave.data.l[0] = qt_xdnd_dragsource_xid;
+ leave.data.l[1] = 0; // flags
+ leave.data.l[2] = 0; // x, y
+ leave.data.l[3] = 0; // w, h
+ leave.data.l[4] = 0; // just null
+
+ TQWidget * w = TQWidget::tqfind( qt_xdnd_current_proxy_target );
+
+ if ( w && w->isDesktop() && !w->acceptDrops() )
+ w = 0;
+
+ if ( w )
+ qt_handle_xdnd_leave( w, (const XEvent *)&leave, FALSE );
+ else
+ XSendEvent( TQPaintDevice::x11AppDisplay(), qt_xdnd_current_proxy_target, False,
+ NoEventMask, (XEvent*)&leave );
+ qt_xdnd_current_target = 0;
+ qt_xdnd_current_proxy_target = 0;
+}
+
+
+
+void qt_handle_xdnd_drop( TQWidget *, const XEvent * xe, bool passive )
+{
+ if ( !qt_xdnd_current_widget ) {
+ qt_xdnd_dragsource_xid = 0;
+ return; // sanity
+ }
+
+ if (!passive && checkEmbedded(qt_xdnd_current_widget, xe)){
+ current_embedding_widget = 0;
+ qt_xdnd_dragsource_xid = 0;
+ qt_xdnd_current_widget = 0;
+ return;
+ }
+ const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
+
+ //qDebug( "xdnd drop" );
+
+ if ( l[0] != qt_xdnd_dragsource_xid ) {
+ //qDebug( "xdnd drop from unexpected source (%08lx not %08lx",
+ // l[0], qt_xdnd_dragsource_xid );
+ return;
+ }
+
+ if (l[2] != 0) {
+ // update the "user time" from the timestamp in the event.
+ SET_QT_X_USER_TIME(l[2]);
+ qt_xdnd_target_current_time = l[2];
+ }
+
+ if ( qt_xdnd_source_object )
+ qt_xdnd_source_object->setTarget( qt_xdnd_current_widget );
+
+ if ( !passive ) {
+ TQDropEvent de( qt_xdnd_current_position );
+ de.setAction( global_accepted_action );
+ TQApplication::sendEvent( qt_xdnd_current_widget, &de );
+ if ( !de.isAccepted() ) {
+ // Ignore a failed drag
+ global_accepted_action = TQDropEvent::Copy;
+ dndCancelled = TRUE;
+ }
+ XClientMessageEvent finished;
+ finished.type = ClientMessage;
+ finished.window = qt_xdnd_dragsource_xid;
+ finished.format = 32;
+ finished.message_type = qt_xdnd_finished;
+ finished.data.l[0] = qt_xdnd_current_widget?qt_xdnd_current_widget->tqtopLevelWidget()->winId():0;
+ finished.data.l[1] = 0; // flags
+ XSendEvent( TQPaintDevice::x11AppDisplay(), qt_xdnd_dragsource_xid, False,
+ NoEventMask, (XEvent*)&finished );
+ } else {
+ TQDragLeaveEvent e;
+ TQApplication::sendEvent( qt_xdnd_current_widget, &e );
+ }
+ qt_xdnd_dragsource_xid = 0;
+ qt_xdnd_current_widget = 0;
+
+ // reset
+ qt_xdnd_target_current_time = CurrentTime;
+}
+
+
+void qt_handle_xdnd_finished( TQWidget *, const XEvent * xe, bool passive )
+{
+ const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
+
+ if ( l[0] && (l[0] == qt_xdnd_current_target
+ || l[0] == qt_xdnd_current_proxy_target) ) {
+ //
+ if ( !passive )
+ (void ) checkEmbedded( qt_xdnd_current_widget, xe);
+ current_embedding_widget = 0;
+ qt_xdnd_current_target = 0;
+ qt_xdnd_current_proxy_target = 0;
+ delete qt_xdnd_source_object;
+ qt_xdnd_source_object = 0;
+ }
+}
+
+
+void TQDragManager::timerEvent( TQTimerEvent* e )
+{
+ if ( e->timerId() == heartbeat && qt_xdnd_source_sameanswer.isNull() )
+ move( TQCursor::pos() );
+}
+
+bool TQDragManager::eventFilter( TQObject * o, TQEvent * e)
+{
+ if ( beingCancelled ) {
+ if ( e->type() == TQEvent::KeyRelease &&
+ ((TQKeyEvent*)e)->key() == Key_Escape ) {
+ tqApp->removeEventFilter( this );
+ object = 0;
+ dragSource = 0;
+ beingCancelled = FALSE;
+ tqApp->exit_loop();
+ return TRUE; // block the key release
+ }
+ return FALSE;
+ }
+
+ TQ_ASSERT( object != 0 );
+
+ if ( !o->isWidgetType() )
+ return FALSE;
+
+ if ( e->type() == TQEvent::MouseMove ) {
+ TQMouseEvent* me = (TQMouseEvent *)e;
+ updateMode(me->stateAfter());
+ move( me->globalPos() );
+ return TRUE;
+ } else if ( e->type() == TQEvent::MouseButtonRelease ) {
+ tqApp->removeEventFilter( this );
+ if ( willDrop )
+ drop();
+ else
+ cancel();
+ object = 0;
+ dragSource = 0;
+ beingCancelled = FALSE;
+ tqApp->exit_loop();
+ return TRUE;
+ } else if ( e->type() == TQEvent::DragResponse ) {
+ if ( ((TQDragResponseEvent *)e)->dragAccepted() ) {
+ if ( !willDrop ) {
+ willDrop = TRUE;
+ }
+ } else {
+ if ( willDrop ) {
+ willDrop = FALSE;
+ }
+ }
+ updateCursor();
+ return TRUE;
+ }
+
+ if ( e->type() == TQEvent::KeyPress
+ || e->type() == TQEvent::KeyRelease )
+ {
+ TQKeyEvent *ke = ((TQKeyEvent*)e);
+ if ( ke->key() == Key_Escape && e->type() == TQEvent::KeyPress ) {
+ cancel();
+ tqApp->removeEventFilter( this );
+ object = 0;
+ dragSource = 0;
+ beingCancelled = FALSE;
+ tqApp->exit_loop();
+ } else {
+ updateMode(ke->stateAfter());
+ qt_xdnd_source_sameanswer = TQRect(); // force move
+ move( TQCursor::pos() );
+ }
+ return TRUE; // Eat all key events
+ }
+
+ // ### We bind modality to widgets, so we have to do this
+ // ### "manually".
+ // DnD is modal - eat all other interactive events
+ switch ( e->type() ) {
+ case TQEvent::MouseButtonPress:
+ case TQEvent::MouseButtonRelease:
+ case TQEvent::MouseButtonDblClick:
+ case TQEvent::MouseMove:
+ case TQEvent::KeyPress:
+ case TQEvent::KeyRelease:
+ case TQEvent::Wheel:
+ case TQEvent::Accel:
+ case TQEvent::AccelAvailable:
+ case TQEvent::AccelOverride:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+
+static TQt::ButtonState oldstate;
+void TQDragManager::updateMode( TQt::ButtonState newstate )
+{
+ if ( newstate == oldstate )
+ return;
+ const int both = ShiftButton|ControlButton;
+ if ( (newstate & both) == both ) {
+ global_requested_action = TQDropEvent::Link;
+ } else {
+ bool local = qt_xdnd_source_object != 0;
+ if ( drag_mode == TQDragObject::DragMove )
+ global_requested_action = TQDropEvent::Move;
+ else if ( drag_mode == TQDragObject::DragCopy )
+ global_requested_action = TQDropEvent::Copy;
+ else if ( drag_mode == TQDragObject::DragLink )
+ global_requested_action = TQDropEvent::Link;
+ else {
+ if ( drag_mode == TQDragObject::DragDefault && local )
+ global_requested_action = TQDropEvent::Move;
+ else
+ global_requested_action = TQDropEvent::Copy;
+ if ( newstate & ShiftButton )
+ global_requested_action = TQDropEvent::Move;
+ else if ( newstate & ControlButton )
+ global_requested_action = TQDropEvent::Copy;
+ }
+ }
+ oldstate = newstate;
+}
+
+
+void TQDragManager::createCursors()
+{
+ if ( !noDropCursor ) {
+ noDropCursor = new TQCursor( Qt::ForbiddenCursor );
+ if ( !pm_cursor[0].isNull() )
+ moveCursor = new TQCursor(pm_cursor[0], 0,0);
+ if ( !pm_cursor[1].isNull() )
+ copyCursor = new TQCursor(pm_cursor[1], 0,0);
+ if ( !pm_cursor[2].isNull() )
+ linkCursor = new TQCursor(pm_cursor[2], 0,0);
+ }
+}
+
+void TQDragManager::updateCursor()
+{
+ TQCursor *c;
+ if ( willDrop ) {
+ if ( global_accepted_action == TQDropEvent::Copy ) {
+ if ( global_requested_action == TQDropEvent::Move )
+ c = moveCursor; // (source can delete)
+ else
+ c = copyCursor;
+ } else if ( global_accepted_action == TQDropEvent::Link ) {
+ c = linkCursor;
+ } else {
+ c = moveCursor;
+ }
+ if ( qt_xdnd_deco ) {
+ qt_xdnd_deco->show();
+ qt_xdnd_deco->raise();
+ }
+ } else {
+ c = noDropCursor;
+ //if ( qt_xdnd_deco )
+ // qt_xdnd_deco->hide();
+ }
+#ifndef TQT_NO_CURSOR
+ if ( c )
+ tqApp->setOverrideCursor( *c, TRUE );
+#endif
+}
+
+
+void TQDragManager::cancel( bool deleteSource )
+{
+ killTimer( heartbeat );
+ heartbeat = -1;
+ if ( object ) {
+ beingCancelled = TRUE;
+ object = 0;
+ }
+
+ if ( qt_xdnd_current_target ) {
+ qt_xdnd_send_leave();
+ }
+
+#ifndef TQT_NO_CURSOR
+ if ( restoreCursor ) {
+ TQApplication::restoreOverrideCursor();
+ restoreCursor = FALSE;
+ }
+#endif
+
+ if ( deleteSource )
+ delete qt_xdnd_source_object;
+ qt_xdnd_source_object = 0;
+ delete qt_xdnd_deco;
+ qt_xdnd_deco = 0;
+
+ dndCancelled = TRUE;
+}
+
+static
+Window tqfindRealWindow( const TQPoint & pos, Window w, int md )
+{
+ if ( qt_xdnd_deco && w == qt_xdnd_deco->winId() )
+ return 0;
+
+ if ( md ) {
+ qt_ignore_badwindow();
+ XWindowAttributes attr;
+ XGetWindowAttributes( TQPaintDevice::x11AppDisplay(), w, &attr );
+ if (qt_badwindow())
+ return 0;
+
+ if ( attr.map_state == IsViewable
+ && TQRect(attr.x,attr.y,attr.width,attr.height)
+ .contains(pos) )
+ {
+ {
+ Atom type = None;
+ int f;
+ unsigned long n, a;
+ unsigned char *data;
+
+ XGetWindowProperty( TQPaintDevice::x11AppDisplay(), w, qt_xdnd_aware, 0,
+ 0, False, AnyPropertyType, &type, &f,&n,&a,&data );
+ if ( data ) XFree(data);
+ if ( type ) return w;
+ }
+
+ Window r, p;
+ Window* c;
+ uint nc;
+ if ( XQueryTree( TQPaintDevice::x11AppDisplay(), w, &r, &p, &c, &nc ) ) {
+ r=0;
+ for (uint i=nc; !r && i--; ) {
+ r = tqfindRealWindow( pos-TQPoint(attr.x,attr.y),
+ c[i], md-1 );
+ }
+ XFree(c);
+ if ( r )
+ return r;
+
+ // We didn't tqfind a client window! Just use the
+ // innermost window.
+ }
+
+ // No tqchildren!
+ return w;
+ }
+ }
+ return 0;
+}
+
+void TQDragManager::move( const TQPoint & globalPos )
+{
+ if (!object) {
+ // perhaps the target crashed?
+ return;
+ }
+
+ int screen = TQCursor::x11Screen();
+ if ( ( qt_xdnd_current_screen == -1 && screen != TQPaintDevice::x11AppScreen() ) ||
+ ( screen != qt_xdnd_current_screen ) ) {
+ // recreate the pixmap on the new screen...
+ delete qt_xdnd_deco;
+ qt_xdnd_deco = new TQShapedPixmapWidget( screen );
+ if (!TQWidget::mouseGrabber()) {
+ updatePixmap();
+ qt_xdnd_deco->grabMouse();
+ }
+ }
+ updatePixmap();
+
+ if ( qt_xdnd_source_sameanswer.contains( globalPos ) &&
+ qt_xdnd_source_sameanswer.isValid() ) {
+ return;
+ }
+
+ qt_xdnd_current_screen = screen;
+ Window rootwin = TQPaintDevice::x11AppRootWindow( qt_xdnd_current_screen );
+ Window target = 0;
+ int lx = 0, ly = 0;
+ if ( !XTranslateCoordinates( TQPaintDevice::x11AppDisplay(), rootwin, rootwin,
+ globalPos.x(), globalPos.y(),
+ &lx, &ly, &target) )
+ // some wierd error...
+ return;
+
+ if ( target == rootwin ) {
+ // Ok.
+ } else if ( target ) {
+ //me
+ Window src = rootwin;
+ while (target != 0) {
+ int lx2, ly2;
+ Window t;
+ // translate coordinates
+ if (!XTranslateCoordinates(TQPaintDevice::x11AppDisplay(), src, target,
+ lx, ly, &lx2, &ly2, &t)) {
+ target = 0;
+ break;
+ }
+ lx = lx2;
+ ly = ly2;
+ src = target;
+
+ // check if it has XdndAware
+ Atom type = None;
+ int f;
+ unsigned long n, a;
+ unsigned char *data = 0;
+ XGetWindowProperty(TQPaintDevice::x11AppDisplay(), target, qt_xdnd_aware, 0, 0, False,
+ AnyPropertyType, &type, &f,&n,&a,&data);
+ if (data)
+ XFree(data);
+ if (type)
+ break;
+
+ // tqfind child at the coordinates
+ if (!XTranslateCoordinates( TQPaintDevice::x11AppDisplay(), src, src,
+ lx, ly, &lx2, &ly2, &target)) {
+ target = 0;
+ break;
+ }
+ }
+ if ( qt_xdnd_deco && (!target || target == qt_xdnd_deco->winId()) ) {
+ target = tqfindRealWindow(globalPos,rootwin,6);
+ }
+ }
+
+ TQWidget* w;
+ if ( target ) {
+ w = TQWidget::tqfind( (WId)target );
+ if ( w && w->isDesktop() && !w->acceptDrops() )
+ w = 0;
+ } else {
+ w = 0;
+ target = rootwin;
+ }
+
+ WId proxy_target = target;
+ int target_version = 1;
+
+ {
+ Atom type = None;
+ int r, f;
+ unsigned long n, a;
+ WId *proxy_id;
+ qt_ignore_badwindow();
+ r = XGetWindowProperty( qt_xdisplay(), target, qt_xdnd_proxy, 0,
+ 1, False, XA_WINDOW, &type, &f,&n,&a,(uchar**)&proxy_id );
+ if ( ( r != Success ) || qt_badwindow() ) {
+ proxy_target = target = 0;
+ } else if ( type == XA_WINDOW && proxy_id ) {
+ proxy_target = *proxy_id;
+ XFree(proxy_id);
+ proxy_id = 0;
+ r = XGetWindowProperty( qt_xdisplay(), proxy_target, qt_xdnd_proxy, 0,
+ 1, False, XA_WINDOW, &type, &f,&n,&a,(uchar**)&proxy_id );
+ if ( ( r != Success ) || qt_badwindow() || !type || !proxy_id || *proxy_id != proxy_target ) {
+ // Bogus
+ proxy_target = 0;
+ target = 0;
+ }
+ if ( proxy_id )
+ XFree(proxy_id);
+ }
+ if ( proxy_target ) {
+ int *tv;
+ qt_ignore_badwindow();
+ r = XGetWindowProperty( qt_xdisplay(), proxy_target, qt_xdnd_aware, 0,
+ 1, False, AnyPropertyType, &type, &f,&n,&a,(uchar**)&tv );
+ if ( r != Success ) {
+ target = 0;
+ } else {
+ target_version = TQMIN(qt_xdnd_version,tv ? *tv : 1);
+ if ( tv )
+ XFree( tv );
+ if (!(!qt_badwindow() && type))
+ target = 0;
+ }
+ }
+ }
+
+ if ( target != qt_xdnd_current_target ) {
+ if ( qt_xdnd_current_target )
+ qt_xdnd_send_leave();
+
+ qt_xdnd_current_target = target;
+ qt_xdnd_current_proxy_target = proxy_target;
+ if ( target ) {
+ TQMemArray<Atom> type;
+ int flags = target_version << 24;
+ const char* fmt;
+ int nfmt=0;
+ for (nfmt=0; (fmt=object->format(nfmt)); nfmt++) {
+ type.resize(nfmt+1);
+ type[nfmt] = *qt_xdnd_str_to_atom( fmt );
+ }
+ if ( nfmt >= 3 ) {
+ XChangeProperty( TQPaintDevice::x11AppDisplay(),
+ object->source()->winId(), qt_xdnd_type_list,
+ XA_ATOM, 32, PropModeReplace,
+ (unsigned char *)type.data(),
+ type.size() );
+ flags |= 0x0001;
+ }
+ XClientMessageEvent enter;
+ enter.type = ClientMessage;
+ enter.window = target;
+ enter.format = 32;
+ enter.message_type = qt_xdnd_enter;
+ enter.data.l[0] = object->source()->winId();
+ enter.data.l[1] = flags;
+ enter.data.l[2] = type.size()>0 ? type[0] : 0;
+ enter.data.l[3] = type.size()>1 ? type[1] : 0;
+ enter.data.l[4] = type.size()>2 ? type[2] : 0;
+ // provisionally set the rectangle to 5x5 pixels...
+ qt_xdnd_source_sameanswer = TQRect( globalPos.x() - 2,
+ globalPos.y() -2 , 5, 5 );
+
+ if ( w ) {
+ qt_handle_xdnd_enter( w, (const XEvent *)&enter, FALSE );
+ } else if ( target ) {
+ XSendEvent( TQPaintDevice::x11AppDisplay(), proxy_target, False, NoEventMask,
+ (XEvent*)&enter );
+ }
+ }
+ }
+
+ if ( target ) {
+ XClientMessageEvent move;
+ move.type = ClientMessage;
+ move.window = target;
+ move.format = 32;
+ move.message_type = qt_xdnd_position;
+ move.window = target;
+ move.data.l[0] = object->source()->winId();
+ move.data.l[1] = 0; // flags
+ move.data.l[2] = (globalPos.x() << 16) + globalPos.y();
+ move.data.l[3] = GET_QT_X_TIME();
+ move.data.l[4] = qtaction_to_xdndaction( global_requested_action );
+
+ if ( w )
+ qt_handle_xdnd_position( w, (const XEvent *)&move, FALSE );
+ else
+ XSendEvent( TQPaintDevice::x11AppDisplay(), proxy_target, False, NoEventMask,
+ (XEvent*)&move );
+ } else {
+ if ( willDrop ) {
+ willDrop = FALSE;
+ updateCursor();
+ }
+ }
+}
+
+
+void TQDragManager::drop()
+{
+ killTimer( heartbeat );
+ heartbeat = -1;
+ if ( !qt_xdnd_current_target )
+ return;
+
+ delete qt_xdnd_deco;
+ qt_xdnd_deco = 0;
+
+ XClientMessageEvent drop;
+ drop.type = ClientMessage;
+ drop.window = qt_xdnd_current_target;
+ drop.format = 32;
+ drop.message_type = qt_xdnd_drop;
+ drop.data.l[0] = object->source()->winId();
+ drop.data.l[1] = 0; // flags
+ drop.data.l[2] = GET_QT_X_TIME();
+ drop.data.l[3] = 0;
+ drop.data.l[4] = 0;
+
+ TQWidget * w = TQWidget::tqfind( qt_xdnd_current_proxy_target );
+
+ if ( w && w->isDesktop() && !w->acceptDrops() )
+ w = 0;
+
+ if ( w )
+ qt_handle_xdnd_drop( w, (const XEvent *)&drop, FALSE );
+ else
+ XSendEvent( TQPaintDevice::x11AppDisplay(), qt_xdnd_current_proxy_target, False,
+ NoEventMask, (XEvent*)&drop );
+
+#ifndef TQT_NO_CURSOR
+ if ( restoreCursor ) {
+ TQApplication::restoreOverrideCursor();
+ restoreCursor = FALSE;
+ }
+#endif
+}
+
+
+
+bool qt_xdnd_handle_badwindow()
+{
+ if ( qt_xdnd_source_object && qt_xdnd_current_target ) {
+ qt_xdnd_current_target = 0;
+ qt_xdnd_current_proxy_target = 0;
+ delete qt_xdnd_source_object;
+ qt_xdnd_source_object = 0;
+ delete qt_xdnd_deco;
+ qt_xdnd_deco = 0;
+ return TRUE;
+ }
+ if ( qt_xdnd_dragsource_xid ) {
+ qt_xdnd_dragsource_xid = 0;
+ if ( qt_xdnd_current_widget ) {
+ TQDragLeaveEvent e;
+ TQApplication::sendEvent( qt_xdnd_current_widget, &e );
+ qt_xdnd_current_widget = 0;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+/*!
+ \class TQDragMoveEvent tqevent.h
+ \ingroup events
+ \ingroup draganddrop
+ \brief The TQDragMoveEvent class provides an event which is sent while a drag and drop is in progress.
+
+ When a widget \link TQWidget::setAcceptDrops() accepts drop
+ events\endlink, it will receive this event repeatedly while the
+ drag is within the widget's boundaries. The widget should examine
+ the event to see what data it \link TQDragMoveEvent::provides()
+ provides\endlink, and accept() the drop if appropriate.
+
+ Note that this class inherits most of its functionality from
+ TQDropEvent.
+*/
+
+
+/*!
+ Returns TRUE if this event provides format \a mimeType; otherwise
+ returns FALSE.
+
+ \sa data()
+*/
+
+bool TQDropEvent::provides( const char *mimeType ) const
+{
+ if ( qt_motifdnd_active && qstrnicmp( mimeType, "text/", 5 ) == 0 )
+ return TRUE;
+
+ int n=0;
+ const char* f;
+ do {
+ f = format( n );
+ if ( !f )
+ return FALSE;
+ n++;
+ } while( qstricmp( mimeType, f ) );
+ return TRUE;
+}
+
+void qt_xdnd_handle_selection_request( const XSelectionRequestEvent * req )
+{
+ if ( !req )
+ return;
+ XEvent evt;
+ evt.xselection.type = SelectionNotify;
+ evt.xselection.display = req->display;
+ evt.xselection.requestor = req->requestor;
+ evt.xselection.selection = req->selection;
+ evt.xselection.target = req->target;
+ evt.xselection.property = None;
+ evt.xselection.time = req->time;
+ const char* format = qt_xdnd_atom_to_str( req->target );
+ if ( format && qt_xdnd_source_object &&
+ qt_xdnd_source_object->provides( format ) ) {
+ TQByteArray a = qt_xdnd_source_object->tqencodedData(format);
+ XChangeProperty ( TQPaintDevice::x11AppDisplay(), req->requestor, req->property,
+ req->target, 8, PropModeReplace,
+ (unsigned char *)a.data(), a.size() );
+ evt.xselection.property = req->property;
+ }
+ // ### this can die if req->requestor crashes at the wrong
+ // ### moment
+ XSendEvent( TQPaintDevice::x11AppDisplay(), req->requestor, False, 0, &evt );
+}
+
+/*
+ XChangeProperty ( TQPaintDevice::x11AppDisplay(), req->requestor, req->property,
+ XA_STRING, 8,
+ PropModeReplace,
+ (uchar *)d->text(), strlen(d->text()) );
+ evt.xselection.property = req->property;
+*/
+
+static TQByteArray qt_xdnd_obtain_data( const char *format )
+{
+ TQByteArray result;
+
+ TQWidget* w;
+ if ( qt_xdnd_dragsource_xid && qt_xdnd_source_object &&
+ (w=TQWidget::tqfind( qt_xdnd_dragsource_xid ))
+ && (!w->isDesktop() || w->acceptDrops()) )
+ {
+ TQDragObject * o = qt_xdnd_source_object;
+ if ( o->provides( format ) )
+ result = o->tqencodedData(format);
+ return result;
+ }
+
+ Atom * a = qt_xdnd_str_to_atom( format );
+ if ( !a || !*a )
+ return result;
+
+ if ( !qt_xdnd_target_data )
+ qt_xdnd_target_data = new TQIntDict<TQByteArray>( 17 );
+
+ if ( qt_xdnd_target_data->tqfind( (int)*a ) ) {
+ result = *(qt_xdnd_target_data->tqfind( (int)*a ));
+ } else {
+ if ( XGetSelectionOwner( TQPaintDevice::x11AppDisplay(),
+ qt_xdnd_selection ) == None )
+ return result; // should never happen?
+
+ TQWidget* tw = qt_xdnd_current_widget;
+ if ( !qt_xdnd_current_widget ||
+ qt_xdnd_current_widget->isDesktop() ) {
+ tw = new TQWidget;
+ }
+ XConvertSelection( TQPaintDevice::x11AppDisplay(),
+ qt_xdnd_selection,
+ *a,
+ qt_xdnd_selection,
+ tw->winId(),
+ qt_xdnd_target_current_time );
+ XFlush( TQPaintDevice::x11AppDisplay() );
+
+ XEvent xevent;
+ bool got=qt_xclb_wait_for_event( TQPaintDevice::x11AppDisplay(),
+ tw->winId(),
+ SelectionNotify, &xevent, 5000);
+ if ( got ) {
+ Atom type;
+
+ if ( qt_xclb_read_property( TQPaintDevice::x11AppDisplay(),
+ tw->winId(),
+ qt_xdnd_selection, TRUE,
+ &result, 0, &type, 0, FALSE ) ) {
+ if ( type == qt_incr_atom ) {
+ int nbytes = result.size() >= 4 ? *((int*)result.data()) : 0;
+ result = qt_xclb_read_incremental_property( TQPaintDevice::x11AppDisplay(),
+ tw->winId(),
+ qt_xdnd_selection,
+ nbytes, FALSE );
+ } else if ( type != *a ) {
+ // (includes None) qDebug( "TQt clipboard: unknown atom %ld", type);
+ }
+#if 0
+ // this needs to be matched by a qt_xdnd_target_data->clear()
+ // when each drag is finished. for 2.0, we do the safe thing
+ // and disable the entire caching.
+ if ( type != None )
+ qt_xdnd_target_data->insert( (int)((long)a), new TQByteArray(result) );
+#endif
+ }
+ }
+ if ( !qt_xdnd_current_widget ||
+ qt_xdnd_current_widget->isDesktop() ) {
+ delete tw;
+ }
+ }
+
+ return result;
+}
+
+
+/*
+ Enable drag and drop for widget w by installing the proper
+ properties on w's toplevel widget.
+*/
+bool qt_dnd_enable( TQWidget* w, bool on )
+{
+ w = w->tqtopLevelWidget();
+
+ if ( on ) {
+ if ( ( (TQExtraWidget*)w)->topData()->dnd )
+ return TRUE; // been there, done that
+ ((TQExtraWidget*)w)->topData()->dnd = 1;
+ }
+
+ qt_motifdnd_enable( w, on );
+ return qt_xdnd_enable( w, on );
+}
+
+
+/*!
+ \class TQDropEvent tqevent.h
+ \ingroup events
+ \ingroup draganddrop
+
+ \brief The TQDropEvent class provides an event which is sent when a drag and drop is completed.
+
+ When a widget \link TQWidget::setAcceptDrops() accepts drop
+ events\endlink, it will receive this event if it has accepted the
+ most recent TQDragEnterEvent or TQDragMoveEvent sent to it.
+
+ The widget should use data() to extract the data in an appropriate
+ format.
+*/
+
+
+/*!
+ \fn TQDropEvent::TQDropEvent (const TQPoint & pos, Type typ)
+
+ Constructs a drop event that drops a drop of type \a typ on point
+ \a pos.
+*/ // ### pos is in which coordinate system?
+
+
+/*!
+ Returns a byte array containing the drag's data, in \a format.
+
+ data() normally needs to get the data from the drag source, which
+ is potentially very slow, so it's advisable to call this function
+ only if you're sure that you will need the data in \a format.
+
+ The resulting data will have a size of 0 if the format was not
+ available.
+
+ \sa format() TQByteArray::size()
+*/
+
+TQByteArray TQDropEvent::tqencodedData( const char *format ) const
+{
+ if ( qt_motifdnd_active )
+ return qt_motifdnd_obtain_data( format );
+ return qt_xdnd_obtain_data( format );
+}
+
+/*!
+ Returns a string describing one of the available data types for
+ this drag. Common examples are "text/plain" and "image/gif". If \a
+ n is less than zero or greater than the number of available data
+ types, format() returns 0.
+
+ This function is provided mainly for debugging. Most drop targets
+ will use provides().
+
+ \sa data() provides()
+*/
+
+const char* TQDropEvent::format( int n ) const
+{
+ if ( qt_motifdnd_active )
+ return qt_motifdnd_format( n );
+
+ int i = 0;
+ while( i<n && qt_xdnd_types[i] )
+ i++;
+ if ( i < n )
+ return 0;
+
+ const char* name = qt_xdnd_atom_to_str( qt_xdnd_types[i] );
+ if ( !name )
+ return 0; // should never happen
+
+ return name;
+}
+
+bool TQDragManager::drag( TQDragObject * o, TQDragObject::DragMode mode )
+{
+ if ( object == o || !o || !o->tqparent() )
+ return FALSE;
+
+ if ( object ) {
+ cancel();
+ tqApp->removeEventFilter( this );
+ beingCancelled = FALSE;
+ }
+
+ if ( qt_xdnd_source_object ) {
+ // the last drag and drop operation hasn't finished, so we are going to wait
+ // for one second to see if it does... if the finish message comes after this,
+ // then we could still have problems, but this is highly unlikely
+ TQApplication::flushX();
+
+ TQTime started = TQTime::currentTime();
+ TQTime now = started;
+ do {
+ XEvent event;
+ if ( XCheckTypedEvent( TQPaintDevice::x11AppDisplay(),
+ ClientMessage, &event ) )
+ tqApp->x11ProcessEvent( &event );
+
+ now = TQTime::currentTime();
+ if ( started > now ) // crossed midnight
+ started = now;
+
+ // sleep 50ms, so we don't use up CPU cycles all the time.
+ struct timeval usleep_tv;
+ usleep_tv.tv_sec = 0;
+ usleep_tv.tv_usec = 50000;
+ select(0, 0, 0, 0, &usleep_tv);
+ } while ( qt_xdnd_source_object && started.msecsTo(now) < 1000 );
+ }
+
+ qt_xdnd_source_object = o;
+ qt_xdnd_source_object->setTarget( 0 );
+ qt_xdnd_deco = new TQShapedPixmapWidget();
+
+ willDrop = FALSE;
+
+ object = o;
+ updatePixmap();
+
+ dragSource = (TQWidget *)(object->tqparent());
+
+ tqApp->installEventFilter( this );
+ qt_xdnd_source_current_time = GET_QT_X_TIME();
+ XSetSelectionOwner( TQPaintDevice::x11AppDisplay(), qt_xdnd_selection,
+ dragSource->tqtopLevelWidget()->winId(),
+ qt_xdnd_source_current_time );
+ oldstate = TQt::ButtonState(-1); // #### Should use state that caused the drag
+ drag_mode = mode;
+ global_accepted_action = TQDropEvent::Copy;
+ updateMode(TQt::ButtonState(0));
+ qt_xdnd_source_sameanswer = TQRect();
+ move(TQCursor::pos());
+ heartbeat = startTimer(200);
+
+#ifndef TQT_NO_CURSOR
+ tqApp->setOverrideCursor( Qt::ArrowCursor );
+ restoreCursor = TRUE;
+ updateCursor();
+#endif
+
+ dndCancelled = FALSE;
+ qt_xdnd_dragging = TRUE;
+
+ if (!TQWidget::mouseGrabber())
+ qt_xdnd_deco->grabMouse();
+
+ tqApp->enter_loop(); // Do the DND.
+
+#ifndef TQT_NO_CURSOR
+ tqApp->restoreOverrideCursor();
+#endif
+
+ delete qt_xdnd_deco;
+ qt_xdnd_deco = 0;
+ killTimer( heartbeat );
+ heartbeat = -1;
+ qt_xdnd_current_screen = -1;
+ qt_xdnd_dragging = FALSE;
+
+ return ((! dndCancelled) && // source del?
+ (global_accepted_action == TQDropEvent::Copy &&
+ global_requested_action == TQDropEvent::Move));
+
+ // qt_xdnd_source_object persists until we get an xdnd_finish message
+}
+
+void TQDragManager::updatePixmap()
+{
+ if ( qt_xdnd_deco ) {
+ TQPixmap pm;
+ TQPoint pm_hot(default_pm_hotx,default_pm_hoty);
+ if ( object ) {
+ pm = object->pixmap();
+ if ( !pm.isNull() )
+ pm_hot = object->pixmapHotSpot();
+ }
+ if ( pm.isNull() ) {
+ if ( !defaultPm )
+ defaultPm = new TQPixmap(default_pm);
+ pm = *defaultPm;
+ }
+ qt_xdnd_deco->setPixmap(pm);
+ qt_xdnd_deco->move(TQCursor::pos()-pm_hot);
+ qt_xdnd_deco->tqrepaint(FALSE);
+ //if ( willDrop ) {
+ qt_xdnd_deco->show();
+ //} else {
+ // qt_xdnd_deco->hide();
+ //}
+ }
+}
+
+#endif // TQT_NO_DRAGANDDROP
diff --git a/tqtinterface/qt4/src/kernel/tqdragobject.cpp b/tqtinterface/qt4/src/kernel/tqdragobject.cpp
new file mode 100644
index 0000000..6e58f84
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdragobject.cpp
@@ -0,0 +1,3378 @@
+#include "tqtglobaldefines.h"
+
+// #ifdef USE_QT4
+#if 0
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformdefs.h"
+
+#ifndef QT_NO_MIME
+
+#include "tqdragobject.h"
+#include "qpixmap.h"
+#include "qevent.h"
+#include "qfile.h"
+#include "qtextcodec.h"
+#include "qapplication.h"
+#include "qpoint.h"
+#include "qwidget.h"
+#include "qbuffer.h"
+#include "qimagereader.h"
+#include "qimagewriter.h"
+#include "qimage.h"
+#include "qregexp.h"
+#include "qdir.h"
+#include "qdrag.h"
+#include "tqstrlist.h"
+#include "tqcstring.h"
+
+// #include <private/qobject_p.h>
+
+#include <ctype.h>
+#if defined(Q_OS_WINCE)
+#include <winsock.h>
+#include "qfunctions_wince.h"
+#endif
+
+QT_BEGIN_NAMESPACE
+
+static QWidget *last_target = 0;
+
+class QDragMime;
+
+class TQDragObjectPrivate : public TQObjectPrivate
+{
+ Q_DECLARE_PUBLIC(TQDragObject)
+public:
+ TQDragObjectPrivate(): hot(0,0),pm_cursor(0) {}
+ QPixmap pixmap;
+ QPoint hot;
+ // store default cursors
+ QPixmap *pm_cursor;
+};
+
+class TQTextDragPrivate : public TQDragObjectPrivate
+{
+ Q_DECLARE_PUBLIC(TQTextDrag)
+public:
+ TQTextDragPrivate() { setSubType(QLatin1String("plain")); }
+ void setSubType(const QString & st) {
+ subtype = st;
+ fmt = "text/" + subtype.toLatin1();
+ }
+
+ QString txt;
+ QString subtype;
+ QByteArray fmt;
+};
+
+class TQStoredDragPrivate : public TQDragObjectPrivate
+{
+ Q_DECLARE_PUBLIC(TQStoredDrag)
+public:
+ TQStoredDragPrivate() {}
+ const char* fmt;
+ QByteArray enc;
+};
+
+class TQImageDragPrivate : public TQDragObjectPrivate
+{
+ Q_DECLARE_PUBLIC(TQImageDrag)
+public:
+ TQImage img;
+ QList<QByteArray> ofmts;
+};
+
+class QDragMime : public QMimeData
+{
+public:
+ QDragMime(TQDragObject *parent) : QMimeData(), dragObject(parent) { }
+ ~QDragMime();
+
+ QByteArray data(const QString &mimetype) const;
+ bool hasFormat(const QString &mimetype) const;
+ QStringList formats() const;
+
+ QPointer<TQDragObject> dragObject;
+};
+
+QDragMime::~QDragMime()
+{
+ delete dragObject;
+}
+QByteArray QDragMime::data(const QString &mimetype) const
+{
+ return dragObject->encodedData(mimetype.latin1());
+}
+
+bool QDragMime::hasFormat(const QString &mimetype) const
+{
+ return dragObject->provides(mimetype.latin1());
+}
+
+QStringList QDragMime::formats() const
+{
+ int i = 0;
+ const char *format;
+ QStringList f;
+ while ((format = dragObject->format(i))) {
+ f.append(QLatin1String(format));
+ ++i;
+ }
+ return f;
+}
+
+/*!
+ Constructs a drag object called \a name with a parent \a
+ dragSource.
+
+ Note that the drag object will be deleted when the \a dragSource is
+ deleted.
+*/
+
+TQDragObject::TQDragObject(QWidget * dragSource, const char * name)
+ :TQObject(*(new TQDragObjectPrivate), dragSource)
+{
+ setObjectName(QLatin1String(name));
+}
+
+/*! \internal */
+TQDragObject::TQDragObject(TQDragObjectPrivate &dd, QWidget *dragSource)
+ :TQObject(dd, dragSource)
+{
+}
+
+/*!
+ Destroys the drag object, canceling any drag and drop operation in
+ which it is involved.
+*/
+
+TQDragObject::~TQDragObject()
+{
+}
+
+#ifndef QT_NO_DRAGANDDROP
+/*!
+ Set the pixmap, \a pm, to display while dragging the object. The
+ platform-specific implementation will use this where it can - so
+ provide a small masked pixmap, and do not assume that the user
+ will actually see it.
+
+ The \a hotspot is the point on (or off) the pixmap that should be
+ under the cursor as it is dragged. It is relative to the top-left
+ pixel of the pixmap.
+
+ \warning We have seen problems with drag cursors on different
+ graphics hardware and driver software on Windows. Setting the
+ graphics acceleration in the display settings down one tick solved
+ the problems in all cases.
+*/
+void TQDragObject::setPixmap(QPixmap pm, const QPoint& hotspot)
+{
+ Q_D(TQDragObject);
+ d->pixmap = pm;
+ d->hot = hotspot;
+}
+
+/*!
+ \overload
+
+ Uses a hotspot that positions the pixmap below and to the right of
+ the mouse pointer. This allows the user to clearly see the point
+ on the window where they are dragging the data.
+*/
+void TQDragObject::setPixmap(QPixmap pm)
+{
+ setPixmap(pm,QPoint(-10, -10));
+}
+
+/*!
+ Returns the currently set pixmap, or a null pixmap if none is set.
+
+ \sa QPixmap::isNull()
+*/
+QPixmap TQDragObject::pixmap() const
+{
+ return d_func()->pixmap;
+}
+
+/*!
+ Returns the currently set pixmap hotspot.
+
+ \sa setPixmap()
+*/
+QPoint TQDragObject::pixmapHotSpot() const
+{
+ return d_func()->hot;
+}
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ DragDefault mode.
+
+ The function returns true if the caller should delete the original
+ copy of the dragged data (but see target()); otherwise returns
+ false.
+
+ If the drag contains \e references to information (e.g. file names
+ in a TQUriDrag are references) then the return value should always
+ be ignored, as the target is expected to directly manipulate the
+ content referred to by the drag object. On X11 the return value should
+ always be correct anyway, but on Windows this is not necessarily
+ the case; e.g. the file manager starts a background process to
+ move files, so the source \e{must not} delete the files!
+
+ Note that on Windows the drag operation will start a blocking modal
+ event loop that will not dispatch any QTimers.
+*/
+bool TQDragObject::drag()
+{
+ return drag(DragDefault);
+}
+
+/*!
+ After the drag completes, this function will return the QWidget
+ which received the drop, or 0 if the data was dropped on another
+ application.
+
+ This can be useful for detecting the case where drag and drop is
+ to and from the same widget.
+*/
+QWidget *TQDragObject::target()
+{
+ return last_target;
+}
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ \c DragMove mode. Be sure to read the constraints described in
+ drag().
+
+ Returns true if the data was dragged as a \e move, indicating that
+ the caller should remove the original source of the data (the drag
+ object must continue to have a copy); otherwise returns false.
+
+ \sa drag() dragCopy() dragLink()
+*/
+bool TQDragObject::dragMove()
+{
+ return drag(DragMove);
+}
+
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ \c DragCopy mode. Be sure to read the constraints described in
+ drag().
+
+ \sa drag() dragMove() dragLink()
+*/
+void TQDragObject::dragCopy()
+{
+ (void)drag(DragCopy);
+}
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ \c DragLink mode. Be sure to read the constraints described in
+ drag().
+
+ \sa drag() dragCopy() dragMove()
+*/
+void TQDragObject::dragLink()
+{
+ (void)drag(DragLink);
+}
+
+
+/*!
+ \enum TQDragObject::DragMode
+
+ This enum describes the possible drag modes.
+
+ \value DragDefault The mode is determined heuristically.
+ \value DragCopy The data is copied.
+ \value DragMove The data is moved.
+ \value DragLink The data is linked.
+ \value DragCopyOrMove The user chooses the mode by using the
+ \key{Shift} key to switch from the default
+ copy mode to move mode.
+*/
+
+
+/*!
+ \overload
+ Starts a drag operation using the contents of this object.
+
+ At this point, the object becomes owned by Qt, not the
+ application. You should not delete the drag object or anything it
+ references. The actual transfer of data to the target application
+ will be done during future event processing - after that time the
+ drag object will be deleted.
+
+ Returns true if the dragged data was dragged as a \e move,
+ indicating that the caller should remove the original source of
+ the data (the drag object must continue to have a copy); otherwise
+ returns false.
+
+ The \a mode specifies the drag mode (see
+ \l{TQDragObject::DragMode}.) Normally one of the simpler drag(),
+ dragMove(), or dragCopy() functions would be used instead.
+*/
+bool TQDragObject::drag(DragMode mode)
+{
+ Q_D(TQDragObject);
+ QDragMime *data = new QDragMime(this);
+ int i = 0;
+ const char *fmt;
+ while ((fmt = format(i))) {
+ data->setData(QLatin1String(fmt), encodedData(fmt));
+ ++i;
+ }
+
+ QDrag *drag = new QDrag(qobject_cast<QWidget *>(parent()));
+ drag->setMimeData(data);
+ drag->setPixmap(d->pixmap);
+ drag->setHotSpot(d->hot);
+
+ Qt::DropActions allowedOps;
+ Qt::DropAction defaultOp = Qt::IgnoreAction;
+ switch(mode) {
+ default:
+ case DragDefault:
+ case DragCopyOrMove:
+ allowedOps = Qt::CopyAction|Qt::MoveAction;
+ defaultOp = Qt::IgnoreAction;
+ break;
+ case DragCopy:
+ allowedOps = Qt::CopyAction;
+ defaultOp = Qt::CopyAction;
+ break;
+ case DragMove:
+ allowedOps = Qt::MoveAction;
+ defaultOp = Qt::MoveAction;
+ break;
+ case DragLink:
+ allowedOps = Qt::LinkAction;
+ defaultOp = Qt::LinkAction;
+ break;
+ }
+ bool retval = (drag->exec(allowedOps, defaultOp) == Qt::MoveAction);
+ last_target = drag->target();
+
+ return retval;
+}
+
+#endif
+
+
+/*!
+ Returns a pointer to the widget where this object originated (the drag
+ source).
+*/
+
+QWidget * TQDragObject::source()
+{
+ if (parent() && parent()->isWidgetType())
+ return (QWidget *)parent();
+ else
+ return 0;
+}
+
+
+/*!
+ \class TQDragObject
+
+ \brief The TQDragObject class encapsulates MIME-based data
+ transfer.
+
+ \compat
+
+ TQDragObject is the base class for all data that needs to be
+ transferred between and within applications, both for drag and
+ drop and for the clipboard.
+
+ See the \link dnd.html Drag and drop documentation\endlink for an
+ overview of how to provide drag and drop in your application.
+
+ See the QClipboard documentation for an overview of how to provide
+ cut and paste in your application.
+
+ The drag() function is used to start a drag operation. You can
+ specify the \l DragMode in the call or use one of the convenience
+ functions dragCopy(), dragMove(), or dragLink(). The drag source
+ where the data originated is retrieved with source(). If the data
+ was dropped on a widget within the application, target() will
+ return a pointer to that widget. Specify the pixmap to display
+ during the drag with setPixmap().
+*/
+
+static
+void stripws(QByteArray& s)
+{
+ int f;
+ while ((f = s.indexOf(' ')) >= 0)
+ s.remove(f,1);
+}
+
+/*!
+ \class TQTextDrag
+
+ \brief The TQTextDrag class is a drag and drop object for
+ transferring plain and Unicode text.
+
+ \compat
+
+ Plain text is passed in a QString which may contain multiple lines
+ (i.e. may contain newline characters). The drag target will receive
+ the newlines according to the runtime environment, e.g. LF on Unix,
+ and CRLF on Windows.
+
+ Qt provides no built-in mechanism for delivering only a single-line.
+
+ For more information about drag and drop, see the TQDragObject class
+ and the \link dnd.html drag and drop documentation\endlink.
+*/
+
+
+/*!
+ Constructs a text drag object with the given \a name, and sets its data
+ to \a text. The \a dragSource is the widget that the drag operation started
+ from.
+*/
+
+TQTextDrag::TQTextDrag(const QString &text, QWidget * dragSource, const char * name)
+ : TQDragObject(*new TQTextDragPrivate, dragSource)
+{
+ setObjectName(QLatin1String(name));
+ setText(text);
+}
+
+
+/*!
+ Constructs a default text drag object with the given \a name.
+ The \a dragSource is the widget that the drag operation started from.
+*/
+
+TQTextDrag::TQTextDrag(QWidget * dragSource, const char * name)
+ : TQDragObject(*(new TQTextDragPrivate), dragSource)
+{
+ setObjectName(QLatin1String(name));
+}
+
+/*! \internal */
+TQTextDrag::TQTextDrag(TQTextDragPrivate &dd, QWidget *dragSource)
+ : TQDragObject(dd, dragSource)
+{
+
+}
+
+/*!
+ Destroys the text drag object.
+*/
+TQTextDrag::~TQTextDrag()
+{
+
+}
+
+/*!
+ \fn void TQTextDrag::setSubtype(const QString &subtype)
+
+ Sets the MIME \a subtype of the text being dragged. The default subtype
+ is "plain", so the default MIME type of the text is "text/plain".
+ You might use this to declare that the text is "text/html" by calling
+ setSubtype("html").
+*/
+void TQTextDrag::setSubtype(const QString & st)
+{
+ d_func()->setSubType(st);
+}
+
+/*!
+ Sets the \a text to be dragged. You will need to call this if you did
+ not pass the text during construction.
+*/
+void TQTextDrag::setText(const QString &text)
+{
+ d_func()->txt = text;
+}
+
+
+/*!
+ \reimp
+*/
+const char * TQTextDrag::format(int i) const
+{
+ if (i > 0)
+ return 0;
+ return d_func()->fmt.constData();
+}
+
+QTextCodec* qt_findcharset(const QByteArray& mimetype)
+{
+ int i=mimetype.indexOf("charset=");
+ if (i >= 0) {
+ QByteArray cs = mimetype.mid(i+8);
+ stripws(cs);
+ i = cs.indexOf(';');
+ if (i >= 0)
+ cs = cs.left(i);
+ // May return 0 if unknown charset
+ return QTextCodec::codecForName(cs);
+ }
+ // no charset=, use locale
+ return QTextCodec::codecForName("utf-8");
+}
+
+static QTextCodec *codecForHTML(const QByteArray &ba)
+{
+ // determine charset
+ int mib = 0;
+ int pos;
+ QTextCodec *c = 0;
+
+ if (ba.size() > 1 && (((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff)
+ || ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe))) {
+ mib = 1015; // utf16
+ } else if (ba.size() > 2
+ && (uchar)ba[0] == 0xef
+ && (uchar)ba[1] == 0xbb
+ && (uchar)ba[2] == 0xbf) {
+ mib = 106; // utf-8
+ } else {
+ pos = 0;
+ while ((pos = ba.indexOf('<', pos)) != -1) {
+ int end = ba.indexOf('>', pos+1);
+ if (end == -1)
+ break;
+ const QString str(QString::fromLatin1(ba.mid(pos, end-pos)));
+ if (str.contains(QLatin1String("meta http-equiv="), Qt::CaseInsensitive)) {
+ pos = str.indexOf(QLatin1String("charset="), 0, Qt::CaseInsensitive) + int(strlen("charset="));
+ if (pos != -1) {
+ int pos2 = ba.indexOf('\"', pos+1);
+ QByteArray cs = ba.mid(pos, pos2-pos);
+ c = QTextCodec::codecForName(cs);
+ if (c)
+ return c;
+ }
+ }
+ pos = end;
+ }
+ }
+ if (mib)
+ c = QTextCodec::codecForMib(mib);
+
+ return c;
+}
+
+static
+QTextCodec* findcodec(const QMimeSource* e)
+{
+ QTextCodec* r = 0;
+ const char* f;
+ int i;
+ for (i=0; (f=e->format(i)); i++) {
+ bool html = !qstrnicmp(f, "text/html", 9);
+ if (html)
+ r = codecForHTML(e->encodedData(f));
+ if (!r)
+ r = qt_findcharset(QByteArray(f).toLower());
+ if (r)
+ return r;
+ }
+ return 0;
+}
+
+
+
+/*!
+ \reimp
+*/
+QByteArray TQTextDrag::encodedData(const char* mime) const
+{
+ Q_D(const TQTextDrag);
+ if (mime != d->fmt)
+ return QByteArray();
+ return d->txt.toUtf8();
+}
+
+/*!
+ \fn bool TQTextDrag::canDecode(const QMimeSource *source)
+
+ Returns true if the information in the MIME \a source can be decoded
+ into a QString; otherwise returns false.
+
+ \sa decode()
+*/
+bool TQTextDrag::canDecode(const QMimeSource* e)
+{
+ const char* f;
+ for (int i=0; (f=e->format(i)); i++) {
+ if (0==qstrnicmp(f,"text/",5)) {
+ return findcodec(e) != 0;
+ }
+ }
+ return false;
+}
+
+/*!
+ \fn bool TQTextDrag::decode(const QMimeSource *source, QString &string, QString &subtype)
+
+ \overload
+
+ Attempts to decode the dropped information in the MIME \a source into
+ the \a string given.
+ Returns true if successful; otherwise returns false. If \a subtype
+ is null, any text subtype is accepted; otherwise only the
+ specified \a subtype is accepted.
+
+ \sa canDecode()
+*/
+bool TQTextDrag::decode(const QMimeSource* e, QString& str, QString& subtype)
+{
+ if(!e)
+ return false;
+
+ const char* mime;
+ for (int i=0; (mime = e->format(i)); i++) {
+ if (0==qstrnicmp(mime,"text/",5)) {
+ QByteArray m(mime);
+ m = m.toLower();
+ int semi = m.indexOf(';');
+ if (semi < 0)
+ semi = m.length();
+ QString foundst(QString::fromLatin1(m.mid(5,semi-5)));
+ if (subtype.isNull() || foundst == subtype) {
+ bool html = !qstrnicmp(mime, "text/html", 9);
+ QTextCodec* codec = 0;
+ if (html)
+ // search for the charset tag in the HTML
+ codec = codecForHTML(e->encodedData(mime));
+ if (!codec)
+ codec = qt_findcharset(m);
+ if (codec) {
+ QByteArray payload;
+
+ payload = e->encodedData(mime);
+ if (payload.size()) {
+ int l;
+ if (codec->mibEnum() != 1015) {
+ // length is at NUL or payload.size()
+ l = 0;
+ while (l < (int)payload.size() && payload[l])
+ l++;
+ } else {
+ l = payload.size();
+ }
+
+ str = codec->toUnicode(payload,l);
+
+ if (subtype.isNull())
+ subtype = foundst;
+
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+}
+
+/*!
+ \fn bool TQTextDrag::decode(const QMimeSource *source, QString &string)
+
+ Attempts to decode the dropped information in the MIME \a source into
+ the \a string given.
+ Returns true if successful; otherwise returns false.
+
+ \sa canDecode()
+*/
+bool TQTextDrag::decode(const QMimeSource* e, QString& str)
+{
+ QString st;
+ return decode(e, str, st);
+}
+
+
+/*
+ TQImageDrag could use an internal MIME type for communicating QPixmaps
+ and TQImages rather than always converting to raw data. This is available
+ for that purpose and others. It is not currently used.
+*/
+
+/*!
+ \class TQImageDrag
+
+ \brief The TQImageDrag class provides a drag and drop object for
+ transferring images.
+
+ \compat
+
+ Images are offered to the receiving application in multiple
+ formats, determined by Qt's output formats.
+*/
+
+/*!
+ Constructs an image drag object with the given \a name, and sets its
+ data to \a image. The \a dragSource is the widget that the drag operation
+ started from.
+*/
+
+TQImageDrag::TQImageDrag(TQImage image,
+ QWidget * dragSource, const char * name)
+ : TQDragObject(*(new TQImageDragPrivate), dragSource)
+{
+ setObjectName(QLatin1String(name));
+ setImage(image);
+}
+
+/*!
+ Constructs a default image drag object with the given \a name.
+ The \a dragSource is the widget that the drag operation started from.
+*/
+
+TQImageDrag::TQImageDrag(QWidget * dragSource, const char * name)
+ : TQDragObject(*(new TQImageDragPrivate), dragSource)
+{
+ setObjectName(QLatin1String(name));
+}
+
+/*! \internal */
+TQImageDrag::TQImageDrag(TQImageDragPrivate &dd, QWidget *dragSource)
+ : TQDragObject(dd, dragSource)
+{
+}
+
+/*!
+ Destroys the image drag object.
+*/
+
+TQImageDrag::~TQImageDrag()
+{
+ // nothing
+}
+
+
+/*!
+ Sets the \a image to be dragged. You will need to call this if you did
+ not pass the image during construction.
+*/
+void TQImageDrag::setImage(TQImage image)
+{
+ Q_D(TQImageDrag);
+ d->img = image;
+ QList<QByteArray> formats = QImageWriter::supportedImageFormats();
+ formats.removeAll("PBM"); // remove non-raw PPM
+ if (image.depth()!=32) {
+ // BMP better than PPM for paletted images
+ if (formats.removeAll("BMP")) // move to front
+ formats.insert(0,"BMP");
+ }
+ // PNG is best of all
+ if (formats.removeAll("PNG")) // move to front
+ formats.insert(0,"PNG");
+
+ for(int i = 0; i < formats.count(); i++) {
+ QByteArray format("image/");
+ format += formats.at(i);
+ format = format.toLower();
+ if (format == "image/pbmraw")
+ format = "image/ppm";
+ d->ofmts.append(format);
+ }
+ d->ofmts.append("application/x-qt-image");
+}
+
+/*!
+ \reimp
+*/
+const char * TQImageDrag::format(int i) const
+{
+ Q_D(const TQImageDrag);
+ return i < d->ofmts.count() ? d->ofmts.at(i).data() : 0;
+}
+
+/*!
+ \reimp
+*/
+QByteArray TQImageDrag::encodedData(const char* fmt) const
+{
+ Q_D(const TQImageDrag);
+ QString imgFormat(fmt);
+ if (imgFormat == QLatin1String("application/x-qt-image"))
+ imgFormat = QLatin1String("image/PNG");
+
+ if (imgFormat.startsWith("image/")){
+ QByteArray f(imgFormat.mid(6).toAscii());
+ QByteArray dat;
+ QBuffer w(&dat);
+ w.open(QIODevice::WriteOnly);
+ QImageWriter writer(&w, f.toUpper());
+ if (!writer.write(d->img))
+ return QByteArray();
+ w.close();
+ return dat;
+ } else {
+ return QByteArray();
+ }
+}
+
+/*!
+ \fn bool TQImageDrag::canDecode(const QMimeSource *source)
+
+ Returns true if the information in the MIME \a source can be decoded
+ into an image; otherwise returns false.
+
+ \sa decode()
+*/
+bool TQImageDrag::canDecode(const QMimeSource* e)
+{
+ return e->provides("application/x-qt-image");
+}
+
+/*!
+ \fn bool TQImageDrag::decode(const QMimeSource *source, QImage &image)
+
+ Decode the dropped information in the MIME \a source into the \a image.
+ Returns true if successful; otherwise returns false.
+
+ \sa canDecode()
+*/
+bool TQImageDrag::decode(const QMimeSource* e, QImage& img)
+{
+ if (!e)
+ return false;
+
+ QByteArray payload = e->encodedData("application/x-qt-image");
+ if (payload.isEmpty())
+ return false;
+
+ img.loadFromData(payload);
+ if (img.isNull())
+ return false;
+
+ return true;
+}
+
+/*!
+ \fn bool TQImageDrag::decode(const QMimeSource *source, QPixmap &pixmap)
+
+ \overload
+
+ Decodes the dropped information in the MIME \a source into the \a pixmap.
+ Returns true if successful; otherwise returns false.
+
+ This is a convenience function that converts the information to a QPixmap
+ via a QImage.
+
+ \sa canDecode()
+*/
+bool TQImageDrag::decode(const QMimeSource* e, QPixmap& pm)
+{
+ if (!e)
+ return false;
+
+ QImage img;
+ // We avoid dither, since the image probably came from this display
+ if (decode(e, img)) {
+ pm = QPixmap::fromImage(img, Qt::AvoidDither);
+ if (pm.isNull())
+ return false;
+
+ return true;
+ }
+ return false;
+}
+
+
+
+
+/*!
+ \class TQStoredDrag
+ \brief The TQStoredDrag class provides a simple stored-value drag object for arbitrary MIME data.
+
+ \compat
+
+ When a block of data has only one representation, you can use a
+ TQStoredDrag to hold it.
+
+ For more information about drag and drop, see the TQDragObject
+ class and the \link dnd.html drag and drop documentation\endlink.
+*/
+
+/*!
+ Constructs a TQStoredDrag. The \a dragSource and \a name are passed
+ to the TQDragObject constructor, and the format is set to \a
+ mimeType.
+
+ The data will be unset. Use setEncodedData() to set it.
+*/
+TQStoredDrag::TQStoredDrag(const char* mimeType, QWidget * dragSource, const char * name) :
+ TQDragObject(*new TQStoredDragPrivate, dragSource)
+{
+ Q_D(TQStoredDrag);
+ setObjectName(QLatin1String(name));
+ d->fmt = qstrdup(mimeType);
+}
+
+/*! \internal */
+TQStoredDrag::TQStoredDrag(TQStoredDragPrivate &dd, const char* mimeType, QWidget * dragSource)
+ : TQDragObject(dd, dragSource)
+{
+ d_func()->fmt = qstrdup(mimeType);
+}
+
+/*!
+ Destroys the drag object.
+*/
+TQStoredDrag::~TQStoredDrag()
+{
+ delete [] (char*)d_func()->fmt;
+}
+
+/*!
+ \reimp
+*/
+const char * TQStoredDrag::format(int i) const
+{
+ if (i==0)
+ return d_func()->fmt;
+ else
+ return 0;
+}
+
+
+/*!
+ \fn void TQStoredDrag::setEncodedData(const QByteArray &data)
+
+ Sets the encoded \a data of this drag object. The encoded data is
+ delivered to drop sites; it must be in a strictly defined and portable
+ format.
+
+ The drag object can't be dropped (by the user) until this function
+ has been called.
+*/
+
+void TQStoredDrag::setEncodedData(const QByteArray & encodedData)
+{
+ d_func()->enc = encodedData;
+}
+
+/*!
+ \fn QByteArray TQStoredDrag::encodedData(const char *format) const
+
+ Returns the stored data in the \a format given.
+
+ \sa setEncodedData()
+*/
+QByteArray TQStoredDrag::encodedData(const char* m) const
+{
+ if (!qstricmp(m, d_func()->fmt))
+ return d_func()->enc;
+ else
+ return QByteArray();
+}
+
+
+/*!
+ \class TQUriDrag
+ \brief The TQUriDrag class provides a drag object for a list of URI references.
+
+ \compat
+
+ URIs are a useful way to refer to files that may be distributed
+ across multiple machines. A URI will often refer to a file on a
+ machine local to both the drag source and the drop target, so the
+ URI can be equivalent to passing a file name but is more
+ extensible.
+
+ Use URIs in Unicode form so that the user can comfortably edit and
+ view them. For use in HTTP or other protocols, use the correctly
+ escaped ASCII form.
+
+ You can convert a list of file names to file URIs using
+ setFileNames(), or into human-readable form with setUnicodeUris().
+
+ Static functions are provided to convert between filenames and
+ URIs; e.g. uriToLocalFile() and localFileToUri(). Static functions
+ are also provided to convert URIs to and from human-readable form;
+ e.g. uriToUnicodeUri() and unicodeUriToUri().
+ You can also decode URIs from a MIME source into a list with
+ decodeLocalFiles() and decodeToUnicodeUris().
+*/
+
+/*!
+ Constructs an object to drag the list of \a uris.
+ The \a dragSource and \a name are passed to the TQStoredDrag constructor.
+
+ Note that URIs are always in escaped UTF8 encoding.
+*/
+TQUriDrag::TQUriDrag(const TQStrList &uris, QWidget * dragSource, const char * name) :
+ TQStoredDrag("text/uri-list", dragSource)
+{
+ setObjectName(QLatin1String(name));
+ setUris(uris);
+}
+
+/*!
+ Constructs an object to drag with the given \a name.
+ You must call setUris() before you start the drag().
+ Both the \a dragSource and the \a name are passed to the TQStoredDrag
+ constructor.
+*/
+TQUriDrag::TQUriDrag(QWidget * dragSource, const char * name) :
+ TQStoredDrag("text/uri-list", dragSource)
+{
+ setObjectName(QLatin1String(name));
+}
+#endif
+
+/*!
+ Destroys the URI drag object.
+*/
+TQUriDrag::~TQUriDrag()
+{
+}
+
+/*!
+ \fn void TQUriDrag::setUris(const QList<QByteArray> &list)
+
+ Changes the \a list of URIs to be dragged.
+
+ Note that URIs are always in escaped UTF8 encoding.
+*/
+void TQUriDrag::setUris(const QList<QByteArray> &uris)
+{
+ QByteArray a;
+ int c = 0;
+ int i;
+ int count = uris.count();
+ for (i = 0; i < count; ++i)
+ c += uris.at(i).size() + 2; //length + \r\n
+ a.reserve(c+1);
+ for (i = 0; i < count; ++i) {
+ a.append(uris.at(i));
+ a.append("\r\n");
+ }
+ a[c] = 0;
+ setEncodedData(a);
+}
+
+
+/*!
+ \fn bool TQUriDrag::canDecode(const QMimeSource *source)
+
+ Returns true if decode() can decode the MIME \a source; otherwise
+ returns false.
+*/
+bool TQUriDrag::canDecode(const QMimeSource* e)
+{
+ return e->provides("text/uri-list");
+}
+
+/*!
+ \fn bool TQUriDrag::decode(const QMimeSource* source, TQStrList& list)
+
+ Decodes URIs from the MIME \a source, placing the result in the \a list.
+ The list is cleared before any items are inserted.
+
+ Returns true if the MIME \a source contained a valid list of URIs;
+ otherwise returns false.
+*/
+bool TQUriDrag::decode(const QMimeSource* e, TQStrList& l)
+{
+ QByteArray payload = e->encodedData("text/uri-list");
+ if (payload.size()) {
+ l.clear();
+ l.setAutoDelete(true);
+ uint c=0;
+ const char* data = payload.data();
+ while ((int)c < payload.size() && data[c]) {
+ uint f = c;
+ // Find line end
+ while ((int)c < payload.size() && data[c] && data[c]!='\r'
+ && data[c] != '\n')
+ c++;
+ TQCString s(data+f,c-f+1);
+ if (s[0] != '#') // non-comment?
+ l.append(s);
+ // Skip junk
+ while ((int)c < payload.size() && data[c] &&
+ (data[c]=='\n' || data[c]=='\r'))
+ c++;
+ }
+ return true;
+ }
+ return false;
+}
+
+static uint htod(int h)
+{
+ if (isdigit(h))
+ return h - '0';
+ return tolower(h) - 'a' + 10;
+}
+
+/*!
+ \fn TQUriDrag::setFilenames(const QStringList &list)
+
+ \obsolete
+
+ Sets the filename's in the drag object to those in the given \a
+ list.
+
+ Use setFileNames() instead.
+*/
+
+/*!
+ \fn void TQUriDrag::setFileNames(const QStringList &filenames)
+
+ Sets the URIs to be local file URIs equivalent to the \a filenames.
+
+ \sa localFileToUri(), setUris()
+*/
+void TQUriDrag::setFileNames(const QStringList & fnames)
+{
+ QList<QByteArray> uris;
+ for (QStringList::ConstIterator i = fnames.begin();
+ i != fnames.end(); ++i) {
+ QByteArray fileUri = localFileToUri(*i);
+ if (!fileUri.isEmpty())
+ uris.append(fileUri);
+ }
+
+ setUris(uris);
+}
+
+/*!
+ \fn void TQUriDrag::setFileNames(const QString &name)
+ \fn void TQUriDrag::setFilenames(const QString &name)
+
+ Same as setFileNames(QStringList(\a name)).
+*/
+
+/*!
+ \fn void TQUriDrag::setUnicodeUris(const QStringList &list)
+
+ Sets the URIs in the \a list to be Unicode URIs (only useful for
+ displaying to humans).
+
+ \sa localFileToUri(), setUris()
+*/
+void TQUriDrag::setUnicodeUris(const QStringList & uuris)
+{
+ QList<QByteArray> uris;
+ for (int i = 0; i < uuris.count(); ++i)
+ uris.append(unicodeUriToUri(uuris.at(i)));
+ setUris(uris);
+}
+
+/*!
+ \fn QByteArray TQUriDrag::unicodeUriToUri(const QString &string)
+
+ Returns the URI equivalent of the Unicode URI given in the \a string
+ (only useful for displaying to humans).
+
+ \sa uriToLocalFile()
+*/
+QByteArray TQUriDrag::unicodeUriToUri(const QString& uuri)
+{
+ QByteArray utf8 = uuri.toUtf8();
+ QByteArray escutf8;
+ int n = utf8.length();
+ bool isFile = uuri.startsWith(QLatin1String("file://"));
+ for (int i=0; i<n; i++) {
+ if ((utf8[i] >= 'a' && utf8[i] <= 'z')
+ || utf8[i] == '/'
+ || (utf8[i] >= '0' && utf8[i] <= '9')
+ || (utf8[i] >= 'A' && utf8[i] <= 'Z')
+
+ || utf8[i] == '-' || utf8[i] == '_'
+ || utf8[i] == '.' || utf8[i] == '!'
+ || utf8[i] == '~' || utf8[i] == '*'
+ || utf8[i] == '(' || utf8[i] == ')'
+ || utf8[i] == '\''
+
+ // Allow this through, so that all URI-references work.
+ || (!isFile && utf8[i] == '#')
+
+ || utf8[i] == ';'
+ || utf8[i] == '?' || utf8[i] == ':'
+ || utf8[i] == '@' || utf8[i] == '&'
+ || utf8[i] == '=' || utf8[i] == '+'
+ || utf8[i] == '$' || utf8[i] == ',')
+ {
+ escutf8 += utf8[i];
+ } else {
+ // Everything else is escaped as %HH
+ QString s;
+ s.sprintf("%%%02x",(uchar)utf8[i]);
+ escutf8 += s.latin1();
+ }
+ }
+ return escutf8;
+}
+
+/*!
+ Returns the URI equivalent to the absolute local \a filename.
+
+ \sa uriToLocalFile()
+*/
+QByteArray TQUriDrag::localFileToUri(const QString& filename)
+{
+ QString r = filename;
+
+ //check that it is an absolute file
+ if (QDir::isRelativePath(r))
+ return QByteArray();
+#ifdef Q_WS_WIN
+
+
+ bool hasHost = false;
+ // convert form network path
+ if (r.left(2) == QLatin1String("\\\\") || r.left(2) == QLatin1String("//")) {
+ r.remove(0, 2);
+ hasHost = true;
+ }
+
+ // Slosh -> Slash
+ int slosh;
+ while ((slosh=r.indexOf(QLatin1Char('\\'))) >= 0) {
+ r[slosh] = QLatin1Char('/');
+ }
+
+ // Drive
+ if (r[0] != QLatin1Char('/') && !hasHost)
+ r.insert(0,QLatin1Char('/'));
+
+#endif
+#if defined (Q_WS_X11) && 0
+ // URL without the hostname is considered to be errorneous by XDnD.
+ // See: http://www.newplanetsoftware.com/xdnd/dragging_files.html
+ // This feature is not active because this would break dnd between old and new qt apps.
+ char hostname[257];
+ if (gethostname(hostname, 255) == 0) {
+ hostname[256] = '\0';
+ r.prepend(QString::fromLatin1(hostname));
+ }
+#endif
+ return unicodeUriToUri(QLatin1String("file://") + r);
+}
+
+/*!
+ \fn QString TQUriDrag::uriToUnicodeUri(const char *string)
+
+ Returns the Unicode URI (only useful for displaying to humans)
+ equivalent of the URI given in the \a string.
+
+ Note that URIs are always in escaped UTF8 encoding.
+
+ \sa localFileToUri()
+*/
+QString TQUriDrag::uriToUnicodeUri(const char* uri)
+{
+ QByteArray utf8;
+
+ while (*uri) {
+ switch (*uri) {
+ case '%': {
+ uint ch = (uchar) uri[1];
+ if (ch && uri[2]) {
+ ch = htod(ch) * 16 + htod((uchar) uri[2]);
+ utf8 += (char) ch;
+ uri += 2;
+ }
+ }
+ break;
+ default:
+ utf8 += *uri;
+ }
+ ++uri;
+ }
+
+ return QString::fromUtf8(utf8);
+}
+
+/*!
+ \fn QString TQUriDrag::uriToLocalFile(const char *string)
+
+ Returns the name of a local file equivalent to the URI given in the
+ \a string, or an empty string if it does not refer to a local file.
+
+ Note that URIs are always in escaped UTF8 encoding.
+
+ \sa localFileToUri()
+*/
+QString TQUriDrag::uriToLocalFile(const char* uri)
+{
+ QString file;
+
+ if (!uri)
+ return file;
+ if (0==qstrnicmp(uri,"file:/",6)) // It is a local file uri
+ uri += 6;
+ else if (QString::fromLatin1(uri).indexOf(QLatin1String(":/")) != -1) // It is a different scheme uri
+ return file;
+
+ bool local = uri[0] != '/' || (uri[0] != '\0' && uri[1] == '/');
+#ifdef Q_WS_X11
+ // do we have a hostname?
+ if (!local && uri[0] == '/' && uri[2] != '/') {
+ // then move the pointer to after the 'hostname/' part of the uri
+ const char* hostname_end = strchr(uri+1, '/');
+ if (hostname_end != NULL) {
+ char hostname[257];
+ if (gethostname(hostname, 255) == 0) {
+ hostname[256] = '\0';
+ if (qstrncmp(uri+1, hostname, hostname_end - (uri+1)) == 0) {
+ uri = hostname_end + 1; // point after the slash
+ local = true;
+ }
+ }
+ }
+ }
+#endif
+ if (local) {
+ file = uriToUnicodeUri(uri);
+ if (uri[1] == '/') {
+ file.remove((uint)0,1);
+ } else {
+ file.insert(0, QLatin1Char('/'));
+ }
+#ifdef Q_WS_WIN
+ if (file.length() > 2 && file[0] == QLatin1Char('/') && file[2] == QLatin1Char('|')) {
+ file[2] = QLatin1Char(':');
+ file.remove(0,1);
+ } else if (file.length() > 2 && file[0] == QLatin1Char('/') && file[1].isLetter() && file[2] == QLatin1Char(':')) {
+ file.remove(0, 1);
+ }
+ // Leave slash as slashes.
+#endif
+ }
+#ifdef Q_WS_WIN
+ else {
+ file = uriToUnicodeUri(uri);
+ // convert to network path
+ file.insert(1, QLatin1Char('/')); // leave as forward slashes
+ }
+#endif
+
+ return file;
+}
+
+/*!
+ \fn bool TQUriDrag::decodeLocalFiles(const QMimeSource *source, QStringList &list)
+
+ Decodes URIs from the MIME \a source, converting them to local filenames
+ where possible, and places them in the \a list (which is first cleared).
+
+ Returns true if the MIME \a source contained a valid list of URIs;
+ otherwise returns false. The list will be empty if no URIs referred to
+ local files.
+*/
+bool TQUriDrag::decodeLocalFiles(const QMimeSource* e, QStringList& l)
+{
+ TQStrList u;
+ if (!decode(e, u))
+ return false;
+
+ l.clear();
+ for (uint i = 0; i < u.count(); ++i) {
+ QString lf = uriToLocalFile(u.at(i));
+ if (!lf.isEmpty())
+ l.append(lf);
+ }
+ return true;
+}
+
+/*!
+ \fn bool TQUriDrag::decodeToUnicodeUris(const QMimeSource *source, QStringList &list)
+
+ Decodes URIs from the MIME \a source, converting them to Unicode URIs
+ (only useful for displaying to humans), and places them in the \a list
+ (which is first cleared).
+
+ Returns true if the MIME \a source contained a valid list of URIs;
+ otherwise returns false.
+*/
+bool TQUriDrag::decodeToUnicodeUris(const QMimeSource* e, QStringList& l)
+{
+ TQStrList u;
+ if (!decode(e, u))
+ return false;
+
+ l.clear();
+ for (uint i = 0; i < u.count(); ++i)
+ l.append(uriToUnicodeUri(u.at(i)));
+
+ return true;
+}
+
+/*!
+ \class TQColorDrag
+
+ \brief The TQColorDrag class provides a drag and drop object for
+ transferring colors between widgets.
+
+ \compat
+
+ This class provides a drag object which can be used to transfer data
+ about colors for drag and drop and in the clipboard. For example, it
+ is used in QColorDialog.
+
+ The color is set in the constructor but can be changed with
+ setColor().
+
+ For more information about drag and drop, see the TQDragObject class
+ and the \link dnd.html drag and drop documentation\endlink.
+*/
+
+/*!
+ Constructs a color drag object with the given \a col. Passes \a
+ dragsource and \a name to the TQStoredDrag constructor.
+*/
+
+TQColorDrag::TQColorDrag(const QColor &col, QWidget *dragsource, const char *name)
+ : TQStoredDrag("application/x-color", dragsource)
+{
+ setObjectName(QLatin1String(name));
+ setColor(col);
+}
+
+/*!
+ Constructs a color drag object with a white color. Passes \a
+ dragsource and \a name to the TQStoredDrag constructor.
+*/
+
+TQColorDrag::TQColorDrag(QWidget *dragsource, const char *name)
+ : TQStoredDrag("application/x-color", dragsource)
+{
+ setObjectName(QLatin1String(name));
+ setColor(Qt::white);
+}
+
+/*!
+ \fn void TQColorDrag::setColor(const QColor &color)
+
+ Sets the \a color of the color drag.
+*/
+
+void TQColorDrag::setColor(const QColor &col)
+{
+ short r = (col.red() << 8) | col.red();
+ short g = (col.green() << 8) | col.green();
+ short b = (col.blue() << 8) | col.blue();
+
+ // make sure we transmit data in network order
+ r = htons(r);
+ g = htons(g);
+ b = htons(b);
+
+ ushort rgba[4] = {
+ r, g, b,
+ 0xffff // Alpha not supported yet.
+ };
+ QByteArray data;
+ data.resize(sizeof(rgba));
+ memcpy(data.data(), rgba, sizeof(rgba));
+ setEncodedData(data);
+}
+
+/*!
+ \fn bool TQColorDrag::canDecode(QMimeSource *source)
+
+ Returns true if the color drag object can decode the MIME \a source;
+ otherwise returns false.
+*/
+
+bool TQColorDrag::canDecode(QMimeSource *e)
+{
+ return e->provides("application/x-color");
+}
+
+/*!
+ \fn bool TQColorDrag::decode(QMimeSource *source, QColor &color)
+
+ Decodes the MIME \a source, and sets the decoded values to the
+ given \a color. Returns true if the decoding is successful.
+ Returns false if the size of the encoded data is not the
+ expected size.
+*/
+
+bool TQColorDrag::decode(QMimeSource *e, QColor &col)
+{
+ QByteArray data = e->encodedData("application/x-color");
+ ushort rgba[4];
+ if (data.size() != sizeof(rgba))
+ return false;
+
+ memcpy(rgba, data.constData(), sizeof(rgba));
+
+ short r = rgba[0];
+ short g = rgba[1];
+ short b = rgba[2];
+ short a = rgba[3];
+
+ // data is in network order
+ r = ntohs(r);
+ g = ntohs(g);
+ b = ntohs(b);
+ a = ntohs(a);
+
+ r = (r >> 8) & 0xff;
+ g = (g >> 8) & 0xff;
+ b = (b >> 8) & 0xff;
+ a = (a >> 8) & 0xff;
+
+ col.setRgb(r, g, b, a);
+ return true;
+}
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of Drag and Drop support
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+// POSIX Large File Support redefines open -> open64
+#if defined(open)
+# undef open
+#endif
+
+#ifndef TQT_NO_MIME
+
+#include "tqdragobject.h"
+#include "tqtextcodec.h"
+#include "tqapplication.h"
+#include "tqpoint.h"
+#include "tqwidget.h"
+#include "tqbuffer.h"
+#include "tqgif.h"
+#include "tqregexp.h"
+#include "tqdir.h"
+#include <ctype.h>
+
+// both a struct for storing stuff in and a wrapper to avoid polluting
+// the name space
+
+class TQDragObjectData
+{
+public:
+ TQDragObjectData(): hot(0,0) {}
+ TQPixmap pixmap;
+ TQPoint hot;
+ // store default cursors
+ TQPixmap *pm_cursor;
+};
+
+static TQWidget* last_target;
+
+/*!
+ After the drag completes, this function will return the TQWidget
+ which received the drop, or 0 if the data was dropped on another
+ application.
+
+ This can be useful for detecting the case where drag and drop is
+ to and from the same widget.
+*/
+TQWidget * TQDragObject::target()
+{
+ return last_target;
+}
+
+/*!
+ \internal
+ Sets the target.
+*/
+void TQDragObject::setTarget(QWidget* t)
+{
+ last_target = TQT_TQWIDGET(t);
+}
+
+class TQStoredDragData
+{
+public:
+ TQStoredDragData() {}
+ const char* fmt;
+ TQByteArray enc;
+};
+
+
+// These pixmaps approximate the images in the Windows User Interface Guidelines.
+
+// XPM
+
+static const char * const move_xpm[] = {
+"11 20 3 1",
+". c None",
+#if defined(TQ_WS_WIN)
+"a c #000000",
+"X c #FFFFFF", // Windows cursor is traditionally white
+#else
+"a c #FFFFFF",
+"X c #000000", // X11 cursor is traditionally black
+#endif
+"aa.........",
+"aXa........",
+"aXXa.......",
+"aXXXa......",
+"aXXXXa.....",
+"aXXXXXa....",
+"aXXXXXXa...",
+"aXXXXXXXa..",
+"aXXXXXXXXa.",
+"aXXXXXXXXXa",
+"aXXXXXXaaaa",
+"aXXXaXXa...",
+"aXXaaXXa...",
+"aXa..aXXa..",
+"aa...aXXa..",
+"a.....aXXa.",
+"......aXXa.",
+".......aXXa",
+".......aXXa",
+"........aa."};
+
+/* XPM */
+static const char * const copy_xpm[] = {
+"24 30 3 1",
+". c None",
+"a c #000000",
+"X c #FFFFFF",
+#if defined(TQ_WS_WIN) // Windows cursor is traditionally white
+"aa......................",
+"aXa.....................",
+"aXXa....................",
+"aXXXa...................",
+"aXXXXa..................",
+"aXXXXXa.................",
+"aXXXXXXa................",
+"aXXXXXXXa...............",
+"aXXXXXXXXa..............",
+"aXXXXXXXXXa.............",
+"aXXXXXXaaaa.............",
+"aXXXaXXa................",
+"aXXaaXXa................",
+"aXa..aXXa...............",
+"aa...aXXa...............",
+"a.....aXXa..............",
+"......aXXa..............",
+".......aXXa.............",
+".......aXXa.............",
+"........aa...aaaaaaaaaaa",
+#else
+"XX......................",
+"XaX.....................",
+"XaaX....................",
+"XaaaX...................",
+"XaaaaX..................",
+"XaaaaaX.................",
+"XaaaaaaX................",
+"XaaaaaaaX...............",
+"XaaaaaaaaX..............",
+"XaaaaaaaaaX.............",
+"XaaaaaaXXXX.............",
+"XaaaXaaX................",
+"XaaXXaaX................",
+"XaX..XaaX...............",
+"XX...XaaX...............",
+"X.....XaaX..............",
+"......XaaX..............",
+".......XaaX.............",
+".......XaaX.............",
+"........XX...aaaaaaaaaaa",
+#endif
+".............aXXXXXXXXXa",
+".............aXXXXXXXXXa",
+".............aXXXXaXXXXa",
+".............aXXXXaXXXXa",
+".............aXXaaaaaXXa",
+".............aXXXXaXXXXa",
+".............aXXXXaXXXXa",
+".............aXXXXXXXXXa",
+".............aXXXXXXXXXa",
+".............aaaaaaaaaaa"};
+
+/* XPM */
+static const char * const link_xpm[] = {
+"24 30 3 1",
+". c None",
+"a c #000000",
+"X c #FFFFFF",
+#if defined(TQ_WS_WIN) // Windows cursor is traditionally white
+"aa......................",
+"aXa.....................",
+"aXXa....................",
+"aXXXa...................",
+"aXXXXa..................",
+"aXXXXXa.................",
+"aXXXXXXa................",
+"aXXXXXXXa...............",
+"aXXXXXXXXa..............",
+"aXXXXXXXXXa.............",
+"aXXXXXXaaaa.............",
+"aXXXaXXa................",
+"aXXaaXXa................",
+"aXa..aXXa...............",
+"aa...aXXa...............",
+"a.....aXXa..............",
+"......aXXa..............",
+".......aXXa.............",
+".......aXXa.............",
+"........aa...aaaaaaaaaaa",
+#else
+"XX......................",
+"XaX.....................",
+"XaaX....................",
+"XaaaX...................",
+"XaaaaX..................",
+"XaaaaaX.................",
+"XaaaaaaX................",
+"XaaaaaaaX...............",
+"XaaaaaaaaX..............",
+"XaaaaaaaaaX.............",
+"XaaaaaaXXXX.............",
+"XaaaXaaX................",
+"XaaXXaaX................",
+"XaX..XaaX...............",
+"XX...XaaX...............",
+"X.....XaaX..............",
+"......XaaX..............",
+".......XaaX.............",
+".......XaaX.............",
+"........XX...aaaaaaaaaaa",
+#endif
+".............aXXXXXXXXXa",
+".............aXXXaaaaXXa",
+".............aXXXXaaaXXa",
+".............aXXXaaaaXXa",
+".............aXXaaaXaXXa",
+".............aXXaaXXXXXa",
+".............aXXaXXXXXXa",
+".............aXXXaXXXXXa",
+".............aXXXXXXXXXa",
+".............aaaaaaaaaaa"};
+
+#ifndef TQT_NO_DRAGANDDROP
+
+// the universe's only drag manager
+TQDragManager * qt_dnd_manager = 0;
+
+
+TQDragManager::TQDragManager()
+ : TQObject( TQT_TQOBJECT(tqApp), "global drag manager" )
+{
+ n_cursor = 3;
+ pm_cursor = new TQPixmap[n_cursor];
+ pm_cursor[0] = TQPixmap((const char **)move_xpm);
+ pm_cursor[1] = TQPixmap((const char **)copy_xpm);
+ pm_cursor[2] = TQPixmap((const char **)link_xpm);
+#if defined(TQ_WS_X11)
+ createCursors(); // Xcursors cache can hold only 8 bitmaps (4 cursors)
+#endif
+ object = 0;
+ dragSource = 0;
+ dropWidget = 0;
+ if ( !qt_dnd_manager )
+ qt_dnd_manager = this;
+ beingCancelled = FALSE;
+ restoreCursor = FALSE;
+ willDrop = FALSE;
+}
+
+
+TQDragManager::~TQDragManager()
+{
+#ifndef TQT_NO_CURSOR
+ if ( restoreCursor )
+ TQApplication::restoreOverrideCursor();
+#endif
+ qt_dnd_manager = 0;
+ delete [] pm_cursor;
+}
+
+#endif
+
+
+/*!
+ Constructs a drag object called \a name, which is a child of \a
+ dragSource.
+
+ Note that the drag object will be deleted when \a dragSource is
+ deleted.
+*/
+
+TQDragObject::TQDragObject( QWidget * dragSource, const char * name )
+ : TQObject( TQT_TQOBJECT(dragSource), name )
+{
+ d = new TQDragObjectData();
+ d->pm_cursor = 0;
+#ifndef TQT_NO_DRAGANDDROP
+ if ( !qt_dnd_manager && tqApp )
+ (void)new TQDragManager();
+#endif
+}
+
+
+/*!
+ Destroys the drag object, canceling any drag and drop operation in
+ which it is involved, and frees up the storage used.
+*/
+
+TQDragObject::~TQDragObject()
+{
+#ifndef TQT_NO_DRAGANDDROP
+ if ( qt_dnd_manager && qt_dnd_manager->object == this )
+ qt_dnd_manager->cancel( FALSE );
+ if ( d->pm_cursor ) {
+ for ( int i = 0; i < qt_dnd_manager->n_cursor; i++ )
+ qt_dnd_manager->pm_cursor[i] = d->pm_cursor[i];
+ delete [] d->pm_cursor;
+ }
+#endif
+ delete d;
+}
+
+#ifndef TQT_NO_DRAGANDDROP
+/*!
+ Set the pixmap \a pm to display while dragging the object. The
+ platform-specific implementation will use this where it can - so
+ provide a small masked pixmap, and do not assume that the user
+ will actually see it. For example, cursors on Windows 95 are of
+ limited size.
+
+ The \a hotspot is the point on (or off) the pixmap that should be
+ under the cursor as it is dragged. It is relative to the top-left
+ pixel of the pixmap.
+
+ \warning We have seen problems with drag cursors on different
+ graphics hardware and driver software on Windows. Setting the
+ graphics acceleration in the display settings down one tick solved
+ the problems in all cases.
+*/
+void TQDragObject::setPixmap(QPixmap pm, const QPoint& hotspot)
+{
+ d->pixmap = pm;
+ d->hot = hotspot;
+ if ( qt_dnd_manager && qt_dnd_manager->object == this )
+ qt_dnd_manager->updatePixmap();
+}
+
+/*!
+ \overload
+ Uses a hotspot that positions the pixmap below and to the right of
+ the mouse pointer. This allows the user to clearly see the point
+ on the window which they are dragging the data onto.
+*/
+void TQDragObject::setPixmap(QPixmap pm)
+{
+ setPixmap(pm,TQPoint(-10, -10));
+}
+
+/*!
+ Returns the currently set pixmap (which \link TQPixmap::isNull()
+ isNull()\endlink if none is set).
+*/
+TQPixmap TQDragObject::pixmap() const
+{
+ return d->pixmap;
+}
+
+/*!
+ Returns the currently set pixmap hotspot.
+*/
+TQPoint TQDragObject::pixmapHotSpot() const
+{
+ return d->hot;
+}
+
+#if 0
+
+// ## reevaluate for TQt 4
+/*!
+ Set the \a cursor used when dragging in mode \a m.
+ Note: X11 only allow bitmaps for cursors.
+*/
+void TQDragObject::setCursor( DragMode m, const TQPixmap &cursor )
+{
+ if ( d->pm_cursor == 0 ) {
+ // safe default cursors
+ d->pm_cursor = new TQPixmap[qt_dnd_manager->n_cursor];
+ for ( int i = 0; i < qt_dnd_manager->n_cursor; i++ )
+ d->pm_cursor[i] = qt_dnd_manager->pm_cursor[i];
+ }
+
+ int index;
+ switch ( m ) {
+ case DragCopy:
+ index = 1;
+ break;
+ case DragLink:
+ index = 2;
+ break;
+ default:
+ index = 0;
+ break;
+ }
+
+ // override default cursor
+ for ( index = 0; index < qt_dnd_manager->n_cursor; index++ )
+ qt_dnd_manager->pm_cursor[index] = cursor;
+}
+
+/*!
+ Returns the cursor used when dragging in mode \a m, or null if no cursor
+ has been set for that mode.
+*/
+TQPixmap *TQDragObject::cursor( DragMode m ) const
+{
+ if ( !d->pm_cursor )
+ return 0;
+
+ int index;
+ switch ( m ) {
+ case DragCopy:
+ index = 1;
+ break;
+ case DragLink:
+ index = 2;
+ break;
+ default:
+ index = 0;
+ break;
+ }
+
+ return qt_dnd_manager->pm_cursor+index;
+}
+
+#endif // 0
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ DragDefault mode.
+
+ The function returns TRUE if the caller should delete the original
+ copy of the dragged data (but see target()); otherwise returns
+ FALSE.
+
+ If the drag tqcontains \e references to information (e.g. file names
+ in a TQUriDrag are references) then the return value should always
+ be ignored, as the target is expected to manipulate the
+ referred-to content directly. On X11 the return value should
+ always be correct anyway, but on Windows this is not necessarily
+ the case (e.g. the file manager starts a background process to
+ move files, so the source \e{must not} delete the files!)
+*/
+bool TQDragObject::drag()
+{
+ return drag( DragDefault );
+}
+
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ \c DragMove mode. Be sure to read the constraints described in
+ drag().
+
+ \sa drag() dragCopy() dragLink()
+*/
+bool TQDragObject::dragMove()
+{
+ return drag( DragMove );
+}
+
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ \c DragCopy mode. Be sure to read the constraints described in
+ drag().
+
+ \sa drag() dragMove() dragLink()
+*/
+void TQDragObject::dragCopy()
+{
+ (void)drag( DragCopy );
+}
+
+/*!
+ Starts a drag operation using the contents of this object, using
+ \c DragLink mode. Be sure to read the constraints described in
+ drag().
+
+ \sa drag() dragCopy() dragMove()
+*/
+void TQDragObject::dragLink()
+{
+ (void)drag( DragLink );
+}
+
+
+/*!
+ \enum TQDragObject::DragMode
+
+ This enum describes the possible drag modes.
+
+ \value DragDefault The mode is determined heuristically.
+ \value DragCopy The data is copied, never moved.
+ \value DragMove The data is moved, if dragged at all.
+ \value DragLink The data is linked, if dragged at all.
+ \value DragCopyOrMove The user chooses the mode by using a
+ control key to switch from the default.
+*/
+
+
+/*!
+ \overload
+ Starts a drag operation using the contents of this object.
+
+ At this point, the object becomes owned by TQt, not the
+ application. You should not delete the drag object or anything it
+ references. The actual transfer of data to the target application
+ will be done during future event processing - after that time the
+ drag object will be deleted.
+
+ Returns TRUE if the dragged data was dragged as a \e move,
+ indicating that the caller should remove the original source of
+ the data (the drag object must continue to have a copy); otherwise
+ returns FALSE.
+
+ The \a mode specifies the drag mode (see
+ \l{TQDragObject::DragMode}.) Normally one of the simpler drag(),
+ dragMove(), or dragCopy() functions would be used instead.
+*/
+bool TQDragObject::drag( DragMode mode )
+{
+ if ( qt_dnd_manager )
+ return qt_dnd_manager->drag( this, mode );
+ else
+ return FALSE;
+}
+
+#endif
+
+
+/*!
+ Returns a pointer to the drag source where this object originated.
+*/
+
+TQWidget * TQDragObject::source()
+{
+ if ( tqparent() && tqparent()->isWidgetType() )
+ return (TQWidget *)tqparent();
+ else
+ return 0;
+}
+
+
+/*!
+ \class TQDragObject tqdragobject.h
+
+ \brief The TQDragObject class encapsulates MIME-based data
+ transfer.
+
+ \ingroup draganddrop
+
+ TQDragObject is the base class for all data that needs to be
+ transferred between and within applications, both for drag and
+ drop and for the \link tqclipboard.html clipboard\endlink.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag and drop in your application.
+
+ See the TQClipboard documentation for an overview of how to provide
+ cut-and-paste in your application.
+
+ The drag() function is used to start a drag operation. You can
+ specify the \l DragMode in the call or use one of the convenience
+ functions dragCopy(), dragMove() or dragLink(). The drag source
+ where the data originated is retrieved with source(). If the data
+ was dropped on a widget within the application, target() will
+ return a pointer to that widget. Specify the pixmap to display
+ during the drag with setPixmap().
+*/
+
+static
+void stripws(TQCString& s)
+{
+ int f;
+ while ( (f=s.tqfind(' ')) >= 0 )
+ s.remove(f,1);
+}
+
+static
+const char * staticCharset(int i)
+{
+ static TQCString localcharset;
+
+ switch ( i ) {
+ case 0:
+ return "UTF-8";
+ case 1:
+ return "ISO-10646-UCS-2";
+ case 2:
+ return ""; // in the 3rd place - some Xdnd targets might only look at 3
+ case 3:
+ if ( localcharset.isNull() ) {
+ TQTextCodec *localCodec = TQTextCodec::codecForLocale();
+ if ( localCodec ) {
+ localcharset = localCodec->name();
+ localcharset = localcharset.lower();
+ stripws(localcharset);
+ } else {
+ localcharset = "";
+ }
+ }
+ return localcharset;
+ }
+ return 0;
+}
+
+
+class TQTextDragPrivate {
+public:
+ TQTextDragPrivate();
+
+ enum { nfmt=4 };
+
+ TQString txt;
+ TQCString fmt[nfmt];
+ TQCString subtype;
+
+ void setSubType(const TQCString & st)
+ {
+ subtype = st.lower();
+ for ( int i=0; i<nfmt; i++ ) {
+ fmt[i] = "text/";
+ fmt[i].append(subtype);
+ TQCString cs = staticCharset(i);
+ if ( !cs.isEmpty() ) {
+ fmt[i].append(";charset=");
+ fmt[i].append(cs);
+ }
+ }
+ }
+};
+
+inline TQTextDragPrivate::TQTextDragPrivate()
+{
+ setSubType("plain");
+}
+
+/*!
+ Sets the MIME subtype of the text being dragged to \a st. The
+ default subtype is "plain", so the default MIME type of the text
+ is "text/plain". You might use this to declare that the text is
+ "text/html" by calling setSubtype("html").
+*/
+void TQTextDrag::setSubtype( const TQCString & st)
+{
+ d->setSubType(st);
+}
+
+/*!
+ \class TQTextDrag tqdragobject.h
+
+ \brief The TQTextDrag class is a drag and drop object for
+ transferring plain and Unicode text.
+
+ \ingroup draganddrop
+
+ Plain text is passed in a TQString which may contain multiple lines
+ (i.e. may contain newline characters). The drag target will receive
+ the newlines according to the runtime environment, e.g. LF on Unix,
+ and CRLF on Windows.
+
+ TQt provides no built-in mechanism for delivering only a single-line.
+
+ For more information about drag and drop, see the TQDragObject class
+ and the \link dnd.html drag and drop documentation\endlink.
+*/
+
+
+/*!
+ Constructs a text drag object and sets its data to \a text. \a
+ dragSource must be the drag source; \a name is the object name.
+*/
+
+TQTextDrag::TQTextDrag( const TQString &text,
+ TQWidget * dragSource, const char * name )
+ : TQDragObject( dragSource, name )
+{
+ d = new TQTextDragPrivate;
+ setText( text );
+}
+
+
+/*!
+ Constructs a default text drag object. \a dragSource must be the
+ drag source; \a name is the object name.
+*/
+
+TQTextDrag::TQTextDrag( TQWidget * dragSource, const char * name )
+ : TQDragObject( dragSource, name )
+{
+ d = new TQTextDragPrivate;
+}
+
+
+/*!
+ Destroys the text drag object and frees up all allocated
+ resources.
+*/
+TQTextDrag::~TQTextDrag()
+{
+ delete d;
+}
+
+
+/*!
+ Sets the text to be dragged to \a text. You will need to call this
+ if you did not pass the text during construction.
+*/
+void TQTextDrag::setText( const TQString &text )
+{
+ d->txt = text;
+}
+
+
+/*!
+ \reimp
+*/
+const char * TQTextDrag::format(int i) const
+{
+ if ( i >= d->nfmt )
+ return 0;
+ return d->fmt[i];
+}
+
+TQTextCodec* qt_tqfindcharset(const TQCString& mimetype)
+{
+ int i=mimetype.tqfind("charset=");
+ if ( i >= 0 ) {
+ TQCString cs = mimetype.mid(i+8);
+ stripws(cs);
+ i = cs.tqfind(';');
+ if ( i >= 0 )
+ cs = cs.left(i);
+ // win98 often has charset=utf16, and we need to get the correct codec for
+ // it to be able to get Unicode text drops.
+ if ( cs == "utf16" )
+ cs = "ISO-10646-UCS-2";
+ // May return 0 if unknown charset
+ return TQTextCodec::codecForName(cs);
+ }
+ // no charset=, use locale
+ return TQTextCodec::codecForLocale();
+}
+
+static TQTextCodec *codecForHTML(const TQCString &ba)
+{
+ // determine charset
+ int mib = 0;
+ int pos;
+ TQTextCodec *c = 0;
+
+ if (ba.size() > 1 && (((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff)
+ || ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe))) {
+ mib = 1000; // utf16
+ } else if (ba.size() > 2
+ && (uchar)ba[0] == 0xef
+ && (uchar)ba[1] == 0xbb
+ && (uchar)ba[2] == 0xbf) {
+ mib = 106; // utf-8
+ } else {
+ pos = 0;
+ while ((pos = ba.tqfind("<meta http-equiv=", pos, FALSE)) != -1) {
+ int end = ba.tqfind('>', pos+1);
+ if (end == -1)
+ break;
+ pos = ba.tqfind("charset=", pos, FALSE) + (int)strlen("charset=");
+ if (pos != -1 && pos < end) {
+ int pos2 = ba.tqfind('\"', pos+1);
+ TQCString cs = ba.mid(pos, pos2-pos);
+ c = TQTextCodec::codecForName(cs);
+ if (c)
+ return c;
+ }
+ pos = end;
+ }
+ }
+ if (mib)
+ c = TQTextCodec::codecForMib(mib);
+
+ return c;
+}
+
+static
+TQTextCodec* tqfindcodec(const TQMimeSource* e)
+{
+ TQTextCodec* r = 0;
+ const char* f;
+ int i;
+ for ( i=0; (f=e->format(i)); i++ ) {
+ bool html = !qstrnicmp(f, "text/html", 9);
+ if (html)
+ r = codecForHTML(TQCString(e->tqencodedData(f)));
+ if (!r)
+ r = qt_tqfindcharset(TQCString(f).lower());
+ if (r)
+ return r;
+ }
+ return 0;
+}
+
+
+
+/*!
+ \reimp
+*/
+TQByteArray TQTextDrag::tqencodedData(const char* mime) const
+{
+ TQCString r;
+ if ( 0==qstrnicmp(mime,"text/",5) ) {
+ TQCString m(mime);
+ m = m.lower();
+ TQTextCodec *codec = qt_tqfindcharset(m);
+ if ( !codec )
+ return r;
+ TQString text( d->txt );
+#if defined(TQ_WS_WIN)
+ int index = text.tqfind( TQString::tqfromLatin1("\r\n"), 0 );
+ while ( index != -1 ) {
+ text.tqreplace( index, 2, TQChar('\n') );
+ index = text.tqfind( "\r\n", index );
+ }
+#endif
+ r = codec->fromUnicode(text);
+ if (!codec || codec->mibEnum() != 1000) {
+ // Don't include NUL in size (TQCString::resize() adds NUL)
+#if defined(TQ_WS_WIN)
+ // This is needed to ensure the \0 isn't lost on Windows 95
+ if ( qWinVersion() & TQt::WV_DOS_based )
+ ((TQByteArray&)r).resize(r.length()+1);
+ else
+#endif
+ ((TQByteArray&)r).resize(r.length());
+ }
+ }
+ return r;
+}
+
+/*!
+ Returns TRUE if the information in \a e can be decoded into a
+ TQString; otherwise returns FALSE.
+
+ \sa decode()
+*/
+bool TQTextDrag::canDecode( const TQMimeSource* e )
+{
+ const char* f;
+ for (int i=0; (f=e->format(i)); i++) {
+ if ( 0==qstrnicmp(f,"text/",5) ) {
+ return tqfindcodec(e) != 0;
+ }
+ }
+ return 0;
+}
+
+/*!
+ \overload
+
+ Attempts to decode the dropped information in \a e into \a str.
+ Returns TRUE if successful; otherwise returns FALSE. If \a subtype
+ is null, any text subtype is accepted; otherwise only the
+ specified \a subtype is accepted.
+
+ \sa canDecode()
+*/
+bool TQTextDrag::decode( const TQMimeSource* e, TQString& str, TQCString& subtype )
+{
+ if(!e)
+ return FALSE;
+
+ if ( e->cacheType == TQMimeSource::Text ) {
+ str = *e->cache.txt.str;
+ subtype = *e->cache.txt.subtype;
+ return TRUE;
+ }
+
+ const char* mime;
+ for (int i=0; (mime = e->format(i)); i++) {
+ if ( 0==qstrnicmp(mime,"text/",5) ) {
+ TQCString m(mime);
+ m = m.lower();
+ int semi = m.tqfind(';');
+ if ( semi < 0 )
+ semi = m.length();
+ TQCString foundst = m.mid(5,semi-5);
+ if ( subtype.isNull() || foundst == subtype ) {
+ bool html = !qstrnicmp(mime, "text/html", 9);
+ TQTextCodec* codec = 0;
+ if (html) {
+ TQByteArray bytes = e->tqencodedData(mime);
+ // search for the charset tag in the HTML
+ codec = codecForHTML(TQCString(bytes.data(), bytes.size()));
+ }
+ if (!codec)
+ codec = qt_tqfindcharset(m);
+ if ( codec ) {
+ TQByteArray payload;
+
+ payload = e->tqencodedData(mime);
+ if ( payload.size() ) {
+ int l;
+ if ( codec->mibEnum() != 1000) {
+ // length is at NUL or payload.size()
+ l = 0;
+ while ( l < (int)payload.size() && payload[l] )
+ l++;
+ } else {
+ l = payload.size();
+ }
+
+ str = codec->toUnicode(payload,l);
+
+ if ( subtype.isNull() )
+ subtype = foundst;
+
+ TQMimeSource *m = (TQMimeSource*)e;
+ m->clearCache();
+ m->cacheType = TQMimeSource::Text;
+ m->cache.txt.str = new TQString( str );
+ m->cache.txt.subtype = new TQCString( subtype );
+
+ return TRUE;
+ }
+ }
+ }
+ }
+ }
+ return FALSE;
+}
+
+/*!
+ Attempts to decode the dropped information in \a e into \a str.
+ Returns TRUE if successful; otherwise returns FALSE.
+
+ \sa canDecode()
+*/
+bool TQTextDrag::decode( const TQMimeSource* e, TQString& str )
+{
+ TQCString st;
+ return decode(e,str,st);
+}
+
+
+/*
+ TQImageDrag could use an internal MIME type for communicating TQPixmaps
+ and TQImages rather than always converting to raw data. This is available
+ for that purpose and others. It is not currently used.
+*/
+class TQImageDragData
+{
+public:
+};
+
+
+/*!
+ \class TQImageDrag tqdragobject.h
+
+ \brief The TQImageDrag class provides a drag and drop object for
+ transferring images.
+
+ \ingroup draganddrop
+
+ Images are offered to the receiving application in multiple
+ formats, determined by TQt's \link TQImage::outputFormats() output
+ formats\endlink.
+
+ For more information about drag and drop, see the TQDragObject
+ class and the \link dnd.html drag and drop documentation\endlink.
+*/
+
+/*!
+ Constructs an image drag object and sets its data to \a image. \a
+ dragSource must be the drag source; \a name is the object name.
+*/
+
+TQImageDrag::TQImageDrag( QImage image,
+ QWidget * dragSource, const char * name )
+ : TQDragObject( dragSource, name ),
+ d(0)
+{
+ setImage( image );
+}
+
+/*!
+ Constructs a default image drag object. \a dragSource must be the
+ drag source; \a name is the object name.
+*/
+
+TQImageDrag::TQImageDrag( QWidget * dragSource, const char * name )
+ : TQDragObject( dragSource, name ),
+ d(0)
+{
+}
+
+
+/*!
+ Destroys the image drag object and frees up all allocated
+ resources.
+*/
+
+TQImageDrag::~TQImageDrag()
+{
+ // nothing
+}
+
+
+/*!
+ Sets the image to be dragged to \a image. You will need to call
+ this if you did not pass the image during construction.
+*/
+void TQImageDrag::setImage( QImage image )
+{
+ img = image; // ### detach?
+ ofmts = TQImage::outputFormats();
+ ofmts.remove("PBM"); // remove non-raw PPM
+ if ( image.depth()!=32 ) {
+ // BMP better than PPM for paletted images
+ if ( ofmts.remove("BMP") ) // move to front
+ ofmts.insert(0,"BMP");
+ }
+ // PNG is best of all
+ if ( ofmts.remove("PNG") ) // move to front
+ ofmts.insert(0,"PNG");
+
+ if(cacheType == TQMimeSource::NoCache) { //cache it
+ cacheType = TQMimeSource::Graphics;
+ cache.gfx.img = new TQImage( img );
+ cache.gfx.pix = 0;
+ }
+}
+
+/*!
+ \reimp
+*/
+const char * TQImageDrag::format(int i) const
+{
+ if ( i < (int)ofmts.count() ) {
+ static TQCString str;
+ str.sprintf("image/%s",(((TQImageDrag*)this)->ofmts).at(i));
+ str = str.lower();
+ if ( str == "image/pbmraw" )
+ str = "image/ppm";
+ return str;
+ } else {
+ return 0;
+ }
+}
+
+/*!
+ \reimp
+*/
+TQByteArray TQImageDrag::tqencodedData(const char* fmt) const
+{
+ if ( qstrnicmp( fmt, "image/", 6 )==0 ) {
+ TQCString f = fmt+6;
+ TQByteArray data;
+ TQBuffer w( data );
+ w.open( IO_WriteOnly );
+ TQImageIO io( &w, f.upper() );
+ io.setImage( img );
+ if ( !io.write() )
+ return TQByteArray();
+ w.close();
+ return data;
+ } else {
+ return TQByteArray();
+ }
+}
+
+/*!
+ Returns TRUE if the information in mime source \a e can be decoded
+ into an image; otherwise returns FALSE.
+
+ \sa decode()
+*/
+bool TQImageDrag::canDecode( const TQMimeSource* e ) {
+ TQStrList fileFormats = TQImageIO::inputFormats();
+
+ fileFormats.first();
+ while ( fileFormats.current()) {
+ TQCString format = fileFormats.current();
+ TQCString type = "image/" + format.lower();
+ if ( e->provides(type.data()))
+ return TRUE;
+ fileFormats.next();
+ }
+
+ return FALSE;
+}
+
+/*!
+ Attempts to decode the dropped information in mime source \a e
+ into \a img. Returns TRUE if successful; otherwise returns FALSE.
+
+ \sa canDecode()
+*/
+bool TQImageDrag::decode( const TQMimeSource* e, QImage& img )
+{
+ if ( !e )
+ return FALSE;
+ if ( e->cacheType == TQMimeSource::Graphics ) {
+ img = *e->cache.gfx.img;
+ return TRUE;
+ }
+
+ TQByteArray payload;
+ TQStrList fileFormats = TQImageIO::inputFormats();
+ // PNG is best of all
+ if ( fileFormats.remove("PNG") ) // move to front
+ fileFormats.insert(0,"PNG");
+ fileFormats.first();
+ while ( fileFormats.current() ) {
+ TQCString format = fileFormats.current();
+ fileFormats.next();
+
+ TQCString type = "image/" + format.lower();
+ if ( ! e->provides( type.data() ) ) continue;
+ payload = e->tqencodedData( type.data() );
+ if ( !payload.isEmpty() )
+ break;
+ }
+
+ if ( payload.isEmpty() )
+ return FALSE;
+
+ img.loadFromData(payload);
+ if ( img.isNull() )
+ return FALSE;
+ TQMimeSource *m = (TQMimeSource*)e;
+ m->clearCache();
+ m->cacheType = TQMimeSource::Graphics;
+ m->cache.gfx.img = new TQImage( img );
+ m->cache.gfx.pix = 0;
+ return TRUE;
+}
+
+/*!
+ \overload
+
+ Attempts to decode the dropped information in mime source \a e
+ into pixmap \a pm. Returns TRUE if successful; otherwise returns
+ FALSE.
+
+ This is a convenience function that converts to a TQPixmap via a
+ TQImage.
+
+ \sa canDecode()
+*/
+bool TQImageDrag::decode( const TQMimeSource* e, QPixmap& pm )
+{
+ if ( !e )
+ return FALSE;
+
+ if ( e->cacheType == TQMimeSource::Graphics && e->cache.gfx.pix) {
+ pm = *e->cache.gfx.pix;
+ return TRUE;
+ }
+
+ TQImage img;
+ // We avoid dither, since the image probably came from this display
+ if ( decode( e, img ) ) {
+ if ( !pm.convertFromImage( img, Qt::AvoidDither ) )
+ return FALSE;
+ // decode initialized the cache for us
+
+ TQMimeSource *m = (TQMimeSource*)e;
+ m->cache.gfx.pix = new TQPixmap( pm );
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+
+
+/*!
+ \class TQStoredDrag tqdragobject.h
+ \brief The TQStoredDrag class provides a simple stored-value drag object for arbitrary MIME data.
+
+ \ingroup draganddrop
+
+ When a block of data has only one representation, you can use a
+ TQStoredDrag to hold it.
+
+ For more information about drag and drop, see the TQDragObject
+ class and the \link dnd.html drag and drop documentation\endlink.
+*/
+
+/*!
+ Constructs a TQStoredDrag. The \a dragSource and \a name are passed
+ to the TQDragObject constructor, and the format is set to \a
+ mimeType.
+
+ The data will be unset. Use setEncodedData() to set it.
+*/
+TQStoredDrag::TQStoredDrag( const char* mimeType, QWidget * dragSource, const char * name ) :
+ TQDragObject(dragSource,name)
+{
+ d = new TQStoredDragData();
+ d->fmt = qstrdup(mimeType);
+}
+
+/*!
+ Destroys the drag object and frees up all allocated resources.
+*/
+TQStoredDrag::~TQStoredDrag()
+{
+ delete [] (char*)d->fmt;
+ delete d;
+}
+
+/*!
+ \reimp
+*/
+const char * TQStoredDrag::format(int i) const
+{
+ if ( i==0 )
+ return d->fmt;
+ else
+ return 0;
+}
+
+
+/*!
+ Sets the encoded data of this drag object to \a tqencodedData. The
+ encoded data is what's delivered to the drop sites. It must be in
+ a strictly defined and portable format.
+
+ The drag object can't be dropped (by the user) until this function
+ has been called.
+*/
+
+void TQStoredDrag::setEncodedData( const TQByteArray & tqencodedData )
+{
+ d->enc = tqencodedData.copy();
+}
+
+/*!
+ Returns the stored data. \a m tqcontains the data's format.
+
+ \sa setEncodedData()
+*/
+TQByteArray TQStoredDrag::tqencodedData(const char* m) const
+{
+ if ( !qstricmp(m,d->fmt) )
+ return d->enc;
+ else
+ return TQByteArray();
+}
+
+
+/*!
+ \class TQUriDrag tqdragobject.h
+ \brief The TQUriDrag class provides a drag object for a list of URI references.
+
+ \ingroup draganddrop
+
+ URIs are a useful way to refer to files that may be distributed
+ across multiple machines. A URI will often refer to a file on a
+ machine local to both the drag source and the drop target, so the
+ URI can be equivalent to passing a file name but is more
+ extensible.
+
+ Use URIs in Unicode form so that the user can comfortably edit and
+ view them. For use in HTTP or other protocols, use the correctly
+ escaped ASCII form.
+
+ You can convert a list of file names to file URIs using
+ setFileNames(), or into human-readble form with setUnicodeUris().
+
+ Static functions are provided to convert between filenames and
+ URIs, e.g. uriToLocalFile() and localFileToUri(), and to and from
+ human-readable form, e.g. uriToUnicodeUri(), tqunicodeUriToUri().
+ You can also decode URIs from a mimesource into a list with
+ decodeLocalFiles() and decodeToUnicodeUris().
+*/
+
+/*!
+ Constructs an object to drag the list of URIs in \a uris. The \a
+ dragSource and \a name arguments are passed on to TQStoredDrag.
+ Note that URIs are always in escaped UTF8 encoding.
+*/
+TQUriDrag::TQUriDrag( TQStrList uris,
+ TQWidget * dragSource, const char * name ) :
+ TQStoredDrag( "text/uri-list", dragSource, name )
+{
+ setUris(uris);
+}
+
+/*!
+ Constructs an object to drag. You must call setUris() before you
+ start the drag(). Passes \a dragSource and \a name to the
+ TQStoredDrag constructor.
+*/
+TQUriDrag::TQUriDrag( TQWidget * dragSource, const char * name ) :
+ TQStoredDrag( "text/uri-list", dragSource, name )
+{
+}
+
+/*!
+ Destroys the object.
+*/
+TQUriDrag::~TQUriDrag()
+{
+}
+
+/*!
+ Changes the list of \a uris to be dragged.
+
+ Note that URIs are always in escaped UTF8 encoding.
+*/
+void TQUriDrag::setUris( TQStrList uris )
+{
+ TQByteArray a;
+ int c=0;
+ for ( const char* s = uris.first(); s; s = uris.next() ) {
+ int l = tqstrlen(s);
+ a.resize(c+l+2);
+ memcpy(a.data()+c,s,l);
+ memcpy(a.data()+c+l,"\r\n",2);
+ c+=l+2;
+ }
+ a.resize(c+1);
+ a[c] = 0;
+ setEncodedData(a);
+}
+
+
+/*!
+ Returns TRUE if decode() would be able to decode \a e; otherwise
+ returns FALSE.
+*/
+bool TQUriDrag::canDecode( const TQMimeSource* e )
+{
+ return e->provides( "text/uri-list" );
+}
+
+/*!
+ Decodes URIs from \a e, placing the result in \a l (which is first
+ cleared).
+
+ Returns TRUE if \a e contained a valid list of URIs; otherwise
+ returns FALSE.
+*/
+bool TQUriDrag::decode( const TQMimeSource* e, TQStrList& l )
+{
+ TQByteArray payload = e->tqencodedData( "text/uri-list" );
+ if ( payload.size() ) {
+ l.clear();
+ l.setAutoDelete(TRUE);
+ uint c=0;
+ const char* d = payload.data();
+ while (c < payload.size() && d[c]) {
+ uint f = c;
+ // Find line end
+ while (c < payload.size() && d[c] && d[c]!='\r'
+ && d[c] != '\n')
+ c++;
+ TQCString s(d+f,c-f+1);
+ if ( s[0] != '#' ) // non-comment?
+ l.append( s );
+ // Skip junk
+ while (c < payload.size() && d[c] &&
+ (d[c]=='\n' || d[c]=='\r'))
+ c++;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static uint htod( int h )
+{
+ if ( isdigit(h) )
+ return h - '0';
+ return tolower( h ) - 'a' + 10;
+}
+
+/*!
+ \fn TQUriDrag::setFilenames( const TQStringList & )
+ \obsolete
+
+ Use setFileNames() instead (notice the N).
+*/
+
+/*!
+ Sets the URIs to be the local-file URIs equivalent to \a fnames.
+
+ \sa localFileToUri(), setUris()
+*/
+void TQUriDrag::setFileNames( const TQStringList & fnames )
+{
+ TQStrList uris;
+ for ( TQStringList::ConstIterator i = fnames.begin();
+ i != fnames.end(); ++i ) {
+ TQCString fileUri = localFileToUri(*i);
+ if (!fileUri.isEmpty())
+ uris.append(fileUri);
+ }
+ setUris( uris );
+}
+
+/*!
+ Sets the URIs in \a uuris to be the Unicode URIs (only useful for
+ displaying to humans).
+
+ \sa localFileToUri(), setUris()
+*/
+void TQUriDrag::setUnicodeUris( const TQStringList & uuris )
+{
+ TQStrList uris;
+ for ( TQStringList::ConstIterator i = uuris.begin();
+ i != uuris.end(); ++i )
+ uris.append( tqunicodeUriToUri(*i) );
+ setUris( uris );
+}
+
+/*!
+ Returns the URI equivalent of the Unicode URI given in \a uuri
+ (only useful for displaying to humans).
+
+ \sa uriToLocalFile()
+*/
+TQCString TQUriDrag::tqunicodeUriToUri(const TQString& uuri)
+{
+ TQCString utf8 = uuri.utf8();
+ TQCString escutf8;
+ int n = utf8.length();
+ bool isFile = uuri.startsWith("file://");
+ for (int i=0; i<n; i++) {
+ if ( (utf8[i] >= 'a' && utf8[i] <= 'z')
+ || utf8[i] == '/'
+ || (utf8[i] >= '0' && utf8[i] <= '9')
+ || (utf8[i] >= 'A' && utf8[i] <= 'Z')
+
+ || utf8[i] == '-' || utf8[i] == '_'
+ || utf8[i] == '.' || utf8[i] == '!'
+ || utf8[i] == '~' || utf8[i] == '*'
+ || utf8[i] == '(' || utf8[i] == ')'
+ || utf8[i] == '\''
+
+ // Allow this through, so that all URI-references work.
+ || (!isFile && utf8[i] == '#')
+
+ || utf8[i] == ';'
+ || utf8[i] == '?' || utf8[i] == ':'
+ || utf8[i] == '@' || utf8[i] == '&'
+ || utf8[i] == '=' || utf8[i] == '+'
+ || utf8[i] == '$' || utf8[i] == ',' )
+ {
+ escutf8 += utf8[i];
+ } else {
+ // Everything else is escaped as %HH
+ TQCString s(4);
+ s.sprintf("%%%02x",(uchar)utf8[i]);
+ escutf8 += s;
+ }
+ }
+ return escutf8;
+}
+
+/*!
+ Returns the URI equivalent to the absolute local file \a filename.
+
+ \sa uriToLocalFile()
+*/
+TQCString TQUriDrag::localFileToUri(const TQString& filename)
+{
+ TQString r = filename;
+
+ //check that it is an absolute file
+ if (TQDir::isRelativePath(r))
+ return TQCString();
+
+#ifdef TQ_WS_WIN
+
+
+ bool hasHost = FALSE;
+ // convert form network path
+ if (r.left(2) == "\\\\" || r.left(2) == "//") {
+ r.remove(0, 2);
+ hasHost = TRUE;
+ }
+
+ // Slosh -> Slash
+ int slosh;
+ while ( (slosh=r.tqfind('\\')) >= 0 ) {
+ r[slosh] = '/';
+ }
+
+ // Drive
+ if ( r[0] != '/' && !hasHost)
+ r.insert(0,'/');
+
+#endif
+#if defined ( TQ_WS_X11 ) && 0
+ // URL without the hostname is considered to be errorneous by XDnD.
+ // See: http://www.newplanetsoftware.com/xdnd/dragging_files.html
+ // This feature is not active because this would break dnd between old and new qt apps.
+ char hostname[257];
+ if ( gethostname( hostname, 255 ) == 0 ) {
+ hostname[256] = '\0';
+ r.prepend( TQString::tqfromLatin1( hostname ) );
+ }
+#endif
+ return tqunicodeUriToUri(TQString("file://" + r));
+}
+
+/*!
+ Returns the Unicode URI (only useful for displaying to humans)
+ equivalent of \a uri.
+
+ Note that URIs are always in escaped UTF8 encoding.
+
+ \sa localFileToUri()
+*/
+TQString TQUriDrag::uriToUnicodeUri(const char* uri)
+{
+ TQCString utf8;
+
+ while (*uri) {
+ switch (*uri) {
+ case '%': {
+ uint ch = (uchar) uri[1];
+ if ( ch && uri[2] ) {
+ ch = htod( ch ) * 16 + htod( (uchar) uri[2] );
+ utf8 += (char) ch;
+ uri += 2;
+ }
+ }
+ break;
+ default:
+ utf8 += *uri;
+ }
+ ++uri;
+ }
+
+ return TQString::fromUtf8(utf8);
+}
+
+/*!
+ Returns the name of a local file equivalent to \a uri or a null
+ string if \a uri is not a local file.
+
+ Note that URIs are always in escaped UTF8 encoding.
+
+ \sa localFileToUri()
+*/
+TQString TQUriDrag::uriToLocalFile(const char* uri)
+{
+ TQString file;
+
+ if (!uri)
+ return file;
+ if (0==qstrnicmp(uri,"file:/",6)) // It is a local file uri
+ uri += 6;
+ else if (TQString(uri).tqfind(":/") != -1) // It is a different scheme uri
+ return file;
+
+ bool local = uri[0] != '/' || ( uri[0] != '\0' && uri[1] == '/' );
+#ifdef TQ_WS_X11
+ // do we have a hostname?
+ if ( !local && uri[0] == '/' && uri[2] != '/' ) {
+ // then move the pointer to after the 'hostname/' part of the uri
+ const char* hostname_end = strchr( uri+1, '/' );
+ if ( hostname_end != NULL ) {
+ char hostname[ 257 ];
+ if ( gethostname( hostname, 255 ) == 0 ) {
+ hostname[ 256 ] = '\0';
+ if ( tqstrncmp( uri+1, hostname, hostname_end - ( uri+1 )) == 0 ) {
+ uri = hostname_end + 1; // point after the slash
+ local = TRUE;
+ }
+ }
+ }
+ }
+#endif
+ if ( local ) {
+ file = uriToUnicodeUri(uri);
+ if ( uri[1] == '/' ) {
+ file.remove((uint)0,1);
+ } else {
+ file.insert(0,'/');
+ }
+#ifdef TQ_WS_WIN
+ if ( file.length() > 2 && file[0] == '/' && file[2] == '|' ) {
+ file[2] = ':';
+ file.remove(0,1);
+ } else if (file.length() > 2 && file[0] == '/' && file[1].isLetter() && file[2] == ':') {
+ file.remove(0, 1);
+ }
+ // Leave slash as slashes.
+#endif
+ }
+#ifdef TQ_WS_WIN
+ else {
+ file = uriToUnicodeUri(uri);
+ // convert to network path
+ file.insert(1, '/'); // leave as forward slashes
+ }
+#endif
+
+ return file;
+}
+
+/*!
+ Decodes URIs from the mime source event \a e, converts them to
+ local files if they refer to local files, and places them in \a l
+ (which is first cleared).
+
+ Returns TRUE if \e contained a valid list of URIs; otherwise
+ returns FALSE. The list will be empty if no URIs were local files.
+*/
+bool TQUriDrag::decodeLocalFiles( const TQMimeSource* e, TQStringList& l )
+{
+ TQStrList u;
+ if ( !decode( e, u ) )
+ return FALSE;
+
+ l.clear();
+ for (const char* s=u.first(); s; s=u.next()) {
+ TQString lf = uriToLocalFile(s);
+ if ( !lf.isNull() )
+ l.append( lf );
+ }
+ return TRUE;
+}
+
+/*!
+ Decodes URIs from the mime source event \a e, converts them to
+ Unicode URIs (only useful for displaying to humans), placing them
+ in \a l (which is first cleared).
+
+ Returns TRUE if \e contained a valid list of URIs; otherwise
+ returns FALSE.
+*/
+bool TQUriDrag::decodeToUnicodeUris( const TQMimeSource* e, TQStringList& l )
+{
+ TQStrList u;
+ if ( !decode( e, u ) )
+ return FALSE;
+
+ l.clear();
+ for (const char* s=u.first(); s; s=u.next())
+ l.append( uriToUnicodeUri(s) );
+
+ return TRUE;
+}
+
+
+#ifndef TQT_NO_DRAGANDDROP
+/*!
+ If the source of the drag operation is a widget in this
+ application, this function returns that source, otherwise it
+ returns 0. The source of the operation is the first parameter to
+ drag object subclasses.
+
+ This is useful if your widget needs special behavior when dragging
+ to itself, etc.
+
+ See TQDragObject::TQDragObject() and subclasses.
+*/
+TQWidget* TQDropEvent::source() const
+{
+ return qt_dnd_manager ? qt_dnd_manager->dragSource : 0;
+}
+#endif
+
+/*!
+ \class TQColorDrag tqdragobject.h
+
+ \brief The TQColorDrag class provides a drag and drop object for
+ transferring colors.
+
+ \ingroup draganddrop
+
+ This class provides a drag object which can be used to transfer data
+ about colors for drag and drop and in the clipboard. For example, it
+ is used in TQColorDialog.
+
+ The color is set in the constructor but can be changed with
+ setColor().
+
+ For more information about drag and drop, see the TQDragObject class
+ and the \link dnd.html drag and drop documentation\endlink.
+*/
+
+/*!
+ Constructs a color drag object with the color \a col. Passes \a
+ dragsource and \a name to the TQStoredDrag constructor.
+*/
+
+TQColorDrag::TQColorDrag( const TQColor &col, TQWidget *dragsource, const char *name )
+ : TQStoredDrag( "application/x-color", dragsource, name )
+{
+ setColor( col );
+}
+
+/*!
+ Constructs a color drag object with a white color. Passes \a
+ dragsource and \a name to the TQStoredDrag constructor.
+*/
+
+TQColorDrag::TQColorDrag( TQWidget *dragsource, const char *name )
+ : TQStoredDrag( "application/x-color", dragsource, name )
+{
+ setColor( TQt::white );
+}
+
+/*!
+ Sets the color of the color drag to \a col.
+*/
+
+void TQColorDrag::setColor( const TQColor &col )
+{
+ short r = (col.red() << 8) | col.red();
+ short g = (col.green() << 8) | col.green();
+ short b = (col.blue() << 8) | col.blue();
+
+ // make sure we transmit data in network order
+ r = htons(r);
+ g = htons(g);
+ b = htons(b);
+
+ ushort rgba[4] = {
+ r, g, b,
+ 0xffff // Alpha not supported yet.
+ };
+ TQByteArray data(sizeof(rgba));
+ memcpy(data.data(), rgba, sizeof(rgba));
+ setEncodedData(data);
+}
+
+/*!
+ Returns TRUE if the color drag object can decode the mime source
+ \a e; otherwise returns FALSE.
+*/
+
+bool TQColorDrag::canDecode( TQMimeSource *e )
+{
+ return e->provides( "application/x-color" );
+}
+
+/*!
+ Decodes the mime source \a e and sets the decoded values to \a
+ col.
+*/
+
+bool TQColorDrag::decode( TQMimeSource *e, TQColor &col )
+{
+ TQByteArray data = e->tqencodedData("application/x-color");
+ ushort rgba[4];
+ if (data.size() != sizeof(rgba))
+ return FALSE;
+
+ memcpy(rgba, data.data(), sizeof(rgba));
+
+ short r = rgba[0];
+ short g = rgba[1];
+ short b = rgba[2];
+
+ // data is in network order
+ r = ntohs(r);
+ g = ntohs(g);
+ b = ntohs(b);
+
+ r = (r >> 8) & 0xff;
+ g = (g >> 8) & 0xff;
+ b = (b >> 8) & 0xff;
+
+ col.setRgb(r, g, b);
+ return TRUE;
+}
+
+#endif // TQT_NO_MIME
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqdragobject.h b/tqtinterface/qt4/src/kernel/tqdragobject.h
new file mode 100644
index 0000000..3d55967
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdragobject.h
@@ -0,0 +1,508 @@
+#include "tqtglobaldefines.h"
+
+// #ifdef USE_QT4
+#if 0
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TQDRAGOBJECT_H
+#define TQDRAGOBJECT_H
+
+#include <QtCore/qobject.h>
+#include <QtGui/qcolor.h>
+#include <QtGui/qmime.h>
+#include <tqimage.h>
+#include <tqstrlist.h>
+#include <QtCore/qlist.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Qt3SupportLight)
+
+class QWidget;
+class TQTextDragPrivate;
+class TQDragObjectPrivate;
+class TQStoredDragPrivate;
+class TQImageDragPrivate;
+class TQImageDrag;
+class TQTextDrag;
+class TQStrList;
+class TQImage;
+class QPixmap;
+
+class TQDragObject : public TQObject, public QMimeSource {
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQDragObject(QWidget * dragSource = 0, const char *name = 0);
+ virtual ~TQDragObject();
+
+ bool drag();
+ bool dragMove();
+ void dragCopy();
+ void dragLink();
+
+ virtual void setPixmap(QPixmap);
+ virtual void setPixmap(QPixmap, const QPoint& hotspot);
+ QPixmap pixmap() const;
+ QPoint pixmapHotSpot() const;
+
+ QWidget * source();
+ static QWidget * target();
+
+ enum DragMode { DragDefault, DragCopy, DragMove, DragLink, DragCopyOrMove };
+
+protected:
+ TQDragObject(TQDragObjectPrivate &, QWidget *dragSource = 0);
+ virtual bool drag(DragMode);
+
+private:
+ friend class QDragMime;
+ Q_DISABLE_COPY(TQDragObject)
+};
+
+class TQStoredDrag: public TQDragObject {
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQStoredDrag(const char *mimeType, QWidget *dragSource = 0, const char *name = 0);
+ ~TQStoredDrag();
+
+ virtual void setEncodedData(const QByteArray &);
+
+ const char * format(int i) const;
+ virtual QByteArray encodedData(const char*) const;
+
+protected:
+ TQStoredDrag(TQStoredDragPrivate &, const char *mimeType, QWidget *dragSource = 0);
+
+private:
+ Q_DISABLE_COPY(TQStoredDrag)
+};
+
+class TQTextDrag: public TQDragObject {
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQTextDrag(const QString &, QWidget *dragSource = 0, const char *name = 0);
+ TQTextDrag(QWidget * dragSource = 0, const char * name = 0);
+ ~TQTextDrag();
+
+ virtual void setText(const QString &);
+ virtual void setSubtype(const QString &);
+
+ const char * format(int i) const;
+ virtual QByteArray encodedData(const char*) const;
+
+ static bool canDecode(const QMimeSource* e);
+ static bool decode(const QMimeSource* e, QString& s);
+ static bool decode(const QMimeSource* e, QString& s, QString& subtype);
+
+protected:
+ TQTextDrag(TQTextDragPrivate &, QWidget * dragSource = 0);
+
+private:
+ Q_DISABLE_COPY(TQTextDrag)
+};Q_COMPAT_EXPORT
+
+class TQImageDrag: public TQDragObject {
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQImageDrag(TQImage image, QWidget * dragSource = 0, const char * name = 0);
+ TQImageDrag(QWidget * dragSource = 0, const char * name = 0);
+ ~TQImageDrag();
+
+ virtual void setImage(TQImage image);
+
+ const char * format(int i) const;
+ virtual QByteArray encodedData(const char*) const;
+
+ static bool canDecode(const QMimeSource* e);
+ static bool decode(const QMimeSource* e, TQImage& i);
+ static bool decode(const QMimeSource* e, QPixmap& i);
+
+protected:
+ TQImageDrag(TQImageDragPrivate &, QWidget * dragSource = 0);
+
+private:
+ Q_DISABLE_COPY(TQImageDrag)
+};
+
+
+class TQUriDrag: public TQStoredDrag {
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ TQUriDrag(const TQStrList &uris, QWidget * dragSource = 0, const char * name = 0);
+ TQUriDrag(QWidget * dragSource = 0, const char * name = 0);
+ ~TQUriDrag();
+
+ void setFileNames(const QStringList & fnames);
+ inline void setFileNames(const QString & fname) { setFileNames(QStringList(fname)); }
+ void setFilenames(const QStringList & fnames) { setFileNames(fnames); }
+ inline void setFilenames(const QString & fname) { setFileNames(QStringList(fname)); }
+ void setUnicodeUris(const QStringList & uuris);
+ virtual void setUris(const QList<QByteArray> &uris);
+
+ static QString uriToLocalFile(const char*);
+ static QByteArray localFileToUri(const QString&);
+ static QString uriToUnicodeUri(const char*);
+ static QByteArray unicodeUriToUri(const QString&);
+ static bool canDecode(const QMimeSource* e);
+ static bool decode(const QMimeSource* e, TQStrList& i);
+ static bool decodeToUnicodeUris(const QMimeSource* e, QStringList& i);
+ static bool decodeLocalFiles(const QMimeSource* e, QStringList& i);
+
+private:
+ Q_DISABLE_COPY(TQUriDrag)
+};
+
+class TQColorDrag : public TQStoredDrag
+{
+ Q_OBJECT
+ TQ_OBJECT
+ QColor color;
+
+public:
+ TQColorDrag(const QColor &col, QWidget *dragsource = 0, const char *name = 0);
+ TQColorDrag(QWidget * dragSource = 0, const char * name = 0);
+ void setColor(const QColor &col);
+
+ static bool canDecode(QMimeSource *);
+ static bool decode(QMimeSource *, QColor &col);
+
+private:
+ Q_DISABLE_COPY(TQColorDrag)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // TQDRAGOBJECT_H
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Definition of TQDragObject
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQDRAGOBJECT_H
+#define TQDRAGOBJECT_H
+
+class TQWidget;
+class TQTextDragPrivate;
+class TQDragObjectData;
+class TQStoredDragData;
+class TQImageDragData;
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqimage.h"
+#include "tqstrlist.h"
+#include "tqcolor.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_MIME
+
+class TQ_EXPORT TQDragObject: public TQObject, public TQMimeSource {
+ TQ_OBJECT
+public:
+ TQDragObject( QWidget * dragSource = 0, const char * name = 0 );
+ virtual ~TQDragObject();
+
+#ifndef TQT_NO_DRAGANDDROP
+ bool drag();
+ bool dragMove();
+ void dragCopy();
+ void dragLink();
+
+ virtual void setPixmap(QPixmap);
+ virtual void setPixmap(QPixmap, const QPoint& hotspot);
+ TQPixmap pixmap() const;
+ TQPoint pixmapHotSpot() const;
+#endif
+
+ TQWidget * source();
+ static TQWidget * target();
+
+ static void setTarget(QWidget*);
+
+#ifndef TQT_NO_DRAGANDDROP
+ enum DragMode { DragDefault, DragCopy, DragMove, DragLink, DragCopyOrMove };
+
+protected:
+ virtual bool drag(DragMode);
+#endif
+
+private:
+ TQDragObjectData * d;
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQDragObject( const TQDragObject & );
+ TQDragObject &operator=( const TQDragObject & );
+#endif
+};
+
+class TQ_EXPORT TQStoredDrag: public TQDragObject {
+ TQ_OBJECT
+ TQStoredDragData * d;
+
+public:
+ TQStoredDrag( const char * mimeType,
+ QWidget * dragSource = 0, const char * name = 0 );
+ ~TQStoredDrag();
+
+ virtual void setEncodedData( const TQByteArray & );
+
+ const char * format(int i) const;
+ virtual TQByteArray tqencodedData(const char*) const;
+
+private:
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQStoredDrag( const TQStoredDrag & );
+ TQStoredDrag &operator=( const TQStoredDrag & );
+#endif
+};
+
+class TQ_EXPORT TQTextDrag: public TQDragObject {
+ TQ_OBJECT
+ TQTextDragPrivate* d;
+public:
+ TQTextDrag( const TQString &,
+ TQWidget * dragSource = 0, const char * name = 0 );
+ TQTextDrag( TQWidget * dragSource = 0, const char * name = 0 );
+ ~TQTextDrag();
+
+ virtual void setText( const TQString &);
+ virtual void setSubtype( const TQCString &);
+
+ const char * format(int i) const;
+ virtual TQByteArray tqencodedData(const char*) const;
+
+ static bool canDecode( const TQMimeSource* e );
+ static bool decode( const TQMimeSource* e, TQString& s );
+ static bool decode( const TQMimeSource* e, TQString& s, TQCString& subtype );
+
+private:
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQTextDrag( const TQTextDrag & );
+ TQTextDrag &operator=( const TQTextDrag & );
+#endif
+};
+
+class TQ_EXPORT TQImageDrag: public TQDragObject {
+ TQ_OBJECT
+ TQImage img;
+ TQStrList ofmts;
+ TQImageDragData* d;
+
+public:
+ TQImageDrag( QImage image, QWidget * dragSource = 0, const char * name = 0 );
+ TQImageDrag( QWidget * dragSource = 0, const char * name = 0 );
+ ~TQImageDrag();
+
+ virtual void setImage( QImage image );
+
+ const char * format(int i) const;
+ virtual TQByteArray tqencodedData(const char*) const;
+
+ static bool canDecode( const TQMimeSource* e );
+ static bool decode( const TQMimeSource* e, QImage& i );
+ static bool decode( const TQMimeSource* e, QPixmap& i );
+
+private:
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQImageDrag( const TQImageDrag & );
+ TQImageDrag &operator=( const TQImageDrag & );
+#endif
+};
+
+
+class TQ_EXPORT TQUriDrag: public TQStoredDrag {
+ TQ_OBJECT
+
+public:
+ TQUriDrag( TQStrList uris, TQWidget * dragSource = 0, const char * name = 0 );
+ TQUriDrag( TQWidget * dragSource = 0, const char * name = 0 );
+ ~TQUriDrag();
+
+ void setFilenames( const TQStringList & fnames ) { setFileNames( fnames ); }
+ void setFileNames( const TQStringList & fnames );
+ void setUnicodeUris( const TQStringList & uuris );
+ virtual void setUris( TQStrList uris );
+
+ static TQString uriToLocalFile(const char*);
+ static TQCString localFileToUri(const TQString&);
+ static TQString uriToUnicodeUri(const char*);
+ static TQCString tqunicodeUriToUri(const TQString&);
+ static bool canDecode( const TQMimeSource* e );
+ static bool decode( const TQMimeSource* e, TQStrList& i );
+ static bool decodeToUnicodeUris( const TQMimeSource* e, TQStringList& i );
+ static bool decodeLocalFiles( const TQMimeSource* e, TQStringList& i );
+
+private:
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQUriDrag( const TQUriDrag & );
+ TQUriDrag &operator=( const TQUriDrag & );
+#endif
+};
+
+class TQ_EXPORT TQColorDrag : public TQStoredDrag
+{
+ TQ_OBJECT
+ TQColor color;
+
+public:
+ TQColorDrag( const TQColor &col, TQWidget *dragsource = 0, const char *name = 0 );
+ TQColorDrag( TQWidget * dragSource = 0, const char * name = 0 );
+ void setColor( const TQColor &col );
+
+ static bool canDecode( TQMimeSource * );
+ static bool decode( TQMimeSource *, TQColor &col );
+
+private:
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQColorDrag( const TQColorDrag & );
+ TQColorDrag &operator=( const TQColorDrag & );
+#endif
+};
+
+#ifndef TQT_NO_COMPAT
+typedef TQUriDrag TQUrlDrag;
+#endif
+
+#ifndef TQT_NO_DRAGANDDROP
+
+// TQDragManager is not part of the public API. It is defined in a
+// header file simply so different .cpp files can implement different
+// member functions.
+//
+
+class TQ_EXPORT TQDragManager: public TQObject {
+ TQ_OBJECT
+
+private:
+ TQDragManager();
+ ~TQDragManager();
+ // only friend classes can use TQDragManager.
+ friend class TQDragObject;
+ friend class TQDragMoveEvent;
+ friend class TQDropEvent;
+ friend class TQApplication;
+
+ bool eventFilter( TQObject *, TQEvent * );
+ void timerEvent( TQTimerEvent* );
+
+ bool drag( TQDragObject *, TQDragObject::DragMode );
+
+ void cancel( bool deleteSource = TRUE );
+ void move( const TQPoint & );
+ void drop();
+ void updatePixmap();
+
+private:
+ TQDragObject * object;
+ void updateMode( TQt::ButtonState newstate );
+ void updateCursor();
+#if defined(TQ_WS_X11)
+ void createCursors();
+#endif
+
+ TQWidget * dragSource;
+ TQWidget * dropWidget;
+ bool beingCancelled;
+ bool restoreCursor;
+ bool willDrop;
+
+ TQPixmap *pm_cursor;
+ int n_cursor;
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQDragManager( const TQDragManager & );
+ TQDragManager &operator=( const TQDragManager & );
+#endif
+};
+
+#endif
+
+#endif // TQT_NO_MIME
+
+#endif // TQDRAGOBJECT_H
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqdrawutil.cpp b/tqtinterface/qt4/src/kernel/tqdrawutil.cpp
new file mode 100644
index 0000000..6ce07d5
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdrawutil.cpp
@@ -0,0 +1,957 @@
+/****************************************************************************
+**
+** Implementation of draw utilities
+**
+** Created : 950920
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqdrawutil.h"
+#ifndef TQT_NO_DRAWUTIL
+#include "tqbitmap.h"
+#include "tqpixmapcache.h"
+#include "tqapplication.h"
+#include "tqpainter.h"
+
+/*!
+ \relates TQPainter
+
+ \c{#include <tqdrawutil.h>}
+
+ Draws a horizontal (\a y1 == \a y2) or vertical (\a x1 == \a x2)
+ shaded line using the painter \a p.
+
+ Nothing is drawn if \a y1 != \a y2 and \a x1 != \a x2 (i.e. the
+ line is neither horizontal nor vertical).
+
+ The color group argument \a g specifies the shading colors (\link
+ TQColorGroup::light() light\endlink, \link TQColorGroup::dark()
+ dark\endlink and \link TQColorGroup::mid() middle\endlink colors).
+
+ The line appears sunken if \a sunken is TRUE, or raised if \a
+ sunken is FALSE.
+
+ The \a lineWidth argument specifies the line width for each of the
+ lines. It is not the total line width.
+
+ The \a midLineWidth argument specifies the width of a middle line
+ drawn in the TQColorGroup::mid() color.
+
+ If you want to use a TQFrame widget instead, you can make it
+ display a shaded line, for example \c{TQFrame::setFrameStyle(
+ TQFrame::HLine | TQFrame::Sunken )}.
+
+ \warning This function does not look at TQWidget::style() or
+ TQApplication::style(). Use the drawing functions in TQStyle to make
+ widgets that follow the current GUI style.
+
+ \sa qDrawShadeRect(), qDrawShadePanel(), TQStyle::drawPrimitive()
+*/
+
+void qDrawShadeLine( TQPainter *p, int x1, int y1, int x2, int y2,
+ const TQColorGroup &g, bool sunken,
+ int lineWidth, int midLineWidth )
+{
+ if (!( p && lineWidth >= 0 && midLineWidth >= 0 ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "qDrawShadeLine invalid parameters." );
+#endif
+ return;
+ }
+ int tlw = lineWidth*2 + midLineWidth; // total line width
+ TQPen oldPen = p->pen(); // save pen
+ if ( sunken )
+ p->setPen( g.dark() );
+ else
+ p->setPen( g.light() );
+ TQPointArray a;
+ int i;
+ if ( y1 == y2 ) { // horizontal line
+ int y = y1 - tlw/2;
+ if ( x1 > x2 ) { // swap x1 and x2
+ int t = x1;
+ x1 = x2;
+ x2 = t;
+ }
+ x2--;
+ for ( i=0; i<lineWidth; i++ ) { // draw top shadow
+ a.setPoints( 3, x1+i, y+tlw-1-i,
+ x1+i, y+i,
+ x2-i, y+i );
+ p->drawPolyline( a );
+ }
+ if ( midLineWidth > 0 ) {
+ p->setPen( g.mid() );
+ for ( i=0; i<midLineWidth; i++ ) // draw lines in the middle
+ p->drawLine( x1+lineWidth, y+lineWidth+i,
+ x2-lineWidth, y+lineWidth+i );
+ }
+ if ( sunken )
+ p->setPen( g.light() );
+ else
+ p->setPen( g.dark() );
+ for ( i=0; i<lineWidth; i++ ) { // draw bottom shadow
+ a.setPoints( 3, x1+i, y+tlw-i-1,
+ x2-i, y+tlw-i-1,
+ x2-i, y+i+1 );
+ p->drawPolyline( a );
+ }
+ }
+ else if ( x1 == x2 ) { // vertical line
+ int x = x1 - tlw/2;
+ if ( y1 > y2 ) { // swap y1 and y2
+ int t = y1;
+ y1 = y2;
+ y2 = t;
+ }
+ y2--;
+ for ( i=0; i<lineWidth; i++ ) { // draw left shadow
+ a.setPoints( 3, x+i, y2,
+ x+i, y1+i,
+ x+tlw-1, y1+i );
+ p->drawPolyline( a );
+ }
+ if ( midLineWidth > 0 ) {
+ p->setPen( g.mid() );
+ for ( i=0; i<midLineWidth; i++ ) // draw lines in the middle
+ p->drawLine( x+lineWidth+i, y1+lineWidth, x+lineWidth+i, y2 );
+ }
+ if ( sunken )
+ p->setPen( g.light() );
+ else
+ p->setPen( g.dark() );
+ for ( i=0; i<lineWidth; i++ ) { // draw right shadow
+ a.setPoints( 3, x+lineWidth, y2-i,
+ x+tlw-i-1, y2-i,
+ x+tlw-i-1, y1+lineWidth );
+ p->drawPolyline( a );
+ }
+ }
+ p->setPen( oldPen );
+}
+
+
+/*!
+ \relates TQPainter
+
+ \c{#include <tqdrawutil.h>}
+
+ Draws the shaded rectangle specified by (\a x, \a y, \a w, \a h)
+ using the painter \a p.
+
+ The color group argument \a g specifies the shading colors (\link
+ TQColorGroup::light() light\endlink, \link TQColorGroup::dark()
+ dark\endlink and \link TQColorGroup::mid() middle\endlink colors).
+
+ The rectangle appears sunken if \a sunken is TRUE, or raised if \a
+ sunken is FALSE.
+
+ The \a lineWidth argument specifies the line width for each of the
+ lines. It is not the total line width.
+
+ The \a midLineWidth argument specifies the width of a middle line
+ drawn in the TQColorGroup::mid() color.
+
+ The rectangle's interior is filled with the \a fill brush unless
+ \a fill is 0.
+
+ If you want to use a TQFrame widget instead, you can make it
+ display a shaded rectangle, for example \c{TQFrame::setFrameStyle(
+ TQFrame::Box | TQFrame::Raised )}.
+
+ \warning This function does not look at TQWidget::style() or
+ TQApplication::style(). Use the drawing functions in TQStyle to make
+ widgets that follow the current GUI style.
+
+ \sa qDrawShadeLine(), qDrawShadePanel(), qDrawPlainRect(),
+ TQStyle::drawItem(), TQStyle::tqdrawControl()
+ TQStyle::tqdrawComplexControl()
+*/
+
+void qDrawShadeRect( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken,
+ int lineWidth, int midLineWidth,
+ const TQBrush *fill )
+{
+ if ( w == 0 || h == 0 )
+ return;
+ if ( ! ( w > 0 && h > 0 && lineWidth >= 0 && midLineWidth >= 0 ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "qDrawShadeRect(): Invalid parameters" );
+#endif
+ return;
+ }
+ TQPen oldPen = p->pen();
+ if ( sunken )
+ p->setPen( g.dark() );
+ else
+ p->setPen( g.light() );
+ int x1=x, y1=y, x2=x+w-1, y2=y+h-1;
+ TQPointArray a;
+
+ if ( lineWidth == 1 && midLineWidth == 0 ) {// standard shade rectangle
+ p->drawRect( x1, y1, w-1, h-1 );
+ if ( sunken )
+ p->setPen( g.light() );
+ else
+ p->setPen( g.dark() );
+ a.setPoints( 8, x1+1,y1+1, x2-2,y1+1, x1+1,y1+2, x1+1,y2-2,
+ x1,y2, x2,y2, x2,y1, x2,y2-1 );
+ p->drawLineSegments( a ); // draw bottom/right lines
+ } else { // more complicated
+ int m = lineWidth+midLineWidth;
+ int i, j=0, k=m;
+ for ( i=0; i<lineWidth; i++ ) { // draw top shadow
+ a.setPoints( 8, x1+i, y2-i, x1+i, y1+i, x1+i, y1+i, x2-i, y1+i,
+ x1+k, y2-k, x2-k, y2-k, x2-k, y2-k, x2-k, y1+k );
+ p->drawLineSegments( a );
+ k++;
+ }
+ p->setPen( g.mid() );
+ j = lineWidth*2;
+ for ( i=0; i<midLineWidth; i++ ) { // draw lines in the middle
+ p->drawRect( x1+lineWidth+i, y1+lineWidth+i, w-j, h-j );
+ j += 2;
+ }
+ if ( sunken )
+ p->setPen( g.light() );
+ else
+ p->setPen( g.dark() );
+ k = m;
+ for ( i=0; i<lineWidth; i++ ) { // draw bottom shadow
+ a.setPoints( 8, x1+1+i,y2-i, x2-i, y2-i, x2-i, y2-i, x2-i, y1+i+1,
+ x1+k, y2-k, x1+k, y1+k, x1+k, y1+k, x2-k, y1+k );
+ p->drawLineSegments( a );
+ k++;
+ }
+ }
+ if ( fill ) {
+ TQBrush oldBrush = p->brush();
+ int tlw = lineWidth + midLineWidth;
+ p->setPen( TQt::NoPen );
+ p->setBrush( *fill );
+ p->drawRect( x+tlw, y+tlw, w-2*tlw, h-2*tlw );
+ p->setBrush( oldBrush );
+ }
+ p->setPen( oldPen ); // restore pen
+}
+
+
+/*!
+ \relates TQPainter
+
+ \c{#include <tqdrawutil.h>}
+
+ Draws the shaded panel specified by (\a x, \a y, \a w, \a h) using
+ the painter \a p.
+
+ The color group argument \a g specifies the shading colors (\link
+ TQColorGroup::light() light\endlink, \link TQColorGroup::dark()
+ dark\endlink and \link TQColorGroup::mid() middle\endlink colors).
+
+ The panel appears sunken if \a sunken is TRUE, or raised if \a
+ sunken is FALSE.
+
+ The \a lineWidth argument specifies the line width.
+
+ The panel's interior is filled with the \a fill brush unless \a
+ fill is 0.
+
+ If you want to use a TQFrame widget instead, you can make it
+ display a shaded panel, for example \c{TQFrame::setFrameStyle(
+ TQFrame::Panel | TQFrame::Sunken )}.
+
+ \warning This function does not look at TQWidget::style() or
+ TQApplication::style(). Use the drawing functions in TQStyle to make
+ widgets that follow the current GUI style.
+
+ \sa qDrawWinPanel(), qDrawShadeLine(), qDrawShadeRect(),
+ TQStyle::drawPrimitive()
+*/
+
+void qDrawShadePanel( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken,
+ int lineWidth, const TQBrush *fill )
+{
+ if ( w == 0 || h == 0 )
+ return;
+ if ( !( w > 0 && h > 0 && lineWidth >= 0 ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "qDrawShadePanel() Invalid parameters." );
+#endif
+ }
+ TQColor shade = g.dark();
+ TQColor light = g.light();
+ if ( fill ) {
+ if ( fill->color() == shade )
+ shade = g.shadow();
+ if ( fill->color() == light )
+ light = g.midlight();
+ }
+ TQPen oldPen = p->pen(); // save pen
+ TQPointArray a( 4*lineWidth );
+ if ( sunken )
+ p->setPen( shade );
+ else
+ p->setPen( light );
+ int x1, y1, x2, y2;
+ int i;
+ int n = 0;
+ x1 = x;
+ y1 = y2 = y;
+ x2 = x+w-2;
+ for ( i=0; i<lineWidth; i++ ) { // top shadow
+ a.setPoint( n++, x1, y1++ );
+ a.setPoint( n++, x2--, y2++ );
+ }
+ x2 = x1;
+ y1 = y+h-2;
+ for ( i=0; i<lineWidth; i++ ) { // left shadow
+ a.setPoint( n++, x1++, y1 );
+ a.setPoint( n++, x2++, y2-- );
+ }
+ p->drawLineSegments( a );
+ n = 0;
+ if ( sunken )
+ p->setPen( light );
+ else
+ p->setPen( shade );
+ x1 = x;
+ y1 = y2 = y+h-1;
+ x2 = x+w-1;
+ for ( i=0; i<lineWidth; i++ ) { // bottom shadow
+ a.setPoint( n++, x1++, y1-- );
+ a.setPoint( n++, x2, y2-- );
+ }
+ x1 = x2;
+ y1 = y;
+ y2 = y+h-lineWidth-1;
+ for ( i=0; i<lineWidth; i++ ) { // right shadow
+ a.setPoint( n++, x1--, y1++ );
+ a.setPoint( n++, x2--, y2 );
+ }
+ p->drawLineSegments( a );
+ if ( fill ) { // fill with fill color
+ TQBrush oldBrush = p->brush();
+ p->setPen( TQt::NoPen );
+ p->setBrush( *fill );
+ p->drawRect( x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2 );
+ p->setBrush( oldBrush );
+ }
+ p->setPen( oldPen ); // restore pen
+}
+
+
+/*!
+ \internal
+ This function draws a rectangle with two pixel line width.
+ It is called from qDrawWinButton() and qDrawWinPanel().
+
+ c1..c4 and fill are used:
+
+ 1 1 1 1 1 2
+ 1 3 3 3 4 2
+ 1 3 F F 4 2
+ 1 3 F F 4 2
+ 1 4 4 4 4 2
+ 2 2 2 2 2 2
+*/
+
+static void qDrawWinShades( TQPainter *p,
+ int x, int y, int w, int h,
+ const TQColor &c1, const TQColor &c2,
+ const TQColor &c3, const TQColor &c4,
+ const TQBrush *fill )
+{
+ if ( w < 2 || h < 2 ) // can't do anything with that
+ return;
+ TQPen oldPen = p->pen();
+ TQPointArray a( 3 );
+ a.setPoints( 3, x, y+h-2, x, y, x+w-2, y );
+ p->setPen( c1 );
+ p->drawPolyline( a );
+ a.setPoints( 3, x, y+h-1, x+w-1, y+h-1, x+w-1, y );
+ p->setPen( c2 );
+ p->drawPolyline( a );
+ if ( w > 4 && h > 4 ) {
+ a.setPoints( 3, x+1, y+h-3, x+1, y+1, x+w-3, y+1 );
+ p->setPen( c3 );
+ p->drawPolyline( a );
+ a.setPoints( 3, x+1, y+h-2, x+w-2, y+h-2, x+w-2, y+1 );
+ p->setPen( c4 );
+ p->drawPolyline( a );
+ if ( fill ) {
+ TQBrush oldBrush = p->brush();
+ p->setBrush( *fill );
+ p->setPen( TQt::NoPen );
+ p->drawRect( x+2, y+2, w-4, h-4 );
+ p->setBrush( oldBrush );
+ }
+ }
+ p->setPen( oldPen );
+}
+
+
+/*!
+ \relates TQPainter
+
+ \c{#include <tqdrawutil.h>}
+
+ Draws the Windows-style button specified by (\a x, \a y, \a w, \a
+ h) using the painter \a p.
+
+ The color group argument \a g specifies the shading colors (\link
+ TQColorGroup::light() light\endlink, \link TQColorGroup::dark()
+ dark\endlink and \link TQColorGroup::mid() middle\endlink colors).
+
+ The button appears sunken if \a sunken is TRUE, or raised if \a
+ sunken is FALSE.
+
+ The line width is 2 pixels.
+
+ The button's interior is filled with the \a *fill brush unless \a
+ fill is 0.
+
+ \warning This function does not look at TQWidget::style() or
+ TQApplication::style(). Use the drawing functions in TQStyle to make
+ widgets that follow the current GUI style.
+
+ \sa qDrawWinPanel(), TQStyle::tqdrawControl()
+*/
+
+void qDrawWinButton( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken,
+ const TQBrush *fill )
+{
+ if ( sunken )
+ qDrawWinShades( p, x, y, w, h,
+ g.shadow(), g.light(), g.dark(), g.button(), fill );
+ else
+ qDrawWinShades( p, x, y, w, h,
+ g.light(), g.shadow(), g.button(), g.dark(), fill );
+}
+
+/*!
+ \relates TQPainter
+
+ \c{#include <tqdrawutil.h>}
+
+ Draws the Windows-style panel specified by (\a x, \a y, \a w, \a
+ h) using the painter \a p.
+
+ The color group argument \a g specifies the shading colors.
+
+ The panel appears sunken if \a sunken is TRUE, or raised if \a
+ sunken is FALSE.
+
+ The line width is 2 pixels.
+
+ The button's interior is filled with the \a fill brush unless \a
+ fill is 0.
+
+ If you want to use a TQFrame widget instead, you can make it
+ display a shaded panel, for example \c{TQFrame::setFrameStyle(
+ TQFrame::WinPanel | TQFrame::Raised )}.
+
+ \warning This function does not look at TQWidget::style() or
+ TQApplication::style(). Use the drawing functions in TQStyle to make
+ widgets that follow the current GUI style.
+
+ \sa qDrawShadePanel(), qDrawWinButton(), TQStyle::drawPrimitive()
+*/
+
+void qDrawWinPanel( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken,
+ const TQBrush *fill )
+{
+ if ( sunken )
+ qDrawWinShades( p, x, y, w, h,
+ g.dark(), g.light(), g.shadow(), g.midlight(), fill );
+ else
+ qDrawWinShades( p, x, y, w, h,
+ g.light(), g.shadow(), g.midlight(), g.dark(), fill );
+}
+
+
+/*!
+ \relates TQPainter
+
+ \c{#include <tqdrawutil.h>}
+
+ Draws the plain rectangle specified by (\a x, \a y, \a w, \a h)
+ using the painter \a p.
+
+ The color argument \a c specifies the line color.
+
+ The \a lineWidth argument specifies the line width.
+
+ The rectangle's interior is filled with the \a fill brush unless
+ \a fill is 0.
+
+ If you want to use a TQFrame widget instead, you can make it
+ display a plain rectangle, for example \c{TQFrame::setFrameStyle(
+ TQFrame::Box | TQFrame::Plain )}.
+
+ \warning This function does not look at TQWidget::style() or
+ TQApplication::style(). Use the drawing functions in TQStyle to make
+ widgets that follow the current GUI style.
+
+ \sa qDrawShadeRect(), TQStyle::drawPrimitive()
+*/
+
+void qDrawPlainRect( TQPainter *p, int x, int y, int w, int h, const TQColor &c,
+ int lineWidth, const TQBrush *fill )
+{
+ if ( w == 0 || h == 0 )
+ return;
+ if ( !( w > 0 && h > 0 && lineWidth >= 0 ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "qDrawPlainRect() Invalid parameters." );
+#endif
+ }
+ TQPen oldPen = p->pen();
+ TQBrush oldBrush = p->brush();
+ p->setPen( c );
+ p->setBrush( TQt::NoBrush );
+ for ( int i=0; i<lineWidth; i++ )
+ p->drawRect( x+i, y+i, w-i*2, h-i*2 );
+ if ( fill ) { // fill with fill color
+ p->setPen( TQt::NoPen );
+ p->setBrush( *fill );
+ p->drawRect( x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2 );
+ }
+ p->setPen( oldPen );
+ p->setBrush( oldBrush );
+}
+
+
+TQRect qItemRect( TQPainter *p, TQt::GUIStyle gs,
+ int x, int y, int w, int h,
+ int flags,
+ bool enabled,
+ const TQPixmap *pixmap,
+ const TQString& text, int len )
+{
+ TQRect result;
+
+ if ( pixmap ) {
+ if ( (flags & TQt::AlignVCenter) == TQt::AlignVCenter )
+ y += h/2 - pixmap->height()/2;
+ else if ( (flags & TQt::AlignBottom) == TQt::AlignBottom)
+ y += h - pixmap->height();
+ if ( (flags & TQt::AlignRight) == TQt::AlignRight )
+ x += w - pixmap->width();
+ else if ( (flags & TQt::AlignHCenter) == TQt::AlignHCenter )
+ x += w/2 - pixmap->width()/2;
+ else if ( (flags & TQt::AlignLeft) != TQt::AlignLeft && TQApplication::reverseLayout() )
+ x += w - pixmap->width();
+ result = TQRect(x, y, pixmap->width(), pixmap->height());
+ } else if ( !text.isNull() && p ) {
+ result = p->boundingRect( x, y, w, h, flags, text, len );
+ if ( gs == TQt::WindowsStyle && !enabled ) {
+ result.setWidth(result.width()+1);
+ result.setHeight(result.height()+1);
+ }
+ } else {
+ result = TQRect(x, y, w, h);
+ }
+
+ return result;
+}
+
+
+void qDrawItem( TQPainter *p, TQt::GUIStyle gs,
+ int x, int y, int w, int h,
+ int flags,
+ const TQColorGroup &g, bool enabled,
+ const TQPixmap *pixmap,
+ const TQString& text, int len , const TQColor* penColor )
+{
+ p->setPen( penColor?*penColor:g.foreground() );
+ if ( pixmap ) {
+ TQPixmap pm( *pixmap );
+ bool clip = (flags & TQt::DontClip) == 0;
+ if ( clip ) {
+ if ( pm.width() < w && pm.height() < h )
+ clip = FALSE;
+ else
+ p->setClipRect( x, y, w, h );
+ }
+ if ( (flags & TQt::AlignVCenter) == TQt::AlignVCenter )
+ y += h/2 - pm.height()/2;
+ else if ( (flags & TQt::AlignBottom) == TQt::AlignBottom)
+ y += h - pm.height();
+ if ( (flags & TQt::AlignRight) == TQt::AlignRight )
+ x += w - pm.width();
+ else if ( (flags & TQt::AlignHCenter) == TQt::AlignHCenter )
+ x += w/2 - pm.width()/2;
+ else if ( ((flags & TQt::AlignLeft) != TQt::AlignLeft) && TQApplication::reverseLayout() ) // AlignAuto && rightToLeft
+ x += w - pm.width();
+
+ if ( !enabled ) {
+ if ( pm.tqmask() ) { // pixmap with a tqmask
+ if ( !pm.selfMask() ) { // tqmask is not pixmap itself
+ TQPixmap pmm( *pm.tqmask() );
+ pmm.setMask( *((TQBitmap *)&pmm) );
+ pm = pmm;
+ }
+ } else if ( pm.depth() == 1 ) { // monochrome pixmap, no tqmask
+ pm.setMask( *((TQBitmap *)&pm) );
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+ } else { // color pixmap, no tqmask
+ TQString k;
+ k.sprintf( "$qt-drawitem-%x", pm.serialNumber() );
+ TQPixmap *tqmask = TQPixmapCache::tqfind(k);
+ bool del=FALSE;
+ if ( !tqmask ) {
+ tqmask = new TQPixmap( pm.createHeuristicMask() );
+ tqmask->setMask( *((TQBitmap*)tqmask) );
+ del = !TQPixmapCache::insert( k, tqmask );
+ }
+ pm = *tqmask;
+ if (del) delete tqmask;
+#endif
+ }
+ if ( gs == TQt::WindowsStyle ) {
+ p->setPen( g.light() );
+ p->drawPixmap( x+1, y+1, pm );
+ p->setPen( g.text() );
+ }
+ }
+ p->drawPixmap( x, y, pm );
+ if ( clip )
+ p->setClipping( FALSE );
+ } else if ( !text.isNull() ) {
+ if ( gs == TQt::WindowsStyle && !enabled ) {
+ p->setPen( g.light() );
+ p->drawText( x+1, y+1, w, h, flags, text, len );
+ p->setPen( g.text() );
+ }
+ p->drawText( x, y, w, h, flags, text, len );
+ }
+}
+
+
+/*****************************************************************************
+ Overloaded functions.
+ *****************************************************************************/
+
+/*!
+ \overload void qDrawShadeLine( TQPainter *p, const TQPoint &p1, const TQPoint &p2, const TQColorGroup &g, bool sunken, int lineWidth, int midLineWidth )
+*/
+
+void qDrawShadeLine( TQPainter *p, const TQPoint &p1, const TQPoint &p2,
+ const TQColorGroup &g, bool sunken,
+ int lineWidth, int midLineWidth )
+{
+ qDrawShadeLine( p, p1.x(), p1.y(), p2.x(), p2.y(), g, sunken,
+ lineWidth, midLineWidth );
+}
+
+/*!
+ \overload void qDrawShadeRect( TQPainter *p, const TQRect &r, const TQColorGroup &g, bool sunken, int lineWidth, int midLineWidth, const TQBrush *fill )
+*/
+
+void qDrawShadeRect( TQPainter *p, const TQRect &r,
+ const TQColorGroup &g, bool sunken,
+ int lineWidth, int midLineWidth,
+ const TQBrush *fill )
+{
+ qDrawShadeRect( p, r.x(), r.y(), r.width(), r.height(), g, sunken,
+ lineWidth, midLineWidth, fill );
+}
+
+/*!
+ \overload void qDrawShadePanel( TQPainter *p, const TQRect &r, const TQColorGroup &g, bool sunken, int lineWidth, const TQBrush *fill )
+*/
+
+void qDrawShadePanel( TQPainter *p, const TQRect &r,
+ const TQColorGroup &g, bool sunken,
+ int lineWidth, const TQBrush *fill )
+{
+ qDrawShadePanel( p, r.x(), r.y(), r.width(), r.height(), g, sunken,
+ lineWidth, fill );
+}
+
+/*!
+ \overload void qDrawWinButton( TQPainter *p, const TQRect &r, const TQColorGroup &g, bool sunken, const TQBrush *fill )
+*/
+
+void qDrawWinButton( TQPainter *p, const TQRect &r,
+ const TQColorGroup &g, bool sunken,
+ const TQBrush *fill )
+{
+ qDrawWinButton( p, r.x(), r.y(), r.width(), r.height(), g, sunken, fill );
+}
+
+/*!
+ \overload void qDrawWinPanel( TQPainter *p, const TQRect &r, const TQColorGroup &g, bool sunken, const TQBrush *fill )
+*/
+
+void qDrawWinPanel( TQPainter *p, const TQRect &r,
+ const TQColorGroup &g, bool sunken,
+ const TQBrush *fill )
+{
+ qDrawWinPanel( p, r.x(), r.y(), r.width(), r.height(), g, sunken, fill );
+}
+
+/*!
+ \overload void qDrawPlainRect( TQPainter *p, const TQRect &r, const TQColor &c, int lineWidth, const TQBrush *fill )
+*/
+
+// void qDrawPlainRect( TQPainter *p, const TQRect &r, const TQColor &c,
+// int lineWidth, const TQBrush *fill )
+// {
+// qDrawPlainRect( p, r.x(), r.y(), r.width(), r.height(), c,
+// lineWidth, fill );
+// }
+
+
+static void qDrawWinArrow( TQPainter *p, TQt::ArrowType type, bool down,
+ int x, int y, int w, int h,
+ const TQColorGroup &g, bool enabled )
+{
+ TQPointArray a; // arrow polygon
+ switch ( type ) {
+ case TQt::UpArrow:
+ a.setPoints( 7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2 );
+ break;
+ case TQt::DownArrow:
+ a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 );
+ break;
+ case TQt::LeftArrow:
+ a.setPoints( 7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0 );
+ break;
+ case TQt::RightArrow:
+ a.setPoints( 7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0 );
+ break;
+ }
+ if ( a.isNull() )
+ return;
+
+ if ( down ) {
+ x++;
+ y++;
+ }
+
+ TQPen savePen = p->pen(); // save current pen
+ if (down)
+ p->setBrushOrigin(p->brushOrigin() + TQPoint(1,1));
+ p->fillRect( x, y, w, h, g.brush( TQColorGroup::Button ) );
+ if (down)
+ p->setBrushOrigin(p->brushOrigin() - TQPoint(1,1));
+ if ( enabled ) {
+ a.translate( x+w/2, y+h/2 );
+ p->setPen( g.foreground() );
+ p->drawLineSegments( a, 0, 3 ); // draw arrow
+ p->drawPoint( a[6] );
+ } else {
+ a.translate( x+w/2+1, y+h/2+1 );
+ p->setPen( g.light() );
+ p->drawLineSegments( a, 0, 3 ); // draw arrow
+ p->drawPoint( a[6] );
+ a.translate( -1, -1 );
+ p->setPen( g.mid() );
+ p->drawLineSegments( a, 0, 3 ); // draw arrow
+ p->drawPoint( a[6] );
+ }
+ p->setPen( savePen ); // restore pen
+}
+
+
+#if defined(TQ_CC_MSVC)
+#pragma warning(disable: 4244)
+#endif
+
+#ifndef TQT_NO_STYLE_MOTIF
+// motif arrows look the same whether they are used or not
+// is this correct?
+static void qDrawMotifArrow( TQPainter *p, TQt::ArrowType type, bool down,
+ int x, int y, int w, int h,
+ const TQColorGroup &g, bool )
+{
+ TQPointArray bFill; // fill polygon
+ TQPointArray bTop; // top shadow.
+ TQPointArray bBot; // bottom shadow.
+ TQPointArray bLeft; // left shadow.
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix matrix; // xform matrix
+#endif
+ bool vertical = type == TQt::UpArrow || type == TQt::DownArrow;
+ bool horizontal = !vertical;
+ int dim = w < h ? w : h;
+ int colspec = 0x0000; // color specification array
+
+ if ( dim < 2 ) // too small arrow
+ return;
+
+ if ( dim > 3 ) {
+ if ( dim > 6 )
+ bFill.resize( dim & 1 ? 3 : 4 );
+ bTop.resize( (dim/2)*2 );
+ bBot.resize( dim & 1 ? dim + 1 : dim );
+ bLeft.resize( dim > 4 ? 4 : 2 );
+ bLeft.putPoints( 0, 2, 0,0, 0,dim-1 );
+ if ( dim > 4 )
+ bLeft.putPoints( 2, 2, 1,2, 1,dim-3 );
+ bTop.putPoints( 0, 4, 1,0, 1,1, 2,1, 3,1 );
+ bBot.putPoints( 0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2 );
+
+ for( int i=0; i<dim/2-2 ; i++ ) {
+ bTop.putPoints( i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i );
+ bBot.putPoints( i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i );
+ }
+ if ( dim & 1 ) // odd number size: extra line
+ bBot.putPoints( dim-1, 2, dim-3,dim/2, dim-1,dim/2 );
+ if ( dim > 6 ) { // dim>6: must fill interior
+ bFill.putPoints( 0, 2, 1,dim-3, 1,2 );
+ if ( dim & 1 ) // if size is an odd number
+ bFill.setPoint( 2, dim - 3, dim / 2 );
+ else
+ bFill.putPoints( 2, 2, dim-4,dim/2-1, dim-4,dim/2 );
+ }
+ }
+ else {
+ if ( dim == 3 ) { // 3x3 arrow pattern
+ bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 );
+ bTop .setPoints( 2, 1,0, 1,0 );
+ bBot .setPoints( 2, 1,2, 2,1 );
+ }
+ else { // 2x2 arrow pattern
+ bLeft.setPoints( 2, 0,0, 0,1 );
+ bTop .setPoints( 2, 1,0, 1,0 );
+ bBot .setPoints( 2, 1,1, 1,1 );
+ }
+ }
+
+ if ( type == TQt::UpArrow || type == TQt::LeftArrow ) {
+#ifndef TQT_NO_TRANSFORMATIONS // #### fix me!
+ matrix.translate( x, y );
+ if ( vertical ) {
+ matrix.translate( 0, h - 1 );
+ matrix.rotate( -90 );
+ } else {
+ matrix.translate( w - 1, h - 1 );
+ matrix.rotate( 180 );
+ }
+#endif
+ if ( down )
+ colspec = horizontal ? 0x2334 : 0x2343;
+ else
+ colspec = horizontal ? 0x1443 : 0x1434;
+ }
+ else if ( type == TQt::DownArrow || type == TQt::RightArrow ) {
+#ifndef TQT_NO_TRANSFORMATIONS // #### fix me!
+ matrix.translate( x, y );
+ if ( vertical ) {
+ matrix.translate( w-1, 0 );
+ matrix.rotate( 90 );
+ }
+#endif
+ if ( down )
+ colspec = horizontal ? 0x2443 : 0x2434;
+ else
+ colspec = horizontal ? 0x1334 : 0x1343;
+ }
+
+ TQColor *cols[5];
+ cols[0] = 0;
+ cols[1] = (TQColor *)&g.button();
+ cols[2] = (TQColor *)&g.mid();
+ cols[3] = (TQColor *)&g.light();
+ cols[4] = (TQColor *)&g.dark();
+#define CMID *cols[ (colspec>>12) & 0xf ]
+#define CLEFT *cols[ (colspec>>8) & 0xf ]
+#define CTOP *cols[ (colspec>>4) & 0xf ]
+#define CBOT *cols[ colspec & 0xf ]
+
+ TQPen savePen = p->pen(); // save current pen
+ TQBrush saveBrush = p->brush(); // save current brush
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix wxm = p->tqworldMatrix();
+#endif
+ TQPen pen( TQt::NoPen );
+ const TQBrush &brush = g.brush( TQColorGroup::Button );
+
+ p->setPen( pen );
+ p->setBrush( brush );
+#ifndef TQT_NO_TRANSFORMATIONS
+ p->setWorldMatrix( matrix, TRUE ); // set transformation matrix
+#endif
+ p->drawPolygon( bFill ); // fill arrow
+ p->setBrush( TQt::NoBrush ); // don't fill
+
+ p->setPen( CLEFT );
+ p->drawLineSegments( bLeft );
+ p->setPen( CTOP );
+ p->drawLineSegments( bTop );
+ p->setPen( CBOT );
+ p->drawLineSegments( bBot );
+
+#ifndef TQT_NO_TRANSFORMATIONS
+ p->setWorldMatrix( wxm );
+#endif
+ p->setBrush( saveBrush ); // restore brush
+ p->setPen( savePen ); // restore pen
+
+#undef CMID
+#undef CLEFT
+#undef CTOP
+#undef CBOT
+}
+#endif
+
+void qDrawArrow( TQPainter *p, TQt::ArrowType type, TQt::GUIStyle style, bool down,
+ int x, int y, int w, int h,
+ const TQColorGroup &g, bool enabled )
+{
+ switch ( style ) {
+ case TQt::WindowsStyle:
+ qDrawWinArrow( p, type, down, x, y, w, h, g, enabled );
+ break;
+#ifndef TQT_NO_STYLE_MOTIF
+ case TQt::MotifStyle:
+ qDrawMotifArrow( p, type, down, x, y, w, h, g, enabled );
+ break;
+#endif
+ default:
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "qDrawArrow: Requested GUI style not supported" );
+#else
+ ;
+#endif
+ }
+}
+#endif //TQT_NO_DRAWUTIL
diff --git a/tqtinterface/qt4/src/kernel/tqdrawutil.h b/tqtinterface/qt4/src/kernel/tqdrawutil.h
new file mode 100644
index 0000000..b92d5d9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdrawutil.h
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Definition of draw utilities
+**
+** Created : 950920
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQDRAWUTIL_H
+#define TQDRAWUTIL_H
+
+#ifndef TQT_H
+#include "tqnamespace.h"
+#include "tqstring.h" // char*->TQString conversion
+#endif // TQT_H
+
+class TQPainter;
+class TQColorGroup;
+class TQPoint;
+class TQBrush;
+class TQRect;
+class TQPixmap;
+
+#ifndef TQT_NO_DRAWUTIL
+//
+// Standard shade drawing
+//
+
+TQ_EXPORT void qDrawShadeLine( TQPainter *p, int x1, int y1, int x2, int y2,
+ const TQColorGroup &g, bool sunken = TRUE,
+ int lineWidth = 1, int midLineWidth = 0 );
+
+TQ_EXPORT void qDrawShadeLine( TQPainter *p, const TQPoint &p1, const TQPoint &p2,
+ const TQColorGroup &g, bool sunken = TRUE,
+ int lineWidth = 1, int midLineWidth = 0 );
+
+TQ_EXPORT void qDrawShadeRect( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &, bool sunken=FALSE,
+ int lineWidth = 1, int midLineWidth = 0,
+ const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawShadeRect( TQPainter *p, const TQRect &r,
+ const TQColorGroup &, bool sunken=FALSE,
+ int lineWidth = 1, int midLineWidth = 0,
+ const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawShadePanel( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &, bool sunken=FALSE,
+ int lineWidth = 1, const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawShadePanel( TQPainter *p, const TQRect &r,
+ const TQColorGroup &, bool sunken=FALSE,
+ int lineWidth = 1, const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawWinButton( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken = FALSE,
+ const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawWinButton( TQPainter *p, const TQRect &r,
+ const TQColorGroup &g, bool sunken = FALSE,
+ const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawWinPanel( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &, bool sunken=FALSE,
+ const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawWinPanel( TQPainter *p, const TQRect &r,
+ const TQColorGroup &, bool sunken=FALSE,
+ const TQBrush *fill = 0 );
+
+TQ_EXPORT void qDrawPlainRect( TQPainter *p, int x, int y, int w, int h, const TQColor &,
+ int lineWidth = 1, const TQBrush *fill = 0 );
+
+// TQ_EXPORT void qDrawPlainRect( TQPainter *p, const TQRect &r, const TQColor &,
+// int lineWidth = 1, const TQBrush *fill = 0 );
+
+
+//
+// Other obsolete drawing functions.
+// Use TQStyle::tqitemRect(), TQStyle::drawItem() and TQStyle::drawArrow() instead.
+//
+TQ_EXPORT TQRect qItemRect( TQPainter *p, TQt::GUIStyle gs, int x, int y, int w, int h,
+ int flags, bool enabled,
+ const TQPixmap *pixmap, const TQString& text, int len=-1 );
+
+TQ_EXPORT void qDrawItem( TQPainter *p, TQt::GUIStyle gs, int x, int y, int w, int h,
+ int flags, const TQColorGroup &g, bool enabled,
+ const TQPixmap *pixmap, const TQString& text,
+ int len=-1, const TQColor* penColor = 0 );
+
+TQ_EXPORT void qDrawArrow( TQPainter *p, TQt::ArrowType type, TQt::GUIStyle style, bool down,
+ int x, int y, int w, int h,
+ const TQColorGroup &g, bool enabled );
+
+#endif // TQT_NO_DRAWUTIL
+#endif // TQDRAWUTIL_H
diff --git a/tqtinterface/qt4/src/kernel/tqdropsite.cpp b/tqtinterface/qt4/src/kernel/tqdropsite.cpp
new file mode 100644
index 0000000..60645b9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdropsite.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Implementation of Drag and Drop support
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqdropsite.h"
+
+#ifndef TQT_NO_DRAGANDDROP
+
+#include "tqwidget.h"
+
+
+// NOT REVISED
+/*!
+ \class TQDropSite tqdropsite.h
+ \brief The TQDropSite class provides nothing and does nothing.
+
+ \obsolete
+
+ If your code uses it, you can safely delete it.
+
+ It was used in TQt 1.x to do some drag and drop; that has since been
+ folded into TQWidget.
+
+ For detailed information about drag-and-drop, see the TQDragObject class.
+
+ \sa TQDragObject, TQTextDrag, TQImageDrag
+*/
+
+/*!
+ Constructs a TQDropSite to handle events for the widget \a self.
+
+ Pass \c this as the \a self parameter.
+ This enables dropping by calling TQWidget::setAcceptDrops(TRUE).
+*/
+TQDropSite::TQDropSite( TQWidget* self )
+{
+ self->setAcceptDrops( TRUE );
+}
+
+/*!
+ Destroys the drop site.
+*/
+TQDropSite::~TQDropSite()
+{
+}
+
+#endif // TQT_NO_DRAGANDDROP
diff --git a/tqtinterface/qt4/src/kernel/tqdropsite.h b/tqtinterface/qt4/src/kernel/tqdropsite.h
new file mode 100644
index 0000000..cd650fa
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqdropsite.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Definitation of Drag and Drop support
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQDROPSITE_H
+#define TQDROPSITE_H
+
+#ifndef TQT_H
+#ifndef TQT_H
+#include "tqglobal.h"
+#endif // TQT_H
+#endif
+
+
+class TQWidget;
+
+
+class TQ_EXPORT TQDropSite {
+public:
+ TQDropSite( TQWidget* tqparent );
+ virtual ~TQDropSite();
+};
+
+
+#endif // TQDROPSITE_H
diff --git a/tqtinterface/qt4/src/kernel/tqevent.cpp b/tqtinterface/qt4/src/kernel/tqevent.cpp
new file mode 100644
index 0000000..b34f38d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqevent.cpp
@@ -0,0 +1,2708 @@
+/****************************************************************************
+**
+** Implementation of event classes
+**
+** Created : 931029
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+#ifdef USE_QT4
+// Nasty, nasty horrid HACK to get access to QFont's private members
+// This is TERRIBLE and I wish there was a way around it
+// See also QRect
+#define private protected
+#include <Qt/qevent.h>
+#undef private
+#endif // USE_QT4
+
+#include "tqevent.h"
+#include "tqcursor.h"
+#include "tqapplication.h"
+
+#ifdef USE_QT4
+
+// TQFocusEvent::Reason TQFocusEvent::prev_reason = TQFocusEvent::Other;
+
+/*!
+ Sets the reason for all future focus events to \a reason.
+
+ \sa reason(), resetReason()
+ */
+void TQFocusEvent::setReason( Qt::FocusReason reason )
+{
+ prev_reason = m_reason;
+ m_reason = reason;
+}
+
+/*!
+ Resets the reason for all future focus events to the value before
+ the last setReason() call.
+
+ \sa reason(), setReason()
+ */
+void TQFocusEvent::resetReason()
+{
+ m_reason = prev_reason;
+}
+
+TQt::ButtonState TQContextMenuEvent::state() const {
+ return TQt::ButtonState(int(QApplication::keyboardModifiers())|QApplication::mouseButtons());
+}
+
+/*!
+ \class TQCustomEvent tqevent.h
+ \brief The TQCustomEvent class provides support for custom events.
+
+ \ingroup events
+
+ TQCustomEvent is a generic event class for user-defined events.
+ User defined events can be sent to widgets or other TQObject
+ instances using TQApplication::postEvent() or
+ TQApplication::sendEvent(). Subclasses of TQObject can easily
+ receive custom events by implementing the TQObject::customEvent()
+ event handler function.
+
+ TQCustomEvent objects should be created with a type ID that
+ uniquely identifies the event type. To avoid clashes with the
+ TQt-defined events types, the value should be at least as large as
+ the value of the "User" entry in the TQEvent::Type enum.
+
+ TQCustomEvent tqcontains a generic void* data member that may be used
+ for transferring event-specific data to the receiver. Note that
+ since events are normally delivered asynchronously, the data
+ pointer, if used, must remain valid until the event has been
+ received and processed.
+
+ TQCustomEvent can be used as-is for simple user-defined event
+ types, but normally you will want to make a subclass of it for
+ your event types. In a subclass, you can add data members that are
+ suitable for your event type.
+
+ Example:
+ \code
+ class ColorChangeEvent : public TQCustomEvent
+ {
+ public:
+ ColorChangeEvent( TQColor color )
+ : TQCustomEvent( 65432 ), c( color ) {}
+ TQColor color() const { return c; }
+ private:
+ TQColor c;
+ };
+
+ // To send an event of this custom event type:
+
+ ColorChangeEvent* ce = new ColorChangeEvent( blue );
+ TQApplication::postEvent( receiver, ce ); // TQt will delete it when done
+
+ // To receive an event of this custom event type:
+
+ void MyWidget::customEvent( TQCustomEvent * e )
+ {
+ if ( e->type() == 65432 ) { // It must be a ColorChangeEvent
+ ColorChangeEvent* ce = (ColorChangeEvent*)e;
+ newColor = ce->color();
+ }
+ }
+ \endcode
+
+ \sa TQWidget::customEvent(), TQApplication::notify()
+*/
+
+
+/*!
+ Constructs a custom event object with event type \a type. The
+ value of \a type must be at least as large as TQEvent::User. The
+ data pointer is set to 0.
+*/
+
+TQCustomEvent::TQCustomEvent( int type )
+ : TQEvent( (TQEvent::Type)type ), d( 0 )
+{
+}
+
+
+/*!
+ \fn TQCustomEvent::TQCustomEvent( Type type, void *data )
+
+ Constructs a custom event object with the event type \a type and a
+ pointer to \a data. (Note that any int value may safely be cast to
+ TQEvent::Type).
+*/
+
+
+/*!
+ \fn void TQCustomEvent::setData( void* data )
+
+ Sets the generic data pointer to \a data.
+
+ \sa data()
+*/
+
+/*!
+ \fn void *TQCustomEvent::data() const
+
+ Returns a pointer to the generic event data.
+
+ \sa setData()
+*/
+
+#else // USE_QT4
+
+/*!
+ \class TQEvent tqevent.h
+ \brief The TQEvent class is the base class of all
+ event classes. Event objects contain event parameters.
+
+ \ingroup events
+ \ingroup environment
+
+ TQt's main event loop (TQApplication::exec()) fetches native window
+ system events from the event queue, translates them into TQEvents
+ and sends the translated events to TQObjects.
+
+ In general, events come from the underlying window system
+ (spontaneous() returns TRUE) but it is also possible to manually
+ send events using TQApplication::sendEvent() and
+ TQApplication::postEvent() (spontaneous() returns FALSE).
+
+ TQObjects receive events by having their TQObject::event() function
+ called. The function can be reimplemented in subclasses to
+ customize event handling and add additional event types;
+ TQWidget::event() is a notable example. By default, events are
+ dispatched to event handlers like TQObject::timerEvent() and
+ TQWidget::mouseMoveEvent(). TQObject::installEventFilter() allows an
+ object to intercept events destined for another object.
+
+ The basic TQEvent tqcontains only an event type parameter.
+ Subclasses of TQEvent contain additional parameters that describe
+ the particular event.
+
+ \sa TQObject::event() TQObject::installEventFilter()
+ TQWidget::event() TQApplication::sendEvent()
+ TQApplication::postEvent() TQApplication::processEvents()
+*/
+
+
+/*!
+ \enum TQt::ButtonState
+
+ This enum type describes the state of the mouse and the modifier
+ buttons.
+
+ \value NoButton used when the button state does not refer to any
+ button (see TQMouseEvent::button()).
+ \value LeftButton set if the left button is pressed, or if this
+ event refers to the left button. (The left button may be
+ the right button on left-handed mice.)
+ \value RightButton the right button.
+ \value MidButton the middle button.
+ \value ShiftButton a Shift key on the keyboard is also pressed.
+ \value ControlButton a Ctrl key on the keyboard is also pressed.
+ \value AltButton an Alt key on the keyboard is also pressed.
+ \value MetaButton a Meta key on the keyboard is also pressed.
+ \value Keypad a keypad button is pressed.
+ \value KeyButtonMask a tqmask for ShiftButton, ControlButton,
+ AltButton and MetaButton.
+ \value MouseButtonMask a tqmask for LeftButton, RightButton and MidButton.
+*/
+
+/*!
+ \enum TQEvent::Type
+
+ This enum type defines the valid event types in TQt. The event
+ types and the specialized classes for each type are these:
+
+ \value None Not an event.
+ \value Accessibility Accessibility information is requested
+ \value Timer Regular timer events, \l{TQTimerEvent}.
+ \value MouseButtonPress Mouse press, \l{TQMouseEvent}.
+ \value MouseButtonRelease Mouse release, \l{TQMouseEvent}.
+ \value MouseButtonDblClick Mouse press again, \l{TQMouseEvent}.
+ \value MouseMove Mouse move, \l{TQMouseEvent}.
+ \value KeyPress Key press (including Shift, for example), \l{TQKeyEvent}.
+ \value KeyRelease Key release, \l{TQKeyEvent}.
+ \value IMStart The start of input method composition, \l{TQIMEvent}.
+ \value IMCompose Input method composition is taking place, \l{TQIMEvent}.
+ \value IMEnd The end of input method composition, \l{TQIMEvent}.
+ \value FocusIn Widget gains keyboard focus, \l{TQFocusEvent}.
+ \value FocusOut Widget loses keyboard focus, \l{TQFocusEvent}.
+ \value Enter Mouse enters widget's boundaries.
+ \value Leave Mouse leaves widget's boundaries.
+ \value Paint Screen update necessary, \l{TQPaintEvent}.
+ \value Move Widget's position changed, \l{TQMoveEvent}.
+ \value Resize Widget's size changed, \l{TQResizeEvent}.
+ \value Show Widget was shown on screen, \l{TQShowEvent}.
+ \value Hide Widget was hidden, \l{TQHideEvent}.
+ \value ShowToParent A child widget has been shown.
+ \value HideToParent A child widget has been hidden.
+ \value Close Widget was closed (permanently), \l{TQCloseEvent}.
+ \value ShowNormal Widget should be shown normally (obsolete).
+ \value ShowMaximized Widget should be shown maximized (obsolete).
+ \value ShowMinimized Widget should be shown minimized (obsolete).
+ \value ShowFullScreen Widget should be shown full-screen (obsolete).
+ \value ShowWindowRequest Widget's window should be shown (obsolete).
+ \value DeferredDelete The object will be deleted after it has
+ cleaned up.
+ \value Accel Key press in child for shortcut key handling, \l{TQKeyEvent}.
+ \value Wheel Mouse wheel rolled, \l{TQWheelEvent}.
+ \value ContextMenu Context popup menu, \l{TQContextMenuEvent}
+ \value AccelOverride Key press in child, for overriding shortcut key handling, \l{TQKeyEvent}.
+ \value AccelAvailable internal.
+ \value WindowActivate Window was activated.
+ \value WindowDeactivate Window was deactivated.
+ \value CaptionChange Widget's caption changed.
+ \value IconChange Widget's icon changed.
+ \value ParentFontChange Font of the tqparent widget changed.
+ \value ApplicationFontChange Default application font changed.
+ \value PaletteChange Palette of the widget changed.
+ \value ParentPaletteChange Palette of the tqparent widget changed.
+ \value ApplicationPaletteChange Default application palette changed.
+ \value Clipboard Clipboard contents have changed.
+ \value SockAct Socket activated, used to implement \l{TQSocketNotifier}.
+ \value DragEnter A drag-and-drop enters widget, \l{TQDragEnterEvent}.
+ \value DragMove A drag-and-drop is in progress, \l{TQDragMoveEvent}.
+ \value DragLeave A drag-and-drop leaves widget, \l{TQDragLeaveEvent}.
+ \value Drop A drag-and-drop is completed, \l{TQDropEvent}.
+ \value DragResponse Internal event used by TQt on some platforms.
+ \value ChildInserted Object gets a child, \l{TQChildEvent}.
+ \value ChildRemoved Object loses a child, \l{TQChildEvent}.
+ \value LayoutHint Widget child has changed tqlayout properties.
+ \value ActivateControl Internal event used by TQt on some platforms.
+ \value DeactivateControl Internal event used by TQt on some platforms.
+ \value LanguageChange The application translation changed, \l{TQTranslator}
+ \value LayoutDirectionChange The direction of layouts changed
+ \value LocaleChange The system locale changed
+ \value Quit Reserved.
+ \value Create Reserved.
+ \value Destroy Reserved.
+ \value Retqparent Reserved.
+ \value Speech Reserved for speech input.
+ \value TabletMove A Wacom Tablet Move Event.
+ \value Style Internal use only
+ \value TabletPress A Wacom Tablet Press Event
+ \value TabletRelease A Wacom Tablet Release Event
+ \value OkRequest Internal event used by TQt on some platforms.
+ \value HelpRequest Internal event used by TQt on some platforms.
+ \value IconDrag Internal event used by TQt on some platforms when proxy icon is dragged.
+ \value WindowStateChange The window's state, i.e. minimized,
+ maximized or full-screen, has changed. See \l{TQWidget::windowState()}.
+ \value WindowBlocked The window is modally blocked
+ \value WindowUnblocked The window leaves modal blocking
+
+ \value User User defined event.
+ \value MaxUser Last user event id.
+
+ User events should have values between User and MaxUser inclusive.
+*/
+/*!
+ \fn TQEvent::TQEvent( Type type )
+
+ Contructs an event object of type \a type.
+*/
+
+/*!
+ \fn TQEvent::Type TQEvent::type() const
+
+ Returns the event type.
+*/
+
+/*!
+ \fn bool TQEvent::spontaneous() const
+
+ Returns TRUE if the event originated outside the application, i.e.
+ it is a system event; otherwise returns FALSE.
+*/
+
+
+/*!
+ \class TQTimerEvent tqevent.h
+ \brief The TQTimerEvent class tqcontains parameters that describe a
+ timer event.
+
+ \ingroup events
+
+ Timer events are sent at regular intervals to objects that have
+ started one or more timers. Each timer has a unique identifier. A
+ timer is started with TQObject::startTimer().
+
+ The TQTimer class provides a high-level programming interface that
+ uses Q_SIGNALS instead of events. It also provides one-shot timers.
+
+ The event handler TQObject::timerEvent() receives timer events.
+
+ \sa TQTimer, TQObject::timerEvent(), TQObject::startTimer(),
+ TQObject::killTimer(), TQObject::killTimers()
+*/
+
+/*!
+ \fn TQTimerEvent::TQTimerEvent( int timerId )
+
+ Constructs a timer event object with the timer identifier set to
+ \a timerId.
+*/
+
+/*!
+ \fn int TQTimerEvent::timerId() const
+
+ Returns the unique timer identifier, which is the same identifier
+ as returned from TQObject::startTimer().
+*/
+
+
+/*!
+ \class TQMouseEvent tqevent.h
+ \ingroup events
+
+ \brief The TQMouseEvent class tqcontains parameters that describe a mouse event.
+
+ Mouse events occur when a mouse button is pressed or released
+ inside a widget or when the mouse cursor is moved.
+
+ Mouse move events will occur only when a mouse button is pressed
+ down, unless mouse tracking has been enabled with
+ TQWidget::setMouseTracking().
+
+ TQt automatically grabs the mouse when a mouse button is pressed
+ inside a widget; the widget will continue to receive mouse events
+ until the last mouse button is released.
+
+ A mouse event tqcontains a special accept flag that indicates
+ whether the receiver wants the event. You should call
+ TQMouseEvent::ignore() if the mouse event is not handled by your
+ widget. A mouse event is propagated up the tqparent widget chain
+ until a widget accepts it with TQMouseEvent::accept() or an event
+ filter consumes it.
+
+ The functions pos(), x() and y() give the cursor position relative
+ to the widget that receives the mouse event. If you move the
+ widget as a result of the mouse event, use the global position
+ returned by globalPos() to avoid a shaking motion.
+
+ The TQWidget::setEnabled() function can be used to enable or
+ disable mouse and keyboard events for a widget.
+
+ The event handlers TQWidget::mousePressEvent(),
+ TQWidget::mouseReleaseEvent(), TQWidget::mouseDoubleClickEvent() and
+ TQWidget::mouseMoveEvent() receive mouse events.
+
+ \sa TQWidget::setMouseTracking(), TQWidget::grabMouse(),
+ TQCursor::pos()
+*/
+
+/*!
+ \fn TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, int button, int state )
+
+ Constructs a mouse event object.
+
+ The \a type parameter must be one of \c TQEvent::MouseButtonPress,
+ \c TQEvent::MouseButtonRelease, \c TQEvent::MouseButtonDblClick or
+ \c TQEvent::MouseMove.
+
+ The \a pos parameter specifies the position relative to the
+ receiving widget. \a button specifies the \link TQt::ButtonState
+ button\endlink that caused the event, which should be \c
+ TQt::NoButton (0), if \a type is \c MouseMove. \a state is the
+ \link TQt::ButtonState ButtonState\endlink at the time of the
+ event.
+
+ The globalPos() is initialized to TQCursor::pos(), which may not be
+ appropriate. Use the other constructor to specify the global
+ position explicitly.
+*/
+
+TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, int button, int state )
+ : TQEvent(type), p(pos), b(button),s((ushort)state), accpt(TRUE){
+ g = TQCursor::pos();
+}
+
+
+/*!
+ \fn TQMouseEvent::TQMouseEvent( Type type, const TQPoint &pos, const TQPoint &globalPos, int button, int state )
+
+ Constructs a mouse event object.
+
+ The \a type parameter must be \c TQEvent::MouseButtonPress, \c
+ TQEvent::MouseButtonRelease, \c TQEvent::MouseButtonDblClick or \c
+ TQEvent::MouseMove.
+
+ The \a pos parameter specifies the position relative to the
+ receiving widget. \a globalPos is the position in absolute
+ coordinates. \a button specifies the \link TQt::ButtonState
+ button\endlink that caused the event, which should be \c
+ TQt::NoButton (0), if \a type is \c MouseMove. \a state is the
+ \link TQt::ButtonState ButtonState\endlink at the time of the
+ event.
+
+*/
+
+/*!
+ \fn const TQPoint &TQMouseEvent::pos() const
+
+ Returns the position of the mouse pointer relative to the widget
+ that received the event.
+
+ If you move the widget as a result of the mouse event, use the
+ global position returned by globalPos() to avoid a shaking motion.
+
+ \sa x(), y(), globalPos()
+*/
+
+/*!
+ \fn const TQPoint &TQMouseEvent::globalPos() const
+
+ Returns the global position of the mouse pointer \e{at the time
+ of the event}. This is important on asynchronous window systems
+ like X11. Whenever you move your widgets around in response to
+ mouse events, globalPos() may differ a lot from the current
+ pointer position TQCursor::pos(), and from TQWidget::mapToGlobal(
+ pos() ).
+
+ \sa globalX(), globalY()
+*/
+
+/*!
+ \fn int TQMouseEvent::x() const
+
+ Returns the x-position of the mouse pointer, relative to the
+ widget that received the event.
+
+ \sa y(), pos()
+*/
+
+/*!
+ \fn int TQMouseEvent::y() const
+
+ Returns the y-position of the mouse pointer, relative to the
+ widget that received the event.
+
+ \sa x(), pos()
+*/
+
+/*!
+ \fn int TQMouseEvent::globalX() const
+
+ Returns the global x-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalY(), globalPos()
+*/
+
+/*!
+ \fn int TQMouseEvent::globalY() const
+
+ Returns the global y-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalX(), globalPos()
+*/
+
+/*!
+ \fn ButtonState TQMouseEvent::button() const
+
+ Returns the button that caused the event.
+
+ Possible return values are \c LeftButton, \c RightButton, \c
+ MidButton and \c NoButton.
+
+ Note that the returned value is always \c NoButton for mouse move
+ events.
+
+ \sa state() TQt::ButtonState
+*/
+
+
+/*!
+ \fn ButtonState TQMouseEvent::state() const
+
+ Returns the button state (a combination of mouse buttons and
+ keyboard modifiers), i.e. what buttons and keys were being pressed
+ immediately before the event was generated.
+
+ This means that if you have a \c TQEvent::MouseButtonPress or a \c
+ TQEvent::MouseButtonDblClick state() will \e not include the mouse
+ button that's pressed. But once the mouse button has been
+ released, the \c TQEvent::MouseButtonRelease event will have the
+ button() that was pressed.
+
+ This value is mainly interesting for \c TQEvent::MouseMove; for the
+ other cases, button() is more useful.
+
+ The returned value is \c LeftButton, \c RightButton, \c MidButton,
+ \c ShiftButton, \c ControlButton and \c AltButton OR'ed together.
+
+ \sa button() stateAfter() TQt::ButtonState
+*/
+
+/*!
+ \fn ButtonState TQMouseEvent::stateAfter() const
+
+ Returns the state of buttons after the event.
+
+ \sa state() TQt::ButtonState
+*/
+TQt::ButtonState TQMouseEvent::stateAfter() const
+{
+ return TQt::ButtonState(state()^button());
+}
+
+
+
+/*!
+ \fn bool TQMouseEvent::isAccepted() const
+
+ Returns TRUE if the receiver of the event wants to keep the key;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn void TQMouseEvent::accept()
+
+ Sets the accept flag of the mouse event object.
+
+ Setting the accept parameter indicates that the receiver of the
+ event wants the mouse event. Unwanted mouse events are sent to the
+ tqparent widget.
+
+ The accept flag is set by default.
+
+ \sa ignore()
+*/
+
+
+/*!
+ \fn void TQMouseEvent::ignore()
+
+ Clears the accept flag parameter of the mouse event object.
+
+ Clearing the accept parameter indicates that the event receiver
+ does not want the mouse event. Unwanted mouse events are sent to
+ the tqparent widget.
+
+ The accept flag is set by default.
+
+ \sa accept()
+*/
+
+
+/*!
+ \class TQWheelEvent tqevent.h
+ \brief The TQWheelEvent class tqcontains parameters that describe a wheel event.
+
+ \ingroup events
+
+ Wheel events are sent to the widget under the mouse, and if that widget
+ does not handle the event they are sent to the focus widget. The rotation
+ distance is provided by delta(). The functions pos() and globalPos() return
+ the mouse pointer location at the time of the event.
+
+ A wheel event tqcontains a special accept flag that indicates
+ whether the receiver wants the event. You should call
+ TQWheelEvent::accept() if you handle the wheel event; otherwise it
+ will be sent to the tqparent widget.
+
+ The TQWidget::setEnable() function can be used to enable or disable
+ mouse and keyboard events for a widget.
+
+ The event handler TQWidget::wheelEvent() receives wheel events.
+
+ \sa TQMouseEvent, TQWidget::grabMouse()
+*/
+
+/*!
+ \fn Orientation TQWheelEvent::orientation() const
+
+ Returns the wheel's orientation.
+*/
+
+/*!
+ \fn TQWheelEvent::TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient = Vertical );
+
+ Constructs a wheel event object.
+
+ The globalPos() is initialized to TQCursor::pos(), i.e. \a pos,
+ which is usually (but not always) right. Use the other constructor
+ if you need to specify the global position explicitly. \a delta
+ tqcontains the rotation distance, \a state holds the keyboard
+ modifier flags at the time of the event and \a orient holds the
+ wheel's orientation.
+
+ \sa pos(), delta(), state()
+*/
+#ifndef TQT_NO_WHEELEVENT
+TQWheelEvent::TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient )
+ : TQEvent(Wheel), p(pos), d(delta), s((ushort)state),
+ accpt(TRUE), o(orient)
+{
+ g = TQCursor::pos();
+}
+#endif
+/*!
+ \fn TQWheelEvent::TQWheelEvent( const TQPoint &pos, const TQPoint& globalPos, int delta, int state, Orientation orient = Vertical )
+
+ Constructs a wheel event object. The position when the event
+ occurred is given in \a pos and \a globalPos. \a delta tqcontains
+ the rotation distance, \a state holds the keyboard modifier flags
+ at the time of the event and \a orient holds the wheel's
+ orientation.
+
+ \sa pos(), globalPos(), delta(), state()
+*/
+
+/*!
+ \fn int TQWheelEvent::delta() const
+
+ Returns the distance that the wheel is rotated expressed in
+ multiples or divisions of the \e{wheel delta}, which is currently
+ defined to be 120. A positive value indicates that the wheel was
+ rotated forwards away from the user; a negative value indicates
+ that the wheel was rotated backwards toward the user.
+
+ The \e{wheel delta} constant was defined to be 120 by wheel mouse
+ vendors to allow building finer-resolution wheels in the future,
+ including perhaps a freely rotating wheel with no notches. The
+ expectation is that such a tqdevice would send more messages per
+ rotation but with a smaller value in each message.
+*/
+
+/*!
+ \fn const TQPoint &TQWheelEvent::pos() const
+
+ Returns the position of the mouse pointer, relative to the widget
+ that received the event.
+
+ If you move your widgets around in response to mouse
+ events, use globalPos() instead of this function.
+
+ \sa x(), y(), globalPos()
+*/
+
+/*!
+ \fn int TQWheelEvent::x() const
+
+ Returns the x-position of the mouse pointer, relative to the
+ widget that received the event.
+
+ \sa y(), pos()
+*/
+
+/*!
+ \fn int TQWheelEvent::y() const
+
+ Returns the y-position of the mouse pointer, relative to the
+ widget that received the event.
+
+ \sa x(), pos()
+*/
+
+
+/*!
+ \fn const TQPoint &TQWheelEvent::globalPos() const
+
+ Returns the global position of the mouse pointer \e{at the time
+ of the event}. This is important on asynchronous window systems
+ such as X11; whenever you move your widgets around in response to
+ mouse events, globalPos() can differ a lot from the current
+ pointer position TQCursor::pos().
+
+ \sa globalX(), globalY()
+*/
+
+/*!
+ \fn int TQWheelEvent::globalX() const
+
+ Returns the global x-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalY(), globalPos()
+*/
+
+/*!
+ \fn int TQWheelEvent::globalY() const
+
+ Returns the global y-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalX(), globalPos()
+*/
+
+
+/*!
+ \fn ButtonState TQWheelEvent::state() const
+
+ Returns the keyboard modifier flags of the event.
+
+ The returned value is \c ShiftButton, \c ControlButton, and \c
+ AltButton OR'ed together.
+*/
+
+/*!
+ \fn bool TQWheelEvent::isAccepted() const
+
+ Returns TRUE if the receiver of the event handles the wheel event;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn void TQWheelEvent::accept()
+
+ Sets the accept flag of the wheel event object.
+
+ Setting the accept parameter indicates that the receiver of the
+ event wants the wheel event. Unwanted wheel events are sent to the
+ tqparent widget.
+
+ The accept flag is set by default.
+
+ \sa ignore()
+*/
+
+/*!
+ \fn void TQWheelEvent::ignore()
+
+ Clears the accept flag parameter of the wheel event object.
+
+ Clearing the accept parameter indicates that the event receiver
+ does not want the wheel event. Unwanted wheel events are sent to
+ the tqparent widget. The accept flag is set by default.
+
+ \sa accept()
+*/
+
+
+/*!
+ \enum TQt::Modifier
+
+ This enum type describes the keyboard modifier keys supported by
+ TQt.
+
+ \value SHIFT the Shift keys provided on all standard keyboards.
+ \value META the Meta keys.
+ \value CTRL the Ctrl keys.
+ \value ALT the normal Alt keys, but not e.g. AltGr.
+ \value MODIFIER_MASK is a tqmask of Shift, Ctrl, Alt and Meta.
+ \value UNICODE_ACCEL the accelerator is specified as a Unicode code
+ point, not as a TQt Key.
+*/
+
+/*!
+ \class TQKeyEvent tqevent.h
+ \brief The TQKeyEvent class tqcontains describes a key event.
+
+ \ingroup events
+
+ Key events occur when a key is pressed or released when a widget
+ has keyboard input focus.
+
+ A key event tqcontains a special accept flag that indicates whether the
+ receiver wants the key event. You should call TQKeyEvent::ignore() if the
+ key press or release event is not handled by your widget. A key event is
+ propagated up the tqparent widget chain until a widget accepts it with
+ TQKeyEvent::accept() or an event filter consumes it.
+ Key events for multi media keys are ignored by default. You should call
+ TQKeyEvent::accept() if your widget handles those events.
+
+ The TQWidget::setEnable() function can be used to enable or disable
+ mouse and keyboard events for a widget.
+
+ The event handlers TQWidget::keyPressEvent() and
+ TQWidget::keyReleaseEvent() receive key events.
+
+ \sa TQFocusEvent, TQWidget::grabKeyboard()
+*/
+
+/*!
+ \fn TQKeyEvent::TQKeyEvent( Type type, int key, int ascii, int state,
+ const TQString& text, bool autorep, ushort count )
+
+ Constructs a key event object.
+
+ The \a type parameter must be \c TQEvent::KeyPress or \c
+ TQEvent::KeyRelease. If \a key is 0 the event is not a result of a
+ known key (e.g. it may be the result of a compose sequence or
+ keyboard macro). \a ascii is the ASCII code of the key that was
+ pressed or released. \a state holds the keyboard modifiers. \a
+ text is the Unicode text that the key generated. If \a autorep is
+ TRUE, isAutoRepeat() will be TRUE. \a count is the number of
+ single keys.
+
+ The accept flag is set to TRUE.
+*/
+
+/*!
+ \fn int TQKeyEvent::key() const
+
+ Returns the code of the key that was pressed or released.
+
+ See \l TQt::Key for the list of keyboard codes. These codes are
+ independent of the underlying window system.
+
+ A value of either 0 or Key_unknown means that the event is not
+ the result of a known key (e.g. it may be the result of a compose
+ sequence or a keyboard macro, or due to key event compression).
+
+ \sa TQWidget::setKeyCompression()
+*/
+
+/*!
+ \fn int TQKeyEvent::ascii() const
+
+ Returns the ASCII code of the key that was pressed or released. We
+ recommend using text() instead.
+
+ \sa text()
+*/
+
+/*!
+ \fn TQString TQKeyEvent::text() const
+
+ Returns the Unicode text that this key generated. The text returned
+ migth be empty, which is the case when pressing or
+ releasing modifying keys as Shift, Control, Alt and Meta. In these
+ cases key() will contain a valid value.
+
+ \sa TQWidget::setKeyCompression()
+*/
+
+/*!
+ \fn ButtonState TQKeyEvent::state() const
+
+ Returns the keyboard modifier flags that existed immediately
+ before the event occurred.
+
+ The returned value is \c ShiftButton, \c ControlButton, \c AltButton
+ and \c MetaButton OR'ed together.
+
+ \sa stateAfter()
+*/
+
+/*!
+ \fn ButtonState TQKeyEvent::stateAfter() const
+
+ Returns the keyboard modifier flags that existed immediately after
+ the event occurred.
+
+ \warning This function cannot be trusted.
+
+ \sa state()
+*/
+//###### We must check with XGetModifierMapping
+TQt::ButtonState TQKeyEvent::stateAfter() const
+{
+ if ( key() == Key_Shift )
+ return TQt::ButtonState(state()^ShiftButton);
+ if ( key() == Key_Control )
+ return TQt::ButtonState(state()^ControlButton);
+ if ( key() == Key_Alt )
+ return TQt::ButtonState(state()^AltButton);
+ if ( key() == Key_Meta )
+ return TQt::ButtonState(state()^MetaButton);
+ return state();
+}
+
+/*!
+ \fn bool TQKeyEvent::isAccepted() const
+
+ Returns TRUE if the receiver of the event wants to keep the key;
+ otherwise returns FALSE
+*/
+
+/*!
+ \fn void TQKeyEvent::accept()
+
+ Sets the accept flag of the key event object.
+
+ Setting the accept parameter indicates that the receiver of the
+ event wants the key event. Unwanted key events are sent to the
+ tqparent widget.
+
+ The accept flag is set by default.
+
+ \sa ignore()
+*/
+
+/*!
+ \fn bool TQKeyEvent::isAutoRepeat() const
+
+ Returns TRUE if this event comes from an auto-repeating key and
+ FALSE if it comes from an initial key press.
+
+ Note that if the event is a multiple-key compressed event that is
+ partly due to auto-repeat, this function could return either TRUE
+ or FALSE indeterminately.
+*/
+
+/*!
+ \fn int TQKeyEvent::count() const
+
+ Returns the number of single keys for this event. If text() is not
+ empty, this is simply the length of the string.
+
+ \sa TQWidget::setKeyCompression()
+*/
+
+/*!
+ \fn void TQKeyEvent::ignore()
+
+ Clears the accept flag parameter of the key event object.
+
+ Clearing the accept parameter indicates that the event receiver
+ does not want the key event. Unwanted key events are sent to the
+ tqparent widget.
+
+ The accept flag is set by default.
+
+ \sa accept()
+*/
+
+/*!
+ \enum TQt::Key
+
+ The key names used by TQt.
+
+ \value Key_Escape
+ \value Key_Tab
+ \value Key_Backtab
+ \value Key_Backspace
+ \value Key_Return
+ \value Key_Enter
+ \value Key_Insert
+ \value Key_Delete
+ \value Key_Pause
+ \value Key_Print
+ \value Key_SysReq
+ \value Key_Home
+ \value Key_End
+ \value Key_Left
+ \value Key_Up
+ \value Key_Right
+ \value Key_Down
+ \value Key_Prior
+ \value Key_Next
+ \value Key_Shift
+ \value Key_Control
+ \value Key_Meta
+ \value Key_Alt
+ \value Key_CapsLock
+ \value Key_NumLock
+ \value Key_ScrollLock
+ \value Key_Clear
+ \value Key_F1
+ \value Key_F2
+ \value Key_F3
+ \value Key_F4
+ \value Key_F5
+ \value Key_F6
+ \value Key_F7
+ \value Key_F8
+ \value Key_F9
+ \value Key_F10
+ \value Key_F11
+ \value Key_F12
+ \value Key_F13
+ \value Key_F14
+ \value Key_F15
+ \value Key_F16
+ \value Key_F17
+ \value Key_F18
+ \value Key_F19
+ \value Key_F20
+ \value Key_F21
+ \value Key_F22
+ \value Key_F23
+ \value Key_F24
+ \value Key_F25
+ \value Key_F26
+ \value Key_F27
+ \value Key_F28
+ \value Key_F29
+ \value Key_F30
+ \value Key_F31
+ \value Key_F32
+ \value Key_F33
+ \value Key_F34
+ \value Key_F35
+ \value Key_Super_L
+ \value Key_Super_R
+ \value Key_Menu
+ \value Key_Hyper_L
+ \value Key_Hyper_R
+ \value Key_Help
+ \value Key_Space
+ \value Key_Any
+ \value Key_Exclam
+ \value Key_QuoteDbl
+ \value Key_NumberSign
+ \value Key_Dollar
+ \value Key_Percent
+ \value Key_Ampersand
+ \value Key_Apostrophe
+ \value Key_ParenLeft
+ \value Key_ParenRight
+ \value Key_Asterisk
+ \value Key_Plus
+ \value Key_Comma
+ \value Key_Minus
+ \value Key_Period
+ \value Key_Slash
+ \value Key_0
+ \value Key_1
+ \value Key_2
+ \value Key_3
+ \value Key_4
+ \value Key_5
+ \value Key_6
+ \value Key_7
+ \value Key_8
+ \value Key_9
+ \value Key_Colon
+ \value Key_Semicolon
+ \value Key_Less
+ \value Key_Equal
+ \value Key_Greater
+ \value Key_Question
+ \value Key_At
+ \value Key_A
+ \value Key_B
+ \value Key_C
+ \value Key_D
+ \value Key_E
+ \value Key_F
+ \value Key_G
+ \value Key_H
+ \value Key_I
+ \value Key_J
+ \value Key_K
+ \value Key_L
+ \value Key_M
+ \value Key_N
+ \value Key_O
+ \value Key_P
+ \value Key_Q
+ \value Key_R
+ \value Key_S
+ \value Key_T
+ \value Key_U
+ \value Key_V
+ \value Key_W
+ \value Key_X
+ \value Key_Y
+ \value Key_Z
+ \value Key_BracketLeft
+ \value Key_Backslash
+ \value Key_BracketRight
+ \value Key_AsciiCircum
+ \value Key_Underscore
+ \value Key_QuoteLeft
+ \value Key_BraceLeft
+ \value Key_Bar
+ \value Key_BraceRight
+ \value Key_AsciiTilde
+
+ \value Key_nobreakspace
+ \value Key_exclamdown
+ \value Key_cent
+ \value Key_sterling
+ \value Key_currency
+ \value Key_yen
+ \value Key_brokenbar
+ \value Key_section
+ \value Key_diaeresis
+ \value Key_copyright
+ \value Key_ordfeminine
+ \value Key_guillemotleft
+ \value Key_notsign
+ \value Key_hyphen
+ \value Key_registered
+ \value Key_macron
+ \value Key_degree
+ \value Key_plusminus
+ \value Key_twosuperior
+ \value Key_threesuperior
+ \value Key_acute
+ \value Key_mu
+ \value Key_paragraph
+ \value Key_periodcentered
+ \value Key_cedilla
+ \value Key_onesuperior
+ \value Key_masculine
+ \value Key_guillemotright
+ \value Key_onequarter
+ \value Key_onehalf
+ \value Key_threequarters
+ \value Key_questiondown
+ \value Key_Agrave
+ \value Key_Aacute
+ \value Key_Acircumflex
+ \value Key_Atilde
+ \value Key_Adiaeresis
+ \value Key_Aring
+ \value Key_AE
+ \value Key_Ccedilla
+ \value Key_Egrave
+ \value Key_Eacute
+ \value Key_Ecircumflex
+ \value Key_Ediaeresis
+ \value Key_Igrave
+ \value Key_Iacute
+ \value Key_Icircumflex
+ \value Key_Idiaeresis
+ \value Key_ETH
+ \value Key_Ntilde
+ \value Key_Ograve
+ \value Key_Oacute
+ \value Key_Ocircumflex
+ \value Key_Otilde
+ \value Key_Odiaeresis
+ \value Key_multiply
+ \value Key_Ooblique
+ \value Key_Ugrave
+ \value Key_Uacute
+ \value Key_Ucircumflex
+ \value Key_Udiaeresis
+ \value Key_Yacute
+ \value Key_THORN
+ \value Key_ssharp
+ \value Key_agrave
+ \value Key_aacute
+ \value Key_acircumflex
+ \value Key_atilde
+ \value Key_adiaeresis
+ \value Key_aring
+ \value Key_ae
+ \value Key_ccedilla
+ \value Key_egrave
+ \value Key_eacute
+ \value Key_ecircumflex
+ \value Key_ediaeresis
+ \value Key_igrave
+ \value Key_iacute
+ \value Key_icircumflex
+ \value Key_idiaeresis
+ \value Key_eth
+ \value Key_ntilde
+ \value Key_ograve
+ \value Key_oacute
+ \value Key_ocircumflex
+ \value Key_otilde
+ \value Key_odiaeresis
+ \value Key_division
+ \value Key_oslash
+ \value Key_ugrave
+ \value Key_uacute
+ \value Key_ucircumflex
+ \value Key_udiaeresis
+ \value Key_yacute
+ \value Key_thorn
+ \value Key_ydiaeresis
+
+ Multimedia keys
+
+ \value Key_Back
+ \value Key_Forward
+ \value Key_Stop
+ \value Key_Refresh
+
+ \value Key_VolumeDown
+ \value Key_VolumeMute
+ \value Key_VolumeUp
+ \value Key_BassBoost
+ \value Key_BassUp
+ \value Key_BassDown
+ \value Key_TrebleUp
+ \value Key_TrebleDown
+
+ \value Key_MediaPlay
+ \value Key_MediaStop
+ \value Key_MediaPrev
+ \value Key_MediaNext
+ \value Key_MediaRecord
+
+ \value Key_HomePage
+ \value Key_Favorites
+ \value Key_Search
+ \value Key_Standby
+ \value Key_OpenUrl
+
+ \value Key_LaunchMail
+ \value Key_LaunchMedia
+ \value Key_Launch0
+ \value Key_Launch1
+ \value Key_Launch2
+ \value Key_Launch3
+ \value Key_Launch4
+ \value Key_Launch5
+ \value Key_Launch6
+ \value Key_Launch7
+ \value Key_Launch8
+ \value Key_Launch9
+ \value Key_LaunchA
+ \value Key_LaunchB
+ \value Key_LaunchC
+ \value Key_LaunchD
+ \value Key_LaunchE
+ \value Key_LaunchF
+
+ \value Key_MediaLast
+
+ \value Key_unknown
+
+ \value Key_Direction_L internal use only
+ \value Key_Direction_R internal use only
+
+*/
+
+
+/*!
+ \class TQFocusEvent tqevent.h
+ \brief The TQFocusEvent class tqcontains event parameters for widget focus
+ events.
+
+ \ingroup events
+
+ Focus events are sent to widgets when the keyboard input focus
+ changes. Focus events occur due to mouse actions, keypresses (e.g.
+ Tab or Backtab), the window system, popup menus, keyboard
+ shortcuts or other application specific reasons. The reason for a
+ particular focus event is returned by reason() in the appropriate
+ event handler.
+
+ The event handlers TQWidget::focusInEvent() and
+ TQWidget::focusOutEvent() receive focus events.
+
+ Use setReason() to set the reason for all focus events, and
+ resetReason() to set the reason for all focus events to the reason
+ in force before the last setReason() call.
+
+ \sa TQWidget::setFocus(), TQWidget::setFocusPolicy()
+*/
+
+/*!
+ \fn TQFocusEvent::TQFocusEvent( Type type )
+
+ Constructs a focus event object.
+
+ The \a type parameter must be either \c TQEvent::FocusIn or \c
+ TQEvent::FocusOut.
+*/
+
+
+
+TQFocusEvent::Reason TQFocusEvent::m_reason = TQFocusEvent::Other;
+TQFocusEvent::Reason TQFocusEvent::prev_reason = TQFocusEvent::Other;
+
+
+/*!
+ \enum TQFocusEvent::Reason
+
+ This enum specifies why the focus changed.
+
+ \value Mouse because of a mouse action.
+ \value Tab because of a Tab press.
+ \value Backtab because of a Backtab press
+ (possibly including Shift/Control, e.g. Shift+Tab).
+ \value ActiveWindow because the window system made this window (in)active.
+ \value Popup because the application opened/closed a popup that grabbed/released focus.
+ \value Shortcut because of a keyboard shortcut.
+ \value Other any other reason, usually application-specific.
+
+ See the \link focus.html keyboard focus overview\endlink for more
+ about focus.
+*/
+
+/*!
+ Returns the reason for this focus event.
+
+ \sa setReason()
+ */
+TQFocusEvent::Reason TQFocusEvent::reason()
+{
+ return m_reason;
+}
+
+/*!
+ Sets the reason for all future focus events to \a reason.
+
+ \sa reason(), resetReason()
+ */
+void TQFocusEvent::setReason( Reason reason )
+{
+ prev_reason = m_reason;
+ m_reason = reason;
+}
+
+/*!
+ Resets the reason for all future focus events to the value before
+ the last setReason() call.
+
+ \sa reason(), setReason()
+ */
+void TQFocusEvent::resetReason()
+{
+ m_reason = prev_reason;
+}
+
+/*!
+ \fn bool TQFocusEvent::gotFocus() const
+
+ Returns TRUE if the widget received the text input focus;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQFocusEvent::lostFocus() const
+
+ Returns TRUE if the widget lost the text input focus; otherwise
+ returns FALSE.
+*/
+
+
+/*!
+ \class TQPaintEvent tqevent.h
+ \brief The TQPaintEvent class tqcontains event parameters for paint events.
+
+ \ingroup events
+
+ Paint events are sent to widgets that need to update themselves,
+ for instance when part of a widget is exposed because a covering
+ widget is moved.
+
+ The event tqcontains a region() that needs to be updated, and a
+ rect() that is the bounding rectangle of that region. Both are
+ provided because many widgets can't make much use of region(), and
+ rect() can be much faster than region().boundingRect(). Painting
+ is clipped to region() during processing of a paint event.
+
+ The erased() function returns TRUE if the region() has been
+ cleared to the widget's background (see
+ TQWidget::backgroundMode()), and FALSE if the region's contents are
+ arbitrary.
+
+ \sa TQPainter TQWidget::update() TQWidget::tqrepaint()
+ TQWidget::paintEvent() TQWidget::backgroundMode() TQRegion
+*/
+
+/*!
+ \fn TQPaintEvent::TQPaintEvent( const TQRegion &paintRegion, bool erased=TRUE )
+
+ Constructs a paint event object with the region that should be
+ updated. The region is given by \a paintRegion. If \a erased is
+ TRUE the region will be cleared before repainting.
+*/
+
+/*!
+ \fn TQPaintEvent::TQPaintEvent( const TQRect &paintRect, bool erased=TRUE )
+
+ Constructs a paint event object with the rectangle that should be
+ updated. The region is also given by \a paintRect. If \a erased is
+ TRUE the region will be cleared before repainting.
+*/
+
+/*!
+ \fn TQPaintEvent::TQPaintEvent( const TQRegion &paintRegion, const TQRect &paintRect, bool erased=TRUE )
+
+ Constructs a paint event object with the rectangle \a paintRect
+ that should be updated. The region is given by \a paintRegion. If
+ \a erased is TRUE the region will be cleared before repainting.
+*/
+
+/*!
+ \fn const TQRect &TQPaintEvent::rect() const
+
+ Returns the rectangle that should be updated.
+
+ \sa region(), TQPainter::setClipRect()
+*/
+
+/*!
+ \fn const TQRegion &TQPaintEvent::region() const
+
+ Returns the region that should be updated.
+
+ \sa rect(), TQPainter::setClipRegion()
+*/
+
+/*!
+ \fn bool TQPaintEvent::erased() const
+
+ Returns TRUE if the paint event region (or rectangle) has been
+ erased with the widget's background; otherwise returns FALSE.
+*/
+
+/*!
+ \class TQMoveEvent tqevent.h
+ \brief The TQMoveEvent class tqcontains event parameters for move events.
+
+ \ingroup events
+
+ Move events are sent to widgets that have been moved to a new position
+ relative to their tqparent.
+
+ The event handler TQWidget::moveEvent() receives move events.
+
+ \sa TQWidget::move(), TQWidget::setGeometry()
+*/
+
+/*!
+ \fn TQMoveEvent::TQMoveEvent( const TQPoint &pos, const TQPoint &oldPos )
+
+ Constructs a move event with the new and old widget positions, \a
+ pos and \a oldPos respectively.
+*/
+
+/*!
+ \fn const TQPoint &TQMoveEvent::pos() const
+
+ Returns the new position of the widget. This excludes the window
+ frame for top level widgets.
+*/
+
+/*!
+ \fn const TQPoint &TQMoveEvent::oldPos() const
+
+ Returns the old position of the widget.
+*/
+
+
+/*!
+ \class TQResizeEvent tqevent.h
+ \brief The TQResizeEvent class tqcontains event parameters for resize events.
+
+ \ingroup events
+
+ Resize events are sent to widgets that have been resized.
+
+ The event handler TQWidget::resizeEvent() receives resize events.
+
+ \sa TQWidget::resize(), TQWidget::setGeometry()
+*/
+
+/*!
+ \fn TQResizeEvent::TQResizeEvent( const TQSize &size, const TQSize &oldSize )
+
+ Constructs a resize event with the new and old widget sizes, \a
+ size and \a oldSize respectively.
+*/
+
+/*!
+ \fn const TQSize &TQResizeEvent::size() const
+
+ Returns the new size of the widget, which is the same as
+ TQWidget::size().
+*/
+
+/*!
+ \fn const TQSize &TQResizeEvent::oldSize() const
+
+ Returns the old size of the widget.
+*/
+
+
+/*!
+ \class TQCloseEvent tqevent.h
+ \brief The TQCloseEvent class tqcontains parameters that describe a close event.
+
+ \ingroup events
+
+ Close events are sent to widgets that the user wants to close,
+ usually by choosing "Close" from the window menu, or by clicking
+ the `X' titlebar button. They are also sent when you call
+ TQWidget::close() to close a widget programmatically.
+
+ Close events contain a flag that indicates whether the receiver
+ wants the widget to be closed or not. When a widget accepts the
+ close event, it is hidden (and destroyed if it was created with
+ the \c WDestructiveClose flag). If it refuses to accept the close
+ event nothing happens. (Under X11 it is possible that the window
+ manager will forcibly close the window; but at the time of writing
+ we are not aware of any window manager that does this.)
+
+ The application's main widget -- TQApplication::mainWidget() --
+ is a special case. When it accepts the close event, TQt leaves the
+ main event loop and the application is immediately terminated
+ (i.e. it returns from the call to TQApplication::exec() in the
+ main() function).
+
+ The event handler TQWidget::closeEvent() receives close events. The
+ default implementation of this event handler accepts the close
+ event. If you do not want your widget to be hidden, or want some
+ special handing, you should reimplement the event handler.
+
+ The \link simple-application.html#closeEvent closeEvent() in the
+ Application Walkthrough\endlink shows a close event handler that
+ asks whether to save a document before closing.
+
+ If you want the widget to be deleted when it is closed, create it
+ with the \c WDestructiveClose widget flag. This is very useful for
+ independent top-level windows in a multi-window application.
+
+ \l{TQObject}s emits the \link TQObject::destroyed()
+ destroyed()\endlink signal when they are deleted.
+
+ If the last top-level window is closed, the
+ TQApplication::lastWindowClosed() signal is emitted.
+
+ The isAccepted() function returns TRUE if the event's receiver has
+ agreed to close the widget; call accept() to agree to close the
+ widget and call ignore() if the receiver of this event does not
+ want the widget to be closed.
+
+ \sa TQWidget::close(), TQWidget::hide(), TQObject::destroyed(),
+ TQApplication::setMainWidget(), TQApplication::lastWindowClosed(),
+ TQApplication::exec(), TQApplication::quit()
+*/
+
+/*!
+ \fn TQCloseEvent::TQCloseEvent()
+
+ Constructs a close event object with the accept parameter flag set
+ to FALSE.
+
+ \sa accept()
+*/
+
+/*!
+ \fn bool TQCloseEvent::isAccepted() const
+
+ Returns TRUE if the receiver of the event has agreed to close the
+ widget; otherwise returns FALSE.
+
+ \sa accept(), ignore()
+*/
+
+/*!
+ \fn void TQCloseEvent::accept()
+
+ Sets the accept flag of the close event object.
+
+ Setting the accept flag indicates that the receiver of this event
+ agrees to close the widget.
+
+ The accept flag is \e not set by default.
+
+ If you choose to accept in TQWidget::closeEvent(), the widget will
+ be hidden. If the widget's \c WDestructiveClose flag is set, it
+ will also be destroyed.
+
+ \sa ignore(), TQWidget::hide()
+*/
+
+/*!
+ \fn void TQCloseEvent::ignore()
+
+ Clears the accept flag of the close event object.
+
+ Clearing the accept flag indicates that the receiver of this event
+ does not want the widget to be closed.
+
+ The close event is constructed with the accept flag cleared.
+
+ \sa accept()
+*/
+
+/*!
+ \class TQIconDragEvent tqevent.h
+ \brief The TQIconDragEvent class Q_SIGNALS that a main icon drag has begun.
+
+ \ingroup events
+
+ Icon drag events are sent to widgets when the main icon of a window has been dragged away.
+ On Mac OS X this is fired when the proxy icon of a window is dragged off titlebar, in response to
+ this event is is normal to begin using drag and drop.
+*/
+
+/*!
+ \fn TQIconDragEvent::TQIconDragEvent()
+
+ Constructs an icon drag event object with the accept parameter
+ flag set to FALSE.
+
+ \sa accept()
+*/
+
+/*!
+ \fn bool TQIconDragEvent::isAccepted() const
+
+ Returns TRUE if the receiver of the event has started a drag and
+ drop operation; otherwise returns FALSE.
+
+ \sa accept(), ignore()
+*/
+
+/*!
+ \fn void TQIconDragEvent::accept()
+
+ Sets the accept flag of the icon drag event object.
+
+ Setting the accept flag indicates that the receiver of this event
+ has started a drag and drop oeration.
+
+ The accept flag is \e not set by default.
+
+ \sa ignore(), TQWidget::hide()
+*/
+
+/*!
+ \fn void TQIconDragEvent::ignore()
+
+ Clears the accept flag of the icon drag object.
+
+ Clearing the accept flag indicates that the receiver of this event
+ has not handled the icon drag as a result other events can be sent.
+
+ The icon drag event is constructed with the accept flag cleared.
+
+ \sa accept()
+*/
+
+/*!
+ \class TQContextMenuEvent tqevent.h
+ \brief The TQContextMenuEvent class tqcontains parameters that describe a context menu event.
+
+ \ingroup events
+
+ Context menu events are sent to widgets when a user triggers a
+ context menu. What triggers this is platform dependent. For
+ example, on Windows, pressing the menu button or releasing the
+ right mouse button will cause this event to be sent.
+
+ When this event occurs it is customary to show a TQPopupMenu with a
+ context menu, if this is relevant to the context.
+
+ Context menu events contain a special accept flag that indicates
+ whether the receiver accepted the event. If the event handler does
+ not accept the event, then whatever triggered the event will be
+ handled as a regular input event if possible.
+
+ \sa TQPopupMenu
+*/
+
+/*!
+ \fn TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, const TQPoint &globalPos, int state )
+
+ Constructs a context menu event object with the accept parameter
+ flag set to FALSE.
+
+ The \a reason parameter must be \c TQContextMenuEvent::Mouse or \c
+ TQContextMenuEvent::Keyboard.
+
+ The \a pos parameter specifies the mouse position relative to the
+ receiving widget. \a globalPos is the mouse position in absolute
+ coordinates. \a state is the ButtonState at the time of the event.
+*/
+
+
+/*!
+ \fn TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, int state )
+
+ Constructs a context menu event object with the accept parameter
+ flag set to FALSE.
+
+ The \a reason parameter must be \c TQContextMenuEvent::Mouse or \c
+ TQContextMenuEvent::Keyboard.
+
+ The \a pos parameter specifies the mouse position relative to the
+ receiving widget. \a state is the ButtonState at the time of the
+ event.
+
+ The globalPos() is initialized to TQCursor::pos(), which may not be
+ appropriate. Use the other constructor to specify the global
+ position explicitly.
+*/
+
+TQContextMenuEvent::TQContextMenuEvent( Reason reason, const TQPoint &pos, int state )
+ : TQEvent( ContextMenu ), p( pos ), accpt(TRUE), consum(TRUE),
+ reas( reason ), s((ushort)state)
+{
+ gp = TQCursor::pos();
+}
+
+/*!
+ \fn const TQPoint &TQContextMenuEvent::pos() const
+
+ Returns the position of the mouse pointer relative to the widget
+ that received the event.
+
+ \sa x(), y(), globalPos()
+*/
+
+/*!
+ \fn int TQContextMenuEvent::x() const
+
+ Returns the x-position of the mouse pointer, relative to the
+ widget that received the event.
+
+ \sa y(), pos()
+*/
+
+/*!
+ \fn int TQContextMenuEvent::y() const
+
+ Returns the y-position of the mouse pointer, relative to the
+ widget that received the event.
+
+ \sa x(), pos()
+*/
+
+/*!
+ \fn const TQPoint &TQContextMenuEvent::globalPos() const
+
+ Returns the global position of the mouse pointer at the time of
+ the event.
+
+ \sa x(), y(), pos()
+*/
+
+/*!
+ \fn int TQContextMenuEvent::globalX() const
+
+ Returns the global x-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalY(), globalPos()
+*/
+
+/*!
+ \fn int TQContextMenuEvent::globalY() const
+
+ Returns the global y-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalX(), globalPos()
+*/
+
+/*!
+ \fn ButtonState TQContextMenuEvent::state() const
+
+ Returns the button state (a combination of mouse buttons and
+ keyboard modifiers), i.e. what buttons and keys were being
+ pressed immediately before the event was generated.
+
+ The returned value is \c LeftButton, \c RightButton, \c MidButton,
+ \c ShiftButton, \c ControlButton and \c AltButton OR'ed together.
+*/
+
+/*!
+ \fn bool TQContextMenuEvent::isConsumed() const
+
+ Returns TRUE (which stops propagation of the event) if the
+ receiver has blocked the event; otherwise returns FALSE.
+
+ \sa accept(), ignore(), consume()
+*/
+
+/*!
+ \fn void TQContextMenuEvent::consume()
+
+ Sets the consume flag of the context event object.
+
+ Setting the consume flag indicates that the receiver of this event
+ does not want the event to be propagated further (i.e. not sent to
+ tqparent classes.)
+
+ The consumed flag is not set by default.
+
+ \sa ignore() accept()
+*/
+
+/*!
+ \fn bool TQContextMenuEvent::isAccepted() const
+
+ Returns TRUE if the receiver has processed the event; otherwise
+ returns FALSE.
+
+ \sa accept(), ignore(), consume()
+*/
+
+/*!
+ \fn void TQContextMenuEvent::accept()
+
+ Sets the accept flag of the context event object.
+
+ Setting the accept flag indicates that the receiver of this event
+ has processed the event. Processing the event means you did
+ something with it and it will be implicitly consumed.
+
+ The accept flag is not set by default.
+
+ \sa ignore() consume()
+*/
+
+/*!
+ \fn void TQContextMenuEvent::ignore()
+
+ Clears the accept flag of the context event object.
+
+ Clearing the accept flag indicates that the receiver of this event
+ does not need to show a context menu. This will implicitly remove
+ the consumed flag as well.
+
+ The accept flag is not set by default.
+
+ \sa accept() consume()
+*/
+
+/*!
+ \enum TQContextMenuEvent::Reason
+
+ This enum describes the reason the ContextMenuEvent was sent. The
+ values are:
+
+ \value Mouse The mouse caused the event to be sent. Normally this
+ means the right mouse button was clicked, but this is platform
+ specific.
+
+ \value Keyboard The keyboard caused this event to be sent. On
+ Windows this means the menu button was pressed.
+
+ \value Other The event was sent by some other means (i.e. not by
+ the mouse or keyboard).
+*/
+
+
+/*!
+ \fn TQContextMenuEvent::Reason TQContextMenuEvent::reason() const
+
+ Returns the reason for this context event.
+*/
+
+
+/*!
+ \class TQIMEvent tqevent.h
+ \brief The TQIMEvent class provides parameters for input method events.
+
+ \ingroup events
+
+ Input method events are sent to widgets when an input method is
+ used to enter text into a widget. Input methods are widely used to
+ enter text in Asian and other complex languages.
+
+ The events are of interest to widgets that accept keyboard input
+ and want to be able to correctly handle complex languages. Text
+ input in such languages is usually a three step process.
+
+ \list 1
+ \i <b>Starting to Compose</b><br>
+ When the user presses the first key on a keyboard an input context
+ is created. This input context will contain a string with the
+ typed characters.
+
+ \i <b>Composing</b><br>
+ With every new key pressed, the input method will try to create a
+ matching string for the text typed so far. While the input context
+ is active, the user can only move the cursor inside the string
+ belonging to this input context.
+
+ \i <b>Completing</b><br>
+ At some point, e.g. when the user presses the Spacebar, they get
+ to this stage, where they can choose from a number of strings that
+ match the text they have typed so far. The user can press Enter to
+ confirm their choice or Escape to cancel the input; in either case
+ the input context will be closed.
+ \endlist
+
+ Note that the particular key presses used for a given input
+ context may differ from those we've mentioned here, i.e. they may
+ not be Spacebar, Enter and Escape.
+
+ These three stages are represented by three different types of
+ events. The IMStartEvent, IMComposeEvent and IMEndEvent. When a
+ new input context is created, an IMStartEvent will be sent to the
+ widget and delivered to the \l TQWidget::imStartEvent() function.
+ The widget can then update internal data structures to reflect
+ this.
+
+ After this, an IMComposeEvent will be sent to the widget for
+ every key the user presses. It will contain the current
+ composition string the widget has to show and the current cursor
+ position within the composition string. This string is temporary
+ and can change with every key the user types, so the widget will
+ need to store the state before the composition started (the state
+ it had when it received the IMStartEvent). IMComposeEvents will be
+ delivered to the \l TQWidget::imComposeEvent() function.
+
+ Usually, widgets try to mark the part of the text that is part of
+ the current composition in a way that is visible to the user. A
+ commonly used visual cue is to use a dotted underline.
+
+ After the user has selected the final string, an IMEndEvent will
+ be sent to the widget. The event tqcontains the final string the
+ user selected, and could be empty if they canceled the
+ composition. This string should be accepted as the final text the
+ user entered, and the intermediate composition string should be
+ cleared. These events are delivered to \l TQWidget::imEndEvent().
+
+ If the user clicks another widget, taking the focus out of the
+ widget where the composition is taking place the IMEndEvent will
+ be sent and the string it holds will be the result of the
+ composition up to that point (which may be an empty string).
+*/
+
+/*!
+ \fn TQIMEvent::TQIMEvent( Type type, const TQString &text, int cursorPosition )
+
+ Constructs a new TQIMEvent with the accept flag set to FALSE. \a
+ type can be one of TQEvent::IMStartEvent, TQEvent::IMComposeEvent
+ or TQEvent::IMEndEvent. \a text tqcontains the current compostion
+ string and \a cursorPosition the current position of the cursor
+ inside \a text.
+*/
+
+/*!
+ \fn const TQString &TQIMEvent::text() const
+
+ Returns the composition text. This is a null string for an
+ IMStartEvent, and tqcontains the final accepted string (which may be
+ empty) in the IMEndEvent.
+*/
+
+/*!
+ \fn int TQIMEvent::cursorPos() const
+
+ Returns the current cursor position inside the composition string.
+ Will return -1 for IMStartEvent and IMEndEvent.
+*/
+
+/*!
+ \fn int TQIMEvent::selectionLength() const
+
+ Returns the number of characters in the composition string (
+ starting at cursorPos() ) that should be marked as selected by the
+ input widget receiving the event.
+ Will return 0 for IMStartEvent and IMEndEvent.
+*/
+
+/*!
+ \fn bool TQIMEvent::isAccepted() const
+
+ Returns TRUE if the receiver of the event processed the event;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn void TQIMEvent::accept()
+
+ Sets the accept flag of the input method event object.
+
+ Setting the accept parameter indicates that the receiver of the
+ event processed the input method event.
+
+ The accept flag is not set by default.
+
+ \sa ignore()
+*/
+
+
+/*!
+ \fn void TQIMEvent::ignore()
+
+ Clears the accept flag parameter of the input method event object.
+
+ Clearing the accept parameter indicates that the event receiver
+ does not want the input method event.
+
+ The accept flag is cleared by default.
+
+ \sa accept()
+*/
+
+/*!
+ \class TQTabletEvent tqevent.h
+ \brief The TQTabletEvent class tqcontains parameters that describe a Tablet
+ event.
+
+ \ingroup events
+
+ Tablet Events are generated from a Wacom&copy; tablet. Most of
+ the time you will want to deal with events from the tablet as if
+ they were events from a mouse, for example retrieving the position
+ with x(), y(), pos(), globalX(), globalY() and globalPos(). In
+ some situations you may wish to retrieve the extra information
+ provided by the tablet tqdevice driver, for example, you might want
+ to adjust color brightness based on pressure. TQTabletEvent allows
+ you to get the pressure(), the xTilt() and yTilt(), as well as the
+ type of tqdevice being used with tqdevice() (see \l{TabletDevice}).
+
+ A tablet event tqcontains a special accept flag that indicates
+ whether the receiver wants the event. You should call
+ TQTabletEvent::accept() if you handle the tablet event; otherwise
+ it will be sent to the tqparent widget.
+
+ The TQWidget::setEnabled() function can be used to enable or
+ disable mouse and keyboard events for a widget.
+
+ The event handler TQWidget::tabletEvent() receives all three types of tablet
+ events. TQt will first send a tabletEvent and then, if it is not accepted,
+ it will send a mouse event. This allows applications that don't utilize
+ tablets to use a tablet like a mouse while also enabling those who want to
+ use both tablets and mouses differently.
+
+*/
+
+/*!
+ \enum TQTabletEvent::TabletDevice
+
+ This enum defines what type of tqdevice is generating the event.
+
+ \value NoDevice No tqdevice, or an unknown tqdevice.
+ \value Puck A Puck (a tqdevice that is similar to a flat mouse with
+ a transtqparent circle with cross-hairs).
+ \value Stylus A Stylus (the narrow end of the pen).
+ \value Eraser An Eraser (the broad end of the pen).
+ \omit
+ \value Menu A menu button was pressed (currently unimplemented).
+*/
+
+/*!
+ \fn TQTabletEvent::TQTabletEvent( Type t, const TQPoint &pos,
+ const TQPoint &globalPos, int tqdevice,
+ int pressure, int xTilt, int yTilt,
+ const TQPair<int,int> &uId )
+ Construct a tablet event of type \a t. The position of when the event occurred is given
+ int \a pos and \a globalPos. \a tqdevice tqcontains the \link TabletDevice tqdevice type\endlink,
+ \a pressure tqcontains the pressure exerted on the \a tqdevice, \a xTilt and \a yTilt contain
+ \a tqdevice's degree of tilt from the X and Y axis respectively. The \a uId tqcontains an
+ event id.
+
+ On Irix, \a globalPos will contain the high-resolution coordinates received from the
+ tablet tqdevice driver, instead of from the windowing system.
+
+ \sa pos(), globalPos(), tqdevice(), pressure(), xTilt(), yTilt()
+*/
+
+TQTabletEvent::TQTabletEvent( Type t, const TQPoint &pos, const TQPoint &globalPos, int tqdevice,
+ int pressure, int xTilt, int yTilt,
+ const TQPair<int, int> &uId )
+ : TQEvent( t ),
+ mPos( pos ),
+ mGPos( globalPos ),
+ mDev( tqdevice ),
+ mPress( pressure ),
+ mXT( xTilt ),
+ mYT( yTilt ),
+ mType( uId.first ),
+ mPhy( uId.second ),
+ mbAcc(TRUE)
+{}
+
+/*!
+ \obsolete
+ \fn TQTabletEvent::TQTabletEvent( const TQPoint &pos, const TQPoint &globalPos, int tqdevice, int pressure, int xTilt, int yTilt, const TQPair<int,int> &uId )
+
+ Constructs a tablet event object. The position when the event
+ occurred is is given in \a pos and \a globalPos. \a tqdevice
+ tqcontains the \link TabletDevice tqdevice type\endlink, \a pressure
+ tqcontains the pressure exerted on the \a tqdevice, \a xTilt and \a
+ yTilt contain the \a tqdevice's degrees of tilt from the X and Y
+ axis respectively. The \a uId tqcontains an event id.
+
+ On Irix, \a globalPos will contain the high-resolution coordinates
+ received from the tablet tqdevice driver, instead of from the
+ windowing system.
+
+ \sa pos(), globalPos(), tqdevice(), pressure(), xTilt(), yTilt()
+*/
+
+/*!
+ \fn TabletDevices TQTabletEvent::tqdevice() const
+
+ Returns the type of tqdevice that generated the event. Useful if you
+ want one end of the pen to do something different than the other.
+
+ \sa TabletDevice
+*/
+
+/*!
+ \fn int TQTabletEvent::pressure() const
+
+ Returns the pressure that is exerted on the tqdevice. This number is
+ a value from 0 (no pressure) to 255 (maximum pressure). The
+ pressure is always scaled to be within this range no matter how
+ many pressure levels the underlying hardware supports.
+*/
+
+/*!
+ \fn int TQTabletEvent::xTilt() const
+
+ Returns the difference from the perpendicular in the X Axis.
+ Positive values are towards the tablet's physical right. The angle
+ is in the range -60 to +60 degrees.
+
+ \sa yTilt()
+*/
+
+/*!
+ \fn int TQTabletEvent::yTilt() const
+
+ Returns the difference from the perpendicular in the Y Axis.
+ Positive values are towards the bottom of the tablet. The angle is
+ within the range -60 to +60 degrees.
+
+ \sa xTilt()
+*/
+
+/*!
+ \fn const TQPoint &TQTabletEvent::pos() const
+
+ Returns the position of the tqdevice, relative to the widget that
+ received the event.
+
+ If you move widgets around in response to mouse events, use
+ globalPos() instead of this function.
+
+ \sa x(), y(), globalPos()
+*/
+
+/*!
+ \fn int TQTabletEvent::x() const
+
+ Returns the x-position of the tqdevice, relative to the widget that
+ received the event.
+
+ \sa y(), pos()
+*/
+
+/*!
+ \fn int TQTabletEvent::y() const
+
+ Returns the y-position of the tqdevice, relative to the widget that
+ received the event.
+
+ \sa x(), pos()
+*/
+
+/*!
+ \fn const TQPoint &TQTabletEvent::globalPos() const
+
+ Returns the global position of the tqdevice \e{at the time of the
+ event}. This is important on asynchronous windows systems like X11;
+ whenever you move your widgets around in response to mouse events,
+ globalPos() can differ significantly from the current position
+ TQCursor::pos().
+
+ \sa globalX(), globalY()
+*/
+
+/*!
+ \fn int TQTabletEvent::globalX() const
+
+ Returns the global x-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalY(), globalPos()
+*/
+
+/*!
+ \fn int TQTabletEvent::globalY() const
+
+ Returns the global y-position of the mouse pointer at the time of
+ the event.
+
+ \sa globalX(), globalPos()
+*/
+
+/*!
+ \fn bool TQTabletEvent::isAccepted() const
+
+ Returns TRUE if the receiver of the event handles the tablet
+ event; otherwise returns FALSE.
+*/
+
+/*!
+ \fn void TQTabletEvent::accept()
+
+ Sets the accept flag of the tablet event object.
+
+ Setting the accept flag indicates that the receiver of the event
+ wants the tablet event. Unwanted tablet events are sent to the
+ tqparent widget.
+
+ The accept flag is set by default.
+
+ \sa ignore()
+*/
+
+/*!
+ \fn void TQTabletEvent::ignore()
+
+ Clears the accept flag parameter of the tablet event object.
+
+ Clearing the accept flag indicates that the event receiver does
+ not want the tablet event. Unwanted tablet events are sent to the
+ tqparent widget.
+
+ The accept flag is set by default.
+
+ \sa accept()
+*/
+
+/*!
+ \fn TQPair<int, int> TQTabletEvent::uniqueId()
+
+ Returns a unique ID for the current tqdevice. It is possible to
+ generate a unique ID for any Wacom&copy; tqdevice. This makes it
+ possible to differentiate between multiple tqdevices being used at
+ the same time on the tablet. The \c first member tqcontains a value
+ for the type, the \c second member tqcontains a physical ID obtained
+ from the tqdevice. Each combination of these values is unique. Note:
+ for different platforms, the \c first value is different due to
+ different driver implementations.
+*/
+
+/*!
+ \class TQChildEvent tqevent.h
+ \brief The TQChildEvent class tqcontains event parameters for child object
+ events.
+
+ \ingroup events
+
+ Child events are sent to objects when tqchildren are inserted or
+ removed.
+
+ A \c ChildRemoved event is sent immediately, but a \c
+ ChildInserted event is \e posted (with TQApplication::postEvent()).
+
+ Note that if a child is removed immediately after it is inserted,
+ the \c ChildInserted event may be suppressed, but the \c
+ ChildRemoved event will always be sent. In this case there will be
+ a \c ChildRemoved event without a corresponding \c ChildInserted
+ event.
+
+ The handler for these events is TQObject::childEvent().
+*/
+
+/*!
+ \fn TQChildEvent::TQChildEvent( Type type, TQObject *child )
+
+ Constructs a child event object. The \a child is the object that
+ is to be removed or inserted.
+
+ The \a type parameter must be either \c TQEvent::ChildInserted or
+ \c TQEvent::ChildRemoved.
+*/
+
+/*!
+ \fn TQObject *TQChildEvent::child() const
+
+ Returns the child widget that was inserted or removed.
+*/
+
+/*!
+ \fn bool TQChildEvent::inserted() const
+
+ Returns TRUE if the widget received a new child; otherwise returns
+ FALSE.
+*/
+
+/*!
+ \fn bool TQChildEvent::removed() const
+
+ Returns TRUE if the object lost a child; otherwise returns FALSE.
+*/
+
+
+
+
+/*!
+ \class TQCustomEvent tqevent.h
+ \brief The TQCustomEvent class provides support for custom events.
+
+ \ingroup events
+
+ TQCustomEvent is a generic event class for user-defined events.
+ User defined events can be sent to widgets or other TQObject
+ instances using TQApplication::postEvent() or
+ TQApplication::sendEvent(). Subclasses of TQObject can easily
+ receive custom events by implementing the TQObject::customEvent()
+ event handler function.
+
+ TQCustomEvent objects should be created with a type ID that
+ uniquely identifies the event type. To avoid clashes with the
+ TQt-defined events types, the value should be at least as large as
+ the value of the "User" entry in the TQEvent::Type enum.
+
+ TQCustomEvent tqcontains a generic void* data member that may be used
+ for transferring event-specific data to the receiver. Note that
+ since events are normally delivered asynchronously, the data
+ pointer, if used, must remain valid until the event has been
+ received and processed.
+
+ TQCustomEvent can be used as-is for simple user-defined event
+ types, but normally you will want to make a subclass of it for
+ your event types. In a subclass, you can add data members that are
+ suitable for your event type.
+
+ Example:
+ \code
+ class ColorChangeEvent : public TQCustomEvent
+ {
+ public:
+ ColorChangeEvent( TQColor color )
+ : TQCustomEvent( 65432 ), c( color ) {}
+ TQColor color() const { return c; }
+ private:
+ TQColor c;
+ };
+
+ // To send an event of this custom event type:
+
+ ColorChangeEvent* ce = new ColorChangeEvent( blue );
+ TQApplication::postEvent( receiver, ce ); // TQt will delete it when done
+
+ // To receive an event of this custom event type:
+
+ void MyWidget::customEvent( TQCustomEvent * e )
+ {
+ if ( e->type() == 65432 ) { // It must be a ColorChangeEvent
+ ColorChangeEvent* ce = (ColorChangeEvent*)e;
+ newColor = ce->color();
+ }
+ }
+ \endcode
+
+ \sa TQWidget::customEvent(), TQApplication::notify()
+*/
+
+
+/*!
+ Constructs a custom event object with event type \a type. The
+ value of \a type must be at least as large as TQEvent::User. The
+ data pointer is set to 0.
+*/
+
+TQCustomEvent::TQCustomEvent( int type )
+ : TQEvent( (TQEvent::Type)type ), d( 0 )
+{
+}
+
+
+/*!
+ \fn TQCustomEvent::TQCustomEvent( Type type, void *data )
+
+ Constructs a custom event object with the event type \a type and a
+ pointer to \a data. (Note that any int value may safely be cast to
+ TQEvent::Type).
+*/
+
+
+/*!
+ \fn void TQCustomEvent::setData( void* data )
+
+ Sets the generic data pointer to \a data.
+
+ \sa data()
+*/
+
+/*!
+ \fn void *TQCustomEvent::data() const
+
+ Returns a pointer to the generic event data.
+
+ \sa setData()
+*/
+
+
+
+/*!
+ \fn TQDragMoveEvent::TQDragMoveEvent( const TQPoint& pos, Type type )
+
+ Creates a TQDragMoveEvent for which the mouse is at point \a pos,
+ and the event is of type \a type.
+
+ \warning Do not create a TQDragMoveEvent yourself since these
+ objects rely on TQt's internal state.
+*/
+
+/*!
+ \fn void TQDragMoveEvent::accept( const TQRect & r )
+
+ The same as accept(), but also notifies that future moves will
+ also be acceptable if they remain within the rectangle \a r on the
+ widget: this can improve performance, but may also be ignored by
+ the underlying system.
+
+ If the rectangle is \link TQRect::isEmpty() empty\endlink, then
+ drag move events will be sent continuously. This is useful if the
+ source is scrolling in a timer event.
+*/
+
+/*!
+ \fn void TQDragMoveEvent::ignore( const TQRect & r)
+
+ The opposite of accept(const TQRect&), i.e. says that moves within
+ rectangle \a r are not acceptable (will be ignored).
+*/
+
+/*!
+ \fn TQRect TQDragMoveEvent::answerRect() const
+
+ Returns the rectangle for which the acceptance of the move event
+ applies.
+*/
+
+
+
+/*!
+ \fn const TQPoint& TQDropEvent::pos() const
+
+ Returns the position where the drop was made.
+*/
+
+/*!
+ \fn bool TQDropEvent::isAccepted () const
+
+ Returns TRUE if the drop target accepts the event; otherwise
+ returns FALSE.
+*/
+
+/*!
+ \fn void TQDropEvent::accept(bool y=TRUE)
+
+ Call this function to indicate whether the event provided data
+ which your widget processed. Set \a y to TRUE (the default) if
+ your widget could process the data, otherwise set \a y to FALSE.
+ To get the data, use tqencodedData(), or preferably, the decode()
+ methods of existing TQDragObject subclasses, such as
+ TQTextDrag::decode(), or your own subclasses.
+
+ \sa acceptAction()
+*/
+
+/*!
+ \fn void TQDropEvent::acceptAction(bool y=TRUE)
+
+ Call this to indicate that the action described by action() is
+ accepted (i.e. if \a y is TRUE, which is the default), not merely
+ the default copy action. If you call acceptAction(TRUE), there is
+ no need to also call accept(TRUE).
+*/
+
+/*!
+ \fn void TQDragMoveEvent::accept( bool y )
+ \reimp
+ \internal
+ Remove in 3.0
+*/
+
+/*!
+ \fn void TQDragMoveEvent::ignore()
+ \reimp
+ \internal
+ Remove in 3.0
+*/
+
+
+/*!
+ \enum TQDropEvent::Action
+
+ This enum describes the action which a source requests that a
+ target perform with dropped data.
+
+ \value Copy The default action. The source simply uses the data
+ provided in the operation.
+ \value Link The source should somehow create a link to the
+ location specified by the data.
+ \value Move The source should somehow move the object from the
+ location specified by the data to a new location.
+ \value Private The target has special knowledge of the MIME type,
+ which the source should respond to in a similar way to
+ a Copy.
+ \value UserAction The source and target can co-operate using
+ special actions. This feature is not currently
+ supported.
+
+ The Link and Move actions only makes sense if the data is a
+ reference, for example, text/uri-list file lists (see TQUriDrag).
+*/
+
+/*!
+ \fn void TQDropEvent::setAction( Action a )
+
+ Sets the action to \a a. This is used internally, you should not
+ need to call this in your code: the \e source decides the action,
+ not the target.
+*/
+
+/*!
+ \fn Action TQDropEvent::action() const
+
+ Returns the Action which the target is requesting to be performed
+ with the data. If your application understands the action and can
+ process the supplied data, call acceptAction(); if your
+ application can process the supplied data but can only perform the
+ Copy action, call accept().
+*/
+
+/*!
+ \fn void TQDropEvent::ignore()
+
+ The opposite of accept(), i.e. you have ignored the drop event.
+*/
+
+/*!
+ \fn bool TQDropEvent::isActionAccepted () const
+
+ Returns TRUE if the drop action was accepted by the drop site;
+ otherwise returns FALSE.
+*/
+
+
+/*!
+ \fn void TQDropEvent::setPoint (const TQPoint & np)
+
+ Sets the drop to happen at point \a np. You do not normally need
+ to use this as it will be set internally before your widget
+ receives the drop event.
+*/ // ### here too - what coordinate system?
+
+
+/*!
+ \class TQDragEnterEvent tqevent.h
+ \brief The TQDragEnterEvent class provides an event which is sent to the widget when a drag and drop first drags onto the widget.
+
+ \ingroup events
+ \ingroup draganddrop
+
+ This event is always immediately followed by a TQDragMoveEvent, so
+ you only need to respond to one or the other event. This class
+ inherits most of its functionality from TQDragMoveEvent, which in
+ turn inherits most of its functionality from TQDropEvent.
+
+ \sa TQDragLeaveEvent, TQDragMoveEvent, TQDropEvent
+*/
+
+/*!
+ \fn TQDragEnterEvent::TQDragEnterEvent (const TQPoint & pos)
+
+ Constructs a TQDragEnterEvent entering at the given point, \a pos.
+
+ \warning Do not create a TQDragEnterEvent yourself since these
+ objects rely on TQt's internal state.
+*/
+
+/*!
+ \class TQDragLeaveEvent tqevent.h
+ \brief The TQDragLeaveEvent class provides an event which is sent to the widget when a drag and drop leaves the widget.
+
+ \ingroup events
+ \ingroup draganddrop
+
+ This event is always preceded by a TQDragEnterEvent and a series of
+ \l{TQDragMoveEvent}s. It is not sent if a TQDropEvent is sent
+ instead.
+
+ \sa TQDragEnterEvent, TQDragMoveEvent, TQDropEvent
+*/
+
+/*!
+ \fn TQDragLeaveEvent::TQDragLeaveEvent()
+
+ Constructs a TQDragLeaveEvent.
+
+ \warning Do not create a TQDragLeaveEvent yourself since these
+ objects rely on TQt's internal state.
+*/
+
+/*!
+ \class TQHideEvent tqevent.h
+ \brief The TQHideEvent class provides an event which is sent after a widget is hidden.
+
+ \ingroup events
+
+ This event is sent just before TQWidget::hide() returns, and also
+ when a top-level window has been hidden (iconified) by the user.
+
+ If spontaneous() is TRUE the event originated outside the
+ application, i.e. the user hid the window using the window manager
+ controls, either by iconifying the window or by switching to
+ another virtual desktop where the window isn't visible. The window
+ will become hidden but not withdrawn. If the window was iconified,
+ TQWidget::isMinimized() returns TRUE.
+
+ \sa TQShowEvent
+*/
+
+/*!
+ \fn TQHideEvent::TQHideEvent()
+
+ Constructs a TQHideEvent.
+*/
+
+/*!
+ \class TQShowEvent tqevent.h
+ \brief The TQShowEvent class provides an event which is sent when a widget is shown.
+
+ \ingroup events
+
+ There are two kinds of show events: show events caused by the
+ window system (spontaneous) and internal show events. Spontaneous
+ show events are sent just after the window system shows the
+ window, including after a top-level window has been shown
+ (un-iconified) by the user. Internal show events are delivered
+ just before the widget becomes visible.
+
+ \sa TQHideEvent
+*/
+
+/*!
+ \fn TQShowEvent::TQShowEvent()
+
+ Constructs a TQShowEvent.
+*/
+
+
+/*!
+ \fn TQByteArray TQDropEvent::data(const char* f) const
+
+ \obsolete
+
+ Use TQDropEvent::tqencodedData().
+*/
+
+
+/*!
+ Destroys the event. If it was \link
+ TQApplication::postEvent() posted \endlink,
+ it will be removed from the list of events to be posted.
+*/
+
+TQEvent::~TQEvent()
+{
+ if ( posted && tqApp )
+ TQApplication::removePostedEvent( this );
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqevent.h b/tqtinterface/qt4/src/kernel/tqevent.h
new file mode 100644
index 0000000..224759f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqevent.h
@@ -0,0 +1,952 @@
+/****************************************************************************
+**
+** Definition of event classes
+**
+** Created : 931029
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQEVENT_H
+#define TQEVENT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqregion.h"
+#include "tqnamespace.h"
+#include "tqmime.h"
+#include "tqpair.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qevent.h>
+#include "tqtenuminheritance.h"
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQEvent : public QEvent, virtual public TQt
+{
+public:
+ enum NewTypes {
+ Reparent = ParentChange,
+ ChildInsertedRequest = 67, // send ChildInserted compatibility events to receiver
+ ChildInserted = 70, // compatibility child inserted
+// LayoutHint = 72, // compatibility relayout request
+ LayoutHint = LayoutRequest, // compatibility relayout request
+ Accel = 30, // accelerator event
+ AccelAvailable = 32, // accelerator available event
+ AccelOverride = ShortcutOverride, // accelerator override event
+ CaptionChange = WindowTitleChange,
+ IconChange = WindowIconChange,
+ EnterEditFocus = 150, // enter edit mode in keypad navigation
+ LeaveEditFocus = 151, // enter edit mode in keypad navigation
+ IMStart = 500, // input method composition start
+ IMCompose = 501, // input method composition
+ IMEnd = 502, // input method composition end
+ ParentPaletteChange = 503, // parent palette changed [FIXME Not triggered anywhere]
+ ParentFontChange = 504, // parent font changed [FIXME Not triggered anywhere]
+ ShowMinimized = 600, // OBSOLETE [FIXME]
+ ShowMaximized = 601, // OBSOLETE [FIXME]
+ ShowFullScreen = 602, // OBSOLETE [FIXME]
+ ShowNormal = 603 // OBSOLETE [FIXME]
+ };
+
+ typedef TQTInheritEnum< NewTypes, QEvent::Type > Type;
+
+ TQEvent( Type type ) : QEvent( (QEvent::Type)((int)type) ) {}
+};
+
+class TQ_EXPORT TQTimerEvent : public QTimerEvent
+{
+public:
+ TQTimerEvent( int timerId ) : QTimerEvent( timerId ) {}
+};
+
+class TQ_EXPORT TQMouseEvent : public QMouseEvent
+{
+public:
+ TQMouseEvent( TQEvent::Type type, const TQPoint &pos, int button, int state ) : QMouseEvent( (QEvent::Type)((int)type), pos, (Qt::MouseButton)button, ((Qt::MouseButtons)state & Qt::MouseButtonMask), ((Qt::KeyboardModifiers)state & TQt::KeyButtonMask) ) {}
+ TQMouseEvent( TQEvent::Type type, const TQPoint &pos, const TQPoint&globalPos, int button, int state ) : QMouseEvent( (QEvent::Type)((int)type), pos, globalPos, (Qt::MouseButton)button, ((Qt::MouseButtons)state & Qt::MouseButtonMask), ((Qt::KeyboardModifiers)state & TQt::KeyButtonMask) ) {}
+
+ inline TQt::ButtonState state() const { return TQt::ButtonState((mouseState^b)|int(modifiers())); }
+ inline TQt::ButtonState stateAfter() const { return (buttons() | modifiers()); }
+};
+
+#ifndef TQT_NO_WHEELEVENT
+class TQ_EXPORT TQWheelEvent : public QWheelEvent
+{
+public:
+ TQWheelEvent( const TQPoint &pos, int delta, int state, Qt::Orientation orient = Qt::Vertical ) : QWheelEvent( pos, delta, ((Qt::MouseButtons)state & Qt::MouseButtonMask), ((Qt::KeyboardModifiers)state & TQt::KeyButtonMask), orient ) {}
+ TQWheelEvent( const TQPoint &pos, const TQPoint& globalPos, int delta, int state, Qt::Orientation orient = Qt::Vertical ) : QWheelEvent( pos, globalPos, delta, ((Qt::MouseButtons)state & Qt::MouseButtonMask), ((Qt::KeyboardModifiers)state & TQt::KeyButtonMask), orient ) {}
+
+ inline TQt::ButtonState state() const { return static_cast<TQt::ButtonState>(int(buttons())|int(modifiers())); }
+};
+#endif // TQT_NO_WHEELEVENT
+
+class TQ_EXPORT TQTabletEvent : public QTabletEvent
+{
+public:
+ TQTabletEvent( Type t, const TQPoint &pos, const TQPoint &globalPos, int tqdevice, int pressure, int xTilt, int yTilt, const TQPair<int,int> &uId ) : QTabletEvent( t, pos, globalPos, globalPos, tqdevice, QTabletEvent::UnknownPointer, pressure, xTilt, yTilt, 0, 0, 0, Qt::NoModifier, uId.first ) {}
+ TQTabletEvent( const TQPoint &pos, const TQPoint &globalPos, int tqdevice, int pressure, int xTilt, int yTilt, const TQPair<int,int> &uId ) : QTabletEvent( QEvent::None, pos, globalPos, globalPos, tqdevice, QTabletEvent::UnknownPointer, pressure, xTilt, yTilt, 0, 0, 0, Qt::NoModifier, uId.first ) {}
+};
+
+class TQ_EXPORT TQKeyEvent : public QKeyEvent
+{
+public:
+ TQKeyEvent( Type type, int key, int ascii, int state, const QString& text=QString::null, bool autorep=FALSE, ushort count=1 ) : QKeyEvent( type, key, ((Qt::KeyboardModifiers)state & Qt::KeyboardModifierMask), text, autorep, count ) { TQ_UNUSED(ascii); }
+ TQKeyEvent( TQEvent::NewTypes type, int key, int ascii, int state, const QString& text=QString::null, bool autorep=FALSE, ushort count=1 ) : QKeyEvent( (Type)type, key, ((Qt::KeyboardModifiers)state & Qt::KeyboardModifierMask), text, autorep, count ) { TQ_UNUSED(ascii); }
+ TQt::ButtonState stateAfter() const { return modifiers(); }
+ TQt::ButtonState state() const { return QInputEvent::modifiers(); }
+ int ascii() const { return (text().length() ? TQT_TQSTRING(text()).tqunicode()->toLatin1() : 0); }
+ friend class TQAccelManager;
+};
+
+class TQ_EXPORT TQFocusEvent : public QFocusEvent
+{
+public:
+ TQFocusEvent( Type type ) : QFocusEvent( type ), prev_reason( Qt::OtherFocusReason ) {}
+
+ enum Reason { Mouse=Qt::MouseFocusReason, Tab=Qt::TabFocusReason,
+ Backtab=Qt::BacktabFocusReason, MenuBar=Qt::MenuBarFocusReason,
+ ActiveWindow=Qt::ActiveWindowFocusReason, Other=Qt::OtherFocusReason,
+ Popup=Qt::PopupFocusReason, Shortcut=Qt::ShortcutFocusReason };
+
+ void setReason( Qt::FocusReason reason );
+ void resetReason();
+
+ inline void setReason( Reason reason ) { setReason((Qt::FocusReason)reason); }
+
+private:
+ Qt::FocusReason prev_reason;
+};
+
+class TQ_EXPORT TQPaintEvent : public QPaintEvent
+{
+public:
+ TQPaintEvent( const QRegion& paintRegion, bool erased = TRUE) : QPaintEvent( paintRegion ), erase(erased) {}
+ TQPaintEvent( const QRect &paintRect, bool erased = TRUE ) : QPaintEvent( paintRect ), erase(erased) {}
+ TQPaintEvent( const QRegion &paintRegion, const QRect &paintRect, bool erased = TRUE ) : QPaintEvent( paintRegion ), erase(erased) { TQ_UNUSED(paintRect); }
+
+ inline bool erased() const { return erase; }
+// inline const TQRect &rect() const { const TQRect &rect1 = QPaintEvent::rect(); return rect1; }
+ inline const TQRect rect() const { return TQRect(QPaintEvent::rect()); }
+protected:
+ bool erase;
+};
+
+class TQ_EXPORT TQMoveEvent : public QMoveEvent
+{
+public:
+ TQMoveEvent( const TQPoint &pos, const TQPoint &oldPos ) : QMoveEvent( pos, oldPos ) {}
+};
+
+class TQ_EXPORT TQResizeEvent : public QResizeEvent
+{
+public:
+ TQResizeEvent( const TQSize &size, const TQSize &oldSize ) : QResizeEvent( size, oldSize ) {};
+};
+
+class TQ_EXPORT TQCloseEvent : public QCloseEvent
+{
+public:
+ TQCloseEvent() : QCloseEvent() {}
+};
+
+class TQ_EXPORT TQIconDragEvent : public QIconDragEvent
+{
+public:
+ TQIconDragEvent() : QIconDragEvent() {}
+};
+
+class TQ_EXPORT TQShowEvent : public QShowEvent
+{
+public:
+ TQShowEvent() : QShowEvent() {}
+};
+
+
+class TQ_EXPORT TQHideEvent : public QHideEvent
+{
+public:
+ TQHideEvent() : QHideEvent() {}
+};
+
+class TQ_EXPORT TQContextMenuEvent : public QContextMenuEvent
+{
+public:
+ TQContextMenuEvent( Reason reason, const TQPoint &pos, const TQPoint &globalPos, int state ) : QContextMenuEvent( reason, pos, globalPos ) { TQ_UNUSED(state); }
+ TQContextMenuEvent( Reason reason, const TQPoint &pos, int state ) : QContextMenuEvent( reason, pos ) { TQ_UNUSED(state); }
+
+ bool isAccepted() const { return accpt; }
+ bool isConsumed() const { return consum; }
+ void consume() { accpt = FALSE; consum = TRUE; }
+ void accept() { accpt = TRUE; consum = TRUE; }
+ void ignore() { accpt = FALSE; consum = FALSE; }
+
+ TQt::ButtonState state() const;
+
+protected:
+ bool accpt;
+ bool consum;
+};
+
+// WARNING: Unimplemented in Qt4
+class TQ_EXPORT TQIMEvent : public TQEvent
+{
+public:
+ TQIMEvent( Type type, const TQString &text, int cursorPosition )
+ : TQEvent(type), txt(text), cpos(cursorPosition), a(TRUE) {}
+ const TQString &text() const { return txt; }
+ int cursorPos() const { return cpos; }
+ bool isAccepted() const { return a; }
+ void accept() { a = TRUE; }
+ void ignore() { a = FALSE; }
+ int selectionLength() const;
+
+private:
+ TQString txt;
+ int cpos;
+ bool a;
+};
+
+// WARNING: Unimplemented in Qt4
+class TQ_EXPORT TQIMComposeEvent : public TQIMEvent
+{
+public:
+ TQIMComposeEvent( Type type, const TQString &text, int cursorPosition,
+ int selLength )
+ : TQIMEvent( type, text, cursorPosition ), selLen( selLength ) { }
+
+private:
+ int selLen;
+
+ friend class TQIMEvent;
+};
+
+inline int TQIMEvent::selectionLength() const
+{
+ if ( (TQEvent::NewTypes)type() != IMCompose ) return 0;
+ TQIMComposeEvent *that = (TQIMComposeEvent *) this;
+ return that->selLen;
+}
+
+#ifndef TQT_NO_DRAGANDDROP
+// WARNING: Unimplemented in Qt4
+
+// This class is rather closed at the moment. If you need to create your
+// own DND event objects, write to qt-bugs@trolltech.com and we'll try to
+// tqfind a way to extend it so it covers your needs.
+
+class TQ_EXPORT TQDropEvent : public TQEvent, public TQMimeSource
+{
+public:
+ TQDropEvent( const TQPoint& pos, Type typ=Drop )
+ : TQEvent(typ), p(pos),
+ act(0), accpt(0), accptact(0), resv(0),
+ d(0)
+ {}
+ const TQPoint &pos() const { return p; }
+ bool isAccepted() const { return accpt || accptact; }
+ void accept(bool y=TRUE) { accpt = y; }
+ void ignore() { accpt = FALSE; }
+
+ bool isActionAccepted() const { return accptact; }
+ void acceptAction(bool y=TRUE) { accptact = y; }
+ enum Action { Copy, Link, Move, Private, UserAction=100 };
+ void setAction( Action a ) { act = (uint)a; }
+ Action action() const { return Action(act); }
+
+ TQWidget* source() const;
+ const char* format( int n = 0 ) const;
+ TQByteArray tqencodedData( const char* ) const;
+ bool provides( const char* ) const;
+
+ TQByteArray data(const char* f) const { return tqencodedData(f); }
+
+ void setPoint( const TQPoint& np ) { p = np; }
+
+protected:
+ TQPoint p;
+ uint act:8;
+ uint accpt:1;
+ uint accptact:1;
+ uint resv:5;
+ void * d;
+};
+
+
+
+class TQ_EXPORT TQDragMoveEvent : public TQDropEvent
+{
+public:
+ TQDragMoveEvent( const TQPoint& pos, Type typ=DragMove )
+ : TQDropEvent(pos,typ),
+ rect( pos, TQSize( 1, 1 ) ) {}
+ TQRect answerRect() const { return rect; }
+ void accept( bool y=TRUE ) { TQDropEvent::accept(y); }
+ void accept( const TQRect & r) { accpt = TRUE; rect = r; }
+ void ignore( const TQRect & r) { accpt =FALSE; rect = r; }
+ void ignore() { TQDropEvent::ignore(); }
+
+protected:
+ TQRect rect;
+};
+
+
+class TQ_EXPORT TQDragEnterEvent : public TQDragMoveEvent
+{
+public:
+ TQDragEnterEvent( const TQPoint& pos ) :
+ TQDragMoveEvent(pos, DragEnter) { }
+};
+
+
+/* An internal class */
+class TQ_EXPORT TQDragResponseEvent : public TQEvent
+{
+public:
+ TQDragResponseEvent( bool accepted )
+ : TQEvent(DragResponse), a(accepted) {}
+ bool dragAccepted() const { return a; }
+protected:
+ bool a;
+};
+
+
+class TQ_EXPORT TQDragLeaveEvent : public TQEvent
+{
+public:
+ TQDragLeaveEvent()
+ : TQEvent(DragLeave) {}
+};
+
+#endif // TQT_NO_DRAGANDDROP
+
+class TQ_EXPORT TQChildEvent : public QChildEvent
+{
+public:
+ TQChildEvent( Type type, TQT_BASE_OBJECT_NAME *child ) : QChildEvent( type, child ) {}
+
+ //bool inserted() const { return type() == ChildAdded; } // Should be ChildInserted as below, they are NOT the same!
+ bool inserted() const { return (TQEvent::NewTypes)type() == TQEvent::ChildInserted; }
+};
+
+// WARNING: Unimplemented in Qt4
+class TQ_EXPORT TQCustomEvent : public TQEvent
+{
+public:
+ TQCustomEvent( int type );
+ TQCustomEvent( Type type, void *data )
+ : TQEvent(type), d(data) {};
+ void *data() const { return d; }
+ void setData( void* data ) { d = data; }
+private:
+ void *d;
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQEvent: public TQt // event base class
+{
+public:
+ enum Type {
+
+ /*
+ If you get a strange compiler error on the line with None,
+ it's probably because you're also including X11 headers,
+ which #define the symbol None. Put the X11 includes after
+ the TQt includes to solve this problem.
+ */
+
+ None = 0, // invalid event
+
+
+ Timer = 1, // timer event
+ MouseButtonPress = 2, // mouse button pressed
+ MouseButtonRelease = 3, // mouse button released
+ MouseButtonDblClick = 4, // mouse button double click
+ MouseMove = 5, // mouse move
+ KeyPress = 6, // key pressed
+ KeyRelease = 7, // key released
+ FocusIn = 8, // keyboard focus received
+ FocusOut = 9, // keyboard focus lost
+ Enter = 10, // mouse enters widget
+ Leave = 11, // mouse leaves widget
+ Paint = 12, // paint widget
+ Move = 13, // move widget
+ Resize = 14, // resize widget
+ Create = 15, // after object creation
+ Destroy = 16, // during object destruction
+ Show = 17, // widget is shown
+ Hide = 18, // widget is hidden
+ Close = 19, // request to close widget
+ Quit = 20, // request to quit application
+ Retqparent = 21, // widget has been reparented
+ ShowMinimized = 22, // widget is shown minimized
+ ShowNormal = 23, // widget is shown normal
+ WindowActivate = 24, // window was activated
+ WindowDeactivate = 25, // window was deactivated
+ ShowToParent = 26, // widget is shown to tqparent
+ HideToParent = 27, // widget is hidden to tqparent
+ ShowMaximized = 28, // widget is shown maximized
+ ShowFullScreen = 29, // widget is shown full-screen
+ Accel = 30, // accelerator event
+ Wheel = 31, // wheel event
+ AccelAvailable = 32, // accelerator available event
+ CaptionChange = 33, // caption changed
+ IconChange = 34, // icon changed
+ ParentFontChange = 35, // tqparent font changed
+ ApplicationFontChange = 36, // application font changed
+ ParentPaletteChange = 37, // tqparent palette changed
+ ApplicationPaletteChange = 38, // application palette changed
+ PaletteChange = 39, // widget palette changed
+ Clipboard = 40, // internal clipboard event
+ Speech = 42, // reserved for speech input
+ SockAct = 50, // socket activation
+ AccelOverride = 51, // accelerator override event
+ DeferredDelete = 52, // deferred delete event
+ DragEnter = 60, // drag moves into widget
+ DragMove = 61, // drag moves in widget
+ DragLeave = 62, // drag leaves or is cancelled
+ Drop = 63, // actual drop
+ DragResponse = 64, // drag accepted/rejected
+ ChildInserted = 70, // new child widget
+ ChildRemoved = 71, // deleted child widget
+ LayoutHint = 72, // child min/max size changed
+ ShowWindowRequest = 73, // widget's window should be mapped
+ WindowBlocked = 74, // window is about to be blocked modally
+ WindowUnblocked = 75, // windows modal blocking has ended
+ ActivateControl = 80, // ActiveX activation
+ DeactivateControl = 81, // ActiveX deactivation
+ ContextMenu = 82, // context popup menu
+ IMStart = 83, // input method composition start
+ IMCompose = 84, // input method composition
+ IMEnd = 85, // input method composition end
+ Accessibility = 86, // accessibility information is requested
+ TabletMove = 87, // Wacom tablet event
+ LocaleChange = 88, // the system locale changed
+ LanguageChange = 89, // the application language changed
+ LayoutDirectionChange = 90, // the tqlayout direction changed
+ Style = 91, // internal style event
+ TabletPress = 92, // tablet press
+ TabletRelease = 93, // tablet release
+ OkRequest = 94, // CE (Ok) button pressed
+ HelpRequest = 95, // CE (?) button pressed
+ WindowStateChange = 96, // window state has changed
+ IconDrag = 97, // proxy icon dragged
+ User = 1000, // first user event id
+ MaxUser = 65535 // last user event id
+ };
+
+
+ TQEvent( Type type ) : t(type), posted(FALSE), spont(FALSE) {}
+ virtual ~TQEvent();
+ Type type() const { return t; }
+ bool spontaneous() const { return spont; }
+protected:
+ Type t;
+private:
+ uint posted : 1;
+ uint spont : 1;
+
+
+ friend class TQApplication;
+ friend class TQAccelManager;
+ friend class TQBaseApplication;
+ friend class TQETWidget;
+};
+
+
+class TQ_EXPORT TQTimerEvent : public TQEvent
+{
+public:
+ TQTimerEvent( int timerId )
+ : TQEvent(Timer), id(timerId) {}
+ int timerId() const { return id; }
+protected:
+ int id;
+};
+
+
+class TQ_EXPORT TQMouseEvent : public TQEvent
+{
+public:
+ TQMouseEvent( Type type, const TQPoint &pos, int button, int state );
+
+ TQMouseEvent( Type type, const TQPoint &pos, const TQPoint&globalPos,
+ int button, int state )
+ : TQEvent(type), p(pos), g(globalPos), b((ushort)button),s((ushort)state),accpt(TRUE) {};
+
+ const TQPoint &pos() const { return p; }
+ const TQPoint &globalPos() const { return g; }
+ int x() const { return p.x(); }
+ int y() const { return p.y(); }
+ int globalX() const { return g.x(); }
+ int globalY() const { return g.y(); }
+ ButtonState button() const { return (ButtonState) b; }
+ ButtonState state() const { return (ButtonState) s; }
+ ButtonState stateAfter() const;
+ bool isAccepted() const { return accpt; }
+ void accept() { accpt = TRUE; }
+ void ignore() { accpt = FALSE; }
+protected:
+ TQPoint p;
+ TQPoint g;
+ ushort b;
+ ushort s;
+ uint accpt:1;
+};
+
+
+#ifndef TQT_NO_WHEELEVENT
+class TQ_EXPORT TQWheelEvent : public TQEvent
+{
+public:
+ TQWheelEvent( const TQPoint &pos, int delta, int state, Orientation orient = Vertical );
+ TQWheelEvent( const TQPoint &pos, const TQPoint& globalPos, int delta, int state, Orientation orient = Vertical )
+ : TQEvent(Wheel), p(pos), g(globalPos), d(delta), s((ushort)state),
+ accpt(TRUE), o(orient) {}
+ int delta() const { return d; }
+ const TQPoint &pos() const { return p; }
+ const TQPoint &globalPos() const { return g; }
+ int x() const { return p.x(); }
+ int y() const { return p.y(); }
+ int globalX() const { return g.x(); }
+ int globalY() const { return g.y(); }
+ ButtonState state() const { return ButtonState(s); }
+ Orientation orientation() const { return o; }
+ bool isAccepted() const { return accpt; }
+ void accept() { accpt = TRUE; }
+ void ignore() { accpt = FALSE; }
+protected:
+ TQPoint p;
+ TQPoint g;
+ int d;
+ ushort s;
+ bool accpt;
+ Orientation o;
+};
+#endif
+
+class TQ_EXPORT TQTabletEvent : public TQEvent
+{
+public:
+ enum TabletDevice { NoDevice = -1, Puck, Stylus, Eraser };
+ TQTabletEvent( Type t, const TQPoint &pos, const TQPoint &globalPos, int tqdevice,
+ int pressure, int xTilt, int yTilt, const TQPair<int,int> &uId );
+ TQTabletEvent( const TQPoint &pos, const TQPoint &globalPos, int tqdevice,
+ int pressure, int xTilt, int yTilt, const TQPair<int,int> &uId )
+ : TQEvent( TabletMove ), mPos( pos ), mGPos( globalPos ), mDev( tqdevice ),
+ mPress( pressure ), mXT( xTilt ), mYT( yTilt ), mType( uId.first ),
+ mPhy( uId.second ), mbAcc(TRUE)
+ {}
+ int pressure() const { return mPress; }
+ int xTilt() const { return mXT; }
+ int yTilt() const { return mYT; }
+ const TQPoint &pos() const { return mPos; }
+ const TQPoint &globalPos() const { return mGPos; }
+ int x() const { return mPos.x(); }
+ int y() const { return mPos.y(); }
+ int globalX() const { return mGPos.x(); }
+ int globalY() const { return mGPos.y(); }
+ TabletDevice tqdevice() const { return TabletDevice(mDev); }
+ int isAccepted() const { return mbAcc; }
+ void accept() { mbAcc = TRUE; }
+ void ignore() { mbAcc = FALSE; }
+ TQPair<int,int> uniqueId() { return TQPair<int,int>( mType, mPhy); }
+protected:
+ TQPoint mPos;
+ TQPoint mGPos;
+ int mDev,
+ mPress,
+ mXT,
+ mYT,
+ mType,
+ mPhy;
+ bool mbAcc;
+
+};
+
+class TQ_EXPORT TQKeyEvent : public TQEvent
+{
+public:
+ TQKeyEvent( Type type, int key, int ascii, int state,
+ const TQString& text=TQString::null, bool autorep=FALSE, ushort count=1 )
+ : TQEvent(type), txt(text), k((ushort)key), s((ushort)state),
+ a((uchar)ascii), accpt(TRUE), autor(autorep), c(count)
+ {
+ if ( key >= Key_Back && key <= Key_MediaLast )
+ accpt = FALSE;
+ }
+ int key() const { return k; }
+ int ascii() const { return a; }
+ ButtonState state() const { return ButtonState(s); }
+ ButtonState stateAfter() const;
+ bool isAccepted() const { return accpt; }
+ TQString text() const { return txt; }
+ bool isAutoRepeat() const { return autor; }
+ int count() const { return int(c); }
+ void accept() { accpt = TRUE; }
+ void ignore() { accpt = FALSE; }
+
+protected:
+ TQString txt;
+ ushort k, s;
+ uchar a;
+ uint accpt:1;
+ uint autor:1;
+ ushort c;
+};
+
+
+class TQ_EXPORT TQFocusEvent : public TQEvent
+{
+public:
+
+ TQFocusEvent( Type type )
+ : TQEvent(type) {}
+
+ bool gotFocus() const { return type() == FocusIn; }
+ bool lostFocus() const { return type() == FocusOut; }
+
+ enum Reason { Mouse, Tab, Backtab, ActiveWindow, Popup, Shortcut, Other };
+ static Reason reason();
+ static void setReason( Reason reason );
+ static void resetReason();
+
+private:
+ static Reason m_reason;
+ static Reason prev_reason;
+};
+
+
+class TQ_EXPORT TQPaintEvent : public TQEvent
+{
+public:
+ TQPaintEvent( const TQRegion& paintRegion, bool erased = TRUE)
+ : TQEvent(Paint),
+ rec(paintRegion.boundingRect()),
+ reg(paintRegion),
+ erase(erased){}
+ TQPaintEvent( const TQRect &paintRect, bool erased = TRUE )
+ : TQEvent(Paint),
+ rec(paintRect),
+ reg(paintRect),
+ erase(erased){}
+ TQPaintEvent( const TQRegion &paintRegion, const TQRect &paintRect, bool erased = TRUE )
+ : TQEvent(Paint),
+ rec(paintRect),
+ reg(paintRegion),
+ erase(erased){}
+
+ const TQRect &rect() const { return rec; }
+ const TQRegion &region() const { return reg; }
+ bool erased() const { return erase; }
+protected:
+ friend class TQApplication;
+ friend class TQBaseApplication;
+ TQRect rec;
+ TQRegion reg;
+ bool erase;
+};
+
+
+class TQ_EXPORT TQMoveEvent : public TQEvent
+{
+public:
+ TQMoveEvent( const TQPoint &pos, const TQPoint &oldPos )
+ : TQEvent(Move), p(pos), oldp(oldPos) {}
+ const TQPoint &pos() const { return p; }
+ const TQPoint &oldPos()const { return oldp;}
+protected:
+ TQPoint p, oldp;
+ friend class TQApplication;
+ friend class TQBaseApplication;
+};
+
+
+class TQ_EXPORT TQResizeEvent : public TQEvent
+{
+public:
+ TQResizeEvent( const TQSize &size, const TQSize &oldSize )
+ : TQEvent(Resize), s(size), olds(oldSize) {}
+ const TQSize &size() const { return s; }
+ const TQSize &oldSize()const { return olds;}
+protected:
+ TQSize s, olds;
+ friend class TQApplication;
+ friend class TQBaseApplication;
+};
+
+
+class TQ_EXPORT TQCloseEvent : public TQEvent
+{
+public:
+ TQCloseEvent()
+ : TQEvent(Close), accpt(FALSE) {}
+ bool isAccepted() const { return accpt; }
+ void accept() { accpt = TRUE; }
+ void ignore() { accpt = FALSE; }
+protected:
+ bool accpt;
+};
+
+
+class TQ_EXPORT TQIconDragEvent : public TQEvent
+{
+public:
+ TQIconDragEvent()
+ : TQEvent(IconDrag), accpt(FALSE) {}
+
+ bool isAccepted() const { return accpt; }
+ void accept() { accpt = TRUE; }
+ void ignore() { accpt = FALSE; }
+protected:
+ bool accpt;
+};
+
+class TQ_EXPORT TQShowEvent : public TQEvent
+{
+public:
+ TQShowEvent()
+ : TQEvent(Show) {}
+};
+
+
+class TQ_EXPORT TQHideEvent : public TQEvent
+{
+public:
+ TQHideEvent()
+ : TQEvent(Hide) {}
+};
+
+class TQ_EXPORT TQContextMenuEvent : public TQEvent
+{
+public:
+ enum Reason { Mouse, Keyboard, Other };
+ TQContextMenuEvent( Reason reason, const TQPoint &pos, const TQPoint &globalPos, int state )
+ : TQEvent( ContextMenu ), p( pos ), gp( globalPos ), accpt( TRUE ), consum( TRUE ),
+ reas( reason ), s((ushort)state) {}
+ TQContextMenuEvent( Reason reason, const TQPoint &pos, int state );
+
+ int x() const { return p.x(); }
+ int y() const { return p.y(); }
+ int globalX() const { return gp.x(); }
+ int globalY() const { return gp.y(); }
+
+ const TQPoint& pos() const { return p; }
+ const TQPoint& globalPos() const { return gp; }
+
+ ButtonState state() const { return (ButtonState) s; }
+ bool isAccepted() const { return accpt; }
+ bool isConsumed() const { return consum; }
+ void consume() { accpt = FALSE; consum = TRUE; }
+ void accept() { accpt = TRUE; consum = TRUE; }
+ void ignore() { accpt = FALSE; consum = FALSE; }
+
+ Reason reason() const { return Reason( reas ); }
+
+protected:
+ TQPoint p;
+ TQPoint gp;
+ bool accpt;
+ bool consum;
+ uint reas:8;
+ ushort s;
+};
+
+
+class TQ_EXPORT TQIMEvent : public TQEvent
+{
+public:
+ TQIMEvent( Type type, const TQString &text, int cursorPosition )
+ : TQEvent(type), txt(text), cpos(cursorPosition), a(TRUE) {}
+ const TQString &text() const { return txt; }
+ int cursorPos() const { return cpos; }
+ bool isAccepted() const { return a; }
+ void accept() { a = TRUE; }
+ void ignore() { a = FALSE; }
+ int selectionLength() const;
+
+private:
+ TQString txt;
+ int cpos;
+ bool a;
+};
+
+class TQ_EXPORT TQIMComposeEvent : public TQIMEvent
+{
+public:
+ TQIMComposeEvent( Type type, const TQString &text, int cursorPosition,
+ int selLength )
+ : TQIMEvent( type, text, cursorPosition ), selLen( selLength ) { }
+
+private:
+ int selLen;
+
+ friend class TQIMEvent;
+};
+
+inline int TQIMEvent::selectionLength() const
+{
+ if ( type() != IMCompose ) return 0;
+ TQIMComposeEvent *that = (TQIMComposeEvent *) this;
+ return that->selLen;
+}
+
+
+#ifndef TQT_NO_DRAGANDDROP
+
+// This class is rather closed at the moment. If you need to create your
+// own DND event objects, write to qt-bugs@trolltech.com and we'll try to
+// tqfind a way to extend it so it covers your needs.
+
+class TQ_EXPORT TQDropEvent : public TQEvent, public TQMimeSource
+{
+public:
+ TQDropEvent( const TQPoint& pos, Type typ=Drop )
+ : TQEvent(typ), p(pos),
+ act(0), accpt(0), accptact(0), resv(0),
+ d(0)
+ {}
+ const TQPoint &pos() const { return p; }
+ bool isAccepted() const { return accpt || accptact; }
+ void accept(bool y=TRUE) { accpt = y; }
+ void ignore() { accpt = FALSE; }
+
+ bool isActionAccepted() const { return accptact; }
+ void acceptAction(bool y=TRUE) { accptact = y; }
+ enum Action { Copy, Link, Move, Private, UserAction=100 };
+ void setAction( Action a ) { act = (uint)a; }
+ Action action() const { return Action(act); }
+
+ TQWidget* source() const;
+ const char* format( int n = 0 ) const;
+ TQByteArray tqencodedData( const char* ) const;
+ bool provides( const char* ) const;
+
+ TQByteArray data(const char* f) const { return tqencodedData(f); }
+
+ void setPoint( const TQPoint& np ) { p = np; }
+
+protected:
+ TQPoint p;
+ uint act:8;
+ uint accpt:1;
+ uint accptact:1;
+ uint resv:5;
+ void * d;
+};
+
+
+
+class TQ_EXPORT TQDragMoveEvent : public TQDropEvent
+{
+public:
+ TQDragMoveEvent( const TQPoint& pos, Type typ=DragMove )
+ : TQDropEvent(pos,typ),
+ rect( pos, TQSize( 1, 1 ) ) {}
+ TQRect answerRect() const { return rect; }
+ void accept( bool y=TRUE ) { TQDropEvent::accept(y); }
+ void accept( const TQRect & r) { accpt = TRUE; rect = r; }
+ void ignore( const TQRect & r) { accpt =FALSE; rect = r; }
+ void ignore() { TQDropEvent::ignore(); }
+
+protected:
+ TQRect rect;
+};
+
+
+class TQ_EXPORT TQDragEnterEvent : public TQDragMoveEvent
+{
+public:
+ TQDragEnterEvent( const TQPoint& pos ) :
+ TQDragMoveEvent(pos, DragEnter) { }
+};
+
+
+/* An internal class */
+class TQ_EXPORT TQDragResponseEvent : public TQEvent
+{
+public:
+ TQDragResponseEvent( bool accepted )
+ : TQEvent(DragResponse), a(accepted) {}
+ bool dragAccepted() const { return a; }
+protected:
+ bool a;
+};
+
+
+class TQ_EXPORT TQDragLeaveEvent : public TQEvent
+{
+public:
+ TQDragLeaveEvent()
+ : TQEvent(DragLeave) {}
+};
+
+#endif // TQT_NO_DRAGANDDROP
+
+class TQ_EXPORT TQChildEvent : public TQEvent
+{
+public:
+ TQChildEvent( Type type, TQObject *child )
+ : TQEvent(type), c(child) {}
+ TQObject *child() const { return c; }
+ bool inserted() const { return t == ChildInserted; }
+ bool removed() const { return t == ChildRemoved; }
+protected:
+ TQObject *c;
+};
+
+
+class TQ_EXPORT TQCustomEvent : public TQEvent
+{
+public:
+ TQCustomEvent( int type );
+ TQCustomEvent( Type type, void *data )
+ : TQEvent(type), d(data) {};
+ void *data() const { return d; }
+ void setData( void* data ) { d = data; }
+private:
+ void *d;
+};
+
+#endif // USE_QT4
+
+#endif // TQEVENT_H
diff --git a/tqtinterface/qt4/src/kernel/tqeventloop.cpp b/tqtinterface/qt4/src/kernel/tqeventloop.cpp
new file mode 100644
index 0000000..704fc43
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqeventloop.cpp
@@ -0,0 +1,394 @@
+/****************************************************************************
+**
+** Implementation of TQEventLoop class
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqeventloop_p.h" // includes qplatformdefs.h
+#include "tqeventloop.h"
+#include "tqapplication.h"
+#include "tqdatetime.h"
+
+/*!
+ \class TQEventLoop
+ \brief The TQEventLoop class manages the event queue.
+
+ \ingroup application
+ \ingroup events
+
+ It receives events from the window system and other sources. It
+ then sends them to TQApplication for processing and delivery.
+
+ TQEventLoop allows the application programmer to have more control
+ over event delivery. Programs that perform long operations can
+ call either processOneEvent() or processEvents() with various
+ ProcessEvent values OR'ed together to control which events should
+ be delivered.
+
+ TQEventLoop also allows the integration of an external event loop
+ with the TQt event loop. The Motif Extension included with TQt
+ includes a reimplementation of TQEventLoop for merging TQt and Motif
+ events together.
+
+ To use your own instance of TQEventLoop or TQEventLoop subclass create
+ it before you create the TQApplication object.
+*/
+
+/*! \enum TQEventLoop::ProcessEvents
+
+ This enum controls the types of events processed by the
+ processEvents() functions.
+
+ \value AllEvents - All events are processed
+ \value ExcludeUserInput - Do not process user input events.
+ ( ButtonPress, KeyPress, etc. )
+ \value ExcludeSocketNotifiers - Do not process socket notifier
+ events.
+ \value WaitForMore - Wait for events if no pending events
+ are available.
+
+ \sa processEvents()
+*/
+
+/*! \enum TQEventLoop::ProcessEventsFlags
+ A \c typedef to allow various ProcessEvents values to be OR'ed together.
+
+ \sa ProcessEvents
+ */
+
+/*!
+ Creates a TQEventLoop object, this object becomes the global event loop object.
+ There can only be one event loop object. The TQEventLoop is usually constructed
+ by calling TQApplication::eventLoop(). To create your own event loop object create
+ it before you instantiate the TQApplication object.
+
+ The \a tqparent and \a name arguments are passed on to the TQObject constructor.
+*/
+TQEventLoop::TQEventLoop( TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( TQApplication::eventloop )
+ qFatal( "TQEventLoop: there must be only one event loop object. \nConstruct it before TQApplication." );
+ // for now ;)
+#endif // TQT_CHECK_STATE
+
+ d = new TQEventLoopPrivate;
+
+ init();
+ TQApplication::eventloop = this;
+}
+
+/*!
+ Destructs the TQEventLoop object.
+*/
+TQEventLoop::~TQEventLoop()
+{
+ cleanup();
+ delete d;
+ TQApplication::eventloop = 0;
+}
+
+/*!
+ Enters the main event loop and waits until exit() is called, and
+ returns the value that was set to exit().
+
+ It is necessary to call this function to start event handling. The
+ main event loop receives events from the window system and
+ dispatches these to the application widgets.
+
+ Generally speaking, no user interaction can take place before
+ calling exec(). As a special case, modal widgets like TQMessageBox
+ can be used before calling exec(), because modal widgets call
+ exec() to start a local event loop.
+
+ To make your application perform idle processing, i.e. executing a
+ special function whenever there are no pending events, use a
+ TQTimer with 0 timeout. More advanced idle processing schemes can
+ be achieved using processEvents().
+
+ \sa TQApplication::quit(), exit(), processEvents()
+*/
+int TQEventLoop::exec()
+{
+ d->reset();
+
+ enterLoop();
+
+ // cleanup
+ d->looplevel = 0;
+ d->quitnow = FALSE;
+ d->exitloop = FALSE;
+ d->shortcut = FALSE;
+ // don't reset quitcode!
+
+ return d->quitcode;
+}
+
+/*! \fn void TQEventLoop::exit( int retcode = 0 )
+
+ Tells the event loop to exit with a return code.
+
+ After this function has been called, the event loop returns from
+ the call to exec(). The exec() function returns \a retcode.
+
+ By convention, a \a retcode of 0 means success, and any non-zero
+ value indicates an error.
+
+ Note that unlike the C library function of the same name, this
+ function \e does return to the caller -- it is event processing that
+ stops.
+
+ \sa TQApplication::quit(), exec()
+*/
+void TQEventLoop::exit( int retcode )
+{
+ if ( d->quitnow ) // preserve existing quitcode
+ return;
+ d->quitcode = retcode;
+ d->quitnow = TRUE;
+ d->exitloop = TRUE;
+ d->shortcut = TRUE;
+}
+
+
+/*! \fn int TQEventLoop::enterLoop()
+
+ This function enters the main event loop (recursively). Do not call
+ it unless you really know what you are doing.
+ */
+int TQEventLoop::enterLoop()
+{
+ // save the current exitloop state
+ bool old_exitloop = d->exitloop;
+ d->exitloop = FALSE;
+ d->shortcut = FALSE;
+
+ d->looplevel++;
+ while ( ! d->exitloop )
+ processEvents( AllEvents | WaitForMore );
+ d->looplevel--;
+
+ // restore the exitloop state, but if quitnow is TRUE, we need to keep
+ // exitloop set so that all other event loops drop out.
+ d->exitloop = old_exitloop || d->quitnow;
+ d->shortcut = d->quitnow;
+
+ if ( d->looplevel < 1 ) {
+ d->quitnow = FALSE;
+ d->exitloop = FALSE;
+ d->shortcut = FALSE;
+ emit tqApp->aboutToQuit();
+
+ // send deferred deletes
+ TQApplication::sendPostedEvents( 0, TQEvent::DeferredDelete );
+ }
+
+ return d->looplevel;
+}
+
+/*! \fn void TQEventLoop::exitLoop()
+
+ This function exits from a recursive call to the main event loop.
+ Do not call it unless you really know what you are doing.
+*/
+void TQEventLoop::exitLoop()
+{
+ d->exitloop = TRUE;
+ d->shortcut = TRUE;
+}
+
+/*! \fn void TQEventLoop::loopLevel() const
+
+ Returns the current loop level.
+*/
+int TQEventLoop::loopLevel() const
+{
+ return d->looplevel;
+}
+
+/*!
+ Process pending events that match \a flags for a maximum of \a
+ maxTime milliseconds, or until there are no more events to
+ process, which ever is shorter.
+
+ This function is especially useful if you have a long running
+ operation and want to show its progress without allowing user
+ input, i.e. by using the \c ExcludeUserInput flag.
+
+ NOTE: This function will not process events continuously; it
+ returns after all available events are processed.
+
+ NOTE: Specifying the \c WaitForMore flag makes no sense and will
+ be ignored.
+*/
+void TQEventLoop::processEvents( ProcessEventsFlags flags, int maxTime )
+{
+ TQTime start = TQTime::currentTime();
+ TQTime now;
+ while ( ! d->quitnow && processEvents( flags & ~WaitForMore ) ) {
+ now = TQTime::currentTime();
+ if ( start.msecsTo( now ) > maxTime )
+ break;
+ }
+}
+
+/*!
+ \fn bool TQEventLoop::processEvents( ProcessEventsFlags flags )
+ \overload
+
+ Processes pending events that match \a flags until there are no
+ more events to process.
+
+ This function is especially useful if you have a long running
+ operation and want to show its progress without allowing user
+ input, i.e. by using the \c ExcludeUserInput flag.
+
+ If the \c WaitForMore flag is set in \a flags, the behavior of
+ this function is as follows:
+
+ \list
+
+ \i If events are available, this function returns after processing
+ them.
+
+ \i If no events are available, this function will wait until more
+ are available and return after processing newly available events.
+
+ \endlist
+
+ If the \c WaitForMore flag is \e not set in \a flags, and no
+ events are available, this function will return immediately.
+
+ NOTE: This function will not process events continuously; it
+ returns after all available events are processed.
+
+ This function returns TRUE if an event was processed; otherwise it
+ returns FALSE.
+
+ \sa ProcessEvents hasPendingEvents()
+*/
+
+/*! \fn bool TQEventLoop::hasPendingEvents() const
+
+ Returns TRUE if there is an event waiting, otherwise it returns FALSE.
+*/
+
+/*! \fn void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier )
+
+ Registers \a notifier with the event loop. Subclasses need to
+ reimplement this method to tie a socket notifier into another
+ event loop. Reimplementations \e MUST call the base
+ implementation.
+*/
+
+/*! \fn void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier )
+
+ Unregisters \a notifier from the event loop. Subclasses need to
+ reimplement this method to tie a socket notifier into another
+ event loop. Reimplementations \e MUST call the base
+ implementation.
+*/
+
+/*! \fn void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier )
+
+ Marks \a notifier as pending. The socket notifier will be
+ activated the next time activateSocketNotifiers() is called.
+*/
+
+/*! \fn int TQEventLoop::activateSocketNotifiers()
+
+ Activates all pending socket notifiers and returns the number of
+ socket notifiers that were activated.
+*/
+
+/*! \fn int TQEventLoop::activateTimers()
+
+ Activates all TQt timers and returns the number of timers that were
+ activated.
+
+ TQEventLoop subclasses that do their own timer handling need to
+ call this after the time returned by timeToWait() has elapsed.
+
+ Note: This function is only useful on systems where \c select() is
+ used to block the eventloop. On Windows, this function always
+ returns 0. On MacOS X, this function always returns 0 when the
+ GUI is enabled. On MacOS X, this function returns the documented
+ value when the GUI is disabled.
+*/
+
+/*! \fn int TQEventLoop::timeToWait() const
+
+ Returns the number of milliseconds that TQt needs to handle its
+ timers or -1 if there are no timers running.
+
+ TQEventLoop subclasses that do their own timer handling need to use
+ this to make sure that TQt's timers continue to work.
+
+ Note: This function is only useful on systems where \c select() is
+ used to block the eventloop. On Windows, this function always
+ returns -1. On MacOS X, this function always returns -1 when the
+ GUI is enabled. On MacOS X, this function returns the documented
+ value when the GUI is disabled.
+*/
+
+/*! \fn void TQEventLoop::wakeUp()
+ \threadsafe
+
+ Wakes up the event loop.
+
+ \sa awake()
+*/
+
+/*! \fn void TQEventLoop::awake()
+
+ This signal is emitted after the event loop returns from a
+ function that could block.
+
+ \sa wakeUp() aboutToBlock()
+*/
+
+/*! \fn void TQEventLoop::aboutToBlock()
+
+ This signal is emitted before the event loop calls a function that
+ could block.
+
+ \sa awake()
+*/
+
+#if !defined(TQ_WS_X11)
+void TQEventLoop::appStartingUp(){}
+void TQEventLoop::appClosingDown(){}
+#endif // TQ_WS_X11
diff --git a/tqtinterface/qt4/src/kernel/tqeventloop.h b/tqtinterface/qt4/src/kernel/tqeventloop.h
new file mode 100644
index 0000000..d837a75
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqeventloop.h
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Declaration of TQEventLoop class
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQEVENTLOOP_H
+#define TQEVENTLOOP_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqsocketnotifier.h"
+#endif // TQT_H
+
+class TQEventLoopPrivate;
+class TQSocketNotifier;
+class TQTimer;
+#ifdef TQ_WS_MAC
+struct timeval; //stdc struct
+struct TimerInfo; //internal structure (qeventloop_mac.cpp)
+#endif
+
+#if defined(TQT_THREAD_SUPPORT)
+class TQMutex;
+#endif // TQT_THREAD_SUPPORT
+
+
+class TQ_EXPORT TQEventLoop : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ TQEventLoop( TQObject *tqparent = 0, const char *name = 0 );
+ ~TQEventLoop();
+
+ enum ProcessEvents {
+ AllEvents = 0x00,
+ ExcludeUserInput = 0x01,
+ ExcludeSocketNotifiers = 0x02,
+ WaitForMore = 0x04
+ };
+ typedef uint ProcessEventsFlags;
+
+ void processEvents( ProcessEventsFlags flags, int maxtime );
+ virtual bool processEvents( ProcessEventsFlags flags );
+
+ virtual bool hasPendingEvents() const;
+
+ virtual void registerSocketNotifier( TQSocketNotifier * );
+ virtual void unregisterSocketNotifier( TQSocketNotifier * );
+ void setSocketNotifierPending( TQSocketNotifier * );
+ int activateSocketNotifiers();
+
+ int activateTimers();
+ int timeToWait() const;
+
+ virtual int exec();
+ virtual void exit( int retcode = 0 );
+
+ virtual int enterLoop();
+ virtual void exitLoop();
+ virtual int loopLevel() const;
+
+ virtual void wakeUp();
+
+Q_SIGNALS:
+ void awake();
+ void aboutToBlock();
+
+private:
+#if defined(TQ_WS_MAC)
+ friend TQMAC_PASCAL void qt_mac_select_timer_callbk(EventLoopTimerRef, void *);
+ int macHandleSelect(timeval *);
+ void macHandleTimer(TimerInfo *);
+#endif // TQ_WS_MAC
+
+ // internal initialization/cleanup - implemented in various platform specific files
+ void init();
+ void cleanup();
+ virtual void appStartingUp();
+ virtual void appClosingDown();
+
+ // data for the default implementation - other implementations should not
+ // use/need this data
+ TQEventLoopPrivate *d;
+
+ friend class TQApplication;
+};
+
+#endif // TQEVENTLOOP_H
diff --git a/tqtinterface/qt4/src/kernel/tqeventloop_p.h b/tqtinterface/qt4/src/kernel/tqeventloop_p.h
new file mode 100644
index 0000000..92ef2f1
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqeventloop_p.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Definition of TQEventLoop class
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQEVENTLOOP_P_H
+#define TQEVENTLOOP_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. This header file may
+// change from version to version without notice, or even be
+// removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#include "tqplatformdefs.h"
+#endif // TQT_H
+
+// SCO OpenServer redefines raise -> kill
+#if defined(raise)
+# undef raise
+#endif
+
+#include "tqwindowdefs.h"
+
+class TQSocketNotifier;
+#ifdef TQ_OS_MAC
+class TQMacSockNotPrivate;
+#endif
+
+#if defined(TQ_OS_UNIX) || defined (TQ_WS_WIN)
+#include "tqptrlist.h"
+#endif // TQ_OS_UNIX || TQ_WS_WIN
+
+#if defined(TQ_OS_UNIX)
+struct TQSockNot
+{
+ TQSocketNotifier *obj;
+ int fd;
+ fd_set *queue;
+};
+
+class TQSockNotType
+{
+public:
+ TQSockNotType();
+ ~TQSockNotType();
+
+ TQPtrList<TQSockNot> *list;
+ fd_set select_fds;
+ fd_set enabled_fds;
+ fd_set pending_fds;
+
+};
+#endif // TQ_OS_UNIX
+
+#if defined(TQ_WS_WIN)
+struct TQSockNot {
+ TQSocketNotifier *obj;
+ int fd;
+};
+#endif // TQ_WS_WIN
+
+class TQEventLoopPrivate
+{
+public:
+ TQEventLoopPrivate()
+ {
+ reset();
+ }
+
+ void reset() {
+ looplevel = 0;
+ quitcode = 0;
+ quitnow = FALSE;
+ exitloop = FALSE;
+ shortcut = FALSE;
+ }
+
+ int looplevel;
+ int quitcode;
+ unsigned int quitnow : 1;
+ unsigned int exitloop : 1;
+ unsigned int shortcut : 1;
+
+#if defined(TQ_WS_MAC)
+ uchar next_select_timer;
+ EventLoopTimerRef select_timer;
+#endif
+
+#if defined(TQ_WS_X11)
+ int xfd;
+#endif // TQ_WS_X11
+
+#if defined(TQ_OS_UNIX)
+ int thread_pipe[2];
+
+ // pending socket notifiers list
+ TQPtrList<TQSockNot> sn_pending_list;
+ // highest fd for all socket notifiers
+ int sn_highest;
+ // 3 socket notifier types - read, write and exception
+ TQSockNotType sn_vec[3];
+#endif
+
+#ifdef TQ_WS_WIN
+ // pending socket notifiers list
+ TQPtrList<TQSockNot> sn_pending_list;
+#endif // TQ_WS_WIN
+
+};
+
+#endif // TQEVENTLOOP_P_H
diff --git a/tqtinterface/qt4/src/kernel/tqeventloop_unix.cpp b/tqtinterface/qt4/src/kernel/tqeventloop_unix.cpp
new file mode 100644
index 0000000..a865978
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqeventloop_unix.cpp
@@ -0,0 +1,587 @@
+/****************************************************************************
+**
+** Implementation of TQEventLoop class
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqeventloop_p.h" // includes qplatformdefs.h
+#include "tqeventloop.h"
+#include "tqapplication.h"
+#include "tqbitarray.h"
+#include <stdlib.h>
+#include <sys/types.h>
+
+
+/*****************************************************************************
+ Timer handling; UNIX has no application timer support so we'll have to
+ make our own from scratch.
+
+ NOTE: These functions are for internal use. TQObject::startTimer() and
+ TQObject::killTimer() are for public use.
+ The TQTimer class provides a high-level interface which translates
+ timer events into Q_SIGNALS.
+
+ qStartTimer( interval, obj )
+ Starts a timer which will run until it is killed with qKillTimer()
+ Arguments:
+ int interval timer interval in milliseconds
+ TQObject *obj where to send the timer event
+ Returns:
+ int timer identifier, or zero if not successful
+
+ qKillTimer( timerId )
+ Stops a timer specified by a timer identifier.
+ Arguments:
+ int timerId timer identifier
+ Returns:
+ bool TRUE if successful
+
+ qKillTimer( obj )
+ Stops all timers that are sent to the specified object.
+ Arguments:
+ TQObject *obj object receiving timer events
+ Returns:
+ bool TRUE if successful
+ *****************************************************************************/
+
+//
+// Internal data structure for timers
+//
+
+struct TimerInfo { // internal timer info
+ int id; // - timer identifier
+ timeval interval; // - timer interval
+ timeval timeout; // - when to sent event
+ TQObject *obj; // - object to receive event
+};
+
+typedef TQPtrList<TimerInfo> TimerList; // list of TimerInfo structs
+
+static TQBitArray *timerBitVec; // timer bit vector
+static TimerList *timerList = 0; // timer list
+
+static void initTimers();
+void cleanupTimers();
+static timeval watchtime; // watch if time is turned back
+timeval *qt_wait_timer();
+timeval *qt_wait_timer_max = 0;
+
+//
+// Internal operator functions for timevals
+//
+
+static inline bool operator<( const timeval &t1, const timeval &t2 )
+{
+ return t1.tv_sec < t2.tv_sec ||
+ (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec);
+}
+
+static inline bool operator==( const timeval &t1, const timeval &t2 )
+{
+ return t1.tv_sec == t2.tv_sec && t1.tv_usec == t2.tv_usec;
+}
+
+static inline timeval &operator+=( timeval &t1, const timeval &t2 )
+{
+ t1.tv_sec += t2.tv_sec;
+ if ( (t1.tv_usec += t2.tv_usec) >= 1000000 ) {
+ t1.tv_sec++;
+ t1.tv_usec -= 1000000;
+ }
+ return t1;
+}
+
+static inline timeval operator+( const timeval &t1, const timeval &t2 )
+{
+ timeval tmp;
+ tmp.tv_sec = t1.tv_sec + t2.tv_sec;
+ if ( (tmp.tv_usec = t1.tv_usec + t2.tv_usec) >= 1000000 ) {
+ tmp.tv_sec++;
+ tmp.tv_usec -= 1000000;
+ }
+ return tmp;
+}
+
+static inline timeval operator-( const timeval &t1, const timeval &t2 )
+{
+ timeval tmp;
+ tmp.tv_sec = t1.tv_sec - t2.tv_sec;
+ if ( (tmp.tv_usec = t1.tv_usec - t2.tv_usec) < 0 ) {
+ tmp.tv_sec--;
+ tmp.tv_usec += 1000000;
+ }
+ return tmp;
+}
+
+
+//
+// Internal functions for manipulating timer data structures.
+// The timerBitVec array is used for keeping track of timer identifiers.
+//
+
+static int allocTimerId() // tqfind avail timer identifier
+{
+ int i = timerBitVec->size()-1;
+ while ( i >= 0 && (*timerBitVec)[i] )
+ i--;
+ if ( i < 0 ) {
+ i = timerBitVec->size();
+ timerBitVec->resize( 4 * i );
+ for( int j=timerBitVec->size()-1; j > i; j-- )
+ timerBitVec->clearBit( j );
+ }
+ timerBitVec->setBit( i );
+ return i+1;
+}
+
+static void insertTimer( const TimerInfo *ti ) // insert timer info into list
+{
+ TimerInfo *t = timerList->first();
+ int index = 0;
+#if defined(TQT_DEBUG)
+ int dangerCount = 0;
+#endif
+ while ( t && t->timeout < ti->timeout ) { // list is sorted by timeout
+#if defined(TQT_DEBUG)
+ if ( t->obj == ti->obj )
+ dangerCount++;
+#endif
+ t = timerList->next();
+ index++;
+ }
+ timerList->insert( index, ti ); // inserts sorted
+#if defined(TQT_DEBUG)
+ if ( dangerCount > 16 )
+ qDebug( "TQObject: %d timers now exist for object %s::%s",
+ dangerCount, ti->obj->className(), ti->obj->name() );
+#endif
+}
+
+static inline void getTime( timeval &t ) // get time of day
+{
+ gettimeofday( &t, 0 );
+ while ( t.tv_usec >= 1000000 ) { // NTP-related fix
+ t.tv_usec -= 1000000;
+ t.tv_sec++;
+ }
+ while ( t.tv_usec < 0 ) {
+ if ( t.tv_sec > 0 ) {
+ t.tv_usec += 1000000;
+ t.tv_sec--;
+ } else {
+ t.tv_usec = 0;
+ break;
+ }
+ }
+}
+
+static void repairTimer( const timeval &time ) // repair broken timer
+{
+ timeval diff = watchtime - time;
+ register TimerInfo *t = timerList->first();
+ while ( t ) { // repair all timers
+ t->timeout = t->timeout - diff;
+ t = timerList->next();
+ }
+}
+
+//
+// Timer activation functions (called from the event loop)
+//
+
+/*
+ Returns the time to wait for the next timer, or null if no timers are
+ waiting.
+
+ The result is bounded to qt_wait_timer_max if this exists.
+*/
+
+timeval *qt_wait_timer()
+{
+ static timeval tm;
+ bool first = TRUE;
+ timeval currentTime;
+ if ( timerList && timerList->count() ) { // there are waiting timers
+ getTime( currentTime );
+ if ( first ) {
+ if ( currentTime < watchtime ) // clock was turned back
+ repairTimer( currentTime );
+ first = FALSE;
+ watchtime = currentTime;
+ }
+ TimerInfo *t = timerList->first(); // first waiting timer
+ if ( currentTime < t->timeout ) { // time to wait
+ tm = t->timeout - currentTime;
+ } else {
+ tm.tv_sec = 0; // no time to wait
+ tm.tv_usec = 0;
+ }
+ if ( qt_wait_timer_max && *qt_wait_timer_max < tm )
+ tm = *qt_wait_timer_max;
+ return &tm;
+ }
+ if ( qt_wait_timer_max ) {
+ tm = *qt_wait_timer_max;
+ return &tm;
+ }
+ return 0; // no timers
+}
+
+// Timer initialization
+static void initTimers() // initialize timers
+{
+ timerBitVec = new TQBitArray( 128 );
+ TQ_CHECK_PTR( timerBitVec );
+ int i = timerBitVec->size();
+ while( i-- > 0 )
+ timerBitVec->clearBit( i );
+ timerList = new TimerList;
+ TQ_CHECK_PTR( timerList );
+ timerList->setAutoDelete( TRUE );
+ gettimeofday( &watchtime, 0 );
+}
+
+// Timer cleanup
+void cleanupTimers()
+{
+ delete timerList;
+ timerList = 0;
+ delete timerBitVec;
+ timerBitVec = 0;
+}
+
+// Main timer functions for starting and killing timers
+int qStartTimer( int interval, TQObject *obj )
+{
+ if ( !timerList ) // initialize timer data
+ initTimers();
+ int id = allocTimerId(); // get free timer id
+ if ( id <= 0 ||
+ id > (int)timerBitVec->size() || !obj )// cannot create timer
+ return 0;
+ timerBitVec->setBit( id-1 ); // set timer active
+ TimerInfo *t = new TimerInfo; // create timer
+ TQ_CHECK_PTR( t );
+ t->id = id;
+ t->interval.tv_sec = interval/1000;
+ t->interval.tv_usec = (interval%1000)*1000;
+ timeval currentTime;
+ getTime( currentTime );
+ t->timeout = currentTime + t->interval;
+ t->obj = obj;
+ insertTimer( t ); // put timer in list
+ return id;
+}
+
+bool qKillTimer( int id )
+{
+ register TimerInfo *t;
+ if ( !timerList || id <= 0 ||
+ id > (int)timerBitVec->size() || !timerBitVec->testBit( id-1 ) )
+ return FALSE; // not init'd or invalid timer
+ t = timerList->first();
+ while ( t && t->id != id ) // tqfind timer info in list
+ t = timerList->next();
+ if ( t ) { // id found
+ timerBitVec->clearBit( id-1 ); // set timer inactive
+ return timerList->remove();
+ }
+ else // id not found
+ return FALSE;
+}
+
+bool qKillTimer( TQObject *obj )
+{
+ register TimerInfo *t;
+ if ( !timerList ) // not initialized
+ return FALSE;
+ t = timerList->first();
+ while ( t ) { // check all timers
+ if ( t->obj == obj ) { // object found
+ timerBitVec->clearBit( t->id-1 );
+ timerList->remove();
+ t = timerList->current();
+ } else {
+ t = timerList->next();
+ }
+ }
+ return TRUE;
+}
+
+/*****************************************************************************
+ Socket notifier type
+ *****************************************************************************/
+TQSockNotType::TQSockNotType()
+ : list( 0 )
+{
+ FD_ZERO( &select_fds );
+ FD_ZERO( &enabled_fds );
+ FD_ZERO( &pending_fds );
+}
+
+TQSockNotType::~TQSockNotType()
+{
+ if ( list )
+ delete list;
+ list = 0;
+}
+
+/*****************************************************************************
+ TQEventLoop implementations for UNIX
+ *****************************************************************************/
+void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier )
+{
+ int sockfd = notifier->socket();
+ int type = notifier->type();
+ if ( sockfd < 0 || sockfd >= FD_SETSIZE || type < 0 || type > 2 || notifier == 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQSocketNotifier: Internal error" );
+#endif
+ return;
+ }
+
+ TQPtrList<TQSockNot> *list = d->sn_vec[type].list;
+ fd_set *fds = &d->sn_vec[type].enabled_fds;
+ TQSockNot *sn;
+
+ if ( ! list ) {
+ // create new list, the TQSockNotType destructor will delete it for us
+ list = new TQPtrList<TQSockNot>;
+ TQ_CHECK_PTR( list );
+ list->setAutoDelete( TRUE );
+ d->sn_vec[type].list = list;
+ }
+
+ sn = new TQSockNot;
+ TQ_CHECK_PTR( sn );
+ sn->obj = notifier;
+ sn->fd = sockfd;
+ sn->queue = &d->sn_vec[type].pending_fds;
+
+ if ( list->isEmpty() ) {
+ list->insert( 0, sn );
+ } else { // sort list by fd, decreasing
+ TQSockNot *p = list->first();
+ while ( p && p->fd > sockfd )
+ p = list->next();
+#if defined(TQT_CHECK_STATE)
+ if ( p && p->fd == sockfd ) {
+ static const char *t[] = { "read", "write", "exception" };
+ qWarning( "TQSocketNotifier: Multiple socket notifiers for "
+ "same socket %d and type %s", sockfd, t[type] );
+ }
+#endif
+ if ( p )
+ list->insert( list->at(), sn );
+ else
+ list->append( sn );
+ }
+
+ FD_SET( sockfd, fds );
+ d->sn_highest = TQMAX( d->sn_highest, sockfd );
+}
+
+void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier )
+{
+ int sockfd = notifier->socket();
+ int type = notifier->type();
+ if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQSocketNotifier: Internal error" );
+#endif
+ return;
+ }
+
+ TQPtrList<TQSockNot> *list = d->sn_vec[type].list;
+ fd_set *fds = &d->sn_vec[type].enabled_fds;
+ TQSockNot *sn;
+ if ( ! list )
+ return;
+ sn = list->first();
+ while ( sn && !(sn->obj == notifier && sn->fd == sockfd) )
+ sn = list->next();
+ if ( !sn ) // not found
+ return;
+
+ FD_CLR( sockfd, fds ); // clear fd bit
+ FD_CLR( sockfd, sn->queue );
+ d->sn_pending_list.removeRef( sn ); // remove from activation list
+ list->remove(); // remove notifier found above
+
+ if ( d->sn_highest == sockfd ) { // tqfind highest fd
+ d->sn_highest = -1;
+ for ( int i=0; i<3; i++ ) {
+ if ( d->sn_vec[i].list && ! d->sn_vec[i].list->isEmpty() )
+ d->sn_highest = TQMAX( d->sn_highest, // list is fd-sorted
+ d->sn_vec[i].list->getFirst()->fd );
+ }
+ }
+}
+
+void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier )
+{
+ int sockfd = notifier->socket();
+ int type = notifier->type();
+ if ( sockfd < 0 || type < 0 || type > 2 || notifier == 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQSocketNotifier: Internal error" );
+#endif
+ return;
+ }
+
+ TQPtrList<TQSockNot> *list = d->sn_vec[type].list;
+ TQSockNot *sn;
+ if ( ! list )
+ return;
+ sn = list->first();
+ while ( sn && !(sn->obj == notifier && sn->fd == sockfd) )
+ sn = list->next();
+ if ( ! sn ) { // not found
+ return;
+ }
+
+ // We choose a random activation order to be more fair under high load.
+ // If a constant order is used and a peer early in the list can
+ // saturate the IO, it might grab our attention completely.
+ // Also, if we're using a straight list, the callback routines may
+ // delete other entries from the list before those other entries are
+ // processed.
+ if ( ! FD_ISSET( sn->fd, sn->queue ) ) {
+ d->sn_pending_list.insert( (rand() & 0xff) %
+ (d->sn_pending_list.count()+1), sn );
+ FD_SET( sn->fd, sn->queue );
+ }
+}
+
+void TQEventLoop::wakeUp()
+{
+ /*
+ Apparently, there is not consistency among different operating
+ systems on how to use FIONREAD.
+
+ FreeBSD, Linux and Solaris all expect the 3rd argument to
+ ioctl() to be an int, which is normally 32-bit even on 64-bit
+ machines.
+
+ IRIX, on the other hand, expects a size_t, which is 64-bit on
+ 64-bit machines.
+
+ So, the solution is to use size_t initialized to zero to make
+ sure all bits are set to zero, preventing underflow with the
+ FreeBSD/Linux/Solaris ioctls.
+ */
+ size_t nbytes = 0;
+ char c = 0;
+ if ( ::ioctl( d->thread_pipe[0], FIONREAD, (char*)&nbytes ) >= 0 && nbytes == 0 ) {
+ ::write( d->thread_pipe[1], &c, 1 );
+ }
+}
+
+int TQEventLoop::timeToWait() const
+{
+ timeval *tm = qt_wait_timer();
+ if ( ! tm ) // no active timers
+ return -1;
+ return (tm->tv_sec*1000) + (tm->tv_usec/1000);
+}
+
+int TQEventLoop::activateTimers()
+{
+ if ( !timerList || !timerList->count() ) // no timers
+ return 0;
+ bool first = TRUE;
+ timeval currentTime;
+ int n_act = 0, maxCount = timerList->count();
+ TimerInfo *begin = 0;
+ register TimerInfo *t;
+
+ for ( ;; ) {
+ if ( ! maxCount-- )
+ break;
+ getTime( currentTime ); // get current time
+ if ( first ) {
+ if ( currentTime < watchtime ) // clock was turned back
+ repairTimer( currentTime );
+ first = FALSE;
+ watchtime = currentTime;
+ }
+ t = timerList->first();
+ if ( !t || currentTime < t->timeout ) // no timer has expired
+ break;
+ if ( ! begin ) {
+ begin = t;
+ } else if ( begin == t ) {
+ // avoid sending the same timer multiple times
+ break;
+ } else if ( t->interval < begin->interval || t->interval == begin->interval ) {
+ begin = t;
+ }
+ timerList->take(); // unlink from list
+ t->timeout += t->interval;
+ if ( t->timeout < currentTime )
+ t->timeout = currentTime + t->interval;
+ insertTimer( t ); // relink timer
+ if ( t->interval.tv_usec > 0 || t->interval.tv_sec > 0 )
+ n_act++;
+ TQTimerEvent e( t->id );
+ TQApplication::sendEvent( t->obj, &e ); // send event
+ if ( timerList->tqfindRef( begin ) == -1 )
+ begin = 0;
+ }
+ return n_act;
+}
+
+int TQEventLoop::activateSocketNotifiers()
+{
+ if ( d->sn_pending_list.isEmpty() )
+ return 0;
+
+ // activate entries
+ int n_act = 0;
+ TQEvent event( TQEvent::SockAct );
+ TQPtrListIterator<TQSockNot> it( d->sn_pending_list );
+ TQSockNot *sn;
+ while ( (sn=it.current()) ) {
+ ++it;
+ d->sn_pending_list.removeRef( sn );
+ if ( FD_ISSET(sn->fd, sn->queue) ) {
+ FD_CLR( sn->fd, sn->queue );
+ TQApplication::sendEvent( sn->obj, &event );
+ n_act++;
+ }
+ }
+
+ return n_act;
+}
diff --git a/tqtinterface/qt4/src/kernel/tqeventloop_x11.cpp b/tqtinterface/qt4/src/kernel/tqeventloop_x11.cpp
new file mode 100644
index 0000000..2c60d10
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqeventloop_x11.cpp
@@ -0,0 +1,417 @@
+/****************************************************************************
+**
+** Implementation of TQEventLoop class
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqeventloop_p.h" // includes qplatformdefs.h
+#include "tqeventloop.h"
+#include "tqapplication.h"
+#include "tqbitarray.h"
+#include "tqcolor_p.h"
+#include "tqt_x11_p.h"
+
+#if defined(TQT_THREAD_SUPPORT)
+# include "tqmutex.h"
+#endif // TQT_THREAD_SUPPORT
+
+#include <errno.h>
+
+
+// resolve the conflict between X11's FocusIn and TQEvent::FocusIn
+#undef FocusOut
+#undef FocusIn
+
+static const int XKeyPress = KeyPress;
+static const int XKeyRelease = KeyRelease;
+#undef KeyPress
+#undef KeyRelease
+
+// from qapplication.cpp
+extern bool qt_is_gui_used;
+
+// from qeventloop_unix.cpp
+extern timeval *qt_wait_timer();
+extern void cleanupTimers();
+
+// ### this needs to go away at some point...
+typedef void (*VFPTR)();
+typedef TQValueList<VFPTR> TQVFuncList;
+void qt_install_preselect_handler( VFPTR );
+void qt_remove_preselect_handler( VFPTR );
+static TQVFuncList *qt_preselect_handler = 0;
+void qt_install_postselect_handler( VFPTR );
+void qt_remove_postselect_handler( VFPTR );
+static TQVFuncList *qt_postselect_handler = 0;
+
+void qt_install_preselect_handler( VFPTR handler )
+{
+ if ( !qt_preselect_handler )
+ qt_preselect_handler = new TQVFuncList;
+ qt_preselect_handler->append( handler );
+}
+void qt_remove_preselect_handler( VFPTR handler )
+{
+ if ( qt_preselect_handler ) {
+ TQVFuncList::Iterator it = qt_preselect_handler->tqfind( handler );
+ if ( it != qt_preselect_handler->end() )
+ qt_preselect_handler->remove( it );
+ }
+}
+void qt_install_postselect_handler( VFPTR handler )
+{
+ if ( !qt_postselect_handler )
+ qt_postselect_handler = new TQVFuncList;
+ qt_postselect_handler->prepend( handler );
+}
+void qt_remove_postselect_handler( VFPTR handler )
+{
+ if ( qt_postselect_handler ) {
+ TQVFuncList::Iterator it = qt_postselect_handler->tqfind( handler );
+ if ( it != qt_postselect_handler->end() )
+ qt_postselect_handler->remove( it );
+ }
+}
+
+
+void TQEventLoop::init()
+{
+ // initialize the common parts of the event loop
+ pipe( d->thread_pipe );
+ fcntl(d->thread_pipe[0], F_SETFD, FD_CLOEXEC);
+ fcntl(d->thread_pipe[1], F_SETFD, FD_CLOEXEC);
+
+ d->sn_highest = -1;
+
+ // intitialize the X11 parts of the event loop
+ d->xfd = -1;
+ if ( qt_is_gui_used )
+ d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() );
+}
+
+void TQEventLoop::cleanup()
+{
+ // cleanup the common parts of the event loop
+ close( d->thread_pipe[0] );
+ close( d->thread_pipe[1] );
+ cleanupTimers();
+
+ // cleanup the X11 parts of the event loop
+ d->xfd = -1;
+}
+
+bool TQEventLoop::processEvents( ProcessEventsFlags flags )
+{
+ // process events from the X server
+ XEvent event;
+ int nevents = 0;
+
+#if defined(TQT_THREAD_SUPPORT)
+ TQMutexLocker locker( TQApplication::qt_mutex );
+#endif
+
+ // handle gui and posted events
+ if ( qt_is_gui_used ) {
+ TQApplication::sendPostedEvents();
+
+ // Two loops so that posted events accumulate
+ while ( XPending( TQPaintDevice::x11AppDisplay() ) ) {
+ // also flushes output buffer
+ while ( XPending( TQPaintDevice::x11AppDisplay() ) ) {
+ if ( d->shortcut ) {
+ return FALSE;
+ }
+
+ XNextEvent( TQPaintDevice::x11AppDisplay(), &event );
+
+ if ( flags & ExcludeUserInput ) {
+ switch ( event.type ) {
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ case XKeyPress:
+ case XKeyRelease:
+ case EnterNotify:
+ case LeaveNotify:
+ continue;
+
+ case ClientMessage:
+ {
+ // from qapplication_x11.cpp
+ extern Atom qt_wm_protocols;
+ extern Atom qt_wm_take_focus;
+ extern Atom qt_qt_scrolldone;
+
+ // only keep the wm_take_focus and
+ // qt_qt_scrolldone protocols, discard all
+ // other client messages
+ if ( event.xclient.format != 32 )
+ continue;
+
+ if ( event.xclient.message_type == qt_wm_protocols ||
+ (Atom) event.xclient.data.l[0] == qt_wm_take_focus )
+ break;
+ if ( event.xclient.message_type == qt_qt_scrolldone )
+ break;
+ }
+
+ default: break;
+ }
+ }
+
+ nevents++;
+ if ( tqApp->x11ProcessEvent( &event ) == 1 )
+ return TRUE;
+ }
+ }
+ }
+
+ if ( d->shortcut ) {
+ return FALSE;
+ }
+
+ TQApplication::sendPostedEvents();
+
+ const uint exclude_all = ExcludeSocketNotifiers | 0x08;
+ // 0x08 == ExcludeTimers for X11 only
+ if ( nevents > 0 && ( flags & exclude_all ) == exclude_all &&
+ ( flags & WaitForMore ) ) {
+ return TRUE;
+ }
+
+ // don't block if exitLoop() or exit()/quit() has been called.
+ bool canWait = d->exitloop || d->quitnow ? FALSE : (flags & WaitForMore);
+
+ // Process timers and socket notifiers - the common UNIX stuff
+
+ // return the maximum time we can wait for an event.
+ static timeval zerotm;
+ timeval *tm = 0;
+ if ( ! ( flags & 0x08 ) ) { // 0x08 == ExcludeTimers for X11 only
+ tm = qt_wait_timer(); // wait for timer or X event
+ if ( !canWait ) {
+ if ( !tm )
+ tm = &zerotm;
+ tm->tv_sec = 0; // no time to wait
+ tm->tv_usec = 0;
+ }
+ }
+
+ int highest = 0;
+ if ( ! ( flags & ExcludeSocketNotifiers ) ) {
+ // return the highest fd we can wait for input on
+ if ( d->sn_highest >= 0 ) { // has socket notifier(s)
+ if ( d->sn_vec[0].list && ! d->sn_vec[0].list->isEmpty() )
+ d->sn_vec[0].select_fds = d->sn_vec[0].enabled_fds;
+ else
+ FD_ZERO( &d->sn_vec[0].select_fds );
+
+ if ( d->sn_vec[1].list && ! d->sn_vec[1].list->isEmpty() )
+ d->sn_vec[1].select_fds = d->sn_vec[1].enabled_fds;
+ else
+ FD_ZERO( &d->sn_vec[1].select_fds );
+
+ if ( d->sn_vec[2].list && ! d->sn_vec[2].list->isEmpty() )
+ d->sn_vec[2].select_fds = d->sn_vec[2].enabled_fds;
+ else
+ FD_ZERO( &d->sn_vec[2].select_fds );
+ } else {
+ FD_ZERO( &d->sn_vec[0].select_fds );
+
+ FD_ZERO( &d->sn_vec[1].select_fds );
+ FD_ZERO( &d->sn_vec[2].select_fds );
+ }
+
+ highest = d->sn_highest;
+ } else {
+ FD_ZERO( &d->sn_vec[0].select_fds );
+ FD_ZERO( &d->sn_vec[1].select_fds );
+ FD_ZERO( &d->sn_vec[2].select_fds );
+ }
+
+ if ( qt_is_gui_used ) {
+ // select for events on the event socket - only on X11
+ FD_SET( d->xfd, &d->sn_vec[0].select_fds );
+ highest = TQMAX( highest, d->xfd );
+ }
+
+ FD_SET( d->thread_pipe[0], &d->sn_vec[0].select_fds );
+ highest = TQMAX( highest, d->thread_pipe[0] );
+
+ if ( canWait )
+ emit aboutToBlock();
+
+ if ( qt_preselect_handler ) {
+ TQVFuncList::Iterator it, end = qt_preselect_handler->end();
+ for ( it = qt_preselect_handler->begin(); it != end; ++it )
+ (**it)();
+ }
+
+ // unlock the GUI mutex and select. when we return from this function, there is
+ // something for us to do
+#if defined(TQT_THREAD_SUPPORT)
+ locker.mutex()->unlock();
+#endif
+
+ int nsel;
+ do {
+ nsel = select( highest + 1,
+ &d->sn_vec[0].select_fds,
+ &d->sn_vec[1].select_fds,
+ &d->sn_vec[2].select_fds,
+ tm );
+ } while (nsel == -1 && (errno == EINTR || errno == EAGAIN));
+
+ // relock the GUI mutex before processing any pending events
+#if defined(TQT_THREAD_SUPPORT)
+ locker.mutex()->lock();
+#endif
+
+ // we are awake, broadcast it
+ emit awake();
+ emit tqApp->guiThreadAwake();
+
+ if (nsel == -1) {
+ if (errno == EBADF) {
+ // it seems a socket notifier has a bad fd... tqfind out
+ // which one it is and disable it
+ fd_set fdset;
+ zerotm.tv_sec = zerotm.tv_usec = 0l;
+
+ for (int type = 0; type < 3; ++type) {
+ TQPtrList<TQSockNot> *list = d->sn_vec[type].list;
+ if (!list) continue;
+
+ TQSockNot *sn = list->first();
+ while (sn) {
+ FD_ZERO(&fdset);
+ FD_SET(sn->fd, &fdset);
+
+ int ret = -1;
+ do {
+ switch (type) {
+ case 0: // read
+ ret = select(sn->fd + 1, &fdset, 0, 0, &zerotm);
+ break;
+ case 1: // write
+ ret = select(sn->fd + 1, 0, &fdset, 0, &zerotm);
+ break;
+ case 2: // except
+ ret = select(sn->fd + 1, 0, 0, &fdset, &zerotm);
+ break;
+ }
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+
+ if (ret == -1 && errno == EBADF) {
+ // disable the invalid socket notifier
+ static const char *t[] = { "Read", "Write", "Exception" };
+ qWarning("TQSocketNotifier: invalid socket %d and type '%s', disabling...",
+ sn->fd, t[type]);
+ sn->obj->setEnabled(FALSE);
+ }
+
+ sn = list->next();
+ }
+ }
+ } else {
+ // EINVAL... shouldn't happen, so let's complain to stderr
+ // and hope someone sends us a bug report
+ perror( "select" );
+ }
+ }
+
+ // some other thread woke us up... consume the data on the thread pipe so that
+ // select doesn't immediately return next time
+ if ( nsel > 0 && FD_ISSET( d->thread_pipe[0], &d->sn_vec[0].select_fds ) ) {
+ char c;
+ ::read( d->thread_pipe[0], &c, 1 );
+ }
+
+ if ( qt_postselect_handler ) {
+ TQVFuncList::Iterator it, end = qt_postselect_handler->end();
+ for ( it = qt_postselect_handler->begin(); it != end; ++it )
+ (**it)();
+ }
+
+ // activate socket notifiers
+ if ( ! ( flags & ExcludeSocketNotifiers ) && nsel > 0 && d->sn_highest >= 0 ) {
+ // if select says data is ready on any socket, then set the socket notifier
+ // to pending
+ int i;
+ for ( i=0; i<3; i++ ) {
+ if ( ! d->sn_vec[i].list )
+ continue;
+
+ TQPtrList<TQSockNot> *list = d->sn_vec[i].list;
+ TQSockNot *sn = list->first();
+ while ( sn ) {
+ if ( FD_ISSET( sn->fd, &d->sn_vec[i].select_fds ) )
+ setSocketNotifierPending( sn->obj );
+ sn = list->next();
+ }
+ }
+
+ nevents += activateSocketNotifiers();
+ }
+
+ // activate timers
+ if ( ! ( flags & 0x08 ) ) {
+ // 0x08 == ExcludeTimers for X11 only
+ nevents += activateTimers();
+ }
+
+ // color approx. optimization - only on X11
+ qt_reset_color_avail();
+
+ // return true if we handled events, false otherwise
+ return (nevents > 0);
+}
+
+bool TQEventLoop::hasPendingEvents() const
+{
+ extern uint qGlobalPostedEventsCount(); // from qapplication.cpp
+ return ( qGlobalPostedEventsCount() || XPending( TQPaintDevice::x11AppDisplay() ) );
+}
+
+void TQEventLoop::appStartingUp()
+{
+ if ( qt_is_gui_used )
+ d->xfd = XConnectionNumber( TQPaintDevice::x11AppDisplay() );
+}
+
+void TQEventLoop::appClosingDown()
+{
+ d->xfd = -1;
+}
diff --git a/tqtinterface/qt4/src/kernel/tqfocusdata.cpp b/tqtinterface/qt4/src/kernel/tqfocusdata.cpp
new file mode 100644
index 0000000..0259940
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfocusdata.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Implementation of TQFocusData class
+**
+** Created : 980622
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqfocusdata.h"
+
+/*!
+ \class TQFocusData tqfocusdata.h
+ \brief The TQFocusData class maintains the list of widgets in the focus
+ chain.
+
+ \ingroup misc
+
+ This read-only list always tqcontains at least one widget (i.e. the
+ top-level widget). It provides a simple cursor which can be reset
+ to the current focus widget using home(), or moved to its
+ neighboring widgets using next() and prev(). You can also retrieve
+ the count() of the number of widgets in the list. The list is a
+ loop, so if you keep iterating, for example using next(), you will
+ never come to the end.
+
+ Some widgets in the list may not accept focus. Widgets are added
+ to the list as necessary, but not removed from it. This lets
+ widgets change focus policy dynamically without disrupting the
+ focus chain the user experiences. When a widget disables and
+ re-enables tab focus, its position in the focus chain does not
+ change.
+
+ When reimplementing TQWidget::focusNextPrevChild() to provide
+ special focus flow, you will usually call TQWidget::focusData() to
+ retrieve the focus data stored at the top-level widget. A
+ top-level widget's focus data tqcontains the focus list for its
+ hierarchy of widgets.
+
+ The cursor may change at any time.
+
+ This class is \e not thread-safe.
+
+ \sa TQWidget::focusNextPrevChild() TQWidget::setTabOrder()
+ TQWidget::setFocusPolicy()
+*/
+
+/*!
+ \fn TQWidget* TQFocusData::tqfocusWidget() const
+
+ Returns the widgets in the hierarchy that are in the focus chain.
+*/
+
+/*!
+ \fn int TQFocusData::count() const
+
+ Returns the number of widgets in the focus chain.
+*/
+
+/*!
+ Moves the cursor to the tqfocusWidget() and returns that widget. You
+ must call this before next() or prev() to iterate meaningfully.
+*/
+TQWidget* TQFocusData::home()
+{
+ tqfocusWidgets.tqfind(it.current());
+ return tqfocusWidgets.current();
+}
+
+/*!
+ Moves the cursor to the next widget in the focus chain. There is
+ \e always a next widget because the list is a loop.
+*/
+TQWidget* TQFocusData::next()
+{
+ TQWidget* r = tqfocusWidgets.next();
+ if ( !r )
+ r = tqfocusWidgets.first();
+ return r;
+}
+
+/*!
+ Moves the cursor to the previous widget in the focus chain. There
+ is \e always a previous widget because the list is a loop.
+*/
+TQWidget* TQFocusData::prev()
+{
+ TQWidget* r = tqfocusWidgets.prev();
+ if ( !r )
+ r = tqfocusWidgets.last();
+ return r;
+}
+
+/*!
+ Returns the last widget in the focus chain.
+ The cursor is not modified.
+*/
+TQWidget *TQFocusData::last() const
+{
+ return tqfocusWidgets.getLast();
+}
+
+/*!
+ Returns the first widget in the focus chain.
+ The cursor is not modified.
+*/
+TQWidget *TQFocusData::first() const
+{
+ return tqfocusWidgets.getFirst();
+}
diff --git a/tqtinterface/qt4/src/kernel/tqfocusdata.h b/tqtinterface/qt4/src/kernel/tqfocusdata.h
new file mode 100644
index 0000000..c4f4c90
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfocusdata.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Definition of internal TQFocusData class
+**
+** Created : 980405
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQFOCUSDATA_H
+#define TQFOCUSDATA_H
+
+#ifndef TQT_H
+#include "tqwidgetlist.h"
+#endif // TQT_H
+
+
+class TQ_EXPORT TQFocusData {
+public:
+ TQWidget* tqfocusWidget() const { return it.current(); }
+
+ TQWidget* home();
+ TQWidget* next();
+ TQWidget* prev();
+ TQWidget* first() const;
+ TQWidget* last() const;
+ int count() const { return tqfocusWidgets.count(); }
+
+private:
+ friend class TQWidget;
+
+ TQFocusData()
+ : it(tqfocusWidgets) {}
+ TQWidgetList tqfocusWidgets;
+ TQWidgetListIt it;
+};
+
+
+#endif // TQFOCUSDATA_H
diff --git a/tqtinterface/qt4/src/kernel/tqfont.cpp b/tqtinterface/qt4/src/kernel/tqfont.cpp
new file mode 100644
index 0000000..48fe5a0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfont.cpp
@@ -0,0 +1,3376 @@
+/****************************************************************************
+**
+** Implementation of TQFont, TQFontMetrics and TQFontInfo classes
+**
+** Created : 941207
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+#ifdef USE_QT4
+// Nasty, nasty horrid HACK to get access to QFont's private members
+// This is TERRIBLE and I wish there was a way around it
+// See also QRect
+#define private protected
+#include <Qt/qfont.h>
+#undef private
+#endif // USE_QT4
+
+#define TQT_FATAL_ASSERT
+
+#include "tqfont.h"
+#include "tqfontdatabase.h"
+#include "tqfontmetrics.h"
+#include "tqfontinfo.h"
+#include "tqpainter.h"
+#include "tqdict.h"
+#include "tqcache.h"
+#include "tqdatastream.h"
+#include "tqapplication.h"
+#include "tqcleanuphandler.h"
+#include "tqstringlist.h"
+#ifdef TQ_WS_MAC
+#include "tqpaintdevicemetrics.h"
+#endif
+
+#include <private/tqunicodetables_p.h>
+#include "tqfontdata_p.h"
+#include "tqfontengine_p.h"
+#include "tqpainter_p.h"
+#include "tqtextengine_p.h"
+
+// #define TQFONTCACHE_DEBUG
+#ifdef TQFONTCACHE_DEBUG
+# define FC_DEBUG qDebug
+#else
+# define FC_DEBUG if (FALSE) qDebug
+#endif
+
+#ifdef USE_QT4
+
+void TQFont::tqt_x11SetScreen( int screen ) {
+ x11SetScreen(screen);
+}
+int TQFont::tqt_x11Screen() const {
+ return x11Screen();
+}
+
+#else // USE_QT4
+
+bool TQFontDef::operator==( const TQFontDef &other ) const
+{
+ /*
+ TQFontDef comparison is more complicated than just simple
+ per-member comparisons.
+
+ When comparing point/pixel sizes, either point or pixelsize
+ could be -1. in This case we have to compare the non negative
+ size value.
+
+ This test will fail if the point-sizes differ by 1/2 point or
+ more or they do not round to the same value. We have to do this
+ since our API still uses 'int' point-sizes in the API, but store
+ deci-point-sizes internally.
+
+ To compare the family members, we need to parse the font names
+ and compare the family/foundry strings separately. This allows
+ us to compare e.g. "Helvetica" and "Helvetica [Adobe]" with
+ positive results.
+ */
+ if (pixelSize != -1 && other.pixelSize != -1) {
+ if (pixelSize != other.pixelSize)
+ return FALSE;
+ } else if (pointSize != -1 && other.pointSize != -1) {
+ if (pointSize != other.pointSize
+ && (TQABS(pointSize - other.pointSize) >= 5
+ || tqRound(pointSize/10.) != tqRound(other.pointSize/10.)))
+ return FALSE;
+ } else {
+ return FALSE;
+ }
+
+ if (!ignorePitch && !other.ignorePitch && fixedPitch != other.fixedPitch)
+ return FALSE;
+
+ if (stretch != 0 && other.stretch != 0 && stretch != other.stretch)
+ return FALSE;
+
+ TQString this_family, this_foundry, other_family, other_foundry;
+ TQFontDatabase::parseFontName(family, this_foundry, this_family);
+ TQFontDatabase::parseFontName(other.family, other_foundry, other_family);
+
+ return ( tqstyleHint == other.tqstyleHint
+ && styleStrategy == other.styleStrategy
+ && weight == other.weight
+ && italic == other.italic
+ && this_family == other_family
+ && (this_foundry.isEmpty()
+ || other_foundry.isEmpty()
+ || this_foundry == other_foundry)
+#ifdef TQ_WS_X11
+ && addStyle == other.addStyle
+#endif // TQ_WS_X11
+ );
+}
+
+
+
+
+TQFontPrivate::TQFontPrivate()
+ : engineData( 0 ), painttqdevice( 0 ),
+ rawMode( FALSE ), underline( FALSE ), overline( FALSE ), strikeOut( FALSE ),
+ tqmask( 0 )
+{
+#ifdef TQ_WS_X11
+ screen = TQPaintDevice::x11AppScreen();
+#else
+ screen = 0;
+#endif // TQ_WS_X11
+}
+
+TQFontPrivate::TQFontPrivate( const TQFontPrivate &other )
+ : TQShared(), request( other.request ), engineData( 0 ),
+ painttqdevice( other.painttqdevice ), screen( other.screen ),
+ rawMode( other.rawMode ), underline( other.underline ), overline( other.overline ),
+ strikeOut( other.strikeOut ), tqmask( other.tqmask )
+{
+}
+
+TQFontPrivate::~TQFontPrivate()
+{
+ if ( engineData )
+ engineData->deref();
+ engineData = 0;
+}
+
+void TQFontPrivate::resolve( const TQFontPrivate *other )
+{
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( other != 0 );
+#endif
+
+ if ( ( tqmask & Complete ) == Complete ) return;
+
+ // assign the unset-bits with the set-bits of the other font def
+ if ( ! ( tqmask & Family ) )
+ request.family = other->request.family;
+
+ if ( ! ( tqmask & Size ) ) {
+ request.pointSize = other->request.pointSize;
+ request.pixelSize = other->request.pixelSize;
+ }
+
+ if ( ! ( tqmask & StyleHint ) )
+ request.tqstyleHint = other->request.tqstyleHint;
+
+ if ( ! ( tqmask & StyleStrategy ) )
+ request.styleStrategy = other->request.styleStrategy;
+
+ if ( ! ( tqmask & Weight ) )
+ request.weight = other->request.weight;
+
+ if ( ! ( tqmask & Italic ) )
+ request.italic = other->request.italic;
+
+ if ( ! ( tqmask & FixedPitch ) )
+ request.fixedPitch = other->request.fixedPitch;
+
+ if ( ! ( tqmask & Stretch ) )
+ request.stretch = other->request.stretch;
+
+ if ( ! ( tqmask & Underline ) )
+ underline = other->underline;
+
+ if ( ! ( tqmask & Overline ) )
+ overline = other->overline;
+
+ if ( ! ( tqmask & StrikeOut ) )
+ strikeOut = other->strikeOut;
+}
+
+
+
+
+TQFontEngineData::TQFontEngineData()
+ : lineWidth( 1 )
+{
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+ memset( engines, 0, TQFont::LastPrivateScript * sizeof( TQFontEngine * ) );
+#else
+ engine = 0;
+#endif // TQ_WS_X11 || TQ_WS_WIN
+#ifndef TQ_WS_MAC
+ memset( widthCache, 0, widthCacheSize*sizeof( uchar ) );
+#endif
+}
+
+TQFontEngineData::~TQFontEngineData()
+{
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+ for ( int i = 0; i < TQFont::LastPrivateScript; i++ ) {
+ if ( engines[i] )
+ engines[i]->deref();
+ engines[i] = 0;
+ }
+#else
+ if ( engine )
+ engine->deref();
+ engine = 0;
+#endif // TQ_WS_X11 || TQ_WS_WIN
+}
+
+
+
+
+/*!
+ \class TQFont tqfont.h
+ \brief The TQFont class specifies a font used for drawing text.
+
+ \ingroup graphics
+ \ingroup appearance
+ \ingroup shared
+ \mainclass
+
+ When you create a TQFont object you specify various attributes that
+ you want the font to have. TQt will use the font with the specified
+ attributes, or if no matching font exists, TQt will use the closest
+ matching installed font. The attributes of the font that is
+ actually used are retrievable from a TQFontInfo object. If the
+ window system provides an exact match exactMatch() returns TRUE.
+ Use TQFontMetrics to get measurements, e.g. the pixel length of a
+ string using TQFontMetrics::width().
+
+ Use TQApplication::setFont() to set the application's default font.
+
+ If a choosen X11 font does not include all the characters that
+ need to be displayed, TQFont will try to tqfind the characters in the
+ nearest equivalent fonts. When a TQPainter draws a character from a
+ font the TQFont will report whether or not it has the character; if
+ it does not, TQPainter will draw an unfilled square.
+
+ Create TQFonts like this:
+ \code
+ TQFont serifFont( "Times", 10, Bold );
+ TQFont sansFont( "Helvetica [Cronyx]", 12 );
+ \endcode
+
+ The attributes set in the constructor can also be set later, e.g.
+ setFamily(), setPointSize(), setPointSizeFloat(), setWeight() and
+ setItalic(). The remaining attributes must be set after
+ contstruction, e.g. setBold(), setUnderline(), setOverline(),
+ setStrikeOut() and setFixedPitch(). TQFontInfo objects should be
+ created \e after the font's attributes have been set. A TQFontInfo
+ object will not change, even if you change the font's
+ attributes. The corresponding "get" functions, e.g. family(),
+ pointSize(), etc., return the values that were set, even though
+ the values used may differ. The actual values are available from a
+ TQFontInfo object.
+
+ If the requested font family is unavailable you can influence the
+ \link #fontmatching font matching algorithm\endlink by choosing a
+ particular \l{TQFont::StyleHint} and \l{TQFont::StyleStrategy} with
+ setStyleHint(). The default family (corresponding to the current
+ style hint) is returned by defaultFamily().
+
+ The font-matching algorithm has a lastResortFamily() and
+ lastResortFont() in cases where a suitable match cannot be found.
+ You can provide substitutions for font family names using
+ insertSubstitution() and insertSubstitutions(). Substitutions can
+ be removed with removeSubstitution(). Use substitute() to retrieve
+ a family's first substitute, or the family name itself if it has
+ no substitutes. Use substitutes() to retrieve a list of a family's
+ substitutes (which may be empty).
+
+ Every TQFont has a key() which you can use, for example, as the key
+ in a cache or dictionary. If you want to store a user's font
+ preferences you could use TQSettings, writing the font information
+ with toString() and reading it back with fromString(). The
+ operator<<() and operator>>() functions are also available, but
+ they work on a data stream.
+
+ It is possible to set the height of characters shown on the screen
+ to a specified number of pixels with setPixelSize(); however using
+ setPointSize() has a similar effect and provides tqdevice
+ independence.
+
+ Under the X Window System you can set a font using its system
+ specific name with setRawName().
+
+ Loading fonts can be expensive, especially on X11. TQFont tqcontains
+ extensive optimizations to make the copying of TQFont objects fast,
+ and to cache the results of the slow window system functions it
+ depends upon.
+
+ \target fontmatching
+ The font matching algorithm works as follows:
+ \list 1
+ \i The specified font family is searched for.
+ \i If not found, the tqstyleHint() is used to select a tqreplacement
+ family.
+ \i Each tqreplacement font family is searched for.
+ \i If none of these are found or there was no tqstyleHint(), "helvetica"
+ will be searched for.
+ \i If "helvetica" isn't found TQt will try the lastResortFamily().
+ \i If the lastResortFamily() isn't found TQt will try the
+ lastResortFont() which will always return a name of some kind.
+ \endlist
+
+ Once a font is found, the remaining attributes are matched in order of
+ priority:
+ \list 1
+ \i fixedPitch()
+ \i pointSize() (see below)
+ \i weight()
+ \i italic()
+ \endlist
+
+ If you have a font which matches on family, even if none of the
+ other attributes match, this font will be chosen in preference to
+ a font which doesn't match on family but which does match on the
+ other attributes. This is because font family is the dominant
+ search criteria.
+
+ The point size is defined to match if it is within 20% of the
+ requested point size. When several fonts match and are only
+ distinguished by point size, the font with the closest point size
+ to the one requested will be chosen.
+
+ The actual family, font size, weight and other font attributes
+ used for drawing text will depend on what's available for the
+ chosen family under the window system. A TQFontInfo object can be
+ used to determine the actual values used for drawing the text.
+
+ Examples:
+
+ \code
+ TQFont f("Helvetica");
+ \endcode
+ If you had both an Adobe and a Cronyx Helvetica, you might get
+ either.
+
+ \code
+ TQFont f1( "Helvetica [Cronyx]" ); // TQt 3.x
+ TQFont f2( "Cronyx-Helvetica" ); // TQt 2.x compatibility
+ \endcode
+ You can specify the foundry you want in the family name. Both fonts,
+ f1 and f2, in the above example will be set to "Helvetica
+ [Cronyx]".
+
+ To determine the attributes of the font actually used in the window
+ system, use a TQFontInfo object, e.g.
+ \code
+ TQFontInfo info( f1 );
+ TQString family = info.family();
+ \endcode
+
+ To tqfind out font metrics use a TQFontMetrics object, e.g.
+ \code
+ TQFontMetrics fm( f1 );
+ int pixelWidth = fm.width( "How many pixels wide is this text?" );
+ int pixelHeight = fm.height();
+ \endcode
+
+ For more general information on fonts, see the
+ \link http://www.nwalsh.com/comp.fonts/FAQ/ comp.fonts FAQ.\endlink
+ Information on encodings can be found from
+ \link http://czyborra.com/ Roman Czyborra's\endlink page.
+
+ \sa TQFontMetrics TQFontInfo TQFontDatabase TQApplication::setFont()
+ TQWidget::setFont() TQPainter::setFont() TQFont::StyleHint
+ TQFont::Weight
+*/
+
+/*!
+ \enum TQFont::Script
+
+ This enum represents \link tqunicode.html Unicode \endlink allocated
+ scripts. For exhaustive coverage see \link
+ http://www.amazon.com/exec/obidos/ASIN/0201616335/trolltech/t The
+ Unicode Standard Version 3.0 \endlink. The following scripts are
+ supported:
+
+ Modern European alphabetic scripts (left to right):
+
+ \value Latin consists of most alphabets based on the original Latin alphabet.
+ \value Greek covers ancient and modern Greek and Coptic.
+ \value Cyrillic covers the Slavic and non-Slavic languages using
+ cyrillic alphabets.
+ \value Armenian tqcontains the Armenian alphabet used with the
+ Armenian language.
+ \value Georgian covers at least the language Georgian.
+ \value Runic covers the known constituents of the Runic alphabets used
+ by the early and medieval societies in the Germanic,
+ Scandinavian, and Anglo-Saxon areas.
+ \value Ogham is an alphabetical script used to write a very early
+ form of Irish.
+ \value SpacingModifiers are small signs indicating modifications
+ to the preceeding letter.
+ \value CombiningMarks consist of diacritical marks not specific to
+ a particular alphabet, diacritical marks used in
+ combination with mathematical and technical symbols, and
+ glyph encodings applied to multiple letterforms.
+
+ Middle Eastern scripts (right to left):
+
+ \value Hebrew is used for writing Hebrew, Yiddish, and some other languages.
+ \value Arabic covers the Arabic language as well as Persian, Urdu,
+ Kurdish and some others.
+ \value Syriac is used to write the active liturgical languages and
+ dialects of several Middle Eastern and Southeast Indian
+ communities.
+ \value Thaana is used to write the Maledivian Dhivehi language.
+
+ South and Southeast Asian scripts (left to right with few historical exceptions):
+
+ \value Devanagari covers classical Sanskrit and modern Hindi as
+ well as several other languages.
+ \value Bengali is a relative to Devanagari employed to write the
+ Bengali language used in West Bengal/India and Bangladesh
+ as well as several minority languages.
+ \value Gurmukhi is another Devanagari relative used to write Punjabi.
+ \value Gujarati is closely related to Devanagari and used to write
+ the Gujarati language of the Gujarat state in India.
+ \value Oriya is used to write the Oriya language of Orissa state/India.
+ \value Tamil is used to write the Tamil language of Tamil Nadu state/India,
+ Sri Lanka, Singapore and parts of Malaysia as well as some
+ minority languages.
+ \value Telugu is used to write the Telugu language of Andhra
+ Pradesh state/India and some minority languages.
+ \value Kannada is another South Indian script used to write the
+ Kannada language of Karnataka state/India and some minority
+ languages.
+ \value Malayalam is used to write the Malayalam language of Kerala
+ state/India.
+ \value Sinhala is used for Sri Lanka's majority language Sinhala
+ and is also employed to write Pali, Sanskrit, and Tamil.
+ \value Thai is used to write Thai and other Southeast Asian languages.
+ \value Lao is a language and script quite similar to Thai.
+ \value Tibetan is the script used to write Tibetan in several
+ countries like Tibet, the bordering Indian regions and
+ Nepal. It is also used in the Buddist philosophy and
+ liturgy of the Mongolian cultural area.
+ \value Myanmar is mainly used to write the Burmese language of
+ Myanmar (former Burma).
+ \value Khmer is the official language of Kampuchea.
+
+ East Asian scripts (traditionally top-down, right to left, modern
+ often horizontal left to right):
+
+ \value Han consists of the CJK (Chinese, Japanese, Korean)
+ idiographic characters.
+ \value Hiragana is a cursive syllabary used to indicate phonetics
+ and pronounciation of Japanese words.
+ \value Katakana is a non-cursive syllabic script used to write
+ Japanese words with visual emphasis and non-Japanese words
+ in a phonetical manner.
+ \value Hangul is a Korean script consisting of alphabetic components.
+ \value Bopomofo is a phonetic alphabet for Chinese (mainly Mandarin).
+ \value Yi (also called Cuan or Wei) is a syllabary used to write
+ the Yi language of Southwestern China, Myanmar, Laos, and Vietnam.
+
+ Additional scripts that do not fit well into the script categories above:
+
+ \value Ethiopic is a syllabary used by several Central East African languages.
+ \value Cherokee is a left-to-right syllabic script used to write
+ the Cherokee language.
+ \value CanadianAboriginal consists of the syllabics used by some
+ Canadian aboriginal societies.
+ \value Mongolian is the traditional (and recently reintroduced)
+ script used to write Mongolian.
+
+ Symbols:
+
+ \value CurrencySymbols tqcontains currency symbols not encoded in other scripts.
+ \value LetterlikeSymbols consists of symbols derived from
+ ordinary letters of an alphabetical script.
+ \value NumberForms are provided for compatibility with other
+ existing character sets.
+ \value MathematicalOperators consists of encodings for operators,
+ relations and other symbols like arrows used in a mathematical context.
+ \value TechnicalSymbols tqcontains representations for control
+ codes, the space symbol, APL symbols and other symbols
+ mainly used in the context of electronic data processing.
+ \value GeometricSymbols covers block elements and geometric tqshapes.
+ \value MiscellaneousSymbols consists of a heterogeneous collection
+ of symbols that do not fit any other Unicode character
+ block, e.g. Dingbats.
+ \value EnclosedAndSquare is provided for compatibility with some
+ East Asian standards.
+ \value Braille is an international writing system used by blind
+ people. This script encodes the 256 eight-dot patterns with
+ the 64 six-dot patterns as a subset.
+
+ \value Tagalog
+ \value Hanunoo
+ \value Buhid
+ \value Tagbanwa
+
+ \value KatakanaHalfWidth
+
+ \value Limbu (Unicode 4.0)
+ \value TaiLe (Unicode 4.0)
+
+ \value Unicode includes all the above scripts.
+*/
+
+/*! \internal
+
+ Constructs a font for use on the paint tqdevice \a pd using the
+ specified font \a data.
+*/
+TQFont::TQFont( TQFontPrivate *data, TQPaintDevice *pd )
+{
+ d = new TQFontPrivate( *data );
+ TQ_CHECK_PTR( d );
+ d->painttqdevice = pd;
+
+ // now a single reference
+ d->count = 1;
+}
+
+/*! \internal
+ Detaches the font object from common font data.
+*/
+void TQFont::detach()
+{
+ if (d->count == 1) {
+ if ( d->engineData )
+ d->engineData->deref();
+ d->engineData = 0;
+
+ return;
+ }
+
+ TQFontPrivate *old_d = d;
+ d = new TQFontPrivate( *old_d );
+
+ /*
+ if this font is a copy of the application default font, set the
+ fontdef tqmask to zero to indicate that *nothing* has been
+ explicitly set by the programmer.
+ */
+ const TQFont appfont = TQApplication::font();
+ if ( old_d == appfont.d )
+ d->tqmask = 0;
+
+ if ( old_d->deref() )
+ delete old_d;
+}
+
+/*!
+ Constructs a font object that uses the application's default font.
+
+ \sa TQApplication::setFont(), TQApplication::font()
+*/
+TQFont::TQFont()
+{
+ const TQFont appfont = TQApplication::font();
+ d = appfont.d;
+ d->ref();
+}
+
+/*!
+ Constructs a font object with the specified \a family, \a
+ pointSize, \a weight and \a italic settings.
+
+ If \a pointSize is <= 0 it is set to 1.
+
+ The \a family name may optionally also include a foundry name,
+ e.g. "Helvetica [Cronyx]". (The TQt 2.x syntax, i.e.
+ "Cronyx-Helvetica", is also supported.) If the \a family is
+ available from more than one foundry and the foundry isn't
+ specified, an arbitrary foundry is chosen. If the family isn't
+ available a family will be set using the \link #fontmatching font
+ matching\endlink algorithm.
+
+ \sa Weight, setFamily(), setPointSize(), setWeight(), setItalic(),
+ setStyleHint() TQApplication::font()
+*/
+TQFont::TQFont( const TQString &family, int pointSize, int weight, bool italic )
+{
+
+ d = new TQFontPrivate;
+ TQ_CHECK_PTR( d );
+
+ d->tqmask = TQFontPrivate::Family;
+
+ if (pointSize <= 0) {
+ pointSize = 12;
+ } else {
+ d->tqmask |= TQFontPrivate::Size;
+ }
+
+ if (weight < 0) {
+ weight = Normal;
+ } else {
+ d->tqmask |= TQFontPrivate::Weight | TQFontPrivate::Italic;
+ }
+
+ d->request.family = family;
+ d->request.pointSize = pointSize * 10;
+ d->request.pixelSize = -1;
+ d->request.weight = weight;
+ d->request.italic = italic;
+}
+
+/*!
+ Constructs a font that is a copy of \a font.
+*/
+TQFont::TQFont( const TQFont &font )
+{
+ d = font.d;
+ d->ref();
+}
+
+/*!
+ Destroys the font object and frees all allocated resources.
+*/
+TQFont::~TQFont()
+{
+ if ( d->deref() )
+ delete d;
+ d = 0;
+}
+
+/*!
+ Assigns \a font to this font and returns a reference to it.
+*/
+TQFont &TQFont::operator=( const TQFont &font )
+{
+ if ( font.d != d ) {
+ if ( d->deref() )
+ delete d;
+ d = font.d;
+ d->ref();
+ }
+
+ return *this;
+}
+
+/*!
+ Returns the requested font family name, i.e. the name set in the
+ constructor or the last setFont() call.
+
+ \sa setFamily() substitutes() substitute()
+*/
+TQString TQFont::family() const
+{
+ return d->request.family;
+}
+
+/*!
+ Sets the family name of the font. The name is case insensitive and
+ may include a foundry name.
+
+ The \a family name may optionally also include a foundry name,
+ e.g. "Helvetica [Cronyx]". (The TQt 2.x syntax, i.e.
+ "Cronyx-Helvetica", is also supported.) If the \a family is
+ available from more than one foundry and the foundry isn't
+ specified, an arbitrary foundry is chosen. If the family isn't
+ available a family will be set using the \link #fontmatching font
+ matching\endlink algorithm.
+
+ \sa family(), setStyleHint(), TQFontInfo
+*/
+void TQFont::setFamily( const TQString &family )
+{
+ detach();
+
+ d->request.family = family;
+#if defined(TQ_WS_X11)
+ d->request.addStyle = TQString::null;
+#endif // TQ_WS_X11
+
+ d->tqmask |= TQFontPrivate::Family;
+}
+
+/*!
+ Returns the point size in 1/10ths of a point.
+
+ The returned value will be -1 if the font size has been specified
+ in pixels.
+
+ \sa pointSize() pointSizeFloat()
+ */
+int TQFont::deciPointSize() const
+{
+ return d->request.pointSize;
+}
+
+/*!
+ Returns the point size of the font. Returns -1 if the font size
+ was specified in pixels.
+
+ \sa setPointSize() deciPointSize() pointSizeFloat()
+*/
+int TQFont::pointSize() const
+{
+ return d->request.pointSize == -1 ? -1 : (d->request.pointSize + 5) / 10;
+}
+
+/*!
+ Sets the point size to \a pointSize. The point size must be
+ greater than zero.
+
+ \sa pointSize() setPointSizeFloat()
+*/
+void TQFont::setPointSize( int pointSize )
+{
+ if ( pointSize <= 0 ) {
+
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQFont::setPointSize: Point size <= 0 (%d)", pointSize );
+#endif
+
+ return;
+ }
+
+ detach();
+
+ d->request.pointSize = pointSize * 10;
+ d->request.pixelSize = -1;
+
+ d->tqmask |= TQFontPrivate::Size;
+}
+
+/*!
+ Sets the point size to \a pointSize. The point size must be
+ greater than zero. The requested precision may not be achieved on
+ all platforms.
+
+ \sa pointSizeFloat() setPointSize() setPixelSize()
+*/
+void TQFont::setPointSizeFloat( float pointSize )
+{
+ if ( pointSize <= 0.0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQFont::setPointSize: Point size <= 0 (%f)", pointSize );
+#endif
+ return;
+ }
+
+ detach();
+
+ d->request.pointSize = tqRound(pointSize * 10.0);
+ d->request.pixelSize = -1;
+
+ d->tqmask |= TQFontPrivate::Size;
+}
+
+/*!
+ Returns the point size of the font. Returns -1 if the font size was
+ specified in pixels.
+
+ \sa pointSize() setPointSizeFloat() pixelSize() TQFontInfo::pointSize() TQFontInfo::pixelSize()
+*/
+float TQFont::pointSizeFloat() const
+{
+ return float( d->request.pointSize == -1 ? -10 : d->request.pointSize ) / 10.0;
+}
+
+/*!
+ Sets the font size to \a pixelSize pixels.
+
+ Using this function makes the font tqdevice dependent. Use
+ setPointSize() or setPointSizeFloat() to set the size of the font
+ in a tqdevice independent manner.
+
+ \sa pixelSize()
+*/
+void TQFont::setPixelSize( int pixelSize )
+{
+ if ( pixelSize <= 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize );
+#endif
+ return;
+ }
+
+ detach();
+
+ d->request.pixelSize = pixelSize;
+ d->request.pointSize = -1;
+
+ d->tqmask |= TQFontPrivate::Size;
+}
+
+/*!
+ Returns the pixel size of the font if it was set with
+ setPixelSize(). Returns -1 if the size was set with setPointSize()
+ or setPointSizeFloat().
+
+ \sa setPixelSize() pointSize() TQFontInfo::pointSize() TQFontInfo::pixelSize()
+*/
+int TQFont::pixelSize() const
+{
+ return d->request.pixelSize;
+}
+
+/*! \obsolete
+
+ Sets the logical pixel height of font characters when shown on
+ the screen to \a pixelSize.
+*/
+void TQFont::setPixelSizeFloat( float pixelSize )
+{
+ setPixelSize( (int)pixelSize );
+}
+
+/*!
+ Returns TRUE if italic has been set; otherwise returns FALSE.
+
+ \sa setItalic()
+*/
+bool TQFont::italic() const
+{
+ return d->request.italic;
+}
+
+/*!
+ If \a enable is TRUE, italic is set on; otherwise italic is set
+ off.
+
+ \sa italic(), TQFontInfo
+*/
+void TQFont::setItalic( bool enable )
+{
+ detach();
+
+ d->request.italic = enable;
+ d->tqmask |= TQFontPrivate::Italic;
+}
+
+/*!
+ Returns the weight of the font which is one of the enumerated
+ values from \l{TQFont::Weight}.
+
+ \sa setWeight(), Weight, TQFontInfo
+*/
+int TQFont::weight() const
+{
+ return d->request.weight;
+}
+
+/*!
+ \enum TQFont::Weight
+
+ TQt uses a weighting scale from 0 to 99 similar to, but not the
+ same as, the scales used in Windows or CSS. A weight of 0 is
+ ultralight, whilst 99 will be an extremely black.
+
+ This enum tqcontains the predefined font weights:
+
+ \value Light 25
+ \value Normal 50
+ \value DemiBold 63
+ \value Bold 75
+ \value Black 87
+*/
+
+/*!
+ Sets the weight the font to \a weight, which should be a value
+ from the \l TQFont::Weight enumeration.
+
+ \sa weight(), TQFontInfo
+*/
+void TQFont::setWeight( int weight )
+{
+ if ( weight < 0 || weight > 99 ) {
+
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQFont::setWeight: Value out of range (%d)", weight );
+#endif
+
+ return;
+ }
+
+ detach();
+
+ d->request.weight = weight;
+ d->tqmask |= TQFontPrivate::Weight;
+}
+
+/*!
+ \fn bool TQFont::bold() const
+
+ Returns TRUE if weight() is a value greater than \link Weight
+ TQFont::Normal \endlink; otherwise returns FALSE.
+
+ \sa weight(), setBold(), TQFontInfo::bold()
+*/
+
+/*!
+ \fn void TQFont::setBold( bool enable )
+
+ If \a enable is true sets the font's weight to \link Weight
+ TQFont::Bold \endlink; otherwise sets the weight to \link Weight
+ TQFont::Normal\endlink.
+
+ For finer boldness control use setWeight().
+
+ \sa bold(), setWeight()
+*/
+
+/*!
+ Returns TRUE if underline has been set; otherwise returns FALSE.
+
+ \sa setUnderline()
+*/
+bool TQFont::underline() const
+{
+ return d->underline;
+}
+
+/*!
+ If \a enable is TRUE, sets underline on; otherwise sets underline
+ off.
+
+ \sa underline(), TQFontInfo
+*/
+void TQFont::setUnderline( bool enable )
+{
+ detach();
+
+ d->underline = enable;
+ d->tqmask |= TQFontPrivate::Underline;
+}
+
+/*!
+ Returns TRUE if overline has been set; otherwise returns FALSE.
+
+ \sa setOverline()
+*/
+bool TQFont::overline() const
+{
+ return d->overline;
+}
+
+/*!
+ If \a enable is TRUE, sets overline on; otherwise sets overline off.
+
+ \sa overline(), TQFontInfo
+*/
+void TQFont::setOverline( bool enable )
+{
+ detach();
+
+ d->overline = enable;
+ d->tqmask |= TQFontPrivate::Overline;
+}
+
+/*!
+ Returns TRUE if strikeout has been set; otherwise returns FALSE.
+
+ \sa setStrikeOut()
+*/
+bool TQFont::strikeOut() const
+{
+ return d->strikeOut;
+}
+
+/*!
+ If \a enable is TRUE, sets strikeout on; otherwise sets strikeout
+ off.
+
+ \sa strikeOut(), TQFontInfo
+*/
+void TQFont::setStrikeOut( bool enable )
+{
+ detach();
+
+ d->strikeOut = enable;
+ d->tqmask |= TQFontPrivate::StrikeOut;
+}
+
+/*!
+ Returns TRUE if fixed pitch has been set; otherwise returns FALSE.
+
+ \sa setFixedPitch(), TQFontInfo::fixedPitch()
+*/
+bool TQFont::fixedPitch() const
+{
+ return d->request.fixedPitch;
+}
+
+/*!
+ If \a enable is TRUE, sets fixed pitch on; otherwise sets fixed
+ pitch off.
+
+ \sa fixedPitch(), TQFontInfo
+*/
+void TQFont::setFixedPitch( bool enable )
+{
+ detach();
+
+ d->request.fixedPitch = enable;
+ d->request.ignorePitch = FALSE;
+ d->tqmask |= TQFontPrivate::FixedPitch;
+}
+
+/*!
+ Returns the StyleStrategy.
+
+ The style strategy affects the \link #fontmatching font
+ matching\endlink algorithm. See \l TQFont::StyleStrategy for the
+ list of strategies.
+
+ \sa setStyleHint() TQFont::StyleHint
+*/
+TQFont::StyleStrategy TQFont::styleStrategy() const
+{
+ return (StyleStrategy) d->request.styleStrategy;
+}
+
+/*!
+ Returns the StyleHint.
+
+ The style hint affects the \link #fontmatching font
+ matching\endlink algorithm. See \l TQFont::StyleHint for the list
+ of strategies.
+
+ \sa setStyleHint(), TQFont::StyleStrategy TQFontInfo::tqstyleHint()
+*/
+TQFont::StyleHint TQFont::tqstyleHint() const
+{
+ return (StyleHint) d->request.tqstyleHint;
+}
+
+/*!
+ \enum TQFont::StyleHint
+
+ Style hints are used by the \link #fontmatching font
+ matching\endlink algorithm to tqfind an appropriate default family
+ if a selected font family is not available.
+
+ \value AnyStyle leaves the font matching algorithm to choose the
+ family. This is the default.
+
+ \value SansSerif the font matcher prefer sans serif fonts.
+ \value Helvetica is a synonym for \c SansSerif.
+
+ \value Serif the font matcher prefers serif fonts.
+ \value Times is a synonym for \c Serif.
+
+ \value TypeWriter the font matcher prefers fixed pitch fonts.
+ \value Courier a synonym for \c TypeWriter.
+
+ \value OldEnglish the font matcher prefers decorative fonts.
+ \value Decorative is a synonym for \c OldEnglish.
+
+ \value System the font matcher prefers system fonts.
+*/
+
+/*!
+ \enum TQFont::StyleStrategy
+
+ The style strategy tells the \link #fontmatching font
+ matching\endlink algorithm what type of fonts should be used to
+ tqfind an appropriate default family.
+
+ The following strategies are available:
+
+ \value PreferDefault the default style strategy. It does not prefer
+ any type of font.
+ \value PreferBitmap prefers bitmap fonts (as opposed to outline
+ fonts).
+ \value PreferDevice prefers tqdevice fonts.
+ \value PreferOutline prefers outline fonts (as opposed to bitmap fonts).
+ \value ForceOutline forces the use of outline fonts.
+ \value NoAntialias don't antialias the fonts.
+ \value PreferAntialias antialias if possible.
+ \value OpenGLCompatible forces the use of OpenGL compatible
+ fonts.
+
+ Any of these may be OR-ed with one of these flags:
+
+ \value PreferMatch prefer an exact match. The font matcher will try to
+ use the exact font size that has been specified.
+ \value PreferQuality prefer the best quality font. The font matcher
+ will use the nearest standard point size that the font
+ supports.
+*/
+
+/*!
+ Sets the style hint and strategy to \a hint and \a strategy,
+ respectively.
+
+ If these aren't set explicitly the style hint will default to
+ \c AnyStyle and the style strategy to \c PreferDefault.
+
+ TQt does not support style hints on X11 since this information
+ is not provided by the window system.
+
+ \sa StyleHint, tqstyleHint(), StyleStrategy, styleStrategy(), TQFontInfo
+*/
+void TQFont::setStyleHint( StyleHint hint, StyleStrategy strategy )
+{
+ detach();
+
+ if ( ( d->tqmask & ( TQFontPrivate::StyleHint | TQFontPrivate::StyleStrategy ) ) &&
+ (StyleHint) d->request.tqstyleHint == hint &&
+ (StyleStrategy) d->request.styleStrategy == strategy )
+ return;
+
+ d->request.tqstyleHint = hint;
+ d->request.styleStrategy = strategy;
+ d->tqmask |= TQFontPrivate::StyleHint;
+ d->tqmask |= TQFontPrivate::StyleStrategy;
+
+#if defined(TQ_WS_X11)
+ d->request.addStyle = TQString::null;
+#endif // TQ_WS_X11
+}
+
+/*!
+ Sets the style strategy for the font to \a s.
+
+ \sa TQFont::StyleStrategy
+*/
+void TQFont::setStyleStrategy( StyleStrategy s )
+{
+ detach();
+
+ if ( ( d->tqmask & TQFontPrivate::StyleStrategy ) &&
+ s == (StyleStrategy)d->request.styleStrategy )
+ return;
+
+ d->request.styleStrategy = s;
+ d->tqmask |= TQFontPrivate::StyleStrategy;
+}
+
+
+/*!
+ \enum TQFont::Stretch
+
+ Predefined stretch values that follow the CSS naming convention.
+
+ \value UltraCondensed 50
+ \value ExtraCondensed 62
+ \value Condensed 75
+ \value SemiCondensed 87
+ \value Unstretched 100
+ \value SemiExpanded 112
+ \value Expanded 125
+ \value ExtraExpanded 150
+ \value UltraExpanded 200
+
+ \sa setStretch() stretch()
+*/
+
+/*!
+ Returns the stretch factor for the font.
+
+ \sa setStretch()
+ */
+int TQFont::stretch() const
+{
+ return d->request.stretch;
+}
+
+/*!
+ Sets the stretch factor for the font.
+
+ The stretch factor changes the width of all characters in the font
+ by \a factor percent. For example, setting \a factor to 150
+ results in all characters in the font being 1.5 times ( ie. 150% )
+ wider. The default stretch factor is 100. The minimum stretch
+ factor is 1, and the maximum stretch factor is 4000.
+
+ The stretch factor is only applied to outline fonts. The stretch
+ factor is ignored for bitmap fonts.
+
+ NOTE: TQFont cannot stretch XLFD fonts. When loading XLFD fonts on
+ X11, the stretch factor is matched against a predefined set of
+ values for the SETWIDTH_NAME field of the XLFD.
+
+ \sa stretch() TQFont::StyleStrategy
+*/
+void TQFont::setStretch( int factor )
+{
+ if ( factor < 1 || factor > 4000 ) {
+#ifdef TQT_CHECK_RANGE
+ qWarning( "TQFont::setStretch(): parameter '%d' out of range", factor );
+#endif // TQT_CHECK_RANGE
+
+ return;
+ }
+
+ detach();
+
+ if ( ( d->tqmask & TQFontPrivate::Stretch ) &&
+ d->request.stretch == (uint)factor )
+ return;
+
+ d->request.stretch = (uint)factor;
+ d->tqmask |= TQFontPrivate::Stretch;
+}
+
+/*!
+ If \a enable is TRUE, turns raw mode on; otherwise turns raw mode
+ off. This function only has an effect under X11.
+
+ If raw mode is enabled, TQt will search for an X font with a
+ complete font name matching the family name, ignoring all other
+ values set for the TQFont. If the font name matches several fonts,
+ TQt will use the first font returned by X. TQFontInfo \e cannot be
+ used to fetch information about a TQFont using raw mode (it will
+ return the values set in the TQFont for all parameters, including
+ the family name).
+
+ \warning Do not use raw mode unless you really, really need it! In
+ most (if not all) cases, setRawName() is a much better choice.
+
+ \sa rawMode(), setRawName()
+*/
+void TQFont::setRawMode( bool enable )
+{
+ detach();
+
+ if ( (bool) d->rawMode == enable ) return;
+
+ d->rawMode = enable;
+}
+
+/*!
+ Returns TRUE if a window system font exactly matching the settings
+ of this font is available.
+
+ \sa TQFontInfo
+*/
+bool TQFont::exactMatch() const
+{
+ TQFontEngine *engine = d->engineForScript( TQFont::NoScript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return d->rawMode ? engine->type() != TQFontEngine::Box
+ : d->request == engine->fontDef;
+}
+
+/*!
+ Returns TRUE if this font is equal to \a f; otherwise returns
+ FALSE.
+
+ Two TQFonts are considered equal if their font attributes are
+ equal. If rawMode() is enabled for both fonts, only the family
+ fields are compared.
+
+ \sa operator!=() isCopyOf()
+*/
+bool TQFont::operator==( const TQFont &f ) const
+{
+ return f.d == d || ( f.d->request == d->request &&
+ f.d->underline == d->underline &&
+ f.d->overline == d->overline &&
+ f.d->strikeOut == d->strikeOut );
+}
+
+/*!
+ Returns TRUE if this font is different from \a f; otherwise
+ returns FALSE.
+
+ Two TQFonts are considered to be different if their font attributes
+ are different. If rawMode() is enabled for both fonts, only the
+ family fields are compared.
+
+ \sa operator==()
+*/
+bool TQFont::operator!=( const TQFont &f ) const
+{
+ return !(operator==( f ));
+}
+
+/*!
+ Returns TRUE if this font and \a f are copies of each other, i.e.
+ one of them was created as a copy of the other and neither has
+ been modified since. This is much stricter than equality.
+
+ \sa operator=() operator==()
+*/
+bool TQFont::isCopyOf( const TQFont & f ) const
+{
+ return d == f.d;
+}
+
+/*!
+ Returns TRUE if raw mode is used for font name matching; otherwise
+ returns FALSE.
+
+ \sa setRawMode() rawName()
+*/
+bool TQFont::rawMode() const
+{
+ return d->rawMode;
+}
+
+/*!
+ Returns a new TQFont that has attributes copied from \a other.
+*/
+TQFont TQFont::resolve( const TQFont &other ) const
+{
+ if ( *this == other && d->tqmask == other.d->tqmask )
+ return *this;
+
+ TQFont font( *this );
+ font.detach();
+
+ /*
+ if this font is a copy of the application default font, set the
+ fontdef tqmask to zero to indicate that *nothing* has been
+ explicitly set by the programmer.
+ */
+ const TQFont appfont = TQApplication::font();
+ if ( d == appfont.d )
+ font.d->tqmask = 0;
+
+ font.d->resolve( other.d );
+
+ return font;
+}
+
+#ifndef TQT_NO_COMPAT
+
+/*! \obsolete
+
+ Please use TQApplication::font() instead.
+*/
+TQFont TQFont::defaultFont()
+{
+ return TQApplication::font();
+}
+
+/*! \obsolete
+
+ Please use TQApplication::setFont() instead.
+*/
+void TQFont::setDefaultFont( const TQFont &f )
+{
+ TQApplication::setFont( f );
+}
+
+
+#endif
+
+
+
+
+#ifndef TQT_NO_STRINGLIST
+
+/*****************************************************************************
+ TQFont substitution management
+ *****************************************************************************/
+
+typedef TQDict<TQStringList> TQFontSubst;
+static TQFontSubst *fontSubst = 0;
+static TQSingleCleanupHandler<TQFontSubst> qfont_cleanup_fontsubst;
+
+
+// create substitution dict
+static void initFontSubst()
+{
+ // default substitutions
+ static const char *initTbl[] = {
+
+#if defined(TQ_WS_X11)
+ "arial", "helvetica",
+ "helv", "helvetica",
+ "tms rmn", "times",
+#elif defined(TQ_WS_WIN)
+ "times", "Times New Roman",
+ "courier", "Courier New",
+ "helvetica", "Arial",
+#endif
+
+ 0, 0
+ };
+
+ if (fontSubst)
+ return;
+
+ fontSubst = new TQFontSubst(17, FALSE);
+ TQ_CHECK_PTR( fontSubst );
+ fontSubst->setAutoDelete( TRUE );
+ qfont_cleanup_fontsubst.set(&fontSubst);
+
+ for ( int i=0; initTbl[i] != 0; i += 2 )
+ TQFont::insertSubstitution(TQString::tqfromLatin1(initTbl[i]),
+ TQString::tqfromLatin1(initTbl[i+1]));
+}
+
+
+/*!
+ Returns the first family name to be used whenever \a familyName is
+ specified. The lookup is case insensitive.
+
+ If there is no substitution for \a familyName, \a familyName is
+ returned.
+
+ To obtain a list of substitutions use substitutes().
+
+ \sa setFamily() insertSubstitutions() insertSubstitution() removeSubstitution()
+*/
+TQString TQFont::substitute( const TQString &familyName )
+{
+ initFontSubst();
+
+ TQStringList *list = fontSubst->tqfind(familyName);
+ if (list && list->count() > 0)
+ return *(list->at(0));
+
+ return familyName;
+}
+
+
+/*!
+ Returns a list of family names to be used whenever \a familyName
+ is specified. The lookup is case insensitive.
+
+ If there is no substitution for \a familyName, an empty list is
+ returned.
+
+ \sa substitute() insertSubstitutions() insertSubstitution() removeSubstitution()
+ */
+TQStringList TQFont::substitutes(const TQString &familyName)
+{
+ initFontSubst();
+
+ TQStringList ret, *list = fontSubst->tqfind(familyName);
+ if (list)
+ ret += *list;
+ return ret;
+}
+
+
+/*!
+ Inserts the family name \a substituteName into the substitution
+ table for \a familyName.
+
+ \sa insertSubstitutions() removeSubstitution() substitutions() substitute() substitutes()
+*/
+void TQFont::insertSubstitution(const TQString &familyName,
+ const TQString &substituteName)
+{
+ initFontSubst();
+
+ TQStringList *list = fontSubst->tqfind(familyName);
+ if (! list) {
+ list = new TQStringList;
+ fontSubst->insert(familyName, list);
+ }
+
+ if (! list->tqcontains(substituteName))
+ list->append(substituteName);
+}
+
+
+/*!
+ Inserts the list of families \a substituteNames into the
+ substitution list for \a familyName.
+
+ \sa insertSubstitution(), removeSubstitution(), substitutions(), substitute()
+*/
+void TQFont::insertSubstitutions(const TQString &familyName,
+ const TQStringList &substituteNames)
+{
+ initFontSubst();
+
+ TQStringList *list = fontSubst->tqfind(familyName);
+ if (! list) {
+ list = new TQStringList;
+ fontSubst->insert(familyName, list);
+ }
+
+ TQStringList::ConstIterator it = substituteNames.begin();
+ while (it != substituteNames.end()) {
+ if (! list->tqcontains(*it))
+ list->append(*it);
+ it++;
+ }
+}
+
+// ### mark: should be called removeSubstitutions()
+/*!
+ Removes all the substitutions for \a familyName.
+
+ \sa insertSubstitutions(), insertSubstitution(), substitutions(), substitute()
+*/
+void TQFont::removeSubstitution( const TQString &familyName )
+{ // ### function name should be removeSubstitutions() or
+ // ### removeSubstitutionList()
+ initFontSubst();
+
+ fontSubst->remove(familyName);
+}
+
+
+/*!
+ Returns a sorted list of substituted family names.
+
+ \sa insertSubstitution(), removeSubstitution(), substitute()
+*/
+TQStringList TQFont::substitutions()
+{
+ initFontSubst();
+
+ TQStringList ret;
+ TQDictIterator<TQStringList> it(*fontSubst);
+
+ while (it.current()) {
+ ret.append(it.currentKey());
+ ++it;
+ }
+
+ ret.sort();
+
+ return ret;
+}
+
+#endif // TQT_NO_STRINGLIST
+
+
+/* \internal
+ Internal function. Converts boolean font settings to an unsigned
+ 8-bit number. Used for serialization etc.
+*/
+static TQ_UINT8 get_font_bits( const TQFontPrivate *f )
+{
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( f != 0 );
+#endif
+
+ TQ_UINT8 bits = 0;
+ if ( f->request.italic )
+ bits |= 0x01;
+ if ( f->underline )
+ bits |= 0x02;
+ if ( f->overline )
+ bits |= 0x40;
+ if ( f->strikeOut )
+ bits |= 0x04;
+ if ( f->request.fixedPitch )
+ bits |= 0x08;
+ // if ( f.hintSetByUser )
+ // bits |= 0x10;
+ if ( f->rawMode )
+ bits |= 0x20;
+ return bits;
+}
+
+
+#ifndef TQT_NO_DATASTREAM
+
+/* \internal
+ Internal function. Sets boolean font settings from an unsigned
+ 8-bit number. Used for serialization etc.
+*/
+static void set_font_bits( TQ_UINT8 bits, TQFontPrivate *f )
+{
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( f != 0 );
+#endif
+
+ f->request.italic = (bits & 0x01) != 0;
+ f->underline = (bits & 0x02) != 0;
+ f->overline = (bits & 0x40) != 0;
+ f->strikeOut = (bits & 0x04) != 0;
+ f->request.fixedPitch = (bits & 0x08) != 0;
+ // f->hintSetByUser = (bits & 0x10) != 0;
+ f->rawMode = (bits & 0x20) != 0;
+}
+
+#endif
+
+
+/*!
+ Returns the font's key, a textual representation of a font. It is
+ typically used as the key for a cache or dictionary of fonts.
+
+ \sa TQMap
+*/
+TQString TQFont::key() const
+{
+ return toString();
+}
+
+/*!
+ Returns a description of the font. The description is a
+ comma-separated list of the attributes, perfectly suited for use
+ in TQSettings.
+
+ \sa fromString() operator<<()
+ */
+TQString TQFont::toString() const
+{
+ const TQChar comma( ',' );
+ return family() + comma +
+ TQString::number( pointSizeFloat() ) + comma +
+ TQString::number( pixelSize() ) + comma +
+ TQString::number( (int) tqstyleHint() ) + comma +
+ TQString::number( weight() ) + comma +
+ TQString::number( (int) italic() ) + comma +
+ TQString::number( (int) underline() ) + comma +
+ TQString::number( (int) strikeOut() ) + comma +
+ TQString::number( (int)fixedPitch() ) + comma +
+ TQString::number( (int) rawMode() );
+}
+
+
+/*!
+ Sets this font to match the description \a descrip. The description
+ is a comma-separated list of the font attributes, as returned by
+ toString().
+
+ \sa toString() operator>>()
+ */
+bool TQFont::fromString(const TQString &descrip)
+{
+#ifndef TQT_NO_STRINGLIST
+ TQStringList l(TQStringList::split(',', descrip));
+
+ int count = (int)l.count();
+#else
+ int count = 0;
+ TQString l[11];
+ int from = 0;
+ int to = descrip.tqfind( ',' );
+ while ( to > 0 && count < 11 ) {
+ l[count] = descrip.mid( from, to-from );
+ count++;
+ from = to+1;
+ to = descrip.tqfind( ',', from );
+ }
+#endif // TQT_NO_STRINGLIST
+ if ( !count || ( count > 2 && count < 9 ) || count > 11 ) {
+
+#ifdef TQT_CHECK_STATE
+ qWarning("TQFont::fromString: invalid description '%s'",
+ descrip.isEmpty() ? "(empty)" : descrip.latin1());
+#endif
+
+ return FALSE;
+ }
+
+ setFamily(l[0]);
+ if ( count > 1 && l[1].toDouble() > 0.0 )
+ setPointSizeFloat(l[1].toDouble());
+ if ( count == 9 ) {
+ setStyleHint((StyleHint) l[2].toInt());
+ setWeight(l[3].toInt());
+ setItalic(l[4].toInt());
+ setUnderline(l[5].toInt());
+ setStrikeOut(l[6].toInt());
+ setFixedPitch(l[7].toInt());
+ setRawMode(l[8].toInt());
+ } else if ( count == 10 ) {
+ if ( l[2].toInt() > 0 )
+ setPixelSize( l[2].toInt() );
+ setStyleHint((StyleHint) l[3].toInt());
+ setWeight(l[4].toInt());
+ setItalic(l[5].toInt());
+ setUnderline(l[6].toInt());
+ setStrikeOut(l[7].toInt());
+ setFixedPitch(l[8].toInt());
+ setRawMode(l[9].toInt());
+ }
+
+ return TRUE;
+}
+
+#if !defined( TQ_WS_TQWS )
+/*! \internal
+
+ Internal function that dumps font cache statistics.
+*/
+void TQFont::cacheStatistics()
+{
+
+
+}
+#endif // !TQ_WS_TQWS
+
+
+
+/*****************************************************************************
+ TQFont stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+
+/*!
+ \relates TQFont
+
+ Writes the font \a font to the data stream \a s. (toString()
+ writes to a text stream.)
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+TQDataStream &operator<<( TQDataStream &s, const TQFont &font )
+{
+ if ( s.version() == 1 ) {
+ TQCString fam( font.d->request.family.latin1() );
+ s << fam;
+ } else {
+ s << font.d->request.family;
+ }
+
+ if ( s.version() <= 3 ) {
+ TQ_INT16 pointSize = (TQ_INT16) font.d->request.pointSize;
+ if ( pointSize == -1 ) {
+#ifdef TQ_WS_X11
+ pointSize = (TQ_INT16)(font.d->request.pixelSize*720/TQPaintDevice::x11AppDpiY());
+#else
+ pointSize = (TQ_INT16)TQFontInfo( font ).pointSize() * 10;
+#endif
+ }
+ s << pointSize;
+ } else {
+ s << (TQ_INT16) font.d->request.pointSize;
+ s << (TQ_INT16) font.d->request.pixelSize;
+ }
+
+ s << (TQ_UINT8) font.d->request.tqstyleHint;
+ if ( s.version() >= 5 )
+ s << (TQ_UINT8 ) font.d->request.styleStrategy;
+ return s << (TQ_UINT8) 0
+ << (TQ_UINT8) font.d->request.weight
+ << get_font_bits(font.d);
+}
+
+
+/*!
+ \relates TQFont
+
+ Reads the font \a font from the data stream \a s. (fromString()
+ reads from a text stream.)
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+TQDataStream &operator>>( TQDataStream &s, TQFont &font )
+{
+ if (font.d->deref()) delete font.d;
+
+ font.d = new TQFontPrivate;
+ font.d->tqmask = TQFontPrivate::Complete;
+
+ TQ_INT16 pointSize, pixelSize = -1;
+ TQ_UINT8 tqstyleHint, styleStrategy = TQFont::PreferDefault, charSet, weight, bits;
+
+ if ( s.version() == 1 ) {
+ TQCString fam;
+ s >> fam;
+ font.d->request.family = TQString( fam );
+ } else {
+ s >> font.d->request.family;
+ }
+
+ s >> pointSize;
+ if ( s.version() >= 4 )
+ s >> pixelSize;
+ s >> tqstyleHint;
+ if ( s.version() >= 5 )
+ s >> styleStrategy;
+ s >> charSet;
+ s >> weight;
+ s >> bits;
+
+ font.d->request.pointSize = pointSize;
+ font.d->request.pixelSize = pixelSize;
+ font.d->request.tqstyleHint = tqstyleHint;
+ font.d->request.styleStrategy = styleStrategy;
+ font.d->request.weight = weight;
+
+ set_font_bits( bits, font.d );
+
+ return s;
+}
+
+#endif // TQT_NO_DATASTREAM
+
+
+
+
+/*****************************************************************************
+ TQFontMetrics member functions
+ *****************************************************************************/
+
+/*!
+ \class TQFontMetrics tqfontmetrics.h
+ \brief The TQFontMetrics class provides font metrics information.
+
+ \ingroup graphics
+ \ingroup shared
+
+ TQFontMetrics functions calculate the size of characters and
+ strings for a given font. There are three ways you can create a
+ TQFontMetrics object:
+
+ \list 1
+ \i Calling the TQFontMetrics constructor with a TQFont creates a
+ font metrics object for a screen-compatible font, i.e. the font
+ cannot be a printer font<sup>*</sup>. If the font is changed
+ later, the font metrics object is \e not updated.
+
+ \i TQWidget::fontMetrics() returns the font metrics for a widget's
+ font. This is equivalent to TQFontMetrics(widget->font()). If the
+ widget's font is changed later, the font metrics object is \e not
+ updated.
+
+ \i TQPainter::fontMetrics() returns the font metrics for a
+ painter's current font. If the painter's font is changed later, the
+ font metrics object is \e not updated.
+ \endlist
+
+ <sup>*</sup> If you use a printer font the values returned may be
+ inaccurate. Printer fonts are not always accessible so the nearest
+ screen font is used if a printer font is supplied.
+
+ Once created, the object provides functions to access the
+ individual metrics of the font, its characters, and for strings
+ rendered in the font.
+
+ There are several functions that operate on the font: ascent(),
+ descent(), height(), leading() and lineSpacing() return the basic
+ size properties of the font. The underlinePos(), overlinePos(),
+ strikeOutPos() and lineWidth() functions, return the properties of
+ the line that underlines, overlines or strikes out the
+ characters. These functions are all fast.
+
+ There are also some functions that operate on the set of glyphs in
+ the font: minLeftBearing(), minRightBearing() and maxWidth().
+ These are by necessity slow, and we recommend avoiding them if
+ possible.
+
+ For each character, you can get its width(), leftBearing() and
+ rightBearing() and tqfind out whether it is in the font using
+ inFont(). You can also treat the character as a string, and use
+ the string functions on it.
+
+ The string functions include width(), to return the width of a
+ string in pixels (or points, for a printer), boundingRect(), to
+ return a rectangle large enough to contain the rendered string,
+ and size(), to return the size of that rectangle.
+
+ Example:
+ \code
+ TQFont font( "times", 24 );
+ TQFontMetrics fm( font );
+ int pixelsWide = fm.width( "What's the width of this text?" );
+ int pixelsHigh = fm.height();
+ \endcode
+
+ \sa TQFont TQFontInfo TQFontDatabase
+*/
+
+/*!
+ Constructs a font metrics object for \a font.
+
+ The font must be screen-compatible, i.e. a font you use when
+ drawing text in \link TQWidget widgets\endlink or \link TQPixmap
+ pixmaps\endlink, not TQPicture or TQPrinter.
+
+ The font metrics object holds the information for the font that is
+ passed in the constructor at the time it is created, and is not
+ updated if the font's attributes are changed later.
+
+ Use TQPainter::fontMetrics() to get the font metrics when painting.
+ This will give correct results also when painting on paint tqdevice
+ that is not screen-compatible.
+*/
+TQFontMetrics::TQFontMetrics( const TQFont &font )
+ : d( font.d ), painter( 0 ), fscript( TQFont::NoScript )
+{
+ d->ref();
+}
+
+/*!
+ \overload
+
+ Constructs a font metrics object for \a font using the given \a
+ script.
+*/
+TQFontMetrics::TQFontMetrics( const TQFont &font, TQFont::Script script )
+ : d( font.d ), painter( 0 ), fscript( script )
+{
+ d->ref();
+}
+
+/*! \internal
+
+ Constructs a font metrics object for the painter's font \a p.
+*/
+TQFontMetrics::TQFontMetrics( const TQPainter *p )
+ : painter ( (TQPainter *) p ), fscript( TQFont::NoScript )
+{
+#if defined(CHECK_STATE)
+ if ( !painter->isActive() )
+ qWarning( "TQFontMetrics: Get font metrics between TQPainter::begin() "
+ "and TQPainter::end()" );
+#endif
+
+ if ( painter->testf(TQPainter::DirtyFont) )
+ painter->updateFont();
+
+ d = painter->pfont ? painter->pfont->d : painter->cfont.d;
+
+#if defined(TQ_WS_X11)
+ if ( d->screen != p->scrn ) {
+ TQFontPrivate *new_d = new TQFontPrivate( *d );
+ TQ_CHECK_PTR( new_d );
+ d = new_d;
+ d->screen = p->scrn;
+ d->count = 1;
+ } else
+#endif // TQ_WS_X11
+ d->ref();
+}
+
+/*!
+ Constructs a copy of \a fm.
+*/
+TQFontMetrics::TQFontMetrics( const TQFontMetrics &fm )
+ : d( fm.d ), painter( 0 ), fscript( fm.fscript )
+{
+ d->ref();
+}
+
+/*!
+ Destroys the font metrics object and frees all allocated
+ resources.
+*/
+TQFontMetrics::~TQFontMetrics()
+{
+ if ( d->deref() )
+ delete d;
+}
+
+/*!
+ Assigns the font metrics \a fm.
+*/
+TQFontMetrics &TQFontMetrics::operator=( const TQFontMetrics &fm )
+{
+ if ( d != fm.d ) {
+ if ( d->deref() )
+ delete d;
+ d = fm.d;
+ d->ref();
+ }
+ painter = fm.painter;
+ return *this;
+}
+
+/*!
+ Returns the ascent of the font.
+
+ The ascent of a font is the distance from the baseline to the
+ highest position characters extend to. In practice, some font
+ designers break this rule, e.g. when they put more than one accent
+ on top of a character, or to accommodate an unusual character in
+ an exotic language, so it is possible (though rare) that this
+ value will be too small.
+
+ \sa descent()
+*/
+int TQFontMetrics::ascent() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( latin_engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return TQMAX(engine->ascent(), latin_engine->ascent());
+}
+
+
+/*!
+ Returns the descent of the font.
+
+ The descent is the distance from the base line to the lowest point
+ characters extend to. (Note that this is different from X, which
+ adds 1 pixel.) In practice, some font designers break this rule,
+ e.g. to accommodate an unusual character in an exotic language, so
+ it is possible (though rare) that this value will be too small.
+
+ \sa ascent()
+*/
+int TQFontMetrics::descent() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( latin_engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return TQMAX(engine->descent(), latin_engine->descent());
+}
+
+/*!
+ Returns the height of the font.
+
+ This is always equal to ascent()+descent()+1 (the 1 is for the
+ base line).
+
+ \sa leading(), lineSpacing()
+*/
+int TQFontMetrics::height() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( latin_engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return (TQMAX(engine->ascent(), latin_engine->ascent()) +
+ TQMAX(engine->descent(), latin_engine->descent()) + 1);
+}
+
+/*!
+ Returns the leading of the font.
+
+ This is the natural inter-line spacing.
+
+ \sa height(), lineSpacing()
+*/
+int TQFontMetrics::leading() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( latin_engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return TQMAX(engine->leading(), latin_engine->leading());
+}
+
+/*!
+ Returns the distance from one base line to the next.
+
+ This value is always equal to leading()+height().
+
+ \sa height(), leading()
+*/
+int TQFontMetrics::lineSpacing() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( latin_engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return (TQMAX(engine->leading(), latin_engine->leading()) +
+ TQMAX(engine->ascent(), latin_engine->ascent()) +
+ TQMAX(engine->descent(), latin_engine->descent()) + 1);
+}
+
+/*!
+ Returns the minimum left bearing of the font.
+
+ This is the smallest leftBearing(char) of all characters in the
+ font.
+
+ Note that this function can be very slow if the font is large.
+
+ \sa minRightBearing(), leftBearing()
+*/
+int TQFontMetrics::minLeftBearing() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( latin_engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return TQMIN(engine->minLeftBearing(), latin_engine->minLeftBearing());
+}
+
+/*!
+ Returns the minimum right bearing of the font.
+
+ This is the smallest rightBearing(char) of all characters in the
+ font.
+
+ Note that this function can be very slow if the font is large.
+
+ \sa minLeftBearing(), rightBearing()
+*/
+int TQFontMetrics::minRightBearing() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( latin_engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return TQMIN(engine->minRightBearing(), latin_engine->minRightBearing());
+}
+
+/*!
+ Returns the width of the widest character in the font.
+*/
+int TQFontMetrics::maxWidth() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+ TQFontEngine *lengine = d->engineForScript( TQFont::Latin );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+ TQ_ASSERT( lengine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return TQMAX(engine->maxCharWidth(), lengine->maxCharWidth());
+}
+
+/*!
+ Returns TRUE if character \a ch is a valid character in the font;
+ otherwise returns FALSE.
+*/
+bool TQFontMetrics::inFont(TQChar ch) const
+{
+ TQFont::Script script;
+ SCRIPT_FOR_CHAR( script, ch );
+
+ TQFontEngine *engine = d->engineForScript( script );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ if ( engine->type() == TQFontEngine::Box ) return FALSE;
+ return engine->canRender( &ch, 1 );
+}
+
+/*! \fn int TQFontMetrics::leftBearing( TQChar ch ) const
+ Returns the left bearing of character \a ch in the font.
+
+ The left bearing is the right-ward distance of the left-most pixel
+ of the character from the logical origin of the character. This
+ value is negative if the pixels of the character extend to the
+ left of the logical origin.
+
+ See width(TQChar) for a graphical description of this metric.
+
+ \sa rightBearing(), minLeftBearing(), width()
+*/
+#if !defined(TQ_WS_WIN) && !defined(TQ_WS_TQWS)
+int TQFontMetrics::leftBearing(TQChar ch) const
+{
+ TQFont::Script script;
+ SCRIPT_FOR_CHAR( script, ch );
+
+ TQFontEngine *engine = d->engineForScript( script );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ if ( engine->type() == TQFontEngine::Box ) return 0;
+
+ glyph_t glyphs[10];
+ int nglyphs = 9;
+ engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE );
+ // ### can nglyphs != 1 happen at all? Not currently I think
+ glyph_metrics_t gi = engine->boundingBox( glyphs[0] );
+ return gi.x;
+}
+#endif // !TQ_WS_WIN
+
+/*! \fn int TQFontMetrics::rightBearing(TQChar ch) const
+ Returns the right bearing of character \a ch in the font.
+
+ The right bearing is the left-ward distance of the right-most
+ pixel of the character from the logical origin of a subsequent
+ character. This value is negative if the pixels of the character
+ extend to the right of the width() of the character.
+
+ See width() for a graphical description of this metric.
+
+ \sa leftBearing(), minRightBearing(), width()
+*/
+#if !defined(TQ_WS_WIN) && !defined(TQ_WS_TQWS)
+int TQFontMetrics::rightBearing(TQChar ch) const
+{
+ TQFont::Script script;
+ SCRIPT_FOR_CHAR( script, ch );
+
+ TQFontEngine *engine = d->engineForScript( script );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ if ( engine->type() == TQFontEngine::Box ) return 0;
+
+ glyph_t glyphs[10];
+ int nglyphs = 9;
+ engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE );
+ // ### can nglyphs != 1 happen at all? Not currently I think
+ glyph_metrics_t gi = engine->boundingBox( glyphs[0] );
+ return gi.xoff - gi.x - gi.width;
+}
+#endif // !TQ_WS_WIN
+
+
+#ifndef TQ_WS_TQWS
+/*!
+ Returns the width in pixels of the first \a len characters of \a
+ str. If \a len is negative (the default), the entire string is
+ used.
+
+ Note that this value is \e not equal to boundingRect().width();
+ boundingRect() returns a rectangle describing the pixels this
+ string will cover whereas width() returns the distance to where
+ the next string should be drawn.
+
+ \sa boundingRect()
+*/
+int TQFontMetrics::width( const TQString &str, int len ) const
+{
+ if (len < 0)
+ len = str.length();
+ if (len == 0)
+ return 0;
+
+ int pos = 0;
+ int width = 0;
+#ifndef TQ_WS_MAC
+ const TQChar *ch = str.tqunicode();
+
+ while (pos < len) {
+ unsigned short uc = ch->tqunicode();
+ if (uc < TQFontEngineData::widthCacheSize && d->engineData && d->engineData->widthCache[uc])
+ width += d->engineData->widthCache[uc];
+ else {
+ TQFont::Script script;
+ SCRIPT_FOR_CHAR( script, *ch );
+
+ if (script >= TQFont::Arabic && script <= TQFont::Khmer)
+ break;
+ if ( ::category( *ch ) != TQChar::Mark_NonSpacing && !qIsZeroWidthChar(ch->tqunicode())) {
+ TQFontEngine *engine = d->engineForScript( script );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ glyph_t glyphs[8];
+ advance_t advances[8];
+ int nglyphs = 7;
+ engine->stringToCMap( ch, 1, glyphs, advances, &nglyphs, FALSE );
+
+ // ### can nglyphs != 1 happen at all? Not currently I think
+ if ( uc < TQFontEngineData::widthCacheSize && advances[0] > 0 && advances[0] < 0x100 )
+ d->engineData->widthCache[ uc ] = advances[0];
+ width += advances[0];
+ }
+ }
+ ++pos;
+ ++ch;
+ }
+ if ( pos < len ) {
+#endif
+ TQTextEngine tqlayout( str, d );
+ tqlayout.itemize( TQTextEngine::WidthOnly );
+ width += tqlayout.width( pos, len-pos );
+#ifndef TQ_WS_MAC
+ }
+#endif
+ return width;
+}
+#endif
+
+/*! \fn int TQFontMetrics::width( TQChar ch ) const
+
+ <img src="bearings.png" align=right>
+
+ Returns the logical width of character \a ch in pixels. This is a
+ distance appropriate for drawing a subsequent character after \a
+ ch.
+
+ Some of the metrics are described in the image to the right. The
+ central dark rectangles cover the logical width() of each
+ character. The outer pale rectangles cover the leftBearing() and
+ rightBearing() of each character. Notice that the bearings of "f"
+ in this particular font are both negative, while the bearings of
+ "o" are both positive.
+
+ \warning This function will produce incorrect results for Arabic
+ characters or non spacing marks in the middle of a string, as the
+ glyph shaping and positioning of marks that happens when
+ processing strings cannot be taken into account. Use charWidth()
+ instead if you aren't looking for the width of isolated
+ characters.
+
+ \sa boundingRect(), charWidth()
+*/
+
+/*! \fn int TQFontMetrics::width( char c ) const
+
+ \overload
+ \obsolete
+
+ Provided to aid porting from TQt 1.x.
+*/
+
+/*! \fn int TQFontMetrics::charWidth( const TQString &str, int pos ) const
+ Returns the width of the character at position \a pos in the
+ string \a str.
+
+ The whole string is needed, as the glyph drawn may change
+ depending on the context (the letter before and after the current
+ one) for some languages (e.g. Arabic).
+
+ This function also takes non spacing marks and ligatures into
+ account.
+*/
+
+#ifndef TQ_WS_TQWS
+/*!
+ Returns the bounding rectangle of the first \a len characters of
+ \a str, which is the set of pixels the text would cover if drawn
+ at (0, 0).
+
+ If \a len is negative (the default), the entire string is used.
+
+ Note that the bounding rectangle may extend to the left of (0, 0),
+ e.g. for italicized fonts, and that the text output may cover \e
+ all pixels in the bounding rectangle.
+
+ Newline characters are processed as normal characters, \e not as
+ linebreaks.
+
+ Due to the different actual character heights, the height of the
+ bounding rectangle of e.g. "Yes" and "yes" may be different.
+
+ \sa width(), TQPainter::boundingRect()
+*/
+TQRect TQFontMetrics::boundingRect( const TQString &str, int len ) const
+{
+ if (len < 0)
+ len = str.length();
+ if (len == 0)
+ return TQRect();
+
+ TQTextEngine tqlayout( str, d );
+ tqlayout.itemize( TQTextEngine::NoBidi|TQTextEngine::SingleLine );
+ glyph_metrics_t gm = tqlayout.boundingBox( 0, len );
+ return TQRect( gm.x, gm.y, gm.width, gm.height );
+}
+#endif
+
+/*!
+ Returns the rectangle that is covered by ink if the character
+ specified by \a ch were to be drawn at the origin of the coordinate
+ system.
+
+ Note that the bounding rectangle may extend to the left of (0, 0),
+ e.g. for italicized fonts, and that the text output may cover \e
+ all pixels in the bounding rectangle. For a space character the rectangle
+ will usually be empty.
+
+ Note that the rectangle usually extends both above and below the
+ base line.
+
+ \warning The width of the returned rectangle is not the advance width
+ of the character. Use boundingRect(const TQString &) or width() instead.
+
+ \sa width()
+*/
+TQRect TQFontMetrics::boundingRect( TQChar ch ) const
+{
+ TQFont::Script script;
+ SCRIPT_FOR_CHAR( script, ch );
+
+ TQFontEngine *engine = d->engineForScript( script );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ glyph_t glyphs[10];
+ int nglyphs = 9;
+ engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE );
+ glyph_metrics_t gi = engine->boundingBox( glyphs[0] );
+ return TQRect( gi.x, gi.y, gi.width, gi.height );
+}
+
+/*!
+ \overload
+
+ Returns the bounding rectangle of the first \a len characters of
+ \a str, which is the set of pixels the text would cover if drawn
+ at (0, 0). The drawing, and hence the bounding rectangle, is
+ constrained to the rectangle (\a x, \a y, \a w, \a h).
+
+ If \a len is negative (which is the default), the entire string is
+ used.
+
+ The \a flgs argument is the bitwise OR of the following flags:
+ \list
+ \i \c AlignAuto aligns to the left border for all languages except
+ Arabic and Hebrew where it aligns to the right.
+ \i \c AlignLeft aligns to the left border.
+ \i \c AlignRight aligns to the right border.
+ \i \c AlignJustify produces justified text.
+ \i \c AlignHCenter aligns horizontally centered.
+ \i \c AlignTop aligns to the top border.
+ \i \c AlignBottom aligns to the bottom border.
+ \i \c AlignVCenter aligns vertically centered
+ \i \c AlignCenter (== \c{AlignHCenter | AlignVCenter})
+ \i \c SingleLine ignores newline characters in the text.
+ \i \c ExpandTabs expands tabs (see below)
+ \i \c ShowPrefix interprets "&amp;x" as "<u>x</u>", i.e. underlined.
+ \i \c WordBreak breaks the text to fit the rectangle.
+ \endlist
+
+ Horizontal tqalignment defaults to \c AlignAuto and vertical
+ tqalignment defaults to \c AlignTop.
+
+ If several of the horizontal or several of the vertical tqalignment
+ flags are set, the resulting tqalignment is undefined.
+
+ These flags are defined in \c tqnamespace.h.
+
+ If \c ExpandTabs is set in \a flgs, then: if \a tabarray is
+ non-null, it specifies a 0-terminated sequence of pixel-positions
+ for tabs; otherwise if \a tabstops is non-zero, it is used as the
+ tab spacing (in pixels).
+
+ Note that the bounding rectangle may extend to the left of (0, 0),
+ e.g. for italicized fonts, and that the text output may cover \e
+ all pixels in the bounding rectangle.
+
+ Newline characters are processed as linebreaks.
+
+ Despite the different actual character heights, the heights of the
+ bounding rectangles of "Yes" and "yes" are the same.
+
+ The bounding rectangle given by this function is somewhat larger
+ than that calculated by the simpler boundingRect() function. This
+ function uses the \link minLeftBearing() maximum left \endlink and
+ \link minRightBearing() right \endlink font bearings as is
+ necessary for multi-line text to align correctly. Also,
+ fontHeight() and lineSpacing() are used to calculate the height,
+ rather than individual character heights.
+
+ The \a intern argument should not be used.
+
+ \sa width(), TQPainter::boundingRect(), TQt::AlignmentFlags
+*/
+TQRect TQFontMetrics::boundingRect( int x, int y, int w, int h, int flgs,
+ const TQString& str, int len, int tabstops,
+ int *tabarray, TQTextParag **intern ) const
+{
+ if ( len < 0 )
+ len = str.length();
+
+ int tabarraylen=0;
+ if (tabarray)
+ while (tabarray[tabarraylen])
+ tabarraylen++;
+
+ TQRect rb;
+ TQRect r(x, y, w, h);
+ qt_format_text( TQFont( d, d->painttqdevice ), r, flgs|TQt::DontPrint, str, len, &rb,
+ tabstops, tabarray, tabarraylen, intern, 0 );
+
+ return rb;
+}
+
+/*!
+ Returns the size in pixels of the first \a len characters of \a
+ str.
+
+ If \a len is negative (the default), the entire string is used.
+
+ The \a flgs argument is the bitwise OR of the following flags:
+ \list
+ \i \c SingleLine ignores newline characters.
+ \i \c ExpandTabs expands tabs (see below)
+ \i \c ShowPrefix interprets "&amp;x" as "<u>x</u>", i.e. underlined.
+ \i \c WordBreak breaks the text to fit the rectangle.
+ \endlist
+
+ These flags are defined in \c tqnamespace.h.
+
+ If \c ExpandTabs is set in \a flgs, then: if \a tabarray is
+ non-null, it specifies a 0-terminated sequence of pixel-positions
+ for tabs; otherwise if \a tabstops is non-zero, it is used as the
+ tab spacing (in pixels).
+
+ Newline characters are processed as linebreaks.
+
+ Despite the different actual character heights, the heights of the
+ bounding rectangles of "Yes" and "yes" are the same.
+
+ The \a intern argument should not be used.
+
+ \sa boundingRect()
+*/
+TQSize TQFontMetrics::size( int flgs, const TQString &str, int len, int tabstops,
+ int *tabarray, TQTextParag **intern ) const
+{
+ return boundingRect(0,0,0,0,flgs,str,len,tabstops,tabarray,intern).size();
+}
+
+/*!
+ Returns the distance from the base line to where an underscore
+ should be drawn.
+
+ \sa overlinePos(), strikeOutPos(), lineWidth()
+*/
+int TQFontMetrics::underlinePos() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return engine->underlinePosition();
+}
+
+/*!
+ Returns the distance from the base line to where an overline
+ should be drawn.
+
+ \sa underlinePos(), strikeOutPos(), lineWidth()
+*/
+int TQFontMetrics::overlinePos() const
+{
+ int pos = ascent() + 1;
+ return pos > 0 ? pos : 1;
+}
+
+/*!
+ Returns the distance from the base line to where the strikeout
+ line should be drawn.
+
+ \sa underlinePos(), overlinePos(), lineWidth()
+*/
+int TQFontMetrics::strikeOutPos() const
+{
+ int pos = ascent() / 3;
+ return pos > 0 ? pos : 1;
+}
+
+/*!
+ Returns the width of the underline and strikeout lines, adjusted
+ for the point size of the font.
+
+ \sa underlinePos(), overlinePos(), strikeOutPos()
+*/
+int TQFontMetrics::lineWidth() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return engine->lineThickness();
+}
+
+
+
+
+/*****************************************************************************
+ TQFontInfo member functions
+ *****************************************************************************/
+
+/*!
+ \class TQFontInfo tqfontinfo.h
+
+ \brief The TQFontInfo class provides general information about fonts.
+
+ \ingroup graphics
+ \ingroup shared
+
+ The TQFontInfo class provides the same access functions as TQFont,
+ e.g. family(), pointSize(), italic(), weight(), fixedPitch(),
+ tqstyleHint() etc. But whilst the TQFont access functions return the
+ values that were set, a TQFontInfo object returns the values that
+ apply to the font that will actually be used to draw the text.
+
+ For example, when the program asks for a 25pt Courier font on a
+ machine that has a non-scalable 24pt Courier font, TQFont will
+ (normally) use the 24pt Courier for rendering. In this case,
+ TQFont::pointSize() returns 25 and TQFontInfo::pointSize() returns
+ 24.
+
+ There are three ways to create a TQFontInfo object.
+ \list 1
+ \i Calling the TQFontInfo constructor with a TQFont creates a font
+ info object for a screen-compatible font, i.e. the font cannot be
+ a printer font<sup>*</sup>. If the font is changed later, the font
+ info object is \e not updated.
+
+ \i TQWidget::fontInfo() returns the font info for a widget's font.
+ This is equivalent to calling TQFontInfo(widget->font()). If the
+ widget's font is changed later, the font info object is \e not
+ updated.
+
+ \i TQPainter::fontInfo() returns the font info for a painter's
+ current font. If the painter's font is changed later, the font
+ info object is \e not updated.
+ \endlist
+
+ <sup>*</sup> If you use a printer font the values returned may be
+ inaccurate. Printer fonts are not always accessible so the nearest
+ screen font is used if a printer font is supplied.
+
+ \sa TQFont TQFontMetrics TQFontDatabase
+*/
+
+/*!
+ Constructs a font info object for \a font.
+
+ The font must be screen-compatible, i.e. a font you use when
+ drawing text in \link TQWidget widgets\endlink or \link TQPixmap
+ pixmaps\endlink, not TQPicture or TQPrinter.
+
+ The font info object holds the information for the font that is
+ passed in the constructor at the time it is created, and is not
+ updated if the font's attributes are changed later.
+
+ Use TQPainter::fontInfo() to get the font info when painting.
+ This will give correct results also when painting on paint tqdevice
+ that is not screen-compatible.
+*/
+TQFontInfo::TQFontInfo( const TQFont &font )
+ : d( font.d ), painter( 0 ), fscript( TQFont::NoScript )
+{
+ d->ref();
+}
+
+/*!
+ Constructs a font info object for \a font using the specified \a
+ script.
+*/
+TQFontInfo::TQFontInfo( const TQFont &font, TQFont::Script script )
+ : d( font.d ), painter( 0 ), fscript( script )
+{
+ d->ref();
+}
+
+/*! \internal
+
+ Constructs a font info object from the painter's font \a p.
+*/
+TQFontInfo::TQFontInfo( const TQPainter *p )
+ : painter( 0 ), fscript( TQFont::NoScript )
+{
+ TQPainter *painter = (TQPainter *) p;
+
+#if defined(CHECK_STATE)
+ if ( !painter->isActive() )
+ qWarning( "TQFontInfo: Get font info between TQPainter::begin() "
+ "and TQPainter::end()" );
+#endif
+
+ painter->setf( TQPainter::FontInf );
+ if ( painter->testf(TQPainter::DirtyFont) )
+ painter->updateFont();
+ if ( painter->pfont )
+ d = painter->pfont->d;
+ else
+ d = painter->cfont.d;
+ d->ref();
+}
+
+/*!
+ Constructs a copy of \a fi.
+*/
+TQFontInfo::TQFontInfo( const TQFontInfo &fi )
+ : d(fi.d), painter(0), fscript( fi.fscript )
+{
+ d->ref();
+}
+
+/*!
+ Destroys the font info object.
+*/
+TQFontInfo::~TQFontInfo()
+{
+ if ( d->deref() )
+ delete d;
+}
+
+/*!
+ Assigns the font info in \a fi.
+*/
+TQFontInfo &TQFontInfo::operator=( const TQFontInfo &fi )
+{
+ if ( d != fi.d ) {
+ if ( d->deref() )
+ delete d;
+ d = fi.d;
+ d->ref();
+ }
+ painter = 0;
+ fscript = fi.fscript;
+ return *this;
+}
+
+/*!
+ Returns the family name of the matched window system font.
+
+ \sa TQFont::family()
+*/
+TQString TQFontInfo::family() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+ return engine->fontDef.family;
+}
+
+/*!
+ Returns the point size of the matched window system font.
+
+ \sa TQFont::pointSize()
+*/
+int TQFontInfo::pointSize() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+ return ( engine->fontDef.pointSize + 5 ) / 10;
+}
+
+/*!
+ Returns the pixel size of the matched window system font.
+
+ \sa TQFont::pointSize()
+*/
+int TQFontInfo::pixelSize() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+ return engine->fontDef.pixelSize;
+}
+
+/*!
+ Returns the italic value of the matched window system font.
+
+ \sa TQFont::italic()
+*/
+bool TQFontInfo::italic() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+ return engine->fontDef.italic;
+}
+
+/*!
+ Returns the weight of the matched window system font.
+
+ \sa TQFont::weight(), bold()
+*/
+int TQFontInfo::weight() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+ return engine->fontDef.weight;
+
+}
+
+/*!
+ \fn bool TQFontInfo::bold() const
+
+ Returns TRUE if weight() would return a value greater than \c
+ TQFont::Normal; otherwise returns FALSE.
+
+ \sa weight(), TQFont::bold()
+*/
+
+/*!
+ Returns the underline value of the matched window system font.
+
+ \sa TQFont::underline()
+
+ \internal
+
+ Here we read the underline flag directly from the TQFont.
+ This is OK for X11 and for Windows because we always get what we want.
+*/
+bool TQFontInfo::underline() const
+{
+ return d->underline;
+}
+
+/*!
+ Returns the overline value of the matched window system font.
+
+ \sa TQFont::overline()
+
+ \internal
+
+ Here we read the overline flag directly from the TQFont.
+ This is OK for X11 and for Windows because we always get what we want.
+*/
+bool TQFontInfo::overline() const
+{
+ return d->overline;
+}
+
+/*!
+ Returns the strikeout value of the matched window system font.
+
+ \sa TQFont::strikeOut()
+
+ \internal Here we read the strikeOut flag directly from the TQFont.
+ This is OK for X11 and for Windows because we always get what we want.
+*/
+bool TQFontInfo::strikeOut() const
+{
+ return d->strikeOut;
+}
+
+/*!
+ Returns the fixed pitch value of the matched window system font.
+
+ \sa TQFont::fixedPitch()
+*/
+bool TQFontInfo::fixedPitch() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+#ifdef TQ_OS_MAC
+ if (!engine->fontDef.fixedPitchComputed) {
+ TQChar ch[2] = { TQChar('i'), TQChar('m') };
+ glyph_t g[2];
+ int l = 2;
+ advance_t a[2];
+ engine->stringToCMap(ch, 2, g, a, &l, FALSE);
+ engine->fontDef.fixedPitch = a[0] == a[1];
+ engine->fontDef.fixedPitchComputed = TRUE;
+ }
+#endif
+ return engine->fontDef.fixedPitch;
+}
+
+/*!
+ Returns the style of the matched window system font.
+
+ Currently only returns the style hint set in TQFont.
+
+ \sa TQFont::tqstyleHint() TQFont::StyleHint
+*/
+TQFont::StyleHint TQFontInfo::tqstyleHint() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+ return (TQFont::StyleHint) engine->fontDef.tqstyleHint;
+}
+
+/*!
+ Returns TRUE if the font is a raw mode font; otherwise returns
+ FALSE.
+
+ If it is a raw mode font, all other functions in TQFontInfo will
+ return the same values set in the TQFont, regardless of the font
+ actually used.
+
+ \sa TQFont::rawMode()
+*/
+bool TQFontInfo::rawMode() const
+{
+ return d->rawMode;
+}
+
+/*!
+ Returns TRUE if the matched window system font is exactly the same
+ as the one specified by the font; otherwise returns FALSE.
+
+ \sa TQFont::exactMatch()
+*/
+bool TQFontInfo::exactMatch() const
+{
+ TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return d->rawMode ? engine->type() != TQFontEngine::Box
+ : d->request == engine->fontDef;
+}
+
+
+
+
+// **********************************************************************
+// TQFontCache
+// **********************************************************************
+
+#ifdef TQFONTCACHE_DEBUG
+// fast timeouts for debugging
+static const int fast_timeout = 1000; // 1s
+static const int slow_timeout = 5000; // 5s
+#else
+static const int fast_timeout = 10000; // 10s
+static const int slow_timeout = 300000; // 5m
+#endif // TQFONTCACHE_DEBUG
+
+TQFontCache *TQFontCache::instance = 0;
+const uint TQFontCache::min_cost = 4*1024; // 4mb
+
+static TQSingleCleanupHandler<TQFontCache> cleanup_fontcache;
+
+
+TQFontCache::TQFontCache()
+ : TQObject( tqApp, "global font cache" ), total_cost( 0 ), max_cost( min_cost ),
+ current_timestamp( 0 ), fast( FALSE ), timer_id( -1 )
+{
+ TQ_ASSERT( instance == 0 );
+ instance = this;
+ cleanup_fontcache.set( &instance );
+}
+
+TQFontCache::~TQFontCache()
+{
+ {
+ EngineDataCache::Iterator it = engineDataCache.begin(),
+ end = engineDataCache.end();
+ while ( it != end ) {
+ if ( it.data()->count == 0 )
+ delete it.data();
+ else
+ FC_DEBUG("TQFontCache::~TQFontCache: engineData %p still has refcount %d",
+ it.data(), it.data()->count);
+ ++it;
+ }
+ }
+ EngineCache::Iterator it = engineCache.begin(),
+ end = engineCache.end();
+ while ( it != end ) {
+ if ( it.data().data->count == 0 ) {
+ if ( --it.data().data->cache_count == 0 ) {
+ FC_DEBUG("TQFontCache::~TQFontCache: deleting engine %p key=(%d / %d %d %d %d %d)",
+ it.data().data, it.key().script, it.key().def.pointSize,
+ it.key().def.pixelSize, it.key().def.weight, it.key().def.italic,
+ it.key().def.fixedPitch);
+
+ delete it.data().data;
+ }
+ } else {
+ FC_DEBUG("TQFontCache::~TQFontCache: engine = %p still has refcount %d",
+ it.data().data, it.data().data->count);
+ }
+ ++it;
+ }
+ instance = 0;
+}
+
+#ifdef TQ_WS_TQWS
+void TQFontCache::clear()
+{
+ {
+ EngineDataCache::Iterator it = engineDataCache.begin(),
+ end = engineDataCache.end();
+ while ( it != end ) {
+ TQFontEngineData *data = it.data();
+ if ( data->engine )
+ data->engine->deref();
+ data->engine = 0;
+ ++it;
+ }
+ }
+
+ EngineCache::Iterator it = engineCache.begin(),
+ end = engineCache.end();
+ while ( it != end ) {
+ if ( it.data().data->count == 0 ) {
+ if ( --it.data().data->cache_count == 0 ) {
+ FC_DEBUG("TQFontCache::~TQFontCache: deleting engine %p key=(%d / %d %d %d %d %d)",
+ it.data().data, it.key().script, it.key().def.pointSize,
+ it.key().def.pixelSize, it.key().def.weight, it.key().def.italic,
+ it.key().def.fixedPitch);
+ delete it.data().data;
+ }
+ } else {
+ FC_DEBUG("TQFontCache::~TQFontCache: engine = %p still has refcount %d",
+ it.data().data, it.data().data->count);
+ }
+ ++it;
+ }
+}
+#endif
+
+TQFontEngineData *TQFontCache::tqfindEngineData( const Key &key ) const
+{
+ EngineDataCache::ConstIterator it = engineDataCache.tqfind( key ),
+ end = engineDataCache.end();
+ if ( it == end ) return 0;
+
+ // found
+ return it.data();
+}
+
+void TQFontCache::insertEngineData( const Key &key, TQFontEngineData *engineData )
+{
+ FC_DEBUG( "TQFontCache: inserting new engine data %p", engineData );
+
+ engineDataCache.insert( key, engineData );
+ increaseCost( sizeof( TQFontEngineData ) );
+}
+
+TQFontEngine *TQFontCache::tqfindEngine( const Key &key )
+{
+ EngineCache::Iterator it = engineCache.tqfind( key ),
+ end = engineCache.end();
+ if ( it == end ) return 0;
+
+ // found... update the hitcount and timestamp
+ it.data().hits++;
+ it.data().timestamp = ++current_timestamp;
+
+ FC_DEBUG( "TQFontCache: found font engine\n"
+ " %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'",
+ it.data().data, it.data().timestamp, it.data().hits,
+ it.data().data->count, it.data().data->cache_count,
+ it.data().data->name() );
+
+ return it.data().data;
+}
+
+void TQFontCache::insertEngine( const Key &key, TQFontEngine *engine )
+{
+ FC_DEBUG( "TQFontCache: inserting new engine %p", engine );
+
+ Engine data( engine );
+ data.timestamp = ++current_timestamp;
+
+ engineCache.insert( key, data );
+
+ // only increase the cost if this is the first time we insert the engine
+ if ( engine->cache_count == 0 )
+ increaseCost( engine->cache_cost );
+
+ ++engine->cache_count;
+}
+
+void TQFontCache::increaseCost( uint cost )
+{
+ cost = ( cost + 512 ) / 1024; // store cost in kb
+ cost = cost > 0 ? cost : 1;
+ total_cost += cost;
+
+ FC_DEBUG( " COST: increased %u kb, total_cost %u kb, max_cost %u kb",
+ cost, total_cost, max_cost );
+
+ if ( total_cost > max_cost) {
+ max_cost = total_cost;
+
+ if ( timer_id == -1 || ! fast ) {
+ FC_DEBUG( " TIMER: starting fast timer (%d ms)", fast_timeout );
+
+ if (timer_id != -1) killTimer( timer_id );
+ timer_id = startTimer( fast_timeout );
+ fast = TRUE;
+ }
+ }
+}
+
+void TQFontCache::decreaseCost( uint cost )
+{
+ cost = ( cost + 512 ) / 1024; // cost is stored in kb
+ cost = cost > 0 ? cost : 1;
+ TQ_ASSERT( cost <= total_cost );
+ total_cost -= cost;
+
+ FC_DEBUG( " COST: decreased %u kb, total_cost %u kb, max_cost %u kb",
+ cost, total_cost, max_cost );
+}
+
+#if defined(TQ_WS_WIN ) || defined (TQ_WS_TQWS)
+void TQFontCache::cleanupPrinterFonts()
+{
+ FC_DEBUG( "TQFontCache::cleanupPrinterFonts" );
+
+ {
+ FC_DEBUG( " CLEAN engine data:" );
+
+ // clean out all unused engine datas
+ EngineDataCache::Iterator it = engineDataCache.begin(),
+ end = engineDataCache.end();
+ while ( it != end ) {
+ if ( it.key().screen == 0 ) {
+ ++it;
+ continue;
+ }
+
+ if( it.data()->count > 0 ) {
+#ifdef TQ_WS_WIN
+ for(int i = 0; i < TQFont::LastPrivateScript; ++i) {
+ if( it.data()->engines[i] ) {
+ it.data()->engines[i]->deref();
+ it.data()->engines[i] = 0;
+ }
+ }
+#else
+ if ( it.data()->engine ) {
+ it.data()->engine->deref();
+ it.data()->engine = 0;
+ }
+#endif
+ ++it;
+ } else {
+
+ EngineDataCache::Iterator rem = it++;
+
+ decreaseCost( sizeof( TQFontEngineData ) );
+
+ FC_DEBUG( " %p", rem.data() );
+
+ delete rem.data();
+ engineDataCache.remove( rem );
+ }
+ }
+ }
+
+ EngineCache::Iterator it = engineCache.begin(),
+ end = engineCache.end();
+ while( it != end ) {
+ if ( it.data().data->count > 0 || it.key().screen == 0) {
+ ++it;
+ continue;
+ }
+
+ FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'",
+ it.data().data, it.data().timestamp, it.data().hits,
+ it.data().data->count, it.data().data->cache_count,
+ it.data().data->name() );
+
+ if ( --it.data().data->cache_count == 0 ) {
+ FC_DEBUG( " DELETE: last occurence in cache" );
+
+ decreaseCost( it.data().data->cache_cost );
+ delete it.data().data;
+ }
+
+ engineCache.remove( it++ );
+ }
+}
+#endif
+
+void TQFontCache::timerEvent( TQTimerEvent * )
+{
+ FC_DEBUG( "TQFontCache::timerEvent: performing cache maintenance (timestamp %u)",
+ current_timestamp );
+
+ if ( total_cost <= max_cost && max_cost <= min_cost ) {
+ FC_DEBUG( " cache redused sufficiently, stopping timer" );
+
+ killTimer( timer_id );
+ timer_id = -1;
+ fast = FALSE;
+
+ return;
+ }
+
+ // go through the cache and count up everything in use
+ uint in_use_cost = 0;
+
+ {
+ FC_DEBUG( " SWEEP engine data:" );
+
+ // make sure the cost of each engine data is at least 1kb
+ const uint engine_data_cost =
+ sizeof( TQFontEngineData ) > 1024 ? sizeof( TQFontEngineData ) : 1024;
+
+ EngineDataCache::ConstIterator it = engineDataCache.begin(),
+ end = engineDataCache.end();
+ for ( ; it != end; ++it ) {
+#ifdef TQFONTCACHE_DEBUG
+ FC_DEBUG( " %p: ref %2d", it.data(), it.data()->count );
+
+# if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+ // print out all engines
+ for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) {
+ if ( ! it.data()->engines[i] ) continue;
+ FC_DEBUG( " tqcontains %p", it.data()->engines[i] );
+ }
+# endif // TQ_WS_X11 || TQ_WS_WIN
+#endif // TQFONTCACHE_DEBUG
+
+ if ( it.data()->count > 0 )
+ in_use_cost += engine_data_cost;
+ }
+ }
+
+ {
+ FC_DEBUG( " SWEEP engine:" );
+
+ EngineCache::ConstIterator it = engineCache.begin(),
+ end = engineCache.end();
+ for ( ; it != end; ++it ) {
+ FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes",
+ it.data().data, it.data().timestamp, it.data().hits,
+ it.data().data->count, it.data().data->cache_count,
+ it.data().data->cache_cost );
+
+ if ( it.data().data->count > 0 )
+ in_use_cost += it.data().data->cache_cost / it.data().data->cache_count;
+ }
+
+ // attempt to make up for rounding errors
+ in_use_cost += (uint)engineCache.count();
+ }
+
+ in_use_cost = ( in_use_cost + 512 ) / 1024; // cost is stored in kb
+
+ /*
+ calculate the new maximum cost for the cache
+
+ NOTE: in_use_cost is *not* correct due to rounding errors in the
+ above algorithm. instead of worrying about getting the
+ calculation correct, we are more interested in speed, and use
+ in_use_cost as a floor for new_max_cost
+ */
+ uint new_max_cost = TQMAX( TQMAX( max_cost / 2, in_use_cost ), min_cost );
+
+ FC_DEBUG( " after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb",
+ in_use_cost, total_cost, max_cost, new_max_cost );
+
+ if ( new_max_cost == max_cost ) {
+ if ( fast ) {
+ FC_DEBUG( " cannot shrink cache, slowing timer" );
+
+ killTimer( timer_id );
+ timer_id = startTimer( slow_timeout );
+ fast = FALSE;
+ }
+
+ return;
+ } else if ( ! fast ) {
+ FC_DEBUG( " dropping into passing gear" );
+
+ killTimer( timer_id );
+ timer_id = startTimer( fast_timeout );
+ fast = TRUE;
+ }
+
+ max_cost = new_max_cost;
+
+ {
+ FC_DEBUG( " CLEAN engine data:" );
+
+ // clean out all unused engine datas
+ EngineDataCache::Iterator it = engineDataCache.begin(),
+ end = engineDataCache.end();
+ while ( it != end ) {
+ if ( it.data()->count > 0 ) {
+ ++it;
+ continue;
+ }
+
+ EngineDataCache::Iterator rem = it++;
+
+ decreaseCost( sizeof( TQFontEngineData ) );
+
+ FC_DEBUG( " %p", rem.data() );
+
+ delete rem.data();
+ engineDataCache.remove( rem );
+ }
+ }
+
+ // clean out the engine cache just enough to get below our new max cost
+ uint current_cost;
+ do {
+ current_cost = total_cost;
+
+ EngineCache::Iterator it = engineCache.begin(),
+ end = engineCache.end();
+ // determine the oldest and least popular of the unused engines
+ uint oldest = ~0;
+ uint least_popular = ~0;
+
+ for ( ; it != end; ++it ) {
+ if ( it.data().data->count > 0 ) continue;
+
+ if ( it.data().timestamp < oldest &&
+ it.data().hits <= least_popular ) {
+ oldest = it.data().timestamp;
+ least_popular = it.data().hits;
+ }
+ }
+
+ FC_DEBUG( " oldest %u least popular %u", oldest, least_popular );
+
+ for ( it = engineCache.begin(); it != end; ++it ) {
+ if ( it.data().data->count == 0 &&
+ it.data().timestamp == oldest &&
+ it.data().hits == least_popular)
+ break;
+ }
+
+ if ( it != end ) {
+ FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'",
+ it.data().data, it.data().timestamp, it.data().hits,
+ it.data().data->count, it.data().data->cache_count,
+ it.data().data->name() );
+
+ if ( --it.data().data->cache_count == 0 ) {
+ FC_DEBUG( " DELETE: last occurence in cache" );
+
+ decreaseCost( it.data().data->cache_cost );
+ delete it.data().data;
+ } else {
+ /*
+ this particular font engine is in the cache multiple
+ times... set current_cost to zero, so that we can
+ keep looping to get rid of all occurences
+ */
+ current_cost = 0;
+ }
+
+ engineCache.remove( it );
+ }
+ } while ( current_cost != total_cost && total_cost > max_cost );
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqfont.h b/tqtinterface/qt4/src/kernel/tqfont.h
new file mode 100644
index 0000000..68e9e07
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfont.h
@@ -0,0 +1,524 @@
+/****************************************************************************
+**
+** Definition of TQFont class
+**
+** Created : 940514
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQFONT_H
+#define TQFONT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqstring.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qfont.h>
+
+#endif // USE_QT4
+
+#ifndef USE_QT4
+
+class TQFontPrivate; /* don't touch */
+
+#endif // USE_QT4
+
+class TQStringList;
+class TQTextFormatCollection;
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQFont : public QFont, virtual public TQt
+{
+public:
+ // default font
+ TQFont() : QFont() {}
+ // specific font
+#ifdef TQ_TQDOC
+ TQFont( const QString &family, int pointSize = 12, int weight = Normal, bool italic = FALSE ) : QFont( family, pointSize, weight, italic ) {}
+#else
+ TQFont( const QString &family, int pointSize = -1, int weight = -1, bool italic = FALSE ) : QFont( family, pointSize, weight, italic ) {}
+#endif
+ // copy constructor
+ TQFont( const QFont &qf ) : QFont( qf ) {}
+
+// static QT3_SUPPORT QFont defaultFont();
+// static QT3_SUPPORT void setDefaultFont(const QFont &);
+// QT3_SUPPORT void setPixelSizeFloat(qreal);
+ inline qreal pointSizeFloat() const { return pointSizeF(); }
+ inline void setPointSizeFloat(qreal size) { setPointSizeF(size); }
+
+ // a copy of this lives in qtqunicodetables.cpp, as we can't include
+ // tqfont.h it in tools/. Do not modify without changing the script
+ // enum in qtqunicodetable_p.h as well.
+ enum Script {
+ // European Alphabetic Scripts
+ Latin,
+ Greek,
+ Cyrillic,
+ Armenian,
+ Georgian,
+ Runic,
+ Ogham,
+ SpacingModifiers,
+ CombiningMarks,
+
+ // Middle Eastern Scripts
+ Hebrew,
+ Arabic,
+ Syriac,
+ Thaana,
+
+ // South and Southeast Asian Scripts
+ Devanagari,
+ Bengali,
+ Gurmukhi,
+ Gujarati,
+ Oriya,
+ Tamil,
+ Telugu,
+ Kannada,
+ Malayalam,
+ Sinhala,
+ Thai,
+ Lao,
+ Tibetan,
+ Myanmar,
+ Khmer,
+
+ // East Asian Scripts
+ Han,
+ Hiragana,
+ Katakana,
+ Hangul,
+ Bopomofo,
+ Yi,
+
+ // Additional Scripts
+ Ethiopic,
+ Cherokee,
+ CanadianAboriginal,
+ Mongolian,
+
+ // Symbols
+ CurrencySymbols,
+ LetterlikeSymbols,
+ NumberForms,
+ MathematicalOperators,
+ TechnicalSymbols,
+ GeometricSymbols,
+ MiscellaneousSymbols,
+ EnclosedAndSquare,
+ Braille,
+
+ Unicode,
+
+ // some scripts added in Unicode 3.2
+ Tagalog,
+ Hanunoo,
+ Buhid,
+ Tagbanwa,
+
+ KatakanaHalfWidth,
+
+ // from Unicode 4.0
+ Limbu,
+ TaiLe,
+
+ // End
+#if !defined(TQ_TQDOC)
+ NScripts,
+ UnknownScript = NScripts,
+
+ NoScript,
+
+ // ----------------------------------------
+ // Dear User, you can see values > NScript,
+ // but they are internal - do not touch.
+
+ Han_Japanese,
+ Han_SimplifiedChinese,
+ Han_TraditionalChinese,
+ Han_Korean,
+
+ LastPrivateScript
+#endif
+ };
+
+private:
+ // We need access to these members
+ void tqt_x11SetScreen( int screen = -1 );
+ int tqt_x11Screen() const;
+
+public:
+ friend class TQTextFormatCollection;
+
+public:
+ // Interoperability
+ static const TQFont& convertFromQFont( QFont& qf );
+};
+
+// Interoperability
+inline static const TQFont& convertFromQFont( const QFont& qf ) {
+ return (*static_cast<const TQFont*>(&qf));
+}
+
+#else // USE_QT4
+
+class TQ_EXPORT TQFont
+{
+public:
+ enum StyleHint {
+ Helvetica, SansSerif = Helvetica,
+ Times, Serif = Times,
+ Courier, TypeWriter = Courier,
+ OldEnglish, Decorative = OldEnglish,
+ System,
+ AnyStyle
+ };
+
+ enum StyleStrategy {
+ PreferDefault = 0x0001,
+ PreferBitmap = 0x0002,
+ PreferDevice = 0x0004,
+ PreferOutline = 0x0008,
+ ForceOutline = 0x0010,
+ PreferMatch = 0x0020,
+ PreferQuality = 0x0040,
+ PreferAntialias = 0x0080,
+ NoAntialias = 0x0100,
+ OpenGLCompatible = 0x0200
+ };
+
+ enum Weight {
+ Light = 25,
+ Normal = 50,
+ DemiBold = 63,
+ Bold = 75,
+ Black = 87
+ };
+
+ enum Stretch {
+ UltraCondensed = 50,
+ ExtraCondensed = 62,
+ Condensed = 75,
+ SemiCondensed = 87,
+ Unstretched = 100,
+ SemiExpanded = 112,
+ Expanded = 125,
+ ExtraExpanded = 150,
+ UltraExpanded = 200
+ };
+
+ // default font
+ TQFont();
+ // specific font
+#ifdef TQ_TQDOC
+ TQFont( const TQString &family, int pointSize = 12, int weight = Normal,
+ bool italic = FALSE );
+#else
+ TQFont( const TQString &family, int pointSize = -1, int weight = -1,
+ bool italic = FALSE );
+#endif
+ // copy constructor
+ TQFont( const TQFont & );
+
+ ~TQFont();
+
+ TQString family() const;
+ void setFamily( const TQString &);
+
+ int pointSize() const;
+ float pointSizeFloat() const;
+ void setPointSize( int );
+ void setPointSizeFloat( float );
+
+ int pixelSize() const;
+ void setPixelSize( int );
+ void setPixelSizeFloat( float );
+
+ int weight() const;
+ void setWeight( int );
+
+ bool bold() const;
+ void setBold( bool );
+
+ bool italic() const;
+ void setItalic( bool );
+
+ bool underline() const;
+ void setUnderline( bool );
+
+ bool overline() const;
+ void setOverline( bool );
+
+ bool strikeOut() const;
+ void setStrikeOut( bool );
+
+ bool fixedPitch() const;
+ void setFixedPitch( bool );
+
+ StyleHint tqstyleHint() const;
+ StyleStrategy styleStrategy() const;
+ void setStyleHint( StyleHint, StyleStrategy = PreferDefault );
+ void setStyleStrategy( StyleStrategy s );
+
+ int stretch() const;
+ void setStretch( int );
+
+ // is raw mode still needed?
+ bool rawMode() const;
+ void setRawMode( bool );
+
+ // dupicated from TQFontInfo
+ bool exactMatch() const;
+
+ TQFont &operator=( const TQFont & );
+ bool operator==( const TQFont & ) const;
+ bool operator!=( const TQFont & ) const;
+ bool isCopyOf( const TQFont & ) const;
+
+
+#ifdef TQ_WS_WIN
+ HFONT handle() const;
+#else // !TQ_WS_WIN
+ TQt::HANDLE handle() const;
+#endif // TQ_WS_WIN
+
+
+ // needed for X11
+ void setRawName( const TQString & );
+ TQString rawName() const;
+
+ TQString key() const;
+
+ TQString toString() const;
+ bool fromString(const TQString &);
+
+#ifndef TQT_NO_STRINGLIST
+ static TQString substitute(const TQString &);
+ static TQStringList substitutes(const TQString &);
+ static TQStringList substitutions();
+ static void insertSubstitution(const TQString&, const TQString &);
+ static void insertSubstitutions(const TQString&, const TQStringList &);
+ static void removeSubstitution(const TQString &);
+#endif //TQT_NO_STRINGLIST
+ static void initialize();
+ static void cleanup();
+#ifndef TQ_WS_TQWS
+ static void cacheStatistics();
+#endif
+
+#if defined(TQ_WS_TQWS)
+ void qwsRenderToDisk(bool all=TRUE);
+#endif
+
+
+ // a copy of this lives in qtqunicodetables.cpp, as we can't include
+ // tqfont.h it in tools/. Do not modify without changing the script
+ // enum in qtqunicodetable_p.h aswell.
+ enum Script {
+ // European Alphabetic Scripts
+ Latin,
+ Greek,
+ Cyrillic,
+ Armenian,
+ Georgian,
+ Runic,
+ Ogham,
+ SpacingModifiers,
+ CombiningMarks,
+
+ // Middle Eastern Scripts
+ Hebrew,
+ Arabic,
+ Syriac,
+ Thaana,
+
+ // South and Southeast Asian Scripts
+ Devanagari,
+ Bengali,
+ Gurmukhi,
+ Gujarati,
+ Oriya,
+ Tamil,
+ Telugu,
+ Kannada,
+ Malayalam,
+ Sinhala,
+ Thai,
+ Lao,
+ Tibetan,
+ Myanmar,
+ Khmer,
+
+ // East Asian Scripts
+ Han,
+ Hiragana,
+ Katakana,
+ Hangul,
+ Bopomofo,
+ Yi,
+
+ // Additional Scripts
+ Ethiopic,
+ Cherokee,
+ CanadianAboriginal,
+ Mongolian,
+
+ // Symbols
+ CurrencySymbols,
+ LetterlikeSymbols,
+ NumberForms,
+ MathematicalOperators,
+ TechnicalSymbols,
+ GeometricSymbols,
+ MiscellaneousSymbols,
+ EnclosedAndSquare,
+ Braille,
+
+ Unicode,
+
+ // some scripts added in Unicode 3.2
+ Tagalog,
+ Hanunoo,
+ Buhid,
+ Tagbanwa,
+
+ KatakanaHalfWidth,
+
+ // from Unicode 4.0
+ Limbu,
+ TaiLe,
+
+ // End
+#if !defined(TQ_TQDOC)
+ NScripts,
+ UnknownScript = NScripts,
+
+ NoScript,
+
+ // ----------------------------------------
+ // Dear User, you can see values > NScript,
+ // but they are internal - do not touch.
+
+ Han_Japanese,
+ Han_SimplifiedChinese,
+ Han_TraditionalChinese,
+ Han_Korean,
+
+ LastPrivateScript
+#endif
+ };
+
+ TQString defaultFamily() const;
+ TQString lastResortFamily() const;
+ TQString lastResortFont() const;
+
+#ifndef TQT_NO_COMPAT
+
+ static TQFont defaultFont();
+ static void setDefaultFont( const TQFont & );
+
+#endif // TQT_NO_COMPAT
+
+ TQFont resolve( const TQFont & ) const;
+
+protected:
+ // why protected?
+ bool dirty() const;
+ int deciPointSize() const;
+
+private:
+ TQFont( TQFontPrivate *, TQPaintDevice *pd );
+
+ void detach();
+
+#if defined(TQ_WS_MAC)
+ void macSetFont(TQPaintDevice *);
+#elif defined(TQ_WS_X11)
+ void x11SetScreen( int screen = -1 );
+ int x11Screen() const;
+#endif
+
+ friend class TQFontMetrics;
+ friend class TQFontInfo;
+ friend class TQPainter;
+ friend class TQPSPrinterFont;
+ friend class TQApplication;
+ friend class TQWidget;
+ friend class TQTextFormatCollection;
+ friend class TQTextLayout;
+ friend class TQTextItem;
+ friend class TQGLContext;
+#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+ friend TQt::HANDLE qt_xft_handle(const TQFont &font);
+#endif
+#ifndef TQT_NO_DATASTREAM
+ friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQFont & );
+ friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQFont & );
+#endif
+
+ TQFontPrivate *d;
+};
+
+
+inline bool TQFont::bold() const
+{ return weight() > Normal; }
+
+
+inline void TQFont::setBold( bool enable )
+{ setWeight( enable ? Bold : Normal ); }
+
+
+
+
+/*****************************************************************************
+ TQFont stream functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQFont & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQFont & );
+#endif
+
+#endif // USE_QT4
+
+#endif // TQFONT_H
diff --git a/tqtinterface/qt4/src/kernel/tqfont_x11.cpp b/tqtinterface/qt4/src/kernel/tqfont_x11.cpp
new file mode 100644
index 0000000..84ea2d6
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfont_x11.cpp
@@ -0,0 +1,747 @@
+/****************************************************************************
+**
+** Implementation of TQFont, TQFontMetrics and TQFontInfo classes for X11
+**
+** Created : 940515
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#define TQT_FATAL_ASSERT
+
+// REVISED: brad
+
+#include "tqplatformdefs.h"
+
+#include "tqfont.h"
+#include "tqapplication.h"
+#include "tqcleanuphandler.h"
+#include "tqfontinfo.h"
+#include "tqfontdatabase.h"
+#include "tqfontmetrics.h"
+#include "tqpaintdevice.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqtextcodec.h"
+
+#include <private/tqfontcodecs_p.h>
+#include <private/tqunicodetables_p.h>
+#include "tqfontdata_p.h"
+#include "tqfontengine_p.h"
+#include "tqtextengine_p.h"
+
+#include "tqt_x11_p.h"
+
+#include <time.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#define TQFONTLOADER_DEBUG
+#define TQFONTLOADER_DEBUG_VERBOSE
+
+#ifdef USE_QT4
+
+TQFont::Script TQFontPrivate::defaultScript = TQFont::UnknownScript;
+int TQFontPrivate::defaultEncodingID = -1;
+TQ_EXPORT bool qt_has_xft = FALSE;
+
+#else // USE_QT4
+
+TQ_EXPORT bool qt_has_xft = FALSE;
+
+#ifndef TQT_NO_XFTFREETYPE
+TQt::HANDLE qt_xft_handle(const TQFont &font)
+{
+ TQFontEngine *engine = font.d->engineForScript( TQFontPrivate::defaultScript );
+ if (!engine->type() == TQFontEngine::Xft)
+ return 0;
+ return (long)static_cast<TQFontEngineXft *>(engine)->font();
+}
+#endif
+
+double qt_pixelSize(double pointSize, TQPaintDevice *painttqdevice, int scr)
+{
+ if (pointSize < 0) return -1.;
+
+ double result = pointSize;
+ if (painttqdevice && TQPaintDeviceMetrics( painttqdevice ).logicalDpiY() != 75)
+ result *= TQPaintDeviceMetrics( painttqdevice ).logicalDpiY() / 72.;
+ else if (TQPaintDevice::x11AppDpiY( scr ) != 75)
+ result *= TQPaintDevice::x11AppDpiY( scr ) / 72.;
+
+ return result;
+}
+
+double qt_pointSize(double pixelSize, TQPaintDevice *painttqdevice, int scr)
+{
+ if (pixelSize < 0) return -1.;
+
+ double result = pixelSize;
+ if ( painttqdevice && TQPaintDeviceMetrics( painttqdevice ).logicalDpiY() != 75)
+ result *= 72. / TQPaintDeviceMetrics( painttqdevice ).logicalDpiY();
+ else if (TQPaintDevice::x11AppDpiY(scr) != 75)
+ result *= 72. / TQPaintDevice::x11AppDpiY( scr );
+
+ return result;
+}
+
+static inline double pixelSize( const TQFontDef &request, TQPaintDevice *painttqdevice,
+ int scr )
+{
+ return ((request.pointSize != -1) ?
+ qt_pixelSize(request.pointSize / 10., painttqdevice, scr) :
+ (double)request.pixelSize);
+}
+
+static inline double pointSize( const TQFontDef &request, TQPaintDevice *painttqdevice,
+ int scr )
+{
+ return ((request.pixelSize != -1) ?
+ qt_pointSize(request.pixelSize, painttqdevice, scr) * 10.:
+ (double)request.pointSize);
+}
+
+
+/*
+ Removes wildcards from an XLFD.
+
+ Returns \a xlfd with all wildcards removed if a match for \a xlfd is
+ found, otherwise it returns \a xlfd.
+*/
+static TQCString qt_fixXLFD( const TQCString &xlfd )
+{
+ TQCString ret = xlfd;
+ int count = 0;
+ char **fontNames =
+ XListFonts( TQPaintDevice::x11AppDisplay(), xlfd, 32768, &count );
+ if ( count > 0 )
+ ret = fontNames[0];
+ XFreeFontNames( fontNames );
+ return ret ;
+}
+
+typedef TQMap<TQFont::Script,TQString> FallbackMap;
+static FallbackMap *fallbackMap = 0;
+static TQSingleCleanupHandler<FallbackMap> qt_fallback_font_family_cleanup;
+
+static void ensure_fallback_map()
+{
+ if ( fallbackMap ) return;
+ fallbackMap = new FallbackMap;
+ qt_fallback_font_family_cleanup.set( &fallbackMap );
+}
+
+// Returns the user-configured fallback family for the specified script.
+TQString qt_fallback_font_family( TQFont::Script script )
+{
+ TQString ret;
+
+ if ( fallbackMap ) {
+ FallbackMap::ConstIterator it, end = fallbackMap->end();
+ it = fallbackMap->tqfind( script );
+ if ( it != end )
+ ret = it.data();
+ }
+
+ return ret;
+}
+
+// Sets the fallback family for the specified script.
+void qt_set_fallback_font_family( TQFont::Script script, const TQString &family )
+{
+ ensure_fallback_map();
+
+ if ( ! family.isEmpty() )
+ fallbackMap->insert( script, family );
+ else
+ fallbackMap->remove( script );
+}
+
+
+TQFont::Script TQFontPrivate::defaultScript = TQFont::UnknownScript;
+int TQFontPrivate::defaultEncodingID = -1;
+
+/*!
+ Internal function that initializes the font system.
+
+ \internal
+ The font cache and font dict do not alloc the keys. The key is a TQString
+ which is shared between TQFontPrivate and TQXFontName.
+*/
+void TQFont::initialize()
+{
+ // create global font cache
+ if ( ! TQFontCache::instance ) (void) new TQFontCache;
+
+#ifndef TQT_NO_CODECS
+#ifndef TQT_NO_BIG_CODECS
+ static bool codecs_once = FALSE;
+ if ( ! codecs_once ) {
+ (void) new TQFontJis0201Codec;
+ (void) new TQFontJis0208Codec;
+ (void) new TQFontKsc5601Codec;
+ (void) new TQFontGb2312Codec;
+ (void) new TQFontGbkCodec;
+ (void) new TQFontGb18030_0Codec;
+ (void) new TQFontBig5Codec;
+ (void) new TQFontBig5hkscsCodec;
+ (void) new TQFontLaoCodec;
+ codecs_once = TRUE;
+ }
+#endif // TQT_NO_BIG_CODECS
+#endif // TQT_NO_CODECS
+
+ extern int qt_encoding_id_for_mib( int mib ); // from qfontdatabase_x11.cpp
+ TQTextCodec *codec = TQTextCodec::codecForLocale();
+ // determine the default encoding id using the locale, otherwise
+ // fallback to latin1 ( mib == 4 )
+ int mib = codec ? codec->mibEnum() : 4;
+
+ // for asian locales, use the mib for the font codec instead of the locale codec
+ switch (mib) {
+ case 38: // eucKR
+ mib = 36;
+ break;
+
+ case 2025: // GB2312
+ mib = 57;
+ break;
+
+ case 113: // GBK
+ mib = -113;
+ break;
+
+ case 114: // GB18030
+ mib = -114;
+ break;
+
+ case 2026: // Big5
+ mib = -2026;
+ break;
+
+ case 2101: // Big5-HKSCS
+ mib = -2101;
+ break;
+
+ case 16: // JIS7
+ mib = 15;
+ break;
+
+ case 17: // SJIS
+ case 18: // eucJP
+ mib = 63;
+ break;
+ }
+
+ // get the default encoding id for the locale encoding...
+ TQFontPrivate::defaultEncodingID = qt_encoding_id_for_mib( mib );
+
+ // get some sample text based on the users locale. we use this to determine the
+ // default script for the font system
+ TQCString oldlctime = setlocale(LC_TIME, 0);
+ TQCString lctime = setlocale(LC_TIME, "");
+
+ time_t ttmp = time(0);
+ struct tm *tt = 0;
+ char samp[64];
+ TQString sample;
+
+ if ( ttmp != -1 ) {
+#if defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+ // use the reentrant versions of localtime() where available
+ tm res;
+ tt = localtime_r( &ttmp, &res );
+#else
+ tt = localtime( &ttmp );
+#endif // TQT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS
+
+ if ( tt != 0 && strftime( samp, 64, "%A%B", tt ) > 0 )
+ if ( codec )
+ sample = codec->toUnicode( samp );
+ }
+
+ if ( ! sample.isNull() && ! sample.isEmpty() ) {
+ TQFont::Script cs = TQFont::NoScript, tmp;
+ const TQChar *uc = sample.tqunicode();
+ TQFontPrivate *priv = new TQFontPrivate;
+
+ for ( uint i = 0; i < sample.length(); i++ ) {
+ SCRIPT_FOR_CHAR( tmp, *uc );
+ uc++;
+ if ( tmp != cs && tmp != TQFont::UnknownScript ) {
+ cs = tmp;
+ break;
+ }
+ }
+ delete priv;
+
+ if ( cs != TQFont::UnknownScript )
+ TQFontPrivate::defaultScript = cs;
+ }
+
+ setlocale( LC_TIME, oldlctime.data() );
+}
+
+/*! \internal
+
+ Internal function that cleans up the font system.
+*/
+void TQFont::cleanup()
+{
+ // delete the global font cache
+ delete TQFontCache::instance;
+}
+
+/*!
+ \internal
+ X11 Only: Returns the screen with which this font is associated.
+*/
+int TQFont::x11Screen() const
+{
+ return d->screen;
+}
+
+/*! \internal
+ X11 Only: Associate the font with the specified \a screen.
+*/
+void TQFont::x11SetScreen( int screen )
+{
+ if ( screen < 0 ) // assume default
+ screen = TQPaintDevice::x11AppScreen();
+
+ if ( screen == d->screen )
+ return; // nothing to do
+
+ detach();
+ d->screen = screen;
+}
+
+/*! \internal
+ Returns a TQFontEngine for the specified \a script that matches the
+ TQFontDef \e request member variable.
+*/
+void TQFontPrivate::load( TQFont::Script script )
+{
+ // NOTE: the X11 and Windows implementations of this function are
+ // identical... if you change one, change both.
+
+#ifdef TQT_CHECK_STATE
+ // sanity checks
+ if (!TQFontCache::instance)
+ qWarning("Must construct a TQApplication before a TQFont");
+ TQ_ASSERT( script >= 0 && script < TQFont::LastPrivateScript );
+#endif // TQT_CHECK_STATE
+
+ TQFontDef req = request;
+ req.pixelSize = tqRound(pixelSize(req, painttqdevice, screen));
+ req.pointSize = 0;
+
+ if ( ! engineData ) {
+ TQFontCache::Key key( req, TQFont::NoScript, screen, painttqdevice );
+
+ // look for the requested font in the engine data cache
+ engineData = TQFontCache::instance->tqfindEngineData( key );
+
+ if ( ! engineData ) {
+ // create a new one
+ engineData = new TQFontEngineData;
+ TQFontCache::instance->insertEngineData( key, engineData );
+ } else {
+ engineData->ref();
+ }
+ }
+
+ // the cached engineData could have already loaded the engine we want
+ if ( engineData->engines[script] ) return;
+
+ // load the font
+ TQFontEngine *engine = 0;
+ // double scale = 1.0; // ### TODO: fix the scale calculations
+
+ // list of families to try
+ TQStringList family_list;
+
+ if (!req.family.isEmpty()) {
+ family_list = TQStringList::split( ',', req.family );
+
+ // append the substitute list for each family in family_list
+ TQStringList subs_list;
+ TQStringList::ConstIterator it = family_list.begin(), end = family_list.end();
+ for ( ; it != end; ++it )
+ subs_list += TQFont::substitutes( *it );
+ family_list += subs_list;
+
+#ifndef TQT_XFT2
+ // with Xft2, we want to use fontconfig to determine better fallbacks,
+ // otherwise we might run into trouble with default fonts as "serif"
+
+ // append the default fallback font for the specified script
+ TQString fallback = qt_fallback_font_family( script );
+ if ( ! fallback.isEmpty() && ! family_list.tqcontains( fallback ) )
+ family_list << fallback;
+
+ // add the default family
+ TQString defaultFamily = TQApplication::font().family();
+ if ( ! family_list.tqcontains( defaultFamily ) )
+ family_list << defaultFamily;
+
+ // add TQFont::defaultFamily() to the list, for compatibility with
+ // previous versions
+ family_list << TQApplication::font().defaultFamily();
+#endif // TQT_XFT2
+ }
+
+ // null family means tqfind the first font matching the specified script
+ family_list << TQString::null;
+
+ TQStringList::ConstIterator it = family_list.begin(), end = family_list.end();
+ for ( ; ! engine && it != end; ++it ) {
+ req.family = *it;
+
+ engine = TQFontDatabase::tqfindFont( script, this, req );
+ if ( engine ) {
+ if ( engine->type() != TQFontEngine::Box )
+ break;
+
+ if ( ! req.family.isEmpty() )
+ engine = 0;
+
+ continue;
+ }
+ }
+
+ engine->ref();
+ engineData->engines[script] = engine;
+}
+
+/*!
+ Returns TRUE if the font attributes have been changed and the font
+ has to be (re)loaded; otherwise returns FALSE.
+*/
+bool TQFont::dirty() const
+{
+ return d->engineData == 0;
+}
+
+/*!
+ Returns the window system handle to the font, for low-level
+ access. Using this function is \e not portable.
+*/
+TQt::HANDLE TQFont::handle() const
+{
+ TQFontEngine *engine = d->engineForScript( TQFontPrivate::defaultScript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ switch ( engine->type() ) {
+ case TQFontEngine::XLFD:
+ return ((TQFontEngineXLFD *) engine)->handle();
+ case TQFontEngine::LatinXLFD:
+ return ((TQFontEngineLatinXLFD *) engine)->handle();
+
+ default: break;
+ }
+ return 0;
+}
+
+/*!
+ Returns the name of the font within the underlying window system.
+
+ On Windows, this is usually just the family name of a TrueType
+ font.
+
+ On X11, it is an XLFD (X Logical Font Description). When TQt is
+ build with Xft support on X11, the return value can be an Xft
+ pattern or an XLFD.
+
+ Using the return value of this function is usually \e not \e
+ portable.
+
+ \sa setRawName()
+*/
+TQString TQFont::rawName() const
+{
+ TQFontEngine *engine = d->engineForScript( TQFontPrivate::defaultScript );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ return TQString::tqfromLatin1( engine->name() );
+}
+
+/*!
+ Sets a font by its system specific name. The function is
+ particularly useful under X, where system font settings (for
+ example X resources) are usually available in XLFD (X Logical Font
+ Description) form only. You can pass an XLFD as \a name to this
+ function.
+
+ A font set with setRawName() is still a full-featured TQFont. It can
+ be queried (for example with italic()) or modified (for example with
+ setItalic()) and is therefore also suitable for rendering rich text.
+
+ If TQt's internal font database cannot resolve the raw name, the
+ font becomes a raw font with \a name as its family.
+
+ Note that the present implementation does not handle wildcards in
+ XLFDs well, and that font aliases (file \c fonts.alias in the font
+ directory on X11) are not supported.
+
+ \sa rawName(), setRawMode(), setFamily()
+*/
+void TQFont::setRawName( const TQString &name )
+{
+ detach();
+
+ // from qfontdatabase_x11.cpp
+ extern bool qt_fillFontDef( const TQCString &xlfd, TQFontDef *fd, int screen );
+
+ if ( ! qt_fillFontDef( qt_fixXLFD( name.latin1() ), &d->request, d->screen ) ) {
+#ifdef TQT_CHECK_STATE
+ qWarning("TQFont::setRawName(): Invalid XLFD: \"%s\"", name.latin1());
+#endif // TQT_CHECK_STATE
+
+ setFamily( name );
+ setRawMode( TRUE );
+ } else {
+ d->tqmask = TQFontPrivate::Complete;
+ }
+}
+
+/*!
+ Returns the "last resort" font family name.
+
+ The current implementation tries a wide variety of common fonts,
+ returning the first one it tqfinds. Is is possible that no family is
+ found in which case a null string is returned.
+
+ \sa lastResortFont()
+*/
+TQString TQFont::lastResortFamily() const
+{
+ return TQString::tqfromLatin1( "Helvetica" );
+}
+
+/*!
+ Returns the family name that corresponds to the current style
+ hint.
+
+ \sa StyleHint tqstyleHint() setStyleHint()
+*/
+TQString TQFont::defaultFamily() const
+{
+ switch ( d->request.tqstyleHint ) {
+ case TQFont::Times:
+ return TQString::tqfromLatin1( "Times" );
+
+ case TQFont::Courier:
+ return TQString::tqfromLatin1( "Courier" );
+
+ case TQFont::Decorative:
+ return TQString::tqfromLatin1( "Old English" );
+
+ case TQFont::Helvetica:
+ case TQFont::System:
+ default:
+ return TQString::tqfromLatin1( "Helvetica" );
+ }
+}
+
+/*
+ Returns a last resort raw font name for the font matching algorithm.
+ This is used if even the last resort family is not available. It
+ returns \e something, almost no matter what. The current
+ implementation tries a wide variety of common fonts, returning the
+ first one it tqfinds. The implementation may change at any time.
+*/
+static const char * const tryFonts[] = {
+ "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*",
+ "-*-courier-medium-r-*-*-*-120-*-*-*-*-*-*",
+ "-*-times-medium-r-*-*-*-120-*-*-*-*-*-*",
+ "-*-lucida-medium-r-*-*-*-120-*-*-*-*-*-*",
+ "-*-helvetica-*-*-*-*-*-120-*-*-*-*-*-*",
+ "-*-courier-*-*-*-*-*-120-*-*-*-*-*-*",
+ "-*-times-*-*-*-*-*-120-*-*-*-*-*-*",
+ "-*-lucida-*-*-*-*-*-120-*-*-*-*-*-*",
+ "-*-helvetica-*-*-*-*-*-*-*-*-*-*-*-*",
+ "-*-courier-*-*-*-*-*-*-*-*-*-*-*-*",
+ "-*-times-*-*-*-*-*-*-*-*-*-*-*-*",
+ "-*-lucida-*-*-*-*-*-*-*-*-*-*-*-*",
+ "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*",
+ "6x13",
+ "7x13",
+ "8x13",
+ "9x15",
+ "fixed",
+ 0
+};
+
+// Returns TRUE if the font exists, FALSE otherwise
+static bool fontExists( const TQString &fontName )
+{
+ int count;
+ char **fontNames = XListFonts( TQPaintDevice::x11AppDisplay(),
+ (char*)fontName.latin1(), 32768, &count );
+ if ( fontNames ) XFreeFontNames( fontNames );
+
+ return count != 0;
+}
+
+/*!
+ Returns a "last resort" font name for the font matching algorithm.
+ This is used if the last resort family is not available. It will
+ always return a name, if necessary returning something like
+ "fixed" or "system".
+
+ The current implementation tries a wide variety of common fonts,
+ returning the first one it tqfinds. The implementation may change
+ at any time, but this function will always return a string
+ containing something.
+
+ It is theoretically possible that there really isn't a
+ lastResortFont() in which case TQt will abort with an error
+ message. We have not been able to identify a case where this
+ happens. Please \link bughowto.html report it as a bug\endlink if
+ it does, preferably with a list of the fonts you have installed.
+
+ \sa lastResortFamily() rawName()
+*/
+TQString TQFont::lastResortFont() const
+{
+ static TQString last;
+
+ // already found
+ if ( ! last.isNull() )
+ return last;
+
+ int i = 0;
+ const char* f;
+
+ while ( ( f = tryFonts[i] ) ) {
+ last = TQString::tqfromLatin1( f );
+
+ if ( fontExists( last ) )
+ return last;
+
+ i++;
+ }
+
+#if defined(CHECK_NULL)
+ qFatal( "TQFontPrivate::lastResortFont: Cannot find any reasonable font" );
+#endif
+
+ return last;
+}
+
+
+
+
+// **********************************************************************
+// TQFontMetrics member methods
+// **********************************************************************
+
+int TQFontMetrics::width( TQChar ch ) const
+{
+ unsigned short uc = ch.tqunicode();
+ if ( uc < TQFontEngineData::widthCacheSize &&
+ d->engineData && d->engineData->widthCache[ uc ] )
+ return d->engineData->widthCache[ uc ];
+
+ if ( ::category( ch ) == TQChar::Mark_NonSpacing || qIsZeroWidthChar(ch.tqunicode()))
+ return 0;
+
+ TQFont::Script script;
+ SCRIPT_FOR_CHAR( script, ch );
+
+ TQFontEngine *engine = d->engineForScript( script );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ glyph_t glyphs[8];
+ advance_t advances[8];
+ int nglyphs = 7;
+ engine->stringToCMap( &ch, 1, glyphs, advances, &nglyphs, FALSE );
+
+ // ### can nglyphs != 1 happen at all? Not currently I think
+ if ( uc < TQFontEngineData::widthCacheSize && advances[0] > 0 && advances[0] < 0x100 )
+ d->engineData->widthCache[ uc ] = advances[0];
+
+ return advances[0];
+}
+
+
+int TQFontMetrics::charWidth( const TQString &str, int pos ) const
+{
+ if ( pos < 0 || pos > (int)str.length() )
+ return 0;
+
+ const TQChar &ch = str.tqunicode()[ pos ];
+ if ( ch.tqunicode() < TQFontEngineData::widthCacheSize &&
+ d->engineData && d->engineData->widthCache[ ch.tqunicode() ] )
+ return d->engineData->widthCache[ ch.tqunicode() ];
+
+ TQFont::Script script;
+ SCRIPT_FOR_CHAR( script, ch );
+
+ int width;
+
+ if ( script >= TQFont::Arabic && script <= TQFont::Khmer ) {
+ // complex script shaping. Have to do some hard work
+ int from = TQMAX( 0, pos - 8 );
+ int to = TQMIN( (int)str.length(), pos + 8 );
+ TQConstString cstr( str.tqunicode()+from, to-from);
+ TQTextEngine tqlayout( cstr.string(), d );
+ tqlayout.itemize( TQTextEngine::WidthOnly );
+ width = tqlayout.width( pos-from, 1 );
+ } else if ( ::category( ch ) == TQChar::Mark_NonSpacing || qIsZeroWidthChar(ch.tqunicode())) {
+ width = 0;
+ } else {
+ TQFontEngine *engine = d->engineForScript( script );
+#ifdef TQT_CHECK_STATE
+ TQ_ASSERT( engine != 0 );
+#endif // TQT_CHECK_STATE
+
+ glyph_t glyphs[8];
+ advance_t advances[8];
+ int nglyphs = 7;
+ engine->stringToCMap( &ch, 1, glyphs, advances, &nglyphs, FALSE );
+ width = advances[0];
+ }
+ if ( ch.tqunicode() < TQFontEngineData::widthCacheSize && width > 0 && width < 0x100 )
+ d->engineData->widthCache[ ch.tqunicode() ] = width;
+ return width;
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqfontdata_p.h b/tqtinterface/qt4/src/kernel/tqfontdata_p.h
new file mode 100644
index 0000000..b6d7a54
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontdata_p.h
@@ -0,0 +1,278 @@
+/****************************************************************************
+**
+** Definition of internal TQFontData struct
+**
+** Created : 941229
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQFONTDATA_P_H
+#define TQFONTDATA_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#include "tqobject.h"
+#include "tqfont.h"
+#include "tqpaintdevicemetrics.h"
+
+// forwards
+class TQFontEngine;
+class TQPaintDevice;
+
+
+struct TQFontDef
+{
+ inline TQFontDef()
+ : pointSize( -1 ), pixelSize( -1 ),
+ tqstyleHint( TQFont::AnyStyle ), styleStrategy( TQFont::PreferDefault ),
+ weight( 50 ), italic( FALSE ), fixedPitch( FALSE ), stretch( 100 ),
+ ignorePitch(TRUE)
+#ifdef TQ_WS_MAC
+ ,fixedPitchComputed(FALSE)
+#endif
+ {
+ }
+
+ TQString family;
+
+#ifdef TQ_WS_X11
+ TQString addStyle;
+#endif // TQ_WS_X11
+
+ int pointSize;
+ int pixelSize;
+
+ uint tqstyleHint : 8;
+ uint styleStrategy : 16;
+
+ uint weight : 7; // 0-99
+ uint italic : 1;
+ uint fixedPitch : 1;
+ uint stretch : 12; // 0-400
+
+ uint ignorePitch : 1;
+ uint fixedPitchComputed : 1; // for Mac OS X only
+ uint reserved : 14; // for future extensions
+
+ bool operator==( const TQFontDef &other ) const;
+ inline bool operator<( const TQFontDef &other ) const
+ {
+ if ( pixelSize != other.pixelSize ) return pixelSize < other.pixelSize;
+ if ( weight != other.weight ) return weight < other.weight;
+ if ( italic != other.italic ) return italic < other.italic;
+ if ( stretch != other.stretch ) return stretch < other.stretch;
+ if ( tqstyleHint != other.tqstyleHint ) return tqstyleHint < other.tqstyleHint;
+ if ( styleStrategy != other.styleStrategy ) return styleStrategy < other.styleStrategy;
+ if ( family != other.family ) return family < other.family;
+
+#ifdef TQ_WS_X11
+ if ( addStyle != other.addStyle ) return addStyle < other.addStyle;
+#endif // TQ_WS_X11
+
+ return FALSE;
+ }
+};
+
+class TQFontEngineData : public TQShared
+{
+public:
+ TQFontEngineData();
+ ~TQFontEngineData();
+
+ uint lineWidth;
+
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+ TQFontEngine *engines[TQFont::LastPrivateScript];
+#else
+ TQFontEngine *engine;
+#endif // TQ_WS_X11 || TQ_WS_WIN
+#ifndef TQ_WS_MAC
+ enum { widthCacheSize = 0x500 };
+ uchar widthCache[widthCacheSize];
+#endif
+};
+
+
+class TQFontPrivate : public TQShared
+{
+public:
+ static TQFont::Script defaultScript;
+#ifdef TQ_WS_X11
+ static int defaultEncodingID;
+#endif // TQ_WS_X11
+
+ TQFontPrivate();
+ TQFontPrivate( const TQFontPrivate &other );
+ ~TQFontPrivate();
+
+ void load( TQFont::Script script );
+ TQFontEngine *engineForScript( TQFont::Script script ) const {
+ if ( script == TQFont::NoScript )
+ script = TQFontPrivate::defaultScript;
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+ if ( ! engineData || ! engineData->engines[script] )
+ ((TQFontPrivate *) this)->load( script );
+ return engineData->engines[script];
+#else
+ if ( ! engineData || ! engineData->engine )
+ ((TQFontPrivate *) this)->load( script );
+ return engineData->engine;
+#endif // TQ_WS_X11 || TQ_WS_WIN
+ }
+
+ TQFontDef request;
+ TQFontEngineData *engineData;
+ TQPaintDevice *painttqdevice;
+ int screen;
+
+ uint rawMode : 1;
+ uint underline : 1;
+ uint overline : 1;
+ uint strikeOut : 1;
+
+ enum {
+ Family = 0x0001,
+ Size = 0x0002,
+ StyleHint = 0x0004,
+ StyleStrategy = 0x0008,
+ Weight = 0x0010,
+ Italic = 0x0020,
+ Underline = 0x0040,
+ Overline = 0x0080,
+ StrikeOut = 0x0100,
+ FixedPitch = 0x0200,
+ Stretch = 0x0400,
+ Complete = 0x07ff
+ };
+
+ uint tqmask;
+
+ void resolve( const TQFontPrivate *other );
+};
+
+
+class TQFontCache : public TQObject
+{
+public:
+ static TQFontCache *instance;
+
+ TQFontCache();
+ ~TQFontCache();
+
+#ifdef TQ_WS_TQWS
+ void clear();
+#endif
+ // universal key structure. TQFontEngineDatas and TQFontEngines are cached using
+ // the same keys
+ struct Key {
+ Key() : script(0), screen( 0 ), dpi(0) { }
+ Key( const TQFontDef &d, TQFont::Script c, int s, TQPaintDevice *pdev )
+ : script(c), screen(s) {
+ def = d;
+#ifdef TQ_WS_X11
+ dpi = pdev ? TQPaintDeviceMetrics(pdev).logicalDpiY() : 0;
+#else
+ TQ_UNUSED(pdev);
+ dpi = 0;
+#endif
+ }
+
+ TQFontDef def;
+ int script;
+ int screen;
+ int dpi;
+
+ inline bool operator<( const Key &other ) const
+ {
+ if ( script != other.script ) return script < other.script;
+ if ( screen != other.screen ) return screen < other.screen;
+ if ( dpi != other.dpi ) return dpi < other.dpi;
+ return def < other.def;
+ }
+ inline bool operator==( const Key &other ) const
+ { return def == other.def && script == other.script &&
+ screen == other.screen && dpi == other.dpi; }
+ };
+
+ // TQFontEngineData cache
+ typedef TQMap<Key,TQFontEngineData*> EngineDataCache;
+ EngineDataCache engineDataCache;
+
+ TQFontEngineData *tqfindEngineData( const Key &key ) const;
+ void insertEngineData( const Key &key, TQFontEngineData *engineData );
+
+ // TQFontEngine cache
+ struct Engine {
+ Engine() : data( 0 ), timestamp( 0 ), hits( 0 ) { }
+ Engine( TQFontEngine *d ) : data( d ), timestamp( 0 ), hits( 0 ) { }
+
+ TQFontEngine *data;
+ uint timestamp;
+ uint hits;
+ };
+
+ typedef TQMap<Key,Engine> EngineCache;
+ EngineCache engineCache;
+
+ TQFontEngine *tqfindEngine( const Key &key );
+ void insertEngine( const Key &key, TQFontEngine *engine );
+
+#if defined(TQ_WS_WIN) || defined(TQ_WS_TQWS)
+ void cleanupPrinterFonts();
+#endif
+
+ private:
+ void increaseCost( uint cost );
+ void decreaseCost( uint cost );
+ void timerEvent( TQTimerEvent *event );
+
+ static const uint min_cost;
+ uint total_cost, max_cost;
+ uint current_timestamp;
+ bool fast;
+ int timer_id;
+};
+
+#endif // TQFONTDATA_P_H
diff --git a/tqtinterface/qt4/src/kernel/tqfontdatabase.cpp b/tqtinterface/qt4/src/kernel/tqfontdatabase.cpp
new file mode 100644
index 0000000..f79c14b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontdatabase.cpp
@@ -0,0 +1,2505 @@
+/****************************************************************************
+**
+** Implementation of font database class.
+**
+** Created : 990603
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+// Nasty, nasty horrid HACK to get access to QFontDatabase's private members
+// This is TERRIBLE and I wish there was a way around it
+// This is a good example of the new, broken & irritating Qt4 API,
+// and the corresponding loss in functionality versus Qt3.
+// See also tqrect.cpp
+#define private protected
+#include <Qt/qfontdatabase.h>
+#undef private
+
+#include "tqfontdatabase.h"
+
+#ifndef TQT_NO_FONTDATABASE
+
+#include <tqtl.h>
+#include <tqapplication.h>
+
+#include <private/tqunicodetables_p.h>
+#include "tqfontengine_p.h"
+
+#include <tqcleanuphandler.h>
+
+#ifdef TQ_WS_X11
+#include <locale.h>
+#endif
+#include <stdlib.h>
+
+//#define TQFONTDATABASE_DEBUG
+#ifdef TQFONTDATABASE_DEBUG
+# define FD_DEBUG qDebug
+#else
+# define FD_DEBUG if (FALSE) qDebug
+#endif
+
+//#define FONT_MATCH_DEBUG
+#ifdef FONT_MATCH_DEBUG
+# define FM_DEBUG qDebug
+#else
+# define FM_DEBUG if (FALSE) qDebug
+#endif
+
+#if defined(TQ_CC_MSVC) && !defined(TQ_CC_MSVC_NET)
+# define for if(0){}else for
+#endif
+
+#ifdef USE_QT4
+
+void TQFontDatabase::tqparseFontName(const QString &name, QString &foundry, QString &family) {
+ parseFontName(name, foundry, family);
+}
+
+#else // USE_QT4
+
+static int ucstricmp( const TQString &as, const TQString &bs )
+{
+ const TQChar *a = as.tqunicode();
+ const TQChar *b = bs.tqunicode();
+ if ( a == b )
+ return 0;
+ if ( a == 0 )
+ return 1;
+ if ( b == 0 )
+ return -1;
+ int l=TQMIN(as.length(),bs.length());
+ while ( l-- && ::lower( *a ) == ::lower( *b ) )
+ a++,b++;
+ if ( l==-1 )
+ return ( as.length()-bs.length() );
+ return ::lower( *a ).tqunicode() - ::lower( *b ).tqunicode();
+}
+
+static int getFontWeight( const TQString &weightString )
+{
+ TQString s = weightString.lower();
+
+ // Test in decreasing order of commonness
+ if (s == "medium" ||
+ s == "normal")
+ return TQFont::Normal;
+ if (s == "bold")
+ return TQFont::Bold;
+ if (s == "demibold" || s == "demi bold")
+ return TQFont::DemiBold;
+ if (s == "black")
+ return TQFont::Black;
+ if (s == "light")
+ return TQFont::Light;
+
+ if (s.tqcontains("bold")) {
+ if (s.tqcontains("demi"))
+ return (int) TQFont::DemiBold;
+ return (int) TQFont::Bold;
+ }
+
+ if (s.tqcontains("light"))
+ return (int) TQFont::Light;
+
+ if (s.tqcontains("black"))
+ return (int) TQFont::Black;
+
+ return (int) TQFont::Normal;
+}
+
+#ifdef TQ_WS_X11
+struct TQtFontEncoding
+{
+ signed int encoding : 16;
+
+ uint xpoint : 16;
+ uint xres : 8;
+ uint yres : 8;
+ uint avgwidth : 16;
+ uchar pitch : 8;
+};
+#endif // TQ_WS_X11
+
+struct TQtFontSize
+{
+ unsigned short pixelSize;
+
+#ifdef TQ_WS_X11
+ int count;
+ TQtFontEncoding *encodings;
+ TQtFontEncoding *encodingID( int id, uint xpoint = 0, uint xres = 0,
+ uint yres = 0, uint avgwidth = 0, bool add = FALSE);
+#endif // TQ_WS_X11
+};
+
+
+#ifdef TQ_WS_X11
+TQtFontEncoding *TQtFontSize::encodingID( int id, uint xpoint, uint xres,
+ uint yres, uint avgwidth, bool add )
+{
+ // we don't match using the xpoint, xres and yres parameters, only the id
+ for ( int i = 0; i < count; ++i ) {
+ if ( encodings[i].encoding == id )
+ return encodings + i;
+ }
+
+ if ( !add ) return 0;
+
+ if ( !(count % 4) )
+ encodings = ( TQtFontEncoding * )
+ realloc( encodings,
+ (((count+4) >> 2 ) << 2 ) * sizeof( TQtFontEncoding ) );
+ encodings[count].encoding = id;
+ encodings[count].xpoint = xpoint;
+ encodings[count].xres = xres;
+ encodings[count].yres = yres;
+ encodings[count].avgwidth = avgwidth;
+ encodings[count].pitch = '*';
+ return encodings + count++;
+}
+#endif // TQ_WS_X11
+
+struct TQtFontStyle
+{
+ struct Key {
+ Key( const TQString &styleString );
+ Key() : italic( FALSE ), oblique( FALSE ),
+ weight( TQFont::Normal ), stretch( 0 ) { }
+ Key( const Key &o ) : italic( o.italic ), oblique( o.oblique ),
+ weight( o.weight ), stretch( o.stretch ) { }
+ uint italic : 1;
+ uint oblique : 1;
+ signed int weight : 8;
+ signed int stretch : 12;
+
+ bool operator==( const Key & other ) {
+ return ( italic == other.italic &&
+ oblique == other.oblique &&
+ weight == other.weight &&
+ (stretch == 0 || other.stretch == 0 || stretch == other.stretch) );
+ }
+ bool operator!=( const Key &other ) {
+ return !operator==(other);
+ }
+ bool operator <( const Key &o ) {
+ int x = (italic << 13) + (oblique << 12) + (weight << 14) + stretch;
+ int y = (o.italic << 13) + (o.oblique << 12) + (o.weight << 14) + o.stretch;
+ return ( x < y );
+ }
+ };
+
+ TQtFontStyle( const Key &k )
+ : key( k ), bitmapScalable( FALSE ), smoothScalable( FALSE ),
+ fakeOblique( FALSE ), count( 0 ), pixelSizes( 0 )
+ {
+#if defined(TQ_WS_X11)
+ weightName = setwidthName = 0;
+#endif // TQ_WS_X11
+ }
+
+ ~TQtFontStyle() {
+#ifdef TQ_WS_X11
+ delete [] weightName;
+ delete [] setwidthName;
+ while ( count-- )
+ free(pixelSizes[count].encodings);
+#endif
+ free( pixelSizes );
+ }
+
+ Key key;
+ bool bitmapScalable : 1;
+ bool smoothScalable : 1;
+ bool fakeOblique : 1;
+ int count : 29;
+ TQtFontSize *pixelSizes;
+
+#ifdef TQ_WS_X11
+ const char *weightName;
+ const char *setwidthName;
+#endif // TQ_WS_X11
+
+ TQtFontSize *pixelSize( unsigned short size, bool = FALSE );
+};
+
+TQtFontStyle::Key::Key( const TQString &styleString )
+ : italic( FALSE ), oblique( FALSE ), weight( TQFont::Normal ), stretch( 0 )
+{
+ weight = getFontWeight( styleString );
+
+ if ( styleString.tqcontains( "Italic" ) )
+ italic = TRUE;
+ else if ( styleString.tqcontains( "Oblique" ) )
+ oblique = TRUE;
+}
+
+TQtFontSize *TQtFontStyle::pixelSize( unsigned short size, bool add )
+{
+ for ( int i = 0; i < count; i++ ) {
+ if ( pixelSizes[i].pixelSize == size )
+ return pixelSizes + i;
+ }
+ if ( !add )
+ return 0;
+
+ if ( !(count % 8) )
+ pixelSizes = (TQtFontSize *)
+ realloc( pixelSizes,
+ (((count+8) >> 3 ) << 3) * sizeof(TQtFontSize) );
+ pixelSizes[count].pixelSize = size;
+#ifdef TQ_WS_X11
+ pixelSizes[count].count = 0;
+ pixelSizes[count].encodings = 0;
+#endif
+ return pixelSizes + (count++);
+}
+
+struct TQtFontFoundry
+{
+ TQtFontFoundry( const TQString &n ) : name( n ), count( 0 ), styles( 0 ) {}
+ ~TQtFontFoundry() {
+ while ( count-- )
+ delete styles[count];
+ free( styles );
+ }
+
+ TQString name;
+
+ int count;
+ TQtFontStyle **styles;
+ TQtFontStyle *style( const TQtFontStyle::Key &, bool = FALSE );
+};
+
+TQtFontStyle *TQtFontFoundry::style( const TQtFontStyle::Key &key, bool create )
+{
+ int pos = 0;
+ if ( count ) {
+ int low = 0;
+ int high = count;
+ pos = count / 2;
+ while ( high > low ) {
+ if ( styles[pos]->key == key )
+ return styles[pos];
+ if ( styles[pos]->key < key )
+ low = pos + 1;
+ else
+ high = pos;
+ pos = (high + low) / 2;
+ };
+ pos = low;
+ }
+ if ( !create )
+ return 0;
+
+// qDebug("adding key (weight=%d, italic=%d, oblique=%d stretch=%d) at %d", key.weight, key.italic, key.oblique, key.stretch, pos );
+ if ( !(count % 8) )
+ styles = (TQtFontStyle **)
+ realloc( styles, (((count+8) >> 3 ) << 3) * sizeof( TQtFontStyle * ) );
+
+ memmove( styles + pos + 1, styles + pos, (count-pos)*sizeof(TQtFontStyle *) );
+ styles[pos] = new TQtFontStyle( key );
+ count++;
+ return styles[pos];
+}
+
+
+struct TQtFontFamily
+{
+ enum ScriptqStatus { Unknown = 0, Supported = 1,
+ UnSupported_Xft= 2, UnSupported_Xlfd = 4, UnSupported = 6 };
+
+ TQtFontFamily(const TQString &n )
+ :
+#ifdef TQ_WS_X11
+ fixedPitch( TRUE ), hasXft( FALSE ), xftScriptCheck( FALSE ), xlfdLoaded( FALSE ), synthetic(FALSE),
+#else
+ fixedPitch( FALSE ),
+#endif
+#ifdef TQ_WS_WIN
+ scriptCheck( FALSE ),
+#endif
+#if defined(TQ_OS_MAC) && !defined(TQWS)
+ fixedPitchComputed(FALSE),
+#endif
+ fullyLoaded( FALSE ),
+ name( n ), count( 0 ), foundries( 0 ) {
+ memset( scripts, 0, sizeof( scripts ) );
+ }
+ ~TQtFontFamily() {
+ while ( count-- )
+ delete foundries[count];
+ free( foundries );
+ }
+
+ bool fixedPitch : 1;
+#ifdef TQ_WS_X11
+ bool hasXft : 1;
+ bool xftScriptCheck : 1;
+ bool xlfdLoaded : 1;
+ bool synthetic : 1;
+#endif
+#ifdef TQ_WS_WIN
+ bool scriptCheck : 1;
+#endif
+#if defined(TQ_OS_MAC) && !defined(TQWS)
+ bool fixedPitchComputed : 1;
+#endif
+ bool fullyLoaded : 1;
+ TQString name;
+ TQString rawName;
+#ifdef TQ_WS_X11
+ TQCString fontFilename;
+ int fontFileIndex;
+#endif
+#ifdef TQ_WS_MAC
+ FMFontFamily macFamily;
+#endif
+#ifdef TQ_WS_WIN
+ TQString english_name;
+#endif
+ int count;
+ TQtFontFoundry **foundries;
+
+ unsigned char scripts[TQFont::LastPrivateScript];
+
+ TQtFontFoundry *foundry( const TQString &f, bool = FALSE );
+};
+
+TQtFontFoundry *TQtFontFamily::foundry( const TQString &f, bool create )
+{
+ if ( f.isNull() && count == 1 )
+ return foundries[0];
+
+ for ( int i = 0; i < count; i++ ) {
+ if ( ucstricmp( foundries[i]->name, f ) == 0 )
+ return foundries[i];
+ }
+ if ( !create )
+ return 0;
+
+ if ( !(count % 8) )
+ foundries = (TQtFontFoundry **)
+ realloc( foundries,
+ (((count+8) >> 3 ) << 3) * sizeof( TQtFontFoundry * ) );
+
+ foundries[count] = new TQtFontFoundry( f );
+ return foundries[count++];
+}
+
+class TQFontDatabasePrivate {
+public:
+ TQFontDatabasePrivate() : count( 0 ), families( 0 ) { }
+ ~TQFontDatabasePrivate() {
+ while ( count-- )
+ delete families[count];
+ free( families );
+ }
+ TQtFontFamily *family( const TQString &f, bool = FALSE );
+
+ int count;
+ TQtFontFamily **families;
+};
+
+TQtFontFamily *TQFontDatabasePrivate::family( const TQString &f, bool create )
+{
+ int low = 0;
+ int high = count;
+ int pos = count / 2;
+ int res = 1;
+ if ( count ) {
+ while ( (res = ucstricmp( families[pos]->name, f )) && pos != low ) {
+ if ( res > 0 )
+ high = pos;
+ else
+ low = pos;
+ pos = (high + low) / 2;
+ };
+ if ( !res )
+ return families[pos];
+ }
+ if ( !create )
+ return 0;
+
+ if ( res < 0 )
+ pos++;
+
+ // qDebug("adding family %s at %d total=%d", f.latin1(), pos, count);
+ if ( !(count % 8) )
+ families = (TQtFontFamily **)
+ realloc( families,
+ (((count+8) >> 3 ) << 3) * sizeof( TQtFontFamily * ) );
+
+ memmove( families + pos + 1, families + pos, (count-pos)*sizeof(TQtFontFamily *) );
+ families[pos] = new TQtFontFamily( f );
+ count++;
+ return families[pos];
+}
+
+
+
+
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+static const unsigned short sample_chars[TQFont::LastPrivateScript][14] =
+{
+ // European Alphabetic Scripts
+ // Latin,
+ { 0x0041, 0x0 },
+ // Greek,
+ { 0x0391, 0x0 },
+ // Cyrillic,
+ { 0x0410, 0x0 },
+ // Armenian,
+ { 0x0540, 0x0 },
+ // Georgian,
+ { 0x10d0, 0x0 },
+ // Runic,
+ { 0x16a0, 0x0 },
+ // Ogham,
+ { 0x1680, 0x0 },
+ // SpacingModifiers,
+ { 0x02c6, 0x0 },
+ // CombiningMarks,
+ { 0x0300, 0x0 },
+
+ // Middle Eastern Scripts
+ // Hebrew,
+ { 0x05d0, 0x0 },
+ // Arabic,
+ { 0x0630, 0x0 },
+ // Syriac,
+ { 0x0710, 0x0 },
+ // Thaana,
+ { 0x0780, 0x0 },
+
+ // South and Southeast Asian Scripts
+ // Devanagari,
+ { 0x0910, 0x0 },
+ // Bengali,
+ { 0x0990, 0x0 },
+ // Gurmukhi,
+ { 0x0a10, 0x0 },
+ // Gujarati,
+ { 0x0a90, 0x0 },
+ // Oriya,
+ { 0x0b10, 0x0 },
+ // Tamil,
+ { 0x0b90, 0x0 },
+ // Telugu,
+ { 0x0c10, 0x0 },
+ // Kannada,
+ { 0x0c90, 0x0 },
+ // Malayalam,
+ { 0x0d10, 0x0 },
+ // Sinhala,
+ { 0x0d90, 0x0 },
+ // Thai,
+ { 0x0e10, 0x0 },
+ // Lao,
+ { 0x0e81, 0x0 },
+ // Tibetan,
+ { 0x0f00, 0x0 },
+ // Myanmar,
+ { 0x1000, 0x0 },
+ // Khmer,
+ { 0x1780, 0x0 },
+
+ // East Asian Scripts
+ // Han,
+ { 0x4e00, 0x0 },
+ // Hiragana,
+ { 0x3050, 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x30FC, 0x5CE0, 0 },
+ // Katakana,
+ { 0x30b0, 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x30FC, 0x5CE0, 0 },
+ // Hangul,
+ { 0xac00, 0x0 },
+ // Bopomofo,
+ { 0x3110, 0x0 },
+ // Yi,
+ { 0xa000, 0x0 },
+
+ // Additional Scripts
+ // Ethiopic,
+ { 0x1200, 0x0 },
+ // Cherokee,
+ { 0x13a0, 0x0 },
+ // CanadianAboriginal,
+ { 0x1410, 0x0 },
+ // Mongolian,
+ { 0x1800, 0x0 },
+
+ // Symbols
+ // CurrencySymbols,
+ { 0x20aa, 0x0 },
+ // LetterlikeSymbols,
+ { 0x2103, 0x0 },
+ // NumberForms,
+ { 0x2160, 0x0 },
+ // MathematicalOperators,
+ { 0x222b, 0x0 },
+ // TechnicalSymbols,
+ { 0x2312, 0x0 },
+ // GeometricSymbols,
+ { 0x2500, 0x0 },
+ // MiscellaneousSymbols,
+ { 0x2640, 0x2714, 0x0 },
+ // EnclosedAndSquare,
+ { 0x2460, 0x0 },
+ // Braille,
+ { 0x2800, 0x0 },
+
+ // Unicode,
+ { 0xfffd, 0x0 },
+
+ // some scripts added in Unicode 3.2
+ // Tagalog,
+ { 0x1700, 0x0 },
+ // Hanunoo,
+ { 0x1720, 0x0 },
+ // Buhid,
+ { 0x1740, 0x0 },
+ // Tagbanwa,
+ { 0x1770, 0x0 },
+
+ // KatakanaHalfWidth
+ { 0xff65, 0x0 },
+
+ // Limbu
+ { 0x1901, 0x0 },
+ // TaiLe
+ { 0x1950, 0x0 },
+
+ // NScripts
+ { 0x0000, 0x0 },
+ // NoScript
+ { 0x0000, 0x0 },
+
+ // Han_Japanese
+ { 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x5CE0, 0 },
+ // Han_SimplifiedChinese, 0x3400 is optional
+ { 0x4e00, 0x201C, 0x3002, 0x6237, 0x9555, 0xFFE5, 0 },
+ // Han_TraditionalChinese, 0xF6B1 is optional
+ // OR Han_HongkongChinese, 0x3435, 0xE000, 0xF6B1 are optional
+ { 0x4e00, 0x201C, 0x3002, 0x6236, 0x9F98, 0xFFE5, 0 },
+ // Han_Korean
+ { 0x4e00, 0 }
+ // Taiwan would be 0x201C, 0x3002, 0x4E00, 0x9F98, 0xFFE5
+};
+
+#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+static inline bool requiresOpenType(TQFont::Script s)
+{
+ return (s >= TQFont::Syriac && s <= TQFont::Sinhala)
+ || (s >= TQFont::Myanmar && s <= TQFont::Khmer);
+}
+#endif
+
+static inline bool canRender( TQFontEngine *fe, TQFont::Script script )
+{
+ if ( !fe ) return FALSE;
+
+ bool hasChar = true;
+
+ if (!sample_chars[script][0])
+ hasChar = false;
+
+ int i = 0;
+ while (hasChar && sample_chars[script][i]){
+ TQChar sample(sample_chars[script][i]);
+ if ( !fe->canRender( &sample, 1 ) ) {
+ hasChar = false;
+#ifdef FONT_MATCH_DEBUG
+ FM_DEBUG(" font has NOT char 0x%04x", sample.tqunicode() );
+ } else {
+ FM_DEBUG(" font has char 0x%04x", sample.tqunicode() );
+#endif
+ }
+ ++i;
+ }
+#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+ if (hasChar && requiresOpenType(script)) {
+ TQOpenType *ot = fe->openType();
+ if (!ot || !ot->supportsScript(script))
+ return FALSE;
+ }
+#endif
+
+ return hasChar;
+}
+#endif // TQ_WS_X11 || TQ_WS_WIN
+
+
+static TQSingleCleanupHandler<TQFontDatabasePrivate> qfontdatabase_cleanup;
+static TQFontDatabasePrivate *db=0;
+#define SMOOTH_SCALABLE 0xffff
+
+#if defined( TQ_WS_X11 )
+# include "tqfontdatabase_x11.cpp"
+#elif defined( TQ_WS_MAC )
+# include "tqfontdatabase_mac.cpp"
+#elif defined( TQ_WS_WIN )
+# include "tqfontdatabase_win.cpp"
+#elif defined( TQ_WS_TQWS )
+# include "tqfontdatabase_qws.cpp"
+#endif
+
+static TQtFontStyle *bestStyle(TQtFontFoundry *foundry, const TQtFontStyle::Key &styleKey)
+{
+ int best = 0;
+ int dist = 0xffff;
+
+ for ( int i = 0; i < foundry->count; i++ ) {
+ TQtFontStyle *style = foundry->styles[i];
+
+ int d = TQABS( styleKey.weight - style->key.weight );
+
+ if ( styleKey.stretch != 0 && style->key.stretch != 0 ) {
+ d += TQABS( styleKey.stretch - style->key.stretch );
+ }
+
+ if ( styleKey.italic ) {
+ if ( !style->key.italic )
+ d += style->key.oblique ? 0x0001 : 0x1000;
+ } else if ( styleKey.oblique ) {
+ if (!style->key.oblique )
+ d += style->key.italic ? 0x0001 : 0x1000;
+ } else if ( style->key.italic || style->key.oblique ) {
+ d += 0x1000;
+ }
+
+ if ( d < dist ) {
+ best = i;
+ dist = d;
+ }
+ }
+
+ FM_DEBUG( " best style has distance 0x%x", dist );
+ return foundry->styles[best];
+}
+
+#if defined(TQ_WS_X11)
+static TQtFontEncoding *tqfindEncoding(TQFont::Script script, int styleStrategy,
+ TQtFontSize *size, int force_encoding_id)
+{
+ TQtFontEncoding *encoding = 0;
+
+ if (force_encoding_id >= 0) {
+ encoding = size->encodingID(force_encoding_id);
+ if (!encoding)
+ FM_DEBUG(" required encoding_id not available");
+ return encoding;
+ }
+
+ if (styleStrategy & (TQFont::OpenGLCompatible | TQFont::PreferBitmap)) {
+ FM_DEBUG(" PreferBitmap and/or OpenGL set, skipping Xft");
+ } else {
+ encoding = size->encodingID(-1); // -1 == prefer Xft
+ if (encoding) return encoding;
+ }
+
+ // Xft not available, tqfind an XLFD font, trying the default encoding first
+ encoding = size->encodingID(TQFontPrivate::defaultEncodingID);
+
+ if (!encoding || !scripts_for_xlfd_encoding[encoding->encoding][script]) {
+ // tqfind the first encoding that supports the requested script
+ encoding = 0;
+ for (int x = 0; !encoding && x < size->count; ++x) {
+ const int enc = size->encodings[x].encoding;
+ if (scripts_for_xlfd_encoding[enc][script]) {
+ encoding = size->encodings + x;
+ break;
+ }
+ }
+ }
+
+ return encoding;
+}
+#endif // TQ_WS_X11
+
+
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+static
+unsigned int bestFoundry( TQFont::Script script, unsigned int score, int styleStrategy,
+ const TQtFontFamily *family, const TQString &foundry_name,
+ TQtFontStyle::Key styleKey, int pixelSize, char pitch,
+ TQtFontFoundry **best_foundry, TQtFontStyle **best_style,
+ TQtFontSize **best_size
+#ifdef TQ_WS_X11
+ , TQtFontEncoding **best_encoding, int force_encoding_id
+#endif
+ )
+{
+ TQ_UNUSED( script );
+ TQ_UNUSED( pitch );
+
+ FM_DEBUG( " REMARK: looking for best foundry for family '%s'", family->name.latin1() );
+
+ for ( int x = 0; x < family->count; ++x ) {
+ TQtFontFoundry *foundry = family->foundries[x];
+ if ( ! foundry_name.isEmpty() &&
+ ucstricmp( foundry->name, foundry_name ) != 0 )
+ continue;
+
+ FM_DEBUG( " looking for matching style in foundry '%s'",
+ foundry->name.isEmpty() ? "-- none --" : foundry->name.latin1() );
+
+ TQtFontStyle *style = bestStyle(foundry, styleKey);
+
+ if ( ! style->smoothScalable && ( styleStrategy & TQFont::ForceOutline ) ) {
+ FM_DEBUG( " ForceOutline set, but not smoothly scalable" );
+ continue;
+ }
+
+ int px = -1;
+ TQtFontSize *size = 0;
+
+ // 1. see if we have an exact matching size
+ if (! (styleStrategy & TQFont::ForceOutline)) {
+ size = style->pixelSize(pixelSize);
+ if (size) {
+ FM_DEBUG(" found exact size match (%d pixels)", size->pixelSize);
+ px = size->pixelSize;
+ }
+ }
+
+ // 2. see if we have a smoothly scalable font
+ if (! size && style->smoothScalable && ! (styleStrategy & TQFont::PreferBitmap)) {
+ size = style->pixelSize(SMOOTH_SCALABLE);
+ if (size) {
+ FM_DEBUG(" found smoothly scalable font (%d pixels)", pixelSize);
+ px = pixelSize;
+ }
+ }
+
+ // 3. see if we have a bitmap scalable font
+ if (! size && style->bitmapScalable && (styleStrategy & TQFont::PreferMatch)) {
+ size = style->pixelSize(0);
+ if (size) {
+ FM_DEBUG(" found bitmap scalable font (%d pixels)", pixelSize);
+ px = pixelSize;
+ }
+ }
+
+#ifdef TQ_WS_X11
+ TQtFontEncoding *encoding = 0;
+#endif
+
+ // 4. tqfind closest size match
+ if (! size) {
+ unsigned int distance = ~0u;
+ for (int x = 0; x < style->count; ++x) {
+#ifdef TQ_WS_X11
+ encoding =
+ tqfindEncoding(script, styleStrategy, style->pixelSizes + x, force_encoding_id);
+ if (!encoding) {
+ FM_DEBUG(" size %3d does not support the script we want",
+ style->pixelSizes[x].pixelSize);
+ continue;
+ }
+#endif
+
+ unsigned int d = TQABS(style->pixelSizes[x].pixelSize - pixelSize);
+ if (d < distance) {
+ distance = d;
+ size = style->pixelSizes + x;
+ FM_DEBUG(" best size so far: %3d (%d)", size->pixelSize, pixelSize);
+ }
+ }
+
+ if (!size) {
+ FM_DEBUG(" no size supports the script we want");
+ continue;
+ }
+
+ if (style->bitmapScalable && ! (styleStrategy & TQFont::PreferQuality) &&
+ (distance * 10 / pixelSize) >= 2) {
+ // the closest size is not close enough, go ahead and
+ // use a bitmap scaled font
+ size = style->pixelSize(0);
+ px = pixelSize;
+ } else {
+ px = size->pixelSize;
+ }
+ }
+
+#ifdef TQ_WS_X11
+ if (size) {
+ encoding = tqfindEncoding(script, styleStrategy, size, force_encoding_id);
+ if (!encoding) size = 0;
+ }
+ if ( ! encoding ) {
+ FM_DEBUG( " foundry doesn't support the script we want" );
+ continue;
+ }
+#endif // TQ_WS_X11
+
+ unsigned int this_score = 0x0000;
+ enum {
+ PitchMismatch = 0x4000,
+ StyleMismatch = 0x2000,
+ BitmapScaledPenalty = 0x1000,
+ EncodingMismatch = 0x0002,
+ XLFDPenalty = 0x0001
+ };
+
+#ifdef TQ_WS_X11
+ if ( encoding->encoding != -1 ) {
+ this_score += XLFDPenalty;
+ if ( encoding->encoding != TQFontPrivate::defaultEncodingID )
+ this_score += EncodingMismatch;
+ }
+ if (pitch != '*') {
+ if ( !( pitch == 'm' && encoding->pitch == 'c' ) && pitch != encoding->pitch )
+ this_score += PitchMismatch;
+ }
+#else
+ // ignore pitch for asian fonts, some of them misreport it, and they are all
+ // fixed pitch anyway.
+ if (pitch != '*' && (script <= TQFont::NScripts && script != TQFont::KatakanaHalfWidth
+ && (script < TQFont::Han || script > TQFont::Yi))) {
+ if ((pitch == 'm' && !family->fixedPitch)
+ || (pitch == 'p' && family->fixedPitch))
+ this_score += PitchMismatch;
+ }
+#endif
+ if ( styleKey != style->key )
+ this_score += StyleMismatch;
+ if ( !style->smoothScalable && px != size->pixelSize ) // bitmap scaled
+ this_score += BitmapScaledPenalty;
+ if (px != pixelSize) // close, but not exact, size match
+ this_score += TQABS(px - pixelSize);
+
+ if ( this_score < score ) {
+ FM_DEBUG( " found a match: score %x best score so far %x",
+ this_score, score );
+
+ score = this_score;
+ *best_foundry = foundry;
+ *best_style = style;
+ *best_size = size;
+#ifdef TQ_WS_X11
+ *best_encoding = encoding;
+#endif // TQ_WS_X11
+ } else {
+ FM_DEBUG( " score %x no better than best %x", this_score, score);
+ }
+ }
+
+ return score;
+}
+
+/*!
+ \internal
+*/
+TQFontEngine *
+TQFontDatabase::tqfindFont( TQFont::Script script, const TQFontPrivate *fp,
+ const TQFontDef &request, int force_encoding_id )
+{
+#ifndef TQ_WS_X11
+ TQ_UNUSED( force_encoding_id );
+#endif
+
+ if ( !db )
+ initializeDb();
+
+ TQFontEngine *fe = 0;
+ if ( fp ) {
+ if ( fp->rawMode ) {
+ fe = loadEngine( script, fp, request, 0, 0, 0
+#ifdef TQ_WS_X11
+ , 0, 0, FALSE
+#endif
+ );
+
+ // if we fail to load the rawmode font, use a 12pixel box engine instead
+ if (! fe) fe = new TQFontEngineBox( 12 );
+ return fe;
+ }
+
+ TQFontCache::Key key( request, script,
+#ifdef TQ_WS_WIN
+ (int)fp->painttqdevice,
+#else
+ fp->screen,
+#endif
+ fp->painttqdevice
+ );
+ fe = TQFontCache::instance->tqfindEngine( key );
+ if ( fe ) return fe;
+ }
+
+#ifdef TQ_WS_WIN
+ if (request.styleStrategy & TQFont::PreferDevice) {
+ TQFontEngine *fe = loadEngine(script, fp, request, 0, 0, 0);
+ if(fe)
+ return fe;
+ }
+#endif
+
+ TQString family_name, foundry_name;
+ TQtFontStyle::Key styleKey;
+ styleKey.italic = request.italic;
+ styleKey.weight = request.weight;
+ styleKey.stretch = request.stretch;
+ char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p';
+
+ parseFontName( request.family, foundry_name, family_name );
+
+#ifdef TQ_WS_X11
+ if (script == TQFont::Han) {
+ // modify script according to locale
+ static TQFont::Script defaultHan = TQFont::UnknownScript;
+ if (defaultHan == TQFont::UnknownScript) {
+ TQCString locale = setlocale(LC_ALL, NULL);
+ if (locale.tqcontains("ko"))
+ defaultHan = TQFont::Han_Korean;
+ else if (locale.tqcontains("zh_TW") || locale.tqcontains("zh_HK"))
+ defaultHan = TQFont::Han_TraditionalChinese;
+ else if (locale.tqcontains("zh"))
+ defaultHan = TQFont::Han_SimplifiedChinese;
+ else
+ defaultHan = TQFont::Han_Japanese;
+ }
+ script = defaultHan;
+ }
+#endif
+
+ FM_DEBUG( "TQFontDatabase::tqfindFont\n"
+ " request:\n"
+ " family: %s [%s], script: %d (%s)\n"
+ " weight: %d, italic: %d\n"
+ " stretch: %d\n"
+ " pixelSize: %d\n"
+ " pitch: %c",
+ family_name.isEmpty() ? "-- first in script --" : family_name.latin1(),
+ foundry_name.isEmpty() ? "-- any --" : foundry_name.latin1(),
+ script, scriptName( script ).latin1(),
+ request.weight, request.italic, request.stretch, request.pixelSize, pitch );
+
+ bool usesFontConfig = FALSE;
+#ifdef TQT_XFT2
+ if (family_name.isEmpty()
+ || family_name == "Sans Serif"
+ || family_name == "Serif"
+ || family_name == "Monospace") {
+ fe = loadFontConfigFont(fp, request, script);
+ usesFontConfig = (fe != 0);
+ }
+ if (!fe)
+#endif
+ {
+ TQtFontFamily *best_family = 0;
+ TQtFontFoundry *best_foundry = 0;
+ TQtFontStyle *best_style = 0;
+ TQtFontSize *best_size = 0;
+#ifdef TQ_WS_X11
+ TQtFontEncoding *best_encoding = 0;
+#endif // TQ_WS_X11
+
+ unsigned int score = ~0;
+
+ load( family_name, script );
+
+ for ( int x = 0; x < db->count; ++x ) {
+ TQtFontFamily *try_family = db->families[x];
+#ifdef TQ_WS_X11
+ if (try_family->synthetic) // skip generated fontconfig fonts
+ continue;
+#endif
+
+ if ( !family_name.isEmpty() &&
+ ucstricmp( try_family->name, family_name ) != 0
+#ifdef TQ_WS_WIN
+ && ucstricmp( try_family->english_name, family_name ) != 0
+#endif
+ )
+ continue;
+
+ if ( family_name.isEmpty() )
+ load( try_family->name, script );
+
+ uint score_adjust = 0;
+ TQFont::Script override_script = script;
+ if ( ! ( try_family->scripts[script] & TQtFontFamily::Supported )
+ && script != TQFont::Unicode) {
+ // family not supported in the script we want
+#ifdef TQ_WS_X11
+ if (script >= TQFont::Han_Japanese && script <= TQFont::Han_Korean
+ && try_family->scripts[TQFont::Han] == TQtFontFamily::Supported) {
+ // try with the han script instead, give it a penalty
+ if (override_script == TQFont::Han_TraditionalChinese
+ && (try_family->scripts[TQFont::Han_SimplifiedChinese] & TQtFontFamily::Supported)) {
+ override_script = TQFont::Han_SimplifiedChinese;
+ score_adjust = 200;
+ } else if (override_script == TQFont::Han_SimplifiedChinese
+ && (try_family->scripts[TQFont::Han_TraditionalChinese] & TQtFontFamily::Supported)) {
+ override_script = TQFont::Han_TraditionalChinese;
+ score_adjust = 200;
+ } else {
+ override_script = TQFont::Han;
+ score_adjust = 400;
+ }
+ } else
+#endif
+ if (family_name.isEmpty()) {
+ continue;
+ } else if (try_family->scripts[TQFont::UnknownScript] & TQtFontFamily::Supported) {
+ // try with the unknown script (for a symbol font)
+ override_script = TQFont::UnknownScript;
+#ifndef TQT_XFT2
+ } else if (try_family->scripts[TQFont::Unicode] & TQtFontFamily::Supported) {
+ // try with the tqunicode script instead
+ override_script = TQFont::Unicode;
+#endif
+ } else {
+ // family not supported by tqunicode/unknown scripts
+ continue;
+ }
+ }
+
+ TQtFontFoundry *try_foundry = 0;
+ TQtFontStyle *try_style = 0;
+ TQtFontSize *try_size = 0;
+#ifdef TQ_WS_X11
+ TQtFontEncoding *try_encoding = 0;
+#endif // TQ_WS_X11
+
+ // as we know the script is supported, we can be sure
+ // to tqfind a matching font here.
+ unsigned int newscore =
+ bestFoundry( override_script, score, request.styleStrategy,
+ try_family, foundry_name, styleKey, request.pixelSize, pitch,
+ &try_foundry, &try_style, &try_size
+#ifdef TQ_WS_X11
+ , &try_encoding, force_encoding_id
+#endif
+ );
+ if ( try_foundry == 0 ) {
+ // the specific foundry was not found, so look for
+ // any foundry matching our requirements
+ newscore = bestFoundry( override_script, score, request.styleStrategy, try_family,
+ TQString::null, styleKey, request.pixelSize,
+ pitch, &try_foundry, &try_style, &try_size
+#ifdef TQ_WS_X11
+ , &try_encoding, force_encoding_id
+#endif
+ );
+ }
+ newscore += score_adjust;
+
+ if ( newscore < score ) {
+ score = newscore;
+ best_family = try_family;
+ best_foundry = try_foundry;
+ best_style = try_style;
+ best_size = try_size;
+#ifdef TQ_WS_X11
+ best_encoding = try_encoding;
+#endif // TQ_WS_X11
+ }
+ if ( newscore < 10 ) // xlfd instead of xft... just accept it
+ break;
+ }
+
+ if ( best_family != 0 && best_foundry != 0 && best_style != 0
+#ifdef TQ_WS_X11
+ && best_size != 0 && best_encoding != 0
+#endif
+ ) {
+ FM_DEBUG( " BEST:\n"
+ " family: %s [%s]\n"
+ " weight: %d, italic: %d, oblique: %d\n"
+ " stretch: %d\n"
+ " pixelSize: %d\n"
+ " pitch: %c\n"
+ " encoding: %d\n",
+ best_family->name.latin1(),
+ best_foundry->name.isEmpty() ? "-- none --" : best_foundry->name.latin1(),
+ best_style->key.weight, best_style->key.italic, best_style->key.oblique,
+ best_style->key.stretch, best_size ? best_size->pixelSize : 0xffff,
+#ifdef TQ_WS_X11
+ best_encoding->pitch, best_encoding->encoding
+#else
+ 'p', 0
+#endif
+ );
+
+ fe = loadEngine( script, fp, request, best_family, best_foundry, best_style
+#ifdef TQ_WS_X11
+ , best_size, best_encoding, ( force_encoding_id >= 0 )
+#endif
+ );
+ }
+ if (fe) {
+ fe->fontDef.family = best_family->name;
+ if ( ! best_foundry->name.isEmpty() ) {
+ fe->fontDef.family += TQString::tqfromLatin1( " [" );
+ fe->fontDef.family += best_foundry->name;
+ fe->fontDef.family += TQString::tqfromLatin1( "]" );
+ }
+
+ if ( best_style->smoothScalable )
+ fe->fontDef.pixelSize = request.pixelSize;
+ else if ( best_style->bitmapScalable &&
+ ( request.styleStrategy & TQFont::PreferMatch ) )
+ fe->fontDef.pixelSize = request.pixelSize;
+ else
+ fe->fontDef.pixelSize = best_size->pixelSize;
+
+ fe->fontDef.tqstyleHint = request.tqstyleHint;
+ fe->fontDef.styleStrategy = request.styleStrategy;
+
+ fe->fontDef.weight = best_style->key.weight;
+ fe->fontDef.italic = best_style->key.italic || best_style->key.oblique;
+ fe->fontDef.fixedPitch = best_family->fixedPitch;
+ fe->fontDef.stretch = best_style->key.stretch;
+ fe->fontDef.ignorePitch = FALSE;
+ }
+ }
+
+ if ( fe ) {
+ if ( script != TQFont::Unicode && !canRender( fe, script ) ) {
+ FM_DEBUG( " WARN: font loaded cannot render a sample char" );
+
+ delete fe;
+ fe = 0;
+ } else if ( fp ) {
+ TQFontDef def = request;
+ if (def.family.isEmpty()) {
+ def.family = fp->request.family;
+ def.family = def.family.left(def.family.tqfind(','));
+ }
+ TQFontCache::Key key( def, script,
+#ifdef TQ_WS_WIN
+ (int)fp->painttqdevice,
+#else
+ fp->screen,
+#endif
+ fp->painttqdevice
+ );
+ TQFontCache::instance->insertEngine( key, fe );
+ if (!usesFontConfig) {
+ for ( int i = 0; i < TQFont::NScripts; ++i ) {
+ if ( i == script ) continue;
+
+ if (!canRender(fe, (TQFont::Script) i))
+ continue;
+
+ key.script = i;
+ TQFontCache::instance->insertEngine( key, fe );
+ }
+ }
+ }
+ }
+
+ if (!fe) {
+ if ( !request.family.isEmpty() )
+ return 0;
+
+ FM_DEBUG( "returning box engine" );
+
+ fe = new TQFontEngineBox( request.pixelSize );
+ fe->fontDef = request;
+
+ if ( fp ) {
+ TQFontCache::Key key( request, script,
+#ifdef TQ_WS_WIN
+ (int)fp->painttqdevice,
+#else
+ fp->screen,
+#endif
+ fp->painttqdevice
+ );
+ TQFontCache::instance->insertEngine( key, fe );
+ }
+ }
+
+ if ( fp ) {
+#if defined(TQ_WS_X11)
+ fe->fontDef.pointSize =
+ tqRound(10. * qt_pointSize(fe->fontDef.pixelSize, fp->painttqdevice, fp->screen));
+#elif defined(TQ_WS_WIN)
+ fe->fontDef.pointSize = int( double( fe->fontDef.pixelSize ) * 720.0 /
+ GetDeviceCaps(shared_dc,LOGPIXELSY) );
+#else
+ fe->fontDef.pointSize = int( double( fe->fontDef.pixelSize ) * 720.0 /
+ 96.0 );
+#endif
+ } else {
+ fe->fontDef.pointSize = request.pointSize;
+ }
+
+ return fe;
+}
+#endif // TQ_WS_X11 || TQ_WS_WIN
+
+
+
+
+static TQString styleString( int weight, bool italic, bool oblique )
+{
+ TQString result;
+ if ( weight >= TQFont::Black )
+ result = "Black";
+ else if ( weight >= TQFont::Bold )
+ result = "Bold";
+ else if ( weight >= TQFont::DemiBold )
+ result = "Demi Bold";
+ else if ( weight < TQFont::Normal )
+ result = "Light";
+
+ if ( italic )
+ result += " Italic";
+ else if ( oblique )
+ result += " Oblique";
+
+ if ( result.isEmpty() )
+ result = "Normal";
+
+ return result.simplifyWhiteSpace();
+}
+
+/*!
+ Returns a string that describes the style of the font \a f. For
+ example, "Bold Italic", "Bold", "Italic" or "Normal". An empty
+ string may be returned.
+*/
+TQString TQFontDatabase::styleString( const TQFont &f )
+{
+ // ### fix oblique here
+ return ::styleString( f.weight(), f.italic(), FALSE );
+}
+
+
+/*!
+ \class TQFontDatabase tqfontdatabase.h
+ \brief The TQFontDatabase class provides information about the fonts available in the underlying window system.
+
+ \ingroup environment
+ \ingroup graphics
+
+ The most common uses of this class are to query the database for
+ the list of font families() and for the pointSizes() and styles()
+ that are available for each family. An alternative to pointSizes()
+ is smoothSizes() which returns the sizes at which a given family
+ and style will look attractive.
+
+ If the font family is available from two or more foundries the
+ foundry name is included in the family name, e.g. "Helvetica
+ [Adobe]" and "Helvetica [Cronyx]". When you specify a family you
+ can either use the old hyphenated TQt 2.x "foundry-family" format,
+ e.g. "Cronyx-Helvetica", or the new bracketed TQt 3.x "family
+ [foundry]" format e.g. "Helvetica [Cronyx]". If the family has a
+ foundry it is always returned, e.g. by families(), using the
+ bracketed format.
+
+ The font() function returns a TQFont given a family, style and
+ point size.
+
+ A family and style combination can be checked to see if it is
+ italic() or bold(), and to retrieve its weight(). Similarly we can
+ call isBitmapScalable(), isSmoothlyScalable(), isScalable() and
+ isFixedPitch().
+
+ A text version of a style is given by styleString().
+
+ The TQFontDatabase class also supports some static functions, for
+ example, standardSizes(). You can retrieve the Unicode 3.0
+ description of a \link TQFont::Script script\endlink using
+ scriptName(), and a sample of characters in a script with
+ scriptSample().
+
+ Example:
+\code
+#include <tqapplication.h>
+#include <tqfontdatabase.h>
+#include <else.h>
+
+int main( int argc, char **argv )
+{
+ TQApplication app( argc, argv );
+ TQFontDatabase fdb;
+ TQStringList families = fdb.families();
+ for ( TQStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
+ TQString family = *f;
+ qDebug( family );
+ TQStringList styles = fdb.styles( family );
+ for ( TQStringList::Iterator s = styles.begin(); s != styles.end(); ++s ) {
+ TQString style = *s;
+ TQString dstyle = "\t" + style + " (";
+ TQValueList<int> smoothies = fdb.smoothSizes( family, style );
+ for ( TQValueList<int>::Iterator points = smoothies.begin();
+ points != smoothies.end(); ++points ) {
+ dstyle += TQString::number( *points ) + " ";
+ }
+ dstyle = dstyle.left( dstyle.length() - 1 ) + ")";
+ qDebug( dstyle );
+ }
+ }
+ return 0;
+}
+\endcode
+ This example gets the list of font families, then the list of
+ styles for each family and the point sizes that are available for
+ each family/style combination.
+*/
+/*!
+ \obsolete
+ \fn inline TQStringList TQFontDatabase::families( bool ) const
+*/
+/*!
+ \obsolete
+ \fn inline TQStringList TQFontDatabase::styles( const TQString &family,
+ const TQString & ) const
+*/
+/*!
+ \obsolete
+ \fn inline TQValueList<int> TQFontDatabase::pointSizes( const TQString &family,
+ const TQString &style ,
+ const TQString & )
+*/
+
+/*!
+ \obsolete
+ \fn inline TQValueList<int> TQFontDatabase::smoothSizes( const TQString &family,
+ const TQString &style,
+ const TQString & )
+*/
+/*!
+ \obsolete
+ \fn inline TQFont TQFontDatabase::font( const TQString &familyName,
+ const TQString &style,
+ int pointSize,
+ const TQString &)
+*/
+/*!
+ \obsolete
+ \fn inline bool TQFontDatabase::isBitmapScalable( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+*/
+
+/*!
+ \obsolete
+ \fn inline bool TQFontDatabase::isSmoothlyScalable( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+*/
+
+/*!
+ \obsolete
+ \fn inline bool TQFontDatabase::isScalable( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+*/
+
+/*!
+ \obsolete
+ \fn inline bool TQFontDatabase::isFixedPitch( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+*/
+
+/*!
+ \obsolete
+ \fn inline bool TQFontDatabase::italic( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+*/
+
+/*!
+ \obsolete
+ \fn inline bool TQFontDatabase::bold( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+*/
+
+/*!
+ \obsolete
+ \fn inline int TQFontDatabase::weight( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+*/
+
+
+/*!
+ Creates a font database object.
+*/
+TQFontDatabase::TQFontDatabase()
+{
+ createDatabase();
+
+ d = db;
+}
+
+
+/*! Returns a sorted list of the names of the available font families.
+
+ If a family exists in several foundries, the returned name for
+ that font is in the form "family [foundry]". Examples: "Times
+ [Adobe]", "Times [Cronyx]", "Palatino".
+*/
+TQStringList TQFontDatabase::families() const
+{
+ load();
+
+ TQStringList flist;
+ for ( int i = 0; i < d->count; i++ ) {
+ TQtFontFamily *f = d->families[i];
+ if ( f->count == 0 )
+ continue;
+ if ( f->count == 1 ) {
+ flist.append( f->name );
+ } else {
+ for ( int j = 0; j < f->count; j++ ) {
+ TQString str = f->name;
+ TQString foundry = f->foundries[j]->name;
+ if ( !foundry.isEmpty() ) {
+ str += " [";
+ str += foundry;
+ str += "]";
+ }
+ flist.append( str );
+ }
+ }
+ }
+ return flist;
+}
+
+/*!
+ \overload
+
+ Returns a sorted list of the available font families which support
+ the Unicode script \a script.
+
+ If a family exists in several foundries, the returned name for
+ that font is in the form "family [foundry]". Examples: "Times
+ [Adobe]", "Times [Cronyx]", "Palatino".
+*/
+TQStringList TQFontDatabase::families( TQFont::Script script ) const
+{
+ load();
+
+ TQStringList flist;
+ for ( int i = 0; i < d->count; i++ ) {
+ TQtFontFamily *f = d->families[i];
+ if ( f->count == 0 )
+ continue;
+ if (!(f->scripts[script] & TQtFontFamily::Supported))
+ continue;
+ if ( f->count == 1 ) {
+ flist.append( f->name );
+ } else {
+ for ( int j = 0; j < f->count; j++ ) {
+ TQString str = f->name;
+ TQString foundry = f->foundries[j]->name;
+ if ( !foundry.isEmpty() ) {
+ str += " [";
+ str += foundry;
+ str += "]";
+ }
+ flist.append( str );
+ }
+ }
+ }
+ return flist;
+}
+
+/*!
+ Returns a list of the styles available for the font family \a
+ family. Some example styles: "Light", "Light Italic", "Bold",
+ "Oblique", "Demi". The list may be empty.
+*/
+TQStringList TQFontDatabase::styles( const TQString &family ) const
+{
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQStringList l;
+ TQtFontFamily *f = d->family( familyName );
+ if ( !f )
+ return l;
+
+ TQtFontFoundry allStyles( foundryName );
+ for ( int j = 0; j < f->count; j++ ) {
+ TQtFontFoundry *foundry = f->foundries[j];
+ if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) {
+ for ( int k = 0; k < foundry->count; k++ ) {
+ TQtFontStyle::Key ke( foundry->styles[k]->key );
+ ke.stretch = 0;
+ allStyles.style( ke, TRUE );
+ }
+ }
+ }
+
+ for ( int i = 0; i < allStyles.count; i++ )
+ l.append( ::styleString( allStyles.styles[i]->key.weight,
+ allStyles.styles[i]->key.italic,
+ allStyles.styles[i]->key.oblique ) );
+ return l;
+}
+
+/*!
+ Returns TRUE if the font that has family \a family and style \a
+ style is fixed pitch; otherwise returns FALSE.
+*/
+
+bool TQFontDatabase::isFixedPitch(const TQString &family,
+ const TQString &style) const
+{
+ TQ_UNUSED(style);
+
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontFamily *f = d->family( familyName );
+#if defined(TQ_OS_MAC) && !defined(TQWS)
+ if (f) {
+ if (!f->fixedPitchComputed) {
+ TQFontMetrics fm(familyName);
+ f->fixedPitch = fm.width('i') == fm.width('m');
+ f->fixedPitchComputed = TRUE;
+ }
+ }
+#endif
+
+ return ( f && f->fixedPitch );
+}
+
+/*!
+ Returns TRUE if the font that has family \a family and style \a
+ style is a scalable bitmap font; otherwise returns FALSE. Scaling
+ a bitmap font usually produces an unattractive hardly readable
+ result, because the pixels of the font are scaled. If you need to
+ scale a bitmap font it is better to scale it to one of the fixed
+ sizes returned by smoothSizes().
+
+ \sa isScalable(), isSmoothlyScalable()
+*/
+bool TQFontDatabase::isBitmapScalable( const TQString &family,
+ const TQString &style) const
+{
+ bool bitmapScalable = FALSE;
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontStyle::Key styleKey( style );
+
+ TQtFontFamily *f = d->family( familyName );
+ if ( !f ) return bitmapScalable;
+
+ for ( int j = 0; j < f->count; j++ ) {
+ TQtFontFoundry *foundry = f->foundries[j];
+ if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) {
+ for ( int k = 0; k < foundry->count; k++ )
+ if ((style.isEmpty() || foundry->styles[k]->key == styleKey) &&
+ foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) {
+ bitmapScalable = TRUE;
+ goto end;
+ }
+ }
+ }
+ end:
+ return bitmapScalable;
+}
+
+
+/*!
+ Returns TRUE if the font that has family \a family and style \a
+ style is smoothly scalable; otherwise returns FALSE. If this
+ function returns TRUE, it's safe to scale this font to any size,
+ and the result will always look attractive.
+
+ \sa isScalable(), isBitmapScalable()
+*/
+bool TQFontDatabase::isSmoothlyScalable( const TQString &family,
+ const TQString &style) const
+{
+ bool smoothScalable = FALSE;
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontStyle::Key styleKey( style );
+
+ TQtFontFamily *f = d->family( familyName );
+ if ( !f ) return smoothScalable;
+
+ for ( int j = 0; j < f->count; j++ ) {
+ TQtFontFoundry *foundry = f->foundries[j];
+ if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) {
+ for ( int k = 0; k < foundry->count; k++ )
+ if ((style.isEmpty() || foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) {
+ smoothScalable = TRUE;
+ goto end;
+ }
+ }
+ }
+ end:
+ return smoothScalable;
+}
+
+/*!
+ Returns TRUE if the font that has family \a family and style \a
+ style is scalable; otherwise returns FALSE.
+
+ \sa isBitmapScalable(), isSmoothlyScalable()
+*/
+bool TQFontDatabase::isScalable( const TQString &family,
+ const TQString &style) const
+{
+ if ( isSmoothlyScalable( family, style) )
+ return TRUE;
+
+ return isBitmapScalable( family, style);
+}
+
+
+/*!
+ Returns a list of the point sizes available for the font that has
+ family \a family and style \a style. The list may be empty.
+
+ \sa smoothSizes(), standardSizes()
+*/
+TQValueList<int> TQFontDatabase::pointSizes( const TQString &family,
+ const TQString &style)
+{
+#if defined(TQ_WS_MAC)
+ // windows and macosx are always smoothly scalable
+ TQ_UNUSED( family );
+ TQ_UNUSED( style );
+ return standardSizes();
+#else
+ bool smoothScalable = FALSE;
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontStyle::Key styleKey( style );
+
+ TQValueList<int> sizes;
+
+ TQtFontFamily *fam = d->family( familyName );
+ if ( !fam ) return sizes;
+
+ for ( int j = 0; j < fam->count; j++ ) {
+ TQtFontFoundry *foundry = fam->foundries[j];
+ if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) {
+ TQtFontStyle *style = foundry->style( styleKey );
+ if ( !style ) continue;
+
+ if ( style->smoothScalable ) {
+ smoothScalable = TRUE;
+ goto end;
+ }
+ for ( int l = 0; l < style->count; l++ ) {
+ const TQtFontSize *size = style->pixelSizes + l;
+
+ if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
+#ifdef TQ_WS_X11
+ const uint pointSize = tqRound(qt_pointSize(size->pixelSize, 0, -1));
+#else
+ const uint pointSize = size->pixelSize; // embedded uses 72dpi
+#endif
+ if (! sizes.tqcontains(pointSize))
+ sizes.append(pointSize);
+ }
+ }
+ }
+ }
+ end:
+ if ( smoothScalable )
+ return standardSizes();
+
+ qHeapSort( sizes );
+ return sizes;
+#endif
+}
+
+/*!
+ Returns a TQFont object that has family \a family, style \a style
+ and point size \a pointSize. If no matching font could be created,
+ a TQFont object that uses the application's default font is
+ returned.
+*/
+TQFont TQFontDatabase::font( const TQString &family, const TQString &style,
+ int pointSize)
+{
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontFoundry allStyles( foundryName );
+ TQtFontFamily *f = d->family( familyName );
+ if ( !f ) return TQApplication::font();
+
+ for ( int j = 0; j < f->count; j++ ) {
+ TQtFontFoundry *foundry = f->foundries[j];
+ if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) {
+ for ( int k = 0; k < foundry->count; k++ )
+ allStyles.style( foundry->styles[k]->key, TRUE );
+ }
+ }
+
+ TQtFontStyle::Key styleKey( style );
+ TQtFontStyle *s = bestStyle(&allStyles, styleKey);
+
+ if ( !s ) // no styles found?
+ return TQApplication::font();
+ return TQFont( family, pointSize, s->key.weight,
+ s->key.italic ? TRUE : s->key.oblique ? TRUE : FALSE );
+}
+
+
+/*!
+ Returns the point sizes of a font that has family \a family and
+ style \a style that will look attractive. The list may be empty.
+ For non-scalable fonts and bitmap scalable fonts, this function
+ is equivalent to pointSizes().
+
+ \sa pointSizes(), standardSizes()
+*/
+TQValueList<int> TQFontDatabase::smoothSizes( const TQString &family,
+ const TQString &style)
+{
+#ifdef TQ_WS_WIN
+ TQ_UNUSED( family );
+ TQ_UNUSED( style );
+ return TQFontDatabase::standardSizes();
+#else
+ bool smoothScalable = FALSE;
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontStyle::Key styleKey( style );
+
+ TQValueList<int> sizes;
+
+ TQtFontFamily *fam = d->family( familyName );
+ if ( !fam )
+ return sizes;
+
+ for ( int j = 0; j < fam->count; j++ ) {
+ TQtFontFoundry *foundry = fam->foundries[j];
+ if ( foundryName.isEmpty() ||
+ ucstricmp( foundry->name, foundryName ) == 0 ) {
+ TQtFontStyle *style = foundry->style( styleKey );
+ if ( !style ) continue;
+
+ if ( style->smoothScalable ) {
+ smoothScalable = TRUE;
+ goto end;
+ }
+ for ( int l = 0; l < style->count; l++ ) {
+ const TQtFontSize *size = style->pixelSizes + l;
+
+ if ( size->pixelSize != 0 && size->pixelSize != USHRT_MAX ) {
+#ifdef TQ_WS_X11
+ const uint pointSize = tqRound(qt_pointSize(size->pixelSize, 0, -1));
+#else
+ const uint pointSize = size->pixelSize; // embedded uses 72dpi
+#endif
+ if (! sizes.tqcontains(pointSize))
+ sizes.append( pointSize );
+ }
+ }
+ }
+ }
+ end:
+ if ( smoothScalable )
+ return TQFontDatabase::standardSizes();
+
+ qHeapSort( sizes );
+ return sizes;
+#endif
+}
+
+
+/*!
+ Returns a list of standard font sizes.
+
+ \sa smoothSizes(), pointSizes()
+*/
+TQValueList<int> TQFontDatabase::standardSizes()
+{
+ TQValueList<int> ret;
+ static const unsigned short standard[] =
+ { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 };
+ const unsigned short *sizes = standard;
+ while ( *sizes ) ret << *sizes++;
+ return ret;
+}
+
+
+/*!
+ Returns TRUE if the font that has family \a family and style \a
+ style is italic; otherwise returns FALSE.
+
+ \sa weight(), bold()
+*/
+bool TQFontDatabase::italic( const TQString &family,
+ const TQString &style) const
+{
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontFoundry allStyles( foundryName );
+ TQtFontFamily *f = d->family( familyName );
+ if ( !f ) return FALSE;
+
+ for ( int j = 0; j < f->count; j++ ) {
+ TQtFontFoundry *foundry = f->foundries[j];
+ if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) {
+ for ( int k = 0; k < foundry->count; k++ )
+ allStyles.style( foundry->styles[k]->key, TRUE );
+ }
+ }
+
+ TQtFontStyle::Key styleKey( style );
+ TQtFontStyle *s = allStyles.style( styleKey );
+ return s && s->key.italic;
+}
+
+
+/*!
+ Returns TRUE if the font that has family \a family and style \a
+ style is bold; otherwise returns FALSE.
+
+ \sa italic(), weight()
+*/
+bool TQFontDatabase::bold( const TQString &family,
+ const TQString &style) const
+{
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontFoundry allStyles( foundryName );
+ TQtFontFamily *f = d->family( familyName );
+ if ( !f ) return FALSE;
+
+ for ( int j = 0; j < f->count; j++ ) {
+ TQtFontFoundry *foundry = f->foundries[j];
+ if ( foundryName.isEmpty() ||
+ ucstricmp( foundry->name, foundryName ) == 0 ) {
+ for ( int k = 0; k < foundry->count; k++ )
+ allStyles.style( foundry->styles[k]->key, TRUE );
+ }
+ }
+
+ TQtFontStyle::Key styleKey( style );
+ TQtFontStyle *s = allStyles.style( styleKey );
+ return s && s->key.weight >= TQFont::Bold;
+}
+
+
+/*!
+ Returns the weight of the font that has family \a family and style
+ \a style. If there is no such family and style combination,
+ returns -1.
+
+ \sa italic(), bold()
+*/
+int TQFontDatabase::weight( const TQString &family,
+ const TQString &style) const
+{
+ TQString familyName, foundryName;
+ parseFontName( family, foundryName, familyName );
+
+ load( familyName );
+
+ TQtFontFoundry allStyles( foundryName );
+ TQtFontFamily *f = d->family( familyName );
+ if ( !f ) return -1;
+
+ for ( int j = 0; j < f->count; j++ ) {
+ TQtFontFoundry *foundry = f->foundries[j];
+ if ( foundryName.isEmpty() ||
+ ucstricmp( foundry->name, foundryName ) == 0 ) {
+ for ( int k = 0; k < foundry->count; k++ )
+ allStyles.style( foundry->styles[k]->key, TRUE );
+ }
+ }
+
+ TQtFontStyle::Key styleKey( style );
+ TQtFontStyle *s = allStyles.style( styleKey );
+ return s ? s->key.weight : -1;
+}
+
+
+/*!
+ Returns a string that gives a default description of the \a script
+ (e.g. for displaying to the user in a dialog). The name matches
+ the name of the script as defined by the Unicode 3.0 standard.
+
+ \sa TQFont::Script
+*/
+TQString TQFontDatabase::scriptName(TQFont::Script script)
+{
+ const char *name = 0;
+
+ switch (script) {
+ case TQFont::Latin:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Latin");
+ break;
+ case TQFont::Greek:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Greek" );
+ break;
+ case TQFont::Cyrillic:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Cyrillic" );
+ break;
+ case TQFont::Armenian:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Armenian" );
+ break;
+ case TQFont::Georgian:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Georgian" );
+ break;
+ case TQFont::Runic:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Runic" );
+ break;
+ case TQFont::Ogham:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Ogham" );
+ break;
+ case TQFont::SpacingModifiers:
+ name = TQT_TRANSLATE_NOOP("TQFont", "SpacingModifiers" );
+ break;
+ case TQFont::CombiningMarks:
+ name = TQT_TRANSLATE_NOOP("TQFont", "CombiningMarks" );
+ break;
+ case TQFont::Hebrew:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Hebrew" );
+ break;
+ case TQFont::Arabic:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Arabic" );
+ break;
+ case TQFont::Syriac:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Syriac" );
+ break;
+ case TQFont::Thaana:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Thaana" );
+ break;
+ case TQFont::Devanagari:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Devanagari" );
+ break;
+ case TQFont::Bengali:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Bengali" );
+ break;
+ case TQFont::Gurmukhi:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Gurmukhi" );
+ break;
+ case TQFont::Gujarati:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Gujarati" );
+ break;
+ case TQFont::Oriya:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Oriya" );
+ break;
+ case TQFont::Tamil:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Tamil" );
+ break;
+ case TQFont::Telugu:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Telugu" );
+ break;
+ case TQFont::Kannada:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Kannada" );
+ break;
+ case TQFont::Malayalam:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Malayalam" );
+ break;
+ case TQFont::Sinhala:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Sinhala" );
+ break;
+ case TQFont::Thai:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Thai" );
+ break;
+ case TQFont::Lao:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Lao" );
+ break;
+ case TQFont::Tibetan:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Tibetan" );
+ break;
+ case TQFont::Myanmar:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Myanmar" );
+ break;
+ case TQFont::Khmer:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Khmer" );
+ break;
+ case TQFont::Han:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Han" );
+ break;
+ case TQFont::Hiragana:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Hiragana" );
+ break;
+ case TQFont::Katakana:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Katakana" );
+ break;
+ case TQFont::Hangul:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Hangul" );
+ break;
+ case TQFont::Bopomofo:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Bopomofo" );
+ break;
+ case TQFont::Yi:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Yi" );
+ break;
+ case TQFont::Ethiopic:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Ethiopic" );
+ break;
+ case TQFont::Cherokee:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Cherokee" );
+ break;
+ case TQFont::CanadianAboriginal:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Canadian Aboriginal" );
+ break;
+ case TQFont::Mongolian:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Mongolian" );
+ break;
+
+ case TQFont::CurrencySymbols:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Currency Symbols" );
+ break;
+
+ case TQFont::LetterlikeSymbols:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Letterlike Symbols" );
+ break;
+
+ case TQFont::NumberForms:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Number Forms" );
+ break;
+
+ case TQFont::MathematicalOperators:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Mathematical Operators" );
+ break;
+
+ case TQFont::TechnicalSymbols:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Technical Symbols" );
+ break;
+
+ case TQFont::GeometricSymbols:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Geometric Symbols" );
+ break;
+
+ case TQFont::MiscellaneousSymbols:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Miscellaneous Symbols" );
+ break;
+
+ case TQFont::EnclosedAndSquare:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Enclosed and Square" );
+ break;
+
+ case TQFont::Braille:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Braille" );
+ break;
+
+ case TQFont::Unicode:
+ name = TQT_TRANSLATE_NOOP("TQFont", "Unicode" );
+ break;
+
+ case TQFont::Tagalog:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Tagalog" );
+ break;
+
+ case TQFont::Hanunoo:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Hanunoo" );
+ break;
+
+ case TQFont::Buhid:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Buhid" );
+ break;
+
+ case TQFont::Tagbanwa:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Tagbanwa" );
+ break;
+
+ case TQFont::KatakanaHalfWidth:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Katakana Half-Width Forms" );
+ break;
+
+ case TQFont::Han_Japanese:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Japanese)" );
+ break;
+
+ case TQFont::Han_SimplifiedChinese:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Simplified Chinese)" );
+ break;
+
+ case TQFont::Han_TraditionalChinese:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Traditional Chinese)" );
+ break;
+
+ case TQFont::Han_Korean:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Korean)" );
+ break;
+
+ default:
+ name = TQT_TRANSLATE_NOOP( "TQFont", "Unknown Script" );
+ break;
+ }
+
+ return tqApp ? tqApp->translate("TQFont", name) : TQString::tqfromLatin1(name);
+}
+
+
+/*!
+ Returns a string with sample characters from \a script.
+
+ \sa TQFont::Script
+*/
+TQString TQFontDatabase::scriptSample(TQFont::Script script)
+{
+ TQString sample = "AaBb";
+
+ switch (script) {
+ case TQFont::Latin:
+ // This is cheating... we only show latin-1 characters so that we don't
+ // end up loading lots of fonts - at least on X11...
+ sample += TQChar(0x00C3);
+ sample += TQChar(0x00E1);
+ sample += "Zz";
+ break;
+ case TQFont::Greek:
+ sample += TQChar(0x0393);
+ sample += TQChar(0x03B1);
+ sample += TQChar(0x03A9);
+ sample += TQChar(0x03C9);
+ break;
+ case TQFont::Cyrillic:
+ sample += TQChar(0x0414);
+ sample += TQChar(0x0434);
+ sample += TQChar(0x0436);
+ sample += TQChar(0x0402);
+ break;
+ case TQFont::Armenian:
+ sample += TQChar(0x053f);
+ sample += TQChar(0x054f);
+ sample += TQChar(0x056f);
+ sample += TQChar(0x057f);
+ break;
+ case TQFont::Georgian:
+ sample += TQChar(0x10a0);
+ sample += TQChar(0x10b0);
+ sample += TQChar(0x10c0);
+ sample += TQChar(0x10d0);
+ break;
+ case TQFont::Runic:
+ sample += TQChar(0x16a0);
+ sample += TQChar(0x16b0);
+ sample += TQChar(0x16c0);
+ sample += TQChar(0x16d0);
+ break;
+ case TQFont::Ogham:
+ sample += TQChar(0x1681);
+ sample += TQChar(0x1687);
+ sample += TQChar(0x1693);
+ sample += TQChar(0x168d);
+ break;
+
+
+
+ case TQFont::Hebrew:
+ sample += TQChar(0x05D0);
+ sample += TQChar(0x05D1);
+ sample += TQChar(0x05D2);
+ sample += TQChar(0x05D3);
+ break;
+ case TQFont::Arabic:
+ sample += TQChar(0x0628);
+ sample += TQChar(0x0629);
+ sample += TQChar(0x062A);
+ sample += TQChar(0x063A);
+ break;
+ case TQFont::Syriac:
+ sample += TQChar(0x0715);
+ sample += TQChar(0x0725);
+ sample += TQChar(0x0716);
+ sample += TQChar(0x0726);
+ break;
+ case TQFont::Thaana:
+ sample += TQChar(0x0784);
+ sample += TQChar(0x0794);
+ sample += TQChar(0x078c);
+ sample += TQChar(0x078d);
+ break;
+
+
+
+ case TQFont::Devanagari:
+ sample += TQChar(0x0905);
+ sample += TQChar(0x0915);
+ sample += TQChar(0x0925);
+ sample += TQChar(0x0935);
+ break;
+ case TQFont::Bengali:
+ sample += TQChar(0x0986);
+ sample += TQChar(0x0996);
+ sample += TQChar(0x09a6);
+ sample += TQChar(0x09b6);
+ break;
+ case TQFont::Gurmukhi:
+ sample += TQChar(0x0a05);
+ sample += TQChar(0x0a15);
+ sample += TQChar(0x0a25);
+ sample += TQChar(0x0a35);
+ break;
+ case TQFont::Gujarati:
+ sample += TQChar(0x0a85);
+ sample += TQChar(0x0a95);
+ sample += TQChar(0x0aa5);
+ sample += TQChar(0x0ab5);
+ break;
+ case TQFont::Oriya:
+ sample += TQChar(0x0b06);
+ sample += TQChar(0x0b16);
+ sample += TQChar(0x0b2b);
+ sample += TQChar(0x0b36);
+ break;
+ case TQFont::Tamil:
+ sample += TQChar(0x0b89);
+ sample += TQChar(0x0b99);
+ sample += TQChar(0x0ba9);
+ sample += TQChar(0x0bb9);
+ break;
+ case TQFont::Telugu:
+ sample += TQChar(0x0c05);
+ sample += TQChar(0x0c15);
+ sample += TQChar(0x0c25);
+ sample += TQChar(0x0c35);
+ break;
+ case TQFont::Kannada:
+ sample += TQChar(0x0c85);
+ sample += TQChar(0x0c95);
+ sample += TQChar(0x0ca5);
+ sample += TQChar(0x0cb5);
+ break;
+ case TQFont::Malayalam:
+ sample += TQChar(0x0d05);
+ sample += TQChar(0x0d15);
+ sample += TQChar(0x0d25);
+ sample += TQChar(0x0d35);
+ break;
+ case TQFont::Sinhala:
+ sample += TQChar(0x0d90);
+ sample += TQChar(0x0da0);
+ sample += TQChar(0x0db0);
+ sample += TQChar(0x0dc0);
+ break;
+ case TQFont::Thai:
+ sample += TQChar(0x0e02);
+ sample += TQChar(0x0e12);
+ sample += TQChar(0x0e22);
+ sample += TQChar(0x0e32);
+ break;
+ case TQFont::Lao:
+ sample += TQChar(0x0e8d);
+ sample += TQChar(0x0e9d);
+ sample += TQChar(0x0ead);
+ sample += TQChar(0x0ebd);
+ break;
+ case TQFont::Tibetan:
+ sample += TQChar(0x0f00);
+ sample += TQChar(0x0f01);
+ sample += TQChar(0x0f02);
+ sample += TQChar(0x0f03);
+ break;
+ case TQFont::Myanmar:
+ sample += TQChar(0x1000);
+ sample += TQChar(0x1001);
+ sample += TQChar(0x1002);
+ sample += TQChar(0x1003);
+ break;
+ case TQFont::Khmer:
+ sample += TQChar(0x1780);
+ sample += TQChar(0x1790);
+ sample += TQChar(0x17b0);
+ sample += TQChar(0x17c0);
+ break;
+
+
+
+ case TQFont::Han:
+ sample += TQChar(0x6f84);
+ sample += TQChar(0x820a);
+ sample += TQChar(0x61a9);
+ sample += TQChar(0x9781);
+ break;
+ case TQFont::Hiragana:
+ sample += TQChar(0x3050);
+ sample += TQChar(0x3060);
+ sample += TQChar(0x3070);
+ sample += TQChar(0x3080);
+ break;
+ case TQFont::Katakana:
+ sample += TQChar(0x30b0);
+ sample += TQChar(0x30c0);
+ sample += TQChar(0x30d0);
+ sample += TQChar(0x30e0);
+ break;
+ case TQFont::Hangul:
+ sample += TQChar(0xac00);
+ sample += TQChar(0xac11);
+ sample += TQChar(0xac1a);
+ sample += TQChar(0xac2f);
+ break;
+ case TQFont::Bopomofo:
+ sample += TQChar(0x3105);
+ sample += TQChar(0x3115);
+ sample += TQChar(0x3125);
+ sample += TQChar(0x3129);
+ break;
+ case TQFont::Yi:
+ sample += TQChar(0xa1a8);
+ sample += TQChar(0xa1a6);
+ sample += TQChar(0xa200);
+ sample += TQChar(0xa280);
+ break;
+
+
+
+ case TQFont::Ethiopic:
+ sample += TQChar(0x1200);
+ sample += TQChar(0x1240);
+ sample += TQChar(0x1280);
+ sample += TQChar(0x12c0);
+ break;
+ case TQFont::Cherokee:
+ sample += TQChar(0x13a0);
+ sample += TQChar(0x13b0);
+ sample += TQChar(0x13c0);
+ sample += TQChar(0x13d0);
+ break;
+ case TQFont::CanadianAboriginal:
+ sample += TQChar(0x1410);
+ sample += TQChar(0x1500);
+ sample += TQChar(0x15f0);
+ sample += TQChar(0x1650);
+ break;
+ case TQFont::Mongolian:
+ sample += TQChar(0x1820);
+ sample += TQChar(0x1840);
+ sample += TQChar(0x1860);
+ sample += TQChar(0x1880);
+ break;
+
+
+ case TQFont::CurrencySymbols:
+ case TQFont::LetterlikeSymbols:
+ case TQFont::NumberForms:
+ case TQFont::MathematicalOperators:
+ case TQFont::TechnicalSymbols:
+ case TQFont::GeometricSymbols:
+ case TQFont::MiscellaneousSymbols:
+ case TQFont::EnclosedAndSquare:
+ case TQFont::Braille:
+ break;
+
+
+ case TQFont::Unicode:
+ sample += TQChar(0x0174);
+ sample += TQChar(0x0628);
+ sample += TQChar(0x0e02);
+ sample += TQChar(0x263A);
+ sample += TQChar(0x3129);
+ sample += TQChar(0x61a9);
+ sample += TQChar(0xac2f);
+ break;
+
+
+
+ default:
+ sample += TQChar(0xfffd);
+ sample += TQChar(0xfffd);
+ sample += TQChar(0xfffd);
+ sample += TQChar(0xfffd);
+ break;
+ }
+
+ return sample;
+}
+
+
+
+
+/*!
+ \internal
+
+ This makes sense of the font family name:
+
+ 1) if the family name tqcontains a '-' (ie. "Adobe-Courier"), then we
+ split at the '-', and use the string as the foundry, and the string to
+ the right as the family
+
+ 2) if the family name tqcontains a '[' and a ']', then we take the text
+ between the square brackets as the foundry, and the text before the
+ square brackets as the family (ie. "Arial [Monotype]")
+*/
+void TQFontDatabase::parseFontName(const TQString &name, TQString &foundry, TQString &family)
+{
+ if ( name.tqcontains('-') ) {
+ int i = name.tqfind('-');
+ foundry = name.left( i );
+ family = name.right( name.length() - i - 1 );
+ } else if ( name.tqcontains('[') && name.tqcontains(']')) {
+ int i = name.tqfind('[');
+ int li = name.tqfindRev(']');
+
+ if (i < li) {
+ foundry = name.mid(i + 1, li - i - 1);
+ if (name[i - 1] == ' ')
+ i--;
+ family = name.left(i);
+ }
+ } else {
+ foundry = TQString::null;
+ family = name;
+ }
+}
+
+#endif // USE_QT4
+
+#endif // TQT_NO_FONTDATABASE
diff --git a/tqtinterface/qt4/src/kernel/tqfontdatabase.h b/tqtinterface/qt4/src/kernel/tqfontdatabase.h
new file mode 100644
index 0000000..f2556ef
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontdatabase.h
@@ -0,0 +1,306 @@
+/****************************************************************************
+**
+** Definition of the TQFontDatabase class
+**
+** Created : 981126
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQFONTDATABASE_H
+#define TQFONTDATABASE_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqstring.h"
+#include "tqstringlist.h"
+#include "tqfont.h"
+#include "tqvaluelist.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qfontdatabase.h>
+#include <Qt/qstringlist.h>
+
+#endif // USE_QT4
+
+#ifndef TQT_NO_FONTDATABASE
+
+#ifndef USE_QT4
+
+class TQFontStylePrivate; /* Don't touch! */
+
+#endif // USE_QT4
+
+struct TQtFontStyle;
+struct TQtFontFamily;
+struct TQtFontFoundry;
+struct TQFontDef;
+class TQFontEngine;
+#ifdef TQ_WS_TQWS
+class TQDiskFont;
+#endif
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQFontDatabase : public QFontDatabase, virtual public TQt
+{
+public:
+ TQFontDatabase() : QFontDatabase() {}
+
+// private:
+// static inline TQFontEngine *tqfindFont( TQFont::Script script, const QFontPrivate *fp, const QFontDef &request, int force_encoding_id = -1 ) { return findFont(script, fp, request, force_encoding_id); }
+
+ static inline TQString scriptName( TQFont::Script s ) { return writingSystemName((QFontDatabase::WritingSystem)s); }
+ static inline TQString scriptSample( TQFont::Script s ) { return writingSystemSample((QFontDatabase::WritingSystem)s); }
+ inline TQStringList tqfamilies() const {
+ QStringList ql = families();
+ TQStringList tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+ inline TQStringList tqfamilies( TQFont::Script s ) const {
+ QStringList ql = families((QFontDatabase::WritingSystem)s);
+ TQStringList tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+ inline TQStringList tqstyles( const QString &s ) const {
+ QStringList ql = styles(s);
+ TQStringList tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+ inline TQValueList<int> tqpointSizes(const QString &s, const QString &t = QString()) {
+ QList<int> ql = pointSizes(s, t);
+ TQValueList<int> tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+
+ inline static TQValueList<int> tqstandardSizes() {
+ QList<int> ql = standardSizes();
+ TQValueList<int> tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+ inline TQValueList<int> tqsmoothSizes( const TQString &s, const TQString &t) {
+ QList<int> ql = smoothSizes(s, t);
+ TQValueList<int> tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+
+private:
+ static void tqparseFontName(const QString &name, QString &foundry, QString &family);
+
+ friend class TQFontDialog;
+};
+
+#else // USE_QT4
+
+class TQFontDatabasePrivate;
+
+class TQ_EXPORT TQFontDatabase
+{
+public:
+ static TQValueList<int> standardSizes();
+
+ TQFontDatabase();
+
+ TQStringList families() const;
+ TQStringList families( TQFont::Script ) const;
+ TQStringList styles( const TQString & ) const;
+ TQValueList<int> pointSizes( const TQString &, const TQString & = TQString::null);
+ TQValueList<int> smoothSizes( const TQString &, const TQString &);
+ TQString styleString( const TQFont &);
+
+ TQFont font( const TQString &, const TQString &, int);
+
+ bool isBitmapScalable( const TQString &, const TQString & = TQString::null) const;
+ bool isSmoothlyScalable( const TQString &, const TQString & = TQString::null) const;
+ bool isScalable( const TQString &, const TQString & = TQString::null) const;
+ bool isFixedPitch( const TQString &, const TQString & = TQString::null) const;
+
+ bool italic( const TQString &, const TQString &) const;
+ bool bold( const TQString &, const TQString &) const;
+ int weight( const TQString &, const TQString &) const;
+
+ static TQString scriptName(TQFont::Script);
+ static TQString scriptSample(TQFont::Script);
+
+#ifdef TQ_WS_TQWS
+ static void qwsAddDiskFont( TQDiskFont *qdf );
+#endif
+
+ // For source compatibility with < 3.0
+#ifndef TQT_NO_COMPAT
+
+ TQStringList families(bool) const;
+ TQStringList styles( const TQString &, const TQString & ) const;
+ TQValueList<int> pointSizes( const TQString &, const TQString &, const TQString & );
+ TQValueList<int> smoothSizes( const TQString &, const TQString &, const TQString & );
+
+ TQFont font( const TQString &, const TQString &, int, const TQString &);
+
+ bool isBitmapScalable( const TQString &, const TQString &, const TQString & ) const;
+ bool isSmoothlyScalable( const TQString &, const TQString &, const TQString & ) const;
+ bool isScalable( const TQString &, const TQString &, const TQString & ) const;
+ bool isFixedPitch( const TQString &, const TQString &, const TQString & ) const;
+
+ bool italic( const TQString &, const TQString &, const TQString & ) const;
+ bool bold( const TQString &, const TQString &, const TQString & ) const;
+ int weight( const TQString &, const TQString &, const TQString & ) const;
+
+#endif // TQT_NO_COMPAT
+
+private:
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+ static TQFontEngine *tqfindFont( TQFont::Script script, const TQFontPrivate *fp,
+ const TQFontDef &request, int force_encoding_id = -1 );
+#endif // TQ_WS_X11
+
+ static void createDatabase();
+
+ static void parseFontName(const TQString &name, TQString &foundry, TQString &family);
+
+ friend struct TQFontDef;
+ friend class TQFontPrivate;
+ friend class TQFontDialog;
+ friend class TQFontEngineLatinXLFD;
+
+ TQFontDatabasePrivate *d;
+};
+
+
+#ifndef TQT_NO_COMPAT
+
+inline TQStringList TQFontDatabase::families( bool ) const
+{
+ return families();
+}
+
+inline TQStringList TQFontDatabase::styles( const TQString &family,
+ const TQString & ) const
+{
+ return styles(family);
+}
+
+inline TQValueList<int> TQFontDatabase::pointSizes( const TQString &family,
+ const TQString &style ,
+ const TQString & )
+{
+ return pointSizes(family, style);
+}
+
+inline TQValueList<int> TQFontDatabase::smoothSizes( const TQString &family,
+ const TQString &style,
+ const TQString & )
+{
+ return smoothSizes(family, style);
+}
+
+inline TQFont TQFontDatabase::font( const TQString &familyName,
+ const TQString &style,
+ int pointSize,
+ const TQString &)
+{
+ return font(familyName, style, pointSize);
+}
+
+inline bool TQFontDatabase::isBitmapScalable( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+{
+ return isBitmapScalable(family, style);
+}
+
+inline bool TQFontDatabase::isSmoothlyScalable( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+{
+ return isSmoothlyScalable(family, style);
+}
+
+inline bool TQFontDatabase::isScalable( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+{
+ return isScalable(family, style);
+}
+
+inline bool TQFontDatabase::isFixedPitch( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+{
+ return isFixedPitch(family, style);
+}
+
+inline bool TQFontDatabase::italic( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+{
+ return italic(family, style);
+}
+
+inline bool TQFontDatabase::bold( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+{
+ return bold(family, style);
+}
+
+inline int TQFontDatabase::weight( const TQString &family,
+ const TQString &style,
+ const TQString & ) const
+{
+ return weight(family, style);
+}
+
+#endif // TQT_NO_COMPAT
+
+#endif // USE_QT4
+
+#endif // TQT_NO_FONTDATABASE
+
+#endif // TQFONTDATABASE_H
diff --git a/tqtinterface/qt4/src/kernel/tqfontdatabase_x11.cpp b/tqtinterface/qt4/src/kernel/tqfontdatabase_x11.cpp
new file mode 100644
index 0000000..8ea403f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontdatabase_x11.cpp
@@ -0,0 +1,2008 @@
+/****************************************************************************
+**
+** Implementation of platform specific TQFontDatabase
+**
+** Created : 970521
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqplatformdefs.h>
+
+#include <tqdatetime.h>
+#include <tqpaintdevicemetrics.h>
+
+#include "tqt_x11_p.h"
+
+#include <ctype.h>
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#ifndef TQT_NO_XFTFREETYPE
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#endif
+
+#ifndef TQT_XFT2
+#define FcBool Bool
+#define FcTrue True
+#define FcFalse False
+#endif
+
+#ifdef TQFONTDATABASE_DEBUG
+# define FD_DEBUG qDebug
+#else
+# define FD_DEBUG if (FALSE) qDebug
+#endif // TQFONTDATABASE_DEBUG
+
+// from qfont_x11.cpp
+extern double qt_pointSize(double pixelSize, TQPaintDevice *painttqdevice, int screen);
+extern double qt_pixelSize(double pointSize, TQPaintDevice *painttqdevice, int screen);
+
+
+static inline void capitalize ( char *s )
+{
+ bool space = TRUE;
+ while( *s ) {
+ if ( space )
+ *s = toupper( *s );
+ space = ( *s == ' ' );
+ ++s;
+ }
+}
+
+
+// ----- begin of generated code -----
+
+#define make_tag( c1, c2, c3, c4 ) \
+( (((unsigned int)c1)<<24) | (((unsigned int)c2)<<16) | \
+(((unsigned int)c3)<<8) | ((unsigned int)c4) )
+
+struct XlfdEncoding {
+ const char *name;
+ int id;
+ int mib;
+ unsigned int hash1;
+ unsigned int hash2;
+};
+
+static const XlfdEncoding xlfd_encoding[] = {
+ { "iso8859-1", 0, 4, make_tag('i','s','o','8'), make_tag('5','9','-','1') },
+ { "iso8859-2", 1, 5, make_tag('i','s','o','8'), make_tag('5','9','-','2') },
+ { "iso8859-3", 2, 6, make_tag('i','s','o','8'), make_tag('5','9','-','3') },
+ { "iso8859-4", 3, 7, make_tag('i','s','o','8'), make_tag('5','9','-','4') },
+ { "iso8859-9", 4, 12, make_tag('i','s','o','8'), make_tag('5','9','-','9') },
+ { "iso8859-10", 5, 13, make_tag('i','s','o','8'), make_tag('9','-','1','0') },
+ { "iso8859-13", 6, 109, make_tag('i','s','o','8'), make_tag('9','-','1','3') },
+ { "iso8859-14", 7, 110, make_tag('i','s','o','8'), make_tag('9','-','1','4') },
+ { "iso8859-15", 8, 111, make_tag('i','s','o','8'), make_tag('9','-','1','5') },
+ { "hp-roman8", 9, 2004, make_tag('h','p','-','r'), make_tag('m','a','n','8') },
+ { "jisx0208*-0", 10, 63, make_tag('j','i','s','x'), 0 },
+#define LAST_LATIN_ENCODING 10
+ { "iso8859-5", 11, 8, make_tag('i','s','o','8'), make_tag('5','9','-','5') },
+ { "*-cp1251", 12, 2251, 0, make_tag('1','2','5','1') },
+ { "koi8-ru", 13, 2084, make_tag('k','o','i','8'), make_tag('8','-','r','u') },
+ { "koi8-u", 14, 2088, make_tag('k','o','i','8'), make_tag('i','8','-','u') },
+ { "koi8-r", 15, 2084, make_tag('k','o','i','8'), make_tag('i','8','-','r') },
+ { "iso8859-7", 16, 10, make_tag('i','s','o','8'), make_tag('5','9','-','7') },
+ { "iso10646-1", 17, 0, make_tag('i','s','o','1'), make_tag('4','6','-','1') },
+ { "iso8859-8", 18, 85, make_tag('i','s','o','8'), make_tag('5','9','-','8') },
+ { "gb18030-0", 19, -114, make_tag('g','b','1','8'), make_tag('3','0','-','0') },
+ { "gb18030.2000-0", 20, -113, make_tag('g','b','1','8'), make_tag('0','0','-','0') },
+ { "gbk-0", 21, -113, make_tag('g','b','k','-'), make_tag('b','k','-','0') },
+ { "gb2312.*-0", 22, 57, make_tag('g','b','2','3'), 0 },
+ { "jisx0201*-0", 23, 15, make_tag('j','i','s','x'), 0 },
+ { "ksc5601*-*", 24, 36, make_tag('k','s','c','5'), 0 },
+ { "big5hkscs-0", 25, -2101, make_tag('b','i','g','5'), make_tag('c','s','-','0') },
+ { "hkscs-1", 26, -2101, make_tag('h','k','s','c'), make_tag('c','s','-','1') },
+ { "big5*-*", 27, -2026, make_tag('b','i','g','5'), 0 },
+ { "tscii-*", 28, 2028, make_tag('t','s','c','i'), 0 },
+ { "tis620*-*", 29, 2259, make_tag('t','i','s','6'), 0 },
+ { "iso8859-11", 30, 2259, make_tag('i','s','o','8'), make_tag('9','-','1','1') },
+ { "mulelao-1", 31, -4242, make_tag('m','u','l','e'), make_tag('a','o','-','1') },
+ { "ethiopic-tqunicode", 32, 0, make_tag('e','t','h','i'), make_tag('c','o','d','e') },
+ { "tqunicode-*", 33, 0, make_tag('u','n','i','c'), 0 },
+ { "*-symbol", 34, 0, 0, make_tag('m','b','o','l') },
+ { "*-fontspecific", 35, 0, 0, make_tag('i','f','i','c') },
+ { "fontspecific-*", 36, 0, make_tag('f','o','n','t'), 0 },
+ { 0, 0, 0, 0, 0 }
+};
+
+static const char scripts_for_xlfd_encoding[37][61] = {
+ // iso8859-1
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-2
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-3
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-4
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-9
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-10
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-13
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-14
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-15
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // hp-roman8
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // jisx0208*-0
+ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
+ 0 },
+ // iso8859-5
+ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // *-cp1251
+ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // koi8-ru
+ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // koi8-u
+ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // koi8-r
+ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-7
+ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso10646-1
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-8
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // gb18030-0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0 },
+ // gb18030.2000-0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0 },
+ // gbk-0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0 },
+ // gb2312.*-0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0 },
+ // jisx0201*-0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // ksc5601*-*
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1 },
+ // big5hkscs-0
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0 },
+ // hkscs-1
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0 },
+ // big5*-*
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0 },
+ // tscii-*
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // tis620*-*
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // iso8859-11
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // mulelao-1
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // ethiopic-tqunicode
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // tqunicode-*
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0 },
+ // *-symbol
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
+ 0 },
+ // *-fontspecific
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
+ 0 },
+ // fontspecific-*
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
+ 0 }
+
+};
+
+// ----- end of generated code -----
+
+
+const int numEncodings = sizeof( xlfd_encoding ) / sizeof( XlfdEncoding ) - 1;
+
+int qt_xlfd_encoding_id( const char *encoding )
+{
+ // qDebug("looking for encoding id for '%s'", encoding );
+ int len = strlen( encoding );
+ if ( len < 4 )
+ return -1;
+ unsigned int hash1 = make_tag( encoding[0], encoding[1], encoding[2], encoding[3] );
+ const char *ch = encoding + len - 4;
+ unsigned int hash2 = make_tag( ch[0], ch[1], ch[2], ch[3] );
+
+ const XlfdEncoding *enc = xlfd_encoding;
+ for ( ; enc->name; ++enc ) {
+ if ( (enc->hash1 && enc->hash1 != hash1) ||
+ (enc->hash2 && enc->hash2 != hash2) )
+ continue;
+ // hashes match, do a compare if strings match
+ // the enc->name can contain '*'s we have to interpret correctly
+ const char *n = enc->name;
+ const char *e = encoding;
+ while ( 1 ) {
+ // qDebug("bol: *e='%c', *n='%c'", *e, *n );
+ if ( *e == '\0' ) {
+ if ( *n )
+ break;
+ // qDebug( "found encoding id %d", enc->id );
+ return enc->id;
+ }
+ if ( *e == *n ) {
+ ++e;
+ ++n;
+ continue;
+ }
+ if ( *n != '*' )
+ break;
+ ++n;
+ // qDebug("skip: *e='%c', *n='%c'", *e, *n );
+ while ( *e && *e != *n )
+ ++e;
+ }
+ }
+ // qDebug( "couldn't tqfind encoding %s", encoding );
+ return -1;
+}
+
+int qt_mib_for_xlfd_encoding( const char *encoding )
+{
+ int id = qt_xlfd_encoding_id( encoding );
+ if ( id != -1 ) return xlfd_encoding[id].mib;
+ return 0;
+}
+
+int qt_encoding_id_for_mib( int mib )
+{
+ const XlfdEncoding *enc = xlfd_encoding;
+ for ( ; enc->name; ++enc ) {
+ if ( enc->mib == mib )
+ return enc->id;
+ }
+ return -1;
+}
+
+static const char * xlfd_for_id( int id )
+{
+ // special case: -1 returns the "*-*" encoding, allowing us to do full
+ // database population in a single X server round trip.
+ if ( id < 0 || id > numEncodings )
+ return "*-*";
+ return xlfd_encoding[id].name;
+}
+
+enum XLFDFieldNames {
+ Foundry,
+ Family,
+ Weight,
+ Slant,
+ Width,
+ AddStyle,
+ PixelSize,
+ PointSize,
+ ResolutionX,
+ ResolutionY,
+ Spacing,
+ AverageWidth,
+ CharsetRegistry,
+ CharsetEncoding,
+ NFontFields
+};
+
+// Splits an X font name into fields separated by '-'
+static bool parseXFontName( char *fontName, char **tokens )
+{
+ if ( ! fontName || fontName[0] == '0' || fontName[0] != '-' ) {
+ tokens[0] = 0;
+ return FALSE;
+ }
+
+ int i;
+ ++fontName;
+ for ( i = 0; i < NFontFields && fontName && fontName[0]; ++i ) {
+ tokens[i] = fontName;
+ for ( ;; ++fontName ) {
+ if ( *fontName == '-' )
+ break;
+ if ( ! *fontName ) {
+ fontName = 0;
+ break;
+ }
+ }
+
+ if ( fontName ) *fontName++ = '\0';
+ }
+
+ if ( i < NFontFields ) {
+ for ( int j = i ; j < NFontFields; ++j )
+ tokens[j] = 0;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static inline bool isZero(char *x)
+{
+ return (x[0] == '0' && x[1] == 0);
+}
+
+static inline bool isScalable( char **tokens )
+{
+ return (isZero(tokens[PixelSize]) &&
+ isZero(tokens[PointSize]) &&
+ isZero(tokens[AverageWidth]));
+}
+
+static inline bool isSmoothlyScalable( char **tokens )
+{
+ return (isZero(tokens[ResolutionX]) &&
+ isZero(tokens[ResolutionY]));
+}
+
+static inline bool isFixedPitch( char **tokens )
+{
+ return (tokens[Spacing][0] == 'm' ||
+ tokens[Spacing][0] == 'c' ||
+ tokens[Spacing][0] == 'M' ||
+ tokens[Spacing][0] == 'C');
+}
+
+/*
+ Fills in a font definition (TQFontDef) from an XLFD (X Logical Font
+ Description).
+
+ Returns TRUE if the the given xlfd is valid. The fields lbearing
+ and rbearing are not given any values.
+*/
+bool qt_fillFontDef( const TQCString &xlfd, TQFontDef *fd, int screen )
+{
+ char *tokens[NFontFields];
+ TQCString buffer = xlfd.copy();
+ if ( ! parseXFontName(buffer.data(), tokens) )
+ return FALSE;
+
+ capitalize(tokens[Family]);
+ capitalize(tokens[Foundry]);
+
+ fd->family = TQString::tqfromLatin1(tokens[Family]);
+ TQString foundry = TQString::tqfromLatin1(tokens[Foundry]);
+ if ( ! foundry.isEmpty() && foundry != TQString::tqfromLatin1("*") )
+ fd->family +=
+ TQString::tqfromLatin1(" [") + foundry + TQString::tqfromLatin1("]");
+
+ if ( tqstrlen( tokens[AddStyle] ) > 0 )
+ fd->addStyle = TQString::tqfromLatin1(tokens[AddStyle]);
+ else
+ fd->addStyle = TQString::null;
+
+ fd->pointSize = atoi(tokens[PointSize]);
+ fd->tqstyleHint = TQFont::AnyStyle; // ### any until we match families
+
+ char slant = tolower( (uchar) tokens[Slant][0] );
+ fd->italic = ( slant == 'o' || slant == 'i' );
+ char fixed = tolower( (uchar) tokens[Spacing][0] );
+ fd->fixedPitch = ( fixed == 'm' || fixed == 'c' );
+ fd->weight = getFontWeight( tokens[Weight] );
+
+ int r = atoi(tokens[ResolutionY]);
+ fd->pixelSize = atoi(tokens[PixelSize]);
+ // not "0" or "*", or required DPI
+ if ( r && fd->pixelSize && TQPaintDevice::x11AppDpiY( screen ) &&
+ r != TQPaintDevice::x11AppDpiY( screen ) ) {
+ // calculate actual pointsize for display DPI
+ fd->pointSize = tqRound(qt_pointSize(fd->pixelSize, 0, screen) * 10.);
+ } else if ( fd->pixelSize == 0 && fd->pointSize ) {
+ // calculate pixel size from pointsize/dpi
+ fd->pixelSize = tqRound(qt_pixelSize(fd->pointSize / 10., 0, screen));
+ }
+
+ return TRUE;
+}
+
+/*
+ Fills in a font definition (TQFontDef) from the font properties in an
+ XFontStruct.
+
+ Returns TRUE if the TQFontDef could be filled with properties from
+ the XFontStruct. The fields lbearing and rbearing are not given any
+ values.
+*/
+static bool qt_fillFontDef( XFontStruct *fs, TQFontDef *fd, int screen )
+{
+ unsigned long value;
+ if ( fs && !XGetFontProperty( fs, XA_FONT, &value ) )
+ return FALSE;
+
+ char *n = XGetAtomName( TQPaintDevice::x11AppDisplay(), value );
+ TQCString xlfd( n );
+ if ( n )
+ XFree( n );
+ return qt_fillFontDef( xlfd.lower(), fd, screen );
+}
+
+
+static TQtFontStyle::Key getStyle( char ** tokens )
+{
+ TQtFontStyle::Key key;
+
+ char slant0 = tolower( (uchar) tokens[Slant][0] );
+
+ if ( slant0 == 'r' ) {
+ if ( tokens[Slant][1]) {
+ char slant1 = tolower( (uchar) tokens[Slant][1] );
+
+ if ( slant1 == 'o' )
+ key.oblique = TRUE;
+ else if ( slant1 == 'i' )
+ key.italic = TRUE;
+ }
+ } else if ( slant0 == 'o' )
+ key.oblique = TRUE;
+ else if ( slant0 == 'i' )
+ key.italic = TRUE;
+
+ key.weight = getFontWeight( tokens[Weight] );
+
+ if ( qstrcmp( tokens[Width], "normal" ) == 0 ) {
+ key.stretch = 100;
+ } else if ( qstrcmp( tokens[Width], "semi condensed" ) == 0 ||
+ qstrcmp( tokens[Width], "semicondensed" ) == 0 ) {
+ key.stretch = 90;
+ } else if ( qstrcmp( tokens[Width], "condensed" ) == 0 ) {
+ key.stretch = 80;
+ } else if ( qstrcmp( tokens[Width], "narrow" ) == 0 ) {
+ key.stretch = 60;
+ }
+
+ return key;
+}
+
+
+extern bool qt_has_xft; // defined in qfont_x11.cpp
+
+static bool xlfdsFullyLoaded = FALSE;
+static unsigned char encodingLoaded[numEncodings];
+
+static void loadXlfds( const char *reqFamily, int encoding_id )
+{
+ TQtFontFamily *fontFamily = reqFamily ? db->family( reqFamily ) : 0;
+
+ // make sure we don't load twice
+ if ( (encoding_id == -1 && xlfdsFullyLoaded) || (encoding_id != -1 && encodingLoaded[encoding_id]) )
+ return;
+ if ( fontFamily && fontFamily->xlfdLoaded )
+ return;
+
+ int fontCount;
+ // force the X server to give us XLFDs
+ TQCString xlfd_pattern = "-*-";
+ xlfd_pattern += reqFamily ? reqFamily : "*";
+ xlfd_pattern += "-*-*-*-*-*-*-*-*-*-*-";
+ xlfd_pattern += xlfd_for_id( encoding_id );
+
+ char **fontList = XListFonts( TQPaintDevice::x11AppDisplay(),
+ xlfd_pattern.data(),
+ 0xffff, &fontCount );
+ // qDebug("requesting xlfd='%s', got %d fonts", xlfd_pattern.data(), fontCount );
+
+
+ char *tokens[NFontFields];
+
+ for( int i = 0 ; i < fontCount ; i++ ) {
+ if ( ! parseXFontName( fontList[i], tokens ) ) continue;
+
+ // get the encoding_id for this xlfd. we need to do this
+ // here, since we can pass -1 to this function to do full
+ // database population
+ *(tokens[CharsetEncoding]-1) = '-';
+ int encoding_id = qt_xlfd_encoding_id( tokens[CharsetRegistry] );
+ if ( encoding_id == -1 )
+ continue;
+
+ char *familyName = tokens[Family];
+ capitalize( familyName );
+ char *foundryName = tokens[Foundry];
+ capitalize( foundryName );
+ TQtFontStyle::Key styleKey = getStyle( tokens );
+
+ bool smooth_scalable = FALSE;
+ bool bitmap_scalable = FALSE;
+ if ( isScalable(tokens) ) {
+ if ( isSmoothlyScalable( tokens ) )
+ smooth_scalable = TRUE;
+ else
+ bitmap_scalable = TRUE;
+ }
+ uint pixelSize = atoi( tokens[PixelSize] );
+ uint xpointSize = atoi( tokens[PointSize] );
+ uint xres = atoi( tokens[ResolutionX] );
+ uint yres = atoi( tokens[ResolutionY] );
+ uint avgwidth = atoi( tokens[AverageWidth] );
+ bool fixedPitch = isFixedPitch( tokens );
+
+ if (avgwidth == 0 && pixelSize != 0) {
+ /*
+ Ignore bitmap scalable fonts that are automatically
+ generated by some X servers. We know they are bitmap
+ scalable because even though they have a specified pixel
+ size, the average width is zero.
+ */
+ continue;
+ }
+
+ TQtFontFamily *family = fontFamily ? fontFamily : db->family( familyName, TRUE );
+ family->fontFileIndex = -1;
+ TQtFontFoundry *foundry = family->foundry( foundryName, TRUE );
+ TQtFontStyle *style = foundry->style( styleKey, TRUE );
+
+ delete [] style->weightName;
+ style->weightName = qstrdup( tokens[Weight] );
+ delete [] style->setwidthName;
+ style->setwidthName = qstrdup( tokens[Width] );
+
+ if ( smooth_scalable ) {
+ style->smoothScalable = TRUE;
+ style->bitmapScalable = FALSE;
+ pixelSize = SMOOTH_SCALABLE;
+ }
+ if ( !style->smoothScalable && bitmap_scalable )
+ style->bitmapScalable = TRUE;
+ if ( !fixedPitch )
+ family->fixedPitch = FALSE;
+
+ TQtFontSize *size = style->pixelSize( pixelSize, TRUE );
+ TQtFontEncoding *enc =
+ size->encodingID( encoding_id, xpointSize, xres, yres, avgwidth, TRUE );
+ enc->pitch = *tokens[Spacing];
+ if ( !enc->pitch ) enc->pitch = '*';
+
+ for ( int script = 0; script < TQFont::LastPrivateScript; ++script ) {
+ if ( scripts_for_xlfd_encoding[encoding_id][script] )
+ family->scripts[script] = TQtFontFamily::Supported;
+ else
+ family->scripts[script] |= TQtFontFamily::UnSupported_Xlfd;
+ }
+ if ( encoding_id == -1 )
+ family->xlfdLoaded = TRUE;
+ }
+ if ( !reqFamily ) {
+ // mark encoding as loaded
+ if ( encoding_id == -1 )
+ xlfdsFullyLoaded = TRUE;
+ else
+ encodingLoaded[encoding_id] = TRUE;
+ }
+
+ XFreeFontNames( fontList );
+}
+
+
+#ifndef TQT_NO_XFTFREETYPE
+static int getXftWeight(int xftweight)
+{
+ int qtweight = TQFont::Black;
+ if (xftweight <= (XFT_WEIGHT_LIGHT + XFT_WEIGHT_MEDIUM) / 2)
+ qtweight = TQFont::Light;
+ else if (xftweight <= (XFT_WEIGHT_MEDIUM + XFT_WEIGHT_DEMIBOLD) / 2)
+ qtweight = TQFont::Normal;
+ else if (xftweight <= (XFT_WEIGHT_DEMIBOLD + XFT_WEIGHT_BOLD) / 2)
+ qtweight = TQFont::DemiBold;
+ else if (xftweight <= (XFT_WEIGHT_BOLD + XFT_WEIGHT_BLACK) / 2)
+ qtweight = TQFont::Bold;
+
+ return qtweight;
+}
+
+static void loadXft()
+{
+ if (!qt_has_xft)
+ return;
+
+#ifdef TQT_XFT2
+ struct XftDefaultFont {
+ const char *qtname;
+ const char *rawname;
+ bool fixed;
+ };
+ const XftDefaultFont defaults[] = {
+ { "Serif", "serif", FALSE },
+ { "Sans Serif", "sans-serif", FALSE },
+ { "Monospace", "monospace", TRUE },
+ { 0, 0, FALSE }
+ };
+ const XftDefaultFont *f = defaults;
+ while (f->qtname) {
+ TQtFontFamily *family = db->family( f->qtname, TRUE );
+ family->fixedPitch = f->fixed;
+ family->rawName = f->rawname;
+ family->hasXft = TRUE;
+ family->synthetic = TRUE;
+ TQtFontFoundry *foundry
+ = family->foundry( TQString::null, TRUE );
+
+ for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) {
+ if (i == TQFont::UnknownScript)
+ continue;
+ family->scripts[i] = TQtFontFamily::Supported;
+ }
+
+ TQtFontStyle::Key styleKey;
+ styleKey.oblique = FALSE;
+ for (int i = 0; i < 4; ++i) {
+ styleKey.italic = (i%2);
+ styleKey.weight = (i > 1) ? TQFont::Bold : TQFont::Normal;
+ TQtFontStyle *style = foundry->style( styleKey, TRUE );
+ style->smoothScalable = TRUE;
+ TQtFontSize *size = style->pixelSize( SMOOTH_SCALABLE, TRUE );
+ TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE );
+ enc->pitch = (f->fixed ? 'm' : 'p');
+ }
+ ++f;
+ }
+#endif
+}
+
+#ifdef XFT_MATRIX
+static void checkXftMatrix( TQtFontFamily* family ) {
+ for ( int j = 0; j < family->count; ++j ) { // each foundry
+ TQtFontFoundry *foundry = family->foundries[j];
+ for ( int k = 0; k < foundry->count; ++k ) {
+ TQtFontStyle *style = foundry->styles[k];
+ if ( style->key.italic || style->key.oblique ) continue;
+
+ TQtFontSize *size = style->pixelSize( SMOOTH_SCALABLE );
+ if ( ! size ) continue;
+ TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE );
+ if ( ! enc ) continue;
+
+ TQtFontStyle::Key key = style->key;
+
+ // does this style have an italic equivalent?
+ key.italic = TRUE;
+ TQtFontStyle *equiv = foundry->style( key );
+ if ( equiv ) continue;
+
+ // does this style have an oblique equivalent?
+ key.italic = FALSE;
+ key.oblique = TRUE;
+ equiv = foundry->style( key );
+ if ( equiv ) continue;
+
+ // let's fake one...
+ equiv = foundry->style( key, TRUE );
+ equiv->fakeOblique = TRUE;
+ equiv->smoothScalable = TRUE;
+
+ TQtFontSize *equiv_size = equiv->pixelSize( SMOOTH_SCALABLE, TRUE );
+ TQtFontEncoding *equiv_enc = equiv_size->encodingID( -1, 0, 0, 0, 0, TRUE );
+
+ // keep the same pitch
+ equiv_enc->pitch = enc->pitch;
+ }
+ }
+}
+#endif // XFT_MATRIX
+
+static bool loadXftFont( FcPattern* font )
+{
+ TQString familyName;
+ TQString rawName;
+ char *value;
+ int weight_value;
+ int slant_value;
+ int spacing_value;
+ char *file_value;
+ int index_value;
+ char *foundry_value = 0;
+ FcBool scalable = FcTrue;
+
+ if (XftPatternGetString( font,
+ XFT_FAMILY, 0, &value) != XftResultMatch )
+ return false;
+ // capitalize( value );
+ rawName = familyName = TQString::fromUtf8(value);
+ familyName.tqreplace('-', ' ');
+ familyName.tqreplace("/", "");
+
+ slant_value = XFT_SLANT_ROMAN;
+ weight_value = XFT_WEIGHT_MEDIUM;
+ spacing_value = XFT_PROPORTIONAL;
+ file_value = 0;
+ index_value = 0;
+ XftPatternGetInteger (font, XFT_SLANT, 0, &slant_value);
+ XftPatternGetInteger (font, XFT_WEIGHT, 0, &weight_value);
+ XftPatternGetInteger (font, XFT_SPACING, 0, &spacing_value);
+ XftPatternGetString (font, XFT_FILE, 0, &file_value);
+ XftPatternGetInteger (font, XFT_INDEX, 0, &index_value);
+#ifdef TQT_XFT2
+ FcPatternGetBool(font, FC_SCALABLE, 0, &scalable);
+ foundry_value = 0;
+ XftPatternGetString(font, FC_FOUNDRY, 0, &foundry_value);
+#endif
+ TQtFontFamily *family = db->family( familyName, TRUE );
+ family->rawName = rawName;
+ family->hasXft = TRUE;
+
+#ifdef TQT_XFT2
+ FcCharSet *charset = 0;
+ FcResult res = FcPatternGetCharSet(font, FC_CHARSET, 0, &charset);
+ if (res == FcResultMatch && FcCharSetCount(charset) > 1) {
+ for (int i = 0; i < TQFont::LastPrivateScript; ++i) {
+ bool supported = sample_chars[i][0];
+ for (int j = 0; sample_chars[i][j]; ++j){
+ if (!FcCharSetHasChar(charset, sample_chars[i][j])) {
+ supported = false;
+ break;
+ }
+ }
+ if ( supported ){
+ family->scripts[i] = TQtFontFamily::Supported;
+ } else {
+ family->scripts[i] |= TQtFontFamily::UnSupported_Xft;
+ }
+ }
+ family->xftScriptCheck = TRUE;
+ } else {
+ // we set UnknownScript to supported for symbol fonts. It makes no sense to merge these
+ // with other ones, as they are special in a way.
+ for ( int i = 0; i < TQFont::LastPrivateScript; ++i )
+ family->scripts[i] |= TQtFontFamily::UnSupported_Xft;
+ family->scripts[TQFont::UnknownScript] = TQtFontFamily::Supported;
+ }
+#endif // TQT_XFT2
+
+ TQCString file = (file_value ? file_value : "");
+ family->fontFilename = file;
+ family->fontFileIndex = index_value;
+
+ TQtFontStyle::Key styleKey;
+ styleKey.italic = (slant_value == XFT_SLANT_ITALIC);
+ styleKey.oblique = (slant_value == XFT_SLANT_OBLIQUE);
+ styleKey.weight = getXftWeight( weight_value );
+#ifdef TQT_XFT2
+ if (!scalable) {
+ int width = 100;
+#if FC_VERSION >= 20193
+ XftPatternGetInteger (font, FC_WIDTH, 0, &width);
+#endif
+ styleKey.stretch = width;
+ }
+#endif
+
+ TQtFontFoundry *foundry
+ = family->foundry( foundry_value ? TQString::fromUtf8(foundry_value) : TQString::null, TRUE );
+ TQtFontStyle *style = foundry->style( styleKey, TRUE );
+
+ if (spacing_value < XFT_MONO )
+ family->fixedPitch = FALSE;
+
+ TQtFontSize *size;
+ if (scalable) {
+ style->smoothScalable = TRUE;
+ size = style->pixelSize( SMOOTH_SCALABLE, TRUE );
+ }
+#ifdef TQT_XFT2
+ else {
+ double pixel_size = 0;
+ XftPatternGetDouble (font, FC_PIXEL_SIZE, 0, &pixel_size);
+ size = style->pixelSize( (int)pixel_size, TRUE );
+ }
+#endif
+ TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE );
+ enc->pitch = ( spacing_value >= XFT_CHARCELL ? 'c' :
+ ( spacing_value >= XFT_MONO ? 'm' : 'p' ) );
+
+ checkXftMatrix( family );
+
+ return true;
+}
+
+#ifndef TQT_XFT2
+
+#define MAKE_TAG( _x1, _x2, _x3, _x4 ) \
+ ( ( (TQ_UINT32)_x1 << 24 ) | \
+ ( (TQ_UINT32)_x2 << 16 ) | \
+ ( (TQ_UINT32)_x3 << 8 ) | \
+ (TQ_UINT32)_x4 )
+
+#ifdef _POSIX_MAPPED_FILES
+static inline TQ_UINT32 getUInt(unsigned char *p)
+{
+ TQ_UINT32 val;
+ val = *p++ << 24;
+ val |= *p++ << 16;
+ val |= *p++ << 8;
+ val |= *p;
+
+ return val;
+}
+
+static inline TQ_UINT16 getUShort(unsigned char *p)
+{
+ TQ_UINT16 val;
+ val = *p++ << 8;
+ val |= *p;
+
+ return val;
+}
+
+static inline void tag_to_string( char *string, TQ_UINT32 tag )
+{
+ string[0] = (tag >> 24)&0xff;
+ string[1] = (tag >> 16)&0xff;
+ string[2] = (tag >> 8)&0xff;
+ string[3] = tag&0xff;
+ string[4] = 0;
+}
+
+static TQ_UINT16 getGlyphIndex( unsigned char *table, TQ_UINT16 format, unsigned short tqunicode )
+{
+ if ( format == 0 ) {
+ if ( tqunicode < 256 )
+ return (int) *(table+6+tqunicode);
+ } else if ( format == 2 ) {
+ qWarning("format 2 encoding table for Unicode, not implemented!");
+ } else if ( format == 4 ) {
+ TQ_UINT16 segCountX2 = getUShort( table + 6 );
+ unsigned char *ends = table + 14;
+ TQ_UINT16 endIndex = 0;
+ int i = 0;
+ for ( ; i < segCountX2/2 && (endIndex = getUShort( ends + 2*i )) < tqunicode; i++ );
+
+ unsigned char *idx = ends + segCountX2 + 2 + 2*i;
+ TQ_UINT16 startIndex = getUShort( idx );
+
+ if ( startIndex > tqunicode )
+ return 0;
+
+ idx += segCountX2;
+ TQ_INT16 idDelta = (TQ_INT16)getUShort( idx );
+ idx += segCountX2;
+ TQ_UINT16 idRangeoffset_t = (TQ_UINT16)getUShort( idx );
+
+ TQ_UINT16 glyphIndex;
+ if ( idRangeoffset_t ) {
+ TQ_UINT16 id = getUShort( idRangeoffset_t + 2*(tqunicode - startIndex) + idx);
+ if ( id )
+ glyphIndex = ( idDelta + id ) % 0x10000;
+ else
+ glyphIndex = 0;
+ } else {
+ glyphIndex = (idDelta + tqunicode) % 0x10000;
+ }
+ return glyphIndex;
+ }
+
+ return 0;
+}
+#endif // _POSIX_MAPPED_FILES
+
+static inline void checkXftCoverage( TQtFontFamily *family )
+{
+#ifdef _POSIX_MAPPED_FILES
+ TQCString ext = family->fontFilename.mid( family->fontFilename.tqfindRev( '.' ) ).lower();
+ if ( family->fontFileIndex == 0 && ( ext == ".ttf" || ext == ".otf" ) ) {
+ void *map;
+ // qDebug("using own ttf code coverage checking of '%s'!", family->name.latin1() );
+ int fd = open( family->fontFilename.data(), O_RDONLY );
+ size_t pagesize = getpagesize();
+ off_t offset = 0;
+ size_t length = (8192 / pagesize + 1) * pagesize;
+
+ if ( fd == -1 )
+ goto xftCheck;
+ {
+ if ( (map = mmap( 0, length, PROT_READ, MAP_SHARED, fd, offset ) ) == MAP_FAILED )
+ goto error;
+
+ unsigned char *ttf = (unsigned char *)map;
+ TQ_UINT32 version = getUInt( ttf );
+ if ( version != 0x00010000 ) {
+ // qDebug("file has wrong version %x", version );
+ goto error1;
+ }
+ TQ_UINT16 numTables = getUShort( ttf+4 );
+
+ unsigned char *table_dir = ttf + 12;
+ TQ_UINT32 cmap_offset = 0;
+ TQ_UINT32 cmap_length = 0;
+ for ( int n = 0; n < numTables; n++ ) {
+ TQ_UINT32 tag = getUInt( table_dir + 16*n );
+ if ( tag == MAKE_TAG( 'c', 'm', 'a', 'p' ) ) {
+ cmap_offset = getUInt( table_dir + 16*n + 8 );
+ cmap_length = getUInt( table_dir + 16*n + 12 );
+ break;
+ }
+ }
+ if ( !cmap_offset ) {
+ // qDebug("no cmap found" );
+ goto error1;
+ }
+
+ if ( cmap_offset + cmap_length > length ) {
+ munmap( map, length );
+ offset = cmap_offset / pagesize * pagesize;
+ cmap_offset -= offset;
+ length = (cmap_offset + cmap_length);
+ if ( (map = mmap( 0, length, PROT_READ, MAP_SHARED, fd, offset ) ) == MAP_FAILED )
+ goto error;
+ }
+
+ unsigned char *cmap = ((unsigned char *)map) + cmap_offset;
+
+ version = getUShort( cmap );
+ if ( version != 0 ) {
+ // qDebug("wrong cmap version" );
+ goto error1;
+ }
+ numTables = getUShort( cmap + 2 );
+ unsigned char *tqunicode_table = 0;
+ bool symbol_table = TRUE;
+ for ( int n = 0; n < numTables; n++ ) {
+ TQ_UINT32 version = getUInt( cmap + 4 + 8*n );
+ // accept both symbol and Unicode encodings. prefer tqunicode.
+ if ( version == 0x00030001 || version == 0x00030000 ) {
+ tqunicode_table = cmap + getUInt( cmap + 4 + 8*n + 4 );
+ if ( version == 0x00030001 ) {
+ symbol_table = FALSE;
+ break;
+ }
+ }
+ }
+
+ if ( !tqunicode_table ) {
+ // qDebug("no tqunicode table found" );
+ goto error1;
+ }
+
+ TQ_UINT16 format = getUShort( tqunicode_table );
+ if ( format != 4 )
+ goto error1;
+
+ if (symbol_table) {
+ // we set UnknownScript to supported for symbol fonts. It makes no sense to merge these
+ // with other ones, as they are special in a way.
+ for ( int i = 0; i < TQFont::LastPrivateScript; ++i )
+ family->scripts[i] |= TQtFontFamily::UnSupported_Xft;
+ family->scripts[TQFont::UnknownScript] = TQtFontFamily::Supported;
+ } else {
+ for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) {
+
+ bool supported = sample_chars[i][0];
+ for (int j = 0; sample_chars[i][j]; ++j) {
+ if (!getGlyphIndex(tqunicode_table, format, sample_chars[i][j])) {
+ supported=false;
+ break;
+ }
+ }
+ if ( supported ){
+ // qDebug("font can render script %d", i );
+ family->scripts[i] = TQtFontFamily::Supported;
+ } else {
+ family->scripts[i] |= TQtFontFamily::UnSupported_Xft;
+ }
+ }
+ }
+ family->xftScriptCheck = TRUE;
+ }
+ error1:
+ munmap( map, length );
+ error:
+ close( fd );
+ if ( family->xftScriptCheck )
+ return;
+ }
+ xftCheck:
+#endif // _POSIX_MAPPED_FILES
+
+ FD_DEBUG("using Freetype for checking of '%s'", family->name.latin1() );
+
+ FT_Library ft_lib;
+ FT_Error error = FT_Init_FreeType( &ft_lib );
+ if ( error ) return;
+ FT_Face face;
+ error = FT_New_Face( ft_lib, family->fontFilename, family->fontFileIndex, &face );
+ if ( error ) return;
+
+ for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) {
+ bool supported = sample_chars[i][j];
+ for (int j = 0; sample_chars[i][j]; ++j){
+ if (!FT_Get_Char_Index(face, sample_chars[i][j])) {
+ supported=false;
+ break;
+ }
+ }
+ if ( supported ){
+ FD_DEBUG("font can render char %04x, %04x script %d '%s'",
+ ch.tqunicode(), FT_Get_Char_Index ( face, ch.tqunicode() ),
+ i, TQFontDatabase::scriptName( (TQFont::Script)i ).latin1() );
+
+ family->scripts[i] = TQtFontFamily::Supported;
+ } else {
+ family->scripts[i] |= TQtFontFamily::UnSupported_Xft;
+ }
+ }
+ FT_Done_Face( face );
+ FT_Done_FreeType( ft_lib );
+ family->xftScriptCheck = TRUE;
+}
+#endif // TQT_XFT2
+#endif // TQT_NO_XFTFREETYPE
+
+static void load( const TQString &family = TQString::null, int script = -1 )
+{
+#ifdef TQFONTDATABASE_DEBUG
+ TQTime t;
+ t.start();
+#endif
+
+ if ( family.isNull() ) {
+#ifndef TQT_NO_XFTFREETYPE
+ static bool xft_readall_done = false;
+ if (qt_has_xft && !xft_readall_done) {
+ xft_readall_done = true;
+ XftFontSet *fonts =
+ XftListFonts(TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppScreen(),
+ (const char *)0,
+ XFT_FAMILY, XFT_WEIGHT, XFT_SLANT,
+ XFT_SPACING, XFT_FILE, XFT_INDEX,
+#ifdef TQT_XFT2
+ FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE,
+#if FC_VERSION >= 20193
+ FC_WIDTH,
+#endif
+#endif // TQT_XFT2
+ (const char *)0);
+ for (int i = 0; i < fonts->nfont; i++)
+ loadXftFont( fonts->fonts[i] );
+ XftFontSetDestroy (fonts);
+ }
+#ifdef TQT_XFT2
+ if (qt_has_xft)
+ return;
+#endif
+#endif // TQT_NO_XFTFREETYPE
+ if ( script == -1 )
+ loadXlfds( 0, -1 );
+ else {
+ for ( int i = 0; i < numEncodings; i++ ) {
+ if ( scripts_for_xlfd_encoding[i][script] )
+ loadXlfds( 0, i );
+ }
+ }
+ } else {
+ TQtFontFamily *f = db->family( family, TRUE );
+ if ( !f->fullyLoaded ) {
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (qt_has_xft) {
+ TQString mfamily = family;
+ redo:
+ XftFontSet *fonts =
+ XftListFonts(TQPaintDevice::x11AppDisplay(),
+ TQPaintDevice::x11AppScreen(),
+ XFT_FAMILY, XftTypeString, mfamily.utf8().data(),
+ (const char *)0,
+ XFT_FAMILY, XFT_WEIGHT, XFT_SLANT,
+ XFT_SPACING, XFT_FILE, XFT_INDEX,
+#ifdef TQT_XFT2
+ FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE,
+#if FC_VERSION >= 20193
+ FC_WIDTH,
+#endif
+#endif // TQT_XFT2
+ (const char *)0);
+ for (int i = 0; i < fonts->nfont; i++)
+ loadXftFont( fonts->fonts[i] );
+ XftFontSetDestroy (fonts);
+ if (mfamily.tqcontains(' ')) {
+ mfamily.tqreplace(TQChar(' '), TQChar('-'));
+ goto redo;
+ }
+ f->fullyLoaded = TRUE;
+#ifdef TQT_XFT2
+ return;
+#endif
+ }
+#ifndef TQT_XFT2
+ // need to check Xft coverage
+ if ( f->hasXft && !f->xftScriptCheck ) {
+ checkXftCoverage( f );
+ }
+#endif
+#endif // TQT_NO_XFTFREETYPE
+ // could reduce this further with some more magic:
+ // would need to remember the encodings loaded for the family.
+ if ( ( script == -1 && !f->xlfdLoaded ) ||
+ ( !f->hasXft && !(f->scripts[script] & TQtFontFamily::Supported) &&
+ !(f->scripts[script] & TQtFontFamily::UnSupported_Xlfd) ) ) {
+ loadXlfds( family, -1 );
+ f->fullyLoaded = TRUE;
+ }
+ }
+ }
+
+#ifdef TQFONTDATABASE_DEBUG
+ FD_DEBUG("TQFontDatabase: load( %s, %d) took %d ms", family.latin1(), script, t.elapsed() );
+#endif
+}
+
+
+static void initializeDb()
+{
+ if ( db ) return;
+ db = new TQFontDatabasePrivate;
+ qfontdatabase_cleanup.set(&db);
+
+#ifndef TQT_XFT2
+ memset( encodingLoaded, FALSE, sizeof( encodingLoaded ) );
+#endif
+
+ TQTime t;
+ t.start();
+
+#ifndef TQT_NO_XFTFREETYPE
+ loadXft();
+ FD_DEBUG("TQFontDatabase: loaded Xft: %d ms", t.elapsed() );
+#endif
+
+ t.start();
+
+#ifndef TQT_NO_XFTFREETYPE
+ for ( int i = 0; i < db->count; i++ ) {
+#ifndef TQT_XFT2
+ checkXftCoverage( db->families[i] );
+ FD_DEBUG("TQFontDatabase: xft coverage check: %d ms", t.elapsed() );
+#endif // TQT_XFT2
+
+#ifdef XFT_MATRIX
+ checkXftMatrix( db->families[i] );
+#endif // XFT_MATRIX
+ }
+#endif
+
+
+#ifdef TQFONTDATABASE_DEBUG
+#ifdef TQT_XFT2
+ if (!qt_has_xft)
+#endif
+ // load everything at startup in debug mode.
+ loadXlfds( 0, -1 );
+
+ // print the database
+ for ( int f = 0; f < db->count; f++ ) {
+ TQtFontFamily *family = db->families[f];
+ FD_DEBUG("'%s' %s hasXft=%s", family->name.latin1(), (family->fixedPitch ? "fixed" : ""),
+ (family->hasXft ? "yes" : "no") );
+ for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) {
+ FD_DEBUG("\t%s: %s", TQFontDatabase::scriptName((TQFont::Script) i).latin1(),
+ ((family->scripts[i] & TQtFontFamily::Supported) ? "Supported" :
+ (family->scripts[i] & TQtFontFamily::UnSupported) == TQtFontFamily::UnSupported ?
+ "UnSupported" : "Unknown"));
+ }
+
+ for ( int fd = 0; fd < family->count; fd++ ) {
+ TQtFontFoundry *foundry = family->foundries[fd];
+ FD_DEBUG("\t\t'%s'", foundry->name.latin1() );
+ for ( int s = 0; s < foundry->count; s++ ) {
+ TQtFontStyle *style = foundry->styles[s];
+ FD_DEBUG("\t\t\tstyle: italic=%d oblique=%d (fake=%d) weight=%d (%s)\n"
+ "\t\t\tstretch=%d (%s)",
+ style->key.italic, style->key.oblique, style->fakeOblique, style->key.weight,
+ style->weightName, style->key.stretch,
+ style->setwidthName ? style->setwidthName : "nil" );
+ if ( style->smoothScalable )
+ FD_DEBUG("\t\t\t\tsmooth scalable" );
+ else if ( style->bitmapScalable )
+ FD_DEBUG("\t\t\t\tbitmap scalable" );
+ if ( style->pixelSizes ) {
+ qDebug("\t\t\t\t%d pixel sizes", style->count );
+ for ( int z = 0; z < style->count; ++z ) {
+ TQtFontSize *size = style->pixelSizes + z;
+ for ( int e = 0; e < size->count; ++e ) {
+ FD_DEBUG( "\t\t\t\t size %5d pitch %c encoding %s",
+ size->pixelSize,
+ size->encodings[e].pitch,
+ xlfd_for_id( size->encodings[e].encoding ) );
+ }
+ }
+ }
+ }
+ }
+ }
+#endif // TQFONTDATABASE_DEBUG
+}
+
+void TQFontDatabase::createDatabase()
+{
+ initializeDb();
+}
+
+
+// --------------------------------------------------------------------------------------
+// font loader
+// --------------------------------------------------------------------------------------
+#define MAXFONTSIZE_XFT 256
+#define MAXFONTSIZE_XLFD 128
+#ifndef TQT_NO_XFTFREETYPE
+static double addPatternProps(XftPattern *pattern, const TQtFontStyle::Key &key, bool fakeOblique,
+ bool smoothScalable, const TQFontPrivate *fp, const TQFontDef &request)
+{
+ int weight_value = XFT_WEIGHT_BLACK;
+ if ( key.weight == 0 )
+ weight_value = XFT_WEIGHT_MEDIUM;
+ else if ( key.weight < (TQFont::Light + TQFont::Normal) / 2 )
+ weight_value = XFT_WEIGHT_LIGHT;
+ else if ( key.weight < (TQFont::Normal + TQFont::DemiBold) / 2 )
+ weight_value = XFT_WEIGHT_MEDIUM;
+ else if ( key.weight < (TQFont::DemiBold + TQFont::Bold) / 2 )
+ weight_value = XFT_WEIGHT_DEMIBOLD;
+ else if ( key.weight < (TQFont::Bold + TQFont::Black) / 2 )
+ weight_value = XFT_WEIGHT_BOLD;
+ XftPatternAddInteger( pattern, XFT_WEIGHT, weight_value );
+
+ int slant_value = XFT_SLANT_ROMAN;
+ if ( key.italic )
+ slant_value = XFT_SLANT_ITALIC;
+ else if ( key.oblique && !fakeOblique )
+ slant_value = XFT_SLANT_OBLIQUE;
+ XftPatternAddInteger( pattern, XFT_SLANT, slant_value );
+
+ /*
+ Xft1 doesn't obey user settings for turning off anti-aliasing using
+ the following:
+
+ match any size > 6 size < 12 edit antialias = false;
+
+ ... if we request pixel sizes. so, work around this limitiation and
+ convert the pixel size to a point size and request that.
+ */
+ double size_value = request.pixelSize;
+ double scale = 1.;
+ if ( size_value > MAXFONTSIZE_XFT ) {
+ scale = (double)size_value/(double)MAXFONTSIZE_XFT;
+ size_value = MAXFONTSIZE_XFT;
+ }
+
+ size_value = size_value*72./TQPaintDevice::x11AppDpiY(fp->screen);
+ XftPatternAddDouble( pattern, XFT_SIZE, size_value );
+
+#ifdef XFT_MATRIX
+# ifdef TQT_XFT2
+ if (!smoothScalable) {
+# if FC_VERSION >= 20193
+ int stretch = request.stretch;
+ if (!stretch)
+ stretch = 100;
+ XftPatternAddInteger(pattern, FC_WIDTH, stretch);
+# endif
+ } else
+# endif
+ if ( ( request.stretch > 0 && request.stretch != 100 ) ||
+ ( key.oblique && fakeOblique ) ) {
+ XftMatrix matrix;
+ XftMatrixInit( &matrix );
+
+ if ( request.stretch > 0 && request.stretch != 100 )
+ XftMatrixScale( &matrix, double( request.stretch ) / 100.0, 1.0 );
+ if ( key.oblique && fakeOblique )
+ XftMatrixShear( &matrix, 0.20, 0.0 );
+
+ XftPatternAddMatrix( pattern, XFT_MATRIX, &matrix );
+ }
+#endif // XFT_MATRIX
+ if (request.styleStrategy & (TQFont::PreferAntialias|TQFont::NoAntialias)) {
+ XftPatternDel(pattern, XFT_ANTIALIAS);
+ XftPatternAddBool(pattern, XFT_ANTIALIAS,
+ !(request.styleStrategy & TQFont::NoAntialias));
+ }
+
+ return scale;
+}
+#endif // TQT_NO_XFTFREETYPE
+
+static
+TQFontEngine *loadEngine( TQFont::Script script,
+ const TQFontPrivate *fp, const TQFontDef &request,
+ TQtFontFamily *family, TQtFontFoundry *foundry,
+ TQtFontStyle *style, TQtFontSize *size,
+ TQtFontEncoding *encoding, bool forced_encoding )
+{
+ TQ_UNUSED(script);
+
+ if ( fp && fp->rawMode ) {
+ TQCString xlfd = request.family.latin1();
+ FM_DEBUG( "Loading XLFD (rawmode) '%s'", xlfd.data() );
+
+ XFontStruct *xfs;
+ if (! (xfs = XLoadQueryFont(TQPaintDevice::x11AppDisplay(), xlfd.data() ) ) )
+ return 0;
+
+ TQFontEngine *fe = new TQFontEngineXLFD( xfs, xlfd.data(), 0 );
+ if ( ! qt_fillFontDef( xfs, &fe->fontDef, TQPaintDevice::x11AppScreen() ) &&
+ ! qt_fillFontDef( xlfd, &fe->fontDef, TQPaintDevice::x11AppScreen() ) )
+ fe->fontDef = TQFontDef();
+
+ return fe;
+ }
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( encoding->encoding == -1 ) {
+
+ FM_DEBUG( " using Xft" );
+
+ XftPattern *pattern = XftPatternCreate();
+ if ( !pattern ) return 0;
+
+ bool symbol = (family->scripts[TQFont::UnknownScript] == TQtFontFamily::Supported);
+# ifdef TQT_XFT2
+ if (!symbol && script != TQFont::Unicode) {
+ FcCharSet *cs = FcCharSetCreate();
+ for ( int j=0; sample_chars[script][j]; j++ )
+ FcCharSetAddChar(cs, sample_chars[script][j]);
+ if (script == TQFont::Latin)
+ // add Euro character
+ FcCharSetAddChar(cs, 0x20ac);
+ FcPatternAddCharSet(pattern, FC_CHARSET, cs);
+ FcCharSetDestroy(cs);
+ }
+# else
+ XftPatternAddString( pattern, XFT_ENCODING, symbol ? "adobe-fontspecific" : "iso10646-1");
+# endif // TQT_XFT2
+
+ if ( !foundry->name.isEmpty() )
+ XftPatternAddString( pattern, XFT_FOUNDRY,
+ foundry->name.utf8().data() );
+
+ if ( !family->rawName.isEmpty() )
+ XftPatternAddString( pattern, XFT_FAMILY,
+ family->rawName.utf8().data() );
+
+
+ char pitch_value = ( encoding->pitch == 'c' ? XFT_CHARCELL :
+ ( encoding->pitch == 'm' ? XFT_MONO : XFT_PROPORTIONAL ) );
+ XftPatternAddInteger( pattern, XFT_SPACING, pitch_value );
+
+ double scale = addPatternProps(pattern, style->key, style->fakeOblique,
+ style->smoothScalable, fp, request);
+
+ XftResult res;
+ XftPattern *result =
+ XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res );
+#ifdef TQT_XFT2
+ if (result && script == TQFont::Latin) {
+ // since we added the Euro char on top, check we actually got the family
+ // we requested. If we didn't get it correctly, remove the Euro from the pattern
+ // and try again.
+ FcChar8 *f;
+ res = FcPatternGetString(result, FC_FAMILY, 0, &f);
+ if (res == FcResultMatch && TQString::fromUtf8((char *)f) != family->rawName) {
+ FcPatternDel(pattern, FC_CHARSET);
+ FcCharSet *cs = FcCharSetCreate();
+ for ( int j=0; sample_chars[script][j]; j++ )
+ FcCharSetAddChar(cs, sample_chars[script][j]);
+ FcPatternAddCharSet(pattern, FC_CHARSET, cs);
+ FcCharSetDestroy(cs);
+ result = XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res );
+ }
+ }
+#endif
+ XftPatternDestroy(pattern);
+ if (!result)
+ return 0;
+
+ // somehow this gets lost in the XftMatch call, reset the anitaliasing property correctly.
+ if (request.styleStrategy & (TQFont::PreferAntialias|TQFont::NoAntialias)) {
+ XftPatternDel(result, XFT_ANTIALIAS);
+ XftPatternAddBool(result, XFT_ANTIALIAS,
+ !(request.styleStrategy & TQFont::NoAntialias));
+ }
+ // We pass a duplicate to XftFontOpenPattern because either xft font
+ // will own the pattern after the call or the pattern will be
+ // destroyed.
+ XftPattern *dup = XftPatternDuplicate( result );
+ XftFont *xftfs = XftFontOpenPattern( TQPaintDevice::x11AppDisplay(), dup );
+
+ if ( ! xftfs ) // Xft couldn't tqfind a font?
+ return 0;
+
+ TQFontEngine *fe = new TQFontEngineXft( xftfs, result, symbol ? 1 : 0 );
+ if (fp->painttqdevice
+ && TQPaintDeviceMetrics(fp->painttqdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) {
+ double px;
+ XftPatternGetDouble(result, XFT_PIXEL_SIZE, 0, &px);
+ scale = (double)request.pixelSize/px;
+ }
+ fe->setScale( scale );
+ return fe;
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ FM_DEBUG( " using XLFD" );
+
+ TQCString xlfd = "-";
+ xlfd += foundry->name.isEmpty() ? "*" : foundry->name.latin1();
+ xlfd += "-";
+ xlfd += family->name.isEmpty() ? "*" : family->name.latin1();
+
+ xlfd += "-";
+ xlfd += style->weightName ? style->weightName : "*";
+ xlfd += "-";
+ xlfd += ( style->key.italic ? "i" : ( style->key.oblique ? "o" : "r" ) );
+
+ xlfd += "-";
+ xlfd += style->setwidthName ? style->setwidthName : "*";
+ // ### handle add-style
+ xlfd += "-*-";
+
+ int px = size->pixelSize;
+ if ( style->smoothScalable && px == SMOOTH_SCALABLE )
+ px = request.pixelSize;
+ else if ( style->bitmapScalable && px == 0 )
+ px = request.pixelSize;
+ double scale = 1.;
+ if ( px > MAXFONTSIZE_XLFD ) {
+ scale = (double)px/(double)MAXFONTSIZE_XLFD;
+ px = MAXFONTSIZE_XLFD;
+ }
+ if (fp && fp->painttqdevice
+ && TQPaintDeviceMetrics(fp->painttqdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY())
+ scale = (double)request.pixelSize/(double)px;
+
+ xlfd += TQString::number( px ).latin1();
+ xlfd += "-";
+ xlfd += TQString::number( encoding->xpoint );
+ xlfd += "-";
+ xlfd += TQString::number( encoding->xres );
+ xlfd += "-";
+ xlfd += TQString::number( encoding->yres );
+ xlfd += "-";
+
+ // ### handle cell spaced fonts
+ xlfd += encoding->pitch;
+ xlfd += "-";
+ xlfd += TQString::number( encoding->avgwidth );
+ xlfd += "-";
+ xlfd += xlfd_for_id( encoding->encoding );
+
+ FM_DEBUG( " xlfd: '%s'", xlfd.data() );
+
+ XFontStruct *xfs;
+ if (! (xfs = XLoadQueryFont(TQPaintDevice::x11AppDisplay(), xlfd.data() ) ) )
+ return 0;
+
+ TQFontEngine *fe = 0;
+ const int mib = xlfd_encoding[ encoding->encoding ].mib;
+ if (script == TQFont::Latin && encoding->encoding <= LAST_LATIN_ENCODING && !forced_encoding) {
+ fe = new TQFontEngineLatinXLFD( xfs, xlfd.data(), mib );
+ } else {
+ fe = new TQFontEngineXLFD( xfs, xlfd.data(), mib );
+ }
+
+ fe->setScale( scale );
+
+ return fe;
+}
+
+
+#ifdef TQT_XFT2
+
+static void parseFontName(const TQString &name, TQString &foundry, TQString &family)
+{
+ if ( name.tqcontains('[') && name.tqcontains(']')) {
+ int i = name.tqfind('[');
+ int li = name.tqfindRev(']');
+
+ if (i < li) {
+ foundry = name.mid(i + 1, li - i - 1);
+ if (name[i - 1] == ' ')
+ i--;
+ family = name.left(i);
+ }
+ } else {
+ foundry = TQString::null;
+ family = name;
+ }
+}
+
+
+static TQFontEngine *loadFontConfigFont(const TQFontPrivate *fp, const TQFontDef &request, TQFont::Script script)
+{
+ if (!qt_has_xft)
+ return 0;
+
+ TQStringList family_list;
+ if (request.family.isEmpty()) {
+ family_list = TQStringList::split(TQChar(','), fp->request.family);
+
+ TQString stylehint;
+ switch ( request.tqstyleHint ) {
+ case TQFont::SansSerif:
+ stylehint = "sans-serif";
+ break;
+ case TQFont::Serif:
+ stylehint = "serif";
+ break;
+ case TQFont::TypeWriter:
+ stylehint = "monospace";
+ break;
+ default:
+ if (request.fixedPitch)
+ stylehint = "monospace";
+ break;
+ }
+ if (!stylehint.isEmpty())
+ family_list << stylehint;
+ } else {
+ family_list << request.family;
+ }
+
+ FcPattern *pattern = FcPatternCreate();
+
+ {
+ TQString family, foundry;
+ for (TQStringList::ConstIterator it = family_list.begin(); it != family_list.end(); ++it) {
+ parseFontName(*it, foundry, family);
+ XftPatternAddString(pattern, XFT_FAMILY, family.utf8().data());
+ }
+ }
+
+ TQtFontStyle::Key key;
+ key.italic = request.italic;
+ key.weight = request.weight;
+ key.stretch = request.stretch;
+
+ double scale = addPatternProps(pattern, key, FALSE, TRUE, fp, request);
+#ifdef FONT_MATCH_DEBUG
+ qDebug("original pattern tqcontains:");
+ FcPatternPrint(pattern);
+#endif
+
+ // XftFontMatch calls the right ConfigSubstitute variants, but as we use
+ // FcFontMatch/Sort here we have to do it manually.
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ XftDefaultSubstitute(TQPaintDevice::x11AppDisplay(), TQPaintDevice::x11AppScreen(), pattern);
+
+// qDebug("1: pattern tqcontains:");
+// FcPatternPrint(pattern);
+
+ {
+ FcValue value;
+ value.type = FcTypeString;
+
+ // these should only get added to the pattern _after_ substitution
+ // append the default fallback font for the specified script
+ extern TQString qt_fallback_font_family( TQFont::Script );
+ TQString fallback = qt_fallback_font_family( script );
+ if ( ! fallback.isEmpty() && ! family_list.tqcontains( fallback ) ) {
+ TQCString cs = fallback.utf8();
+ value.u.s = (const FcChar8 *)cs.data();
+ FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
+ }
+
+ // add the default family
+ TQString defaultFamily = TQApplication::font().family();
+ if ( ! family_list.tqcontains( defaultFamily ) ) {
+ TQCString cs = defaultFamily.utf8();
+ value.u.s = (const FcChar8 *)cs.data();
+ FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
+ }
+
+ // add TQFont::defaultFamily() to the list, for compatibility with
+ // previous versions
+ defaultFamily = TQApplication::font().defaultFamily();
+ if ( ! family_list.tqcontains( defaultFamily ) ) {
+ TQCString cs = defaultFamily.utf8();
+ value.u.s = (const FcChar8 *)cs.data();
+ FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
+ }
+ }
+
+ if (script != TQFont::Unicode) {
+ FcCharSet *cs = FcCharSetCreate();
+ for ( int j=0; sample_chars[script][j]; j++ )
+ FcCharSetAddChar(cs, sample_chars[script][j]);
+ if (script == TQFont::Latin)
+ // add Euro character
+ FcCharSetAddChar(cs, 0x20ac);
+ FcPatternAddCharSet(pattern, FC_CHARSET, cs);
+ FcCharSetDestroy(cs);
+ }
+
+#ifdef FONT_MATCH_DEBUG
+ printf("final pattern tqcontains:\n");
+ FcPatternPrint(pattern);
+#endif
+
+ TQFontEngine *fe = 0;
+
+ for( int jj = (FcGetVersion() >= 20392 ? 0 : 1); jj < 2; ++jj ) {
+ bool use_fontsort = ( jj == 1 );
+
+ FcResult result;
+ FcFontSet *fs = 0;
+ FcPattern *fsp = 0;
+ if( use_fontsort ) {
+ fs = FcFontSort(0, pattern, FcFalse, 0, &result);
+ if (!fs)
+ continue;
+ } else {
+ fsp = FcFontMatch(0, pattern, &result);
+ if (!fsp)
+ continue;
+ }
+
+#ifdef FONT_MATCH_DEBUG
+ if( use_fontsort ) {
+ printf("fontset tqcontains:\n");
+ for (int i = 0; i < fs->nfont; ++i) {
+ FcPattern *test = fs->fonts[i];
+ FcChar8 *fam;
+ FcPatternGetString(test, FC_FAMILY, 0, &fam);
+ printf(" %s\n", fam);
+ }
+ } else {
+ printf("fontmatch:");
+ FcChar8 *fam;
+ FcPatternGetString(fsp, FC_FAMILY, 0, &fam);
+ printf(" %s\n", fam);
+ }
+#endif
+
+ double size_value = request.pixelSize;
+ if ( size_value > MAXFONTSIZE_XFT )
+ size_value = MAXFONTSIZE_XFT;
+
+ int cnt = use_fontsort ? fs->nfont : 1;
+
+ for (int i = 0; i < cnt; ++i) {
+ FcPattern *font = use_fontsort ? fs->fonts[i] : fsp;
+ FcCharSet *cs;
+ FcResult res = FcPatternGetCharSet(font, FC_CHARSET, 0, &cs);
+ if (res != FcResultMatch)
+ continue;
+ bool do_break=true;
+ for ( int j=0; sample_chars[script][j]; j++ ){
+ do_break=false;
+ if (!FcCharSetHasChar(cs, sample_chars[script][j])) {
+ do_break=true;
+ break;
+ }
+ }
+ if ( do_break )
+ continue;
+ FcBool scalable;
+ res = FcPatternGetBool(font, FC_SCALABLE, 0, &scalable);
+ if (res != FcResultMatch || !scalable) {
+ int pixelSize;
+ res = FcPatternGetInteger(font, FC_PIXEL_SIZE, 0, &pixelSize);
+ if (res != FcResultMatch || TQABS((size_value-pixelSize)/size_value) > 0.2)
+ continue;
+ }
+
+ XftPattern *pattern = XftPatternDuplicate(font);
+ // add properties back in as the font selected from the list doesn't contain them.
+ addPatternProps(pattern, key, FALSE, TRUE, fp, request);
+
+ XftPattern *result =
+ XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res );
+ XftPatternDestroy(pattern);
+
+ // We pass a duplicate to XftFontOpenPattern because either xft font
+ // will own the pattern after the call or the pattern will be
+ // destroyed.
+ XftPattern *dup = XftPatternDuplicate( result );
+ XftFont *xftfs = XftFontOpenPattern( TQPaintDevice::x11AppDisplay(), dup );
+
+ if ( !xftfs ) {
+ // Xft couldn't tqfind a font?
+ qDebug("couldn't open fontconfigs chosen font with Xft!!!");
+ } else {
+ fe = new TQFontEngineXft( xftfs, result, 0 );
+ if (fp->painttqdevice
+ && TQPaintDeviceMetrics(fp->painttqdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) {
+ double px;
+ XftPatternGetDouble(result, XFT_PIXEL_SIZE, 0, &px);
+ scale = request.pixelSize/px;
+ }
+ fe->setScale( scale );
+ fe->fontDef = request;
+ if ( script != TQFont::Unicode && !canRender(fe, script) ) {
+ FM_DEBUG( " WARN: font loaded cannot render samples" );
+ delete fe;
+ fe = 0;
+ }else
+ FM_DEBUG( " USE: %s", fe->fontDef.family.latin1() );
+ }
+ if (fe) {
+ TQFontEngineXft *xft = (TQFontEngineXft *)fe;
+ char *family;
+ if (XftPatternGetString(xft->pattern(), XFT_FAMILY, 0, &family) == XftResultMatch)
+ xft->fontDef.family = TQString::fromUtf8(family);
+
+ double px;
+ if (XftPatternGetDouble(xft->pattern(), XFT_PIXEL_SIZE, 0, &px) == XftResultMatch)
+ xft->fontDef.pixelSize = tqRound(px);
+
+ int weight = XFT_WEIGHT_MEDIUM;
+ XftPatternGetInteger(xft->pattern(), XFT_WEIGHT, 0, &weight);
+ xft->fontDef.weight = getXftWeight(weight);
+
+ int slant = XFT_SLANT_ROMAN;
+ XftPatternGetInteger(xft->pattern(), XFT_SLANT, 0, &slant);
+ xft->fontDef.italic = (slant != XFT_SLANT_ROMAN);
+
+ int spacing = XFT_PROPORTIONAL;
+ XftPatternGetInteger(xft->pattern(), XFT_SPACING, 0, &spacing);
+ xft->fontDef.fixedPitch = spacing != XFT_PROPORTIONAL;
+
+ xft->fontDef.ignorePitch = FALSE;
+ break;
+ }
+ }
+
+ if( use_fontsort )
+ FcFontSetDestroy(fs);
+ else
+ FcPatternDestroy(fsp);
+
+ if( fe )
+ break;
+
+ } // for( jj )
+
+ FcPatternDestroy(pattern);
+
+ return fe;
+}
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqfontengine_p.h b/tqtinterface/qt4/src/kernel/tqfontengine_p.h
new file mode 100644
index 0000000..cba46a7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontengine_p.h
@@ -0,0 +1,642 @@
+/****************************************************************************
+**
+** ???
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQFONTENGINE_P_H
+#define TQFONTENGINE_P_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqglobal.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+// FIXME
+
+#else // USE_QT4
+
+#ifdef TQ_WS_WIN
+#include "tqt_windows.h"
+#include "tqptrdict.h"
+#endif
+
+#include "tqtextengine_p.h"
+
+class TQPaintDevice;
+
+struct glyph_metrics_t;
+class TQChar;
+typedef unsigned short glyph_t;
+struct qoffset_t;
+typedef int advance_t;
+class TQOpenType;
+struct TransformedFont;
+
+#if defined( TQ_WS_X11 ) || defined( TQ_WS_WIN) || defined( TQ_WS_MAC )
+class TQFontEngine : public TQShared
+{
+public:
+ enum Error {
+ NoError,
+ OutOfMemory
+ };
+
+ enum Type {
+ // X11 types
+ Box,
+ XLFD,
+ LatinXLFD,
+ Xft,
+
+ // MS Windows types
+ Win,
+ Uniscribe,
+
+ // Apple MacOS types
+ Mac,
+
+ // Trolltech TQWS types
+ TQWS
+ };
+
+ TQFontEngine() {
+ count = 0; cache_count = 0;
+#ifdef TQ_WS_X11
+ transformed_fonts = 0;
+#endif
+ }
+ virtual ~TQFontEngine();
+
+ /* returns 0 as glyph index for non existant glyphs */
+ virtual Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs,
+ advance_t *advances, int *nglyphs, bool mirrored ) const = 0;
+
+#ifdef TQ_WS_X11
+ virtual int cmap() const { return -1; }
+ virtual TQOpenType *openType() const { return 0; }
+#endif
+
+ virtual void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) = 0;
+
+ virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances,
+ const qoffset_t *offsets, int numGlyphs ) = 0;
+ virtual glyph_metrics_t boundingBox( glyph_t glyph ) = 0;
+
+ virtual int ascent() const = 0;
+ virtual int descent() const = 0;
+ virtual int leading() const = 0;
+
+ virtual int lineThickness() const;
+ virtual int underlinePosition() const;
+
+ virtual int maxCharWidth() const = 0;
+ virtual int minLeftBearing() const { return 0; }
+ virtual int minRightBearing() const { return 0; }
+
+ virtual const char *name() const = 0;
+
+ virtual bool canRender( const TQChar *string, int len ) = 0;
+
+ virtual void setScale( double ) {}
+ virtual double scale() const { return 1.; }
+
+ virtual Type type() const = 0;
+
+ TQFontDef fontDef;
+ uint cache_cost; // amount of mem used in kb by the font
+ int cache_count;
+
+#ifdef TQ_WS_WIN
+ HDC dc() const;
+ void getGlyphIndexes( const TQChar *ch, int numChars, glyph_t *glyphs, bool mirrored ) const;
+ void getCMap();
+
+ TQCString _name;
+ HDC hdc;
+ HFONT hfont;
+ LOGFONT logfont;
+ uint stockFont : 1;
+ uint paintDevice : 1;
+ uint useTextOutA : 1;
+ uint ttf : 1;
+ uint symbol : 1;
+ union {
+ TEXTMETRICW w;
+ TEXTMETRICA a;
+ } tm;
+ int lw;
+ unsigned char *cmap;
+ void *script_cache;
+ static TQPtrDict<TQFontEngine> cacheDict;
+ short lbearing;
+ short rbearing;
+#endif // TQ_WS_WIN
+#ifdef TQ_WS_X11
+ TransformedFont *transformed_fonts;
+#endif
+};
+#elif defined( TQ_WS_TQWS )
+class TQGfx;
+
+class TQFontEngine : public TQShared
+{
+public:
+ TQFontEngine( const TQFontDef&, const TQPaintDevice * = 0 );
+ ~TQFontEngine();
+ /*TQMemoryManager::FontID*/ void *handle() const;
+
+ enum Type {
+ // X11 types
+ Box,
+ XLFD,
+ Xft,
+
+ // MS Windows types
+ Win,
+ Uniscribe,
+
+ // Apple MacOS types
+ Mac,
+
+ // Trolltech TQWS types
+ Qws
+ };
+
+ enum TextFlags {
+ Underline = 0x01,
+ Overline = 0x02,
+ StrikeOut = 0x04
+ };
+
+ enum Error {
+ NoError,
+ OutOfMemory
+ };
+ /* returns 0 as glyph index for non existant glyphs */
+ Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
+
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags );
+
+ glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
+ glyph_metrics_t boundingBox( glyph_t glyph );
+
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ int maxCharWidth() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+ int underlinePosition() const;
+ int lineThickness() const;
+
+ Type type() { return Qws; }
+
+ bool canRender( const TQChar *string, int len );
+ inline const char *name() const { return 0; }
+ TQFontDef fontDef;
+ /*TQMemoryManager::FontID*/ void *id;
+ int cache_cost;
+ int cache_count;
+ int scale;
+};
+#endif // WIN || X11 || MAC
+
+
+
+enum IndicFeatures {
+ CcmpFeature,
+ InitFeature,
+ NuktaFeature,
+ AkhantFeature,
+ RephFeature,
+ BelowFormFeature,
+ HalfFormFeature,
+ PostFormFeature,
+ VattuFeature,
+ PreSubstFeature,
+ AboveSubstFeature,
+ BelowSubstFeature,
+ PostSubstFeature,
+ HalantFeature
+};
+
+#if defined(TQ_WS_X11) || defined(TQ_WS_WIN)
+class TQFontEngineBox : public TQFontEngine
+{
+public:
+ TQFontEngineBox( int size );
+ ~TQFontEngineBox();
+
+ Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
+
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags );
+
+ virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
+ glyph_metrics_t boundingBox( glyph_t glyph );
+
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ int maxCharWidth() const;
+ int minLeftBearing() const { return 0; }
+ int minRightBearing() const { return 0; }
+
+#ifdef TQ_WS_X11
+ int cmap() const;
+#endif
+ const char *name() const;
+
+ bool canRender( const TQChar *string, int len );
+
+ Type type() const;
+ inline int size() const { return _size; }
+
+private:
+ friend class TQFontPrivate;
+ int _size;
+};
+#endif
+
+#ifdef TQ_WS_X11
+#include "tqt_x11_p.h"
+
+
+struct TransformedFont
+{
+ float xx;
+ float xy;
+ float yx;
+ float yy;
+ union {
+ Font xlfd_font;
+#ifndef TQT_NO_XFTFREETYPE
+ XftFont *xft_font;
+#endif
+ };
+ TransformedFont *next;
+};
+
+#ifndef TQT_NO_XFTFREETYPE
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include "ftxopen.h"
+
+class TQTextCodec;
+
+class TQFontEngineXft : public TQFontEngine
+{
+public:
+ TQFontEngineXft( XftFont *font, XftPattern *pattern, int cmap );
+ ~TQFontEngineXft();
+
+ TQOpenType *openType() const;
+
+ Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
+
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags );
+
+ virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
+ glyph_metrics_t boundingBox( glyph_t glyph );
+
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ int lineThickness() const;
+ int underlinePosition() const;
+ int maxCharWidth() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+
+ int cmap() const;
+ const char *name() const;
+
+ void setScale( double scale );
+ double scale() const { return _scale; }
+
+ bool canRender( const TQChar *string, int len );
+
+ Type type() const;
+ XftPattern *pattern() const { return _pattern; }
+ FT_Face face() const { return _face; }
+ XftFont *font() const { return _font; }
+
+ void recalcAdvances( int len, glyph_t *glyphs, advance_t *advances );
+
+private:
+ friend class TQFontPrivate;
+ friend class TQOpenType;
+ XftFont *_font;
+ XftPattern *_pattern;
+ FT_Face _face;
+ TQOpenType *_openType;
+ int _cmap;
+ short lbearing;
+ short rbearing;
+ float _scale;
+ enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 };
+ unsigned char widthCache[widthCacheSize];
+ glyph_t cmapCache[cmapCacheSize];
+};
+#endif
+
+class TQFontEngineLatinXLFD;
+
+class TQFontEngineXLFD : public TQFontEngine
+{
+public:
+ TQFontEngineXLFD( XFontStruct *fs, const char *name, int cmap );
+ ~TQFontEngineXLFD();
+
+ Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
+
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags );
+
+ virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
+ glyph_metrics_t boundingBox( glyph_t glyph );
+
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ int maxCharWidth() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+
+ int cmap() const;
+ const char *name() const;
+
+ bool canRender( const TQChar *string, int len );
+
+ void setScale( double scale );
+ double scale() const { return _scale; }
+ Type type() const;
+
+ TQt::HANDLE handle() const { return (TQt::HANDLE) _fs->fid; }
+
+private:
+ friend class TQFontPrivate;
+ XFontStruct *_fs;
+ TQCString _name;
+ TQTextCodec *_codec;
+ float _scale; // needed for printing, to correctly scale font metrics for bitmap fonts
+ int _cmap;
+ short lbearing;
+ short rbearing;
+ enum XlfdTransformations {
+ XlfdTrUnknown,
+ XlfdTrSupported,
+ XlfdTrUnsupported
+ };
+ XlfdTransformations xlfd_transformations;
+
+ friend class TQFontEngineLatinXLFD;
+};
+
+class TQFontEngineLatinXLFD : public TQFontEngine
+{
+public:
+ TQFontEngineLatinXLFD( XFontStruct *xfs, const char *name, int cmap );
+ ~TQFontEngineLatinXLFD();
+
+ Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs,
+ advance_t *advances, int *nglyphs, bool mirrored ) const;
+
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine,
+ const TQScriptItem *si, int textFlags );
+
+ virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances,
+ const qoffset_t *offsets, int numGlyphs );
+ glyph_metrics_t boundingBox( glyph_t glyph );
+
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ int maxCharWidth() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+
+ int cmap() const { return -1; } // ###
+ const char *name() const;
+
+ bool canRender( const TQChar *string, int len );
+
+ void setScale( double scale );
+ double scale() const { return _engines[0]->scale(); }
+ Type type() const { return LatinXLFD; }
+
+ TQt::HANDLE handle() const { return ((TQFontEngineXLFD *) _engines[0])->handle(); }
+
+private:
+ void tqfindEngine( const TQChar &ch );
+
+ TQFontEngine **_engines;
+ int _count;
+
+ glyph_t glyphIndices [0x200];
+ advance_t glyphAdvances[0x200];
+ glyph_t euroIndex;
+ advance_t euroAdvance;
+};
+
+class TQScriptItem;
+class TQTextEngine;
+
+#ifndef TQT_NO_XFTFREETYPE
+
+#include "tqscriptengine_p.h"
+#include "tqtextengine_p.h"
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include "ftxopen.h"
+
+enum { PositioningProperties = 0x80000000 };
+
+class TQOpenType
+{
+public:
+ TQOpenType(TQFontEngineXft *fe);
+ ~TQOpenType();
+
+ struct Features {
+ uint tag;
+ uint property;
+ };
+
+ bool supportsScript(unsigned int script) {
+ TQ_ASSERT(script < TQFont::NScripts);
+ return supported_scripts[script];
+ }
+ void selectScript(unsigned int script, const Features *features = 0);
+
+ bool tqshape(TQShaperItem *item, const unsigned int *properties = 0);
+ bool positionAndAdd(TQShaperItem *item, bool doLogClusters = TRUE);
+
+ OTL_GlyphItem glyphs() const { return otl_buffer->in_string; }
+ int len() const { return otl_buffer->in_length; }
+ void setProperty(int index, uint property) { otl_buffer->in_string[index].properties = property; }
+
+
+private:
+ bool checkScript(unsigned int script);
+ TQFontEngine *fontEngine;
+ FT_Face face;
+ TTO_GDEF gdef;
+ TTO_GSUB gsub;
+ TTO_GPOS gpos;
+ bool supported_scripts[TQFont::NScripts];
+ FT_ULong current_script;
+ bool positioned : 1;
+ OTL_Buffer otl_buffer;
+ GlyphAttributes *tmpAttributes;
+ unsigned int *tmpLogClusters;
+ int length;
+ int orig_nglyphs;
+ int loadFlags;
+};
+
+#endif // TQT_NO_XFTFREETYPE
+
+#elif defined( TQ_WS_MAC )
+#include "tqt_mac.h"
+#include <tqmap.h>
+#include <tqcache.h>
+
+class TQFontEngineMac : public TQFontEngine
+{
+#if 0
+ ATSFontMetrics *info;
+#else
+ FontInfo *info;
+#endif
+ int psize;
+ FMFontFamily fmfam;
+ TQMacFontInfo *internal_fi;
+ mutable ATSUTextLayout mTextLayout;
+ enum { widthCacheSize = 0x500 };
+ mutable unsigned char widthCache[widthCacheSize];
+ friend class TQFont;
+ friend class TQGLContext;
+ friend class TQFontPrivate;
+ friend class TQMacSetFontInfo;
+
+public:
+ TQFontEngineMac();
+ ~TQFontEngineMac();
+
+ Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
+
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags );
+
+ glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
+ glyph_metrics_t boundingBox( glyph_t glyph );
+
+ int ascent() const { return (int)info->ascent; }
+ int descent() const { return (int)info->descent; }
+ int leading() const { return (int)info->leading; }
+#if 0
+ int maxCharWidth() const { return (int)info->maxAdvanceWidth; }
+#else
+ int maxCharWidth() const { return info->widMax; }
+#endif
+
+ const char *name() const { return "ATSUI"; }
+
+ bool canRender( const TQChar *string, int len );
+
+ Type type() const { return TQFontEngine::Mac; }
+
+ void calculateCost();
+
+ enum { WIDTH=0x01, DRAW=0x02, EXISTS=0x04 };
+ int doTextTask(const TQChar *s, int pos, int use_len, int len, uchar task, int =-1, int y=-1,
+ TQPaintDevice *dev=NULL, const TQRegion *rgn=NULL) const;
+};
+
+#elif defined( TQ_WS_WIN )
+
+class TQFontEngineWin : public TQFontEngine
+{
+public:
+ TQFontEngineWin( const char *name, HDC, HFONT, bool, LOGFONT );
+
+ Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
+
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags );
+
+ glyph_metrics_t boundingBox( const glyph_t *glyphs,
+ const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
+ glyph_metrics_t boundingBox( glyph_t glyph );
+
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ int maxCharWidth() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+
+ const char *name() const;
+
+ bool canRender( const TQChar *string, int len );
+
+ Type type() const;
+
+ enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 };
+ unsigned char widthCache[widthCacheSize];
+};
+
+#if 0
+class TQFontEngineUniscribe : public TQFontEngineWin
+{
+public:
+ void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags );
+ bool canRender( const TQChar *string, int len );
+
+ Type type() const;
+};
+#endif
+
+#endif // TQ_WS_WIN
+
+#endif // USE_QT4
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqfontengine_x11.cpp b/tqtinterface/qt4/src/kernel/tqfontengine_x11.cpp
new file mode 100644
index 0000000..0b45ec9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontengine_x11.cpp
@@ -0,0 +1,2752 @@
+/****************************************************************************
+**
+** ???
+**
+** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+#include <Qt/qdatastream.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+#else // USE_QT4
+#include "tqfontengine_p.h"
+#endif // USE_QT4
+
+// #define FONTENGINE_DEBUG
+
+#include <tqwidget.h>
+#include <tqcstring.h>
+#include <tqtextcodec.h>
+
+#include "tqbitmap.h"
+#include "tqfontdatabase.h"
+#include "tqpaintdevice.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqpainter.h"
+#include "tqimage.h"
+
+#include "tqt_x11_p.h"
+
+#include "tqfont.h"
+#include "tqtextengine_p.h"
+
+#include <private/tqunicodetables_p.h>
+
+#ifdef USE_QT4
+#include "tqfontengine_p.h"
+#endif // USE_QT4
+
+#include <limits.h>
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+// defined in qfontdatbase_x11.cpp
+extern int qt_mib_for_xlfd_encoding( const char *encoding );
+extern int qt_xlfd_encoding_id( const char *encoding );
+
+extern void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill );
+
+static void drawLines( TQPainter *p, TQFontEngine *fe, int baseline, int x1, int w, int textFlags )
+{
+ int lw = fe->lineThickness();
+ if ( textFlags & TQt::Underline ) {
+ int pos = fe->underlinePosition();
+ qt_draw_transformed_rect( p, x1, baseline+pos, w, lw, TRUE );
+ }
+ if ( textFlags & TQt::Overline ) {
+ int pos = fe->ascent()+1;
+ if ( !pos ) pos = 1;
+ qt_draw_transformed_rect( p, x1, baseline-pos, w, lw, TRUE );
+ }
+ if ( textFlags & TQt::StrikeOut ) {
+ int pos = fe->ascent()/3;
+ if ( !pos ) pos = 1;
+ qt_draw_transformed_rect( p, x1, baseline-pos, w, lw, TRUE );
+ }
+}
+
+
+inline static void qSafeXDestroyImage( XImage *x )
+{
+ if ( x->data ) {
+ free( x->data );
+ x->data = 0;
+ }
+ XDestroyImage( x );
+}
+
+extern bool qt_xForm_helper( const TQWMatrix &trueMat, int xoffset,
+ int type, int depth,
+ uchar *dptr, int dbpl, int p_inc, int dHeight,
+ uchar *sptr, int sbpl, int sWidth, int sHeight
+ );
+
+static TQBitmap transform(Display *dpy, const TQBitmap &source, int xoff, int yoff, int w, int h, const TQWMatrix &matrix)
+{
+ int ws = source.width();
+ int hs = source.height();
+
+ bool invertible;
+ TQWMatrix mat = matrix.invert( &invertible ); // invert matrix
+
+ if (!invertible )
+ return TQBitmap();
+ mat.translate(xoff, yoff);
+
+ XImage *xi = XGetImage(dpy, source.handle(), 0, 0, ws, hs, AllPlanes, XYPixmap);
+
+ if ( !xi )
+ return TQBitmap();
+
+ int sbpl = xi->bytes_per_line;
+ uchar *sptr = (uchar *)xi->data;
+
+ int dbpl = (w+7)/8;
+ int dbytes = dbpl*h;
+
+ uchar *dptr = (uchar *)malloc( dbytes ); // create buffer for bits
+ memset( dptr, 0, dbytes );
+
+ int type = xi->bitmap_bit_order == MSBFirst ? TQT_XFORM_TYPE_MSBFIRST : TQT_XFORM_TYPE_LSBFIRST;
+ int xbpl, p_inc;
+ xbpl = (w+7)/8;
+ p_inc = dbpl - xbpl;
+
+ bool ok = qt_xForm_helper( mat, xi->xoffset, type, 1, dptr, xbpl, p_inc, h, sptr, sbpl, ws, hs );
+ qSafeXDestroyImage(xi);
+ TQBitmap bm;
+ if (ok) {
+ bm = TQBitmap( w, h, dptr, TQImage::systemBitOrder() != TQImage::BigEndian );
+ } else {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQFontEngineXft::tranform: xform failed");
+#endif
+ }
+
+ free( dptr );
+ return bm;
+}
+
+
+static void drawScaled(int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags,
+ Display *dpy, GC gc, TQPaintDevice *pdev, TQFontEngine *fe,
+ const TQWMatrix &xmat, float scale)
+{
+ // font doesn't support transformations, need to do it by hand
+ int w = tqRound(si->width/scale);
+ int h = tqRound((si->ascent + si->descent + 1)/scale);
+ if (w == 0 || h == 0)
+ return;
+ TQWMatrix mat1 = xmat;
+ mat1.scale(scale, scale);
+
+ w += h; // add some pixels to width because of italic correction
+ TQBitmap bm( w, h, TRUE ); // create bitmap
+ TQPainter paint;
+ paint.begin( &bm ); // draw text in bitmap
+ fe->draw( &paint, 0, si->ascent/scale, engine, si, textFlags );
+ paint.end();
+
+ TQRect pdevRect;
+ if (pdev->devType() == TQInternal::Widget)
+ pdevRect = ((TQWidget *)pdev)->rect();
+ else if (pdev->devType() == TQInternal::Pixmap)
+ pdevRect = ((TQPixmap *)pdev)->rect();
+ else
+ return;
+
+
+ TQRect br = mat1.mapRect(TQRect(x, y - si->ascent, w, h));
+ TQRect br2 = br & pdevRect;
+ if (br2.width() <= 0 || br2.height() <= 0
+ || br2.width() >= 32768 || br2.height() >= 32768)
+ return;
+ TQWMatrix mat = TQT_TQWMATRIX_OBJECT(TQPixmap::trueMatrix( mat1, w, h ));
+ TQBitmap wx_bm = ::transform(dpy, bm, br2.x() - br.x(), br2.y() - br.y(), br2.width(), br2.height(), mat);
+ if ( wx_bm.isNull() )
+ return;
+
+ x = br2.x();
+ y = br2.y();
+
+ TQt::HANDLE hd = pdev->handle();
+ XSetFillStyle( dpy, gc, FillStippled );
+ XSetStipple( dpy, gc, wx_bm.handle() );
+ XSetTSOrigin( dpy, gc, x, y );
+ XFillRectangle( dpy, hd, gc, x, y, wx_bm.width(), wx_bm.height() );
+ XSetTSOrigin( dpy, gc, 0, 0 );
+ XSetFillStyle( dpy, gc, FillSolid );
+}
+
+
+TQFontEngine::~TQFontEngine()
+{
+}
+
+int TQFontEngine::lineThickness() const
+{
+ // ad hoc algorithm
+ int score = fontDef.weight * fontDef.pixelSize;
+ int lw = score / 700;
+
+ // looks better with thicker line for small pointsizes
+ if ( lw < 2 && score >= 1050 ) lw = 2;
+ if ( lw == 0 ) lw = 1;
+
+ return lw;
+}
+
+int TQFontEngine::underlinePosition() const
+{
+ int pos = ( ( lineThickness() * 2 ) + 3 ) / 6;
+ return pos ? pos : 1;
+}
+
+// ------------------------------------------------------------------
+// The box font engine
+// ------------------------------------------------------------------
+
+
+TQFontEngineBox::TQFontEngineBox( int size )
+ : _size( size )
+{
+ cache_cost = sizeof( TQFontEngineBox );
+}
+
+TQFontEngineBox::~TQFontEngineBox()
+{
+}
+
+TQFontEngine::Error TQFontEngineBox::stringToCMap( const TQChar *, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool ) const
+{
+ if ( *nglyphs < len ) {
+ *nglyphs = len;
+ return OutOfMemory;
+ }
+
+ memset( glyphs, 0, len * sizeof( glyph_t ) );
+ *nglyphs = len;
+
+ if ( advances ) {
+ for ( int i = 0; i < len; i++ )
+ *(advances++) = _size;
+ }
+ return NoError;
+}
+
+void TQFontEngineBox::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags )
+{
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ TQt::HANDLE hd = p->tqdevice()->handle();
+ GC gc = p->gc;
+
+#ifdef FONTENGINE_DEBUG
+ p->save();
+ p->setBrush( TQt::white );
+ glyph_metrics_t ci = boundingBox( glyphs, offsets, numGlyphs );
+ p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height );
+ p->drawRect( x + ci.x, y + 50 + ci.y, ci.width, ci.height );
+ qDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height );
+ p->restore();
+ int xp = x;
+ int yp = y;
+#endif
+
+ GlyphAttributes *glyphAttributes = engine->glyphAttributes( si );
+
+ if ( p->txop > TQPainter::TxTranslate ) {
+ int xp = x;
+ int yp = _size + 2;
+ int s = _size - 3;
+ for (int k = 0; k < si->num_glyphs; k++) {
+ if (!glyphAttributes[k].zeroWidth)
+ qt_draw_transformed_rect( p, xp, yp, s, s, FALSE );
+ xp += _size;
+ }
+ } else {
+ if ( p->txop == TQPainter::TxTranslate )
+ p->map( x, y, &x, &y );
+
+ XRectangle rects[64];
+
+ int gl = 0;
+ while (gl < si->num_glyphs) {
+ int toDraw = TQMIN(64, si->num_glyphs-gl);
+ int adv = toDraw*_size;
+ if (x + adv < SHRT_MAX && x > SHRT_MIN) {
+ int ng = 0;
+ for (int k = 0; k < toDraw; k++) {
+ if (!glyphAttributes[gl + k].zeroWidth) {
+ rects[ng].x = x + (k * _size);
+ rects[ng].y = y - _size + 2;
+ rects[ng].width = rects[k].height = _size - 3;
+ ++ng;
+ }
+ }
+ XDrawRectangles(dpy, hd, gc, rects, ng);
+ }
+ gl += toDraw;
+ x += adv;
+ }
+ }
+
+ if ( textFlags != 0 )
+ drawLines( p, this, y, x, si->num_glyphs*_size, textFlags );
+
+#ifdef FONTENGINE_DEBUG
+ x = xp;
+ y = yp;
+ p->save();
+ p->setPen( TQt::red );
+ for ( int i = 0; i < numGlyphs; i++ ) {
+ glyph_metrics_t ci = boundingBox( glyphs[i] );
+ x += offsets[i].x;
+ y += offsets[i].y;
+ p->drawRect( x + ci.x, y + 50 + ci.y, ci.width, ci.height );
+ qDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offset=(%d/%d)", i, ci.x, ci.y, ci.width, ci.height,
+ ci.xoff, ci.yoff, offsets[i].x, offsets[i].y );
+ x += ci.xoff;
+ y += ci.yoff;
+ }
+ p->restore();
+#endif
+}
+
+glyph_metrics_t TQFontEngineBox::boundingBox( const glyph_t *, const advance_t *, const qoffset_t *, int numGlyphs )
+{
+ glyph_metrics_t overall;
+ overall.x = overall.y = 0;
+ overall.width = _size*numGlyphs;
+ overall.height = _size;
+ overall.xoff = overall.width;
+ overall.yoff = 0;
+ return overall;
+}
+
+glyph_metrics_t TQFontEngineBox::boundingBox( glyph_t )
+{
+ return glyph_metrics_t( 0, _size, _size, _size, _size, 0 );
+}
+
+
+
+int TQFontEngineBox::ascent() const
+{
+ return _size;
+}
+
+int TQFontEngineBox::descent() const
+{
+ return 0;
+}
+
+int TQFontEngineBox::leading() const
+{
+ int l = tqRound( _size * 0.15 );
+ return (l > 0) ? l : 1;
+}
+
+int TQFontEngineBox::maxCharWidth() const
+{
+ return _size;
+}
+
+int TQFontEngineBox::cmap() const
+{
+ return -1;
+}
+
+const char *TQFontEngineBox::name() const
+{
+ return "null";
+}
+
+bool TQFontEngineBox::canRender( const TQChar *, int )
+{
+ return TRUE;
+}
+
+TQFontEngine::Type TQFontEngineBox::type() const
+{
+ return Box;
+}
+
+
+
+
+// ------------------------------------------------------------------
+// Xlfd cont engine
+// ------------------------------------------------------------------
+
+static inline XCharStruct *charStruct( XFontStruct *xfs, uint ch )
+{
+ XCharStruct *xcs = 0;
+ unsigned char r = ch>>8;
+ unsigned char c = ch&0xff;
+ if ( r >= xfs->min_byte1 &&
+ r <= xfs->max_byte1 &&
+ c >= xfs->min_char_or_byte2 &&
+ c <= xfs->max_char_or_byte2) {
+ if ( !xfs->per_char )
+ xcs = &(xfs->min_bounds);
+ else {
+ xcs = xfs->per_char + ((r - xfs->min_byte1) *
+ (xfs->max_char_or_byte2 -
+ xfs->min_char_or_byte2 + 1)) +
+ (c - xfs->min_char_or_byte2);
+ if (xcs->width == 0 && xcs->ascent == 0 && xcs->descent == 0)
+ xcs = 0;
+ }
+ }
+ return xcs;
+}
+
+TQFontEngineXLFD::TQFontEngineXLFD( XFontStruct *fs, const char *name, int mib )
+ : _fs( fs ), _name( name ), _codec( 0 ), _scale( 1. ), _cmap( mib )
+{
+ if ( _cmap ) _codec = TQTextCodec::codecForMib( _cmap );
+
+ cache_cost = (((fs->max_byte1 - fs->min_byte1) *
+ (fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1)) +
+ fs->max_char_or_byte2 - fs->min_char_or_byte2);
+ cache_cost = ((fs->max_bounds.ascent + fs->max_bounds.descent) *
+ (fs->max_bounds.width * cache_cost / 8));
+ lbearing = SHRT_MIN;
+ rbearing = SHRT_MIN;
+
+#if 1
+ // Server side transformations do not seem to work correctly for
+ // all types of fonts (for example, it works for bdf/pcf fonts,
+ // but not for ttf). It also seems to be extermely server
+ // dependent. The best thing is to just disable server side
+ // transformations until either server support matures or we
+ // figure out a better way to do it.
+ xlfd_transformations = XlfdTrUnsupported;
+#else
+ xlfd_transformations = XlfdTrUnknown;
+
+ // Hummingbird's Exceed X server will substitute 'fixed' for any
+ // known fonts, and it doesn't seem to support transformations, so
+ // we should never try to use xlfd transformations with it
+ if (strstr(ServerVendor(TQPaintDevice::x11AppDisplay()), "Hummingbird"))
+ xlfd_transformations = XlfdTrUnsupported;
+#endif
+}
+
+TQFontEngineXLFD::~TQFontEngineXLFD()
+{
+ XFreeFont( TQPaintDevice::x11AppDisplay(), _fs );
+ _fs = 0;
+ TransformedFont *trf = transformed_fonts;
+ while ( trf ) {
+ XUnloadFont( TQPaintDevice::x11AppDisplay(), trf->xlfd_font );
+ TransformedFont *tmp = trf;
+ trf = trf->next;
+ delete tmp;
+ }
+}
+
+TQFontEngine::Error TQFontEngineXLFD::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const
+{
+ if ( *nglyphs < len ) {
+ *nglyphs = len;
+ return OutOfMemory;
+ }
+
+ if ( _codec ) {
+ bool haveNbsp = FALSE;
+ for ( int i = 0; i < len; i++ )
+ if ( str[i].tqunicode() == 0xa0 ) {
+ haveNbsp = TRUE;
+ break;
+ }
+
+ TQChar *chars = (TQChar *)str;
+ if ( haveNbsp || mirrored ) {
+ chars = (TQChar *)malloc( len*sizeof(TQChar) );
+ for ( int i = 0; i < len; i++ )
+ chars[i] = (str[i].tqunicode() == 0xa0 ? 0x20 :
+ (mirrored ? ::mirroredChar(str[i]).tqunicode() : str[i].tqunicode()));
+ }
+ _codec->fromUnicodeInternal( chars, glyphs, len );
+ if (chars != str)
+ free( chars );
+ } else {
+ glyph_t *g = glyphs + len;
+ const TQChar *c = str + len;
+ if ( mirrored ) {
+ while ( c != str )
+ *(--g) = (--c)->tqunicode() == 0xa0 ? 0x20 : ::mirroredChar(*c).tqunicode();
+ } else {
+ while ( c != str )
+ *(--g) = (--c)->tqunicode() == 0xa0 ? 0x20 : c->tqunicode();
+ }
+ }
+ *nglyphs = len;
+
+ if ( advances ) {
+ glyph_t *g = glyphs + len;
+ advance_t *a = advances + len;
+ XCharStruct *xcs;
+ // inlined for better perfomance
+ if ( !_fs->per_char ) {
+ xcs = &_fs->min_bounds;
+ while ( a != advances )
+ *(--a) = xcs->width;
+ }
+ else if ( !_fs->max_byte1 ) {
+ XCharStruct *base = _fs->per_char - _fs->min_char_or_byte2;
+ while ( g-- != glyphs ) {
+ unsigned int gl = *g;
+ xcs = (gl >= _fs->min_char_or_byte2 && gl <= _fs->max_char_or_byte2) ?
+ base + gl : 0;
+ *(--a) = (!xcs || (!xcs->width && !xcs->ascent && !xcs->descent)) ? _fs->ascent : xcs->width;
+ }
+ }
+ else {
+ while ( g != glyphs ) {
+ xcs = charStruct( _fs, *(--g) );
+ *(--a) = (xcs ? xcs->width : _fs->ascent);
+ }
+ }
+ if ( _scale != 1. ) {
+ for ( int i = 0; i < len; i++ )
+ advances[i] = tqRound(advances[i]*_scale);
+ }
+ }
+ return NoError;
+}
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static bool x_font_load_error = FALSE;
+static int x_font_errorhandler(Display *, XErrorEvent *)
+{
+ x_font_load_error = TRUE;
+ return 0;
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+void TQFontEngineXLFD::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags )
+{
+ if ( !si->num_glyphs )
+ return;
+
+// qDebug("TQFontEngineXLFD::draw( %d, %d, numglyphs=%d", x, y, si->num_glyphs );
+
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ TQt::HANDLE hd = p->tqdevice()->handle();
+ GC gc = p->gc;
+
+ bool transform = FALSE;
+ int xorig = x;
+ int yorig = y;
+
+ TQt::HANDLE font_id = _fs->fid;
+ if ( p->txop > TQPainter::TxTranslate || _scale < 0.9999 || _scale > 1.0001 ) {
+ bool degenerate = TQABS( p->m11()*p->m22() - p->m12()*p->m21() ) < 0.01;
+ if ( !degenerate && xlfd_transformations != XlfdTrUnsupported ) {
+ // need a transformed font from the server
+ TQCString xlfd_transformed = _name;
+ int field = 0;
+ char *data = xlfd_transformed.data();
+ int pos = 0;
+ while ( field < 7 ) {
+ if ( data[pos] == '-' )
+ field++;
+ pos++;
+ }
+ int endPos = pos;
+ while ( data[endPos] != '-' )
+ endPos++;
+ float size = xlfd_transformed.mid( pos, endPos-pos ).toInt();
+ float mat[4];
+ mat[0] = p->m11()*size*_scale;
+ mat[1] = -p->m12()*size*_scale;
+ mat[2] = -p->m21()*size*_scale;
+ mat[3] = p->m22()*size*_scale;
+
+ // check if we have it cached
+ TransformedFont *trf = transformed_fonts;
+ TransformedFont *prev = 0;
+ int i = 0;
+ while ( trf ) {
+ if ( trf->xx == mat[0] &&
+ trf->xy == mat[1] &&
+ trf->yx == mat[2] &&
+ trf->yy == mat[3] )
+ break;
+ TransformedFont *tmp = trf;
+ trf = trf->next;
+ if (i > 10) {
+ XUnloadFont( TQPaintDevice::x11AppDisplay(), tmp->xlfd_font );
+ delete tmp;
+ prev->next = trf;
+ } else {
+ prev = tmp;
+ }
+ ++i;
+ }
+ if ( trf ) {
+ if ( prev ) {
+ // move to beginning of list
+ prev->next = trf->next;
+ trf->next = transformed_fonts;
+ transformed_fonts = trf;
+ }
+ font_id = trf->xlfd_font;
+ } else {
+ TQCString matrix="[";
+ for ( int i = 0; i < 4; i++ ) {
+ float f = mat[i];
+ if ( f < 0 ) {
+ matrix += '~';
+ f = -f;
+ }
+ matrix += TQString::number( f, 'f', 5 ).latin1();
+ matrix += ' ';
+ }
+ matrix += ']';
+ //qDebug("m: %2.2f %2.2f %2.2f %2.2f, matrix=%s", p->m11(), p->m12(), p->m21(), p->m22(), matrix.data());
+ xlfd_transformed.tqreplace( pos, endPos-pos, matrix );
+
+ x_font_load_error = FALSE;
+ XErrorHandler old_handler = XSetErrorHandler( x_font_errorhandler );
+ font_id = XLoadFont( dpy, xlfd_transformed.data() );
+ XSync( dpy, FALSE );
+ XSetErrorHandler( old_handler );
+ if ( x_font_load_error ) {
+ //qDebug( "couldn't load transformed font" );
+ font_id = _fs->fid;
+ xlfd_transformations = XlfdTrUnsupported;
+ } else {
+ TransformedFont *trf = new TransformedFont;
+ trf->xx = mat[0];
+ trf->xy = mat[1];
+ trf->yx = mat[2];
+ trf->yy = mat[3];
+ trf->xlfd_font = font_id;
+ trf->next = transformed_fonts;
+ transformed_fonts = trf;
+ }
+ }
+ }
+ if ( degenerate || xlfd_transformations == XlfdTrUnsupported ) {
+ // XServer or font don't support server side transformations, need to do it by hand
+ float tmp = _scale;
+ _scale = 1.;
+ drawScaled(x, y, engine, si, textFlags, dpy, p->gc, p->tqdevice(), this, p->xmat, tmp);
+ _scale = tmp;
+ return;
+ }
+ transform = TRUE;
+ } else if ( p->txop == TQPainter::TxTranslate ) {
+ p->map( x, y, &x, &y );
+ }
+
+ XSetFont(dpy, gc, font_id);
+
+#ifdef FONTENGINE_DEBUG
+ p->save();
+ p->setBrush( TQt::white );
+ glyph_metrics_t ci = boundingBox( glyphs, advances, offsets, si->num_glyphs );
+ p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height );
+ p->drawRect( x + ci.x, y + 100 + ci.y, ci.width, ci.height );
+ qDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height );
+ p->restore();
+ int xp = x;
+ int yp = y;
+#endif
+
+ glyph_t *glyphs = engine->glyphs( si );
+ advance_t *advances = engine->advances( si );
+ qoffset_t *offsets = engine->offsets( si );
+
+ XChar2b ch[256];
+ XChar2b *chars = ch;
+ if ( si->num_glyphs > 255 )
+ chars = (XChar2b *)malloc( si->num_glyphs*sizeof(XChar2b) );
+
+ for (int i = 0; i < si->num_glyphs; i++) {
+ chars[i].byte1 = glyphs[i] >> 8;
+ chars[i].byte2 = glyphs[i] & 0xff;
+ }
+
+ int xpos = x;
+ GlyphAttributes *glyphAttributes = engine->glyphAttributes( si );
+
+ if ( si->analysis.bidiLevel % 2 ) {
+ int i = si->num_glyphs;
+ while( i-- ) {
+ advance_t adv = advances[i];
+ // qDebug("advance = %d/%d", adv.x, adv.y );
+ x += adv;
+ glyph_metrics_t gi = boundingBox( glyphs[i] );
+ int xp = x-offsets[i].x-gi.xoff;
+ int yp = y+offsets[i].y-gi.yoff;
+ if ( transform )
+ p->map( xp, yp, &xp, &yp );
+ if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN)
+ XDrawString16(dpy, hd, gc, xp, yp, chars+i, 1 );
+ }
+ } else {
+ if ( transform || si->hasPositioning ) {
+ int i = 0;
+ while( i < si->num_glyphs ) {
+ int xp = x+offsets[i].x;
+ int yp = y+offsets[i].y;
+ if ( transform )
+ p->map( xp, yp, &xp, &yp );
+ if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN)
+ XDrawString16(dpy, hd, gc, xp, yp, chars+i, 1 );
+ advance_t adv = advances[i];
+ // qDebug("advance = %d/%d", adv.x, adv.y );
+ x += adv;
+ i++;
+ }
+ } else {
+ // we can take a shortcut
+ int gl = 0;
+ while (gl < si->num_glyphs) {
+ int toDraw = TQMIN(64, si->num_glyphs-gl);
+ int adv = 0;
+ for (int i = gl; i < gl+toDraw; ++i)
+ adv += advances[i];
+ if (x + adv < SHRT_MAX && x > SHRT_MIN)
+ XDrawString16(dpy, hd, gc, x, y, chars+gl, toDraw);
+ gl += toDraw;
+ x += adv;
+ }
+ }
+ }
+
+ if ( chars != ch )
+ free( chars );
+
+ if ( textFlags != 0 )
+ drawLines( p, this, yorig, xorig, x-xpos, textFlags );
+
+#ifdef FONTENGINE_DEBUG
+ x = xp;
+ y = yp;
+ p->save();
+ p->setPen( TQt::red );
+ for ( int i = 0; i < si->num_glyphs; i++ ) {
+ glyph_metrics_t ci = boundingBox( glyphs[i] );
+ p->drawRect( x + ci.x + offsets[i].x, y + 100 + ci.y + offsets[i].y, ci.width, ci.height );
+ qDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=(%d/%d)", i, ci.x, ci.y, ci.width, ci.height,
+ ci.xoff, ci.yoff, offsets[i].x, offsets[i].y,
+ advances[i].x, advances[i].y);
+ x += advances[i].x;
+ y += advances[i].y;
+ }
+ p->restore();
+#endif
+}
+
+glyph_metrics_t TQFontEngineXLFD::boundingBox( const glyph_t *glyphs, const advance_t *advances, const qoffset_t *offsets, int numGlyphs )
+{
+ int i;
+
+ glyph_metrics_t overall;
+ int ymax = 0;
+ int xmax = 0;
+ for (i = 0; i < numGlyphs; i++) {
+ XCharStruct *xcs = charStruct( _fs, glyphs[i] );
+ if (xcs) {
+ int x = overall.xoff + offsets[i].x - xcs->lbearing;
+ int y = overall.yoff + offsets[i].y - xcs->ascent;
+ overall.x = TQMIN( overall.x, x );
+ overall.y = TQMIN( overall.y, y );
+ xmax = TQMAX( xmax, overall.xoff + offsets[i].x + xcs->rbearing );
+ ymax = TQMAX( ymax, y + xcs->ascent + xcs->descent );
+ overall.xoff += tqRound(advances[i]/_scale);
+ } else {
+ int size = _fs->ascent;
+ overall.x = TQMIN(overall.x, overall.xoff );
+ overall.y = TQMIN(overall.y, overall.yoff - size );
+ ymax = TQMAX( ymax, overall.yoff );
+ overall.xoff += size;
+ xmax = TQMAX( xmax, overall.xoff );
+ }
+ }
+ overall.height = ymax - overall.y;
+ overall.width = xmax - overall.x;
+
+ if ( _scale != 1. ) {
+ overall.x = tqRound(overall.x * _scale);
+ overall.y = tqRound(overall.y * _scale);
+ overall.height = tqRound(overall.height * _scale);
+ overall.width = tqRound(overall.width * _scale);
+ overall.xoff = tqRound(overall.xoff * _scale);
+ overall.yoff = tqRound(overall.yoff * _scale);
+ }
+ return overall;
+}
+
+glyph_metrics_t TQFontEngineXLFD::boundingBox( glyph_t glyph )
+{
+ glyph_metrics_t gm;
+ // ### scale missing!
+ XCharStruct *xcs = charStruct( _fs, glyph );
+ if (xcs) {
+ gm = glyph_metrics_t( xcs->lbearing, -xcs->ascent, xcs->rbearing- xcs->lbearing, xcs->ascent + xcs->descent, xcs->width, 0 );
+ } else {
+ int size = _fs->ascent;
+ gm = glyph_metrics_t( 0, size, size, size, size, 0 );
+ }
+ if ( _scale != 1. ) {
+ gm.x = tqRound(gm.x * _scale);
+ gm.y = tqRound(gm.y * _scale);
+ gm.height = tqRound(gm.height * _scale);
+ gm.width = tqRound(gm.width * _scale);
+ gm.xoff = tqRound(gm.xoff * _scale);
+ gm.yoff = tqRound(gm.yoff * _scale);
+ }
+ return gm;
+}
+
+
+int TQFontEngineXLFD::ascent() const
+{
+ return tqRound(_fs->ascent*_scale);
+}
+
+int TQFontEngineXLFD::descent() const
+{
+ return tqRound((_fs->descent-1)*_scale);
+}
+
+int TQFontEngineXLFD::leading() const
+{
+ int l = tqRound((TQMIN(_fs->ascent, _fs->max_bounds.ascent)
+ + TQMIN(_fs->descent, _fs->max_bounds.descent)) * _scale * 0.15 );
+ return (l > 0) ? l : 1;
+}
+
+int TQFontEngineXLFD::maxCharWidth() const
+{
+ return tqRound(_fs->max_bounds.width*_scale);
+}
+
+
+// Loads the font for the specified script
+static inline int maxIndex(XFontStruct *f) {
+ return (((f->max_byte1 - f->min_byte1) *
+ (f->max_char_or_byte2 - f->min_char_or_byte2 + 1)) +
+ f->max_char_or_byte2 - f->min_char_or_byte2);
+}
+
+int TQFontEngineXLFD::minLeftBearing() const
+{
+ if ( lbearing == SHRT_MIN ) {
+ if ( _fs->per_char ) {
+ XCharStruct *cs = _fs->per_char;
+ int nc = maxIndex(_fs) + 1;
+ int mx = cs->lbearing;
+
+ for (int c = 1; c < nc; c++) {
+ // ignore the bearings for characters whose ink is
+ // completely outside the normal bounding box
+ if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) ||
+ (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width))
+ continue;
+
+ int nmx = cs[c].lbearing;
+
+ if (nmx < mx)
+ mx = nmx;
+ }
+
+ ((TQFontEngineXLFD *)this)->lbearing = mx;
+ } else
+ ((TQFontEngineXLFD *)this)->lbearing = _fs->min_bounds.lbearing;
+ }
+ return tqRound (lbearing*_scale);
+}
+
+int TQFontEngineXLFD::minRightBearing() const
+{
+ if ( rbearing == SHRT_MIN ) {
+ if ( _fs->per_char ) {
+ XCharStruct *cs = _fs->per_char;
+ int nc = maxIndex(_fs) + 1;
+ int mx = cs->rbearing;
+
+ for (int c = 1; c < nc; c++) {
+ // ignore the bearings for characters whose ink is
+ // completely outside the normal bounding box
+ if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) ||
+ (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width))
+ continue;
+
+ int nmx = cs[c].rbearing;
+
+ if (nmx < mx)
+ mx = nmx;
+ }
+
+ ((TQFontEngineXLFD *)this)->rbearing = mx;
+ } else
+ ((TQFontEngineXLFD *)this)->rbearing = _fs->min_bounds.rbearing;
+ }
+ return tqRound (rbearing*_scale);
+}
+
+int TQFontEngineXLFD::cmap() const
+{
+ return _cmap;
+}
+
+const char *TQFontEngineXLFD::name() const
+{
+ return _name;
+}
+
+bool TQFontEngineXLFD::canRender( const TQChar *string, int len )
+{
+ glyph_t glyphs[256];
+ int nglyphs = 255;
+ glyph_t *g = glyphs;
+ if ( stringToCMap( string, len, g, 0, &nglyphs, FALSE ) == OutOfMemory ) {
+ g = (glyph_t *)malloc( nglyphs*sizeof(glyph_t) );
+ stringToCMap( string, len, g, 0, &nglyphs, FALSE );
+ }
+
+ bool allExist = TRUE;
+ for ( int i = 0; i < nglyphs; i++ ) {
+ if ( !g[i] || !charStruct( _fs, g[i] ) ) {
+ allExist = FALSE;
+ break;
+ }
+ }
+
+ if ( g != glyphs )
+ free( g );
+
+ return allExist;
+}
+
+
+void TQFontEngineXLFD::setScale( double scale )
+{
+ _scale = scale;
+}
+
+
+TQFontEngine::Type TQFontEngineXLFD::type() const
+{
+ return XLFD;
+}
+
+
+// ------------------------------------------------------------------
+// LatinXLFD engine
+// ------------------------------------------------------------------
+
+static const int engine_array_inc = 4;
+
+TQFontEngineLatinXLFD::TQFontEngineLatinXLFD( XFontStruct *xfs, const char *name,
+ int mib )
+{
+ _engines = new TQFontEngine*[ engine_array_inc ];
+ _engines[0] = new TQFontEngineXLFD( xfs, name, mib );
+ _count = 1;
+
+ cache_cost = _engines[0]->cache_cost;
+
+ memset( glyphIndices, 0, sizeof( glyphIndices ) );
+ memset( glyphAdvances, 0, sizeof( glyphAdvances ) );
+ euroIndex = 0;
+ euroAdvance = 0;
+}
+
+TQFontEngineLatinXLFD::~TQFontEngineLatinXLFD()
+{
+ for ( int i = 0; i < _count; ++i ) {
+ delete _engines[i];
+ _engines[i] = 0;
+ }
+ delete [] _engines;
+ _engines = 0;
+}
+
+void TQFontEngineLatinXLFD::tqfindEngine( const TQChar &ch )
+{
+ if ( ch.tqunicode() == 0 ) return;
+
+ static const char *alternate_encodings[] = {
+ "iso8859-1",
+ "iso8859-2",
+ "iso8859-3",
+ "iso8859-4",
+ "iso8859-9",
+ "iso8859-10",
+ "iso8859-13",
+ "iso8859-14",
+ "iso8859-15",
+ "hp-roman8"
+ };
+ static const int mib_count = sizeof( alternate_encodings ) / sizeof( const char * );
+
+ // see if one of the above mibs can map the char we want
+ TQTextCodec *codec = 0;
+ int which = -1;
+ int i;
+ for ( i = 0; i < mib_count; ++i ) {
+ const int mib = qt_mib_for_xlfd_encoding( alternate_encodings[i] );
+ bool skip = FALSE;
+ for ( int e = 0; e < _count; ++e ) {
+ if ( _engines[e]->cmap() == mib ) {
+ skip = TRUE;
+ break;
+ }
+ }
+ if ( skip ) continue;
+
+ codec = TQTextCodec::codecForMib( mib );
+ if ( codec && codec->canEncode( ch ) ) {
+ which = i;
+ break;
+ }
+ }
+
+ if ( ! codec || which == -1 )
+ return;
+
+ const int enc_id = qt_xlfd_encoding_id( alternate_encodings[which] );
+ TQFontDef req = fontDef;
+ TQFontEngine *engine = TQFontDatabase::tqfindFont( TQFont::Latin, 0, req, enc_id );
+ if ( ! engine ) {
+ req.family = TQString::null;
+ engine = TQFontDatabase::tqfindFont( TQFont::Latin, 0, req, enc_id );
+ if ( ! engine ) return;
+ }
+ engine->setScale( scale() );
+
+ if ( ! ( _count % engine_array_inc ) ) {
+ // grow the engines array
+ TQFontEngine **old = _engines;
+ int new_size =
+ ( ( ( _count+engine_array_inc ) / engine_array_inc ) * engine_array_inc );
+ _engines = new TQFontEngine*[new_size];
+ for ( i = 0; i < _count; ++i )
+ _engines[i] = old[i];
+ delete [] old;
+ }
+
+ _engines[_count] = engine;
+ const int hi = _count << 8;
+ ++_count;
+
+ unsigned short chars[0x201];
+ glyph_t glyphs[0x201];
+ advance_t advances[0x201];
+ for ( i = 0; i < 0x200; ++i )
+ chars[i] = i;
+ chars[0x200] = 0x20ac;
+ int glyphCount = 0x201;
+ engine->stringToCMap( (const TQChar *) chars, 0x201, glyphs, advances, &glyphCount, FALSE );
+
+ // merge member data with the above
+ for ( i = 0; i < 0x200; ++i ) {
+ if ( glyphIndices[i] != 0 || glyphs[i] == 0 ) continue;
+ glyphIndices[i] = glyphs[i] >= 0x2100 ? glyphs[i] : hi | glyphs[i];
+ glyphAdvances[i] = advances[i];
+ }
+ if (!euroIndex && glyphs[0x200]) {
+ euroIndex = hi | glyphs[0x200];
+ euroAdvance = advances[0x200];
+ }
+}
+
+TQFontEngine::Error
+TQFontEngineLatinXLFD::stringToCMap( const TQChar *str, int len, glyph_t *glyphs,
+ advance_t *advances, int *nglyphs, bool mirrored ) const
+{
+ if ( *nglyphs < len ) {
+ *nglyphs = len;
+ return OutOfMemory;
+ }
+
+ int i;
+ bool missing = FALSE;
+ const TQChar *c = str+len;
+ glyph_t *g = glyphs+len;
+ if ( advances ) {
+ int asc = ascent();
+ advance_t *a = advances+len;
+ if ( mirrored ) {
+ while ( c != str ) {
+ --c;
+ --g;
+ --a;
+ if ( c->tqunicode() < 0x200 ) {
+ unsigned short ch = ::mirroredChar(*c).tqunicode();
+ *g = glyphIndices[ch];
+ *a = glyphAdvances[ch];
+ } else {
+ if ( c->tqunicode() == 0x20ac ) {
+ *g = euroIndex;
+ *a = euroAdvance;
+ } else {
+ *g = 0;
+ *a = asc;
+ }
+ }
+ missing = ( missing || ( *g == 0 ) );
+ }
+ } else {
+ while ( c != str ) {
+ --c;
+ --g;
+ --a;
+ if ( c->tqunicode() < 0x200 ) {
+ *g = glyphIndices[c->tqunicode()];
+ *a = glyphAdvances[c->tqunicode()];
+ } else {
+ if ( c->tqunicode() == 0x20ac ) {
+ *g = euroIndex;
+ *a = euroAdvance;
+ } else {
+ *g = 0;
+ *a = asc;
+ }
+ }
+ missing = ( missing || ( *g == 0 ) );
+ }
+ }
+ } else {
+ if ( mirrored ) {
+ while ( c != str ) {
+ --c;
+ --g;
+ *g = ( ( c->tqunicode() < 0x200 ) ? glyphIndices[::mirroredChar(*c).tqunicode()]
+ : (c->tqunicode() == 0x20ac) ? euroIndex : 0 );
+ missing = ( missing || ( *g == 0 ) );
+ }
+ } else {
+ while ( c != str ) {
+ --c;
+ --g;
+ *g = ( ( c->tqunicode() < 0x200 ) ? glyphIndices[c->tqunicode()]
+ : (c->tqunicode() == 0x20ac) ? euroIndex : 0 );
+ missing = ( missing || ( *g == 0 ) );
+ }
+ }
+ }
+
+ if ( missing ) {
+ for ( i = 0; i < len; ++i ) {
+ unsigned short uc = str[i].tqunicode();
+ if ( glyphs[i] != 0 || (uc >= 0x200 && uc != 0x20ac) )
+ continue;
+
+ TQFontEngineLatinXLFD *that = (TQFontEngineLatinXLFD *) this;
+ that->tqfindEngine( str[i] );
+ glyphs[i] = (uc == 0x20ac ? euroIndex : that->glyphIndices[uc]);
+ if ( advances )
+ advances[i] = (uc == 0x20ac ? euroAdvance : glyphAdvances[uc]);
+ }
+ }
+
+ *nglyphs = len;
+ return NoError;
+}
+
+void TQFontEngineLatinXLFD::draw( TQPainter *p, int x, int y, const TQTextEngine *engine,
+ const TQScriptItem *si, int textFlags )
+{
+ if ( !si->num_glyphs ) return;
+
+ glyph_t *glyphs = engine->glyphs( si );
+ advance_t *advances = engine->advances( si );
+ int which = glyphs[0] >> 8;
+ if (which > 0x20)
+ which = 0;
+
+ int start = 0;
+ int end, i;
+ for ( end = 0; end < si->num_glyphs; ++end ) {
+ int e = glyphs[end] >> 8;
+ if (e > 0x20)
+ e = 0;
+ if ( e == which ) continue;
+
+ // set the high byte to zero
+ if (which != 0) {
+ for ( i = start; i < end; ++i )
+ glyphs[i] = glyphs[i] & 0xff;
+ }
+
+ // draw the text
+ TQScriptItem si2 = *si;
+ si2.glyph_data_offset = si->glyph_data_offset + start;
+ si2.num_glyphs = end - start;
+ _engines[which]->draw( p, x, y, engine, &si2, textFlags );
+
+ // reset the high byte for all glyphs and advance to the next sub-string
+ const int hi = which << 8;
+ for ( i = start; i < end; ++i ) {
+ glyphs[i] = hi | glyphs[i];
+ x += advances[i];
+ }
+
+ // change engine
+ start = end;
+ which = e;
+ }
+
+ // set the high byte to zero
+ if (which != 0) {
+ for ( i = start; i < end; ++i )
+ glyphs[i] = glyphs[i] & 0xff;
+ }
+ // draw the text
+ TQScriptItem si2 = *si;
+ si2.glyph_data_offset = si->glyph_data_offset + start;
+ si2.num_glyphs = end - start;
+ _engines[which]->draw( p, x, y, engine, &si2, textFlags );
+
+ // reset the high byte for all glyphs
+ if (which != 0) {
+ const int hi = which << 8;
+ for ( i = start; i < end; ++i )
+ glyphs[i] = hi | glyphs[i];
+ }
+}
+
+glyph_metrics_t TQFontEngineLatinXLFD::boundingBox( const glyph_t *glyphs_const,
+ const advance_t *advances,
+ const qoffset_t *offsets,
+ int numGlyphs )
+{
+ if ( numGlyphs <= 0 ) return glyph_metrics_t();
+
+ glyph_metrics_t overall;
+
+ glyph_t *glyphs = (glyph_t *) glyphs_const;
+ int which = glyphs[0] >> 8;
+ if (which > 0x20)
+ which = 0;
+
+ int start = 0;
+ int end, i;
+ for ( end = 0; end < numGlyphs; ++end ) {
+ int e = glyphs[end] >> 8;
+ if (e > 0x20)
+ e = 0;
+ if ( e == which ) continue;
+
+ // set the high byte to zero
+ if (which != 0) {
+ for ( i = start; i < end; ++i )
+ glyphs[i] = glyphs[i] & 0xff;
+ }
+
+ // merge the bounding box for this run
+ const glyph_metrics_t gm =
+ _engines[which]->boundingBox( glyphs + start,
+ advances + start,
+ offsets + start,
+ end - start );
+
+ overall.x = TQMIN( overall.x, gm.x );
+ overall.y = TQMIN( overall.y, gm.y );
+ overall.width = overall.xoff + gm.width;
+ overall.height = TQMAX( overall.height + overall.y, gm.height + gm.y ) -
+ TQMIN( overall.y, gm.y );
+ overall.xoff += gm.xoff;
+ overall.yoff += gm.yoff;
+
+ // reset the high byte for all glyphs
+ if (which != 0) {
+ const int hi = which << 8;
+ for ( i = start; i < end; ++i )
+ glyphs[i] = hi | glyphs[i];
+ }
+
+ // change engine
+ start = end;
+ which = e;
+ }
+
+ // set the high byte to zero
+ if (which != 0) {
+ for ( i = start; i < end; ++i )
+ glyphs[i] = glyphs[i] & 0xff;
+ }
+
+ // merge the bounding box for this run
+ const glyph_metrics_t gm =
+ _engines[which]->boundingBox( glyphs + start,
+ advances + start,
+ offsets + start,
+ end - start );
+
+ overall.x = TQMIN( overall.x, gm.x );
+ overall.y = TQMIN( overall.y, gm.y );
+ overall.width = overall.xoff + gm.width;
+ overall.height = TQMAX( overall.height + overall.y, gm.height + gm.y ) -
+ TQMIN( overall.y, gm.y );
+ overall.xoff += gm.xoff;
+ overall.yoff += gm.yoff;
+
+ // reset the high byte for all glyphs
+ if (which != 0) {
+ const int hi = which << 8;
+ for ( i = start; i < end; ++i )
+ glyphs[i] = hi | glyphs[i];
+ }
+
+ return overall;
+}
+
+glyph_metrics_t TQFontEngineLatinXLFD::boundingBox( glyph_t glyph )
+{
+ int engine = glyph >> 8;
+ if (engine > 0x20)
+ engine = 0;
+ TQ_ASSERT( engine < _count );
+ return _engines[engine]->boundingBox( engine > 0 ? glyph & 0xff : glyph );
+}
+
+int TQFontEngineLatinXLFD::ascent() const
+{
+ return _engines[0]->ascent();
+}
+
+int TQFontEngineLatinXLFD::descent() const
+{
+ return _engines[0]->descent();
+}
+
+int TQFontEngineLatinXLFD::leading() const
+{
+ return _engines[0]->leading();
+}
+
+int TQFontEngineLatinXLFD::maxCharWidth() const
+{
+ return _engines[0]->maxCharWidth();
+}
+
+int TQFontEngineLatinXLFD::minLeftBearing() const
+{
+ return _engines[0]->minLeftBearing();
+}
+
+int TQFontEngineLatinXLFD::minRightBearing() const
+{
+ return _engines[0]->minRightBearing();
+}
+
+const char *TQFontEngineLatinXLFD::name() const
+{
+ return _engines[0]->name();
+}
+
+bool TQFontEngineLatinXLFD::canRender( const TQChar *string, int len )
+{
+ bool all = TRUE;
+ int i;
+ for ( i = 0; i < len; ++i ) {
+ if ( string[i].tqunicode() >= 0x200 ||
+ glyphIndices[string[i].tqunicode()] == 0 ) {
+ if (string[i].tqunicode() != 0x20ac || euroIndex == 0)
+ all = FALSE;
+ break;
+ }
+ }
+
+ if ( all )
+ return TRUE;
+
+ all = TRUE;
+ for ( i = 0; i < len; ++i ) {
+ if ( string[i].tqunicode() >= 0x200 ) {
+ if (string[i].tqunicode() == 0x20ac) {
+ if (euroIndex)
+ continue;
+
+ tqfindEngine(string[i]);
+ if (euroIndex)
+ continue;
+ }
+ all = FALSE;
+ break;
+ }
+ if ( glyphIndices[string[i].tqunicode()] != 0 ) continue;
+
+ tqfindEngine( string[i] );
+ if ( glyphIndices[string[i].tqunicode()] == 0 ) {
+ all = FALSE;
+ break;
+ }
+ }
+
+ return all;
+}
+
+void TQFontEngineLatinXLFD::setScale( double scale )
+{
+ int i;
+ for ( i = 0; i < _count; ++i )
+ _engines[i]->setScale( scale );
+ unsigned short chars[0x200];
+ for ( i = 0; i < 0x200; ++i )
+ chars[i] = i;
+ int glyphCount = 0x200;
+ _engines[0]->stringToCMap( (const TQChar *)chars, 0x200,
+ glyphIndices, glyphAdvances, &glyphCount, FALSE );
+}
+
+
+// ------------------------------------------------------------------
+// Xft cont engine
+// ------------------------------------------------------------------
+// #define FONTENGINE_DEBUG
+
+#ifndef TQT_NO_XFTFREETYPE
+class TQ_HackPaintDevice : public TQPaintDevice
+{
+public:
+ inline TQ_HackPaintDevice() : TQPaintDevice( 0 ) {}
+ inline XftDraw *xftDrawHandle() const {
+ return (XftDraw *)rendhd;
+ }
+
+};
+
+#ifdef TQT_XFT2
+static inline void getGlyphInfo( XGlyphInfo *xgi, XftFont *font, int glyph )
+{
+ FT_UInt x = glyph;
+ XftGlyphExtents( TQPaintDevice::x11AppDisplay(), font, &x, 1, xgi );
+}
+#else
+static inline XftFontStruct *getFontStruct( XftFont *font )
+{
+ if (font->core)
+ return 0;
+ return font->u.ft.font;
+}
+
+static inline void getGlyphInfo(XGlyphInfo *xgi, XftFont *font, int glyph)
+{
+
+ XftTextExtents32(TQPaintDevice::x11AppDisplay(), font, (XftChar32 *) &glyph, 1, xgi);
+}
+#endif // TQT_XFT2
+
+static inline FT_Face lockFTFace( XftFont *font )
+{
+#ifdef TQT_XFT2
+ return XftLockFace( font );
+#else
+ if (font->core) return 0;
+ return font->u.ft.font->face;
+#endif // TQT_XFT2
+}
+
+static inline void unlockFTFace( XftFont *font )
+{
+#ifdef TQT_XFT2
+ XftUnlockFace( font );
+#else
+ TQ_UNUSED( font );
+#endif // TQT_XFT2
+}
+
+
+
+TQFontEngineXft::TQFontEngineXft( XftFont *font, XftPattern *pattern, int cmap )
+ : _font( font ), _pattern( pattern ), _openType( 0 ), _cmap( cmap )
+{
+ _face = lockFTFace( _font );
+
+#ifndef TQT_XFT2
+ XftFontStruct *xftfs = getFontStruct( _font );
+ if ( xftfs ) {
+ // dirty hack: we set the charmap in the Xftfreetype to -1, so
+ // XftFreetype assumes no encoding and really draws glyph
+ // indices. The FT_Face still has the Unicode encoding to we
+ // can convert from Unicode to glyph index
+ xftfs->charmap = -1;
+ }
+#else
+ _cmap = -1;
+ // Xft maps Unicode and adobe roman for us.
+ for (int i = 0; i < _face->num_charmaps; ++i) {
+ FT_CharMap cm = _face->charmaps[i];
+// qDebug("font has charmap %x", cm->encoding);
+ if (cm->encoding == ft_encoding_adobe_custom
+ || cm->encoding == ft_encoding_symbol) {
+// qDebug("font has adobe custom or ms symbol charmap");
+ _cmap = i;
+ break;
+ }
+ }
+#endif // TQT_XFT2
+
+
+ cache_cost = _font->height * _font->max_advance_width *
+ ( _face ? _face->num_glyphs : 1024 );
+
+ // if the Xft font is not antialiased, it uses bitmaps instead of
+ // 8-bit alpha maps... adjust the cache_cost to reflect this
+ Bool antialiased = TRUE;
+ if ( XftPatternGetBool( pattern, XFT_ANTIALIAS,
+ 0, &antialiased ) == XftResultMatch &&
+ ! antialiased ) {
+ cache_cost /= 8;
+ }
+ lbearing = SHRT_MIN;
+ rbearing = SHRT_MIN;
+
+ memset( widthCache, 0, sizeof(widthCache) );
+ memset( cmapCache, 0, sizeof(cmapCache) );
+}
+
+TQFontEngineXft::~TQFontEngineXft()
+{
+ delete _openType;
+ unlockFTFace( _font );
+
+ XftFontClose( TQPaintDevice::x11AppDisplay(),_font );
+ XftPatternDestroy( _pattern );
+ _font = 0;
+ _pattern = 0;
+ TransformedFont *trf = transformed_fonts;
+ while ( trf ) {
+ XftFontClose( TQPaintDevice::x11AppDisplay(), trf->xft_font );
+ TransformedFont *tmp = trf;
+ trf = trf->next;
+ delete tmp;
+ }
+}
+
+#ifdef TQT_XFT2
+static glyph_t getAdobeCharIndex(XftFont *font, int cmap, uint ucs4)
+{
+ FT_Face _face = XftLockFace( font );
+ FT_Set_Charmap(_face, _face->charmaps[cmap]);
+ glyph_t g = FT_Get_Char_Index(_face, ucs4);
+ XftUnlockFace(font);
+ return g;
+}
+#endif
+
+TQFontEngine::Error TQFontEngineXft::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const
+{
+ if ( *nglyphs < len ) {
+ *nglyphs = len;
+ return OutOfMemory;
+ }
+
+#ifdef TQT_XFT2
+ if (_cmap != -1) {
+ for ( int i = 0; i < len; ++i ) {
+ unsigned short uc = str[i].tqunicode();
+ if (mirrored)
+ uc = ::mirroredChar(str[i]).tqunicode();
+ glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0;
+ if ( !glyphs[i] ) {
+ glyph_t glyph = XftCharIndex(0, _font, uc);
+ if (!glyph)
+ glyph = getAdobeCharIndex(_font, _cmap, uc);
+ glyphs[i] = glyph;
+ if ( uc < cmapCacheSize )
+ ((TQFontEngineXft *)this)->cmapCache[uc] = glyph;
+ }
+ }
+ } else if ( mirrored ) {
+ for ( int i = 0; i < len; ++i ) {
+ unsigned short uc = ::mirroredChar(str[i]).tqunicode();
+ glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0;
+ if ( !glyphs[i] ) {
+ if (uc == 0xa0)
+ uc = 0x20;
+ glyph_t glyph = XftCharIndex(0, _font, uc);
+ glyphs[i] = glyph;
+ if ( uc < cmapCacheSize )
+ ((TQFontEngineXft *)this)->cmapCache[uc] = glyph;
+ }
+ }
+ } else {
+ for ( int i = 0; i < len; ++i ) {
+ unsigned short uc = str[i].tqunicode();
+ glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0;
+ if ( !glyphs[i] ) {
+ if (uc == 0xa0)
+ uc = 0x20;
+ glyph_t glyph = XftCharIndex(0, _font, uc);
+ glyphs[i] = glyph;
+ if ( uc < cmapCacheSize )
+ ((TQFontEngineXft *)this)->cmapCache[uc] = glyph;
+ }
+ }
+ }
+
+ if ( advances ) {
+ for ( int i = 0; i < len; i++ ) {
+ FT_UInt glyph = *(glyphs + i);
+ advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0;
+ if ( !advances[i] ) {
+ XGlyphInfo gi;
+ XftGlyphExtents( TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi );
+ advances[i] = gi.xOff;
+ if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 )
+ ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff;
+ }
+ }
+ if ( _scale != 1. ) {
+ for ( int i = 0; i < len; i++ )
+ advances[i] = tqRound(advances[i]*_scale);
+ }
+ }
+#else
+ if ( !_face ) {
+ if ( mirrored ) {
+ for ( int i = 0; i < len; i++ )
+ glyphs[i] = ::mirroredChar(str[i]).tqunicode();
+ } else {
+ for ( int i = 0; i < len; i++ )
+ glyphs[i] = str[i].tqunicode();
+ }
+ } else {
+ if ( _cmap == 1 ) {
+ // symbol font
+ for ( int i = 0; i < len; i++ ) {
+ unsigned short uc = str[i].tqunicode();
+ glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0;
+ if ( !glyphs[i] ) {
+ glyph_t glyph = FT_Get_Char_Index( _face, uc );
+ if(!glyph && uc < 0x100)
+ glyph = FT_Get_Char_Index( _face, uc+0xf000 );
+ glyphs[i] = glyph;
+ if ( uc < cmapCacheSize )
+ ((TQFontEngineXft *)this)->cmapCache[uc] = glyph;
+ }
+ }
+ } else if ( mirrored ) {
+ for ( int i = 0; i < len; i++ ) {
+ unsigned short uc = ::mirroredChar(str[i]).tqunicode();
+ glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0;
+ if ( !glyphs[i] ) {
+ glyph_t glyph = FT_Get_Char_Index( _face, uc );
+ glyphs[i] = glyph;
+ if ( uc < cmapCacheSize )
+ ((TQFontEngineXft *)this)->cmapCache[uc] = glyph;
+ }
+ }
+ } else {
+ for ( int i = 0; i < len; i++ ) {
+ unsigned short uc = str[i].tqunicode();
+ glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0;
+ if ( !glyphs[i] ) {
+ glyph_t glyph = FT_Get_Char_Index( _face, uc );
+ glyphs[i] = glyph;
+ if ( uc < cmapCacheSize )
+ ((TQFontEngineXft *)this)->cmapCache[uc] = glyph;
+ }
+ }
+ }
+ }
+
+ if ( advances ) {
+ for ( int i = 0; i < len; i++ ) {
+ XftChar16 glyph = *(glyphs + i);
+ advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0;
+ if ( !advances[i] ) {
+ XGlyphInfo gi;
+ XftTextExtents16(TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi);
+ advances[i] = gi.xOff;
+ if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 )
+ ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff;
+ }
+ }
+ if ( _scale != 1. ) {
+ for ( int i = 0; i < len; i++ )
+ advances[i] = tqRound(advances[i]*_scale);
+ }
+ }
+#endif // TQT_XFT2
+
+ *nglyphs = len;
+ return NoError;
+}
+
+
+void TQFontEngineXft::recalcAdvances( int len, glyph_t *glyphs, advance_t *advances )
+{
+
+#ifdef TQT_XFT2
+ for ( int i = 0; i < len; i++ ) {
+ FT_UInt glyph = *(glyphs + i);
+ advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0;
+ if ( !advances[i] ) {
+ XGlyphInfo gi;
+ XftGlyphExtents( TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi );
+ advances[i] = gi.xOff;
+ if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 )
+ ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff;
+ }
+ if ( _scale != 1. ) {
+ for ( int i = 0; i < len; i++ )
+ advances[i] = tqRound(advances[i]*_scale);
+ }
+ }
+#else
+ for ( int i = 0; i < len; i++ ) {
+ XftChar16 glyph = *(glyphs + i);
+ advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0;
+ if ( !advances[i] ) {
+ XGlyphInfo gi;
+ XftTextExtents16(TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi);
+ advances[i] = gi.xOff;
+ if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 )
+ ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff;
+ }
+ }
+ if ( _scale != 1. ) {
+ for ( int i = 0; i < len; i++ )
+ advances[i] = tqRound(advances[i]*_scale);
+ }
+#endif // TQT_XFT2
+}
+
+//#define FONTENGINE_DEBUG
+void TQFontEngineXft::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags )
+{
+ if ( !si->num_glyphs )
+ return;
+
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+
+ int xorig = x;
+ int yorig = y;
+
+ GlyphAttributes *glyphAttributes = engine->glyphAttributes( si );
+
+ XftFont *fnt = _font;
+ bool transform = FALSE;
+ if ( p->txop >= TQPainter::TxScale || p->rop != TQt::CopyROP || _scale < 0.9999 || _scale > 1.001) {
+ bool can_scale = (_face->face_flags & FT_FACE_FLAG_SCALABLE) && p->rop == TQt::CopyROP;
+ double size = (p->m11()*p->m22() - p->m12()*p->m21())*_scale*_scale*fontDef.pixelSize*fontDef.pixelSize;
+ if (size > 256*256 || _scale < .9999 || _scale > 1.001)
+ can_scale = FALSE;
+ if (!can_scale) {
+ // font doesn't support transformations, need to do it by hand
+ float tmp = _scale;
+ _scale = 1.;
+ drawScaled(x, y, engine, si, textFlags, dpy, p->gc, p->tqdevice(), this, p->xmat, tmp);
+ _scale = tmp;
+ return;
+ }
+
+ XftMatrix *mat = 0;
+ XftPatternGetMatrix( _pattern, XFT_MATRIX, 0, &mat );
+ XftMatrix m2;
+ m2.xx = p->m11()*_scale;
+ m2.xy = -p->m21()*_scale;
+ m2.yx = -p->m12()*_scale;
+ m2.yy = p->m22()*_scale;
+
+ // check if we have it cached
+ TransformedFont *trf = transformed_fonts;
+ TransformedFont *prev = 0;
+ int i = 0;
+ while ( trf ) {
+ if ( trf->xx == (float)m2.xx &&
+ trf->xy == (float)m2.xy &&
+ trf->yx == (float)m2.yx &&
+ trf->yy == (float)m2.yy )
+ break;
+ TransformedFont *tmp = trf;
+ trf = trf->next;
+ if (i > 10) {
+ XftFontClose( TQPaintDevice::x11AppDisplay(), tmp->xft_font );
+ delete tmp;
+ prev->next = trf;
+ } else {
+ prev = tmp;
+ }
+ ++i;
+ }
+ if ( trf ) {
+ if ( prev ) {
+ // move to beginning of list
+ prev->next = trf->next;
+ trf->next = transformed_fonts;
+ transformed_fonts = trf;
+ }
+ fnt = trf->xft_font;
+ } else {
+ if ( mat )
+ XftMatrixMultiply( &m2, &m2, mat );
+
+ XftPattern *pattern = XftPatternDuplicate( _pattern );
+ XftPatternDel( pattern, XFT_MATRIX );
+ XftPatternAddMatrix( pattern, XFT_MATRIX, &m2 );
+
+ fnt = XftFontOpenPattern( dpy, pattern );
+#ifndef TQT_XFT2
+ XftFontStruct *xftfs = getFontStruct( fnt );
+ if ( xftfs ) {
+ // dirty hack: we set the charmap in the Xftfreetype to -1, so
+ // XftFreetype assumes no encoding and really draws glyph
+ // indices. The FT_Face still has the Unicode encoding to we
+ // can convert from Unicode to glyph index
+ xftfs->charmap = -1;
+ }
+#endif // TQT_XFT2
+ TransformedFont *trf = new TransformedFont;
+ trf->xx = (float)m2.xx;
+ trf->xy = (float)m2.xy;
+ trf->yx = (float)m2.yx;
+ trf->yy = (float)m2.yy;
+ trf->xft_font = fnt;
+ trf->next = transformed_fonts;
+ transformed_fonts = trf;
+ }
+ transform = TRUE;
+ } else if ( p->txop == TQPainter::TxTranslate ) {
+ p->map( x, y, &x, &y );
+ }
+
+ glyph_t *glyphs = engine->glyphs( si );
+ advance_t *advances = engine->advances( si );
+ qoffset_t *offsets = engine->offsets( si );
+
+ const TQColor &pen = p->cpen.color();
+ XftDraw *draw = ((TQ_HackPaintDevice *)p->pdev)->xftDrawHandle();
+
+ XftColor col;
+ col.color.red = pen.red () | pen.red() << 8;
+ col.color.green = pen.green () | pen.green() << 8;
+ col.color.blue = pen.blue () | pen.blue() << 8;
+ col.color.alpha = 0xffff;
+ col.pixel = pen.pixel();
+#ifdef FONTENGINE_DEBUG
+ qDebug("===== drawing %d glyphs reverse=%s ======", si->num_glyphs, si->analysis.bidiLevel % 2?"TRUE":"FALSE" );
+ p->save();
+ p->setBrush( TQt::white );
+ glyph_metrics_t ci = boundingBox( glyphs, advances, offsets, si->num_glyphs );
+ p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height );
+ p->drawRect( x + ci.x, y + 100 + ci.y, ci.width, ci.height );
+ qDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height );
+ p->restore();
+ int yp = y;
+ int xp = x;
+#endif
+
+ if ( textFlags != 0 )
+ drawLines( p, this, yorig, xorig, si->width, textFlags );
+
+
+ if ( si->isSpace )
+ return;
+
+ if ( transform || si->hasPositioning ) {
+ if ( si->analysis.bidiLevel % 2 ) {
+ int i = si->num_glyphs;
+ while( i-- ) {
+ int xp = x + offsets[i].x;
+ int yp = y + offsets[i].y;
+ if ( transform )
+ p->map( xp, yp, &xp, &yp );
+#ifdef TQT_XFT2
+ FT_UInt glyph = *(glyphs + i);
+ if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN)
+ XftDrawGlyphs( draw, &col, fnt, xp, yp, &glyph, 1 );
+#else
+ if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN)
+ XftDrawString16( draw, &col, fnt, xp, yp, (XftChar16 *) (glyphs+i), 1);
+#endif // TQT_XFT2
+#ifdef FONTENGINE_DEBUG
+ glyph_metrics_t gi = boundingBox( glyphs[i] );
+ p->drawRect( x+offsets[i].x+gi.x, y+offsets[i].y+100+gi.y, gi.width, gi.height );
+ p->drawLine( x+offsets[i].x, y + 150 + 5*i , x+offsets[i].x+advances[i], y + 150 + 5*i );
+ p->drawLine( x+offsets[i].x, y + 152 + 5*i , x+offsets[i].x+gi.xoff, y + 152 + 5*i );
+ qDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=%d", i, gi.x, gi.y, gi.width, gi.height,
+ gi.xoff, gi.yoff, offsets[i].x, offsets[i].y, advances[i]);
+#endif
+ x += advances[i];
+ }
+ } else {
+ int i = 0;
+ while ( i < si->num_glyphs ) {
+ int xp = x + offsets[i].x;
+ int yp = y + offsets[i].y;
+ if ( transform )
+ p->map( xp, yp, &xp, &yp );
+#ifdef TQT_XFT2
+ FT_UInt glyph = *(glyphs + i);
+ if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN)
+ XftDrawGlyphs( draw, &col, fnt, xp, yp, &glyph, 1 );
+#else
+ if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN)
+ XftDrawString16( draw, &col, fnt, xp, yp, (XftChar16 *) (glyphs+i), 1 );
+#endif // TQT_XFT2
+ // qDebug("advance = %d/%d", adv.x, adv.y );
+ x += advances[i];
+ i++;
+ }
+ }
+ } else {
+ // Xft has real trouble drawing the glyphs on their own.
+ // Drawing them as one string increases performance significantly.
+#ifdef TQT_XFT2
+ // #### we should use a different method anyways on Xft2
+ FT_UInt g[64];
+ int gl = 0;
+ while (gl < si->num_glyphs) {
+ int toDraw = TQMIN(64, si->num_glyphs-gl);
+ int adv = 0;
+ if ( si->analysis.bidiLevel % 2 ) {
+ for ( int i = 0; i < toDraw; i++ ) {
+ g[i] = glyphs[si->num_glyphs-1-(gl+i)];
+ adv += advances[si->num_glyphs-1-(gl+i)];
+ }
+ } else {
+ for ( int i = 0; i < toDraw; i++ ) {
+ g[i] = glyphs[gl+i];
+ adv += advances[gl+i];
+ }
+ }
+ if (x + adv < SHRT_MAX && x > SHRT_MIN)
+ XftDrawGlyphs( draw, &col, fnt, x, y, g, toDraw );
+ gl += toDraw;
+ x += adv;
+ }
+#else
+ XftChar16 g[64];
+ int gl = 0;
+ while (gl < si->num_glyphs) {
+ int toDraw = TQMIN(64, si->num_glyphs-gl);
+ int adv = 0;
+ if ( si->analysis.bidiLevel % 2 ) {
+ for ( int i = 0; i < toDraw; i++ ) {
+ g[i] = glyphs[si->num_glyphs-1-(gl+i)];
+ adv += advances[si->num_glyphs-1-(gl+i)];
+ }
+ } else {
+ for ( int i = 0; i < toDraw; i++ ) {
+ g[i] = glyphs[gl+i];
+ adv += advances[gl+i];
+ }
+ }
+ if (x + adv < SHRT_MAX && x > SHRT_MIN)
+ XftDrawString16( draw, &col, fnt, x, y, g, toDraw );
+ gl += toDraw;
+ x += adv;
+ }
+#endif // TQT_XFT2
+ }
+
+#ifdef FONTENGINE_DEBUG
+ if ( !si->analysis.bidiLevel % 2 ) {
+ x = xp;
+ y = yp;
+ p->save();
+ p->setPen( TQt::red );
+ for ( int i = 0; i < si->num_glyphs; i++ ) {
+ glyph_metrics_t ci = boundingBox( glyphs[i] );
+ p->drawRect( x + ci.x + offsets[i].x, y + 100 + ci.y + offsets[i].y, ci.width, ci.height );
+ qDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=%d", i, ci.x, ci.y, ci.width, ci.height,
+ ci.xoff, ci.yoff, offsets[i].x, offsets[i].y, advances[i]);
+ x += advances[i];
+ }
+ p->restore();
+ }
+#endif
+}
+
+glyph_metrics_t TQFontEngineXft::boundingBox( const glyph_t *glyphs, const advance_t *advances, const qoffset_t *offsets, int numGlyphs )
+{
+ XGlyphInfo xgi;
+
+ glyph_metrics_t overall;
+ int ymax = 0;
+ int xmax = 0;
+ if (_scale != 1) {
+ for (int i = 0; i < numGlyphs; i++) {
+ getGlyphInfo( &xgi, _font, glyphs[i] );
+ int x = overall.xoff + offsets[i].x - xgi.x;
+ int y = overall.yoff + offsets[i].y - xgi.y;
+ overall.x = TQMIN( overall.x, x );
+ overall.y = TQMIN( overall.y, y );
+ xmax = TQMAX( xmax, x + xgi.width );
+ ymax = TQMAX( ymax, y + xgi.height );
+ overall.xoff += tqRound(advances[i]/_scale);
+ }
+ overall.x = tqRound(overall.x * _scale);
+ overall.y = tqRound(overall.y * _scale);
+ overall.xoff = tqRound(overall.xoff * _scale);
+ overall.yoff = tqRound(overall.yoff * _scale);
+ xmax = tqRound(xmax * _scale);
+ ymax = tqRound(ymax * _scale);
+ } else {
+ for (int i = 0; i < numGlyphs; i++) {
+ getGlyphInfo( &xgi, _font, glyphs[i] );
+ int x = overall.xoff + offsets[i].x - xgi.x;
+ int y = overall.yoff + offsets[i].y - xgi.y;
+ overall.x = TQMIN( overall.x, x );
+ overall.y = TQMIN( overall.y, y );
+ xmax = TQMAX( xmax, x + xgi.width );
+ ymax = TQMAX( ymax, y + xgi.height );
+ overall.xoff += advances[i];
+ }
+ }
+ overall.height = ymax - overall.y;
+ overall.width = xmax - overall.x;
+ return overall;
+}
+
+glyph_metrics_t TQFontEngineXft::boundingBox( glyph_t glyph )
+{
+ XGlyphInfo xgi;
+ getGlyphInfo( &xgi, _font, glyph );
+ glyph_metrics_t gm = glyph_metrics_t( -xgi.x, -xgi.y, xgi.width, xgi.height, xgi.xOff, -xgi.yOff );
+ if ( _scale != 1. ) {
+ gm.x = tqRound(gm.x * _scale);
+ gm.y = tqRound(gm.y * _scale);
+ gm.height = tqRound(gm.height * _scale);
+ gm.width = tqRound(gm.width * _scale);
+ gm.xoff = tqRound(gm.xoff * _scale);
+ gm.yoff = tqRound(gm.yoff * _scale);
+ }
+ return gm;
+}
+
+
+
+int TQFontEngineXft::ascent() const
+{
+ return tqRound(_font->ascent*_scale);
+}
+
+int TQFontEngineXft::descent() const
+{
+ return tqRound((_font->descent-1)*_scale);
+}
+
+// #### use Freetype to determine this
+int TQFontEngineXft::leading() const
+{
+ int l = tqRound(TQMIN( _font->height - (_font->ascent + _font->descent),
+ ((_font->ascent + _font->descent) >> 4)*_scale ));
+ return (l > 0) ? l : 1;
+}
+
+// #### use Freetype to determine this
+int TQFontEngineXft::lineThickness() const
+{
+ // ad hoc algorithm
+ int score = fontDef.weight * fontDef.pixelSize;
+ int lw = score / 700;
+
+ // looks better with thicker line for small pointsizes
+ if ( lw < 2 && score >= 1050 ) lw = 2;
+ if ( lw == 0 ) lw = 1;
+
+ return lw;
+}
+
+// #### use Freetype to determine this
+int TQFontEngineXft::underlinePosition() const
+{
+ int pos = ( ( lineThickness() * 2 ) + 3 ) / 6;
+ return pos ? pos : 1;
+}
+
+int TQFontEngineXft::maxCharWidth() const
+{
+ return tqRound(_font->max_advance_width*_scale);
+}
+
+static const ushort char_table[] = {
+ 40,
+ 67,
+ 70,
+ 75,
+ 86,
+ 88,
+ 89,
+ 91,
+ 102,
+ 114,
+ 124,
+ 127,
+ 205,
+ 645,
+ 884,
+ 922,
+ 1070,
+ 12386
+};
+
+static const int char_table_entries = sizeof(char_table)/sizeof(ushort);
+
+
+int TQFontEngineXft::minLeftBearing() const
+{
+ if ( lbearing == SHRT_MIN )
+ minRightBearing(); // calculates both
+
+ return lbearing;
+}
+
+int TQFontEngineXft::minRightBearing() const
+{
+ if ( rbearing == SHRT_MIN ) {
+ TQFontEngineXft *that = (TQFontEngineXft *)this;
+ that->lbearing = that->rbearing = 0;
+ TQChar *ch = (TQChar *)char_table;
+ glyph_t glyphs[char_table_entries];
+ int ng = char_table_entries;
+ stringToCMap(ch, char_table_entries, glyphs, 0, &ng, FALSE);
+ while (--ng) {
+ if (glyphs[ng]) {
+ glyph_metrics_t gi = that->boundingBox( glyphs[ng] );
+ if (gi.xoff) {
+ that->lbearing = TQMIN(lbearing, gi.x);
+ that->rbearing = TQMIN(rbearing, gi.xoff - gi.x - gi.width);
+ }
+ }
+ }
+ }
+
+ return rbearing;
+}
+
+int TQFontEngineXft::cmap() const
+{
+ return _cmap;
+}
+
+const char *TQFontEngineXft::name() const
+{
+ return "xft";
+}
+
+void TQFontEngineXft::setScale( double scale )
+{
+ _scale = scale;
+}
+
+bool TQFontEngineXft::canRender( const TQChar *string, int len )
+{
+ bool allExist = TRUE;
+
+#ifdef TQT_XFT2
+ if (_cmap != -1) {
+ for ( int i = 0; i < len; i++ ) {
+ if (!XftCharExists(0, _font, string[i].tqunicode())
+ && getAdobeCharIndex(_font, _cmap, string[i].tqunicode()) == 0) {
+ allExist = FALSE;
+ break;
+ }
+ }
+ } else {
+ for ( int i = 0; i < len; i++ ) {
+ if (!XftCharExists(0, _font, string[i].tqunicode())) {
+ allExist = FALSE;
+ break;
+ }
+ }
+ }
+#else
+ glyph_t glyphs[256];
+ int nglyphs = 255;
+ glyph_t *g = glyphs;
+ if ( stringToCMap( string, len, g, 0, &nglyphs, FALSE ) == OutOfMemory ) {
+ g = (glyph_t *)malloc( nglyphs*sizeof(glyph_t) );
+ stringToCMap( string, len, g, 0, &nglyphs, FALSE );
+ }
+
+ for ( int i = 0; i < nglyphs; i++ ) {
+ if ( !XftGlyphExists(TQPaintDevice::x11AppDisplay(), _font, g[i]) ) {
+ allExist = FALSE;
+ break;
+ }
+ }
+
+ if ( g != glyphs )
+ free( g );
+#endif // TQT_XFT2
+
+ return allExist;
+}
+
+TQOpenType *TQFontEngineXft::openType() const
+{
+// qDebug("openTypeIface requested!");
+ if ( _openType )
+ return _openType;
+
+ if ( !_face || ! FT_IS_SFNT( _face ) )
+ return 0;
+
+ TQFontEngineXft *that = (TQFontEngineXft *)this;
+ that->_openType = new TQOpenType(that);
+ return _openType;
+}
+
+
+TQFontEngine::Type TQFontEngineXft::type() const
+{
+ return Xft;
+}
+#endif
+
+
+// --------------------------------------------------------------------------------------------------------------------
+// Open type support
+// --------------------------------------------------------------------------------------------------------------------
+
+#ifndef TQT_NO_XFTFREETYPE
+
+#include "tqscriptengine_p.h"
+
+//#define OT_DEBUG
+
+#ifdef OT_DEBUG
+static inline char *tag_to_string(FT_ULong tag)
+{
+ static char string[5];
+ string[0] = (tag >> 24)&0xff;
+ string[1] = (tag >> 16)&0xff;
+ string[2] = (tag >> 8)&0xff;
+ string[3] = tag&0xff;
+ string[4] = 0;
+ return string;
+}
+#endif
+
+#define DefaultLangSys 0xffff
+#define DefaultScript FT_MAKE_TAG('D', 'F', 'L', 'T')
+
+enum {
+ RequiresGsub = 1,
+ RequiresGpos = 2
+};
+
+struct OTScripts {
+ unsigned int tag;
+ int flags;
+};
+
+static const OTScripts ot_scripts [] = {
+// // European Alphabetic Scripts
+// Latin,
+ { FT_MAKE_TAG( 'l', 'a', 't', 'n' ), 0 },
+// Greek,
+ { FT_MAKE_TAG( 'g', 'r', 'e', 'k' ), 0 },
+// Cyrillic,
+ { FT_MAKE_TAG( 'c', 'y', 'r', 'l' ), 0 },
+// Armenian,
+ { FT_MAKE_TAG( 'a', 'r', 'm', 'n' ), 0 },
+// Georgian,
+ { FT_MAKE_TAG( 'g', 'e', 'o', 'r' ), 0 },
+// Runic,
+ { FT_MAKE_TAG( 'r', 'u', 'n', 'r' ), 0 },
+// Ogham,
+ { FT_MAKE_TAG( 'o', 'g', 'a', 'm' ), 0 },
+// SpacingModifiers,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// CombiningMarks,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+
+// // Middle Eastern Scripts
+// Hebrew,
+ { FT_MAKE_TAG( 'h', 'e', 'b', 'r' ), 1 },
+// Arabic,
+ { FT_MAKE_TAG( 'a', 'r', 'a', 'b' ), 1 },
+// Syriac,
+ { FT_MAKE_TAG( 's', 'y', 'r', 'c' ), 1 },
+// Thaana,
+ { FT_MAKE_TAG( 't', 'h', 'a', 'a' ), 1 },
+
+// // South and Southeast Asian Scripts
+// Devanagari,
+ { FT_MAKE_TAG( 'd', 'e', 'v', 'a' ), 1 },
+// Bengali,
+ { FT_MAKE_TAG( 'b', 'e', 'n', 'g' ), 1 },
+// Gurmukhi,
+ { FT_MAKE_TAG( 'g', 'u', 'r', 'u' ), 1 },
+// Gujarati,
+ { FT_MAKE_TAG( 'g', 'u', 'j', 'r' ), 1 },
+// Oriya,
+ { FT_MAKE_TAG( 'o', 'r', 'y', 'a' ), 1 },
+// Tamil,
+ { FT_MAKE_TAG( 't', 'a', 'm', 'l' ), 1 },
+// Telugu,
+ { FT_MAKE_TAG( 't', 'e', 'l', 'u' ), 1 },
+// Kannada,
+ { FT_MAKE_TAG( 'k', 'n', 'd', 'a' ), 1 },
+// Malayalam,
+ { FT_MAKE_TAG( 'm', 'l', 'y', 'm' ), 1 },
+// Sinhala,
+ // ### could not tqfind any OT specs on this
+ { FT_MAKE_TAG( 's', 'i', 'n', 'h' ), 1 },
+// Thai,
+ { FT_MAKE_TAG( 't', 'h', 'a', 'i' ), 1 },
+// Lao,
+ { FT_MAKE_TAG( 'l', 'a', 'o', ' ' ), 1 },
+// Tibetan,
+ { FT_MAKE_TAG( 't', 'i', 'b', 't' ), 1 },
+// Myanmar,
+ { FT_MAKE_TAG( 'm', 'y', 'm', 'r' ), 1 },
+// Khmer,
+ { FT_MAKE_TAG( 'k', 'h', 'm', 'r' ), 1 },
+
+// // East Asian Scripts
+// Han,
+ { FT_MAKE_TAG( 'h', 'a', 'n', 'i' ), 0 },
+// Hiragana,
+ { FT_MAKE_TAG( 'k', 'a', 'n', 'a' ), 0 },
+// Katakana,
+ { FT_MAKE_TAG( 'k', 'a', 'n', 'a' ), 0 },
+// Hangul,
+ { FT_MAKE_TAG( 'h', 'a', 'n', 'g' ), 1 },
+// Bopomofo,
+ { FT_MAKE_TAG( 'b', 'o', 'p', 'o' ), 0 },
+// Yi,
+ { FT_MAKE_TAG( 'y', 'i', ' ', ' ' ), 0 },
+
+// // Additional Scripts
+// Ethiopic,
+ { FT_MAKE_TAG( 'e', 't', 'h', 'i' ), 0 },
+// Cherokee,
+ { FT_MAKE_TAG( 'c', 'h', 'e', 'r' ), 0 },
+// CanadianAboriginal,
+ { FT_MAKE_TAG( 'c', 'a', 'n', 's' ), 0 },
+// Mongolian,
+ { FT_MAKE_TAG( 'm', 'o', 'n', 'g' ), 0 },
+// // Symbols
+// CurrencySymbols,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// LetterlikeSymbols,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// NumberForms,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// MathematicalOperators,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// TechnicalSymbols,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// GeometricSymbols,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// MiscellaneousSymbols,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// EnclosedAndSquare,
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+// Braille,
+ { FT_MAKE_TAG( 'b', 'r', 'a', 'i' ), 0 },
+// Unicode, should be used
+ { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }
+ // ### where are these?
+// { FT_MAKE_TAG( 'b', 'y', 'z', 'm' ), 0 },
+// { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 },
+ // ### Hangul Jamo
+// { FT_MAKE_TAG( 'j', 'a', 'm', 'o' ), 0 },
+};
+
+TQOpenType::TQOpenType(TQFontEngineXft *fe)
+ : fontEngine(fe), gdef(0), gsub(0), gpos(0), current_script(0)
+{
+ face = fe->face();
+ otl_buffer_new(face->memory, &otl_buffer);
+ tmpAttributes = 0;
+ tmpLogClusters = 0;
+
+ FT_Error error;
+ if ((error = TT_Load_GDEF_Table(face, &gdef))) {
+#ifdef OT_DEBUG
+ qDebug("error loading gdef table: %d", error);
+#endif
+ gdef = 0;
+ }
+
+ if ((error = TT_Load_GSUB_Table(face, &gsub, gdef))) {
+ gsub = 0;
+#ifdef OT_DEBUG
+ if (error != FT_Err_Table_Missing) {
+ qDebug("error loading gsub table: %d", error);
+ } else {
+ qDebug("face doesn't have a gsub table");
+ }
+#endif
+ }
+
+ if ((error = TT_Load_GPOS_Table(face, &gpos, gdef))) {
+ gpos = 0;
+#ifdef OT_DEBUG
+ qDebug("error loading gpos table: %d", error);
+#endif
+ }
+
+ for (uint i = 0; i < TQFont::NScripts; ++i)
+ supported_scripts[i] = checkScript(i);
+}
+
+TQOpenType::~TQOpenType()
+{
+ if (gpos)
+ TT_Done_GPOS_Table(gpos);
+ if (gsub)
+ TT_Done_GSUB_Table(gsub);
+ if (gdef)
+ TT_Done_GDEF_Table(gdef);
+ if (otl_buffer)
+ otl_buffer_free(otl_buffer);
+ if (tmpAttributes)
+ free(tmpAttributes);
+ if (tmpLogClusters)
+ free(tmpLogClusters);
+}
+
+bool TQOpenType::checkScript(unsigned int script)
+{
+ assert(script < TQFont::NScripts);
+
+ uint tag = ot_scripts[script].tag;
+ int requirements = ot_scripts[script].flags;
+
+ if (requirements & RequiresGsub) {
+ if (!gsub)
+ return FALSE;
+
+ FT_UShort script_index;
+ FT_Error error = TT_GSUB_Select_Script(gsub, tag, &script_index);
+ if (error) {
+#ifdef OT_DEBUG
+ qDebug("could not select script %d in GSub table: %d", (int)script, error);
+#endif
+ return FALSE;
+ }
+ }
+
+ if (requirements & RequiresGpos) {
+ if (!gpos)
+ return FALSE;
+
+ FT_UShort script_index;
+ FT_Error error = TT_GPOS_Select_Script(gpos, script, &script_index);
+ if (error) {
+#ifdef OT_DEBUG
+ qDebug("could not select script in gpos table: %d", error);
+#endif
+ return FALSE;
+ }
+
+ }
+ return TRUE;
+}
+
+
+void TQOpenType::selectScript(unsigned int script, const Features *features)
+{
+ if (current_script == script)
+ return;
+
+ assert(script < TQFont::NScripts);
+ // tqfind script in our list of supported scripts.
+ uint tag = ot_scripts[script].tag;
+
+ if (gsub && features) {
+#ifdef OT_DEBUG
+ {
+ TTO_FeatureList featurelist = gsub->FeatureList;
+ int numfeatures = featurelist.FeatureCount;
+ qDebug("gsub table has %d features", numfeatures);
+ for(int i = 0; i < numfeatures; i++) {
+ TTO_FeatureRecord *r = featurelist.FeatureRecord + i;
+ qDebug(" feature '%s'", tag_to_string(r->FeatureTag));
+ }
+ }
+#endif
+ TT_GSUB_Clear_Features(gsub);
+ FT_UShort script_index;
+ FT_Error error = TT_GSUB_Select_Script(gsub, tag, &script_index);
+ if (!error) {
+#ifdef OT_DEBUG
+ qDebug("script %s has script index %d", tag_to_string(script), script_index);
+#endif
+ while (features->tag) {
+ FT_UShort feature_index;
+ error = TT_GSUB_Select_Feature(gsub, features->tag, script_index, 0xffff, &feature_index);
+ if (!error) {
+#ifdef OT_DEBUG
+ qDebug(" adding feature %s", tag_to_string(features->tag));
+#endif
+ TT_GSUB_Add_Feature(gsub, feature_index, features->property);
+ }
+ ++features;
+ }
+ }
+ }
+
+ if (gpos) {
+ TT_GPOS_Clear_Features(gpos);
+ FT_UShort script_index;
+ FT_Error error = TT_GPOS_Select_Script(gpos, tag, &script_index);
+ if (!error) {
+#ifdef OT_DEBUG
+ {
+ TTO_FeatureList featurelist = gpos->FeatureList;
+ int numfeatures = featurelist.FeatureCount;
+ qDebug("gpos table has %d features", numfeatures);
+ for(int i = 0; i < numfeatures; i++) {
+ TTO_FeatureRecord *r = featurelist.FeatureRecord + i;
+ FT_UShort feature_index;
+ TT_GPOS_Select_Feature(gpos, r->FeatureTag, script_index, 0xffff, &feature_index);
+ qDebug(" feature '%s'", tag_to_string(r->FeatureTag));
+ }
+ }
+#endif
+ FT_ULong *feature_tag_list;
+ error = TT_GPOS_Query_Features(gpos, script_index, 0xffff, &feature_tag_list);
+ if (!error) {
+ while (*feature_tag_list) {
+ FT_UShort feature_index;
+ error = TT_GPOS_Select_Feature(gpos, *feature_tag_list, script_index, 0xffff, &feature_index);
+ if (!error)
+ TT_GPOS_Add_Feature(gpos, feature_index, PositioningProperties);
+ ++feature_tag_list;
+ }
+ }
+ }
+ }
+
+ current_script = script;
+}
+
+#ifdef OT_DEBUG
+static void dump_string(OTL_Buffer buffer)
+{
+ for (uint i = 0; i < buffer->in_length; ++i) {
+ qDebug(" %x: cluster=%d", buffer->in_string[i].gindex, buffer->in_string[i].cluster);
+ }
+}
+#endif
+
+extern void qt_heuristicPosition(TQShaperItem *item);
+
+bool TQOpenType::tqshape(TQShaperItem *item, const unsigned int *properties)
+{
+ length = item->num_glyphs;
+
+ otl_buffer_clear(otl_buffer);
+
+ tmpAttributes = (GlyphAttributes *) realloc(tmpAttributes, length*sizeof(GlyphAttributes));
+ tmpLogClusters = (unsigned int *) realloc(tmpLogClusters, length*sizeof(unsigned int));
+ for (int i = 0; i < length; ++i) {
+ otl_buffer_add_glyph(otl_buffer, item->glyphs[i], properties ? properties[i] : 0, i);
+ tmpAttributes[i] = item->attributes[i];
+ tmpLogClusters[i] = item->log_clusters[i];
+ }
+
+#ifdef OT_DEBUG
+ qDebug("-----------------------------------------");
+// qDebug("log clusters before shaping:");
+// for (int j = 0; j < length; j++)
+// qDebug(" log[%d] = %d", j, item->log_clusters[j]);
+ qDebug("original glyphs: %p", item->glyphs);
+ for (int i = 0; i < length; ++i)
+ qDebug(" glyph=%4x", otl_buffer->in_string[i].gindex);
+// dump_string(otl_buffer);
+#endif
+
+ loadFlags = FT_LOAD_DEFAULT;
+
+ if (gsub) {
+ uint error = TT_GSUB_Apply_String(gsub, otl_buffer);
+ if (error && error != TTO_Err_Not_Covered)
+ return false;
+ }
+
+#ifdef OT_DEBUG
+// qDebug("log clusters before shaping:");
+// for (int j = 0; j < length; j++)
+// qDebug(" log[%d] = %d", j, item->log_clusters[j]);
+ qDebug("tqshaped glyphs:");
+ for (int i = 0; i < length; ++i)
+ qDebug(" glyph=%4x", otl_buffer->in_string[i].gindex);
+ qDebug("-----------------------------------------");
+// dump_string(otl_buffer);
+#endif
+
+ return true;
+}
+
+bool TQOpenType::positionAndAdd(TQShaperItem *item, bool doLogClusters)
+{
+ if (gpos) {
+#ifdef TQ_WS_X11
+ TQ_ASSERT(fontEngine->type() == TQFontEngine::Xft);
+ face = lockFTFace(static_cast<TQFontEngineXft *>(fontEngine)->font());
+#endif
+ memset(otl_buffer->positions, 0, otl_buffer->in_length*sizeof(OTL_PositionRec));
+ // #### check that passing "FALSE,FALSE" is correct
+ TT_GPOS_Apply_String(face, gpos, loadFlags, otl_buffer, FALSE, FALSE);
+#ifdef TQ_WS_X11
+ unlockFTFace(static_cast<TQFontEngineXft *>(fontEngine)->font());
+#endif
+ }
+
+ // make sure we have enough space to write everything back
+ if (item->num_glyphs < (int)otl_buffer->in_length) {
+ item->num_glyphs = otl_buffer->in_length;
+ return FALSE;
+ }
+
+ for (unsigned int i = 0; i < otl_buffer->in_length; ++i) {
+ item->glyphs[i] = otl_buffer->in_string[i].gindex;
+ item->attributes[i] = tmpAttributes[otl_buffer->in_string[i].cluster];
+ if (i && otl_buffer->in_string[i].cluster == otl_buffer->in_string[i-1].cluster)
+ item->attributes[i].clusterStart = FALSE;
+ }
+ item->num_glyphs = otl_buffer->in_length;
+
+ if (doLogClusters) {
+ // we can't do this for indic, as we pass the stuf in syllables and it's easier to do it in the tqshaper.
+ unsigned short *logClusters = item->log_clusters;
+ int clusterStart = 0;
+ int oldCi = 0;
+ for (unsigned int i = 0; i < otl_buffer->in_length; ++i) {
+ int ci = otl_buffer->in_string[i].cluster;
+ // qDebug(" ci[%d] = %d mark=%d, cmb=%d, cs=%d",
+ // i, ci, glyphAttributes[i].mark, glyphAttributes[i].combiningClass, glyphAttributes[i].clusterStart);
+ if (!item->attributes[i].mark && item->attributes[i].clusterStart && ci != oldCi) {
+ for (int j = oldCi; j < ci; j++)
+ logClusters[j] = clusterStart;
+ clusterStart = i;
+ oldCi = ci;
+ }
+ }
+ for (int j = oldCi; j < length; j++)
+ logClusters[j] = clusterStart;
+ }
+
+ // calulate the advances for the tqshaped glyphs
+// qDebug("unpositioned: ");
+ static_cast<TQFontEngineXft *>(item->font)->recalcAdvances(item->num_glyphs, item->glyphs, item->advances);
+
+ // positioning code:
+ if (gpos) {
+ float scale = item->font->scale();
+ OTL_Position positions = otl_buffer->positions;
+
+// qDebug("positioned glyphs:");
+ for (unsigned int i = 0; i < otl_buffer->in_length; i++) {
+// qDebug(" %d:\t orig advance: (%d/%d)\tadv=(%d/%d)\tpos=(%d/%d)\tback=%d\tnew_advance=%d", i,
+// glyphs[i].advance.x.toInt(), glyphs[i].advance.y.toInt(),
+// (int)(positions[i].x_advance >> 6), (int)(positions[i].y_advance >> 6),
+// (int)(positions[i].x_pos >> 6), (int)(positions[i].y_pos >> 6),
+// positions[i].back, positions[i].new_advance);
+ // ###### fix the case where we have y advances. How do we handle this in Uniscribe?????
+ if (positions[i].new_advance) {
+ item->advances[i] = item->flags & TQTextEngine::RightToLeft
+ ? -tqRound((positions[i].x_advance >> 6)*scale)
+ : tqRound((positions[i].x_advance >> 6)*scale);
+ } else {
+ item->advances[i] += item->flags & TQTextEngine::RightToLeft
+ ? -tqRound((positions[i].x_advance >> 6)*scale)
+ : tqRound((positions[i].x_advance >> 6)*scale);
+ }
+ int back = 0;
+ item->offsets[i].x = tqRound((positions[i].x_pos >> 6)*scale);
+ item->offsets[i].y = tqRound((positions[i].y_pos >> 6)*scale);
+ while (positions[i-back].back) {
+ back += positions[i - back].back;
+ item->offsets[i].x += tqRound((positions[i - back].x_pos >> 6)*scale);
+ item->offsets[i].y += tqRound((positions[i - back].y_pos >> 6)*scale);
+ }
+ item->offsets[i].y = -item->offsets[i].y;
+ back = positions[i].back;
+ if (item->flags & TQTextEngine::RightToLeft) {
+ while (back--) {
+ item->offsets[i].x -= item->advances[i-back];
+ }
+ } else {
+ while (back) {
+ item->offsets[i].x -= item->advances[i-back];
+ --back;
+ }
+ }
+// qDebug(" ->\tadv=%d\tpos=(%d/%d)",
+// glyphs[i].advance.x.toInt(), glyphs[i].offset.x.toInt(), glyphs[i].offset.y.toInt());
+ }
+ item->has_positioning = TRUE;
+ } else {
+ qt_heuristicPosition(item);
+ }
+
+#ifdef OT_DEBUG
+// if (doLogClusters) {
+// qDebug("log clusters after shaping:");
+// for (int j = 0; j < length; j++)
+// qDebug(" log[%d] = %d", j, item->log_clusters[j]);
+// }
+ qDebug("final glyphs:");
+ for (int i = 0; i < (int)otl_buffer->in_length; ++i)
+ qDebug(" glyph=%4x char_index=%d mark: %d cmp: %d, clusterStart: %d advance=%d offset=%d/%d",
+ item->glyphs[i], otl_buffer->in_string[i].cluster, item->attributes[i].mark,
+ item->attributes[i].combiningClass, item->attributes[i].clusterStart,
+ item->advances[i],
+ item->offsets[i].x, item->offsets[i].y);
+ qDebug("-----------------------------------------");
+#endif
+ return TRUE;
+}
+
+#endif
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqfontinfo.h b/tqtinterface/qt4/src/kernel/tqfontinfo.h
new file mode 100644
index 0000000..916169e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontinfo.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Definition of TQFontInfo class
+**
+** Created : 950131
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQFONTINFO_H
+#define TQFONTINFO_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqfont.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qfontinfo.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQFontInfo : public QFontInfo, virtual public TQt
+{
+public:
+ TQFontInfo( const TQFont &fn ) : QFontInfo ( fn ) {}
+ TQFontInfo( const TQFont &fn, TQFont::Script sc ) : QFontInfo ( fn ) { TQ_UNUSED(sc); }
+ TQFontInfo( const TQFontInfo &fi ) : QFontInfo ( fi ) {}
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQFontInfo
+{
+public:
+ TQFontInfo( const TQFont & );
+ TQFontInfo( const TQFont &, TQFont::Script );
+ TQFontInfo( const TQFontInfo & );
+ ~TQFontInfo();
+
+ TQFontInfo &operator=( const TQFontInfo & );
+
+ TQString family() const;
+ int pixelSize() const;
+ int pointSize() const;
+ bool italic() const;
+ int weight() const;
+ bool bold() const;
+ bool underline() const;
+ bool overline() const;
+ bool strikeOut() const;
+ bool fixedPitch() const;
+ TQFont::StyleHint tqstyleHint() const;
+ bool rawMode() const;
+
+ bool exactMatch() const;
+
+
+private:
+ TQFontInfo( const TQPainter * );
+
+ TQFontPrivate *d;
+ TQPainter *painter;
+ int fscript;
+
+ friend class TQWidget;
+ friend class TQPainter;
+};
+
+
+inline bool TQFontInfo::bold() const
+{ return weight() > TQFont::Normal; }
+
+#endif // USE_QT4
+
+#endif // TQFONTINFO_H
diff --git a/tqtinterface/qt4/src/kernel/tqfontmetrics.h b/tqtinterface/qt4/src/kernel/tqfontmetrics.h
new file mode 100644
index 0000000..aca4c58
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqfontmetrics.h
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Definition of TQFontMetrics class
+**
+** Created : 940514
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQFONTMETRICS_H
+#define TQFONTMETRICS_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqfont.h"
+#include "tqrect.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qfontmetrics.h>
+
+#endif // USE_QT4
+
+#ifdef TQ_WS_TQWS
+class TQFontEngine;
+#endif
+
+class TQTextCodec;
+class TQTextParag;
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQFontMetrics : public QFontMetrics, virtual public TQt
+{
+public:
+ TQFontMetrics( const QFont &fn ) : QFontMetrics( fn ) {}
+ TQFontMetrics( const QFont &fn, TQFont::Script sc ) : QFontMetrics( fn ) { TQ_UNUSED(sc); }
+ TQFontMetrics( const QFontMetrics &fm ) : QFontMetrics( fm ) {}
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQFontMetrics
+{
+public:
+ TQFontMetrics( const TQFont & );
+ TQFontMetrics( const TQFont &, TQFont::Script );
+ TQFontMetrics( const TQFontMetrics & );
+ ~TQFontMetrics();
+
+ TQFontMetrics &operator=( const TQFontMetrics & );
+
+ int ascent() const;
+ int descent() const;
+ int height() const;
+ int leading() const;
+ int lineSpacing() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+ int maxWidth() const;
+
+ bool inFont(TQChar) const;
+
+ int leftBearing(TQChar) const;
+ int rightBearing(TQChar) const;
+ int width( const TQString &, int len = -1 ) const;
+
+ int width( TQChar ) const;
+#ifndef TQT_NO_COMPAT
+ int width( char c ) const { return width( (TQChar) c ); }
+#endif
+
+ int charWidth( const TQString &str, int pos ) const;
+ TQRect boundingRect( const TQString &, int len = -1 ) const;
+ TQRect boundingRect( TQChar ) const;
+ TQRect boundingRect( int x, int y, int w, int h, int flags,
+ const TQString& str, int len=-1, int tabstops=0,
+ int *tabarray=0, TQTextParag **intern=0 ) const;
+ TQSize size( int flags,
+ const TQString& str, int len=-1, int tabstops=0,
+ int *tabarray=0, TQTextParag **intern=0 ) const;
+
+ int underlinePos() const;
+ int overlinePos() const;
+ int strikeOutPos() const;
+ int lineWidth() const;
+
+private:
+ TQFontMetrics( const TQPainter * );
+
+ friend class TQWidget;
+ friend class TQPainter;
+ friend class TQTextFormat;
+#if defined( TQ_WS_MAC )
+ friend class TQFontPrivate;
+#endif
+
+ TQFontPrivate *d;
+ TQPainter *painter;
+ int fscript;
+};
+
+#endif // USE_QT4
+
+#endif // TQFONTMETRICS_H
diff --git a/tqtinterface/qt4/src/kernel/tqgif.h b/tqtinterface/qt4/src/kernel/tqgif.h
new file mode 100644
index 0000000..749b637
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqgif.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** To enable built-in reading of GIF images in TQt, change the definition
+** below to "#define TQT_BUILTIN_GIF_READER 1".
+**
+** To disable built-in reading of GIF images in TQt, change the definition
+** below to "#define TQT_BUILTIN_GIF_READER 0".
+**
+** WARNING:
+** A separate license from Unisys may be required to use the gif
+** reader. See http://www.unisys.com/about__unisys/lzw/
+** for information from Unisys
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQGIF_H
+#define TQGIF_H
+
+#ifndef TQT_H
+#include "tqglobal.h"
+#endif // TQT_H
+
+#ifndef TQT_BUILTIN_GIF_READER
+#define TQT_BUILTIN_GIF_READER 0
+#endif
+
+bool qt_builtin_gif_reader();
+
+#endif // TQGIF_H
diff --git a/tqtinterface/qt4/src/kernel/tqgplugin.cpp b/tqtinterface/qt4/src/kernel/tqgplugin.cpp
new file mode 100644
index 0000000..848e6c7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqgplugin.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** ...
+**
+** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqgplugin.h"
+
+#ifndef TQT_NO_COMPONENT
+
+#include <private/tqcom_p.h>
+
+TQGPlugin::TQGPlugin()
+ : _iface( 0 )
+{
+}
+
+TQGPlugin::TQGPlugin( TQUnknownInterface *i )
+ : _iface( i )
+{
+}
+
+TQGPlugin::~TQGPlugin()
+{
+}
+
+TQUnknownInterface* TQGPlugin::iface()
+{
+ TQ_ASSERT( _iface );
+ TQUnknownInterface *i;
+ _iface->queryInterface( IID_TQUnknown, &i );
+ return i;
+}
+
+void TQGPlugin::setIface( TQUnknownInterface *iface )
+{
+ _iface = iface;
+}
+
+#endif // TQT_NO_COMPONENT
diff --git a/tqtinterface/qt4/src/kernel/tqgplugin.h b/tqtinterface/qt4/src/kernel/tqgplugin.h
new file mode 100644
index 0000000..f892d77
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqgplugin.h
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** ...
+**
+** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQGPLUGIN_H
+#define TQGPLUGIN_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of a number of TQt sources files. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_COMPONENT
+
+#ifndef TQ_EXTERN_C
+#ifdef __cplusplus
+#define TQ_EXTERN_C extern "C"
+#else
+#define TQ_EXTERN_C extern
+#endif
+#endif
+
+#ifndef TQ_EXPORT_PLUGIN
+#if defined(TQT_THREAD_SUPPORT)
+#define TQT_THREADED_BUILD 1
+#define TQ_PLUGIN_FLAGS_STRING "11"
+#else
+#define TQT_THREADED_BUILD 0
+#define TQ_PLUGIN_FLAGS_STRING "01"
+#endif
+
+// this is duplicated at TQ_UCM_VERIFICATION_DATA in qcom_p.h
+// NOTE: if you change pattern, you MUST change the pattern in
+// qcomlibrary.cpp as well. changing the pattern will break all
+// backwards compatibility as well (no old plugins will be loaded).
+#ifndef TQ_PLUGIN_VERIFICATION_DATA
+# define TQ_PLUGIN_VERIFICATION_DATA \
+ static const char *qt_ucm_verification_data = \
+ "pattern=""TQT_UCM_VERIFICATION_DATA""\n" \
+ "version="TQT_VERSION_STR"\n" \
+ "flags="TQ_PLUGIN_FLAGS_STRING"\n" \
+ "buildkey="TQT_BUILD_KEY"\0";
+#endif // TQ_PLUGIN_VERIFICATION_DATA
+
+#define TQ_PLUGIN_INSTANTIATE( IMPLEMENTATION ) \
+ { \
+ IMPLEMENTATION *i = new IMPLEMENTATION; \
+ return i->iface(); \
+ }
+
+# ifdef TQ_WS_WIN
+# ifdef TQ_CC_BOR
+# define TQ_EXPORT_PLUGIN(PLUGIN) \
+ TQ_PLUGIN_VERIFICATION_DATA \
+ TQ_EXTERN_C __declspec(dllexport) \
+ const char * __stdcall qt_ucm_query_verification_data() \
+ { return qt_ucm_verification_data; } \
+ TQ_EXTERN_C __declspec(dllexport) TQUnknownInterface* \
+ __stdcall ucm_instantiate() \
+ TQ_PLUGIN_INSTANTIATE( PLUGIN )
+# else
+# define TQ_EXPORT_PLUGIN(PLUGIN) \
+ TQ_PLUGIN_VERIFICATION_DATA \
+ TQ_EXTERN_C __declspec(dllexport) \
+ const char *qt_ucm_query_verification_data() \
+ { return qt_ucm_verification_data; } \
+ TQ_EXTERN_C __declspec(dllexport) TQUnknownInterface* ucm_instantiate() \
+ TQ_PLUGIN_INSTANTIATE( PLUGIN )
+# endif
+# else
+# define TQ_EXPORT_PLUGIN(PLUGIN) \
+ TQ_PLUGIN_VERIFICATION_DATA \
+ TQ_EXTERN_C \
+ const char *qt_ucm_query_verification_data() \
+ { return qt_ucm_verification_data; } \
+ TQ_EXTERN_C TQUnknownInterface* ucm_instantiate() \
+ TQ_PLUGIN_INSTANTIATE( PLUGIN )
+# endif
+
+#endif
+
+struct TQUnknownInterface;
+
+class TQ_EXPORT TQGPlugin : public TQObject
+{
+ TQ_OBJECT
+public:
+ TQGPlugin( TQUnknownInterface *i );
+ ~TQGPlugin();
+
+ TQUnknownInterface* iface();
+ void setIface( TQUnknownInterface *iface );
+
+private:
+ TQGPlugin();
+ TQUnknownInterface* _iface;
+};
+
+#endif // TQT_NO_COMPONENT
+
+#endif // TQGPLUGIN_H
diff --git a/tqtinterface/qt4/src/kernel/tqguardedptr.cpp b/tqtinterface/qt4/src/kernel/tqguardedptr.cpp
new file mode 100644
index 0000000..ca41d8d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqguardedptr.cpp
@@ -0,0 +1,226 @@
+/****************************************************************************
+**
+** Implementation of TQGuardedPtr class
+**
+** Created : 990929
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqguardedptr.h"
+
+/*!
+ \class TQGuardedPtr tqguardedptr.h
+ \brief The TQGuardedPtr class is a template class that provides guarded pointers to TQObjects.
+
+ \ingroup objectmodel
+ \mainclass
+
+ A guarded pointer, \c{TQGuardedPtr<X>}, behaves like a normal C++
+ pointer \c{X*}, except that it is automatically set to 0 when
+ the referenced object is destroyed (unlike normal C++ pointers,
+ which become "dangling pointers" in such cases). \c X must be a
+ subclass of TQObject.
+
+ Guarded pointers are useful whenever you need to store a pointer
+ to a TQObject that is owned by someone else and therefore might be
+ destroyed while you still hold a reference to it. You can safely
+ test the pointer for validity.
+
+ Example:
+ \code
+ TQGuardedPtr<TQLabel> label = new TQLabel( 0, "label" );
+ label->setText( "I like guarded pointers" );
+
+ delete (TQLabel*) label; // simulate somebody destroying the label
+
+ if ( label)
+ label->show();
+ else
+ qDebug("The label has been destroyed");
+ \endcode
+
+ The program will output \c{The label has been destroyed} rather
+ than dereferencing an invalid address in \c label->show().
+
+ The functions and operators available with a TQGuardedPtr are the
+ same as those available with a normal unguarded pointer, except
+ the pointer arithmetic operators (++, --, -, and +), which are
+ normally used only with arrays of objects. Use them like normal
+ pointers and you will not need to read this class documentation.
+
+ For creating guarded pointers, you can construct or assign to them
+ from an X* or from another guarded pointer of the same type. You
+ can compare them with each other using operator==() and
+ operator!=(), or test for 0 with isNull(). And you can dereference
+ them using either the \c *x or the \c x->member notation.
+
+ A guarded pointer will automatically cast to an X*, so you can
+ freely mix guarded and unguarded pointers. This means that if you
+ have a TQGuardedPtr<TQWidget>, you can pass it to a function that
+ requires a TQWidget*. For this reason, it is of little value to
+ declare functions to take a TQGuardedPtr as a parameter; just use
+ normal pointers. Use a TQGuardedPtr when you are storing a pointer
+ over time.
+
+ Note again that class \e X must inherit TQObject, or a compilation
+ or link error will result.
+*/
+
+/*!
+ \fn TQGuardedPtr::TQGuardedPtr()
+
+ Constructs a 0 guarded pointer.
+
+ \sa isNull()
+*/
+
+/*!
+ \fn TQGuardedPtr::TQGuardedPtr( T* p )
+
+ Constructs a guarded pointer that points to same object as \a p
+ points to.
+*/
+
+/*!
+ \fn TQGuardedPtr::TQGuardedPtr(const TQGuardedPtr<T> &p)
+
+ Copy one guarded pointer from another. The constructed guarded
+ pointer points to the same object that \a p points to (which may
+ be 0).
+*/
+
+/*!
+ \fn TQGuardedPtr::~TQGuardedPtr()
+
+ Destroys the guarded pointer. Just like a normal pointer,
+ destroying a guarded pointer does \e not destroy the object being
+ pointed to.
+*/
+
+/*!
+ \fn TQGuardedPtr<T>& TQGuardedPtr::operator=(const TQGuardedPtr<T> &p)
+
+ Assignment operator. This guarded pointer then points to the same
+ object as \a p points to.
+*/
+
+/*!
+ \overload TQGuardedPtr<T> & TQGuardedPtr::operator=(T* p)
+
+ Assignment operator. This guarded pointer then points to the same
+ object as \a p points to.
+*/
+
+/*!
+ \fn bool TQGuardedPtr::operator==( const TQGuardedPtr<T> &p ) const
+
+ Equality operator; implements traditional pointer semantics.
+ Returns TRUE if both \a p and this guarded pointer are 0, or if
+ both \a p and this pointer point to the same object; otherwise
+ returns FALSE.
+
+ \sa operator!=()
+*/
+
+/*!
+ \fn bool TQGuardedPtr::operator!= ( const TQGuardedPtr<T>& p ) const
+
+ Inequality operator; implements pointer semantics, the negation of
+ operator==(). Returns TRUE if \a p and this guarded pointer are
+ not pointing to the same object; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQGuardedPtr::isNull() const
+
+ Returns \c TRUE if the referenced object has been destroyed or if
+ there is no referenced object; otherwise returns FALSE.
+*/
+
+/*!
+ \fn T* TQGuardedPtr::operator->() const
+
+ Overloaded arrow operator; implements pointer semantics. Just use
+ this operator as you would with a normal C++ pointer.
+*/
+
+/*!
+ \fn T& TQGuardedPtr::operator*() const
+
+ Dereference operator; implements pointer semantics. Just use this
+ operator as you would with a normal C++ pointer.
+*/
+
+/*!
+ \fn TQGuardedPtr::operator T*() const
+
+ Cast operator; implements pointer semantics. Because of this
+ function you can pass a TQGuardedPtr\<X\> to a function where an X*
+ is required.
+*/
+
+
+/* Internal classes */
+
+
+TQGuardedPtrPrivate::TQGuardedPtrPrivate( TQObject* o)
+ : TQObject(0, "_ptrpriv" ), obj( o )
+{
+ if ( obj )
+ connect( obj, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( objectDestroyed() ) );
+}
+
+
+TQGuardedPtrPrivate::~TQGuardedPtrPrivate()
+{
+}
+
+void TQGuardedPtrPrivate::reconnect( TQObject *o )
+{
+ if ( obj == o )
+ return;
+ if ( obj )
+ disconnect( obj, TQT_SIGNAL( destroyed() ),
+ this, TQT_SLOT( objectDestroyed() ) );
+ obj = o;
+ if ( obj )
+ connect( obj, TQT_SIGNAL( destroyed() ),
+ this, TQT_SLOT( objectDestroyed() ) );
+}
+
+void TQGuardedPtrPrivate::objectDestroyed()
+{
+ obj = 0;
+}
diff --git a/tqtinterface/qt4/src/kernel/tqguardedptr.h b/tqtinterface/qt4/src/kernel/tqguardedptr.h
new file mode 100644
index 0000000..d786d12
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqguardedptr.h
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Definition of TQGuardedPtr class
+**
+** Created : 990929
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQGUARDEDPTR_H
+#define TQGUARDEDPTR_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+// ### 4.0: rename to something without Private in it. Not really internal.
+class TQ_EXPORT TQGuardedPtrPrivate : public TQObject, public TQShared
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQGuardedPtrPrivate( TQObject* );
+ ~TQGuardedPtrPrivate();
+
+ TQObject* object() const;
+ void reconnect( TQObject* );
+
+private Q_SLOTS:
+ void objectDestroyed();
+
+private:
+ TQObject* obj;
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQGuardedPtrPrivate( const TQGuardedPtrPrivate & );
+ TQGuardedPtrPrivate &operator=( const TQGuardedPtrPrivate & );
+#endif
+};
+
+template <class T>
+class TQGuardedPtr
+{
+public:
+ TQGuardedPtr() : priv( new TQGuardedPtrPrivate( 0 ) ) {}
+
+ TQGuardedPtr( T* o) {
+ priv = new TQGuardedPtrPrivate( (TQObject*)o );
+ }
+
+ TQGuardedPtr(const TQGuardedPtr<T> &p) {
+ priv = p.priv;
+ ref();
+ }
+
+ ~TQGuardedPtr() { deref(); }
+
+ TQGuardedPtr<T> &operator=(const TQGuardedPtr<T> &p) {
+ if ( priv != p.priv ) {
+ deref();
+ priv = p.priv;
+ ref();
+ }
+ return *this;
+ }
+
+ TQGuardedPtr<T> &operator=(T* o) {
+ if ( priv && priv->count == 1 ) {
+ priv->reconnect( (TQObject*)o );
+ } else {
+ deref();
+ priv = new TQGuardedPtrPrivate( (TQObject*)o );
+ }
+ return *this;
+ }
+
+ bool operator==( const TQGuardedPtr<T> &p ) const {
+ return (T*)(*this) == (T*) p;
+ }
+
+ bool operator!= ( const TQGuardedPtr<T>& p ) const {
+ return !( *this == p );
+ }
+
+ bool isNull() const { return !priv || !priv->object(); }
+
+ T* operator->() const { return (T*)(priv?priv->object():0); }
+
+ T& operator*() const { return *((T*)(priv?priv->object():0)); }
+
+ operator T*() const { return (T*)(priv?priv->object():0); }
+
+private:
+
+ void ref() { if (priv) priv->ref(); }
+
+ void deref() {
+ if ( priv && priv->deref() )
+ delete priv;
+ }
+
+ TQGuardedPtrPrivate* priv;
+};
+
+
+
+
+inline TQObject* TQGuardedPtrPrivate::object() const
+{
+ return obj;
+}
+
+#define TQ_DEFINED_TQGUARDEDPTR
+#include "tqwinexport.h"
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqiconset.cpp b/tqtinterface/qt4/src/kernel/tqiconset.cpp
new file mode 100644
index 0000000..e5769f8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqiconset.cpp
@@ -0,0 +1,949 @@
+/****************************************************************************
+**
+** Implementation of TQIconSet class
+**
+** Created : 980318
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqiconset.h"
+
+#ifndef TQT_NO_ICONSET
+
+#include "tqapplication.h"
+#include "tqbitmap.h"
+#include "tqcleanuphandler.h"
+#include "tqimage.h"
+#include "tqpainter.h"
+
+enum { NumSizes = 2, NumModes = 3, NumStates = 2 };
+
+static TQIconFactory *defaultFac = 0;
+static TQSingleCleanupHandler<TQIconFactory> q_cleanup_icon_factory;
+
+static short widths[2] = { 22, 32 };
+static short heights[2] = { 22, 32 };
+
+enum TQIconSetIconOrigin {
+ SuppliedFileName, // 'fileName' tqcontains the name of the file
+ SuppliedPixmap, // 'pixmap' is a pointer to the user-supplied pixmap
+ Manufactured, // 'pixmap' is a factory-generated pixmap (or 0)
+ Generated // 'pixmap' is a TQIconSet-generated pixmap (or 0)
+};
+
+struct TQIconSetIcon
+{
+ TQIconSetIconOrigin origin;
+ union {
+ TQString *fileName;
+ TQPixmap *pixmap;
+ };
+
+ TQIconSetIcon() : origin( Generated ) { pixmap = 0; }
+ TQIconSetIcon( const TQIconSetIcon& other )
+ : origin( Generated ) {
+ pixmap = 0;
+ operator=( other );
+ }
+ ~TQIconSetIcon() {
+ if ( origin == SuppliedFileName ) {
+ delete fileName;
+ } else {
+ delete pixmap;
+ }
+ }
+
+ TQIconSetIcon& operator=( const TQIconSetIcon& other );
+
+ void clearCached() {
+ if ( pixmap && (origin == Manufactured || origin == Generated) ) {
+ origin = Generated;
+ delete pixmap;
+ pixmap = 0;
+ }
+ }
+};
+
+TQIconSetIcon& TQIconSetIcon::operator=( const TQIconSetIcon& other )
+{
+ TQPixmap *oldPixmap = 0;
+ TQString *oldFileName = 0;
+ if ( origin == SuppliedFileName ) {
+ oldFileName = fileName;
+ } else {
+ oldPixmap = pixmap;
+ }
+
+ origin = other.origin;
+ if ( other.origin == SuppliedFileName ) {
+ fileName = new TQString( *other.fileName );
+ } else {
+ if ( other.pixmap ) {
+ pixmap = new TQPixmap( *other.pixmap );
+ } else {
+ pixmap = 0;
+ }
+ }
+ delete oldPixmap;
+ delete oldFileName;
+ return *this;
+}
+
+class TQIconSetPrivate : public TQShared
+{
+public:
+ TQIconSetIcon icons[NumSizes][NumModes][NumStates];
+ TQPixmap defaultPix;
+ TQIconFactory *factory;
+
+ TQIconSetPrivate() : factory( 0 ) { }
+ TQIconSetPrivate( const TQIconSetPrivate& other ) : TQShared() {
+ count = 1;
+ for ( int i = 0; i < NumSizes; i++ ) {
+ for ( int j = 0; j < NumModes; j++ ) {
+ for ( int k = 0; k < NumStates; k++ ) {
+ icons[i][j][k] = other.icons[i][j][k];
+ }
+ }
+ }
+ defaultPix = other.defaultPix;
+ factory = other.factory;
+ if ( factory )
+ factory->ref();
+ }
+ ~TQIconSetPrivate() {
+ setFactory( 0 );
+ }
+
+ TQIconSetIcon *icon( const TQIconSet *iconSet, TQIconSet::Size size,
+ TQIconSet::Mode mode, TQIconSet::State state );
+ void setFactory( TQIconFactory *newFactory ) {
+ if ( newFactory )
+ newFactory->ref();
+ if ( factory && factory->deref() && factory->autoDelete() )
+ delete factory;
+ factory = newFactory;
+ }
+
+ TQ_DUMMY_COMPARISON_OPERATOR( TQIconSetPrivate )
+};
+
+TQIconSetIcon *TQIconSetPrivate::icon( const TQIconSet *iconSet,
+ TQIconSet::Size size, TQIconSet::Mode mode,
+ TQIconSet::State state )
+{
+ TQIconSetIcon *ik = &icons[(int) size - 1][(int) mode][(int) state];
+
+ if ( iconSet ) {
+ if ( ik->origin == SuppliedFileName ) {
+ TQPixmap *newPixmap = new TQPixmap( *ik->fileName );
+ delete ik->fileName;
+
+ if ( newPixmap->isNull() ) {
+ delete newPixmap;
+ ik->origin = Generated;
+ ik->pixmap = 0;
+ } else {
+ ik->origin = SuppliedPixmap;
+ ik->pixmap = newPixmap;
+ }
+ }
+
+ if ( !ik->pixmap && ik->origin == Generated ) {
+ TQIconFactory *f = factory;
+ if ( !f )
+ f = defaultFac;
+
+ if ( f ) {
+ /*
+ We set 'origin' to Manufactured half a second too
+ early to prevent recursive calls to this function.
+ (This can happen if createPixmap() calls
+ TQIconSet::pixmap(), which in turn calls this
+ function.)
+ */
+ ik->origin = Manufactured;
+ ik->pixmap = f->createPixmap( *iconSet, size, mode, state );
+ if ( !ik->pixmap )
+ ik->origin = Generated;
+ }
+ }
+ }
+ return ik;
+}
+
+/*! \class TQIconSet
+
+ \brief The TQIconSet class provides a set of icons with different
+ styles and sizes.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+ \mainclass
+
+ A TQIconSet can generate smaller, larger, active, and disabled pixmaps
+ from the set of icons it is given. Such pixmaps are used by
+ TQToolButton, TQHeader, TQPopupMenu, etc. to show an icon representing a
+ particular action.
+
+ The simplest use of TQIconSet is to create one from a TQPixmap and then
+ use it, allowing TQt to work out all the required icon styles and
+ sizes. For example:
+
+ \code
+ TQToolButton *but = new TQToolButton( TQIconSet( TQPixmap("open.xpm") ), ... );
+ \endcode
+
+ Using whichever pixmaps you specify as a base, TQIconSet provides a
+ set of six icons, each with a \l Size and a \l Mode: Small Normal,
+ Small Disabled, Small Active, Large Normal, Large Disabled, and
+ Large Active.
+
+ An additional set of six icons can be provided for widgets that have
+ an "On" or "Off" state, like checkable menu items or toggleable
+ toolbuttons. If you provide pixmaps for the "On" state, but not for
+ the "Off" state, the TQIconSet will provide the "Off" pixmaps. You may
+ specify icons for both states in you wish.
+
+ You can set any of the icons using setPixmap().
+
+ When you retrieve a pixmap using pixmap(Size, Mode, State),
+ TQIconSet will return the icon that has been set or previously
+ generated for that size, mode and state combination. If none is
+ available, TQIconSet will ask the icon factory. If the icon factory
+ cannot provide any (the default), TQIconSet generates a pixmap based
+ on the pixmaps it has been given and returns it.
+
+ The \c Disabled appearance is computed using an algorithm that
+ produces results very similar to those used in Microsoft Windows
+ 95. The \c Active appearance is identical to the \c Normal
+ appearance unless you use setPixmap() to set it to something
+ special.
+
+ When scaling icons, TQIconSet uses \link TQImage::smoothScale()
+ smooth scaling\endlink, which can partially blend the color component
+ of pixmaps. If the results look poor, the best solution
+ is to supply pixmaps in both large and small sizes.
+
+ You can use the static function setIconSize() to set the preferred
+ size of the generated large/small icons. The default small size is
+ 22 x 22, while the default large size is 32 x 32. These sizes only
+ affect generated icons.
+
+ The isGenerated() function returns TRUE if an icon was generated by
+ TQIconSet or by a factory; clearGenerated() clears all cached
+ pixmaps.
+
+ \section1 Making Classes that Use TQIconSet
+
+ If you write your own widgets that have an option to set a small
+ pixmap, consider allowing a TQIconSet to be set for that pixmap. The
+ TQt class TQToolButton is an example of such a widget.
+
+ Provide a method to set a TQIconSet, and when you draw the icon, choose
+ whichever icon is appropriate for the current state of your widget.
+ For example:
+ \code
+ void MyWidget::drawIcon( TQPainter* p, TQPoint pos )
+ {
+ p->drawPixmap( pos, icons->pixmap(
+ TQIconSet::Small,
+ isEnabled() ? TQIconSet::Normal :
+ TQIconSet::Disabled,
+ isEnabled() ? TQIconSet::On :
+ TQIconSet::Off));
+ }
+ \endcode
+
+ You might also make use of the \c Active mode, perhaps making your
+ widget \c Active when the mouse is over the widget (see \l
+ TQWidget::enterEvent()), while the mouse is pressed pending the
+ release that will activate the function, or when it is the currently
+ selected item. If the widget can be toggled, the "On" mode might be
+ used to draw a different icon.
+
+ \img iconset.png TQIconSet
+
+ \sa TQIconFactory TQPixmap TQMainWindow::setUsesBigPixmaps()
+ \link guibooks.html#fowler GUI Design Handbook: Iconic Label \endlink
+*/
+
+
+/*!
+ \enum TQIconSet::Size
+
+ This enum type describes the size at which a pixmap is intended to be
+ used.
+ The currently defined sizes are:
+
+ \value Automatic The size of the pixmap is determined from its
+ pixel size. This is a useful default.
+ \value Small The pixmap is the smaller of two.
+ \value Large The pixmap is the larger of two.
+
+ If a Small pixmap is not set by TQIconSet::setPixmap(), the Large
+ pixmap will be automatically scaled down to the size of a small pixmap
+ to generate the Small pixmap when required. Similarly, a Small pixmap
+ will be automatically scaled up to generate a Large pixmap. The
+ preferred sizes for large/small generated icons can be set using
+ setIconSize().
+
+ \sa setIconSize() iconSize() setPixmap() pixmap() TQMainWindow::setUsesBigPixmaps()
+*/
+
+/*!
+ \enum TQIconSet::Mode
+
+ This enum type describes the mode for which a pixmap is intended to be
+ used.
+ The currently defined modes are:
+
+ \value Normal
+ Display the pixmap when the user is
+ not interacting with the icon, but the
+ functionality represented by the icon is available.
+ \value Disabled
+ Display the pixmap when the
+ functionality represented by the icon is not available.
+ \value Active
+ Display the pixmap when the
+ functionality represented by the icon is available and
+ the user is interacting with the icon, for example, moving the
+ mouse over it or clicking it.
+*/
+
+/*!
+ \enum TQIconSet::State
+
+ This enum describes the state for which a pixmap is intended to be
+ used. The \e state can be:
+
+ \value Off Display the pixmap when the widget is in an "off" state
+ \value On Display the pixmap when the widget is in an "on" state
+
+ \sa setPixmap() pixmap()
+*/
+
+/*!
+ Constructs a null icon set.
+
+ \sa setPixmap(), reset()
+*/
+TQIconSet::TQIconSet()
+ : d( 0 )
+{
+}
+
+/*!
+ Constructs an icon set for which the Normal pixmap is \a pixmap,
+ which is assumed to be of size \a size.
+
+ The default for \a size is \c Automatic, which means that TQIconSet
+ will determine whether the pixmap is Small or Large from its pixel
+ size. Pixmaps less than the width of a small generated icon are
+ considered to be Small. You can use setIconSize() to set the
+ preferred size of a generated icon.
+
+ \sa setIconSize() reset()
+*/
+TQIconSet::TQIconSet( const TQPixmap& pixmap, Size size )
+ : d( 0 )
+{
+ reset( pixmap, size );
+}
+
+/*! Creates an iconset which uses the pixmap \a smallPix for for
+ displaying a small icon, and the pixmap \a largePix for displaying a
+ large icon.
+*/
+TQIconSet::TQIconSet( const TQPixmap& smallPix, const TQPixmap& largePix )
+ : d( 0 )
+{
+ reset( smallPix, Small );
+ reset( largePix, Large );
+}
+
+/*!
+ Constructs a copy of \a other. This is very fast.
+*/
+TQIconSet::TQIconSet( const TQIconSet& other )
+ : d( other.d )
+{
+ if ( d )
+ d->ref();
+}
+
+/*!
+ Destroys the icon set and frees any allocated resources.
+*/
+TQIconSet::~TQIconSet()
+{
+ if ( d && d->deref() )
+ delete d;
+}
+
+/*!
+ Sets this icon set to use pixmap \a pixmap for the Normal pixmap,
+ assuming it to be of size \a size.
+
+ This is equivalent to assigning TQIconSet(\a pixmap, \a size) to this
+ icon set.
+
+ This function does nothing if \a pixmap is a null pixmap.
+*/
+void TQIconSet::reset( const TQPixmap& pixmap, Size size )
+{
+ if ( pixmap.isNull() )
+ return;
+
+ detach();
+ normalize( size, pixmap.size() );
+ setPixmap( pixmap, size, Normal );
+ d->defaultPix = pixmap;
+ d->setFactory( 0 );
+}
+
+/*!
+ Sets this icon set to provide pixmap \a pixmap for size \a size, mode \a
+ mode and state \a state. The icon set may also use \a pixmap for
+ generating other pixmaps if they are not explicitly set.
+
+ The \a size can be one of Automatic, Large or Small. If Automatic is
+ used, TQIconSet will determine if the pixmap is Small or Large from its
+ pixel size.
+
+ Pixmaps less than the width of a small generated icon are
+ considered to be Small. You can use setIconSize() to set the preferred
+ size of a generated icon.
+
+ This function does nothing if \a pixmap is a null pixmap.
+
+ \sa reset()
+*/
+void TQIconSet::setPixmap( const TQPixmap& pixmap, Size size, Mode mode,
+ State state )
+{
+ if ( pixmap.isNull() )
+ return;
+
+ normalize( size, pixmap.size() );
+
+ detach();
+ clearGenerated();
+
+ TQIconSetIcon *icon = d->icon( 0, size, mode, state );
+ if ( icon->origin == SuppliedFileName ) {
+ delete icon->fileName;
+ icon->pixmap = 0;
+ }
+ icon->origin = SuppliedPixmap;
+ if ( icon->pixmap == 0 ) {
+ icon->pixmap = new TQPixmap( pixmap );
+ } else {
+ *icon->pixmap = pixmap;
+ }
+}
+
+/*!
+ \overload
+
+ The pixmap is loaded from \a fileName when it becomes necessary.
+*/
+void TQIconSet::setPixmap( const TQString& fileName, Size size, Mode mode,
+ State state )
+{
+ if ( size == Automatic ) {
+ setPixmap( TQPixmap(fileName), size, mode, state );
+ } else {
+ detach();
+ clearGenerated();
+
+ TQIconSetIcon *icon = d->icon( 0, size, mode, state );
+ if ( icon->origin == SuppliedFileName ) {
+ *icon->fileName = fileName;
+ } else {
+ delete icon->pixmap;
+ icon->fileName = new TQString( fileName );
+ icon->origin = SuppliedFileName;
+ }
+ }
+}
+
+/*!
+ Returns a pixmap with size \a size, mode \a mode and state \a
+ state, generating one if necessary. Generated pixmaps are cached.
+*/
+TQPixmap TQIconSet::pixmap( Size size, Mode mode, State state ) const
+{
+ if ( !d ) {
+ if ( defaultFac ) {
+ TQIconSet *that = (TQIconSet *) this;
+ that->detach();
+ } else {
+ return TQPixmap();
+ }
+ }
+
+ if ( size == Automatic )
+ size = Small;
+
+ TQIconSetIcon *icon = d->icon( this, size, mode, state );
+ if ( icon->pixmap )
+ return *icon->pixmap;
+ if ( icon->origin == Manufactured ) {
+ /*
+ This can only occur during the half a second's time when
+ the icon is being manufactured. If TQIconFactory somehow
+ tries to access the pixmap it's supposed to be creating, it
+ will get a null pixmap.
+ */
+ return TQPixmap();
+ }
+
+ if ( mode == Active )
+ return pixmap( size, Normal, state );
+
+ Size otherSize = ( size == Large ) ? Small : Large;
+ TQIconSetIcon *otherSizeIcon = d->icon( this, otherSize, mode, state );
+
+ if ( state == Off ) {
+ if ( mode == Disabled &&
+ d->icon(this, size, Normal, Off)->origin != Generated ) {
+ icon->pixmap = createDisabled( size, Off );
+ } else if ( otherSizeIcon->origin != Generated ) {
+ icon->pixmap = createScaled( size, otherSizeIcon->pixmap );
+ } else if ( mode == Disabled ) {
+ icon->pixmap = createDisabled( size, Off );
+ } else if ( !d->defaultPix.isNull() ) {
+ icon->pixmap = new TQPixmap( d->defaultPix );
+ } else {
+ /*
+ No icons are available for { TRUE, Normal, Off } and
+ { FALSE, Normal, Off }. Try the other 10 combinaisons,
+ best ones first.
+ */
+ const int N = 10;
+ static const struct {
+ bool sameSize;
+ Mode mode;
+ State state;
+ } tryList[N] = {
+ { TRUE, Active, Off },
+ { TRUE, Normal, On },
+ { TRUE, Active, On },
+ { FALSE, Active, Off },
+ { FALSE, Normal, On },
+ { FALSE, Active, On },
+ { TRUE, Disabled, Off },
+ { TRUE, Disabled, On },
+ { FALSE, Disabled, Off },
+ { FALSE, Disabled, On }
+ };
+
+ for ( int i = 0; i < N; i++ ) {
+ bool sameSize = tryList[i].sameSize;
+ TQIconSetIcon *tryIcon =
+ d->icon( this, sameSize ? size : otherSize,
+ tryList[i].mode, tryList[i].state );
+ if ( tryIcon->origin != Generated ) {
+ if ( sameSize ) {
+ if ( tryIcon->pixmap )
+ icon->pixmap = new TQPixmap( *tryIcon->pixmap );
+ } else {
+ icon->pixmap = createScaled( size, tryIcon->pixmap );
+ }
+ break;
+ }
+ }
+ }
+ } else { /* ( state == On ) */
+ if ( mode == Normal ) {
+ if ( otherSizeIcon->origin != Generated ) {
+ icon->pixmap = createScaled( size, otherSizeIcon->pixmap );
+ } else {
+ icon->pixmap = new TQPixmap( pixmap(size, mode, Off) );
+ }
+ } else { /* ( mode == Disabled ) */
+ TQIconSetIcon *offIcon = d->icon( this, size, mode, Off );
+ TQIconSetIcon *otherSizeOffIcon = d->icon( this, otherSize, mode,
+ Off );
+
+ if ( offIcon->origin != Generated ) {
+ if ( offIcon->pixmap )
+ icon->pixmap = new TQPixmap( *offIcon->pixmap );
+ } else if ( d->icon(this, size, Normal, On)->origin != Generated ) {
+ icon->pixmap = createDisabled( size, On );
+ } else if ( otherSizeIcon->origin != Generated ) {
+ icon->pixmap = createScaled( size, otherSizeIcon->pixmap );
+ } else if ( otherSizeOffIcon->origin != Generated ) {
+ icon->pixmap = createScaled( size, otherSizeOffIcon->pixmap );
+ } else {
+ icon->pixmap = createDisabled( size, On );
+ }
+ }
+ }
+ if ( icon->pixmap ) {
+ return *icon->pixmap;
+ } else {
+ return TQPixmap();
+ }
+}
+
+/*! \overload
+ \obsolete
+
+ This is the same as pixmap(\a size, \a enabled, \a state).
+*/
+TQPixmap TQIconSet::pixmap( Size size, bool enabled, State state ) const
+{
+ return pixmap( size, enabled ? Normal : Disabled, state );
+}
+
+/*!
+ \overload
+
+ Returns the pixmap originally provided to the constructor or to
+ reset(). This is the Normal pixmap of unspecified Size.
+
+ \sa reset()
+*/
+TQPixmap TQIconSet::pixmap() const
+{
+ if ( !d )
+ return TQPixmap();
+ return d->defaultPix;
+}
+
+/*!
+ Returns TRUE if the pixmap with size \a size, mode \a mode and
+ state \a state is generated from other pixmaps; otherwise returns
+ FALSE.
+
+ A pixmap obtained from a TQIconFactory is considered non-generated.
+*/
+bool TQIconSet::isGenerated( Size size, Mode mode, State state ) const
+{
+ if ( !d )
+ return TRUE;
+ return d->icon( this, size, mode, state )->origin == Generated;
+}
+
+/*!
+ Clears all cached pixmaps, including those obtained from an
+ eventual TQIconFactory.
+*/
+void TQIconSet::clearGenerated()
+{
+ if ( !d )
+ return;
+
+ for ( int i = 0; i < NumSizes; i++ ) {
+ for ( int j = 0; j < NumModes; j++ ) {
+ for ( int k = 0; k < NumStates; k++ ) {
+ d->icons[i][j][k].clearCached();
+ }
+ }
+ }
+}
+
+/*!
+ Installs \a factory as the icon factory for this iconset. The
+ icon factory is used to generates pixmaps not set by the user.
+
+ If no icon factory is installed, TQIconFactory::defaultFactory()
+ is used.
+*/
+void TQIconSet::installIconFactory( TQIconFactory *factory )
+{
+ detach();
+ d->setFactory( factory );
+}
+
+/*!
+ Returns TRUE if the icon set is empty; otherwise returns FALSE.
+*/
+bool TQIconSet::isNull() const
+{
+ return !d;
+}
+
+/*!
+ Detaches this icon set from others with which it may share data.
+
+ You will never need to call this function; other TQIconSet functions
+ call it as necessary.
+*/
+void TQIconSet::detach()
+{
+ if ( !d ) {
+ d = new TQIconSetPrivate;
+ return;
+ }
+ if ( d->count != 1 ) {
+ d->deref();
+ d = new TQIconSetPrivate( *d );
+ }
+}
+
+/*!
+ Assigns \a other to this icon set and returns a reference to this
+ icon set.
+
+ \sa detach()
+*/
+TQIconSet& TQIconSet::operator=( const TQIconSet& other )
+{
+ if ( other.d )
+ other.d->ref();
+
+ if ( d && d->deref() )
+ delete d;
+ d = other.d;
+ return *this;
+}
+
+/*!
+ Set the preferred size for all small or large icons that are
+ generated after this call. If \a which is Small, sets the preferred
+ size of small generated icons to \a size. Similarly, if \a which is
+ Large, sets the preferred size of large generated icons to \a size.
+
+ Note that cached icons will not be regenerated, so it is recommended
+ that you set the preferred icon sizes before generating any icon sets.
+ Also note that the preferred icon sizes will be ignored for icon sets
+ that have been created using both small and large pixmaps.
+
+ \sa iconSize()
+*/
+void TQIconSet::setIconSize( Size which, const TQSize& size )
+{
+ widths[(int) which - 1] = size.width();
+ heights[(int) which - 1] = size.height();
+}
+
+/*!
+ If \a which is Small, returns the preferred size of a small
+ generated icon; if \a which is Large, returns the preferred size
+ of a large generated icon.
+
+ \sa setIconSize()
+*/
+const TQSize& TQIconSet::iconSize( Size which )
+{
+ // ### tqreplace 'const TQSize&' with TQSize in TQt 4 and simply this code
+ static TQSize size;
+ size = TQSize( widths[(int) which - 1], heights[(int) which - 1] );
+ return size;
+}
+
+void TQIconSet::normalize( Size& which, const TQSize& pixSize )
+{
+ if ( which == Automatic )
+ which = pixSize.width() > iconSize( Small ).width() ? Large : Small;
+}
+
+/*!
+ Returns a new pixmap that is a copy of \a suppliedPix, scaled to
+ the icon size \a size.
+*/
+TQPixmap *TQIconSet::createScaled( Size size, const TQPixmap *suppliedPix ) const
+{
+ if ( !suppliedPix || suppliedPix->isNull() )
+ return 0;
+
+ TQImage img = suppliedPix->convertToImage();
+ TQSize imgSize = iconSize( size );
+ if ( size == Small ) {
+ imgSize = imgSize.boundedTo( img.size() );
+ } else {
+ imgSize = imgSize.expandedTo( img.size() );
+ }
+ img = img.smoothScale( imgSize );
+
+ TQPixmap *pixmap = new TQPixmap( img );
+ if ( !pixmap->tqmask() ) {
+ TQBitmap tqmask;
+ tqmask.convertFromImage( img.createHeuristicMask(),
+ TQt::MonoOnly | TQt::ThresholdDither );
+ pixmap->setMask( tqmask );
+ }
+ return pixmap;
+}
+
+/*!
+ Returns a new pixmap that has a 'disabled' look, taking as its
+ base the iconset's icon with size \a size and state \a state.
+*/
+TQPixmap *TQIconSet::createDisabled( Size size, State state ) const
+{
+ TQPixmap normalPix = pixmap( size, Normal, state );
+ if ( normalPix.isNull() )
+ return 0;
+
+ TQImage img;
+ TQPixmap *pixmap = 0;
+ TQBitmap normalMask;
+ if ( normalPix.tqmask() ) {
+ normalMask = *normalPix.tqmask();
+ } else {
+ img = normalPix.convertToImage();
+ normalMask.convertFromImage( img.createHeuristicMask(),
+ TQt::MonoOnly | TQt::ThresholdDither );
+ }
+
+ pixmap = new TQPixmap( normalPix.width() + 1,
+ normalPix.height() + 1 );
+ const TQColorGroup &dis = TQApplication::tqpalette().disabled();
+ pixmap->fill( dis.background() );
+
+ TQPainter painter;
+ painter.begin( pixmap );
+ painter.setPen( dis.base() );
+ painter.drawPixmap( 1, 1, normalMask );
+ painter.setPen( dis.foreground() );
+ painter.drawPixmap( 0, 0, normalMask );
+ painter.end();
+
+ if ( !normalMask.tqmask() )
+ normalMask.setMask( normalMask );
+
+ TQBitmap tqmask( pixmap->size() );
+ tqmask.fill( TQt::color0 );
+ painter.begin( &tqmask );
+ painter.drawPixmap( 0, 0, normalMask );
+ painter.drawPixmap( 1, 1, normalMask );
+ painter.end();
+ pixmap->setMask( tqmask );
+ return pixmap;
+}
+
+/*! \class TQIconFactory
+ \ingroup advanced
+ \brief The TQIconFactory class is used to create pixmaps for a TQIconSet.
+
+ By reimplementing createPixmap(), you can override TQIconSet's
+ default algorithm for computing pixmaps not supplied by the user.
+
+ Call setAutoDelete(TRUE) if you want the factory to automatically
+ delete itself when it is no longer needed by TQIconSet.
+
+ \sa TQIconSet
+*/
+
+/*!
+ Constructs an icon factory.
+*/
+TQIconFactory::TQIconFactory()
+ : autoDel( 0 )
+{
+ count = 0;
+}
+
+/*!
+ Destroys the object and frees any allocated resources.
+*/
+TQIconFactory::~TQIconFactory()
+{
+}
+
+/*!
+ Ceates a pixmap for \a iconSet with a certain \a size, \a mode, and
+ \a state. Returns 0 if the default TQIconSet algorithm should be
+ used to create a pixmap that wasn't supplied by the user.
+
+ It is the caller's responsibility to delete the returned pixmap.
+
+ The default implementation always returns 0.
+*/
+TQPixmap *TQIconFactory::createPixmap( const TQIconSet& /* iconSet */,
+ TQIconSet::Size /* size */,
+ TQIconSet::Mode /* mode */,
+ TQIconSet::State /* state */ )
+{
+ return 0;
+}
+
+/*!
+ \fn void TQIconFactory::setAutoDelete( bool autoDelete )
+
+ If \a autoDelete is TRUE, sets the icon factory to automatically
+ delete itself when it is no longer referenced by any TQIconSet and
+ isn't the default factory. If \a autoDelete is FALSE (the default)
+ auto-deletion is disabled.
+
+ \sa autoDelete(), defaultFactory()
+*/
+
+/*!
+ \fn bool TQIconFactory::autoDelete() const
+
+ Returns TRUE if auto-deletion is enabled; otherwise returns FALSE.
+
+ \sa setAutoDelete()
+*/
+
+/*!
+ Returns the default icon factory.
+
+ \sa installDefaultFactory()
+*/
+TQIconFactory *TQIconFactory::defaultFactory()
+{
+ if ( !defaultFac ) {
+ defaultFac = new TQIconFactory;
+ defaultFac->setAutoDelete( TRUE );
+ defaultFac->ref();
+ q_cleanup_icon_factory.set( &defaultFac );
+ }
+ return defaultFac;
+}
+
+/*!
+ Replaces the default icon factory with \a factory.
+*/
+void TQIconFactory::installDefaultFactory( TQIconFactory *factory )
+{
+ if ( !factory )
+ return;
+
+ factory->ref();
+ if ( defaultFac && defaultFac->deref() && defaultFac->autoDelete() )
+ delete defaultFac;
+ defaultFac = factory;
+ q_cleanup_icon_factory.set( &defaultFac );
+}
+
+#endif // TQT_NO_ICONSET
diff --git a/tqtinterface/qt4/src/kernel/tqiconset.h b/tqtinterface/qt4/src/kernel/tqiconset.h
new file mode 100644
index 0000000..31249ab
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqiconset.h
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Definition of TQIconSet class
+**
+** Created : 980318
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQICONSET_H
+#define TQICONSET_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqpixmap.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_ICONSET
+
+class TQIconFactory;
+class TQIconSetPrivate;
+
+// ### Remove all 'virtual' functions in TQIconSet (but not TQIconFactory) in TQt 4.0
+class TQ_EXPORT TQIconSet
+{
+public:
+ // the implementation makes assumptions about the value of these
+ enum Size { Automatic, Small, Large };
+ enum Mode { Normal, Disabled, Active };
+ enum State { On, Off };
+
+ TQIconSet();
+ TQIconSet( const TQPixmap& pixmap, Size size = Automatic );
+ TQIconSet( const TQPixmap& smallPix, const TQPixmap& largePix );
+ TQIconSet( const TQIconSet& other );
+ virtual ~TQIconSet();
+
+ void reset( const TQPixmap& pixmap, Size size );
+
+ virtual void setPixmap( const TQPixmap& pixmap, Size size,
+ Mode mode = Normal, State state = Off );
+ virtual void setPixmap( const TQString& fileName, Size size,
+ Mode mode = Normal, State state = Off );
+ TQPixmap pixmap( Size size, Mode mode, State state = Off ) const;
+ TQPixmap pixmap( Size size, bool enabled, State state = Off ) const;
+ TQPixmap pixmap() const;
+ bool isGenerated( Size size, Mode mode, State state = Off ) const;
+ void clearGenerated();
+ void installIconFactory( TQIconFactory *factory );
+
+ bool isNull() const;
+
+ void detach();
+
+ TQIconSet& operator=( const TQIconSet& other );
+
+ // static functions
+ static void setIconSize( Size which, const TQSize& size );
+ static const TQSize& iconSize( Size which );
+
+#ifndef TQ_TQDOC
+ TQ_DUMMY_COMPARISON_OPERATOR(TQIconSet)
+#endif
+
+private:
+ void normalize( Size& which, const TQSize& pixSize );
+ TQPixmap *createScaled( Size size, const TQPixmap *suppliedPix ) const;
+ TQPixmap *createDisabled( Size size, State state ) const;
+
+ TQIconSetPrivate *d;
+};
+
+class TQ_EXPORT TQIconFactory : private TQShared
+{
+public:
+ TQIconFactory();
+ virtual ~TQIconFactory();
+
+ virtual TQPixmap *createPixmap( const TQIconSet& iconSet, TQIconSet::Size size,
+ TQIconSet::Mode mode, TQIconSet::State state );
+ void setAutoDelete( bool autoDelete ) { autoDel = autoDelete; }
+ bool autoDelete() const { return autoDel; }
+
+ static TQIconFactory *defaultFactory();
+ static void installDefaultFactory( TQIconFactory *factory );
+
+private:
+#if defined(TQ_DISABLE_COPY)
+ TQIconFactory( const TQIconFactory & );
+ TQIconFactory &operator=( const TQIconFactory & );
+#endif
+
+ friend class TQIconSet;
+ friend class TQIconSetPrivate;
+
+ uint autoDel : 1;
+ uint unused : 31;
+};
+
+#endif // TQT_NO_ICONSET
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqimage.cpp b/tqtinterface/qt4/src/kernel/tqimage.cpp
new file mode 100644
index 0000000..0c97e64
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqimage.cpp
@@ -0,0 +1,9526 @@
+/****************************************************************************
+**
+** Implementation of TQImage and TQImageIO classes
+**
+** Created : 950207
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+// Nasty, nasty horrid HACK to get access to QImage's private members
+// This is TERRIBLE and I wish there was a way around it
+// This is a good example of the new, broken & irritating Qt4 API,
+// and the corresponding loss in functionality versus Qt3.
+// See also tqrect.cpp
+#define private protected
+#include <Qt/qimage.h>
+#undef private
+
+#include "tqimage.h"
+#include "tqregexp.h"
+#include "tqfile.h"
+#include "tqdatastream.h"
+#include "tqtextstream.h"
+#include "tqbuffer.h"
+#include "tqptrlist.h"
+#include "tqasyncimageio.h"
+#include "tqpngio.h"
+#include "tqmngio.h"
+#include "tqjpegio.h"
+#include "tqmap.h"
+#include <private/tqpluginmanager_p.h>
+#include "tqimageformatinterface_p.h"
+#include "tqwmatrix.h"
+#include "tqapplication.h"
+#include "tqmime.h"
+#include "tqdragobject.h"
+#include <ctype.h>
+#include <stdlib.h>
+
+#ifdef TQ_WS_TQWS
+#include "tqgfx_qws.h"
+#endif
+
+#ifdef USE_QT4
+
+#include <Qt/qx11info_x11.h>
+
+#include "private/tqt_x11_p.h"
+#include "private/qt4_qimage_p.h"
+
+QImage::Format TQImage::formatFor(int depth, TQImage::Endian bitOrder)
+{
+ QImage::Format format;
+ if (depth == 1) {
+ format = bitOrder == TQImage::BigEndian ? QImage::Format_Mono : QImage::Format_MonoLSB;
+ } else if (depth == 8) {
+ format = QImage::Format_Indexed8;
+ } else if (depth == 32) {
+ format = QImage::Format_ARGB32;
+ } else if (depth == 24) {
+ format = QImage::Format_RGB888;
+ } else if (depth == 16) {
+ format = QImage::Format_RGB16;
+ } else {
+ qWarning("QImage: Depth %d not supported", depth);
+ format = QImage::Format_Invalid;
+ }
+ return format;
+}
+
+static QImage::Format tqformatFor(int depth, TQImage::Endian bitOrder)
+{
+ QImage::Format format;
+ if (depth == 1) {
+ format = bitOrder == TQImage::BigEndian ? QImage::Format_Mono : QImage::Format_MonoLSB;
+ } else if (depth == 8) {
+ format = QImage::Format_Indexed8;
+ } else if (depth == 32) {
+ format = QImage::Format_RGB32;
+ } else if (depth == 24) {
+ format = QImage::Format_RGB888;
+ } else if (depth == 16) {
+ format = QImage::Format_RGB16;
+ } else {
+ qWarning("QImage: Depth %d not supported", depth);
+ format = QImage::Format_Invalid;
+ }
+ return format;
+}
+
+/*!
+ Converts the depth (bpp) of the image to the given \a depth and
+ returns the converted image. The original image is not changed.
+ Returns this image if \a depth is equal to the image depth, or a
+ null image if this image cannot be converted. The \a depth
+ argument must be 1, 8 or 32. If the image needs to be modified to
+ fit in a lower-resolution result (e.g. converting from 32-bit to
+ 8-bit), use the \a flags to specify how you'd prefer this to
+ happen.
+
+ Use the convertToFormat() function instead.
+*/
+
+TQImage TQImage::convertDepth(int newdepth, Qt::ImageConversionFlags flags) const
+{
+ if (depth() == newdepth)
+ return *this;
+
+ Format format = tqformatFor(newdepth, LittleEndian);
+ return convertToFormat(format, flags);
+}
+
+#ifndef TQT_NO_IMAGEIO
+/*!
+ Returns a string that specifies the image format of the file \a
+ fileName, or 0 if the file cannot be read or if the format is not
+ recognized.
+
+ The TQImageIO documentation lists the guaranteed supported image
+ formats, or use TQImage::inputFormats() and TQImage::outputFormats()
+ to get lists that include the installed formats.
+
+ \sa load() save()
+*/
+
+const char* TQImage::imageFormat( const TQString &fileName )
+{
+ return TQImageIO::imageFormat( fileName );
+}
+#endif
+
+/*!
+ Returns true if alpha buffer mode is enabled; otherwise returns
+ false.
+
+ Use the hasAlphaChannel() function instead.
+
+*/
+bool TQImage::hasAlphaBuffer() const
+{
+ switch (format()) {
+ case Format_ARGB32:
+ case Format_ARGB32_Premultiplied:
+ case Format_ARGB8565_Premultiplied:
+ case Format_ARGB8555_Premultiplied:
+ case Format_ARGB6666_Premultiplied:
+ case Format_ARGB4444_Premultiplied:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/*!
+ Enables alpha buffer mode if \a enable is true, otherwise disables
+ it. The alpha buffer is used to set a mask when a QImage is
+ translated to a QPixmap.
+
+ If a monochrome or indexed 8-bit image has alpha channels in their
+ color tables they will automatically detect that they have an
+ alpha channel, so this function is not required. To force alpha
+ channels on 32-bit images, use the convertToFormat() function.
+*/
+
+void TQImage::setAlphaBuffer(bool enable)
+{
+ if (format() == Format_Mono
+ || format() == Format_MonoLSB
+ || format() == Format_Indexed8)
+ return;
+ if (enable && (format() == Format_ARGB32 ||
+ format() == Format_ARGB32_Premultiplied ||
+ format() == Format_ARGB8565_Premultiplied ||
+ format() == Format_ARGB6666_Premultiplied ||
+ format() == Format_ARGB8555_Premultiplied ||
+ format() == Format_ARGB4444_Premultiplied))
+ {
+ return;
+ }
+ else {
+ // Emulate Ye Olde Tyme Qt3.x behaviour, where the alpha channel is always present
+ // in bits 24:31. This is to allow code that purposefully shuts down the alpha channel
+ // so that it may be initialized unhindered to function correctly under Qt4.
+ // The only side effect that I am aware of is that disabling the alpha channel will clear it out.
+ if (format() == Format_ARGB32 ||
+ format() == Format_ARGB32_Premultiplied ||
+ format() == Format_ARGB8565_Premultiplied ||
+ format() == Format_ARGB6666_Premultiplied ||
+ format() == Format_ARGB8555_Premultiplied ||
+ format() == Format_ARGB4444_Premultiplied)
+ {
+ if (!enable) {
+ // Set the alpha buffer to opaque
+ // This may be a bit slow/memory intensive! Alternative suggestions are welcome.
+ detach();
+ *this=convertToFormat(Format_RGB32);
+ detach();
+ *this=convertToFormat(Format_ARGB32);
+ }
+ }
+ // As mentioned above, we get an alpha channel whether we wanted one or not!
+ detach();
+ *this=convertToFormat(Format_ARGB32);
+ }
+}
+
+/*!
+ Returns a pointer to the scanline pointer table. This is the
+ beginning of the data block for the image.
+ Returns 0 in case of an error.
+
+ Use the bits() or scanLine() function instead.
+*/
+uchar **TQImage::jumpTable()
+{
+// if (!d)
+// return 0;
+// detach();
+//
+// // in case detach() ran out of memory..
+// if (!d)
+// return 0;
+//
+// if (!d->jumptable) {
+// d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));
+// if (!d->jumptable)
+// return 0;
+// uchar *data = d->data;
+// int height = d->height;
+// uchar **p = d->jumptable;
+// while (height--) {
+// *p++ = data;
+// data += d->bytes_per_line;
+// }
+// }
+// return d->jumptable;
+
+ // Qt4 does not have native jumpTable support; here is an approximate replacement
+ // We essentially reconstruct the jumptable here
+ if (jumptable)
+ free(jumptable);
+ jumptable = (uchar **)malloc(height()*sizeof(uchar *));
+ if (!jumptable)
+ return 0;
+ uchar *data = scanLine(0);
+ int h = height();
+ uchar **p = jumptable;
+ while (h--) {
+ *p++ = data;
+ data += bytesPerLine();
+ }
+ return jumptable;
+}
+
+/*!
+ \overload
+*/
+const uchar * const *TQImage::jumpTable() const
+{
+// if (!d)
+// return 0;
+// if (!d->jumptable) {
+// d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));
+// if (!d->jumptable)
+// return 0;
+// uchar *data = d->data;
+// int height = d->height;
+// uchar **p = d->jumptable;
+// while (height--) {
+// *p++ = data;
+// data += d->bytes_per_line;
+// }
+// }
+// return d->jumptable;
+
+
+ // Qt4 does not have native jumpTable support; here is an approximate replacement
+ // We essentially reconstruct the jumptable here
+ if (jumptable)
+ free(jumptable);
+ jumptable = (uchar **)malloc(height()*sizeof(uchar *));
+ if (!jumptable)
+ return 0;
+ const uchar *data = scanLine(0);
+ int h = height();
+ uchar **p = jumptable;
+ while (h--) {
+ *p++ = const_cast<uchar*>(data);
+ data += bytesPerLine();
+ }
+ return jumptable;
+}
+
+/*!
+ \internal
+ Deallocates the image data and sets the bits pointer to 0.
+*/
+
+void TQImage::freeBits()
+{
+// if ( data->bits ) { // dealloc image bits
+// free( data->bits );
+// data->bits = 0;
+// }
+
+ // [FIXME]
+ printf("[WARNING] TQImage::freeBits() unimplemented\n\r");
+}
+
+void TQImage::reinit()
+{
+// data->w = data->h = data->d = data->ncols = 0;
+// data->nbytes = 0;
+// data->ctbl = 0;
+// data->bits = 0;
+// data->bitordr = TQImage::IgnoreEndian;
+// data->alpha = FALSE;
+// #ifndef TQT_NO_IMAGE_TEXT
+// data->misc = 0;
+// #endif
+// data->dpmx = 0;
+// data->dpmy = 0;
+// data->offset = TQPoint(0,0);
+
+ // [FIXME]
+ printf("[WARNING] TQImage::reinit() unimplemented\n\r");
+}
+
+/*!
+ \fn bool TQImage::create(int width, int height, int depth, int numColors, Endian bitOrder)
+
+ Sets the image \a width, \a height, \a depth, its number of colors
+ (in \a numColors), and bit order. Returns true if successful, or
+ false if the parameters are incorrect or if memory cannot be
+ allocated.
+
+ The \a width and \a height is limited to 32767. \a depth must be
+ 1, 8, or 32. If \a depth is 1, \a bitOrder must be set to
+ either QImage::LittleEndian or QImage::BigEndian. For other depths
+ \a bitOrder must be QImage::IgnoreEndian.
+
+ This function allocates a color table and a buffer for the image
+ data. The image data is not initialized. The image buffer is
+ allocated as a single block that consists of a table of scanLine()
+ pointers (jumpTable()) and the image data (bits()).
+
+ Use a QImage constructor instead.
+*/
+bool TQImage::create(int width, int height, int depth, int numColors, Endian bitOrder)
+{
+ if (d && !d->ref.deref())
+ delete d;
+ d = QImageData::create(QSize(width, height), formatFor(depth, bitOrder), numColors);
+ return true;
+}
+
+/*!
+ \fn bool TQImage::create(const QSize& size, int depth, int numColors, Endian bitOrder)
+ \overload
+
+ The width and height are specified in the \a size argument.
+
+ Use a QImage constructor instead.
+*/
+bool TQImage::create(const TQSize& size, int depth, int numColors, TQImage::Endian bitOrder)
+{
+ if (d && !d->ref.deref())
+ delete d;
+ d = QImageData::create(size, formatFor(depth, bitOrder), numColors);
+ return true;
+}
+
+// [FIXME] [CRITICAL] [MEMLEAK] Memory leak!
+// BUT any attempt to define this destructor will cause a glibc invalid pointer crash
+// [FIXME] [CRITICAL] [MEMLEAK]
+// TQImage::~TQImage()
+// {
+// if (jumptable)
+// free(jumptable);
+// jumptable = 0;
+// }
+
+#if 0
+/*!
+ Sets the image IO status to \a status. A non-zero value indicates
+ an error, whereas 0 means that the IO operation was successful.
+
+ \sa status()
+*/
+
+void TQImageIO::setqStatus( int status )
+{
+ static_cast<TQIODevice*>(QImageReader::device())->setqStatus(status);
+ static_cast<TQIODevice*>(QImageWriter::device())->setqStatus(status);
+}
+#else
+
+/*!
+ Returns a list of image formats that are supported for image
+ input.
+
+ \sa outputFormats() inputFormatList() TQImageIO
+*/
+TQStrList TQImage::inputFormats()
+{
+ return TQImageIO::inputFormats();
+}
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Returns a list of image formats that are supported for image
+ input.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myImage.inputFormatList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa outputFormatList() inputFormats() TQImageIO
+*/
+TQStringList TQImage::inputFormatList()
+{
+ return TQStringList::fromStrList(TQImageIO::inputFormats());
+}
+
+
+/*!
+ Returns a list of image formats that are supported for image
+ output.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myImage.outputFormatList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa inputFormatList() outputFormats() TQImageIO
+*/
+TQStringList TQImage::outputFormatList()
+{
+ return TQStringList::fromStrList(TQImageIO::outputFormats());
+}
+#endif //TQT_NO_STRINGLIST
+
+/*!
+ Returns a list of image formats that are supported for image
+ output.
+
+ \sa inputFormats() outputFormatList() TQImageIO
+*/
+TQStrList TQImage::outputFormats()
+{
+ return TQImageIO::outputFormats();
+}
+
+
+/*!
+ Loads an image from the file \a fileName. Returns TRUE if the
+ image was successfully loaded; otherwise returns FALSE.
+
+ If \a format is specified, the loader attempts to read the image
+ using the specified format. If \a format is not specified (which
+ is the default), the loader reads a few bytes from the header to
+ guess the file format.
+
+ The TQImageIO documentation lists the supported image formats and
+ explains how to add extra formats.
+
+ \sa loadFromData() save() imageFormat() TQPixmap::load() TQImageIO
+*/
+
+bool TQImage::load( const TQString &fileName, const char* format )
+{
+ TQImageIO io( fileName, format );
+ bool result = io.read();
+ if ( result )
+ operator=( io.image() );
+ return result;
+}
+
+/*!
+ Loads an image from the first \a len bytes of binary data in \a
+ buf. Returns TRUE if the image was successfully loaded; otherwise
+ returns FALSE.
+
+ If \a format is specified, the loader attempts to read the image
+ using the specified format. If \a format is not specified (which
+ is the default), the loader reads a few bytes from the header to
+ guess the file format.
+
+ The TQImageIO documentation lists the supported image formats and
+ explains how to add extra formats.
+
+ \sa load() save() imageFormat() TQPixmap::loadFromData() TQImageIO
+*/
+
+bool TQImage::loadFromData( const uchar *buf, uint len, const char *format )
+{
+ TQByteArray a;
+ a.setRawData( (char *)buf, len );
+ TQBuffer b( a );
+ b.open( IO_ReadOnly );
+ TQImageIO io( &b, format );
+ bool result = io.read();
+ b.close();
+ a.resetRawData( (char *)buf, len );
+ if ( result )
+ operator=( io.image() );
+ return result;
+}
+
+/*!
+ \overload
+
+ Loads an image from the TQByteArray \a buf.
+*/
+bool TQImage::loadFromData( TQByteArray buf, const char *format )
+{
+ return loadFromData( (const uchar *)(buf.data()), buf.size(), format );
+}
+
+/*!
+ Saves the image to the file \a fileName, using the image file
+ format \a format and a quality factor of \a quality. \a quality
+ must be in the range 0..100 or -1. Specify 0 to obtain small
+ compressed files, 100 for large uncompressed files, and -1 (the
+ default) to use the default settings.
+
+ Returns TRUE if the image was successfully saved; otherwise
+ returns FALSE.
+
+ \sa load() loadFromData() imageFormat() TQPixmap::save() TQImageIO
+*/
+
+bool TQImage::save( const TQString &fileName, const char* format, int quality ) const
+{
+ if ( isNull() )
+ return FALSE; // nothing to save
+ TQImageIO io( fileName, format );
+ return doImageIO( &io, quality );
+}
+
+/*!
+ \overload
+
+ This function writes a TQImage to the TQIODevice, \a tqdevice. This
+ can be used, for example, to save an image directly into a
+ TQByteArray:
+ \code
+ TQImage image;
+ TQByteArray ba;
+ TQBuffer buffer( ba );
+ buffer.open( IO_WriteOnly );
+ image.save( &buffer, "PNG" ); // writes image into ba in PNG format
+ \endcode
+*/
+
+bool TQImage::save( QIODevice* tqdevice, const char* format, int quality ) const
+{
+ if ( isNull() )
+ return FALSE; // nothing to save
+ TQImageIO io( tqdevice, format );
+ return doImageIO( &io, quality );
+}
+
+/* \internal
+*/
+
+bool TQImage::doImageIO( TQImageIO* io, int quality ) const
+{
+ if ( !io )
+ return FALSE;
+ io->setImage( *this );
+#if defined(TQT_CHECK_RANGE)
+ if ( quality > 100 || quality < -1 )
+ qWarning( "TQPixmap::save: quality out of range [-1,100]" );
+#endif
+ if ( quality >= 0 )
+ io->setQuality( TQMIN(quality,100) );
+ return io->write();
+}
+
+/*****************************************************************************
+ Standard image io handlers (defined below)
+ *****************************************************************************/
+
+// standard image io handlers (defined below)
+#ifndef TQT_NO_IMAGEIO_BMP
+static void read_bmp_image( TQImageIO * );
+static void write_bmp_image( TQImageIO * );
+#endif
+#ifndef TQT_NO_IMAGEIO_PPM
+static void read_pbm_image( TQImageIO * );
+static void write_pbm_image( TQImageIO * );
+#endif
+#ifndef TQT_NO_IMAGEIO_XBM
+static void read_xbm_image( TQImageIO * );
+static void write_xbm_image( TQImageIO * );
+#endif
+#ifndef TQT_NO_IMAGEIO_XPM
+static void read_xpm_image( TQImageIO * );
+static void write_xpm_image( TQImageIO * );
+#endif
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+static void read_async_image( TQImageIO * ); // Not in table of handlers
+#endif
+
+/*****************************************************************************
+ Misc. utility functions
+ *****************************************************************************/
+#if !defined(TQT_NO_IMAGEIO_XPM) || !defined(TQT_NO_IMAGEIO_XBM)
+static TQString fbname( const TQString &fileName ) // get file basename (sort of)
+{
+ TQString s = fileName;
+ if ( !s.isEmpty() ) {
+ int i;
+ if ( (i = s.tqfindRev('/')) >= 0 )
+ s = s.mid( i );
+ if ( (i = s.tqfindRev('\\')) >= 0 )
+ s = s.mid( i );
+ TQRegExp r( TQString::tqfromLatin1("[a-zA-Z][a-zA-Z0-9_]*") );
+ int p = r.search( s );
+ if ( p == -1 )
+ s.truncate( 0 );
+ else
+ s = s.mid( p, r.matchedLength() );
+ }
+ if ( s.isEmpty() )
+ s = TQString::tqfromLatin1( "dummy" );
+ return s;
+}
+#endif
+
+#ifndef TQT_NO_IMAGEIO_BMP
+static void swapPixel01( TQImage *image ) // 1-bpp: swap 0 and 1 pixels
+{
+ int i;
+ if ( image->depth() == 1 && image->numColors() == 2 ) {
+ register uint *p = (uint *)image->bits();
+ int nbytes = image->numBytes();
+ for ( i=0; i<nbytes/4; i++ ) {
+ *p = ~*p;
+ p++;
+ }
+ uchar *p2 = (uchar *)p;
+ for ( i=0; i<(nbytes&3); i++ ) {
+ *p2 = ~*p2;
+ p2++;
+ }
+ TQRgb t = image->color(0); // swap color 0 and 1
+ image->setColor( 0, image->color(1) );
+ image->setColor( 1, t );
+ }
+}
+#endif
+
+
+/*****************************************************************************
+ TQImageIO member functions
+ *****************************************************************************/
+
+/*!
+ \class TQImageIO tqimage.h
+
+ \brief The TQImageIO class tqcontains parameters for loading and
+ saving images.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup io
+
+ TQImageIO tqcontains a TQIODevice object that is used for image data
+ I/O. The programmer can install new image file formats in addition
+ to those that TQt provides.
+
+ TQt currently supports the following image file formats: PNG, BMP,
+ XBM, XPM and PNM. It may also support JPEG, MNG and GIF, if
+ specially configured during compilation. The different PNM formats
+ are: PBM (P1 or P4), PGM (P2 or P5), and PPM (P3 or P6).
+
+ You don't normally need to use this class; TQPixmap::load(),
+ TQPixmap::save(), and TQImage contain sufficient functionality.
+
+ For image files that contain sequences of images, only the first
+ is read. See TQMovie for loading multiple images.
+
+ PBM, PGM, and PPM format \e output is always in the more condensed
+ raw format. PPM and PGM files with more than 256 levels of
+ intensity are scaled down when reading.
+
+ \warning If you are in a country which recognizes software patents
+ and in which Unisys holds a patent on LZW compression and/or
+ decompression and you want to use GIF, Unisys may require you to
+ license the technology. Such countries include Canada, Japan, the
+ USA, France, Germany, Italy and the UK. It is believed that as of
+ this writing (March 15, 2011) all GIF software patents have expired.
+ However, this does not constitute legal advice! Check with a lawyer
+ if you want to know if the patents have expired in your country.
+
+ GIF support may be removed completely in a future version of TQt.
+ We strongly recommend using the lossless PNG format.
+
+ \sa TQImage TQPixmap TQFile TQMovie
+*/
+
+#ifndef TQT_NO_IMAGEIO
+struct TQImageIOData
+{
+ const char *parameters;
+ int quality;
+ float gamma;
+};
+
+/*!
+ Constructs a TQImageIO object with all parameters set to zero.
+*/
+
+TQImageIO::TQImageIO()
+{
+ init();
+}
+
+/*!
+ Constructs a TQImageIO object with the I/O tqdevice \a ioDevice and a
+ \a format tag.
+*/
+
+TQImageIO::TQImageIO( QIODevice *ioDevice, const char *format )
+ : frmt(format)
+{
+ init();
+ iodev = TQT_TQIODEVICE(ioDevice);
+}
+
+/*!
+ Constructs a TQImageIO object with the file name \a fileName and a
+ \a format tag.
+*/
+
+TQImageIO::TQImageIO( const TQString &fileName, const char* format )
+ : frmt(format), fname(fileName)
+{
+ init();
+}
+
+/*!
+ Contains initialization common to all TQImageIO constructors.
+*/
+
+void TQImageIO::init()
+{
+ d = new TQImageIOData();
+ d->parameters = 0;
+ d->quality = -1; // default quality of the current format
+ d->gamma=0.0f;
+ iostat = 0;
+ iodev = 0;
+}
+
+/*!
+ Destroys the object and all related data.
+*/
+
+TQImageIO::~TQImageIO()
+{
+ if ( d->parameters )
+ delete [] (char*)d->parameters;
+ delete d;
+}
+
+
+/*****************************************************************************
+ TQImageIO image handler functions
+ *****************************************************************************/
+
+class TQImageHandler
+{
+public:
+ TQImageHandler( const char *f, const char *h, const TQCString& fl,
+ image_io_handler r, image_io_handler w );
+ TQCString format; // image format
+ TQRegExp header; // image header pattern
+ enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode;
+ image_io_handler read_image; // image read function
+ image_io_handler write_image; // image write function
+ bool obsolete; // support not "published"
+};
+
+TQImageHandler::TQImageHandler( const char *f, const char *h, const TQCString& fl,
+ image_io_handler r, image_io_handler w )
+ : format(f), header(TQString::tqfromLatin1(h))
+{
+ text_mode = Untranslated;
+ if ( fl.tqcontains('t') )
+ text_mode = TranslateIn;
+ else if ( fl.tqcontains('T') )
+ text_mode = TranslateInOut;
+ obsolete = fl.tqcontains('O');
+ read_image = r;
+ write_image = w;
+}
+
+typedef TQPtrList<TQImageHandler> TQIHList;// list of image handlers
+static TQIHList *imageHandlers = 0;
+#ifndef TQT_NO_COMPONENT
+static TQPluginManager<TQImageFormatInterface> *plugin_manager = 0;
+#else
+static void *plugin_manager = 0;
+#endif
+
+void qt_init_image_plugins()
+{
+#ifndef TQT_NO_COMPONENT
+ if ( plugin_manager )
+ return;
+
+ plugin_manager = new TQPluginManager<TQImageFormatInterface>( IID_TQImageFormat, TQApplication::libraryPaths(), "/imageformats" );
+
+ TQStringList features = plugin_manager->featureList();
+ TQStringList::Iterator it = features.begin();
+ while ( it != features.end() ) {
+ TQString str = *it;
+ ++it;
+ TQInterfacePtr<TQImageFormatInterface> iface;
+ plugin_manager->queryInterface( str, &iface );
+ if ( iface )
+ iface->installIOHandler( str );
+ }
+#endif
+}
+
+static void cleanup()
+{
+ // make sure that image handlers are deleted before plugin manager
+ delete imageHandlers;
+ imageHandlers = 0;
+#ifndef TQT_NO_COMPONENT
+ delete plugin_manager;
+ plugin_manager = 0;
+#endif
+}
+
+void qt_init_image_handlers() // initialize image handlers
+{
+ if ( !imageHandlers ) {
+ imageHandlers = new TQIHList;
+ TQ_CHECK_PTR( imageHandlers );
+ imageHandlers->setAutoDelete( TRUE );
+ qAddPostRoutine( cleanup );
+#ifndef TQT_NO_IMAGEIO_BMP
+ TQImageIO::defineIOHandler( "BMP", "^BM", 0,
+ read_bmp_image, write_bmp_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_PPM
+ TQImageIO::defineIOHandler( "PBM", "^P1", "t",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PBMRAW", "^P4", "O",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PGM", "^P2", "t",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PGMRAW", "^P5", "O",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PPM", "^P3", "t",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PPMRAW", "^P6", "O",
+ read_pbm_image, write_pbm_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_XBM
+ TQImageIO::defineIOHandler( "XBM", "^((/\\*(?!.XPM.\\*/))|#define)", "T",
+ read_xbm_image, write_xbm_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_XPM
+ TQImageIO::defineIOHandler( "XPM", "/\\*.XPM.\\*/", "T",
+ read_xpm_image, write_xpm_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_MNG
+ qInitMngIO();
+#endif
+#ifndef TQT_NO_IMAGEIO_PNG
+ qInitPngIO();
+#endif
+#ifndef TQT_NO_IMAGEIO_JPEG
+ qInitJpegIO();
+#endif
+ }
+}
+
+static TQImageHandler *get_image_handler( const char *format )
+{ // get pointer to handler
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+ register TQImageHandler *p = imageHandlers->first();
+ while ( p ) { // traverse list
+ if ( p->format == format )
+ return p;
+ p = imageHandlers->next();
+ }
+ return 0; // no such handler
+}
+
+
+/*!
+ Defines an image I/O handler for the image format called \a
+ format, which is recognized using the \link tqregexp.html#details
+ regular expression\endlink \a header, read using \a readImage and
+ written using \a writeImage.
+
+ \a flags is a string of single-character flags for this format.
+ The only flag defined currently is T (upper case), so the only
+ legal value for \a flags are "T" and the empty string. The "T"
+ flag means that the image file is a text file, and TQt should treat
+ all newline conventions as equivalent. (XPM files and some PPM
+ files are text files for example.)
+
+ \a format is used to select a handler to write a TQImage; \a header
+ is used to select a handler to read an image file.
+
+ If \a readImage is a null pointer, the TQImageIO will not be able
+ to read images in \a format. If \a writeImage is a null pointer,
+ the TQImageIO will not be able to write images in \a format. If
+ both are null, the TQImageIO object is valid but useless.
+
+ Example:
+ \code
+ void readGIF( TQImageIO *image )
+ {
+ // read the image using the image->ioDevice()
+ }
+
+ void writeGIF( TQImageIO *image )
+ {
+ // write the image using the image->ioDevice()
+ }
+
+ // add the GIF image handler
+
+ TQImageIO::defineIOHandler( "GIF",
+ "^GIF[0-9][0-9][a-z]",
+ 0,
+ readGIF,
+ writeGIF );
+ \endcode
+
+ Before the regex test, all the 0 bytes in the file header are
+ converted to 1 bytes. This is done because when TQt was
+ ASCII-based, TQRegExp could not handle 0 bytes in strings.
+
+ The regexp is only applied on the first 14 bytes of the file.
+
+ Note that TQt assumes that there is only one handler per format; if
+ two handlers support the same format, TQt will choose one
+ arbitrarily. It is not possible to have one handler support
+ reading, and another support writing.
+*/
+
+void TQImageIO::defineIOHandler( const char *format,
+ const char *header,
+ const char *flags,
+ image_io_handler readImage,
+ image_io_handler writeImage )
+{
+ qt_init_image_handlers();
+ TQImageHandler *p;
+ p = new TQImageHandler( format, header, flags,
+ readImage, writeImage );
+ TQ_CHECK_PTR( p );
+ imageHandlers->insert( 0, p );
+}
+
+
+/*****************************************************************************
+ TQImageIO normal member functions
+ *****************************************************************************/
+
+/*!
+ \fn const TQImage &TQImageIO::image() const
+
+ Returns the image currently set.
+
+ \sa setImage()
+*/
+
+/*!
+ \fn int TQImageIO::status() const
+
+ Returns the image's IO status. A non-zero value indicates an
+ error, whereas 0 means that the IO operation was successful.
+
+ \sa setqStatus()
+*/
+
+/*!
+ \fn const char *TQImageIO::format() const
+
+ Returns the image format string or 0 if no format has been
+ explicitly set.
+*/
+
+/*!
+ \fn TQIODevice *TQImageIO::ioDevice() const
+
+ Returns the IO tqdevice currently set.
+
+ \sa setIODevice()
+*/
+
+/*!
+ \fn TQString TQImageIO::fileName() const
+
+ Returns the file name currently set.
+
+ \sa setFileName()
+*/
+
+/*!
+ \fn TQString TQImageIO::description() const
+
+ Returns the image description string.
+
+ \sa setDescription()
+*/
+
+
+/*!
+ Sets the image to \a image.
+
+ \sa image()
+*/
+
+void TQImageIO::setImage( const QImage &image )
+{
+ im = image;
+}
+
+/*!
+ Sets the image IO status to \a status. A non-zero value indicates
+ an error, whereas 0 means that the IO operation was successful.
+
+ \sa status()
+*/
+
+void TQImageIO::setqStatus( int status )
+{
+ iostat = status;
+}
+
+/*!
+ Sets the image format to \a format for the image to be read or
+ written.
+
+ It is necessary to specify a format before writing an image, but
+ it is not necessary to specify a format before reading an image.
+
+ If no format has been set, TQt guesses the image format before
+ reading it. If a format is set the image will only be read if it
+ has that format.
+
+ \sa read() write() format()
+*/
+
+void TQImageIO::setFormat( const char *format )
+{
+ frmt = format;
+}
+
+/*!
+ Sets the IO tqdevice to be used for reading or writing an image.
+
+ Setting the IO tqdevice allows images to be read/written to any
+ block-oriented TQIODevice.
+
+ If \a ioDevice is not null, this IO tqdevice will override file name
+ settings.
+
+ \sa setFileName()
+*/
+
+void TQImageIO::setIODevice( TQIODevice *ioDevice )
+{
+ iodev = ioDevice;
+}
+
+/*!
+ Sets the name of the file to read or write an image from to \a
+ fileName.
+
+ \sa setIODevice()
+*/
+
+void TQImageIO::setFileName( const TQString &fileName )
+{
+ fname = fileName;
+}
+
+/*!
+ Returns the quality of the written image, related to the
+ compression ratio.
+
+ \sa setQuality() TQImage::save()
+*/
+
+int TQImageIO::quality() const
+{
+ return d->quality;
+}
+
+/*!
+ Sets the quality of the written image to \a q, related to the
+ compression ratio.
+
+ \a q must be in the range -1..100. Specify 0 to obtain small
+ compressed files, 100 for large uncompressed files. (-1 signifies
+ the default compression.)
+
+ \sa quality() TQImage::save()
+*/
+
+void TQImageIO::setQuality( int q )
+{
+ d->quality = q;
+}
+
+/*!
+ Returns the image's parameters string.
+
+ \sa setParameters()
+*/
+
+const char *TQImageIO::parameters() const
+{
+ return d->parameters;
+}
+
+/*!
+ Sets the image's parameter string to \a parameters. This is for
+ image handlers that require special parameters.
+
+ Although the current image formats supported by TQt ignore the
+ parameters string, it may be used in future extensions or by
+ contributions (for example, JPEG).
+
+ \sa parameters()
+*/
+
+void TQImageIO::setParameters( const char *parameters )
+{
+ if ( d && d->parameters )
+ delete [] (char*)d->parameters;
+ d->parameters = qstrdup( parameters );
+}
+
+/*!
+ Sets the gamma value at which the image will be viewed to \a
+ gamma. If the image format stores a gamma value for which the
+ image is intended to be used, then this setting will be used to
+ modify the image. Setting to 0.0 will disable gamma correction
+ (i.e. any specification in the file will be ignored).
+
+ The default value is 0.0.
+
+ \sa gamma()
+*/
+void TQImageIO::setGamma( float gamma )
+{
+ d->gamma=gamma;
+}
+
+/*!
+ Returns the gamma value at which the image will be viewed.
+
+ \sa setGamma()
+*/
+float TQImageIO::gamma() const
+{
+ return d->gamma;
+}
+
+/*!
+ Sets the image description string for image handlers that support
+ image descriptions to \a description.
+
+ Currently, no image format supported by TQt uses the description
+ string.
+*/
+
+void TQImageIO::setDescription( const TQString &description )
+{
+ descr = description;
+}
+
+
+/*!
+ Returns a string that specifies the image format of the file \a
+ fileName, or null if the file cannot be read or if the format is
+ not recognized.
+*/
+
+const char* TQImageIO::imageFormat( const TQString &fileName )
+{
+ TQFile file( fileName );
+ if ( !file.open(IO_ReadOnly) )
+ return 0;
+ const char* format = imageFormat( TQT_TQIODEVICE(&file) );
+ file.close();
+ return format;
+}
+
+/*!
+ \overload
+
+ Returns a string that specifies the image format of the image read
+ from IO tqdevice \a d, or 0 if the tqdevice cannot be read or if the
+ format is not recognized.
+
+ Make sure that \a d is at the right position in the tqdevice (for
+ example, at the beginning of the file).
+
+ \sa TQIODevice::at()
+*/
+
+const char *TQImageIO::imageFormat( TQIODevice *d )
+{
+ // if you change this change the documentation for defineIOHandler()
+ const int buflen = 14;
+
+ char buf[buflen];
+ char buf2[buflen];
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+ int pos = d->at(); // save position
+ int rdlen = d->readBlock( buf, buflen ); // read a few bytes
+
+ if ( rdlen != buflen )
+ return 0;
+
+ memcpy( buf2, buf, buflen );
+
+ const char* format = 0;
+ for ( int n = 0; n < rdlen; n++ )
+ if ( buf[n] == '\0' )
+ buf[n] = '\001';
+ if ( d->status() == IO_Ok && rdlen > 0 ) {
+ buf[rdlen - 1] = '\0';
+ TQString bufStr = TQString::tqfromLatin1(buf);
+ TQImageHandler *p = imageHandlers->first();
+ int bestMatch = -1;
+ while ( p ) {
+ if ( p->read_image && p->header.search(bufStr) != -1 ) {
+ // try match with header if a read function is available
+ if (p->header.matchedLength() > bestMatch) {
+ // keep looking for best match
+ format = p->format;
+ bestMatch = p->header.matchedLength();
+ }
+ }
+ p = imageHandlers->next();
+ }
+ }
+ d->at( pos ); // restore position
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ if ( !format )
+ format = TQImageDecoder::formatName( (uchar*)buf2, rdlen );
+#endif
+
+ return format;
+}
+
+/*!
+ Returns a sorted list of image formats that are supported for
+ image input.
+*/
+TQStrList TQImageIO::inputFormats()
+{
+ TQStrList result;
+
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ // Include asynchronous loaders first.
+ result = TQImageDecoder::inputFormats();
+#endif
+
+ TQImageHandler *p = imageHandlers->first();
+ while ( p ) {
+ if ( p->read_image
+ && !p->obsolete
+ && !result.tqcontains(p->format) )
+ {
+ result.inSort(p->format);
+ }
+ p = imageHandlers->next();
+ }
+
+ return result;
+}
+
+/*!
+ Returns a sorted list of image formats that are supported for
+ image output.
+*/
+TQStrList TQImageIO::outputFormats()
+{
+ TQStrList result;
+
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+
+ // Include asynchronous writers (!) first.
+ // (None)
+
+ TQImageHandler *p = imageHandlers->first();
+ while ( p ) {
+ if ( p->write_image
+ && !p->obsolete
+ && !result.tqcontains(p->format) )
+ {
+ result.inSort(p->format);
+ }
+ p = imageHandlers->next();
+ }
+
+ return result;
+}
+
+
+
+/*!
+ Reads an image into memory and returns TRUE if the image was
+ successfully read; otherwise returns FALSE.
+
+ Before reading an image you must set an IO tqdevice or a file name.
+ If both an IO tqdevice and a file name have been set, the IO tqdevice
+ will be used.
+
+ Setting the image file format string is optional.
+
+ Note that this function does \e not set the \link format()
+ format\endlink used to read the image. If you need that
+ information, use the imageFormat() static functions.
+
+ Example:
+
+ \code
+ TQImageIO iio;
+ TQPixmap pixmap;
+ iio.setFileName( "vegeburger.bmp" );
+ if ( image.read() ) // ok
+ pixmap = iio.image(); // convert to pixmap
+ \endcode
+
+ \sa setIODevice() setFileName() setFormat() write() TQPixmap::load()
+*/
+
+bool TQImageIO::read()
+{
+ TQFile file;
+ const char *image_format;
+ TQImageHandler *h;
+
+ if ( iodev ) { // read from io tqdevice
+ // ok, already open
+ } else if ( !fname.isEmpty() ) { // read from file
+ file.setName( fname );
+ if ( !file.open(IO_ReadOnly) )
+ return FALSE; // cannot open file
+ iodev = TQT_TQIODEVICE(&file);
+ } else { // no file name or io tqdevice
+ return FALSE;
+ }
+ if (frmt.isEmpty()) {
+ // Try to guess format
+ image_format = imageFormat( iodev ); // get image format
+ if ( !image_format ) {
+ if ( file.isOpen() ) { // unknown format
+ file.close();
+ iodev = 0;
+ }
+ return FALSE;
+ }
+ } else {
+ image_format = frmt;
+ }
+
+ h = get_image_handler( image_format );
+ if ( file.isOpen() ) {
+#if !defined(TQ_OS_UNIX)
+ if ( h && h->text_mode ) { // reopen in translated mode
+ file.close();
+ file.open( IO_ReadOnly | IO_Translate );
+ }
+ else
+#endif
+ file.at( 0 ); // position to start
+ }
+ iostat = 1; // assume error
+
+ if ( h && h->read_image ) {
+ (*h->read_image)( this );
+ }
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ else {
+ // Format name, but no handler - must be an asychronous reader
+ read_async_image( this );
+ }
+#endif
+
+ if ( file.isOpen() ) { // image was read using file
+ file.close();
+ iodev = 0;
+ }
+ return iostat == 0; // image successfully read?
+}
+
+
+/*!
+ Writes an image to an IO tqdevice and returns TRUE if the image was
+ successfully written; otherwise returns FALSE.
+
+ Before writing an image you must set an IO tqdevice or a file name.
+ If both an IO tqdevice and a file name have been set, the IO tqdevice
+ will be used.
+
+ The image will be written using the specified image format.
+
+ Example:
+ \code
+ TQImageIO iio;
+ TQImage im;
+ im = pixmap; // convert to image
+ iio.setImage( im );
+ iio.setFileName( "vegeburger.bmp" );
+ iio.setFormat( "BMP" );
+ if ( iio.write() )
+ // returned TRUE if written successfully
+ \endcode
+
+ \sa setIODevice() setFileName() setFormat() read() TQPixmap::save()
+*/
+
+bool TQImageIO::write()
+{
+ if ( frmt.isEmpty() )
+ return FALSE;
+ TQImageHandler *h = get_image_handler( frmt );
+ if ( !h && !plugin_manager) {
+ qt_init_image_plugins();
+ h = get_image_handler( frmt );
+ }
+ if ( !h || !h->write_image ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImageIO::write: No such image format handler: %s",
+ format() );
+#endif
+ return FALSE;
+ }
+ TQFile file;
+ if ( !iodev && !fname.isEmpty() ) {
+ file.setName( fname );
+ bool translate = h->text_mode==TQImageHandler::TranslateInOut;
+ int fmode = translate ? IO_WriteOnly|IO_Translate : IO_WriteOnly;
+ if ( !file.open(fmode) ) // couldn't create file
+ return FALSE;
+ iodev = TQT_TQIODEVICE(&file);
+ }
+ iostat = 1;
+ (*h->write_image)( this );
+ if ( file.isOpen() ) { // image was written using file
+ file.close();
+ iodev = 0;
+ }
+ return iostat == 0; // image successfully written?
+}
+
+#ifndef TQT_NO_IMAGEIO_BMP
+
+/*****************************************************************************
+ BMP (DIB) image read/write functions
+ *****************************************************************************/
+
+const int BMP_FILEHDR_SIZE = 14; // size of BMP_FILEHDR data
+
+struct BMP_FILEHDR { // BMP file header
+ char bfType[2]; // "BM"
+ TQ_INT32 bfSize; // size of file
+ TQ_INT16 bfReserved1;
+ TQ_INT16 bfReserved2;
+ TQ_INT32 bfOffBits; // pointer to the pixmap bits
+};
+
+TQDataStream &operator>>( TQDataStream &s, BMP_FILEHDR &bf )
+{ // read file header
+ s.readRawBytes( bf.bfType, 2 );
+ s >> bf.bfSize >> bf.bfReserved1 >> bf.bfReserved2 >> bf.bfOffBits;
+ return s;
+}
+
+TQDataStream &operator<<( TQDataStream &s, const BMP_FILEHDR &bf )
+{ // write file header
+ s.writeRawBytes( bf.bfType, 2 );
+ s << bf.bfSize << bf.bfReserved1 << bf.bfReserved2 << bf.bfOffBits;
+ return s;
+}
+
+
+const int BMP_OLD = 12; // old Windows/OS2 BMP size
+const int BMP_WIN = 40; // new Windows BMP size
+const int BMP_OS2 = 64; // new OS/2 BMP size
+
+const int BMP_RGB = 0; // no compression
+const int BMP_RLE8 = 1; // run-length encoded, 8 bits
+const int BMP_RLE4 = 2; // run-length encoded, 4 bits
+const int BMP_BITFIELDS = 3; // RGB values encoded in data as bit-fields
+
+struct BMP_INFOHDR { // BMP information header
+ TQ_INT32 biSize; // size of this struct
+ TQ_INT32 biWidth; // pixmap width
+ TQ_INT32 biHeight; // pixmap height
+ TQ_INT16 biPlanes; // should be 1
+ TQ_INT16 biBitCount; // number of bits per pixel
+ TQ_INT32 biCompression; // compression method
+ TQ_INT32 biSizeImage; // size of image
+ TQ_INT32 biXPelsPerMeter; // horizontal resolution
+ TQ_INT32 biYPelsPerMeter; // vertical resolution
+ TQ_INT32 biClrUsed; // number of colors used
+ TQ_INT32 biClrImportant; // number of important colors
+};
+
+
+TQDataStream &operator>>( TQDataStream &s, BMP_INFOHDR &bi )
+{
+ s >> bi.biSize;
+ if ( bi.biSize == BMP_WIN || bi.biSize == BMP_OS2 ) {
+ s >> bi.biWidth >> bi.biHeight >> bi.biPlanes >> bi.biBitCount;
+ s >> bi.biCompression >> bi.biSizeImage;
+ s >> bi.biXPelsPerMeter >> bi.biYPelsPerMeter;
+ s >> bi.biClrUsed >> bi.biClrImportant;
+ }
+ else { // probably old Windows format
+ TQ_INT16 w, h;
+ s >> w >> h >> bi.biPlanes >> bi.biBitCount;
+ bi.biWidth = w;
+ bi.biHeight = h;
+ bi.biCompression = BMP_RGB; // no compression
+ bi.biSizeImage = 0;
+ bi.biXPelsPerMeter = bi.biYPelsPerMeter = 0;
+ bi.biClrUsed = bi.biClrImportant = 0;
+ }
+ return s;
+}
+
+TQDataStream &operator<<( TQDataStream &s, const BMP_INFOHDR &bi )
+{
+ s << bi.biSize;
+ s << bi.biWidth << bi.biHeight;
+ s << bi.biPlanes;
+ s << bi.biBitCount;
+ s << bi.biCompression;
+ s << bi.biSizeImage;
+ s << bi.biXPelsPerMeter << bi.biYPelsPerMeter;
+ s << bi.biClrUsed << bi.biClrImportant;
+ return s;
+}
+
+static
+int calc_shift(int tqmask)
+{
+ int result = 0;
+ while (!(tqmask & 1)) {
+ result++;
+ tqmask >>= 1;
+ }
+ return result;
+}
+
+static
+bool read_dib( TQDataStream& s, int offset, int startpos, TQImage& image )
+{
+ BMP_INFOHDR bi;
+ TQIODevice* d = s.tqdevice();
+
+ s >> bi; // read BMP info header
+ if ( d->atEnd() ) // end of stream/file
+ return FALSE;
+#if 0
+ qDebug( "offset...........%d", offset );
+ qDebug( "startpos.........%d", startpos );
+ qDebug( "biSize...........%d", bi.biSize );
+ qDebug( "biWidth..........%d", bi.biWidth );
+ qDebug( "biHeight.........%d", bi.biHeight );
+ qDebug( "biPlanes.........%d", bi.biPlanes );
+ qDebug( "biBitCount.......%d", bi.biBitCount );
+ qDebug( "biCompression....%d", bi.biCompression );
+ qDebug( "biSizeImage......%d", bi.biSizeImage );
+ qDebug( "biXPelsPerMeter..%d", bi.biXPelsPerMeter );
+ qDebug( "biYPelsPerMeter..%d", bi.biYPelsPerMeter );
+ qDebug( "biClrUsed........%d", bi.biClrUsed );
+ qDebug( "biClrImportant...%d", bi.biClrImportant );
+#endif
+ int w = bi.biWidth, h = bi.biHeight, nbits = bi.biBitCount;
+ int t = bi.biSize, comp = bi.biCompression;
+ int red_mask, green_mask, blue_mask;
+ int red_shift = 0;
+ int green_shift = 0;
+ int blue_shift = 0;
+ int red_scale = 0;
+ int green_scale = 0;
+ int blue_scale = 0;
+
+ if ( !(nbits == 1 || nbits == 4 || nbits == 8 || nbits == 16 || nbits == 24 || nbits == 32) ||
+ bi.biPlanes != 1 || comp > BMP_BITFIELDS )
+ return FALSE; // weird BMP image
+ if ( !(comp == BMP_RGB || (nbits == 4 && comp == BMP_RLE4) ||
+ (nbits == 8 && comp == BMP_RLE8) || ((nbits == 16 || nbits == 32) && comp == BMP_BITFIELDS)) )
+ return FALSE; // weird compression type
+
+ int ncols;
+ int depth;
+ switch ( nbits ) {
+ case 32:
+ case 24:
+ case 16:
+ depth = 32;
+ break;
+ case 8:
+ case 4:
+ depth = 8;
+ break;
+ default:
+ depth = 1;
+ }
+ if ( depth == 32 ) // there's no colormap
+ ncols = 0;
+ else // # colors used
+ ncols = bi.biClrUsed ? bi.biClrUsed : 1 << nbits;
+
+ image.create( w, h, depth, ncols, nbits == 1 ?
+ TQImage::BigEndian : TQImage::IgnoreEndian );
+ if ( image.isNull() ) // could not create image
+ return FALSE;
+
+ image.setDotsPerMeterX( bi.biXPelsPerMeter );
+ image.setDotsPerMeterY( bi.biYPelsPerMeter );
+
+ d->at( startpos + BMP_FILEHDR_SIZE + bi.biSize ); // goto start of colormap
+
+ if ( ncols > 0 ) { // read color table
+ uchar rgb[4];
+ int rgb_len = t == BMP_OLD ? 3 : 4;
+ for ( int i=0; i<ncols; i++ ) {
+ if ( d->readBlock( (char *)rgb, rgb_len ) != rgb_len )
+ return FALSE;
+ image.setColor( i, tqRgb(rgb[2],rgb[1],rgb[0]) );
+ if ( d->atEnd() ) // truncated file
+ return FALSE;
+ }
+ } else if (comp == BMP_BITFIELDS && (nbits == 16 || nbits == 32)) {
+ if ( (TQ_ULONG)d->readBlock( (char *)&red_mask, sizeof(red_mask) ) != sizeof(red_mask) )
+ return FALSE;
+ if ( (TQ_ULONG)d->readBlock( (char *)&green_mask, sizeof(green_mask) ) != sizeof(green_mask) )
+ return FALSE;
+ if ( (TQ_ULONG)d->readBlock( (char *)&blue_mask, sizeof(blue_mask) ) != sizeof(blue_mask) )
+ return FALSE;
+ red_shift = calc_shift(red_mask);
+ red_scale = 256 / ((red_mask >> red_shift) + 1);
+ green_shift = calc_shift(green_mask);
+ green_scale = 256 / ((green_mask >> green_shift) + 1);
+ blue_shift = calc_shift(blue_mask);
+ blue_scale = 256 / ((blue_mask >> blue_shift) + 1);
+ } else if (comp == BMP_RGB && (nbits == 24 || nbits == 32)) {
+ blue_mask = 0x000000ff;
+ green_mask = 0x0000ff00;
+ red_mask = 0x00ff0000;
+ blue_shift = 0;
+ green_shift = 8;
+ red_shift = 16;
+ blue_scale = green_scale = red_scale = 1;
+ } else if (comp == BMP_RGB && nbits == 16) // don't support RGB values for 15/16 bpp
+ return FALSE;
+
+ // offset can be bogus, be careful
+ if (offset>=0 && startpos + offset > (TQ_LONG)d->at() )
+ d->at( startpos + offset ); // start of image data
+
+ int bpl = image.bytesPerLine();
+#ifdef TQ_WS_TQWS
+ //
+ // Guess the number of bytes-per-line if we don't know how much
+ // image data is in the file (bogus image ?).
+ //
+ int bmpbpl = bi.biSizeImage > 0 ?
+ bi.biSizeImage / bi.biHeight :
+ (d->size() - offset) / bi.biHeight;
+ int pad = bmpbpl-bpl;
+#endif
+ uchar **line = image.jumpTable();
+
+ if ( nbits == 1 ) { // 1 bit BMP image
+ while ( --h >= 0 ) {
+ if ( d->readBlock((char*)line[h],bpl) != bpl )
+ break;
+#ifdef TQ_WS_TQWS
+ if ( pad > 0 )
+ d->at(d->at()+pad);
+#endif
+ }
+ if ( ncols == 2 && tqGray(image.color(0)) < tqGray(image.color(1)) )
+ swapPixel01( &image ); // pixel 0 is white!
+ }
+
+ else if ( nbits == 4 ) { // 4 bit BMP image
+ int buflen = ((w+7)/8)*4;
+ uchar *buf = new uchar[buflen];
+ TQ_CHECK_PTR( buf );
+ if ( comp == BMP_RLE4 ) { // run length compression
+ int x=0, y=0, b, c, i;
+ register uchar *p = line[h-1];
+ uchar *endp = line[h-1]+w;
+ while ( y < h ) {
+ if ( (b=d->getch()) == EOF )
+ break;
+ if ( b == 0 ) { // escape code
+ switch ( (b=d->getch()) ) {
+ case 0: // end of line
+ x = 0;
+ y++;
+ p = line[h-y-1];
+ break;
+ case 1: // end of image
+ case EOF: // end of file
+ y = h; // exit loop
+ break;
+ case 2: // delta (jump)
+ x += d->getch();
+ y += d->getch();
+
+ // Protection
+ if ( (uint)x >= (uint)w )
+ x = w-1;
+ if ( (uint)y >= (uint)h )
+ y = h-1;
+
+ p = line[h-y-1] + x;
+ break;
+ default: // absolute mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ i = (c = b)/2;
+ while ( i-- ) {
+ b = d->getch();
+ *p++ = b >> 4;
+ *p++ = b & 0x0f;
+ }
+ if ( c & 1 )
+ *p++ = d->getch() >> 4;
+ if ( (((c & 3) + 1) & 2) == 2 )
+ d->getch(); // align on word boundary
+ x += c;
+ }
+ } else { // encoded mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ i = (c = b)/2;
+ b = d->getch(); // 2 pixels to be repeated
+ while ( i-- ) {
+ *p++ = b >> 4;
+ *p++ = b & 0x0f;
+ }
+ if ( c & 1 )
+ *p++ = b >> 4;
+ x += c;
+ }
+ }
+ } else if ( comp == BMP_RGB ) { // no compression
+ while ( --h >= 0 ) {
+ if ( d->readBlock((char*)buf,buflen) != buflen )
+ break;
+ register uchar *p = line[h];
+ uchar *b = buf;
+ for ( int i=0; i<w/2; i++ ) { // convert nibbles to bytes
+ *p++ = *b >> 4;
+ *p++ = *b++ & 0x0f;
+ }
+ if ( w & 1 ) // the last nibble
+ *p = *b >> 4;
+ }
+ }
+ delete [] buf;
+ }
+
+ else if ( nbits == 8 ) { // 8 bit BMP image
+ if ( comp == BMP_RLE8 ) { // run length compression
+ int x=0, y=0, b;
+ register uchar *p = line[h-1];
+ const uchar *endp = line[h-1]+w;
+ while ( y < h ) {
+ if ( (b=d->getch()) == EOF )
+ break;
+ if ( b == 0 ) { // escape code
+ switch ( (b=d->getch()) ) {
+ case 0: // end of line
+ x = 0;
+ y++;
+ p = line[h-y-1];
+ break;
+ case 1: // end of image
+ case EOF: // end of file
+ y = h; // exit loop
+ break;
+ case 2: // delta (jump)
+ x += d->getch();
+ y += d->getch();
+
+ // Protection
+ if ( (uint)x >= (uint)w )
+ x = w-1;
+ if ( (uint)y >= (uint)h )
+ y = h-1;
+
+ p = line[h-y-1] + x;
+ break;
+ default: // absolute mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ if ( d->readBlock( (char *)p, b ) != b )
+ return FALSE;
+ if ( (b & 1) == 1 )
+ d->getch(); // align on word boundary
+ x += b;
+ p += b;
+ }
+ } else { // encoded mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ memset( p, d->getch(), b ); // repeat pixel
+ x += b;
+ p += b;
+ }
+ }
+ } else if ( comp == BMP_RGB ) { // uncompressed
+ while ( --h >= 0 ) {
+ if ( d->readBlock((char *)line[h],bpl) != bpl )
+ break;
+#ifdef TQ_WS_TQWS
+ if ( pad > 0 )
+ d->at(d->at()+pad);
+#endif
+ }
+ }
+ }
+
+ else if ( nbits == 16 || nbits == 24 || nbits == 32 ) { // 16,24,32 bit BMP image
+ register TQRgb *p;
+ TQRgb *end;
+ uchar *buf24 = new uchar[bpl];
+ int bpl24 = ((w*nbits+31)/32)*4;
+ uchar *b;
+ int c;
+
+ while ( --h >= 0 ) {
+ p = (TQRgb *)line[h];
+ end = p + w;
+ if ( d->readBlock( (char *)buf24,bpl24) != bpl24 )
+ break;
+ b = buf24;
+ while ( p < end ) {
+ c = *(uchar*)b | (*(uchar*)(b+1)<<8);
+ if (nbits != 16)
+ c |= *(uchar*)(b+2)<<16;
+ *p++ = tqRgb(((c & red_mask) >> red_shift) * red_scale,
+ ((c & green_mask) >> green_shift) * green_scale,
+ ((c & blue_mask) >> blue_shift) * blue_scale);
+ b += nbits/8;
+ }
+ }
+ delete[] buf24;
+ }
+
+ return TRUE;
+}
+
+bool qt_read_dib( TQDataStream& s, TQImage& image )
+{
+ return read_dib(s,-1,-BMP_FILEHDR_SIZE,image);
+}
+
+
+static void read_bmp_image( TQImageIO *iio )
+{
+ TQIODevice *d = iio->ioDevice();
+ TQDataStream s( d );
+ BMP_FILEHDR bf;
+ int startpos = d->at();
+
+ s.setByteOrder( TQDataStream::LittleEndian );// Intel byte order
+ s >> bf; // read BMP file header
+
+ if ( tqstrncmp(bf.bfType,"BM",2) != 0 ) // not a BMP image
+ return;
+
+ TQImage image;
+ if (read_dib( s, bf.bfOffBits, startpos, image )) {
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+ }
+}
+
+bool qt_write_dib( TQDataStream& s, TQImage image )
+{
+ int nbits;
+ int bpl_bmp;
+ int bpl = image.bytesPerLine();
+
+ TQIODevice* d = s.tqdevice();
+
+ if ( image.depth() == 8 && image.numColors() <= 16 ) {
+ bpl_bmp = (((bpl+1)/2+3)/4)*4;
+ nbits = 4;
+ } else if ( image.depth() == 32 ) {
+ bpl_bmp = ((image.width()*24+31)/32)*4;
+ nbits = 24;
+#ifdef TQ_WS_TQWS
+ } else if ( image.depth() == 1 || image.depth() == 8 ) {
+ // TQt/E doesn't word align.
+ bpl_bmp = ((image.width()*image.depth()+31)/32)*4;
+ nbits = image.depth();
+#endif
+ } else {
+ bpl_bmp = bpl;
+ nbits = image.depth();
+ }
+
+ BMP_INFOHDR bi;
+ bi.biSize = BMP_WIN; // build info header
+ bi.biWidth = image.width();
+ bi.biHeight = image.height();
+ bi.biPlanes = 1;
+ bi.biBitCount = nbits;
+ bi.biCompression = BMP_RGB;
+ bi.biSizeImage = bpl_bmp*image.height();
+ bi.biXPelsPerMeter = image.dotsPerMeterX() ? image.dotsPerMeterX()
+ : 2834; // 72 dpi default
+ bi.biYPelsPerMeter = image.dotsPerMeterY() ? image.dotsPerMeterY() : 2834;
+ bi.biClrUsed = image.numColors();
+ bi.biClrImportant = image.numColors();
+ s << bi; // write info header
+
+ if ( image.depth() != 32 ) { // write color table
+ uchar *color_table = new uchar[4*image.numColors()];
+ uchar *rgb = color_table;
+ TQRgb *c = image.tqcolorTable();
+ for ( int i=0; i<image.numColors(); i++ ) {
+ *rgb++ = tqBlue ( c[i] );
+ *rgb++ = tqGreen( c[i] );
+ *rgb++ = tqRed ( c[i] );
+ *rgb++ = 0;
+ }
+ d->writeBlock( (char *)color_table, 4*image.numColors() );
+ delete [] color_table;
+ }
+
+ if ( image.depth() == 1 && image.bitOrder() != TQImage::BigEndian )
+ image = image.convertBitOrder( TQImage::BigEndian );
+
+ int y;
+
+ if ( nbits == 1 || nbits == 8 ) { // direct output
+#ifdef TQ_WS_TQWS
+ // TQt/E doesn't word align.
+ int pad = bpl_bmp - bpl;
+ char padding[4];
+#endif
+ for ( y=image.height()-1; y>=0; y-- ) {
+ d->writeBlock( (char*)image.scanLine(y), bpl );
+#ifdef TQ_WS_TQWS
+ d->writeBlock( padding, pad );
+#endif
+ }
+ return TRUE;
+ }
+
+ uchar *buf = new uchar[bpl_bmp];
+ uchar *b, *end;
+ register uchar *p;
+
+ memset( buf, 0, bpl_bmp );
+ for ( y=image.height()-1; y>=0; y-- ) { // write the image bits
+ if ( nbits == 4 ) { // convert 8 -> 4 bits
+ p = image.scanLine(y);
+ b = buf;
+ end = b + image.width()/2;
+ while ( b < end ) {
+ *b++ = (*p << 4) | (*(p+1) & 0x0f);
+ p += 2;
+ }
+ if ( image.width() & 1 )
+ *b = *p << 4;
+ } else { // 32 bits
+ TQRgb *p = (TQRgb *)image.scanLine( y );
+ TQRgb *end = p + image.width();
+ b = buf;
+ while ( p < end ) {
+ *b++ = tqBlue(*p);
+ *b++ = tqGreen(*p);
+ *b++ = tqRed(*p);
+ p++;
+ }
+ }
+ if ( bpl_bmp != d->writeBlock( (char*)buf, bpl_bmp ) ) {
+ delete[] buf;
+ return FALSE;
+ }
+ }
+ delete[] buf;
+ return TRUE;
+}
+
+
+static void write_bmp_image( TQImageIO *iio )
+{
+ TQIODevice *d = iio->ioDevice();
+ TQImage image = iio->image();
+ TQDataStream s( d );
+ BMP_FILEHDR bf;
+ int bpl_bmp;
+ int bpl = image.bytesPerLine();
+
+ // Code partially repeated in qt_write_dib
+ if ( image.depth() == 8 && image.numColors() <= 16 ) {
+ bpl_bmp = (((bpl+1)/2+3)/4)*4;
+ } else if ( image.depth() == 32 ) {
+ bpl_bmp = ((image.width()*24+31)/32)*4;
+ } else {
+ bpl_bmp = bpl;
+ }
+
+ iio->setqStatus( 0 );
+ s.setByteOrder( TQDataStream::LittleEndian );// Intel byte order
+ strncpy( bf.bfType, "BM", 2 ); // build file header
+ bf.bfReserved1 = bf.bfReserved2 = 0; // reserved, should be zero
+ bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.numColors()*4;
+ bf.bfSize = bf.bfOffBits + bpl_bmp*image.height();
+ s << bf; // write file header
+
+ if ( !qt_write_dib( s, image ) )
+ iio->setqStatus( 1 );
+
+}
+
+#endif // TQT_NO_IMAGEIO_BMP
+
+#ifndef TQT_NO_IMAGEIO_PPM
+
+/*****************************************************************************
+ PBM/PGM/PPM (ASCII and RAW) image read/write functions
+ *****************************************************************************/
+
+static int read_pbm_int( TQIODevice *d )
+{
+ int c;
+ int val = -1;
+ bool digit;
+ const int buflen = 100;
+ char buf[buflen];
+ for ( ;; ) {
+ if ( (c=d->getch()) == EOF ) // end of file
+ break;
+ digit = isdigit( (uchar) c );
+ if ( val != -1 ) {
+ if ( digit ) {
+ val = 10*val + c - '0';
+ continue;
+ } else {
+ if ( c == '#' ) // comment
+ d->readLine( buf, buflen );
+ break;
+ }
+ }
+ if ( digit ) // first digit
+ val = c - '0';
+ else if ( isspace((uchar) c) )
+ continue;
+ else if ( c == '#' )
+ d->readLine( buf, buflen );
+ else
+ break;
+ }
+ return val;
+}
+
+static void read_pbm_image( TQImageIO *iio ) // read PBM image data
+{
+ const int buflen = 300;
+ char buf[buflen];
+ TQIODevice *d = iio->ioDevice();
+ int w, h, nbits, mcc, y;
+ int pbm_bpl;
+ char type;
+ bool raw;
+ TQImage image;
+
+ if ( d->readBlock( buf, 3 ) != 3 ) // read P[1-6]<white-space>
+ return;
+ if ( !(buf[0] == 'P' && isdigit((uchar) buf[1]) && isspace((uchar) buf[2])) )
+ return;
+ switch ( (type=buf[1]) ) {
+ case '1': // ascii PBM
+ case '4': // raw PBM
+ nbits = 1;
+ break;
+ case '2': // ascii PGM
+ case '5': // raw PGM
+ nbits = 8;
+ break;
+ case '3': // ascii PPM
+ case '6': // raw PPM
+ nbits = 32;
+ break;
+ default:
+ return;
+ }
+ raw = type >= '4';
+ w = read_pbm_int( d ); // get image width
+ h = read_pbm_int( d ); // get image height
+ if ( nbits == 1 )
+ mcc = 1; // ignore max color component
+ else
+ mcc = read_pbm_int( d ); // get max color component
+ if ( w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0 )
+ return; // weird P.M image
+
+ int maxc = mcc;
+ if ( maxc > 255 )
+ maxc = 255;
+ image.create( w, h, nbits, 0,
+ nbits == 1 ? TQImage::BigEndian : TQImage::IgnoreEndian );
+ if ( image.isNull() )
+ return;
+
+ pbm_bpl = (nbits*w+7)/8; // bytes per scanline in PBM
+
+ if ( raw ) { // read raw data
+ if ( nbits == 32 ) { // type 6
+ pbm_bpl = 3*w;
+ uchar *buf24 = new uchar[pbm_bpl], *b;
+ TQRgb *p;
+ TQRgb *end;
+ for ( y=0; y<h; y++ ) {
+ if ( d->readBlock( (char *)buf24, pbm_bpl ) != pbm_bpl ) {
+ delete[] buf24;
+ return;
+ }
+ p = (TQRgb *)image.scanLine( y );
+ end = p + w;
+ b = buf24;
+ while ( p < end ) {
+ *p++ = tqRgb(b[0],b[1],b[2]);
+ b += 3;
+ }
+ }
+ delete[] buf24;
+ } else { // type 4,5
+ for ( y=0; y<h; y++ ) {
+ if ( d->readBlock( (char *)image.scanLine(y), pbm_bpl )
+ != pbm_bpl )
+ return;
+ }
+ }
+ } else { // read ascii data
+ register uchar *p;
+ int n;
+ for ( y=0; y<h; y++ ) {
+ p = image.scanLine( y );
+ n = pbm_bpl;
+ if ( nbits == 1 ) {
+ int b;
+ while ( n-- ) {
+ b = 0;
+ for ( int i=0; i<8; i++ )
+ b = (b << 1) | (read_pbm_int(d) & 1);
+ *p++ = b;
+ }
+ } else if ( nbits == 8 ) {
+ if ( mcc == maxc ) {
+ while ( n-- ) {
+ *p++ = read_pbm_int( d );
+ }
+ } else {
+ while ( n-- ) {
+ *p++ = read_pbm_int( d ) * maxc / mcc;
+ }
+ }
+ } else { // 32 bits
+ n /= 4;
+ int r, g, b;
+ if ( mcc == maxc ) {
+ while ( n-- ) {
+ r = read_pbm_int( d );
+ g = read_pbm_int( d );
+ b = read_pbm_int( d );
+ *((TQRgb*)p) = tqRgb( r, g, b );
+ p += 4;
+ }
+ } else {
+ while ( n-- ) {
+ r = read_pbm_int( d ) * maxc / mcc;
+ g = read_pbm_int( d ) * maxc / mcc;
+ b = read_pbm_int( d ) * maxc / mcc;
+ *((TQRgb*)p) = tqRgb( r, g, b );
+ p += 4;
+ }
+ }
+ }
+ }
+ }
+
+ if ( nbits == 1 ) { // bitmap
+ image.setNumColors( 2 );
+ image.setColor( 0, tqRgb(255,255,255) ); // white
+ image.setColor( 1, tqRgb(0,0,0) ); // black
+ } else if ( nbits == 8 ) { // graymap
+ image.setNumColors( maxc+1 );
+ for ( int i=0; i<=maxc; i++ )
+ image.setColor( i, tqRgb(i*255/maxc,i*255/maxc,i*255/maxc) );
+ }
+
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+}
+
+
+static void write_pbm_image( TQImageIO *iio )
+{
+ TQIODevice* out = iio->ioDevice();
+ TQCString str;
+
+ TQImage image = iio->image();
+ TQCString format = iio->format();
+ format = format.left(3); // ignore RAW part
+ bool gray = format == "PGM";
+
+ if ( format == "PBM" ) {
+ image = image.convertDepth(1);
+ } else if ( image.depth() == 1 ) {
+ image = image.convertDepth(8);
+ }
+
+ if ( image.depth() == 1 && image.numColors() == 2 ) {
+ if ( tqGray(image.color(0)) < tqGray(image.color(1)) ) {
+ // 0=dark/black, 1=light/white - invert
+ image.detach();
+ for ( int y=0; y<image.height(); y++ ) {
+ uchar *p = image.scanLine(y);
+ uchar *end = p + image.bytesPerLine();
+ while ( p < end )
+ *p++ ^= 0xff;
+ }
+ }
+ }
+
+ uint w = image.width();
+ uint h = image.height();
+
+ str.sprintf("P\n%d %d\n", w, h);
+
+ switch (image.depth()) {
+ case 1: {
+ str.insert(1, '4');
+ if ((uint)out->writeBlock(str, str.length()) != str.length()) {
+ iio->setqStatus(1);
+ return;
+ }
+ w = (w+7)/8;
+ for (uint y=0; y<h; y++) {
+ uchar* line = image.scanLine(y);
+ if ( w != (uint)out->writeBlock((char*)line, w) ) {
+ iio->setqStatus(1);
+ return;
+ }
+ }
+ }
+ break;
+
+ case 8: {
+ str.insert(1, gray ? '5' : '6');
+ str.append("255\n");
+ if ((uint)out->writeBlock(str, str.length()) != str.length()) {
+ iio->setqStatus(1);
+ return;
+ }
+ TQRgb *color = image.tqcolorTable();
+ uint bpl = w*(gray ? 1 : 3);
+ uchar *buf = new uchar[bpl];
+ for (uint y=0; y<h; y++) {
+ uchar *b = image.scanLine(y);
+ uchar *p = buf;
+ uchar *end = buf+bpl;
+ if ( gray ) {
+ while ( p < end ) {
+ uchar g = (uchar)tqGray(color[*b++]);
+ *p++ = g;
+ }
+ } else {
+ while ( p < end ) {
+ TQRgb rgb = color[*b++];
+ *p++ = tqRed(rgb);
+ *p++ = tqGreen(rgb);
+ *p++ = tqBlue(rgb);
+ }
+ }
+ if ( bpl != (uint)out->writeBlock((char*)buf, bpl) ) {
+ iio->setqStatus(1);
+ return;
+ }
+ }
+ delete [] buf;
+ }
+ break;
+
+ case 32: {
+ str.insert(1, gray ? '5' : '6');
+ str.append("255\n");
+ if ((uint)out->writeBlock(str, str.length()) != str.length()) {
+ iio->setqStatus(1);
+ return;
+ }
+ uint bpl = w*(gray ? 1 : 3);
+ uchar *buf = new uchar[bpl];
+ for (uint y=0; y<h; y++) {
+ TQRgb *b = (TQRgb*)image.scanLine(y);
+ uchar *p = buf;
+ uchar *end = buf+bpl;
+ if ( gray ) {
+ while ( p < end ) {
+ uchar g = (uchar)tqGray(*b++);
+ *p++ = g;
+ }
+ } else {
+ while ( p < end ) {
+ TQRgb rgb = *b++;
+ *p++ = tqRed(rgb);
+ *p++ = tqGreen(rgb);
+ *p++ = tqBlue(rgb);
+ }
+ }
+ if ( bpl != (uint)out->writeBlock((char*)buf, bpl) ) {
+ iio->setqStatus(1);
+ return;
+ }
+ }
+ delete [] buf;
+ }
+ }
+
+ iio->setqStatus(0);
+}
+
+#endif // TQT_NO_IMAGEIO_PPM
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+
+class TQImageIOFrameGrabber : public TQImageConsumer {
+public:
+ TQImageIOFrameGrabber() : framecount(0) { }
+
+ TQImageDecoder *decoder;
+ int framecount;
+
+ void changed(const TQRect&) { }
+ void end() { }
+ void frameDone(const TQPoint&, const TQRect&) { framecount++; }
+ void frameDone() { framecount++; }
+ void setLooping(int) { }
+ void setFramePeriod(int) { }
+ void setSize(int, int) { }
+};
+
+static void read_async_image( TQImageIO *iio )
+{
+ const int buf_len = 2048;
+ uchar buffer[buf_len];
+ TQIODevice *d = iio->ioDevice();
+ TQImageIOFrameGrabber* consumer = new TQImageIOFrameGrabber();
+ TQImageDecoder *decoder = new TQImageDecoder(consumer);
+ consumer->decoder = decoder;
+ int startAt = d->at();
+ int totLen = 0;
+
+ for (;;) {
+ int length = d->readBlock((char*)buffer, buf_len);
+ if ( length <= 0 ) {
+ iio->setqStatus(length);
+ break;
+ }
+ uchar* b = buffer;
+ int r = -1;
+ while (length > 0 && consumer->framecount==0) {
+ r = decoder->decode(b, length);
+ if ( r <= 0 ) break;
+ b += r;
+ totLen += r;
+ length -= r;
+ }
+ if ( consumer->framecount ) {
+ // Stopped after first frame
+ if ( d->isDirectAccess() )
+ d->at( startAt + totLen );
+ else {
+ // ### We have (probably) read too much from the stream into
+ // the buffer, and there is no way to put it back!
+ }
+ iio->setImage(decoder->image());
+ iio->setqStatus(0);
+ break;
+ }
+ if ( r <= 0 ) {
+ iio->setqStatus(r);
+ break;
+ }
+ }
+
+ consumer->decoder = 0;
+ delete decoder;
+ delete consumer;
+}
+
+#endif // TQT_NO_ASYNC_IMAGE_IO
+
+#ifndef TQT_NO_IMAGEIO_XBM
+
+/*****************************************************************************
+ X bitmap image read/write functions
+ *****************************************************************************/
+
+static inline int hex2byte( register char *p )
+{
+ return ( (isdigit((uchar) *p) ? *p - '0' : toupper((uchar) *p) - 'A' + 10) << 4 ) |
+ ( isdigit((uchar) *(p+1)) ? *(p+1) - '0' : toupper((uchar) *(p+1)) - 'A' + 10 );
+}
+
+static void read_xbm_image( TQImageIO *iio )
+{
+ const int buflen = 300;
+ char buf[buflen];
+ TQRegExp r1, r2;
+ TQIODevice *d = iio->ioDevice();
+ int w=-1, h=-1;
+ TQImage image;
+
+ r1 = TQString::tqfromLatin1("^#define[ \t]+[a-zA-Z0-9._]+[ \t]+");
+ r2 = TQString::tqfromLatin1("[0-9]+");
+ d->readLine( buf, buflen ); // "#define .._width <num>"
+
+ while (!d->atEnd() && buf[0] != '#') //skip leading comment, if any
+ d->readLine( buf, buflen );
+
+ TQString sbuf;
+ sbuf = TQString::tqfromLatin1(buf);
+
+ if ( r1.search(sbuf) == 0 &&
+ r2.search(sbuf, r1.matchedLength()) == r1.matchedLength() )
+ w = atoi( &buf[r1.matchedLength()] );
+
+ d->readLine( buf, buflen ); // "#define .._height <num>"
+ sbuf = TQString::tqfromLatin1(buf);
+
+ if ( r1.search(sbuf) == 0 &&
+ r2.search(sbuf, r1.matchedLength()) == r1.matchedLength() )
+ h = atoi( &buf[r1.matchedLength()] );
+
+ if ( w <= 0 || w > 32767 || h <= 0 || h > 32767 )
+ return; // format error
+
+ for ( ;; ) { // scan for data
+ if ( d->readLine(buf, buflen) <= 0 ) // end of file
+ return;
+ if ( strstr(buf,"0x") != 0 ) // does line contain data?
+ break;
+ }
+
+ image.create( w, h, 1, 2, TQImage::LittleEndian );
+ if ( image.isNull() )
+ return;
+
+ image.setColor( 0, tqRgb(255,255,255) ); // white
+ image.setColor( 1, tqRgb(0,0,0) ); // black
+
+ int x = 0, y = 0;
+ uchar *b = image.scanLine(0);
+ char *p = strstr( buf, "0x" );
+ w = (w+7)/8; // byte width
+
+ while ( y < h ) { // for all encoded bytes...
+ if ( p ) { // p = "0x.."
+ *b++ = hex2byte(p+2);
+ p += 2;
+ if ( ++x == w && ++y < h ) {
+ b = image.scanLine(y);
+ x = 0;
+ }
+ p = strstr( p, "0x" );
+ } else { // read another line
+ if ( d->readLine(buf,buflen) <= 0 ) // EOF ==> truncated image
+ break;
+ p = strstr( buf, "0x" );
+ }
+ }
+
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+}
+
+
+static void write_xbm_image( TQImageIO *iio )
+{
+ TQIODevice *d = iio->ioDevice();
+ TQImage image = iio->image();
+ int w = image.width();
+ int h = image.height();
+ int i;
+ TQString s = fbname(iio->fileName()); // get file base name
+ char *buf = new char[s.length() + 100];
+
+ sprintf( buf, "#define %s_width %d\n", s.ascii(), w );
+ d->writeBlock( buf, tqstrlen(buf) );
+ sprintf( buf, "#define %s_height %d\n", s.ascii(), h );
+ d->writeBlock( buf, tqstrlen(buf) );
+ sprintf( buf, "static char %s_bits[] = {\n ", s.ascii() );
+ d->writeBlock( buf, tqstrlen(buf) );
+
+ iio->setqStatus( 0 );
+
+ if ( image.depth() != 1 )
+ image = image.convertDepth( 1 ); // dither
+ if ( image.bitOrder() != TQImage::LittleEndian )
+ image = image.convertBitOrder( TQImage::LittleEndian );
+
+ bool invert = tqGray(image.color(0)) < tqGray(image.color(1));
+ char hexrep[16];
+ for ( i=0; i<10; i++ )
+ hexrep[i] = '0' + i;
+ for ( i=10; i<16; i++ )
+ hexrep[i] = 'a' -10 + i;
+ if ( invert ) {
+ char t;
+ for ( i=0; i<8; i++ ) {
+ t = hexrep[15-i];
+ hexrep[15-i] = hexrep[i];
+ hexrep[i] = t;
+ }
+ }
+ int bcnt = 0;
+ register char *p = buf;
+ int bpl = (w+7)/8;
+ for (int y = 0; y < h; ++y) {
+ uchar *b = image.scanLine(y);
+ for (i = 0; i < bpl; ++i) {
+ *p++ = '0'; *p++ = 'x';
+ *p++ = hexrep[*b >> 4];
+ *p++ = hexrep[*b++ & 0xf];
+
+ if ( i < bpl - 1 || y < h - 1 ) {
+ *p++ = ',';
+ if ( ++bcnt > 14 ) {
+ *p++ = '\n';
+ *p++ = ' ';
+ *p = '\0';
+ if ( (int)tqstrlen(buf) != d->writeBlock( buf, tqstrlen(buf) ) ) {
+ iio->setqStatus( 1 );
+ delete [] buf;
+ return;
+ }
+ p = buf;
+ bcnt = 0;
+ }
+ }
+ }
+ }
+ strcpy( p, " };\n" );
+ if ( (int)tqstrlen(buf) != d->writeBlock( buf, tqstrlen(buf) ) )
+ iio->setqStatus( 1 );
+ delete [] buf;
+}
+
+#endif // TQT_NO_IMAGEIO_XBM
+
+
+#ifndef TQT_NO_IMAGEIO_XPM
+
+/*****************************************************************************
+ XPM image read/write functions
+ *****************************************************************************/
+
+
+// Skip until ", read until the next ", return the rest in *buf
+// Returns FALSE on error, TRUE on success
+
+static bool read_xpm_string( TQCString &buf, TQIODevice *d,
+ const char * const *source, int &index )
+{
+ if ( source ) {
+ buf = source[index++];
+ return TRUE;
+ }
+
+ if ( buf.size() < 69 ) //# just an approximation
+ buf.resize( 123 );
+
+ buf[0] = '\0';
+ int c;
+ int i;
+ while ( (c=d->getch()) != EOF && c != '"' ) { }
+ if ( c == EOF ) {
+ return FALSE;
+ }
+ i = 0;
+ while ( (c=d->getch()) != EOF && c != '"' ) {
+ if ( i == (int)buf.size() )
+ buf.resize( i*2+42 );
+ buf[i++] = c;
+ }
+ if ( c == EOF ) {
+ return FALSE;
+ }
+
+ if ( i == (int)buf.size() ) // always use a 0 terminator
+ buf.resize( i+1 );
+ buf[i] = '\0';
+ return TRUE;
+}
+
+
+
+static int nextColorSpec(const TQCString & buf)
+{
+ int i = buf.tqfind(" c ");
+ if (i < 0)
+ i = buf.tqfind(" g ");
+ if (i < 0)
+ i = buf.tqfind(" g4 ");
+ if (i < 0)
+ i = buf.tqfind(" m ");
+ if (i < 0)
+ i = buf.tqfind(" s ");
+ return i;
+}
+
+//
+// INTERNAL
+//
+// Reads an .xpm from either the TQImageIO or from the TQString *.
+// One of the two HAS to be 0, the other one is used.
+//
+
+static void read_xpm_image_or_array( TQImageIO * iio, const char * const * source,
+ TQImage & image)
+{
+ TQCString buf;
+ TQIODevice *d = 0;
+ buf.resize( 200 );
+
+ int i, cpp, ncols, w, h, index = 0;
+
+ if ( iio ) {
+ iio->setqStatus( 1 );
+ d = iio ? iio->ioDevice() : 0;
+ d->readLine( buf.data(), buf.size() ); // "/* XPM */"
+ TQRegExp r( TQString::tqfromLatin1("/\\*.XPM.\\*/") );
+ if ( buf.tqfind(r) == -1 )
+ return; // bad magic
+ } else if ( !source ) {
+ return;
+ }
+
+ if ( !read_xpm_string( buf, d, source, index ) )
+ return;
+
+ if ( sscanf( buf, "%d %d %d %d", &w, &h, &ncols, &cpp ) < 4 )
+ return; // < 4 numbers parsed
+
+ if ( cpp > 15 )
+ return;
+
+ if ( ncols > 256 ) {
+ image.create( w, h, 32 );
+ } else {
+ image.create( w, h, 8, ncols );
+ }
+
+ if (image.isNull())
+ return;
+
+ TQMap<TQString, int> colorMap;
+ int currentColor;
+
+ for( currentColor=0; currentColor < ncols; ++currentColor ) {
+ if ( !read_xpm_string( buf, d, source, index ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage: XPM color specification missing");
+#endif
+ return;
+ }
+ TQString index;
+ index = buf.left( cpp );
+ buf = buf.mid( cpp ).simplifyWhiteSpace().lower();
+ buf.prepend( " " );
+ i = nextColorSpec(buf);
+ if ( i < 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage: XPM color specification is missing: %s", buf.data());
+#endif
+ return; // no c/g/g4/m/s specification at all
+ }
+ buf = buf.mid( i+3 );
+ // Strip any other colorspec
+ int end = nextColorSpec(buf);
+ if (end != -1)
+ buf.truncate(end);
+ buf = buf.stripWhiteSpace();
+ if ( buf == "none" ) {
+ image.setAlphaBuffer( TRUE );
+ int transparentColor = currentColor;
+ if ( image.depth() == 8 ) {
+ image.setColor( transparentColor,
+ TQRGB_MASK & tqRgb(198,198,198) );
+ colorMap.insert( index, transparentColor );
+ } else {
+ TQRgb rgb = TQRGB_MASK & tqRgb(198,198,198);
+ colorMap.insert( index, rgb );
+ }
+ } else {
+ if ( ((buf.length()-1) % 3) && (buf[0] == '#') ) {
+ buf.truncate (((buf.length()-1) / 4 * 3) + 1); // remove alpha channel left by imagemagick
+ }
+ TQColor c( buf.data() );
+ if ( image.depth() == 8 ) {
+ image.setColor( currentColor, 0xff000000 | c.rgb() );
+ colorMap.insert( index, currentColor );
+ } else {
+ TQRgb rgb = 0xff000000 | c.rgb();
+ colorMap.insert( index, rgb );
+ }
+ }
+ }
+
+ // Read pixels
+ for( int y=0; y<h; y++ ) {
+ if ( !read_xpm_string( buf, d, source, index ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage: XPM pixels missing on image line %d", y);
+#endif
+ return;
+ }
+ if ( image.depth() == 8 ) {
+ uchar *p = image.scanLine(y);
+ uchar *d = (uchar *)buf.data();
+ uchar *end = d + buf.length();
+ int x;
+ if ( cpp == 1 ) {
+ char b[2];
+ b[1] = '\0';
+ for ( x=0; x<w && d<end; x++ ) {
+ b[0] = *d++;
+ *p++ = (uchar)colorMap[b];
+ }
+ } else {
+ char b[16];
+ b[cpp] = '\0';
+ for ( x=0; x<w && d<end; x++ ) {
+ strncpy( b, (char *)d, cpp );
+ *p++ = (uchar)colorMap[b];
+ d += cpp;
+ }
+ }
+ } else {
+ TQRgb *p = (TQRgb*)image.scanLine(y);
+ uchar *d = (uchar *)buf.data();
+ uchar *end = d + buf.length();
+ int x;
+ char b[16];
+ b[cpp] = '\0';
+ for ( x=0; x<w && d<end; x++ ) {
+ strncpy( b, (char *)d, cpp );
+ *p++ = (TQRgb)colorMap[b];
+ d += cpp;
+ }
+ }
+ }
+ if ( iio ) {
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+ }
+}
+
+
+static void read_xpm_image( TQImageIO * iio )
+{
+ TQImage i;
+ (void)read_xpm_image_or_array( iio, 0, i );
+ return;
+}
+
+
+static const char* xpm_color_name( int cpp, int index )
+{
+ static char returnable[5];
+ static const char code[] = ".#abcdefghijklmnopqrstuvwxyzABCD"
+ "EFGHIJKLMNOPTQRSTUVWXYZ0123456789";
+ // cpp is limited to 4 and index is limited to 64^cpp
+ if ( cpp > 1 ) {
+ if ( cpp > 2 ) {
+ if ( cpp > 3 ) {
+ returnable[3] = code[index % 64];
+ index /= 64;
+ } else
+ returnable[3] = '\0';
+ returnable[2] = code[index % 64];
+ index /= 64;
+ } else
+ returnable[2] = '\0';
+ // the following 4 lines are a joke!
+ if ( index == 0 )
+ index = 64*44+21;
+ else if ( index == 64*44+21 )
+ index = 0;
+ returnable[1] = code[index % 64];
+ index /= 64;
+ } else
+ returnable[1] = '\0';
+ returnable[0] = code[index];
+
+ return returnable;
+}
+
+
+// write XPM image data
+static void write_xpm_image( TQImageIO * iio )
+{
+ if ( iio )
+ iio->setqStatus( 1 );
+ else
+ return;
+
+ // ### 8-bit case could be made faster
+ TQImage image;
+ if ( iio->image().depth() != 32 )
+ image = iio->image().convertDepth( 32 );
+ else
+ image = iio->image();
+
+ TQMap<TQRgb, int> colorMap;
+
+ int w = image.width(), h = image.height(), ncolors = 0;
+ int x, y;
+
+ // build color table
+ for( y=0; y<h; y++ ) {
+ TQRgb * yp = (TQRgb *)image.scanLine( y );
+ for( x=0; x<w; x++ ) {
+ TQRgb color = *(yp + x);
+ if ( !colorMap.tqcontains(color) )
+ colorMap.insert( color, ncolors++ );
+ }
+ }
+
+ // number of 64-bit characters per pixel needed to encode all colors
+ int cpp = 1;
+ for ( int k = 64; ncolors > k; k *= 64 ) {
+ ++cpp;
+ // limit to 4 characters per pixel
+ // 64^4 colors is enough for a 4096x4096 image
+ if ( cpp > 4)
+ break;
+ }
+
+ TQString line;
+
+ // write header
+ TQTextStream s( iio->ioDevice() );
+ s << "/* XPM */" << endl
+ << "static char *" << fbname(iio->fileName()) << "[]={" << endl
+ << "\"" << w << " " << h << " " << ncolors << " " << cpp << "\"";
+
+ // write palette
+ TQMap<TQRgb, int>::Iterator c = colorMap.begin();
+ while ( c != colorMap.end() ) {
+ TQRgb color = c.key();
+ if ( image.hasAlphaBuffer() && color == (color & TQRGB_MASK) )
+ line.sprintf( "\"%s c None\"",
+ xpm_color_name(cpp, *c) );
+ else
+ line.sprintf( "\"%s c #%02x%02x%02x\"",
+ xpm_color_name(cpp, *c),
+ tqRed(color),
+ tqGreen(color),
+ tqBlue(color) );
+ ++c;
+ s << "," << endl << line;
+ }
+
+ // write pixels, limit to 4 characters per pixel
+ line.truncate( cpp*w );
+ for( y=0; y<h; y++ ) {
+ TQRgb * yp = (TQRgb *) image.scanLine( y );
+ int cc = 0;
+ for( x=0; x<w; x++ ) {
+ int color = (int)(*(yp + x));
+ TQCString chars = xpm_color_name( cpp, colorMap[color] );
+ line[cc++] = chars[0];
+ if ( cpp > 1 ) {
+ line[cc++] = chars[1];
+ if ( cpp > 2 ) {
+ line[cc++] = chars[2];
+ if ( cpp > 3 ) {
+ line[cc++] = chars[3];
+ }
+ }
+ }
+ }
+ s << "," << endl << "\"" << line << "\"";
+ }
+ s << "};" << endl;
+
+ iio->setqStatus( 0 );
+}
+
+#endif // TQT_NO_IMAGEIO_XPM
+#endif //TQT_NO_IMAGEIO
+#endif
+
+// table to flip bits
+static const uchar bitflip[256] = {
+ /*
+ open OUT, "| fmt";
+ for $i (0..255) {
+ print OUT (($i >> 7) & 0x01) | (($i >> 5) & 0x02) |
+ (($i >> 3) & 0x04) | (($i >> 1) & 0x08) |
+ (($i << 7) & 0x80) | (($i << 5) & 0x40) |
+ (($i << 3) & 0x20) | (($i << 1) & 0x10), ", ";
+ }
+ close OUT;
+ */
+ 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
+ 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
+ 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
+ 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
+ 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
+ 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
+ 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
+ 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
+ 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
+ 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
+ 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
+ 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
+ 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
+ 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
+ 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
+ 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
+};
+
+/*!
+ Converts the bit order of the image to the given \a bitOrder and
+ returns the converted image. The original image is not changed.
+ Returns this image if the given \a bitOrder is equal to the image
+ current bit order, or a null image if this image cannot be
+ converted.
+
+ Use convertToFormat() instead.
+*/
+
+TQImage TQImage::convertBitOrder(Endian bitOrder) const
+{
+ if (isNull() || depth() != 1 || !(bitOrder == BigEndian || bitOrder == LittleEndian))
+ return QImage();
+
+ if ((format() == Format_Mono && bitOrder == BigEndian)
+ || (format() == Format_MonoLSB && bitOrder == LittleEndian))
+ return *this;
+
+ TQImage image(width(), height(), format() == Format_Mono ? Format_MonoLSB : Format_Mono);
+
+ const uchar *data = bits();
+ const uchar *end = data + byteCount();
+ uchar *ndata = image.bits();
+ while (data < end)
+ *ndata++ = bitflip[*data++];
+
+ image.setDotsPerMeterX(dotsPerMeterX());
+ image.setDotsPerMeterY(dotsPerMeterY());
+
+ image.setColorTable(colorTable());
+ return image;
+}
+
+TQImage::Endian TQImage::systemBitOrder() {
+#if defined(Q_WS_X11)
+ return BitmapBitOrder(QX11Info::display()) == MSBFirst ? BigEndian : LittleEndian;
+#else
+ return BigEndian;
+#endif
+}
+
+/*!
+ \fn TQImage TQImage::convertDepthWithPalette(int depth, QRgb* palette, int palette_count, Qt::ImageConversionFlags flags) const
+
+ Returns an image with the given \a depth, using the \a
+ palette_count colors pointed to by \a palette. If \a depth is 1 or
+ 8, the returned image will have its color table ordered in the
+ same way as \a palette.
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a flags to
+ specify how you'd prefer this to happen.
+
+ Note: currently no closest-color search is made. If colors are
+ found that are not in the palette, the palette may not be used at
+ all. This result should not be considered valid because it may
+ change in future implementations.
+
+ Currently inefficient for non-32-bit images.
+
+ Use the convertToFormat() function in combination with the
+ setColorTable() function instead.
+*/
+TQImage TQImage::convertDepthWithPalette(int d, QRgb* palette, int palette_count, Qt::ImageConversionFlags flags) const
+{
+ Format f = const_cast<TQImage*>(this)->formatFor(d, TQImage::LittleEndian);
+ QVector<QRgb> colortable;
+ for (int i = 0; i < palette_count; ++i)
+ colortable.append(palette[i]);
+ return convertToFormat(f, colortable, flags);
+}
+
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+TQImage TQImage::createHeuristicMask( bool clipTight ) const {
+ return TQImage(QImage::createHeuristicMask(clipTight));
+}
+#endif
+
+#else // USE_QT4
+
+// 16bpp images on supported on TQt/Embedded
+#if !defined( TQ_WS_TQWS ) && !defined(TQT_NO_IMAGE_16_BIT)
+#define TQT_NO_IMAGE_16_BIT
+#endif
+
+
+/*!
+ \class TQImage
+ \brief The TQImage class provides a hardware-independent pixmap
+ representation with direct access to the pixel data.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup shared
+ \mainclass
+
+ It is one of the two classes TQt provides for dealing with images,
+ the other being TQPixmap. TQImage is designed and optimized for I/O
+ and for direct pixel access/manipulation. TQPixmap is designed and
+ optimized for drawing. There are (slow) functions to convert
+ between TQImage and TQPixmap: TQPixmap::convertToImage() and
+ TQPixmap::convertFromImage().
+
+ An image has the parameters \link width() width\endlink, \link
+ height() height\endlink and \link depth() depth\endlink (bits per
+ pixel, bpp), a color table and the actual \link bits()
+ pixels\endlink. TQImage supports 1-bpp, 8-bpp and 32-bpp image
+ data. 1-bpp and 8-bpp images use a color lookup table; the pixel
+ value is a color table index.
+
+ 32-bpp images encode an RGB value in 24 bits and ignore the color
+ table. The most significant byte is used for the \link
+ setAlphaBuffer() alpha buffer\endlink.
+
+ An entry in the color table is an RGB triplet encoded as a \c
+ uint. Use the \link ::tqRed() tqRed()\endlink, \link ::tqGreen()
+ tqGreen()\endlink and \link ::tqBlue() tqBlue()\endlink functions (\c
+ tqcolor.h) to access the components, and \link ::tqRgb()
+ tqRgb\endlink to make an RGB triplet (see the TQColor class
+ documentation).
+
+ 1-bpp (monochrome) images have a color table with a most two
+ colors. There are two different formats: big endian (MSB first) or
+ little endian (LSB first) bit order. To access a single bit you
+ will must do some bit shifts:
+
+ \code
+ TQImage image;
+ // sets bit at (x,y) to 1
+ if ( image.bitOrder() == TQImage::LittleEndian )
+ *(image.scanLine(y) + (x >> 3)) |= 1 << (x & 7);
+ else
+ *(image.scanLine(y) + (x >> 3)) |= 1 << (7 - (x & 7));
+ \endcode
+
+ If this looks complicated, it might be a good idea to convert the
+ 1-bpp image to an 8-bpp image using convertDepth().
+
+ 8-bpp images are much easier to work with than 1-bpp images
+ because they have a single byte per pixel:
+
+ \code
+ TQImage image;
+ // set entry 19 in the color table to yellow
+ image.setColor( 19, tqRgb(255,255,0) );
+ // set 8 bit pixel at (x,y) to value yellow (in color table)
+ *(image.scanLine(y) + x) = 19;
+ \endcode
+
+ 32-bpp images ignore the color table; instead, each pixel tqcontains
+ the RGB triplet. 24 bits contain the RGB value; the most
+ significant byte is reserved for the alpha buffer.
+
+ \code
+ TQImage image;
+ // sets 32 bit pixel at (x,y) to yellow.
+ uint *p = (uint *)image.scanLine(y) + x;
+ *p = tqRgb(255,255,0);
+ \endcode
+
+ On TQt/Embedded, scanlines are aligned to the pixel depth and may
+ be padded to any degree, while on all other platforms, the
+ scanlines are 32-bit aligned for all depths. The constructor
+ taking a \c{uchar*} argument always expects 32-bit aligned data.
+ On TQt/Embedded, an additional constructor allows the number of
+ bytes-per-line to be specified.
+
+ TQImage supports a variety of methods for getting information about
+ the image, for example, colorTable(), allGray(), isGrayscale(),
+ bitOrder(), bytesPerLine(), depth(), dotsPerMeterX() and
+ dotsPerMeterY(), hasAlphaBuffer(), numBytes(), numColors(), and
+ width() and height().
+
+ Pixel colors are retrieved with pixel() and set with setPixel().
+
+ TQImage also supports a number of functions for creating a new
+ image that is a transformed version of the original. For example,
+ copy(), convertBitOrder(), convertDepth(), createAlphaMask(),
+ createHeuristicMask(), mirror(), scale(), smoothScale(), swapRGB()
+ and xForm(). There are also functions for changing attributes of
+ an image in-place, for example, setAlphaBuffer(), setColor(),
+ setDotsPerMeterX() and setDotsPerMeterY() and setNumColors().
+
+ Images can be loaded and saved in the supported formats. Images
+ are saved to a file with save(). Images are loaded from a file
+ with load() (or in the constructor) or from an array of data with
+ loadFromData(). The lists of supported formats are available from
+ inputFormatList() and outputFormatList().
+
+ Strings of text may be added to images using setText().
+
+ The TQImage class uses explicit \link shclass.html sharing\endlink,
+ similar to that used by TQMemArray.
+
+ New image formats can be added as \link plugins-howto.html
+ plugins\endlink.
+
+ \sa TQImageIO TQPixmap \link shclass.html Shared Classes\endlink
+*/
+
+
+/*!
+ \enum TQImage::Endian
+
+ This enum type is used to describe the endianness of the CPU and
+ graphics hardware.
+
+ \value IgnoreEndian Endianness does not matter. Useful for some
+ operations that are independent of endianness.
+ \value BigEndian Network byte order, as on SPARC and Motorola CPUs.
+ \value LittleEndian PC/Alpha byte order.
+*/
+
+/*!
+ \enum TQt::ImageConversionFlags
+
+ The conversion flag is a bitwise-OR of the following values. The
+ options marked "(default)" are set if no other values from the
+ list are included (since the defaults are zero):
+
+ Color/Mono preference (ignored for TQBitmap)
+ \value AutoColor (default) - If the image has \link
+ TQImage::depth() depth\endlink 1 and tqcontains only
+ black and white pixels, the pixmap becomes monochrome.
+ \value ColorOnly The pixmap is dithered/converted to the
+ \link TQPixmap::defaultDepth() native display depth\endlink.
+ \value MonoOnly The pixmap becomes monochrome. If necessary,
+ it is dithered using the chosen dithering algorithm.
+
+ Dithering mode preference for RGB channels
+ \value DiffuseDither (default) - A high-quality dither.
+ \value OrderedDither A faster, more ordered dither.
+ \value ThresholdDither No dithering; closest color is used.
+
+ Dithering mode preference for alpha channel
+ \value ThresholdAlphaDither (default) - No dithering.
+ \value OrderedAlphaDither A faster, more ordered dither.
+ \value DiffuseAlphaDither A high-quality dither.
+ \value NoAlpha Not supported.
+
+ Color matching versus dithering preference
+ \value PreferDither (default when converting to a pixmap) - Always dither
+ 32-bit images when the image is converted to 8 bits.
+ \value AvoidDither (default when converting for the purpose of saving to
+ file) - Dither 32-bit images only if the image has more than 256
+ colors and it is being converted to 8 bits.
+ \value AutoDither Not supported.
+
+ The following are not values that are used directly, but masks for
+ the above classes:
+ \value ColorMode_Mask Mask for the color mode.
+ \value Dither_Mask Mask for the dithering mode for RGB channels.
+ \value AlphaDither_Mask Mask for the dithering mode for the alpha channel.
+ \value DitherMode_Mask Mask for the mode that determines the preference of
+ color matching versus dithering.
+
+ Using 0 as the conversion flag sets all the default options.
+*/
+
+#if defined(TQ_CC_DEC) && defined(__alpha) && (__DECCXX_VER-0 >= 50190001)
+#pragma message disable narrowptr
+#endif
+
+#ifndef TQT_NO_IMAGE_TEXT
+class TQImageDataMisc {
+public:
+ TQImageDataMisc() { }
+ TQImageDataMisc( const TQImageDataMisc& o ) :
+ text_lang(o.text_lang) { }
+
+ TQImageDataMisc& operator=(const TQImageDataMisc& o)
+ {
+ text_lang = o.text_lang;
+ return *this;
+ }
+ TQValueList<TQImageTextKeyLang> list()
+ {
+ return text_lang.keys();
+ }
+
+ TQStringList languages()
+ {
+ TQStringList r;
+ TQMap<TQImageTextKeyLang,TQString>::Iterator it = text_lang.begin();
+ for ( ; it != text_lang.end(); ++it ) {
+ r.remove( it.key().lang );
+ r.append( it.key().lang );
+ }
+ return r;
+ }
+ TQStringList keys()
+ {
+ TQStringList r;
+ TQMap<TQImageTextKeyLang,TQString>::Iterator it = text_lang.begin();
+ for ( ; it != text_lang.end(); ++it ) {
+ r.remove( it.key().key );
+ r.append( it.key().key );
+ }
+ return r;
+ }
+
+ TQMap<TQImageTextKeyLang,TQString> text_lang;
+};
+#endif // TQT_NO_IMAGE_TEXT
+
+
+
+/*****************************************************************************
+ TQImage member functions
+ *****************************************************************************/
+
+// table to flip bits
+static const uchar bitflip[256] = {
+ /*
+ open OUT, "| fmt";
+ for $i (0..255) {
+ print OUT (($i >> 7) & 0x01) | (($i >> 5) & 0x02) |
+ (($i >> 3) & 0x04) | (($i >> 1) & 0x08) |
+ (($i << 7) & 0x80) | (($i << 5) & 0x40) |
+ (($i << 3) & 0x20) | (($i << 1) & 0x10), ", ";
+ }
+ close OUT;
+ */
+ 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
+ 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
+ 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
+ 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
+ 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
+ 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
+ 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
+ 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
+ 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
+ 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
+ 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
+ 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
+ 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
+ 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
+ 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
+ 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
+};
+
+const uchar *qt_get_bitflip_array() // called from TQPixmap code
+{
+ return bitflip;
+}
+
+
+/*!
+ Constructs a null image.
+
+ \sa isNull()
+*/
+
+TQImage::TQImage()
+{
+ init();
+}
+
+/*!
+ Constructs an image with \a w width, \a h height, \a depth bits
+ per pixel, \a numColors colors and bit order \a bitOrder.
+
+ Using this constructor is the same as first constructing a null
+ image and then calling the create() function.
+
+ \sa create()
+*/
+
+TQImage::TQImage( int w, int h, int depth, int numColors, Endian bitOrder )
+{
+ init();
+ create( w, h, depth, numColors, bitOrder );
+}
+
+/*!
+ Constructs an image with size \a size pixels, depth \a depth bits,
+ \a numColors and \a bitOrder endianness.
+
+ Using this constructor is the same as first constructing a null
+ image and then calling the create() function.
+
+ \sa create()
+*/
+TQImage::TQImage( const TQSize& size, int depth, int numColors, Endian bitOrder )
+{
+ init();
+ create( size, depth, numColors, bitOrder );
+}
+
+#ifndef TQT_NO_IMAGEIO
+/*!
+ Constructs an image and tries to load the image from the file \a
+ fileName.
+
+ If \a format is specified, the loader attempts to read the image
+ using the specified format. If \a format is not specified (which
+ is the default), the loader reads a few bytes from the header to
+ guess the file format.
+
+ If the loading of the image failed, this object is a \link
+ isNull() null\endlink image.
+
+ The TQImageIO documentation lists the supported image formats and
+ explains how to add extra formats.
+
+ \sa load() isNull() TQImageIO
+*/
+
+TQImage::TQImage( const TQString &fileName, const char* format )
+{
+ init();
+ load( fileName, format );
+}
+
+#ifndef TQT_NO_IMAGEIO_XPM
+// helper
+static void read_xpm_image_or_array( TQImageIO *, const char * const *, TQImage & );
+#endif
+/*!
+ Constructs an image from \a xpm, which must be a valid XPM image.
+
+ Errors are silently ignored.
+
+ Note that it's possible to squeeze the XPM variable a little bit
+ by using an unusual declaration:
+
+ \code
+ static const char * const start_xpm[]={
+ "16 15 8 1",
+ "a c #cec6bd",
+ ....
+ \endcode
+
+ The extra \c const makes the entire definition read-only, which is
+ slightly more efficient (e.g. when the code is in a shared
+ library) and ROMable when the application is to be stored in ROM.
+*/
+
+TQImage::TQImage( const char * const xpm[] )
+{
+ init();
+#ifndef TQT_NO_IMAGEIO_XPM
+ read_xpm_image_or_array( 0, xpm, *this );
+#else
+ // We use a qFatal rather than disabling the whole function, as this
+ // constructor may be ambiguous.
+ qFatal("XPM not supported");
+#endif
+}
+
+/*!
+ Constructs an image from the binary data \a array. It tries to
+ guess the file format.
+
+ If the loading of the image failed, this object is a \link
+ isNull() null\endlink image.
+
+ \sa loadFromData() isNull() imageFormat()
+*/
+TQImage::TQImage( const TQByteArray &array )
+{
+ init();
+ loadFromData(array);
+}
+#endif //TQT_NO_IMAGEIO
+
+
+/*!
+ Constructs a \link shclass.html shallow copy\endlink of \a image.
+*/
+
+TQImage::TQImage( const TQImage &image )
+{
+ data = image.data;
+ data->ref();
+}
+
+/*!
+ Constructs an image \a w pixels wide, \a h pixels high with a
+ color depth of \a depth, that uses an existing memory buffer, \a
+ yourdata. The buffer must remain valid throughout the life of the
+ TQImage. The image does not delete the buffer at destruction.
+
+ If \a colortable is 0, a color table sufficient for \a numColors
+ will be allocated (and destructed later).
+
+ Note that \a yourdata must be 32-bit aligned.
+
+ The endianness is given in \a bitOrder.
+*/
+TQImage::TQImage( uchar* yourdata, int w, int h, int depth,
+ TQRgb* colortable, int numColors,
+ Endian bitOrder )
+{
+ init();
+ int bpl = ((w*depth+31)/32)*4; // bytes per scanline
+ if ( w <= 0 || h <= 0 || depth <= 0 || numColors < 0
+ || INT_MAX / sizeof(uchar *) < uint(h)
+ || INT_MAX / uint(depth) < uint(w)
+ || bpl <= 0
+ || INT_MAX / uint(bpl) < uint(h) )
+ return; // invalid parameter(s)
+ data->w = w;
+ data->h = h;
+ data->d = depth;
+ data->ncols = depth != 32 ? numColors : 0;
+ if ( !yourdata )
+ return; // Image header info can be saved without needing to allocate memory.
+ data->nbytes = bpl*h;
+ if ( colortable || !data->ncols ) {
+ data->ctbl = colortable;
+ data->ctbl_mine = FALSE;
+ } else {
+ // calloc since we realloc, etc. later (ick)
+ data->ctbl = (TQRgb*)calloc( data->ncols*sizeof(TQRgb), data->ncols );
+ TQ_CHECK_PTR(data->ctbl);
+ data->ctbl_mine = TRUE;
+ }
+ uchar** jt = (uchar**)malloc(h*sizeof(uchar*));
+ TQ_CHECK_PTR(jt);
+ for (int j=0; j<h; j++) {
+ jt[j] = yourdata+j*bpl;
+ }
+ data->bits = jt;
+ data->bitordr = bitOrder;
+}
+
+#ifdef TQ_WS_TQWS
+
+/*!
+ Constructs an image that uses an existing memory buffer. The
+ buffer must remain valid for the life of the TQImage. The image
+ does not delete the buffer at destruction. The buffer is passed as
+ \a yourdata. The image's width is \a w and its height is \a h. The
+ color depth is \a depth. \a bpl specifies the number of bytes per
+ line.
+
+ If \a colortable is 0, a color table sufficient for \a numColors
+ will be allocated (and destructed later).
+
+ The endianness is specified by \a bitOrder.
+
+ \warning This constructor is only available on TQt/Embedded.
+*/
+TQImage::TQImage( uchar* yourdata, int w, int h, int depth,
+ int bpl, TQRgb* colortable, int numColors,
+ Endian bitOrder )
+{
+ init();
+ if ( !yourdata || w <= 0 || h <= 0 || depth <= 0 || numColors < 0
+ || INT_MAX / sizeof(uchar *) < uint(h)
+ || INT_MAX / uint(bpl) < uint(h)
+ )
+ return; // invalid parameter(s)
+ data->w = w;
+ data->h = h;
+ data->d = depth;
+ data->ncols = numColors;
+ data->nbytes = bpl * h;
+ if ( colortable || !numColors ) {
+ data->ctbl = colortable;
+ data->ctbl_mine = FALSE;
+ } else {
+ // calloc since we realloc, etc. later (ick)
+ data->ctbl = (TQRgb*)calloc( numColors*sizeof(TQRgb), numColors );
+ TQ_CHECK_PTR(data->ctbl);
+ data->ctbl_mine = TRUE;
+ }
+ uchar** jt = (uchar**)malloc(h*sizeof(uchar*));
+ TQ_CHECK_PTR(jt);
+ for (int j=0; j<h; j++) {
+ jt[j] = yourdata+j*bpl;
+ }
+ data->bits = jt;
+ data->bitordr = bitOrder;
+}
+#endif // TQ_WS_TQWS
+
+/*!
+ Destroys the image and cleans up.
+*/
+
+TQImage::~TQImage()
+{
+ if ( data && data->deref() ) {
+ reset();
+ delete data;
+ }
+}
+
+
+
+
+/*! Convenience function. Gets the data associated with the absolute
+ name \a abs_name from the default mime source factory and decodes it
+ to an image.
+
+ \sa TQMimeSourceFactory, TQImage::fromMimeSource(), TQImageDrag::decode()
+*/
+#ifndef TQT_NO_MIME
+TQImage TQImage::fromMimeSource( const TQString &abs_name )
+{
+ const TQMimeSource *m = TQMimeSourceFactory::defaultFactory()->data( abs_name );
+ if ( !m ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning("TQImage::fromMimeSource: Cannot find image \"%s\" in the mime source factory", abs_name.latin1() );
+#endif
+ return TQImage();
+ }
+ TQImage img;
+ TQImageDrag::decode( m, img );
+ return img;
+}
+#endif
+
+
+/*!
+ Assigns a \link shclass.html shallow copy\endlink of \a image to
+ this image and returns a reference to this image.
+
+ \sa copy()
+*/
+
+TQImage &TQImage::operator=( const TQImage &image )
+{
+ image.data->ref(); // avoid 'x = x'
+ if ( data->deref() ) {
+ reset();
+ delete data;
+ }
+ data = image.data;
+ return *this;
+}
+
+/*!
+ \overload
+
+ Sets the image bits to the \a pixmap contents and returns a
+ reference to the image.
+
+ If the image shares data with other images, it will first
+ dereference the shared data.
+
+ Makes a call to TQPixmap::convertToImage().
+*/
+
+TQImage &TQImage::operator=( const TQPixmap &pixmap )
+{
+ *this = pixmap.convertToImage();
+ return *this;
+}
+
+/*!
+ Detaches from shared image data and makes sure that this image is
+ the only one referring to the data.
+
+ If multiple images share common data, this image makes a copy of
+ the data and detaches itself from the sharing mechanism.
+ Nothing is done if there is just a single reference.
+
+ \sa copy()
+*/
+
+void TQImage::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+}
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the image.
+
+ \sa detach()
+*/
+
+TQImage TQImage::copy() const
+{
+ if ( isNull() ) {
+ // maintain the fields of invalid TQImages when copied
+ return TQImage( 0, width(), height(), depth(), colorTable(), numColors(), bitOrder() );
+ } else {
+ TQImage image;
+ image.create( width(), height(), depth(), numColors(), bitOrder() );
+#ifdef TQ_WS_TQWS
+ // TQt/Embedded can create images with non-default bpl
+ // make sure we don't crash.
+ if ( image.numBytes() != numBytes() )
+ for ( int i = 0; i < height(); i++ )
+ memcpy( image.scanLine(i), scanLine(i), image.bytesPerLine() );
+ else
+#endif
+ memcpy( image.bits(), bits(), numBytes() );
+ memcpy( image.colorTable(), colorTable(), numColors() * sizeof(TQRgb) );
+ image.setAlphaBuffer( hasAlphaBuffer() );
+ image.data->dpmx = dotsPerMeterX();
+ image.data->dpmy = dotsPerMeterY();
+ image.data->offset = offset();
+#ifndef TQT_NO_IMAGE_TEXT
+ if ( data->misc ) {
+ image.data->misc = new TQImageDataMisc;
+ *image.data->misc = misc();
+ }
+#endif
+ return image;
+ }
+}
+
+/*!
+ \overload
+
+ Returns a \link shclass.html deep copy\endlink of a sub-area of
+ the image.
+
+ The returned image is always \a w by \a h pixels in size, and is
+ copied from position \a x, \a y in this image. In areas beyond
+ this image pixels are filled with pixel 0.
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a
+ conversion_flags to specify how you'd prefer this to happen.
+
+ \sa bitBlt() TQt::ImageConversionFlags
+*/
+
+TQImage TQImage::copy(int x, int y, int w, int h, int conversion_flags) const
+{
+ int dx = 0;
+ int dy = 0;
+ if ( w <= 0 || h <= 0 ) return TQImage(); // Nothing to copy
+
+ TQImage image( w, h, depth(), numColors(), bitOrder() );
+
+ if ( x < 0 || y < 0 || x + w > width() || y + h > height() ) {
+ // bitBlt will not cover entire image - clear it.
+ // ### should deal with each side separately for efficiency
+ image.fill(0);
+ if ( x < 0 ) {
+ dx = -x;
+ x = 0;
+ }
+ if ( y < 0 ) {
+ dy = -y;
+ y = 0;
+ }
+ }
+
+ bool has_alpha = hasAlphaBuffer();
+ if ( has_alpha ) {
+ // alpha channel should be only copied, not used by bitBlt(), and
+ // this is mutable, we will restore the image state before returning
+ TQImage *that = (TQImage *) this;
+ that->setAlphaBuffer( FALSE );
+ }
+ memcpy( image.colorTable(), colorTable(), numColors()*sizeof(TQRgb) );
+ bitBlt( &image, dx, dy, this, x, y, -1, -1, conversion_flags );
+ if ( has_alpha ) {
+ // restore image state
+ TQImage *that = (TQImage *) this;
+ that->setAlphaBuffer( TRUE );
+ }
+ image.setAlphaBuffer(hasAlphaBuffer());
+ image.data->dpmx = dotsPerMeterX();
+ image.data->dpmy = dotsPerMeterY();
+ image.data->offset = offset();
+#ifndef TQT_NO_IMAGE_TEXT
+ if ( data->misc ) {
+ image.data->misc = new TQImageDataMisc;
+ *image.data->misc = misc();
+ }
+#endif
+ return image;
+}
+
+/*!
+ \overload TQImage TQImage::copy(const TQRect& r) const
+
+ Returns a \link shclass.html deep copy\endlink of a sub-area of
+ the image.
+
+ The returned image always has the size of the rectangle \a r. In
+ areas beyond this image pixels are filled with pixel 0.
+*/
+
+/*!
+ \fn bool TQImage::isNull() const
+
+ Returns TRUE if it is a null image; otherwise returns FALSE.
+
+ A null image has all parameters set to zero and no allocated data.
+*/
+
+
+/*!
+ \fn int TQImage::width() const
+
+ Returns the width of the image.
+
+ \sa height() size() rect()
+*/
+
+/*!
+ \fn int TQImage::height() const
+
+ Returns the height of the image.
+
+ \sa width() size() rect()
+*/
+
+/*!
+ \fn TQSize TQImage::size() const
+
+ Returns the size of the image, i.e. its width and height.
+
+ \sa width() height() rect()
+*/
+
+/*!
+ \fn TQRect TQImage::rect() const
+
+ Returns the enclosing rectangle (0, 0, width(), height()) of the
+ image.
+
+ \sa width() height() size()
+*/
+
+/*!
+ \fn int TQImage::depth() const
+
+ Returns the depth of the image.
+
+ The image depth is the number of bits used to encode a single
+ pixel, also called bits per pixel (bpp) or bit planes of an image.
+
+ The supported depths are 1, 8, 16 (TQt/Embedded only) and 32.
+
+ \sa convertDepth()
+*/
+
+/*!
+ \fn int TQImage::numColors() const
+
+ Returns the size of the color table for the image.
+
+ Notice that numColors() returns 0 for 16-bpp (TQt/Embedded only)
+ and 32-bpp images because these images do not use color tables,
+ but instead encode pixel values as RGB triplets.
+
+ \sa setNumColors() colorTable()
+*/
+
+/*!
+ \fn TQImage::Endian TQImage::bitOrder() const
+
+ Returns the bit order for the image.
+
+ If it is a 1-bpp image, this function returns either
+ TQImage::BigEndian or TQImage::LittleEndian.
+
+ If it is not a 1-bpp image, this function returns
+ TQImage::IgnoreEndian.
+
+ \sa depth()
+*/
+
+/*!
+ \fn uchar **TQImage::jumpTable() const
+
+ Returns a pointer to the scanline pointer table.
+
+ This is the beginning of the data block for the image.
+
+ \sa bits() scanLine()
+*/
+
+/*!
+ \fn TQRgb *TQImage::colorTable() const
+
+ Returns a pointer to the color table.
+
+ \sa numColors()
+*/
+
+/*!
+ \fn int TQImage::numBytes() const
+
+ Returns the number of bytes occupied by the image data.
+
+ \sa bytesPerLine() bits()
+*/
+
+/*!
+ \fn int TQImage::bytesPerLine() const
+
+ Returns the number of bytes per image scanline. This is equivalent
+ to numBytes()/height().
+
+ \sa numBytes() scanLine()
+*/
+
+/*!
+ \fn TQRgb TQImage::color( int i ) const
+
+ Returns the color in the color table at index \a i. The first
+ color is at index 0.
+
+ A color value is an RGB triplet. Use the \link ::tqRed()
+ tqRed()\endlink, \link ::tqGreen() tqGreen()\endlink and \link
+ ::tqBlue() tqBlue()\endlink functions (defined in \c tqcolor.h) to
+ get the color value components.
+
+ \sa setColor() numColors() TQColor
+*/
+
+/*!
+ \fn void TQImage::setColor( int i, TQRgb c )
+
+ Sets a color in the color table at index \a i to \a c.
+
+ A color value is an RGB triplet. Use the \link ::tqRgb()
+ tqRgb()\endlink function (defined in \c tqcolor.h) to make RGB
+ triplets.
+
+ \sa color() setNumColors() numColors()
+*/
+
+/*!
+ \fn uchar *TQImage::scanLine( int i ) const
+
+ Returns a pointer to the pixel data at the scanline with index \a
+ i. The first scanline is at index 0.
+
+ The scanline data is aligned on a 32-bit boundary.
+
+ \warning If you are accessing 32-bpp image data, cast the returned
+ pointer to \c{TQRgb*} (TQRgb has a 32-bit size) and use it to
+ read/write the pixel value. You cannot use the \c{uchar*} pointer
+ directly, because the pixel format depends on the byte order on
+ the underlying platform. Hint: use \link ::tqRed() tqRed()\endlink,
+ \link ::tqGreen() tqGreen()\endlink and \link ::tqBlue()
+ tqBlue()\endlink, etc. (tqcolor.h) to access the pixels.
+
+ \warning If you are accessing 16-bpp image data, you must handle
+ endianness yourself. (TQt/Embedded only)
+
+ \sa bytesPerLine() bits() jumpTable()
+*/
+
+/*!
+ \fn uchar *TQImage::bits() const
+
+ Returns a pointer to the first pixel data. This is equivalent to
+ scanLine(0).
+
+ \sa numBytes() scanLine() jumpTable()
+*/
+
+
+
+void TQImage::warningIndexRange( const char *func, int i )
+{
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::%s: Index %d out of range", func, i );
+#else
+ TQ_UNUSED( func )
+ TQ_UNUSED( i )
+#endif
+}
+
+
+/*!
+ Resets all image parameters and deallocates the image data.
+*/
+
+void TQImage::reset()
+{
+ freeBits();
+ setNumColors( 0 );
+#ifndef TQT_NO_IMAGE_TEXT
+ delete data->misc;
+#endif
+ reinit();
+}
+
+
+/*!
+ Fills the entire image with the pixel value \a pixel.
+
+ If the \link depth() depth\endlink of this image is 1, only the
+ lowest bit is used. If you say fill(0), fill(2), etc., the image
+ is filled with 0s. If you say fill(1), fill(3), etc., the image is
+ filled with 1s. If the depth is 8, the lowest 8 bits are used.
+
+ If the depth is 32 and the image has no alpha buffer, the \a pixel
+ value is written to each pixel in the image. If the image has an
+ alpha buffer, only the 24 RGB bits are set and the upper 8 bits
+ (alpha value) are left unchanged.
+
+ Note: TQImage::pixel() returns the color of the pixel at the given
+ coordinates; TQColor::pixel() returns the pixel value of the
+ underlying window system (essentially an index value), so normally
+ you will want to use TQImage::pixel() to use a color from an
+ existing image or TQColor::rgb() to use a specific color.
+
+ \sa invertPixels() depth() hasAlphaBuffer() create()
+*/
+
+void TQImage::fill( uint pixel )
+{
+ if ( depth() == 1 || depth() == 8 ) {
+ if ( depth() == 1 ) {
+ if ( pixel & 1 )
+ pixel = 0xffffffff;
+ else
+ pixel = 0;
+ } else {
+ uint c = pixel & 0xff;
+ pixel = c | ((c << 8) & 0xff00) | ((c << 16) & 0xff0000) |
+ ((c << 24) & 0xff000000);
+ }
+ int bpl = bytesPerLine();
+ for ( int i=0; i<height(); i++ )
+ memset( scanLine(i), pixel, bpl );
+#ifndef TQT_NO_IMAGE_16_BIT
+ } else if ( depth() == 16 ) {
+ for ( int i=0; i<height(); i++ ) {
+ //optimize with 32-bit writes, since image is always aligned
+ uint *p = (uint *)scanLine(i);
+ uint *end = (uint*)(((ushort*)p) + width());
+ uint fill;
+ ushort *f = (ushort*)&fill;
+ f[0]=pixel;
+ f[1]=pixel;
+ while ( p < end )
+ *p++ = fill;
+ }
+#endif // TQT_NO_IMAGE_16_BIT
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ } else if ( depth() == 32 ) {
+ if ( hasAlphaBuffer() ) {
+ pixel &= 0x00ffffff;
+ for ( int i=0; i<height(); i++ ) {
+ uint *p = (uint *)scanLine(i);
+ uint *end = p + width();
+ while ( p < end ) {
+ *p = (*p & 0xff000000) | pixel;
+ p++;
+ }
+ }
+ } else {
+ for ( int i=0; i<height(); i++ ) {
+ uint *p = (uint *)scanLine(i);
+ uint *end = p + width();
+ while ( p < end )
+ *p++ = pixel;
+ }
+ }
+#endif // TQT_NO_IMAGE_TRUECOLOR
+ }
+}
+
+
+/*!
+ Inverts all pixel values in the image.
+
+ If the depth is 32: if \a invertAlpha is TRUE, the alpha bits are
+ also inverted, otherwise they are left unchanged.
+
+ If the depth is not 32, the argument \a invertAlpha has no
+ meaning.
+
+ Note that inverting an 8-bit image means to tqreplace all pixels
+ using color index \e i with a pixel using color index 255 minus \e
+ i. Similarly for a 1-bit image. The color table is not changed.
+
+ \sa fill() depth() hasAlphaBuffer()
+*/
+
+void TQImage::invertPixels( bool invertAlpha )
+{
+ TQ_UINT32 n = numBytes();
+ if ( n % 4 ) {
+ TQ_UINT8 *p = (TQ_UINT8*)bits();
+ TQ_UINT8 *end = p + n;
+ while ( p < end )
+ *p++ ^= 0xff;
+ } else {
+ TQ_UINT32 *p = (TQ_UINT32*)bits();
+ TQ_UINT32 *end = p + n/4;
+ uint xorbits = invertAlpha && depth() == 32 ? 0x00ffffff : 0xffffffff;
+ while ( p < end )
+ *p++ ^= xorbits;
+ }
+}
+
+
+/*!
+ Determines the host computer byte order. Returns
+ TQImage::LittleEndian (LSB first) or TQImage::BigEndian (MSB first).
+
+ \sa systemBitOrder()
+*/
+
+TQImage::Endian TQImage::systemByteOrder()
+{
+ static Endian sbo = IgnoreEndian;
+ if ( sbo == IgnoreEndian ) { // initialize
+ int ws;
+ bool be;
+ qSysInfo( &ws, &be );
+ sbo = be ? BigEndian : LittleEndian;
+ }
+ return sbo;
+}
+
+
+#if defined(TQ_WS_X11)
+#include <X11/Xlib.h> // needed for systemBitOrder
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#if defined(TQ_OS_WIN32)
+#undef open
+#undef close
+#undef read
+#undef write
+#endif
+#endif
+
+// POSIX Large File Support redefines open -> open64
+#if defined(open)
+# undef open
+#endif
+
+// POSIX Large File Support redefines truncate -> truncate64
+#if defined(truncate)
+# undef truncate
+#endif
+
+/*!
+ Determines the bit order of the display hardware. Returns
+ TQImage::LittleEndian (LSB first) or TQImage::BigEndian (MSB first).
+
+ \sa systemByteOrder()
+*/
+
+TQImage::Endian TQImage::systemBitOrder()
+{
+#if defined(TQ_WS_X11)
+ return BitmapBitOrder(qt_xdisplay()) == MSBFirst ? BigEndian :LittleEndian;
+#else
+ return BigEndian;
+#endif
+}
+
+
+/*!
+ Resizes the color table to \a numColors colors.
+
+ If the color table is expanded all the extra colors will be set to
+ black (RGB 0,0,0).
+
+ \sa numColors() color() setColor() colorTable()
+*/
+
+void TQImage::setNumColors( int numColors )
+{
+ if ( numColors == data->ncols )
+ return;
+ if ( numColors == 0 ) { // use no color table
+ if ( data->ctbl ) {
+ if ( data->ctbl_mine )
+ free( data->ctbl );
+ else
+ data->ctbl_mine = TRUE;
+ data->ctbl = 0;
+ }
+ data->ncols = 0;
+ return;
+ }
+ if ( data->ctbl && data->ctbl_mine ) { // already has color table
+ data->ctbl = (TQRgb*)realloc( data->ctbl, numColors*sizeof(TQRgb) );
+ if ( data->ctbl && numColors > data->ncols )
+ memset( (char *)&data->ctbl[data->ncols], 0,
+ (numColors-data->ncols)*sizeof(TQRgb) );
+ } else { // create new color table
+ data->ctbl = (TQRgb*)calloc( numColors*sizeof(TQRgb), 1 );
+ TQ_CHECK_PTR(data->ctbl);
+ data->ctbl_mine = TRUE;
+ }
+ data->ncols = data->ctbl == 0 ? 0 : numColors;
+}
+
+
+/*!
+ \fn bool TQImage::hasAlphaBuffer() const
+
+ Returns TRUE if alpha buffer mode is enabled; otherwise returns
+ FALSE.
+
+ \sa setAlphaBuffer()
+*/
+
+/*!
+ Enables alpha buffer mode if \a enable is TRUE, otherwise disables
+ it. The default setting is disabled.
+
+ An 8-bpp image has 8-bit pixels. A pixel is an index into the
+ \link color() color table\endlink, which tqcontains 32-bit color
+ values. In a 32-bpp image, the 32-bit pixels are the color values.
+
+ This 32-bit value is encoded as follows: The lower 24 bits are
+ used for the red, green, and blue components. The upper 8 bits
+ contain the alpha component.
+
+ The alpha component specifies the transparency of a pixel. 0 means
+ completely transtqparent and 255 means opaque. The alpha component
+ is ignored if you do not enable alpha buffer mode.
+
+ The alpha buffer is used to set a tqmask when a TQImage is translated
+ to a TQPixmap.
+
+ \sa hasAlphaBuffer() createAlphaMask()
+*/
+
+void TQImage::setAlphaBuffer( bool enable )
+{
+ data->alpha = enable;
+}
+
+
+/*!
+ Sets the image \a width, \a height, \a depth, its number of colors
+ (in \a numColors), and bit order. Returns TRUE if successful, or
+ FALSE if the parameters are incorrect or if memory cannot be
+ allocated.
+
+ The \a width and \a height is limited to 32767. \a depth must be
+ 1, 8, or 32. If \a depth is 1, \a bitOrder must be set to
+ either TQImage::LittleEndian or TQImage::BigEndian. For other depths
+ \a bitOrder must be TQImage::IgnoreEndian.
+
+ This function allocates a color table and a buffer for the image
+ data. The image data is not initialized.
+
+ The image buffer is allocated as a single block that consists of a
+ table of \link scanLine() scanline\endlink pointers (jumpTable())
+ and the image data (bits()).
+
+ \sa fill() width() height() depth() numColors() bitOrder()
+ jumpTable() scanLine() bits() bytesPerLine() numBytes()
+*/
+
+bool TQImage::create( int width, int height, int depth, int numColors,
+ Endian bitOrder )
+{
+ reset(); // reset old data
+ if ( width <= 0 || height <= 0 || depth <= 0 || numColors < 0 )
+ return FALSE; // invalid parameter(s)
+ if ( depth == 1 && bitOrder == IgnoreEndian ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::create: Bit order is required for 1 bpp images" );
+#endif
+ return FALSE;
+ }
+ if ( depth != 1 )
+ bitOrder = IgnoreEndian;
+
+#if defined(TQT_CHECK_RANGE)
+ if ( depth == 24 )
+ qWarning( "TQImage::create: 24-bpp images no longer supported, "
+ "use 32-bpp instead" );
+#endif
+ switch ( depth ) {
+ case 1:
+ case 8:
+#ifndef TQT_NO_IMAGE_16_BIT
+ case 16:
+#endif
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ case 32:
+#endif
+ break;
+ default: // invalid depth
+ return FALSE;
+ }
+
+ if ( depth == 32 )
+ numColors = 0;
+ setNumColors( numColors );
+ if ( data->ncols != numColors ) // could not alloc color table
+ return FALSE;
+
+ if ( INT_MAX / uint(depth) < uint(width) ) { // sanity check for potential overflow
+ setNumColors( 0 );
+ return FALSE;
+ }
+// TQt/Embedded doesn't waste memory on unnecessary padding.
+#ifdef TQ_WS_TQWS
+ const int bpl = (width*depth+7)/8; // bytes per scanline
+ const int pad = 0;
+#else
+ const int bpl = ((width*depth+31)/32)*4; // bytes per scanline
+ // #### WWA: shouldn't this be (width*depth+7)/8:
+ const int pad = bpl - (width*depth)/8; // pad with zeros
+#endif
+ if ( INT_MAX / uint(bpl) < uint(height)
+ || bpl < 0
+ || INT_MAX / sizeof(uchar *) < uint(height) ) { // sanity check for potential overflow
+ setNumColors( 0 );
+ return FALSE;
+ }
+ int nbytes = bpl*height; // image size
+ int ptbl = height*sizeof(uchar*); // pointer table size
+ int size = nbytes + ptbl; // total size of data block
+ uchar **p = (uchar **)malloc( size ); // alloc image bits
+ TQ_CHECK_PTR(p);
+ if ( !p ) { // no memory
+ setNumColors( 0 );
+ return FALSE;
+ }
+ data->w = width;
+ data->h = height;
+ data->d = depth;
+ data->nbytes = nbytes;
+ data->bitordr = bitOrder;
+ data->bits = p; // set image pointer
+ //uchar *d = (uchar*)p + ptbl; // setup scanline pointers
+ uchar *d = (uchar*)(p + height); // setup scanline pointers
+ while ( height-- ) {
+ *p++ = d;
+ if ( pad )
+ memset( d+bpl-pad, 0, pad );
+ d += bpl;
+ }
+ return TRUE;
+}
+
+/*!
+ \overload bool TQImage::create( const TQSize&, int depth, int numColors, Endian bitOrder )
+*/
+bool TQImage::create( const TQSize& size, int depth, int numColors,
+ TQImage::Endian bitOrder )
+{
+ return create(size.width(), size.height(), depth, numColors, bitOrder);
+}
+
+/*!
+ \internal
+ Initializes the image data structure.
+*/
+
+void TQImage::init()
+{
+ data = new TQImageData;
+ TQ_CHECK_PTR( data );
+ reinit();
+}
+
+void TQImage::reinit()
+{
+ data->w = data->h = data->d = data->ncols = 0;
+ data->nbytes = 0;
+ data->ctbl = 0;
+ data->bits = 0;
+ data->bitordr = TQImage::IgnoreEndian;
+ data->alpha = FALSE;
+#ifndef TQT_NO_IMAGE_TEXT
+ data->misc = 0;
+#endif
+ data->dpmx = 0;
+ data->dpmy = 0;
+ data->offset = TQPoint(0,0);
+}
+
+/*!
+ \internal
+ Deallocates the image data and sets the bits pointer to 0.
+*/
+
+void TQImage::freeBits()
+{
+ if ( data->bits ) { // dealloc image bits
+ free( data->bits );
+ data->bits = 0;
+ }
+}
+
+
+/*****************************************************************************
+ Internal routines for converting image depth.
+ *****************************************************************************/
+
+//
+// convert_32_to_8: Converts a 32 bits depth (true color) to an 8 bit
+// image with a colormap. If the 32 bit image has more than 256 colors,
+// we convert the red,green and blue bytes into a single byte encoded
+// as 6 shades of each of red, green and blue.
+//
+// if dithering is needed, only 1 color at most is available for alpha.
+//
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+struct TQRgbMap {
+ TQRgbMap() : rgb(0xffffffff) { }
+ bool used() const { return rgb!=0xffffffff; }
+ uchar pix;
+ TQRgb rgb;
+};
+
+static bool convert_32_to_8( const TQImage *src, TQImage *dst, int conversion_flags, TQRgb* palette=0, int palette_count=0 )
+{
+ register TQRgb *p;
+ uchar *b;
+ bool do_quant = FALSE;
+ int y, x;
+
+ if ( !dst->create(src->width(), src->height(), 8, 256) )
+ return FALSE;
+
+ const int tablesize = 997; // prime
+ TQRgbMap table[tablesize];
+ int pix=0;
+ TQRgb atqmask = src->hasAlphaBuffer() ? 0xffffffff : 0x00ffffff;
+ if ( src->hasAlphaBuffer() )
+ dst->setAlphaBuffer(TRUE);
+
+ if ( palette ) {
+ // Preload palette into table.
+
+ p = palette;
+ // Almost same code as pixel insertion below
+ while ( palette_count-- > 0 ) {
+ // Find in table...
+ int hash = (*p & atqmask) % tablesize;
+ for (;;) {
+ if ( table[hash].used() ) {
+ if ( table[hash].rgb == (*p & atqmask) ) {
+ // Found previous insertion - use it
+ break;
+ } else {
+ // Keep searching...
+ if (++hash == tablesize) hash = 0;
+ }
+ } else {
+ // Cannot be in table
+ TQ_ASSERT ( pix != 256 ); // too many colors
+ // Insert into table at this unused position
+ dst->setColor( pix, (*p & atqmask) );
+ table[hash].pix = pix++;
+ table[hash].rgb = *p & atqmask;
+ break;
+ }
+ }
+ p++;
+ }
+ }
+
+ if ( (conversion_flags & TQt::DitherMode_Mask) == TQt::PreferDither ) {
+ do_quant = TRUE;
+ } else {
+ for ( y=0; y<src->height(); y++ ) { // check if <= 256 colors
+ p = (TQRgb *)src->scanLine(y);
+ b = dst->scanLine(y);
+ x = src->width();
+ while ( x-- ) {
+ // Find in table...
+ int hash = (*p & atqmask) % tablesize;
+ for (;;) {
+ if ( table[hash].used() ) {
+ if ( table[hash].rgb == (*p & atqmask) ) {
+ // Found previous insertion - use it
+ break;
+ } else {
+ // Keep searching...
+ if (++hash == tablesize) hash = 0;
+ }
+ } else {
+ // Cannot be in table
+ if ( pix == 256 ) { // too many colors
+ do_quant = TRUE;
+ // Break right out
+ x = 0;
+ y = src->height();
+ } else {
+ // Insert into table at this unused position
+ dst->setColor( pix, (*p & atqmask) );
+ table[hash].pix = pix++;
+ table[hash].rgb = (*p & atqmask);
+ }
+ break;
+ }
+ }
+ *b++ = table[hash].pix; // May occur once incorrectly
+ p++;
+ }
+ }
+ }
+ int ncols = do_quant ? 256 : pix;
+
+ static uint bm[16][16];
+ static int init=0;
+ if (!init) {
+ // Build a Bayer Matrix for dithering
+
+ init = 1;
+ int n, i, j;
+
+ bm[0][0]=0;
+
+ for (n=1; n<16; n*=2) {
+ for (i=0; i<n; i++) {
+ for (j=0; j<n; j++) {
+ bm[i][j]*=4;
+ bm[i+n][j]=bm[i][j]+2;
+ bm[i][j+n]=bm[i][j]+3;
+ bm[i+n][j+n]=bm[i][j]+1;
+ }
+ }
+ }
+
+ for (i=0; i<16; i++)
+ for (j=0; j<16; j++)
+ bm[i][j]<<=8;
+ }
+
+ dst->setNumColors( ncols );
+
+ if ( do_quant ) { // quantization needed
+
+#define MAX_R 5
+#define MAX_G 5
+#define MAX_B 5
+#define INDEXOF(r,g,b) (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b))
+
+ int rc, gc, bc;
+
+ for ( rc=0; rc<=MAX_R; rc++ ) // build 6x6x6 color cube
+ for ( gc=0; gc<=MAX_G; gc++ )
+ for ( bc=0; bc<=MAX_B; bc++ ) {
+ dst->setColor( INDEXOF(rc,gc,bc),
+ (atqmask&0xff000000)
+ | tqRgb( rc*255/MAX_R, gc*255/MAX_G, bc*255/MAX_B ) );
+ }
+
+ int sw = src->width();
+
+ int* line1[3];
+ int* line2[3];
+ int* pv[3];
+ if ( ( conversion_flags & TQt::Dither_Mask ) == TQt::DiffuseDither ) {
+ line1[0] = new int[src->width()];
+ line2[0] = new int[src->width()];
+ line1[1] = new int[src->width()];
+ line2[1] = new int[src->width()];
+ line1[2] = new int[src->width()];
+ line2[2] = new int[src->width()];
+ pv[0] = new int[sw];
+ pv[1] = new int[sw];
+ pv[2] = new int[sw];
+ }
+
+ for ( y=0; y < src->height(); y++ ) {
+ p = (TQRgb *)src->scanLine(y);
+ b = dst->scanLine(y);
+ TQRgb *end = p + sw;
+
+ // perform quantization
+ if ( ( conversion_flags & TQt::Dither_Mask ) == TQt::ThresholdDither ) {
+#define DITHER(p,m) ((uchar) ((p * (m) + 127) / 255))
+ while ( p < end ) {
+ rc = tqRed( *p );
+ gc = tqGreen( *p );
+ bc = tqBlue( *p );
+
+ *b++ =
+ INDEXOF(
+ DITHER(rc, MAX_R),
+ DITHER(gc, MAX_G),
+ DITHER(bc, MAX_B)
+ );
+
+ p++;
+ }
+#undef DITHER
+ } else if ( ( conversion_flags & TQt::Dither_Mask ) == TQt::OrderedDither ) {
+#define DITHER(p,d,m) ((uchar) ((((256 * (m) + (m) + 1)) * (p) + (d)) / 65536 ))
+
+ int x = 0;
+ while ( p < end ) {
+ uint d = bm[y&15][x&15];
+
+ rc = tqRed( *p );
+ gc = tqGreen( *p );
+ bc = tqBlue( *p );
+
+ *b++ =
+ INDEXOF(
+ DITHER(rc, d, MAX_R),
+ DITHER(gc, d, MAX_G),
+ DITHER(bc, d, MAX_B)
+ );
+
+ p++;
+ x++;
+ }
+#undef DITHER
+ } else { // Diffuse
+ int endian = (TQImage::systemByteOrder() == TQImage::BigEndian);
+ int x;
+ uchar* q = src->scanLine(y);
+ uchar* q2 = src->scanLine(y+1 < src->height() ? y + 1 : 0);
+ for (int chan = 0; chan < 3; chan++) {
+ b = dst->scanLine(y);
+ int *l1 = (y&1) ? line2[chan] : line1[chan];
+ int *l2 = (y&1) ? line1[chan] : line2[chan];
+ if ( y == 0 ) {
+ for (int i=0; i<sw; i++)
+ l1[i] = q[i*4+chan+endian];
+ }
+ if ( y+1 < src->height() ) {
+ for (int i=0; i<sw; i++)
+ l2[i] = q2[i*4+chan+endian];
+ }
+ // Bi-directional error diffusion
+ if ( y&1 ) {
+ for (x=0; x<sw; x++) {
+ int pix = TQMAX(TQMIN(5, (l1[x] * 5 + 128)/ 255), 0);
+ int err = l1[x] - pix * 255 / 5;
+ pv[chan][x] = pix;
+
+ // Spread the error around...
+ if ( x+1<sw ) {
+ l1[x+1] += (err*7)>>4;
+ l2[x+1] += err>>4;
+ }
+ l2[x]+=(err*5)>>4;
+ if (x>1)
+ l2[x-1]+=(err*3)>>4;
+ }
+ } else {
+ for (x=sw; x-->0; ) {
+ int pix = TQMAX(TQMIN(5, (l1[x] * 5 + 128)/ 255), 0);
+ int err = l1[x] - pix * 255 / 5;
+ pv[chan][x] = pix;
+
+ // Spread the error around...
+ if ( x > 0 ) {
+ l1[x-1] += (err*7)>>4;
+ l2[x-1] += err>>4;
+ }
+ l2[x]+=(err*5)>>4;
+ if (x+1 < sw)
+ l2[x+1]+=(err*3)>>4;
+ }
+ }
+ }
+ if (endian) {
+ for (x=0; x<sw; x++) {
+ *b++ = INDEXOF(pv[0][x],pv[1][x],pv[2][x]);
+ }
+ } else {
+ for (x=0; x<sw; x++) {
+ *b++ = INDEXOF(pv[2][x],pv[1][x],pv[0][x]);
+ }
+ }
+ }
+ }
+
+#ifndef TQT_NO_IMAGE_DITHER_TO_1
+ if ( src->hasAlphaBuffer() ) {
+ const int trans = 216;
+ dst->setColor(trans, 0x00000000); // transtqparent
+ TQImage tqmask = src->createAlphaMask(conversion_flags);
+ uchar* m;
+ for ( y=0; y < src->height(); y++ ) {
+ uchar bit = 0x80;
+ m = tqmask.scanLine(y);
+ b = dst->scanLine(y);
+ int w = src->width();
+ for ( x = 0; x<w; x++ ) {
+ if ( !(*m&bit) )
+ b[x] = trans;
+ if (!(bit >>= 1)) {
+ bit = 0x80;
+ while ( x<w-1 && *++m == 0xff ) // skip chunks
+ x+=8;
+ }
+ }
+ }
+ }
+#endif
+
+ if ( ( conversion_flags & TQt::Dither_Mask ) == TQt::DiffuseDither ) {
+ delete [] line1[0];
+ delete [] line2[0];
+ delete [] line1[1];
+ delete [] line2[1];
+ delete [] line1[2];
+ delete [] line2[2];
+ delete [] pv[0];
+ delete [] pv[1];
+ delete [] pv[2];
+ }
+
+#undef MAX_R
+#undef MAX_G
+#undef MAX_B
+#undef INDEXOF
+
+ }
+
+ return TRUE;
+}
+
+
+static bool convert_8_to_32( const TQImage *src, TQImage *dst )
+{
+ if ( !dst->create(src->width(), src->height(), 32) )
+ return FALSE; // create failed
+ dst->setAlphaBuffer( src->hasAlphaBuffer() );
+ for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
+ register uint *p = (uint *)dst->scanLine(y);
+ uchar *b = src->scanLine(y);
+ uint *end = p + dst->width();
+ while ( p < end )
+ *p++ = src->color(*b++);
+ }
+ return TRUE;
+}
+
+
+static bool convert_1_to_32( const TQImage *src, TQImage *dst )
+{
+ if ( !dst->create(src->width(), src->height(), 32) )
+ return FALSE; // could not create
+ dst->setAlphaBuffer( src->hasAlphaBuffer() );
+ for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
+ register uint *p = (uint *)dst->scanLine(y);
+ uchar *b = src->scanLine(y);
+ int x;
+ if ( src->bitOrder() == TQImage::BigEndian ) {
+ for ( x=0; x<dst->width(); x++ ) {
+ *p++ = src->color( (*b >> (7 - (x & 7))) & 1 );
+ if ( (x & 7) == 7 )
+ b++;
+ }
+ } else {
+ for ( x=0; x<dst->width(); x++ ) {
+ *p++ = src->color( (*b >> (x & 7)) & 1 );
+ if ( (x & 7) == 7 )
+ b++;
+ }
+ }
+ }
+ return TRUE;
+}
+#endif // TQT_NO_IMAGE_TRUECOLOR
+
+static bool convert_1_to_8( const TQImage *src, TQImage *dst )
+{
+ if ( !dst->create(src->width(), src->height(), 8, 2) )
+ return FALSE; // something failed
+ dst->setAlphaBuffer( src->hasAlphaBuffer() );
+ if (src->numColors() >= 2) {
+ dst->setColor( 0, src->color(0) ); // copy color table
+ dst->setColor( 1, src->color(1) );
+ } else {
+ // Unlikely, but they do exist
+ if (src->numColors() >= 1)
+ dst->setColor( 0, src->color(0) );
+ else
+ dst->setColor( 0, 0xffffffff );
+ dst->setColor( 1, 0xff000000 );
+ }
+ for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
+ register uchar *p = dst->scanLine(y);
+ uchar *b = src->scanLine(y);
+ int x;
+ if ( src->bitOrder() == TQImage::BigEndian ) {
+ for ( x=0; x<dst->width(); x++ ) {
+ *p++ = (*b >> (7 - (x & 7))) & 1;
+ if ( (x & 7) == 7 )
+ b++;
+ }
+ } else {
+ for ( x=0; x<dst->width(); x++ ) {
+ *p++ = (*b >> (x & 7)) & 1;
+ if ( (x & 7) == 7 )
+ b++;
+ }
+ }
+ }
+ return TRUE;
+}
+
+#ifndef TQT_NO_IMAGE_DITHER_TO_1
+//
+// dither_to_1: Uses selected dithering algorithm.
+//
+
+static bool dither_to_1( const TQImage *src, TQImage *dst,
+ int conversion_flags, bool fromalpha )
+{
+ if ( !dst->create(src->width(), src->height(), 1, 2, TQImage::BigEndian) )
+ return FALSE; // something failed
+
+ enum { Threshold, Ordered, Diffuse } dithermode;
+
+ if ( fromalpha ) {
+ if ( ( conversion_flags & TQt::AlphaDither_Mask ) == TQt::DiffuseAlphaDither )
+ dithermode = Diffuse;
+ else if ( ( conversion_flags & TQt::AlphaDither_Mask ) == TQt::OrderedAlphaDither )
+ dithermode = Ordered;
+ else
+ dithermode = Threshold;
+ } else {
+ if ( ( conversion_flags & TQt::Dither_Mask ) == TQt::ThresholdDither )
+ dithermode = Threshold;
+ else if ( ( conversion_flags & TQt::Dither_Mask ) == TQt::OrderedDither )
+ dithermode = Ordered;
+ else
+ dithermode = Diffuse;
+ }
+
+ dst->setColor( 0, tqRgb(255, 255, 255) );
+ dst->setColor( 1, tqRgb( 0, 0, 0) );
+ int w = src->width();
+ int h = src->height();
+ int d = src->depth();
+ uchar gray[256]; // gray map for 8 bit images
+ bool use_gray = d == 8;
+ if ( use_gray ) { // make gray map
+ if ( fromalpha ) {
+ // Alpha 0x00 -> 0 pixels (white)
+ // Alpha 0xFF -> 1 pixels (black)
+ for ( int i=0; i<src->numColors(); i++ )
+ gray[i] = (255 - (src->color(i) >> 24));
+ } else {
+ // Pixel 0x00 -> 1 pixels (black)
+ // Pixel 0xFF -> 0 pixels (white)
+ for ( int i=0; i<src->numColors(); i++ )
+ gray[i] = tqGray( src->color(i) & 0x00ffffff );
+ }
+ }
+
+ switch ( dithermode ) {
+ case Diffuse: {
+ int *line1 = new int[w];
+ int *line2 = new int[w];
+ int bmwidth = (w+7)/8;
+ if ( !(line1 && line2) )
+ return FALSE;
+ register uchar *p;
+ uchar *end;
+ int *b1, *b2;
+ int wbytes = w * (d/8);
+ p = src->bits();
+ end = p + wbytes;
+ b2 = line2;
+ if ( use_gray ) { // 8 bit image
+ while ( p < end )
+ *b2++ = gray[*p++];
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ } else { // 32 bit image
+ if ( fromalpha ) {
+ while ( p < end ) {
+ *b2++ = 255 - (*(uint*)p >> 24);
+ p += 4;
+ }
+ } else {
+ while ( p < end ) {
+ *b2++ = tqGray(*(uint*)p);
+ p += 4;
+ }
+ }
+#endif
+ }
+ int x, y;
+ for ( y=0; y<h; y++ ) { // for each scan line...
+ int *tmp = line1; line1 = line2; line2 = tmp;
+ bool not_last_line = y < h - 1;
+ if ( not_last_line ) { // calc. grayvals for next line
+ p = src->scanLine(y+1);
+ end = p + wbytes;
+ b2 = line2;
+ if ( use_gray ) { // 8 bit image
+ while ( p < end )
+ *b2++ = gray[*p++];
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ } else { // 24 bit image
+ if ( fromalpha ) {
+ while ( p < end ) {
+ *b2++ = 255 - (*(uint*)p >> 24);
+ p += 4;
+ }
+ } else {
+ while ( p < end ) {
+ *b2++ = tqGray(*(uint*)p);
+ p += 4;
+ }
+ }
+#endif
+ }
+ }
+
+ int err;
+ p = dst->scanLine( y );
+ memset( p, 0, bmwidth );
+ b1 = line1;
+ b2 = line2;
+ int bit = 7;
+ for ( x=1; x<=w; x++ ) {
+ if ( *b1 < 128 ) { // black pixel
+ err = *b1++;
+ *p |= 1 << bit;
+ } else { // white pixel
+ err = *b1++ - 255;
+ }
+ if ( bit == 0 ) {
+ p++;
+ bit = 7;
+ } else {
+ bit--;
+ }
+ if ( x < w )
+ *b1 += (err*7)>>4; // spread error to right pixel
+ if ( not_last_line ) {
+ b2[0] += (err*5)>>4; // pixel below
+ if ( x > 1 )
+ b2[-1] += (err*3)>>4; // pixel below left
+ if ( x < w )
+ b2[1] += err>>4; // pixel below right
+ }
+ b2++;
+ }
+ }
+ delete [] line1;
+ delete [] line2;
+ } break;
+ case Ordered: {
+ static uint bm[16][16];
+ static int init=0;
+ if (!init) {
+ // Build a Bayer Matrix for dithering
+
+ init = 1;
+ int n, i, j;
+
+ bm[0][0]=0;
+
+ for (n=1; n<16; n*=2) {
+ for (i=0; i<n; i++) {
+ for (j=0; j<n; j++) {
+ bm[i][j]*=4;
+ bm[i+n][j]=bm[i][j]+2;
+ bm[i][j+n]=bm[i][j]+3;
+ bm[i+n][j+n]=bm[i][j]+1;
+ }
+ }
+ }
+
+ // Force black to black
+ bm[0][0]=1;
+ }
+
+ dst->fill( 0 );
+ uchar** mline = dst->jumpTable();
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ if ( d == 32 ) {
+ uint** line = (uint**)src->jumpTable();
+ for ( int i=0; i<h; i++ ) {
+ uint *p = line[i];
+ uint *end = p + w;
+ uchar *m = mline[i];
+ int bit = 7;
+ int j = 0;
+ if ( fromalpha ) {
+ while ( p < end ) {
+ if ( (*p++ >> 24) >= bm[j++&15][i&15] )
+ *m |= 1 << bit;
+ if ( bit == 0 ) {
+ m++;
+ bit = 7;
+ } else {
+ bit--;
+ }
+ }
+ } else {
+ while ( p < end ) {
+ if ( (uint)tqGray(*p++) < bm[j++&15][i&15] )
+ *m |= 1 << bit;
+ if ( bit == 0 ) {
+ m++;
+ bit = 7;
+ } else {
+ bit--;
+ }
+ }
+ }
+ }
+ } else
+#endif // TQT_NO_IMAGE_TRUECOLOR
+ /* ( d == 8 ) */ {
+ uchar** line = src->jumpTable();
+ for ( int i=0; i<h; i++ ) {
+ uchar *p = line[i];
+ uchar *end = p + w;
+ uchar *m = mline[i];
+ int bit = 7;
+ int j = 0;
+ while ( p < end ) {
+ if ( (uint)gray[*p++] < bm[j++&15][i&15] )
+ *m |= 1 << bit;
+ if ( bit == 0 ) {
+ m++;
+ bit = 7;
+ } else {
+ bit--;
+ }
+ }
+ }
+ }
+ } break;
+ default: { // Threshold:
+ dst->fill( 0 );
+ uchar** mline = dst->jumpTable();
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ if ( d == 32 ) {
+ uint** line = (uint**)src->jumpTable();
+ for ( int i=0; i<h; i++ ) {
+ uint *p = line[i];
+ uint *end = p + w;
+ uchar *m = mline[i];
+ int bit = 7;
+ if ( fromalpha ) {
+ while ( p < end ) {
+ if ( (*p++ >> 24) >= 128 )
+ *m |= 1 << bit; // Set tqmask "on"
+ if ( bit == 0 ) {
+ m++;
+ bit = 7;
+ } else {
+ bit--;
+ }
+ }
+ } else {
+ while ( p < end ) {
+ if ( tqGray(*p++) < 128 )
+ *m |= 1 << bit; // Set pixel "black"
+ if ( bit == 0 ) {
+ m++;
+ bit = 7;
+ } else {
+ bit--;
+ }
+ }
+ }
+ }
+ } else
+#endif //TQT_NO_IMAGE_TRUECOLOR
+ if ( d == 8 ) {
+ uchar** line = src->jumpTable();
+ for ( int i=0; i<h; i++ ) {
+ uchar *p = line[i];
+ uchar *end = p + w;
+ uchar *m = mline[i];
+ int bit = 7;
+ while ( p < end ) {
+ if ( gray[*p++] < 128 )
+ *m |= 1 << bit; // Set tqmask "on"/ pixel "black"
+ if ( bit == 0 ) {
+ m++;
+ bit = 7;
+ } else {
+ bit--;
+ }
+ }
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+#endif
+
+#ifndef TQT_NO_IMAGE_16_BIT
+//###### Endianness issues!
+static inline bool is16BitGray( ushort c )
+{
+ int r=(c & 0xf800) >> 11;
+ int g=(c & 0x07e0) >> 6; //green/2
+ int b=(c & 0x001f);
+ return r == g && g == b;
+}
+
+
+static bool convert_16_to_32( const TQImage *src, TQImage *dst )
+{
+ if ( !dst->create(src->width(), src->height(), 32) )
+ return FALSE; // create failed
+ dst->setAlphaBuffer( src->hasAlphaBuffer() );
+ for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
+ register uint *p = (uint *)dst->scanLine(y);
+ ushort *s = (ushort*)src->scanLine(y);
+ uint *end = p + dst->width();
+ while ( p < end )
+ *p++ = qt_conv16ToRgb( *s++ );
+ }
+ return TRUE;
+}
+
+
+static bool convert_32_to_16( const TQImage *src, TQImage *dst )
+{
+ if ( !dst->create(src->width(), src->height(), 16) )
+ return FALSE; // create failed
+ dst->setAlphaBuffer( src->hasAlphaBuffer() );
+ for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
+ register ushort *p = (ushort *)dst->scanLine(y);
+ uint *s = (uint*)src->scanLine(y);
+ ushort *end = p + dst->width();
+ while ( p < end )
+ *p++ = qt_convRgbTo16( *s++ );
+ }
+ return TRUE;
+}
+
+
+#endif
+
+/*!
+ Converts the depth (bpp) of the image to \a depth and returns the
+ converted image. The original image is not changed.
+
+ The \a depth argument must be 1, 8, 16 (TQt/Embedded only) or 32.
+
+ Returns \c *this if \a depth is equal to the image depth, or a
+ \link isNull() null\endlink image if this image cannot be
+ converted.
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a
+ conversion_flags to specify how you'd prefer this to happen.
+
+ \sa TQt::ImageConversionFlags depth() isNull()
+*/
+
+TQImage TQImage::convertDepth( int depth, int conversion_flags ) const
+{
+ TQImage image;
+ if ( data->d == depth )
+ image = *this; // no conversion
+#ifndef TQT_NO_IMAGE_DITHER_TO_1
+ else if ( (data->d == 8 || data->d == 32) && depth == 1 ) // dither
+ dither_to_1( this, &image, conversion_flags, FALSE );
+#endif
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ else if ( data->d == 32 && depth == 8 ) // 32 -> 8
+ convert_32_to_8( this, &image, conversion_flags );
+ else if ( data->d == 8 && depth == 32 ) // 8 -> 32
+ convert_8_to_32( this, &image );
+#endif
+ else if ( data->d == 1 && depth == 8 ) // 1 -> 8
+ convert_1_to_8( this, &image );
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ else if ( data->d == 1 && depth == 32 ) // 1 -> 32
+ convert_1_to_32( this, &image );
+#endif
+#ifndef TQT_NO_IMAGE_16_BIT
+ else if ( data->d == 16 && depth != 16 ) {
+ TQImage tmp;
+ convert_16_to_32( this, &tmp );
+ image = tmp.convertDepth( depth, conversion_flags );
+ } else if ( data->d != 16 && depth == 16 ) {
+ TQImage tmp = convertDepth( 32, conversion_flags );
+ convert_32_to_16( &tmp, &image );
+ }
+#endif
+ else {
+#if defined(TQT_CHECK_RANGE)
+ if ( isNull() )
+ qWarning( "TQImage::convertDepth: Image is a null image" );
+ else
+ qWarning( "TQImage::convertDepth: Depth %d not supported", depth );
+#endif
+ }
+ return image;
+}
+
+/*!
+ \overload
+*/
+
+TQImage TQImage::convertDepth( int depth ) const
+{
+ return convertDepth( depth, 0 );
+}
+
+/*!
+ Returns TRUE if ( \a x, \a y ) is a valid coordinate in the image;
+ otherwise returns FALSE.
+
+ \sa width() height() pixelIndex()
+*/
+
+bool TQImage::valid( int x, int y ) const
+{
+ return x >= 0 && x < width()
+ && y >= 0 && y < height();
+}
+
+/*!
+ Returns the pixel index at the given coordinates.
+
+ If (\a x, \a y) is not \link valid() valid\endlink, or if the
+ image is not a paletted image (depth() \> 8), the results are
+ undefined.
+
+ \sa valid() depth()
+*/
+
+int TQImage::pixelIndex( int x, int y ) const
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( x < 0 || x >= width() ) {
+ qWarning( "TQImage::pixel: x=%d out of range", x );
+ return -12345;
+ }
+#endif
+ uchar * s = scanLine( y );
+ switch( depth() ) {
+ case 1:
+ if ( bitOrder() == TQImage::LittleEndian )
+ return (*(s + (x >> 3)) >> (x & 7)) & 1;
+ else
+ return (*(s + (x >> 3)) >> (7- (x & 7))) & 1;
+ case 8:
+ return (int)s[x];
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+#ifndef TQT_NO_IMAGE_16_BIT
+ case 16:
+#endif
+ case 32:
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::pixelIndex: Not applicable for %d-bpp images "
+ "(no palette)", depth() );
+#endif
+ return 0;
+#endif //TQT_NO_IMAGE_TRUECOLOR
+ }
+ return 0;
+}
+
+
+/*!
+ Returns the color of the pixel at the coordinates (\a x, \a y).
+
+ If (\a x, \a y) is not \link valid() on the image\endlink, the
+ results are undefined.
+
+ \sa setPixel() tqRed() tqGreen() tqBlue() valid()
+*/
+
+TQRgb TQImage::pixel( int x, int y ) const
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( x < 0 || x >= width() ) {
+ qWarning( "TQImage::pixel: x=%d out of range", x );
+ return 12345;
+ }
+#endif
+ uchar * s = scanLine( y );
+ switch( depth() ) {
+ case 1:
+ if ( bitOrder() == TQImage::LittleEndian )
+ return color( (*(s + (x >> 3)) >> (x & 7)) & 1 );
+ else
+ return color( (*(s + (x >> 3)) >> (7- (x & 7))) & 1 );
+ case 8:
+ return color( (int)s[x] );
+#ifndef TQT_NO_IMAGE_16_BIT
+ case 16:
+ return qt_conv16ToRgb(((ushort*)s)[x]);
+#endif
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ case 32:
+ return ((TQRgb*)s)[x];
+#endif
+ default:
+ return 100367;
+ }
+}
+
+
+/*!
+ Sets the pixel index or color at the coordinates (\a x, \a y) to
+ \a index_or_rgb.
+
+ If (\a x, \a y) is not \link valid() valid\endlink, the result is
+ undefined.
+
+ If the image is a paletted image (depth() \<= 8) and \a
+ index_or_rgb \>= numColors(), the result is undefined.
+
+ \sa pixelIndex() pixel() tqRgb() tqRgba() valid()
+*/
+
+void TQImage::setPixel( int x, int y, uint index_or_rgb )
+{
+ if ( x < 0 || x >= width() ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::setPixel: x=%d out of range", x );
+#endif
+ return;
+ }
+ if ( depth() == 1 ) {
+ uchar * s = scanLine( y );
+ if ( index_or_rgb > 1) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::setPixel: index=%d out of range",
+ index_or_rgb );
+#endif
+ } else if ( bitOrder() == TQImage::LittleEndian ) {
+ if (index_or_rgb==0)
+ *(s + (x >> 3)) &= ~(1 << (x & 7));
+ else
+ *(s + (x >> 3)) |= (1 << (x & 7));
+ } else {
+ if (index_or_rgb==0)
+ *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
+ else
+ *(s + (x >> 3)) |= (1 << (7-(x & 7)));
+ }
+ } else if ( depth() == 8 ) {
+ if (index_or_rgb > (uint)numColors()) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::setPixel: index=%d out of range",
+ index_or_rgb );
+#endif
+ return;
+ }
+ uchar * s = scanLine( y );
+ s[x] = index_or_rgb;
+#ifndef TQT_NO_IMAGE_16_BIT
+ } else if ( depth() == 16 ) {
+ ushort * s = (ushort*)scanLine( y );
+ s[x] = qt_convRgbTo16(index_or_rgb);
+#endif
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ } else if ( depth() == 32 ) {
+ TQRgb * s = (TQRgb*)scanLine( y );
+ s[x] = index_or_rgb;
+#endif
+ }
+}
+
+
+/*!
+ Converts the bit order of the image to \a bitOrder and returns the
+ converted image. The original image is not changed.
+
+ Returns \c *this if the \a bitOrder is equal to the image bit
+ order, or a \link isNull() null\endlink image if this image cannot
+ be converted.
+
+ \sa bitOrder() systemBitOrder() isNull()
+*/
+
+TQImage TQImage::convertBitOrder( Endian bitOrder ) const
+{
+ if ( isNull() || data->d != 1 || // invalid argument(s)
+ !(bitOrder == BigEndian || bitOrder == LittleEndian) ) {
+ TQImage nullImage;
+ return nullImage;
+ }
+ if ( data->bitordr == bitOrder ) // nothing to do
+ return copy();
+
+ TQImage image( data->w, data->h, 1, data->ncols, bitOrder );
+
+ int bpl = (width() + 7) / 8;
+ for ( int y = 0; y < data->h; y++ ) {
+ register uchar *p = jumpTable()[y];
+ uchar *end = p + bpl;
+ uchar *b = image.jumpTable()[y];
+ while ( p < end )
+ *b++ = bitflip[*p++];
+ }
+ memcpy( image.colorTable(), colorTable(), numColors()*sizeof(TQRgb) );
+ return image;
+}
+
+// ### Candidate (renamed) for tqcolor.h
+static
+bool isGray(TQRgb c)
+{
+ return tqRed(c) == tqGreen(c)
+ && tqRed(c) == tqBlue(c);
+}
+
+/*!
+ Returns TRUE if all the colors in the image are shades of gray
+ (i.e. their red, green and blue components are equal); otherwise
+ returns FALSE.
+
+ This function is slow for large 16-bit (TQt/Embedded only) and 32-bit images.
+
+ \sa isGrayscale()
+*/
+bool TQImage::allGray() const
+{
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ if (depth()==32) {
+ int p = width()*height();
+ TQRgb* b = (TQRgb*)bits();
+ while (p--)
+ if (!isGray(*b++))
+ return FALSE;
+#ifndef TQT_NO_IMAGE_16_BIT
+ } else if (depth()==16) {
+ int p = width()*height();
+ ushort* b = (ushort*)bits();
+ while (p--)
+ if (!is16BitGray(*b++))
+ return FALSE;
+#endif
+ } else
+#endif //TQT_NO_IMAGE_TRUECOLOR
+ {
+ if (!data->ctbl) return TRUE;
+ for (int i=0; i<numColors(); i++)
+ if (!isGray(data->ctbl[i]))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/*!
+ For 16-bit (TQt/Embedded only) and 32-bit images, this function is
+ equivalent to allGray().
+
+ For 8-bpp images, this function returns TRUE if color(i) is
+ TQRgb(i,i,i) for all indices of the color table; otherwise returns
+ FALSE.
+
+ \sa allGray() depth()
+*/
+bool TQImage::isGrayscale() const
+{
+ switch (depth()) {
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ case 32:
+#ifndef TQT_NO_IMAGE_16_BIT
+ case 16:
+#endif
+ return allGray();
+#endif //TQT_NO_IMAGE_TRUECOLOR
+ case 8: {
+ for (int i=0; i<numColors(); i++)
+ if (data->ctbl[i] != tqRgb(i,i,i))
+ return FALSE;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+#ifndef TQT_NO_IMAGE_SMOOTHSCALE
+static
+void pnmscale(const TQImage& src, TQImage& dst)
+{
+ TQRgb* xelrow = 0;
+ TQRgb* tempxelrow = 0;
+ register TQRgb* xP;
+ register TQRgb* nxP;
+ int rows, cols, rowsread, newrows, newcols;
+ register int row, col, needtoreadrow;
+ const uchar maxval = 255;
+ double xscale, yscale;
+ long sxscale, syscale;
+ register long fracrowtofill, fracrowleft;
+ long* as;
+ long* rs;
+ long* gs;
+ long* bs;
+ int rowswritten = 0;
+
+ cols = src.width();
+ rows = src.height();
+ newcols = dst.width();
+ newrows = dst.height();
+
+ long SCALE;
+ long HALFSCALE;
+
+ if (cols > 4096)
+ {
+ SCALE = 4096;
+ HALFSCALE = 2048;
+ }
+ else
+ {
+ int fac = 4096;
+
+ while (cols * fac > 4096)
+ {
+ fac /= 2;
+ }
+
+ SCALE = fac * cols;
+ HALFSCALE = fac * cols / 2;
+ }
+
+ xscale = (double) newcols / (double) cols;
+ yscale = (double) newrows / (double) rows;
+
+ sxscale = (long)(xscale * SCALE);
+ syscale = (long)(yscale * SCALE);
+
+ if ( newrows != rows ) /* shortcut Y scaling if possible */
+ tempxelrow = new TQRgb[cols];
+
+ if ( src.hasAlphaBuffer() ) {
+ dst.setAlphaBuffer(TRUE);
+ as = new long[cols];
+ for ( col = 0; col < cols; ++col )
+ as[col] = HALFSCALE;
+ } else {
+ as = 0;
+ }
+ rs = new long[cols];
+ gs = new long[cols];
+ bs = new long[cols];
+ rowsread = 0;
+ fracrowleft = syscale;
+ needtoreadrow = 1;
+ for ( col = 0; col < cols; ++col )
+ rs[col] = gs[col] = bs[col] = HALFSCALE;
+ fracrowtofill = SCALE;
+
+ for ( row = 0; row < newrows; ++row ) {
+ /* First scale Y from xelrow into tempxelrow. */
+ if ( newrows == rows ) {
+ /* shortcut Y scaling if possible */
+ tempxelrow = xelrow = (TQRgb*)src.scanLine(rowsread++);
+ } else {
+ while ( fracrowleft < fracrowtofill ) {
+ if ( needtoreadrow && rowsread < rows )
+ xelrow = (TQRgb*)src.scanLine(rowsread++);
+ for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) {
+ if (as) {
+ as[col] += fracrowleft * tqAlpha( *xP );
+ rs[col] += fracrowleft * tqRed( *xP ) * tqAlpha( *xP ) / 255;
+ gs[col] += fracrowleft * tqGreen( *xP ) * tqAlpha( *xP ) / 255;
+ bs[col] += fracrowleft * tqBlue( *xP ) * tqAlpha( *xP ) / 255;
+ } else {
+ rs[col] += fracrowleft * tqRed( *xP );
+ gs[col] += fracrowleft * tqGreen( *xP );
+ bs[col] += fracrowleft * tqBlue( *xP );
+ }
+ }
+ fracrowtofill -= fracrowleft;
+ fracrowleft = syscale;
+ needtoreadrow = 1;
+ }
+ /* Now fracrowleft is >= fracrowtofill, so we can produce a row. */
+ if ( needtoreadrow && rowsread < rows ) {
+ xelrow = (TQRgb*)src.scanLine(rowsread++);
+ needtoreadrow = 0;
+ }
+ register long a=0;
+ for ( col = 0, xP = xelrow, nxP = tempxelrow;
+ col < cols; ++col, ++xP, ++nxP )
+ {
+ register long r, g, b;
+
+ if ( as ) {
+ r = rs[col] + fracrowtofill * tqRed( *xP ) * tqAlpha( *xP ) / 255;
+ g = gs[col] + fracrowtofill * tqGreen( *xP ) * tqAlpha( *xP ) / 255;
+ b = bs[col] + fracrowtofill * tqBlue( *xP ) * tqAlpha( *xP ) / 255;
+ a = as[col] + fracrowtofill * tqAlpha( *xP );
+ if ( a ) {
+ r = r * 255 / a * SCALE;
+ g = g * 255 / a * SCALE;
+ b = b * 255 / a * SCALE;
+ }
+ } else {
+ r = rs[col] + fracrowtofill * tqRed( *xP );
+ g = gs[col] + fracrowtofill * tqGreen( *xP );
+ b = bs[col] + fracrowtofill * tqBlue( *xP );
+ }
+ r /= SCALE;
+ if ( r > maxval ) r = maxval;
+ g /= SCALE;
+ if ( g > maxval ) g = maxval;
+ b /= SCALE;
+ if ( b > maxval ) b = maxval;
+ if ( as ) {
+ a /= SCALE;
+ if ( a > maxval ) a = maxval;
+ *nxP = tqRgba( (int)r, (int)g, (int)b, (int)a );
+ as[col] = HALFSCALE;
+ } else {
+ *nxP = tqRgb( (int)r, (int)g, (int)b );
+ }
+ rs[col] = gs[col] = bs[col] = HALFSCALE;
+ }
+ fracrowleft -= fracrowtofill;
+ if ( fracrowleft == 0 ) {
+ fracrowleft = syscale;
+ needtoreadrow = 1;
+ }
+ fracrowtofill = SCALE;
+ }
+
+ /* Now scale X from tempxelrow into dst and write it out. */
+ if ( newcols == cols ) {
+ /* shortcut X scaling if possible */
+ memcpy(dst.scanLine(rowswritten++), tempxelrow, newcols*4);
+ } else {
+ register long a, r, g, b;
+ register long fraccoltofill, fraccolleft = 0;
+ register int needcol;
+
+ nxP = (TQRgb*)dst.scanLine(rowswritten++);
+ fraccoltofill = SCALE;
+ a = r = g = b = HALFSCALE;
+ needcol = 0;
+ for ( col = 0, xP = tempxelrow; col < cols; ++col, ++xP ) {
+ fraccolleft = sxscale;
+ while ( fraccolleft >= fraccoltofill ) {
+ if ( needcol ) {
+ ++nxP;
+ a = r = g = b = HALFSCALE;
+ }
+ if ( as ) {
+ r += fraccoltofill * tqRed( *xP ) * tqAlpha( *xP ) / 255;
+ g += fraccoltofill * tqGreen( *xP ) * tqAlpha( *xP ) / 255;
+ b += fraccoltofill * tqBlue( *xP ) * tqAlpha( *xP ) / 255;
+ a += fraccoltofill * tqAlpha( *xP );
+ if ( a ) {
+ r = r * 255 / a * SCALE;
+ g = g * 255 / a * SCALE;
+ b = b * 255 / a * SCALE;
+ }
+ } else {
+ r += fraccoltofill * tqRed( *xP );
+ g += fraccoltofill * tqGreen( *xP );
+ b += fraccoltofill * tqBlue( *xP );
+ }
+ r /= SCALE;
+ if ( r > maxval ) r = maxval;
+ g /= SCALE;
+ if ( g > maxval ) g = maxval;
+ b /= SCALE;
+ if ( b > maxval ) b = maxval;
+ if (as) {
+ a /= SCALE;
+ if ( a > maxval ) a = maxval;
+ *nxP = tqRgba( (int)r, (int)g, (int)b, (int)a );
+ } else {
+ *nxP = tqRgb( (int)r, (int)g, (int)b );
+ }
+ fraccolleft -= fraccoltofill;
+ fraccoltofill = SCALE;
+ needcol = 1;
+ }
+ if ( fraccolleft > 0 ) {
+ if ( needcol ) {
+ ++nxP;
+ a = r = g = b = HALFSCALE;
+ needcol = 0;
+ }
+ if (as) {
+ a += fraccolleft * tqAlpha( *xP );
+ r += fraccolleft * tqRed( *xP ) * tqAlpha( *xP ) / 255;
+ g += fraccolleft * tqGreen( *xP ) * tqAlpha( *xP ) / 255;
+ b += fraccolleft * tqBlue( *xP ) * tqAlpha( *xP ) / 255;
+ } else {
+ r += fraccolleft * tqRed( *xP );
+ g += fraccolleft * tqGreen( *xP );
+ b += fraccolleft * tqBlue( *xP );
+ }
+ fraccoltofill -= fraccolleft;
+ }
+ }
+ if ( fraccoltofill > 0 ) {
+ --xP;
+ if (as) {
+ a += fraccolleft * tqAlpha( *xP );
+ r += fraccoltofill * tqRed( *xP ) * tqAlpha( *xP ) / 255;
+ g += fraccoltofill * tqGreen( *xP ) * tqAlpha( *xP ) / 255;
+ b += fraccoltofill * tqBlue( *xP ) * tqAlpha( *xP ) / 255;
+ if ( a ) {
+ r = r * 255 / a * SCALE;
+ g = g * 255 / a * SCALE;
+ b = b * 255 / a * SCALE;
+ }
+ } else {
+ r += fraccoltofill * tqRed( *xP );
+ g += fraccoltofill * tqGreen( *xP );
+ b += fraccoltofill * tqBlue( *xP );
+ }
+ }
+ if ( ! needcol ) {
+ r /= SCALE;
+ if ( r > maxval ) r = maxval;
+ g /= SCALE;
+ if ( g > maxval ) g = maxval;
+ b /= SCALE;
+ if ( b > maxval ) b = maxval;
+ if (as) {
+ a /= SCALE;
+ if ( a > maxval ) a = maxval;
+ *nxP = tqRgba( (int)r, (int)g, (int)b, (int)a );
+ } else {
+ *nxP = tqRgb( (int)r, (int)g, (int)b );
+ }
+ }
+ }
+ }
+
+ if ( newrows != rows && tempxelrow )// Robust, tempxelrow might be 0 1 day
+ delete [] tempxelrow;
+ if ( as ) // Avoid purify complaint
+ delete [] as;
+ if ( rs ) // Robust, rs might be 0 one day
+ delete [] rs;
+ if ( gs ) // Robust, gs might be 0 one day
+ delete [] gs;
+ if ( bs ) // Robust, bs might be 0 one day
+ delete [] bs;
+}
+#endif
+
+/*!
+ \enum TQImage::ScaleMode
+
+ The functions scale() and smoothScale() use different modes for
+ scaling the image. The purpose of these modes is to retain the
+ ratio of the image if this is required.
+
+ \img scaling.png
+
+ \value ScaleFree The image is scaled freely: the resulting image
+ fits exactly into the specified size; the ratio will not
+ necessarily be preserved.
+ \value ScaleMin The ratio of the image is preserved and the
+ resulting image is guaranteed to fit into the specified size
+ (it is as large as possible within these constraints) - the
+ image might be smaller than the requested size.
+ \value ScaleMax The ratio of the image is preserved and the
+ resulting image fills the whole specified rectangle (it is as
+ small as possible within these constraints) - the image might
+ be larger than the requested size.
+*/
+
+#ifndef TQT_NO_IMAGE_SMOOTHSCALE
+/*!
+ Returns a smoothly scaled copy of the image. The returned image
+ has a size of width \a w by height \a h pixels if \a mode is \c
+ ScaleFree. The modes \c ScaleMin and \c ScaleMax may be used to
+ preserve the ratio of the image: if \a mode is \c ScaleMin, the
+ returned image is guaranteed to fit into the rectangle specified
+ by \a w and \a h (it is as large as possible within the
+ constraints); if \a mode is \c ScaleMax, the returned image fits
+ at least into the specified rectangle (it is a small as possible
+ within the constraints).
+
+ For 32-bpp images and 1-bpp/8-bpp color images the result will be
+ 32-bpp, whereas \link allGray() all-gray \endlink images
+ (including black-and-white 1-bpp) will produce 8-bit \link
+ isGrayscale() grayscale \endlink images with the palette spanning
+ 256 grays from black to white.
+
+ This function uses code based on pnmscale.c by Jef Poskanzer.
+
+ pnmscale.c - read a portable anymap and scale it
+
+ \legalese
+
+ Copyright (C) 1989, 1991 by Jef Poskanzer.
+
+ Permission to use, copy, modify, and distribute this software and
+ its documentation for any purpose and without fee is hereby
+ granted, provided that the above copyright notice appear in all
+ copies and that both that copyright notice and this permission
+ notice appear in supporting documentation. This software is
+ provided "as is" without express or implied warranty.
+
+ \sa scale() mirror()
+*/
+TQImage TQImage::smoothScale( int w, int h, ScaleMode mode ) const
+{
+ return smoothScale( TQSize( w, h ), mode );
+}
+#endif
+
+#ifndef TQT_NO_IMAGE_SMOOTHSCALE
+/*!
+ \overload
+
+ The requested size of the image is \a s.
+*/
+TQImage TQImage::smoothScale( const TQSize& s, ScaleMode mode ) const
+{
+ if ( isNull() ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::smoothScale: Image is a null image" );
+#endif
+ return copy();
+ }
+
+ TQSize newSize = size();
+ newSize.scale( s, (TQSize::ScaleMode)mode ); // ### remove cast in TQt 4.0
+ if ( newSize == size() )
+ return copy();
+
+ if ( depth() == 32 ) {
+ TQImage img( newSize, 32 );
+ // 32-bpp to 32-bpp
+ pnmscale( *this, img );
+ return img;
+ } else if ( depth() != 16 && allGray() && !hasAlphaBuffer() ) {
+ // Inefficient
+ return convertDepth(32).smoothScale(newSize, mode).convertDepth(8);
+ } else {
+ // Inefficient
+ return convertDepth(32).smoothScale(newSize, mode);
+ }
+}
+#endif
+
+/*!
+ Returns a copy of the image scaled to a rectangle of width \a w
+ and height \a h according to the ScaleMode \a mode.
+
+ \list
+ \i If \a mode is \c ScaleFree, the image is scaled to (\a w,
+ \a h).
+ \i If \a mode is \c ScaleMin, the image is scaled to a rectangle
+ as large as possible inside (\a w, \a h), preserving the aspect
+ ratio.
+ \i If \a mode is \c ScaleMax, the image is scaled to a rectangle
+ as small as possible outside (\a w, \a h), preserving the aspect
+ ratio.
+ \endlist
+
+ If either the width \a w or the height \a h is 0 or negative, this
+ function returns a \link isNull() null\endlink image.
+
+ This function uses a simple, fast algorithm. If you need better
+ quality, use smoothScale() instead.
+
+ \sa scaleWidth() scaleHeight() smoothScale() xForm()
+*/
+#ifndef TQT_NO_IMAGE_TRANSFORMATION
+TQImage TQImage::scale( int w, int h, ScaleMode mode ) const
+{
+ return scale( TQSize( w, h ), mode );
+}
+#endif
+
+/*!
+ \overload
+
+ The requested size of the image is \a s.
+*/
+#ifndef TQT_NO_IMAGE_TRANSFORMATION
+TQImage TQImage::scale( const TQSize& s, ScaleMode mode ) const
+{
+ if ( isNull() ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::scale: Image is a null image" );
+#endif
+ return copy();
+ }
+ if ( s.isEmpty() )
+ return TQImage();
+
+ TQSize newSize = size();
+ newSize.scale( s, (TQSize::ScaleMode)mode ); // ### remove cast in TQt 4.0
+ if ( newSize == size() )
+ return copy();
+
+ TQImage img;
+ TQWMatrix wm;
+ wm.scale( (double)newSize.width() / width(), (double)newSize.height() / height() );
+ img = xForm( wm );
+ // ### I should test and resize the image if it has not the right size
+// if ( img.width() != newSize.width() || img.height() != newSize.height() )
+// img.resize( newSize.width(), newSize.height() );
+ return img;
+}
+#endif
+
+/*!
+ Returns a scaled copy of the image. The returned image has a width
+ of \a w pixels. This function automatically calculates the height
+ of the image so that the ratio of the image is preserved.
+
+ If \a w is 0 or negative a \link isNull() null\endlink image is
+ returned.
+
+ \sa scale() scaleHeight() smoothScale() xForm()
+*/
+#ifndef TQT_NO_IMAGE_TRANSFORMATION
+TQImage TQImage::scaleWidth( int w ) const
+{
+ if ( isNull() ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::scaleWidth: Image is a null image" );
+#endif
+ return copy();
+ }
+ if ( w <= 0 )
+ return TQImage();
+
+ TQWMatrix wm;
+ double factor = (double) w / width();
+ wm.scale( factor, factor );
+ return xForm( wm );
+}
+#endif
+
+/*!
+ Returns a scaled copy of the image. The returned image has a
+ height of \a h pixels. This function automatically calculates the
+ width of the image so that the ratio of the image is preserved.
+
+ If \a h is 0 or negative a \link isNull() null\endlink image is
+ returned.
+
+ \sa scale() scaleWidth() smoothScale() xForm()
+*/
+#ifndef TQT_NO_IMAGE_TRANSFORMATION
+TQImage TQImage::scaleHeight( int h ) const
+{
+ if ( isNull() ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage::scaleHeight: Image is a null image" );
+#endif
+ return copy();
+ }
+ if ( h <= 0 )
+ return TQImage();
+
+ TQWMatrix wm;
+ double factor = (double) h / height();
+ wm.scale( factor, factor );
+ return xForm( wm );
+}
+#endif
+
+
+/*!
+ Returns a copy of the image that is transformed using the
+ transformation matrix, \a matrix.
+
+ The transformation \a matrix is internally adjusted to compensate
+ for unwanted translation, i.e. xForm() returns the smallest image
+ that tqcontains all the transformed points of the original image.
+
+ \sa scale() TQPixmap::xForm() TQPixmap::trueMatrix() TQWMatrix
+*/
+#ifndef TQT_NO_IMAGE_TRANSFORMATION
+TQImage TQImage::xForm( const TQWMatrix &matrix ) const
+{
+ // This function uses the same algorithm as (and steals quite some
+ // code from) TQPixmap::xForm().
+
+ if ( isNull() )
+ return copy();
+
+ if ( depth() == 16 ) {
+ // inefficient
+ return convertDepth( 32 ).xForm( matrix );
+ }
+
+ // source image data
+ int ws = width();
+ int hs = height();
+ int sbpl = bytesPerLine();
+ uchar *sptr = bits();
+
+ // target image data
+ int wd;
+ int hd;
+
+ int bpp = depth();
+
+ // compute size of target image
+ TQWMatrix mat = TQPixmap::trueMatrix( matrix, ws, hs );
+ if ( mat.m12() == 0.0F && mat.m21() == 0.0F ) {
+ if ( mat.m11() == 1.0F && mat.m22() == 1.0F ) // identity matrix
+ return copy();
+ hd = tqRound( mat.m22() * hs );
+ wd = tqRound( mat.m11() * ws );
+ hd = TQABS( hd );
+ wd = TQABS( wd );
+ } else { // rotation or shearing
+ TQPointArray a( TQRect(0, 0, ws, hs) );
+ a = mat.map( a );
+ TQRect r = a.boundingRect().normalize();
+ wd = r.width();
+ hd = r.height();
+ }
+
+ bool invertible;
+ mat = mat.invert( &invertible ); // invert matrix
+ if ( hd == 0 || wd == 0 || !invertible ) // error, return null image
+ return TQImage();
+
+ // create target image (some of the code is from TQImage::copy())
+ TQImage dImage( wd, hd, depth(), numColors(), bitOrder() );
+
+ // If the image allocation failed, we need to gracefully abort.
+ if (dImage.isNull())
+ return dImage;
+
+ memcpy( dImage.colorTable(), colorTable(), numColors()*sizeof(TQRgb) );
+ dImage.setAlphaBuffer( hasAlphaBuffer() );
+ dImage.data->dpmx = dotsPerMeterX();
+ dImage.data->dpmy = dotsPerMeterY();
+
+ switch ( bpp ) {
+ // initizialize the data
+ case 1:
+ memset( dImage.bits(), 0, dImage.numBytes() );
+ break;
+ case 8:
+ if ( dImage.data->ncols < 256 ) {
+ // colors are left in the color table, so pick that one as transtqparent
+ dImage.setNumColors( dImage.data->ncols+1 );
+ dImage.setColor( dImage.data->ncols-1, 0x00 );
+ memset( dImage.bits(), dImage.data->ncols-1, dImage.numBytes() );
+ } else {
+ memset( dImage.bits(), 0, dImage.numBytes() );
+ }
+ break;
+ case 16:
+ memset( dImage.bits(), 0xff, dImage.numBytes() );
+ break;
+ case 32:
+ memset( dImage.bits(), 0x00, dImage.numBytes() );
+ break;
+ }
+
+ int type;
+ if ( bitOrder() == BigEndian )
+ type = TQT_XFORM_TYPE_MSBFIRST;
+ else
+ type = TQT_XFORM_TYPE_LSBFIRST;
+ int dbpl = dImage.bytesPerLine();
+ qt_xForm_helper( mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl,
+ ws, hs );
+ return dImage;
+}
+#endif
+
+/*!
+ Builds and returns a 1-bpp tqmask from the alpha buffer in this
+ image. Returns a \link isNull() null\endlink image if \link
+ setAlphaBuffer() alpha buffer mode\endlink is disabled.
+
+ See TQPixmap::convertFromImage() for a description of the \a
+ conversion_flags argument.
+
+ The returned image has little-endian bit order, which you can
+ convert to big-endianness using convertBitOrder().
+
+ \sa createHeuristicMask() hasAlphaBuffer() setAlphaBuffer()
+*/
+#ifndef TQT_NO_IMAGE_DITHER_TO_1
+TQImage TQImage::createAlphaMask( int conversion_flags ) const
+{
+ if ( conversion_flags == 1 ) {
+ // Old code is passing "TRUE".
+ conversion_flags = TQt::DiffuseAlphaDither;
+ }
+
+ if ( isNull() || !hasAlphaBuffer() )
+ return TQImage();
+
+ if ( depth() == 1 ) {
+ // A monochrome pixmap, with alpha channels on those two colors.
+ // Pretty unlikely, so use less efficient solution.
+ return convertDepth(8, conversion_flags)
+ .createAlphaMask( conversion_flags );
+ }
+
+ TQImage tqmask1;
+ dither_to_1( this, &tqmask1, conversion_flags, TRUE );
+ return tqmask1;
+}
+#endif
+
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+/*!
+ Creates and returns a 1-bpp heuristic tqmask for this image. It
+ works by selecting a color from one of the corners, then chipping
+ away pixels of that color starting at all the edges.
+
+ The four corners vote for which color is to be masked away. In
+ case of a draw (this generally means that this function is not
+ applicable to the image), the result is arbitrary.
+
+ The returned image has little-endian bit order, which you can
+ convert to big-endianness using convertBitOrder().
+
+ If \a clipTight is TRUE the tqmask is just large enough to cover the
+ pixels; otherwise, the tqmask is larger than the data pixels.
+
+ This function disregards the \link hasAlphaBuffer() alpha buffer
+ \endlink.
+
+ \sa createAlphaMask()
+*/
+
+TQImage TQImage::createHeuristicMask( bool clipTight ) const
+{
+ if ( isNull() ) {
+ TQImage nullImage;
+ return nullImage;
+ }
+ if ( depth() != 32 ) {
+ TQImage img32 = convertDepth(32);
+ return img32.createHeuristicMask(clipTight);
+ }
+
+#define PIX(x,y) (*((TQRgb*)scanLine(y)+x) & 0x00ffffff)
+
+ int w = width();
+ int h = height();
+ TQImage m(w, h, 1, 2, TQImage::LittleEndian);
+ m.setColor( 0, 0xffffff );
+ m.setColor( 1, 0 );
+ m.fill( 0xff );
+
+ TQRgb background = PIX(0,0);
+ if ( background != PIX(w-1,0) &&
+ background != PIX(0,h-1) &&
+ background != PIX(w-1,h-1) ) {
+ background = PIX(w-1,0);
+ if ( background != PIX(w-1,h-1) &&
+ background != PIX(0,h-1) &&
+ PIX(0,h-1) == PIX(w-1,h-1) ) {
+ background = PIX(w-1,h-1);
+ }
+ }
+
+ int x,y;
+ bool done = FALSE;
+ uchar *ypp, *ypc, *ypn;
+ while( !done ) {
+ done = TRUE;
+ ypn = m.scanLine(0);
+ ypc = 0;
+ for ( y = 0; y < h; y++ ) {
+ ypp = ypc;
+ ypc = ypn;
+ ypn = (y == h-1) ? 0 : m.scanLine(y+1);
+ TQRgb *p = (TQRgb *)scanLine(y);
+ for ( x = 0; x < w; x++ ) {
+ // slowness here - it's possible to do six of these tests
+ // together in one go. oh well.
+ if ( ( x == 0 || y == 0 || x == w-1 || y == h-1 ||
+ !(*(ypc + ((x-1) >> 3)) & (1 << ((x-1) & 7))) ||
+ !(*(ypc + ((x+1) >> 3)) & (1 << ((x+1) & 7))) ||
+ !(*(ypp + (x >> 3)) & (1 << (x & 7))) ||
+ !(*(ypn + (x >> 3)) & (1 << (x & 7))) ) &&
+ ( (*(ypc + (x >> 3)) & (1 << (x & 7))) ) &&
+ ( (*p & 0x00ffffff) == background ) ) {
+ done = FALSE;
+ *(ypc + (x >> 3)) &= ~(1 << (x & 7));
+ }
+ p++;
+ }
+ }
+ }
+
+ if ( !clipTight ) {
+ ypn = m.scanLine(0);
+ ypc = 0;
+ for ( y = 0; y < h; y++ ) {
+ ypp = ypc;
+ ypc = ypn;
+ ypn = (y == h-1) ? 0 : m.scanLine(y+1);
+ TQRgb *p = (TQRgb *)scanLine(y);
+ for ( x = 0; x < w; x++ ) {
+ if ( (*p & 0x00ffffff) != background ) {
+ if ( x > 0 )
+ *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7));
+ if ( x < w-1 )
+ *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7));
+ if ( y > 0 )
+ *(ypp + (x >> 3)) |= (1 << (x & 7));
+ if ( y < h-1 )
+ *(ypn + (x >> 3)) |= (1 << (x & 7));
+ }
+ p++;
+ }
+ }
+ }
+
+#undef PIX
+
+ return m;
+}
+#endif //TQT_NO_IMAGE_HEURISTIC_MASK
+
+#ifndef TQT_NO_IMAGE_MIRROR
+/*
+ This code is contributed by Philipp Lang,
+ GeneriCom Software Germany (www.generi.com)
+ under the terms of the TQPL, Version 1.0
+*/
+
+/*!
+ \overload
+
+ Returns a mirror of the image, mirrored in the horizontal and/or
+ the vertical direction depending on whether \a horizontal and \a
+ vertical are set to TRUE or FALSE. The original image is not
+ changed.
+
+ \sa smoothScale()
+*/
+TQImage TQImage::mirror(bool horizontal, bool vertical) const
+{
+ int w = width();
+ int h = height();
+ if ( (w <= 1 && h <= 1) || (!horizontal && !vertical) )
+ return copy();
+
+ // Create result image, copy colormap
+ TQImage result(w, h, depth(), numColors(), bitOrder());
+ memcpy(result.colorTable(), colorTable(), numColors()*sizeof(TQRgb));
+ result.setAlphaBuffer(hasAlphaBuffer());
+
+ if (depth() == 1)
+ w = (w+7)/8;
+ int dxi = horizontal ? -1 : 1;
+ int dxs = horizontal ? w-1 : 0;
+ int dyi = vertical ? -1 : 1;
+ int dy = vertical ? h-1: 0;
+
+ // 1 bit, 8 bit
+ if (depth() == 1 || depth() == 8) {
+ for (int sy = 0; sy < h; sy++, dy += dyi) {
+ TQ_UINT8* ssl = (TQ_UINT8*)(data->bits[sy]);
+ TQ_UINT8* dsl = (TQ_UINT8*)(result.data->bits[dy]);
+ int dx = dxs;
+ for (int sx = 0; sx < w; sx++, dx += dxi)
+ dsl[dx] = ssl[sx];
+ }
+ }
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+#ifndef TQT_NO_IMAGE_16_BIT
+ // 16 bit
+ else if (depth() == 16) {
+ for (int sy = 0; sy < h; sy++, dy += dyi) {
+ TQ_UINT16* ssl = (TQ_UINT16*)(data->bits[sy]);
+ TQ_UINT16* dsl = (TQ_UINT16*)(result.data->bits[dy]);
+ int dx = dxs;
+ for (int sx = 0; sx < w; sx++, dx += dxi)
+ dsl[dx] = ssl[sx];
+ }
+ }
+#endif
+ // 32 bit
+ else if (depth() == 32) {
+ for (int sy = 0; sy < h; sy++, dy += dyi) {
+ TQ_UINT32* ssl = (TQ_UINT32*)(data->bits[sy]);
+ TQ_UINT32* dsl = (TQ_UINT32*)(result.data->bits[dy]);
+ int dx = dxs;
+ for (int sx = 0; sx < w; sx++, dx += dxi)
+ dsl[dx] = ssl[sx];
+ }
+ }
+#endif
+
+ // special handling of 1 bit images for horizontal mirroring
+ if (horizontal && depth() == 1) {
+ int shift = width() % 8;
+ for (int y = h-1; y >= 0; y--) {
+ TQ_UINT8* a0 = (TQ_UINT8*)(result.data->bits[y]);
+ // Swap bytes
+ TQ_UINT8* a = a0+dxs;
+ while (a >= a0) {
+ *a = bitflip[*a];
+ a--;
+ }
+ // Shift bits if unaligned
+ if (shift != 0) {
+ a = a0+dxs;
+ TQ_UINT8 c = 0;
+ if (bitOrder() == TQImage::LittleEndian) {
+ while (a >= a0) {
+ TQ_UINT8 nc = *a << shift;
+ *a = (*a >> (8-shift)) | c;
+ --a;
+ c = nc;
+ }
+ } else {
+ while (a >= a0) {
+ TQ_UINT8 nc = *a >> shift;
+ *a = (*a << (8-shift)) | c;
+ --a;
+ c = nc;
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+}
+
+/*!
+ Returns a TQImage which is a vertically mirrored copy of this
+ image. The original TQImage is not changed.
+*/
+
+TQImage TQImage::mirror() const
+{
+ return mirror(FALSE,TRUE);
+}
+#endif //TQT_NO_IMAGE_MIRROR
+
+/*!
+ Returns a TQImage in which the values of the red and blue
+ components of all pixels have been swapped, effectively converting
+ an RGB image to a BGR image. The original TQImage is not changed.
+*/
+
+TQImage TQImage::swapRGB() const
+{
+ TQImage res = copy();
+ if ( !isNull() ) {
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ if ( depth() == 32 ) {
+ for ( int i=0; i < height(); i++ ) {
+ uint *p = (uint*)scanLine( i );
+ uint *q = (uint*)res.scanLine( i );
+ uint *end = p + width();
+ while ( p < end ) {
+ *q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) |
+ (*p & 0xff00ff00);
+ p++;
+ q++;
+ }
+ }
+#ifndef TQT_NO_IMAGE_16_BIT
+ } else if ( depth() == 16 ) {
+ qWarning( "TQImage::swapRGB not implemented for 16bpp" );
+#endif
+ } else
+#endif //TQT_NO_IMAGE_TRUECOLOR
+ {
+ uint* p = (uint*)colorTable();
+ uint* q = (uint*)res.colorTable();
+ if ( p && q ) {
+ for ( int i=0; i < numColors(); i++ ) {
+ *q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) |
+ (*p & 0xff00ff00);
+ p++;
+ q++;
+ }
+ }
+ }
+ }
+ return res;
+}
+
+#ifndef TQT_NO_IMAGEIO
+/*!
+ Returns a string that specifies the image format of the file \a
+ fileName, or 0 if the file cannot be read or if the format is not
+ recognized.
+
+ The TQImageIO documentation lists the guaranteed supported image
+ formats, or use TQImage::inputFormats() and TQImage::outputFormats()
+ to get lists that include the installed formats.
+
+ \sa load() save()
+*/
+
+const char* TQImage::imageFormat( const TQString &fileName )
+{
+ return TQImageIO::imageFormat( fileName );
+}
+
+/*!
+ Returns a list of image formats that are supported for image
+ input.
+
+ \sa outputFormats() inputFormatList() TQImageIO
+*/
+TQStrList TQImage::inputFormats()
+{
+ return TQImageIO::inputFormats();
+}
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Returns a list of image formats that are supported for image
+ input.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myImage.inputFormatList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa outputFormatList() inputFormats() TQImageIO
+*/
+TQStringList TQImage::inputFormatList()
+{
+ return TQStringList::fromStrList(TQImageIO::inputFormats());
+}
+
+
+/*!
+ Returns a list of image formats that are supported for image
+ output.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myImage.outputFormatList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa inputFormatList() outputFormats() TQImageIO
+*/
+TQStringList TQImage::outputFormatList()
+{
+ return TQStringList::fromStrList(TQImageIO::outputFormats());
+}
+#endif //TQT_NO_STRINGLIST
+
+/*!
+ Returns a list of image formats that are supported for image
+ output.
+
+ \sa inputFormats() outputFormatList() TQImageIO
+*/
+TQStrList TQImage::outputFormats()
+{
+ return TQImageIO::outputFormats();
+}
+
+
+/*!
+ Loads an image from the file \a fileName. Returns TRUE if the
+ image was successfully loaded; otherwise returns FALSE.
+
+ If \a format is specified, the loader attempts to read the image
+ using the specified format. If \a format is not specified (which
+ is the default), the loader reads a few bytes from the header to
+ guess the file format.
+
+ The TQImageIO documentation lists the supported image formats and
+ explains how to add extra formats.
+
+ \sa loadFromData() save() imageFormat() TQPixmap::load() TQImageIO
+*/
+
+bool TQImage::load( const TQString &fileName, const char* format )
+{
+ TQImageIO io( fileName, format );
+ bool result = io.read();
+ if ( result )
+ operator=( io.image() );
+ return result;
+}
+
+/*!
+ Loads an image from the first \a len bytes of binary data in \a
+ buf. Returns TRUE if the image was successfully loaded; otherwise
+ returns FALSE.
+
+ If \a format is specified, the loader attempts to read the image
+ using the specified format. If \a format is not specified (which
+ is the default), the loader reads a few bytes from the header to
+ guess the file format.
+
+ The TQImageIO documentation lists the supported image formats and
+ explains how to add extra formats.
+
+ \sa load() save() imageFormat() TQPixmap::loadFromData() TQImageIO
+*/
+
+bool TQImage::loadFromData( const uchar *buf, uint len, const char *format )
+{
+ TQByteArray a;
+ a.setRawData( (char *)buf, len );
+ TQBuffer b( a );
+ b.open( IO_ReadOnly );
+ TQImageIO io( &b, format );
+ bool result = io.read();
+ b.close();
+ a.resetRawData( (char *)buf, len );
+ if ( result )
+ operator=( io.image() );
+ return result;
+}
+
+/*!
+ \overload
+
+ Loads an image from the TQByteArray \a buf.
+*/
+bool TQImage::loadFromData( TQByteArray buf, const char *format )
+{
+ return loadFromData( (const uchar *)(buf.data()), buf.size(), format );
+}
+
+/*!
+ Saves the image to the file \a fileName, using the image file
+ format \a format and a quality factor of \a quality. \a quality
+ must be in the range 0..100 or -1. Specify 0 to obtain small
+ compressed files, 100 for large uncompressed files, and -1 (the
+ default) to use the default settings.
+
+ Returns TRUE if the image was successfully saved; otherwise
+ returns FALSE.
+
+ \sa load() loadFromData() imageFormat() TQPixmap::save() TQImageIO
+*/
+
+bool TQImage::save( const TQString &fileName, const char* format, int quality ) const
+{
+ if ( isNull() )
+ return FALSE; // nothing to save
+ TQImageIO io( fileName, format );
+ return doImageIO( &io, quality );
+}
+
+/*!
+ \overload
+
+ This function writes a TQImage to the TQIODevice, \a tqdevice. This
+ can be used, for example, to save an image directly into a
+ TQByteArray:
+ \code
+ TQImage image;
+ TQByteArray ba;
+ TQBuffer buffer( ba );
+ buffer.open( IO_WriteOnly );
+ image.save( &buffer, "PNG" ); // writes image into ba in PNG format
+ \endcode
+*/
+
+bool TQImage::save( TQIODevice* tqdevice, const char* format, int quality ) const
+{
+ if ( isNull() )
+ return FALSE; // nothing to save
+ TQImageIO io( tqdevice, format );
+ return doImageIO( &io, quality );
+}
+
+/* \internal
+*/
+
+bool TQImage::doImageIO( TQImageIO* io, int quality ) const
+{
+ if ( !io )
+ return FALSE;
+ io->setImage( *this );
+#if defined(TQT_CHECK_RANGE)
+ if ( quality > 100 || quality < -1 )
+ qWarning( "TQPixmap::save: quality out of range [-1,100]" );
+#endif
+ if ( quality >= 0 )
+ io->setQuality( TQMIN(quality,100) );
+ return io->write();
+}
+#endif //TQT_NO_IMAGEIO
+
+/*****************************************************************************
+ TQImage stream functions
+ *****************************************************************************/
+#if !defined(TQT_NO_DATASTREAM) && !defined(TQT_NO_IMAGEIO)
+/*!
+ \relates TQImage
+
+ Writes the image \a image to the stream \a s as a PNG image, or as a
+ BMP image if the stream's version is 1.
+
+ Note that writing the stream to a file will not produce a valid image file.
+
+ \sa TQImage::save()
+ \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQImage &image )
+{
+ if ( s.version() >= 5 ) {
+ if ( image.isNull() ) {
+ s << (TQ_INT32) 0; // null image marker
+ return s;
+ } else {
+ s << (TQ_INT32) 1;
+ // continue ...
+ }
+ }
+ TQImageIO io;
+ io.setIODevice( s.tqdevice() );
+ if ( s.version() == 1 )
+ io.setFormat( "BMP" );
+ else
+ io.setFormat( "PNG" );
+
+ io.setImage( image );
+ io.write();
+ return s;
+}
+
+/*!
+ \relates TQImage
+
+ Reads an image from the stream \a s and stores it in \a image.
+
+ \sa TQImage::load()
+ \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQImage &image )
+{
+ if ( s.version() >= 5 ) {
+ TQ_INT32 nullMarker;
+ s >> nullMarker;
+ if ( !nullMarker ) {
+ image = TQImage(); // null image
+ return s;
+ }
+ }
+ TQImageIO io( s.tqdevice(), 0 );
+ if ( io.read() )
+ image = io.image();
+ return s;
+}
+#endif
+
+/*****************************************************************************
+ Standard image io handlers (defined below)
+ *****************************************************************************/
+
+// standard image io handlers (defined below)
+#ifndef TQT_NO_IMAGEIO_BMP
+static void read_bmp_image( TQImageIO * );
+static void write_bmp_image( TQImageIO * );
+#endif
+#ifndef TQT_NO_IMAGEIO_PPM
+static void read_pbm_image( TQImageIO * );
+static void write_pbm_image( TQImageIO * );
+#endif
+#ifndef TQT_NO_IMAGEIO_XBM
+static void read_xbm_image( TQImageIO * );
+static void write_xbm_image( TQImageIO * );
+#endif
+#ifndef TQT_NO_IMAGEIO_XPM
+static void read_xpm_image( TQImageIO * );
+static void write_xpm_image( TQImageIO * );
+#endif
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+static void read_async_image( TQImageIO * ); // Not in table of handlers
+#endif
+
+/*****************************************************************************
+ Misc. utility functions
+ *****************************************************************************/
+#if !defined(TQT_NO_IMAGEIO_XPM) || !defined(TQT_NO_IMAGEIO_XBM)
+static TQString fbname( const TQString &fileName ) // get file basename (sort of)
+{
+ TQString s = fileName;
+ if ( !s.isEmpty() ) {
+ int i;
+ if ( (i = s.tqfindRev('/')) >= 0 )
+ s = s.mid( i );
+ if ( (i = s.tqfindRev('\\')) >= 0 )
+ s = s.mid( i );
+ TQRegExp r( TQString::tqfromLatin1("[a-zA-Z][a-zA-Z0-9_]*") );
+ int p = r.search( s );
+ if ( p == -1 )
+ s.truncate( 0 );
+ else
+ s = s.mid( p, r.matchedLength() );
+ }
+ if ( s.isEmpty() )
+ s = TQString::tqfromLatin1( "dummy" );
+ return s;
+}
+#endif
+
+#ifndef TQT_NO_IMAGEIO_BMP
+static void swapPixel01( TQImage *image ) // 1-bpp: swap 0 and 1 pixels
+{
+ int i;
+ if ( image->depth() == 1 && image->numColors() == 2 ) {
+ register uint *p = (uint *)image->bits();
+ int nbytes = image->numBytes();
+ for ( i=0; i<nbytes/4; i++ ) {
+ *p = ~*p;
+ p++;
+ }
+ uchar *p2 = (uchar *)p;
+ for ( i=0; i<(nbytes&3); i++ ) {
+ *p2 = ~*p2;
+ p2++;
+ }
+ TQRgb t = image->color(0); // swap color 0 and 1
+ image->setColor( 0, image->color(1) );
+ image->setColor( 1, t );
+ }
+}
+#endif
+
+
+/*****************************************************************************
+ TQImageIO member functions
+ *****************************************************************************/
+
+/*!
+ \class TQImageIO tqimage.h
+
+ \brief The TQImageIO class tqcontains parameters for loading and
+ saving images.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup io
+
+ TQImageIO tqcontains a TQIODevice object that is used for image data
+ I/O. The programmer can install new image file formats in addition
+ to those that TQt provides.
+
+ TQt currently supports the following image file formats: PNG, BMP,
+ XBM, XPM and PNM. It may also support JPEG, MNG and GIF, if
+ specially configured during compilation. The different PNM formats
+ are: PBM (P1 or P4), PGM (P2 or P5), and PPM (P3 or P6).
+
+ You don't normally need to use this class; TQPixmap::load(),
+ TQPixmap::save(), and TQImage contain sufficient functionality.
+
+ For image files that contain sequences of images, only the first
+ is read. See TQMovie for loading multiple images.
+
+ PBM, PGM, and PPM format \e output is always in the more condensed
+ raw format. PPM and PGM files with more than 256 levels of
+ intensity are scaled down when reading.
+
+ \warning If you are in a country which recognizes software patents
+ and in which Unisys holds a patent on LZW compression and/or
+ decompression and you want to use GIF, Unisys may require you to
+ license the technology. Such countries include Canada, Japan, the
+ USA, France, Germany, Italy and the UK.
+
+ GIF support may be removed completely in a future version of TQt.
+ We recommend using the PNG format.
+
+ \sa TQImage TQPixmap TQFile TQMovie
+*/
+
+#ifndef TQT_NO_IMAGEIO
+struct TQImageIOData
+{
+ const char *parameters;
+ int quality;
+ float gamma;
+};
+
+/*!
+ Constructs a TQImageIO object with all parameters set to zero.
+*/
+
+TQImageIO::TQImageIO()
+{
+ init();
+}
+
+/*!
+ Constructs a TQImageIO object with the I/O tqdevice \a ioDevice and a
+ \a format tag.
+*/
+
+TQImageIO::TQImageIO( TQIODevice *ioDevice, const char *format )
+ : frmt(format)
+{
+ init();
+ iodev = ioDevice;
+}
+
+/*!
+ Constructs a TQImageIO object with the file name \a fileName and a
+ \a format tag.
+*/
+
+TQImageIO::TQImageIO( const TQString &fileName, const char* format )
+ : frmt(format), fname(fileName)
+{
+ init();
+}
+
+/*!
+ Contains initialization common to all TQImageIO constructors.
+*/
+
+void TQImageIO::init()
+{
+ d = new TQImageIOData();
+ d->parameters = 0;
+ d->quality = -1; // default quality of the current format
+ d->gamma=0.0f;
+ iostat = 0;
+ iodev = 0;
+}
+
+/*!
+ Destroys the object and all related data.
+*/
+
+TQImageIO::~TQImageIO()
+{
+ if ( d->parameters )
+ delete [] (char*)d->parameters;
+ delete d;
+}
+
+
+/*****************************************************************************
+ TQImageIO image handler functions
+ *****************************************************************************/
+
+class TQImageHandler
+{
+public:
+ TQImageHandler( const char *f, const char *h, const TQCString& fl,
+ image_io_handler r, image_io_handler w );
+ TQCString format; // image format
+ TQRegExp header; // image header pattern
+ enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode;
+ image_io_handler read_image; // image read function
+ image_io_handler write_image; // image write function
+ bool obsolete; // support not "published"
+};
+
+TQImageHandler::TQImageHandler( const char *f, const char *h, const TQCString& fl,
+ image_io_handler r, image_io_handler w )
+ : format(f), header(TQString::tqfromLatin1(h))
+{
+ text_mode = Untranslated;
+ if ( fl.tqcontains('t') )
+ text_mode = TranslateIn;
+ else if ( fl.tqcontains('T') )
+ text_mode = TranslateInOut;
+ obsolete = fl.tqcontains('O');
+ read_image = r;
+ write_image = w;
+}
+
+typedef TQPtrList<TQImageHandler> TQIHList;// list of image handlers
+static TQIHList *imageHandlers = 0;
+#ifndef TQT_NO_COMPONENT
+static TQPluginManager<TQImageFormatInterface> *plugin_manager = 0;
+#else
+static void *plugin_manager = 0;
+#endif
+
+void qt_init_image_plugins()
+{
+#ifndef TQT_NO_COMPONENT
+ if ( plugin_manager )
+ return;
+
+ plugin_manager = new TQPluginManager<TQImageFormatInterface>( IID_TQImageFormat, TQApplication::libraryPaths(), "/imageformats" );
+
+ TQStringList features = plugin_manager->featureList();
+ TQStringList::Iterator it = features.begin();
+ while ( it != features.end() ) {
+ TQString str = *it;
+ ++it;
+ TQInterfacePtr<TQImageFormatInterface> iface;
+ plugin_manager->queryInterface( str, &iface );
+ if ( iface )
+ iface->installIOHandler( str );
+ }
+#endif
+}
+
+static void cleanup()
+{
+ // make sure that image handlers are delete before plugin manager
+ delete imageHandlers;
+ imageHandlers = 0;
+#ifndef TQT_NO_COMPONENT
+ delete plugin_manager;
+ plugin_manager = 0;
+#endif
+}
+
+void qt_init_image_handlers() // initialize image handlers
+{
+ if ( !imageHandlers ) {
+ imageHandlers = new TQIHList;
+ TQ_CHECK_PTR( imageHandlers );
+ imageHandlers->setAutoDelete( TRUE );
+ qAddPostRoutine( cleanup );
+#ifndef TQT_NO_IMAGEIO_BMP
+ TQImageIO::defineIOHandler( "BMP", "^BM", 0,
+ read_bmp_image, write_bmp_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_PPM
+ TQImageIO::defineIOHandler( "PBM", "^P1", "t",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PBMRAW", "^P4", "O",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PGM", "^P2", "t",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PGMRAW", "^P5", "O",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PPM", "^P3", "t",
+ read_pbm_image, write_pbm_image );
+ TQImageIO::defineIOHandler( "PPMRAW", "^P6", "O",
+ read_pbm_image, write_pbm_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_XBM
+ TQImageIO::defineIOHandler( "XBM", "^((/\\*(?!.XPM.\\*/))|#define)", "T",
+ read_xbm_image, write_xbm_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_XPM
+ TQImageIO::defineIOHandler( "XPM", "/\\*.XPM.\\*/", "T",
+ read_xpm_image, write_xpm_image );
+#endif
+#ifndef TQT_NO_IMAGEIO_MNG
+ qInitMngIO();
+#endif
+#ifndef TQT_NO_IMAGEIO_PNG
+ qInitPngIO();
+#endif
+#ifndef TQT_NO_IMAGEIO_JPEG
+ qInitJpegIO();
+#endif
+ }
+}
+
+static TQImageHandler *get_image_handler( const char *format )
+{ // get pointer to handler
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+ register TQImageHandler *p = imageHandlers->first();
+ while ( p ) { // traverse list
+ if ( p->format == format )
+ return p;
+ p = imageHandlers->next();
+ }
+ return 0; // no such handler
+}
+
+
+/*!
+ Defines an image I/O handler for the image format called \a
+ format, which is recognized using the \link tqregexp.html#details
+ regular expression\endlink \a header, read using \a readImage and
+ written using \a writeImage.
+
+ \a flags is a string of single-character flags for this format.
+ The only flag defined currently is T (upper case), so the only
+ legal value for \a flags are "T" and the empty string. The "T"
+ flag means that the image file is a text file, and TQt should treat
+ all newline conventions as equivalent. (XPM files and some PPM
+ files are text files for example.)
+
+ \a format is used to select a handler to write a TQImage; \a header
+ is used to select a handler to read an image file.
+
+ If \a readImage is a null pointer, the TQImageIO will not be able
+ to read images in \a format. If \a writeImage is a null pointer,
+ the TQImageIO will not be able to write images in \a format. If
+ both are null, the TQImageIO object is valid but useless.
+
+ Example:
+ \code
+ void readGIF( TQImageIO *image )
+ {
+ // read the image using the image->ioDevice()
+ }
+
+ void writeGIF( TQImageIO *image )
+ {
+ // write the image using the image->ioDevice()
+ }
+
+ // add the GIF image handler
+
+ TQImageIO::defineIOHandler( "GIF",
+ "^GIF[0-9][0-9][a-z]",
+ 0,
+ readGIF,
+ writeGIF );
+ \endcode
+
+ Before the regex test, all the 0 bytes in the file header are
+ converted to 1 bytes. This is done because when TQt was
+ ASCII-based, TQRegExp could not handle 0 bytes in strings.
+
+ The regexp is only applied on the first 14 bytes of the file.
+
+ Note that TQt assumes that there is only one handler per format; if
+ two handlers support the same format, TQt will choose one
+ arbitrarily. It is not possible to have one handler support
+ reading, and another support writing.
+*/
+
+void TQImageIO::defineIOHandler( const char *format,
+ const char *header,
+ const char *flags,
+ image_io_handler readImage,
+ image_io_handler writeImage )
+{
+ qt_init_image_handlers();
+ TQImageHandler *p;
+ p = new TQImageHandler( format, header, flags,
+ readImage, writeImage );
+ TQ_CHECK_PTR( p );
+ imageHandlers->insert( 0, p );
+}
+
+
+/*****************************************************************************
+ TQImageIO normal member functions
+ *****************************************************************************/
+
+/*!
+ \fn const TQImage &TQImageIO::image() const
+
+ Returns the image currently set.
+
+ \sa setImage()
+*/
+
+/*!
+ \fn int TQImageIO::status() const
+
+ Returns the image's IO status. A non-zero value indicates an
+ error, whereas 0 means that the IO operation was successful.
+
+ \sa setqStatus()
+*/
+
+/*!
+ \fn const char *TQImageIO::format() const
+
+ Returns the image format string or 0 if no format has been
+ explicitly set.
+*/
+
+/*!
+ \fn TQIODevice *TQImageIO::ioDevice() const
+
+ Returns the IO tqdevice currently set.
+
+ \sa setIODevice()
+*/
+
+/*!
+ \fn TQString TQImageIO::fileName() const
+
+ Returns the file name currently set.
+
+ \sa setFileName()
+*/
+
+/*!
+ \fn TQString TQImageIO::description() const
+
+ Returns the image description string.
+
+ \sa setDescription()
+*/
+
+
+/*!
+ Sets the image to \a image.
+
+ \sa image()
+*/
+
+void TQImageIO::setImage( const TQImage &image )
+{
+ im = image;
+}
+
+/*!
+ Sets the image IO status to \a status. A non-zero value indicates
+ an error, whereas 0 means that the IO operation was successful.
+
+ \sa status()
+*/
+
+void TQImageIO::setqStatus( int status )
+{
+ iostat = status;
+}
+
+/*!
+ Sets the image format to \a format for the image to be read or
+ written.
+
+ It is necessary to specify a format before writing an image, but
+ it is not necessary to specify a format before reading an image.
+
+ If no format has been set, TQt guesses the image format before
+ reading it. If a format is set the image will only be read if it
+ has that format.
+
+ \sa read() write() format()
+*/
+
+void TQImageIO::setFormat( const char *format )
+{
+ frmt = format;
+}
+
+/*!
+ Sets the IO tqdevice to be used for reading or writing an image.
+
+ Setting the IO tqdevice allows images to be read/written to any
+ block-oriented TQIODevice.
+
+ If \a ioDevice is not null, this IO tqdevice will override file name
+ settings.
+
+ \sa setFileName()
+*/
+
+void TQImageIO::setIODevice( TQIODevice *ioDevice )
+{
+ iodev = ioDevice;
+}
+
+/*!
+ Sets the name of the file to read or write an image from to \a
+ fileName.
+
+ \sa setIODevice()
+*/
+
+void TQImageIO::setFileName( const TQString &fileName )
+{
+ fname = fileName;
+}
+
+/*!
+ Returns the quality of the written image, related to the
+ compression ratio.
+
+ \sa setQuality() TQImage::save()
+*/
+
+int TQImageIO::quality() const
+{
+ return d->quality;
+}
+
+/*!
+ Sets the quality of the written image to \a q, related to the
+ compression ratio.
+
+ \a q must be in the range -1..100. Specify 0 to obtain small
+ compressed files, 100 for large uncompressed files. (-1 signifies
+ the default compression.)
+
+ \sa quality() TQImage::save()
+*/
+
+void TQImageIO::setQuality( int q )
+{
+ d->quality = q;
+}
+
+/*!
+ Returns the image's parameters string.
+
+ \sa setParameters()
+*/
+
+const char *TQImageIO::parameters() const
+{
+ return d->parameters;
+}
+
+/*!
+ Sets the image's parameter string to \a parameters. This is for
+ image handlers that require special parameters.
+
+ Although the current image formats supported by TQt ignore the
+ parameters string, it may be used in future extensions or by
+ contributions (for example, JPEG).
+
+ \sa parameters()
+*/
+
+void TQImageIO::setParameters( const char *parameters )
+{
+ if ( d && d->parameters )
+ delete [] (char*)d->parameters;
+ d->parameters = qstrdup( parameters );
+}
+
+/*!
+ Sets the gamma value at which the image will be viewed to \a
+ gamma. If the image format stores a gamma value for which the
+ image is intended to be used, then this setting will be used to
+ modify the image. Setting to 0.0 will disable gamma correction
+ (i.e. any specification in the file will be ignored).
+
+ The default value is 0.0.
+
+ \sa gamma()
+*/
+void TQImageIO::setGamma( float gamma )
+{
+ d->gamma=gamma;
+}
+
+/*!
+ Returns the gamma value at which the image will be viewed.
+
+ \sa setGamma()
+*/
+float TQImageIO::gamma() const
+{
+ return d->gamma;
+}
+
+/*!
+ Sets the image description string for image handlers that support
+ image descriptions to \a description.
+
+ Currently, no image format supported by TQt uses the description
+ string.
+*/
+
+void TQImageIO::setDescription( const TQString &description )
+{
+ descr = description;
+}
+
+
+/*!
+ Returns a string that specifies the image format of the file \a
+ fileName, or null if the file cannot be read or if the format is
+ not recognized.
+*/
+
+const char* TQImageIO::imageFormat( const TQString &fileName )
+{
+ TQFile file( fileName );
+ if ( !file.open(IO_ReadOnly) )
+ return 0;
+ const char* format = imageFormat( &file );
+ file.close();
+ return format;
+}
+
+/*!
+ \overload
+
+ Returns a string that specifies the image format of the image read
+ from IO tqdevice \a d, or 0 if the tqdevice cannot be read or if the
+ format is not recognized.
+
+ Make sure that \a d is at the right position in the tqdevice (for
+ example, at the beginning of the file).
+
+ \sa TQIODevice::at()
+*/
+
+const char *TQImageIO::imageFormat( TQIODevice *d )
+{
+ // if you change this change the documentation for defineIOHandler()
+ const int buflen = 14;
+
+ char buf[buflen];
+ char buf2[buflen];
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+ int pos = d->at(); // save position
+ int rdlen = d->readBlock( buf, buflen ); // read a few bytes
+
+ if ( rdlen != buflen )
+ return 0;
+
+ memcpy( buf2, buf, buflen );
+
+ const char* format = 0;
+ for ( int n = 0; n < rdlen; n++ )
+ if ( buf[n] == '\0' )
+ buf[n] = '\001';
+ if ( d->status() == IO_Ok && rdlen > 0 ) {
+ buf[rdlen - 1] = '\0';
+ TQString bufStr = TQString::tqfromLatin1(buf);
+ TQImageHandler *p = imageHandlers->first();
+ int bestMatch = -1;
+ while ( p ) {
+ if ( p->read_image && p->header.search(bufStr) != -1 ) {
+ // try match with header if a read function is available
+ if (p->header.matchedLength() > bestMatch) {
+ // keep looking for best match
+ format = p->format;
+ bestMatch = p->header.matchedLength();
+ }
+ }
+ p = imageHandlers->next();
+ }
+ }
+ d->at( pos ); // restore position
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ if ( !format )
+ format = TQImageDecoder::formatName( (uchar*)buf2, rdlen );
+#endif
+
+ return format;
+}
+
+/*!
+ Returns a sorted list of image formats that are supported for
+ image input.
+*/
+TQStrList TQImageIO::inputFormats()
+{
+ TQStrList result;
+
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ // Include asynchronous loaders first.
+ result = TQImageDecoder::inputFormats();
+#endif
+
+ TQImageHandler *p = imageHandlers->first();
+ while ( p ) {
+ if ( p->read_image
+ && !p->obsolete
+ && !result.tqcontains(p->format) )
+ {
+ result.inSort(p->format);
+ }
+ p = imageHandlers->next();
+ }
+
+ return result;
+}
+
+/*!
+ Returns a sorted list of image formats that are supported for
+ image output.
+*/
+TQStrList TQImageIO::outputFormats()
+{
+ TQStrList result;
+
+ qt_init_image_handlers();
+ qt_init_image_plugins();
+
+ // Include asynchronous writers (!) first.
+ // (None)
+
+ TQImageHandler *p = imageHandlers->first();
+ while ( p ) {
+ if ( p->write_image
+ && !p->obsolete
+ && !result.tqcontains(p->format) )
+ {
+ result.inSort(p->format);
+ }
+ p = imageHandlers->next();
+ }
+
+ return result;
+}
+
+
+
+/*!
+ Reads an image into memory and returns TRUE if the image was
+ successfully read; otherwise returns FALSE.
+
+ Before reading an image you must set an IO tqdevice or a file name.
+ If both an IO tqdevice and a file name have been set, the IO tqdevice
+ will be used.
+
+ Setting the image file format string is optional.
+
+ Note that this function does \e not set the \link format()
+ format\endlink used to read the image. If you need that
+ information, use the imageFormat() static functions.
+
+ Example:
+
+ \code
+ TQImageIO iio;
+ TQPixmap pixmap;
+ iio.setFileName( "vegeburger.bmp" );
+ if ( image.read() ) // ok
+ pixmap = iio.image(); // convert to pixmap
+ \endcode
+
+ \sa setIODevice() setFileName() setFormat() write() TQPixmap::load()
+*/
+
+bool TQImageIO::read()
+{
+ TQFile file;
+ const char *image_format;
+ TQImageHandler *h;
+
+ if ( iodev ) { // read from io tqdevice
+ // ok, already open
+ } else if ( !fname.isEmpty() ) { // read from file
+ file.setName( fname );
+ if ( !file.open(IO_ReadOnly) )
+ return FALSE; // cannot open file
+ iodev = &file;
+ } else { // no file name or io tqdevice
+ return FALSE;
+ }
+ if (frmt.isEmpty()) {
+ // Try to guess format
+ image_format = imageFormat( iodev ); // get image format
+ if ( !image_format ) {
+ if ( file.isOpen() ) { // unknown format
+ file.close();
+ iodev = 0;
+ }
+ return FALSE;
+ }
+ } else {
+ image_format = frmt;
+ }
+
+ h = get_image_handler( image_format );
+ if ( file.isOpen() ) {
+#if !defined(TQ_OS_UNIX)
+ if ( h && h->text_mode ) { // reopen in translated mode
+ file.close();
+ file.open( IO_ReadOnly | IO_Translate );
+ }
+ else
+#endif
+ file.at( 0 ); // position to start
+ }
+ iostat = 1; // assume error
+
+ if ( h && h->read_image ) {
+ (*h->read_image)( this );
+ }
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ else {
+ // Format name, but no handler - must be an asychronous reader
+ read_async_image( this );
+ }
+#endif
+
+ if ( file.isOpen() ) { // image was read using file
+ file.close();
+ iodev = 0;
+ }
+ return iostat == 0; // image successfully read?
+}
+
+
+/*!
+ Writes an image to an IO tqdevice and returns TRUE if the image was
+ successfully written; otherwise returns FALSE.
+
+ Before writing an image you must set an IO tqdevice or a file name.
+ If both an IO tqdevice and a file name have been set, the IO tqdevice
+ will be used.
+
+ The image will be written using the specified image format.
+
+ Example:
+ \code
+ TQImageIO iio;
+ TQImage im;
+ im = pixmap; // convert to image
+ iio.setImage( im );
+ iio.setFileName( "vegeburger.bmp" );
+ iio.setFormat( "BMP" );
+ if ( iio.write() )
+ // returned TRUE if written successfully
+ \endcode
+
+ \sa setIODevice() setFileName() setFormat() read() TQPixmap::save()
+*/
+
+bool TQImageIO::write()
+{
+ if ( frmt.isEmpty() )
+ return FALSE;
+ TQImageHandler *h = get_image_handler( frmt );
+ if ( !h && !plugin_manager) {
+ qt_init_image_plugins();
+ h = get_image_handler( frmt );
+ }
+ if ( !h || !h->write_image ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImageIO::write: No such image format handler: %s",
+ format() );
+#endif
+ return FALSE;
+ }
+ TQFile file;
+ if ( !iodev && !fname.isEmpty() ) {
+ file.setName( fname );
+ bool translate = h->text_mode==TQImageHandler::TranslateInOut;
+ int fmode = translate ? IO_WriteOnly|IO_Translate : IO_WriteOnly;
+ if ( !file.open(fmode) ) // couldn't create file
+ return FALSE;
+ iodev = &file;
+ }
+ iostat = 1;
+ (*h->write_image)( this );
+ if ( file.isOpen() ) { // image was written using file
+ file.close();
+ iodev = 0;
+ }
+ return iostat == 0; // image successfully written?
+}
+#endif //TQT_NO_IMAGEIO
+
+#ifndef TQT_NO_IMAGEIO_BMP
+
+/*****************************************************************************
+ BMP (DIB) image read/write functions
+ *****************************************************************************/
+
+const int BMP_FILEHDR_SIZE = 14; // size of BMP_FILEHDR data
+
+struct BMP_FILEHDR { // BMP file header
+ char bfType[2]; // "BM"
+ TQ_INT32 bfSize; // size of file
+ TQ_INT16 bfReserved1;
+ TQ_INT16 bfReserved2;
+ TQ_INT32 bfOffBits; // pointer to the pixmap bits
+};
+
+TQDataStream &operator>>( TQDataStream &s, BMP_FILEHDR &bf )
+{ // read file header
+ s.readRawBytes( bf.bfType, 2 );
+ s >> bf.bfSize >> bf.bfReserved1 >> bf.bfReserved2 >> bf.bfOffBits;
+ return s;
+}
+
+TQDataStream &operator<<( TQDataStream &s, const BMP_FILEHDR &bf )
+{ // write file header
+ s.writeRawBytes( bf.bfType, 2 );
+ s << bf.bfSize << bf.bfReserved1 << bf.bfReserved2 << bf.bfOffBits;
+ return s;
+}
+
+
+const int BMP_OLD = 12; // old Windows/OS2 BMP size
+const int BMP_WIN = 40; // new Windows BMP size
+const int BMP_OS2 = 64; // new OS/2 BMP size
+
+const int BMP_RGB = 0; // no compression
+const int BMP_RLE8 = 1; // run-length encoded, 8 bits
+const int BMP_RLE4 = 2; // run-length encoded, 4 bits
+const int BMP_BITFIELDS = 3; // RGB values encoded in data as bit-fields
+
+struct BMP_INFOHDR { // BMP information header
+ TQ_INT32 biSize; // size of this struct
+ TQ_INT32 biWidth; // pixmap width
+ TQ_INT32 biHeight; // pixmap height
+ TQ_INT16 biPlanes; // should be 1
+ TQ_INT16 biBitCount; // number of bits per pixel
+ TQ_INT32 biCompression; // compression method
+ TQ_INT32 biSizeImage; // size of image
+ TQ_INT32 biXPelsPerMeter; // horizontal resolution
+ TQ_INT32 biYPelsPerMeter; // vertical resolution
+ TQ_INT32 biClrUsed; // number of colors used
+ TQ_INT32 biClrImportant; // number of important colors
+};
+
+
+TQDataStream &operator>>( TQDataStream &s, BMP_INFOHDR &bi )
+{
+ s >> bi.biSize;
+ if ( bi.biSize == BMP_WIN || bi.biSize == BMP_OS2 ) {
+ s >> bi.biWidth >> bi.biHeight >> bi.biPlanes >> bi.biBitCount;
+ s >> bi.biCompression >> bi.biSizeImage;
+ s >> bi.biXPelsPerMeter >> bi.biYPelsPerMeter;
+ s >> bi.biClrUsed >> bi.biClrImportant;
+ }
+ else { // probably old Windows format
+ TQ_INT16 w, h;
+ s >> w >> h >> bi.biPlanes >> bi.biBitCount;
+ bi.biWidth = w;
+ bi.biHeight = h;
+ bi.biCompression = BMP_RGB; // no compression
+ bi.biSizeImage = 0;
+ bi.biXPelsPerMeter = bi.biYPelsPerMeter = 0;
+ bi.biClrUsed = bi.biClrImportant = 0;
+ }
+ return s;
+}
+
+TQDataStream &operator<<( TQDataStream &s, const BMP_INFOHDR &bi )
+{
+ s << bi.biSize;
+ s << bi.biWidth << bi.biHeight;
+ s << bi.biPlanes;
+ s << bi.biBitCount;
+ s << bi.biCompression;
+ s << bi.biSizeImage;
+ s << bi.biXPelsPerMeter << bi.biYPelsPerMeter;
+ s << bi.biClrUsed << bi.biClrImportant;
+ return s;
+}
+
+static
+int calc_shift(int tqmask)
+{
+ int result = 0;
+ while (!(tqmask & 1)) {
+ result++;
+ tqmask >>= 1;
+ }
+ return result;
+}
+
+static
+bool read_dib( TQDataStream& s, int offset, int startpos, TQImage& image )
+{
+ BMP_INFOHDR bi;
+ TQIODevice* d = s.tqdevice();
+
+ s >> bi; // read BMP info header
+ if ( d->atEnd() ) // end of stream/file
+ return FALSE;
+#if 0
+ qDebug( "offset...........%d", offset );
+ qDebug( "startpos.........%d", startpos );
+ qDebug( "biSize...........%d", bi.biSize );
+ qDebug( "biWidth..........%d", bi.biWidth );
+ qDebug( "biHeight.........%d", bi.biHeight );
+ qDebug( "biPlanes.........%d", bi.biPlanes );
+ qDebug( "biBitCount.......%d", bi.biBitCount );
+ qDebug( "biCompression....%d", bi.biCompression );
+ qDebug( "biSizeImage......%d", bi.biSizeImage );
+ qDebug( "biXPelsPerMeter..%d", bi.biXPelsPerMeter );
+ qDebug( "biYPelsPerMeter..%d", bi.biYPelsPerMeter );
+ qDebug( "biClrUsed........%d", bi.biClrUsed );
+ qDebug( "biClrImportant...%d", bi.biClrImportant );
+#endif
+ int w = bi.biWidth, h = bi.biHeight, nbits = bi.biBitCount;
+ int t = bi.biSize, comp = bi.biCompression;
+ int red_mask, green_mask, blue_mask;
+ int red_shift = 0;
+ int green_shift = 0;
+ int blue_shift = 0;
+ int red_scale = 0;
+ int green_scale = 0;
+ int blue_scale = 0;
+
+ if ( !(nbits == 1 || nbits == 4 || nbits == 8 || nbits == 16 || nbits == 24 || nbits == 32) ||
+ bi.biPlanes != 1 || comp > BMP_BITFIELDS )
+ return FALSE; // weird BMP image
+ if ( !(comp == BMP_RGB || (nbits == 4 && comp == BMP_RLE4) ||
+ (nbits == 8 && comp == BMP_RLE8) || ((nbits == 16 || nbits == 32) && comp == BMP_BITFIELDS)) )
+ return FALSE; // weird compression type
+
+ int ncols;
+ int depth;
+ switch ( nbits ) {
+ case 32:
+ case 24:
+ case 16:
+ depth = 32;
+ break;
+ case 8:
+ case 4:
+ depth = 8;
+ break;
+ default:
+ depth = 1;
+ }
+ if ( depth == 32 ) // there's no colormap
+ ncols = 0;
+ else // # colors used
+ ncols = bi.biClrUsed ? bi.biClrUsed : 1 << nbits;
+
+ image.create( w, h, depth, ncols, nbits == 1 ?
+ TQImage::BigEndian : TQImage::IgnoreEndian );
+ if ( image.isNull() ) // could not create image
+ return FALSE;
+
+ image.setDotsPerMeterX( bi.biXPelsPerMeter );
+ image.setDotsPerMeterY( bi.biYPelsPerMeter );
+
+ d->at( startpos + BMP_FILEHDR_SIZE + bi.biSize ); // goto start of colormap
+
+ if ( ncols > 0 ) { // read color table
+ uchar rgb[4];
+ int rgb_len = t == BMP_OLD ? 3 : 4;
+ for ( int i=0; i<ncols; i++ ) {
+ if ( d->readBlock( (char *)rgb, rgb_len ) != rgb_len )
+ return FALSE;
+ image.setColor( i, tqRgb(rgb[2],rgb[1],rgb[0]) );
+ if ( d->atEnd() ) // truncated file
+ return FALSE;
+ }
+ } else if (comp == BMP_BITFIELDS && (nbits == 16 || nbits == 32)) {
+ if ( (TQ_ULONG)d->readBlock( (char *)&red_mask, sizeof(red_mask) ) != sizeof(red_mask) )
+ return FALSE;
+ if ( (TQ_ULONG)d->readBlock( (char *)&green_mask, sizeof(green_mask) ) != sizeof(green_mask) )
+ return FALSE;
+ if ( (TQ_ULONG)d->readBlock( (char *)&blue_mask, sizeof(blue_mask) ) != sizeof(blue_mask) )
+ return FALSE;
+ red_shift = calc_shift(red_mask);
+ red_scale = 256 / ((red_mask >> red_shift) + 1);
+ green_shift = calc_shift(green_mask);
+ green_scale = 256 / ((green_mask >> green_shift) + 1);
+ blue_shift = calc_shift(blue_mask);
+ blue_scale = 256 / ((blue_mask >> blue_shift) + 1);
+ } else if (comp == BMP_RGB && (nbits == 24 || nbits == 32)) {
+ blue_mask = 0x000000ff;
+ green_mask = 0x0000ff00;
+ red_mask = 0x00ff0000;
+ blue_shift = 0;
+ green_shift = 8;
+ red_shift = 16;
+ blue_scale = green_scale = red_scale = 1;
+ } else if (comp == BMP_RGB && nbits == 16) // don't support RGB values for 15/16 bpp
+ return FALSE;
+
+ // offset can be bogus, be careful
+ if (offset>=0 && startpos + offset > (TQ_LONG)d->at() )
+ d->at( startpos + offset ); // start of image data
+
+ int bpl = image.bytesPerLine();
+#ifdef TQ_WS_TQWS
+ //
+ // Guess the number of bytes-per-line if we don't know how much
+ // image data is in the file (bogus image ?).
+ //
+ int bmpbpl = bi.biSizeImage > 0 ?
+ bi.biSizeImage / bi.biHeight :
+ (d->size() - offset) / bi.biHeight;
+ int pad = bmpbpl-bpl;
+#endif
+ uchar **line = image.jumpTable();
+
+ if ( nbits == 1 ) { // 1 bit BMP image
+ while ( --h >= 0 ) {
+ if ( d->readBlock((char*)line[h],bpl) != bpl )
+ break;
+#ifdef TQ_WS_TQWS
+ if ( pad > 0 )
+ d->at(d->at()+pad);
+#endif
+ }
+ if ( ncols == 2 && tqGray(image.color(0)) < tqGray(image.color(1)) )
+ swapPixel01( &image ); // pixel 0 is white!
+ }
+
+ else if ( nbits == 4 ) { // 4 bit BMP image
+ int buflen = ((w+7)/8)*4;
+ uchar *buf = new uchar[buflen];
+ TQ_CHECK_PTR( buf );
+ if ( comp == BMP_RLE4 ) { // run length compression
+ int x=0, y=0, b, c, i;
+ register uchar *p = line[h-1];
+ uchar *endp = line[h-1]+w;
+ while ( y < h ) {
+ if ( (b=d->getch()) == EOF )
+ break;
+ if ( b == 0 ) { // escape code
+ switch ( (b=d->getch()) ) {
+ case 0: // end of line
+ x = 0;
+ y++;
+ p = line[h-y-1];
+ break;
+ case 1: // end of image
+ case EOF: // end of file
+ y = h; // exit loop
+ break;
+ case 2: // delta (jump)
+ x += d->getch();
+ y += d->getch();
+
+ // Protection
+ if ( (uint)x >= (uint)w )
+ x = w-1;
+ if ( (uint)y >= (uint)h )
+ y = h-1;
+
+ p = line[h-y-1] + x;
+ break;
+ default: // absolute mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ i = (c = b)/2;
+ while ( i-- ) {
+ b = d->getch();
+ *p++ = b >> 4;
+ *p++ = b & 0x0f;
+ }
+ if ( c & 1 )
+ *p++ = d->getch() >> 4;
+ if ( (((c & 3) + 1) & 2) == 2 )
+ d->getch(); // align on word boundary
+ x += c;
+ }
+ } else { // encoded mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ i = (c = b)/2;
+ b = d->getch(); // 2 pixels to be repeated
+ while ( i-- ) {
+ *p++ = b >> 4;
+ *p++ = b & 0x0f;
+ }
+ if ( c & 1 )
+ *p++ = b >> 4;
+ x += c;
+ }
+ }
+ } else if ( comp == BMP_RGB ) { // no compression
+ while ( --h >= 0 ) {
+ if ( d->readBlock((char*)buf,buflen) != buflen )
+ break;
+ register uchar *p = line[h];
+ uchar *b = buf;
+ for ( int i=0; i<w/2; i++ ) { // convert nibbles to bytes
+ *p++ = *b >> 4;
+ *p++ = *b++ & 0x0f;
+ }
+ if ( w & 1 ) // the last nibble
+ *p = *b >> 4;
+ }
+ }
+ delete [] buf;
+ }
+
+ else if ( nbits == 8 ) { // 8 bit BMP image
+ if ( comp == BMP_RLE8 ) { // run length compression
+ int x=0, y=0, b;
+ register uchar *p = line[h-1];
+ const uchar *endp = line[h-1]+w;
+ while ( y < h ) {
+ if ( (b=d->getch()) == EOF )
+ break;
+ if ( b == 0 ) { // escape code
+ switch ( (b=d->getch()) ) {
+ case 0: // end of line
+ x = 0;
+ y++;
+ p = line[h-y-1];
+ break;
+ case 1: // end of image
+ case EOF: // end of file
+ y = h; // exit loop
+ break;
+ case 2: // delta (jump)
+ x += d->getch();
+ y += d->getch();
+
+ // Protection
+ if ( (uint)x >= (uint)w )
+ x = w-1;
+ if ( (uint)y >= (uint)h )
+ y = h-1;
+
+ p = line[h-y-1] + x;
+ break;
+ default: // absolute mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ if ( d->readBlock( (char *)p, b ) != b )
+ return FALSE;
+ if ( (b & 1) == 1 )
+ d->getch(); // align on word boundary
+ x += b;
+ p += b;
+ }
+ } else { // encoded mode
+ // Protection
+ if ( p + b > endp )
+ b = endp-p;
+
+ memset( p, d->getch(), b ); // repeat pixel
+ x += b;
+ p += b;
+ }
+ }
+ } else if ( comp == BMP_RGB ) { // uncompressed
+ while ( --h >= 0 ) {
+ if ( d->readBlock((char *)line[h],bpl) != bpl )
+ break;
+#ifdef TQ_WS_TQWS
+ if ( pad > 0 )
+ d->at(d->at()+pad);
+#endif
+ }
+ }
+ }
+
+ else if ( nbits == 16 || nbits == 24 || nbits == 32 ) { // 16,24,32 bit BMP image
+ register TQRgb *p;
+ TQRgb *end;
+ uchar *buf24 = new uchar[bpl];
+ int bpl24 = ((w*nbits+31)/32)*4;
+ uchar *b;
+ int c;
+
+ while ( --h >= 0 ) {
+ p = (TQRgb *)line[h];
+ end = p + w;
+ if ( d->readBlock( (char *)buf24,bpl24) != bpl24 )
+ break;
+ b = buf24;
+ while ( p < end ) {
+ c = *(uchar*)b | (*(uchar*)(b+1)<<8);
+ if (nbits != 16)
+ c |= *(uchar*)(b+2)<<16;
+ *p++ = tqRgb(((c & red_mask) >> red_shift) * red_scale,
+ ((c & green_mask) >> green_shift) * green_scale,
+ ((c & blue_mask) >> blue_shift) * blue_scale);
+ b += nbits/8;
+ }
+ }
+ delete[] buf24;
+ }
+
+ return TRUE;
+}
+
+bool qt_read_dib( TQDataStream& s, TQImage& image )
+{
+ return read_dib(s,-1,-BMP_FILEHDR_SIZE,image);
+}
+
+
+static void read_bmp_image( TQImageIO *iio )
+{
+ TQIODevice *d = iio->ioDevice();
+ TQDataStream s( d );
+ BMP_FILEHDR bf;
+ int startpos = d->at();
+
+ s.setByteOrder( TQDataStream::LittleEndian );// Intel byte order
+ s >> bf; // read BMP file header
+
+ if ( tqstrncmp(bf.bfType,"BM",2) != 0 ) // not a BMP image
+ return;
+
+ TQImage image;
+ if (read_dib( s, bf.bfOffBits, startpos, image )) {
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+ }
+}
+
+bool qt_write_dib( TQDataStream& s, TQImage image )
+{
+ int nbits;
+ int bpl_bmp;
+ int bpl = image.bytesPerLine();
+
+ TQIODevice* d = s.tqdevice();
+
+ if ( image.depth() == 8 && image.numColors() <= 16 ) {
+ bpl_bmp = (((bpl+1)/2+3)/4)*4;
+ nbits = 4;
+ } else if ( image.depth() == 32 ) {
+ bpl_bmp = ((image.width()*24+31)/32)*4;
+ nbits = 24;
+#ifdef TQ_WS_TQWS
+ } else if ( image.depth() == 1 || image.depth() == 8 ) {
+ // TQt/E doesn't word align.
+ bpl_bmp = ((image.width()*image.depth()+31)/32)*4;
+ nbits = image.depth();
+#endif
+ } else {
+ bpl_bmp = bpl;
+ nbits = image.depth();
+ }
+
+ BMP_INFOHDR bi;
+ bi.biSize = BMP_WIN; // build info header
+ bi.biWidth = image.width();
+ bi.biHeight = image.height();
+ bi.biPlanes = 1;
+ bi.biBitCount = nbits;
+ bi.biCompression = BMP_RGB;
+ bi.biSizeImage = bpl_bmp*image.height();
+ bi.biXPelsPerMeter = image.dotsPerMeterX() ? image.dotsPerMeterX()
+ : 2834; // 72 dpi default
+ bi.biYPelsPerMeter = image.dotsPerMeterY() ? image.dotsPerMeterY() : 2834;
+ bi.biClrUsed = image.numColors();
+ bi.biClrImportant = image.numColors();
+ s << bi; // write info header
+
+ if ( image.depth() != 32 ) { // write color table
+ uchar *color_table = new uchar[4*image.numColors()];
+ uchar *rgb = color_table;
+ TQRgb *c = image.colorTable();
+ for ( int i=0; i<image.numColors(); i++ ) {
+ *rgb++ = tqBlue ( c[i] );
+ *rgb++ = tqGreen( c[i] );
+ *rgb++ = tqRed ( c[i] );
+ *rgb++ = 0;
+ }
+ d->writeBlock( (char *)color_table, 4*image.numColors() );
+ delete [] color_table;
+ }
+
+ if ( image.depth() == 1 && image.bitOrder() != TQImage::BigEndian )
+ image = image.convertBitOrder( TQImage::BigEndian );
+
+ int y;
+
+ if ( nbits == 1 || nbits == 8 ) { // direct output
+#ifdef TQ_WS_TQWS
+ // TQt/E doesn't word align.
+ int pad = bpl_bmp - bpl;
+ char padding[4];
+#endif
+ for ( y=image.height()-1; y>=0; y-- ) {
+ d->writeBlock( (char*)image.scanLine(y), bpl );
+#ifdef TQ_WS_TQWS
+ d->writeBlock( padding, pad );
+#endif
+ }
+ return TRUE;
+ }
+
+ uchar *buf = new uchar[bpl_bmp];
+ uchar *b, *end;
+ register uchar *p;
+
+ memset( buf, 0, bpl_bmp );
+ for ( y=image.height()-1; y>=0; y-- ) { // write the image bits
+ if ( nbits == 4 ) { // convert 8 -> 4 bits
+ p = image.scanLine(y);
+ b = buf;
+ end = b + image.width()/2;
+ while ( b < end ) {
+ *b++ = (*p << 4) | (*(p+1) & 0x0f);
+ p += 2;
+ }
+ if ( image.width() & 1 )
+ *b = *p << 4;
+ } else { // 32 bits
+ TQRgb *p = (TQRgb *)image.scanLine( y );
+ TQRgb *end = p + image.width();
+ b = buf;
+ while ( p < end ) {
+ *b++ = tqBlue(*p);
+ *b++ = tqGreen(*p);
+ *b++ = tqRed(*p);
+ p++;
+ }
+ }
+ if ( bpl_bmp != d->writeBlock( (char*)buf, bpl_bmp ) ) {
+ delete[] buf;
+ return FALSE;
+ }
+ }
+ delete[] buf;
+ return TRUE;
+}
+
+
+static void write_bmp_image( TQImageIO *iio )
+{
+ TQIODevice *d = iio->ioDevice();
+ TQImage image = iio->image();
+ TQDataStream s( d );
+ BMP_FILEHDR bf;
+ int bpl_bmp;
+ int bpl = image.bytesPerLine();
+
+ // Code partially repeated in qt_write_dib
+ if ( image.depth() == 8 && image.numColors() <= 16 ) {
+ bpl_bmp = (((bpl+1)/2+3)/4)*4;
+ } else if ( image.depth() == 32 ) {
+ bpl_bmp = ((image.width()*24+31)/32)*4;
+ } else {
+ bpl_bmp = bpl;
+ }
+
+ iio->setqStatus( 0 );
+ s.setByteOrder( TQDataStream::LittleEndian );// Intel byte order
+ strncpy( bf.bfType, "BM", 2 ); // build file header
+ bf.bfReserved1 = bf.bfReserved2 = 0; // reserved, should be zero
+ bf.bfOffBits = BMP_FILEHDR_SIZE + BMP_WIN + image.numColors()*4;
+ bf.bfSize = bf.bfOffBits + bpl_bmp*image.height();
+ s << bf; // write file header
+
+ if ( !qt_write_dib( s, image ) )
+ iio->setqStatus( 1 );
+
+}
+
+#endif // TQT_NO_IMAGEIO_BMP
+
+#ifndef TQT_NO_IMAGEIO_PPM
+
+/*****************************************************************************
+ PBM/PGM/PPM (ASCII and RAW) image read/write functions
+ *****************************************************************************/
+
+static int read_pbm_int( TQIODevice *d )
+{
+ int c;
+ int val = -1;
+ bool digit;
+ const int buflen = 100;
+ char buf[buflen];
+ for ( ;; ) {
+ if ( (c=d->getch()) == EOF ) // end of file
+ break;
+ digit = isdigit( (uchar) c );
+ if ( val != -1 ) {
+ if ( digit ) {
+ val = 10*val + c - '0';
+ continue;
+ } else {
+ if ( c == '#' ) // comment
+ d->readLine( buf, buflen );
+ break;
+ }
+ }
+ if ( digit ) // first digit
+ val = c - '0';
+ else if ( isspace((uchar) c) )
+ continue;
+ else if ( c == '#' )
+ d->readLine( buf, buflen );
+ else
+ break;
+ }
+ return val;
+}
+
+static void read_pbm_image( TQImageIO *iio ) // read PBM image data
+{
+ const int buflen = 300;
+ char buf[buflen];
+ TQIODevice *d = iio->ioDevice();
+ int w, h, nbits, mcc, y;
+ int pbm_bpl;
+ char type;
+ bool raw;
+ TQImage image;
+
+ if ( d->readBlock( buf, 3 ) != 3 ) // read P[1-6]<white-space>
+ return;
+ if ( !(buf[0] == 'P' && isdigit((uchar) buf[1]) && isspace((uchar) buf[2])) )
+ return;
+ switch ( (type=buf[1]) ) {
+ case '1': // ascii PBM
+ case '4': // raw PBM
+ nbits = 1;
+ break;
+ case '2': // ascii PGM
+ case '5': // raw PGM
+ nbits = 8;
+ break;
+ case '3': // ascii PPM
+ case '6': // raw PPM
+ nbits = 32;
+ break;
+ default:
+ return;
+ }
+ raw = type >= '4';
+ w = read_pbm_int( d ); // get image width
+ h = read_pbm_int( d ); // get image height
+ if ( nbits == 1 )
+ mcc = 1; // ignore max color component
+ else
+ mcc = read_pbm_int( d ); // get max color component
+ if ( w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0 )
+ return; // weird P.M image
+
+ int maxc = mcc;
+ if ( maxc > 255 )
+ maxc = 255;
+ image.create( w, h, nbits, 0,
+ nbits == 1 ? TQImage::BigEndian : TQImage::IgnoreEndian );
+ if ( image.isNull() )
+ return;
+
+ pbm_bpl = (nbits*w+7)/8; // bytes per scanline in PBM
+
+ if ( raw ) { // read raw data
+ if ( nbits == 32 ) { // type 6
+ pbm_bpl = 3*w;
+ uchar *buf24 = new uchar[pbm_bpl], *b;
+ TQRgb *p;
+ TQRgb *end;
+ for ( y=0; y<h; y++ ) {
+ if ( d->readBlock( (char *)buf24, pbm_bpl ) != pbm_bpl ) {
+ delete[] buf24;
+ return;
+ }
+ p = (TQRgb *)image.scanLine( y );
+ end = p + w;
+ b = buf24;
+ while ( p < end ) {
+ *p++ = tqRgb(b[0],b[1],b[2]);
+ b += 3;
+ }
+ }
+ delete[] buf24;
+ } else { // type 4,5
+ for ( y=0; y<h; y++ ) {
+ if ( d->readBlock( (char *)image.scanLine(y), pbm_bpl )
+ != pbm_bpl )
+ return;
+ }
+ }
+ } else { // read ascii data
+ register uchar *p;
+ int n;
+ for ( y=0; y<h; y++ ) {
+ p = image.scanLine( y );
+ n = pbm_bpl;
+ if ( nbits == 1 ) {
+ int b;
+ while ( n-- ) {
+ b = 0;
+ for ( int i=0; i<8; i++ )
+ b = (b << 1) | (read_pbm_int(d) & 1);
+ *p++ = b;
+ }
+ } else if ( nbits == 8 ) {
+ if ( mcc == maxc ) {
+ while ( n-- ) {
+ *p++ = read_pbm_int( d );
+ }
+ } else {
+ while ( n-- ) {
+ *p++ = read_pbm_int( d ) * maxc / mcc;
+ }
+ }
+ } else { // 32 bits
+ n /= 4;
+ int r, g, b;
+ if ( mcc == maxc ) {
+ while ( n-- ) {
+ r = read_pbm_int( d );
+ g = read_pbm_int( d );
+ b = read_pbm_int( d );
+ *((TQRgb*)p) = tqRgb( r, g, b );
+ p += 4;
+ }
+ } else {
+ while ( n-- ) {
+ r = read_pbm_int( d ) * maxc / mcc;
+ g = read_pbm_int( d ) * maxc / mcc;
+ b = read_pbm_int( d ) * maxc / mcc;
+ *((TQRgb*)p) = tqRgb( r, g, b );
+ p += 4;
+ }
+ }
+ }
+ }
+ }
+
+ if ( nbits == 1 ) { // bitmap
+ image.setNumColors( 2 );
+ image.setColor( 0, tqRgb(255,255,255) ); // white
+ image.setColor( 1, tqRgb(0,0,0) ); // black
+ } else if ( nbits == 8 ) { // graymap
+ image.setNumColors( maxc+1 );
+ for ( int i=0; i<=maxc; i++ )
+ image.setColor( i, tqRgb(i*255/maxc,i*255/maxc,i*255/maxc) );
+ }
+
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+}
+
+
+static void write_pbm_image( TQImageIO *iio )
+{
+ TQIODevice* out = iio->ioDevice();
+ TQCString str;
+
+ TQImage image = iio->image();
+ TQCString format = iio->format();
+ format = format.left(3); // ignore RAW part
+ bool gray = format == "PGM";
+
+ if ( format == "PBM" ) {
+ image = image.convertDepth(1);
+ } else if ( image.depth() == 1 ) {
+ image = image.convertDepth(8);
+ }
+
+ if ( image.depth() == 1 && image.numColors() == 2 ) {
+ if ( tqGray(image.color(0)) < tqGray(image.color(1)) ) {
+ // 0=dark/black, 1=light/white - invert
+ image.detach();
+ for ( int y=0; y<image.height(); y++ ) {
+ uchar *p = image.scanLine(y);
+ uchar *end = p + image.bytesPerLine();
+ while ( p < end )
+ *p++ ^= 0xff;
+ }
+ }
+ }
+
+ uint w = image.width();
+ uint h = image.height();
+
+ str.sprintf("P\n%d %d\n", w, h);
+
+ switch (image.depth()) {
+ case 1: {
+ str.insert(1, '4');
+ if ((uint)out->writeBlock(str, str.length()) != str.length()) {
+ iio->setqStatus(1);
+ return;
+ }
+ w = (w+7)/8;
+ for (uint y=0; y<h; y++) {
+ uchar* line = image.scanLine(y);
+ if ( w != (uint)out->writeBlock((char*)line, w) ) {
+ iio->setqStatus(1);
+ return;
+ }
+ }
+ }
+ break;
+
+ case 8: {
+ str.insert(1, gray ? '5' : '6');
+ str.append("255\n");
+ if ((uint)out->writeBlock(str, str.length()) != str.length()) {
+ iio->setqStatus(1);
+ return;
+ }
+ TQRgb *color = image.colorTable();
+ uint bpl = w*(gray ? 1 : 3);
+ uchar *buf = new uchar[bpl];
+ for (uint y=0; y<h; y++) {
+ uchar *b = image.scanLine(y);
+ uchar *p = buf;
+ uchar *end = buf+bpl;
+ if ( gray ) {
+ while ( p < end ) {
+ uchar g = (uchar)tqGray(color[*b++]);
+ *p++ = g;
+ }
+ } else {
+ while ( p < end ) {
+ TQRgb rgb = color[*b++];
+ *p++ = tqRed(rgb);
+ *p++ = tqGreen(rgb);
+ *p++ = tqBlue(rgb);
+ }
+ }
+ if ( bpl != (uint)out->writeBlock((char*)buf, bpl) ) {
+ iio->setqStatus(1);
+ return;
+ }
+ }
+ delete [] buf;
+ }
+ break;
+
+ case 32: {
+ str.insert(1, gray ? '5' : '6');
+ str.append("255\n");
+ if ((uint)out->writeBlock(str, str.length()) != str.length()) {
+ iio->setqStatus(1);
+ return;
+ }
+ uint bpl = w*(gray ? 1 : 3);
+ uchar *buf = new uchar[bpl];
+ for (uint y=0; y<h; y++) {
+ TQRgb *b = (TQRgb*)image.scanLine(y);
+ uchar *p = buf;
+ uchar *end = buf+bpl;
+ if ( gray ) {
+ while ( p < end ) {
+ uchar g = (uchar)tqGray(*b++);
+ *p++ = g;
+ }
+ } else {
+ while ( p < end ) {
+ TQRgb rgb = *b++;
+ *p++ = tqRed(rgb);
+ *p++ = tqGreen(rgb);
+ *p++ = tqBlue(rgb);
+ }
+ }
+ if ( bpl != (uint)out->writeBlock((char*)buf, bpl) ) {
+ iio->setqStatus(1);
+ return;
+ }
+ }
+ delete [] buf;
+ }
+ }
+
+ iio->setqStatus(0);
+}
+
+#endif // TQT_NO_IMAGEIO_PPM
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+
+class TQImageIOFrameGrabber : public TQImageConsumer {
+public:
+ TQImageIOFrameGrabber() : framecount(0) { }
+
+ TQImageDecoder *decoder;
+ int framecount;
+
+ void changed(const TQRect&) { }
+ void end() { }
+ void frameDone(const TQPoint&, const TQRect&) { framecount++; }
+ void frameDone() { framecount++; }
+ void setLooping(int) { }
+ void setFramePeriod(int) { }
+ void setSize(int, int) { }
+};
+
+static void read_async_image( TQImageIO *iio )
+{
+ const int buf_len = 2048;
+ uchar buffer[buf_len];
+ TQIODevice *d = iio->ioDevice();
+ TQImageIOFrameGrabber* consumer = new TQImageIOFrameGrabber();
+ TQImageDecoder *decoder = new TQImageDecoder(consumer);
+ consumer->decoder = decoder;
+ int startAt = d->at();
+ int totLen = 0;
+
+ for (;;) {
+ int length = d->readBlock((char*)buffer, buf_len);
+ if ( length <= 0 ) {
+ iio->setqStatus(length);
+ break;
+ }
+ uchar* b = buffer;
+ int r = -1;
+ while (length > 0 && consumer->framecount==0) {
+ r = decoder->decode(b, length);
+ if ( r <= 0 ) break;
+ b += r;
+ totLen += r;
+ length -= r;
+ }
+ if ( consumer->framecount ) {
+ // Stopped after first frame
+ if ( d->isDirectAccess() )
+ d->at( startAt + totLen );
+ else {
+ // ### We have (probably) read too much from the stream into
+ // the buffer, and there is no way to put it back!
+ }
+ iio->setImage(decoder->image());
+ iio->setqStatus(0);
+ break;
+ }
+ if ( r <= 0 ) {
+ iio->setqStatus(r);
+ break;
+ }
+ }
+
+ consumer->decoder = 0;
+ delete decoder;
+ delete consumer;
+}
+
+#endif // TQT_NO_ASYNC_IMAGE_IO
+
+#ifndef TQT_NO_IMAGEIO_XBM
+
+/*****************************************************************************
+ X bitmap image read/write functions
+ *****************************************************************************/
+
+static inline int hex2byte( register char *p )
+{
+ return ( (isdigit((uchar) *p) ? *p - '0' : toupper((uchar) *p) - 'A' + 10) << 4 ) |
+ ( isdigit((uchar) *(p+1)) ? *(p+1) - '0' : toupper((uchar) *(p+1)) - 'A' + 10 );
+}
+
+static void read_xbm_image( TQImageIO *iio )
+{
+ const int buflen = 300;
+ char buf[buflen];
+ TQRegExp r1, r2;
+ TQIODevice *d = iio->ioDevice();
+ int w=-1, h=-1;
+ TQImage image;
+
+ r1 = TQString::tqfromLatin1("^#define[ \t]+[a-zA-Z0-9._]+[ \t]+");
+ r2 = TQString::tqfromLatin1("[0-9]+");
+ d->readLine( buf, buflen ); // "#define .._width <num>"
+
+ while (!d->atEnd() && buf[0] != '#') //skip leading comment, if any
+ d->readLine( buf, buflen );
+
+ TQString sbuf;
+ sbuf = TQString::tqfromLatin1(buf);
+
+ if ( r1.search(sbuf) == 0 &&
+ r2.search(sbuf, r1.matchedLength()) == r1.matchedLength() )
+ w = atoi( &buf[r1.matchedLength()] );
+
+ d->readLine( buf, buflen ); // "#define .._height <num>"
+ sbuf = TQString::tqfromLatin1(buf);
+
+ if ( r1.search(sbuf) == 0 &&
+ r2.search(sbuf, r1.matchedLength()) == r1.matchedLength() )
+ h = atoi( &buf[r1.matchedLength()] );
+
+ if ( w <= 0 || w > 32767 || h <= 0 || h > 32767 )
+ return; // format error
+
+ for ( ;; ) { // scan for data
+ if ( d->readLine(buf, buflen) <= 0 ) // end of file
+ return;
+ if ( strstr(buf,"0x") != 0 ) // does line contain data?
+ break;
+ }
+
+ image.create( w, h, 1, 2, TQImage::LittleEndian );
+ if ( image.isNull() )
+ return;
+
+ image.setColor( 0, tqRgb(255,255,255) ); // white
+ image.setColor( 1, tqRgb(0,0,0) ); // black
+
+ int x = 0, y = 0;
+ uchar *b = image.scanLine(0);
+ char *p = strstr( buf, "0x" );
+ w = (w+7)/8; // byte width
+
+ while ( y < h ) { // for all encoded bytes...
+ if ( p ) { // p = "0x.."
+ *b++ = hex2byte(p+2);
+ p += 2;
+ if ( ++x == w && ++y < h ) {
+ b = image.scanLine(y);
+ x = 0;
+ }
+ p = strstr( p, "0x" );
+ } else { // read another line
+ if ( d->readLine(buf,buflen) <= 0 ) // EOF ==> truncated image
+ break;
+ p = strstr( buf, "0x" );
+ }
+ }
+
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+}
+
+
+static void write_xbm_image( TQImageIO *iio )
+{
+ TQIODevice *d = iio->ioDevice();
+ TQImage image = iio->image();
+ int w = image.width();
+ int h = image.height();
+ int i;
+ TQString s = fbname(iio->fileName()); // get file base name
+ char *buf = new char[s.length() + 100];
+
+ sprintf( buf, "#define %s_width %d\n", s.ascii(), w );
+ d->writeBlock( buf, tqstrlen(buf) );
+ sprintf( buf, "#define %s_height %d\n", s.ascii(), h );
+ d->writeBlock( buf, tqstrlen(buf) );
+ sprintf( buf, "static char %s_bits[] = {\n ", s.ascii() );
+ d->writeBlock( buf, tqstrlen(buf) );
+
+ iio->setqStatus( 0 );
+
+ if ( image.depth() != 1 )
+ image = image.convertDepth( 1 ); // dither
+ if ( image.bitOrder() != TQImage::LittleEndian )
+ image = image.convertBitOrder( TQImage::LittleEndian );
+
+ bool invert = tqGray(image.color(0)) < tqGray(image.color(1));
+ char hexrep[16];
+ for ( i=0; i<10; i++ )
+ hexrep[i] = '0' + i;
+ for ( i=10; i<16; i++ )
+ hexrep[i] = 'a' -10 + i;
+ if ( invert ) {
+ char t;
+ for ( i=0; i<8; i++ ) {
+ t = hexrep[15-i];
+ hexrep[15-i] = hexrep[i];
+ hexrep[i] = t;
+ }
+ }
+ int bcnt = 0;
+ register char *p = buf;
+ int bpl = (w+7)/8;
+ for (int y = 0; y < h; ++y) {
+ uchar *b = image.scanLine(y);
+ for (i = 0; i < bpl; ++i) {
+ *p++ = '0'; *p++ = 'x';
+ *p++ = hexrep[*b >> 4];
+ *p++ = hexrep[*b++ & 0xf];
+
+ if ( i < bpl - 1 || y < h - 1 ) {
+ *p++ = ',';
+ if ( ++bcnt > 14 ) {
+ *p++ = '\n';
+ *p++ = ' ';
+ *p = '\0';
+ if ( (int)tqstrlen(buf) != d->writeBlock( buf, tqstrlen(buf) ) ) {
+ iio->setqStatus( 1 );
+ delete [] buf;
+ return;
+ }
+ p = buf;
+ bcnt = 0;
+ }
+ }
+ }
+ }
+ strcpy( p, " };\n" );
+ if ( (int)tqstrlen(buf) != d->writeBlock( buf, tqstrlen(buf) ) )
+ iio->setqStatus( 1 );
+ delete [] buf;
+}
+
+#endif // TQT_NO_IMAGEIO_XBM
+
+
+#ifndef TQT_NO_IMAGEIO_XPM
+
+/*****************************************************************************
+ XPM image read/write functions
+ *****************************************************************************/
+
+
+// Skip until ", read until the next ", return the rest in *buf
+// Returns FALSE on error, TRUE on success
+
+static bool read_xpm_string( TQCString &buf, TQIODevice *d,
+ const char * const *source, int &index )
+{
+ if ( source ) {
+ buf = source[index++];
+ return TRUE;
+ }
+
+ if ( buf.size() < 69 ) //# just an approximation
+ buf.resize( 123 );
+
+ buf[0] = '\0';
+ int c;
+ int i;
+ while ( (c=d->getch()) != EOF && c != '"' ) { }
+ if ( c == EOF ) {
+ return FALSE;
+ }
+ i = 0;
+ while ( (c=d->getch()) != EOF && c != '"' ) {
+ if ( i == (int)buf.size() )
+ buf.resize( i*2+42 );
+ buf[i++] = c;
+ }
+ if ( c == EOF ) {
+ return FALSE;
+ }
+
+ if ( i == (int)buf.size() ) // always use a 0 terminator
+ buf.resize( i+1 );
+ buf[i] = '\0';
+ return TRUE;
+}
+
+
+
+static int nextColorSpec(const TQCString & buf)
+{
+ int i = buf.tqfind(" c ");
+ if (i < 0)
+ i = buf.tqfind(" g ");
+ if (i < 0)
+ i = buf.tqfind(" g4 ");
+ if (i < 0)
+ i = buf.tqfind(" m ");
+ if (i < 0)
+ i = buf.tqfind(" s ");
+ return i;
+}
+
+//
+// INTERNAL
+//
+// Reads an .xpm from either the TQImageIO or from the TQString *.
+// One of the two HAS to be 0, the other one is used.
+//
+
+static void read_xpm_image_or_array( TQImageIO * iio, const char * const * source,
+ TQImage & image)
+{
+ TQCString buf;
+ TQIODevice *d = 0;
+ buf.resize( 200 );
+
+ int i, cpp, ncols, w, h, index = 0;
+
+ if ( iio ) {
+ iio->setqStatus( 1 );
+ d = iio ? iio->ioDevice() : 0;
+ d->readLine( buf.data(), buf.size() ); // "/* XPM */"
+ TQRegExp r( TQString::tqfromLatin1("/\\*.XPM.\\*/") );
+ if ( buf.tqfind(r) == -1 )
+ return; // bad magic
+ } else if ( !source ) {
+ return;
+ }
+
+ if ( !read_xpm_string( buf, d, source, index ) )
+ return;
+
+ if ( sscanf( buf, "%d %d %d %d", &w, &h, &ncols, &cpp ) < 4 )
+ return; // < 4 numbers parsed
+
+ if ( cpp > 15 )
+ return;
+
+ if ( ncols > 256 ) {
+ image.create( w, h, 32 );
+ } else {
+ image.create( w, h, 8, ncols );
+ }
+
+ if (image.isNull())
+ return;
+
+ TQMap<TQString, int> colorMap;
+ int currentColor;
+
+ for( currentColor=0; currentColor < ncols; ++currentColor ) {
+ if ( !read_xpm_string( buf, d, source, index ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage: XPM color specification missing");
+#endif
+ return;
+ }
+ TQString index;
+ index = buf.left( cpp );
+ buf = buf.mid( cpp ).simplifyWhiteSpace().lower();
+ buf.prepend( " " );
+ i = nextColorSpec(buf);
+ if ( i < 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage: XPM color specification is missing: %s", buf.data());
+#endif
+ return; // no c/g/g4/m/s specification at all
+ }
+ buf = buf.mid( i+3 );
+ // Strip any other colorspec
+ int end = nextColorSpec(buf);
+ if (end != -1)
+ buf.truncate(end);
+ buf = buf.stripWhiteSpace();
+ if ( buf == "none" ) {
+ image.setAlphaBuffer( TRUE );
+ int transparentColor = currentColor;
+ if ( image.depth() == 8 ) {
+ image.setColor( transparentColor,
+ TQRGB_MASK & tqRgb(198,198,198) );
+ colorMap.insert( index, transparentColor );
+ } else {
+ TQRgb rgb = TQRGB_MASK & tqRgb(198,198,198);
+ colorMap.insert( index, rgb );
+ }
+ } else {
+ if ( ((buf.length()-1) % 3) && (buf[0] == '#') ) {
+ buf.truncate (((buf.length()-1) / 4 * 3) + 1); // remove alpha channel left by imagemagick
+ }
+ TQColor c( buf.data() );
+ if ( image.depth() == 8 ) {
+ image.setColor( currentColor, 0xff000000 | c.rgb() );
+ colorMap.insert( index, currentColor );
+ } else {
+ TQRgb rgb = 0xff000000 | c.rgb();
+ colorMap.insert( index, rgb );
+ }
+ }
+ }
+
+ // Read pixels
+ for( int y=0; y<h; y++ ) {
+ if ( !read_xpm_string( buf, d, source, index ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQImage: XPM pixels missing on image line %d", y);
+#endif
+ return;
+ }
+ if ( image.depth() == 8 ) {
+ uchar *p = image.scanLine(y);
+ uchar *d = (uchar *)buf.data();
+ uchar *end = d + buf.length();
+ int x;
+ if ( cpp == 1 ) {
+ char b[2];
+ b[1] = '\0';
+ for ( x=0; x<w && d<end; x++ ) {
+ b[0] = *d++;
+ *p++ = (uchar)colorMap[b];
+ }
+ } else {
+ char b[16];
+ b[cpp] = '\0';
+ for ( x=0; x<w && d<end; x++ ) {
+ strncpy( b, (char *)d, cpp );
+ *p++ = (uchar)colorMap[b];
+ d += cpp;
+ }
+ }
+ } else {
+ TQRgb *p = (TQRgb*)image.scanLine(y);
+ uchar *d = (uchar *)buf.data();
+ uchar *end = d + buf.length();
+ int x;
+ char b[16];
+ b[cpp] = '\0';
+ for ( x=0; x<w && d<end; x++ ) {
+ strncpy( b, (char *)d, cpp );
+ *p++ = (TQRgb)colorMap[b];
+ d += cpp;
+ }
+ }
+ }
+ if ( iio ) {
+ iio->setImage( image );
+ iio->setqStatus( 0 ); // image ok
+ }
+}
+
+
+static void read_xpm_image( TQImageIO * iio )
+{
+ TQImage i;
+ (void)read_xpm_image_or_array( iio, 0, i );
+ return;
+}
+
+
+static const char* xpm_color_name( int cpp, int index )
+{
+ static char returnable[5];
+ static const char code[] = ".#abcdefghijklmnopqrstuvwxyzABCD"
+ "EFGHIJKLMNOPTQRSTUVWXYZ0123456789";
+ // cpp is limited to 4 and index is limited to 64^cpp
+ if ( cpp > 1 ) {
+ if ( cpp > 2 ) {
+ if ( cpp > 3 ) {
+ returnable[3] = code[index % 64];
+ index /= 64;
+ } else
+ returnable[3] = '\0';
+ returnable[2] = code[index % 64];
+ index /= 64;
+ } else
+ returnable[2] = '\0';
+ // the following 4 lines are a joke!
+ if ( index == 0 )
+ index = 64*44+21;
+ else if ( index == 64*44+21 )
+ index = 0;
+ returnable[1] = code[index % 64];
+ index /= 64;
+ } else
+ returnable[1] = '\0';
+ returnable[0] = code[index];
+
+ return returnable;
+}
+
+
+// write XPM image data
+static void write_xpm_image( TQImageIO * iio )
+{
+ if ( iio )
+ iio->setqStatus( 1 );
+ else
+ return;
+
+ // ### 8-bit case could be made faster
+ TQImage image;
+ if ( iio->image().depth() != 32 )
+ image = iio->image().convertDepth( 32 );
+ else
+ image = iio->image();
+
+ TQMap<TQRgb, int> colorMap;
+
+ int w = image.width(), h = image.height(), ncolors = 0;
+ int x, y;
+
+ // build color table
+ for( y=0; y<h; y++ ) {
+ TQRgb * yp = (TQRgb *)image.scanLine( y );
+ for( x=0; x<w; x++ ) {
+ TQRgb color = *(yp + x);
+ if ( !colorMap.tqcontains(color) )
+ colorMap.insert( color, ncolors++ );
+ }
+ }
+
+ // number of 64-bit characters per pixel needed to encode all colors
+ int cpp = 1;
+ for ( int k = 64; ncolors > k; k *= 64 ) {
+ ++cpp;
+ // limit to 4 characters per pixel
+ // 64^4 colors is enough for a 4096x4096 image
+ if ( cpp > 4)
+ break;
+ }
+
+ TQString line;
+
+ // write header
+ TQTextStream s( iio->ioDevice() );
+ s << "/* XPM */" << endl
+ << "static char *" << fbname(iio->fileName()) << "[]={" << endl
+ << "\"" << w << " " << h << " " << ncolors << " " << cpp << "\"";
+
+ // write palette
+ TQMap<TQRgb, int>::Iterator c = colorMap.begin();
+ while ( c != colorMap.end() ) {
+ TQRgb color = c.key();
+ if ( image.hasAlphaBuffer() && color == (color & TQRGB_MASK) )
+ line.sprintf( "\"%s c None\"",
+ xpm_color_name(cpp, *c) );
+ else
+ line.sprintf( "\"%s c #%02x%02x%02x\"",
+ xpm_color_name(cpp, *c),
+ tqRed(color),
+ tqGreen(color),
+ tqBlue(color) );
+ ++c;
+ s << "," << endl << line;
+ }
+
+ // write pixels, limit to 4 characters per pixel
+ line.truncate( cpp*w );
+ for( y=0; y<h; y++ ) {
+ TQRgb * yp = (TQRgb *) image.scanLine( y );
+ int cc = 0;
+ for( x=0; x<w; x++ ) {
+ int color = (int)(*(yp + x));
+ TQCString chars = xpm_color_name( cpp, colorMap[color] );
+ line[cc++] = chars[0];
+ if ( cpp > 1 ) {
+ line[cc++] = chars[1];
+ if ( cpp > 2 ) {
+ line[cc++] = chars[2];
+ if ( cpp > 3 ) {
+ line[cc++] = chars[3];
+ }
+ }
+ }
+ }
+ s << "," << endl << "\"" << line << "\"";
+ }
+ s << "};" << endl;
+
+ iio->setqStatus( 0 );
+}
+
+#endif // TQT_NO_IMAGEIO_XPM
+
+/*!
+ Returns an image with depth \a d, using the \a palette_count
+ colors pointed to by \a palette. If \a d is 1 or 8, the returned
+ image will have its color table ordered the same as \a palette.
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a
+ conversion_flags to specify how you'd prefer this to happen.
+
+ Note: currently no closest-color search is made. If colors are
+ found that are not in the palette, the palette may not be used at
+ all. This result should not be considered valid because it may
+ change in future implementations.
+
+ Currently inefficient for non-32-bit images.
+
+ \sa TQt::ImageConversionFlags
+*/
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+TQImage TQImage::convertDepthWithPalette( int d, TQRgb* palette, int palette_count, int conversion_flags ) const
+{
+ if ( depth() == 1 ) {
+ return convertDepth( 8, conversion_flags )
+ .convertDepthWithPalette( d, palette, palette_count, conversion_flags );
+ } else if ( depth() == 8 ) {
+ // ### this could be easily made more efficient
+ return convertDepth( 32, conversion_flags )
+ .convertDepthWithPalette( d, palette, palette_count, conversion_flags );
+ } else {
+ TQImage result;
+ convert_32_to_8( this, &result,
+ (conversion_flags&~TQt::DitherMode_Mask) | TQt::AvoidDither,
+ palette, palette_count );
+ return result.convertDepth( d );
+ }
+}
+#endif
+static
+bool
+haveSamePalette(const TQImage& a, const TQImage& b)
+{
+ if (a.depth() != b.depth()) return FALSE;
+ if (a.numColors() != b.numColors()) return FALSE;
+ TQRgb* ca = a.colorTable();
+ TQRgb* cb = b.colorTable();
+ for (int i=a.numColors(); i--; ) {
+ if (*ca++ != *cb++) return FALSE;
+ }
+ return TRUE;
+}
+
+/*!
+ \relates TQImage
+
+ Copies a block of pixels from \a src to \a dst. The pixels
+ copied from source (src) are converted according to
+ \a conversion_flags if it is incompatible with the destination
+ (\a dst).
+
+ \a sx, \a sy is the top-left pixel in \a src, \a dx, \a dy
+ is the top-left position in \a dst and \a sw, \a sh is the
+ size of the copied block.
+
+ The copying is clipped if areas outside \a src or \a dst are
+ specified.
+
+ If \a sw is -1, it is adjusted to src->width(). Similarly, if \a
+ sh is -1, it is adjusted to src->height().
+
+ Currently inefficient for non 32-bit images.
+*/
+void bitBlt( TQImage* dst, int dx, int dy, const TQImage* src,
+ int sx, int sy, int sw, int sh, int conversion_flags )
+{
+ // Parameter correction
+ if ( sw < 0 ) sw = src->width();
+ if ( sh < 0 ) sh = src->height();
+ if ( sx < 0 ) { dx -= sx; sw += sx; sx = 0; }
+ if ( sy < 0 ) { dy -= sy; sh += sy; sy = 0; }
+ if ( dx < 0 ) { sx -= dx; sw += dx; dx = 0; }
+ if ( dy < 0 ) { sy -= dy; sh += dy; dy = 0; }
+ if ( sx + sw > src->width() ) sw = src->width() - sx;
+ if ( sy + sh > src->height() ) sh = src->height() - sy;
+ if ( dx + sw > dst->width() ) sw = dst->width() - dx;
+ if ( dy + sh > dst->height() ) sh = dst->height() - dy;
+ if ( sw <= 0 || sh <= 0 ) return; // Nothing left to copy
+ if ( (dst->data == src->data) && dx==sx && dy==sy ) return; // Same pixels
+
+ // "Easy" to copy if both same depth and one of:
+ // - 32 bit
+ // - 8 bit, identical palette
+ // - 1 bit, identical palette and byte-aligned area
+ //
+ if ( haveSamePalette(*dst,*src)
+ && ( dst->depth() != 1 ||
+ !( (dx&7) || (sx&7) ||
+ ((sw&7) && (sx+sw < src->width()) ||
+ (dx+sw < dst->width()) ) ) ) )
+ {
+ // easy to copy
+ } else if ( dst->depth() != 32 ) {
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+
+ TQImage dstconv = dst->convertDepth( 32 );
+ bitBlt( &dstconv, dx, dy, src, sx, sy, sw, sh,
+ (conversion_flags&~TQt::DitherMode_Mask) | TQt::AvoidDither );
+ *dst = dstconv.convertDepthWithPalette( dst->depth(),
+ dst->colorTable(), dst->numColors() );
+#endif
+ return;
+ }
+
+ // Now assume palette can be ignored
+
+ if ( dst->depth() != src->depth() ) {
+ if ( sw == src->width() && sh == src->height() || dst->depth()==32 ) {
+ TQImage srcconv = src->convertDepth( dst->depth(), conversion_flags );
+ bitBlt( dst, dx, dy, &srcconv, sx, sy, sw, sh, conversion_flags );
+ } else {
+ TQImage srcconv = src->copy( sx, sy, sw, sh ); // ie. bitBlt
+ bitBlt( dst, dx, dy, &srcconv, 0, 0, sw, sh, conversion_flags );
+ }
+ return;
+ }
+
+ // Now assume both are the same depth.
+
+ // Now assume both are 32-bit or 8-bit with compatible palettes.
+
+ // "Easy"
+
+ switch ( dst->depth() ) {
+ case 1:
+ {
+ uchar* d = dst->scanLine(dy) + dx/8;
+ uchar* s = src->scanLine(sy) + sx/8;
+ const int bw = (sw+7)/8;
+ if ( bw < 64 ) {
+ // Trust ourselves
+ const int dd = dst->bytesPerLine() - bw;
+ const int ds = src->bytesPerLine() - bw;
+ while ( sh-- ) {
+ for ( int t=bw; t--; )
+ *d++ = *s++;
+ d += dd;
+ s += ds;
+ }
+ } else {
+ // Trust libc
+ const int dd = dst->bytesPerLine();
+ const int ds = src->bytesPerLine();
+ while ( sh-- ) {
+ memcpy( d, s, bw );
+ d += dd;
+ s += ds;
+ }
+ }
+ }
+ break;
+ case 8:
+ {
+ uchar* d = dst->scanLine(dy) + dx;
+ uchar* s = src->scanLine(sy) + sx;
+ if ( sw < 64 ) {
+ // Trust ourselves
+ const int dd = dst->bytesPerLine() - sw;
+ const int ds = src->bytesPerLine() - sw;
+ while ( sh-- ) {
+ for ( int t=sw; t--; )
+ *d++ = *s++;
+ d += dd;
+ s += ds;
+ }
+ } else {
+ // Trust libc
+ const int dd = dst->bytesPerLine();
+ const int ds = src->bytesPerLine();
+ while ( sh-- ) {
+ memcpy( d, s, sw );
+ d += dd;
+ s += ds;
+ }
+ }
+ }
+ break;
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ case 32:
+ if ( src->hasAlphaBuffer() ) {
+ TQRgb* d = (TQRgb*)dst->scanLine(dy) + dx;
+ TQRgb* s = (TQRgb*)src->scanLine(sy) + sx;
+ const int dd = dst->width() - sw;
+ const int ds = src->width() - sw;
+ while ( sh-- ) {
+ for ( int t=sw; t--; ) {
+ unsigned char a = tqAlpha(*s);
+ if ( a == 255 )
+ *d++ = *s++;
+ else if ( a == 0 )
+ ++d,++s; // nothing
+ else {
+ unsigned char r = ((tqRed(*s)-tqRed(*d)) * a) / 256 + tqRed(*d);
+ unsigned char g = ((tqGreen(*s)-tqGreen(*d)) * a) / 256 + tqGreen(*d);
+ unsigned char b = ((tqBlue(*s)-tqBlue(*d)) * a) / 256 + tqBlue(*d);
+ a = TQMAX(tqAlpha(*d),a); // alternatives...
+ *d++ = tqRgba(r,g,b,a);
+ ++s;
+ }
+ }
+ d += dd;
+ s += ds;
+ }
+ } else {
+ TQRgb* d = (TQRgb*)dst->scanLine(dy) + dx;
+ TQRgb* s = (TQRgb*)src->scanLine(sy) + sx;
+ if ( sw < 64 ) {
+ // Trust ourselves
+ const int dd = dst->width() - sw;
+ const int ds = src->width() - sw;
+ while ( sh-- ) {
+ for ( int t=sw; t--; )
+ *d++ = *s++;
+ d += dd;
+ s += ds;
+ }
+ } else {
+ // Trust libc
+ const int dd = dst->width();
+ const int ds = src->width();
+ const int b = sw*sizeof(TQRgb);
+ while ( sh-- ) {
+ memcpy( d, s, b );
+ d += dd;
+ s += ds;
+ }
+ }
+ }
+ break;
+#endif // TQT_NO_IMAGE_TRUECOLOR
+ }
+}
+
+
+/*!
+ Returns TRUE if this image and image \a i have the same contents;
+ otherwise returns FALSE. The comparison can be slow, unless there
+ is some obvious difference, such as different widths, in which
+ case the function will return quickly.
+
+ \sa operator=()
+*/
+
+bool TQImage::operator==( const TQImage & i ) const
+{
+ // same object, or shared?
+ if ( i.data == data )
+ return TRUE;
+ // obviously different stuff?
+ if ( i.data->h != data->h ||
+ i.data->w != data->w )
+ return FALSE;
+ // not equal if one has alphabuffer and the other does not
+ if ( i.hasAlphaBuffer() != hasAlphaBuffer() )
+ return FALSE;
+ // that was the fast bit...
+ TQImage i1 = convertDepth( 32 );
+ TQImage i2 = i.convertDepth( 32 );
+ int l;
+ // if no alpha buffer used, there might still be junk in the
+ // alpha bits; thus, we can't do memcmp-style comparison of scanlines
+ if ( !hasAlphaBuffer() ) {
+ int m;
+ TQRgb *i1line;
+ TQRgb *i2line;
+ for( l=0; l < data->h; l++ ) {
+ i1line = (uint *)i1.scanLine( l );
+ i2line = (uint *)i2.scanLine( l );
+ // compare pixels of scanline individually
+ for ( m=0; m < data->w; m++ )
+ if ( (i1line[m] ^ i2line[m]) & 0x00FFFFFF )
+ return FALSE;
+ }
+ } else {
+ // yay, we can do fast binary comparison on entire scanlines
+ for( l=0; l < data->h; l++ )
+ if ( memcmp( i1.scanLine( l ), i2.scanLine( l ), 4*data->w ) )
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+/*!
+ Returns TRUE if this image and image \a i have different contents;
+ otherwise returns FALSE. The comparison can be slow, unless there
+ is some obvious difference, such as different widths, in which
+ case the function will return quickly.
+
+ \sa operator=()
+*/
+
+bool TQImage::operator!=( const TQImage & i ) const
+{
+ return !(*this == i);
+}
+
+
+
+
+/*!
+ \fn int TQImage::dotsPerMeterX() const
+
+ Returns the number of pixels that fit horizontally in a physical
+ meter. This and dotsPerMeterY() define the intended scale and
+ aspect ratio of the image.
+
+ \sa setDotsPerMeterX()
+*/
+
+/*!
+ \fn int TQImage::dotsPerMeterY() const
+
+ Returns the number of pixels that fit vertically in a physical
+ meter. This and dotsPerMeterX() define the intended scale and
+ aspect ratio of the image.
+
+ \sa setDotsPerMeterY()
+*/
+
+/*!
+ Sets the value returned by dotsPerMeterX() to \a x.
+*/
+void TQImage::setDotsPerMeterX(int x)
+{
+ data->dpmx = x;
+}
+
+/*!
+ Sets the value returned by dotsPerMeterY() to \a y.
+*/
+void TQImage::setDotsPerMeterY(int y)
+{
+ data->dpmy = y;
+}
+
+/*!
+ \fn TQPoint TQImage::offset() const
+
+ Returns the number of pixels by which the image is intended to be
+ offset by when positioning relative to other images.
+*/
+
+/*!
+ Sets the value returned by offset() to \a p.
+*/
+void TQImage::setOffset(const TQPoint& p)
+{
+ data->offset = p;
+}
+#ifndef TQT_NO_IMAGE_TEXT
+/*!
+ \internal
+
+ Returns the internal TQImageDataMisc object. This object will be
+ created if it doesn't already exist.
+*/
+TQImageDataMisc& TQImage::misc() const
+{
+ if ( !data->misc )
+ data->misc = new TQImageDataMisc;
+ return *data->misc;
+}
+
+/*!
+ Returns the string recorded for the keyword \a key in language \a
+ lang, or in a default language if \a lang is 0.
+*/
+TQString TQImage::text(const char* key, const char* lang) const
+{
+ TQImageTextKeyLang x(key,lang);
+ return misc().text_lang[x];
+}
+
+/*!
+ \overload
+
+ Returns the string recorded for the keyword and language \a kl.
+*/
+TQString TQImage::text(const TQImageTextKeyLang& kl) const
+{
+ return misc().text_lang[kl];
+}
+
+/*!
+ Returns the language identifiers for which some texts are
+ recorded.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myImage.textLanguages();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa textList() text() setText() textKeys()
+*/
+TQStringList TQImage::textLanguages() const
+{
+ if ( !data->misc )
+ return TQStringList();
+ return misc().languages();
+}
+
+/*!
+ Returns the keywords for which some texts are recorded.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myImage.textKeys();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa textList() text() setText() textLanguages()
+*/
+TQStringList TQImage::textKeys() const
+{
+ if ( !data->misc )
+ return TQStringList();
+ return misc().keys();
+}
+
+/*!
+ Returns a list of TQImageTextKeyLang objects that enumerate all the
+ texts key/language pairs set by setText() for this image.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQImageTextKeyLang> list = myImage.textList();
+ TQValueList<TQImageTextKeyLang>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQValueList<TQImageTextKeyLang> TQImage::textList() const
+{
+ if ( !data->misc )
+ return TQValueList<TQImageTextKeyLang>();
+ return misc().list();
+}
+
+/*!
+ Records string \a s for the keyword \a key. The \a key should be a
+ portable keyword recognizable by other software - some suggested
+ values can be found in \link
+ http://www.libpng.org/pub/png/spec/1.2/png-1.2-pdg.html#C.Anc-text
+ the PNG specification \endlink. \a s can be any text. \a lang
+ should specify the language code (see
+ \link http://www.rfc-editor.org/rfc/rfc1766.txt RFC 1766 \endlink) or 0.
+*/
+void TQImage::setText(const char* key, const char* lang, const TQString& s)
+{
+ TQImageTextKeyLang x(key,lang);
+ misc().text_lang.tqreplace(x,s);
+}
+
+#endif // TQT_NO_IMAGE_TEXT
+
+#ifdef TQ_WS_TQWS
+/*!
+ \internal
+*/
+TQGfx * TQImage::graphicsContext()
+{
+ TQGfx * ret=0;
+ if(depth()) {
+ int w = qt_screen->mapToDevice( TQSize(width(),height()) ).width();
+ int h = qt_screen->mapToDevice( TQSize(width(),height()) ).height();
+ ret=TQGfx::createGfx(depth(),bits(),w,h,bytesPerLine());
+ } else {
+ qDebug("Trying to create image for null depth");
+ return 0;
+ }
+ if(depth()<=8) {
+ TQRgb * tmp=colorTable();
+ int nc=numColors();
+ if(tmp==0) {
+ static TQRgb table[2] = { tqRgb(255,255,255), tqRgb(0,0,0) };
+ tmp=table;
+ nc=2;
+ }
+ ret->setClut(tmp,nc);
+ }
+ return ret;
+}
+
+#endif
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqimage.h b/tqtinterface/qt4/src/kernel/tqimage.h
new file mode 100644
index 0000000..19dc1a0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqimage.h
@@ -0,0 +1,695 @@
+/****************************************************************************
+**
+** Definition of TQImage and TQImageIO classes
+**
+** Created : 950207
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQIMAGE_H
+#define TQIMAGE_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpixmap.h"
+#include "tqstrlist.h"
+#include "tqstringlist.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qbitmap.h>
+#include <Qt/qstringlist.h>
+#include <Qt/qimagereader.h>
+#include <Qt/qimagewriter.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+#ifndef TQT_NO_IMAGE_TEXT
+class TQ_EXPORT TQImageTextKeyLang : public QImageTextKeyLang, virtual public TQt {
+public:
+ TQImageTextKeyLang(const char* k, const char* l) : QImageTextKeyLang(k, l) { }
+ TQImageTextKeyLang() : QImageTextKeyLang() { }
+
+ bool operator< (const TQImageTextKeyLang& other) const { return key < other.key || (key==other.key && lang < other.lang); }
+ bool operator== (const TQImageTextKeyLang& other) const { return key==other.key && lang==other.lang; }
+
+ // Interoperability
+ static const TQImageTextKeyLang& convertFromQImageTextKeyLang( QImageTextKeyLang& qbr );
+};
+
+// Interoperability
+inline static const TQImageTextKeyLang& convertFromQImageTextKeyLang( const QImageTextKeyLang& qbr ) {
+ return (*static_cast<const TQImageTextKeyLang*>(&qbr));
+}
+#endif //TQT_NO_IMAGE_TEXT
+
+class TQ_EXPORT TQImage : public QImage, virtual public TQt
+{
+public:
+ enum Endian { IgnoreEndian, BigEndian, LittleEndian };
+
+ QImage::Format formatFor(int depth, Endian bitOrder);
+
+ TQImage() : QImage() { jumptable=NULL; }
+ TQImage( int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian ) : QImage( width, height, formatFor(depth, bitOrder) ) { jumptable=NULL; setColorCount(numColors); }
+ TQImage( const QSize&ts, int depth, int numColors=0, Endian bitOrder=IgnoreEndian ) : QImage( ts, formatFor(depth, bitOrder) ) { jumptable=NULL; setColorCount(numColors); }
+#ifndef TQT_NO_IMAGEIO
+ TQImage( const QString &fileName, const char* format=0 ) : QImage( fileName, format ) { jumptable=NULL; }
+ TQImage( const char * const xpm[] ) : QImage( xpm ) { jumptable=NULL; }
+// TQImage( const QByteArray &data ) : QImage( data ) {}
+#endif
+ TQImage( uchar* data, int w, int h, int depth, QRgb* colortable, int numColors, Endian bitOrder ) : QImage( data, w, h, formatFor(depth, bitOrder) ) {
+ jumptable=NULL;
+ setColorCount(numColors);
+ if (colortable) {
+ setColorCount(numColors);
+ for (int i = 0; i < numColors; ++i) {
+ setColor(i, colortable[i]);
+ }
+ }
+ }
+// ~TQImage();
+
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+ TQImage createHeuristicMask( bool clipTight=TRUE ) const;
+#endif
+
+ Endian bitOrder() const {
+ Format f = format();
+ return f == Format_Mono ? BigEndian : (f == Format_MonoLSB ? LittleEndian : IgnoreEndian);
+ }
+#ifdef TQ_WS_TQWS
+ TQImage( uchar* data, int w, int h, int depth, int pbl, QRgb* colortable, int numColors, Endian bitOrder ) : QImage( data, w, h, depth, pbl, colortable, numColors, bitOrder ) { jumptable=NULL; }
+#endif
+ TQImage( const QImage &im ) : QImage( im ) { jumptable=NULL; }
+
+// static TQStrList inputFormats() { return TQT_TQSTRLIST_OBJECT(QImageReader::supportedImageFormats()); }
+// static TQStrList outputFormats() { return TQT_TQSTRLIST_OBJECT(QImageWriter::supportedImageFormats()); }
+
+ inline TQImage smoothScale(int w, int h, AspectRatioMode mode = IgnoreAspectRatio) const { return scaled(QSize(w, h), (Qt::AspectRatioMode)mode, Qt::SmoothTransformation); }
+ inline TQImage smoothScale(const QSize &s, AspectRatioMode mode = IgnoreAspectRatio) const { return scaled(s, (Qt::AspectRatioMode)mode, Qt::SmoothTransformation); }
+ inline TQImage swapRGB() const { return rgbSwapped(); }
+ inline TQImage mirror(bool horizontally = false, bool vertically = true) const { return mirrored(horizontally, vertically); }
+
+#ifndef TQT_NO_IMAGE_TRANSFORMATION
+ inline TQImage scale( int w, int h, ScaleMode mode=ScaleFree ) const { return scaled(QSize(w, h), (Qt::AspectRatioMode)mode, Qt::FastTransformation); }
+ inline TQImage scale( const TQSize& s, ScaleMode mode=ScaleFree ) const { return scaled(s, (Qt::AspectRatioMode)mode, Qt::FastTransformation); }
+ inline TQImage scaleWidth( int w ) const { return scaledToWidth(w, Qt::FastTransformation); }
+ inline TQImage scaleHeight( int h ) const { return scaledToHeight(h, Qt::FastTransformation); }
+ inline TQImage xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
+#endif
+
+ TQImage convertDepth(int, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
+ TQImage convertDepthWithPalette(int, QRgb* p, int pc, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
+ TQImage convertBitOrder(Endian) const;
+
+ inline void tqinvertPixels( bool invertAlpha = TRUE ) { if (invertAlpha) invertPixels(InvertRgba); else invertPixels(InvertRgb); }
+
+ bool hasAlphaBuffer() const;
+ void setAlphaBuffer(bool);
+
+ static inline Endian systemByteOrder() { return QSysInfo::ByteOrder == QSysInfo::BigEndian ? BigEndian : LittleEndian; }
+ static Endian systemBitOrder();
+
+ uchar **jumpTable();
+ const uchar * const *jumpTable() const;
+
+ bool create( int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian );
+ bool create( const TQSize&, int depth, int numColors=0, Endian bitOrder=IgnoreEndian );
+ inline void reset() { *this = QImage(); }
+
+ inline TQValueList<TQImageTextKeyLang> tqtextList() const {
+ QList<QImageTextKeyLang> qs = textList();
+ TQValueList<TQImageTextKeyLang> qn;
+ for (int i = 0; i < qs.size(); ++i) qn.append(convertFromQImageTextKeyLang(qs.at(i)));
+ return qn;
+ }
+
+ inline TQRgb *tqcolorTable() const {
+ return colorTable().data();
+ }
+
+#ifndef TQT_NO_IMAGEIO
+ static const char* imageFormat( const TQString &fileName );
+ static TQStrList inputFormats();
+ static TQStrList outputFormats();
+#ifndef TQT_NO_STRINGLIST
+ static TQStringList inputFormatList();
+ static TQStringList outputFormatList();
+#endif
+ bool load( const TQString &fileName, const char* format=0 );
+ bool loadFromData( const uchar *buf, uint len, const char *format=0 );
+ bool loadFromData( TQByteArray data, const char* format=0 );
+ bool save( const TQString &fileName, const char* format, int quality=-1 ) const;
+ bool save( QIODevice * tqdevice, const char* format, int quality=-1 ) const;
+#endif //TQT_NO_IMAGEIO
+
+private:
+ mutable uchar **jumptable;
+ void reinit();
+ void freeBits();
+#ifndef TQT_NO_IMAGEIO
+ bool doImageIO( TQImageIO* io, int quality ) const;
+#endif
+
+public:
+ // Interoperability
+ static const TQImage& convertFromQImage( QImage& qi );
+
+ using QImage::operator=;
+};
+
+// Interoperability
+inline static const TQImage& convertFromQImage( const QImage& qi ) {
+ return (*static_cast<const TQImage*>(&qi));
+}
+
+#if 0
+typedef void (*image_io_handler)( TQImageIO * ); // image IO handler
+
+class TQ_EXPORT TQImageIO : public QImageReader, public QImageWriter, virtual public TQt
+{
+public:
+ TQImageIO() : QImageReader(), QImageWriter() {}
+ TQImageIO( QIODevice *ioDevice, const char *format ) : QImageReader( ioDevice, format ), QImageWriter( ioDevice, format ) {}
+ TQImageIO( const QString &fileName, const char* format ) : QImageReader( fileName, format ), QImageWriter( fileName, format ) {}
+
+ static TQStrList inputFormats() { return TQT_TQSTRLIST_OBJECT(QImageReader::supportedImageFormats()); }
+ static TQStrList outputFormats() { return TQT_TQSTRLIST_OBJECT(QImageWriter::supportedImageFormats()); }
+
+ inline void setImage( const QImage &qi ) { internalImage = qi; }
+ inline bool write() { return QImageWriter::write( internalImage ); }
+ inline bool read() { if (QImageReader::read().isNull() == true) return false; else return true; }
+ inline int quality() const { return QImageWriter::quality(); }
+ inline const TQImage &image() { return TQT_TQIMAGE_OBJECT(QImageReader::read()); }
+
+ inline static void defineIOHandler( const char *format, const char *header, const char *flags, image_io_handler read_image, image_io_handler write_image ) {
+ // [FIXME] Is this now automatic in Qt4??
+ TQ_UNUSED(format);
+ TQ_UNUSED(header);
+ TQ_UNUSED(flags);
+ TQ_UNUSED(read_image);
+ TQ_UNUSED(write_image);
+ printf("[WARNING] static void defineIOHandler( const char *format, const char *header, const char *flags, image_io_handler read_image, image_io_handler write_image ) unimplemented\n\r");
+ }
+
+ void setqStatus( int );
+ inline TQIODevice *ioDevice() const { if (QImageReader::device() != 0) return static_cast<TQIODevice*>(QImageReader::device()); else return static_cast<TQIODevice*>(QImageWriter::device()); }
+ inline const char *format() const { if (QImageReader::format() != "") return QImageReader::format(); else return QImageWriter::format(); }
+ inline TQString fileName() const { if (QImageReader::fileName() != "") return QImageReader::fileName(); else return QImageWriter::fileName(); }
+ inline const char *parameters() const { printf("[WARNING] const char *parameters() const unimplemented\n\r"); return 0; }
+ inline void setFileName( const QString &qs ) { QImageReader::setFileName(qs); QImageWriter::setFileName(qs); }
+ inline void setQuality( int ql ) { QImageReader::setQuality(ql); QImageWriter::setQuality(ql); }
+ inline void setIODevice( TQIODevice *tqiod ) { QImageReader::setDevice(tqiod); QImageWriter::setDevice(tqiod); }
+ inline void setParameters( const char * ) { printf("[WARNING] void setParameters(const char *) unimplemented\n\r"); }
+ inline void setFormat( const char * format ) { QImageReader::setFormat(format); QImageWriter::setFormat(format); }
+
+private:
+ QImage internalImage;
+};
+#else
+class TQIODevice;
+typedef void (*image_io_handler)( TQImageIO * ); // image IO handler
+
+
+struct TQImageIOData;
+
+
+class TQ_EXPORT TQImageIO
+{
+public:
+ TQImageIO();
+ TQImageIO( QIODevice *ioDevice, const char *format );
+ TQImageIO( const TQString &fileName, const char* format );
+ ~TQImageIO();
+
+
+ const TQImage &image() const { return im; }
+ int status() const { return iostat; }
+ const char *format() const { return frmt; }
+ TQIODevice *ioDevice() const { return iodev; }
+ TQString fileName() const { return fname; }
+ int quality() const;
+ TQString description() const { return descr; }
+ const char *parameters() const;
+ float gamma() const;
+
+ void setImage( const QImage & );
+ void setqStatus( int );
+ void setFormat( const char * );
+ void setIODevice( TQIODevice * );
+ void setFileName( const TQString & );
+ void setQuality( int );
+ void setDescription( const TQString & );
+ void setParameters( const char * );
+ void setGamma( float );
+
+ bool read();
+ bool write();
+
+ static const char* imageFormat( const TQString &fileName );
+ static const char *imageFormat( TQIODevice * );
+ static TQStrList inputFormats();
+ static TQStrList outputFormats();
+
+ static void defineIOHandler( const char *format,
+ const char *header,
+ const char *flags,
+ image_io_handler read_image,
+ image_io_handler write_image );
+
+private:
+ void init();
+
+ TQImage im; // image
+ int iostat; // IO status
+ TQCString frmt; // image format
+ TQIODevice *iodev; // IO tqdevice
+ TQString fname; // file name
+ char *params; // image parameters //### change to TQImageIOData *d in 3.0
+ TQString descr; // image description
+ TQImageIOData *d;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQImageIO( const TQImageIO & );
+ TQImageIO &operator=( const TQImageIO & );
+#endif
+};
+#endif
+
+#else // USE_QT4
+
+class TQImageDataMisc; // internal
+#ifndef TQT_NO_IMAGE_TEXT
+class TQ_EXPORT TQImageTextKeyLang {
+public:
+ TQImageTextKeyLang(const char* k, const char* l) : key(k), lang(l) { }
+ TQImageTextKeyLang() { }
+
+ TQCString key;
+ TQCString lang;
+
+ bool operator< (const TQImageTextKeyLang& other) const
+ { return key < other.key || (key==other.key && lang < other.lang); }
+ bool operator== (const TQImageTextKeyLang& other) const
+ { return key==other.key && lang==other.lang; }
+};
+#endif //TQT_NO_IMAGE_TEXT
+
+
+class TQ_EXPORT TQImage
+{
+public:
+ enum Endian { IgnoreEndian, BigEndian, LittleEndian };
+
+ TQImage();
+ TQImage( int width, int height, int depth, int numColors=0,
+ Endian bitOrder=IgnoreEndian );
+ TQImage( const TQSize&, int depth, int numColors=0,
+ Endian bitOrder=IgnoreEndian );
+#ifndef TQT_NO_IMAGEIO
+ TQImage( const TQString &fileName, const char* format=0 );
+ TQImage( const char * const xpm[] );
+ TQImage( const TQByteArray &data );
+#endif
+ TQImage( uchar* data, int w, int h, int depth,
+ TQRgb* colortable, int numColors,
+ Endian bitOrder );
+#ifdef TQ_WS_TQWS
+ TQImage( uchar* data, int w, int h, int depth, int pbl,
+ TQRgb* colortable, int numColors,
+ Endian bitOrder );
+#endif
+ TQImage( const TQImage & );
+ ~TQImage();
+
+ TQImage &operator=( const TQImage & );
+ TQImage &operator=( const TQPixmap & );
+ bool operator==( const TQImage & ) const;
+ bool operator!=( const TQImage & ) const;
+ void detach();
+ TQImage copy() const;
+ TQImage copy(int x, int y, int w, int h, int conversion_flags=0) const;
+ TQImage copy(const TQRect&) const;
+#ifndef TQT_NO_MIME
+ static TQImage fromMimeSource( const TQString& abs_name );
+#endif
+ bool isNull() const { return data->bits == 0; }
+
+ int width() const { return data->w; }
+ int height() const { return data->h; }
+ TQSize size() const { return TQSize(data->w,data->h); }
+ TQRect rect() const { return TQRect(0,0,data->w,data->h); }
+ int depth() const { return data->d; }
+ int numColors() const { return data->ncols; }
+ Endian bitOrder() const { return (Endian) data->bitordr; }
+
+ TQRgb color( int i ) const;
+ void setColor( int i, TQRgb c );
+ void setNumColors( int );
+
+ bool hasAlphaBuffer() const;
+ void setAlphaBuffer( bool );
+
+ bool allGray() const;
+ bool isGrayscale() const;
+
+ uchar *bits() const;
+ uchar *scanLine( int ) const;
+ uchar **jumpTable() const;
+ TQRgb *colorTable() const;
+ int numBytes() const;
+ int bytesPerLine() const;
+
+#ifdef TQ_WS_TQWS
+ TQGfx * graphicsContext();
+#endif
+
+ bool create( int width, int height, int depth, int numColors=0,
+ Endian bitOrder=IgnoreEndian );
+ bool create( const TQSize&, int depth, int numColors=0,
+ Endian bitOrder=IgnoreEndian );
+ void reset();
+
+ void fill( uint pixel );
+ void invertPixels( bool invertAlpha = TRUE );
+
+ TQImage convertDepth( int ) const;
+#ifndef TQT_NO_IMAGE_TRUECOLOR
+ TQImage convertDepthWithPalette( int, TQRgb* p, int pc, int cf=0 ) const;
+#endif
+ TQImage convertDepth( int, int conversion_flags ) const;
+ TQImage convertBitOrder( Endian ) const;
+
+ enum ScaleMode {
+ ScaleFree,
+ ScaleMin,
+ ScaleMax
+ };
+#ifndef TQT_NO_IMAGE_SMOOTHSCALE
+ TQImage smoothScale( int w, int h, ScaleMode mode=ScaleFree ) const;
+ TQImage smoothScale( const TQSize& s, ScaleMode mode=ScaleFree ) const;
+#endif
+#ifndef TQT_NO_IMAGE_TRANSFORMATION
+ TQImage scale( int w, int h, ScaleMode mode=ScaleFree ) const;
+ TQImage scale( const TQSize& s, ScaleMode mode=ScaleFree ) const;
+ TQImage scaleWidth( int w ) const;
+ TQImage scaleHeight( int h ) const;
+ TQImage xForm( const TQWMatrix &matrix ) const;
+#endif
+
+#ifndef TQT_NO_IMAGE_DITHER_TO_1
+ TQImage createAlphaMask( int conversion_flags=0 ) const;
+#endif
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+ TQImage createHeuristicMask( bool clipTight=TRUE ) const;
+#endif
+#ifndef TQT_NO_IMAGE_MIRROR
+ TQImage mirror() const;
+ TQImage mirror(bool horizontally, bool vertically) const;
+#endif
+ TQImage swapRGB() const;
+
+ static Endian systemBitOrder();
+ static Endian systemByteOrder();
+
+#ifndef TQT_NO_IMAGEIO
+ static const char* imageFormat( const TQString &fileName );
+ static TQStrList inputFormats();
+ static TQStrList outputFormats();
+#ifndef TQT_NO_STRINGLIST
+ static TQStringList inputFormatList();
+ static TQStringList outputFormatList();
+#endif
+ bool load( const TQString &fileName, const char* format=0 );
+ bool loadFromData( const uchar *buf, uint len,
+ const char *format=0 );
+ bool loadFromData( TQByteArray data, const char* format=0 );
+ bool save( const TQString &fileName, const char* format,
+ int quality=-1 ) const;
+ bool save( TQIODevice * tqdevice, const char* format,
+ int quality=-1 ) const;
+#endif //TQT_NO_IMAGEIO
+
+ bool valid( int x, int y ) const;
+ int pixelIndex( int x, int y ) const;
+ TQRgb pixel( int x, int y ) const;
+ void setPixel( int x, int y, uint index_or_rgb );
+
+ // Auxiliary data
+ int dotsPerMeterX() const;
+ int dotsPerMeterY() const;
+ void setDotsPerMeterX(int);
+ void setDotsPerMeterY(int);
+ TQPoint offset() const;
+ void setOffset(const TQPoint&);
+#ifndef TQT_NO_IMAGE_TEXT
+ TQValueList<TQImageTextKeyLang> textList() const;
+ TQStringList textLanguages() const;
+ TQStringList textKeys() const;
+ TQString text(const char* key, const char* lang=0) const;
+ TQString text(const TQImageTextKeyLang&) const;
+ void setText(const char* key, const char* lang, const TQString&);
+#endif
+private:
+ void init();
+ void reinit();
+ void freeBits();
+ static void warningIndexRange( const char *, int );
+
+ struct TQImageData : public TQShared { // internal image data
+ int w; // image width
+ int h; // image height
+ int d; // image depth
+ int ncols; // number of colors
+ int nbytes; // number of bytes data
+ int bitordr; // bit order (1 bit depth)
+ TQRgb *ctbl; // color table
+ uchar **bits; // image data
+ bool alpha; // alpha buffer
+ int dpmx; // dots per meter X (or 0)
+ int dpmy; // dots per meter Y (or 0)
+ TQPoint offset; // offset in pixels
+#ifndef TQT_NO_IMAGE_TEXT
+ TQImageDataMisc* misc; // less common stuff
+#endif
+ bool ctbl_mine; // this allocated ctbl
+ } *data;
+#ifndef TQT_NO_IMAGE_TEXT
+ TQImageDataMisc& misc() const;
+#endif
+#ifndef TQT_NO_IMAGEIO
+ bool doImageIO( TQImageIO* io, int quality ) const;
+#endif
+ friend TQ_EXPORT void bitBlt( TQImage* dst, int dx, int dy,
+ const TQImage* src, int sx, int sy,
+ int sw, int sh, int conversion_flags );
+};
+
+
+// TQImage stream functions
+
+#if !defined(TQT_NO_DATASTREAM) && !defined(TQT_NO_IMAGEIO)
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQImage & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQImage & );
+#endif
+
+#ifndef TQT_NO_IMAGEIO
+class TQIODevice;
+typedef void (*image_io_handler)( TQImageIO * ); // image IO handler
+
+
+struct TQImageIOData;
+
+
+class TQ_EXPORT TQImageIO
+{
+public:
+ TQImageIO();
+ TQImageIO( TQIODevice *ioDevice, const char *format );
+ TQImageIO( const TQString &fileName, const char* format );
+ ~TQImageIO();
+
+
+ const TQImage &image() const { return im; }
+ int status() const { return iostat; }
+ const char *format() const { return frmt; }
+ TQIODevice *ioDevice() const { return iodev; }
+ TQString fileName() const { return fname; }
+ int quality() const;
+ TQString description() const { return descr; }
+ const char *parameters() const;
+ float gamma() const;
+
+ void setImage( const TQImage & );
+ void setqStatus( int );
+ void setFormat( const char * );
+ void setIODevice( TQIODevice * );
+ void setFileName( const TQString & );
+ void setQuality( int );
+ void setDescription( const TQString & );
+ void setParameters( const char * );
+ void setGamma( float );
+
+ bool read();
+ bool write();
+
+ static const char* imageFormat( const TQString &fileName );
+ static const char *imageFormat( TQIODevice * );
+ static TQStrList inputFormats();
+ static TQStrList outputFormats();
+
+ static void defineIOHandler( const char *format,
+ const char *header,
+ const char *flags,
+ image_io_handler read_image,
+ image_io_handler write_image );
+
+private:
+ void init();
+
+ TQImage im; // image
+ int iostat; // IO status
+ TQCString frmt; // image format
+ TQIODevice *iodev; // IO tqdevice
+ TQString fname; // file name
+ char *params; // image parameters //### change to TQImageIOData *d in 3.0
+ TQString descr; // image description
+ TQImageIOData *d;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQImageIO( const TQImageIO & );
+ TQImageIO &operator=( const TQImageIO & );
+#endif
+};
+
+#endif //TQT_NO_IMAGEIO
+
+TQ_EXPORT void bitBlt( TQImage* dst, int dx, int dy, const TQImage* src,
+ int sx=0, int sy=0, int sw=-1, int sh=-1,
+ int conversion_flags=0 );
+
+
+/*****************************************************************************
+ TQImage member functions
+ *****************************************************************************/
+
+inline bool TQImage::hasAlphaBuffer() const
+{
+ return data->alpha;
+}
+
+inline uchar *TQImage::bits() const
+{
+ return data->bits ? data->bits[0] : 0;
+}
+
+inline uchar **TQImage::jumpTable() const
+{
+ return data->bits;
+}
+
+inline TQRgb *TQImage::colorTable() const
+{
+ return data->ctbl;
+}
+
+inline int TQImage::numBytes() const
+{
+ return data->nbytes;
+}
+
+inline int TQImage::bytesPerLine() const
+{
+ return data->h ? data->nbytes/data->h : 0;
+}
+
+inline TQImage TQImage::copy(const TQRect& r) const
+{
+ return copy(r.x(), r.y(), r.width(), r.height());
+}
+
+inline TQRgb TQImage::color( int i ) const
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( i >= data->ncols )
+ warningIndexRange( "color", i );
+#endif
+ return data->ctbl ? data->ctbl[i] : (TQRgb)-1;
+}
+
+inline void TQImage::setColor( int i, TQRgb c )
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( i >= data->ncols )
+ warningIndexRange( "setColor", i );
+#endif
+ if ( data->ctbl )
+ data->ctbl[i] = c;
+}
+
+inline uchar *TQImage::scanLine( int i ) const
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( i >= data->h )
+ warningIndexRange( "scanLine", i );
+#endif
+ return data->bits ? data->bits[i] : 0;
+}
+
+inline int TQImage::dotsPerMeterX() const
+{
+ return data->dpmx;
+}
+
+inline int TQImage::dotsPerMeterY() const
+{
+ return data->dpmy;
+}
+
+inline TQPoint TQImage::offset() const
+{
+ return data->offset;
+}
+
+#endif // USE_QT4
+
+#endif // TQIMAGE_H
diff --git a/tqtinterface/qt4/src/kernel/tqimageformatinterface_p.h b/tqtinterface/qt4/src/kernel/tqimageformatinterface_p.h
new file mode 100644
index 0000000..f851ff1
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqimageformatinterface_p.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** ...
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQIMAGEFORMATINTERFACE_P_H
+#define TQIMAGEFORMATINTERFACE_P_H
+
+#ifndef TQT_H
+#include <private/tqcom_p.h>
+#endif // TQT_H
+
+#if __GNUC__ - 0 > 3
+#pragma GCC system_header
+#endif
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_NO_COMPONENT
+
+// {04903F05-54B1-4726-A849-FB5CB097CA87}
+#ifndef IID_TQImageFormat
+#define IID_TQImageFormat TQUuid( 0x04903f05, 0x54b1, 0x4726, 0xa8, 0x49, 0xfb, 0x5c, 0xb0, 0x97, 0xca, 0x87 )
+#endif
+
+class TQImage;
+
+struct TQ_EXPORT TQImageFormatInterface : public TQFeatureListInterface
+{
+ virtual TQRESULT loadImage( const TQString &format, const TQString &filename, TQImage * ) = 0;
+ virtual TQRESULT saveImage( const TQString &format, const TQString &filename, const TQImage & ) = 0;
+
+ virtual TQRESULT installIOHandler( const TQString & ) = 0;
+};
+
+#endif // TQT_NO_COMPONENT
+
+#endif // TQIMAGEFORMATINTERFACE_P_H
diff --git a/tqtinterface/qt4/src/kernel/tqimageformatplugin.cpp b/tqtinterface/qt4/src/kernel/tqimageformatplugin.cpp
new file mode 100644
index 0000000..536b9c8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqimageformatplugin.cpp
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** ...
+**
+** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqimageformatplugin.h"
+#ifndef TQT_NO_IMAGEFORMATPLUGIN
+#include "tqimageformatinterface_p.h"
+#include "tqimage.h"
+
+/*!
+ \class TQImageFormatPlugin tqimageformatplugin.h
+ \brief The TQImageFormatPlugin class provides an abstract base for custom image format plugins.
+
+ \ingroup plugins
+
+ The image format plugin is a simple plugin interface that makes
+ it easy to create custom image formats that can be used
+ transparently by applications.
+
+ Writing an image format plugin is achieved by subclassing this
+ base class, reimplementing the pure virtual functions keys() and
+ installIOHandler(), and exporting the class with the
+ TQ_EXPORT_PLUGIN macro. See the \link plugins-howto.html Plugins
+ documentation\endlink for details.
+*/
+
+/*!
+ \fn TQStringList TQImageFormatPlugin::keys() const
+
+ Returns the list of image formats this plugin supports.
+
+ \sa installIOHandler()
+*/
+
+
+/*!
+ \fn bool TQImageFormatPlugin::installIOHandler( const TQString &format )
+
+ Installs a TQImageIO image I/O handler for the image format \a
+ format.
+
+ \sa keys()
+*/
+
+class TQImageFormatPluginPrivate : public TQImageFormatInterface
+{
+public:
+ TQImageFormatPluginPrivate( TQImageFormatPlugin *p )
+ : plugin( p )
+ {
+ }
+ virtual ~TQImageFormatPluginPrivate();
+
+ TQRESULT queryInterface( const TQUuid &iid, TQUnknownInterface **iface );
+ TQ_REFCOUNT;
+
+ TQStringList featureList() const;
+
+ TQRESULT loadImage( const TQString &format, const TQString &filename, TQImage * );
+ TQRESULT saveImage( const TQString &format, const TQString &filename, const TQImage & );
+
+ TQRESULT installIOHandler( const TQString & );
+
+private:
+ TQImageFormatPlugin *plugin;
+};
+
+TQImageFormatPluginPrivate::~TQImageFormatPluginPrivate()
+{
+ delete plugin;
+}
+
+TQRESULT TQImageFormatPluginPrivate::queryInterface( const TQUuid &iid, TQUnknownInterface **iface )
+{
+ *iface = 0;
+
+ if ( iid == IID_TQUnknown )
+ *iface = this;
+ else if ( iid == IID_TQFeatureList )
+ *iface = this;
+ else if ( iid == IID_TQImageFormat )
+ *iface = this;
+ else
+ return TQE_NOINTERFACE;
+
+ (*iface)->addRef();
+ return TQS_OK;
+}
+
+TQStringList TQImageFormatPluginPrivate::featureList() const
+{
+ return plugin->keys();
+}
+
+TQRESULT TQImageFormatPluginPrivate::loadImage( const TQString &format, const TQString &filename, TQImage *image )
+{
+ return plugin->loadImage( format, filename, image ) ? TQS_FALSE : TQS_OK;
+}
+
+TQRESULT TQImageFormatPluginPrivate::saveImage( const TQString &format, const TQString &filename, const TQImage &image )
+{
+ return plugin->saveImage( format, filename, image ) ? TQS_FALSE : TQS_OK;
+}
+
+TQRESULT TQImageFormatPluginPrivate::installIOHandler( const TQString &format )
+{
+ return plugin->installIOHandler( format ) ? TQS_FALSE : TQS_OK;
+}
+
+/*!
+ Constructs an image format plugin. This is invoked automatically
+ by the TQ_EXPORT_PLUGIN macro.
+*/
+TQImageFormatPlugin::TQImageFormatPlugin()
+ : TQGPlugin( d = new TQImageFormatPluginPrivate( this ) )
+{
+}
+
+/*!
+ Destroys the image format plugin.
+
+ You never have to call this explicitly. TQt destroys a plugin
+ automatically when it is no longer used.
+*/
+TQImageFormatPlugin::~TQImageFormatPlugin()
+{
+}
+
+
+/*!\internal
+ */
+bool TQImageFormatPlugin::loadImage( const TQString &format, const TQString &filename, TQImage *image )
+{
+ TQ_UNUSED( format )
+ TQ_UNUSED( filename )
+ TQ_UNUSED( image )
+ return FALSE;
+}
+
+/*! \internal
+ */
+bool TQImageFormatPlugin::saveImage( const TQString &format, const TQString &filename, const TQImage &image )
+{
+ TQ_UNUSED( format )
+ TQ_UNUSED( filename )
+ TQ_UNUSED( image )
+ return FALSE;
+}
+
+#endif // TQT_NO_IMAGEFORMATPLUGIN
diff --git a/tqtinterface/qt4/src/kernel/tqimageformatplugin.h b/tqtinterface/qt4/src/kernel/tqimageformatplugin.h
new file mode 100644
index 0000000..ac9d873
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqimageformatplugin.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Definition of ???
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQIMAGEFORMATPLUGIN_H
+#define TQIMAGEFORMATPLUGIN_H
+
+#ifndef TQT_H
+#include "tqgplugin.h"
+#include "tqstringlist.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_IMAGEFORMATPLUGIN
+class TQImageFormat;
+class TQImageFormatPluginPrivate;
+
+class TQ_EXPORT TQImageFormatPlugin : public TQGPlugin
+{
+ TQ_OBJECT
+public:
+ TQImageFormatPlugin();
+ ~TQImageFormatPlugin();
+
+ virtual TQStringList keys() const = 0;
+ virtual bool loadImage( const TQString &format, const TQString &filename, TQImage *image );
+ virtual bool saveImage( const TQString &format, const TQString &filename, const TQImage &image );
+ virtual bool installIOHandler( const TQString &format ) = 0;
+
+private:
+ TQImageFormatPluginPrivate *d;
+};
+#endif // TQT_NO_IMAGEFORMATPLUGIN
+#endif // TQIMAGEFORMATPLUGIN_H
diff --git a/tqtinterface/qt4/src/kernel/tqinputcontext_p.h b/tqtinterface/qt4/src/kernel/tqinputcontext_p.h
new file mode 100644
index 0000000..03ecaf6
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqinputcontext_p.h
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Definition of ???
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQINPUTCONTEXT_P_H
+#define TQINPUTCONTEXT_P_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#include "tqglobal.h"
+
+class TQKeyEvent;
+class TQWidget;
+class TQFont;
+class TQString;
+
+
+#ifdef TQ_WS_X11
+#include "tqarray.h"
+#include "tqwindowdefs.h"
+#include "tqt_x11_p.h"
+#endif
+
+#ifdef TQ_WS_WIN
+#include "tqt_windows.h"
+#endif
+
+#ifdef TQ_WS_TQWS
+class TQWSIMEvent;
+#endif
+
+class TQInputContext
+{
+public:
+#ifdef TQ_WS_X11
+ TQInputContext(TQWidget *); // should be a toplevel widget
+ ~TQInputContext();
+
+ void setFocus();
+ void setComposePosition(int, int);
+ void setComposeArea(int, int, int, int);
+ void reset();
+
+ int lookupString(XKeyEvent *, TQCString &, KeySym *, Status *) const;
+ void setXFontSet(const TQFont &);
+
+ void *ic;
+ TQString text;
+ TQWidget *tqfocusWidget;
+ bool composing;
+ TQFont font;
+ XFontSet fontset;
+ TQMemArray<bool> selectedChars;
+#endif // TQ_WS_X11
+
+#ifdef TQ_WS_TQWS
+ static void translateIMEvent( TQWSIMEvent *, TQWidget * );
+ static void reset();
+private:
+ static TQWidget* tqfocusWidget;
+ static TQString* composition;
+#endif //TQ_WS_TQWS
+
+#ifdef TQ_WS_WIN
+ static void init();
+ static void shutdown();
+
+ static void TranslateMessage( const MSG *msg);
+ static LRESULT DefWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
+
+ static void setFont( const TQWidget *w, const TQFont & );
+ static void setFocusHint( int x, int y, int w, int h, const TQWidget *widget );
+ static bool startComposition();
+ static bool endComposition( TQWidget *fw = 0 );
+ static bool composition( LPARAM lparam );
+
+ static void accept( TQWidget *fw = 0 );
+ static void enable( TQWidget *w, bool b );
+#endif
+};
+
+#endif // TQINPUTCONTEXT_P_H
diff --git a/tqtinterface/qt4/src/kernel/tqinputcontext_x11.cpp b/tqtinterface/qt4/src/kernel/tqinputcontext_x11.cpp
new file mode 100644
index 0000000..758b56d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqinputcontext_x11.cpp
@@ -0,0 +1,535 @@
+/****************************************************************************
+**
+** Implementation of TQInputContext class
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+#include "tqapplication.h"
+#include "tqwidget.h"
+#include "tqinputcontext_p.h"
+
+#include <stdlib.h>
+#include <limits.h>
+
+
+bool qt_compose_emptied = FALSE;
+
+#if !defined(TQT_NO_XIM)
+
+#define XK_MISCELLANY
+#define XK_LATIN1
+#include <X11/keysymdef.h>
+
+// #define TQT_XIM_DEBUG
+
+// from qapplication_x11.cpp
+extern XIM qt_xim;
+extern XIMStyle qt_xim_style;
+
+/* The cache here is needed, as X11 leaks a few kb for every
+ XFreeFontSet call, so we avoid creating and deletion of fontsets as
+ much as possible
+*/
+static XFontSet fontsetCache[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+static int fontsetRefCount = 0;
+
+static const char * const fontsetnames[] = {
+ "-*-fixed-medium-r-*-*-16-*,-*-*-medium-r-*-*-16-*",
+ "-*-fixed-medium-i-*-*-16-*,-*-*-medium-i-*-*-16-*",
+ "-*-fixed-bold-r-*-*-16-*,-*-*-bold-r-*-*-16-*",
+ "-*-fixed-bold-i-*-*-16-*,-*-*-bold-i-*-*-16-*",
+ "-*-fixed-medium-r-*-*-24-*,-*-*-medium-r-*-*-24-*",
+ "-*-fixed-medium-i-*-*-24-*,-*-*-medium-i-*-*-24-*",
+ "-*-fixed-bold-r-*-*-24-*,-*-*-bold-r-*-*-24-*",
+ "-*-fixed-bold-i-*-*-24-*,-*-*-bold-i-*-*-24-*"
+};
+
+static XFontSet getFontSet( const TQFont &f )
+{
+ int i = 0;
+ if (f.italic())
+ i |= 1;
+ if (f.bold())
+ i |= 2;
+
+ if ( f.pointSize() > 20 )
+ i += 4;
+
+ if ( !fontsetCache[i] ) {
+ Display* dpy = TQPaintDevice::x11AppDisplay();
+ int missCount;
+ char** missList;
+ fontsetCache[i] = XCreateFontSet(dpy, fontsetnames[i], &missList, &missCount, 0);
+ if(missCount > 0)
+ XFreeStringList(missList);
+ if ( !fontsetCache[i] ) {
+ fontsetCache[i] = XCreateFontSet(dpy, "-*-fixed-*-*-*-*-16-*", &missList, &missCount, 0);
+ if(missCount > 0)
+ XFreeStringList(missList);
+ if ( !fontsetCache[i] )
+ fontsetCache[i] = (XFontSet)-1;
+ }
+ }
+ return (fontsetCache[i] == (XFontSet)-1) ? 0 : fontsetCache[i];
+}
+
+
+#ifdef TQ_C_CALLBACKS
+extern "C" {
+#endif // TQ_C_CALLBACKS
+
+ static int xic_start_callback(XIC, XPointer client_data, XPointer) {
+ TQInputContext *qic = (TQInputContext *) client_data;
+ if (! qic) {
+#ifdef TQT_XIM_DEBUG
+ qDebug("compose start: no qic");
+#endif // TQT_XIM_DEBUG
+
+ return 0;
+ }
+
+ qic->composing = TRUE;
+ qic->text = TQString::null;
+ qic->tqfocusWidget = 0;
+
+ if ( qic->selectedChars.size() < 128 )
+ qic->selectedChars.resize( 128 );
+ qic->selectedChars.fill( 0 );
+
+#ifdef TQT_XIM_DEBUG
+ qDebug("compose start");
+#endif // TQT_XIM_DEBUG
+
+ return 0;
+ }
+
+ static int xic_draw_callback(XIC, XPointer client_data, XPointer call_data) {
+ TQInputContext *qic = (TQInputContext *) client_data;
+ if (! qic) {
+#ifdef TQT_XIM_DEBUG
+ qDebug("compose event: invalid compose event %p", qic);
+#endif // TQT_XIM_DEBUG
+
+ return 0;
+ }
+
+ bool send_imstart = FALSE;
+ if (tqApp->tqfocusWidget() != qic->tqfocusWidget && qic->text.isEmpty()) {
+ if (qic->tqfocusWidget) {
+#ifdef TQT_XIM_DEBUG
+ qDebug( "sending IMEnd (empty) to %p", qic->tqfocusWidget );
+#endif // TQT_XIM_DEBUG
+
+ TQIMEvent endevent(TQEvent::IMEnd, TQString::null, -1);
+ TQApplication::sendEvent(qic->tqfocusWidget, &endevent);
+ }
+
+ qic->text = TQString::null;
+ qic->tqfocusWidget = tqApp->tqfocusWidget();
+ qic->composing = FALSE;
+
+ if ( qic->selectedChars.size() < 128 )
+ qic->selectedChars.resize( 128 );
+ qic->selectedChars.fill( 0 );
+
+ if (qic->tqfocusWidget) {
+ qic->composing = TRUE;
+ send_imstart = TRUE;
+ }
+ }
+
+ if (! qic->composing || ! qic->tqfocusWidget) {
+#ifdef TQT_XIM_DEBUG
+ qDebug("compose event: invalid compose event %d %p",
+ qic->composing, qic->tqfocusWidget);
+#endif // TQT_XIM_DEBUG
+
+ return 0;
+ }
+
+ if ( send_imstart ) {
+#ifdef TQT_XIM_DEBUG
+ qDebug( "sending IMStart to %p", qic->tqfocusWidget );
+#endif // TQT_XIM_DEBUG
+
+ qt_compose_emptied = FALSE;
+ TQIMEvent startevent(TQEvent::IMStart, TQString::null, -1);
+ TQApplication::sendEvent(qic->tqfocusWidget, &startevent);
+ }
+
+ XIMPreeditDrawCallbackStruct *drawstruct =
+ (XIMPreeditDrawCallbackStruct *) call_data;
+ XIMText *text = (XIMText *) drawstruct->text;
+ int cursor = drawstruct->caret, sellen = 0;
+
+ if ( ! drawstruct->caret && ! drawstruct->chg_first &&
+ ! drawstruct->chg_length && ! text ) {
+ // nothing to do
+ return 0;
+ }
+
+ if (text) {
+ char *str = 0;
+ if (text->encoding_is_wchar) {
+ int l = wcstombs(NULL, text->string.wide_char, text->length);
+ if (l != -1) {
+ str = new char[l + 1];
+ wcstombs(str, text->string.wide_char, l);
+ str[l] = 0;
+ }
+ } else
+ str = text->string.multi_byte;
+
+ if (! str)
+ return 0;
+
+ TQString s = TQString::fromLocal8Bit(str);
+
+ if (text->encoding_is_wchar)
+ delete [] str;
+
+ if (drawstruct->chg_length < 0)
+ qic->text.tqreplace(drawstruct->chg_first, UINT_MAX, s);
+ else
+ qic->text.tqreplace(drawstruct->chg_first, drawstruct->chg_length, s);
+
+ if ( qic->selectedChars.size() < qic->text.length() ) {
+ // expand the selectedChars array if the compose string is longer
+ uint from = qic->selectedChars.size();
+ qic->selectedChars.resize( qic->text.length() );
+ for ( uint x = from; from < qic->selectedChars.size(); ++x )
+ qic->selectedChars[x] = 0;
+ }
+
+ uint x;
+ bool *p = qic->selectedChars.data() + drawstruct->chg_first;
+ // determine if the changed chars are selected based on text->feedback
+ for ( x = 0; x < s.length(); ++x )
+ *p++ = ( text->feedback ? ( text->feedback[x] & XIMReverse ) : 0 );
+
+ // figure out where the selection starts, and how long it is
+ p = qic->selectedChars.data();
+ bool started = FALSE;
+ for ( x = 0; x < TQMIN(qic->text.length(), qic->selectedChars.size()); ++x ) {
+ if ( started ) {
+ if ( *p ) ++sellen;
+ else break;
+ } else {
+ if ( *p ) {
+ cursor = x;
+ started = TRUE;
+ sellen = 1;
+ }
+ }
+ ++p;
+ }
+ } else {
+ if (drawstruct->chg_length == 0)
+ drawstruct->chg_length = -1;
+
+ qic->text.remove(drawstruct->chg_first, drawstruct->chg_length);
+ qt_compose_emptied = qic->text.isEmpty();
+ if ( qt_compose_emptied ) {
+#ifdef TQT_XIM_DEBUG
+ qDebug( "compose emptied" );
+#endif // TQT_XIM_DEBUG
+
+ // don't send an empty compose, since we will send an IMEnd with
+ // either the correct compose text (or null text if the user has
+ // cancelled the compose or deleted all chars).
+ return 0;
+ }
+ }
+
+#ifdef TQT_XIM_DEBUG
+ qDebug( "sending IMCompose to %p with %d chars",
+ qic->tqfocusWidget, qic->text.length() );
+#endif // TQT_XIM_DEBUG
+
+ TQIMComposeEvent event( TQEvent::IMCompose, qic->text, cursor, sellen );
+ TQApplication::sendEvent(qic->tqfocusWidget, &event);
+ return 0;
+ }
+
+ static int xic_done_callback(XIC, XPointer client_data, XPointer) {
+ TQInputContext *qic = (TQInputContext *) client_data;
+ if (! qic)
+ return 0;
+
+ if (qic->composing && qic->tqfocusWidget) {
+#ifdef TQT_XIM_DEBUG
+ qDebug( "sending IMEnd (empty) to %p", qic->tqfocusWidget );
+#endif // TQT_XIM_DEBUG
+
+ TQIMEvent event(TQEvent::IMEnd, TQString::null, -1);
+ TQApplication::sendEvent(qic->tqfocusWidget, &event);
+ }
+
+ qic->composing = FALSE;
+ qic->tqfocusWidget = 0;
+
+ if ( qic->selectedChars.size() < 128 )
+ qic->selectedChars.resize( 128 );
+ qic->selectedChars.fill( 0 );
+
+ return 0;
+ }
+
+#ifdef TQ_C_CALLBACKS
+}
+#endif // TQ_C_CALLBACKS
+
+#endif // !TQT_NO_XIM
+
+
+
+TQInputContext::TQInputContext(TQWidget *widget)
+ : ic(0), tqfocusWidget(0), composing(FALSE), fontset(0)
+{
+#if !defined(TQT_NO_XIM)
+ fontsetRefCount++;
+ if (! qt_xim) {
+ qWarning("TQInputContext: no input method context available");
+ return;
+ }
+
+ if (! widget->isTopLevel()) {
+ qWarning("TQInputContext: cannot create input context for non-toplevel widgets");
+ return;
+ }
+
+ XPoint spot;
+ XRectangle rect;
+ XVaNestedList preedit_attr = 0;
+ XIMCallback startcallback, drawcallback, donecallback;
+
+ font = widget->font();
+ fontset = getFontSet( font );
+
+ if (qt_xim_style & XIMPreeditArea) {
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = widget->width();
+ rect.height = widget->height();
+
+ preedit_attr = XVaCreateNestedList(0,
+ XNArea, &rect,
+ XNFontSet, fontset,
+ (char *) 0);
+ } else if (qt_xim_style & XIMPreeditPosition) {
+ spot.x = 1;
+ spot.y = 1;
+
+ preedit_attr = XVaCreateNestedList(0,
+ XNSpotLocation, &spot,
+ XNFontSet, fontset,
+ (char *) 0);
+ } else if (qt_xim_style & XIMPreeditCallbacks) {
+ startcallback.client_data = (XPointer) this;
+ startcallback.callback = (XIMProc) xic_start_callback;
+ drawcallback.client_data = (XPointer) this;
+ drawcallback.callback = (XIMProc)xic_draw_callback;
+ donecallback.client_data = (XPointer) this;
+ donecallback.callback = (XIMProc) xic_done_callback;
+
+ preedit_attr = XVaCreateNestedList(0,
+ XNPreeditStartCallback, &startcallback,
+ XNPreeditDrawCallback, &drawcallback,
+ XNPreeditDoneCallback, &donecallback,
+ (char *) 0);
+ }
+
+ if (preedit_attr) {
+ ic = XCreateIC(qt_xim,
+ XNInputStyle, qt_xim_style,
+ XNClientWindow, widget->winId(),
+ XNPreeditAttributes, preedit_attr,
+ (char *) 0);
+ XFree(preedit_attr);
+ } else
+ ic = XCreateIC(qt_xim,
+ XNInputStyle, qt_xim_style,
+ XNClientWindow, widget->winId(),
+ (char *) 0);
+
+ if (! ic)
+ qFatal("Failed to create XIM input context!");
+
+ // when resetting the input context, preserve the input state
+ (void) XSetICValues((XIC) ic, XNResetState, XIMPreserveState, (char *) 0);
+#endif // !TQT_NO_XIM
+}
+
+
+TQInputContext::~TQInputContext()
+{
+
+#if !defined(TQT_NO_XIM)
+ if (ic)
+ XDestroyIC((XIC) ic);
+
+ if ( --fontsetRefCount == 0 ) {
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ for ( int i = 0; i < 8; i++ ) {
+ if ( fontsetCache[i] && fontsetCache[i] != (XFontSet)-1 ) {
+ XFreeFontSet(dpy, fontsetCache[i]);
+ fontsetCache[i] = 0;
+ }
+ }
+ }
+
+#endif // !TQT_NO_XIM
+
+ ic = 0;
+ tqfocusWidget = 0;
+ composing = FALSE;
+}
+
+
+void TQInputContext::reset()
+{
+#if !defined(TQT_NO_XIM)
+ if (tqfocusWidget && composing && ! text.isNull()) {
+#ifdef TQT_XIM_DEBUG
+ qDebug("TQInputContext::reset: composing - sending IMEnd (empty) to %p",
+ tqfocusWidget);
+#endif // TQT_XIM_DEBUG
+
+ TQIMEvent endevent(TQEvent::IMEnd, TQString::null, -1);
+ TQApplication::sendEvent(tqfocusWidget, &endevent);
+ tqfocusWidget = 0;
+ text = TQString::null;
+ if ( selectedChars.size() < 128 )
+ selectedChars.resize( 128 );
+ selectedChars.fill( 0 );
+
+ char *mb = XmbResetIC((XIC) ic);
+ if (mb)
+ XFree(mb);
+ }
+#endif // !TQT_NO_XIM
+}
+
+
+void TQInputContext::setComposePosition(int x, int y)
+{
+#if !defined(TQT_NO_XIM)
+ if (qt_xim && ic) {
+ XPoint point;
+ point.x = x;
+ point.y = y;
+
+ XVaNestedList preedit_attr =
+ XVaCreateNestedList(0,
+ XNSpotLocation, &point,
+
+ (char *) 0);
+ XSetICValues((XIC) ic, XNPreeditAttributes, preedit_attr, (char *) 0);
+ XFree(preedit_attr);
+ }
+#endif // !TQT_NO_XIM
+}
+
+
+void TQInputContext::setComposeArea(int x, int y, int w, int h)
+{
+#if !defined(TQT_NO_XIM)
+ if (qt_xim && ic) {
+ XRectangle rect;
+ rect.x = x;
+ rect.y = y;
+ rect.width = w;
+ rect.height = h;
+
+ XVaNestedList preedit_attr = XVaCreateNestedList(0,
+ XNArea, &rect,
+
+ (char *) 0);
+ XSetICValues((XIC) ic, XNPreeditAttributes, preedit_attr, (char *) 0);
+ XFree(preedit_attr);
+ }
+#endif
+}
+
+
+int TQInputContext::lookupString(XKeyEvent *event, TQCString &chars,
+ KeySym *key, Status *status) const
+{
+ int count = 0;
+
+#if !defined(TQT_NO_XIM)
+ if (qt_xim && ic) {
+ count = XmbLookupString((XIC) ic, event, chars.data(),
+ chars.size(), key, status);
+
+ if ((*status) == XBufferOverflow ) {
+ chars.resize(count + 1);
+ count = XmbLookupString((XIC) ic, event, chars.data(),
+ chars.size(), key, status);
+ }
+ }
+
+#endif // TQT_NO_XIM
+
+ return count;
+}
+
+void TQInputContext::setFocus()
+{
+#if !defined(TQT_NO_XIM)
+ if (qt_xim && ic)
+ XSetICFocus((XIC) ic);
+#endif // !TQT_NO_XIM
+}
+
+void TQInputContext::setXFontSet(const TQFont &f)
+{
+#if !defined(TQT_NO_XIM)
+ if (font == f) return; // nothing to do
+ font = f;
+
+ XFontSet fs = getFontSet(font);
+ if (fontset == fs) return; // nothing to do
+ fontset = fs;
+
+ XVaNestedList preedit_attr = XVaCreateNestedList(0, XNFontSet, fontset, (char *) 0);
+ XSetICValues((XIC) ic, XNPreeditAttributes, preedit_attr, (char *) 0);
+ XFree(preedit_attr);
+#else
+ TQ_UNUSED( f );
+#endif
+}
diff --git a/tqtinterface/qt4/src/kernel/tqinternal.cpp b/tqtinterface/qt4/src/kernel/tqinternal.cpp
new file mode 100644
index 0000000..7ad13f1
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqinternal.cpp
@@ -0,0 +1,785 @@
+/****************************************************************************
+**
+** Implementation of some internal classes
+**
+** Created : 010427
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "private/tqinternal_p.h"
+#include "tqwidget.h"
+#include "tqpixmap.h"
+#include "tqpainter.h"
+#include "tqcleanuphandler.h"
+
+static TQPixmap* qdb_shared_pixmap = 0;
+static TQPixmap *qdb_force_pixmap = 0;
+static TQSharedDoubleBuffer* qdb_owner = 0;
+
+TQCleanupHandler<TQPixmap> qdb_pixmap_cleanup;
+
+#ifdef TQ_WS_MACX
+bool TQSharedDoubleBuffer::dblbufr = FALSE;
+#else
+bool TQSharedDoubleBuffer::dblbufr = TRUE;
+#endif
+
+
+/*
+ hardLimitWidth/Height: if >= 0, the maximum number of pixels that
+ get double buffered.
+
+ sharedLimitWidth/Height: if >= 0, the maximum number of pixels the
+ shared double buffer can keep.
+
+ For x with sharedLimitSize < x <= hardLimitSize, temporary buffers
+ are constructed.
+ */
+static const int hardLimitWidth = -1;
+static const int hardLimitHeight = -1;
+// #if defined( TQ_WS_TQWS ) || defined( TQ_WS_MAC9 )
+// // Small in TQt/Embedded / Mac9 - 5K on 32bpp
+// static const int sharedLimitWidth = 64;
+// static const int sharedLimitHeight = 20;
+// #else
+// 240K on 32bpp
+static const int sharedLimitWidth = 640;
+static const int sharedLimitHeight = 100;
+// #endif
+
+// *******************************************************************
+// TQSharedDoubleBufferCleaner declaration and implementation
+// *******************************************************************
+
+/* \internal
+ This class is responsible for cleaning up the pixmaps created by the
+ TQSharedDoubleBuffer class. When TQSharedDoubleBuffer creates a
+ pixmap larger than the shared limits, this class deletes it after a
+ specified amount of time.
+
+ When the large pixmap is created/used, you must call start(). If the
+ large pixmap is ever deleted, you must call stop(). The start()
+ method always restarts the timer, so if the large pixmap is
+ constantly in use, the timer will never fire, and the pixmap will
+ not be constantly created and destroyed.
+*/
+
+static const int shared_double_buffer_cleanup_timeout = 30000; // 30 seconds
+
+// declaration
+
+class TQSharedDoubleBufferCleaner : public TQObject
+{
+public:
+ TQSharedDoubleBufferCleaner( void );
+
+ void start( void );
+ void stop( void );
+
+ void doCleanup( void );
+
+ bool event( TQEvent *e );
+
+private:
+ int timer_id;
+};
+
+// implementation
+
+/* \internal
+ Creates a TQSharedDoubleBufferCleaner object. The timer is not
+ started when creating the object.
+*/
+TQSharedDoubleBufferCleaner::TQSharedDoubleBufferCleaner( void )
+ : TQObject( 0, "internal shared double buffer cleanup object" ),
+ timer_id( -1 )
+{
+}
+
+/* \internal
+ Starts the cleanup timer. Any previously running timer is stopped.
+*/
+void TQSharedDoubleBufferCleaner::start( void )
+{
+ stop();
+ timer_id = startTimer( shared_double_buffer_cleanup_timeout );
+}
+
+/* \internal
+ Stops the cleanup timer, if it is running.
+*/
+void TQSharedDoubleBufferCleaner::stop( void )
+{
+ if ( timer_id != -1 )
+ killTimer( timer_id );
+ timer_id = -1;
+}
+
+/* \internal
+ */
+void TQSharedDoubleBufferCleaner::doCleanup( void )
+{
+ qdb_pixmap_cleanup.remove( &qdb_force_pixmap );
+ delete qdb_force_pixmap;
+ qdb_force_pixmap = 0;
+}
+
+/* \internal
+ Event handler reimplementation. Calls doCleanup() when the timer
+ fires.
+*/
+bool TQSharedDoubleBufferCleaner::event( TQEvent *e )
+{
+ if ( e->type() != TQEvent::Timer )
+ return FALSE;
+
+ TQTimerEvent *event = (TQTimerEvent *) e;
+ if ( event->timerId() == timer_id ) {
+ doCleanup();
+ stop();
+ }
+#ifdef TQT_CHECK_STATE
+ else {
+ qWarning( "TQSharedDoubleBufferCleaner::event: invalid timer event received." );
+ return FALSE;
+ }
+#endif // TQT_CHECK_STATE
+
+ return TRUE;
+}
+
+// static instance
+static TQSharedDoubleBufferCleaner *static_cleaner = 0;
+TQSingleCleanupHandler<TQSharedDoubleBufferCleaner> cleanup_static_cleaner;
+
+inline static TQSharedDoubleBufferCleaner *staticCleaner()
+{
+ if ( ! static_cleaner ) {
+ static_cleaner = new TQSharedDoubleBufferCleaner();
+ cleanup_static_cleaner.set( &static_cleaner );
+ }
+ return static_cleaner;
+}
+
+
+// *******************************************************************
+// TQSharedDoubleBuffer implementation
+// *******************************************************************
+
+/* \internal
+ \enum DoubleBufferFlags
+
+ \value InitBG initialize the background of the double buffer.
+
+ \value Force disable shared buffer size limits.
+
+ \value Default InitBG and Force are used by default.
+*/
+
+/* \internal
+ \enum DoubleBufferState
+
+ \value Active indicates that the buffer may be used.
+
+ \value BufferActive indicates that painting with painter() will be
+ double buffered.
+
+ \value ExternalPainter indicates that painter() will return a
+ painter that was not created by TQSharedDoubleBuffer.
+*/
+
+/* \internal
+ \class TQSharedDoubleBuffer
+
+ This class provides a single, reusable double buffer. This class
+ is used internally by TQt widgets that need double buffering, which
+ prevents each individual widget form creating a double buffering
+ pixmap.
+
+ Using a single pixmap double buffer and sharing it across all
+ widgets is nicer on window system resources.
+*/
+
+/* \internal
+ Creates a TQSharedDoubleBuffer with flags \f.
+
+ \sa DoubleBufferFlags
+*/
+TQSharedDoubleBuffer::TQSharedDoubleBuffer( DBFlags f )
+ : wid( 0 ), rx( 0 ), ry( 0 ), rw( 0 ), rh( 0 ), flags( f ), state( 0 ),
+ p( 0 ), external_p( 0 ), pix( 0 )
+{
+}
+
+/* \internal
+ Creates a TQSharedDoubleBuffer with flags \f. The \a widget, \a x,
+ \a y, \a w and \a h arguments are passed to begin().
+
+ \sa DoubleBufferFlags begin()
+*/
+TQSharedDoubleBuffer::TQSharedDoubleBuffer( TQWidget* widget,
+ int x, int y, int w, int h,
+ DBFlags f )
+ : wid( 0 ), rx( 0 ), ry( 0 ), rw( 0 ), rh( 0 ), flags( f ), state( 0 ),
+ p( 0 ), external_p( 0 ), pix( 0 )
+{
+ begin( widget, x, y, w, h );
+}
+
+/* \internal
+ Creates a TQSharedDoubleBuffer with flags \f. The \a painter, \a x,
+ \a y, \a w and \a h arguments are passed to begin().
+
+ \sa DoubleBufferFlags begin()
+*/
+TQSharedDoubleBuffer::TQSharedDoubleBuffer( TQPainter* painter,
+ int x, int y, int w, int h,
+ DBFlags f)
+ : wid( 0 ), rx( 0 ), ry( 0 ), rw( 0 ), rh( 0 ), flags( f ), state( 0 ),
+ p( 0 ), external_p( 0 ), pix( 0 )
+{
+ begin( painter, x, y, w, h );
+}
+
+/* \internal
+ Creates a TQSharedDoubleBuffer with flags \f. The \a widget and
+ \a r arguments are passed to begin().
+
+ \sa DoubleBufferFlags begin()
+*/
+TQSharedDoubleBuffer::TQSharedDoubleBuffer( TQWidget *widget, const TQRect &r, DBFlags f )
+ : wid( 0 ), rx( 0 ), ry( 0 ), rw( 0 ), rh( 0 ), flags( f ), state( 0 ),
+ p( 0 ), external_p( 0 ), pix( 0 )
+{
+ begin( widget, r );
+}
+
+/* \internal
+ Creates a TQSharedDoubleBuffer with flags \f. The \a painter and
+ \a r arguments are passed to begin().
+
+ \sa DoubleBufferFlags begin()
+*/
+TQSharedDoubleBuffer::TQSharedDoubleBuffer( TQPainter *painter, const TQRect &r, DBFlags f )
+ : wid( 0 ), rx( 0 ), ry( 0 ), rw( 0 ), rh( 0 ), flags( f ), state( 0 ),
+ p( 0 ), external_p( 0 ), pix( 0 )
+{
+ begin( painter, r );
+}
+
+/* \internal
+ Destructs the TQSharedDoubleBuffer and calls end() if the buffer is
+ active.
+
+ \sa isActive() end()
+*/
+TQSharedDoubleBuffer::~TQSharedDoubleBuffer()
+{
+ if ( isActive() )
+ end();
+}
+
+/* \internal
+ Starts double buffered painting in the area specified by \a x,
+ \a y, \a w and \a h on \a painter. Painting should be done using the
+ TQPainter returned by TQSharedDoubleBuffer::painter().
+
+ The double buffered area will be updated when calling end().
+
+ \sa painter() isActive() end()
+*/
+bool TQSharedDoubleBuffer::begin( TQPainter* painter, int x, int y, int w, int h )
+{
+ if ( isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQSharedDoubleBuffer::begin: Buffer is already active."
+ "\n\tYou must end() the buffer before a second begin()" );
+#endif // TQT_CHECK_STATE
+ return FALSE;
+ }
+
+ external_p = painter;
+
+ if ( painter->tqdevice()->devType() == TQInternal::Widget )
+// return begin( (TQWidget *) painter->tqdevice(), x, y, w, h ); // This was very lazy code on Trolltech's part! Nothing like a bad reinterpret cast, completely ignoring the different base object addresses, to ruin your week...
+ return begin( static_cast<TQWidget*>(static_cast<QWidget*>(static_cast<QPaintDevice*>(painter->tqdevice()))), x, y, w, h );
+
+ state = Active;
+
+ rx = x;
+ ry = y;
+ rw = w;
+ rh = h;
+
+ if ( ( pix = getPixmap() ) ) {
+#ifdef TQ_WS_X11
+ if ( painter->tqdevice()->x11Screen() != pix->x11Screen() )
+ pix->x11SetScreen( painter->tqdevice()->x11Screen() );
+ TQPixmap::x11SetDefaultScreen( pix->x11Screen() );
+#endif // TQ_WS_X11
+
+ state |= BufferActive;
+ p = new TQPainter( pix );
+ if ( p->isActive() ) {
+ p->setPen( external_p->pen() );
+ p->setBackgroundColor( external_p->backgroundColor() );
+ p->setFont( external_p->font() );
+ }
+ } else {
+ state |= ExternalPainter;
+ p = external_p;
+ }
+
+ return TRUE;
+}
+
+/* \internal
+
+
+ Starts double buffered painting in the area specified by \a x,
+ \a y, \a w and \a h on \a widget. Painting should be done using the
+ TQPainter returned by TQSharedDoubleBuffer::painter().
+
+ The double buffered area will be updated when calling end().
+
+ \sa painter() isActive() end()
+*/
+bool TQSharedDoubleBuffer::begin( TQWidget* widget, int x, int y, int w, int h )
+{
+ if ( isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQSharedDoubleBuffer::begin: Buffer is already active."
+ "\n\tYou must end() the buffer before a second begin()" );
+#endif // TQT_CHECK_STATE
+ return FALSE;
+ }
+
+ state = Active;
+
+ wid = widget;
+ rx = x;
+ ry = y;
+ rw = w <= 0 ? wid->width() : w;
+ rh = h <= 0 ? wid->height() : h;
+
+ if ( ( pix = getPixmap() ) ) {
+#ifdef TQ_WS_X11
+ if ( wid->x11Screen() != pix->x11Screen() )
+ pix->x11SetScreen( wid->x11Screen() );
+ TQPixmap::x11SetDefaultScreen( pix->x11Screen() );
+#endif // TQ_WS_X11
+
+ state |= BufferActive;
+ if ( flags & InitBG ) {
+ pix->fill( wid, rx, ry );
+ }
+ p = new TQPainter( static_cast<QPaintDevice*>(pix), wid );
+ // newly created painters should be translated to the origin
+ // of the widget, so that paint methods can draw onto the double
+ // buffered painter in widget coordinates.
+ p->setBrushOrigin( -rx, -ry );
+ p->translate( -rx, -ry );
+ } else {
+ if ( external_p ) {
+ state |= ExternalPainter;
+ p = external_p;
+ } else {
+ p = new TQPainter( wid );
+ }
+
+ if ( flags & InitBG ) {
+ wid->erase( rx, ry, rw, rh );
+ }
+ }
+ return TRUE;
+}
+
+/* \internal
+ Ends double buffered painting. The contents of the shared double
+ buffer pixmap are drawn onto the destination by calling flush(),
+ and ownership of the shared double buffer pixmap is released.
+
+ \sa begin() flush()
+*/
+bool TQSharedDoubleBuffer::end()
+{
+ if ( ! isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQSharedDoubleBuffer::end: Buffer is not active."
+ "\n\tYou must call begin() before calling end()." );
+#endif // TQT_CHECK_STATE
+ return FALSE;
+ }
+
+ if ( ! ( state & ExternalPainter ) ) {
+ p->end();
+ delete p;
+ }
+
+ flush();
+
+ if ( pix ) {
+ releasePixmap();
+ }
+
+ wid = 0;
+ rx = ry = rw = rh = 0;
+ // do not reset flags!
+ state = 0;
+
+ p = external_p = 0;
+ pix = 0;
+
+ return TRUE;
+}
+
+/* \internal
+ Paints the contents of the shared double buffer pixmap onto the
+ destination. The destination is determined from the arguments
+ based to begin().
+
+ Note: You should not need to call this function, since it is called
+ from end().
+
+ \sa begin() end()
+*/
+void TQSharedDoubleBuffer::flush()
+{
+ if ( ! isActive() || ! ( state & BufferActive ) )
+ return;
+
+ if ( external_p )
+ external_p->drawPixmap( rx, ry, *pix, 0, 0, rw, rh );
+ else if ( wid && wid->isVisible() )
+ bitBlt( wid, rx, ry, pix, 0, 0, rw, rh );
+}
+
+/* \internal
+ Aquire ownership of the shared double buffer pixmap, subject to the
+ following conditions:
+
+ \list 1
+ \i double buffering is enabled globally.
+ \i the shared double buffer pixmap is not in use.
+ \i the size specified in begin() is valid, and within limits.
+ \endlist
+
+ If all of these conditions are met, then this TQSharedDoubleBuffer
+ object becomes the owner of the shared double buffer pixmap. The
+ shared double buffer pixmap is resize if necessary, and this
+ function returns a pointer to the pixmap. Ownership must later be
+ relinquished by calling releasePixmap().
+
+ If none of the above conditions are met, this function returns
+ zero.
+
+ \sa releasePixmap()
+*/
+TQPixmap *TQSharedDoubleBuffer::getPixmap()
+{
+ if ( isDisabled() ) {
+ // double buffering disabled globally
+ return 0;
+ }
+
+ if ( qdb_owner ) {
+ // shared pixmap already in use
+ return 0;
+ }
+
+ if ( rw <= 0 || rh <= 0 ||
+ ( hardLimitWidth > 0 && rw >= hardLimitWidth ) ||
+ ( hardLimitHeight > 0 && rh >= hardLimitHeight ) ) {
+ // invalid size, or hard limit reached
+ return 0;
+ }
+
+ if ( rw >= sharedLimitWidth || rh >= sharedLimitHeight ) {
+ if ( flags & Force ) {
+#ifdef USE_QT4
+ printf("[WARNING] Working around mysterious TQSharedDoubleBuffer [tqinternal.cpp] resize problem\n\r");
+ rw = 4000; // 32MB seems reasonable enough, but the usage is likely to be wider than it is tall (think of multiple wide monitors)
+ rh = 2000;
+#else // USE_QT4
+ rw = TQMIN(rw, 8000);
+ rh = TQMIN(rh, 8000);
+#endif // USE_QT4
+ // need to create a big pixmap and start the cleaner
+ if ( ! qdb_force_pixmap ) {
+ qdb_force_pixmap = new TQPixmap( rw, rh );
+ qdb_pixmap_cleanup.add( &qdb_force_pixmap );
+ } else if ( qdb_force_pixmap->width () < rw ||
+ qdb_force_pixmap->height() < rh ) {
+// qdb_force_pixmap->resize( rw, rh );
+ qdb_force_pixmap->resize( TQMAX(rw,qdb_force_pixmap->width()), TQMAX(rh,qdb_force_pixmap->height()) );
+ }
+ qdb_owner = this;
+ staticCleaner()->start();
+ return qdb_force_pixmap;
+ }
+
+ // size is outside shared limit
+ return 0;
+ }
+
+ if ( ! qdb_shared_pixmap ) {
+#ifdef USE_QT4
+ printf("[WARNING] Working around mysterious TQSharedDoubleBuffer [tqinternal.cpp] resize problem\n\r");
+ qdb_shared_pixmap = new TQPixmap( sharedLimitWidth, sharedLimitHeight );
+#else // USE_QT4
+ qdb_shared_pixmap = new TQPixmap( rw, rh );
+#endif // USE_QT4
+ qdb_pixmap_cleanup.add( &qdb_shared_pixmap );
+ } else if ( qdb_shared_pixmap->width() < rw ||
+ qdb_shared_pixmap->height() < rh ) {
+// qdb_shared_pixmap->resize( rw, rh );
+ qdb_shared_pixmap->resize( TQMAX(rw,qdb_shared_pixmap->width()), TQMAX(rh,qdb_shared_pixmap->height()) );
+ }
+ qdb_owner = this;
+ return qdb_shared_pixmap;
+}
+
+/* \internal
+ Releases ownership of the shared double buffer pixmap.
+
+ \sa getPixmap()
+*/
+void TQSharedDoubleBuffer::releasePixmap()
+{
+ if ( qdb_owner != this ) {
+ // sanity check
+
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQSharedDoubleBuffer::releasePixmap: internal error."
+ "\n\t%p does not own shared pixmap, %p does.",
+ (void*)this, (void*)qdb_owner );
+#endif // TQT_CHECK_STATE
+
+ return;
+ }
+
+ qdb_owner = 0;
+}
+
+/* \internal
+ \fn bool TQSharedDoubleBuffer::isDisabled()
+
+ Returns TRUE if double buffering is disabled globally, FALSE otherwise.
+*/
+
+/* \internal
+ \fn void TQSharedDoubleBuffer::setDisabled( bool off )
+
+ Disables global double buffering \a off is TRUE, otherwise global
+ double buffering is enabled.
+*/
+
+/* \internal
+ Deletes the shared double buffer pixmap. You should not need to
+ call this function, since it is called from the TQApplication
+ destructor.
+*/
+void TQSharedDoubleBuffer::cleanup()
+{
+ qdb_pixmap_cleanup.remove( &qdb_shared_pixmap );
+ qdb_pixmap_cleanup.remove( &qdb_force_pixmap );
+ delete qdb_shared_pixmap;
+ delete qdb_force_pixmap;
+ qdb_shared_pixmap = 0;
+ qdb_force_pixmap = 0;
+ qdb_owner = 0;
+}
+
+/* \internal
+ \fn bool TQSharedDoubleBuffer::begin( TQWidget *widget, const TQRect &r )
+ \overload
+*/
+
+/* \internal
+ \fn bool TQSharedDoubleBuffer::begin( TQPainter *painter, const TQRect &r )
+ \overload
+*/
+
+/* \internal
+ \fn TQPainter *TQSharedDoubleBuffer::painter() const
+
+ Returns the active painter on the double buffered area,
+ or zero if double buffered painting is not active.
+*/
+
+/* \internal
+ \fn bool TQSharedDoubleBuffer::isActive() const
+
+ Returns TRUE if double buffered painting is active, FALSE otherwise.
+*/
+
+/* \internal
+ \fn bool TQSharedDoubleBuffer::isBuffered() const
+
+ Returns TRUE if painting is double buffered, FALSE otherwise.
+*/
+
+
+// *******************************************************************
+// TQMembuf declaration and implementation
+// *******************************************************************
+
+/* \internal
+ This class implements an efficient buffering of data that is often used by
+ asynchronous IO classes like TQSocket, TQHttp and TQProcess.
+*/
+
+TQMembuf::TQMembuf() : _size(0), _index(0)
+{
+ buf = new TQPtrList<TQByteArray>;
+ buf->setAutoDelete( TRUE );
+}
+
+TQMembuf::~TQMembuf()
+{
+ delete buf;
+}
+
+/*! \internal
+ This function consumes \a nbytes bytes of data from the
+ buffer and copies it into \a sink. If \a sink is a 0 pointer
+ the data goes into the nirvana.
+*/
+bool TQMembuf::consumeBytes( TQ_ULONG nbytes, char *sink )
+{
+ if ( nbytes <= 0 || nbytes > _size )
+ return FALSE;
+ _size -= nbytes;
+ for ( ;; ) {
+ TQByteArray *a = buf->first();
+ if ( _index + nbytes >= a->size() ) {
+ // Here we skip the whole byte array and get the next later
+ int len = a->size() - _index;
+ if ( sink ) {
+ memcpy( sink, a->data()+_index, len );
+ sink += len;
+ }
+ nbytes -= len;
+ buf->remove();
+ _index = 0;
+ if ( nbytes == 0 )
+ break;
+ } else {
+ // Here we skip only a part of the first byte array
+ if ( sink )
+ memcpy( sink, a->data()+_index, nbytes );
+ _index += nbytes;
+ break;
+ }
+ }
+ return TRUE;
+}
+
+/*! \internal
+ Scans for any occurrence of '\n' in the buffer. If \a store
+ is not 0 the text up to the first '\n' (or terminating 0) is
+ written to \a store, and a terminating 0 is appended to \a store
+ if necessary. Returns TRUE if a '\n' was found; otherwise returns
+ FALSE.
+*/
+bool TQMembuf::scanNewline( TQByteArray *store )
+{
+ if ( _size == 0 )
+ return FALSE;
+ int i = 0; // index into 'store'
+ TQByteArray *a = 0;
+ char *p;
+ int n;
+ for ( ;; ) {
+ if ( !a ) {
+ a = buf->first();
+ if ( !a || a->size() == 0 )
+ return FALSE;
+ p = a->data() + _index;
+ n = a->size() - _index;
+ } else {
+ a = buf->next();
+ if ( !a || a->size() == 0 )
+ return FALSE;
+ p = a->data();
+ n = a->size();
+ }
+ if ( store ) {
+ while ( n-- > 0 ) {
+ *(store->data()+i) = *p;
+ if ( ++i == (int)store->size() )
+ store->resize( store->size() < 256
+ ? 1024 : store->size()*4 );
+ switch ( *p ) {
+ case '\0':
+ store->resize( i );
+ return FALSE;
+ case '\n':
+ *(store->data()+i) = '\0';
+ store->resize( i );
+ return TRUE;
+ }
+ p++;
+ }
+ } else {
+ while ( n-- > 0 ) {
+ switch ( *p++ ) {
+ case '\0':
+ return FALSE;
+ case '\n':
+ return TRUE;
+ }
+ }
+ }
+ }
+}
+
+int TQMembuf::ungetch( int ch )
+{
+ if ( buf->isEmpty() || _index==0 ) {
+ // we need a new TQByteArray
+ TQByteArray *ba = new TQByteArray( 1 );
+ buf->insert( 0, ba );
+ _size++;
+ ba->tqat( 0 ) = ch;
+ } else {
+ // we can reuse a place in the buffer
+ TQByteArray *ba = buf->first();
+ _index--;
+ _size++;
+ ba->tqat( _index ) = ch;
+ }
+ return ch;
+}
diff --git a/tqtinterface/qt4/src/kernel/tqinternal_p.h b/tqtinterface/qt4/src/kernel/tqinternal_p.h
new file mode 100644
index 0000000..08c5c8a
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqinternal_p.h
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Definition of some shared interal classes
+**
+** Created : 010427
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQINTERNAL_P_H
+#define TQINTERNAL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of a number of TQt sources files. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+#ifndef TQT_H
+#include "tqnamespace.h"
+#include "tqrect.h"
+#include "tqptrlist.h"
+#include "tqcstring.h"
+#include "tqiodevice.h"
+#endif // TQT_H
+
+class TQWidget;
+class TQPainter;
+class TQPixmap;
+
+class TQ_EXPORT TQSharedDoubleBuffer
+{
+public:
+ enum DoubleBufferFlags {
+ NoFlags = 0x00,
+ InitBG = 0x01,
+ Force = 0x02,
+ Default = InitBG | Force
+ };
+ typedef uint DBFlags;
+
+ TQSharedDoubleBuffer( DBFlags f = Default );
+ TQSharedDoubleBuffer( TQWidget* widget,
+ int x = 0, int y = 0, int w = -1, int h = -1,
+ DBFlags f = Default );
+ TQSharedDoubleBuffer( TQPainter* painter,
+ int x = 0, int y = 0, int w = -1, int h = -1,
+ DBFlags f = Default );
+ TQSharedDoubleBuffer( TQWidget *widget, const TQRect &r, DBFlags f = Default );
+ TQSharedDoubleBuffer( TQPainter *painter, const TQRect &r, DBFlags f = Default );
+ ~TQSharedDoubleBuffer();
+
+ bool begin( TQWidget* widget, int x = 0, int y = 0, int w = -1, int h = -1 );
+ bool begin( TQPainter* painter, int x = 0, int y = 0, int w = -1, int h = -1);
+ bool begin( TQWidget* widget, const TQRect &r );
+ bool begin( TQPainter* painter, const TQRect &r );
+ bool end();
+
+ TQPainter* painter() const;
+
+ bool isActive() const;
+ bool isBuffered() const;
+ void flush();
+
+ static bool isDisabled() { return !dblbufr; }
+ static void setDisabled( bool off ) { dblbufr = !off; }
+
+ static void cleanup();
+
+private:
+ enum DoubleBufferState {
+ Active = 0x0100,
+ BufferActive = 0x0200,
+ ExternalPainter = 0x0400
+ };
+ typedef uint DBState;
+
+ TQPixmap *getPixmap();
+ void releasePixmap();
+
+ TQWidget *wid;
+ int rx, ry, rw, rh;
+ DBFlags flags;
+ DBState state;
+
+ TQPainter *p, *external_p;
+ TQPixmap *pix;
+
+ static bool dblbufr;
+};
+
+inline bool TQSharedDoubleBuffer::begin( TQWidget* widget, const TQRect &r )
+{ return begin( widget, r.x(), r.y(), r.width(), r.height() ); }
+
+inline bool TQSharedDoubleBuffer::begin( TQPainter *painter, const TQRect &r )
+{ return begin( painter, r.x(), r.y(), r.width(), r.height() ); }
+
+inline TQPainter* TQSharedDoubleBuffer::painter() const
+{ return p; }
+
+inline bool TQSharedDoubleBuffer::isActive() const
+{ return ( state & Active ); }
+
+inline bool TQSharedDoubleBuffer::isBuffered() const
+{ return ( state & BufferActive ); }
+
+
+class TQVirtualDestructor {
+public:
+ virtual ~TQVirtualDestructor() {}
+};
+
+template <class T>
+class TQAutoDeleter : public TQVirtualDestructor {
+public:
+ TQAutoDeleter( T* p ) : ptr( p ) {}
+ ~TQAutoDeleter() { delete ptr; }
+ T* data() const { return ptr; }
+private:
+ T* ptr;
+};
+
+template <class T>
+T* qAutoDeleterData( TQAutoDeleter<T>* ad )
+{
+ if ( !ad )
+ return 0;
+ return ad->data();
+}
+
+template <class T>
+TQAutoDeleter<T>* qAutoDeleter( T* p )
+{
+ return new TQAutoDeleter<T>( p );
+}
+
+class TQ_EXPORT TQMembuf
+{
+public:
+ TQMembuf();
+ ~TQMembuf();
+
+ void append( TQByteArray *ba );
+ void clear();
+
+ bool consumeBytes( TQ_ULONG nbytes, char *sink );
+ TQByteArray readAll();
+ bool scanNewline( TQByteArray *store );
+ bool canReadLine() const;
+
+ int ungetch( int ch );
+
+ TQIODevice::Offset size() const;
+
+private:
+
+ TQPtrList<TQByteArray> *buf;
+ TQIODevice::Offset _size;
+ TQIODevice::Offset _index;
+};
+
+inline void TQMembuf::append( TQByteArray *ba )
+{ buf->append( ba ); _size += ba->size(); }
+
+inline void TQMembuf::clear()
+{ buf->clear(); _size=0; _index=0; }
+
+inline TQByteArray TQMembuf::readAll()
+{ TQByteArray ba(_size); consumeBytes(_size,ba.data()); return ba; }
+
+inline bool TQMembuf::canReadLine() const
+{ return ((TQMembuf*)this)->scanNewline( 0 ); }
+
+inline TQIODevice::Offset TQMembuf::size() const
+{ return _size; }
+
+#endif // TQINTERNAL_P_H
diff --git a/tqtinterface/qt4/src/kernel/tqjpegio.cpp b/tqtinterface/qt4/src/kernel/tqjpegio.cpp
new file mode 100644
index 0000000..20b7b17
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqjpegio.cpp
@@ -0,0 +1,599 @@
+/****************************************************************************
+**
+** Implementation of JPEG TQImage IOHandler
+**
+** Created : 990521
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQT_CLEAN_NAMESPACE
+#define TQT_CLEAN_NAMESPACE
+#endif
+
+#include "tqimage.h"
+
+#ifndef TQT_NO_IMAGEIO_JPEG
+
+#include "tqiodevice.h"
+#include "tqjpegio.h"
+
+#include <stdio.h> // jpeglib needs this to be pre-included
+#include <setjmp.h>
+
+
+// including jpeglib.h seems to be a little messy
+extern "C" {
+#define XMD_H // shut JPEGlib up
+#if defined(TQ_OS_UNIXWARE)
+# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this
+#endif
+#include <jpeglib.h>
+#ifdef const
+# undef const // remove crazy C hackery in jconfig.h
+#endif
+}
+
+
+struct my_error_mgr : public jpeg_error_mgr {
+ jmp_buf setjmp_buffer;
+};
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static
+void my_error_exit (j_common_ptr cinfo)
+{
+ my_error_mgr* myerr = (my_error_mgr*) cinfo->err;
+ char buffer[JMSG_LENGTH_MAX];
+ (*cinfo->err->format_message)(cinfo, buffer);
+ qWarning(buffer);
+ longjmp(myerr->setjmp_buffer, 1);
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+static const int max_buf = 4096;
+
+struct my_jpeg_source_mgr : public jpeg_source_mgr {
+ // Nothing dynamic - cannot rely on destruction over longjump
+ TQImageIO* iio;
+ JOCTET buffer[max_buf];
+
+public:
+ my_jpeg_source_mgr(TQImageIO* iio);
+};
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static
+void qt_init_source(j_decompress_ptr)
+{
+}
+
+static
+boolean qt_fill_input_buffer(j_decompress_ptr cinfo)
+{
+ int num_read;
+ my_jpeg_source_mgr* src = (my_jpeg_source_mgr*)cinfo->src;
+ TQIODevice* dev = src->iio->ioDevice();
+ src->next_input_byte = src->buffer;
+ num_read = dev->readBlock((char*)src->buffer, max_buf);
+ if ( num_read <= 0 ) {
+ // Insert a fake EOI marker - as per jpeglib recommendation
+ src->buffer[0] = (JOCTET) 0xFF;
+ src->buffer[1] = (JOCTET) JPEG_EOI;
+ src->bytes_in_buffer = 2;
+ } else {
+ src->bytes_in_buffer = num_read;
+ }
+#if defined(TQ_OS_UNIXWARE)
+ return B_TRUE;
+#else
+ return TRUE;
+#endif
+}
+
+static
+void qt_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
+{
+ my_jpeg_source_mgr* src = (my_jpeg_source_mgr*)cinfo->src;
+
+ // `dumb' implementation from jpeglib
+
+ /* Just a dumb implementation for now. Could use fseek() except
+ * it doesn't work on pipes. Not clear that being smart is worth
+ * any trouble anyway --- large skips are infrequent.
+ */
+ if (num_bytes > 0) {
+ while (num_bytes > (long) src->bytes_in_buffer) {
+ num_bytes -= (long) src->bytes_in_buffer;
+ (void) qt_fill_input_buffer(cinfo);
+ /* note we assume that qt_fill_input_buffer will never return FALSE,
+ * so suspension need not be handled.
+ */
+ }
+ src->next_input_byte += (size_t) num_bytes;
+ src->bytes_in_buffer -= (size_t) num_bytes;
+ }
+}
+
+static
+void qt_term_source(j_decompress_ptr)
+{
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+inline my_jpeg_source_mgr::my_jpeg_source_mgr(TQImageIO* iioptr)
+{
+ jpeg_source_mgr::init_source = qt_init_source;
+ jpeg_source_mgr::fill_input_buffer = qt_fill_input_buffer;
+ jpeg_source_mgr::skip_input_data = qt_skip_input_data;
+ jpeg_source_mgr::resync_to_restart = jpeg_resync_to_restart;
+ jpeg_source_mgr::term_source = qt_term_source;
+ iio = iioptr;
+ bytes_in_buffer = 0;
+ next_input_byte = buffer;
+}
+
+
+static
+void scaleSize( int &reqW, int &reqH, int imgW, int imgH, TQ_ScaleMode mode )
+{
+ if ( mode == TQ_ScaleFree )
+ return;
+ int t1 = imgW * reqH;
+ int t2 = reqW * imgH;
+ if (( mode == TQ_ScaleMin && (t1 > t2) ) || ( mode == TQ_ScaleMax && (t1 < t2) ))
+ reqH = t2 / imgW;
+ else
+ reqW = t1 / imgH;
+}
+
+
+static
+void read_jpeg_image(TQImageIO* iio)
+{
+ TQImage image;
+
+ struct jpeg_decompress_struct cinfo;
+
+ struct my_jpeg_source_mgr *iod_src = new my_jpeg_source_mgr(iio);
+ struct my_error_mgr jerr;
+
+ jpeg_create_decompress(&cinfo);
+
+ cinfo.src = iod_src;
+
+ cinfo.err = jpeg_std_error(&jerr);
+ jerr.error_exit = my_error_exit;
+
+ if (!setjmp(jerr.setjmp_buffer)) {
+#if defined(TQ_OS_UNIXWARE)
+ (void) jpeg_read_header(&cinfo, B_TRUE);
+#else
+ (void) jpeg_read_header(&cinfo, TRUE);
+#endif
+
+ (void) jpeg_start_decompress(&cinfo);
+
+ TQString params = iio->parameters();
+ params.simplifyWhiteSpace();
+ int sWidth = 0, sHeight = 0;
+ char sModeStr[1024] = "";
+ TQ_ScaleMode sMode;
+
+ if ( params.tqcontains( "GetHeaderInformation" ) ) {
+
+ // Create TQImage's without allocating the data
+ if ( cinfo.output_components == 3 || cinfo.output_components == 4) {
+ image = TQImage( NULL, cinfo.output_width, cinfo.output_height, 32, NULL, 0, TQImage::IgnoreEndian );
+ } else if ( cinfo.output_components == 1 ) {
+ image = TQImage( NULL, cinfo.output_width, cinfo.output_height, 8, NULL, 0, TQImage::IgnoreEndian );
+ } else {
+ // Unsupported format
+ }
+
+
+ } else if ( params.tqcontains( "Scale" ) ) {
+ sscanf( params.latin1(), "Scale( %i, %i, %1023s )",
+ &sWidth, &sHeight, sModeStr );
+
+ TQString sModeTQStr( sModeStr );
+ if ( sModeTQStr == "ScaleFree" ) {
+ sMode = TQ_ScaleFree;
+ } else if ( sModeTQStr == "ScaleMin" ) {
+ sMode = TQ_ScaleMin;
+ } else if ( sModeTQStr == "ScaleMax" ) {
+ sMode = TQ_ScaleMax;
+ } else {
+ qDebug("read_jpeg_image: invalid scale mode \"%s\", see TTQ_ScaleMode documentation", sModeStr);
+ sMode = TQ_ScaleFree;
+ }
+
+// qDebug( "Parameters ask to scale the image to %i x %i ScaleMode: %s", sWidth, sHeight, sModeStr );
+ scaleSize( sWidth, sHeight, cinfo.output_width, cinfo.output_height, sMode );
+// qDebug( "Scaling the jpeg to %i x %i", sWidth, sHeight, sModeStr );
+
+ bool created = FALSE;
+ if ( cinfo.output_components == 3 || cinfo.output_components == 4) {
+ created = image.create( sWidth, sHeight, 32 );
+ } else if ( cinfo.output_components == 1 ) {
+ created = image.create( sWidth, sHeight, 8, 256 );
+ for (int i=0; i<256; i++)
+ image.setColor(i, tqRgb(i,i,i));
+ } else {
+ // Unsupported format
+ }
+ if (!created)
+ image = TQImage();
+
+ if (!image.isNull()) {
+ TQImage tmpImage( cinfo.output_width, 1, 32 );
+ uchar** inLines = tmpImage.jumpTable();
+ uchar** outLines = image.jumpTable();
+ while (cinfo.output_scanline < cinfo.output_height) {
+ int outputLine = sHeight * cinfo.output_scanline / cinfo.output_height;
+ (void) jpeg_read_scanlines(&cinfo, inLines, 1);
+ if ( cinfo.output_components == 3 ) {
+ uchar *in = inLines[0];
+ TQRgb *out = (TQRgb*)outLines[outputLine];
+ for (uint i=0; i<cinfo.output_width; i++ ) {
+// ### Only scaling down an image works, I don't think scaling up will work at the moment
+// ### An idea I have to make this a smooth scale is to progressively add the pixel values up
+// When scaling down, multiple values are being over drawn in to the output buffer.
+// Instead, a weighting based on the distance the line or pixel is from the output pixel determines
+// the weight of it when added to the output buffer. At present it is a non-smooth scale which is
+// inefficently implemented, it still uncompresses all the jpeg, an optimization for progressive
+// jpegs could be made if scaling by say 50% or some other special cases
+ out[sWidth * i / cinfo.output_width] = tqRgb( in[0], in[1], in[2] );
+ in += 3;
+ }
+ } else {
+// ### Need to test the case where the jpeg is grayscale, need some black and white jpegs to test
+// this code. (also only scales down and probably won't scale to a larger size)
+ uchar *in = inLines[0];
+ uchar *out = outLines[outputLine];
+ for (uint i=0; i<cinfo.output_width; i++ ) {
+ out[sWidth * i / cinfo.output_width] = in[i];
+ }
+ }
+ }
+ (void) jpeg_finish_decompress(&cinfo);
+ }
+
+ } else {
+
+ bool created = FALSE;
+ if ( cinfo.output_components == 3 || cinfo.output_components == 4) {
+ created = image.create( cinfo.output_width, cinfo.output_height, 32 );
+ } else if ( cinfo.output_components == 1 ) {
+ created = image.create( cinfo.output_width, cinfo.output_height, 8, 256 );
+ for (int i=0; i<256; i++)
+ image.setColor(i, tqRgb(i,i,i));
+ } else {
+ // Unsupported format
+ }
+ if (!created)
+ image = TQImage();
+
+ if (!image.isNull()) {
+ uchar** lines = image.jumpTable();
+ while (cinfo.output_scanline < cinfo.output_height)
+ (void) jpeg_read_scanlines(&cinfo,
+ lines + cinfo.output_scanline,
+ cinfo.output_height);
+ (void) jpeg_finish_decompress(&cinfo);
+
+ if ( cinfo.output_components == 3 ) {
+ // Expand 24->32 bpp.
+ for (uint j=0; j<cinfo.output_height; j++) {
+ uchar *in = image.scanLine(j) + cinfo.output_width * 3;
+ TQRgb *out = (TQRgb*)image.scanLine(j);
+
+ for (uint i=cinfo.output_width; i--; ) {
+ in-=3;
+ out[i] = tqRgb(in[0], in[1], in[2]);
+ }
+ }
+ }
+ }
+ }
+
+ if (!image.isNull()) {
+ if ( cinfo.density_unit == 1 ) {
+ image.setDotsPerMeterX( int(100. * cinfo.X_density / 2.54) );
+ image.setDotsPerMeterY( int(100. * cinfo.Y_density / 2.54) );
+ } else if ( cinfo.density_unit == 2 ) {
+ image.setDotsPerMeterX( int(100. * cinfo.X_density) );
+ image.setDotsPerMeterY( int(100. * cinfo.Y_density) );
+ }
+ }
+
+ iio->setImage(image);
+ iio->setqStatus(image.isNull());
+ }
+
+ jpeg_destroy_decompress(&cinfo);
+ delete iod_src;
+}
+
+
+struct my_jpeg_destination_mgr : public jpeg_destination_mgr {
+ // Nothing dynamic - cannot rely on destruction over longjump
+ TQImageIO* iio;
+ JOCTET buffer[max_buf];
+
+public:
+ my_jpeg_destination_mgr(TQImageIO*);
+};
+
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static
+void qt_init_destination(j_compress_ptr)
+{
+}
+
+static
+void qt_exit_on_error(j_compress_ptr cinfo, TQIODevice* dev)
+{
+ if (dev->status() == IO_Ok) {
+ return;
+ } else {
+ // cinfo->err->msg_code = JERR_FILE_WRITE;
+ (*cinfo->err->error_exit)((j_common_ptr)cinfo);
+ }
+}
+
+static
+boolean qt_empty_output_buffer(j_compress_ptr cinfo)
+{
+ my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest;
+ TQIODevice* dev = dest->iio->ioDevice();
+
+ if ( dev->writeBlock( (char*)dest->buffer, max_buf ) != max_buf )
+ qt_exit_on_error(cinfo, dev);
+
+ dest->next_output_byte = dest->buffer;
+ dest->free_in_buffer = max_buf;
+
+#if defined(TQ_OS_UNIXWARE)
+ return B_TRUE;
+#else
+ return TRUE;
+#endif
+}
+
+static
+void qt_term_destination(j_compress_ptr cinfo)
+{
+ my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest;
+ TQIODevice* dev = dest->iio->ioDevice();
+ TQ_LONG n = max_buf - dest->free_in_buffer;
+
+ if ( dev->writeBlock( (char*)dest->buffer, n ) != n )
+ qt_exit_on_error(cinfo, dev);
+
+ dev->flush();
+
+ qt_exit_on_error(cinfo, dev);
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+inline
+my_jpeg_destination_mgr::my_jpeg_destination_mgr(TQImageIO* iioptr)
+{
+ jpeg_destination_mgr::init_destination = qt_init_destination;
+ jpeg_destination_mgr::empty_output_buffer = qt_empty_output_buffer;
+ jpeg_destination_mgr::term_destination = qt_term_destination;
+ iio = iioptr;
+ next_output_byte = buffer;
+ free_in_buffer = max_buf;
+}
+
+
+static
+void write_jpeg_image(TQImageIO* iio)
+{
+ TQImage image = iio->image();
+
+ struct jpeg_compress_struct cinfo;
+ JSAMPROW row_pointer[1];
+ row_pointer[0] = 0;
+
+ struct my_jpeg_destination_mgr *iod_dest = new my_jpeg_destination_mgr(iio);
+ struct my_error_mgr jerr;
+
+ cinfo.err = jpeg_std_error(&jerr);
+
+ jerr.error_exit = my_error_exit;
+
+ if (!setjmp(jerr.setjmp_buffer)) {
+ jpeg_create_compress(&cinfo);
+
+ cinfo.dest = iod_dest;
+
+ cinfo.image_width = image.width();
+ cinfo.image_height = image.height();
+
+ TQRgb* cmap=0;
+ bool gray=FALSE;
+ switch ( image.depth() ) {
+ case 1:
+ case 8:
+ cmap = image.tqcolorTable();
+ gray = TRUE;
+ int i;
+ for (i=image.numColors(); gray && i--; ) {
+ gray = gray & ( tqRed(cmap[i]) == tqGreen(cmap[i]) &&
+ tqRed(cmap[i]) == tqBlue(cmap[i]) );
+ }
+ cinfo.input_components = gray ? 1 : 3;
+ cinfo.in_color_space = gray ? JCS_GRAYSCALE : JCS_RGB;
+ break;
+ case 32:
+ cinfo.input_components = 3;
+ cinfo.in_color_space = JCS_RGB;
+ }
+
+ jpeg_set_defaults(&cinfo);
+
+ float diffInch = TQABS(image.dotsPerMeterX()*2.54/100. - tqRound(image.dotsPerMeterX()*2.54/100.))
+ + TQABS(image.dotsPerMeterY()*2.54/100. - tqRound(image.dotsPerMeterY()*2.54/100.));
+ float diffCm = (TQABS(image.dotsPerMeterX()/100. - tqRound(image.dotsPerMeterX()/100.))
+ + TQABS(image.dotsPerMeterY()/100. - tqRound(image.dotsPerMeterY()/100.)))*2.54;
+ if (diffInch < diffCm) {
+ cinfo.density_unit = 1; // dots/inch
+ cinfo.X_density = tqRound(image.dotsPerMeterX()*2.54/100.);
+ cinfo.Y_density = tqRound(image.dotsPerMeterY()*2.54/100.);
+ } else {
+ cinfo.density_unit = 2; // dots/cm
+ cinfo.X_density = (image.dotsPerMeterX()+50) / 100;
+ cinfo.Y_density = (image.dotsPerMeterY()+50) / 100;
+ }
+
+ int quality = iio->quality() >= 0 ? TQMIN(iio->quality(),100) : 75;
+#if defined(TQ_OS_UNIXWARE)
+ jpeg_set_quality(&cinfo, quality, B_TRUE /* limit to baseline-JPEG values */);
+ jpeg_start_compress(&cinfo, B_TRUE);
+#else
+ jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
+ jpeg_start_compress(&cinfo, TRUE);
+#endif
+
+ row_pointer[0] = new uchar[cinfo.image_width*cinfo.input_components];
+ int w = cinfo.image_width;
+ while (cinfo.next_scanline < cinfo.image_height) {
+ uchar *row = row_pointer[0];
+ switch ( image.depth() ) {
+ case 1:
+ if (gray) {
+ uchar* data = image.scanLine(cinfo.next_scanline);
+ if ( image.bitOrder() == TQImage::LittleEndian ) {
+ for (int i=0; i<w; i++) {
+ bool bit = !!(*(data + (i >> 3)) & (1 << (i & 7)));
+ row[i] = tqRed(cmap[bit]);
+ }
+ } else {
+ for (int i=0; i<w; i++) {
+ bool bit = !!(*(data + (i >> 3)) & (1 << (7 -(i & 7))));
+ row[i] = tqRed(cmap[bit]);
+ }
+ }
+ } else {
+ uchar* data = image.scanLine(cinfo.next_scanline);
+ if ( image.bitOrder() == TQImage::LittleEndian ) {
+ for (int i=0; i<w; i++) {
+ bool bit = !!(*(data + (i >> 3)) & (1 << (i & 7)));
+ *row++ = tqRed(cmap[bit]);
+ *row++ = tqGreen(cmap[bit]);
+ *row++ = tqBlue(cmap[bit]);
+ }
+ } else {
+ for (int i=0; i<w; i++) {
+ bool bit = !!(*(data + (i >> 3)) & (1 << (7 -(i & 7))));
+ *row++ = tqRed(cmap[bit]);
+ *row++ = tqGreen(cmap[bit]);
+ *row++ = tqBlue(cmap[bit]);
+ }
+ }
+ }
+ break;
+ case 8:
+ if (gray) {
+ uchar* pix = image.scanLine(cinfo.next_scanline);
+ for (int i=0; i<w; i++) {
+ *row = tqRed(cmap[*pix]);
+ ++row; ++pix;
+ }
+ } else {
+ uchar* pix = image.scanLine(cinfo.next_scanline);
+ for (int i=0; i<w; i++) {
+ *row++ = tqRed(cmap[*pix]);
+ *row++ = tqGreen(cmap[*pix]);
+ *row++ = tqBlue(cmap[*pix]);
+ ++pix;
+ }
+ }
+ break;
+ case 32: {
+ TQRgb* rgb = (TQRgb*)image.scanLine(cinfo.next_scanline);
+ for (int i=0; i<w; i++) {
+ *row++ = tqRed(*rgb);
+ *row++ = tqGreen(*rgb);
+ *row++ = tqBlue(*rgb);
+ ++rgb;
+ }
+ }
+ }
+ jpeg_write_scanlines(&cinfo, row_pointer, 1);
+ }
+
+ jpeg_finish_compress(&cinfo);
+ jpeg_destroy_compress(&cinfo);
+
+ iio->setqStatus(0);
+ }
+
+ delete iod_dest;
+ delete [] row_pointer[0];
+}
+
+void qInitJpegIO()
+{
+ // Not much to go on - just 3 bytes: 0xFF, M_SOI, 0xFF
+ // Even the third is not strictly specified as required.
+ TQImageIO::defineIOHandler("JPEG", "^\377\330\377", 0, read_jpeg_image, write_jpeg_image);
+}
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqjpegio.h b/tqtinterface/qt4/src/kernel/tqjpegio.h
new file mode 100644
index 0000000..c27c4fb
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqjpegio.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Definition of JPEG TQImage IOHandler
+**
+** Created : 970621
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQJPEGIO_H
+#define TQJPEGIO_H
+
+#include "tqglobal.h"
+
+#ifndef TQT_NO_IMAGEIO_JPEG
+
+void qInitJpegIO();
+
+#endif // TQT_NO_IMAGEIO_JPEG
+
+#endif // TQJPEGIO_H
diff --git a/tqtinterface/qt4/src/kernel/tqkeycode.h b/tqtinterface/qt4/src/kernel/tqkeycode.h
new file mode 100644
index 0000000..1d376e1
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqkeycode.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Definition of keyboard codes
+**
+** Created : 931030
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQKEYCODE_H
+#define TQKEYCODE_H
+
+#ifndef TQT_H
+#include "tqnamespace.h"
+#endif // TQT_H
+
+// all key codes are now in the TQt namespace class
+
+#endif // TQKEYCODE_H
diff --git a/tqtinterface/qt4/src/kernel/tqkeysequence.cpp b/tqtinterface/qt4/src/kernel/tqkeysequence.cpp
new file mode 100644
index 0000000..f34f697
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqkeysequence.cpp
@@ -0,0 +1,731 @@
+/****************************************************************************
+**
+** Implementation of TQKeySequence class
+**
+** Created : 0108007
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqkeysequence.h"
+
+#ifndef TQT_NO_ACCEL
+
+#include "tqaccel.h"
+#include "tqshared.h"
+#include "tqvaluelist.h"
+#ifndef TQT_NO_REGEXP
+# include "tqregexp.h"
+#endif
+
+#ifdef TQ_WS_MAC
+#define TQMAC_CTRL (TQString(TQChar(0x2318)))
+#define TQMAC_META (TQString(TQChar(0x2303)))
+#define TQMAC_ALT (TQString(TQChar(0x2325)))
+#define TQMAC_SHIFT (TQString(TQChar(0x21E7)))
+#endif
+
+/*!
+ \class TQKeySequence tqkeysequence.h
+ \brief The TQKeySequence class encapsulates a key sequence as used
+ by accelerators.
+
+ \ingroup misc
+
+ A key sequence consists of up to four keyboard codes, each
+ optionally combined with modifiers, e.g. \c SHIFT, \c CTRL, \c
+ ALT, \c META, or \c UNICODE_ACCEL. For example, \c{CTRL + Key_P}
+ might be a sequence used as a shortcut for printing a document.
+ The key codes are listed in \c{tqnamespace.h}. As an alternative,
+ use \c UNICODE_ACCEL with the tqunicode code point of the character.
+ For example, \c{UNICODE_ACCEL + 'A'} gives the same key sequence
+ as \c Key_A.
+
+ Key sequences can be constructed either from an integer key code,
+ or from a human readable translatable string such as
+ "Ctrl+X,Alt+Space". A key sequence can be cast to a TQString to
+ obtain a human readable translated version of the sequence.
+ Translations are done in the "TQAccel" context.
+
+ \sa TQAccel
+*/
+
+/*!
+ \enum TQt::SequenceMatch
+
+ \value NoMatch Sequences have nothing in common
+ \value PartialMatch Sequences match partially, but are not complete
+ \value Identical Sequences do not differ
+*/
+
+static struct {
+ int key;
+ const char* name;
+} keyname[] = {
+ { TQt::Key_Space, TQT_TRANSLATE_NOOP( "TQAccel", "Space" ) },
+ { TQt::Key_Escape, TQT_TRANSLATE_NOOP( "TQAccel", "Esc" ) },
+ { TQt::Key_Tab, TQT_TRANSLATE_NOOP( "TQAccel", "Tab" ) },
+ { TQt::Key_Backtab, TQT_TRANSLATE_NOOP( "TQAccel", "Backtab" ) },
+ { TQt::Key_Backspace, TQT_TRANSLATE_NOOP( "TQAccel", "Backspace" ) },
+ { TQt::Key_Return, TQT_TRANSLATE_NOOP( "TQAccel", "Return" ) },
+ { TQt::Key_Enter, TQT_TRANSLATE_NOOP( "TQAccel", "Enter" ) },
+ { TQt::Key_Insert, TQT_TRANSLATE_NOOP( "TQAccel", "Ins" ) },
+ { TQt::Key_Delete, TQT_TRANSLATE_NOOP( "TQAccel", "Del" ) },
+ { TQt::Key_Pause, TQT_TRANSLATE_NOOP( "TQAccel", "Pause" ) },
+ { TQt::Key_Print, TQT_TRANSLATE_NOOP( "TQAccel", "Print" ) },
+ { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( "TQAccel", "SysReq" ) },
+ { TQt::Key_Home, TQT_TRANSLATE_NOOP( "TQAccel", "Home" ) },
+ { TQt::Key_End, TQT_TRANSLATE_NOOP( "TQAccel", "End" ) },
+ { TQt::Key_Left, TQT_TRANSLATE_NOOP( "TQAccel", "Left" ) },
+ { TQt::Key_Up, TQT_TRANSLATE_NOOP( "TQAccel", "Up" ) },
+ { TQt::Key_Right, TQT_TRANSLATE_NOOP( "TQAccel", "Right" ) },
+ { TQt::Key_Down, TQT_TRANSLATE_NOOP( "TQAccel", "Down" ) },
+ { TQt::Key_Prior, TQT_TRANSLATE_NOOP( "TQAccel", "PgUp" ) },
+ { TQt::Key_Next, TQT_TRANSLATE_NOOP( "TQAccel", "PgDown" ) },
+ { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( "TQAccel", "CapsLock" ) },
+ { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "NumLock" ) },
+ { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( "TQAccel", "ScrollLock" ) },
+ { TQt::Key_Menu, TQT_TRANSLATE_NOOP( "TQAccel", "Menu" ) },
+ { TQt::Key_Help, TQT_TRANSLATE_NOOP( "TQAccel", "Help" ) },
+
+ // Multimedia keys
+ { TQt::Key_Back, TQT_TRANSLATE_NOOP( "TQAccel", "Back" ) },
+ { TQt::Key_Forward, TQT_TRANSLATE_NOOP( "TQAccel", "Forward" ) },
+ { TQt::Key_Stop, TQT_TRANSLATE_NOOP( "TQAccel", "Stop" ) },
+ { TQt::Key_Refresh, TQT_TRANSLATE_NOOP( "TQAccel", "Refresh" ) },
+ { TQt::Key_VolumeDown, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Down" ) },
+ { TQt::Key_VolumeMute, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Mute" ) },
+ { TQt::Key_VolumeUp, TQT_TRANSLATE_NOOP( "TQAccel", "Volume Up" ) },
+ { TQt::Key_BassBoost, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Boost" ) },
+ { TQt::Key_BassUp, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Up" ) },
+ { TQt::Key_BassDown, TQT_TRANSLATE_NOOP( "TQAccel", "Bass Down" ) },
+ { TQt::Key_TrebleUp, TQT_TRANSLATE_NOOP( "TQAccel", "Treble Up" ) },
+ { TQt::Key_TrebleDown, TQT_TRANSLATE_NOOP( "TQAccel", "Treble Down" ) },
+ { TQt::Key_MediaPlay, TQT_TRANSLATE_NOOP( "TQAccel", "Media Play" ) },
+ { TQt::Key_MediaStop, TQT_TRANSLATE_NOOP( "TQAccel", "Media Stop" ) },
+ { TQt::Key_MediaPrev, TQT_TRANSLATE_NOOP( "TQAccel", "Media Previous" ) },
+ { TQt::Key_MediaNext, TQT_TRANSLATE_NOOP( "TQAccel", "Media Next" ) },
+ { TQt::Key_MediaRecord, TQT_TRANSLATE_NOOP( "TQAccel", "Media Record" ) },
+ { TQt::Key_HomePage, TQT_TRANSLATE_NOOP( "TQAccel", "Home" ) },
+ { TQt::Key_Favorites, TQT_TRANSLATE_NOOP( "TQAccel", "Favorites" ) },
+ { TQt::Key_Search, TQT_TRANSLATE_NOOP( "TQAccel", "Search" ) },
+ { TQt::Key_Standby, TQT_TRANSLATE_NOOP( "TQAccel", "Standby" ) },
+ { TQt::Key_OpenUrl, TQT_TRANSLATE_NOOP( "TQAccel", "Open URL" ) },
+ { TQt::Key_LaunchMail, TQT_TRANSLATE_NOOP( "TQAccel", "Launch Mail" ) },
+ { TQt::Key_LaunchMedia, TQT_TRANSLATE_NOOP( "TQAccel", "Launch Media" ) },
+ { TQt::Key_Launch0, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (0)" ) },
+ { TQt::Key_Launch1, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (1)" ) },
+ { TQt::Key_Launch2, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (2)" ) },
+ { TQt::Key_Launch3, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (3)" ) },
+ { TQt::Key_Launch4, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (4)" ) },
+ { TQt::Key_Launch5, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (5)" ) },
+ { TQt::Key_Launch6, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (6)" ) },
+ { TQt::Key_Launch7, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (7)" ) },
+ { TQt::Key_Launch8, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (8)" ) },
+ { TQt::Key_Launch9, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (9)" ) },
+ { TQt::Key_LaunchA, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (A)" ) },
+ { TQt::Key_LaunchB, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (B)" ) },
+ { TQt::Key_LaunchC, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (C)" ) },
+ { TQt::Key_LaunchD, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (D)" ) },
+ { TQt::Key_LaunchE, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (E)" ) },
+ { TQt::Key_LaunchF, TQT_TRANSLATE_NOOP( "TQAccel", "Launch (F)" ) },
+
+ // --------------------------------------------------------------
+ // More consistent namings
+ { TQt::Key_Print, TQT_TRANSLATE_NOOP( "TQAccel", "Print Screen" ) },
+ { TQt::Key_Prior, TQT_TRANSLATE_NOOP( "TQAccel", "Page Up" ) },
+ { TQt::Key_Next, TQT_TRANSLATE_NOOP( "TQAccel", "Page Down" ) },
+ { TQt::Key_CapsLock, TQT_TRANSLATE_NOOP( "TQAccel", "Caps Lock" ) },
+ { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "Num Lock" ) },
+ { TQt::Key_NumLock, TQT_TRANSLATE_NOOP( "TQAccel", "Number Lock" ) },
+ { TQt::Key_ScrollLock, TQT_TRANSLATE_NOOP( "TQAccel", "Scroll Lock" ) },
+ { TQt::Key_Insert, TQT_TRANSLATE_NOOP( "TQAccel", "Insert" ) },
+ { TQt::Key_Delete, TQT_TRANSLATE_NOOP( "TQAccel", "Delete" ) },
+ { TQt::Key_Escape, TQT_TRANSLATE_NOOP( "TQAccel", "Escape" ) },
+ { TQt::Key_SysReq, TQT_TRANSLATE_NOOP( "TQAccel", "System Request" ) },
+
+ { 0, 0 }
+};
+
+
+class TQKeySequencePrivate : public TQShared
+{
+public:
+ inline TQKeySequencePrivate()
+ {
+ key[0] = key[1] = key[2] = key[3] = 0;
+ }
+ inline TQKeySequencePrivate( TQKeySequencePrivate *copy )
+ {
+ key[0] = copy->key[0];
+ key[1] = copy->key[1];
+ key[2] = copy->key[2];
+ key[3] = copy->key[3];
+ }
+ int key[4];
+};
+
+
+/*!
+ Constructs an empty key sequence.
+*/
+TQKeySequence::TQKeySequence()
+{
+ d = new TQKeySequencePrivate();
+ TQ_CHECK_PTR( d );
+}
+
+/*!
+ Creates a key sequence from the string \a key. For example
+ "Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl",
+ "Shift", "Alt" and "Meta" are recognized, as well as their
+ translated equivalents in the "TQAccel" context (using
+ TQObject::tr()).
+
+ Multiple key codes (up to four) may be entered by separating them
+ with commas, e.g. "Alt+X,Ctrl+S,Q".
+
+ This contructor is typically used with \link TQObject::tr() tr
+ \endlink(), so that accelerator keys can be tqreplaced in
+ translations:
+
+ \code
+ TQPopupMenu *file = new TQPopupMenu( this );
+ file->insertItem( tr("&Open..."), this, TQT_SLOT(open()),
+ TQKeySequence( tr("Ctrl+O", "File|Open") ) );
+ \endcode
+
+ Note the \c "File|Open" translator comment. It is by no means
+ necessary, but it provides some context for the human translator.
+*/
+TQKeySequence::TQKeySequence( const TQString& key )
+{
+ d = new TQKeySequencePrivate();
+ TQ_CHECK_PTR( d );
+ assign( key );
+}
+
+
+// ### BCI: Merge with constructor below for 4.0
+/*!
+ Constructs a key sequence that has a single \a key.
+
+ The key codes are listed in \c{tqnamespace.h} and can be
+ combined with modifiers, e.g. with \c SHIFT, \c CTRL, \c
+ ALT, \c META or \c UNICODE_ACCEL.
+*/
+TQKeySequence::TQKeySequence( int key )
+{
+ d = new TQKeySequencePrivate();
+ TQ_CHECK_PTR( d );
+ d->key[0] = key;
+}
+
+/*!
+ Constructs a key sequence with up to 4 keys \a k1, \a k2,
+ \a k3 and \a k4.
+
+ The key codes are listed in \c{tqnamespace.h} and can be
+ combined with modifiers, e.g. with \c SHIFT, \c CTRL, \c
+ ALT, \c META or \c UNICODE_ACCEL.
+*/
+TQKeySequence::TQKeySequence( int k1, int k2, int k3, int k4 )
+{
+ d = new TQKeySequencePrivate();
+ TQ_CHECK_PTR( d );
+ d->key[0] = k1;
+ d->key[1] = k2;
+ d->key[2] = k3;
+ d->key[3] = k4;
+}
+
+/*!
+ Copy constructor. Makes a copy of \a keysequence.
+ */
+TQKeySequence::TQKeySequence( const TQKeySequence& keysequence )
+ : d( keysequence.d )
+{
+ d->ref();
+}
+
+
+/*!
+ Destroys the key sequence.
+ */
+TQKeySequence::~TQKeySequence()
+{
+ if ( d->deref() )
+ delete d;
+}
+
+/*!
+ \internal
+ KeySequences should never be modified, but rather just created.
+ Internally though we do need to modify to keep pace in event
+ delivery.
+*/
+
+void TQKeySequence::setKey( int key, int index )
+{
+#ifdef TQT_CHECK_STATE
+ if ( 0 > index && 4 < index ) {
+ qWarning( "TQKeySequence::setKey: index %u out of range", index );
+ return;
+ }
+#endif // TQT_CHECK_STATE
+
+ if ( 1 < d->count ) {
+ TQKeySequencePrivate *newd = new TQKeySequencePrivate( d );
+ d->deref();
+ d = newd;
+ }
+ d->key[index] = key;
+}
+
+/*!
+ Returns the number of keys in the key sequence.
+ The maximum is 4.
+ */
+uint TQKeySequence::count() const
+{
+ if ( ! d->key[0] )
+ return 0;
+ if ( ! d->key[1] )
+ return 1;
+ if ( ! d->key[2] )
+ return 2;
+ if ( ! d->key[3] )
+ return 3;
+ return 4;
+}
+
+
+/*!
+ Returns TRUE if the key sequence is empty; otherwise returns
+ FALSE.
+*/
+bool TQKeySequence::isEmpty() const
+{
+ return !d->key[0];
+}
+
+
+/*!
+ Adds the string \a keyseq to the key sequence. \a keyseq may
+ contain up to four key codes, provided they are seperated by a
+ comma, e.g. "Alt+X,Ctrl+S,Z"). Returns the number of key codes
+ added.
+*/
+int TQKeySequence::assign( TQString keyseq )
+{
+ TQString part;
+ int n = 0;
+ int p = 0, diff = 0;
+
+ // Run through the whole string, but stop
+ // if we have 4 keys before the end.
+ while ( keyseq.length() && n < 4 ) {
+ // We MUST use something to seperate each sequence, and space
+ // does not cut it, since some of the key names have space
+ // in them.. (Let's hope no one translate with a comma in it:)
+ p = keyseq.tqfind( ',' );
+ if ( -1 != p ) {
+ if ( ',' == keyseq[p+1] ) // e.g. 'Ctrl+,, Shift+,,'
+ p++;
+ if ( ' ' == keyseq[p+1] ) { // Space after comma
+ diff = 1;
+ p++;
+ } else if ( '\0' == keyseq[p+1] ) { // Last comma 'Ctrl+,'
+ p = -1;
+ } else {
+ diff = 0;
+ }
+ }
+ part = keyseq.left( -1==p?keyseq.length():p-diff );
+ keyseq = keyseq.right( -1==p?0:keyseq.length() - ( p + 1 ) );
+ d->key[n] = decodeString( part );
+ n++;
+ }
+ return n;
+}
+
+struct ModifKeyName {
+ ModifKeyName() { }
+ ModifKeyName(int q, TQString n) : qt_key(q), name(n) { }
+ int qt_key;
+ TQString name;
+};
+
+/*!
+ Constructs a single key from the string \str.
+ */
+int TQKeySequence::decodeString( const TQString& str )
+{
+ int ret = 0;
+ TQString accel = str;
+
+ TQValueList<ModifKeyName> modifs;
+#ifdef TQMAC_CTRL
+ modifs << ModifKeyName( CTRL, TQMAC_CTRL );
+#endif
+#ifdef TQMAC_ALT
+ modifs << ModifKeyName( ALT, TQMAC_ALT );
+#endif
+#ifdef TQMAC_META
+ modifs << ModifKeyName( META, TQMAC_META );
+#endif
+#ifdef TQMAC_SHIFT
+ modifs << ModifKeyName( SHIFT, TQMAC_SHIFT );
+#endif
+ modifs << ModifKeyName( CTRL, "ctrl+" ) << ModifKeyName( CTRL, TQAccel::tqtr("Ctrl").lower().append('+') );
+ modifs << ModifKeyName( SHIFT, "shift+" ) << ModifKeyName( SHIFT, TQAccel::tqtr("Shift").lower().append('+') );
+ modifs << ModifKeyName( ALT, "alt+" ) << ModifKeyName( ALT, TQAccel::tqtr("Alt").lower().append('+') );
+ modifs << ModifKeyName( META, "meta+" ) << ModifKeyName( ALT, TQAccel::tqtr("Meta").lower().append('+') );
+ TQString sl = accel.lower();
+ for( TQValueList<ModifKeyName>::iterator it = modifs.begin(); it != modifs.end(); ++it ) {
+ if ( sl.tqcontains( (*it).name ) ) {
+ ret |= (*it).qt_key;
+#ifndef TQT_NO_REGEXP
+ accel.remove( TQRegExp(TQRegExp::escape((*it).name), FALSE) );
+#else
+ accel.remove( (*it).name );
+#endif
+ sl = accel.lower();
+ }
+ }
+
+ int p = accel.tqfindRev( '+', str.length() - 2 ); // -2 so that Ctrl++ works
+ if( p > 0 )
+ accel = accel.mid( p + 1 );
+
+ int fnum = 0;
+ if ( accel.length() == 1 ) {
+ char ltr = TQChar(accel[0]).upper().latin1();
+ // We can only upper A-Z without problems.
+ if ( ltr < (char)Key_A || ltr > (char)Key_Z )
+ ret |= TQChar(accel[0]).tqunicode();
+ else
+ ret |= TQChar(accel[0]).upper().tqunicode();
+ ret |= UNICODE_ACCEL;
+ } else if ( accel[0] == 'F' && (fnum = accel.mid(1).toInt()) && (fnum >= 1) && (fnum <= 35) ) {
+ ret |= Key_F1 + fnum - 1;
+ } else {
+ // Check through translation table for the correct key name
+ // ...or fall back on english table.
+ bool found = FALSE;
+ for ( int tran = 0; tran < 2; tran++ ) {
+ for ( int i = 0; keyname[i].name; i++ ) {
+ if ( tran ? accel == TQAccel::tr(keyname[i].name)
+ : accel == keyname[i].name ) {
+ ret |= keyname[i].key;
+ found = TRUE;
+ break;
+ }
+ }
+ if(found)
+ break;
+ }
+ }
+ return ret;
+}
+
+
+/*!
+ Creates an accelerator string for \a key. For example,
+ CTRL+Key_O gives "Ctrl+O". The strings, "Ctrl", "Shift", etc. are
+ translated (using TQObject::tr()) in the "TQAccel" context.
+ */
+TQString TQKeySequence::encodeString( int key )
+{
+ TQString s;
+#if defined(TQ_OS_MAC) && !defined(TQWS)
+ // On MAC the order is Meta, Alt, Shift, Control.
+ if ( (key & META) == META )
+ s += TQMAC_META;
+ if ( (key & ALT) == ALT )
+ s += TQMAC_ALT;
+ if ( (key & SHIFT) == SHIFT )
+ s += TQMAC_SHIFT;
+ if ( (key & CTRL) == CTRL )
+ s += TQMAC_CTRL;
+#else
+ // On other systems the order is Meta, Control, Alt, Shift
+ if ( (key & META) == META )
+ s += TQAccel::tqtr( "Meta" );
+ if ( (key & CTRL) == CTRL ) {
+ if ( !s.isEmpty() )
+ s += TQAccel::tqtr( "+" );
+ s += TQAccel::tqtr( "Ctrl" );
+ }
+ if ( (key & ALT) == ALT ) {
+ if ( !s.isEmpty() )
+ s += TQAccel::tqtr( "+" );
+ s += TQAccel::tqtr( "Alt" );
+ }
+ if ( (key & SHIFT) == SHIFT ) {
+ if ( !s.isEmpty() )
+ s += TQAccel::tqtr( "+" );
+ s += TQAccel::tqtr( "Shift" );
+ }
+#endif
+
+
+ key &= ~(SHIFT | CTRL | ALT | META );
+ TQString p;
+
+ if ( (key & UNICODE_ACCEL) == UNICODE_ACCEL ) {
+ // Note: This character should NOT be upper()'ed, since
+ // the encoded string should indicate EXACTLY what the
+ // key represents! Hence a 'Ctrl+Shift+c' is posible to
+ // represent, but is clearly impossible to trigger...
+ p = TQChar(key & 0xffff);
+ } else if ( key >= Key_F1 && key <= Key_F35 ) {
+ p = TQAccel::tqtr( "F%1" ).arg(key - Key_F1 + 1);
+ } else if ( key > Key_Space && key <= Key_AsciiTilde ) {
+ p.sprintf( "%c", key );
+ } else {
+ int i=0;
+ while (keyname[i].name) {
+ if ( key == keyname[i].key ) {
+ p = TQAccel::tqtr(keyname[i].name);
+ break;
+ }
+ ++i;
+ }
+ // If we can't tqfind the actual translatable keyname,
+ // fall back on the tqunicode representation of it...
+ // Or else characters like Key_aring may not get displayed
+ // ( Really depends on you locale )
+ if ( !keyname[i].name )
+ // Note: This character should NOT be upper()'ed, see above!
+ p = TQChar(key & 0xffff);
+ }
+
+#ifndef TQ_OS_MAC
+ if ( !s.isEmpty() )
+ s += TQAccel::tqtr( "+" );
+#endif
+
+ s += p;
+ return s;
+}
+
+/*!
+ Matches the sequence with \a seq. Returns \c TQt::Identical if
+ successful, \c TQt::PartialMatch for matching but incomplete \a seq,
+ and \c TQt::NoMatch if the sequences have nothing in common.
+ Returns \c TQt::NoMatch if \a seq is shorter.
+*/
+TQt::SequenceMatch TQKeySequence::matches( const TQKeySequence& seq ) const
+{
+ uint userN = count(),
+ seqN = seq.count();
+
+ if ( userN > seqN )
+ return NoMatch;
+
+ // If equal in length, we have a potential Identical sequence,
+ // else we already know it can only be partial.
+ SequenceMatch match = ( userN == seqN ? Identical : PartialMatch );
+
+ for ( uint i = 0; i < userN; i++ ) {
+ int userKey = (*this)[i],
+ sequenceKey = seq[i];
+
+ if ( (userKey & ~TQt::UNICODE_ACCEL) !=
+ (sequenceKey & ~TQt::UNICODE_ACCEL) )
+ return NoMatch;
+ }
+ return match;
+}
+
+
+/*!
+ Creates an accelerator string for the key sequence.
+ For instance CTRL+Key_O gives "Ctrl+O". If the key sequence has
+ multiple key codes they are returned comma-separated, e.g.
+ "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are
+ translated (using TQObject::tr()) in the "TQAccel" scope. If the key
+ sequence has no keys, TQString::null is returned.
+
+ On Mac OS X, the string returned resembles the sequence that is shown in
+ the menubar.
+*/
+TQKeySequence::operator TQString() const
+{
+ int end = count();
+ if ( !end ) return TQString::null;
+
+ TQString complete;
+ int i = 0;
+ while ( i < end ) {
+ complete += encodeString( d->key[i] );
+ i++;
+ if ( i != end)
+ complete += ", ";
+ }
+ return complete;
+}
+
+
+/*!
+ \obsolete
+ For backward compatibility: returns the first keycode
+ as integer. If the key sequence is empty, 0 is returned.
+ */
+TQKeySequence::operator int () const
+{
+ if ( 1 <= count() )
+ return d->key[0];
+ return 0;
+}
+
+
+/*!
+ Returns a reference to the element at position \a index in the key
+ sequence. This can only be used to read an element.
+ */
+int TQKeySequence::operator[]( uint index ) const
+{
+#ifdef TQT_CHECK_STATE
+ if ( index > 4 ) {
+ qWarning( "TQKeySequence::operator[]: index %u out of range", index );
+ return 0;
+ }
+#endif // TQT_CHECK_STATE
+ return d->key[index];
+}
+
+
+/*!
+ Assignment operator. Assigns \a keysequence to this
+ object.
+ */
+TQKeySequence &TQKeySequence::operator=( const TQKeySequence & keysequence )
+{
+ keysequence.d->ref();
+ if ( d->deref() )
+ delete d;
+ d = keysequence.d;
+ return *this;
+}
+
+
+/*!
+ Returns TRUE if \a keysequence is equal to this key
+ sequence; otherwise returns FALSE.
+ */
+
+
+bool TQKeySequence::operator==( const TQKeySequence& keysequence ) const
+{
+ return ( (d->key[0]&~UNICODE_ACCEL) == (keysequence.d->key[0]&~UNICODE_ACCEL) &&
+ (d->key[1]&~UNICODE_ACCEL) == (keysequence.d->key[1]&~UNICODE_ACCEL) &&
+ (d->key[2]&~UNICODE_ACCEL) == (keysequence.d->key[2]&~UNICODE_ACCEL) &&
+ (d->key[3]&~UNICODE_ACCEL) == (keysequence.d->key[3]&~UNICODE_ACCEL) );
+}
+
+
+/*!
+ Returns TRUE if \a keysequence is not equal to this key sequence;
+ otherwise returns FALSE.
+*/
+bool TQKeySequence::operator!= ( const TQKeySequence& keysequence ) const
+{
+ TQKeySequence *that = (TQKeySequence*)this;
+ return !( (*that) == keysequence );
+}
+
+
+/*****************************************************************************
+ TQKeySequence stream functions
+ *****************************************************************************/
+#if !defined(TQT_NO_DATASTREAM) && !defined(TQT_NO_IMAGEIO)
+/*!
+ \relates TQKeySequence
+
+ Writes the key sequence \a keysequence to the stream \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+TQDataStream &operator<<( TQDataStream &s, const TQKeySequence &keysequence )
+{
+ TQValueList<int> list;
+ list += keysequence.d->key[0];
+ list += keysequence.d->key[1];
+ list += keysequence.d->key[2];
+ list += keysequence.d->key[3];
+ s << list;
+
+ return s;
+}
+
+
+/*!
+ \relates TQKeySequence
+
+ Reads a key sequence from the stream \a s into the key sequence \a
+ keysequence.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+TQDataStream &operator>>( TQDataStream &s, TQKeySequence &keysequence )
+{
+ TQValueList<int> list;
+ s >> list;
+
+#ifdef TQT_CHECK_STATE
+ if ( 1 != list.count() && 4 != list.count() ) {
+ qWarning( "Invalid TQKeySequence data in the datastream." );
+ return s;
+ }
+#endif
+
+ if ( 1 == list.count() ) {
+ keysequence.d->key[0] = *list.at( 0 );
+ keysequence.d->key[1] =
+ keysequence.d->key[2] =
+ keysequence.d->key[3] = 0;
+ } else {
+ keysequence.d->key[0] = *list.at( 0 );
+ keysequence.d->key[1] = *list.at( 1 );
+ keysequence.d->key[2] = *list.at( 2 );
+ keysequence.d->key[3] = *list.at( 3 );
+ }
+ return s;
+}
+
+#endif //TQT_NO_DATASTREAM
+
+#endif //TQT_NO_ACCEL
diff --git a/tqtinterface/qt4/src/kernel/tqkeysequence.h b/tqtinterface/qt4/src/kernel/tqkeysequence.h
new file mode 100644
index 0000000..a1274ac
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqkeysequence.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Definition of TQKeySequence class
+**
+** Created : 0108007
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQKEYSETQUENCE_H
+#define TQKEYSETQUENCE_H
+
+#ifndef TQT_H
+#ifndef TQT_H
+#include "tqnamespace.h"
+#include "tqstring.h"
+#endif // TQT_H
+#endif
+
+#ifndef TQT_NO_ACCEL
+
+/*****************************************************************************
+ TQKeySequence stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+class TQKeySequence;
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQKeySequence & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQKeySequence & );
+#endif
+
+class TQKeySequencePrivate;
+
+class TQ_EXPORT TQKeySequence : public TQt
+{
+public:
+ TQKeySequence();
+ TQKeySequence( const TQString& key );
+ TQKeySequence( int key );
+ TQKeySequence( int k1, int k2, int k3 = 0, int k4 = 0 );
+ TQKeySequence( const TQKeySequence & );
+ ~TQKeySequence();
+
+ uint count() const;
+ bool isEmpty() const;
+ TQt::SequenceMatch matches( const TQKeySequence & ) const;
+
+ operator TQString() const;
+ operator int () const;
+ int operator[]( uint ) const;
+ TQKeySequence &operator=( const TQKeySequence & );
+ bool operator==( const TQKeySequence& ) const;
+ bool operator!= ( const TQKeySequence& ) const;
+
+private:
+ static int decodeString( const TQString & );
+ static TQString encodeString( int );
+ int assign( TQString );
+ void setKey( int key, int index );
+
+ TQKeySequencePrivate* d;
+
+ friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQKeySequence & );
+ friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQKeySequence & );
+ friend class TQAccelManager;
+};
+
+#else
+
+class TQ_EXPORT TQKeySequence : public TQt
+{
+public:
+ TQKeySequence() {}
+ TQKeySequence( int ) {}
+};
+
+#endif //TQT_NO_ACCEL
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqlayout.cpp b/tqtinterface/qt4/src/kernel/tqlayout.cpp
new file mode 100644
index 0000000..e9f5493
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlayout.cpp
@@ -0,0 +1,4056 @@
+/****************************************************************************
+**
+** Implementation of tqlayout classes
+**
+** Created : 960416
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqlayout.h"
+
+#ifndef TQT_NO_LAYOUT
+
+#include "tqapplication.h"
+#include "tqwidget.h"
+#include "tqmenubar.h"
+#include "tqptrlist.h"
+#include "tqsizepolicy.h"
+
+#include "tqlayoutengine_p.h"
+
+#ifdef USE_QT4
+
+int menuBarHeightForWidth( QWidget *menubar_w, int w )
+{
+#ifndef TQT_NO_MENUBAR
+ TQMenuBar *menubar = static_cast<TQMenuBar*>(TQT_TQWIDGET(menubar_w));
+ if ( menubar && !menubar->isHidden() && !menubar->isTopLevel() )
+ return menubar->heightForWidth( TQMAX(w, menubar->minimumWidth()) );
+ else
+#endif
+ return 0;
+}
+
+TQLayout::TQLayout( QWidget *tqparent, int margin, int spacing, const char *name ) : QLayout( tqparent ), autoNewChild(false)
+{
+ setObjectName(QString::fromAscii(name));
+ setMargin(margin);
+ if (spacing < 0)
+ setSpacing(margin);
+ else
+ setSpacing(spacing);
+ if ( tqparent ) tqparent->installEventFilter( this );
+ TQT_TQOBJECT_REQUIRED_INITIALIZATION(tqparent)
+}
+
+TQLayout::TQLayout( QLayout *parentLayout, int spacing, const char *name ) : QLayout(), autoNewChild(false)
+{
+ setObjectName(QString::fromAscii(name));
+ setSpacing(spacing);
+ if ( parentLayout ) parentLayout->addItem(this);
+ if ( parentLayout ) parentLayout->installEventFilter( this );
+ TQT_TQOBJECT_REQUIRED_INITIALIZATION(parentLayout)
+}
+
+TQLayout::TQLayout( int spacing, const char *name ) : QLayout(), autoNewChild(false)
+{
+ setObjectName(QString::fromAscii(name));
+ setSpacing(spacing);
+}
+
+TQ_SPExpandData TQLayout::expandingDirections() const {
+ return (Qt::Orientations)TQSizePolicy::BothDirections;
+}
+
+TQLayout *TQLayout::tqlayout() {
+ return this;
+}
+
+TQSize TQLayout::tqsizeHint() const {
+ return sizeHint();
+}
+
+TQSize TQLayout::tqminimumSize() const {
+ return QLayout::minimumSize();
+}
+
+TQSize TQLayout::tqmaximumSize() const {
+ return QLayout::maximumSize();
+}
+
+TQWidget *TQLayout::mainWidget() {
+ return TQT_TQWIDGET(parentWidget());
+}
+
+void TQLayout::tqinvalidate() {
+ QLayout::invalidate();
+}
+
+void TQLayout::invalidate() {
+ tqinvalidate();
+}
+
+TQRect TQLayout::tqgeometry() const {
+ return QLayout::geometry();
+}
+
+const char *TQLayout::tqname() const {
+ if (dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQLayout::tqname() on an object without a constructed TQLayout object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+const char *TQLayout::name() const {
+ if (dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQLayout::tqname() on an object without a constructed TQLayout object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+int TQLayout::tqalignment() const {
+ return alignment();
+}
+
+TQWidget *TQLayout::mainWidget() const {
+ return TQT_TQWIDGET(parentWidget());
+}
+
+void TQLayout::remove(QWidget *w) {
+ removeWidget(w);
+}
+
+void TQLayout::add(QWidget *w) {
+ addWidget(w);
+}
+
+void TQLayout::setResizeMode(SizeConstraint s) {
+ setSizeConstraint(s);
+}
+
+void TQLayout::setResizeMode(ResizeMode s) {
+ setResizeMode((SizeConstraint)s);
+}
+
+TQLayout::SizeConstraint TQLayout::resizeMode() const {
+ return sizeConstraint();
+}
+
+TQLayout::ResizeMode TQLayout::tqresizeMode() const {
+ return (ResizeMode)sizeConstraint();
+}
+
+void TQLayout::setAutoAdd(bool a) {
+ autoNewChild = a;
+}
+
+bool TQLayout::autoAdd() const {
+ return autoNewChild;
+}
+
+void TQLayout::tqsetAlignment( int a ) {
+ return setAlignment((Qt::Alignment)a);
+}
+
+// Qt4 handler interface
+bool TQLayout::eventFilter( QObject *q, QEvent *e ) {
+ return eventFilter(static_cast<TQObject*>(q), static_cast<TQEvent*>(e));
+}
+
+bool TQLayout::event( QEvent *e ) {
+ return event(static_cast<TQEvent*>(e));
+}
+
+void TQLayout::timerEvent(QTimerEvent *e) {
+ timerEvent(static_cast<TQTimerEvent*>(e));
+}
+
+void TQLayout::childEvent(QChildEvent *e) {
+ TQT_TQOBJECT_CHILDEVENT_CONDITIONAL childEvent(static_cast<TQChildEvent*>(e));
+}
+
+void TQLayout::customEvent(QEvent *e) {
+ customEvent(static_cast<TQCustomEvent*>(e));
+}
+
+bool TQLayout::eventFilter( TQObject *o, TQEvent *e ) {
+ TQ_UNUSED(o);
+
+ if (e->type() == TQEvent::Resize) {
+ activate();
+ TQResizeEvent *r = (TQResizeEvent *)e;
+ int mbh = 0;
+#ifndef TQT_NO_MENUBAR
+ mbh = menuBarHeightForWidth( menuBar(), r->size().width() );
+#endif
+// int b = marginImpl ? 0 : outsideBorder;
+ int b = 0;
+ setGeometry( TQRect( b, mbh + b, r->size().width() - 2 * b, r->size().height() - mbh - 2 * b ) );
+ }
+
+ else if (e->type() == TQEvent::ChildInserted) {
+ if (autoNewChild) {
+ QChildEvent *c = (QChildEvent *)e;
+ if (c->child()->isWidgetType()) {
+ QWidget *w = (QWidget *)c->child();
+ if (!w->isWindow()) {
+// #if !defined(QT_NO_MENUBAR) && !defined(QT_NO_TOOLBAR)
+// if (qobject_cast<QMenuBar*>(w) && !qobject_cast<QToolBar*>(w->parentWidget())) {
+// setMenuBar( (QMenuBar *)w );
+// invalidate();
+// } else
+// #endif
+// #ifndef QT_NO_SIZEGRIP
+// if (qobject_cast<QSizeGrip*>(w) ) {
+// //SizeGrip is handled by the dialog itself.
+// } else
+// #endif
+// addItem(QLayoutPrivate::createWidgetItem(this, w));
+ addWidget(w);
+ }
+ }
+ }
+ }
+ else if (e->type() == TQEvent::LayoutHint) {
+// d->d = false;
+// if (parent()) {
+// if (static_cast<QWidget *>(parent())->isVisible()) {
+ activate();
+// }
+// }
+ }
+// return FALSE;
+ return QLayout::eventFilter( o, e );
+// return TQObject::eventFilter( o, e );
+}
+
+TQLayoutIterator TQLayout::iterator() {
+ return TQLayoutIterator(this,true);
+}
+
+/*!
+ \compat
+
+ Sets this layout's parent widget to a fixed size with width \a w
+ and height \a h, stopping the user from resizing it, and also
+ prevents the layout from resizing it, even if the layout's size
+ hint should change. Does nothing if this is not a top-level
+ layout (i.e., if parent()->isWidgetType()).
+
+ As a special case, if both \a w and \a h are 0, then the layout's
+ current sizeHint() is used.
+
+ Use \c setResizeMode(Fixed) to stop the widget from being resized
+ by the user, while still allowing the layout to resize it when
+ the sizeHint() changes.
+
+ Use \c setResizeMode(FreeResize) to allow the user to resize the
+ widget, while preventing the layout from resizing it.
+
+*/
+void TQLayout::freeze(int w, int h)
+{
+// if (!isTopLevel())
+// return;
+ if (w <= 0 || h <= 0) {
+ QSize s = totalSizeHint();
+ w = s.width();
+ h = s.height();
+ }
+ setSizeConstraint(SetNoConstraint); // layout will not change min/max size
+ QWidget *parent = parentWidget();
+ if (parent)
+ parent->setFixedSize(w, h);
+}
+
+// Use the TQt virtual functions, not the built in Qt ones...
+// This requires that the base virtual Qt functions be reimplemented so as to point to the TQt virtual functions instead as shown below.
+// This way, when Trinity overrides a TQt virtual function, the calling Qt code will blithely use the overriden TQt function instead.
+QLayout *TQLayout::layout() {
+ return tqlayout();
+}
+
+void TQLayout::setGeometry(const TQRect &r) {
+ return QLayout::setGeometry(r);
+}
+
+TQRect TQLayout::alignmentRect( const TQRect& qr ) const {
+ return alignmentRect(qr);
+}
+
+void TQLayout::tqt_handle_qt_destroyed(QObject* obj) {
+ emit destroyed(TQT_TQOBJECT(obj));
+}
+
+TQLayoutIterator::TQLayoutIterator(QLayout *i) : layout(static_cast<TQLayout*>(i)), index(0) {
+}
+
+TQLayoutIterator::TQLayoutIterator(QLayout *i, bool) : layout(static_cast<TQLayout*>(i)), index(0) {
+}
+
+TQLayoutItem *TQLayoutIterator::operator++() {
+ return static_cast<TQLayoutItem*>(layout->itemAt(++index));
+}
+
+TQLayoutItem *TQLayoutIterator::current() {
+ return static_cast<TQLayoutItem*>(layout->itemAt(index));
+}
+
+TQLayoutItem *TQLayoutIterator::takeCurrent() {
+ return static_cast<TQLayoutItem*>(layout->takeAt(index));
+}
+
+void TQLayoutIterator::deleteCurrent() {
+ delete layout->takeAt(index);
+}
+
+TQSpacerItem *TQLayoutItem::tqspacerItem()
+{
+ return static_cast<TQSpacerItem*>(QLayoutItem::spacerItem());
+}
+
+/*!
+ This virtual function receives events to an object and should
+ return TRUE if the event \a e was recognized and processed.
+
+ The event() function can be reimplemented to customize the
+ behavior of an object.
+
+ \sa installEventFilter(), timerEvent(), TQApplication::sendEvent(),
+ TQApplication::postEvent(), TQWidget::event()
+*/
+
+bool TQLayout::event( TQEvent *e )
+{
+#if defined(TQT_CHECK_NULL)
+ if ( e == 0 )
+ qWarning( "TQLayout::event: Null events are not permitted" );
+#endif
+// if ( eventFilters ) { // try filters
+// if ( activate_filters(e) ) // stopped by a filter
+// return TRUE;
+// }
+//
+ switch ( e->type() ) {
+// case TQEvent::Timer:
+// timerEvent( (TQTimerEvent*)e );
+// return TRUE;
+//
+// case TQEvent::DeferredDelete:
+// delete this;
+// return TRUE;
+//
+// default:
+// if ( e->type() >= TQEvent::User ) {
+// customEvent( (TQCustomEvent*) e );
+// return TRUE;
+// }
+// break;
+// }
+
+ case TQEvent::ChildInserted:
+// case TQEvent::ChildRemoved: // Causes a recursion loop if uncommented
+ childEvent( (TQChildEvent*)e );
+ return TRUE;
+
+ default:
+ return QLayout::event(e);
+ }
+
+ return FALSE;
+}
+
+#if 0
+void TQGridLayout::tqsetAlignment( int a )
+{
+ setAlignment((Qt::AlignmentFlag)a);
+}
+#endif
+
+#if 0
+
+// NOTE
+// The following functions are cloned from TQWidget
+// They are only required for TQLayout and TQGridLayout becase those classes do not inherit TQObject or TQWidget
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse move events for the widget.
+
+ If mouse tracking is switched off, mouse move events only occur if
+ a mouse button is pressed while the mouse is being moved. If mouse
+ tracking is switched on, mouse move events occur even if no mouse
+ button is pressed.
+
+ TQMouseEvent::pos() reports the position of the mouse cursor,
+ relative to this widget. For press and release events, the
+ position is usually the same as the position of the last mouse
+ move event, but it might be different if the user's hand shakes.
+ This is a feature of the underlying window system, not TQt.
+
+ \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
+ mouseDoubleClickEvent(), event(), TQMouseEvent
+*/
+
+void TQLayout::mouseMoveEvent( TQMouseEvent * e)
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse press events for the widget.
+
+ If you create new widgets in the mousePressEvent() the
+ mouseReleaseEvent() may not end up where you expect, depending on
+ the underlying window system (or X11 window manager), the widgets'
+ location and maybe more.
+
+ The default implementation implements the closing of popup widgets
+ when you click outside the window. For other widget types it does
+ nothing.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQLayout::mousePressEvent( TQMouseEvent * )
+{
+// TQT_TQWIDGET_CONST(this)->mousePressEvent(e);
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse release events for the widget.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQLayout::mouseReleaseEvent( TQMouseEvent * e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse double click events for the widget.
+
+ The default implementation generates a normal mouse press event.
+
+ Note that the widgets gets a mousePressEvent() and a
+ mouseReleaseEvent() before the mouseDoubleClickEvent().
+
+ \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
+ event(), TQMouseEvent
+*/
+
+void TQLayout::mouseDoubleClickEvent( TQMouseEvent *e )
+{
+ mousePressEvent( e ); // try mouse press event
+}
+
+#ifndef TQT_NO_WHEELEVENT
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive wheel events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQWheelEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQWheelEvent::ignore(), TQWheelEvent::accept(), event(),
+ TQWheelEvent
+*/
+
+void TQLayout::wheelEvent( TQWheelEvent *e )
+{
+ e->ignore();
+}
+#endif
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive tablet events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQTabletEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQTabletEvent::ignore(), TQTabletEvent::accept(), event(),
+ TQTabletEvent
+*/
+
+void TQLayout::tabletEvent( TQTabletEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key press events for the widget.
+
+ A widget must call setFocusPolicy() to accept focus initially and
+ have focus in order to receive a key press event.
+
+ If you reimplement this handler, it is very important that you
+ explicitly \link TQKeyEvent::ignore() ignore\endlink the event
+ if you do not understand it, so that the widget's tqparent can
+ interpret it; otherwise, the event will be implicitly accepted.
+ Although top-level widgets are able to choose whether to accept
+ or ignore unknown events because they have no tqparent widgets that
+ could otherwise handle them, it is good practice to explicitly
+ ignore events to make widgets as reusable as possible.
+
+ The default implementation closes popup widgets if the user
+ presses <b>Esc</b>. Otherwise the event is ignored.
+
+ \sa keyReleaseEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQLayout::keyPressEvent( TQKeyEvent * )
+{
+// TQT_TQWIDGET_CONST(this)->keyPressEvent(e);
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key release events for the widget.
+
+ A widget must \link setFocusPolicy() accept focus\endlink
+ initially and \link hasFocus() have focus\endlink in order to
+ receive a key release event.
+
+ If you reimplement this handler, it is very important that you
+ \link TQKeyEvent ignore()\endlink the release if you do not
+ understand it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa keyPressEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQLayout::keyReleaseEvent( TQKeyEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus received) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQLayout::focusInEvent( TQFocusEvent * )
+{
+// TQT_TQWIDGET_CONST(this)->focusInEvent(e);
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus lost) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQLayout::focusOutEvent( TQFocusEvent * )
+{
+// TQT_TQWIDGET_CONST(this)->focusOutEvent(e);
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget enter events.
+
+ An event is sent to the widget when the mouse cursor enters the
+ widget.
+
+ \sa leaveEvent(), mouseMoveEvent(), event()
+*/
+
+void TQLayout::enterEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget leave events.
+
+ A leave event is sent to the widget when the mouse cursor leaves
+ the widget.
+
+ \sa enterEvent(), mouseMoveEvent(), event()
+*/
+
+void TQLayout::leaveEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ paint events.
+
+ A paint event is a request to tqrepaint all or part of the widget.
+ It can happen as a result of tqrepaint() or update(), or because the
+ widget was obscured and has now been uncovered, or for many other
+ reasons.
+
+ Many widgets can simply tqrepaint their entire surface when asked
+ to, but some slow widgets need to optimize by painting only the
+ requested region: TQPaintEvent::region(). This speed optimization
+ does not change the result, as painting is clipped to that region
+ during event processing. TQListView and TQCanvas do this, for
+ example.
+
+ TQt also tries to speed up painting by merging multiple paint
+ events into one. When update() is called several times or the
+ window system sends several paint events, TQt merges these events
+ into one event with a larger region (see TQRegion::unite()).
+ tqrepaint() does not permit this optimization, so we suggest using
+ update() when possible.
+
+ When the paint event occurs, the update region has normally been
+ erased, so that you're painting on the widget's background. There
+ are a couple of exceptions and TQPaintEvent::erased() tells you
+ whether the widget has been erased or not.
+
+ The background can be set using setBackgroundMode(),
+ setPaletteBackgroundColor() or setBackgroundPixmap(). The
+ documentation for setBackgroundMode() elaborates on the
+ background; we recommend reading it.
+
+ \sa event(), tqrepaint(), update(), TQPainter, TQPixmap, TQPaintEvent
+*/
+
+void TQLayout::paintEvent( TQPaintEvent *e )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget move events. When the widget receives this event, it is
+ already at the new position.
+
+ The old position is accessible through TQMoveEvent::oldPos().
+
+ \sa resizeEvent(), event(), move(), TQMoveEvent
+*/
+
+void TQLayout::moveEvent( TQMoveEvent * )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget resize events. When resizeEvent() is called, the widget
+ already has its new tqgeometry. The old size is accessible through
+ TQResizeEvent::oldSize().
+
+ The widget will be erased and receive a paint event immediately
+ after processing the resize event. No drawing need be (or should
+ be) done inside this handler.
+
+ Widgets that have been created with the \c WNoAutoErase flag
+ will not be erased. Nevertheless, they will receive a paint event
+ for their entire area afterwards. Again, no drawing needs to be
+ done inside this handler.
+
+ The default implementation calls updateMask() if the widget has
+ \link TQLayout::setAutoMask() automatic masking\endlink enabled.
+
+ \sa moveEvent(), event(), resize(), TQResizeEvent, paintEvent()
+*/
+
+void TQLayout::resizeEvent( TQResizeEvent * )
+{
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget close events.
+
+ The default implementation calls e->accept(), which hides this
+ widget. See the \l TQCloseEvent documentation for more details.
+
+ \sa event(), hide(), close(), TQCloseEvent
+*/
+
+void TQLayout::closeEvent( TQCloseEvent *e )
+{
+ e->accept();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget context menu events.
+
+ The default implementation calls e->ignore(), which rejects the
+ context event. See the \l TQContextMenuEvent documentation for
+ more details.
+
+ \sa event(), TQContextMenuEvent
+*/
+
+void TQLayout::contextMenuEvent( TQContextMenuEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user begins entering text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQLayout::imStartEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has entered some text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQLayout::imComposeEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has finished inputting text via an Input
+ Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQLayout::imEndEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+#ifndef TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragEnterEvent
+*/
+void TQLayout::dragEnterEvent( TQDragEnterEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget, and whenever it moves within the widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragMoveEvent
+*/
+void TQLayout::dragMoveEvent( TQDragMoveEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse leaves this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragLeaveEvent
+*/
+void TQLayout::dragLeaveEvent( TQDragLeaveEvent * )
+{
+}
+
+/*!
+ This event handler is called when the drag is dropped on this
+ widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDropEvent
+*/
+void TQLayout::dropEvent( TQDropEvent * )
+{
+}
+
+#endif // TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget show events.
+
+ Non-spontaneous show events are sent to widgets immediately before
+ they are shown. The spontaneous show events of top-level widgets
+ are delivered afterwards.
+
+ \sa event(), TQShowEvent
+*/
+void TQLayout::showEvent( TQShowEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget hide events.
+
+ Hide events are sent to widgets immediately after they have been
+ hidden.
+
+ \sa event(), TQHideEvent
+*/
+void TQLayout::hideEvent( TQHideEvent * )
+{
+}
+
+#endif
+
+void TQLayout::timerEvent( TQTimerEvent * )
+{
+}
+
+void TQLayout::childEvent( TQChildEvent * )
+{
+}
+
+void TQLayout::customEvent( TQCustomEvent * )
+{
+}
+
+#if 0
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse move events for the widget.
+
+ If mouse tracking is switched off, mouse move events only occur if
+ a mouse button is pressed while the mouse is being moved. If mouse
+ tracking is switched on, mouse move events occur even if no mouse
+ button is pressed.
+
+ TQMouseEvent::pos() reports the position of the mouse cursor,
+ relative to this widget. For press and release events, the
+ position is usually the same as the position of the last mouse
+ move event, but it might be different if the user's hand shakes.
+ This is a feature of the underlying window system, not TQt.
+
+ \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
+ mouseDoubleClickEvent(), event(), TQMouseEvent
+*/
+
+void TQGridLayout::mouseMoveEvent( TQMouseEvent * e)
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse press events for the widget.
+
+ If you create new widgets in the mousePressEvent() the
+ mouseReleaseEvent() may not end up where you expect, depending on
+ the underlying window system (or X11 window manager), the widgets'
+ location and maybe more.
+
+ The default implementation implements the closing of popup widgets
+ when you click outside the window. For other widget types it does
+ nothing.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQGridLayout::mousePressEvent( TQMouseEvent * )
+{
+// TQT_TQLAYOUT_CONST(this)->mousePressEvent(e);
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse release events for the widget.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQGridLayout::mouseReleaseEvent( TQMouseEvent * e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse double click events for the widget.
+
+ The default implementation generates a normal mouse press event.
+
+ Note that the widgets gets a mousePressEvent() and a
+ mouseReleaseEvent() before the mouseDoubleClickEvent().
+
+ \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
+ event(), TQMouseEvent
+*/
+
+void TQGridLayout::mouseDoubleClickEvent( TQMouseEvent *e )
+{
+ mousePressEvent( e ); // try mouse press event
+}
+
+#ifndef TQT_NO_WHEELEVENT
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive wheel events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQWheelEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQWheelEvent::ignore(), TQWheelEvent::accept(), event(),
+ TQWheelEvent
+*/
+
+void TQGridLayout::wheelEvent( TQWheelEvent *e )
+{
+ e->ignore();
+}
+#endif
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive tablet events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQTabletEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQTabletEvent::ignore(), TQTabletEvent::accept(), event(),
+ TQTabletEvent
+*/
+
+void TQGridLayout::tabletEvent( TQTabletEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key press events for the widget.
+
+ A widget must call setFocusPolicy() to accept focus initially and
+ have focus in order to receive a key press event.
+
+ If you reimplement this handler, it is very important that you
+ explicitly \link TQKeyEvent::ignore() ignore\endlink the event
+ if you do not understand it, so that the widget's tqparent can
+ interpret it; otherwise, the event will be implicitly accepted.
+ Although top-level widgets are able to choose whether to accept
+ or ignore unknown events because they have no tqparent widgets that
+ could otherwise handle them, it is good practice to explicitly
+ ignore events to make widgets as reusable as possible.
+
+ The default implementation closes popup widgets if the user
+ presses <b>Esc</b>. Otherwise the event is ignored.
+
+ \sa keyReleaseEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQGridLayout::keyPressEvent( TQKeyEvent * )
+{
+// TQT_TQLAYOUT_CONST(this)->keyPressEvent(e);
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key release events for the widget.
+
+ A widget must \link setFocusPolicy() accept focus\endlink
+ initially and \link hasFocus() have focus\endlink in order to
+ receive a key release event.
+
+ If you reimplement this handler, it is very important that you
+ \link TQKeyEvent ignore()\endlink the release if you do not
+ understand it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa keyPressEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQGridLayout::keyReleaseEvent( TQKeyEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus received) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQGridLayout::focusInEvent( TQFocusEvent * )
+{
+// TQT_TQLAYOUT_CONST(this)->focusInEvent(e);
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus lost) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQGridLayout::focusOutEvent( TQFocusEvent * )
+{
+// TQT_TQLAYOUT_CONST(this)->focusOutEvent(e);
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget enter events.
+
+ An event is sent to the widget when the mouse cursor enters the
+ widget.
+
+ \sa leaveEvent(), mouseMoveEvent(), event()
+*/
+
+void TQGridLayout::enterEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget leave events.
+
+ A leave event is sent to the widget when the mouse cursor leaves
+ the widget.
+
+ \sa enterEvent(), mouseMoveEvent(), event()
+*/
+
+void TQGridLayout::leaveEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ paint events.
+
+ A paint event is a request to tqrepaint all or part of the widget.
+ It can happen as a result of tqrepaint() or update(), or because the
+ widget was obscured and has now been uncovered, or for many other
+ reasons.
+
+ Many widgets can simply tqrepaint their entire surface when asked
+ to, but some slow widgets need to optimize by painting only the
+ requested region: TQPaintEvent::region(). This speed optimization
+ does not change the result, as painting is clipped to that region
+ during event processing. TQListView and TQCanvas do this, for
+ example.
+
+ TQt also tries to speed up painting by merging multiple paint
+ events into one. When update() is called several times or the
+ window system sends several paint events, TQt merges these events
+ into one event with a larger region (see TQRegion::unite()).
+ tqrepaint() does not permit this optimization, so we suggest using
+ update() when possible.
+
+ When the paint event occurs, the update region has normally been
+ erased, so that you're painting on the widget's background. There
+ are a couple of exceptions and TQPaintEvent::erased() tells you
+ whether the widget has been erased or not.
+
+ The background can be set using setBackgroundMode(),
+ setPaletteBackgroundColor() or setBackgroundPixmap(). The
+ documentation for setBackgroundMode() elaborates on the
+ background; we recommend reading it.
+
+ \sa event(), tqrepaint(), update(), TQPainter, TQPixmap, TQPaintEvent
+*/
+
+void TQGridLayout::paintEvent( TQPaintEvent *e )
+{
+// // At least let Qt4 get a shot at painting it
+// QWidget::paintEvent(e);
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget move events. When the widget receives this event, it is
+ already at the new position.
+
+ The old position is accessible through TQMoveEvent::oldPos().
+
+ \sa resizeEvent(), event(), move(), TQMoveEvent
+*/
+
+void TQGridLayout::moveEvent( TQMoveEvent * )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget resize events. When resizeEvent() is called, the widget
+ already has its new tqgeometry. The old size is accessible through
+ TQResizeEvent::oldSize().
+
+ The widget will be erased and receive a paint event immediately
+ after processing the resize event. No drawing need be (or should
+ be) done inside this handler.
+
+ Widgets that have been created with the \c WNoAutoErase flag
+ will not be erased. Nevertheless, they will receive a paint event
+ for their entire area afterwards. Again, no drawing needs to be
+ done inside this handler.
+
+ The default implementation calls updateMask() if the widget has
+ \link TQGridLayout::setAutoMask() automatic masking\endlink enabled.
+
+ \sa moveEvent(), event(), resize(), TQResizeEvent, paintEvent()
+*/
+
+void TQGridLayout::resizeEvent( TQResizeEvent * )
+{
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget close events.
+
+ The default implementation calls e->accept(), which hides this
+ widget. See the \l TQCloseEvent documentation for more details.
+
+ \sa event(), hide(), close(), TQCloseEvent
+*/
+
+void TQGridLayout::closeEvent( TQCloseEvent *e )
+{
+ e->accept();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget context menu events.
+
+ The default implementation calls e->ignore(), which rejects the
+ context event. See the \l TQContextMenuEvent documentation for
+ more details.
+
+ \sa event(), TQContextMenuEvent
+*/
+
+void TQGridLayout::contextMenuEvent( TQContextMenuEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user begins entering text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQGridLayout::imStartEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has entered some text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQGridLayout::imComposeEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has finished inputting text via an Input
+ Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQGridLayout::imEndEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+#ifndef TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragEnterEvent
+*/
+void TQGridLayout::dragEnterEvent( TQDragEnterEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget, and whenever it moves within the widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragMoveEvent
+*/
+void TQGridLayout::dragMoveEvent( TQDragMoveEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse leaves this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragLeaveEvent
+*/
+void TQGridLayout::dragLeaveEvent( TQDragLeaveEvent * )
+{
+}
+
+/*!
+ This event handler is called when the drag is dropped on this
+ widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDropEvent
+*/
+void TQGridLayout::dropEvent( TQDropEvent * )
+{
+}
+
+#endif // TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget show events.
+
+ Non-spontaneous show events are sent to widgets immediately before
+ they are shown. The spontaneous show events of top-level widgets
+ are delivered afterwards.
+
+ \sa event(), TQShowEvent
+*/
+void TQGridLayout::showEvent( TQShowEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget hide events.
+
+ Hide events are sent to widgets immediately after they have been
+ hidden.
+
+ \sa event(), TQHideEvent
+*/
+void TQGridLayout::hideEvent( TQHideEvent * )
+{
+}
+
+void TQGridLayout::timerEvent( TQTimerEvent * )
+{
+}
+
+void TQGridLayout::childEvent( TQChildEvent * )
+{
+}
+
+void TQGridLayout::customEvent( TQCustomEvent * )
+{
+}
+
+#endif
+
+TQMetaObject *TQLayout::tqmetaObject() const {
+ return TQT_TQOBJECT_CONST(this)->tqmetaObject();
+}
+
+#else // USE_QT4
+
+#endif // USE_QT4
+
+/*
+ Three internal classes related to TQGridLayout: (1) TQGridBox is a
+ TQLayoutItem with (row, column) information; (2) TQGridMultiBox is a
+ TQGridBox with (torow, tocolumn) information; (3) TQGridLayoutData is
+ the internal representation of a TQGridLayout.
+*/
+
+class TQGridBox
+{
+public:
+ TQGridBox( TQLayoutItem *lit ) { item_ = lit; }
+
+ TQGridBox( TQWidget *wid ) { item_ = new TQWidgetItem( wid ); }
+ TQGridBox( int w, int h, TQSizePolicy::SizeType hData = TQSizePolicy::Minimum,
+ TQSizePolicy::SizeType vData = TQSizePolicy::Minimum )
+ { item_ = TQT_TQLAYOUTITEM(new TQSpacerItem( w, h, hData, vData )); }
+ ~TQGridBox() { delete item_; }
+
+ QSize tqsizeHint() const { return item_->sizeHint(); }
+ QSize tqminimumSize() const { return item_->minimumSize(); }
+ QSize tqmaximumSize() const { return item_->maximumSize(); }
+ TQ_SPExpandData expandingDirections() const { return item_->expandingDirections(); }
+ bool isEmpty() const { return item_->isEmpty(); }
+
+ bool hasHeightForWidth() const { return item_->hasHeightForWidth(); }
+ int heightForWidth( int w ) const { return item_->heightForWidth(w); }
+
+ void tqsetAlignment( int a ) { item_->tqsetAlignment( a ); }
+ void setGeometry( const TQRect &r ) { item_->setGeometry( r ); }
+ int tqalignment() const { return item_->tqalignment(); }
+ TQLayoutItem *item() { return item_; }
+ TQLayoutItem *takeItem() { TQLayoutItem *i = item_; item_ = 0; return i; }
+
+ int hStretch() { return item_->widget() ?
+ TQT_TQSIZEPOLICY_OBJECT(item_->widget()->sizePolicy()).horStretch() : 0; }
+ int vStretch() { return item_->widget() ?
+ TQT_TQSIZEPOLICY_OBJECT(item_->widget()->sizePolicy()).verStretch() : 0; }
+
+private:
+ friend class TQGridLayoutData;
+ friend class TQGridLayoutDataIterator;
+
+ TQLayoutItem *item_;
+ int row, col;
+};
+
+class TQGridMultiBox
+{
+public:
+ TQGridMultiBox( TQGridBox *box, int toRow, int toCol )
+ : box_( box ), torow( toRow ), tocol( toCol ) { }
+ ~TQGridMultiBox() { delete box_; }
+ TQGridBox *box() { return box_; }
+ TQLayoutItem *takeItem() { return box_->takeItem(); }
+
+private:
+ friend class TQGridLayoutData;
+ friend class TQGridLayoutDataIterator;
+
+ TQGridBox *box_;
+ int torow, tocol;
+};
+
+class TQGridLayoutData
+{
+public:
+ TQGridLayoutData();
+ TQGridLayoutData( int nRows, int nCols );
+ ~TQGridLayoutData();
+
+ void add( TQGridBox*, int row, int col );
+ void add( TQGridBox*, int row1, int row2, int col1, int col2 );
+ QSize tqsizeHint( int ) const;
+ QSize tqminimumSize( int ) const;
+ QSize tqmaximumSize( int ) const;
+
+ TQ_SPExpandData expanding( int spacing );
+
+ void distribute( TQRect, int );
+ inline int numRows() const { return rr; }
+ inline int numCols() const { return cc; }
+ inline void expand( int rows, int cols )
+ { setSize( TQMAX(rows, rr), TQMAX(cols, cc) ); }
+ inline void setRowStretch( int r, int s )
+ { expand( r + 1, 0 ); rStretch[r] = s; setDirty(); }
+ inline void setColStretch( int c, int s )
+ { expand( 0, c + 1 ); cStretch[c] = s; setDirty(); }
+ inline int rowStretch( int r ) const { return rStretch[r]; }
+ inline int colStretch( int c ) const { return cStretch[c]; }
+ inline void setRowSpacing( int r, int s )
+ { expand( r + 1, 0 ); rSpacing[r] = s; setDirty(); }
+ inline void setColSpacing( int c, int s )
+ { expand( 0, c + 1 ); cSpacing[c] = s; setDirty(); }
+ inline int rowSpacing( int r ) const { return rSpacing[r]; }
+ inline int colSpacing( int c ) const { return cSpacing[c]; }
+
+ inline void setReversed( bool r, bool c ) { hReversed = c; vReversed = r; }
+ inline bool horReversed() const { return hReversed; }
+ inline bool verReversed() const { return vReversed; }
+ inline void setDirty() { needRecalc = TRUE; hfw_width = -1; }
+ inline bool isDirty() const { return needRecalc; }
+ bool hasHeightForWidth( int space );
+ int heightForWidth( int, int, int );
+ int minimumHeightForWidth( int, int, int );
+
+ bool tqfindWidget( TQWidget* w, int *row, int *col );
+
+ inline void getNextPos( int &row, int &col ) { row = nextR; col = nextC; }
+ inline uint count() const
+ { return things.count() + ( multi ? multi->count() : 0 ); }
+ TQRect cellGeometry( int row, int col ) const;
+
+private:
+ void setNextPosAfter( int r, int c );
+ void recalcHFW( int w, int s );
+ void addHfwData ( TQGridBox *box, int width );
+ void init();
+ TQSize tqfindSize( TQCOORD TQLayoutStruct::*, int ) const;
+ void addData( TQGridBox *b, bool r = TRUE, bool c = TRUE );
+ void setSize( int rows, int cols );
+ void setupLayoutData( int space );
+ void setupHfwLayoutData( int space );
+
+ int rr;
+ int cc;
+ TQMemArray<TQLayoutStruct> rowData;
+ TQMemArray<TQLayoutStruct> colData;
+ TQMemArray<TQLayoutStruct> *hfwData;
+ TQMemArray<int> rStretch;
+ TQMemArray<int> cStretch;
+ TQMemArray<int> rSpacing;
+ TQMemArray<int> cSpacing;
+ TQPtrList<TQGridBox> things;
+ TQPtrList<TQGridMultiBox> *multi;
+
+ int hfw_width;
+ int hfw_height;
+ int hfw_minheight;
+ int nextR;
+ int nextC;
+
+ uint hReversed : 1;
+ uint vReversed : 1;
+ uint needRecalc : 1;
+ uint has_hfw : 1;
+ uint addVertical : 1;
+
+ friend class TQGridLayoutDataIterator;
+};
+
+TQGridLayoutData::TQGridLayoutData()
+{
+ init();
+}
+
+TQGridLayoutData::TQGridLayoutData( int nRows, int nCols )
+ : rowData( 0 ), colData( 0 )
+{
+ init();
+ if ( nRows < 0 ) {
+ nRows = 1;
+ addVertical = FALSE;
+ }
+ if ( nCols < 0 ) {
+ nCols = 1;
+ addVertical = TRUE;
+ }
+ setSize( nRows, nCols );
+}
+
+TQGridLayoutData::~TQGridLayoutData()
+{
+ // must be cleared while the data is still in a stable state
+ things.clear();
+
+ delete multi;
+ delete hfwData;
+}
+
+void TQGridLayoutData::init()
+{
+ addVertical = FALSE;
+ setDirty();
+ multi = 0;
+ rr = cc = 0;
+ nextR = nextC = 0;
+ hfwData = 0;
+ things.setAutoDelete( TRUE );
+ hReversed = FALSE;
+ vReversed = FALSE;
+}
+
+bool TQGridLayoutData::hasHeightForWidth( int spacing )
+{
+ setupLayoutData( spacing );
+ return has_hfw;
+}
+
+/*
+ Assumes that setupLayoutData() has been called, and that
+ qGeomCalc() has filled in colData with appropriate values.
+*/
+void TQGridLayoutData::recalcHFW( int w, int spacing )
+{
+ /*
+ Go through all tqchildren, using colData and heightForWidth()
+ and put the results in hfw_rowData.
+ */
+ if ( !hfwData )
+ hfwData = new TQMemArray<TQLayoutStruct>( rr );
+ setupHfwLayoutData( spacing );
+ TQMemArray<TQLayoutStruct> &rData = *hfwData;
+
+ int h = 0;
+ int mh = 0;
+ int n = 0;
+ for ( int r = 0; r < rr; r++ ) {
+ h += rData[r].tqsizeHint;
+ mh += rData[r].tqminimumSize;
+ if ( !rData[r].empty )
+ n++;
+ }
+ if ( n ) {
+ h += ( n - 1 ) * spacing;
+ mh += ( n - 1 ) * spacing;
+ }
+
+ hfw_width = w;
+ hfw_height = TQMIN( TQLAYOUTSIZE_MAX, h );
+ hfw_minheight = TQMIN( TQLAYOUTSIZE_MAX, mh );
+}
+
+int TQGridLayoutData::heightForWidth( int w, int margin, int spacing )
+{
+ setupLayoutData( spacing );
+ if ( !has_hfw )
+ return -1;
+ if ( w + 2*margin != hfw_width ) {
+ qGeomCalc( colData, 0, cc, 0, w+2*margin, spacing );
+ recalcHFW( w+2*margin, spacing );
+ }
+ return hfw_height + 2*margin;
+}
+
+int TQGridLayoutData::minimumHeightForWidth( int w, int margin, int spacing )
+{
+ (void) heightForWidth( w, margin, spacing );
+ return has_hfw ? (hfw_minheight + 2*margin) : -1;
+}
+
+bool TQGridLayoutData::tqfindWidget( TQWidget* w, int *row, int *col )
+{
+ TQPtrListIterator<TQGridBox> it( things );
+ TQGridBox * box;
+ while ( (box = it.current()) != 0 ) {
+ ++it;
+ if ( box->item()->widget() == w ) {
+ if ( row )
+ *row = box->row;
+ if ( col )
+ *col = box->col;
+ return TRUE;
+ }
+ }
+ if ( multi ) {
+ TQPtrListIterator<TQGridMultiBox> it( *multi );
+ TQGridMultiBox * mbox;
+ while ( (mbox = it.current()) != 0 ) {
+ ++it;
+ box = mbox->box();
+ if ( box->item()->widget() == w ) {
+ if ( row )
+ *row = box->row;
+ if ( col )
+ *col = box->col;
+ return TRUE;
+ }
+
+ }
+ }
+ return FALSE;
+}
+
+TQSize TQGridLayoutData::tqfindSize( TQCOORD TQLayoutStruct::*size, int spacer ) const
+{
+ TQGridLayoutData *that = (TQGridLayoutData *)this;
+ that->setupLayoutData( spacer );
+
+ int w = 0;
+ int h = 0;
+ int n = 0;
+ for ( int r = 0; r < rr; r++ ) {
+ h = h + rowData[r].*size;
+ if ( !rowData[r].empty )
+ n++;
+ }
+ if ( n )
+ h += ( n - 1 ) * spacer;
+ n = 0;
+ for ( int c = 0; c < cc; c++ ) {
+ w = w + colData[c].*size;
+ if ( !colData[c].empty )
+ n++;
+ }
+ if ( n )
+ w += ( n - 1 ) * spacer;
+ w = TQMIN( TQLAYOUTSIZE_MAX, w );
+ h = TQMIN( TQLAYOUTSIZE_MAX, h );
+
+ return TQSize( w, h );
+}
+
+TQ_SPExpandData TQGridLayoutData::expanding( int spacing )
+{
+ setupLayoutData( spacing );
+ int ret = 0;
+
+ for ( int r = 0; r < rr; r++ ) {
+ if ( rowData[r].expansive ) {
+ ret |= (int) TQSizePolicy::Vertically;
+ break;
+ }
+ }
+ for ( int c = 0; c < cc; c++ ) {
+ if ( colData[c].expansive ) {
+ ret |= (int) TQSizePolicy::Horizontally;
+ break;
+ }
+ }
+ return (TQ_SPExpandData) ret;
+}
+
+QSize TQGridLayoutData::tqsizeHint( int spacer ) const
+{
+ return tqfindSize( &TQLayoutStruct::tqsizeHint, spacer );
+}
+
+QSize TQGridLayoutData::tqmaximumSize( int spacer ) const
+{
+ return tqfindSize( &TQLayoutStruct::tqmaximumSize, spacer );
+}
+
+QSize TQGridLayoutData::tqminimumSize( int spacer ) const
+{
+ return tqfindSize( &TQLayoutStruct::tqminimumSize, spacer );
+}
+
+void TQGridLayoutData::setSize( int r, int c )
+{
+ if ( (int)rowData.size() < r ) {
+ int newR = TQMAX( r, rr * 2 );
+ rowData.resize( newR );
+ rStretch.resize( newR );
+ rSpacing.resize( newR );
+ for ( int i = rr; i < newR; i++ ) {
+ rowData[i].init();
+ rStretch[i] = 0;
+ rSpacing[i] = 0;
+ }
+ }
+ if ( (int)colData.size() < c ) {
+ int newC = TQMAX( c, cc * 2 );
+ colData.resize( newC );
+ cStretch.resize( newC );
+ cSpacing.resize( newC );
+ for ( int i = cc; i < newC; i++ ) {
+ colData[i].init();
+ cStretch[i] = 0;
+ cSpacing[i] = 0;
+ }
+ }
+
+ if ( hfwData && (int)hfwData->size() < r ) {
+ delete hfwData;
+ hfwData = 0;
+ hfw_width = -1;
+ }
+ rr = r;
+ cc = c;
+}
+
+void TQGridLayoutData::setNextPosAfter( int row, int col )
+{
+ if ( addVertical ) {
+ if ( col > nextC || (col == nextC && row >= nextR) ) {
+ nextR = row + 1;
+ nextC = col;
+ if ( nextR >= rr ) {
+ nextR = 0;
+ nextC++;
+ }
+ }
+ } else {
+ if ( row > nextR || (row == nextR && col >= nextC) ) {
+ nextR = row;
+ nextC = col + 1;
+ if ( nextC >= cc ) {
+ nextC = 0;
+ nextR++;
+ }
+ }
+ }
+}
+
+void TQGridLayoutData::add( TQGridBox *box, int row, int col )
+{
+ expand( row+1, col+1 );
+ box->row = row;
+ box->col = col;
+ things.append( box );
+ setDirty();
+ setNextPosAfter( row, col );
+}
+
+void TQGridLayoutData::add( TQGridBox *box, int row1, int row2, int col1,
+ int col2 )
+{
+#ifdef TQT_CHECK_RANGE
+ if ( row2 >= 0 && row2 < row1 )
+ qWarning( "TQGridLayout: Multi-cell fromRow greater than toRow" );
+ if ( col2 >= 0 && col2 < col1 )
+ qWarning( "TQGridLayout: Multi-cell fromCol greater than toCol" );
+#endif
+ if ( row1 == row2 && col1 == col2 ) {
+ add( box, row1, col1 );
+ return;
+ }
+ expand( row2+1, col2+1 );
+ box->row = row1;
+ box->col = col1;
+ TQGridMultiBox *mbox = new TQGridMultiBox( box, row2, col2 );
+ if ( !multi ) {
+ multi = new TQPtrList<TQGridMultiBox>;
+ multi->setAutoDelete( TRUE );
+ }
+ multi->append( mbox );
+ setDirty();
+ if ( col2 < 0 )
+ col2 = cc - 1;
+
+ setNextPosAfter( row2, col2 );
+}
+
+void TQGridLayoutData::addData( TQGridBox *box, bool r, bool c )
+{
+ TQSize hint = box->tqsizeHint();
+ TQSize minS = box->tqminimumSize();
+ TQSize maxS = box->tqmaximumSize();
+
+ if ( c ) {
+ if ( !cStretch[box->col] )
+ colData[box->col].stretch = TQMAX( colData[box->col].stretch,
+ box->hStretch() );
+ colData[box->col].tqsizeHint = TQMAX( hint.width(),
+ colData[box->col].tqsizeHint );
+ colData[box->col].tqminimumSize = TQMAX( minS.width(),
+ colData[box->col].tqminimumSize );
+
+ qMaxExpCalc( colData[box->col].tqmaximumSize, colData[box->col].expansive,
+ maxS.width(),
+ box->expandingDirections() & TQSizePolicy::Horizontally );
+ }
+ if ( r ) {
+ if ( !rStretch[box->row] )
+ rowData[box->row].stretch = TQMAX( rowData[box->row].stretch,
+ box->vStretch() );
+ rowData[box->row].tqsizeHint = TQMAX( hint.height(),
+ rowData[box->row].tqsizeHint );
+ rowData[box->row].tqminimumSize = TQMAX( minS.height(),
+ rowData[box->row].tqminimumSize );
+
+ qMaxExpCalc( rowData[box->row].tqmaximumSize, rowData[box->row].expansive,
+ maxS.height(),
+ box->expandingDirections() & TQSizePolicy::Vertically );
+ }
+ if ( box->isEmpty() ) {
+ if ( box->item()->widget() != 0 ) {
+ /*
+ Hidden widgets should behave exactly the same as if
+ there were no widgets at all in the cell. We could have
+ TQWidgetItem::tqmaximumSize() to return
+ TQSize(TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX). However, that
+ value is not suitable for TQBoxLayouts. So let's fix it
+ here.
+ */
+ if ( c )
+ colData[box->col].tqmaximumSize = TQLAYOUTSIZE_MAX;
+ if ( r )
+ rowData[box->row].tqmaximumSize = TQLAYOUTSIZE_MAX;
+ }
+ } else {
+ // Empty boxes (i.e. spacers) do not get borders. This is
+ // hacky, but compatible.
+ if ( c )
+ colData[box->col].empty = FALSE;
+ if ( r )
+ rowData[box->row].empty = FALSE;
+ }
+}
+
+static void distributeMultiBox( TQMemArray<TQLayoutStruct> &chain, int spacing,
+ int start, int end,
+ int minSize, int tqsizeHint,
+ TQMemArray<int> &stretchArray, int stretch )
+{
+ int i;
+ int w = 0;
+ int wh = 0;
+ int max = 0;
+ for ( i = start; i <= end; i++ ) {
+ w += chain[i].tqminimumSize;
+ wh += chain[i].tqsizeHint;
+ max += chain[i].tqmaximumSize;
+ chain[i].empty = FALSE;
+ if ( stretchArray[i] == 0 )
+ chain[i].stretch = TQMAX(chain[i].stretch,stretch);
+ }
+ w += spacing * ( end - start );
+ wh += spacing * ( end - start );
+ max += spacing * ( end - start );
+
+ if ( max < minSize ) { // implies w < minSize
+ /*
+ We must increase the maximum size of at least one of the
+ items. qGeomCalc() will put the extra space in between the
+ items. We must recover that extra space and put it
+ somewhere. It does not really matter where, since the user
+ can always specify stretch factors and avoid this code.
+ */
+ qGeomCalc( chain, start, end - start + 1, 0, minSize, spacing );
+ int pos = 0;
+ for ( i = start; i <= end; i++ ) {
+ int nextPos = ( i == end ) ? minSize - 1 : chain[i + 1].pos;
+ int realSize = nextPos - pos;
+ if ( i != end )
+ realSize -= spacing;
+ if ( chain[i].tqminimumSize < realSize )
+ chain[i].tqminimumSize = realSize;
+ if ( chain[i].tqmaximumSize < chain[i].tqminimumSize )
+ chain[i].tqmaximumSize = chain[i].tqminimumSize;
+ pos = nextPos;
+ }
+ } else if ( w < minSize ) {
+ qGeomCalc( chain, start, end - start + 1, 0, minSize, spacing );
+ for ( i = start; i <= end; i++ ) {
+ if ( chain[i].tqminimumSize < chain[i].size )
+ chain[i].tqminimumSize = chain[i].size;
+ }
+ }
+
+ if ( wh < tqsizeHint ) {
+ qGeomCalc( chain, start, end - start + 1, 0, tqsizeHint, spacing );
+ for ( i = start; i <= end; i++ ) {
+ if ( chain[i].tqsizeHint < chain[i].size )
+ chain[i].tqsizeHint = chain[i].size;
+ }
+ }
+}
+
+//#define TQT_LAYOUT_DISABLE_CACHING
+
+void TQGridLayoutData::setupLayoutData( int spacing )
+{
+#ifndef TQT_LAYOUT_DISABLE_CACHING
+ if ( !needRecalc )
+ return;
+#endif
+ has_hfw = FALSE;
+ int i;
+
+ for ( i = 0; i < rr; i++ )
+ rowData[i].init( rStretch[i], rSpacing[i] );
+ for ( i = 0; i < cc; i++ )
+ colData[i].init( cStretch[i], cSpacing[i] );
+
+ TQPtrListIterator<TQGridBox> it( things );
+ TQGridBox * box;
+ while ( (box = it.current()) != 0 ) {
+ ++it;
+ addData( box );
+ has_hfw = has_hfw || box->item()->hasHeightForWidth();
+ }
+
+ if ( multi ) {
+ TQPtrListIterator<TQGridMultiBox> it( *multi );
+ TQGridMultiBox * mbox;
+ while ( (mbox = it.current()) != 0 ) {
+ ++it;
+ TQGridBox *box = mbox->box();
+ int r1 = box->row;
+ int c1 = box->col;
+ int r2 = mbox->torow;
+ int c2 = mbox->tocol;
+ if ( r2 < 0 )
+ r2 = rr - 1;
+ if ( c2 < 0 )
+ c2 = cc - 1;
+
+ TQSize hint = box->tqsizeHint();
+ TQSize min = box->tqminimumSize();
+ if ( box->hasHeightForWidth() )
+ has_hfw = TRUE;
+
+ if ( r1 == r2 ) {
+ addData( box, TRUE, FALSE );
+ } else {
+ distributeMultiBox( rowData, spacing, r1, r2,
+ min.height(), hint.height(),
+ rStretch, box->vStretch() );
+ }
+ if ( c1 == c2 ) {
+ addData( box, FALSE, TRUE );
+ } else {
+ distributeMultiBox( colData, spacing, c1, c2,
+ min.width(), hint.width(),
+ cStretch, box->hStretch() );
+ }
+ }
+ }
+ for ( i = 0; i < rr; i++ )
+ rowData[i].expansive = rowData[i].expansive || rowData[i].stretch > 0;
+ for ( i = 0; i < cc; i++ )
+ colData[i].expansive = colData[i].expansive || colData[i].stretch > 0;
+
+ needRecalc = FALSE;
+}
+
+void TQGridLayoutData::addHfwData( TQGridBox *box, int width )
+{
+ TQMemArray<TQLayoutStruct> &rData = *hfwData;
+ if ( box->hasHeightForWidth() ) {
+ int hint = box->heightForWidth( width );
+ rData[box->row].tqsizeHint = TQMAX( hint, rData[box->row].tqsizeHint );
+ rData[box->row].tqminimumSize = TQMAX( hint, rData[box->row].tqminimumSize );
+ } else {
+ TQSize hint = box->tqsizeHint();
+ TQSize minS = box->tqminimumSize();
+ rData[box->row].tqsizeHint = TQMAX( hint.height(),
+ rData[box->row].tqsizeHint );
+ rData[box->row].tqminimumSize = TQMAX( minS.height(),
+ rData[box->row].tqminimumSize );
+ }
+}
+
+/*
+ Similar to setupLayoutData(), but uses heightForWidth(colData)
+ instead of tqsizeHint(). Assumes that setupLayoutData() and
+ qGeomCalc(colData) has been called.
+*/
+void TQGridLayoutData::setupHfwLayoutData( int spacing )
+{
+ TQMemArray<TQLayoutStruct> &rData = *hfwData;
+ int i;
+ for ( i = 0; i < rr; i++ ) {
+ rData[i] = rowData[i];
+ rData[i].tqminimumSize = rData[i].tqsizeHint = 0;
+ }
+ TQPtrListIterator<TQGridBox> it( things );
+ TQGridBox * box;
+ while ( (box=it.current()) != 0 ) {
+ ++it;
+ addHfwData( box, colData[box->col].size );
+ }
+ if ( multi ) {
+ TQPtrListIterator<TQGridMultiBox> it( *multi );
+ TQGridMultiBox * mbox;
+ while ( (mbox=it.current()) != 0 ) {
+ ++it;
+ TQGridBox *box = mbox->box();
+ int r1 = box->row;
+ int c1 = box->col;
+ int r2 = mbox->torow;
+ int c2 = mbox->tocol;
+ if ( r2 < 0 )
+ r2 = rr-1;
+ if ( c2 < 0 )
+ c2 = cc-1;
+ int w = colData[c2].pos + colData[c2].size - colData[c1].pos;
+ if ( r1 == r2 ) {
+ addHfwData( box, w );
+ } else {
+ TQSize hint = box->tqsizeHint();
+ TQSize min = box->tqminimumSize();
+ if ( box->hasHeightForWidth() ) {
+ int hfwh = box->heightForWidth( w );
+ if ( hfwh > hint.height() )
+ hint.setHeight( hfwh );
+ if ( hfwh > min.height() )
+ min.setHeight( hfwh );
+ }
+ distributeMultiBox( rData, spacing, r1, r2,
+ min.height(), hint.height(),
+ rStretch, box->vStretch() );
+ }
+ }
+ }
+ for ( i = 0; i < rr; i++ )
+ rData[i].expansive = rData[i].expansive || rData[i].stretch > 0;
+}
+
+void TQGridLayoutData::distribute( TQRect r, int spacing )
+{
+ bool visualHReversed = hReversed;
+ if ( TQApplication::reverseLayout() )
+ visualHReversed = !visualHReversed;
+
+ setupLayoutData( spacing );
+
+ qGeomCalc( colData, 0, cc, r.x(), r.width(), spacing );
+ TQMemArray<TQLayoutStruct> *rDataPtr;
+ if ( has_hfw ) {
+ recalcHFW( r.width(), spacing );
+ qGeomCalc( *hfwData, 0, rr, r.y(), r.height(), spacing );
+ rDataPtr = hfwData;
+ } else {
+ qGeomCalc( rowData, 0, rr, r.y(), r.height(), spacing );
+ rDataPtr = &rowData;
+ }
+ TQMemArray<TQLayoutStruct> &rData = *rDataPtr;
+
+ TQPtrListIterator<TQGridBox> it( things );
+ TQGridBox * box;
+ while ( (box=it.current()) != 0 ) {
+ ++it;
+ int x = colData[box->col].pos;
+ int y = rData[box->row].pos;
+ int w = colData[box->col].size;
+ int h = rData[box->row].size;
+ if ( visualHReversed )
+ x = r.left() + r.right() - x - w + 1;
+ if ( vReversed )
+ y = r.top() + r.bottom() - y - h + 1;
+ box->setGeometry( TQRect( x, y, w, h ) );
+ }
+ if ( multi ) {
+ TQPtrListIterator<TQGridMultiBox> it( *multi );
+ TQGridMultiBox * mbox;
+ while ( (mbox=it.current()) != 0 ) {
+ ++it;
+ TQGridBox *box = mbox->box();
+ int r2 = mbox->torow;
+ int c2 = mbox->tocol;
+ if ( r2 < 0 )
+ r2 = rr-1;
+ if ( c2 < 0 )
+ c2 = cc-1;
+
+ int x = colData[box->col].pos;
+ int y = rData[box->row].pos;
+ int x2p = colData[c2].pos + colData[c2].size; // x2+1
+ int y2p = rData[r2].pos + rData[r2].size; // y2+1
+ int w = x2p - x;
+ int h = y2p - y;
+ // this code is copied from above:
+ if ( visualHReversed )
+ x = r.left() + r.right() - x - w + 1;
+ if ( vReversed )
+ y = r.top() + r.bottom() - y - h + 1;
+ box->setGeometry( TQRect( x, y, w, h ) );
+ }
+ }
+}
+
+TQRect TQGridLayoutData::cellGeometry( int row, int col ) const
+{
+ if ( row < 0 || row >= rr || col < 0 || col >= cc )
+ return TQRect();
+
+ const TQMemArray<TQLayoutStruct> *rDataPtr;
+ if ( has_hfw )
+ rDataPtr = hfwData;
+ else
+ rDataPtr = &rowData;
+ return TQRect( colData[col].pos, (*rDataPtr)[row].pos,
+ colData[col].size, (*rDataPtr)[row].size );
+}
+
+class TQGridLayoutDataIterator : public TQGLayoutIterator
+{
+public:
+ TQGridLayoutDataIterator( TQGridLayoutData *d );
+ uint count() const { return data->count(); }
+ TQLayoutItem *current() {
+ if ( multi ) {
+ if ( !data->multi || idx >= (int)data->multi->count() )
+ return 0;
+ return data->multi->at( idx )->box()->item();
+ } else {
+ if ( idx >= (int)data->things.count() )
+ return 0;
+ return data->things.at( idx )->item();
+ }
+ }
+ void toFirst() {
+ multi = data->things.isEmpty();
+ idx = 0;
+ }
+ TQLayoutItem *next() {
+ idx++;
+ if ( !multi && idx >= (int)data->things.count() ) {
+ multi = TRUE;
+ idx = 0;
+ }
+ return current();
+ }
+ TQLayoutItem *takeCurrent() {
+ TQLayoutItem *item = 0;
+ if ( multi ) {
+ if ( !data->multi || idx >= (int)data->multi->count() )
+ return 0;
+ TQGridMultiBox *b = data->multi->take( idx );
+ item = b->takeItem();
+ delete b;
+ } else {
+ if ( idx >= (int)data->things.count() )
+ return 0;
+ TQGridBox *b = data->things.take( idx );
+ item = b->takeItem();
+ delete b;
+ }
+ return item;
+ }
+
+private:
+ TQGridLayoutData *data;
+ bool multi;
+ int idx;
+};
+
+inline TQGridLayoutDataIterator::TQGridLayoutDataIterator( TQGridLayoutData *d )
+ : data( d )
+{
+ toFirst();
+}
+
+/*!
+ \class TQGridLayout
+
+ \brief The TQGridLayout class lays out widgets in a grid.
+
+ \ingroup geomanagement
+ \ingroup appearance
+ \mainclass
+
+ TQGridLayout takes the space made available to it (by its tqparent
+ tqlayout or by the mainWidget()), divides it up into rows and
+ columns, and puts each widget it manages into the correct cell.
+
+ Columns and rows behave identically; we will discuss columns, but
+ there are equivalent functions for rows.
+
+ Each column has a minimum width and a stretch factor. The minimum
+ width is the greatest of that set using addColSpacing() and the
+ minimum width of each widget in that column. The stretch factor is
+ set using setColStretch() and determines how much of the available
+ space the column will get over and above its necessary minimum.
+
+ Normally, each managed widget or tqlayout is put into a cell of its
+ own using addWidget(), addLayout() or by the \link
+ TQLayout::setAutoAdd() auto-add facility\endlink. It is also
+ possible for a widget to occupy multiple cells using
+ addMultiCellWidget(). If you do this, TQGridLayout will guess how
+ to distribute the size over the columns/rows (based on the stretch
+ factors).
+
+ To remove a widget from a tqlayout, call remove(). Calling
+ TQWidget::hide() on a widget also effectively removes the widget
+ from the tqlayout until TQWidget::show() is called.
+
+ This illustration shows a fragment of a dialog with a five-column,
+ three-row grid (the grid is shown overlaid in magenta):
+
+ \img gridtqlayout.png
+
+ Columns 0, 2 and 4 in this dialog fragment are made up of a
+ TQLabel, a TQLineEdit, and a TQListBox. Columns 1 and 3 are
+ placeholders made with addColSpacing(). Row 0 consists of three
+ TQLabel objects, row 1 of three TQLineEdit objects and row 2 of
+ three TQListBox objects. We used placeholder columns (1 and 3) to
+ get the right amount of space between the columns.
+
+ Note that the columns and rows are not equally wide or tall. If
+ you want two columns to have the same width, you must set their
+ minimum widths and stretch factors to be the same yourself. You do
+ this using addColSpacing() and setColStretch().
+
+ If the TQGridLayout is not the top-level tqlayout (i.e. does not
+ manage all of the widget's area and tqchildren), you must add it to
+ its tqparent tqlayout when you create it, but before you do anything
+ with it. The normal way to add a tqlayout is by calling
+ parentLayout-\>addLayout().
+
+ Once you have added your tqlayout you can start putting widgets and
+ other layouts into the cells of your grid tqlayout using
+ addWidget(), addLayout() and addMultiCellWidget().
+
+ TQGridLayout also includes two margin widths: the border and the
+ spacing. The border is the width of the reserved space along each
+ of the TQGridLayout's four sides. The spacing is the width of the
+ automatically allocated spacing between neighboring boxes.
+
+ Both the border and the spacing are parameters of the constructor
+ and default to 0.
+
+ \sa TQGrid, \link tqlayout.html Layout Overview \endlink
+*/
+
+/*
+ Returns TRUE if the widget \a w can be added to the tqlayout \a l;
+ otherwise returns FALSE.
+*/
+static bool checkWidget( TQLayout *l, TQWidget *w )
+{
+ if ( !w ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQLayout: Cannot add null widget to %s/%s", l->className(),
+ l->name() );
+#endif
+ return FALSE;
+ }
+ if ( w->parentWidget() != l->mainWidget() && l->mainWidget() ) {
+#if defined(TQT_CHECK_STATE)
+ if ( w->parentWidget() )
+ qWarning( "TQLayout: Adding %s/%s (child of %s/%s) to tqlayout for "
+ "%s/%s", w->className(), w->name(),
+ w->parentWidget()->className(), w->parentWidget()->name(),
+ l->mainWidget()->className(), l->mainWidget()->name() );
+ else
+ qWarning( "TQLayout: Adding %s/%s (top-level widget) to tqlayout for"
+ " %s/%s", w->className(), w->name(),
+ l->mainWidget()->className(), l->mainWidget()->name() );
+#endif
+ return FALSE;
+ }
+ return TRUE;
+}
+
+// #ifdef USE_QT4
+//
+// #else // USE_QT4
+
+/*!
+ \enum TQGridLayout::Corner
+
+ This enum identifies which corner is the origin (0, 0) of the
+ tqlayout.
+
+ \value TopLeft the top-left corner
+ \value TopRight the top-right corner
+ \value BottomLeft the bottom-left corner
+ \value BottomRight the bottom-right corner
+*/
+
+/*!
+ Constructs a new TQGridLayout with \a nRows rows, \a nCols columns
+ and tqparent widget, \a tqparent. \a tqparent may not be 0. The grid
+ tqlayout is called \a name.
+
+ \a margin is the number of pixels between the edge of the widget
+ and its managed tqchildren. \a space is the default number of pixels
+ between cells. If \a space is -1, the value of \a margin is used.
+*/
+TQGridLayout::TQGridLayout( TQWidget *tqparent, int nRows, int nCols, int margin,
+ int space, const char *name )
+ : TQLayout( tqparent, margin, space, name )
+{
+ init( nRows, nCols );
+}
+
+/*!
+ Constructs a new grid that is placed inside \a parentLayout with
+ \a nRows rows and \a nCols columns. If \a spacing is -1, this
+ TQGridLayout inherits its tqparent's spacing(); otherwise \a spacing
+ is used. The grid tqlayout is called \a name.
+
+ This grid is placed according to \a parentLayout's default
+ placement rules.
+*/
+TQGridLayout::TQGridLayout( TQLayout *parentLayout, int nRows, int nCols,
+ int spacing, const char *name )
+ : TQLayout( parentLayout, spacing, name )
+{
+ init( nRows, nCols );
+}
+
+/*!
+ Constructs a new grid with \a nRows rows and \a nCols columns. If
+ \a spacing is -1, this TQGridLayout inherits its tqparent's
+ spacing(); otherwise \a spacing is used. The grid tqlayout is called
+ \a name.
+
+ You must insert this grid into another tqlayout. You can insert
+ widgets and layouts into this tqlayout at any time, but laying out
+ will not be performed before this is inserted into another tqlayout.
+*/
+TQGridLayout::TQGridLayout( int nRows, int nCols,
+ int spacing, const char *name )
+ : TQLayout( spacing, name )
+{
+ init( nRows, nCols );
+}
+
+/*!
+ Destroys the grid tqlayout. Geometry management is terminated if
+ this is a top-level grid.
+
+ The tqlayout's widgets aren't destroyed.
+*/
+TQGridLayout::~TQGridLayout()
+{
+ delete data;
+}
+
+/*!
+ Returns the number of rows in this grid.
+*/
+int TQGridLayout::numRows() const
+{
+ return data->numRows();
+}
+
+/*!
+ Returns the number of columns in this grid.
+*/
+int TQGridLayout::numCols() const
+{
+ return data->numCols();
+}
+
+/*!
+ Returns the preferred size of this grid.
+*/
+TQSize TQGridLayout::tqsizeHint() const
+{
+ return data->tqsizeHint( spacing() ) + TQSize( 2 * margin(), 2 * margin() );
+}
+
+/*!
+ Returns the minimum size needed by this grid.
+*/
+TQSize TQGridLayout::tqminimumSize() const
+{
+ return data->tqminimumSize( spacing() ) + TQSize( 2 * margin(), 2 * margin() );
+}
+
+/*!
+ Returns the maximum size needed by this grid.
+*/
+TQSize TQGridLayout::tqmaximumSize() const
+{
+ TQSize s = data->tqmaximumSize( spacing() ) +
+ TQSize( 2 * margin(), 2 * margin() );
+ s = s.boundedTo( TQSize(TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX) );
+ if ( tqalignment() & TQt::AlignHorizontal_Mask )
+ s.setWidth( TQLAYOUTSIZE_MAX );
+ if ( tqalignment() & TQt::AlignVertical_Mask )
+ s.setHeight( TQLAYOUTSIZE_MAX );
+ return s;
+}
+
+/*!
+ Returns TRUE if this tqlayout's preferred height depends on its
+ width; otherwise returns FALSE.
+*/
+bool TQGridLayout::hasHeightForWidth() const
+{
+ return ((TQGridLayout*)this)->data->hasHeightForWidth( spacing() );
+}
+
+/*!
+ Returns the tqlayout's preferred height when it is \a w pixels wide.
+*/
+int TQGridLayout::heightForWidth( int w ) const
+{
+ TQGridLayout *that = (TQGridLayout*)this;
+ return that->data->heightForWidth( w, margin(), spacing() );
+}
+
+/*! \internal */
+int TQGridLayout::minimumHeightForWidth( int w ) const
+{
+ TQGridLayout *that = (TQGridLayout*)this;
+ return that->data->minimumHeightForWidth( w, margin(), spacing() );
+}
+
+/*!
+ Searches for widget \a w in this tqlayout (not including child
+ layouts). If \a w is found, it sets \c \a row and \c \a col to
+ the row and column and returns TRUE; otherwise returns FALSE.
+
+ Note: if a widget spans multiple rows/columns, the top-left cell
+ is returned.
+*/
+bool TQGridLayout::tqfindWidget( TQWidget* w, int *row, int *col )
+{
+ return data->tqfindWidget( w, row, col );
+}
+
+/*!
+ Resizes managed widgets within the rectangle \a r.
+*/
+void TQGridLayout::setGeometry( const TQRect &r )
+{
+ if ( data->isDirty() || r != tqgeometry() ) {
+ TQLayout::setGeometry( r );
+ TQRect cr = tqalignment() ? alignmentRect( r ) : r;
+ TQRect s( cr.x() + margin(), cr.y() + margin(),
+ cr.width() - 2 * margin(), cr.height() - 2 * margin() );
+ data->distribute( s, spacing() );
+ }
+}
+
+/*!
+ Returns the tqgeometry of the cell with row \a row and column \a col
+ in the grid. Returns an invalid rectangle if \a row or \a col is
+ outside the grid.
+
+ \warning in the current version of TQt this function does not
+ return valid results until setGeometry() has been called, i.e.
+ after the mainWidget() is visible.
+*/
+TQRect TQGridLayout::cellGeometry( int row, int col ) const
+{
+ return data->cellGeometry( row, col );
+}
+
+/*!
+ Expands this grid so that it will have \a nRows rows and \a nCols
+ columns. Will not shrink the grid. You should not need to call
+ this function because TQGridLayout expands automatically as new
+ items are inserted.
+*/
+void TQGridLayout::expand( int nRows, int nCols )
+{
+ data->expand( nRows, nCols );
+}
+
+/*!
+ Sets up the grid.
+*/
+void TQGridLayout::init( int nRows, int nCols )
+{
+ setSupportsMargin( TRUE );
+ data = new TQGridLayoutData( nRows, nCols );
+}
+
+/*!
+ \overload
+
+ Adds \a item to the next free position of this tqlayout.
+*/
+void TQGridLayout::addItem( QLayoutItem *item )
+{
+ int r, c;
+ data->getNextPos( r, c );
+ add( TQT_TQLAYOUTITEM(item), r, c );
+}
+
+/*!
+ Adds \a item at position \a row, \a col. The tqlayout takes
+ ownership of the \a item.
+*/
+void TQGridLayout::addItem( QLayoutItem *item, int row, int col )
+{
+ add( TQT_TQLAYOUTITEM(item), row, col );
+}
+
+/*!
+ Adds \a item at position \a row, \a col. The tqlayout takes
+ ownership of the \a item.
+*/
+void TQGridLayout::add( TQLayoutItem *item, int row, int col )
+{
+ TQGridBox *box = new TQGridBox( item );
+ data->add( box, row, col );
+}
+
+/*!
+ Adds the \a item to the cell grid, spanning multiple rows/columns.
+
+ The cell will span from \a fromRow, \a fromCol to \a toRow, \a
+ toCol. Alignment is specified by \a tqalignment, which is a bitwise
+ OR of \l TQt::AlignmentFlags values. The default tqalignment is 0,
+ which means that the widget fills the entire cell.
+*/
+void TQGridLayout::addMultiCell( QLayoutItem *item, int fromRow, int toRow,
+ int fromCol, int toCol, int tqalignment )
+{
+ TQGridBox *b = new TQGridBox( TQT_TQLAYOUTITEM(item) );
+ b->tqsetAlignment( tqalignment );
+ data->add( b, fromRow, toRow, fromCol, toCol );
+}
+
+/*!
+ Adds the widget \a w to the cell grid at \a row, \a col. The
+ top-left position is (0, 0) by default.
+
+ Alignment is specified by \a tqalignment, which is a bitwise OR of
+ \l TQt::AlignmentFlags values. The default tqalignment is 0, which
+ means that the widget fills the entire cell.
+
+ \list
+ \i You should not call this if you have enabled the
+ \link TQLayout::setAutoAdd() auto-add facility of the tqlayout\endlink.
+
+ \i From TQt 3.0, the \a tqalignment parameter is interpreted more
+ aggressively than in previous versions of TQt. A non-default
+ tqalignment now indicates that the widget should not grow to fill
+ the available space, but should be sized according to tqsizeHint().
+ \endlist
+
+ \sa addMultiCellWidget()
+*/
+void TQGridLayout::addWidget( TQWidget *w, int row, int col, int tqalignment )
+{
+ if ( !checkWidget( this, w ) )
+ return;
+ if ( row < 0 || col < 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQGridLayout: Cannot add %s/%s to %s/%s at row %d col %d",
+ w->className(), w->name(), className(), name(), row, col );
+#endif
+ return;
+ }
+ TQWidgetItem *b = new TQWidgetItem( w );
+ b->tqsetAlignment( tqalignment );
+ add( b, row, col );
+}
+
+/*!
+ Adds the widget \a w to the cell grid, spanning multiple
+ rows/columns. The cell will span from \a fromRow, \a fromCol to \a
+ toRow, \a toCol.
+
+ Alignment is specified by \a tqalignment, which is a bitwise OR of
+ \l TQt::AlignmentFlags values. The default tqalignment is 0, which
+ means that the widget fills the entire cell.
+
+ A non-zero tqalignment indicates that the widget should not grow to
+ fill the available space but should be sized according to
+ tqsizeHint().
+
+ \sa addWidget()
+*/
+void TQGridLayout::addMultiCellWidget( TQWidget *w, int fromRow, int toRow,
+ int fromCol, int toCol, int tqalignment )
+{
+ TQGridBox *b = new TQGridBox( w );
+ b->tqsetAlignment( tqalignment );
+ data->add( b, fromRow, toRow, fromCol, toCol );
+}
+
+/*!
+ Places the \a tqlayout at position (\a row, \a col) in the grid. The
+ top-left position is (0, 0).
+
+ \a tqlayout becomes a child of the grid tqlayout.
+
+ When a tqlayout is constructed with another tqlayout as its tqparent,
+ you don't need to call addLayout(); the child tqlayout is
+ automatically added to the tqparent tqlayout as it is constructed.
+
+ \sa addMultiCellLayout()
+*/
+void TQGridLayout::addLayout( TQLayout *tqlayout, int row, int col )
+{
+ addChildLayout( tqlayout );
+ add( TQT_TQLAYOUTITEM(tqlayout), row, col );
+}
+
+/*!
+ Adds the tqlayout \a tqlayout to the cell grid, spanning multiple
+ rows/columns. The cell will span from \a fromRow, \a fromCol to \a
+ toRow, \a toCol.
+
+ Alignment is specified by \a tqalignment, which is a bitwise OR of
+ \l TQt::AlignmentFlags values. The default tqalignment is 0, which
+ means that the widget fills the entire cell.
+
+ A non-zero tqalignment indicates that the tqlayout should not grow to
+ fill the available space but should be sized according to
+ tqsizeHint().
+
+ \a tqlayout becomes a child of the grid tqlayout.
+
+ \sa addLayout()
+*/
+void TQGridLayout::addMultiCellLayout( TQLayout *tqlayout, int fromRow, int toRow,
+ int fromCol, int toCol, int tqalignment )
+{
+ addChildLayout( tqlayout );
+ TQGridBox *b = new TQGridBox( TQT_TQLAYOUTITEM(tqlayout) );
+ b->tqsetAlignment( tqalignment );
+ data->add( b, fromRow, toRow, fromCol, toCol );
+}
+
+/*!
+ Sets the stretch factor of row \a row to \a stretch. The first row
+ is number 0.
+
+ The stretch factor is relative to the other rows in this grid.
+ Rows with a higher stretch factor take more of the available
+ space.
+
+ The default stretch factor is 0. If the stretch factor is 0 and no
+ other row in this table can grow at all, the row may still grow.
+
+ \sa rowStretch(), setRowSpacing(), setColStretch()
+*/
+void TQGridLayout::setRowStretch( int row, int stretch )
+{
+ data->setRowStretch( row, stretch );
+}
+
+/*!
+ Returns the stretch factor for row \a row.
+
+ \sa setRowStretch()
+*/
+int TQGridLayout::rowStretch( int row ) const
+{
+ return data->rowStretch( row );
+}
+
+/*!
+ Returns the stretch factor for column \a col.
+
+ \sa setColStretch()
+*/
+int TQGridLayout::colStretch( int col ) const
+{
+ return data->colStretch( col );
+}
+
+/*!
+ Sets the stretch factor of column \a col to \a stretch. The first
+ column is number 0.
+
+ The stretch factor is relative to the other columns in this grid.
+ Columns with a higher stretch factor take more of the available
+ space.
+
+ The default stretch factor is 0. If the stretch factor is 0 and no
+ other column in this table can grow at all, the column may still
+ grow.
+
+ \sa colStretch(), addColSpacing(), setRowStretch()
+*/
+void TQGridLayout::setColStretch( int col, int stretch )
+{
+ data->setColStretch( col, stretch );
+}
+
+#if TQT_VERSION >= 0x040000
+#error "Make add{Row,Col}Spacing() inline TQT_NO_COMPAT functions defined in terms of set{Row,Col}Spacing()"
+#endif
+
+/*!
+ \obsolete
+
+ Sets the minimum height of row \a row to \a minsize pixels.
+
+ Use setRowSpacing() instead.
+*/
+void TQGridLayout::addRowSpacing( int row, int minsize )
+{
+ TQLayoutItem *b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, minsize ));
+ add( b, row, 0 );
+}
+
+/*!
+ \obsolete
+
+ Sets the minimum width of column \a col to \a minsize pixels.
+
+ Use setColSpacing() instead.
+*/
+void TQGridLayout::addColSpacing( int col, int minsize )
+{
+ TQLayoutItem *b = TQT_TQLAYOUTITEM(new TQSpacerItem( minsize, 0 ));
+ add( b, 0, col );
+}
+
+/*!
+ Sets the minimum height of row \a row to \a minSize pixels.
+
+ \sa rowSpacing(), setColSpacing()
+*/
+void TQGridLayout::setRowSpacing( int row, int minSize )
+{
+ data->setRowSpacing( row, minSize );
+}
+
+/*!
+ Returns the row spacing for row \a row.
+
+ \sa setRowSpacing()
+*/
+int TQGridLayout::rowSpacing( int row ) const
+{
+ return data->rowSpacing( row );
+}
+
+/*!
+ Sets the minimum width of column \a col to \a minSize pixels.
+
+ \sa colSpacing(), setRowSpacing()
+*/
+void TQGridLayout::setColSpacing( int col, int minSize )
+{
+ data->setColSpacing( col, minSize );
+}
+
+/*!
+ Returns the column spacing for column \a col.
+
+ \sa setColSpacing()
+*/
+int TQGridLayout::colSpacing( int col ) const
+{
+ return data->colSpacing( col );
+}
+
+/*!
+ Returns whether this tqlayout can make use of more space than
+ tqsizeHint(). A value of \c Vertical or \c Horizontal means that it wants
+ to grow in only one dimension, whereas \c BothDirections means that
+ it wants to grow in both dimensions.
+*/
+TQ_SPExpandData TQGridLayout::expandingDirections() const
+{
+ return data->expanding( spacing() );
+}
+
+/*!
+ Sets the grid's origin corner, i.e. position (0, 0), to \a c.
+*/
+void TQGridLayout::setOrigin( Corner c )
+{
+ data->setReversed( c == BottomLeft || c == BottomRight,
+ c == TopRight || c == BottomRight );
+}
+
+/*!
+ Returns the corner that's used for the grid's origin, i.e. for
+ position (0, 0).
+*/
+TQGridLayout::Corner TQGridLayout::origin() const
+{
+ if ( data->horReversed() ) {
+ return data->verReversed() ? BottomRight : TopRight;
+ } else {
+ return data->verReversed() ? BottomLeft : TopLeft;
+ }
+}
+
+/*!
+ Resets cached information.
+*/
+void TQGridLayout::tqinvalidate()
+{
+ TQLayout::tqinvalidate();
+ TQLayout::setGeometry( TQRect() ); // for binary compatibility (?)
+ data->setDirty();
+}
+
+/*! \reimp */
+// TQLayoutIterator TQGridLayout::iterator()
+// {
+// return TQLayoutIterator( new TQGridLayoutDataIterator(data) );
+// }
+
+#ifdef USE_QT4
+
+/*!
+ \reimp
+*/
+int TQGridLayout::count() const {
+ return data->count();
+}
+
+/*!
+ \reimp
+*/
+TQLayoutItem* TQGridLayout::itemAt(int index) const {
+ TQGridLayoutDataIterator tqgli = TQGridLayoutDataIterator(data);
+ for (int i=0; i<index; i++) { tqgli.next(); }
+ return index >= 0 && index < data->count() ? tqgli.current() : 0;
+}
+
+/*!
+ \reimp
+*/
+TQLayoutItem* TQGridLayout::takeAt(int index) {
+ if (index < 0 || index >= data->count())
+ return 0;
+ TQGridLayoutDataIterator tqgli = TQGridLayoutDataIterator(data);
+ for (int i=0; i<index; i++) { tqgli.next(); }
+ return tqgli.takeCurrent();
+}
+
+#endif // USE_QT4
+
+// #endif // USE_QT4
+
+struct TQBoxLayoutItem
+{
+ TQBoxLayoutItem( TQLayoutItem *it, int stretch_ = 0 )
+ : item( it ), stretch( stretch_ ), magic( FALSE ) { }
+ ~TQBoxLayoutItem() { delete item; }
+
+ int hfw( int w ) {
+ if ( item->hasHeightForWidth() ) {
+ return item->heightForWidth( w );
+ } else {
+ return item->sizeHint().height();
+ }
+ }
+ int mhfw( int w ) {
+ if ( item->hasHeightForWidth() ) {
+ return item->heightForWidth( w );
+ } else {
+ return item->minimumSize().height();
+ }
+ }
+ int hStretch() {
+ if ( stretch == 0 && item->widget() ) {
+ return TQT_TQSIZEPOLICY_OBJECT(item->widget()->sizePolicy()).horStretch();
+ } else {
+ return stretch;
+ }
+ }
+ int vStretch() {
+ if ( stretch == 0 && item->widget() ) {
+ return TQT_TQSIZEPOLICY_OBJECT(item->widget()->sizePolicy()).verStretch();
+ } else {
+ return stretch;
+ }
+ }
+
+ TQLayoutItem *item;
+ int stretch;
+ bool magic;
+};
+
+class TQBoxLayoutData
+{
+public:
+ TQBoxLayoutData() : geomArray( 0 ), hfwWidth( -1 ), dirty( TRUE )
+ { list.setAutoDelete( TRUE ); }
+
+ ~TQBoxLayoutData() { delete geomArray; }
+ void setDirty() {
+ delete geomArray;
+ geomArray = 0;
+ hfwWidth = -1;
+ hfwHeight = -1;
+ dirty = TRUE;
+ }
+
+ TQPtrList<TQBoxLayoutItem> list;
+ TQMemArray<TQLayoutStruct> *geomArray;
+ int hfwWidth;
+ int hfwHeight;
+ int hfwMinHeight;
+ TQSize tqsizeHint;
+ TQSize minSize;
+ TQSize maxSize;
+ TQ_SPExpandData expanding;
+ uint hasHfw : 1;
+ uint dirty : 1;
+};
+
+class TQBoxLayoutIterator : public TQGLayoutIterator
+{
+public:
+ TQBoxLayoutIterator( TQBoxLayoutData *d ) : data( d ), idx( 0 ) {}
+ TQLayoutItem *current() {
+ if ( idx >= int(data->list.count()) )
+ return 0;
+ return data->list.at(idx)->item;
+ }
+ TQLayoutItem *next() {
+ idx++;
+ return current();
+ }
+ TQLayoutItem *takeCurrent() {
+ TQLayoutItem *item = 0;
+
+ TQBoxLayoutItem *b = data->list.take( idx );
+ if ( b ) {
+ item = b->item;
+ b->item = 0;
+ delete b;
+ }
+ data->setDirty();
+ return item;
+ }
+
+private:
+ TQBoxLayoutData *data;
+ int idx;
+};
+
+/*!
+ \class TQBoxLayout
+
+ \brief The TQBoxLayout class lines up child widgets horizontally or
+ vertically.
+
+ \ingroup geomanagement
+ \ingroup appearance
+
+ TQBoxLayout takes the space it gets (from its tqparent tqlayout or from
+ the mainWidget()), divides it up into a row of boxes, and makes
+ each managed widget fill one box.
+
+ \img qhbox-m.png Horizontal box with five child widgets
+
+ If the TQBoxLayout's orientation is \c Horizontal the boxes are
+ placed in a row, with suitable sizes. Each widget (or other box)
+ will get at least its minimum size and at most its maximum size.
+ Any excess space is shared according to the stretch factors (more
+ about that below).
+
+ \img qvbox-m.png Vertical box with five child widgets
+
+ If the TQBoxLayout's orientation is \c Vertical, the boxes are
+ placed in a column, again with suitable sizes.
+
+ The easiest way to create a TQBoxLayout is to use one of the
+ convenience classes, e.g. TQHBoxLayout (for \c Horizontal boxes) or
+ TQVBoxLayout (for \c Vertical boxes). You can also use the
+ TQBoxLayout constructor directly, specifying its direction as \c
+ LeftToRight, \c Down, \c RightToLeft or \c Up.
+
+ If the TQBoxLayout is not the top-level tqlayout (i.e. it is not
+ managing all of the widget's area and tqchildren), you must add it
+ to its tqparent tqlayout before you can do anything with it. The
+ normal way to add a tqlayout is by calling
+ parentLayout-\>addLayout().
+
+ Once you have done this, you can add boxes to the TQBoxLayout using
+ one of four functions:
+
+ \list
+ \i addWidget() to add a widget to the TQBoxLayout and set the
+ widget's stretch factor. (The stretch factor is along the row of
+ boxes.)
+
+ \i addSpacing() to create an empty box; this is one of the
+ functions you use to create nice and spacious dialogs. See below
+ for ways to set margins.
+
+ \i addStretch() to create an empty, stretchable box.
+
+ \i addLayout() to add a box containing another TQLayout to the row
+ and set that tqlayout's stretch factor.
+ \endlist
+
+ Use insertWidget(), insertSpacing(), insertStretch() or
+ insertLayout() to insert a box at a specified position in the
+ tqlayout.
+
+ TQBoxLayout also includes two margin widths:
+
+ \list
+ \i setMargin() sets the width of the outer border. This is the width
+ of the reserved space along each of the TQBoxLayout's four sides.
+ \i setSpacing() sets the width between neighboring boxes. (You
+ can use addSpacing() to get more space at a particular spot.)
+ \endlist
+
+ The margin defaults to 0. The spacing defaults to the same as the
+ margin width for a top-level tqlayout, or to the same as the tqparent
+ tqlayout. Both are parameters to the constructor.
+
+ To remove a widget from a tqlayout, call remove(). Calling
+ TQWidget::hide() on a widget also effectively removes the widget
+ from the tqlayout until TQWidget::show() is called.
+
+ You will almost always want to use TQVBoxLayout and TQHBoxLayout
+ rather than TQBoxLayout because of their convenient constructors.
+
+ \sa TQGrid \link tqlayout.html Layout Overview \endlink
+*/
+
+/*!
+ \enum TQBoxLayout::Direction
+
+ This type is used to determine the direction of a box tqlayout.
+
+ \value LeftToRight Horizontal, from left to right
+ \value RightToLeft Horizontal, from right to left
+ \value TopToBottom Vertical, from top to bottom
+ \value Down The same as \c TopToBottom
+ \value BottomToTop Vertical, from bottom to top
+ \value Up The same as \c BottomToTop
+*/
+
+static inline bool horz( TQBoxLayout::Direction dir )
+{
+ return dir == TQBoxLayout::RightToLeft || dir == TQBoxLayout::LeftToRight;
+}
+
+/*!
+ Constructs a new TQBoxLayout with direction \a d and main widget \a
+ tqparent. \a tqparent may not be 0.
+
+ The \a margin is the number of pixels between the edge of the
+ widget and its managed tqchildren. The \a spacing is the default
+ number of pixels between neighboring tqchildren. If \a spacing is -1
+ the value of \a margin is used for \a spacing.
+
+ \a name is the internal object name.
+
+ \sa direction()
+*/
+TQBoxLayout::TQBoxLayout( TQWidget *tqparent, Direction d,
+ int margin, int spacing, const char *name )
+ : TQLayout( tqparent, margin, spacing, name )
+{
+ data = new TQBoxLayoutData;
+ dir = d;
+ setSupportsMargin( TRUE );
+}
+
+/*!
+ Constructs a new TQBoxLayout called \a name, with direction \a d,
+ and inserts it into \a parentLayout.
+
+ The \a spacing is the default number of pixels between neighboring
+ tqchildren. If \a spacing is -1, the tqlayout will inherit its
+ tqparent's spacing().
+*/
+TQBoxLayout::TQBoxLayout( TQLayout *parentLayout, Direction d, int spacing,
+ const char *name )
+ : TQLayout( parentLayout, spacing, name )
+{
+ data = new TQBoxLayoutData;
+ dir = d;
+ setSupportsMargin( TRUE );
+}
+
+/*!
+ Constructs a new TQBoxLayout called \a name, with direction \a d.
+
+ If \a spacing is -1, the tqlayout will inherit its tqparent's
+ spacing(); otherwise \a spacing is used.
+
+ You must insert this box into another tqlayout.
+*/
+TQBoxLayout::TQBoxLayout( Direction d, int spacing, const char *name )
+ : TQLayout( spacing, name )
+{
+ data = new TQBoxLayoutData;
+ dir = d;
+ setSupportsMargin( TRUE );
+}
+
+/*!
+ Destroys this box tqlayout.
+
+ The tqlayout's widgets aren't destroyed.
+*/
+TQBoxLayout::~TQBoxLayout()
+{
+ delete data;
+}
+
+/*!
+ Returns the preferred size of this box tqlayout.
+*/
+TQSize TQBoxLayout::tqsizeHint() const
+{
+ if ( data->dirty ) {
+ TQBoxLayout *that = (TQBoxLayout*)this;
+ that->setupGeom();
+ }
+ return data->tqsizeHint + TQSize( 2 * margin(), 2 * margin() );
+}
+
+/*!
+ Returns the minimum size needed by this box tqlayout.
+*/
+TQSize TQBoxLayout::tqminimumSize() const
+{
+ if ( data->dirty ) {
+ TQBoxLayout *that = (TQBoxLayout*)this;
+ that->setupGeom();
+ }
+ return data->minSize + TQSize( 2 * margin(), 2 * margin() );
+}
+
+/*!
+ Returns the maximum size needed by this box tqlayout.
+*/
+TQSize TQBoxLayout::tqmaximumSize() const
+{
+ if ( data->dirty ) {
+ TQBoxLayout *that = (TQBoxLayout*)this;
+ that->setupGeom();
+ }
+ TQSize s = ( data->maxSize + TQSize(2 * margin(), 2 * margin()) )
+ .boundedTo(TQSize(TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX));
+ if ( tqalignment() & TQt::AlignHorizontal_Mask )
+ s.setWidth( TQLAYOUTSIZE_MAX );
+ if ( tqalignment() & TQt::AlignVertical_Mask )
+ s.setHeight( TQLAYOUTSIZE_MAX );
+ return s;
+}
+
+/*!
+ Returns TRUE if this tqlayout's preferred height depends on its width;
+ otherwise returns FALSE.
+*/
+bool TQBoxLayout::hasHeightForWidth() const
+{
+ if ( data->dirty ) {
+ TQBoxLayout *that = (TQBoxLayout*)this;
+ that->setupGeom();
+ }
+ return data->hasHfw;
+}
+
+/*!
+ Returns the tqlayout's preferred height when it is \a w pixels wide.
+*/
+int TQBoxLayout::heightForWidth( int w ) const
+{
+ if ( !hasHeightForWidth() )
+ return -1;
+ w -= 2 * margin();
+ if ( w != data->hfwWidth ) {
+ TQBoxLayout *that = (TQBoxLayout*)this;
+ that->calcHfw( w );
+ }
+ return data->hfwHeight + 2 * margin();
+}
+
+/*! \internal */
+int TQBoxLayout::minimumHeightForWidth( int w ) const
+{
+ (void) heightForWidth( w );
+ return data->hasHfw ? (data->hfwMinHeight + 2 * margin() ) : -1;
+}
+
+/*!
+ Resets cached information.
+*/
+void TQBoxLayout::tqinvalidate()
+{
+ TQLayout::tqinvalidate();
+ data->setDirty();
+}
+
+/*!
+ \reimp
+*/
+int TQBoxLayout::count() const {
+ return data->list.count();
+}
+
+/*!
+ \reimp
+*/
+TQLayoutItem* TQBoxLayout::itemAt(int index) const {
+ return index >= 0 && index < data->list.count() ? data->list.at(index)->item : 0;
+}
+
+/*!
+ \reimp
+*/
+TQLayoutItem* TQBoxLayout::takeAt(int index) {
+ if (index < 0 || index >= data->list.count())
+ return 0;
+ TQBoxLayoutItem *b = data->list.take(index);
+ TQLayoutItem *item = b->item;
+ b->item = 0;
+ delete b;
+
+ invalidate();
+ return item;
+}
+
+/*!
+ \reimp
+*/
+// TQLayoutIterator TQBoxLayout::iterator()
+// {
+// return TQLayoutIterator( new TQBoxLayoutIterator(data) );
+// }
+
+/*!
+ Returns whether this tqlayout can make use of more space than
+ tqsizeHint(). A value of \c Vertical or \c Horizontal means that it wants
+ to grow in only one dimension, whereas \c BothDirections means that
+ it wants to grow in both dimensions.
+*/
+TQ_SPExpandData TQBoxLayout::expandingDirections() const
+{
+ if ( data->dirty ) {
+ TQBoxLayout *that = (TQBoxLayout*)this;
+ that->setupGeom();
+ }
+ return data->expanding;
+}
+
+/*!
+ Resizes managed widgets within the rectangle \a r.
+*/
+void TQBoxLayout::setGeometry( const TQRect &r )
+{
+ if ( !data->geomArray || r != tqgeometry() ) {
+ TQLayout::setGeometry( r );
+ if ( !data->geomArray )
+ setupGeom();
+ TQRect cr = tqalignment() ? alignmentRect( r ) : r;
+ TQRect s( cr.x() + margin(), cr.y() + margin(),
+ cr.width() - 2 * margin(), cr.height() - 2 * margin() );
+
+ TQMemArray<TQLayoutStruct> a = *data->geomArray;
+ int pos = horz( dir ) ? s.x() : s.y();
+ int space = horz( dir ) ? s.width() : s.height();
+ int n = a.count();
+ if ( data->hasHfw && !horz(dir) ) {
+ for ( int i = 0; i < n; i++ ) {
+ TQBoxLayoutItem *box = data->list.at( i );
+ if ( box->item->hasHeightForWidth() )
+ a[i].tqsizeHint = a[i].tqminimumSize =
+ box->item->heightForWidth( s.width() );
+ }
+ }
+
+ Direction visualDir = dir;
+ if ( TQApplication::reverseLayout() ) {
+ if ( dir == LeftToRight )
+ visualDir = RightToLeft;
+ else if ( dir == RightToLeft )
+ visualDir = LeftToRight;
+ }
+
+ qGeomCalc( a, 0, n, pos, space, spacing() );
+ for ( int i = 0; i < n; i++ ) {
+ TQBoxLayoutItem *box = data->list.at( i );
+
+ switch ( visualDir ) {
+ case LeftToRight:
+ box->item->setGeometry( TQRect(a[i].pos, s.y(),
+ a[i].size, s.height()) );
+ break;
+ case RightToLeft:
+ box->item->setGeometry( TQRect(s.left() + s.right()
+ - a[i].pos - a[i].size + 1, s.y(),
+ a[i].size, s.height()) );
+ break;
+ case TopToBottom:
+ box->item->setGeometry( TQRect(s.x(), a[i].pos,
+ s.width(), a[i].size) );
+ break;
+ case BottomToTop:
+ box->item->setGeometry( TQRect(s.x(), s.top() + s.bottom()
+ - a[i].pos - a[i].size + 1,
+ s.width(), a[i].size) );
+ }
+ }
+ }
+}
+
+/*!
+ Adds \a item to the end of this box tqlayout.
+*/
+void TQBoxLayout::addItem( QLayoutItem *item )
+{
+ TQBoxLayoutItem *it = new TQBoxLayoutItem( static_cast<TQLayoutItem*>(item) );
+ data->list.append( it );
+ tqinvalidate();
+}
+
+/*!
+ Inserts \a item into this box tqlayout at position \a index. If \a
+ index is negative, the item is added at the end.
+
+ \warning Does not call TQLayout::insertChildLayout() if \a item is
+ a TQLayout.
+
+ \sa addItem(), tqfindWidget()
+*/
+void TQBoxLayout::insertItem( int index, TQLayoutItem *item )
+{
+ if ( index < 0 ) // append
+ index = data->list.count();
+
+ TQBoxLayoutItem *it = new TQBoxLayoutItem( item );
+ data->list.insert( index, it );
+ tqinvalidate();
+}
+
+/*!
+ Inserts a non-stretchable space at position \a index, with size \a
+ size. If \a index is negative the space is added at the end.
+
+ The box tqlayout has default margin and spacing. This function adds
+ additional space.
+
+ \sa insertStretch()
+*/
+void TQBoxLayout::insertSpacing( int index, int size )
+{
+ if ( index < 0 ) // append
+ index = data->list.count();
+
+ // hack in TQGridLayoutData: spacers do not get insideSpacing
+ TQLayoutItem *b;
+ if ( horz( dir ) )
+ b = TQT_TQLAYOUTITEM(new TQSpacerItem( size, 0, TQSizePolicy::Fixed,
+ TQSizePolicy::Minimum ));
+ else
+ b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, size, TQSizePolicy::Minimum,
+ TQSizePolicy::Fixed ));
+
+ TQBoxLayoutItem *it = new TQBoxLayoutItem( b );
+ it->magic = TRUE;
+ data->list.insert( index, it );
+ tqinvalidate();
+}
+
+/*!
+ Inserts a stretchable space at position \a index, with zero
+ minimum size and stretch factor \a stretch. If \a index is
+ negative the space is added at the end.
+
+ \sa insertSpacing()
+*/
+void TQBoxLayout::insertStretch( int index, int stretch )
+{
+ if ( index < 0 ) // append
+ index = data->list.count();
+
+ // hack in TQGridLayoutData: spacers do not get insideSpacing
+ TQLayoutItem *b;
+ if ( horz( dir ) )
+ b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, 0, TQSizePolicy::Expanding,
+ TQSizePolicy::Minimum ));
+ else
+ b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, 0, TQSizePolicy::Minimum,
+ TQSizePolicy::Expanding ));
+
+ TQBoxLayoutItem *it = new TQBoxLayoutItem( b, stretch );
+ it->magic = TRUE;
+ data->list.insert( index, it );
+ tqinvalidate();
+}
+
+/*!
+ Inserts \a tqlayout at position \a index, with stretch factor \a
+ stretch. If \a index is negative, the tqlayout is added at the end.
+
+ \a tqlayout becomes a child of the box tqlayout.
+
+ \sa setAutoAdd(), insertWidget(), insertSpacing()
+*/
+void TQBoxLayout::insertLayout( int index, TQLayout *tqlayout, int stretch )
+{
+ if ( index < 0 ) // append
+ index = data->list.count();
+
+ addChildLayout( tqlayout );
+ TQBoxLayoutItem *it = new TQBoxLayoutItem( TQT_TQLAYOUTITEM(tqlayout), stretch );
+ data->list.insert( index, it );
+ tqinvalidate();
+}
+
+/*!
+ Inserts \a widget at position \a index, with stretch factor \a
+ stretch and tqalignment \a tqalignment. If \a index is negative, the
+ widget is added at the end.
+
+ The stretch factor applies only in the \link direction() direction
+ \endlink of the TQBoxLayout, and is relative to the other boxes and
+ widgets in this TQBoxLayout. Widgets and boxes with higher stretch
+ factors grow more.
+
+ If the stretch factor is 0 and nothing else in the TQBoxLayout has
+ a stretch factor greater than zero, the space is distributed
+ according to the TQWidget:sizePolicy() of each widget that's
+ involved.
+
+ Alignment is specified by \a tqalignment, which is a bitwise OR of
+ \l TQt::AlignmentFlags values. The default tqalignment is 0, which
+ means that the widget fills the entire cell.
+
+ From TQt 3.0, the \a tqalignment parameter is interpreted more
+ aggressively than in previous versions of TQt. A non-default
+ tqalignment now indicates that the widget should not grow to fill
+ the available space, but should be sized according to tqsizeHint().
+
+ \sa setAutoAdd(), insertLayout(), insertSpacing()
+*/
+void TQBoxLayout::insertWidget( int index, TQWidget *widget, int stretch,
+ int tqalignment )
+{
+ if ( !checkWidget(this, widget) )
+ return;
+
+ if ( index < 0 ) // append
+ index = data->list.count();
+
+ TQWidgetItem *b = new TQWidgetItem( widget );
+ b->tqsetAlignment( tqalignment );
+ TQBoxLayoutItem *it = new TQBoxLayoutItem( b, stretch );
+ data->list.insert( index, it );
+ tqinvalidate();
+}
+
+/*!
+ Adds a non-stretchable space with size \a size to the end of this
+ box tqlayout. TQBoxLayout provides default margin and spacing. This
+ function adds additional space.
+
+ \sa insertSpacing(), addStretch()
+*/
+void TQBoxLayout::addSpacing( int size )
+{
+ insertSpacing( -1, size );
+}
+
+/*!
+ Adds a stretchable space with zero minimum size and stretch factor
+ \a stretch to the end of this box tqlayout.
+
+ \sa addSpacing()
+*/
+void TQBoxLayout::addStretch( int stretch )
+{
+ insertStretch( -1, stretch );
+}
+
+/*!
+ Adds \a widget to the end of this box tqlayout, with a stretch
+ factor of \a stretch and tqalignment \a tqalignment.
+
+ The stretch factor applies only in the \link direction() direction
+ \endlink of the TQBoxLayout, and is relative to the other boxes and
+ widgets in this TQBoxLayout. Widgets and boxes with higher stretch
+ factors grow more.
+
+ If the stretch factor is 0 and nothing else in the TQBoxLayout has
+ a stretch factor greater than zero, the space is distributed
+ according to the TQWidget:sizePolicy() of each widget that's
+ involved.
+
+ Alignment is specified by \a tqalignment which is a bitwise OR of \l
+ TQt::AlignmentFlags values. The default tqalignment is 0, which means
+ that the widget fills the entire cell.
+
+ From TQt 3.0, the \a tqalignment parameter is interpreted more
+ aggressively than in previous versions of TQt. A non-default
+ tqalignment now indicates that the widget should not grow to fill
+ the available space, but should be sized according to tqsizeHint().
+
+ \sa insertWidget(), setAutoAdd(), addLayout(), addSpacing()
+*/
+void TQBoxLayout::addWidget( TQWidget *widget, int stretch,
+ int tqalignment )
+{
+ insertWidget( -1, widget, stretch, tqalignment );
+}
+
+/*!
+ Adds \a tqlayout to the end of the box, with serial stretch factor
+ \a stretch.
+
+ When a tqlayout is constructed with another tqlayout as its tqparent,
+ you don't need to call addLayout(); the child tqlayout is
+ automatically added to the tqparent tqlayout as it is constructed.
+
+ \sa insertLayout(), setAutoAdd(), addWidget(), addSpacing()
+*/
+void TQBoxLayout::addLayout( TQLayout *tqlayout, int stretch )
+{
+ insertLayout( -1, tqlayout, stretch );
+}
+
+/*!
+ Limits the perpendicular dimension of the box (e.g. height if the
+ box is LeftToRight) to a minimum of \a size. Other constraints may
+ increase the limit.
+*/
+void TQBoxLayout::addStrut( int size )
+{
+ TQLayoutItem *b;
+ if ( horz( dir ) )
+ b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, size, TQSizePolicy::Fixed,
+ TQSizePolicy::Minimum ));
+ else
+ b = TQT_TQLAYOUTITEM(new TQSpacerItem( size, 0, TQSizePolicy::Minimum,
+ TQSizePolicy::Fixed ));
+
+ TQBoxLayoutItem *it = new TQBoxLayoutItem( b );
+ it->magic = TRUE;
+ data->list.append( it );
+ tqinvalidate();
+}
+
+/*!
+ Searches for widget \a w in this tqlayout (not including child
+ layouts).
+
+ Returns the index of \a w, or -1 if \a w is not found.
+*/
+int TQBoxLayout::tqfindWidget( TQWidget* w )
+{
+ const int n = data->list.count();
+ for ( int i = 0; i < n; i++ ) {
+ if ( data->list.at(i)->item->widget() == w )
+ return i;
+ }
+ return -1;
+}
+
+/*!
+ Sets the stretch factor for widget \a w to \a stretch and returns
+ TRUE if \a w is found in this tqlayout (not including child
+ layouts); otherwise returns FALSE.
+*/
+bool TQBoxLayout::setStretchFactor( TQWidget *w, int stretch )
+{
+ TQPtrListIterator<TQBoxLayoutItem> it( data->list );
+ TQBoxLayoutItem *box;
+ while ( (box=it.current()) != 0 ) {
+ ++it;
+ if ( box->item->widget() == w ) {
+ box->stretch = stretch;
+ tqinvalidate();
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*!
+ \overload
+
+ Sets the stretch factor for the tqlayout \a l to \a stretch and
+ returns TRUE if \a l is found in this tqlayout (not including child
+ layouts); otherwise returns FALSE.
+*/
+bool TQBoxLayout::setStretchFactor( TQLayout *l, int stretch )
+{
+ TQPtrListIterator<TQBoxLayoutItem> it( data->list );
+ TQBoxLayoutItem *box;
+ while ( (box=it.current()) != 0 ) {
+ ++it;
+ if ( box->item->tqlayout() == l ) {
+ box->stretch = stretch;
+ tqinvalidate();
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*!
+ Sets the direction of this tqlayout to \a direction.
+*/
+void TQBoxLayout::setDirection( Direction direction )
+{
+ if ( dir == direction )
+ return;
+ if ( horz(dir) != horz(direction) ) {
+ //swap around the spacers (the "magic" bits)
+ //#### a bit yucky, knows too much.
+ //#### probably best to add access functions to tqspacerItem
+ //#### or even a TQSpacerItem::flip()
+ TQPtrListIterator<TQBoxLayoutItem> it( data->list );
+ TQBoxLayoutItem *box;
+ while ( (box=it.current()) != 0 ) {
+ ++it;
+ if ( box->magic ) {
+ TQSpacerItem *sp = box->item->tqspacerItem();
+ if ( sp ) {
+ if ( sp->expandingDirections() == TQSizePolicy::NoDirection ) {
+ //spacing or strut
+ TQSize s = sp->tqsizeHint();
+ sp->changeSize( s.height(), s.width(),
+ horz(direction) ? TQSizePolicy::Fixed:TQSizePolicy::Minimum,
+ horz(direction) ? TQSizePolicy::Minimum:TQSizePolicy::Fixed );
+
+ } else {
+ //stretch
+ if ( horz(direction) )
+ sp->changeSize( 0, 0, TQSizePolicy::Expanding,
+ TQSizePolicy::Minimum );
+ else
+ sp->changeSize( 0, 0, TQSizePolicy::Minimum,
+ TQSizePolicy::Expanding );
+ }
+ }
+ }
+ }
+ }
+ dir = direction;
+ tqinvalidate();
+ if ( mainWidget() ) {
+ TQEvent *lh = new TQEvent( TQEvent::LayoutHint );
+ TQApplication::postEvent( mainWidget(), lh );
+ }
+
+}
+
+/*
+ Initializes the data structure needed by qGeomCalc and
+ recalculates max/min and size hint.
+*/
+void TQBoxLayout::setupGeom()
+{
+ if ( !data->dirty )
+ return;
+
+ int maxw = horz( dir ) ? 0 : TQLAYOUTSIZE_MAX;
+ int maxh = horz( dir ) ? TQLAYOUTSIZE_MAX : 0;
+ int minw = 0;
+ int minh = 0;
+ int hintw = 0;
+ int hinth = 0;
+
+ bool horexp = FALSE;
+ bool verexp = FALSE;
+
+ data->hasHfw = FALSE;
+
+ delete data->geomArray;
+ int n = data->list.count();
+ data->geomArray = new TQMemArray<TQLayoutStruct>( n );
+ TQMemArray<TQLayoutStruct>& a = *data->geomArray;
+
+ bool first = TRUE;
+ for ( int i = 0; i < n; i++ ) {
+ TQBoxLayoutItem *box = data->list.at( i );
+ TQSize max = box->item->maximumSize();
+ TQSize min = box->item->minimumSize();
+ TQSize hint = box->item->sizeHint();
+
+ TQ_SPExpandData exp = box->item->expandingDirections();
+ bool empty = box->item->isEmpty();
+ // space before non-empties, except the first:
+ int space = ( empty || first ) ? 0 : spacing();
+ bool ignore = empty && box->item->widget(); // ignore hidden widgets
+
+ if ( horz(dir) ) {
+ bool expand = exp & TQSizePolicy::Horizontally || box->stretch > 0;
+ horexp = horexp || expand;
+ maxw += max.width() + space;
+ minw += min.width() + space;
+ hintw += hint.width() + space;
+ if ( !ignore )
+ qMaxExpCalc( maxh, verexp,
+ max.height(), exp & TQSizePolicy::Vertically );
+ minh = TQMAX( minh, min.height() );
+ hinth = TQMAX( hinth, hint.height() );
+
+ a[i].tqsizeHint = hint.width();
+ a[i].tqmaximumSize = max.width();
+ a[i].tqminimumSize = min.width();
+ a[i].expansive = expand;
+ a[i].stretch = box->stretch ? box->stretch : box->hStretch();
+ } else {
+ bool expand = ( exp & TQSizePolicy::Vertically || box->stretch > 0 );
+ verexp = verexp || expand;
+ maxh += max.height() + space;
+ minh += min.height() + space;
+ hinth += hint.height() + space;
+ if ( !ignore )
+ qMaxExpCalc( maxw, horexp,
+ max.width(), exp & TQSizePolicy::Horizontally );
+ minw = TQMAX( minw, min.width() );
+ hintw = TQMAX( hintw, hint.width() );
+
+ a[i].tqsizeHint = hint.height();
+ a[i].tqmaximumSize = max.height();
+ a[i].tqminimumSize = min.height();
+ a[i].expansive = expand;
+ a[i].stretch = box->stretch ? box->stretch : box->vStretch();
+ }
+
+ a[i].empty = empty;
+ data->hasHfw = data->hasHfw || box->item->hasHeightForWidth();
+ first = first && empty;
+ }
+
+ data->minSize = TQSize( minw, minh );
+ data->maxSize = TQSize( maxw, maxh ).expandedTo( data->minSize );
+
+ data->expanding = (TQ_SPExpandData)
+ ( (horexp ? TQSizePolicy::Horizontally : 0)
+ | (verexp ? TQSizePolicy::Vertically : 0) );
+
+ data->tqsizeHint = TQSize( hintw, hinth )
+ .expandedTo( data->minSize )
+ .boundedTo( data->maxSize );
+
+ data->dirty = FALSE;
+}
+
+/*
+ Calculates and stores the preferred height given the width \a w.
+*/
+void TQBoxLayout::calcHfw( int w )
+{
+ int h = 0;
+ int mh = 0;
+
+ if ( horz(dir) ) {
+ TQMemArray<TQLayoutStruct> &a = *data->geomArray;
+ int n = a.count();
+ qGeomCalc( a, 0, n, 0, w, spacing() );
+ for ( int i = 0; i < n; i++ ) {
+ TQBoxLayoutItem *box = data->list.at(i);
+ h = TQMAX( h, box->hfw(a[i].size) );
+ mh = TQMAX( mh, box->mhfw(a[i].size) );
+ }
+ } else {
+ TQPtrListIterator<TQBoxLayoutItem> it( data->list );
+ TQBoxLayoutItem *box;
+ bool first = TRUE;
+ while ( (box = it.current()) != 0 ) {
+ ++it;
+ bool empty = box->item->isEmpty();
+ h += box->hfw( w );
+ mh += box->mhfw( w );
+ if ( !first && !empty ) {
+ h += spacing();
+ mh += spacing();
+ }
+ first = first && empty;
+ }
+ }
+ data->hfwWidth = w;
+ data->hfwHeight = h;
+ data->hfwMinHeight = mh;
+}
+
+/*!
+ \fn TQBoxLayout::Direction TQBoxLayout::direction() const
+
+ Returns the direction of the box. addWidget() and addSpacing()
+ work in this direction; the stretch stretches in this direction.
+
+ \sa TQBoxLayout::Direction addWidget() addSpacing()
+*/
+
+/*!
+ \class TQHBoxLayout
+ \brief The TQHBoxLayout class lines up widgets horizontally.
+
+ \ingroup geomanagement
+ \ingroup appearance
+ \mainclass
+
+ This class is used to construct horizontal box tqlayout objects. See
+ \l TQBoxLayout for more details.
+
+ The simplest use of the class is like this:
+ \code
+ TQBoxLayout * l = new TQHBoxLayout( widget );
+ l->setAutoAdd( TRUE );
+ new TQSomeWidget( widget );
+ new TQSomeOtherWidget( widget );
+ new TQAnotherWidget( widget );
+ \endcode
+
+ or like this:
+ \code
+ TQBoxLayout * l = new TQHBoxLayout( widget );
+ l->addWidget( existingChildOfWidget );
+ l->addWidget( anotherChildOfWidget );
+ \endcode
+
+ \img qhboxtqlayout.png TQHBox
+
+ \sa TQVBoxLayout TQGridLayout
+ \link tqlayout.html the Layout overview \endlink
+*/
+
+/*!
+ Constructs a new top-level horizontal box called \a name, with
+ tqparent \a tqparent.
+
+ The \a margin is the number of pixels between the edge of the
+ widget and its managed tqchildren. The \a spacing is the default
+ number of pixels between neighboring tqchildren. If \a spacing is -1
+ the value of \a margin is used for \a spacing.
+*/
+TQHBoxLayout::TQHBoxLayout( TQWidget *tqparent, int margin,
+ int spacing, const char *name )
+ : TQBoxLayout( tqparent, LeftToRight, margin, spacing, name )
+{
+}
+
+/*!
+ Constructs a new horizontal box called name \a name and adds it to
+ \a parentLayout.
+
+ The \a spacing is the default number of pixels between neighboring
+ tqchildren. If \a spacing is -1, this TQHBoxLayout will inherit its
+ tqparent's spacing().
+*/
+TQHBoxLayout::TQHBoxLayout( TQLayout *parentLayout, int spacing,
+ const char *name )
+ : TQBoxLayout( parentLayout, LeftToRight, spacing, name )
+{
+}
+
+/*!
+ Constructs a new horizontal box called name \a name. You must add
+ it to another tqlayout.
+
+ The \a spacing is the default number of pixels between neighboring
+ tqchildren. If \a spacing is -1, this TQHBoxLayout will inherit its
+ tqparent's spacing().
+*/
+TQHBoxLayout::TQHBoxLayout( int spacing, const char *name )
+ : TQBoxLayout( LeftToRight, spacing, name )
+{
+}
+
+/*!
+ Destroys this box tqlayout.
+
+ The tqlayout's widgets aren't destroyed.
+*/
+TQHBoxLayout::~TQHBoxLayout()
+{
+}
+
+/*!
+ \class TQVBoxLayout
+
+ \brief The TQVBoxLayout class lines up widgets vertically.
+
+ \ingroup geomanagement
+ \ingroup appearance
+ \mainclass
+
+ This class is used to construct vertical box tqlayout objects. See
+ TQBoxLayout for more details.
+
+ The simplest use of the class is like this:
+ \code
+ TQBoxLayout * l = new TQVBoxLayout( widget );
+ l->addWidget( aWidget );
+ l->addWidget( anotherWidget );
+ \endcode
+
+ \img qvboxtqlayout.png TQVBox
+
+ \sa TQHBoxLayout TQGridLayout \link tqlayout.html the Layout overview \endlink
+*/
+
+/*!
+ Constructs a new top-level vertical box called \a name, with
+ tqparent \a tqparent.
+
+ The \a margin is the number of pixels between the edge of the
+ widget and its managed tqchildren. The \a spacing is the default
+ number of pixels between neighboring tqchildren. If \a spacing is -1
+ the value of \a margin is used for \a spacing.
+*/
+TQVBoxLayout::TQVBoxLayout( TQWidget *tqparent, int margin, int spacing,
+ const char *name )
+ : TQBoxLayout( tqparent, TopToBottom, margin, spacing, name )
+{
+
+}
+
+/*!
+ Constructs a new vertical box called name \a name and adds it to
+ \a parentLayout.
+
+ The \a spacing is the default number of pixels between neighboring
+ tqchildren. If \a spacing is -1, this TQVBoxLayout will inherit its
+ tqparent's spacing().
+*/
+TQVBoxLayout::TQVBoxLayout( TQLayout *parentLayout, int spacing,
+ const char *name )
+ : TQBoxLayout( parentLayout, TopToBottom, spacing, name )
+{
+}
+
+/*!
+ Constructs a new vertical box called name \a name. You must add
+ it to another tqlayout.
+
+ The \a spacing is the default number of pixels between neighboring
+ tqchildren. If \a spacing is -1, this TQVBoxLayout will inherit its
+ tqparent's spacing().
+*/
+TQVBoxLayout::TQVBoxLayout( int spacing, const char *name )
+ : TQBoxLayout( TopToBottom, spacing, name )
+{
+}
+
+/*!
+ Destroys this box tqlayout.
+
+ The tqlayout's widgets aren't destroyed.
+*/
+TQVBoxLayout::~TQVBoxLayout()
+{
+}
+
+TQBoxLayout *TQBoxLayout::createTmpCopy()
+{
+ TQBoxLayout *bl = new TQBoxLayout( direction() );
+ delete bl->data;
+ bl->data = data;
+ return bl;
+}
+
+#endif // TQT_NO_LAYOUT
diff --git a/tqtinterface/qt4/src/kernel/tqlayout.h b/tqtinterface/qt4/src/kernel/tqlayout.h
new file mode 100644
index 0000000..5423cad
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlayout.h
@@ -0,0 +1,1146 @@
+/****************************************************************************
+**
+** Definition of tqlayout classes
+**
+** Created : 960416
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+// TQT TODO:
+// 1. TQLayout and TQGridLayout addItem functions may not be able to be subclassed by TQt classes
+// This will probably require an inline redirect from the Qt4 method addItem(QLayoutItem) to the TQt method addItem(TQLayoutItem)
+// See also TQLayout::setGeometry() for an example of how to do this
+// See tqlayout.cpp line 3074 for why this is needed
+// MAYBE?????
+
+#ifndef TQLAYOUT_H
+#define TQLAYOUT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqsizepolicy.h"
+#include "tqwidget.h"
+#endif // TQT_H
+
+#include <limits.h>
+
+#ifndef TQT_NO_LAYOUT
+
+#ifdef USE_QT4
+
+#include <Qt/qlayout.h>
+
+#endif // USE_QT4
+
+#if 0
+TQ_OBJECT
+#endif
+
+static const int TQLAYOUTSIZE_MAX = INT_MAX/256/16;
+
+class TQGridLayoutBox;
+class TQGridLayoutData;
+class TQLayout;
+class TQLayoutItem;
+struct TQLayoutData;
+class TQMenuBar;
+class TQSpacerItem;
+class TQWidget;
+
+class TQ_EXPORT TQGLayoutIterator : public TQShared
+{
+public:
+ virtual ~TQGLayoutIterator();
+ virtual TQLayoutItem *next() = 0;
+ virtual TQLayoutItem *current() = 0;
+ virtual TQLayoutItem *takeCurrent() = 0;
+};
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQLayoutIterator
+{
+public:
+ TQLayoutIterator(QLayout *i);
+ inline TQLayoutIterator(const TQLayoutIterator &i)
+ : layout(i.layout), index(i.index) {}
+ inline TQLayoutIterator &operator=(const TQLayoutIterator &i) {
+ layout = i.layout;
+ index = i.index;
+ return *this;
+ }
+ TQLayoutItem *operator++();
+ TQLayoutItem *current();
+ TQLayoutItem *takeCurrent();
+ void deleteCurrent();
+
+private:
+ // hack to avoid deprecated warning
+ friend class QLayout;
+ friend class TQLayout;
+ TQLayoutIterator(QLayout *i, bool);
+ TQLayout *layout;
+ int index;
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQLayoutIterator
+{
+public:
+ TQLayoutIterator( TQGLayoutIterator *i ) : it( i ) { }
+ TQLayoutIterator( const TQLayoutIterator &i ) : it( i.it ) {
+ if ( it )
+ it->ref();
+ }
+ ~TQLayoutIterator() { if ( it && it->deref() ) delete it; }
+ TQLayoutIterator &operator=( const TQLayoutIterator &i ) {
+ if ( i.it )
+ i.it->ref();
+ if ( it && it->deref() )
+ delete it;
+ it = i.it;
+ return *this;
+ }
+ TQLayoutItem *operator++() { return it ? it->next() : 0; }
+ TQLayoutItem *current() { return it ? it->current() : 0; }
+ TQLayoutItem *takeCurrent() { return it ? it->takeCurrent() : 0; }
+ void deleteCurrent();
+
+private:
+ TQGLayoutIterator *it;
+};
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+// Abstract base classes cannot have their abstract methods modified or added to
+// Also, all TQt functions MUST be NON VIRTUAL (and are recommended to be inline as well) <-- this may not always be true
+// Virtual functions are resolved at run time, causing all kinds of problems at runtime with the interface layer
+class TQ_EXPORT TQLayoutItem : public QLayoutItem, virtual public TQt
+{
+public:
+ TQLayoutItem( int tqalignment = 0 ) : QLayoutItem( (Qt::Alignment)tqalignment ) {}
+
+ inline int tqalignment() const { return alignment(); }
+
+ TQSpacerItem *tqspacerItem();
+ inline TQLayout *tqlayout() { return 0; }
+ inline TQWidget *widget() { return static_cast<TQWidget*>(QLayoutItem::widget()); }
+// inline bool hasHeightForWidth() const { return QLayoutItem::hasHeightForWidth(); }
+// inline int heightForWidth( int i ) const { return QLayoutItem::heightForWidth( i ); }
+// inline virtual TQLayoutIterator iterator() { return TQLayoutIterator( 0 ); }
+ inline TQLayoutIterator iterator() { return TQLayoutIterator( 0 ); }
+ inline void tqsetAlignment( int a ) { QLayoutItem::setAlignment((Qt::AlignmentFlag)a); }
+ virtual inline void tqinvalidate() { QLayoutItem::invalidate(); }
+ virtual inline void invalidate() { tqinvalidate(); }
+
+// inline virtual TQSize tqsizeHint() const { return QLayoutItem::sizeHint(); }
+// inline virtual TQSize tqminimumSize() const { return QLayoutItem::minimumSize(); }
+// inline virtual TQSize tqmaximumSize() const { return QLayoutItem::maximumSize(); }
+// inline virtual void setGeometry( const TQRect&r ) { QLayoutItem::setGeometry(r); }
+// inline virtual TQRect tqgeometry() const { return QLayoutItem::geometry(); }
+// inline virtual TQ_SPExpandData expandingDirections() const { return QLayoutItem::expandingDirections(); }
+
+ // These functions are pure virtual in Qt4
+ inline TQSize tqsizeHint() const { return sizeHint(); }
+ inline TQSize tqminimumSize() const { return minimumSize(); }
+ inline TQSize tqmaximumSize() const { return maximumSize(); }
+// inline void setGeometry( const TQRect&r ) { TQ_UNUSED(r); }
+ inline TQRect tqgeometry() const { return geometry(); }
+};
+
+ // Use the TQt virtual functions, not the built in Qt ones...
+ // This requires that the base virtual Qt functions be reimplemented so as to point to the TQt virtual functions instead as shown below.
+ // This way, when Trinity overrides a TQt virtual function, the calling Qt code will blithely use the overriden TQt function instead.
+#define QLAYOUTITEM_REQUIRED_FUNCTIONS \
+ virtual inline QSize sizeHint() const { return tqsizeHint(); } \
+ virtual inline QSize minimumSize() const { return tqminimumSize(); } \
+ virtual inline QSize maximumSize() const { return tqmaximumSize(); } \
+ virtual inline void setGeometry( const QRect &r ) { return setGeometry( TQT_TQRECT_OBJECT(r) ); } \
+ virtual inline QRect geometry() const { return tqgeometry(); }
+ // inline void setAlignment( Qt::AlignmentFlag a ) { return tqsetAlignment(a); }
+
+// class TQ_EXPORT TQLayoutItem : public QLayoutItem, virtual public TQt
+// {
+// public:
+// TQLayoutItem( int tqalignment = 0 ) : QLayoutItem( (Qt::Alignment)tqalignment ) {}
+// virtual ~TQLayoutItem();
+//
+// inline int tqalignment() const { return alignment(); }
+//
+// virtual TQSpacerItem *tqspacerItem();
+// virtual TQLayout *tqlayout();
+// virtual TQWidget *widget();
+// virtual bool hasHeightForWidth() const;
+// virtual int heightForWidth( int ) const;
+// virtual TQLayoutIterator iterator();
+//
+// virtual TQSize tqsizeHint() const = 0;
+// virtual TQSize tqminimumSize() const = 0;
+// virtual TQSize tqmaximumSize() const = 0;
+// virtual void setGeometry( const TQRect& ) = 0;
+// virtual TQRect tqgeometry() const = 0;
+// virtual void tqsetAlignment( int a );
+// virtual void tqinvalidate();
+// virtual TQ_SPExpandData expandingDirections() const;
+//
+// // Use the TQt virtual functions, not the built in Qt ones...
+// // This requires that the base virtual Qt functions be reimplemented so as to point to the TQt virtual functions instead as shown below.
+// // This way, when Trinity overrides a TQt virtual function, the calling Qt code will blithely use the overriden TQt function instead.
+// inline QSize sizeHint() const { return tqsizeHint(); }
+// inline QSize minimumSize() const { return tqminimumSize(); }
+// inline QSize maximumSize() const { return tqmaximumSize(); }
+// inline void setGeometry( const QRect &r ) { return TQLayoutItem::setGeometry( r ); }
+// inline QRect geometry() const { return tqgeometry(); }
+// inline void setAlignment( Qt::AlignmentFlag a ) { return tqsetAlignment(a); }
+// inline void invalidate() { return tqinvalidate(); }
+// inline Qt::Orientations expandingDirections() const { return TQLayoutItem::expandingDirections(); }
+// };
+
+#else // USE_QT4
+
+class TQ_EXPORT TQLayoutItem
+{
+public:
+ TQLayoutItem( int tqalignment = 0 ) : align( tqalignment ) { }
+ virtual ~TQLayoutItem();
+ virtual TQSize tqsizeHint() const = 0;
+ virtual TQSize tqminimumSize() const = 0;
+ virtual TQSize tqmaximumSize() const = 0;
+ virtual TQ_SPExpandData expandingDirections() const = 0;
+ virtual void setGeometry( const TQRect& ) = 0;
+ virtual TQRect tqgeometry() const = 0;
+ virtual bool isEmpty() const = 0;
+ virtual bool hasHeightForWidth() const;
+ virtual int heightForWidth( int ) const;
+ // ### add minimumHeightForWidth( int ) in TQt 4.0
+ virtual void tqinvalidate();
+
+ virtual TQWidget *widget();
+ virtual TQLayoutIterator iterator();
+ virtual TQLayout *tqlayout();
+ virtual TQSpacerItem *tqspacerItem();
+
+ int tqalignment() const { return align; }
+ virtual void tqsetAlignment( int a );
+
+protected:
+ int align;
+};
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQSpacerItem : public QSpacerItem, virtual public TQt
+{
+public:
+ TQSpacerItem( int w, int h, TQSizePolicy::SizeType hData = TQSizePolicy::Minimum, TQSizePolicy::SizeType vData = TQSizePolicy::Minimum ) : QSpacerItem( w, h, hData, vData ) {}
+
+ TQSpacerItem *tqspacerItem(); // Used by tqabstractlayout.cpp
+ inline void changeSize( int w, int h, TQSizePolicy::SizeType hData = TQSizePolicy::Minimum, TQSizePolicy::SizeType vData = TQSizePolicy::Minimum ) { return QSpacerItem::changeSize( w, h, hData, vData ); }
+ TQ_SPExpandData expandingDirections() const; // Used by tqabstractlayout.cpp
+ bool isEmpty() const; // Used by tqabstractlayout.cpp
+
+ TQSize tqsizeHint() const;
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+ void setGeometry( const TQRect &qr );
+ TQRect tqgeometry() const;
+
+ // Use the TQt virtual functions, not the built in Qt ones...
+ // This requires that the base virtual Qt functions be reimplemented so as to point to the TQt virtual functions instead as shown below.
+ // This way, when Trinity overrides a TQt virtual function, the calling Qt code will blithely use the overriden TQt function instead.
+ inline QSize sizeHint() const { return tqsizeHint(); }
+ inline QSize minimumSize() const { return tqminimumSize(); }
+ inline QSize maximumSize() const { return tqmaximumSize(); }
+ inline void setGeometry( const QRect &r ) { return TQSpacerItem::setGeometry( TQT_TQRECT_OBJECT(r) ); }
+ inline QRect geometry() { return tqgeometry(); }
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQSpacerItem : public TQLayoutItem
+{
+public:
+ TQSpacerItem( int w, int h,
+ TQSizePolicy::SizeType hData = TQSizePolicy::Minimum,
+ TQSizePolicy::SizeType vData = TQSizePolicy::Minimum )
+ : width( w ), height( h ), sizeP( hData, vData ) { }
+ void changeSize( int w, int h,
+ TQSizePolicy::SizeType hData = TQSizePolicy::Minimum,
+ TQSizePolicy::SizeType vData = TQSizePolicy::Minimum );
+ TQSize tqsizeHint() const;
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+ TQ_SPExpandData expandingDirections() const;
+ bool isEmpty() const;
+ void setGeometry( const TQRect& );
+ TQRect tqgeometry() const;
+ TQSpacerItem *tqspacerItem();
+
+private:
+ int width;
+ int height;
+ TQSizePolicy sizeP;
+ TQRect rect;
+};
+
+#endif // USE_QT4
+
+class TQ_EXPORT TQWidgetItem : public TQLayoutItem
+{
+public:
+ TQWidgetItem( TQWidget *w ) : wid( w ) { }
+ TQSize tqsizeHint() const;
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+ TQ_SPExpandData expandingDirections() const;
+ bool isEmpty() const;
+ void setGeometry( const TQRect& );
+ TQRect tqgeometry() const;
+ virtual TQWidget *widget();
+
+ bool hasHeightForWidth() const;
+ int heightForWidth( int ) const;
+
+ QLAYOUTITEM_REQUIRED_FUNCTIONS
+
+private:
+ TQWidget *wid;
+};
+
+#ifdef USE_QT4
+// #if 0
+
+extern int menuBarHeightForWidth( QWidget *menubar, int w );
+
+class TQ_EXPORT TQLayout : public QLayout, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ enum ResizeMode {
+ FreeResize = QLayout::SetNoConstraint,
+ Minimum = QLayout::SetMinimumSize,
+ Fixed = QLayout::SetFixedSize,
+ Auto = QLayout::SetDefaultConstraint
+ };
+
+ TQLayout( QWidget *tqparent, int margin = 0, int spacing = -1, const char *name = 0 );
+ TQLayout( QLayout *parentLayout, int spacing = -1, const char *name = 0 );
+ TQLayout( int spacing = -1, const char *name = 0 );
+ virtual TQ_SPExpandData expandingDirections() const;
+
+ TQLayout *tqlayout();
+ virtual TQSize tqsizeHint() const;
+ virtual TQSize tqminimumSize() const;
+ virtual TQSize tqmaximumSize() const;
+
+ TQWidget *mainWidget();
+ virtual void tqinvalidate();
+ virtual void invalidate();
+ virtual TQRect tqgeometry() const;
+ const char *tqname() const;
+ const char *name() const;
+ int tqalignment() const;
+
+ TQWidget *mainWidget() const;
+ void remove(QWidget *w);
+ void add(QWidget *w);
+ void setResizeMode(SizeConstraint s);
+ void setResizeMode(ResizeMode s);
+ SizeConstraint resizeMode() const;
+ ResizeMode tqresizeMode() const;
+ void setAutoAdd(bool a);
+ bool autoAdd() const;
+ void tqsetAlignment( int a );
+
+// bool isTopLevel() const;
+ void freeze( int w, int h );
+ void freeze() { setResizeMode( Fixed ); }
+
+ TQMetaObject *tqmetaObject() const;
+
+ // Required to interface correctly, as QLayout is not a derived class of TQWidget or TQObject
+public:
+ // TQt handler
+// virtual bool eventFilter( TQObject *, TQEvent * );
+
+ // Qt4 handler interface
+ bool eventFilter( QObject *q, QEvent *e );
+
+// TQt event handlers
+protected:
+ virtual bool event( TQEvent *e );
+
+// TQFocusData *focusData();
+ bool event( QEvent *e );
+// virtual void mousePressEvent( TQMouseEvent * ); // NOTE: All event handlers that can be subclassed must be declared here, and
+// virtual void mouseReleaseEvent( TQMouseEvent * ); // declared virtual, so that run time dynamic call resolution will occur
+// virtual void mouseDoubleClickEvent( TQMouseEvent * );
+// virtual void mouseMoveEvent( TQMouseEvent * );
+// #ifndef TQT_NO_WHEELEVENT
+// virtual void wheelEvent( TQWheelEvent * );
+// #endif
+// virtual void keyPressEvent( TQKeyEvent * );
+// virtual void keyReleaseEvent( TQKeyEvent * );
+// virtual void focusInEvent( TQFocusEvent * );
+// virtual void focusOutEvent( TQFocusEvent * );
+// virtual void enterEvent( TQEvent * );
+// virtual void leaveEvent( TQEvent * );
+// virtual void paintEvent( TQPaintEvent * );
+// virtual void moveEvent( TQMoveEvent * );
+// virtual void resizeEvent( TQResizeEvent * );
+// virtual void closeEvent( TQCloseEvent * );
+// virtual void contextMenuEvent( TQContextMenuEvent * );
+// virtual void imStartEvent( TQIMEvent * );
+// virtual void imComposeEvent( TQIMEvent * );
+// virtual void imEndEvent( TQIMEvent * );
+// virtual void tabletEvent( TQTabletEvent * );
+//
+// #ifndef TQT_NO_DRAGANDDROP
+// virtual void dragEnterEvent( TQDragEnterEvent * );
+// virtual void dragMoveEvent( TQDragMoveEvent * );
+// virtual void dragLeaveEvent( TQDragLeaveEvent * );
+// virtual void dropEvent( TQDropEvent * );
+// #endif
+//
+// virtual void showEvent( TQShowEvent * );
+// virtual void hideEvent( TQHideEvent * );
+
+// // Qt4 event handler interface
+// protected:
+// inline virtual void mousePressEvent(QMouseEvent *e) { mousePressEvent(static_cast<TQMouseEvent*>(e)); } // QLayout::mousePressEvent(e) }
+// inline virtual void mouseReleaseEvent(QMouseEvent *e) { mouseReleaseEvent(static_cast<TQMouseEvent*>(e)); } // QLayout::mouseReleaseEvent(e) }
+// inline virtual void mouseDoubleClickEvent(QMouseEvent *e) { mouseDoubleClickEvent(static_cast<TQMouseEvent*>(e)); } // QLayout::mouseDoubleClickEvent(e) }
+// inline virtual void mouseMoveEvent(QMouseEvent *e) { mouseMoveEvent(static_cast<TQMouseEvent*>(e)); } // QLayout::mouseMoveEvent(e) }
+// #ifndef QT_NO_WHEELEVENT
+// inline virtual void wheelEvent(QWheelEvent *e) { wheelEvent(static_cast<TQWheelEvent*>(e)); } // QLayout::wheelEvent(e) }
+// #endif
+// inline virtual void keyPressEvent(QKeyEvent *e) { keyPressEvent(static_cast<TQKeyEvent*>(e)); } // QLayout::keyPressEvent(e) }
+// inline virtual void keyReleaseEvent(QKeyEvent *e) { keyReleaseEvent(static_cast<TQKeyEvent*>(e)); } // QLayout::keyReleaseEvent(e) }
+// inline virtual void focusInEvent(QFocusEvent *e) { focusInEvent(static_cast<TQFocusEvent*>(e)); } // QLayout::focusInEvent(e) }
+// inline virtual void focusOutEvent(QFocusEvent *e) { focusOutEvent(static_cast<TQFocusEvent*>(e)); } // QLayout::focusOutEvent(e) }
+// inline virtual void enterEvent(QEvent *e) { enterEvent(static_cast<TQEvent*>(e)); } // QLayout::enterEvent(e) }
+// inline virtual void leaveEvent(QEvent *e) { leaveEvent(static_cast<TQEvent*>(e)); } // QLayout::leaveEvent(e) }
+// inline virtual void paintEvent(QPaintEvent *e) { paintEvent(static_cast<TQPaintEvent*>(e)); } // QLayout::paintEvent(e) }
+// inline virtual void moveEvent(QMoveEvent *e) { moveEvent(static_cast<TQMoveEvent*>(e)); } // QLayout::moveEvent(e) }
+// inline virtual void resizeEvent(QResizeEvent *e) { resizeEvent(static_cast<TQResizeEvent*>(e)); } // QLayout::resizeEvent(e) }
+// inline virtual void closeEvent(QCloseEvent *e) { closeEvent(static_cast<TQCloseEvent*>(e)); } // QLayout::closeEvent(e) }
+// #ifndef QT_NO_CONTEXTMENU
+// inline virtual void contextMenuEvent(QContextMenuEvent *e) { contextMenuEvent(static_cast<TQContextMenuEvent*>(e)); } // QLayout::contextMenuEvent(e); }
+// #endif
+// #ifndef QT_NO_TABLETEVENT
+// inline virtual void tabletEvent(QTabletEvent *e) { tabletEvent(static_cast<TQTabletEvent*>(e)); } // QLayout::tabletEvent(e) }
+// #endif
+// #ifndef QT_NO_ACTION
+// // inline virtual void actionEvent(QActionEvent *e) { actionEvent(static_cast<TQActionEvent*>(e)); QLayout::actionEvent(e) }
+// #endif
+//
+// // #ifndef QT_NO_DRAGANDDROP
+// // inline virtual void dragEnterEvent(QDragEnterEvent *e) { dragEnterEvent(static_cast<TQDragEnterEvent*>(e)); QLayout::dragEnterEvent(e) }
+// // inline virtual void dragMoveEvent(QDragMoveEvent *e) { dragMoveEvent(static_cast<TQDragMoveEvent*>(e)); QLayout::dragMoveEvent(e) }
+// // inline virtual void dragLeaveEvent(QDragLeaveEvent *e) { dragLeaveEvent(static_cast<TQDragLeaveEvent*>(e)); QLayout::dragLeaveEvent(e) }
+// // inline virtual void dropEvent(QDropEvent *e) { dropEvent(static_cast<TQDropEvent*>(e)); QLayout::dropEvent(e) }
+// // #endif
+//
+// inline virtual void showEvent(QShowEvent *e) { showEvent(static_cast<TQShowEvent*>(e)); } // QLayout::showEvent(e) }
+// inline virtual void hideEvent(QHideEvent *e) { hideEvent(static_cast<TQHideEvent*>(e)); } // QLayout::hideEvent(e) }
+
+// TQt event handlers
+protected:
+ virtual void timerEvent( TQTimerEvent * );
+ virtual void childEvent( TQChildEvent * );
+ virtual void customEvent( TQCustomEvent * );
+
+// Qt4 event handler interface
+protected:
+ virtual void timerEvent(QTimerEvent *e);
+ virtual void childEvent(QChildEvent *e);
+ virtual void customEvent(QEvent *e);
+
+protected:
+ bool eventFilter( TQObject *o, TQEvent *e );
+
+public:
+ // Interoperability
+ static const TQLayout& convertFromQLayout( QLayout& ql );
+
+// virtual void addItem( TQLayoutItem * ) = 0;
+ TQLayoutIterator iterator();
+
+ QLayout *layout();
+ virtual void setGeometry(const TQRect &r);
+
+ QLAYOUTITEM_REQUIRED_FUNCTIONS
+
+protected:
+ void setSupportsMargin( bool ); // Implemented in tqabstractlayout.cpp
+ TQRect alignmentRect( const TQRect& qr ) const;
+ void deleteAllItems();
+
+public Q_SLOTS:
+ void tqt_handle_qt_destroyed(QObject* obj);
+
+Q_SIGNALS:
+ void destroyed( TQObject* obj );
+
+private:
+ bool autoNewChild;
+ mutable TQString static_object_name;
+};
+
+// Interoperability
+inline static const TQLayout& convertFromQLayout( const QLayout& ql ) {
+ return (*static_cast<const TQLayout*>(&ql));
+}
+
+#else // USE_QT4
+
+class TQ_EXPORT TQLayout : public TQObject, public TQLayoutItem
+{
+ Q_OBJECT
+ TQ_OBJECT
+ TQ_ENUMS( ResizeMode )
+ Q_PROPERTY( int margin READ margin WRITE setMargin )
+ Q_PROPERTY( int spacing READ spacing WRITE setSpacing )
+ Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
+
+public:
+ // ### TQt 4.0: put 'Auto' first in enum
+ enum ResizeMode { FreeResize, Minimum, Fixed, Auto };
+
+ TQLayout( TQWidget *tqparent, int margin = 0, int spacing = -1,
+ const char *name = 0 );
+ TQLayout( TQLayout *parentLayout, int spacing = -1, const char *name = 0 );
+ TQLayout( int spacing = -1, const char *name = 0 );
+ ~TQLayout();
+
+ int margin() const { return outsideBorder; }
+ int spacing() const { return insideSpacing; }
+
+ virtual void setMargin( int );
+ virtual void setSpacing( int );
+
+ int defaultBorder() const { return insideSpacing; }
+ void freeze( int w, int h );
+ void freeze() { setResizeMode( Fixed ); }
+
+ void setResizeMode( ResizeMode );
+ ResizeMode resizeMode() const;
+
+#ifndef TQT_NO_MENUBAR
+ virtual void setMenuBar( TQMenuBar *w );
+ TQMenuBar *menuBar() const { return menubar; }
+#endif
+
+ TQWidget *mainWidget();
+ bool isTopLevel() const { return topLevel; }
+
+ virtual void setAutoAdd( bool );
+ bool autoAdd() const { return autoNewChild; }
+
+ void tqinvalidate();
+ TQRect tqgeometry() const;
+ bool activate();
+
+ void add( TQWidget *w ) { addItem( new TQWidgetItem(w) ); }
+ virtual void addItem( TQLayoutItem * ) = 0;
+
+ void remove( TQWidget *w );
+ void removeItem( TQLayoutItem * );
+
+ TQ_SPExpandData expandingDirections() const;
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+ void setGeometry( const TQRect& ) = 0;
+ TQLayoutIterator iterator() = 0;
+ bool isEmpty() const;
+
+ int totalHeightForWidth( int w ) const;
+ TQSize totalMinimumSize() const;
+ TQSize totalMaximumSize() const;
+ TQSize totalSizeHint() const;
+ TQLayout *tqlayout();
+
+ bool supportsMargin() const { return marginImpl; }
+
+ void setEnabled( bool );
+ bool isEnabled() const;
+
+protected:
+ bool eventFilter( TQObject *, TQEvent * );
+ void childEvent( TQChildEvent *e );
+ void addChildLayout( TQLayout *l );
+ void deleteAllItems();
+
+ void setSupportsMargin( bool );
+ TQRect alignmentRect( const TQRect& ) const;
+
+private:
+ void setWidgetLayout( TQWidget *, TQLayout * );
+ void init();
+ int insideSpacing;
+ int outsideBorder;
+ uint topLevel : 1;
+ uint enabled : 1;
+ uint autoNewChild : 1;
+ uint frozen : 1;
+ uint activated : 1;
+ uint marginImpl : 1;
+ uint autoMinimum : 1;
+ uint autoResizeMode : 1;
+ TQRect rect;
+ TQLayoutData *extraData;
+#ifndef TQT_NO_MENUBAR
+ TQMenuBar *menubar;
+#endif
+
+private:
+#if defined(TQ_DISABLE_COPY)
+ TQLayout( const TQLayout & );
+ TQLayout &operator=( const TQLayout & );
+#endif
+
+ static void propagateSpacing( TQLayout *tqlayout );
+};
+
+inline void TQLayoutIterator::deleteCurrent()
+{
+ delete takeCurrent();
+}
+#endif // USE_QT4
+
+#define QLAYOUT_REQUIRED_METHOD_DECLARATIONS \
+ int count() const; \
+ TQLayoutItem* itemAt(int index) const; \
+ TQLayoutItem* takeAt(int index); \
+ virtual inline QSize sizeHint() const { return tqsizeHint(); } \
+ virtual inline QSize minimumSize() const { return tqminimumSize(); } \
+ virtual inline QSize maximumSize() const { return tqmaximumSize(); } \
+ virtual inline void setGeometry( const QRect &r ) { return setGeometry( TQT_TQRECT_OBJECT(r) ); } \
+ virtual inline QRect geometry() const { return tqgeometry(); }
+
+#define QLAYOUT_REQUIRED_METHOD_IMPLEMENTATIONS \
+ inline int count() const { \
+ return data->list.count(); \
+ } \
+ \
+ inline TQLayoutItem* itemAt(int index) const { \
+ return index >= 0 && index < data->list.count() ? data->list.at(index)->item : 0; \
+ } \
+ \
+ inline TQLayoutItem* takeAt(int index) { \
+ if (index < 0 || index >= data->list.count()) \
+ return 0; \
+ TQBoxLayoutItem *b = data->list.take(index); \
+ TQLayoutItem *item = b->item; \
+ b->item = 0; \
+ delete b; \
+ \
+ invalidate(); \
+ return item; \
+ }
+
+#if 0
+
+class TQ_EXPORT TQGridLayout : public QGridLayout, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQGridLayout( TQWidget *tqparent, int nRows = 1, int nCols = 1, int border = 0, int spacing = -1, const char *name = 0 ) : QGridLayout( tqparent ), autoNewChild(false)
+ {
+ expand(nRows, nCols);
+ setMargin(border);
+ setSpacing(spacing < 0 ? border : spacing);
+ setObjectName(QString::fromAscii(name));
+ if ( tqparent ) tqparent->installEventFilter( this );
+ TQT_TQOBJECT_REQUIRED_INITIALIZATION(tqparent)
+ }
+ TQGridLayout( int nRows = 1, int nCols = 1, int spacing = -1, const char *name = 0 ) : QGridLayout(), autoNewChild(false)
+ {
+ expand(nRows, nCols);
+ setSpacing(spacing);
+ setObjectName(QString::fromAscii(name));
+ }
+ TQGridLayout( QLayout *parentLayout, int nRows = 1, int nCols = 1, int spacing = -1, const char *name = 0 ) : QGridLayout(), autoNewChild(false)
+ {
+ expand(nRows, nCols);
+ if (spacing == -1) {setSpacing(parentLayout->spacing());} else {setSpacing(spacing);};
+ setObjectName(QString::fromAscii(name));
+ if ( parentLayout ) parentLayout->addItem(this);
+ if ( parentLayout ) parentLayout->installEventFilter( this );
+ TQT_TQOBJECT_REQUIRED_INITIALIZATION(parentLayout)
+ }
+
+ void expand( int rows, int cols ) {
+ // Nasty, nasty HACK
+ // Yet another example of lost functionality in Qt4...sigh...
+ QSpacerItem *hack= new QSpacerItem(1,1);
+ addItem(hack, (rows != -1) ? rows-1 : 0, (cols != -1) ? cols-1 : 0);
+ QGridLayout::removeItem(hack);
+ delete hack;
+ }
+
+ inline TQSize tqsizeHint() const { return sizeHint(); }
+ inline TQSize tqminimumSize() const { return minimumSize(); }
+ inline TQSize tqmaximumSize() const { return maximumSize(); }
+ inline void tqinvalidate() { invalidate(); }
+
+ inline TQRect tqgeometry() const { return geometry(); }
+
+ inline TQWidget *mainWidget() const { return TQT_TQWIDGET(parentWidget()); }
+ inline void remove(QWidget *w) { removeWidget(w); }
+ inline void add(QWidget *w) { addWidget(w); }
+ inline void setResizeMode(SizeConstraint s) {setSizeConstraint(s);}
+ inline void setResizeMode(TQLayout::ResizeMode s) {setResizeMode((SizeConstraint)s);}
+ inline SizeConstraint resizeMode() const {return sizeConstraint();}
+ inline void setAutoAdd(bool a) { autoNewChild = a; }
+ inline bool autoAdd() const { return autoNewChild; }
+
+ inline void addRowSpacing(int row, int minsize) { addItem(new QSpacerItem(0,minsize), row, 0); }
+ inline void addColSpacing(int col, int minsize) { addItem(new QSpacerItem(minsize,0), 0, col); }
+ inline void addMultiCellWidget(QWidget *w, int fromRow, int toRow, int fromCol, int toCol, Qt::Alignment _align = 0) { addWidget(w, fromRow, fromCol, (toRow < 0) ? -1 : toRow - fromRow + 1, (toCol < 0) ? -1 : toCol - fromCol + 1, _align); }
+ inline void addMultiCell(QLayoutItem *l, int fromRow, int toRow, int fromCol, int toCol, Qt::Alignment _align = 0) { addItem(l, fromRow, fromCol, (toRow < 0) ? -1 : toRow - fromRow + 1, (toCol < 0) ? -1 : toCol - fromCol + 1, _align); }
+ inline void addMultiCellLayout(QLayout *layout, int fromRow, int toRow, int fromCol, int toCol, Qt::Alignment _align = 0) { addLayout(layout, fromRow, fromCol, (toRow < 0) ? -1 : toRow - fromRow + 1, (toCol < 0) ? -1 : toCol - fromCol + 1, _align); }
+
+ inline int numRows() const { return rowCount(); }
+ inline int numCols() const { return columnCount(); }
+ inline void setColStretch(int col, int stretch) {setColumnStretch(col, stretch); }
+ inline int colStretch(int col) const {return columnStretch(col); }
+ inline void setColSpacing(int col, int minSize) { setColumnMinimumWidth(col, minSize); }
+ inline int colSpacing(int col) const { return columnMinimumWidth(col); }
+ inline void setRowSpacing(int row, int minSize) {setRowMinimumHeight(row, minSize); }
+ inline int rowSpacing(int row) const {return rowMinimumHeight(row); }
+
+ virtual void tqsetAlignment( int a );
+
+ // Required to interface correctly, as QLayout is not a derived class of TQWidget or TQObject
+public:
+ // TQt handler
+// virtual bool eventFilter( TQObject *, TQEvent * );
+
+ // Qt4 handler interface
+ inline bool eventFilter( QObject *q, QEvent *e ) { return eventFilter(static_cast<TQObject*>(q), static_cast<TQEvent*>(e)); }
+
+// TQt event handlers
+protected:
+// virtual bool event( TQEvent *e );
+
+// TQFocusData *focusData();
+// inline bool event( QEvent *e ) { return event(static_cast<TQEvent*>(e)); }
+ virtual void mousePressEvent( TQMouseEvent * ); // NOTE: All event handlers that can be subclassed must be declared here, and
+ virtual void mouseReleaseEvent( TQMouseEvent * ); // declared virtual, so that run time dynamic call resolution will occur
+ virtual void mouseDoubleClickEvent( TQMouseEvent * );
+ virtual void mouseMoveEvent( TQMouseEvent * );
+#ifndef TQT_NO_WHEELEVENT
+ virtual void wheelEvent( TQWheelEvent * );
+#endif
+ virtual void keyPressEvent( TQKeyEvent * );
+ virtual void keyReleaseEvent( TQKeyEvent * );
+ virtual void focusInEvent( TQFocusEvent * );
+ virtual void focusOutEvent( TQFocusEvent * );
+ virtual void enterEvent( TQEvent * );
+ virtual void leaveEvent( TQEvent * );
+ virtual void paintEvent( TQPaintEvent * );
+ virtual void moveEvent( TQMoveEvent * );
+ virtual void resizeEvent( TQResizeEvent * );
+ virtual void closeEvent( TQCloseEvent * );
+ virtual void contextMenuEvent( TQContextMenuEvent * );
+ virtual void imStartEvent( TQIMEvent * );
+ virtual void imComposeEvent( TQIMEvent * );
+ virtual void imEndEvent( TQIMEvent * );
+ virtual void tabletEvent( TQTabletEvent * );
+
+#ifndef TQT_NO_DRAGANDDROP
+ virtual void dragEnterEvent( TQDragEnterEvent * );
+ virtual void dragMoveEvent( TQDragMoveEvent * );
+ virtual void dragLeaveEvent( TQDragLeaveEvent * );
+ virtual void dropEvent( TQDropEvent * );
+#endif
+
+ virtual void showEvent( TQShowEvent * );
+ virtual void hideEvent( TQHideEvent * );
+
+// Qt4 event handler interface
+protected:
+ inline virtual void mousePressEvent(QMouseEvent *e) { mousePressEvent(static_cast<TQMouseEvent*>(e)); } // QGridLayout::mousePressEvent(e) }
+ inline virtual void mouseReleaseEvent(QMouseEvent *e) { mouseReleaseEvent(static_cast<TQMouseEvent*>(e)); } // QGridLayout::mouseReleaseEvent(e) }
+ inline virtual void mouseDoubleClickEvent(QMouseEvent *e) { mouseDoubleClickEvent(static_cast<TQMouseEvent*>(e)); } // QGridLayout::mouseDoubleClickEvent(e) }
+ inline virtual void mouseMoveEvent(QMouseEvent *e) { mouseMoveEvent(static_cast<TQMouseEvent*>(e)); } // QGridLayout::mouseMoveEvent(e) }
+#ifndef QT_NO_WHEELEVENT
+ inline virtual void wheelEvent(QWheelEvent *e) { wheelEvent(static_cast<TQWheelEvent*>(e)); } // QGridLayout::wheelEvent(e) }
+#endif
+ inline virtual void keyPressEvent(QKeyEvent *e) { keyPressEvent(static_cast<TQKeyEvent*>(e)); } // QGridLayout::keyPressEvent(e) }
+ inline virtual void keyReleaseEvent(QKeyEvent *e) { keyReleaseEvent(static_cast<TQKeyEvent*>(e)); } // QGridLayout::keyReleaseEvent(e) }
+ inline virtual void focusInEvent(QFocusEvent *e) { focusInEvent(static_cast<TQFocusEvent*>(e)); } // QGridLayout::focusInEvent(e) }
+ inline virtual void focusOutEvent(QFocusEvent *e) { focusOutEvent(static_cast<TQFocusEvent*>(e)); } // QGridLayout::focusOutEvent(e) }
+ inline virtual void enterEvent(QEvent *e) { enterEvent(static_cast<TQEvent*>(e)); } // QGridLayout::enterEvent(e) }
+ inline virtual void leaveEvent(QEvent *e) { leaveEvent(static_cast<TQEvent*>(e)); } // QGridLayout::leaveEvent(e) }
+ inline virtual void paintEvent(QPaintEvent *e) { paintEvent(static_cast<TQPaintEvent*>(e)); } // QGridLayout::paintEvent(e) }
+ inline virtual void moveEvent(QMoveEvent *e) { moveEvent(static_cast<TQMoveEvent*>(e)); } // QGridLayout::moveEvent(e) }
+ inline virtual void resizeEvent(QResizeEvent *e) { resizeEvent(static_cast<TQResizeEvent*>(e)); } // QGridLayout::resizeEvent(e) }
+ inline virtual void closeEvent(QCloseEvent *e) { closeEvent(static_cast<TQCloseEvent*>(e)); } // QGridLayout::closeEvent(e) }
+#ifndef QT_NO_CONTEXTMENU
+ inline virtual void contextMenuEvent(QContextMenuEvent *e { contextMenuEvent(static_cast<TQContextMenuEvent*>(e)); QGridLayout::contextMenuEvent(e) }
+#endif
+#ifndef QT_NO_TABLETEVENT
+ inline virtual void tabletEvent(QTabletEvent *e) { tabletEvent(static_cast<TQTabletEvent*>(e)); } // QGridLayout::tabletEvent(e) }
+#endif
+#ifndef QT_NO_ACTION
+// inline virtual void actionEvent(QActionEvent *e) { actionEvent(static_cast<TQActionEvent*>(e)); QGridLayout::actionEvent(e) }
+#endif
+
+// #ifndef QT_NO_DRAGANDDROP
+// inline virtual void dragEnterEvent(QDragEnterEvent *e) { dragEnterEvent(static_cast<TQDragEnterEvent*>(e)); QGridLayout::dragEnterEvent(e) }
+// inline virtual void dragMoveEvent(QDragMoveEvent *e) { dragMoveEvent(static_cast<TQDragMoveEvent*>(e)); QGridLayout::dragMoveEvent(e) }
+// inline virtual void dragLeaveEvent(QDragLeaveEvent *e) { dragLeaveEvent(static_cast<TQDragLeaveEvent*>(e)); QGridLayout::dragLeaveEvent(e) }
+// inline virtual void dropEvent(QDropEvent *e) { dropEvent(static_cast<TQDropEvent*>(e)); QGridLayout::dropEvent(e) }
+// #endif
+
+ inline virtual void showEvent(QShowEvent *e) { showEvent(static_cast<TQShowEvent*>(e)); } // QGridLayout::showEvent(e) }
+ inline virtual void hideEvent(QHideEvent *e) { hideEvent(static_cast<TQHideEvent*>(e)); } // QGridLayout::hideEvent(e) }
+
+// TQt event handlers
+protected:
+ virtual void timerEvent( TQTimerEvent * );
+ virtual void childEvent( TQChildEvent * );
+ virtual void customEvent( TQCustomEvent * );
+
+// Qt4 event handler interface
+protected:
+ inline virtual void timerEvent(QTimerEvent *e) { timerEvent(static_cast<TQTimerEvent*>(e)); } // QGridLayout::timerEvent(e) }
+ inline virtual void childEvent(QChildEvent *e) { TQT_TQOBJECT_CHILDEVENT_CONDITIONAL childEvent(static_cast<TQChildEvent*>(e)); } // QGridLayout::childEvent(e) }
+// inline virtual void customEvent(QCustomEvent *e) { customEvent(static_cast<TQCustomEvent*>(e)); }
+
+// protected:
+// bool eventFilter( TQObject *o, TQEvent *e ) {
+// TQ_UNUSED(o);
+// if (e->type() == TQEvent::ChildInserted) {
+// if (autoNewChild) {
+// QChildEvent *c = (QChildEvent *)e;
+// if (c->child()->isWidgetType()) {
+// QWidget *w = (QWidget *)c->child();
+// if (!w->isWindow()) {
+// addWidget(w);
+// }
+// }
+// }
+// }
+// else if (e->type() == TQEvent::LayoutHint) {
+// // d->activated = false;
+// if (parent()) {
+// if (static_cast<QWidget *>(parent())->isVisible()) {
+// activate();
+// }
+// }
+// }
+// return FALSE;
+// }
+
+// Taken from TQLayout above
+protected:
+ bool eventFilter( TQObject *o, TQEvent *e ) {
+ TQ_UNUSED(o);
+
+ if (e->type() == TQEvent::Resize) {
+ activate();
+ TQResizeEvent *r = (TQResizeEvent *)e;
+ int mbh = 0;
+#ifndef TQT_NO_MENUBAR
+ mbh = menuBarHeightForWidth( menuBar(), r->size().width() );
+#endif
+// int b = marginImpl ? 0 : outsideBorder;
+ int b = 0;
+ setGeometry( TQRect( b, mbh + b, r->size().width() - 2 * b, r->size().height() - mbh - 2 * b ) );
+ }
+
+ else if (e->type() == TQEvent::ChildInserted) {
+ if (autoNewChild) {
+ QChildEvent *c = (QChildEvent *)e;
+ if (c->child()->isWidgetType()) {
+ QWidget *w = (QWidget *)c->child();
+ if (!w->isWindow()) {
+// #if !defined(QT_NO_MENUBAR) && !defined(QT_NO_TOOLBAR)
+// if (qobject_cast<QMenuBar*>(w) && !qobject_cast<QToolBar*>(w->parentWidget())) {
+// setMenuBar( (QMenuBar *)w );
+// invalidate();
+// } else
+// #endif
+// #ifndef QT_NO_SIZEGRIP
+// if (qobject_cast<QSizeGrip*>(w) ) {
+// //SizeGrip is handled by the dialog itself.
+// } else
+// #endif
+// addItem(QLayoutPrivate::createWidgetItem(this, w));
+ addWidget(w);
+ }
+ }
+ }
+ }
+ else if (e->type() == TQEvent::LayoutHint) {
+// d->d = false;
+ if (parent()) {
+ if (static_cast<QWidget *>(parent())->isVisible()) {
+ activate();
+ }
+ }
+ }
+ return FALSE;
+ }
+
+public:
+ virtual void setGeometry(const TQRect &r) { return QGridLayout::setGeometry(r); }
+ virtual inline void setGeometry(const QRect &r) { return setGeometry(TQT_TQRECT_OBJECT(r)); }
+
+public Q_SLOTS:
+ void tqt_handle_qt_destroyed(QObject* obj) { emit destroyed(TQT_TQOBJECT(obj)); }
+
+Q_SIGNALS:
+ void destroyed( TQObject* obj );
+
+private:
+ bool autoNewChild;
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQGridLayout : public TQLayout
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQGridLayout( TQWidget *tqparent, int nRows = 1, int nCols = 1, int border = 0,
+ int spacing = -1, const char *name = 0 );
+ TQGridLayout( int nRows = 1, int nCols = 1, int spacing = -1,
+ const char *name = 0 );
+ TQGridLayout( TQLayout *parentLayout, int nRows = 1, int nCols = 1,
+ int spacing = -1, const char *name = 0 );
+ ~TQGridLayout();
+
+ TQSize tqsizeHint() const;
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+
+ // ### remove 'virtual' in 4.0 (or add 'virtual' to set{Row,Col}Spacing())
+ virtual void setRowStretch( int row, int stretch );
+ virtual void setColStretch( int col, int stretch );
+ int rowStretch( int row ) const;
+ int colStretch( int col ) const;
+
+ void setRowSpacing( int row, int minSize );
+ void setColSpacing( int col, int minSize );
+ int rowSpacing( int row ) const;
+ int colSpacing( int col ) const;
+
+ int numRows() const;
+ int numCols() const;
+ TQRect cellGeometry( int row, int col ) const;
+
+ bool hasHeightForWidth() const;
+ int heightForWidth( int ) const;
+ int minimumHeightForWidth( int ) const;
+
+ TQ_SPExpandData expandingDirections() const;
+ void tqinvalidate();
+
+ void addItem( QLayoutItem * );
+ void addItem( QLayoutItem *item, int row, int col );
+ void addMultiCell( QLayoutItem *, int fromRow, int toRow,
+ int fromCol, int toCol, int align = 0 );
+
+ void addWidget( TQWidget *, int row, int col, int align = 0 );
+ void addMultiCellWidget( TQWidget *, int fromRow, int toRow,
+ int fromCol, int toCol, int align = 0 );
+ void addLayout( TQLayout *tqlayout, int row, int col);
+ void addMultiCellLayout( TQLayout *tqlayout, int fromRow, int toRow,
+ int fromCol, int toCol, int align = 0 );
+ void addRowSpacing( int row, int minsize );
+ void addColSpacing( int col, int minsize );
+
+ void expand( int rows, int cols );
+
+ enum Corner { TopLeft, TopRight, BottomLeft, BottomRight };
+ void setOrigin( Corner );
+ Corner origin() const;
+// TQLayoutIterator iterator();
+ void setGeometry( const TQRect& );
+
+#ifdef USE_QT4
+
+ QLAYOUT_REQUIRED_METHOD_DECLARATIONS
+
+#endif // USE_QT4
+
+protected:
+ bool tqfindWidget( TQWidget* w, int *r, int *c );
+ void add( TQLayoutItem*, int row, int col );
+
+private:
+#if defined(TQ_DISABLE_COPY)
+ TQGridLayout( const TQGridLayout & );
+ TQGridLayout &operator=( const TQGridLayout & );
+#endif
+
+ void init( int rows, int cols );
+ TQGridLayoutData *data;
+};
+
+#endif // USE_QT4
+
+class TQBoxLayoutData;
+class TQDockWindow;
+
+class TQ_EXPORT TQBoxLayout : public TQLayout
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ enum Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop,
+ Down = TopToBottom, Up = BottomToTop };
+
+ TQBoxLayout( TQWidget *tqparent, Direction, int border = 0, int spacing = -1,
+ const char *name = 0 );
+ TQBoxLayout( TQLayout *parentLayout, Direction, int spacing = -1,
+ const char *name = 0 );
+ TQBoxLayout( Direction, int spacing = -1, const char *name = 0 );
+ ~TQBoxLayout();
+
+ void addItem( QLayoutItem * );
+
+ Direction direction() const { return dir; }
+ void setDirection( Direction );
+
+ void addSpacing( int size );
+ void addStretch( int stretch = 0 );
+ void addWidget( TQWidget *, int stretch = 0, int tqalignment = 0 );
+ void addLayout( TQLayout *tqlayout, int stretch = 0 );
+ void addStrut( int );
+
+ void insertSpacing( int index, int size );
+ void insertStretch( int index, int stretch = 0 );
+ void insertWidget( int index, TQWidget *widget, int stretch = 0,
+ int tqalignment = 0 );
+ void insertLayout( int index, TQLayout *tqlayout, int stretch = 0 );
+
+ bool setStretchFactor( TQWidget*, int stretch );
+ bool setStretchFactor( TQLayout *l, int stretch );
+
+ TQSize tqsizeHint() const;
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+
+ bool hasHeightForWidth() const;
+ int heightForWidth( int ) const;
+ int minimumHeightForWidth( int ) const;
+
+ TQ_SPExpandData expandingDirections() const;
+ void tqinvalidate();
+// TQLayoutIterator iterator();
+ void setGeometry( const TQRect& );
+
+ int tqfindWidget( TQWidget* w );
+
+#ifdef USE_QT4
+
+ QLAYOUT_REQUIRED_METHOD_DECLARATIONS
+
+#endif // USE_QT4
+
+protected:
+ void insertItem( int index, TQLayoutItem * );
+
+private:
+ friend class TQDockWindow;
+#if defined(TQ_DISABLE_COPY)
+ TQBoxLayout( const TQBoxLayout & );
+ TQBoxLayout &operator=( const TQBoxLayout & );
+#endif
+
+ void setupGeom();
+ void calcHfw( int );
+ TQBoxLayoutData *data;
+ Direction dir;
+ TQBoxLayout *createTmpCopy();
+};
+
+class TQ_EXPORT TQHBoxLayout : public TQBoxLayout
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQHBoxLayout( TQWidget *tqparent, int border = 0,
+ int spacing = -1, const char *name = 0 );
+ TQHBoxLayout( TQLayout *parentLayout,
+ int spacing = -1, const char *name = 0 );
+ TQHBoxLayout( int spacing = -1, const char *name = 0 );
+
+ ~TQHBoxLayout();
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQHBoxLayout( const TQHBoxLayout & );
+ TQHBoxLayout &operator=( const TQHBoxLayout & );
+#endif
+};
+
+class TQ_EXPORT TQVBoxLayout : public TQBoxLayout
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQVBoxLayout( TQWidget *tqparent, int border = 0,
+ int spacing = -1, const char *name = 0 );
+ TQVBoxLayout( TQLayout *parentLayout,
+ int spacing = -1, const char *name = 0 );
+ TQVBoxLayout( int spacing = -1, const char *name = 0 );
+
+ ~TQVBoxLayout();
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQVBoxLayout( const TQVBoxLayout & );
+ TQVBoxLayout &operator=( const TQVBoxLayout & );
+#endif
+};
+
+#endif // TQT_NO_LAYOUT
+#endif // TQLAYOUT_H
diff --git a/tqtinterface/qt4/src/kernel/tqlayoutengine.cpp b/tqtinterface/qt4/src/kernel/tqlayoutengine.cpp
new file mode 100644
index 0000000..7dca5e0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlayoutengine.cpp
@@ -0,0 +1,322 @@
+/****************************************************************************
+**
+** Implementation of TQLayout functionality
+**
+** Created : 981231
+**
+** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqlayout.h"
+#include "private/tqlayoutengine_p.h"
+
+#ifndef TQT_NO_LAYOUT
+
+static inline int toFixed( int i ) { return i * 256; }
+static inline int fRound( int i ) {
+ return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256;
+}
+
+/*
+ This is the main workhorse of the TQGridLayout. It portions out
+ available space to the chain's tqchildren.
+
+ The calculation is done in fixed point: "fixed" variables are
+ scaled by a factor of 256.
+
+ If the tqlayout runs "backwards" (i.e. RightToLeft or Up) the tqlayout
+ is computed mirror-reversed, and it's the caller's responsibility
+ do reverse the values before use.
+
+ chain tqcontains input and output parameters describing the tqgeometry.
+ count is the count of items in the chain; pos and space give the
+ interval (relative to parentWidget topLeft).
+*/
+TQ_EXPORT void qGeomCalc( TQMemArray<TQLayoutStruct> &chain, int start, int count,
+ int pos, int space, int spacer )
+{
+ typedef int fixed;
+ int cHint = 0;
+ int cMin = 0;
+ int cMax = 0;
+ int sumStretch = 0;
+ int spacerCount = 0;
+
+ bool wannaGrow = FALSE; // anyone who really wants to grow?
+ // bool canShrink = FALSE; // anyone who could be persuaded to shrink?
+
+ int i;
+ for ( i = start; i < start + count; i++ ) {
+ chain[i].done = FALSE;
+ cHint += chain[i].smartSizeHint();
+ cMin += chain[i].tqminimumSize;
+ cMax += chain[i].tqmaximumSize;
+ sumStretch += chain[i].stretch;
+ if ( !chain[i].empty )
+ spacerCount++;
+ wannaGrow = wannaGrow || chain[i].expansive || chain[i].stretch > 0;
+ }
+
+ int extraspace = 0;
+ if ( spacerCount )
+ spacerCount--; // only spacers between things
+ if ( space < cMin + spacerCount * spacer ) {
+ for ( i = start; i < start+count; i++ ) {
+ chain[i].size = chain[i].tqminimumSize;
+ chain[i].done = TRUE;
+ }
+ } else if ( space < cHint + spacerCount*spacer ) {
+ /*
+ Less space than smartSizeHint(), but more than tqminimumSize.
+ Currently take space equally from each, as in TQt 2.x.
+ Commented-out lines will give more space to stretchier
+ items.
+ */
+ int n = count;
+ int space_left = space - spacerCount*spacer;
+ int overdraft = cHint - space_left;
+
+ // first give to the fixed ones:
+ for ( i = start; i < start + count; i++ ) {
+ if ( !chain[i].done
+ && chain[i].tqminimumSize >= chain[i].smartSizeHint() ) {
+ chain[i].size = chain[i].smartSizeHint();
+ chain[i].done = TRUE;
+ space_left -= chain[i].smartSizeHint();
+ // sumStretch -= chain[i].stretch;
+ n--;
+ }
+ }
+ bool finished = n == 0;
+ while ( !finished ) {
+ finished = TRUE;
+ fixed fp_over = toFixed( overdraft );
+ fixed fp_w = 0;
+
+ for ( i = start; i < start+count; i++ ) {
+ if ( chain[i].done )
+ continue;
+ // if ( sumStretch <= 0 )
+ fp_w += fp_over / n;
+ // else
+ // fp_w += (fp_over * chain[i].stretch) / sumStretch;
+ int w = fRound( fp_w );
+ chain[i].size = chain[i].smartSizeHint() - w;
+ fp_w -= toFixed( w ); // give the difference to the next
+ if ( chain[i].size < chain[i].tqminimumSize ) {
+ chain[i].done = TRUE;
+ chain[i].size = chain[i].tqminimumSize;
+ finished = FALSE;
+ overdraft -= ( chain[i].smartSizeHint()
+ - chain[i].tqminimumSize );
+ // sumStretch -= chain[i].stretch;
+ n--;
+ break;
+ }
+ }
+ }
+ } else { // extra space
+ int n = count;
+ int space_left = space - spacerCount*spacer;
+ // first give to the fixed ones, and handle non-expansiveness
+ for ( i = start; i < start + count; i++ ) {
+ if ( !chain[i].done
+ && (chain[i].tqmaximumSize <= chain[i].smartSizeHint()
+ || (wannaGrow && !chain[i].expansive && chain[i].stretch == 0)) ) {
+ chain[i].size = chain[i].smartSizeHint();
+ chain[i].done = TRUE;
+ space_left -= chain[i].smartSizeHint();
+ sumStretch -= chain[i].stretch;
+ n--;
+ }
+ }
+ extraspace = space_left;
+
+ /*
+ Do a trial distribution and calculate how much it is off.
+ If there are more deficit pixels than surplus pixels, give
+ the minimum size items what they need, and repeat.
+ Otherwise give to the maximum size items, and repeat.
+
+ Paul Olav Tvete has a wonderful mathematical proof of the
+ correctness of this principle, but unfortunately this
+ comment is too small to contain it.
+ */
+ int surplus, deficit;
+ do {
+ surplus = deficit = 0;
+ fixed fp_space = toFixed( space_left );
+ fixed fp_w = 0;
+ for ( i = start; i < start+count; i++ ) {
+ if ( chain[i].done )
+ continue;
+ extraspace = 0;
+ if ( sumStretch <= 0 )
+ fp_w += fp_space / n;
+ else
+ fp_w += (fp_space * chain[i].stretch) / sumStretch;
+ int w = fRound( fp_w );
+ chain[i].size = w;
+ fp_w -= toFixed( w ); // give the difference to the next
+ if ( w < chain[i].smartSizeHint() ) {
+ deficit += chain[i].smartSizeHint() - w;
+ } else if ( w > chain[i].tqmaximumSize ) {
+ surplus += w - chain[i].tqmaximumSize;
+ }
+ }
+ if ( deficit > 0 && surplus <= deficit ) {
+ // give to the ones that have too little
+ for ( i = start; i < start+count; i++ ) {
+ if ( !chain[i].done &&
+ chain[i].size < chain[i].smartSizeHint() ) {
+ chain[i].size = chain[i].smartSizeHint();
+ chain[i].done = TRUE;
+ space_left -= chain[i].smartSizeHint();
+ sumStretch -= chain[i].stretch;
+ n--;
+ }
+ }
+ }
+ if ( surplus > 0 && surplus >= deficit ) {
+ // take from the ones that have too much
+ for ( i = start; i < start+count; i++ ) {
+ if ( !chain[i].done &&
+ chain[i].size > chain[i].tqmaximumSize ) {
+ chain[i].size = chain[i].tqmaximumSize;
+ chain[i].done = TRUE;
+ space_left -= chain[i].tqmaximumSize;
+ sumStretch -= chain[i].stretch;
+ n--;
+ }
+ }
+ }
+ } while ( n > 0 && surplus != deficit );
+ if ( n == 0 )
+ extraspace = space_left;
+ }
+
+ /*
+ As a last resort, we distribute the unwanted space equally
+ among the spacers (counting the start and end of the chain). We
+ could, but don't, attempt a sub-pixel allocation of the extra
+ space.
+ */
+ int extra = extraspace / ( spacerCount + 2 );
+ int p = pos + extra;
+ for ( i = start; i < start+count; i++ ) {
+ chain[i].pos = p;
+ p = p + chain[i].size;
+ if ( !chain[i].empty )
+ p += spacer+extra;
+ }
+}
+
+TQ_EXPORT TQSize tqSmartMinSize( const TQWidgetItem *i )
+{
+ TQWidget *w = ((TQWidgetItem *)i)->widget();
+
+ TQSize s( 0, 0 );
+ if ( w->tqlayout() ) {
+ s = w->tqlayout()->totalMinimumSize();
+ } else {
+ TQSize sh;
+
+ if ( TQT_TQSIZEPOLICY_OBJECT(w->sizePolicy()).horData() != TQSizePolicy::Ignored ) {
+ if ( TQT_TQSIZEPOLICY_OBJECT(w->sizePolicy()).mayShrinkHorizontally() ) {
+ s.setWidth( w->tqminimumSizeHint().width() );
+ } else {
+ sh = w->tqsizeHint();
+ s.setWidth( sh.width() );
+ }
+ }
+
+ if ( TQT_TQSIZEPOLICY_OBJECT(w->sizePolicy()).verData() != TQSizePolicy::Ignored ) {
+ if ( TQT_TQSIZEPOLICY_OBJECT(w->sizePolicy()).mayShrinkVertically() ) {
+ s.setHeight( w->tqminimumSizeHint().height() );
+ } else {
+ s.setHeight( sh.isValid() ? sh.height()
+ : w->tqsizeHint().height() );
+ }
+ }
+ }
+ s = s.boundedTo( w->tqmaximumSize() );
+ TQSize min = w->tqminimumSize();
+ if ( min.width() > 0 )
+ s.setWidth( min.width() );
+ if ( min.height() > 0 )
+ s.setHeight( min.height() );
+
+ if ( i->hasHeightForWidth() && min.height() == 0 && min.width() > 0 )
+ s.setHeight( i->heightForWidth(s.width()) );
+
+ s = s.expandedTo( TQSize(1, 1) );
+ return s;
+}
+
+TQ_EXPORT TQSize tqSmartMinSize( TQWidget *w )
+{
+ TQWidgetItem item( w );
+ return tqSmartMinSize( &item );
+}
+
+TQ_EXPORT TQSize tqSmartMaxSize( const TQWidgetItem *i, int align )
+{
+ TQWidget *w = ( (TQWidgetItem*)i )->widget();
+ if ( align & TQt::AlignHorizontal_Mask && align & TQt::AlignVertical_Mask )
+ return TQSize( TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX );
+ TQSize s = w->tqmaximumSize();
+ if ( s.width() == TQWIDGETSIZE_MAX && !(align & TQt::AlignHorizontal_Mask) )
+ if ( !TQT_TQSIZEPOLICY_OBJECT(w->sizePolicy()).mayGrowHorizontally() )
+ s.setWidth( w->tqsizeHint().width() );
+
+ if ( s.height() == TQWIDGETSIZE_MAX && !(align & TQt::AlignVertical_Mask) )
+ if ( !TQT_TQSIZEPOLICY_OBJECT(w->sizePolicy()).mayGrowVertically() )
+ s.setHeight( w->tqsizeHint().height() );
+
+ s = s.expandedTo( w->tqminimumSize() );
+
+ if ( align & TQt::AlignHorizontal_Mask )
+ s.setWidth( TQLAYOUTSIZE_MAX );
+ if ( align & TQt::AlignVertical_Mask )
+ s.setHeight( TQLAYOUTSIZE_MAX );
+ return s;
+}
+
+TQ_EXPORT TQSize tqSmartMaxSize( TQWidget *w, int align )
+{
+ TQWidgetItem item( w );
+ return tqSmartMaxSize( &item, align );
+}
+
+#endif // TQT_NO_LAYOUT
diff --git a/tqtinterface/qt4/src/kernel/tqlayoutengine_p.h b/tqtinterface/qt4/src/kernel/tqlayoutengine_p.h
new file mode 100644
index 0000000..9c8064b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlayoutengine_p.h
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Internal header file.
+**
+** Created : 981027
+**
+** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQLAYOUTENGINE_P_H
+#define TQLAYOUTENGINE_P_H
+
+#ifndef TQLAYOUT_H
+ #error "Need to include tqlayout.h before including qtqlayoutengine_p.h"
+#endif
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of qtqlayout.cpp, tqlayoutengine.cpp, qmainwindow.cpp and qsplitter.cpp.
+// This header file may change from version to version without notice,
+// or even be removed.
+//
+// We mean it.
+//
+//
+
+
+#ifndef TQT_H
+#include "tqabstractlayout.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_LAYOUT
+
+struct TQLayoutStruct
+{
+ inline void init( int stretchFactor = 0, int spacing = 0 ) {
+ stretch = stretchFactor;
+ tqminimumSize = tqsizeHint = spacing;
+ tqmaximumSize = TQLAYOUTSIZE_MAX;
+ expansive = FALSE;
+ empty = TRUE;
+ }
+
+ TQCOORD smartSizeHint() {
+ return ( stretch > 0 ) ? tqminimumSize : tqsizeHint;
+ }
+
+ // parameters
+ int stretch;
+ TQCOORD tqsizeHint;
+ TQCOORD tqmaximumSize;
+ TQCOORD tqminimumSize;
+ bool expansive;
+ bool empty;
+
+ // temporary storage
+ bool done;
+
+ // result
+ int pos;
+ int size;
+};
+
+
+TQ_EXPORT void qGeomCalc( TQMemArray<TQLayoutStruct> &chain, int start, int count,
+ int pos, int space, int spacer );
+TQ_EXPORT TQSize tqSmartMinSize( const TQWidgetItem *i );
+TQ_EXPORT TQSize tqSmartMinSize( TQWidget *w );
+TQ_EXPORT TQSize tqSmartMaxSize( const TQWidgetItem *i, int align = 0 );
+TQ_EXPORT TQSize tqSmartMaxSize( TQWidget *w, int align = 0 );
+
+
+/*
+ Modify total maximum (max) and total expansion (exp)
+ when adding boxmax/boxexp.
+
+ Expansive boxes win over non-expansive boxes.
+*/
+static inline void qMaxExpCalc( TQCOORD & max, bool &exp,
+ TQCOORD boxmax, bool boxexp )
+{
+ if ( exp ) {
+ if ( boxexp )
+ max = TQMAX( max, boxmax );
+ } else {
+ if ( boxexp )
+ max = boxmax;
+ else
+ max = TQMIN( max, boxmax );
+ }
+ exp = exp || boxexp;
+}
+
+#endif //TQT_NO_LAYOUT
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqlocalfs.cpp b/tqtinterface/qt4/src/kernel/tqlocalfs.cpp
new file mode 100644
index 0000000..c26c9f4
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlocalfs.cpp
@@ -0,0 +1,407 @@
+/****************************************************************************
+**
+** Implementation of TQLocalFs class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqlocalfs.h"
+
+#ifndef TQT_NO_NETWORKPROTOCOL
+
+#include "tqfileinfo.h"
+#include "tqfile.h"
+#include "tqurlinfo.h"
+#include "tqapplication.h"
+#include "tqurloperator.h"
+#include "tqguardedptr.h"
+
+//#define TQLOCALFS_DEBUG
+
+
+/*!
+ \class TQLocalFs tqlocalfs.h
+ \brief The TQLocalFs class is an implementation of a
+ TQNetworkProtocol that works on the local file system.
+\if defined(commercial)
+ It is part of the <a href="commercialeditions.html">TQt Enterprise Edition</a>.
+\endif
+
+ \module network
+
+ \ingroup io
+
+ This class is derived from TQNetworkProtocol. TQLocalFs is not
+ normally used directly, but rather through a TQUrlOperator, for
+ example:
+ \code
+ TQUrlOperator op( "file:///tmp" );
+ op.listChildren(); // Asks the server to provide a directory listing
+ \endcode
+
+ This code will only work if the TQLocalFs class is registered; to
+ register the class, you must call qInitNetworkProtocols() before
+ using a TQUrlOperator with TQLocalFs.
+
+ If you really need to use TQLocalFs directly, don't forget
+ to set its TQUrlOperator with setUrl().
+
+ \sa \link network.html TQt Network Documentation \endlink TQNetworkProtocol, TQUrlOperator
+*/
+
+/*!
+ Constructor.
+*/
+
+TQLocalFs::TQLocalFs()
+ : TQNetworkProtocol()
+{
+}
+
+static int convertPermissions(TQFileInfo *fi)
+{
+ int p = 0;
+ if ( fi->permission( TQFileInfo::ReadOwner ) )
+ p |= TQUrlInfo::ReadOwner;
+ if ( fi->permission( TQFileInfo::WriteOwner ) )
+ p |= TQUrlInfo::WriteOwner;
+ if ( fi->permission( TQFileInfo::ExeOwner ) )
+ p |= TQUrlInfo::ExeOwner;
+ if ( fi->permission( TQFileInfo::ReadGroup ) )
+ p |= TQUrlInfo::ReadGroup;
+ if ( fi->permission( TQFileInfo::WriteGroup ) )
+ p |= TQUrlInfo::WriteGroup;
+ if ( fi->permission( TQFileInfo::ExeGroup ) )
+ p |= TQUrlInfo::ExeGroup;
+ if ( fi->permission( TQFileInfo::ReadOther ) )
+ p |= TQUrlInfo::ReadOther;
+ if ( fi->permission( TQFileInfo::WriteOther ) )
+ p |= TQUrlInfo::WriteOther;
+ if ( fi->permission( TQFileInfo::ExeOther ) )
+ p |= TQUrlInfo::ExeOther;
+ return p;
+}
+
+/*!
+ \reimp
+*/
+
+void TQLocalFs::operationListChildren( TQNetworkOperation *op )
+{
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: operationListChildren" );
+#endif
+ op->setState( StInProgress );
+
+ dir = TQDir( url()->path() );
+ dir.setNameFilter( url()->nameFilter() );
+ dir.setMatchAllDirs( TRUE );
+ if ( !dir.isReadable() ) {
+ TQString msg = tr( "Could not read directory\n%1" ).arg( url()->path() );
+ op->setState( StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)ErrListChildren );
+ emit finished( op );
+ return;
+ }
+
+ const TQFileInfoList *filist = dir.entryInfoList( TQDir::All | TQDir::Hidden | TQDir::System );
+ if ( !filist ) {
+ TQString msg = tr( "Could not read directory\n%1" ).arg( url()->path() );
+ op->setState( StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)ErrListChildren );
+ emit finished( op );
+ return;
+ }
+
+ emit start( op );
+
+ TQFileInfoListIterator it( *filist );
+ TQFileInfo *fi;
+ TQValueList<TQUrlInfo> infos;
+ while ( ( fi = it.current() ) != 0 ) {
+ ++it;
+ infos << TQUrlInfo( fi->fileName(), convertPermissions(fi), fi->owner(), fi->group(),
+ fi->size(), fi->lastModified(), fi->lastRead(), fi->isDir(), fi->isFile(),
+ fi->isSymLink(), fi->isWritable(), fi->isReadable(), fi->isExecutable() );
+ }
+ emit newChildren( infos, op );
+ op->setState( StDone );
+ emit finished( op );
+}
+
+/*!
+ \reimp
+*/
+
+void TQLocalFs::operationMkDir( TQNetworkOperation *op )
+{
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: operationMkDir" );
+#endif
+ op->setState( StInProgress );
+ TQString dirname = op->arg( 0 );
+
+ dir = TQDir( url()->path() );
+ if ( dir.mkdir( dirname ) ) {
+ TQFileInfo fi( dir, dirname );
+ TQUrlInfo inf( fi.fileName(), convertPermissions(&fi), fi.owner(), fi.group(),
+ fi.size(), fi.lastModified(), fi.lastRead(), fi.isDir(), fi.isFile(),
+ fi.isSymLink(), fi.isWritable(), fi.isReadable(), fi.isExecutable() );
+ emit newChild( inf, op );
+ op->setState( StDone );
+ emit createdDirectory( inf, op );
+ emit finished( op );
+ } else {
+ TQString msg = tr( "Could not create directory\n%1" ).arg( dirname );
+ op->setState( StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)ErrMkDir );
+ emit finished( op );
+ }
+}
+
+/*!
+ \reimp
+*/
+
+void TQLocalFs::operationRemove( TQNetworkOperation *op )
+{
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: operationRemove" );
+#endif
+ op->setState( StInProgress );
+ TQString name = TQUrl( op->arg( 0 ) ).path();
+ bool deleted = FALSE;
+
+ dir = TQDir( url()->path() );
+
+ TQFileInfo fi( dir, name );
+ if ( fi.isDir() ) {
+ if ( dir.rmdir( name ) )
+ deleted = TRUE;
+ }
+
+ if ( deleted || dir.remove( name ) ) {
+ op->setState( StDone );
+ emit removed( op );
+ emit finished( op );
+ } else {
+ TQString msg = tr( "Could not remove file or directory\n%1" ).arg( name );
+ op->setState( StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)ErrRemove );
+ emit finished( op );
+ }
+}
+
+/*!
+ \reimp
+*/
+
+void TQLocalFs::operationRename( TQNetworkOperation *op )
+{
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: operationRename" );
+#endif
+ op->setState( StInProgress );
+ TQString oldname = op->arg( 0 );
+ TQString newname = op->arg( 1 );
+
+ dir = TQDir( url()->path() );
+ if ( dir.rename( oldname, newname ) ) {
+ op->setState( StDone );
+ emit itemChanged( op );
+ emit finished( op );
+ } else {
+ TQString msg = tr( "Could not rename\n%1\nto\n%2" ).arg( oldname ).arg( newname );
+ op->setState( StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)ErrRename );
+ emit finished( op );
+ }
+}
+
+/*!
+ \reimp
+*/
+
+void TQLocalFs::operationGet( TQNetworkOperation *op )
+{
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: operationGet" );
+#endif
+ op->setState( StInProgress );
+ TQString from = TQUrl( op->arg( 0 ) ).path();
+
+ TQFile f( from );
+ if ( !f.open( IO_ReadOnly ) ) {
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: could not open %s", from.latin1() );
+#endif
+ TQString msg = tr( "Could not open\n%1" ).arg( from );
+ op->setState( StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)ErrGet );
+ emit finished( op );
+ return;
+ }
+
+ TQByteArray s;
+ emit dataTransferProgress( 0, f.size(), op );
+ if ( f.size() != 0 ) {
+ int blockSize = calcBlockSize( f.size() );
+ if ( (int)f.size() < blockSize ) {
+ s.resize( f.size() );
+ f.readBlock( s.data(), f.size() );
+ emit data( s, op );
+ emit dataTransferProgress( f.size(), f.size(), op );
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: got all %d bytes at once", f.size() );
+#endif
+ } else {
+ s.resize( blockSize );
+ int remaining = f.size();
+ TQGuardedPtr<TQObject> that = this;
+ while ( that && remaining > 0 ) {
+ if ( operationInProgress() != op )
+ return;
+ if ( remaining >= blockSize ) {
+ f.readBlock( s.data(), blockSize );
+ emit data( s, op );
+ emit dataTransferProgress( f.size() - remaining, f.size(), op );
+ remaining -= blockSize;
+ } else {
+ s.resize( remaining );
+ f.readBlock( s.data(), remaining );
+ emit data( s, op );
+ emit dataTransferProgress( f.size() - remaining, f.size(), op );
+ remaining -= remaining;
+ }
+ tqApp->processEvents();
+ }
+ if (!that)
+ return;
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: got all %d bytes step by step", f.size() );
+#endif
+ emit dataTransferProgress( f.size(), f.size(), op );
+ }
+ }
+ op->setState( StDone );
+ f.close();
+ emit finished( op );
+}
+
+/*!
+ \reimp
+*/
+
+void TQLocalFs::operationPut( TQNetworkOperation *op )
+{
+#ifdef TQLOCALFS_DEBUG
+ qDebug( "TQLocalFs: operationPut" );
+#endif
+ op->setState( StInProgress );
+ TQString to = TQUrl( op->arg( 0 ) ).path();
+
+ TQFile f( to );
+ if ( !f.open( IO_WriteOnly ) ) {
+ TQString msg = tr( "Could not write\n%1" ).arg( to );
+ op->setState( StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)ErrPut );
+ emit finished( op );
+ return;
+ }
+
+ TQByteArray ba( op->rawArg( 1 ) );
+ emit dataTransferProgress( 0, ba.size(), op );
+ int blockSize = calcBlockSize( ba.size() );
+ if ( (int)ba.size() < blockSize ) {
+ f.writeBlock( ba.data(), ba.size() );
+ emit dataTransferProgress( ba.size(), ba.size(), op );
+ } else {
+ int i = 0;
+ while ( i + blockSize < (int)ba.size() - 1 ) {
+ if ( operationInProgress() != op )
+ return;
+ f.writeBlock( &ba.data()[ i ], blockSize );
+ f.flush();
+ emit dataTransferProgress( i + blockSize, ba.size(), op );
+ i += blockSize;
+ TQGuardedPtr<TQObject> that = this;
+ tqApp->processEvents();
+ if (!that)
+ return;
+ }
+ if ( i < (int)ba.size() - 1 )
+ f.writeBlock( &ba.data()[ i ], ba.size() - i );
+ emit dataTransferProgress( ba.size(), ba.size(), op );
+ }
+ op->setState( StDone );
+ f.close();
+ emit finished( op );
+}
+
+/*!
+ \reimp
+*/
+
+int TQLocalFs::supportedOperations() const
+{
+ return OpListChildren | OpMkDir | OpRemove | OpRename | OpGet | OpPut;
+}
+
+/*!
+ \internal
+*/
+
+int TQLocalFs::calcBlockSize( int totalSize ) const
+{
+ if ( totalSize == 0 )
+ return 1024;
+ int s = totalSize / 100;
+ // we want a block size between 1KB and 1MB
+ if ( s < 1024 )
+ s = 1024;
+ if ( s > 1048576 )
+ s = 1048576;
+ return s;
+}
+
+#endif // TQT_NO_NETWORKPROTOCOL
diff --git a/tqtinterface/qt4/src/kernel/tqlocalfs.h b/tqtinterface/qt4/src/kernel/tqlocalfs.h
new file mode 100644
index 0000000..d327d63
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlocalfs.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Definition of TQLocalFs class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQLOCALFS_H
+#define TQLOCALFS_H
+
+#ifndef TQT_H
+#include "tqnetworkprotocol.h"
+#include "tqdir.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_NETWORKPROTOCOL
+
+class TQ_EXPORT TQLocalFs : public TQNetworkProtocol
+{
+ TQ_OBJECT
+
+public:
+ TQLocalFs();
+ virtual int supportedOperations() const;
+
+protected:
+ virtual void operationListChildren( TQNetworkOperation *op );
+ virtual void operationMkDir( TQNetworkOperation *op );
+ virtual void operationRemove( TQNetworkOperation *op );
+ virtual void operationRename( TQNetworkOperation *op );
+ virtual void operationGet( TQNetworkOperation *op );
+ virtual void operationPut( TQNetworkOperation *op );
+
+private:
+ int calcBlockSize( int totalSize ) const;
+ TQDir dir;
+
+};
+
+#endif // TQT_NO_NETWORKPROTOCOL
+
+#endif // TQLOCALFS_H
diff --git a/tqtinterface/qt4/src/kernel/tqlock.cpp b/tqtinterface/qt4/src/kernel/tqlock.cpp
new file mode 100644
index 0000000..8e32602
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlock.cpp
@@ -0,0 +1,297 @@
+/****************************************************************************
+**
+** Definition of TQLock class. This manages interprocess locking
+**
+** Created : 20000406
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqlock_p.h"
+
+#ifndef TQT_NO_TQWS_MULTIPROCESS
+
+#include <unistd.h>
+#include <sys/types.h>
+#if defined(TQ_OS_MACX)
+#define TQ_NO_SEMAPHORE
+#include <sys/stat.h>
+#include <sys/file.h>
+#else
+#include <sys/sem.h>
+#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) \
+ || defined(TQ_OS_FREEBSD) || defined(TQ_OS_OPENBSD) || defined(TQ_OS_NETBSD) || defined(TQ_OS_BSDI)
+/* union semun is defined by including <sys/sem.h> */
+#else
+/* according to X/OPEN we have to define it ourselves */
+union semun {
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
+ unsigned short *array; /* array for GETALL, SETALL */
+};
+#endif
+#endif
+#include <sys/ipc.h>
+#include <string.h>
+#include <errno.h>
+
+#define MAX_LOCKS 200 // maximum simultaneous read locks
+
+class TQLockData
+{
+public:
+#ifdef TQ_NO_SEMAPHORE
+ TQCString file;
+#endif
+ int id;
+ int count;
+ bool owned;
+};
+
+#endif
+
+/*!
+ \class TQLock qlock_p.h
+ \brief The TQLock class is a wrapper for a System V shared semaphore.
+
+ \ingroup qws
+ \ingroup io
+
+ \internal
+
+ It is used by TQt/Embedded for synchronizing access to the graphics
+ card and shared memory region between processes.
+*/
+
+/*!
+ \enum TQLock::Type
+
+ \value Read
+ \value Write
+*/
+
+/*!
+ \fn TQLock::TQLock( const TQString &filename, char id, bool create )
+
+ Creates a lock. \a filename is the file path of the Unix-domain
+ socket the TQt/Embedded client is using. \a id is the name of the
+ particular lock to be created on that socket. If \a create is TRUE
+ the lock is to be created (as the TQt/Embedded server does); if \a
+ create is FALSE the lock should exist already (as the TQt/Embedded
+ client expects).
+*/
+
+TQLock::TQLock( const TQString &filename, char id, bool create )
+{
+#ifndef TQT_NO_TQWS_MULTIPROCESS
+ data = new TQLockData;
+ data->count = 0;
+#ifdef TQ_NO_SEMAPHORE
+ data->file = TQString(filename+id).local8Bit();
+ for(int x = 0; x < 2; x++) {
+ data->id = open(data->file, O_RDWR | (x ? O_CREAT : 0), S_IRWXU);
+ if(data->id != -1 || !create) {
+ data->owned = x;
+ break;
+ }
+ }
+#else
+ key_t semkey = ftok(filename, id);
+ data->id = semget(semkey,0,0);
+ data->owned = create;
+ if ( create ) {
+ semun arg; arg.val = 0;
+ if ( data->id != -1 )
+ semctl(data->id,0,IPC_RMID,arg);
+ data->id = semget(semkey,1,IPC_CREAT|0600);
+ arg.val = MAX_LOCKS;
+ semctl(data->id,0,SETVAL,arg);
+ }
+#endif
+ if ( data->id == -1 ) {
+ qWarning( "Cannot %s semaphore %s \'%c\'",
+ create ? "create" : "get", filename.latin1(), id );
+ qDebug("Error %d %s\n",errno,strerror(errno));
+ }
+#endif
+}
+
+/*!
+ \fn TQLock::~TQLock()
+
+ Destroys a lock
+*/
+
+TQLock::~TQLock()
+{
+#ifndef TQT_NO_TQWS_MULTIPROCESS
+ if ( locked() )
+ unlock();
+#ifdef TQ_NO_SEMAPHORE
+ if(isValid()) {
+ close(data->id);
+ if( data->owned )
+ unlink( data->file );
+ }
+#else
+ if(data->owned) {
+ semun arg; arg.val = 0;
+ semctl( data->id, 0, IPC_RMID, arg );
+ }
+#endif
+ delete data;
+#endif
+}
+
+/*!
+ \fn bool TQLock::isValid() const
+
+ Returns TRUE if the lock constructor was succesful; returns FALSE if
+ the lock could not be created or was not available to connect to.
+*/
+
+bool TQLock::isValid() const
+{
+#ifndef TQT_NO_TQWS_MULTIPROCESS
+ return (data->id != -1);
+#else
+ return TRUE;
+#endif
+}
+
+/*!
+ Locks the semaphore with a lock of type \a t. Locks can either be
+ \c Read or \c Write. If a lock is \c Read, attempts by other
+ processes to obtain \c Read locks will succeed, and \c Write
+ attempts will block until the lock is unlocked. If locked as \c
+ Write, all attempts to lock by other processes will block until
+ the lock is unlocked. Locks are stacked: i.e. a given TQLock can be
+ locked multiple times by the same process without blocking, and
+ will only be unlocked after a corresponding number of unlock()
+ calls.
+*/
+
+void TQLock::lock( Type t )
+{
+#ifndef TQT_NO_TQWS_MULTIPROCESS
+ if ( !data->count ) {
+#ifdef TQ_NO_SEMAPHORE
+ int op = LOCK_SH;
+ if(t == Write)
+ op = LOCK_EX;
+ for( int rv=1; rv; ) {
+ rv = flock(data->id, op);
+ if (rv == -1 && errno != EINTR)
+ qDebug("Semop lock failure %s",strerror(errno));
+ }
+#else
+ sembuf sops;
+ sops.sem_num = 0;
+ sops.sem_flg = SEM_UNDO;
+
+ if ( t == Write ) {
+ sops.sem_op = -MAX_LOCKS;
+ type = Write;
+ } else {
+ sops.sem_op = -1;
+ type = Read;
+ }
+
+ int rv;
+ do {
+ rv = semop(data->id,&sops,1);
+ if (rv == -1 && errno != EINTR)
+ qDebug("Semop lock failure %s",strerror(errno));
+ } while ( rv == -1 && errno == EINTR );
+#endif
+ }
+ data->count++;
+#endif
+}
+
+/*!
+ \fn void TQLock::unlock()
+
+ Unlocks the semaphore. If other processes were blocking waiting to
+ lock() the semaphore, one of them will wake up and succeed in
+ lock()ing.
+*/
+
+void TQLock::unlock()
+{
+#ifndef TQT_NO_TQWS_MULTIPROCESS
+ if( data->count ) {
+ data->count--;
+ if( !data->count ) {
+#ifdef TQ_NO_SEMAPHORE
+ for( int rv=1; rv; ) {
+ rv = flock(data->id, LOCK_UN);
+ if (rv == -1 && errno != EINTR)
+ qDebug("Semop lock failure %s",strerror(errno));
+ }
+#else
+ sembuf sops;
+ sops.sem_num = 0;
+ sops.sem_op = 1;
+ sops.sem_flg = SEM_UNDO;
+ if ( type == Write )
+ sops.sem_op = MAX_LOCKS;
+
+ int rv;
+ do {
+ rv = semop(data->id,&sops,1);
+ if (rv == -1 && errno != EINTR)
+ qDebug("Semop unlock failure %s",strerror(errno));
+ } while ( rv == -1 && errno == EINTR );
+#endif
+ }
+ } else {
+ qDebug("Unlock without corresponding lock");
+ }
+#endif
+}
+
+/*!
+ \fn bool TQLock::locked() const
+
+ Returns TRUE if the lock is currently held by the current process;
+ otherwise returns FALSE.
+*/
+
+bool TQLock::locked() const
+{
+#ifndef TQT_NO_TQWS_MULTIPROCESS
+ return (data->count > 0);
+#else
+ return FALSE;
+#endif
+}
diff --git a/tqtinterface/qt4/src/kernel/tqlock_p.h b/tqtinterface/qt4/src/kernel/tqlock_p.h
new file mode 100644
index 0000000..0f45144
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqlock_p.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Definition of TQLock class. This manages interprocess locking
+**
+** Created : 20000406
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQLOCK_P_H
+#define TQLOCK_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. This header file may
+// change from version to version without notice, or even be
+// removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#include "tqstring.h"
+#endif // TQT_H
+
+class TQLockData;
+
+class TQLock
+{
+public:
+ TQLock( const TQString &filename, char id, bool create = FALSE );
+ ~TQLock();
+
+ enum Type { Read, Write };
+
+ bool isValid() const;
+ void lock( Type type );
+ void unlock();
+ bool locked() const;
+
+private:
+ Type type;
+ TQLockData *data;
+};
+
+
+// Nice class for ensuring the lock is released.
+// Just create one on the stack and the lock is automatically released
+// when TQLockHolder is destructed.
+class TQLockHolder
+{
+public:
+ TQLockHolder( TQLock *l, TQLock::Type type ) : qlock(l) {
+ qlock->lock( type );
+ }
+ ~TQLockHolder() { if ( locked() ) qlock->unlock(); }
+
+ void lock( TQLock::Type type ) { qlock->lock( type ); }
+ void unlock() { qlock->unlock(); }
+ bool locked() const { return qlock->locked(); }
+
+private:
+ TQLock *qlock;
+};
+
+#endif
+
diff --git a/tqtinterface/qt4/src/kernel/tqmetaobject.cpp b/tqtinterface/qt4/src/kernel/tqmetaobject.cpp
new file mode 100644
index 0000000..09d8439
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmetaobject.cpp
@@ -0,0 +1,1792 @@
+/****************************************************************************
+**
+** Implementation of TQMetaObject class
+**
+** Created : 930419
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqmetaobject.h"
+#include "tqasciidict.h"
+
+#ifdef TQT_THREAD_SUPPORT
+#include <private/tqmutexpool_p.h>
+#endif // TQT_THREAD_SUPPORT
+
+#include <private/tqucom_p.h>
+
+#ifdef USE_QT4
+
+// #include <private/qt4_qmetaobject_p.h>
+
+/*!
+ Returns a list with the names of all this class's properties.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property()
+*/
+TQStrList TQMetaObject::propertyNames( bool super ) const
+{
+ TQStrList l( FALSE );
+ int n = numProperties( super );
+ for( int i = 0; i < n; ++i ) {
+ if (property( i, super))
+ l.append( property( i, super)->name() );
+ else
+ l.append( "[TQt TQMetaObject::propertyNames was unable to find the Qt4 name for this property]" );
+ }
+ return l;
+}
+
+const char * TQMetaData::name() const {
+ return signature(); // Member name
+}
+
+const TQUMethod* TQMetaData::method() const {
+ // FIXME
+ // Verify that this routine accurately fills internal_method_information!
+ printf("[WARNING] const TQUMethod* TQMetaData::method() partially implemented!\n\r");
+
+ if (!internal_method_information) {
+ internal_method_information = new TQUMethod;
+ internal_method_information->parameters = 0;
+ }
+ internal_method_information->name = QMetaMethod::signature();
+ internal_method_information->count = QMetaMethod::parameterNames().count();
+ if (internal_method_information->parameters) {
+ for (int i=0; i<internal_method_information->count; i++) {
+ if (internal_method_information->parameters[i].type)
+ delete internal_method_information->parameters[i].type;
+ }
+ delete [] internal_method_information->parameters;
+ }
+ internal_method_information->parameters = new TQUParameter[internal_method_information->count];
+ for (int i=0; i<internal_method_information->count; i++) {
+ const_cast<TQUParameter&>(internal_method_information->parameters[i]).name = QMetaMethod::parameterNames().at(i).data();
+// const_cast<TQUParameter&>(internal_method_information->parameters[i]).type = new TQUType;
+// const_cast<TQUParameter&>(internal_method_information->parameters[i]).type.desc = QMetaMethod::parameterTypes().at(i).data();
+ const_cast<TQUParameter&>(internal_method_information->parameters[i]).typeExtra = 0;
+ const_cast<TQUParameter&>(internal_method_information->parameters[i]).inOut = 3;
+ }
+ return internal_method_information;
+}
+
+TQMetaEnum::TQMetaEnum() : QMetaEnum() { internal_item_list = 0; }
+
+uint TQMetaEnum::count() const {
+ return QMetaEnum::keyCount();
+}
+
+TQMetaEnum::Item* TQMetaEnum::items() const {
+ if (internal_item_list)
+ delete [] internal_item_list;
+ int internal_item_count = count();
+ internal_item_list = new Item[internal_item_count];
+ for (int i=0; i<internal_item_count;i++) {
+ internal_item_list[i].key = QMetaEnum::key(i);
+ internal_item_list[i].value = QMetaEnum::value(i);
+ }
+ return internal_item_list;
+}
+
+TQMetaData::TQMetaData() : QMetaMethod() {}
+
+TQMetaProperty::TQMetaProperty() : QMetaProperty() {}
+
+/*!
+ Returns the possible enumeration keys if this property is an
+ enumeration type (or a set type).
+
+ \sa isEnumType()
+*/
+TQStrList TQMetaProperty::enumKeys() const
+{
+ TQStrList l( FALSE );
+ QMetaEnum ed = enumerator();
+ for( uint i = 0; i < ed.keyCount(); ++i ) {
+ uint j = 0;
+ while ( j < i && ed.value(j) != ed.value(i) )
+ ++j;
+ if ( i == j )
+ l.append( ed.key(i) );
+ }
+ return l;
+}
+
+bool TQMetaProperty::isSetType() const {
+ return isFlagType ();
+}
+
+int TQMetaProperty::keyToValue( const char* key ) const {
+ return enumerator().keyToValue(key);
+}
+
+const char* TQMetaProperty::valueToKey( int value ) const {
+ return enumerator().valueToKey(value);
+}
+
+int TQMetaProperty::keysToValue( const TQStrList& keys_in ) const {
+ TQString tqs = "";
+ TQStrList keys = keys_in;
+ char *key;
+ for ( key = keys.first(); key; key = keys.next() ) {
+ tqs = tqs + "|" + key;
+ }
+ tqs.remove(0,1);
+ return enumerator().keysToValue(TQCString(tqs));
+}
+
+TQStrList TQMetaProperty::valueToKeys( int value ) const {
+ TQStrList keys;
+ QByteArray qba = enumerator().valueToKeys(value);
+ TQStringList keys_out = TQStringList::split("|", TQString(TQCString(qba)));
+ for ( TQStringList::Iterator it = keys_out.begin(); it != keys_out.end(); ++it ) {
+ keys.append(*it);
+ }
+ return keys;
+}
+
+bool TQMetaProperty::writable() const {
+ return isWritable();
+}
+
+const char* TQMetaProperty::type() const {
+ return QMetaProperty::typeName();
+}
+
+bool TQMetaProperty::designable( TQT_BASE_OBJECT_NAME *o ) const {
+ return isDesignable(o);
+}
+
+bool TQMetaProperty::scriptable( TQT_BASE_OBJECT_NAME *o ) const {
+ return isScriptable(o);
+}
+
+bool TQMetaProperty::stored( TQT_BASE_OBJECT_NAME *o ) const {
+ return isStored(o);
+}
+
+/*!\internal
+ */
+bool TQMetaProperty::stdSet() const
+{
+// if ( !testFlags( Override ) || testFlags( Writable ) )
+// return testFlags( StdSet );
+// const TQMetaObject* mo = (*meta);
+// const TQMetaProperty* tqparent = mo->resolveProperty( this );
+// return tqparent ? tqparent->stdSet() : FALSE;
+
+ // [FIXME]
+ printf("[WARNING] bool TQMetaProperty::stdSet() const unimplemented\n\r");
+ return FALSE;
+}
+
+TQMetaObject::TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums,
+#endif // TQT_NO_PROPERTIES
+ const TQClassInfo *const class_info, int n_info ) : QMetaObject() {
+ printf("[WARNING] TQMetaObject() constructor unimplemented\n\r"); // [FIXME]
+}
+
+#ifndef TQT_NO_PROPERTIES
+TQMetaObject::TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS, const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums, bool (*qt_static_property)(TQObject*, int, int, TQVariant*), const TQClassInfo *const class_info, int n_info ) : QMetaObject() {
+ printf("[WARNING] TQMetaObject() constructor unimplemented\n\r"); // [FIXME]
+}
+#endif // TQT_NO_PROPERTIES
+
+TQStrList TQMetaObject::slotNames( bool super ) const {
+ printf("[WARNING] TQStrList slotNames( bool super = FALSE ) unimplemented\n\r");
+ return TQStrList();
+}
+
+TQStrList TQMetaObject::signalNames( bool super ) const {
+ printf("[WARNING] TQStrList signalNames( bool super = FALSE ) const unimplemented\n\r");
+ return TQStrList();
+}
+
+/*!
+ Returns the number of Q_SLOTS for this class.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+
+ \sa slotNames()
+*/
+int TQMetaObject::numSlots( bool super ) const // number of Q_SLOTS
+{
+ int i;
+ int n=0;
+ for (i=0;i<methodCount();i++) {
+ if (method(i).methodType() == QMetaMethod::Slot) {
+ n++;
+ }
+ }
+
+ if ( !super || !superClass() )
+ return n;
+ return n + tqsuperClass()->numSlots( super );
+}
+
+/*!
+ Returns the number of items of class information available for
+ this class.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+int TQMetaObject::numClassInfo( bool super ) const
+{
+ return classInfoCount() + ((super && tqsuperClass())?tqsuperClass()->numClassInfo(super):0);
+}
+
+/*!
+ Returns the number of Q_SIGNALS for this class.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+
+ \sa signalNames()
+*/
+int TQMetaObject::numSignals( bool super ) const // number of Q_SIGNALS
+{
+ int i;
+ int n=0;
+ for (i=0;i<methodCount();i++) {
+ if (method(i).methodType() == QMetaMethod::Signal) {
+ n++;
+ }
+ }
+
+ if ( !super || !superClass() )
+ return n;
+ return n + tqsuperClass()->numSignals( super );
+}
+
+#if 0
+/*! \internal
+
+ Returns the meta data of the slot with the name \a n or 0 if no
+ such slot exists.
+
+ If \a super is TRUE, inherited slots are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::slot( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( slotDict && idx >= 0 && idx < (int) slotDict->count() ) {
+ if ( idx >= 0 && idx < numSlots(true) ) {
+// return slotData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->slot( index, super );
+}
+
+/*! \internal
+
+ Returns the meta data of the signal with the name \a n or 0 if no
+ such signal exists.
+
+ If \a super is TRUE, inherited signals are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::signal( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( signalDict && idx >= 0 && idx < (int) signalDict->count() ) {
+ if ( idx >= 0 && idx < numSignals(true) ) {
+// return signalData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->signal( index, super );
+}
+#endif
+
+/*! \internal
+
+ Returns the meta data of the slot with the name \a n or 0 if no
+ such slot exists.
+
+ If \a super is TRUE, inherited slots are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::slot( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( slotDict && idx >= 0 && idx < (int) slotDict->count() ) {
+ if ( idx >= 0 && idx < numSlots(true) ) {
+// return slotData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->slot( index, super );
+}
+
+/*! \internal
+
+ Returns the meta data of the signal with the name \a n or 0 if no
+ such signal exists.
+
+ If \a super is TRUE, inherited signals are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::signal( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( signalDict && idx >= 0 && idx < (int) signalDict->count() ) {
+ if ( idx >= 0 && idx < numSignals(true) ) {
+// return signalData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->signal( index, super );
+}
+
+/*! \internal
+ Returns the index of the slot with name \n or -1 if no such slot exists.
+
+ If \a super is TRUE, inherited slots are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+int TQMetaObject::tqfindSlot( const char* n, bool super ) const
+{
+// TQStrList l( FALSE );
+// int m = methodCount();
+// for( int i = 0; i < m; ++i ) {
+// // if ( normalizedSignature(slot( i, super)->signature()) == QByteArray(n) ) {
+// if ( normalizedSignature(method(i).signature()) == QByteArray(n) ) {
+// if (method(i).methodType() == QMetaMethod::Slot) {
+// return i;
+// }
+// }
+// }
+// return -1;
+
+ if (super) printf("[WARNING] In TQMetaObject::tqfindSlot(), superclasses are not being searched for the slot\n\r");
+ return indexOfSlot(normalizedSignature(n));
+}
+
+/*! \internal
+ Returns the index of the signal with name \n or -1 if no such signal exists.
+
+ If \a super is TRUE, inherited signals are included.
+
+ [FIXME]: Superclass handling is badly broken
+*/
+int TQMetaObject::tqfindSignal( const char* n, bool super ) const
+{
+// TQStrList l( FALSE );
+// int m = methodCount();
+// for( int i = 0; i < m; ++i ) {
+// // if ( normalizedSignature(signal( i, super)->signature()) == QByteArray(n) ) {
+// if ( normalizedSignature(method(i).signature()) == QByteArray(n) ) {
+// if (method(i).methodType() == QMetaMethod::Signal) {
+// return i;
+// }
+// }
+// }
+// return -1;
+
+ if (super) printf("[WARNING] In TQMetaObject::tqfindSignal(), superclasses are not being searched for the signal\n\r");
+ return indexOfSignal(normalizedSignature(n));
+}
+
+#ifndef QT_NO_PROPERTIES
+
+/*!
+ Returns the number of properties for this class.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+ */
+int TQMetaObject::numProperties( bool super ) const // number of properties
+{
+ int i;
+ int n=0;
+ for (i=0;i<propertyCount();i++) {
+// if (property(i).propertyType() == QMetaProperty::Property) {
+ n++;
+// }
+ }
+
+ if ( !super || !superClass() )
+ return n;
+ return n + tqsuperClass()->numProperties( super );
+}
+
+/*!
+ Returns the property meta data for the property at index \a index
+ or 0 if no such property exists.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+
+ [FIXME]: Superclass handling is badly broken
+ */
+static QMetaProperty tqmo_propmethod_curprop;
+const TQMetaProperty* TQMetaObject::property( int index, bool super ) const
+{
+ QMetaProperty mp;
+ const QMetaProperty *pr;
+ int idx = index - ( super ? propertyOffset() : 0 );
+// if ( d->propData && idx >= 0 && idx < (int)d->numPropData )
+ if ( idx >= 0 && idx < numProperties(true) )
+ tqmo_propmethod_curprop = QMetaObject::property(idx);
+ return static_cast<const TQMetaProperty*>(&tqmo_propmethod_curprop);
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->property( index, super );
+}
+
+int TQMetaObject::tqfindProperty( const char *name, bool super ) const {
+ TQ_UNUSED(name);
+ return indexOfProperty(name);
+}
+
+TQMetaObject * TQMetaObject::tqsuperClass() const {
+ return static_cast<TQMetaObject*>(const_cast<QMetaObject*>(superClass()));
+}
+
+const char * TQMetaObject::tqsuperClassName() const {
+ return static_cast<TQMetaObject*>(const_cast<QMetaObject*>(superClass()))->className();
+}
+
+#endif // QT_NO_PROPERTIES
+
+/*!
+ Returns the class information with index \a index or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const TQClassInfo* TQMetaObject::classInfo( int index, bool super ) const
+{
+ if ( index < 0 )
+ return 0;
+ if ( index < QMetaObject::classInfoCount() )
+ return static_cast<TQClassInfo*>(&(QMetaObject::classInfo(index)));
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->classInfo( index - QMetaObject::classInfoCount(), super );
+}
+
+/*!
+ \overload
+ Returns the class information with name \a name or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const char* TQMetaObject::classInfo( const char* name, bool super ) const
+{
+ for( int i = 0; i < QMetaObject::classInfoCount(); ++i ) {
+ if ( qstrcmp( QMetaObject::classInfo(i).name(), name ) == 0 )
+ return QMetaObject::classInfo(i).value();
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->classInfo( name, super );
+}
+
+/*!\internal
+
+ */
+TQStrList TQMetaObject::enumeratorNames( bool super ) const
+{
+ TQStrList l( FALSE );
+
+ if ( tqsuperClass() && super ) {
+ TQStrList sl = tqsuperClass()->enumeratorNames( super );
+ for ( TQStrListIterator slit( sl ); slit.current(); ++slit )
+ l.append( slit.current() );
+ }
+
+ for( int i = 0; i < QMetaObject::enumeratorCount(); ++i ) {
+// if ( d->enumData[i].items )
+ if (QMetaObject::enumerator(i).name() != "")
+ l.append( QMetaObject::enumerator(i).name() );
+ }
+
+ return l;
+}
+
+/*!\internal
+ */
+const TQMetaEnum* TQMetaObject::enumerator( const char* name, bool super ) const
+{
+ for( int i = 0; i < QMetaObject::enumeratorCount(); ++i )
+ if ( qstrcmp( QMetaObject::enumerator(i).name(), name ) == 0 )
+ return static_cast<TQMetaEnum*>(&(QMetaObject::enumerator(i)));
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->enumerator( name, super );
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQMetaData tqmetaobject.h
+ \reentrant
+
+ \brief The TQMetaData class provides information about a member function that is known to the meta object system.
+
+ \internal
+
+ The struct consists of three members, \e name, \e method and \e access:
+
+ \code
+ const char *name; // - member name
+ const TQUMethod* method; // - detailed method description
+ enum Access { Private, Protected, Public };
+ Access access; // - access permission
+ \endcode
+ */
+
+/*!
+ \class TQClassInfo tqmetaobject.h
+
+ \brief The TQClassInfo class provides a struct that stores some basic information about a single class.
+
+ \internal
+
+ The class information is a simple \e name - \e value pair:
+
+ \code
+ const char* name;
+ const char* value;
+ \endcode
+
+ */
+
+
+/*!
+ \class TQMetaObject tqmetaobject.h
+ \brief The TQMetaObject class tqcontains meta information about TQt objects.
+
+ \ingroup objectmodel
+
+ The Meta Object System in TQt is responsible for the Q_SIGNALS and
+ Q_SLOTS inter-object communication mechanism, runtime type
+ information and the property system. All meta information in TQt is
+ kept in a single instance of TQMetaObject per class.
+
+ This class is not normally required for application programming.
+ But if you write meta applications, such as scripting engines or
+ GUI builders, you might tqfind these functions useful:
+ \list
+ \i className() to get the name of a class.
+ \i superClassName() to get the name of the superclass.
+ \i inherits(), the function called by TQObject::inherits().
+ \i superClass() to access the superclass's meta object.
+ \i numSlots(), numSignals(), slotNames(), and signalNames() to get
+ information about a class's Q_SIGNALS and Q_SLOTS.
+ \i property() and propertyNames() to obtain information about a
+ class's properties.
+ \endlist
+
+ Classes may have a list of name-value pairs of class information.
+ The number of pairs is returned by numClassInfo(), and values are
+ returned by classInfo().
+
+ \sa \link tqmoc.html tqmoc (Meta Object Compiler)\endlink
+
+*/
+
+
+/*****************************************************************************
+ The private object.
+ *****************************************************************************/
+
+// extra flags from tqmoc.y
+enum Flags {
+ Invalid = 0x00000000,
+ Readable = 0x00000001,
+ Writable = 0x00000002,
+ EnumOrSet = 0x00000004,
+ UnresolvedEnum = 0x00000008,
+ StdSet = 0x00000100,
+ Override = 0x00000200,
+ NotDesignable = 0x00001000,
+ DesignableOverride = 0x00002000,
+ NotScriptable = 0x00004000,
+ ScriptableOverride = 0x00008000,
+ NotStored = 0x00010000,
+ StoredOverride = 0x00020000
+};
+
+static TQAsciiDict<void> *qt_metaobjects = 0;
+static int qt_metaobjects_count = 0;
+
+class TQMetaObjectPrivate
+{
+public:
+ TQMetaObjectPrivate() :
+#ifndef TQT_NO_PROPERTIES
+ enumData(0), numEnumData(0),
+ propData(0),numPropData(0),
+ qt_static_property(0),
+#endif
+ classInfo(0), numClassInfo(0) {}
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaEnum *enumData;
+ int numEnumData;
+ const TQMetaProperty *propData;
+ int numPropData;
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*);
+#endif
+ const TQClassInfo *classInfo;
+ int numClassInfo;
+};
+
+
+/*****************************************************************************
+ Internal dictionary for fast access to class members
+ *****************************************************************************/
+
+#if defined(TQ_CANNOT_DELETE_CONSTANT)
+typedef TQMetaData TQConstMetaData;
+#else
+typedef const TQMetaData TQConstMetaData;
+#endif
+
+class TQ_EXPORT TQMemberDict : public TQAsciiDict<TQConstMetaData>
+{
+public:
+ TQMemberDict( int size = 17, bool cs = TRUE, bool ck = TRUE ) :
+ TQAsciiDict<TQConstMetaData>(size,cs,ck) {}
+ TQMemberDict( const TQMemberDict &dict ) : TQAsciiDict<TQConstMetaData>(dict) {}
+ ~TQMemberDict() { clear(); }
+ TQMemberDict &operator=(const TQMemberDict &dict)
+ { return (TQMemberDict&)TQAsciiDict<TQConstMetaData>::operator=(dict); }
+};
+
+
+/*
+ Calculate optimal dictionary size for n entries using prime numbers,
+ and assuming there are no more than 40 entries.
+*/
+
+static int optDictSize( int n )
+{
+ if ( n < 6 )
+ n = 5;
+ else if ( n < 10 )
+ n = 11;
+ else if ( n < 14 )
+ n = 17;
+ else
+ n = 23;
+ return n;
+}
+
+
+/*****************************************************************************
+ TQMetaObject member functions
+ *****************************************************************************/
+
+/*!\internal
+ */
+TQMetaObject::TQMetaObject( const char *const class_name, TQMetaObject *super_class,
+ const TQMetaData *const slot_data, int n_Q_SLOTS,
+ const TQMetaData *const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+#endif
+ const TQClassInfo *const class_info, int n_info )
+{
+ classname = class_name; // set meta data
+ superclass = super_class;
+ superclassname = superclass ? superclass->className() : 0;
+ slotDict = init( slotData = slot_data, n_Q_SLOTS );
+ signalDict = init( signalData = signal_data, n_Q_SIGNALS );
+
+ d = new TQMetaObjectPrivate;
+ reserved = 0;
+
+#ifndef TQT_NO_PROPERTIES
+ d->propData = prop_data;
+ d->numPropData = n_props;
+ d->enumData = enum_data;
+ d->numEnumData = n_enums;
+#endif
+ d->classInfo = class_info;
+ d->numClassInfo = n_info;
+
+ signaloffset = superclass ? ( superclass->signalOffset() + superclass->numSignals() ) : 0;
+ slotoffset = superclass ? ( superclass->slotOffset() + superclass->numSlots() ) : 0;
+#ifndef TQT_NO_PROPERTIES
+ propertyoffset = superclass ? ( superclass->propertyOffset() + superclass->numProperties() ) : 0;
+#endif
+}
+
+#ifndef TQT_NO_PROPERTIES
+/*!\internal
+ */
+TQMetaObject::TQMetaObject( const char *const class_name, TQMetaObject *super_class,
+ const TQMetaData *const slot_data, int n_Q_SLOTS,
+ const TQMetaData *const signal_data, int n_Q_SIGNALS,
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo *const class_info, int n_info )
+{
+ classname = class_name; // set meta data
+ superclass = super_class;
+ superclassname = superclass ? superclass->className() : 0;
+ slotDict = init( slotData = slot_data, n_Q_SLOTS );
+ signalDict = init( signalData = signal_data, n_Q_SIGNALS );
+
+ d = new TQMetaObjectPrivate;
+ reserved = 0;
+
+ d->propData = prop_data;
+ d->numPropData = n_props;
+ d->enumData = enum_data;
+ d->numEnumData = n_enums;
+ d->qt_static_property = qt_static_property;
+ d->classInfo = class_info;
+ d->numClassInfo = n_info;
+
+ signaloffset = superclass ? ( superclass->signalOffset() + superclass->numSignals() ) : 0;
+ slotoffset = superclass ? ( superclass->slotOffset() + superclass->numSlots() ) : 0;
+ propertyoffset = superclass ? ( superclass->propertyOffset() + superclass->numProperties() ) : 0;
+}
+#endif
+
+/*!\internal
+ */
+TQMetaObject::~TQMetaObject()
+{
+ delete slotDict; // delete dicts
+ delete signalDict;
+ delete d;
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ if ( qt_metaobjects ) {
+ qt_metaobjects->remove( classname );
+ if ( qt_metaobjects->isEmpty() ) {
+ delete qt_metaobjects;
+ qt_metaobjects = 0;
+ }
+ }
+
+ // delete reserved; // Unused void*
+}
+
+
+/*!
+ \fn const char *TQMetaObject::className() const
+
+ Returns the class name.
+
+ \sa TQObject::className(), superClassName()
+*/
+
+/*!
+ \fn const char *TQMetaObject::superClassName() const
+
+ Returns the class name of the superclass or 0 if there is no
+ superclass in the TQObject hierachy.
+
+ \sa className()
+*/
+
+/*!
+ \fn TQMetaObject *TQMetaObject::superClass() const
+
+ Returns the meta object of the super class or 0 if there is no
+ such object.
+*/
+
+/*!
+ Returns the number of Q_SLOTS for this class.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+
+ \sa slotNames()
+*/
+int TQMetaObject::numSlots( bool super ) const // number of Q_SLOTS
+{
+ int n = slotDict ? slotDict->count() : 0;
+ if ( !super || !superclass )
+ return n;
+ return n + superclass->numSlots( super );
+}
+
+/*!
+ Returns the number of Q_SIGNALS for this class.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+
+ \sa signalNames()
+*/
+int TQMetaObject::numSignals( bool super ) const // number of Q_SIGNALS
+{
+ int n = signalDict ? signalDict->count() : 0;
+ if ( !super || !superclass )
+ return n;
+ return n + superclass->numSignals( super );
+}
+
+
+/*! \internal
+
+ Returns the meta data of the slot with the name \a n or 0 if no
+ such slot exists.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+ */
+const TQMetaData* TQMetaObject::slot( int index, bool super ) const
+{
+ int idx = index - ( super ? slotOffset() : 0 );
+ if ( slotDict && idx >= 0 && idx < (int) slotDict->count() ) {
+ return slotData + idx;
+ }
+ if ( !super || !superclass )
+ return 0;
+ return superclass->slot( index, super );
+}
+
+/*! \internal
+
+ Returns the meta data of the signal with the name \a n or 0 if no
+ such signal exists.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+ */
+const TQMetaData* TQMetaObject::signal( int index, bool super ) const
+{
+ int idx = index - ( super ? signalOffset() : 0 );
+ if ( signalDict && idx >= 0 && idx < (int) signalDict->count() ) {
+ return signalData + idx;
+ }
+ if ( !super || !superclass )
+ return 0;
+ return superclass->signal( index, super );
+}
+
+
+/*!
+ \fn int TQMetaObject::signalOffset() const
+
+ \internal
+
+ Returns the signal offset for this metaobject.
+
+*/
+
+/*!
+ \fn int TQMetaObject::propertyOffset() const
+
+ \internal
+
+ Returns the property offset for this metaobject.
+
+*/
+
+/*! \internal
+ Returns the index of the signal with name \n or -1 if no such signal exists.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+*/
+int TQMetaObject::tqfindSignal( const char* n, bool super ) const
+{
+ const TQMetaObject *mo = this;
+ int offset = -1;
+
+ do {
+ const TQMetaData *md = mo->signalDict ? mo->signalDict->tqfind( n ) : 0;
+ if ( md ) {
+#if defined(TQT_CHECK_RANGE)
+ if ( offset != -1 ) {
+ qWarning( "TQMetaObject::tqfindSignal:%s: Conflict with %s::%s",
+ className(), mo->className(), n );
+ return offset;
+ }
+#endif
+ offset = mo->signalOffset() + ( md - mo->signalData );
+#if !defined(TQT_CHECK_RANGE)
+ return offset;
+#endif
+ }
+ } while ( super && (mo = mo->superclass) );
+
+ return offset;
+}
+
+/*!
+ \fn int TQMetaObject::slotOffset() const
+
+ \internal
+
+ Returns the slot offset for this metaobject.
+
+*/
+
+/*! \internal
+ Returns the index of the slot with name \n or -1 if no such slot exists.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+ */
+int TQMetaObject::tqfindSlot( const char* n, bool super ) const
+{
+ const TQMetaData *md = slotDict ? slotDict->tqfind( n ) : 0;
+ if ( md )
+ return slotOffset() + ( md - slotData );
+ if ( !super || !superclass)
+ return -1;
+ return superclass->tqfindSlot( n, super );
+}
+
+/*!\internal
+ */
+TQMetaObject *TQMetaObject::new_metaobject( const char *classname,
+ TQMetaObject *superclassobject,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty * const prop_data, int n_props,
+ const TQMetaEnum * const enum_data, int n_enums,
+#endif
+ const TQClassInfo * const class_info, int n_info )
+{
+ return new TQMetaObject( classname, superclassobject, slot_data, n_Q_SLOTS,
+ signal_data, n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ prop_data, n_props,
+ enum_data, n_enums,
+#endif
+ class_info, n_info );
+}
+
+#ifndef TQT_NO_PROPERTIES
+/*!\internal
+ */
+TQMetaObject *TQMetaObject::new_metaobject( const char *classname,
+ TQMetaObject *superclassobject,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+ const TQMetaProperty * const prop_data, int n_props,
+ const TQMetaEnum * const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo * const class_info, int n_info )
+{
+ return new TQMetaObject( classname, superclassobject, slot_data, n_Q_SLOTS,
+ signal_data, n_Q_SIGNALS,
+ prop_data, n_props,
+ enum_data, n_enums,
+ qt_static_property,
+ class_info, n_info );
+}
+#endif
+
+/*!\internal
+ */
+TQMemberDict *TQMetaObject::init( const TQMetaData * data, int n )
+{
+ if ( n == 0 ) // nothing, then make no dict
+ return 0;
+ TQMemberDict *dict = new TQMemberDict( optDictSize(n), TRUE, FALSE );
+ TQ_CHECK_PTR( dict );
+ while ( n-- ) { // put all members into dict
+ dict->insert( data->name, data );
+ data++;
+ }
+ return dict;
+}
+
+/*!
+ Returns the number of items of class information available for
+ this class.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+int TQMetaObject::numClassInfo( bool super ) const
+{
+ return d->numClassInfo + ((super && superclass)?superclass->numClassInfo(super):0);
+}
+
+/*!
+ Returns the class information with index \a index or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const TQClassInfo* TQMetaObject::classInfo( int index, bool super ) const
+{
+ if ( index < 0 )
+ return 0;
+ if ( index < d->numClassInfo )
+ return &(d->classInfo[ index ]);
+ if ( !super || !superclass )
+ return 0;
+ return superclass->classInfo( index - d->numClassInfo, super );
+}
+
+/*!
+ \overload
+ Returns the class information with name \a name or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const char* TQMetaObject::classInfo( const char* name, bool super ) const
+{
+ for( int i = 0; i < d->numClassInfo; ++i ) {
+ if ( qstrcmp( d->classInfo[i].name, name ) == 0 )
+ return d->classInfo[i].value;
+ }
+ if ( !super || !superclass )
+ return 0;
+ return superclass->classInfo( name, super );
+}
+
+#ifndef TQT_NO_PROPERTIES
+
+/*!
+ Returns the number of properties for this class.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+ */
+int TQMetaObject::numProperties( bool super ) const // number of Q_SIGNALS
+{
+ int n = d->numPropData;
+ if ( !super || !superclass )
+ return n;
+ return n + superclass->numProperties( super );
+}
+
+/*!
+ Returns the property meta data for the property at index \a index
+ or 0 if no such property exists.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+ */
+const TQMetaProperty* TQMetaObject::property( int index, bool super ) const
+{
+ int idx = index - ( super ? propertyOffset() : 0 );
+ if ( d->propData && idx >= 0 && idx < (int)d->numPropData )
+ return d->propData + idx;
+ if ( !super || !superclass )
+ return 0;
+ return superclass->property( index, super );
+}
+
+
+/*!
+ Returns the index for the property with name \a name or -1 if no
+ such property exists.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property(), propertyNames()
+*/
+
+int TQMetaObject::tqfindProperty( const char *name, bool super ) const
+{
+ for( int i = 0; i < d->numPropData; ++i ) {
+ if ( d->propData[i].isValid() && qstrcmp( d->propData[i].name(), name ) == 0 ) {
+ return ( super ? propertyOffset() : 0 ) + i;
+ }
+ }
+ if ( !super || !superclass )
+ return -1;
+ return superclass->tqfindProperty( name, super );
+}
+
+/*! \internal
+
+ Returns the index for the property \a prop
+ or -1 if the property can not be found.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property(), propertyNames()
+*/
+
+int TQMetaObject::indexOfProperty( const TQMetaProperty* prop, bool super ) const
+{
+ if ( *prop->meta == this )
+ return ( super ? propertyOffset() : 0 ) + ( prop - d->propData);
+ if ( !super || !superclass )
+ return -1;
+ return superclass->indexOfProperty( prop, super );
+}
+
+/*!\internal
+
+ Returns the tqparent property of property \a p or 0, if the property
+ cannot be resolved.
+
+ \a p has to be contained in this meta object
+*/
+
+const TQMetaProperty* TQMetaObject::resolveProperty( const TQMetaProperty* p ) const
+{
+ if ( !superclass )
+ return 0;
+ return superclass->property( superclass->tqfindProperty( p->n, TRUE ), TRUE );
+}
+
+/*!\internal
+
+ \overload
+
+ The version of resolveProperty that is used by tqmoc generated code
+*/
+
+int TQMetaObject::resolveProperty( int index ) const
+{
+ if ( !superclass )
+ return -1;
+ const TQMetaProperty* p = d->propData + ( index - propertyOffset() );
+ return superclass->tqfindProperty( p->n, TRUE );
+}
+
+
+/*!
+ Returns a list with the names of all this class's properties.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property()
+*/
+TQStrList TQMetaObject::propertyNames( bool super ) const
+{
+ TQStrList l( FALSE );
+
+ if ( superclass && super ) {
+ TQStrList sl = superclass->propertyNames( super );
+ for ( TQStrListIterator slit( sl ); slit.current(); ++slit )
+ l.append( slit.current() );
+ }
+
+ for( int i = 0; i < d->numPropData; ++i ) {
+ if ( d->propData[i].isValid() )
+ l.append( d->propData[i].name() );
+ }
+
+ return l;
+}
+
+/*!
+ Returns a list with the names of all this class's Q_SIGNALS.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+*/
+TQStrList TQMetaObject::signalNames( bool super ) const
+{
+ TQStrList l( FALSE );
+ int n = numSignals( super );
+ for( int i = 0; i < n; ++i ) {
+ l.append( signal(i, super)->name );
+ }
+ return l;
+}
+
+/*!
+ Returns a list with the names of all this class's Q_SLOTS.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+
+ \sa numSlots()
+*/
+TQStrList TQMetaObject::slotNames( bool super ) const
+{
+ TQStrList l( FALSE );
+ int n = numSlots( super );
+ for( int i = 0; i < n; ++i )
+ l.append( slot( i, super)->name );
+ return l;
+}
+
+/*!\internal
+
+ */
+
+int TQMetaObject::numEnumerators( bool super ) const
+{
+ int n = 0;
+ if ( superclass && super )
+ n += superclass->numEnumerators( super );
+ return n + d->numEnumData;
+}
+
+/*!\internal
+
+ */
+TQStrList TQMetaObject::enumeratorNames( bool super ) const
+{
+ TQStrList l( FALSE );
+
+ if ( superclass && super ) {
+ TQStrList sl = superclass->enumeratorNames( super );
+ for ( TQStrListIterator slit( sl ); slit.current(); ++slit )
+ l.append( slit.current() );
+ }
+
+ for( int i = 0; i < d->numEnumData; ++i ) {
+ if ( d->enumData[i].items )
+ l.append( d->enumData[i].name );
+ }
+
+ return l;
+}
+
+/*!\internal
+ */
+const TQMetaEnum* TQMetaObject::enumerator( const char* name, bool super ) const
+{
+ for( int i = 0; i < d->numEnumData; ++i )
+ if ( qstrcmp( d->enumData[i].name, name ) == 0 )
+ return &(d->enumData[i]);
+ if ( !super || !superclass )
+ return 0;
+ return superclass->enumerator( name, super );
+}
+
+#endif // TQT_NO_PROPERTIES
+
+
+/*!
+ Returns TRUE if this class inherits \a clname within the meta
+ object inheritance chain; otherwise returns FALSE.
+
+ (A class is considered to inherit itself.)
+*/
+bool TQMetaObject::inherits( const char* clname ) const
+{
+ const TQMetaObject *meta = this;
+ while ( meta ) {
+ if ( qstrcmp(clname, meta->className()) == 0 )
+ return TRUE;
+ meta = meta->superclass;
+ }
+ return FALSE;
+}
+
+/*! \internal */
+
+TQMetaObject *TQMetaObject::tqmetaObject( const char *class_name )
+{
+ if ( !qt_metaobjects )
+ return 0;
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ TQtStaticMetaObjectFunction func = (TQtStaticMetaObjectFunction)qt_metaobjects->tqfind( class_name );
+ if ( func )
+ return func();
+ return 0;
+}
+
+/*! \internal */
+bool TQMetaObject::hasMetaObject( const char *class_name )
+{
+ if ( !qt_metaobjects )
+ return FALSE;
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ return !!qt_metaobjects->tqfind( class_name );
+}
+
+#ifndef TQT_NO_PROPERTIES
+/*! \internal
+
+### this functions will go away. It exists purely for the sake of meta
+### object code generated with TQt 3.1.0
+*/
+bool TQMetaObject::qt_static_property( TQObject* o, int id, int f, TQVariant* v)
+{
+ if ( d->qt_static_property )
+ return d->qt_static_property( o, id, f, v );
+ else if ( o ) // compatibility
+ return o->qt_property( id, f, v );
+ else if ( superclass )
+ return superclass->qt_static_property( o, id, f, v );
+ switch ( f ) {
+ case 3: case 4: case 5:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+
+/*!
+ \class TQMetaProperty tqmetaobject.h
+
+ \brief The TQMetaProperty class stores meta data about a property.
+
+ \ingroup objectmodel
+
+ Property meta data includes type(), name(), and whether a property
+ is writable(), designable() and stored().
+
+ The functions isSetType(), isEnumType() and enumKeys() provide
+ further information about a property's type. The conversion
+ functions keyToValue(), valueToKey(), keysToValue() and
+ valueToKeys() allow conversion between the integer representation
+ of an enumeration or set value and its literal representation.
+
+ Actual property values are set and received through TQObject's set
+ and get functions. See TQObject::setProperty() and
+ TQObject::property() for details.
+
+ You receive meta property data through an object's meta object.
+ See TQMetaObject::property() and TQMetaObject::propertyNames() for
+ details.
+*/
+
+/*!
+ Returns the possible enumeration keys if this property is an
+ enumeration type (or a set type).
+
+ \sa isEnumType()
+*/
+TQStrList TQMetaProperty::enumKeys() const
+{
+ TQStrList l( FALSE );
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return l;
+ if ( ed != 0 ) {
+ for( uint i = 0; i < ed->count; ++i ) {
+ uint j = 0;
+ while ( j < i &&
+ ed->items[j].value != ed->items[i].value )
+ ++j;
+ if ( i == j )
+ l.append( ed->items[i].key );
+ }
+ }
+ return l;
+}
+
+/*!
+ Converts the enumeration key \a key to its integer value.
+
+ For set types, use keysToValue().
+
+ \sa valueToKey(), isSetType(), keysToValue()
+*/
+int TQMetaProperty::keyToValue( const char* key ) const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return -1;
+ for ( uint i = 0; i < ed->count; ++i ) {
+ if ( !qstrcmp( key, ed->items[i].key) )
+ return ed->items[i].value;
+ }
+ return -1;
+}
+
+/*!
+ Converts the enumeration value \a value to its literal key.
+
+ For set types, use valueToKeys().
+
+ \sa valueToKey(), isSetType(), valueToKeys()
+*/
+const char* TQMetaProperty::valueToKey( int value ) const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return 0;
+ for ( uint i = 0; i < ed->count; ++i ) {
+ if ( value == ed->items[i].value )
+ return ed->items[i].key ;
+ }
+ return 0;
+}
+
+/*!
+ Converts the list of keys \a keys to their combined (OR-ed)
+ integer value.
+
+ \sa isSetType(), valueToKey(), keysToValue()
+*/
+int TQMetaProperty::keysToValue( const TQStrList& keys ) const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return -1;
+ int value = 0;
+ for ( TQStrListIterator it( keys ); it.current(); ++it ) {
+ uint i;
+ for( i = ed->count; i > 0; --i ) {
+ if ( !qstrcmp( it.current(), ed->items[i-1].key) ) {
+ value |= ed->items[i-1].value;
+ break;
+ }
+ }
+ if ( i == 0 )
+ value |= -1;
+ }
+ return value;
+}
+
+/*!
+ Converts the set value \a value to a list of keys.
+
+ \sa isSetType(), valueToKey(), valueToKeys()
+*/
+TQStrList TQMetaProperty::valueToKeys( int value ) const
+{
+ TQStrList keys;
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return keys;
+
+ int v = value;
+ for( uint i = ed->count; i > 0; --i ) {
+ int k = ed->items[i-1].value;
+ if ( ( k != 0 && (v & k) == k ) || ( k == value) ) {
+ v = v & ~k;
+ keys.append( ed->items[i-1].key );
+ }
+ }
+ return keys;
+}
+
+bool TQMetaProperty::writable() const
+{
+ if ( !testFlags( Override ) || testFlags( Writable ) )
+ return testFlags( Writable );
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->writable() : FALSE;
+}
+
+/*!\internal
+ */
+bool TQMetaProperty::stdSet() const
+{
+ if ( !testFlags( Override ) || testFlags( Writable ) )
+ return testFlags( StdSet );
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->stdSet() : FALSE;
+}
+
+/*!\internal
+ */
+int TQMetaProperty::id() const
+{
+ return _id < 0 ? (*meta)->indexOfProperty( this, TRUE ) : _id;
+}
+
+/*! \internal
+*/
+void TQMetaProperty::clear()
+{
+ t = n = 0;
+ meta = 0;
+ enumData = 0;
+ _id = -1;
+ flags = 0;
+}
+
+bool TQMetaProperty::isValid() const
+{
+ if ( testFlags( UnresolvedEnum ) ) {
+ if ( !enumData && (!meta || !(*meta)->enumerator( t, TRUE ) ) )
+ return FALSE;
+ }
+ if ( !testFlags( Override ) || testFlags( Readable ) )
+ return testFlags( Readable );
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->isValid() : FALSE;
+}
+
+bool TQMetaProperty::isSetType() const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ return ( ed != 0 && ed->set );
+}
+
+bool TQMetaProperty::isEnumType() const
+{
+ return testFlags( EnumOrSet );
+}
+
+
+
+/*!
+ \fn const char* TQMetaProperty::type() const
+
+ Returns the type of the property.
+*/
+
+/*!
+ \fn const char* TQMetaProperty::name() const
+
+ Returns the name of the property.
+*/
+
+/*!
+ \fn bool TQMetaProperty::writable() const
+
+ Returns TRUE if the property is writable; otherwise returns FALSE.
+
+*/
+
+/*! \fn bool TQMetaProperty::isValid() const
+
+ \internal
+
+ Returns whether the property is valid.
+*/
+
+/*!
+ \fn bool TQMetaProperty::isEnumType() const
+
+ Returns TRUE if the property's type is an enumeration value;
+ otherwise returns FALSE.
+
+ \sa isSetType(), enumKeys()
+*/
+
+/*!
+ \fn bool TQMetaProperty::isSetType() const
+
+ Returns TRUE if the property's type is an enumeration value that
+ is used as set, i.e. if the enumeration values can be OR-ed
+ together; otherwise returns FALSE. A set type is implicitly also
+ an enum type.
+
+ \sa isEnumType(), enumKeys()
+*/
+
+
+/*! Returns TRUE if the property is designable for object \a o;
+ otherwise returns FALSE.
+
+ If no object \a o is given, the function returns a static
+ approximation.
+ */
+bool TQMetaProperty::designable( TQObject* o ) const
+{
+ if ( !isValid() || !writable() )
+ return FALSE;
+ if ( o ) {
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ return idx >= 0 && o->qt_property( idx, 3, 0 );
+ }
+ if ( testFlags( DesignableOverride ) ) {
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->designable() : FALSE;
+ }
+ return !testFlags( NotDesignable );
+}
+
+/*!
+ Returns TRUE if the property is scriptable for object \a o;
+ otherwise returns FALSE.
+
+ If no object \a o is given, the function returns a static
+ approximation.
+ */
+bool TQMetaProperty::scriptable( TQObject* o ) const
+{
+ if ( o ) {
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ return idx >= 0 && o->qt_property( idx, 4, 0 );
+ }
+ if ( testFlags( ScriptableOverride ) ) {
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->scriptable() : FALSE;
+ }
+ return !testFlags( NotScriptable );
+}
+
+/*!
+ Returns TRUE if the property shall be stored for object \a o;
+ otherwise returns FALSE.
+
+ If no object \a o is given, the function returns a static
+ approximation.
+ */
+bool TQMetaProperty::stored( TQObject* o ) const
+{
+ if ( !isValid() || !writable() )
+ return FALSE;
+ if ( o ) {
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ return idx >= 0 && o->qt_property( idx, 5, 0 );
+ }
+ if ( testFlags( StoredOverride ) ) {
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->stored() : FALSE;
+ }
+ return !testFlags( NotStored );
+}
+
+
+/*!
+ Tries to reset the property for object \a o with a reset method.
+ On success, returns TRUE; otherwise returns FALSE.
+
+ Reset methods are optional, usually only a few properties support
+ them.
+*/
+bool TQMetaProperty::reset( TQObject* o ) const
+{
+ if ( !o )
+ return FALSE;
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ if ( idx < 0 )
+ return 0;
+ return o->qt_property( idx, 2, 0 );
+}
+
+
+/*! \enum TQMetaProperty::Flags
+
+ \internal
+*/
+
+#endif // TQT_NO_PROPERTIES
+
+/*
+ * TQMetaObjectCleanUp is used as static global object in the tqmoc-generated cpp
+ * files and deletes the TQMetaObject provided with setMetaObject. It sets the
+ * TQObject reference to the metaObj to NULL when it is destroyed.
+ */
+TQMetaObjectCleanUp::TQMetaObjectCleanUp( const char *mo_name, TQtStaticMetaObjectFunction func )
+ : tqmetaObject( 0 )
+{
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ if ( !qt_metaobjects )
+ qt_metaobjects = new TQAsciiDict<void>( 257 );
+ qt_metaobjects->insert( mo_name, (void*)func );
+
+ qt_metaobjects_count++;
+}
+
+TQMetaObjectCleanUp::TQMetaObjectCleanUp()
+ : tqmetaObject( 0 )
+{
+}
+
+/*! \fn bool TQMetaProperty::testFlags( uint f ) const
+ \internal
+*/
+
+TQMetaObjectCleanUp::~TQMetaObjectCleanUp()
+{
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ if ( !--qt_metaobjects_count ) {
+ delete qt_metaobjects;
+ qt_metaobjects = 0;
+ }
+ if ( tqmetaObject ) {
+ delete *tqmetaObject;
+ *tqmetaObject = 0;
+ tqmetaObject = 0;
+ }
+}
+
+void TQMetaObjectCleanUp::setMetaObject( TQMetaObject *&mo )
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( tqmetaObject )
+ qWarning( "TQMetaObjectCleanUp::setMetaObject: Double use of TQMetaObjectCleanUp!" );
+#endif
+ tqmetaObject = &mo;
+}
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqmetaobject.cpp~ b/tqtinterface/qt4/src/kernel/tqmetaobject.cpp~
new file mode 100644
index 0000000..09d8439
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmetaobject.cpp~
@@ -0,0 +1,1792 @@
+/****************************************************************************
+**
+** Implementation of TQMetaObject class
+**
+** Created : 930419
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqmetaobject.h"
+#include "tqasciidict.h"
+
+#ifdef TQT_THREAD_SUPPORT
+#include <private/tqmutexpool_p.h>
+#endif // TQT_THREAD_SUPPORT
+
+#include <private/tqucom_p.h>
+
+#ifdef USE_QT4
+
+// #include <private/qt4_qmetaobject_p.h>
+
+/*!
+ Returns a list with the names of all this class's properties.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property()
+*/
+TQStrList TQMetaObject::propertyNames( bool super ) const
+{
+ TQStrList l( FALSE );
+ int n = numProperties( super );
+ for( int i = 0; i < n; ++i ) {
+ if (property( i, super))
+ l.append( property( i, super)->name() );
+ else
+ l.append( "[TQt TQMetaObject::propertyNames was unable to find the Qt4 name for this property]" );
+ }
+ return l;
+}
+
+const char * TQMetaData::name() const {
+ return signature(); // Member name
+}
+
+const TQUMethod* TQMetaData::method() const {
+ // FIXME
+ // Verify that this routine accurately fills internal_method_information!
+ printf("[WARNING] const TQUMethod* TQMetaData::method() partially implemented!\n\r");
+
+ if (!internal_method_information) {
+ internal_method_information = new TQUMethod;
+ internal_method_information->parameters = 0;
+ }
+ internal_method_information->name = QMetaMethod::signature();
+ internal_method_information->count = QMetaMethod::parameterNames().count();
+ if (internal_method_information->parameters) {
+ for (int i=0; i<internal_method_information->count; i++) {
+ if (internal_method_information->parameters[i].type)
+ delete internal_method_information->parameters[i].type;
+ }
+ delete [] internal_method_information->parameters;
+ }
+ internal_method_information->parameters = new TQUParameter[internal_method_information->count];
+ for (int i=0; i<internal_method_information->count; i++) {
+ const_cast<TQUParameter&>(internal_method_information->parameters[i]).name = QMetaMethod::parameterNames().at(i).data();
+// const_cast<TQUParameter&>(internal_method_information->parameters[i]).type = new TQUType;
+// const_cast<TQUParameter&>(internal_method_information->parameters[i]).type.desc = QMetaMethod::parameterTypes().at(i).data();
+ const_cast<TQUParameter&>(internal_method_information->parameters[i]).typeExtra = 0;
+ const_cast<TQUParameter&>(internal_method_information->parameters[i]).inOut = 3;
+ }
+ return internal_method_information;
+}
+
+TQMetaEnum::TQMetaEnum() : QMetaEnum() { internal_item_list = 0; }
+
+uint TQMetaEnum::count() const {
+ return QMetaEnum::keyCount();
+}
+
+TQMetaEnum::Item* TQMetaEnum::items() const {
+ if (internal_item_list)
+ delete [] internal_item_list;
+ int internal_item_count = count();
+ internal_item_list = new Item[internal_item_count];
+ for (int i=0; i<internal_item_count;i++) {
+ internal_item_list[i].key = QMetaEnum::key(i);
+ internal_item_list[i].value = QMetaEnum::value(i);
+ }
+ return internal_item_list;
+}
+
+TQMetaData::TQMetaData() : QMetaMethod() {}
+
+TQMetaProperty::TQMetaProperty() : QMetaProperty() {}
+
+/*!
+ Returns the possible enumeration keys if this property is an
+ enumeration type (or a set type).
+
+ \sa isEnumType()
+*/
+TQStrList TQMetaProperty::enumKeys() const
+{
+ TQStrList l( FALSE );
+ QMetaEnum ed = enumerator();
+ for( uint i = 0; i < ed.keyCount(); ++i ) {
+ uint j = 0;
+ while ( j < i && ed.value(j) != ed.value(i) )
+ ++j;
+ if ( i == j )
+ l.append( ed.key(i) );
+ }
+ return l;
+}
+
+bool TQMetaProperty::isSetType() const {
+ return isFlagType ();
+}
+
+int TQMetaProperty::keyToValue( const char* key ) const {
+ return enumerator().keyToValue(key);
+}
+
+const char* TQMetaProperty::valueToKey( int value ) const {
+ return enumerator().valueToKey(value);
+}
+
+int TQMetaProperty::keysToValue( const TQStrList& keys_in ) const {
+ TQString tqs = "";
+ TQStrList keys = keys_in;
+ char *key;
+ for ( key = keys.first(); key; key = keys.next() ) {
+ tqs = tqs + "|" + key;
+ }
+ tqs.remove(0,1);
+ return enumerator().keysToValue(TQCString(tqs));
+}
+
+TQStrList TQMetaProperty::valueToKeys( int value ) const {
+ TQStrList keys;
+ QByteArray qba = enumerator().valueToKeys(value);
+ TQStringList keys_out = TQStringList::split("|", TQString(TQCString(qba)));
+ for ( TQStringList::Iterator it = keys_out.begin(); it != keys_out.end(); ++it ) {
+ keys.append(*it);
+ }
+ return keys;
+}
+
+bool TQMetaProperty::writable() const {
+ return isWritable();
+}
+
+const char* TQMetaProperty::type() const {
+ return QMetaProperty::typeName();
+}
+
+bool TQMetaProperty::designable( TQT_BASE_OBJECT_NAME *o ) const {
+ return isDesignable(o);
+}
+
+bool TQMetaProperty::scriptable( TQT_BASE_OBJECT_NAME *o ) const {
+ return isScriptable(o);
+}
+
+bool TQMetaProperty::stored( TQT_BASE_OBJECT_NAME *o ) const {
+ return isStored(o);
+}
+
+/*!\internal
+ */
+bool TQMetaProperty::stdSet() const
+{
+// if ( !testFlags( Override ) || testFlags( Writable ) )
+// return testFlags( StdSet );
+// const TQMetaObject* mo = (*meta);
+// const TQMetaProperty* tqparent = mo->resolveProperty( this );
+// return tqparent ? tqparent->stdSet() : FALSE;
+
+ // [FIXME]
+ printf("[WARNING] bool TQMetaProperty::stdSet() const unimplemented\n\r");
+ return FALSE;
+}
+
+TQMetaObject::TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums,
+#endif // TQT_NO_PROPERTIES
+ const TQClassInfo *const class_info, int n_info ) : QMetaObject() {
+ printf("[WARNING] TQMetaObject() constructor unimplemented\n\r"); // [FIXME]
+}
+
+#ifndef TQT_NO_PROPERTIES
+TQMetaObject::TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS, const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums, bool (*qt_static_property)(TQObject*, int, int, TQVariant*), const TQClassInfo *const class_info, int n_info ) : QMetaObject() {
+ printf("[WARNING] TQMetaObject() constructor unimplemented\n\r"); // [FIXME]
+}
+#endif // TQT_NO_PROPERTIES
+
+TQStrList TQMetaObject::slotNames( bool super ) const {
+ printf("[WARNING] TQStrList slotNames( bool super = FALSE ) unimplemented\n\r");
+ return TQStrList();
+}
+
+TQStrList TQMetaObject::signalNames( bool super ) const {
+ printf("[WARNING] TQStrList signalNames( bool super = FALSE ) const unimplemented\n\r");
+ return TQStrList();
+}
+
+/*!
+ Returns the number of Q_SLOTS for this class.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+
+ \sa slotNames()
+*/
+int TQMetaObject::numSlots( bool super ) const // number of Q_SLOTS
+{
+ int i;
+ int n=0;
+ for (i=0;i<methodCount();i++) {
+ if (method(i).methodType() == QMetaMethod::Slot) {
+ n++;
+ }
+ }
+
+ if ( !super || !superClass() )
+ return n;
+ return n + tqsuperClass()->numSlots( super );
+}
+
+/*!
+ Returns the number of items of class information available for
+ this class.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+int TQMetaObject::numClassInfo( bool super ) const
+{
+ return classInfoCount() + ((super && tqsuperClass())?tqsuperClass()->numClassInfo(super):0);
+}
+
+/*!
+ Returns the number of Q_SIGNALS for this class.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+
+ \sa signalNames()
+*/
+int TQMetaObject::numSignals( bool super ) const // number of Q_SIGNALS
+{
+ int i;
+ int n=0;
+ for (i=0;i<methodCount();i++) {
+ if (method(i).methodType() == QMetaMethod::Signal) {
+ n++;
+ }
+ }
+
+ if ( !super || !superClass() )
+ return n;
+ return n + tqsuperClass()->numSignals( super );
+}
+
+#if 0
+/*! \internal
+
+ Returns the meta data of the slot with the name \a n or 0 if no
+ such slot exists.
+
+ If \a super is TRUE, inherited slots are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::slot( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( slotDict && idx >= 0 && idx < (int) slotDict->count() ) {
+ if ( idx >= 0 && idx < numSlots(true) ) {
+// return slotData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->slot( index, super );
+}
+
+/*! \internal
+
+ Returns the meta data of the signal with the name \a n or 0 if no
+ such signal exists.
+
+ If \a super is TRUE, inherited signals are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::signal( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( signalDict && idx >= 0 && idx < (int) signalDict->count() ) {
+ if ( idx >= 0 && idx < numSignals(true) ) {
+// return signalData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->signal( index, super );
+}
+#endif
+
+/*! \internal
+
+ Returns the meta data of the slot with the name \a n or 0 if no
+ such slot exists.
+
+ If \a super is TRUE, inherited slots are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::slot( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( slotDict && idx >= 0 && idx < (int) slotDict->count() ) {
+ if ( idx >= 0 && idx < numSlots(true) ) {
+// return slotData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->slot( index, super );
+}
+
+/*! \internal
+
+ Returns the meta data of the signal with the name \a n or 0 if no
+ such signal exists.
+
+ If \a super is TRUE, inherited signals are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+const TQMetaData* TQMetaObject::signal( int index, bool super ) const
+{
+ QMetaMethod mm;
+ const QMetaMethod *mr;
+ int idx = index - ( super ? methodOffset() : 0 );
+// if ( signalDict && idx >= 0 && idx < (int) signalDict->count() ) {
+ if ( idx >= 0 && idx < numSignals(true) ) {
+// return signalData + idx;
+ mm = method(idx);
+ mr = &mm;
+ return static_cast<const TQMetaData*>(mr);
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->signal( index, super );
+}
+
+/*! \internal
+ Returns the index of the slot with name \n or -1 if no such slot exists.
+
+ If \a super is TRUE, inherited slots are included.
+
+ [FIXME]: Superclass handling is badly broken
+ */
+int TQMetaObject::tqfindSlot( const char* n, bool super ) const
+{
+// TQStrList l( FALSE );
+// int m = methodCount();
+// for( int i = 0; i < m; ++i ) {
+// // if ( normalizedSignature(slot( i, super)->signature()) == QByteArray(n) ) {
+// if ( normalizedSignature(method(i).signature()) == QByteArray(n) ) {
+// if (method(i).methodType() == QMetaMethod::Slot) {
+// return i;
+// }
+// }
+// }
+// return -1;
+
+ if (super) printf("[WARNING] In TQMetaObject::tqfindSlot(), superclasses are not being searched for the slot\n\r");
+ return indexOfSlot(normalizedSignature(n));
+}
+
+/*! \internal
+ Returns the index of the signal with name \n or -1 if no such signal exists.
+
+ If \a super is TRUE, inherited signals are included.
+
+ [FIXME]: Superclass handling is badly broken
+*/
+int TQMetaObject::tqfindSignal( const char* n, bool super ) const
+{
+// TQStrList l( FALSE );
+// int m = methodCount();
+// for( int i = 0; i < m; ++i ) {
+// // if ( normalizedSignature(signal( i, super)->signature()) == QByteArray(n) ) {
+// if ( normalizedSignature(method(i).signature()) == QByteArray(n) ) {
+// if (method(i).methodType() == QMetaMethod::Signal) {
+// return i;
+// }
+// }
+// }
+// return -1;
+
+ if (super) printf("[WARNING] In TQMetaObject::tqfindSignal(), superclasses are not being searched for the signal\n\r");
+ return indexOfSignal(normalizedSignature(n));
+}
+
+#ifndef QT_NO_PROPERTIES
+
+/*!
+ Returns the number of properties for this class.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+ */
+int TQMetaObject::numProperties( bool super ) const // number of properties
+{
+ int i;
+ int n=0;
+ for (i=0;i<propertyCount();i++) {
+// if (property(i).propertyType() == QMetaProperty::Property) {
+ n++;
+// }
+ }
+
+ if ( !super || !superClass() )
+ return n;
+ return n + tqsuperClass()->numProperties( super );
+}
+
+/*!
+ Returns the property meta data for the property at index \a index
+ or 0 if no such property exists.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+
+ [FIXME]: Superclass handling is badly broken
+ */
+static QMetaProperty tqmo_propmethod_curprop;
+const TQMetaProperty* TQMetaObject::property( int index, bool super ) const
+{
+ QMetaProperty mp;
+ const QMetaProperty *pr;
+ int idx = index - ( super ? propertyOffset() : 0 );
+// if ( d->propData && idx >= 0 && idx < (int)d->numPropData )
+ if ( idx >= 0 && idx < numProperties(true) )
+ tqmo_propmethod_curprop = QMetaObject::property(idx);
+ return static_cast<const TQMetaProperty*>(&tqmo_propmethod_curprop);
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->property( index, super );
+}
+
+int TQMetaObject::tqfindProperty( const char *name, bool super ) const {
+ TQ_UNUSED(name);
+ return indexOfProperty(name);
+}
+
+TQMetaObject * TQMetaObject::tqsuperClass() const {
+ return static_cast<TQMetaObject*>(const_cast<QMetaObject*>(superClass()));
+}
+
+const char * TQMetaObject::tqsuperClassName() const {
+ return static_cast<TQMetaObject*>(const_cast<QMetaObject*>(superClass()))->className();
+}
+
+#endif // QT_NO_PROPERTIES
+
+/*!
+ Returns the class information with index \a index or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const TQClassInfo* TQMetaObject::classInfo( int index, bool super ) const
+{
+ if ( index < 0 )
+ return 0;
+ if ( index < QMetaObject::classInfoCount() )
+ return static_cast<TQClassInfo*>(&(QMetaObject::classInfo(index)));
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->classInfo( index - QMetaObject::classInfoCount(), super );
+}
+
+/*!
+ \overload
+ Returns the class information with name \a name or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const char* TQMetaObject::classInfo( const char* name, bool super ) const
+{
+ for( int i = 0; i < QMetaObject::classInfoCount(); ++i ) {
+ if ( qstrcmp( QMetaObject::classInfo(i).name(), name ) == 0 )
+ return QMetaObject::classInfo(i).value();
+ }
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->classInfo( name, super );
+}
+
+/*!\internal
+
+ */
+TQStrList TQMetaObject::enumeratorNames( bool super ) const
+{
+ TQStrList l( FALSE );
+
+ if ( tqsuperClass() && super ) {
+ TQStrList sl = tqsuperClass()->enumeratorNames( super );
+ for ( TQStrListIterator slit( sl ); slit.current(); ++slit )
+ l.append( slit.current() );
+ }
+
+ for( int i = 0; i < QMetaObject::enumeratorCount(); ++i ) {
+// if ( d->enumData[i].items )
+ if (QMetaObject::enumerator(i).name() != "")
+ l.append( QMetaObject::enumerator(i).name() );
+ }
+
+ return l;
+}
+
+/*!\internal
+ */
+const TQMetaEnum* TQMetaObject::enumerator( const char* name, bool super ) const
+{
+ for( int i = 0; i < QMetaObject::enumeratorCount(); ++i )
+ if ( qstrcmp( QMetaObject::enumerator(i).name(), name ) == 0 )
+ return static_cast<TQMetaEnum*>(&(QMetaObject::enumerator(i)));
+ if ( !super || !superClass() )
+ return 0;
+ return tqsuperClass()->enumerator( name, super );
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQMetaData tqmetaobject.h
+ \reentrant
+
+ \brief The TQMetaData class provides information about a member function that is known to the meta object system.
+
+ \internal
+
+ The struct consists of three members, \e name, \e method and \e access:
+
+ \code
+ const char *name; // - member name
+ const TQUMethod* method; // - detailed method description
+ enum Access { Private, Protected, Public };
+ Access access; // - access permission
+ \endcode
+ */
+
+/*!
+ \class TQClassInfo tqmetaobject.h
+
+ \brief The TQClassInfo class provides a struct that stores some basic information about a single class.
+
+ \internal
+
+ The class information is a simple \e name - \e value pair:
+
+ \code
+ const char* name;
+ const char* value;
+ \endcode
+
+ */
+
+
+/*!
+ \class TQMetaObject tqmetaobject.h
+ \brief The TQMetaObject class tqcontains meta information about TQt objects.
+
+ \ingroup objectmodel
+
+ The Meta Object System in TQt is responsible for the Q_SIGNALS and
+ Q_SLOTS inter-object communication mechanism, runtime type
+ information and the property system. All meta information in TQt is
+ kept in a single instance of TQMetaObject per class.
+
+ This class is not normally required for application programming.
+ But if you write meta applications, such as scripting engines or
+ GUI builders, you might tqfind these functions useful:
+ \list
+ \i className() to get the name of a class.
+ \i superClassName() to get the name of the superclass.
+ \i inherits(), the function called by TQObject::inherits().
+ \i superClass() to access the superclass's meta object.
+ \i numSlots(), numSignals(), slotNames(), and signalNames() to get
+ information about a class's Q_SIGNALS and Q_SLOTS.
+ \i property() and propertyNames() to obtain information about a
+ class's properties.
+ \endlist
+
+ Classes may have a list of name-value pairs of class information.
+ The number of pairs is returned by numClassInfo(), and values are
+ returned by classInfo().
+
+ \sa \link tqmoc.html tqmoc (Meta Object Compiler)\endlink
+
+*/
+
+
+/*****************************************************************************
+ The private object.
+ *****************************************************************************/
+
+// extra flags from tqmoc.y
+enum Flags {
+ Invalid = 0x00000000,
+ Readable = 0x00000001,
+ Writable = 0x00000002,
+ EnumOrSet = 0x00000004,
+ UnresolvedEnum = 0x00000008,
+ StdSet = 0x00000100,
+ Override = 0x00000200,
+ NotDesignable = 0x00001000,
+ DesignableOverride = 0x00002000,
+ NotScriptable = 0x00004000,
+ ScriptableOverride = 0x00008000,
+ NotStored = 0x00010000,
+ StoredOverride = 0x00020000
+};
+
+static TQAsciiDict<void> *qt_metaobjects = 0;
+static int qt_metaobjects_count = 0;
+
+class TQMetaObjectPrivate
+{
+public:
+ TQMetaObjectPrivate() :
+#ifndef TQT_NO_PROPERTIES
+ enumData(0), numEnumData(0),
+ propData(0),numPropData(0),
+ qt_static_property(0),
+#endif
+ classInfo(0), numClassInfo(0) {}
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaEnum *enumData;
+ int numEnumData;
+ const TQMetaProperty *propData;
+ int numPropData;
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*);
+#endif
+ const TQClassInfo *classInfo;
+ int numClassInfo;
+};
+
+
+/*****************************************************************************
+ Internal dictionary for fast access to class members
+ *****************************************************************************/
+
+#if defined(TQ_CANNOT_DELETE_CONSTANT)
+typedef TQMetaData TQConstMetaData;
+#else
+typedef const TQMetaData TQConstMetaData;
+#endif
+
+class TQ_EXPORT TQMemberDict : public TQAsciiDict<TQConstMetaData>
+{
+public:
+ TQMemberDict( int size = 17, bool cs = TRUE, bool ck = TRUE ) :
+ TQAsciiDict<TQConstMetaData>(size,cs,ck) {}
+ TQMemberDict( const TQMemberDict &dict ) : TQAsciiDict<TQConstMetaData>(dict) {}
+ ~TQMemberDict() { clear(); }
+ TQMemberDict &operator=(const TQMemberDict &dict)
+ { return (TQMemberDict&)TQAsciiDict<TQConstMetaData>::operator=(dict); }
+};
+
+
+/*
+ Calculate optimal dictionary size for n entries using prime numbers,
+ and assuming there are no more than 40 entries.
+*/
+
+static int optDictSize( int n )
+{
+ if ( n < 6 )
+ n = 5;
+ else if ( n < 10 )
+ n = 11;
+ else if ( n < 14 )
+ n = 17;
+ else
+ n = 23;
+ return n;
+}
+
+
+/*****************************************************************************
+ TQMetaObject member functions
+ *****************************************************************************/
+
+/*!\internal
+ */
+TQMetaObject::TQMetaObject( const char *const class_name, TQMetaObject *super_class,
+ const TQMetaData *const slot_data, int n_Q_SLOTS,
+ const TQMetaData *const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+#endif
+ const TQClassInfo *const class_info, int n_info )
+{
+ classname = class_name; // set meta data
+ superclass = super_class;
+ superclassname = superclass ? superclass->className() : 0;
+ slotDict = init( slotData = slot_data, n_Q_SLOTS );
+ signalDict = init( signalData = signal_data, n_Q_SIGNALS );
+
+ d = new TQMetaObjectPrivate;
+ reserved = 0;
+
+#ifndef TQT_NO_PROPERTIES
+ d->propData = prop_data;
+ d->numPropData = n_props;
+ d->enumData = enum_data;
+ d->numEnumData = n_enums;
+#endif
+ d->classInfo = class_info;
+ d->numClassInfo = n_info;
+
+ signaloffset = superclass ? ( superclass->signalOffset() + superclass->numSignals() ) : 0;
+ slotoffset = superclass ? ( superclass->slotOffset() + superclass->numSlots() ) : 0;
+#ifndef TQT_NO_PROPERTIES
+ propertyoffset = superclass ? ( superclass->propertyOffset() + superclass->numProperties() ) : 0;
+#endif
+}
+
+#ifndef TQT_NO_PROPERTIES
+/*!\internal
+ */
+TQMetaObject::TQMetaObject( const char *const class_name, TQMetaObject *super_class,
+ const TQMetaData *const slot_data, int n_Q_SLOTS,
+ const TQMetaData *const signal_data, int n_Q_SIGNALS,
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo *const class_info, int n_info )
+{
+ classname = class_name; // set meta data
+ superclass = super_class;
+ superclassname = superclass ? superclass->className() : 0;
+ slotDict = init( slotData = slot_data, n_Q_SLOTS );
+ signalDict = init( signalData = signal_data, n_Q_SIGNALS );
+
+ d = new TQMetaObjectPrivate;
+ reserved = 0;
+
+ d->propData = prop_data;
+ d->numPropData = n_props;
+ d->enumData = enum_data;
+ d->numEnumData = n_enums;
+ d->qt_static_property = qt_static_property;
+ d->classInfo = class_info;
+ d->numClassInfo = n_info;
+
+ signaloffset = superclass ? ( superclass->signalOffset() + superclass->numSignals() ) : 0;
+ slotoffset = superclass ? ( superclass->slotOffset() + superclass->numSlots() ) : 0;
+ propertyoffset = superclass ? ( superclass->propertyOffset() + superclass->numProperties() ) : 0;
+}
+#endif
+
+/*!\internal
+ */
+TQMetaObject::~TQMetaObject()
+{
+ delete slotDict; // delete dicts
+ delete signalDict;
+ delete d;
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ if ( qt_metaobjects ) {
+ qt_metaobjects->remove( classname );
+ if ( qt_metaobjects->isEmpty() ) {
+ delete qt_metaobjects;
+ qt_metaobjects = 0;
+ }
+ }
+
+ // delete reserved; // Unused void*
+}
+
+
+/*!
+ \fn const char *TQMetaObject::className() const
+
+ Returns the class name.
+
+ \sa TQObject::className(), superClassName()
+*/
+
+/*!
+ \fn const char *TQMetaObject::superClassName() const
+
+ Returns the class name of the superclass or 0 if there is no
+ superclass in the TQObject hierachy.
+
+ \sa className()
+*/
+
+/*!
+ \fn TQMetaObject *TQMetaObject::superClass() const
+
+ Returns the meta object of the super class or 0 if there is no
+ such object.
+*/
+
+/*!
+ Returns the number of Q_SLOTS for this class.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+
+ \sa slotNames()
+*/
+int TQMetaObject::numSlots( bool super ) const // number of Q_SLOTS
+{
+ int n = slotDict ? slotDict->count() : 0;
+ if ( !super || !superclass )
+ return n;
+ return n + superclass->numSlots( super );
+}
+
+/*!
+ Returns the number of Q_SIGNALS for this class.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+
+ \sa signalNames()
+*/
+int TQMetaObject::numSignals( bool super ) const // number of Q_SIGNALS
+{
+ int n = signalDict ? signalDict->count() : 0;
+ if ( !super || !superclass )
+ return n;
+ return n + superclass->numSignals( super );
+}
+
+
+/*! \internal
+
+ Returns the meta data of the slot with the name \a n or 0 if no
+ such slot exists.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+ */
+const TQMetaData* TQMetaObject::slot( int index, bool super ) const
+{
+ int idx = index - ( super ? slotOffset() : 0 );
+ if ( slotDict && idx >= 0 && idx < (int) slotDict->count() ) {
+ return slotData + idx;
+ }
+ if ( !super || !superclass )
+ return 0;
+ return superclass->slot( index, super );
+}
+
+/*! \internal
+
+ Returns the meta data of the signal with the name \a n or 0 if no
+ such signal exists.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+ */
+const TQMetaData* TQMetaObject::signal( int index, bool super ) const
+{
+ int idx = index - ( super ? signalOffset() : 0 );
+ if ( signalDict && idx >= 0 && idx < (int) signalDict->count() ) {
+ return signalData + idx;
+ }
+ if ( !super || !superclass )
+ return 0;
+ return superclass->signal( index, super );
+}
+
+
+/*!
+ \fn int TQMetaObject::signalOffset() const
+
+ \internal
+
+ Returns the signal offset for this metaobject.
+
+*/
+
+/*!
+ \fn int TQMetaObject::propertyOffset() const
+
+ \internal
+
+ Returns the property offset for this metaobject.
+
+*/
+
+/*! \internal
+ Returns the index of the signal with name \n or -1 if no such signal exists.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+*/
+int TQMetaObject::tqfindSignal( const char* n, bool super ) const
+{
+ const TQMetaObject *mo = this;
+ int offset = -1;
+
+ do {
+ const TQMetaData *md = mo->signalDict ? mo->signalDict->tqfind( n ) : 0;
+ if ( md ) {
+#if defined(TQT_CHECK_RANGE)
+ if ( offset != -1 ) {
+ qWarning( "TQMetaObject::tqfindSignal:%s: Conflict with %s::%s",
+ className(), mo->className(), n );
+ return offset;
+ }
+#endif
+ offset = mo->signalOffset() + ( md - mo->signalData );
+#if !defined(TQT_CHECK_RANGE)
+ return offset;
+#endif
+ }
+ } while ( super && (mo = mo->superclass) );
+
+ return offset;
+}
+
+/*!
+ \fn int TQMetaObject::slotOffset() const
+
+ \internal
+
+ Returns the slot offset for this metaobject.
+
+*/
+
+/*! \internal
+ Returns the index of the slot with name \n or -1 if no such slot exists.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+ */
+int TQMetaObject::tqfindSlot( const char* n, bool super ) const
+{
+ const TQMetaData *md = slotDict ? slotDict->tqfind( n ) : 0;
+ if ( md )
+ return slotOffset() + ( md - slotData );
+ if ( !super || !superclass)
+ return -1;
+ return superclass->tqfindSlot( n, super );
+}
+
+/*!\internal
+ */
+TQMetaObject *TQMetaObject::new_metaobject( const char *classname,
+ TQMetaObject *superclassobject,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty * const prop_data, int n_props,
+ const TQMetaEnum * const enum_data, int n_enums,
+#endif
+ const TQClassInfo * const class_info, int n_info )
+{
+ return new TQMetaObject( classname, superclassobject, slot_data, n_Q_SLOTS,
+ signal_data, n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ prop_data, n_props,
+ enum_data, n_enums,
+#endif
+ class_info, n_info );
+}
+
+#ifndef TQT_NO_PROPERTIES
+/*!\internal
+ */
+TQMetaObject *TQMetaObject::new_metaobject( const char *classname,
+ TQMetaObject *superclassobject,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+ const TQMetaProperty * const prop_data, int n_props,
+ const TQMetaEnum * const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo * const class_info, int n_info )
+{
+ return new TQMetaObject( classname, superclassobject, slot_data, n_Q_SLOTS,
+ signal_data, n_Q_SIGNALS,
+ prop_data, n_props,
+ enum_data, n_enums,
+ qt_static_property,
+ class_info, n_info );
+}
+#endif
+
+/*!\internal
+ */
+TQMemberDict *TQMetaObject::init( const TQMetaData * data, int n )
+{
+ if ( n == 0 ) // nothing, then make no dict
+ return 0;
+ TQMemberDict *dict = new TQMemberDict( optDictSize(n), TRUE, FALSE );
+ TQ_CHECK_PTR( dict );
+ while ( n-- ) { // put all members into dict
+ dict->insert( data->name, data );
+ data++;
+ }
+ return dict;
+}
+
+/*!
+ Returns the number of items of class information available for
+ this class.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+int TQMetaObject::numClassInfo( bool super ) const
+{
+ return d->numClassInfo + ((super && superclass)?superclass->numClassInfo(super):0);
+}
+
+/*!
+ Returns the class information with index \a index or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const TQClassInfo* TQMetaObject::classInfo( int index, bool super ) const
+{
+ if ( index < 0 )
+ return 0;
+ if ( index < d->numClassInfo )
+ return &(d->classInfo[ index ]);
+ if ( !super || !superclass )
+ return 0;
+ return superclass->classInfo( index - d->numClassInfo, super );
+}
+
+/*!
+ \overload
+ Returns the class information with name \a name or 0 if no such
+ information exists.
+
+ If \a super is TRUE, inherited class information is included.
+*/
+const char* TQMetaObject::classInfo( const char* name, bool super ) const
+{
+ for( int i = 0; i < d->numClassInfo; ++i ) {
+ if ( qstrcmp( d->classInfo[i].name, name ) == 0 )
+ return d->classInfo[i].value;
+ }
+ if ( !super || !superclass )
+ return 0;
+ return superclass->classInfo( name, super );
+}
+
+#ifndef TQT_NO_PROPERTIES
+
+/*!
+ Returns the number of properties for this class.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+ */
+int TQMetaObject::numProperties( bool super ) const // number of Q_SIGNALS
+{
+ int n = d->numPropData;
+ if ( !super || !superclass )
+ return n;
+ return n + superclass->numProperties( super );
+}
+
+/*!
+ Returns the property meta data for the property at index \a index
+ or 0 if no such property exists.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa propertyNames()
+ */
+const TQMetaProperty* TQMetaObject::property( int index, bool super ) const
+{
+ int idx = index - ( super ? propertyOffset() : 0 );
+ if ( d->propData && idx >= 0 && idx < (int)d->numPropData )
+ return d->propData + idx;
+ if ( !super || !superclass )
+ return 0;
+ return superclass->property( index, super );
+}
+
+
+/*!
+ Returns the index for the property with name \a name or -1 if no
+ such property exists.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property(), propertyNames()
+*/
+
+int TQMetaObject::tqfindProperty( const char *name, bool super ) const
+{
+ for( int i = 0; i < d->numPropData; ++i ) {
+ if ( d->propData[i].isValid() && qstrcmp( d->propData[i].name(), name ) == 0 ) {
+ return ( super ? propertyOffset() : 0 ) + i;
+ }
+ }
+ if ( !super || !superclass )
+ return -1;
+ return superclass->tqfindProperty( name, super );
+}
+
+/*! \internal
+
+ Returns the index for the property \a prop
+ or -1 if the property can not be found.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property(), propertyNames()
+*/
+
+int TQMetaObject::indexOfProperty( const TQMetaProperty* prop, bool super ) const
+{
+ if ( *prop->meta == this )
+ return ( super ? propertyOffset() : 0 ) + ( prop - d->propData);
+ if ( !super || !superclass )
+ return -1;
+ return superclass->indexOfProperty( prop, super );
+}
+
+/*!\internal
+
+ Returns the tqparent property of property \a p or 0, if the property
+ cannot be resolved.
+
+ \a p has to be contained in this meta object
+*/
+
+const TQMetaProperty* TQMetaObject::resolveProperty( const TQMetaProperty* p ) const
+{
+ if ( !superclass )
+ return 0;
+ return superclass->property( superclass->tqfindProperty( p->n, TRUE ), TRUE );
+}
+
+/*!\internal
+
+ \overload
+
+ The version of resolveProperty that is used by tqmoc generated code
+*/
+
+int TQMetaObject::resolveProperty( int index ) const
+{
+ if ( !superclass )
+ return -1;
+ const TQMetaProperty* p = d->propData + ( index - propertyOffset() );
+ return superclass->tqfindProperty( p->n, TRUE );
+}
+
+
+/*!
+ Returns a list with the names of all this class's properties.
+
+ If \a super is TRUE, inherited properties are included.
+
+ \sa property()
+*/
+TQStrList TQMetaObject::propertyNames( bool super ) const
+{
+ TQStrList l( FALSE );
+
+ if ( superclass && super ) {
+ TQStrList sl = superclass->propertyNames( super );
+ for ( TQStrListIterator slit( sl ); slit.current(); ++slit )
+ l.append( slit.current() );
+ }
+
+ for( int i = 0; i < d->numPropData; ++i ) {
+ if ( d->propData[i].isValid() )
+ l.append( d->propData[i].name() );
+ }
+
+ return l;
+}
+
+/*!
+ Returns a list with the names of all this class's Q_SIGNALS.
+
+ If \a super is TRUE, inherited Q_SIGNALS are included.
+*/
+TQStrList TQMetaObject::signalNames( bool super ) const
+{
+ TQStrList l( FALSE );
+ int n = numSignals( super );
+ for( int i = 0; i < n; ++i ) {
+ l.append( signal(i, super)->name );
+ }
+ return l;
+}
+
+/*!
+ Returns a list with the names of all this class's Q_SLOTS.
+
+ If \a super is TRUE, inherited Q_SLOTS are included.
+
+ \sa numSlots()
+*/
+TQStrList TQMetaObject::slotNames( bool super ) const
+{
+ TQStrList l( FALSE );
+ int n = numSlots( super );
+ for( int i = 0; i < n; ++i )
+ l.append( slot( i, super)->name );
+ return l;
+}
+
+/*!\internal
+
+ */
+
+int TQMetaObject::numEnumerators( bool super ) const
+{
+ int n = 0;
+ if ( superclass && super )
+ n += superclass->numEnumerators( super );
+ return n + d->numEnumData;
+}
+
+/*!\internal
+
+ */
+TQStrList TQMetaObject::enumeratorNames( bool super ) const
+{
+ TQStrList l( FALSE );
+
+ if ( superclass && super ) {
+ TQStrList sl = superclass->enumeratorNames( super );
+ for ( TQStrListIterator slit( sl ); slit.current(); ++slit )
+ l.append( slit.current() );
+ }
+
+ for( int i = 0; i < d->numEnumData; ++i ) {
+ if ( d->enumData[i].items )
+ l.append( d->enumData[i].name );
+ }
+
+ return l;
+}
+
+/*!\internal
+ */
+const TQMetaEnum* TQMetaObject::enumerator( const char* name, bool super ) const
+{
+ for( int i = 0; i < d->numEnumData; ++i )
+ if ( qstrcmp( d->enumData[i].name, name ) == 0 )
+ return &(d->enumData[i]);
+ if ( !super || !superclass )
+ return 0;
+ return superclass->enumerator( name, super );
+}
+
+#endif // TQT_NO_PROPERTIES
+
+
+/*!
+ Returns TRUE if this class inherits \a clname within the meta
+ object inheritance chain; otherwise returns FALSE.
+
+ (A class is considered to inherit itself.)
+*/
+bool TQMetaObject::inherits( const char* clname ) const
+{
+ const TQMetaObject *meta = this;
+ while ( meta ) {
+ if ( qstrcmp(clname, meta->className()) == 0 )
+ return TRUE;
+ meta = meta->superclass;
+ }
+ return FALSE;
+}
+
+/*! \internal */
+
+TQMetaObject *TQMetaObject::tqmetaObject( const char *class_name )
+{
+ if ( !qt_metaobjects )
+ return 0;
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ TQtStaticMetaObjectFunction func = (TQtStaticMetaObjectFunction)qt_metaobjects->tqfind( class_name );
+ if ( func )
+ return func();
+ return 0;
+}
+
+/*! \internal */
+bool TQMetaObject::hasMetaObject( const char *class_name )
+{
+ if ( !qt_metaobjects )
+ return FALSE;
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ return !!qt_metaobjects->tqfind( class_name );
+}
+
+#ifndef TQT_NO_PROPERTIES
+/*! \internal
+
+### this functions will go away. It exists purely for the sake of meta
+### object code generated with TQt 3.1.0
+*/
+bool TQMetaObject::qt_static_property( TQObject* o, int id, int f, TQVariant* v)
+{
+ if ( d->qt_static_property )
+ return d->qt_static_property( o, id, f, v );
+ else if ( o ) // compatibility
+ return o->qt_property( id, f, v );
+ else if ( superclass )
+ return superclass->qt_static_property( o, id, f, v );
+ switch ( f ) {
+ case 3: case 4: case 5:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+
+/*!
+ \class TQMetaProperty tqmetaobject.h
+
+ \brief The TQMetaProperty class stores meta data about a property.
+
+ \ingroup objectmodel
+
+ Property meta data includes type(), name(), and whether a property
+ is writable(), designable() and stored().
+
+ The functions isSetType(), isEnumType() and enumKeys() provide
+ further information about a property's type. The conversion
+ functions keyToValue(), valueToKey(), keysToValue() and
+ valueToKeys() allow conversion between the integer representation
+ of an enumeration or set value and its literal representation.
+
+ Actual property values are set and received through TQObject's set
+ and get functions. See TQObject::setProperty() and
+ TQObject::property() for details.
+
+ You receive meta property data through an object's meta object.
+ See TQMetaObject::property() and TQMetaObject::propertyNames() for
+ details.
+*/
+
+/*!
+ Returns the possible enumeration keys if this property is an
+ enumeration type (or a set type).
+
+ \sa isEnumType()
+*/
+TQStrList TQMetaProperty::enumKeys() const
+{
+ TQStrList l( FALSE );
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return l;
+ if ( ed != 0 ) {
+ for( uint i = 0; i < ed->count; ++i ) {
+ uint j = 0;
+ while ( j < i &&
+ ed->items[j].value != ed->items[i].value )
+ ++j;
+ if ( i == j )
+ l.append( ed->items[i].key );
+ }
+ }
+ return l;
+}
+
+/*!
+ Converts the enumeration key \a key to its integer value.
+
+ For set types, use keysToValue().
+
+ \sa valueToKey(), isSetType(), keysToValue()
+*/
+int TQMetaProperty::keyToValue( const char* key ) const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return -1;
+ for ( uint i = 0; i < ed->count; ++i ) {
+ if ( !qstrcmp( key, ed->items[i].key) )
+ return ed->items[i].value;
+ }
+ return -1;
+}
+
+/*!
+ Converts the enumeration value \a value to its literal key.
+
+ For set types, use valueToKeys().
+
+ \sa valueToKey(), isSetType(), valueToKeys()
+*/
+const char* TQMetaProperty::valueToKey( int value ) const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return 0;
+ for ( uint i = 0; i < ed->count; ++i ) {
+ if ( value == ed->items[i].value )
+ return ed->items[i].key ;
+ }
+ return 0;
+}
+
+/*!
+ Converts the list of keys \a keys to their combined (OR-ed)
+ integer value.
+
+ \sa isSetType(), valueToKey(), keysToValue()
+*/
+int TQMetaProperty::keysToValue( const TQStrList& keys ) const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return -1;
+ int value = 0;
+ for ( TQStrListIterator it( keys ); it.current(); ++it ) {
+ uint i;
+ for( i = ed->count; i > 0; --i ) {
+ if ( !qstrcmp( it.current(), ed->items[i-1].key) ) {
+ value |= ed->items[i-1].value;
+ break;
+ }
+ }
+ if ( i == 0 )
+ value |= -1;
+ }
+ return value;
+}
+
+/*!
+ Converts the set value \a value to a list of keys.
+
+ \sa isSetType(), valueToKey(), valueToKeys()
+*/
+TQStrList TQMetaProperty::valueToKeys( int value ) const
+{
+ TQStrList keys;
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ if ( !ed )
+ return keys;
+
+ int v = value;
+ for( uint i = ed->count; i > 0; --i ) {
+ int k = ed->items[i-1].value;
+ if ( ( k != 0 && (v & k) == k ) || ( k == value) ) {
+ v = v & ~k;
+ keys.append( ed->items[i-1].key );
+ }
+ }
+ return keys;
+}
+
+bool TQMetaProperty::writable() const
+{
+ if ( !testFlags( Override ) || testFlags( Writable ) )
+ return testFlags( Writable );
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->writable() : FALSE;
+}
+
+/*!\internal
+ */
+bool TQMetaProperty::stdSet() const
+{
+ if ( !testFlags( Override ) || testFlags( Writable ) )
+ return testFlags( StdSet );
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->stdSet() : FALSE;
+}
+
+/*!\internal
+ */
+int TQMetaProperty::id() const
+{
+ return _id < 0 ? (*meta)->indexOfProperty( this, TRUE ) : _id;
+}
+
+/*! \internal
+*/
+void TQMetaProperty::clear()
+{
+ t = n = 0;
+ meta = 0;
+ enumData = 0;
+ _id = -1;
+ flags = 0;
+}
+
+bool TQMetaProperty::isValid() const
+{
+ if ( testFlags( UnresolvedEnum ) ) {
+ if ( !enumData && (!meta || !(*meta)->enumerator( t, TRUE ) ) )
+ return FALSE;
+ }
+ if ( !testFlags( Override ) || testFlags( Readable ) )
+ return testFlags( Readable );
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->isValid() : FALSE;
+}
+
+bool TQMetaProperty::isSetType() const
+{
+ const TQMetaEnum* ed = enumData;
+ if ( !enumData && meta )
+ ed = (*meta)->enumerator( t, TRUE );
+ return ( ed != 0 && ed->set );
+}
+
+bool TQMetaProperty::isEnumType() const
+{
+ return testFlags( EnumOrSet );
+}
+
+
+
+/*!
+ \fn const char* TQMetaProperty::type() const
+
+ Returns the type of the property.
+*/
+
+/*!
+ \fn const char* TQMetaProperty::name() const
+
+ Returns the name of the property.
+*/
+
+/*!
+ \fn bool TQMetaProperty::writable() const
+
+ Returns TRUE if the property is writable; otherwise returns FALSE.
+
+*/
+
+/*! \fn bool TQMetaProperty::isValid() const
+
+ \internal
+
+ Returns whether the property is valid.
+*/
+
+/*!
+ \fn bool TQMetaProperty::isEnumType() const
+
+ Returns TRUE if the property's type is an enumeration value;
+ otherwise returns FALSE.
+
+ \sa isSetType(), enumKeys()
+*/
+
+/*!
+ \fn bool TQMetaProperty::isSetType() const
+
+ Returns TRUE if the property's type is an enumeration value that
+ is used as set, i.e. if the enumeration values can be OR-ed
+ together; otherwise returns FALSE. A set type is implicitly also
+ an enum type.
+
+ \sa isEnumType(), enumKeys()
+*/
+
+
+/*! Returns TRUE if the property is designable for object \a o;
+ otherwise returns FALSE.
+
+ If no object \a o is given, the function returns a static
+ approximation.
+ */
+bool TQMetaProperty::designable( TQObject* o ) const
+{
+ if ( !isValid() || !writable() )
+ return FALSE;
+ if ( o ) {
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ return idx >= 0 && o->qt_property( idx, 3, 0 );
+ }
+ if ( testFlags( DesignableOverride ) ) {
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->designable() : FALSE;
+ }
+ return !testFlags( NotDesignable );
+}
+
+/*!
+ Returns TRUE if the property is scriptable for object \a o;
+ otherwise returns FALSE.
+
+ If no object \a o is given, the function returns a static
+ approximation.
+ */
+bool TQMetaProperty::scriptable( TQObject* o ) const
+{
+ if ( o ) {
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ return idx >= 0 && o->qt_property( idx, 4, 0 );
+ }
+ if ( testFlags( ScriptableOverride ) ) {
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->scriptable() : FALSE;
+ }
+ return !testFlags( NotScriptable );
+}
+
+/*!
+ Returns TRUE if the property shall be stored for object \a o;
+ otherwise returns FALSE.
+
+ If no object \a o is given, the function returns a static
+ approximation.
+ */
+bool TQMetaProperty::stored( TQObject* o ) const
+{
+ if ( !isValid() || !writable() )
+ return FALSE;
+ if ( o ) {
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ return idx >= 0 && o->qt_property( idx, 5, 0 );
+ }
+ if ( testFlags( StoredOverride ) ) {
+ const TQMetaObject* mo = (*meta);
+ const TQMetaProperty* tqparent = mo->resolveProperty( this );
+ return tqparent ? tqparent->stored() : FALSE;
+ }
+ return !testFlags( NotStored );
+}
+
+
+/*!
+ Tries to reset the property for object \a o with a reset method.
+ On success, returns TRUE; otherwise returns FALSE.
+
+ Reset methods are optional, usually only a few properties support
+ them.
+*/
+bool TQMetaProperty::reset( TQObject* o ) const
+{
+ if ( !o )
+ return FALSE;
+ int idx = _id >= 0 ? _id : (*meta)->indexOfProperty( this, TRUE );
+ if ( idx < 0 )
+ return 0;
+ return o->qt_property( idx, 2, 0 );
+}
+
+
+/*! \enum TQMetaProperty::Flags
+
+ \internal
+*/
+
+#endif // TQT_NO_PROPERTIES
+
+/*
+ * TQMetaObjectCleanUp is used as static global object in the tqmoc-generated cpp
+ * files and deletes the TQMetaObject provided with setMetaObject. It sets the
+ * TQObject reference to the metaObj to NULL when it is destroyed.
+ */
+TQMetaObjectCleanUp::TQMetaObjectCleanUp( const char *mo_name, TQtStaticMetaObjectFunction func )
+ : tqmetaObject( 0 )
+{
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ if ( !qt_metaobjects )
+ qt_metaobjects = new TQAsciiDict<void>( 257 );
+ qt_metaobjects->insert( mo_name, (void*)func );
+
+ qt_metaobjects_count++;
+}
+
+TQMetaObjectCleanUp::TQMetaObjectCleanUp()
+ : tqmetaObject( 0 )
+{
+}
+
+/*! \fn bool TQMetaProperty::testFlags( uint f ) const
+ \internal
+*/
+
+TQMetaObjectCleanUp::~TQMetaObjectCleanUp()
+{
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( &qt_metaobjects ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+ if ( !--qt_metaobjects_count ) {
+ delete qt_metaobjects;
+ qt_metaobjects = 0;
+ }
+ if ( tqmetaObject ) {
+ delete *tqmetaObject;
+ *tqmetaObject = 0;
+ tqmetaObject = 0;
+ }
+}
+
+void TQMetaObjectCleanUp::setMetaObject( TQMetaObject *&mo )
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( tqmetaObject )
+ qWarning( "TQMetaObjectCleanUp::setMetaObject: Double use of TQMetaObjectCleanUp!" );
+#endif
+ tqmetaObject = &mo;
+}
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqmetaobject.h b/tqtinterface/qt4/src/kernel/tqmetaobject.h
new file mode 100644
index 0000000..5502743
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmetaobject.h
@@ -0,0 +1,404 @@
+/****************************************************************************
+**
+** Definition of TQMetaObject class
+**
+** Created : 930419
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQMETAOBJECT_H
+#define TQMETAOBJECT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqconnection.h"
+#include "tqstrlist.h"
+#endif // TQT_H
+
+#ifndef TQ_TQMOC_OUTPUT_REVISION
+#define TQ_TQMOC_OUTPUT_REVISION 26
+#endif
+
+#ifdef USE_QT4
+
+#include <Qt/qmetaobject.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+struct TQUMethod;
+
+class TQ_EXPORT TQMetaEnum : public QMetaEnum, virtual public TQt
+{
+public:
+ TQMetaEnum();
+
+ struct Item // - a name/value pair
+ {
+ const char *key;
+ int value;
+ };
+
+ uint count() const;
+ Item* items() const;
+
+private:
+ mutable Item* internal_item_list;
+ mutable int internal_item_count;
+};
+
+class TQ_EXPORT TQMetaData : public QMetaMethod, virtual public TQt
+{
+public:
+ TQMetaData();
+
+ const char *name() const;
+ const TQUMethod* method() const;
+
+ mutable TQUMethod* internal_method_information;
+};
+
+class TQ_EXPORT TQMetaProperty : public QMetaProperty, virtual public TQt
+{
+public:
+ TQMetaProperty();
+
+ bool isSetType() const;
+ int keyToValue( const char* key ) const;
+ const char* valueToKey( int value ) const;
+ int keysToValue( const TQStrList& keys_in ) const;
+ TQStrList valueToKeys( int value ) const;
+ bool writable() const;
+ const char* type() const;
+ TQStrList enumKeys() const;
+
+ bool designable( TQT_BASE_OBJECT_NAME *o = 0 ) const;
+ bool scriptable( TQT_BASE_OBJECT_NAME *o = 0 ) const;
+ bool stored( TQT_BASE_OBJECT_NAME *o = 0 ) const;
+
+ bool stdSet() const; // internal
+
+// inline bool reset( TQT_BASE_OBJECT_NAME *o ) const { return isResettable(o); }
+};
+
+class TQ_EXPORT TQClassInfo : public QMetaClassInfo, virtual public TQt
+{
+public:
+ TQClassInfo() : QMetaClassInfo() {}
+};
+
+class TQ_EXPORT TQMetaObject : public QMetaObject, virtual public TQt
+{
+public:
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums,
+#endif // TQT_NO_PROPERTIES
+ const TQClassInfo *const class_info, int n_info );
+
+#ifndef TQT_NO_PROPERTIES
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS, const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums, bool (*qt_static_property)(TQObject*, int, int, TQVariant*), const TQClassInfo *const class_info, int n_info );
+#endif // TQT_NO_PROPERTIES
+
+ TQStrList slotNames( bool super = FALSE ) const;
+ TQStrList signalNames( bool super = FALSE ) const;
+
+#ifndef TQT_NO_PROPERTIES
+ int tqfindProperty( const char *name, bool super = FALSE ) const;
+ TQMetaObject *tqsuperClass() const;
+ const char *tqsuperClassName() const;
+ TQStrList propertyNames( bool super = FALSE ) const;
+
+ int numSlots( bool super = FALSE ) const;
+ int numSignals( bool super = FALSE ) const;
+ int numClassInfo( bool super = FALSE ) const;
+
+ const TQMetaData *slot( int index, bool super = FALSE ) const;
+ const TQMetaData *signal( int index, bool super = FALSE ) const;
+
+ int tqfindSlot( const char *, bool super = FALSE ) const;
+ int tqfindSignal( const char *, bool super = FALSE ) const;
+
+ int numProperties( bool super = FALSE ) const;
+ const TQMetaProperty *property( int index, bool super = FALSE ) const;
+
+ const TQMetaEnum *enumerator( const char* name, bool super = FALSE ) const;
+ TQStrList enumeratorNames( bool super = FALSE ) const;
+#endif // TQT_NO_PROPERTIES
+
+ const TQClassInfo *classInfo( int index, bool super = FALSE ) const;
+ const char *classInfo( const char* name, bool super = FALSE ) const;
+};
+
+#else // USE_QT4
+
+class TQObject;
+struct TQUMethod;
+class TQMetaObjectPrivate;
+
+struct TQMetaData // - member function meta data
+{ // for signal and Q_SLOTS
+ const char *name; // - member name
+ const TQUMethod* method; // - detailed method description
+ enum Access { Private, Protected, Public };
+ Access access; // - access permission
+};
+
+#ifndef TQT_NO_PROPERTIES
+struct TQMetaEnum // enumerator meta data
+{ // for properties
+ const char *name; // - enumerator name
+ uint count; // - number of values
+ struct Item // - a name/value pair
+ {
+ const char *key;
+ int value;
+ };
+ const Item *items; // - the name/value pairs
+ bool set; // whether enum has to be treated as a set
+};
+#endif
+
+#ifndef TQT_NO_PROPERTIES
+
+class TQ_EXPORT TQMetaProperty // property meta data
+{
+public:
+ const char* type() const { return t; } // type of the property
+ const char* name() const { return n; } // name of the property
+
+ bool writable() const;
+ bool isValid() const;
+
+ bool isSetType() const;
+ bool isEnumType() const;
+ TQStrList enumKeys() const; // enumeration names
+
+ int keyToValue( const char* key ) const; // enum and set conversion functions
+ const char* valueToKey( int value ) const;
+ int keysToValue( const TQStrList& keys ) const;
+ TQStrList valueToKeys( int value ) const;
+
+ bool designable( TQObject* = 0 ) const;
+ bool scriptable( TQObject* = 0 ) const;
+ bool stored( TQObject* = 0 ) const;
+
+ bool reset( TQObject* ) const;
+
+ const char* t; // internal
+ const char* n; // internal
+
+ enum Flags {
+ Invalid = 0x00000000,
+ Readable = 0x00000001,
+ Writable = 0x00000002,
+ EnumOrSet = 0x00000004,
+ UnresolvedEnum = 0x00000008,
+ StdSet = 0x00000100,
+ Override = 0x00000200
+ };
+
+ uint flags; // internal
+ bool testFlags( uint f ) const; // internal
+ bool stdSet() const; // internal
+ int id() const; // internal
+
+ TQMetaObject** meta; // internal
+
+ const TQMetaEnum* enumData; // internal
+ int _id; // internal
+ void clear(); // internal
+};
+
+inline bool TQMetaProperty::testFlags( uint f ) const
+{ return (flags & (uint)f) != (uint)0; }
+
+#endif // TQT_NO_PROPERTIES
+
+struct TQClassInfo // class info meta data
+{
+ const char* name; // - name of the info
+ const char* value; // - value of the info
+};
+
+class TQ_EXPORT TQMetaObject // meta object class
+{
+public:
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+#endif
+ const TQClassInfo *const class_info, int n_info );
+
+#ifndef TQT_NO_PROPERTIES
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo *const class_info, int n_info );
+#endif
+
+
+ virtual ~TQMetaObject();
+
+ const char *className() const { return classname; }
+ const char *superClassName() const { return superclassname; }
+
+ TQMetaObject *superClass() const { return superclass; }
+
+ bool inherits( const char* clname ) const;
+
+ int numSlots( bool super = FALSE ) const;
+ int numSignals( bool super = FALSE ) const;
+
+ int tqfindSlot( const char *, bool super = FALSE ) const;
+ int tqfindSignal( const char *, bool super = FALSE ) const;
+
+ const TQMetaData *slot( int index, bool super = FALSE ) const;
+ const TQMetaData *signal( int index, bool super = FALSE ) const;
+
+ TQStrList slotNames( bool super = FALSE ) const;
+ TQStrList signalNames( bool super = FALSE ) const;
+
+ int slotOffset() const;
+ int signalOffset() const;
+ int propertyOffset() const;
+
+ int numClassInfo( bool super = FALSE ) const;
+ const TQClassInfo *classInfo( int index, bool super = FALSE ) const;
+ const char *classInfo( const char* name, bool super = FALSE ) const;
+
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *property( int index, bool super = FALSE ) const;
+ int tqfindProperty( const char *name, bool super = FALSE ) const;
+ int indexOfProperty( const TQMetaProperty*, bool super = FALSE ) const;
+ const TQMetaProperty* resolveProperty( const TQMetaProperty* ) const;
+ int resolveProperty( int ) const;
+ TQStrList propertyNames( bool super = FALSE ) const;
+ int numProperties( bool super = FALSE ) const;
+#endif
+
+ // static wrappers around constructors, necessary to work around a
+ // Windows-DLL limitation: objects can only be deleted within a
+ // DLL if they were actually created within that DLL.
+ static TQMetaObject *new_metaobject( const char *, TQMetaObject *,
+ const TQMetaData *const, int,
+ const TQMetaData *const, int,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+#endif
+ const TQClassInfo *const class_info, int n_info );
+#ifndef TQT_NO_PROPERTIES
+ static TQMetaObject *new_metaobject( const char *, TQMetaObject *,
+ const TQMetaData *const, int,
+ const TQMetaData *const, int,
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo *const class_info, int n_info );
+ TQStrList enumeratorNames( bool super = FALSE ) const;
+ int numEnumerators( bool super = FALSE ) const;
+ const TQMetaEnum *enumerator( const char* name, bool super = FALSE ) const;
+#endif
+
+ static TQMetaObject *tqmetaObject( const char *class_name );
+ static bool hasMetaObject( const char *class_name );
+
+private:
+ TQMemberDict *init( const TQMetaData *, int );
+
+ const char *classname; // class name
+ const char *superclassname; // super class name
+ TQMetaObject *superclass; // super class meta object
+ TQMetaObjectPrivate *d; // private data for...
+ void *reserved; // ...binary compatibility
+ const TQMetaData *slotData; // slot meta data
+ TQMemberDict *slotDict; // slot dictionary
+ const TQMetaData *signalData; // signal meta data
+ TQMemberDict *signalDict; // signal dictionary
+ int signaloffset;
+ int slotoffset;
+#ifndef TQT_NO_PROPERTIES
+ int propertyoffset;
+public:
+ bool qt_static_property( TQObject* o, int id, int f, TQVariant* v);
+private:
+ friend class TQMetaProperty;
+#endif
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQMetaObject( const TQMetaObject & );
+ TQMetaObject &operator=( const TQMetaObject & );
+#endif
+};
+
+inline int TQMetaObject::slotOffset() const
+{ return slotoffset; }
+
+inline int TQMetaObject::signalOffset() const
+{ return signaloffset; }
+
+#ifndef TQT_NO_PROPERTIES
+inline int TQMetaObject::propertyOffset() const
+{ return propertyoffset; }
+#endif
+
+typedef TQMetaObject *(*TQtStaticMetaObjectFunction)();
+
+class TQ_EXPORT TQMetaObjectCleanUp
+{
+public:
+ TQMetaObjectCleanUp( const char *mo_name, TQtStaticMetaObjectFunction );
+ TQMetaObjectCleanUp();
+ ~TQMetaObjectCleanUp();
+
+ void setMetaObject( TQMetaObject *&mo );
+
+private:
+ TQMetaObject **tqmetaObject;
+};
+
+#endif // USE_QT4
+
+#endif // TQMETAOBJECT_H
diff --git a/tqtinterface/qt4/src/kernel/tqmetaobject.h~ b/tqtinterface/qt4/src/kernel/tqmetaobject.h~
new file mode 100644
index 0000000..ecb6c23
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmetaobject.h~
@@ -0,0 +1,403 @@
+/****************************************************************************
+**
+** Definition of TQMetaObject class
+**
+** Created : 930419
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQMETAOBJECT_H
+#define TQMETAOBJECT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqconnection.h"
+#include "tqstrlist.h"
+#endif // TQT_H
+
+#ifndef TQ_TQMOC_OUTPUT_REVISION
+#define TQ_TQMOC_OUTPUT_REVISION 26
+#endif
+
+#ifdef USE_QT4
+
+#include <Qt/qmetaobject.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+struct TQUMethod;
+
+class TQ_EXPORT TQMetaEnum : public QMetaEnum, virtual public TQt
+{
+public:
+ TQMetaEnum();
+
+ struct Item // - a name/value pair
+ {
+ const char *key;
+ int value;
+ };
+
+ uint count() const;
+ Item* items() const;
+
+private:
+ mutable Item* internal_item_list;
+};
+
+class TQ_EXPORT TQMetaData : public QMetaMethod, virtual public TQt
+{
+public:
+ TQMetaData();
+
+ const char *name() const;
+ const TQUMethod* method() const;
+
+ mutable TQUMethod* internal_method_information;
+};
+
+class TQ_EXPORT TQMetaProperty : public QMetaProperty, virtual public TQt
+{
+public:
+ TQMetaProperty();
+
+ bool isSetType() const;
+ int keyToValue( const char* key ) const;
+ const char* valueToKey( int value ) const;
+ int keysToValue( const TQStrList& keys_in ) const;
+ TQStrList valueToKeys( int value ) const;
+ bool writable() const;
+ const char* type() const;
+ TQStrList enumKeys() const;
+
+ bool designable( TQT_BASE_OBJECT_NAME *o = 0 ) const;
+ bool scriptable( TQT_BASE_OBJECT_NAME *o = 0 ) const;
+ bool stored( TQT_BASE_OBJECT_NAME *o = 0 ) const;
+
+ bool stdSet() const; // internal
+
+// inline bool reset( TQT_BASE_OBJECT_NAME *o ) const { return isResettable(o); }
+};
+
+class TQ_EXPORT TQClassInfo : public QMetaClassInfo, virtual public TQt
+{
+public:
+ TQClassInfo() : QMetaClassInfo() {}
+};
+
+class TQ_EXPORT TQMetaObject : public QMetaObject, virtual public TQt
+{
+public:
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums,
+#endif // TQT_NO_PROPERTIES
+ const TQClassInfo *const class_info, int n_info );
+
+#ifndef TQT_NO_PROPERTIES
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass, const TQMetaData * const slot_data, int n_Q_SLOTS, const TQMetaData * const signal_data, int n_Q_SIGNALS, const TQMetaProperty *const prop_data, int n_props, const TQMetaEnum *const enum_data, int n_enums, bool (*qt_static_property)(TQObject*, int, int, TQVariant*), const TQClassInfo *const class_info, int n_info );
+#endif // TQT_NO_PROPERTIES
+
+ TQStrList slotNames( bool super = FALSE ) const;
+ TQStrList signalNames( bool super = FALSE ) const;
+
+#ifndef TQT_NO_PROPERTIES
+ int tqfindProperty( const char *name, bool super = FALSE ) const;
+ TQMetaObject *tqsuperClass() const;
+ const char *tqsuperClassName() const;
+ TQStrList propertyNames( bool super = FALSE ) const;
+
+ int numSlots( bool super = FALSE ) const;
+ int numSignals( bool super = FALSE ) const;
+ int numClassInfo( bool super = FALSE ) const;
+
+ const TQMetaData *slot( int index, bool super = FALSE ) const;
+ const TQMetaData *signal( int index, bool super = FALSE ) const;
+
+ int tqfindSlot( const char *, bool super = FALSE ) const;
+ int tqfindSignal( const char *, bool super = FALSE ) const;
+
+ int numProperties( bool super = FALSE ) const;
+ const TQMetaProperty *property( int index, bool super = FALSE ) const;
+
+ const TQMetaEnum *enumerator( const char* name, bool super = FALSE ) const;
+ TQStrList enumeratorNames( bool super = FALSE ) const;
+#endif // TQT_NO_PROPERTIES
+
+ const TQClassInfo *classInfo( int index, bool super = FALSE ) const;
+ const char *classInfo( const char* name, bool super = FALSE ) const;
+};
+
+#else // USE_QT4
+
+class TQObject;
+struct TQUMethod;
+class TQMetaObjectPrivate;
+
+struct TQMetaData // - member function meta data
+{ // for signal and Q_SLOTS
+ const char *name; // - member name
+ const TQUMethod* method; // - detailed method description
+ enum Access { Private, Protected, Public };
+ Access access; // - access permission
+};
+
+#ifndef TQT_NO_PROPERTIES
+struct TQMetaEnum // enumerator meta data
+{ // for properties
+ const char *name; // - enumerator name
+ uint count; // - number of values
+ struct Item // - a name/value pair
+ {
+ const char *key;
+ int value;
+ };
+ const Item *items; // - the name/value pairs
+ bool set; // whether enum has to be treated as a set
+};
+#endif
+
+#ifndef TQT_NO_PROPERTIES
+
+class TQ_EXPORT TQMetaProperty // property meta data
+{
+public:
+ const char* type() const { return t; } // type of the property
+ const char* name() const { return n; } // name of the property
+
+ bool writable() const;
+ bool isValid() const;
+
+ bool isSetType() const;
+ bool isEnumType() const;
+ TQStrList enumKeys() const; // enumeration names
+
+ int keyToValue( const char* key ) const; // enum and set conversion functions
+ const char* valueToKey( int value ) const;
+ int keysToValue( const TQStrList& keys ) const;
+ TQStrList valueToKeys( int value ) const;
+
+ bool designable( TQObject* = 0 ) const;
+ bool scriptable( TQObject* = 0 ) const;
+ bool stored( TQObject* = 0 ) const;
+
+ bool reset( TQObject* ) const;
+
+ const char* t; // internal
+ const char* n; // internal
+
+ enum Flags {
+ Invalid = 0x00000000,
+ Readable = 0x00000001,
+ Writable = 0x00000002,
+ EnumOrSet = 0x00000004,
+ UnresolvedEnum = 0x00000008,
+ StdSet = 0x00000100,
+ Override = 0x00000200
+ };
+
+ uint flags; // internal
+ bool testFlags( uint f ) const; // internal
+ bool stdSet() const; // internal
+ int id() const; // internal
+
+ TQMetaObject** meta; // internal
+
+ const TQMetaEnum* enumData; // internal
+ int _id; // internal
+ void clear(); // internal
+};
+
+inline bool TQMetaProperty::testFlags( uint f ) const
+{ return (flags & (uint)f) != (uint)0; }
+
+#endif // TQT_NO_PROPERTIES
+
+struct TQClassInfo // class info meta data
+{
+ const char* name; // - name of the info
+ const char* value; // - value of the info
+};
+
+class TQ_EXPORT TQMetaObject // meta object class
+{
+public:
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+#endif
+ const TQClassInfo *const class_info, int n_info );
+
+#ifndef TQT_NO_PROPERTIES
+ TQMetaObject( const char * const class_name, TQMetaObject *superclass,
+ const TQMetaData * const slot_data, int n_Q_SLOTS,
+ const TQMetaData * const signal_data, int n_Q_SIGNALS,
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo *const class_info, int n_info );
+#endif
+
+
+ virtual ~TQMetaObject();
+
+ const char *className() const { return classname; }
+ const char *superClassName() const { return superclassname; }
+
+ TQMetaObject *superClass() const { return superclass; }
+
+ bool inherits( const char* clname ) const;
+
+ int numSlots( bool super = FALSE ) const;
+ int numSignals( bool super = FALSE ) const;
+
+ int tqfindSlot( const char *, bool super = FALSE ) const;
+ int tqfindSignal( const char *, bool super = FALSE ) const;
+
+ const TQMetaData *slot( int index, bool super = FALSE ) const;
+ const TQMetaData *signal( int index, bool super = FALSE ) const;
+
+ TQStrList slotNames( bool super = FALSE ) const;
+ TQStrList signalNames( bool super = FALSE ) const;
+
+ int slotOffset() const;
+ int signalOffset() const;
+ int propertyOffset() const;
+
+ int numClassInfo( bool super = FALSE ) const;
+ const TQClassInfo *classInfo( int index, bool super = FALSE ) const;
+ const char *classInfo( const char* name, bool super = FALSE ) const;
+
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *property( int index, bool super = FALSE ) const;
+ int tqfindProperty( const char *name, bool super = FALSE ) const;
+ int indexOfProperty( const TQMetaProperty*, bool super = FALSE ) const;
+ const TQMetaProperty* resolveProperty( const TQMetaProperty* ) const;
+ int resolveProperty( int ) const;
+ TQStrList propertyNames( bool super = FALSE ) const;
+ int numProperties( bool super = FALSE ) const;
+#endif
+
+ // static wrappers around constructors, necessary to work around a
+ // Windows-DLL limitation: objects can only be deleted within a
+ // DLL if they were actually created within that DLL.
+ static TQMetaObject *new_metaobject( const char *, TQMetaObject *,
+ const TQMetaData *const, int,
+ const TQMetaData *const, int,
+#ifndef TQT_NO_PROPERTIES
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+#endif
+ const TQClassInfo *const class_info, int n_info );
+#ifndef TQT_NO_PROPERTIES
+ static TQMetaObject *new_metaobject( const char *, TQMetaObject *,
+ const TQMetaData *const, int,
+ const TQMetaData *const, int,
+ const TQMetaProperty *const prop_data, int n_props,
+ const TQMetaEnum *const enum_data, int n_enums,
+ bool (*qt_static_property)(TQObject*, int, int, TQVariant*),
+ const TQClassInfo *const class_info, int n_info );
+ TQStrList enumeratorNames( bool super = FALSE ) const;
+ int numEnumerators( bool super = FALSE ) const;
+ const TQMetaEnum *enumerator( const char* name, bool super = FALSE ) const;
+#endif
+
+ static TQMetaObject *tqmetaObject( const char *class_name );
+ static bool hasMetaObject( const char *class_name );
+
+private:
+ TQMemberDict *init( const TQMetaData *, int );
+
+ const char *classname; // class name
+ const char *superclassname; // super class name
+ TQMetaObject *superclass; // super class meta object
+ TQMetaObjectPrivate *d; // private data for...
+ void *reserved; // ...binary compatibility
+ const TQMetaData *slotData; // slot meta data
+ TQMemberDict *slotDict; // slot dictionary
+ const TQMetaData *signalData; // signal meta data
+ TQMemberDict *signalDict; // signal dictionary
+ int signaloffset;
+ int slotoffset;
+#ifndef TQT_NO_PROPERTIES
+ int propertyoffset;
+public:
+ bool qt_static_property( TQObject* o, int id, int f, TQVariant* v);
+private:
+ friend class TQMetaProperty;
+#endif
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQMetaObject( const TQMetaObject & );
+ TQMetaObject &operator=( const TQMetaObject & );
+#endif
+};
+
+inline int TQMetaObject::slotOffset() const
+{ return slotoffset; }
+
+inline int TQMetaObject::signalOffset() const
+{ return signaloffset; }
+
+#ifndef TQT_NO_PROPERTIES
+inline int TQMetaObject::propertyOffset() const
+{ return propertyoffset; }
+#endif
+
+typedef TQMetaObject *(*TQtStaticMetaObjectFunction)();
+
+class TQ_EXPORT TQMetaObjectCleanUp
+{
+public:
+ TQMetaObjectCleanUp( const char *mo_name, TQtStaticMetaObjectFunction );
+ TQMetaObjectCleanUp();
+ ~TQMetaObjectCleanUp();
+
+ void setMetaObject( TQMetaObject *&mo );
+
+private:
+ TQMetaObject **tqmetaObject;
+};
+
+#endif // USE_QT4
+
+#endif // TQMETAOBJECT_H
diff --git a/tqtinterface/qt4/src/kernel/tqmime.cpp b/tqtinterface/qt4/src/kernel/tqmime.cpp
new file mode 100644
index 0000000..46d07d3
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmime.cpp
@@ -0,0 +1,1158 @@
+/****************************************************************************
+**
+** Implementation of MIME support
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqmime.h"
+
+#ifndef TQT_NO_MIME
+
+#include "tqmap.h"
+#include "tqstringlist.h"
+#include "tqfileinfo.h"
+#include "tqdir.h"
+#include "tqdragobject.h"
+#include "tqcleanuphandler.h"
+#include "tqapplication.h" // ### for now
+#include "tqclipboard.h" // ### for now
+
+#ifdef USE_QT4
+
+#include "Qt/qmap.h"
+#include "Qt/qstringlist.h"
+#include "Qt/qfileinfo.h"
+#include "Qt/qdir.h"
+#include "tqdragobject.h"
+#include "Qt/qpixmap.h"
+#include "Qt/qimagereader.h"
+#include "tqcleanuphandler.h"
+#include "private/qt4_qtextimagehandler_p.h"
+
+#endif // USE_QT4
+
+static int qt_mime_serial_number = 0;
+static TQMimeSourceFactory* defaultfactory = 0;
+static TQSingleCleanupHandler<TQMimeSourceFactory> qmime_cleanup_factory;
+
+#ifdef USE_QT4
+// #if 0
+
+TQMimeSource::TQMimeSource() : QMimeSource() {
+ cacheType = NoCache;
+ ser_no = qt_mime_serial_number++;
+}
+
+/*!
+ \fn int TQMimeSource::serialNumber() const
+
+ Returns the mime source's globally unique serial number.
+*/
+
+
+void TQMimeSource::clearCache()
+{
+ if ( cacheType == Text ) {
+ delete cache.txt.str;
+ delete cache.txt.subtype;
+ cache.txt.str = 0;
+ cache.txt.subtype = 0;
+ } else if ( cacheType == Graphics ) {
+ delete cache.gfx.img;
+ delete cache.gfx.pix;
+ cache.gfx.img = 0;
+ cache.gfx.pix = 0;
+ }
+ cacheType = NoCache;
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQMimeSource tqmime.h
+ \brief The TQMimeSource class is an abstraction of objects which provide formatted data of a certain MIME type.
+
+ \ingroup io
+ \ingroup draganddrop
+ \ingroup misc
+
+ \link dnd.html Drag-and-drop\endlink and
+ \link TQClipboard clipboard\endlink use this abstraction.
+
+ \sa \link http://www.isi.edu/in-notes/iana/assignments/media-types/
+ IANA list of MIME media types\endlink
+*/
+
+/*!
+ Constructs a mime source and assigns a globally unique serial
+ number to it.
+
+ \sa serialNumber()
+*/
+
+TQMimeSource::TQMimeSource()
+{
+ ser_no = qt_mime_serial_number++;
+ cacheType = NoCache;
+}
+
+/*!
+ \fn int TQMimeSource::serialNumber() const
+
+ Returns the mime source's globally unique serial number.
+*/
+
+
+void TQMimeSource::clearCache()
+{
+ if ( cacheType == Text ) {
+ delete cache.txt.str;
+ delete cache.txt.subtype;
+ cache.txt.str = 0;
+ cache.txt.subtype = 0;
+ } else if ( cacheType == Graphics ) {
+ delete cache.gfx.img;
+ delete cache.gfx.pix;
+ cache.gfx.img = 0;
+ cache.gfx.pix = 0;
+ }
+ cacheType = NoCache;
+}
+
+/*!
+ Provided to ensure that subclasses destroy themselves correctly.
+*/
+TQMimeSource::~TQMimeSource()
+{
+#ifndef TQT_NO_CLIPBOARD
+ extern void qt_clipboard_cleanup_mime_source(TQMimeSource *);
+ qt_clipboard_cleanup_mime_source(this);
+#endif
+ clearCache();
+}
+
+/*!
+ \fn TQByteArray TQMimeSource::tqencodedData(const char*) const
+
+ Returns the encoded data of this object in the specified MIME
+ format.
+
+ Subclasses must reimplement this function.
+*/
+
+
+
+/*!
+ Returns TRUE if the object can provide the data in format \a
+ mimeType; otherwise returns FALSE.
+
+ If you inherit from TQMimeSource, for consistency reasons it is
+ better to implement the more abstract canDecode() functions such
+ as TQTextDrag::canDecode() and TQImageDrag::canDecode().
+*/
+bool TQMimeSource::provides(const char* mimeType) const
+{
+ const char* fmt;
+ for (int i=0; (fmt = format(i)); i++) {
+ if ( !qstricmp(mimeType,fmt) )
+ return TRUE;
+ }
+ return FALSE;
+}
+
+#endif // USE_QT4
+
+// #ifdef USE_QT4
+#if 0
+
+QT_BEGIN_NAMESPACE
+
+class TQMimeSourceFactoryData {
+public:
+ TQMimeSourceFactoryData() :
+ last(0)
+ {
+ }
+
+ ~TQMimeSourceFactoryData()
+ {
+ QMap<QString, QMimeSource*>::Iterator it = stored.begin();
+ while (it != stored.end()) {
+ delete *it;
+ ++it;
+ }
+ delete last;
+ }
+
+ QMap<QString, QMimeSource*> stored;
+ QMap<QString, QString> extensions;
+ QStringList path;
+ QMimeSource* last;
+ QList<TQMimeSourceFactory*> factories;
+};
+
+static QImage richTextImageLoader(const QString &name, const QString &context)
+{
+ QImage img;
+
+ const TQMimeSource *src = static_cast<const TQMimeSource*>(TQMimeSourceFactory::defaultFactory()->data(name, context));
+ if (src && TQImageDrag::decode(src, img))
+ return img;
+
+ return QImage();
+}
+
+/*!
+ \class TQMimeSourceFactory
+ \brief The TQMimeSourceFactory class is an extensible provider of mime-typed data.
+
+ \compat
+
+ A TQMimeSourceFactory provides an abstract interface to a
+ collection of information. Each piece of information is
+ represented by a QMimeSource object which can be examined and
+ converted to concrete data types by functions such as
+ TQImageDrag::canDecode() and TQImageDrag::decode().
+
+ The base TQMimeSourceFactory can be used in two ways: as an
+ abstraction of a collection of files or as specifically stored
+ data. For it to access files, call setFilePath() before accessing
+ data. For stored data, call setData() for each item (there are
+ also convenience functions, e.g. setText(), setImage() and
+ setPixmap(), that simply call setData() with appropriate
+ parameters).
+
+ The rich text widgets, QTextEdit and QTextBrowser, use
+ TQMimeSourceFactory to resolve references such as images or links
+ within rich text documents. They either access the default factory
+ (see \l{defaultFactory()}) or their own. Other classes that are
+ capable of displaying rich text (such as QLabel, QWhatsThis or
+ QMessageBox) always use the default factory.
+
+ A factory can also be used as a container to store data associated
+ with a name. This technique is useful whenever rich text contains
+ images that are stored in the program itself, not loaded from the
+ hard disk. Your program may, for example, define some image data
+ as:
+ \snippet doc/src/snippets/code/src_qt3support_other_q3mimefactory.cpp 0
+
+ To be able to use this image within some rich text, for example
+ inside a QLabel, you must create a QImage from the raw data and
+ insert it into the factory with a unique name:
+ \snippet doc/src/snippets/code/src_qt3support_other_q3mimefactory.cpp 1
+
+ Now you can create a rich text QLabel with
+
+ \snippet doc/src/snippets/code/src_qt3support_other_q3mimefactory.cpp 2
+
+ When no longer needed, you can clear the data from the factory:
+
+ \snippet doc/src/snippets/code/src_qt3support_other_q3mimefactory.cpp 3
+*/
+
+
+/*!
+ Constructs a TQMimeSourceFactory that has no file path and no
+ stored content.
+*/
+TQMimeSourceFactory::TQMimeSourceFactory() :
+ d(new TQMimeSourceFactoryData)
+{
+// addFilePath(QLatin1String(":/qt/q3mimesourcefactory/")); //to get from the resources // Where did this come from??!?!?!?
+ // add some reasonable defaults
+ setExtensionType(QLatin1String("htm"), "text/html;charset=iso8859-1");
+ setExtensionType(QLatin1String("html"), "text/html;charset=iso8859-1");
+ setExtensionType(QLatin1String("txt"), "text/plain");
+ setExtensionType(QLatin1String("xml"), "text/xml;charset=UTF-8");
+ setExtensionType(QLatin1String("jpg"), "image/jpeg"); // support misspelled jpeg files
+}
+
+/*!
+ Destroys the TQMimeSourceFactory, deleting all stored content.
+*/
+TQMimeSourceFactory::~TQMimeSourceFactory()
+{
+ if (defaultFactory() == this)
+ defaultfactory = 0;
+ delete d;
+}
+
+QMimeSource* TQMimeSourceFactory::dataInternal(const QString& abs_name, const QMap<QString, QString> &extensions) const
+{
+ QMimeSource* r = 0;
+ QStringList attempted_names(abs_name);
+ TQFileInfo fi(abs_name);
+ if (fi.isReadable()) {
+ // get the right mimetype
+ QString e = fi.extension(false);
+ QByteArray mimetype("application/octet-stream");
+ if (extensions.contains(e))
+ mimetype = TQT_TQSTRING(extensions[e]).latin1();
+ if (!QImageReader::imageFormat(abs_name).isEmpty())
+ mimetype = "application/x-qt-image";
+
+ TQFile f(abs_name);
+ if (f.open(QIODevice::ReadOnly) && f.size()) {
+ QByteArray ba;
+ ba.resize(f.size());
+ f.readBlock(ba.data(), ba.size());
+ TQStoredDrag* sr = new TQStoredDrag(mimetype);
+ sr->setEncodedData(TQT_TQBYTEARRAY_OBJECT(ba));
+ delete d->last;
+ d->last = r = sr;
+ }
+ }
+
+ // we didn't find the mime-source, so ask the default factory for
+ // the mime-source (this one will iterate over all installed ones)
+ //
+ // this looks dangerous, as this dataInternal() function will be
+ // called again when the default factory loops over all installed
+ // factories (including this), but the static bool looping in
+ // data() avoids endless recursions
+ if (!r && this != defaultFactory())
+ r = (QMimeSource*)defaultFactory()->data(abs_name);
+
+ return r;
+}
+
+
+/*!
+ Returns a reference to the data associated with \a abs_name. The
+ return value remains valid only until the next data() or setData()
+ call, so you should immediately decode the result.
+
+ If there is no data associated with \a abs_name in the factory's
+ store, the factory tries to access the local filesystem. If \a
+ abs_name isn't an absolute file name, the factory will search for
+ it in all defined paths (see \l{setFilePath()}).
+
+ The factory understands all the image formats supported by
+ QImageReader. Any other mime types are determined by the file name
+ extension. The default settings are
+ \snippet doc/src/snippets/code/src_qt3support_other_q3mimefactory.cpp 4
+ The effect of these is that file names ending in "txt" will be
+ treated as text encoded in the local encoding; those ending in
+ "xml" will be treated as text encoded in Unicode UTF-8 encoding.
+ The text/html type is treated specially, since the encoding can be
+ specified in the html file itself. "html" or "htm" will be treated
+ as text encoded in the encoding specified by the html meta tag, if
+ none could be found, the charset of the mime type will be used.
+ The text subtype ("html", "plain", or "xml") does not affect the
+ factory, but users of the factory may behave differently. We
+ recommend creating "xml" files where practical. These files can be
+ viewed regardless of the runtime encoding and can encode any
+ Unicode characters without resorting to encoding definitions
+ inside the file.
+
+ Any file data that is not recognized will be retrieved as a
+ QMimeSource providing the "application/octet-stream" mime type,
+ meaning uninterpreted binary data.
+
+ You can add further extensions or change existing ones with
+ subsequent calls to setExtensionType(). If the extension mechanism
+ is not sufficient for your problem domain, you can inherit
+ TQMimeSourceFactory and reimplement this function to perform some
+ more specialized mime-type detection. The same applies if you want
+ to use the mime source factory to access URL referenced data over
+ a network.
+*/
+const TQMimeSource *TQMimeSourceFactory::data(const QString& abs_name) const
+{
+ if (d->stored.contains(abs_name))
+ return static_cast<TQMimeSource*>(d->stored[abs_name]);
+
+ const QMimeSource *r = 0;
+ if (abs_name.isEmpty())
+ return static_cast<const TQMimeSource*>(r);
+ QStringList::Iterator it;
+ if (abs_name[0] == QLatin1Char('/')
+#ifdef Q_WS_WIN
+ || (abs_name[0].isLetter() && abs_name[1] == QLatin1Char(':')) || abs_name.startsWith(QLatin1String("\\\\"))
+#endif
+ )
+ {
+ // handle absolute file names directly
+ r = dataInternal(abs_name, d->extensions);
+ }
+ else { // check list of paths
+ for (it = d->path.begin(); !r && it != d->path.end(); ++it) {
+ QString filename = *it;
+ if (filename[(int)filename.length()-1] != QLatin1Char('/'))
+ filename += QLatin1Char('/');
+ filename += abs_name;
+ r = dataInternal(filename, d->extensions);
+ }
+ }
+
+ static bool looping = false;
+ if (!r && this == defaultFactory()) {
+ // we found no mime-source and we are the default factory, so
+ // we know all the other installed mime-source factories, so
+ // ask them
+ if (!looping) {
+ // to avoid endless recustions, don't enter the loop below
+ // if data() got called from within the loop below
+ looping = true;
+ for (int i = 0; i < d->factories.size(); ++i) {
+ const TQMimeSourceFactory *f = d->factories.at(i);
+ if (f == this)
+ continue;
+ r = static_cast<const QMimeSource *>(f->data(abs_name));
+ if (r) {
+ looping = false;
+ return static_cast<const TQMimeSource*>(r);
+ }
+ }
+ looping = false;
+ }
+ } else if (!r) {
+ // we are not the default mime-source factory, so ask the
+ // default one for the mime-source, as this one will loop over
+ // all installed mime-source factories and ask these
+ r = static_cast<const QMimeSource *>(defaultFactory()->data(abs_name));
+ }
+ return static_cast<const TQMimeSource*>(r);
+}
+
+/*!
+ \fn void TQMimeSourceFactory::setFilePath(const QStringList &path)
+ \fn void TQMimeSourceFactory::setFilePath(const QString &path)
+
+ Sets the list of directories that will be searched when named data
+ is requested to those given in the string list \a path.
+
+ \sa filePath()
+*/
+void TQMimeSourceFactory::setFilePath(const QStringList& path)
+{
+ d->path = path;
+}
+
+/*!
+ Returns the currently set search paths.
+*/
+TQStringList TQMimeSourceFactory::filePath() const
+{
+ return TQT_TQSTRINGLIST_OBJECT(d->path);
+}
+
+/*!
+ Adds another search path, \a p to the existing search paths.
+
+ \sa setFilePath()
+*/
+void TQMimeSourceFactory::addFilePath(const QString& p)
+{
+ d->path += p;
+}
+
+/*!
+ Sets the mime-type to be associated with the file name extension,
+ \a ext to \a mimetype. This determines the mime-type for files
+ found via the paths set by setFilePath().
+*/
+void TQMimeSourceFactory::setExtensionType(const QString& ext, const char* mimetype)
+{
+ d->extensions.insert(ext, QLatin1String(mimetype));
+}
+
+/*!
+ Converts the absolute or relative data item name \a
+ abs_or_rel_name to an absolute name, interpreted within the
+ context (path) of the data item named \a context (this must be an
+ absolute name).
+*/
+TQString TQMimeSourceFactory::makeAbsolute(const QString& abs_or_rel_name, const QString& context) const
+{
+ if (context.isNull() ||
+ !(context[0] == QLatin1Char('/')
+#ifdef Q_WS_WIN
+ || (context[0].isLetter() && context[1] == QLatin1Char(':'))
+#endif
+ ))
+ return abs_or_rel_name;
+ if (abs_or_rel_name.isEmpty())
+ return context;
+ TQFileInfo c(context);
+ if (!c.isDir()) {
+ TQFileInfo r(c.dir(true), abs_or_rel_name);
+ return r.absFilePath();
+ } else {
+ TQDir d(context);
+ TQFileInfo r(d, abs_or_rel_name);
+ return r.absFilePath();
+ }
+}
+
+/*!
+ \overload
+ A convenience function. See data(const QString& abs_name). The
+ file name is given in \a abs_or_rel_name and the path is in \a
+ context.
+*/
+const TQMimeSource* TQMimeSourceFactory::data(const QString& abs_or_rel_name, const QString& context) const
+{
+ const QMimeSource* r = data(makeAbsolute(abs_or_rel_name,context));
+ if (!r && !d->path.isEmpty())
+ r = data(abs_or_rel_name);
+ return static_cast<const TQMimeSource*>(r);
+}
+
+
+/*!
+ Sets \a text to be the data item associated with the absolute name
+ \a abs_name.
+
+ Equivalent to setData(abs_name, new TQTextDrag(text)).
+*/
+void TQMimeSourceFactory::setText(const QString& abs_name, const QString& text)
+{
+ setData(abs_name, new TQTextDrag(text));
+}
+
+/*!
+ Sets \a image to be the data item associated with the absolute
+ name \a abs_name.
+
+ Equivalent to setData(abs_name, new TQImageDrag(image)).
+*/
+void TQMimeSourceFactory::setImage(const QString& abs_name, const QImage& image)
+{
+ setData(abs_name, new TQImageDrag(image));
+}
+
+/*!
+ Sets \a pixmap to be the data item associated with the absolute
+ name \a abs_name.
+*/
+void TQMimeSourceFactory::setPixmap(const QString& abs_name, const QPixmap& pixmap)
+{
+ setData(abs_name, new TQImageDrag(TQT_TQPIXMAP_OBJECT(pixmap).convertToImage()));
+}
+
+/*!
+ Sets \a data to be the data item associated with
+ the absolute name \a abs_name. Note that the ownership of \a data is
+ transferred to the factory: do not delete or access the pointer after
+ passing it to this function.
+
+ Passing 0 for data removes previously stored data.
+*/
+void TQMimeSourceFactory::setData(const QString& abs_name, QMimeSource* data)
+{
+ if (d->stored.contains(abs_name))
+ delete d->stored[abs_name];
+ d->stored.insert(abs_name,data);
+}
+
+
+/*!
+ Returns the application-wide default mime source factory. This
+ factory is used by rich text rendering classes such as
+ QSimpleRichText, QWhatsThis and QMessageBox to resolve named
+ references within rich text documents. It serves also as the
+ initial factory for the more complex render widgets, QTextEdit and
+ QTextBrowser.
+
+ \sa setDefaultFactory()
+*/
+TQMimeSourceFactory* TQMimeSourceFactory::defaultFactory()
+{
+ if (!defaultfactory)
+ {
+ defaultfactory = new TQMimeSourceFactory();
+ qmime_cleanup_factory.set(&defaultfactory);
+ QTextImageHandler::externalLoader = richTextImageLoader;
+ }
+ return defaultfactory;
+}
+
+/*!
+ Sets the default \a factory, destroying any previously set mime
+ source provider. The ownership of the factory is transferred to
+ Qt.
+
+ \sa defaultFactory()
+*/
+void TQMimeSourceFactory::setDefaultFactory(TQMimeSourceFactory* factory)
+{
+ if (!defaultfactory)
+ qmime_cleanup_factory.set(&defaultfactory);
+ else if (defaultfactory != factory)
+ delete defaultfactory;
+ defaultfactory = factory;
+}
+
+/*!
+ Sets the defaultFactory() to 0 and returns the previous one.
+*/
+
+TQMimeSourceFactory* TQMimeSourceFactory::takeDefaultFactory()
+{
+ TQMimeSourceFactory *f = defaultfactory;
+ defaultfactory = 0;
+ return f;
+}
+
+/*!
+ Adds the TQMimeSourceFactory \a f to the list of available
+ mimesource factories. If the defaultFactory() can't resolve a
+ data() it iterates over the list of installed mimesource factories
+ until the data can be resolved.
+
+ \sa removeFactory()
+*/
+
+void TQMimeSourceFactory::addFactory(TQMimeSourceFactory *f)
+{
+ TQMimeSourceFactory::defaultFactory()->d->factories.append(f);
+}
+
+/*!
+ Removes the mimesource factory \a f from the list of available
+ mimesource factories.
+
+ \sa addFactory()
+*/
+
+void TQMimeSourceFactory::removeFactory(TQMimeSourceFactory *f)
+{
+ TQMimeSourceFactory::defaultFactory()->d->factories.removeAll(f);
+}
+
+QPixmap qPixmapFromMimeSource(const QString &abs_name)
+{
+ const TQMimeSource *m = TQT_TQMIMESOURCE_CONST(TQMimeSourceFactory::defaultFactory()->data(abs_name));
+ if (!m) {
+ if (QFile::exists(abs_name))
+ return QPixmap(abs_name);
+ if (!abs_name.isEmpty())
+ qWarning("QPixmap::fromMimeSource: Cannot find pixmap \"%s\" in the mime source factory",
+ TQT_TQSTRING(abs_name).latin1());
+ return QPixmap();
+ }
+ QPixmap pix;
+ TQImageDrag::decode(m, pix);
+ return pix;
+}
+
+QImage qImageFromMimeSource(const QString &abs_name)
+{
+ const TQMimeSource *m = TQT_TQMIMESOURCE_CONST(TQMimeSourceFactory::defaultFactory()->data(abs_name));
+ if (!m) {
+ qWarning("QImage::fromMimeSource: Cannot find image \"%s\" in the mime source factory", TQT_TQSTRING(abs_name).latin1());
+ return QImage();
+ }
+ QImage img;
+ TQImageDrag::decode(m, img);
+ return img;
+}
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/*!
+ \fn const char * TQMimeSource::format(int i) const
+
+ Returns the \a{i}-th supported MIME format, or 0.
+*/
+
+
+
+class TQMimeSourceFactoryData {
+public:
+ TQMimeSourceFactoryData() :
+ last(0)
+ {
+ }
+
+ ~TQMimeSourceFactoryData()
+ {
+ TQMap<TQString, TQMimeSource*>::Iterator it = stored.begin();
+ while ( it != stored.end() ) {
+ delete *it;
+ ++it;
+ }
+ delete last;
+ }
+
+ TQMap<TQString, TQMimeSource*> stored;
+ TQMap<TQString, TQString> extensions;
+ TQStringList path;
+ TQMimeSource* last;
+ TQPtrList<TQMimeSourceFactory> factories;
+};
+
+/*!
+ \class TQMimeSourceFactory tqmime.h
+ \brief The TQMimeSourceFactory class is an extensible provider of mime-typed data.
+
+ \ingroup io
+ \ingroup environment
+
+ A TQMimeSourceFactory provides an abstract interface to a
+ collection of information. Each piece of information is
+ represented by a TQMimeSource object which can be examined and
+ converted to concrete data types by functions such as
+ TQImageDrag::canDecode() and TQImageDrag::decode().
+
+ The base TQMimeSourceFactory can be used in two ways: as an
+ abstraction of a collection of files or as specifically stored
+ data. For it to access files, call setFilePath() before accessing
+ data. For stored data, call setData() for each item (there are
+ also convenience functions, e.g. setText(), setImage() and
+ setPixmap(), that simply call setData() with appropriate
+ parameters).
+
+ The rich text widgets, TQTextEdit and TQTextBrowser, use
+ TQMimeSourceFactory to resolve references such as images or links
+ within rich text documents. They either access the default factory
+ (see \l{defaultFactory()}) or their own (see
+ \l{TQTextEdit::setMimeSourceFactory()}). Other classes that are
+ capable of displaying rich text (such as TQLabel, TQWhatsThis or
+ TQMessageBox) always use the default factory.
+
+ A factory can also be used as a container to store data associated
+ with a name. This technique is useful whenever rich text tqcontains
+ images that are stored in the program itself, not loaded from the
+ hard disk. Your program may, for example, define some image data
+ as:
+ \code
+ static const char* myimage_data[]={
+ "...",
+ ...
+ "..."};
+ \endcode
+
+ To be able to use this image within some rich text, for example
+ inside a TQLabel, you must create a TQImage from the raw data and
+ insert it into the factory with a unique name:
+ \code
+ TQMimeSourceFactory::defaultFactory()->setImage( "myimage", TQImage(myimage_data) );
+ \endcode
+
+ Now you can create a rich text TQLabel with
+
+ \code
+ TQLabel* label = new TQLabel(
+ "Rich text with embedded image:<img source=\"myimage\">"
+ "Isn't that <em>cute</em>?" );
+ \endcode
+
+ When no longer needed, you can clear the data from the factory:
+
+ \code
+ delete label;
+ TQMimeSourceFactory::defaultFactory()->setData( "myimage", 0 );
+ \endcode
+*/
+
+
+/*!
+ Constructs a TQMimeSourceFactory that has no file path and no
+ stored content.
+*/
+TQMimeSourceFactory::TQMimeSourceFactory() :
+ d(new TQMimeSourceFactoryData)
+{
+ // add some reasonable defaults
+ setExtensionType("htm", "text/html;charset=iso8859-1");
+ setExtensionType("html", "text/html;charset=iso8859-1");
+ setExtensionType("txt", "text/plain");
+ setExtensionType("xml", "text/xml;charset=UTF-8");
+ setExtensionType("jpg", "image/jpeg"); // support misspelled jpeg files
+}
+
+/*!
+ Destroys the TQMimeSourceFactory, deleting all stored content.
+*/
+TQMimeSourceFactory::~TQMimeSourceFactory()
+{
+ if ( defaultFactory() == this )
+ defaultfactory = 0;
+ delete d;
+}
+
+TQMimeSource* TQMimeSourceFactory::dataInternal(const TQString& abs_name, const TQMap<TQString, TQString> &extensions ) const
+{
+ TQMimeSource* r = 0;
+ TQFileInfo fi(abs_name);
+ if ( fi.isReadable() ) {
+
+ // get the right mimetype
+ TQString e = fi.extension(FALSE);
+ TQCString mimetype = "application/octet-stream";
+ const char* imgfmt;
+ if ( extensions.tqcontains(e) )
+ mimetype = extensions[e].latin1();
+ else if ( ( imgfmt = TQImage::imageFormat( abs_name ) ) )
+ mimetype = TQCString("image/")+TQCString(imgfmt).lower();
+
+ TQFile f(abs_name);
+ if ( f.open(IO_ReadOnly) && f.size() ) {
+ TQByteArray ba(f.size());
+ f.readBlock(ba.data(), ba.size());
+ TQStoredDrag* sr = new TQStoredDrag( mimetype );
+ sr->setEncodedData( ba );
+ delete d->last;
+ d->last = r = sr;
+ }
+ }
+
+ // we didn't tqfind the mime-source, so ask the default factory for
+ // the mime-source (this one will iterate over all installed ones)
+ //
+ // this looks dangerous, as this dataInternal() function will be
+ // called again when the default factory loops over all installed
+ // factories (including this), but the static bool looping in
+ // data() avoids endless recursions
+ if ( !r && this != defaultFactory() )
+ r = (TQMimeSource*)defaultFactory()->data( abs_name );
+
+ return r;
+}
+
+
+/*!
+ Returns a reference to the data associated with \a abs_name. The
+ return value remains valid only until the next data() or setData()
+ call, so you should immediately decode the result.
+
+ If there is no data associated with \a abs_name in the factory's
+ store, the factory tries to access the local filesystem. If \a
+ abs_name isn't an absolute file name, the factory will search for
+ it in all defined paths (see \l{setFilePath()}).
+
+ The factory understands all the image formats supported by
+ TQImageIO. Any other mime types are determined by the file name
+ extension. The default settings are
+ \code
+ setExtensionType("html", "text/html;charset=iso8859-1");
+ setExtensionType("htm", "text/html;charset=iso8859-1");
+ setExtensionType("txt", "text/plain");
+ setExtensionType("xml", "text/xml;charset=UTF-8");
+ \endcode
+ The effect of these is that file names ending in "txt" will be
+ treated as text encoded in the local encoding; those ending in
+ "xml" will be treated as text encoded in Unicode UTF-8 encoding.
+ The text/html type is treated specially, since the encoding can be
+ specified in the html file itself. "html" or "htm" will be treated
+ as text encoded in the encoding specified by the html meta tag, if
+ none could be found, the charset of the mime type will be used.
+ The text subtype ("html", "plain", or "xml") does not affect the
+ factory, but users of the factory may behave differently. We
+ recommend creating "xml" files where practical. These files can be
+ viewed regardless of the runtime encoding and can encode any
+ Unicode characters without resorting to encoding definitions
+ inside the file.
+
+ Any file data that is not recognized will be retrieved as a
+ TQMimeSource providing the "application/octet-stream" mime type,
+ meaning uninterpreted binary data.
+
+ You can add further extensions or change existing ones with
+ subsequent calls to setExtensionType(). If the extension mechanism
+ is not sufficient for your problem domain, you can inherit
+ TQMimeSourceFactory and reimplement this function to perform some
+ more specialized mime-type detection. The same applies if you want
+ to use the mime source factory to access URL referenced data over
+ a network.
+*/
+const TQMimeSource* TQMimeSourceFactory::data(const TQString& abs_name) const
+{
+ if ( d->stored.tqcontains(abs_name) )
+ return d->stored[abs_name];
+
+ TQMimeSource* r = 0;
+ TQStringList::Iterator it;
+ if ( abs_name[0] == '/'
+#ifdef TQ_WS_WIN
+ || ( abs_name[0] && abs_name[1] == ':' ) || abs_name.startsWith("\\\\")
+#endif
+ )
+ {
+ // handle absolute file names directly
+ r = dataInternal( abs_name, d->extensions);
+ }
+ else { // check list of paths
+ for ( it = d->path.begin(); !r && it != d->path.end(); ++it ) {
+ TQString filename = *it;
+ if ( filename[(int)filename.length()-1] != '/' )
+ filename += '/';
+ filename += abs_name;
+ r = dataInternal( filename, d->extensions );
+ }
+ }
+
+ static bool looping = FALSE;
+ if ( !r && this == defaultFactory() ) {
+ // we found no mime-source and we are the default factory, so
+ // we know all the other installed mime-source factories, so
+ // ask them
+ if ( !looping ) {
+ // to avoid endless recursions, don't enter the loop below
+ // if data() got called from within the loop below
+ looping = TRUE;
+ TQPtrListIterator<TQMimeSourceFactory> it( d->factories );
+ TQMimeSourceFactory *f;
+ while ( ( f = it.current() ) ) {
+ ++it;
+ if ( f == this )
+ continue;
+ r = (TQMimeSource*)f->data( abs_name );
+ if ( r ) {
+ looping = FALSE;
+ return r;
+ }
+ }
+ looping = FALSE;
+ }
+ } else if ( !r ) {
+ // we are not the default mime-source factory, so ask the
+ // default one for the mime-source, as this one will loop over
+ // all installed mime-source factories and ask these
+ r = (TQMimeSource*)defaultFactory()->data( abs_name );
+ }
+
+ return r;
+}
+
+/*!
+ Sets the list of directories that will be searched when named data
+ is requested to the those given in the string list \a path.
+
+ \sa filePath()
+*/
+void TQMimeSourceFactory::setFilePath( const TQStringList& path )
+{
+ d->path = path;
+}
+
+/*!
+ Returns the currently set search paths.
+*/
+TQStringList TQMimeSourceFactory::filePath() const
+{
+ return d->path;
+}
+
+/*!
+ Adds another search path, \a p to the existing search paths.
+
+ \sa setFilePath()
+*/
+void TQMimeSourceFactory::addFilePath( const TQString& p )
+{
+ d->path += p;
+}
+
+/*!
+ Sets the mime-type to be associated with the file name extension,
+ \a ext to \a mimetype. This determines the mime-type for files
+ found via the paths set by setFilePath().
+*/
+void TQMimeSourceFactory::setExtensionType( const TQString& ext, const char* mimetype )
+{
+ d->extensions.tqreplace(ext, mimetype);
+}
+
+/*!
+ Converts the absolute or relative data item name \a
+ abs_or_rel_name to an absolute name, interpreted within the
+ context (path) of the data item named \a context (this must be an
+ absolute name).
+*/
+TQString TQMimeSourceFactory::makeAbsolute(const TQString& abs_or_rel_name, const TQString& context) const
+{
+ if ( context.isNull() ||
+ !(context[0] == '/'
+#ifdef TQ_WS_WIN
+ || ( context[0] && context[1] == ':')
+#endif
+ ))
+ return abs_or_rel_name;
+ if ( abs_or_rel_name.isEmpty() )
+ return context;
+ TQFileInfo c( context );
+ if (!c.isDir()) {
+ TQFileInfo r( c.dir(TRUE), abs_or_rel_name );
+ return r.absFilePath();
+ } else {
+ TQDir d(context);
+ TQFileInfo r(d, abs_or_rel_name);
+ return r.absFilePath();
+ }
+}
+
+/*!
+ \overload
+ A convenience function. See data(const TQString& abs_name). The
+ file name is given in \a abs_or_rel_name and the path is in \a
+ context.
+*/
+const TQMimeSource* TQMimeSourceFactory::data(const TQString& abs_or_rel_name, const TQString& context) const
+{
+ const TQMimeSource* r = data(makeAbsolute(abs_or_rel_name,context));
+ if ( !r && !d->path.isEmpty() )
+ r = data(abs_or_rel_name);
+ return r;
+}
+
+
+/*!
+ Sets \a text to be the data item associated with the absolute name
+ \a abs_name.
+
+ Equivalent to setData(abs_name, new TQTextDrag(text)).
+*/
+void TQMimeSourceFactory::setText( const TQString& abs_name, const TQString& text )
+{
+ setData(abs_name, new TQTextDrag(text));
+}
+
+/*!
+ Sets \a image to be the data item associated with the absolute
+ name \a abs_name.
+
+ Equivalent to setData(abs_name, new TQImageDrag(image)).
+*/
+void TQMimeSourceFactory::setImage( const TQString& abs_name, const TQImage& image )
+{
+ setData(abs_name, new TQImageDrag(image));
+}
+
+/*!
+ Sets \a pixmap to be the data item associated with the absolute
+ name \a abs_name.
+*/
+void TQMimeSourceFactory::setPixmap( const TQString& abs_name, const TQPixmap& pixmap )
+{
+ setData(abs_name, new TQImageDrag(pixmap.convertToImage()));
+}
+
+/*!
+ Sets \a data to be the data item associated with
+ the absolute name \a abs_name. Note that the ownership of \a data is
+ transferred to the factory: do not delete or access the pointer after
+ passing it to this function.
+
+ Passing 0 for data removes previously stored data.
+*/
+void TQMimeSourceFactory::setData( const TQString& abs_name, TQMimeSource* data )
+{
+ if ( d->stored.tqcontains(abs_name) )
+ delete d->stored[abs_name];
+ d->stored.tqreplace(abs_name,data);
+}
+
+
+/*!
+ Returns the application-wide default mime source factory. This
+ factory is used by rich text rendering classes such as
+ TQSimpleRichText, TQWhatsThis and TQMessageBox to resolve named
+ references within rich text documents. It serves also as the
+ initial factory for the more complex render widgets, TQTextEdit and
+ TQTextBrowser.
+
+ \sa setDefaultFactory()
+*/
+TQMimeSourceFactory* TQMimeSourceFactory::defaultFactory()
+{
+ if (!defaultfactory)
+ {
+ defaultfactory = new TQMimeSourceFactory();
+ qmime_cleanup_factory.set( &defaultfactory );
+ }
+ return defaultfactory;
+}
+
+/*!
+ Sets the default \a factory, destroying any previously set mime
+ source provider. The ownership of the factory is transferred to
+ TQt.
+
+ \sa defaultFactory()
+*/
+void TQMimeSourceFactory::setDefaultFactory( TQMimeSourceFactory* factory)
+{
+ if ( !defaultfactory )
+ qmime_cleanup_factory.set( &defaultfactory );
+ else if ( defaultfactory != factory )
+ delete defaultfactory;
+ defaultfactory = factory;
+}
+
+/*!
+ Sets the defaultFactory() to 0 and returns the previous one.
+*/
+
+TQMimeSourceFactory* TQMimeSourceFactory::takeDefaultFactory()
+{
+ TQMimeSourceFactory *f = defaultfactory;
+ defaultfactory = 0;
+ return f;
+}
+
+/*!
+ Adds the TQMimeSourceFactory \a f to the list of available
+ mimesource factories. If the defaultFactory() can't resolve a
+ data() it iterates over the list of installed mimesource factories
+ until the data can be resolved.
+
+ \sa removeFactory();
+*/
+
+void TQMimeSourceFactory::addFactory( TQMimeSourceFactory *f )
+{
+ TQMimeSourceFactory::defaultFactory()->d->factories.append( f );
+}
+
+/*!
+ Removes the mimesource factory \a f from the list of available
+ mimesource factories.
+
+ \sa addFactory();
+*/
+
+void TQMimeSourceFactory::removeFactory( TQMimeSourceFactory *f )
+{
+ TQMimeSourceFactory::defaultFactory()->d->factories.removeRef( f );
+}
+
+#endif // USE_QT4
+
+#endif // TQT_NO_MIME
diff --git a/tqtinterface/qt4/src/kernel/tqmime.h b/tqtinterface/qt4/src/kernel/tqmime.h
new file mode 100644
index 0000000..b683f48
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmime.h
@@ -0,0 +1,312 @@
+/****************************************************************************
+**
+** Definition of mime classes
+**
+** Created : 981204
+**
+** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQMIME_H
+#define TQMIME_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqmap.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qmime.h>
+#include <QtGui/qwindowdefs.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qmap.h>
+#include <QtGui/qpixmap.h>
+
+#endif // USE_QT4
+
+#ifndef TQT_NO_MIME
+
+#ifdef USE_QT4
+// #if 0
+
+class TQ_EXPORT TQMimeSource : public QMimeSource, virtual public TQt
+{
+ friend class TQClipboardData;
+
+public:
+ TQMimeSource();
+
+ virtual TQByteArray tqencodedData( const char* ) const = 0;
+ inline QByteArray encodedData( const char *ch ) const { return tqencodedData(ch); } // Qt4 connection
+ inline int serialNumber() const { return ser_no; }
+
+private:
+ int ser_no;
+ enum { NoCache, Text, Graphics } cacheType;
+ union
+ {
+ struct
+ {
+ TQString *str;
+ TQCString *subtype;
+ } txt;
+ struct
+ {
+ TQImage *img;
+ TQPixmap *pix;
+ } gfx;
+ } cache;
+ void clearCache();
+
+ // friends for caching
+ friend class TQImageDrag;
+ friend class TQTextDrag;
+};
+
+#else // USE_QT4
+
+class TQImageDrag;
+class TQTextDrag;
+
+class TQ_EXPORT TQMimeSource
+{
+ friend class TQClipboardData;
+
+public:
+ TQMimeSource();
+ virtual ~TQMimeSource();
+ virtual const char* format( int n = 0 ) const = 0;
+ virtual bool provides( const char* ) const;
+ virtual TQByteArray tqencodedData( const char* ) const = 0;
+ int serialNumber() const;
+
+private:
+ int ser_no;
+ enum { NoCache, Text, Graphics } cacheType;
+ union
+ {
+ struct
+ {
+ TQString *str;
+ TQCString *subtype;
+ } txt;
+ struct
+ {
+ TQImage *img;
+ TQPixmap *pix;
+ } gfx;
+ } cache;
+ void clearCache();
+
+ // friends for caching
+ friend class TQImageDrag;
+ friend class TQTextDrag;
+
+};
+
+inline int TQMimeSource::serialNumber() const
+{ return ser_no; }
+
+#endif // USE_QT4
+
+class TQStringList;
+class TQMimeSourceFactoryData;
+
+// NOTE:
+// For an unknown reason the Qt3Support TQMimeSourceFactory will not work with embedded text images (s/a Trinity Desktop's ktip application)
+// Do not reactivate this Qt3Support code until that problem is fixed!
+
+// #ifdef USE_QT4
+#if 0
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Qt3SupportLight)
+
+#ifndef QT_NO_MIMEFACTORY
+
+class QStringList;
+class QMimeSource;
+class TQMimeSourceFactoryData;
+
+class Q_COMPAT_EXPORT TQMimeSourceFactory {
+public:
+ TQMimeSourceFactory();
+ virtual ~TQMimeSourceFactory();
+
+ static TQMimeSourceFactory* defaultFactory();
+ static void setDefaultFactory(TQMimeSourceFactory*);
+ static TQMimeSourceFactory* takeDefaultFactory();
+ static void addFactory(TQMimeSourceFactory *f);
+ static void removeFactory(TQMimeSourceFactory *f);
+
+ virtual const TQMimeSource* data(const QString& abs_name) const;
+ virtual TQString makeAbsolute(const QString& abs_or_rel_name, const QString& context) const;
+ const TQMimeSource* data(const QString& abs_or_rel_name, const QString& context) const;
+
+ virtual void setText(const QString& abs_name, const QString& text);
+ virtual void setImage(const QString& abs_name, const QImage& im);
+ virtual void setPixmap(const QString& abs_name, const QPixmap& pm);
+ virtual void setData(const QString& abs_name, QMimeSource* data);
+ virtual void setFilePath(const QStringList&);
+ inline void setFilePath(const QString &path) { setFilePath(QStringList(path)); }
+ virtual TQStringList filePath() const;
+ void addFilePath(const QString&);
+ virtual void setExtensionType(const QString& ext, const char* mimetype);
+
+private:
+ QMimeSource *dataInternal(const QString& abs_name, const QMap<QString, QString> &extensions) const;
+ TQMimeSourceFactoryData* d;
+};
+
+Q_COMPAT_EXPORT QPixmap qPixmapFromMimeSource(const QString &abs_name);
+
+Q_COMPAT_EXPORT QImage qImageFromMimeSource(const QString &abs_name);
+
+#endif // QT_NO_MIMEFACTORY
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+class TQ_EXPORT TQMimeSourceFactory {
+public:
+ TQMimeSourceFactory();
+ virtual ~TQMimeSourceFactory();
+
+ static TQMimeSourceFactory* defaultFactory();
+ static void setDefaultFactory( TQMimeSourceFactory* );
+ static TQMimeSourceFactory* takeDefaultFactory();
+ static void addFactory( TQMimeSourceFactory *f );
+ static void removeFactory( TQMimeSourceFactory *f );
+
+ virtual const TQMimeSource* data(const TQString& abs_name) const;
+ virtual TQString makeAbsolute(const TQString& abs_or_rel_name, const TQString& context) const;
+ const TQMimeSource* data(const TQString& abs_or_rel_name, const TQString& context) const;
+
+ virtual void setText( const TQString& abs_name, const TQString& text );
+ virtual void setImage( const TQString& abs_name, const TQImage& im );
+ virtual void setPixmap( const TQString& abs_name, const TQPixmap& pm );
+ virtual void setData( const TQString& abs_name, TQMimeSource* data );
+ virtual void setFilePath( const TQStringList& );
+ virtual TQStringList filePath() const;
+ void addFilePath( const TQString& );
+ virtual void setExtensionType( const TQString& ext, const char* mimetype );
+
+private:
+ TQMimeSource *dataInternal(const TQString& abs_name, const TQMap<TQString, TQString> &extensions ) const;
+ TQMimeSourceFactoryData* d;
+};
+
+#endif // USE_QT4
+
+#if defined(TQ_WS_WIN)
+
+#ifndef TQT_H
+#include "tqptrlist.h" // down here for GCC 2.7.* compatibility
+#endif // TQT_H
+
+/*
+ Encapsulation of conversion between MIME and Windows CLIPFORMAT.
+ Not need on X11, as the underlying protocol uses the MIME standard
+ directly.
+*/
+
+class TQ_EXPORT TQWindowsMime {
+public:
+ TQWindowsMime();
+ virtual ~TQWindowsMime();
+
+ static void initialize();
+
+ static TQPtrList<TQWindowsMime> all();
+ static TQWindowsMime* convertor( const char* mime, int cf );
+ static const char* cfToMime(int cf);
+
+ static int registerMimeType(const char *mime);
+
+ virtual const char* convertorName()=0;
+ virtual int countCf()=0;
+ virtual int cf(int index)=0;
+ virtual bool canConvert( const char* mime, int cf )=0;
+ virtual const char* mimeFor(int cf)=0;
+ virtual int cfFor(const char* )=0;
+ virtual TQByteArray convertToMime( TQByteArray data, const char* mime, int cf )=0;
+ virtual TQByteArray convertFromMime( TQByteArray data, const char* mime, int cf )=0;
+};
+
+#endif
+#if defined(TQ_WS_MAC)
+
+#ifndef TQT_H
+#include "tqptrlist.h" // down here for GCC 2.7.* compatibility
+#endif // TQT_H
+
+/*
+ Encapsulation of conversion between MIME and Mac flavor.
+ Not need on X11, as the underlying protocol uses the MIME standard
+ directly.
+*/
+
+class TQ_EXPORT TQMacMime {
+ char type;
+public:
+ enum TQMacMimeType { MIME_DND=0x01, MIME_CLIP=0x02, MIME_TQT_CONVERTOR=0x04, MIME_ALL=MIME_DND|MIME_CLIP };
+ TQMacMime(char);
+ virtual ~TQMacMime();
+
+ static void initialize();
+
+ static TQPtrList<TQMacMime> all(TQMacMimeType);
+ static TQMacMime* convertor(TQMacMimeType, const char* mime, int flav);
+ static const char* flavorToMime(TQMacMimeType, int flav);
+
+ virtual const char* convertorName()=0;
+ virtual int countFlavors()=0;
+ virtual int flavor(int index)=0;
+ virtual bool canConvert(const char* mime, int flav)=0;
+ virtual const char* mimeFor(int flav)=0;
+ virtual int flavorFor(const char*)=0;
+ virtual TQByteArray convertToMime(TQValueList<TQByteArray> data, const char* mime, int flav)=0;
+ virtual TQValueList<TQByteArray> convertFromMime(TQByteArray data, const char* mime, int flav)=0;
+};
+
+#endif // TQ_WS_MAC
+
+#endif // TQT_NO_MIME
+
+#endif // TQMIME_H
diff --git a/tqtinterface/qt4/src/kernel/tqmngio.cpp b/tqtinterface/qt4/src/kernel/tqmngio.cpp
new file mode 100644
index 0000000..250fda1
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmngio.cpp
@@ -0,0 +1,464 @@
+/****************************************************************************
+**
+** Implementation of MNG TQImage IOHandler
+**
+** Created : 970521
+**
+** Copyright (C) 1997-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQT_CLEAN_NAMESPACE
+#define TQT_CLEAN_NAMESPACE
+#endif
+
+#include "tqdatetime.h"
+
+#ifndef TQT_NO_IMAGEIO_MNG
+
+#include "tqimage.h"
+#include "tqasyncimageio.h"
+#include "tqiodevice.h"
+#include "tqmngio.h"
+
+// Define XMD_H prohibits the included headers of libmng.h to typedef INT32.
+// This is needed for Borland with STL support, since in that case, INT32 is
+// already defined by some Borland header.
+#define XMD_H
+#if defined(TQ_OS_UNIXWARE)
+# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this
+#endif
+#include <libmng.h>
+#include <stdlib.h>
+
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+
+class TQMNGFormat : public TQImageFormat {
+public:
+ TQMNGFormat();
+ virtual ~TQMNGFormat();
+
+ int decode(TQImage& img, TQImageConsumer* consumer,
+ const uchar* buffer, int length);
+
+ bool openstream()
+ {
+ // ### We should figure out how many loops an MNG has, but for now always assume infinite.
+ if (consumer)
+ consumer->setLooping(0);
+ return TRUE;
+ }
+ bool closestream( )
+ {
+ if (consumer)
+ consumer->end();
+ return TRUE;
+ }
+ bool readdata( mng_ptr pBuf, mng_uint32 iBuflen, mng_uint32p pRead )
+ {
+ uint m = ndata + nbuffer - ubuffer;
+ if ( iBuflen > m ) {
+ iBuflen = m;
+ }
+ *pRead = iBuflen;
+ uint n = nbuffer-ubuffer;
+ if ( iBuflen < n ) {
+ // enough in buffer
+ memcpy(pBuf, buffer+ubuffer, iBuflen);
+ ubuffer += iBuflen;
+ return TRUE;
+ }
+ if ( n ) {
+ // consume buffer
+ memcpy(pBuf, buffer+ubuffer, n );
+ pBuf = (mng_ptr)((char*)pBuf + n);
+ iBuflen -= n;
+ ubuffer = nbuffer;
+ }
+ if ( iBuflen ) {
+ // fill from incoming data
+ memcpy(pBuf, data, iBuflen);
+ data += iBuflen;
+ ndata -= iBuflen;
+ }
+ return TRUE;
+ }
+ bool errorproc( mng_int32 iErrorcode,
+ mng_int8 /*iSeverity*/,
+ mng_chunkid iChunkname,
+ mng_uint32 /*iChunkseq*/,
+ mng_int32 iExtra1,
+ mng_int32 iExtra2,
+ mng_pchar zErrortext )
+ {
+ qWarning("MNG error %d: %s; chunk %c%c%c%c; subcode %d:%d",
+ iErrorcode, zErrortext ? zErrortext : "",
+ (iChunkname>>24)&0xff,
+ (iChunkname>>16)&0xff,
+ (iChunkname>>8)&0xff,
+ (iChunkname>>0)&0xff,
+ iExtra1,iExtra2);
+ return TRUE;
+ }
+ bool processheader( mng_uint32 iWidth, mng_uint32 iHeight )
+ {
+ image->create(iWidth,iHeight,32);
+ image->setAlphaBuffer(TRUE);
+ memset(image->bits(),0,iWidth*iHeight*4);
+ consumer->setSize(iWidth,iHeight);
+ mng_set_canvasstyle(handle,
+ TQImage::systemByteOrder() == TQImage::LittleEndian
+ ? MNG_CANVAS_BGRA8 : MNG_CANVAS_ARGB8 );
+ return TRUE;
+ }
+ mng_ptr getcanvasline( mng_uint32 iLinenr )
+ {
+ return image->scanLine(iLinenr);
+ }
+ mng_bool refresh( mng_uint32 x, mng_uint32 y, mng_uint32 w, mng_uint32 h )
+ {
+ TQRect r(x,y,w,h);
+ consumer->changed(r);
+ consumer->setFramePeriod(0);
+ consumer->frameDone();
+ return TRUE;
+ }
+ mng_uint32 gettickcount( )
+ {
+ return timer.elapsed() - losttime;
+ }
+ bool settimer( mng_uint32 iMsecs )
+ {
+ consumer->setFramePeriod(iMsecs);
+ consumer->frameDone();
+ state = Time;
+ losingtimer.start();
+ losttime -= iMsecs;
+ return TRUE;
+ }
+
+private:
+ // Animation-level information
+ enum { MovieStart, Time, Data, Data2 } state;
+
+ // Image-level information
+ mng_handle handle;
+
+ // For storing unused data
+ uchar *buffer;
+ uint maxbuffer;
+ uint nbuffer;
+
+ // Timing
+ TQTime timer;
+ TQTime losingtimer;
+ int losttime;
+
+ void enlargeBuffer(uint n)
+ {
+ if ( n > maxbuffer ) {
+ maxbuffer = n;
+ buffer = (uchar*)realloc(buffer,n);
+ }
+ }
+
+ // Temporary locals during single data-chunk processing
+ const uchar* data;
+ uint ndata;
+ uint ubuffer;
+ TQImageConsumer* consumer;
+ TQImage* image;
+};
+
+class TQMNGFormatType : public TQImageFormatType
+{
+ TQImageFormat* decoderFor(const uchar* buffer, int length);
+ const char* formatName() const;
+};
+
+
+/*
+ \class TQMNGFormat tqmngio.h
+ \brief Incremental image decoder for MNG image format.
+
+ \ingroup images
+ \ingroup graphics
+
+ This subclass of TQImageFormat decodes MNG format images,
+ including animated MNGs.
+
+ Animated MNG images are standard MNG images. The MNG standard
+ defines two extension chunks that are useful for animations:
+
+ <dl>
+ <dt>gIFg - GIF-like Graphic Control Extension
+ <dd>Includes frame disposal, user input flag (we ignore this),
+ and inter-frame delay.
+ <dt>gIFx - GIF-like Application Extension
+ <dd>Multi-purpose, but we just use the Netscape extension
+ which specifies looping.
+ </dl>
+
+ The subimages usually contain a offset chunk (oFFs) but need not.
+
+ The first image defines the "screen" size. Any subsequent image that
+ doesn't fit is clipped.
+
+TODO: decide on this point. gIFg gives disposal types, so it can be done.
+ All images paste (\e not composite, just place all-channel copying)
+ over the previous image to produce a subsequent frame.
+*/
+
+/*
+ \class TQMNGFormatType tqasyncimageio.h
+ \brief Incremental image decoder for MNG image format.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup io
+
+ This subclass of TQImageFormatType recognizes MNG
+ format images, creating a TQMNGFormat when required. An instance
+ of this class is created automatically before any other factories,
+ so you should have no need for such objects.
+*/
+
+TQImageFormat* TQMNGFormatType::decoderFor( const uchar* buffer, int length )
+{
+ if (length < 8) return 0;
+
+ if (buffer[0]==138 // MNG signature
+ && buffer[1]=='M'
+ && buffer[2]=='N'
+ && buffer[3]=='G'
+ && buffer[4]==13
+ && buffer[5]==10
+ && buffer[6]==26
+ && buffer[7]==10
+ || buffer[0]==139 // JNG signature
+ && buffer[1]=='J'
+ && buffer[2]=='N'
+ && buffer[3]=='G'
+ && buffer[4]==13
+ && buffer[5]==10
+ && buffer[6]==26
+ && buffer[7]==10
+#ifdef TQT_NO_IMAGEIO_PNG // if we don't have native PNG support use libmng
+ || buffer[0]==137 // PNG signature
+ && buffer[1]=='P'
+ && buffer[2]=='N'
+ && buffer[3]=='G'
+ && buffer[4]==13
+ && buffer[5]==10
+ && buffer[6]==26
+ && buffer[7]==10
+#endif
+ )
+ return new TQMNGFormat;
+ return 0;
+}
+
+const char* TQMNGFormatType::formatName() const
+{
+ return "MNG";
+}
+
+
+/*!
+ Constructs a TQMNGFormat.
+*/
+TQMNGFormat::TQMNGFormat()
+{
+ state = MovieStart;
+ handle = 0;
+ nbuffer = 0;
+ maxbuffer = 0;
+ buffer = 0;
+ losttime = 0;
+}
+
+/*
+ Destroys a TQMNGFormat.
+*/
+TQMNGFormat::~TQMNGFormat()
+{
+ // We're setting the consumer to 0 since it may have been
+ // deleted by read_async_image in qimage.cpp
+ consumer = 0;
+ if (handle) mng_cleanup(&handle);
+}
+
+
+// C-callback to C++-member-function conversion
+//
+static mng_bool openstream( mng_handle handle )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->openstream();
+}
+static mng_bool closestream( mng_handle handle )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->closestream();
+}
+static mng_bool readdata( mng_handle handle, mng_ptr pBuf, mng_uint32 iBuflen, mng_uint32p pRead )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->readdata(pBuf,iBuflen,pRead);
+}
+static mng_bool errorproc( mng_handle handle,
+ mng_int32 iErrorcode,
+ mng_int8 iSeverity,
+ mng_chunkid iChunkname,
+ mng_uint32 iChunkseq,
+ mng_int32 iExtra1,
+ mng_int32 iExtra2,
+ mng_pchar zErrortext )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->errorproc(iErrorcode,
+ iSeverity,iChunkname,iChunkseq,iExtra1,iExtra2,zErrortext);
+}
+static mng_bool processheader( mng_handle handle,
+ mng_uint32 iWidth, mng_uint32 iHeight )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->processheader(iWidth,iHeight);
+}
+static mng_ptr getcanvasline( mng_handle handle, mng_uint32 iLinenr )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->getcanvasline(iLinenr);
+}
+static mng_bool refresh( mng_handle handle,
+ mng_uint32 iTop,
+ mng_uint32 iLeft,
+ mng_uint32 iBottom,
+ mng_uint32 iRight )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->refresh(iTop,iLeft,iBottom,iRight);
+}
+static mng_uint32 gettickcount( mng_handle handle )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->gettickcount();
+}
+static mng_bool settimer( mng_handle handle, mng_uint32 iMsecs )
+{
+ return ((TQMNGFormat*)mng_get_userdata(handle))->settimer(iMsecs);
+}
+
+static mng_ptr memalloc( mng_size_t iLen )
+{
+ return calloc(1,iLen);
+}
+static void memfree( mng_ptr iPtr, mng_size_t /*iLen*/ )
+{
+ free(iPtr);
+}
+
+/*!
+ This function decodes some data into image changes.
+
+ Returns the number of bytes consumed.
+*/
+int TQMNGFormat::decode( TQImage& img, TQImageConsumer* cons,
+ const uchar* buf, int length )
+{
+ consumer = cons;
+ image = &img;
+
+ data = buf;
+ ndata = length;
+ ubuffer = 0;
+
+ if ( state == MovieStart ) {
+ handle = mng_initialize( (mng_ptr)this, ::memalloc, ::memfree, 0 );
+ mng_set_suspensionmode( handle, MNG_TRUE );
+ mng_setcb_openstream( handle, ::openstream );
+ mng_setcb_closestream( handle, ::closestream );
+ mng_setcb_readdata( handle, ::readdata );
+ mng_setcb_errorproc( handle, ::errorproc );
+ mng_setcb_processheader( handle, ::processheader );
+ mng_setcb_getcanvasline( handle, ::getcanvasline );
+ mng_setcb_refresh( handle, ::refresh );
+ mng_setcb_gettickcount( handle, ::gettickcount );
+ mng_setcb_settimer( handle, ::settimer );
+ state = Data;
+ mng_readdisplay(handle);
+ losingtimer.start();
+ }
+
+ losttime += losingtimer.elapsed();
+ if ( ndata || !length )
+ mng_display_resume(handle);
+ losingtimer.start();
+
+ image = 0;
+
+ nbuffer -= ubuffer;
+ if ( nbuffer ) {
+ // Move back unused tail
+ memcpy(buffer,buffer+ubuffer,nbuffer);
+ }
+ if ( ndata ) {
+ // Not all used.
+ enlargeBuffer(nbuffer+ndata);
+ memcpy(buffer+nbuffer,data,ndata);
+ nbuffer += ndata;
+ }
+
+ return length;
+}
+
+static TQMNGFormatType* globalMngFormatTypeObject = 0;
+
+#endif // TQT_NO_ASYNC_IMAGE_IO
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+void qCleanupMngIO()
+{
+ if ( globalMngFormatTypeObject ) {
+ delete globalMngFormatTypeObject;
+ globalMngFormatTypeObject = 0;
+ }
+}
+#endif
+
+void qInitMngIO()
+{
+ static bool done = FALSE;
+ if ( !done ) {
+ done = TRUE;
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ globalMngFormatTypeObject = new TQMNGFormatType;
+ qAddPostRoutine( qCleanupMngIO );
+#endif
+ }
+}
+
+#endif // TQT_NO_IMAGEIO_MNG
diff --git a/tqtinterface/qt4/src/kernel/tqmngio.h b/tqtinterface/qt4/src/kernel/tqmngio.h
new file mode 100644
index 0000000..3467350
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmngio.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Definition of MNG TQImage IOHandler
+**
+** Created : 970521
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQMNGIO_H
+#define TQMNGIO_H
+
+#ifndef TQT_H
+#endif // TQT_H
+
+#ifndef TQT_NO_IMAGEIO_MNG
+
+void qInitMngIO();
+
+#endif // TQT_NO_IMAGEIO_MNG
+
+#endif // TQMNGIO_H
diff --git a/tqtinterface/qt4/src/kernel/tqmotifdnd_x11.cpp b/tqtinterface/qt4/src/kernel/tqmotifdnd_x11.cpp
new file mode 100644
index 0000000..7c17e68
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmotifdnd_x11.cpp
@@ -0,0 +1,978 @@
+/****************************************************************************
+**
+** Implementation of Motif Dynamic Drag and Drop class
+**
+** Created : 950419
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+/* The following copyright notice pertains to the code as contributed
+to Trolltech, not to Trolltech's modifications. It is replicated
+in doc/dnd.doc, where the documentation system can see it. */
+
+/* Copyright 1996 Daniel Dardailler.
+
+ Permission to use, copy, modify, distribute, and sell this software
+ for any purpose is hereby granted without fee, provided that the above
+ copyright notice appear in all copies and that both that copyright
+ notice and this permission notice appear in supporting documentation,
+ and that the name of Daniel Dardailler not be used in advertising or
+ publicity pertaining to distribution of the software without specific,
+ written prior permission. Daniel Dardailler makes no representations
+ about the suitability of this software for any purpose. It is
+ provided "as is" without express or implied warranty.
+
+ Modifications Copyright 1999 Matt Koss, under the same license as
+ above.
+************************************************************/
+
+/***********************************************************/
+/* Motif Drag&Drop Dynamic Protocol messaging API code */
+/* Only requires Xlib layer - not MT safe */
+/* Author: Daniel Dardailler, daniel@x.org */
+/* Adapted by : Matt Koss, koss@napri.sk */
+/* Further adaptions by : Trolltech ASA */
+/***********************************************************/
+
+#include "tqplatformdefs.h"
+
+#include "tqapplication.h"
+
+#ifndef TQT_NO_DRAGANDDROP
+
+#include "tqwidget.h"
+#include "tqt_x11_p.h"
+
+#include <stdlib.h>
+
+
+static Atom atom_message_type, atom_receiver_info, atom_src_property_type;
+static Atom atom_motif_window, atom_target_list ;
+
+static bool in_drop_site = FALSE;
+static Window cur_window = 0;
+static TQWidget *drop_widget = 0L;
+
+static Atom Dnd_transfer_success, Dnd_transfer_failure;
+
+static Atom Dnd_selection;
+static Time Dnd_selection_time;
+
+static Atom * src_targets ;
+static ushort num_src_targets ;
+
+extern bool qt_motifdnd_active;
+
+// this stuff is copied from qclipboard_x11.cpp
+
+extern bool qt_xclb_wait_for_event( Display *dpy, Window win, int type,
+ XEvent *event, int timeout );
+extern bool qt_xclb_read_property( Display *dpy, Window win, Atom property,
+ bool deleteProperty,
+ TQByteArray *buffer, int *size, Atom *type,
+ int *format, bool nullterm );
+
+extern Atom* qt_xdnd_str_to_atom( const char *mimeType );
+extern const char* qt_xdnd_atom_to_str( Atom );
+
+
+// Motif definitions
+#define DndVersion 1
+#define DndRevision 0
+#define DndIncludeVersion (DndVersion * 10 + DndRevision)
+
+/* The following values are used in the DndData structure */
+
+/* protocol style */
+#define DND_DRAG_NONE 0
+#define DND_DRAG_DROP_ONLY 1
+#define DND_DRAG_DYNAMIC 5
+
+/* message type */
+#define DND_TOP_LEVEL_ENTER 0
+#define DND_TOP_LEVEL_LEAVE 1
+#define DND_DRAG_MOTION 2
+#define DND_DROP_SITE_ENTER 3
+#define DND_DROP_SITE_LEAVE 4
+#define DND_DROP_START 5
+#define DND_OPERATION_CHANGED 8
+
+/* operation(s) */
+#define DND_NOOP 0L
+#define DND_MOVE (1L << 0)
+#define DND_COPY (1L << 1)
+#define DND_LINK (1L << 2)
+
+/* status */
+#define DND_NO_DROP_SITE 1
+#define DND_INVALID_DROP_SITE 2
+#define DND_VALID_DROP_SITE 3
+
+/* completion */
+#define DND_DROP 0
+#define DND_DROP_HELP 1
+#define DND_DROP_CANCEL 2
+
+#define BYTE unsigned char
+#define CARD32 unsigned int
+#define CARD16 unsigned short
+#define INT16 signed short
+
+/* Client side structure used in the API */
+typedef struct {
+ unsigned char reason; /* message type: DND_TOP_LEVEL_ENTER, etc */
+ Time time ;
+ unsigned char operation;
+ unsigned char operations;
+ unsigned char status;
+ unsigned char completion;
+ short x ;
+ short y ;
+ Window src_window ;
+ Atom property ;
+} DndData ;
+
+
+typedef struct _DndSrcProp {
+ BYTE byte_order ;
+ BYTE protocol_version ;
+ CARD16 target_index ;
+ CARD32 selection ;
+} DndSrcProp ;
+
+typedef struct _DndReceiverProp {
+ BYTE byte_order ;
+ BYTE protocol_version ;
+ BYTE protocol_style ;
+ BYTE pad1;
+ CARD32 proxy_window;
+ CARD16 num_drop_sites ;
+ CARD16 pad2;
+ CARD32 total_size;
+} DndReceiverProp ;
+
+/* need to use some union hack since window and property are in
+ different order depending on the message ... */
+typedef struct _DndTop {
+ CARD32 src_window;
+ CARD32 property;
+} DndTop ;
+
+typedef struct _DndPot {
+ INT16 x;
+ INT16 y;
+ CARD32 property;
+ CARD32 src_window;
+} DndPot ;
+
+typedef struct _DndMessage {
+ BYTE reason;
+ BYTE byte_order;
+ CARD16 flags;
+ CARD32 time;
+ union {
+ DndTop top ;
+ DndPot pot ;
+ } data ;
+} DndMessage ;
+
+typedef struct {
+ BYTE byte_order;
+ BYTE protocol_version;
+ CARD16 num_target_lists;
+ CARD32 data_size;
+ /* then come series of CARD16,CARD32,CARD32,CARD32... */
+} DndTargets;
+
+
+/* protocol version */
+#define DND_PROTOCOL_VERSION 0
+
+
+#define DND_EVENT_TYPE_MASK ((BYTE)0x80)
+#define DND_EVENT_TYPE_SHIFT 7
+#define DND_CLEAR_EVENT_TYPE ((BYTE)0x7F)
+
+/* message_type is data[0] of the client_message
+ this return 1 (receiver bit up) or 0 (initiator) */
+#define DND_GET_EVENT_TYPE(message_type) \
+((char) (((message_type) & DND_EVENT_TYPE_MASK) >> DND_EVENT_TYPE_SHIFT))
+
+/* event_type can be 0 (initiator) or 1 (receiver) */
+#define DND_SET_EVENT_TYPE(event_type) \
+(((BYTE)(event_type) << DND_EVENT_TYPE_SHIFT) & DND_EVENT_TYPE_MASK)
+
+
+#define DND_OPERATION_MASK ((CARD16) 0x000F)
+#define DND_OPERATION_SHIFT 0
+#define DND_STATUS_MASK ((CARD16) 0x00F0)
+#define DND_STATUS_SHIFT 4
+#define DND_OPERATIONS_MASK ((CARD16) 0x0F00)
+#define DND_OPERATIONS_SHIFT 8
+#define DND_COMPLETION_MASK ((CARD16) 0xF000)
+#define DND_COMPLETION_SHIFT 12
+
+#define DND_GET_OPERATION(flags) \
+((unsigned char) \
+(((flags) & DND_OPERATION_MASK) >> DND_OPERATION_SHIFT))
+
+#define DND_SET_OPERATION(operation) \
+(((CARD16)(operation) << DND_OPERATION_SHIFT)\
+& DND_OPERATION_MASK)
+
+#define DND_GET_STATUS(flags) \
+((unsigned char) \
+(((flags) & DND_STATUS_MASK) >> DND_STATUS_SHIFT))
+
+#define DND_SET_STATUS(status) \
+(((CARD16)(status) << DND_STATUS_SHIFT)\
+& DND_STATUS_MASK)
+
+#define DND_GET_OPERATIONS(flags) \
+((unsigned char) \
+(((flags) & DND_OPERATIONS_MASK) >> DND_OPERATIONS_SHIFT))
+
+#define DND_SET_OPERATIONS(operation) \
+(((CARD16)(operation) << DND_OPERATIONS_SHIFT)\
+& DND_OPERATIONS_MASK)
+
+#define DND_GET_COMPLETION(flags) \
+((unsigned char) \
+(((flags) & DND_COMPLETION_MASK) >> DND_COMPLETION_SHIFT))
+
+#define DND_SET_COMPLETION(completion) \
+(((CARD16)(completion) << DND_COMPLETION_SHIFT)\
+& DND_COMPLETION_MASK)
+
+
+#define SWAP4BYTES(l) {\
+struct { unsigned t :32;} bit32;\
+char n, *tp = (char *) &bit32;\
+bit32.t = l;\
+n = tp[0]; tp[0] = tp[3]; tp[3] = n;\
+n = tp[1]; tp[1] = tp[2]; tp[2] = n;\
+l = bit32.t;\
+}
+
+#define SWAP2BYTES(s) {\
+struct { unsigned t :16; } bit16;\
+char n, *tp = (char *) &bit16;\
+bit16.t = s;\
+n = tp[0]; tp[0] = tp[1]; tp[1] = n;\
+s = bit16.t;\
+}
+
+
+/** Private extern functions */
+
+static unsigned char DndByteOrder ();
+
+
+/***** Targets/Index stuff */
+
+typedef struct {
+ int num_targets;
+ Atom *targets;
+} DndTargetsTableEntryRec, * DndTargetsTableEntry;
+
+typedef struct {
+ int num_entries;
+ DndTargetsTableEntry entries;
+} DndTargetsTableRec, * DndTargetsTable;
+
+
+static int _DndIndexToTargets(Display * display,
+ int index,
+ Atom ** targets);
+
+extern void qt_x11_intern_atom( const char *, Atom * );
+
+/////////////////////////////////////////////////////////////////
+
+void qt_x11_motifdnd_init()
+{
+ /* Init atoms used in the com */
+
+ qt_x11_intern_atom( "_MOTIF_DRAG_AND_DROP_MESSAGE", &atom_message_type );
+ qt_x11_intern_atom( "_MOTIF_DRAG_INITIATOR_INFO", &atom_src_property_type );
+ qt_x11_intern_atom( "_MOTIF_DRAG_RECEIVER_INFO", &atom_receiver_info );
+ qt_x11_intern_atom( "_MOTIF_DRAG_WINDOW", &atom_motif_window );
+ qt_x11_intern_atom( "_MOTIF_DRAG_TARGETS", &atom_target_list );
+
+ qt_x11_intern_atom( "XmTRANSFER_SUCCESS", &Dnd_transfer_success );
+ qt_x11_intern_atom( "XmTRANSFER_FAILURE", &Dnd_transfer_failure );
+
+ char my_dnd_selection_name[30]; // 11-digit number should be enough
+ sprintf(my_dnd_selection_name, "_MY_DND_SELECTION_%d", (int)getpid());
+ qt_x11_intern_atom( my_dnd_selection_name, &Dnd_selection );
+}
+
+static unsigned char DndByteOrder ()
+{
+ static unsigned char byte_order = 0;
+
+ if (!byte_order) {
+ unsigned int endian = 1;
+ byte_order = (*((char *)&endian))?'l':'B';
+ }
+ return byte_order ;
+}
+
+
+
+static void DndReadSourceProperty(Display * dpy,
+ Window window, Atom dnd_selection,
+ Atom ** targets, unsigned short * num_targets)
+{
+ DndSrcProp * src_prop = 0;
+ Atom type ;
+ int format ;
+ unsigned long bytesafter, lengthRtn;
+
+ if ((XGetWindowProperty (dpy, window, dnd_selection, 0L, 100000L,
+ False, atom_src_property_type, &type,
+ &format, &lengthRtn, &bytesafter,
+ (unsigned char **) &src_prop) != Success)
+ || (type == None)) {
+ *num_targets = 0;
+ return ;
+ }
+
+ if (src_prop->byte_order != DndByteOrder()) {
+ SWAP2BYTES(src_prop->target_index);
+ SWAP4BYTES(src_prop->selection);
+ }
+
+ *num_targets = _DndIndexToTargets(dpy, src_prop->target_index, targets);
+
+ XFree((char*)src_prop);
+}
+
+
+/* Position the _MOTIF_DRAG_RECEIVER_INFO property on the dropsite window.
+ Called by the receiver of the drop to indicate the
+ supported protocol style : dynamic, drop_only or none */
+static void DndWriteReceiverProperty(Display * dpy, Window window,
+ unsigned char protocol_style)
+{
+ DndReceiverProp receiver_prop ;
+
+ receiver_prop.byte_order = DndByteOrder() ;
+ receiver_prop.protocol_version = DND_PROTOCOL_VERSION;
+ receiver_prop.protocol_style = protocol_style ;
+ receiver_prop.proxy_window = None ;
+ receiver_prop.num_drop_sites = 0 ;
+ receiver_prop.total_size = sizeof(DndReceiverProp);
+
+ /* write the buffer to the property */
+ XChangeProperty (dpy, window, atom_receiver_info, atom_receiver_info,
+ 8, PropModeReplace,
+ (unsigned char *)&receiver_prop,
+ sizeof(DndReceiverProp));
+}
+
+
+/* protocol style equiv (preregister stuff really) */
+#define DND_DRAG_DROP_ONLY_ETQUIV 3
+#define DND_DRAG_DYNAMIC_ETQUIV1 2
+#define DND_DRAG_DYNAMIC_ETQUIV2 4
+
+
+/* Produce a client message to be sent by the caller */
+static void DndFillClientMessage(Display * dpy, Window window,
+ XClientMessageEvent *cm,
+ DndData * dnd_data,
+ char receiver)
+{
+ DndMessage * dnd_message = (DndMessage*)&cm->data.b[0] ;
+
+ cm->display = dpy;
+ cm->type = ClientMessage;
+ cm->serial = LastKnownRequestProcessed(dpy);
+ cm->send_event = True;
+ cm->window = window;
+ cm->format = 8;
+ cm->message_type = atom_message_type ;/* _MOTIF_DRAG_AND_DROP_MESSAGE */
+
+ dnd_message->reason = dnd_data->reason | DND_SET_EVENT_TYPE(receiver);
+
+ dnd_message->byte_order = DndByteOrder();
+
+ /* we're filling in flags with more stuff that necessary,
+ depending on the reason, but it doesn't matter */
+ dnd_message->flags = 0 ;
+ dnd_message->flags |= DND_SET_STATUS(dnd_data->status) ;
+ dnd_message->flags |= DND_SET_OPERATION(dnd_data->operation) ;
+ dnd_message->flags |= DND_SET_OPERATIONS(dnd_data->operations) ;
+ dnd_message->flags |= DND_SET_COMPLETION(dnd_data->completion) ;
+
+ dnd_message->time = dnd_data->time ;
+
+ switch(dnd_data->reason) {
+ case DND_DROP_SITE_LEAVE: break ;
+ case DND_TOP_LEVEL_ENTER:
+ case DND_TOP_LEVEL_LEAVE:
+ dnd_message->data.top.src_window = dnd_data->src_window ;
+ dnd_message->data.top.property = dnd_data->property ;
+ break ; /* cannot fall thru since the byte tqlayout is different in
+ both set of messages, see top and pot union stuff */
+
+ case DND_DRAG_MOTION:
+ case DND_OPERATION_CHANGED:
+ case DND_DROP_SITE_ENTER:
+ case DND_DROP_START:
+ dnd_message->data.pot.x = dnd_data->x ; /* mouse position */
+ dnd_message->data.pot.y = dnd_data->y ;
+ dnd_message->data.pot.src_window = dnd_data->src_window ;
+ dnd_message->data.pot.property = dnd_data->property ;
+ break ;
+ default:
+ break ;
+ }
+
+}
+
+static Bool DndParseClientMessage(XClientMessageEvent *cm, DndData * dnd_data,
+ char * receiver)
+{
+ DndMessage * dnd_message = (DndMessage*)&cm->data.b[0] ;
+
+ if (cm->message_type != atom_message_type) {
+ return False ;
+ }
+
+ if (dnd_message->byte_order != DndByteOrder()) {
+ SWAP2BYTES(dnd_message->flags);
+ SWAP4BYTES(dnd_message->time);
+ } /* do the rest in the switch */
+
+ dnd_data->reason = dnd_message->reason ;
+ if (DND_GET_EVENT_TYPE(dnd_data->reason))
+ *receiver = 1 ;
+ else
+ *receiver = 0 ;
+ dnd_data->reason &= DND_CLEAR_EVENT_TYPE ;
+
+ dnd_data->time = dnd_message->time ;
+
+ /* we're reading in more stuff that necessary. but who cares */
+ dnd_data->status = DND_GET_STATUS(dnd_message->flags) ;
+ dnd_data->operation = DND_GET_OPERATION(dnd_message->flags) ;
+ dnd_data->operations = DND_GET_OPERATIONS(dnd_message->flags) ;
+ dnd_data->completion = DND_GET_COMPLETION(dnd_message->flags) ;
+
+ switch(dnd_data->reason) {
+ case DND_TOP_LEVEL_ENTER:
+ case DND_TOP_LEVEL_LEAVE:
+ if (dnd_message->byte_order != DndByteOrder()) {
+ SWAP4BYTES(dnd_message->data.top.src_window);
+ SWAP4BYTES(dnd_message->data.top.property);
+ }
+ dnd_data->src_window = dnd_message->data.top.src_window ;
+ dnd_data->property = dnd_message->data.top.property ;
+ break ; /* cannot fall thru, see above comment in write msg */
+
+ case DND_DRAG_MOTION:
+ case DND_OPERATION_CHANGED:
+ case DND_DROP_SITE_ENTER:
+ case DND_DROP_START:
+ if (dnd_message->byte_order != DndByteOrder()) {
+ SWAP2BYTES(dnd_message->data.pot.x);
+ SWAP2BYTES(dnd_message->data.pot.y);
+ SWAP4BYTES(dnd_message->data.pot.property);
+ SWAP4BYTES(dnd_message->data.pot.src_window);
+ }
+ dnd_data->x = dnd_message->data.pot.x ;
+ dnd_data->y = dnd_message->data.pot.y ;
+ dnd_data->property = dnd_message->data.pot.property ;
+ dnd_data->src_window = dnd_message->data.pot.src_window ;
+ break ;
+
+ case DND_DROP_SITE_LEAVE:
+ break;
+ default:
+ break ;
+ }
+
+ return True ;
+}
+
+
+static Window MotifWindow(Display *display )
+{
+ Atom type;
+ int format;
+ unsigned long size;
+ unsigned long bytes_after;
+ Window *property = 0;
+ Window motif_window ;
+
+ /* this version does no caching, so it's slow: round trip each time */
+
+ if ((XGetWindowProperty (display, DefaultRootWindow(display),
+ atom_motif_window,
+ 0L, 100000L, False, AnyPropertyType,
+ &type, &format, &size, &bytes_after,
+ (unsigned char **) &property) == Success) &&
+ (type != None)) {
+ motif_window = *property;
+ } else {
+ XSetWindowAttributes sAttributes;
+
+ /* really, this should be done on a separate connection,
+ with XSetCloseDownMode (RetainPermanent), so that
+ others don't have to recreate it; hopefully, some real
+ Motif application will be around to do it */
+
+ sAttributes.override_redirect = True;
+ sAttributes.event_mask = PropertyChangeMask;
+ motif_window = XCreateWindow (display,
+ DefaultRootWindow (display),
+ -170, -560, 1, 1, 0, 0,
+ InputOnly, CopyFromParent,
+ (CWOverrideRedirect |CWEventMask),
+ &sAttributes);
+ XMapWindow (display, motif_window);
+ }
+
+ if (property) {
+ XFree ((char *)property);
+ }
+
+ return (motif_window);
+}
+
+
+static DndTargetsTable TargetsTable(Display *display)
+{
+ Atom type;
+ int format;
+ unsigned long size;
+ unsigned long bytes_after;
+ Window motif_window = MotifWindow(display) ;
+ DndTargets * target_prop;
+ DndTargetsTable targets_table ;
+ int i,j ;
+ char * target_data ;
+
+ /* this version does no caching, so it's slow: round trip each time */
+ /* ideally, register for property notify on this target_list
+ atom and update when necessary only */
+
+ if ((XGetWindowProperty (display, motif_window,
+ atom_target_list, 0L, 100000L,
+ False, atom_target_list,
+ &type, &format, &size, &bytes_after,
+ (unsigned char **) &target_prop) != Success) ||
+ type == None) {
+ qWarning("TQMotifDND: cannot get property on motif window");
+ return 0;
+ }
+
+ if (target_prop->protocol_version != DND_PROTOCOL_VERSION) {
+ qWarning("TQMotifDND: protocol mismatch");
+ }
+
+ if (target_prop->byte_order != DndByteOrder()) {
+ /* need to swap num_target_lists and size */
+ SWAP2BYTES(target_prop->num_target_lists);
+ SWAP4BYTES(target_prop->data_size);
+ }
+
+ /* now parse DndTarget prop data in a TargetsTable */
+
+ targets_table = (DndTargetsTable)malloc(sizeof(DndTargetsTableRec));
+ targets_table->num_entries = target_prop->num_target_lists ;
+ targets_table->entries = (DndTargetsTableEntry)
+ malloc(sizeof(DndTargetsTableEntryRec) * target_prop->num_target_lists);
+
+ target_data = (char*)target_prop + sizeof(*target_prop) ;
+
+ for (i = 0 ; i < targets_table->num_entries; i++) {
+ CARD16 num_targets ;
+ CARD32 atom ;
+
+ memcpy(&num_targets, target_data, 2);
+ target_data += 2;
+
+ /* potential swap needed here */
+ if (target_prop->byte_order != DndByteOrder())
+ SWAP2BYTES(num_targets);
+
+ targets_table->entries[i].num_targets = num_targets ;
+ targets_table->entries[i].targets = (Atom *)
+ malloc(sizeof(Atom) * targets_table->entries[i].num_targets);
+
+
+ for (j = 0; j < num_targets; j++) {
+ memcpy(&atom, target_data, 4 );
+ target_data += 4;
+
+ /* another potential swap needed here */
+ if (target_prop->byte_order != DndByteOrder())
+ SWAP4BYTES(atom);
+
+ targets_table->entries[i].targets[j] = (Atom) atom ;
+ }
+ }
+
+ if (target_prop) {
+ XFree((char *)target_prop);
+ }
+
+ return targets_table ;
+}
+
+
+static int _DndIndexToTargets(Display * display,
+ int index,
+ Atom ** targets)
+{
+ DndTargetsTable targets_table;
+ int i ;
+
+ /* again, slow: no caching here, alloc/free each time */
+
+ if (!(targets_table = TargetsTable (display)) ||
+ (index >= targets_table->num_entries)) {
+ return -1;
+ }
+
+ /* transfer the correct target list index */
+ *targets = (Atom*)malloc(sizeof(Atom)*targets_table->
+ entries[index].num_targets);
+ memcpy((char*)*targets,
+ (char*)targets_table->entries[index].targets,
+ sizeof(Atom)*targets_table->entries[index].num_targets);
+
+ /* free the target table and its guts */
+ for (i=0 ; i < targets_table->num_entries; i++)
+ XFree((char*)targets_table->entries[i].targets);
+
+ int tmp = targets_table->entries[index].num_targets;
+ XFree((char*)targets_table);
+
+ return tmp; // targets_table->entries[index].num_targets;
+}
+
+
+const char *qt_motifdnd_format( int n )
+{
+ if ( ! qt_motifdnd_active )
+ return 0; // should not happen
+
+ if ( n == 0 )
+ return "text/plain";
+ if ( n == 1 )
+ return "text/uri-list";
+ n -= 2;
+
+ if ( n >= num_src_targets )
+ return 0;
+
+ Atom target = src_targets[n];
+
+ // duplicated from qclipboard_x11.cpp - not the best solution
+ static Atom xa_utf8_string = *qt_xdnd_str_to_atom( "UTF8_STRING" );
+ static Atom xa_text = *qt_xdnd_str_to_atom( "TEXT" );
+ static Atom xa_compound_text = *qt_xdnd_str_to_atom( "COMPOUND_TEXT" );
+
+ if ( target == XA_STRING )
+ return "text/plain;charset=ISO-8859-1";
+ if ( target == xa_utf8_string )
+ return "text/plain;charset=UTF-8";
+ if ( target == xa_text ||
+ target == xa_compound_text )
+ return "text/plain";
+
+ return qt_xdnd_atom_to_str( target );
+}
+
+
+TQByteArray qt_motifdnd_obtain_data( const char *mimeType )
+{
+ TQByteArray result;
+
+ // try to convert the selection to the requested property
+ // qDebug( "trying to convert to '%s'", mimeType );
+
+ int n=0;
+ const char* f;
+ do {
+ f = qt_motifdnd_format( n );
+ if ( !f )
+ return result;
+ n++;
+ } while( qstricmp( mimeType, f ) );
+
+ // found one
+ Atom conversion_type;
+
+ if ( qstrnicmp( f, "text/", 5 ) == 0 ) {
+ // always convert text to XA_STRING for compatibility with
+ // prior TQt versions
+ conversion_type = XA_STRING;
+ } else {
+ conversion_type = *qt_xdnd_str_to_atom( f );
+ // qDebug( "found format '%s' 0x%lx '%s'", f, conversion_type,
+ // qt_xdnd_atom_to_str( conversion_type ) );
+ }
+
+ if ( XGetSelectionOwner( qt_xdisplay(),
+ Dnd_selection ) == None ) {
+ return result; // should never happen?
+ }
+
+ TQWidget* tw = drop_widget;
+ if ( drop_widget->isDesktop() ) {
+ tw = new TQWidget;
+ }
+
+ // convert selection to the appropriate type
+ XConvertSelection (qt_xdisplay(), Dnd_selection, conversion_type,
+ Dnd_selection, tw->winId(), Dnd_selection_time);
+
+ XFlush( qt_xdisplay() );
+
+ XEvent xevent;
+ bool got=qt_xclb_wait_for_event( qt_xdisplay(),
+ tw->winId(),
+ SelectionNotify, &xevent, 5000);
+ if ( got ) {
+ Atom type;
+
+ if ( qt_xclb_read_property( qt_xdisplay(),
+ tw->winId(),
+ Dnd_selection, TRUE,
+ &result, 0, &type, 0, TRUE ) ) {
+ }
+ }
+
+ // we have to convert selection in order to indicate success to the initiator
+ XConvertSelection (qt_xdisplay(), Dnd_selection, Dnd_transfer_success,
+ Dnd_selection, tw->winId(), Dnd_selection_time);
+
+ // wait again for SelectionNotify event
+ qt_xclb_wait_for_event( qt_xdisplay(),
+ tw->winId(),
+ SelectionNotify, &xevent, 5000);
+
+ if ( drop_widget->isDesktop() ) {
+ delete tw;
+ }
+
+ return result;
+}
+
+
+void qt_motifdnd_enable( TQWidget *widget, bool )
+{
+ DndWriteReceiverProperty( widget->x11Display(), widget->winId(),
+ DND_DRAG_DYNAMIC);
+}
+
+
+void qt_motifdnd_handle_msg( TQWidget * /* w */ , const XEvent * xe, bool /* passive */ )
+{
+
+ XEvent event = *xe;
+ XClientMessageEvent cm ;
+ DndData dnd_data ;
+ char receiver ;
+
+ if (!(DndParseClientMessage ((XClientMessageEvent*)&event,
+ &dnd_data, &receiver))) {
+ return;
+ }
+
+ switch ( dnd_data.reason ) {
+
+ case DND_DRAG_MOTION:
+
+ {
+ /* check if in drop site, and depending on the state,
+ send a drop site enter or drop site leave or echo */
+
+ TQPoint p( dnd_data.x, dnd_data.y );
+ TQWidget *c = TQApplication::widgetAt( p, TRUE );
+ if (c)
+ p = c->mapFromGlobal(p);
+
+ while ( c && !c->acceptDrops() && !c->isTopLevel() ) {
+ p = c->mapToParent( p );
+ c = c->parentWidget();
+ }
+
+ TQDragMoveEvent me( p );
+ TQDropEvent::Action accepted_action = TQDropEvent::Copy;
+ me.setAction(accepted_action);
+
+ if ( c != 0L && c->acceptDrops() ) {
+
+ if ( drop_widget != 0L && drop_widget->acceptDrops() &&
+ drop_widget != c ) {
+ TQDragLeaveEvent e;
+ TQApplication::sendEvent( drop_widget, &e );
+ TQDragEnterEvent de( p );
+ TQApplication::sendEvent( c, &de );
+ }
+
+ drop_widget = c;
+
+ if (!in_drop_site) {
+ in_drop_site = True ;
+
+ dnd_data.reason = DND_DROP_SITE_ENTER ;
+ dnd_data.time = CurrentTime ;
+ dnd_data.operation = DND_MOVE|DND_COPY;
+ dnd_data.operations = DND_MOVE|DND_COPY;
+
+ DndFillClientMessage (event.xclient.display,
+ cur_window,
+ &cm, &dnd_data, 0);
+
+ XSendEvent(event.xbutton.display,
+ cur_window, False, 0,
+ (XEvent *)&cm) ;
+
+ TQDragEnterEvent de( p );
+ TQApplication::sendEvent( drop_widget, &de );
+ if ( de.isAccepted() ) {
+ me.accept( de.answerRect() );
+ } else {
+ me.ignore( de.answerRect() );
+ }
+
+ } else {
+ dnd_data.reason = DND_DRAG_MOTION ;
+ dnd_data.time = CurrentTime ;
+ dnd_data.operation = DND_MOVE|DND_COPY;
+ dnd_data.operations = DND_MOVE|DND_COPY;
+
+ DndFillClientMessage (event.xclient.display,
+ cur_window,
+ &cm, &dnd_data, 0);
+
+ XSendEvent(event.xbutton.display,
+ cur_window, False, 0,
+ (XEvent *)&cm) ;
+
+ TQApplication::sendEvent( drop_widget, &me );
+ }
+ } else {
+ if (in_drop_site) {
+ in_drop_site = False ;
+
+ dnd_data.reason = DND_DROP_SITE_LEAVE ;
+ dnd_data.time = CurrentTime ;
+
+ DndFillClientMessage (event.xclient.display,
+ cur_window,
+ &cm, &dnd_data, 0);
+
+ XSendEvent(event.xbutton.display,
+ cur_window, False, 0,
+ (XEvent *)&cm) ;
+
+ TQDragLeaveEvent e;
+ TQApplication::sendEvent( drop_widget, &e );
+ }
+ }
+ }
+ break;
+
+ case DND_TOP_LEVEL_ENTER:
+
+ /* get the size of our drop site for later use */
+
+ cur_window = dnd_data.src_window ;
+ qt_motifdnd_active = TRUE;
+
+ /* no answer needed, just read source property */
+ DndReadSourceProperty (event.xclient.display,
+ cur_window,
+ dnd_data.property,
+ &src_targets, &num_src_targets);
+ break;
+
+ case DND_TOP_LEVEL_LEAVE:
+ /* no need to do anything */
+ break;
+
+ case DND_OPERATION_CHANGED:
+ /* need to echo */
+ break;
+
+ case DND_DROP_START:
+ if (!in_drop_site) {
+ // we have to convert selection in order to indicate failure to the initiator
+ XConvertSelection (qt_xdisplay(), dnd_data.property, Dnd_transfer_failure,
+ dnd_data.property, cur_window, dnd_data.time);
+ TQDragLeaveEvent e;
+ TQApplication::sendEvent( drop_widget, &e );
+ drop_widget = 0;
+ return;
+ }
+
+ /* need to echo and then request a convert */
+ dnd_data.reason = DND_DROP_START ;
+
+ DndFillClientMessage (event.xclient.display,
+ drop_widget->winId(),
+ &cm, &dnd_data, 0);
+
+ XSendEvent(event.xbutton.display,
+ cur_window, False, 0,
+ (XEvent *)&cm) ;
+
+ // store selection and its time
+ Dnd_selection = dnd_data.property;
+ Dnd_selection_time = dnd_data.time;
+
+ TQPoint p( dnd_data.x, dnd_data.y );
+ TQDropEvent de( drop_widget->mapFromGlobal(p) );
+ de.setAction( TQDropEvent::Copy );
+ TQApplication::sendEvent( drop_widget, &de );
+
+ if (in_drop_site)
+ in_drop_site = False ;
+
+ drop_widget = 0;
+ cur_window = 0;
+ break;
+ } // end of switch ( dnd_data.reason )
+}
+
+#endif // TQT_NO_DRAGANDDROP
diff --git a/tqtinterface/qt4/src/kernel/tqmovie.cpp b/tqtinterface/qt4/src/kernel/tqmovie.cpp
new file mode 100644
index 0000000..4b77249
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmovie.cpp
@@ -0,0 +1,1082 @@
+/****************************************************************************
+**
+** Implementation of movie classes
+**
+** Created : 970617
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+// #define TQT_SAVE_MOVIE_HACK
+
+#include "tqtimer.h"
+#include "tqpainter.h"
+#include "tqptrlist.h"
+#include "tqbitmap.h"
+#include "tqmovie.h"
+#include "tqfile.h"
+#include "tqbuffer.h"
+#include "tqobject.h"
+#include "tqpixmapcache.h"
+
+#ifndef TQT_NO_MOVIE
+
+#ifdef TQ_WS_TQWS
+#include "tqgfx_qws.h"
+#endif
+
+#include "tqasyncio.h"
+#include "tqasyncimageio.h"
+
+#include <stdlib.h>
+
+/*!
+ \class TQMovie tqmovie.h
+ \brief The TQMovie class provides incremental loading of animations or images, signalling as it progresses.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup multimedia
+ \mainclass
+
+ The simplest way to display a TQMovie is to use a TQLabel and
+ TQLabel::setMovie().
+
+ A TQMovie provides a TQPixmap as the framePixmap(); connections can
+ be made via connectResize() and connectUpdate() to receive
+ notification of size and pixmap changes. All decoding is driven
+ by the normal event-processing mechanisms.
+
+ The movie begins playing as soon as the TQMovie is created
+ (actually, once control returns to the event loop). When the last
+ frame in the movie has been played, it may loop back to the start
+ if such looping is defined in the input source.
+
+ TQMovie objects are explicitly shared. This means that a TQMovie
+ copied from another TQMovie will be displaying the same frame at
+ all times. If one shared movie pauses, all pause. To make \e
+ independent movies, they must be constructed separately.
+
+ The set of data formats supported by TQMovie is determined by the
+ decoder factories that have been installed; the format of the
+ input is determined as the input is decoded.
+
+ The supported formats are MNG (if TQt is configured with MNG
+ support enabled) and GIF (if TQt is configured with GIF support
+ enabled, see tqgif.h).
+
+ If TQt is configured to support GIF reading, we are required to
+ state that "The Graphics Interchange Format(c) is the Copyright
+ property of CompuServe Incorporated. GIF(sm) is a Service Mark
+ property of CompuServe Incorporated.
+
+ \warning If you are in a country that recognizes software patents
+ and in which Unisys holds a patent on LZW compression and/or
+ decompression and you want to use GIF, Unisys may require you to
+ license that technology. Such countries include Canada, Japan,
+ the USA, France, Germany, Italy and the UK.
+
+ GIF support may be removed completely in a future version of TQt.
+ We recommend using the MNG or PNG format.
+
+ \img qmovie.png TQMovie
+
+ \sa TQLabel::setMovie()
+*/
+
+/*!
+ \enum TQMovie::tqStatus
+
+ \value SourceEmpty
+ \value UnrecognizedFormat
+ \value Paused
+ \value EndOfFrame
+ \value EndOfLoop
+ \value EndOfMovie
+ \value SpeedChanged
+*/
+
+class TQMoviePrivate : public TQObject, public TQShared,
+ private TQDataSink, private TQImageConsumer
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public: // for TQMovie
+
+ // Creates a null Private
+ TQMoviePrivate();
+
+ // NOTE: The ownership of the TQDataSource is transferred to the Private
+ TQMoviePrivate(TQDataSource* src, TQMovie* movie, int bufsize);
+
+ virtual ~TQMoviePrivate();
+
+ bool isNull() const;
+
+ // Initialize, possibly to the null state
+ void init(bool fully);
+ void flushBuffer();
+ void updatePixmapFromImage();
+ void updatePixmapFromImage(const TQPoint& off, const TQRect& area);
+ void showChanges();
+
+ // This as TQImageConsumer
+ void changed(const TQRect& rect);
+ void end();
+ void preFrameDone(); //util func
+ void frameDone();
+ void frameDone(const TQPoint&, const TQRect& rect);
+ void restartTimer();
+ void setLooping(int l);
+ void setFramePeriod(int milliseconds);
+ void setSize(int w, int h);
+
+ // This as TQDataSink
+ int readyToReceive();
+ void receive(const uchar* b, int bytecount);
+ void eof();
+ void pause();
+
+Q_SIGNALS:
+ void sizeChanged(const TQSize&);
+ void areaChanged(const TQRect&);
+ void datatqStatus(int);
+
+public Q_SLOTS:
+ void refresh();
+
+public:
+ TQMovie *that;
+ TQWidget * display_widget;
+
+ TQImageDecoder *decoder;
+
+ // Cyclic buffer
+ int buf_size;
+ uchar *buffer;
+ int buf_r, buf_w, buf_usage;
+
+ int framenumber;
+ int frameperiod;
+ int speed;
+ TQTimer *frametimer;
+ int lasttimerinterval;
+ int loop;
+ bool movie_ended;
+ bool dirty_cache;
+ bool waitingForFrameTick;
+ int stepping;
+ TQRect changed_area;
+ TQRect valid_area;
+ TQDataPump *pump;
+ TQDataSource *source;
+ TQPixmap mypixmap;
+ TQBitmap mytqmask;
+ TQColor bg;
+
+ int error;
+ bool empty;
+
+#ifdef TQT_SAVE_MOVIE_HACK
+ bool save_image;
+ int image_number;
+#endif
+};
+
+
+TQMoviePrivate::TQMoviePrivate()
+{
+ dirty_cache = FALSE;
+ buffer = 0;
+ pump = 0;
+ source = 0;
+ decoder = 0;
+ display_widget=0;
+ buf_size = 0;
+ init(FALSE);
+}
+
+// NOTE: The ownership of the TQDataSource is transferred to the Private
+TQMoviePrivate::TQMoviePrivate(TQDataSource* src, TQMovie* movie, int bufsize) :
+ that(movie),
+ buf_size(bufsize)
+{
+ frametimer = new TQTimer(this);
+ pump = src ? new TQDataPump(src, this) : 0;
+ TQObject::connect(frametimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(refresh()));
+ dirty_cache = FALSE;
+ source = src;
+ buffer = 0;
+ decoder = 0;
+ speed = 100;
+ display_widget=0;
+ init(TRUE);
+}
+
+TQMoviePrivate::~TQMoviePrivate()
+{
+ if ( buffer ) // Avoid purify complaint
+ delete [] buffer;
+ delete pump;
+ delete decoder;
+ delete source;
+
+ // Too bad.. but better be safe than sorry
+ if ( dirty_cache )
+ TQPixmapCache::clear();
+}
+
+bool TQMoviePrivate::isNull() const
+{
+ return !buf_size;
+}
+
+// Initialize. Only actually allocate any space if \a fully is TRUE,
+// otherwise, just enough to be a valid null Private.
+void TQMoviePrivate::init(bool fully)
+{
+#ifdef TQT_SAVE_MOVIE_HACK
+ save_image = TRUE;
+ image_number = 0;
+#endif
+
+ buf_usage = buf_r = buf_w = 0;
+ if ( buffer ) // Avoid purify complaint
+ delete [] buffer;
+ buffer = fully ? new uchar[buf_size] : 0;
+ if ( buffer )
+ memset( buffer, 0, buf_size );
+
+ delete decoder;
+ decoder = fully ? new TQImageDecoder(this) : 0;
+
+#ifdef AVOID_OPEN_FDS
+ if ( source && !source->isOpen() )
+ source->open(IO_ReadOnly);
+#endif
+
+ waitingForFrameTick = FALSE;
+ stepping = -1;
+ framenumber = 0;
+ frameperiod = -1;
+ if (fully) frametimer->stop();
+ lasttimerinterval = -1;
+ changed_area.setRect(0,0,-1,-1);
+ valid_area = changed_area;
+ loop = -1;
+ movie_ended = FALSE;
+ error = 0;
+ empty = TRUE;
+}
+
+void TQMoviePrivate::flushBuffer()
+{
+ int used;
+ while (buf_usage && !waitingForFrameTick && stepping != 0 && !error) {
+ used = decoder->decode(buffer + buf_r, TQMIN(buf_usage, buf_size - buf_r));
+ if (used <= 0) {
+ if ( used < 0 ) {
+ error = 1;
+ emit datatqStatus(TQMovie::UnrecognizedFormat);
+ }
+ break;
+ }
+ buf_r = (buf_r + used) % buf_size;
+ buf_usage -= used;
+ }
+
+ // Some formats, like MNG, can make stuff happen without any extra data.
+ // Only do this if the movie hasn't ended, however or we'll never get the end of loop signal.
+ if (!movie_ended) {
+ used = decoder->decode(buffer + buf_r, 0);
+ if (used <= 0) {
+ if ( used < 0 ) {
+ error = 1;
+ emit datatqStatus(TQMovie::UnrecognizedFormat);
+ }
+ }
+ }
+
+ if (error)
+ frametimer->stop();
+ maybeReady();
+}
+
+void TQMoviePrivate::updatePixmapFromImage()
+{
+ if (changed_area.isEmpty()) return;
+ updatePixmapFromImage(TQPoint(0,0),changed_area);
+}
+
+void TQMoviePrivate::updatePixmapFromImage(const TQPoint& off,
+ const TQRect& area)
+{
+ // Create temporary TQImage to hold the part we want
+ const TQImage& gimg = decoder->image();
+ TQImage img = gimg.copy(area);
+
+#ifdef TQT_SAVE_MOVIE_HACK
+ if ( save_image ) {
+ TQString name;
+ name.sprintf("movie%i.ppm",image_number++);
+ gimg.save( name, "PPM" );
+ }
+#endif
+
+ // Resize to size of image
+ if (mypixmap.width() != gimg.width() || mypixmap.height() != gimg.height())
+ mypixmap.resize(gimg.width(), gimg.height());
+
+ // Convert to pixmap and paste that onto myself
+ TQPixmap lines;
+
+#ifndef TQT_NO_SPRINTF
+ if (!(frameperiod < 0 && loop == -1)) {
+ // its an animation, lets see if we converted
+ // this frame already.
+ TQString key;
+ key.sprintf( "%08lx:%04d", ( long )this, framenumber );
+ if ( !TQPixmapCache::tqfind( key, lines ) ) {
+ lines.convertFromImage(img, TQt::ColorOnly);
+ TQPixmapCache::insert( key, lines );
+ dirty_cache = TRUE;
+ }
+ } else
+#endif
+ {
+ lines.convertFromImage(img, TQt::ColorOnly);
+ }
+
+ if (bg.isValid()) {
+ TQPainter p;
+ p.begin(&mypixmap);
+ p.fillRect(area, bg);
+ p.drawPixmap(area, lines);
+ p.end();
+ } else {
+ if (gimg.hasAlphaBuffer()) {
+ // Resize to size of image
+ if (mytqmask.isNull()) {
+ mytqmask.resize(gimg.width(), gimg.height());
+ mytqmask.fill( TQt::color1 );
+ }
+ }
+ mypixmap.setMask(TQBitmap()); // Remove reference to my tqmask
+ copyBlt( &mypixmap, area.left(), area.top(),
+ &lines, off.x(), off.y(), area.width(), area.height() );
+ }
+
+#ifdef TQ_WS_TQWS
+ if(display_widget) {
+ TQGfx * mygfx=display_widget->graphicsContext();
+ if(mygfx) {
+ double xscale,yscale;
+ xscale=display_widget->width();
+ yscale=display_widget->height();
+ xscale=xscale/((double)mypixmap.width());
+ yscale=yscale/((double)mypixmap.height());
+ double xh,yh;
+ xh=xscale*((double)area.left());
+ yh=yscale*((double)area.top());
+ mygfx->setSource(&mypixmap);
+ mygfx->setAlphaType(TQGfx::IgnoreAlpha);
+ mygfx->stretchBlt(0,0,display_widget->width(),
+ display_widget->height(),mypixmap.width(),
+ mypixmap.height());
+ delete mygfx;
+ }
+ }
+#endif
+}
+
+void TQMoviePrivate::showChanges()
+{
+ if (changed_area.isValid()) {
+ updatePixmapFromImage();
+
+ valid_area = valid_area.unite(changed_area);
+ emit areaChanged(changed_area);
+
+ changed_area.setWidth(-1); // make empty
+ }
+}
+
+// Private as TQImageConsumer
+void TQMoviePrivate::changed(const TQRect& rect)
+{
+ if (!frametimer->isActive())
+ frametimer->start(0);
+ changed_area = changed_area.unite(rect);
+}
+
+void TQMoviePrivate::end()
+{
+ movie_ended = TRUE;
+}
+
+void TQMoviePrivate::preFrameDone()
+{
+ if (stepping > 0) {
+ stepping--;
+ if (!stepping) {
+ frametimer->stop();
+ emit datatqStatus( TQMovie::Paused );
+ }
+ } else {
+ waitingForFrameTick = TRUE;
+ restartTimer();
+ }
+}
+void TQMoviePrivate::frameDone()
+{
+ preFrameDone();
+ showChanges();
+ emit datatqStatus(TQMovie::EndOfFrame);
+ framenumber++;
+}
+void TQMoviePrivate::frameDone(const TQPoint& p,
+ const TQRect& rect)
+{
+ preFrameDone();
+ const TQImage& gimg = decoder->image();
+ TQPoint point = p - gimg.offset();
+ if (framenumber==0)
+ emit sizeChanged(gimg.size());
+ valid_area = valid_area.unite(TQRect(point,rect.size()));
+ updatePixmapFromImage(point,rect);
+ emit areaChanged(TQRect(point,rect.size()));
+ emit datatqStatus(TQMovie::EndOfFrame);
+ framenumber++;
+}
+
+void TQMoviePrivate::restartTimer()
+{
+ if (speed > 0) {
+ int i = frameperiod >= 0 ? frameperiod * 100/speed : 0;
+ if ( i != lasttimerinterval || !frametimer->isActive() ) {
+ lasttimerinterval = i;
+ frametimer->start( i );
+ }
+ } else {
+ frametimer->stop();
+ }
+}
+
+void TQMoviePrivate::setLooping(int nloops)
+{
+ if (loop == -1) { // Only if we don't already know how many loops!
+ if (source && source->rewindable()) {
+ source->enableRewind(TRUE);
+ loop = nloops;
+ } else {
+ // Cannot loop from this source
+ loop = -2;
+ }
+ }
+}
+
+void TQMoviePrivate::setFramePeriod(int milliseconds)
+{
+ // Animation: only show complete frame
+ frameperiod = milliseconds;
+ if (stepping<0 && frameperiod >= 0) restartTimer();
+}
+
+void TQMoviePrivate::setSize(int w, int h)
+{
+ if (mypixmap.width() != w || mypixmap.height() != h) {
+ mypixmap.resize(w, h);
+ emit sizeChanged(TQSize(w, h));
+ }
+}
+
+
+// Private as TQDataSink
+
+int TQMoviePrivate::readyToReceive()
+{
+ // Could pre-fill buffer, but more efficient to just leave the
+ // data back at the source.
+ return (waitingForFrameTick || !stepping || buf_usage || error)
+ ? 0 : buf_size;
+}
+
+void TQMoviePrivate::receive(const uchar* b, int bytecount)
+{
+ if ( bytecount ) empty = FALSE;
+
+ while (bytecount && !waitingForFrameTick && stepping != 0) {
+ int used = decoder->decode(b, bytecount);
+ if (used<=0) {
+ if ( used < 0 ) {
+ error = 1;
+ emit datatqStatus(TQMovie::UnrecognizedFormat);
+ }
+ break;
+ }
+ b+=used;
+ bytecount-=used;
+ }
+
+ // Append unused to buffer
+ while (bytecount--) {
+ buffer[buf_w] = *b++;
+ buf_w = (buf_w+1)%buf_size;
+ buf_usage++;
+ }
+}
+
+void TQMoviePrivate::eof()
+{
+ if ( !movie_ended )
+ return;
+
+ if ( empty )
+ emit datatqStatus(TQMovie::SourceEmpty);
+
+#ifdef TQT_SAVE_MOVIE_HACK
+ save_image = FALSE;
+#endif
+
+ emit datatqStatus(TQMovie::EndOfLoop);
+
+ if (loop >= 0) {
+ if (loop) {
+ loop--;
+ if (!loop) return;
+ }
+ delete decoder;
+ decoder = new TQImageDecoder(this);
+ source->rewind();
+ framenumber = 0;
+ movie_ended = FALSE;
+ } else {
+ delete decoder;
+ decoder = 0;
+ if ( buffer ) // Avoid purify complaint
+ delete [] buffer;
+ buffer = 0;
+ emit datatqStatus(TQMovie::EndOfMovie);
+#ifdef AVOID_OPEN_FDS
+ if ( source )
+ source->close();
+#endif
+ }
+}
+
+void TQMoviePrivate::pause()
+{
+ if ( stepping ) {
+ stepping = 0;
+ frametimer->stop();
+ emit datatqStatus( TQMovie::Paused );
+ }
+}
+
+void TQMoviePrivate::refresh()
+{
+ if (!decoder) {
+ frametimer->stop();
+ return;
+ }
+
+ if (frameperiod < 0 && loop == -1) {
+ // Only show changes if probably not an animation
+ showChanges();
+ }
+
+ if (!buf_usage) {
+ frametimer->stop();
+ }
+
+ waitingForFrameTick = FALSE;
+ flushBuffer();
+}
+
+///////////////// End of Private /////////////////
+
+
+
+
+
+/*!
+ Constructs a null TQMovie. The only interesting thing to do with
+ such a movie is to assign another movie to it.
+
+ \sa isNull()
+*/
+TQMovie::TQMovie()
+{
+ d = new TQMoviePrivate();
+}
+
+/*!
+ Constructs a TQMovie with an external data source. You should later
+ call pushData() to send incoming animation data to the movie.
+
+ The \a bufsize argument sets the maximum amount of data the movie
+ will transfer from the data source per event loop. The lower this
+ value, the better interleaved the movie playback will be with
+ other event processing, but the slower the overall processing will
+ be.
+
+ \sa pushData()
+*/
+TQMovie::TQMovie(int bufsize)
+{
+ d = new TQMoviePrivate(0, this, bufsize);
+}
+
+/*!
+ Returns the maximum amount of data that can currently be pushed
+ into the movie by a call to pushData(). This is affected by the
+ initial buffer size, but varies as the movie plays and data is
+ consumed.
+*/
+int TQMovie::pushSpace() const
+{
+ return d->readyToReceive();
+}
+
+/*!
+ Pushes \a length bytes from \a data into the movie. \a length must
+ be no more than the amount returned by pushSpace() since the
+ previous call to pushData().
+*/
+void TQMovie::pushData(const uchar* data, int length)
+{
+ d->receive(data,length);
+}
+
+#ifdef TQ_WS_TQWS // ##### Temporary performance experiment
+/*!
+ \internal
+*/
+void TQMovie::setDisplayWidget(TQWidget * w)
+{
+ d->display_widget=w;
+}
+#endif
+
+/*!
+ Constructs a TQMovie that reads an image sequence from the given
+ data source, \a src. The source must be allocated dynamically,
+ because TQMovie will take ownership of it and will destroy it when
+ the movie is destroyed. The movie starts playing as soon as event
+ processing continues.
+
+ The \a bufsize argument sets the maximum amount of data the movie
+ will transfer from the data source per event loop. The lower this
+ value, the better interleaved the movie playback will be with
+ other event processing, but the slower the overall processing will
+ be.
+*/
+TQMovie::TQMovie(TQDataSource* src, int bufsize)
+{
+ d = new TQMoviePrivate(src, this, bufsize);
+}
+
+/*!
+ Constructs a TQMovie that reads an image sequence from the file, \a
+ fileName.
+
+ The \a bufsize argument sets the maximum amount of data the movie
+ will transfer from the data source per event loop. The lower this
+ value, the better interleaved the movie playback will be with
+ other event processing, but the slower the overall processing will
+ be.
+*/
+TQMovie::TQMovie(const TQString &fileName, int bufsize)
+{
+ TQFile* file = new TQFile(fileName);
+ if ( !fileName.isEmpty() )
+ file->open(IO_ReadOnly);
+ d = new TQMoviePrivate(new TQIODeviceSource(TQT_TQIODEVICE(file), bufsize), this, bufsize);
+}
+
+/*!
+ Constructs a TQMovie that reads an image sequence from the byte
+ array, \a data.
+
+ The \a bufsize argument sets the maximum amount of data the movie
+ will transfer from the data source per event loop. The lower this
+ value, the better interleaved the movie playback will be with
+ other event processing, but the slower the overall processing will
+ be.
+*/
+TQMovie::TQMovie(TQByteArray data, int bufsize)
+{
+ TQBuffer* buffer = new TQBuffer(data);
+ buffer->open(IO_ReadOnly);
+ d = new TQMoviePrivate(new TQIODeviceSource(TQT_TQIODEVICE(buffer), bufsize), this, bufsize);
+}
+
+/*!
+ Constructs a movie that uses the same data as movie \a movie.
+ TQMovies use explicit sharing, so operations on the copy will
+ affect both.
+*/
+TQMovie::TQMovie(const TQMovie& movie)
+{
+ d = movie.d;
+ d->ref();
+}
+
+/*!
+ Destroys the TQMovie. If this is the last reference to the data of
+ the movie, the data is deallocated.
+*/
+TQMovie::~TQMovie()
+{
+ if (d->deref()) delete d;
+}
+
+/*!
+ Returns TRUE if the movie is null; otherwise returns FALSE.
+*/
+bool TQMovie::isNull() const
+{
+ return d->isNull();
+}
+
+/*!
+ Makes this movie use the same data as movie \a movie. TQMovies use
+ explicit sharing.
+*/
+TQMovie& TQMovie::operator=(const TQMovie& movie)
+{
+ movie.d->ref();
+ if (d->deref()) delete d;
+ d = movie.d;
+ return *this;
+}
+
+
+/*!
+ Sets the background color of the pixmap to \a c. If the background
+ color isValid(), the pixmap will never have a tqmask because the
+ background color will be used in transtqparent regions of the image.
+
+ \sa backgroundColor()
+*/
+void TQMovie::setBackgroundColor(const TQColor& c)
+{
+ d->bg = c;
+}
+
+/*!
+ Returns the background color of the movie set by
+ setBackgroundColor().
+*/
+const TQColor& TQMovie::backgroundColor() const
+{
+ return d->bg;
+}
+
+/*!
+ Returns the area of the pixmap for which pixels have been
+ generated.
+*/
+const TQRect& TQMovie::getValidRect() const
+{
+ return d->valid_area;
+}
+
+/*!
+ Returns the current frame of the movie, as a TQPixmap. It is not
+ generally useful to keep a copy of this pixmap. It is better to
+ keep a copy of the TQMovie and get the framePixmap() only when
+ needed for drawing.
+
+ \sa frameImage()
+*/
+const TQPixmap& TQMovie::framePixmap() const
+{
+ return d->mypixmap;
+}
+
+/*!
+ Returns the current frame of the movie, as a TQImage. It is not
+ generally useful to keep a copy of this image. Also note that you
+ must not call this function if the movie is finished(), since by
+ then the image will not be available.
+
+ \sa framePixmap()
+*/
+const TQImage& TQMovie::frameImage() const
+{
+ return d->decoder->image();
+}
+
+/*!
+ Returns the number of steps remaining after a call to step(). If
+ the movie is paused, steps() returns 0. If it's running normally
+ or is finished, steps() returns a negative number.
+*/
+int TQMovie::steps() const
+{
+ return d->stepping;
+}
+
+/*!
+ Returns the number of times EndOfFrame has been emitted since the
+ start of the current loop of the movie. Thus, before any
+ EndOfFrame has been emitted the value will be 0; within Q_SLOTS
+ processing the first signal, frameNumber() will be 1, and so on.
+*/
+int TQMovie::frameNumber() const { return d->framenumber; }
+
+/*!
+ Returns TRUE if the image is paused; otherwise returns FALSE.
+*/
+bool TQMovie::paused() const
+{
+ return d->stepping == 0;
+}
+
+/*!
+ Returns TRUE if the image is no longer playing: this happens when
+ all loops of all frames are complete; otherwise returns FALSE.
+*/
+bool TQMovie::finished() const
+{
+ return !d->decoder;
+}
+
+/*!
+ Returns TRUE if the image is not single-stepping, not paused, and
+ not finished; otherwise returns FALSE.
+*/
+bool TQMovie::running() const
+{
+ return d->stepping<0 && d->decoder;
+}
+
+/*!
+ Pauses the progress of the animation.
+
+ \sa unpause()
+*/
+void TQMovie::pause()
+{
+ d->pause();
+}
+
+/*!
+ Unpauses the progress of the animation.
+
+ \sa pause()
+*/
+void TQMovie::unpause()
+{
+ if ( d->stepping >= 0 ) {
+ if (d->isNull())
+ return;
+ d->stepping = -1;
+ d->restartTimer();
+ }
+}
+
+/*!
+ \overload
+
+ Steps forward, showing \a steps frames, and then pauses.
+*/
+void TQMovie::step(int steps)
+{
+ if (d->isNull())
+ return;
+ d->stepping = steps;
+ d->frametimer->start(0);
+ d->waitingForFrameTick = FALSE; // Full speed ahead!
+}
+
+/*!
+ Steps forward 1 frame and then pauses.
+*/
+void TQMovie::step()
+{
+ step(1);
+}
+
+/*!
+ Rewinds the movie to the beginning. If the movie has not been
+ paused, it begins playing again.
+*/
+void TQMovie::restart()
+{
+ if (d->isNull())
+ return;
+ if (d->source->rewindable()) {
+ d->source->enableRewind(TRUE);
+ d->source->rewind();
+ int s = d->stepping;
+ d->init(TRUE);
+ if ( s>0 )
+ step(s);
+ else if ( s==0 )
+ pause();
+ }
+}
+
+/*!
+ Returns the movie's play speed as a percentage. The default is 100
+ percent.
+
+ \sa setSpeed()
+*/
+int TQMovie::speed() const
+{
+ return d->speed;
+}
+
+/*!
+ Sets the movie's play speed as a percentage, to \a percent. This
+ is a percentage of the speed dictated by the input data format.
+ The default is 100 percent.
+*/
+void TQMovie::setSpeed(int percent)
+{
+ int oldspeed = d->speed;
+ if ( oldspeed != percent && percent >= 0 ) {
+ d->speed = percent;
+ // Restart timer only if really needed
+ if (d->stepping < 0) {
+ if ( !percent || !oldspeed // To or from zero
+ || oldspeed*4 / percent > 4 // More than 20% slower
+ || percent*4 / oldspeed > 4 // More than 20% faster
+ )
+ d->restartTimer();
+ }
+ }
+}
+
+/*!
+ Connects the \a{receiver}'s \a member of type \c{void member(const
+ TQSize&)} so that it is signalled when the movie changes size.
+
+ Note that due to the explicit sharing of TQMovie objects, these
+ connections persist until they are explicitly disconnected with
+ disconnectResize() or until \e every shared copy of the movie is
+ deleted.
+*/
+void TQMovie::connectResize(TQT_BASE_OBJECT_NAME* receiver, const char *member)
+{
+ TQObject::connect(d, TQT_SIGNAL(sizeChanged(const TQSize&)), TQT_TQOBJECT(receiver), member);
+}
+
+/*!
+ Disconnects the \a{receiver}'s \a member (or all members if \a
+ member is zero) that were previously connected by connectResize().
+*/
+void TQMovie::disconnectResize(TQT_BASE_OBJECT_NAME* receiver, const char *member)
+{
+ TQObject::disconnect(d, TQT_SIGNAL(sizeChanged(const TQSize&)), TQT_TQOBJECT(receiver), member);
+}
+
+/*!
+ Connects the \a{receiver}'s \a member of type \c{void member(const
+ TQRect&)} so that it is signalled when an area of the framePixmap()
+ has changed since the previous frame.
+
+ Note that due to the explicit sharing of TQMovie objects, these
+ connections persist until they are explicitly disconnected with
+ disconnectUpdate() or until \e every shared copy of the movie is
+ deleted.
+*/
+void TQMovie::connectUpdate(TQT_BASE_OBJECT_NAME* receiver, const char *member)
+{
+ TQObject::connect(d, TQT_SIGNAL(areaChanged(const TQRect&)), TQT_TQOBJECT(receiver), member);
+}
+
+/*!
+ Disconnects the \a{receiver}'s \a member (or all members if \q
+ member is zero) that were previously connected by connectUpdate().
+*/
+void TQMovie::disconnectUpdate(TQT_BASE_OBJECT_NAME* receiver, const char *member)
+{
+ TQObject::disconnect(d, TQT_SIGNAL(areaChanged(const TQRect&)), TQT_TQOBJECT(receiver), member);
+}
+
+/*!
+ Connects the \a{receiver}'s \a member, of type \c{void
+ member(int)} so that it is signalled when the movie changes
+ status. The status codes are negative for errors and positive for
+ information.
+
+ \table
+ \header \i tqStatus Code \i Meaning
+ \row \i TQMovie::SourceEmpty
+ \i signalled if the input cannot be read.
+ \row \i TQMovie::UnrecognizedFormat
+ \i signalled if the input data is unrecognized.
+ \row \i TQMovie::Paused
+ \i signalled when the movie is paused by a call to paused()
+ or by after \link step() stepping \endlink pauses.
+ \row \i TQMovie::EndOfFrame
+ \i signalled at end-of-frame after any update and Paused Q_SIGNALS.
+ \row \i TQMovie::EndOfLoop
+ \i signalled at end-of-loop, after any update Q_SIGNALS,
+ EndOfFrame - but before EndOfMovie.
+ \row \i TQMovie::EndOfMovie
+ \i signalled when the movie completes and is not about to loop.
+ \endtable
+
+ More status messages may be added in the future, so a general test
+ for errors would test for negative.
+
+ Note that due to the explicit sharing of TQMovie objects, these
+ connections persist until they are explicitly disconnected with
+ disconnectqStatus() or until \e every shared copy of the movie is
+ deleted.
+*/
+void TQMovie::connectqStatus(TQObject* receiver, const char *member)
+{
+ TQObject::connect(d, TQT_SIGNAL(datatqStatus(int)), receiver, member);
+}
+
+/*!
+ Disconnects the \a{receiver}'s \a member (or all members if \a
+ member is zero) that were previously connected by connectqStatus().
+*/
+void TQMovie::disconnectqStatus(TQObject* receiver, const char *member)
+{
+ TQObject::disconnect(d, TQT_SIGNAL(datatqStatus(int)), receiver, member);
+}
+
+
+#include "tqmovie.tqmoc"
+
+#endif // TQT_NO_MOVIE
diff --git a/tqtinterface/qt4/src/kernel/tqmovie.h b/tqtinterface/qt4/src/kernel/tqmovie.h
new file mode 100644
index 0000000..1c63a5e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqmovie.h
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Definition of movie classes
+**
+** Created : 970617
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQMOVIE_H
+#define TQMOVIE_H
+
+#ifndef TQT_H
+#include "tqpixmap.h" // ### remove or keep for users' convenience?
+#endif // TQT_H
+
+#ifndef TQT_NO_MOVIE
+
+class TQDataSource;
+class TQObject;
+class TQMoviePrivate;
+
+class TQ_EXPORT TQMovie {
+public:
+ TQMovie();
+ TQMovie(int bufsize);
+ TQMovie(TQDataSource*, int bufsize=1024);
+ TQMovie(const TQString &fileName, int bufsize=1024);
+ TQMovie(TQByteArray data, int bufsize=1024);
+ TQMovie(const TQMovie&);
+ ~TQMovie();
+
+ TQMovie& operator=(const TQMovie&);
+
+ int pushSpace() const;
+ void pushData(const uchar* data, int length);
+
+ const TQColor& backgroundColor() const;
+ void setBackgroundColor(const TQColor&);
+
+ const TQRect& getValidRect() const;
+ const TQPixmap& framePixmap() const;
+ const TQImage& frameImage() const;
+
+ bool isNull() const;
+
+ int frameNumber() const;
+ int steps() const;
+ bool paused() const;
+ bool finished() const;
+ bool running() const;
+
+ void unpause();
+ void pause();
+ void step();
+ void step(int);
+ void restart();
+
+ int speed() const;
+ void setSpeed(int);
+
+ void connectResize(TQT_BASE_OBJECT_NAME* receiver, const char *member);
+ void disconnectResize(TQT_BASE_OBJECT_NAME* receiver, const char *member=0);
+
+ void connectUpdate(TQT_BASE_OBJECT_NAME* receiver, const char *member);
+ void disconnectUpdate(TQT_BASE_OBJECT_NAME* receiver, const char *member=0);
+
+#ifdef TQ_WS_TQWS
+ // Temporary hack
+ void setDisplayWidget(TQWidget * w);
+#endif
+
+ enum tqStatus { SourceEmpty=-2,
+ UnrecognizedFormat=-1,
+ Paused=1,
+ EndOfFrame=2,
+ EndOfLoop=3,
+ EndOfMovie=4,
+ SpeedChanged=5 };
+ void connectqStatus(TQObject* receiver, const char *member);
+ void disconnectqStatus(TQObject* receiver, const char *member=0);
+
+ inline void connectStatus(TQObject* receiver, const char *member) { connectqStatus(receiver, member); }
+ inline void disconnectStatus(TQObject* receiver, const char *member=0) { disconnectqStatus(receiver, member); }
+
+private:
+ TQMoviePrivate *d;
+};
+
+#endif // TQT_NO_MOVIE
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqnamespace.h b/tqtinterface/qt4/src/kernel/tqnamespace.h
new file mode 100644
index 0000000..b158936
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqnamespace.h
@@ -0,0 +1,1159 @@
+/****************************************************************************
+**
+** Definition of TQt namespace (as class for compiler compatibility)
+**
+** Created : 980927
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQNAMESPACE_H
+#define TQNAMESPACE_H
+
+#ifndef TQT_H
+#include "tqglobal.h"
+#endif // TQT_H
+
+#include "tqtglobalsettings.h"
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+#include <Qt/qglobal.h>
+#include <Qt/qnamespace.h>
+#include "tqtenuminheritance.h"
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+enum AspectRatioMode {
+ IgnoreAspectRatio,
+ KeepAspectRatio,
+ KeepAspectRatioByExpanding,
+ ScaleFree = IgnoreAspectRatio,
+ ScaleMin = KeepAspectRatio,
+ ScaleMax = KeepAspectRatioByExpanding
+};
+typedef AspectRatioMode ScaleMode;
+
+enum CursorShape {
+ ArrowCursor,
+ UpArrowCursor,
+ CrossCursor,
+ WaitCursor,
+ IBeamCursor,
+ SizeVerCursor,
+ SizeHorCursor,
+ SizeBDiagCursor,
+ SizeFDiagCursor,
+ SizeAllCursor,
+ BlankCursor,
+ SplitVCursor,
+ SplitHCursor,
+ PointingHandCursor,
+ ForbiddenCursor,
+ WhatsThisCursor,
+ BusyCursor,
+ OpenHandCursor,
+ ClosedHandCursor,
+ DragCopyCursor,
+ DragMoveCursor,
+ DragLinkCursor,
+ LastCursor = DragLinkCursor,
+ BitmapCursor = 24,
+ CustomCursor = 25
+};
+
+#endif
+
+class TQColor;
+class TQCursor;
+
+class TQ_EXPORT TQt {
+public:
+ TQT_STATIC_CONST TQColor & color0;
+ TQT_STATIC_CONST TQColor & color1;
+ TQT_STATIC_CONST TQColor & black;
+ TQT_STATIC_CONST TQColor & white;
+ TQT_STATIC_CONST TQColor & darkGray;
+ TQT_STATIC_CONST TQColor & gray;
+ TQT_STATIC_CONST TQColor & lightGray;
+ TQT_STATIC_CONST TQColor & red;
+ TQT_STATIC_CONST TQColor & green;
+ TQT_STATIC_CONST TQColor & blue;
+ TQT_STATIC_CONST TQColor & cyan;
+ TQT_STATIC_CONST TQColor & magenta;
+ TQT_STATIC_CONST TQColor & yellow;
+ TQT_STATIC_CONST TQColor & darkRed;
+ TQT_STATIC_CONST TQColor & darkGreen;
+ TQT_STATIC_CONST TQColor & darkBlue;
+ TQT_STATIC_CONST TQColor & darkCyan;
+ TQT_STATIC_CONST TQColor & darkMagenta;
+ TQT_STATIC_CONST TQColor & darkYellow;
+
+#ifdef USE_QT4
+
+ enum ButtonState_enum {
+ ShiftButton = ((int)Qt::ShiftModifier),
+ ControlButton = ((int)Qt::ControlModifier),
+ AltButton = ((int)Qt::AltModifier),
+ MetaButton = ((int)Qt::MetaModifier),
+ Keypad = ((int)Qt::KeypadModifier),
+ KeyButtonMask = ((int)Qt::KeyboardModifierMask)
+ };
+ typedef int ButtonState;
+
+#else // USE_QT4
+
+ // documented in qevent.cpp
+ enum ButtonState { // mouse/keyboard state values
+ NoButton = 0x0000,
+ LeftButton = 0x0001,
+ RightButton = 0x0002,
+ MidButton = 0x0004,
+ MouseButtonMask = 0x0007,
+ ShiftButton = 0x0100,
+ ControlButton = 0x0200,
+ AltButton = 0x0400,
+ MetaButton = 0x0800,
+ KeyButtonMask = 0x0f00,
+ Keypad = 0x4000
+ };
+
+#endif // USE_QT4
+
+
+#ifdef USE_QT4
+
+typedef Qt::Orientation Orientation;
+
+#else // USE_QT4
+
+ // documented in qobject.cpp
+ // ideally would start at 1, as in TQSizePolicy, but that breaks other things
+ enum Orientation {
+ Horizontal = 0,
+ Vertical
+ };
+
+#endif // USE_QT4
+
+ // documented in qlistview.cpp
+ enum SortOrder {
+ Ascending,
+ Descending
+ };
+
+ // Text formatting flags for TQPainter::drawText and TQLabel
+ // the following four enums can be combined to one integer which
+ // is passed as textflag to drawText and qt_format_text.
+
+ // documented in qpainter.cpp
+
+#ifdef USE_QT4
+ enum AlignmentFlags {
+ AlignAuto = ((int)Qt::AlignLeft), // text tqalignment
+ AlignLeft = ((int)Qt::AlignLeft),
+ AlignRight = ((int)Qt::AlignRight),
+ AlignHCenter = ((int)Qt::AlignHCenter),
+ AlignJustify = ((int)Qt::AlignJustify),
+ AlignAbsolute = ((int)Qt::AlignAbsolute),
+ AlignHorizontal_Mask = AlignLeft | AlignRight | AlignHCenter | AlignJustify | AlignAbsolute,
+ AlignTop = ((int)Qt::AlignTop),
+ AlignBottom = ((int)Qt::AlignBottom),
+ AlignVCenter = ((int)Qt::AlignVCenter),
+ AlignVertical_Mask = AlignTop | AlignBottom | AlignVCenter,
+ AlignCenter = AlignVCenter | AlignHCenter
+ };
+#else // USE_QT4
+ enum AlignmentFlags {
+ AlignAuto = 0x0000, // text tqalignment
+ AlignLeft = 0x0001,
+ AlignRight = 0x0002,
+ AlignHCenter = 0x0004,
+ AlignJustify = 0x0008,
+ AlignHorizontal_Mask = AlignLeft | AlignRight | AlignHCenter | AlignJustify,
+ AlignTop = 0x0010,
+ AlignBottom = 0x0020,
+ AlignVCenter = 0x0040,
+ AlignVertical_Mask = AlignTop | AlignBottom | AlignVCenter,
+ AlignCenter = AlignVCenter | AlignHCenter
+ };
+#endif // USE_QT4
+
+#ifdef USE_QT4
+ enum TextFlags {
+ SingleLine = Qt::TextSingleLine,
+ DontClip = Qt::TextDontClip,
+ ExpandTabs = Qt::TextExpandTabs,
+ ShowPrefix = Qt::TextShowMnemonic,
+ WordBreak = Qt::TextWordWrap,
+ BreakAnywhere = Qt::TextWrapAnywhere,
+#ifndef TQ_TQDOC
+ DontPrint = Qt::TextDontPrint,
+ Underline = 0x01000000,
+ Overline = 0x02000000,
+ StrikeOut = 0x04000000,
+ IncludeTrailingSpaces = Qt::TextIncludeTrailingSpaces,
+#endif
+ NoAccel = 0x4000
+ };
+#else // USE_QT4
+ // documented in qpainter.cpp
+ enum TextFlags {
+ SingleLine = 0x0080, // misc. flags
+ DontClip = 0x0100,
+ ExpandTabs = 0x0200,
+ ShowPrefix = 0x0400,
+ WordBreak = 0x0800,
+ BreakAnywhere = 0x1000,
+#ifndef TQ_TQDOC
+ DontPrint = 0x2000,
+ Underline = 0x01000000,
+ Overline = 0x02000000,
+ StrikeOut = 0x04000000,
+ IncludeTrailingSpaces = 0x08000000,
+#endif
+ NoAccel = 0x4000
+ };
+#endif // USE_QT4
+
+#ifdef USE_QT4
+ typedef Qt::WindowStates WState;
+#else // USE_QT4
+ // Widget flags; documented in qwidget.cpp
+ typedef uint WState;
+#endif // USE_QT4
+
+ // TQWidget state flags (internal, barely documented in qwidget.cpp)
+ enum WidgetState {
+ WState_Created = 0x00000001,
+ WState_Disabled = 0x00000002,
+ WState_Visible = 0x00000004,
+ WState_ForceHide = 0x00000008,
+ WState_OwnCursor = 0x00000010,
+ WState_MouseTracking = 0x00000020,
+ WState_CompressKeys = 0x00000040,
+ WState_BlockUpdates = 0x00000080,
+ WState_InPaintEvent = 0x00000100,
+ WState_Reparented = 0x00000200,
+ WState_ConfigPending = 0x00000400,
+ WState_Resized = 0x00000800,
+ WState_AutoMask = 0x00001000,
+ WState_Polished = 0x00002000,
+ WState_DND = 0x00004000,
+ WState_Reserved0 = 0x00008000,
+ WState_FullScreen = 0x00010000,
+ WState_OwnSizePolicy = 0x00020000,
+ WState_CreatedHidden = 0x00040000,
+ WState_Maximized = 0x00080000,
+ WState_Minimized = 0x00100000,
+ WState_ForceDisabled = 0x00200000,
+ WState_Exposed = 0x00400000,
+ WState_HasMouse = 0x00800000
+ };
+
+// #ifdef USE_QT4
+//
+// typedef Qt::WindowFlags WindowFlags;
+//
+// #else // USE_QT4
+//
+// // Widget flags2; documented in qwidget.cpp
+// typedef uint WFlags;
+//
+// #endif // USE_QT4
+
+// typedef unsigned long long WFlags;
+
+#ifdef USE_QT4
+
+ // documented in qwidget.cpp
+ enum WidgetFlags {
+ WType_TopLevel = ((int)Qt::Window), // widget type flags
+ WType_Dialog = 0x00000002 | WType_TopLevel,
+ WType_Popup = 0x00000008 | WType_TopLevel,
+ WType_Desktop = 0x00000010 | WType_TopLevel,
+ WType_Mask = 0x000000ff,
+
+ WStyle_Customize = 0x00000000, // window style flags
+ WStyle_NormalBorder = 0x00000000,
+ WStyle_DialogBorder = ((int)Qt::MSWindowsFixedSizeDialogHint), // MS-Windows only
+ WStyle_NoBorder = ((int)Qt::FramelessWindowHint),
+ WStyle_Title = ((int)Qt::WindowTitleHint),
+ WStyle_SysMenu = ((int)Qt::WindowSystemMenuHint),
+ WStyle_Minimize = ((int)Qt::WindowMinimizeButtonHint),
+ WStyle_Maximize = ((int)Qt::WindowMaximizeButtonHint),
+ WStyle_MinMax = WStyle_Minimize | WStyle_Maximize,
+// WStyle_Tool = ((int)Qt::Tool), // This is NOT the Qt4 equivalent...using Qt::Tool will cause undocked toolbar handles to stay in the top left corner of the screen
+ WStyle_Tool = ((int)0), // [FIXME] Huh? Why do the toolbars work in Qt4 when Qt::Tool is not set?!?!? [FIXME] [UNDEFINED BEHAVIOUR]
+ WStyle_StaysOnTop = ((int)Qt::WindowStaysOnTopHint),
+ WStyle_ContextHelp = ((int)Qt::WindowContextHelpButtonHint),
+// WStyle_Reserved = 0x00008000,
+ WStyle_Reserved = 0x00000000,
+ WStyle_Mask = 0x0000fff0,
+
+ WDestructiveClose = 0x00100000, // misc flags
+ WPaintDesktop = 0x00000000,
+ WPaintClever = 0x00000000,
+ WStaticContents = 0x00200000,
+
+ WX11BypassWM = ((int)Qt::X11BypassWindowManagerHint),
+ WWinOwnDC = ((int)Qt::MSWindowsOwnDC),
+ WMacNoSheet = 0x00000000,
+ WMacDrawer = ((int)Qt::Drawer),
+
+ WGroupLeader = 0x00400000,
+ WShowModal = 0x00800000,
+ WNoMousePropagation = 0x01000000,
+ WSubWindow = ((int)Qt::SubWindow),
+
+ WStyle_Splash = ((int)Qt::SplashScreen),
+
+ // TQt specific flags
+ WNoAutoErase = 0x0000000100000000ULL,
+ WRepaintNoErase = WNoAutoErase, // OBSOLETE
+ WResizeNoErase = WNoAutoErase, // OBSOLETE
+ WMouseNoMask = 0x0000000200000000ULL,
+ WPaintOnScreen = 0x0000000400000000ULL, // NOTE: This disables Qt4 composition (i.e. transparent windows) to allow fast direct access to the X11 screen. Use with caution!
+ WPaintUnclipped = 0x0000000800000000ULL, // NOTE: This implicitly enables WPaintOnScreen, which disables composition
+ WTQtFlagMask = 0xffffffff00000000ULL
+#ifndef TQT_NO_COMPAT
+ ,
+ WNorthWestGravity = WStaticContents,
+ WType_Modal = WType_Dialog | WShowModal,
+ WStyle_Dialog = WType_Dialog,
+ WStyle_NoBorderEx = WStyle_NoBorder
+#endif
+ };
+
+ typedef unsigned long long WFlags;
+
+#else // USE_QT4
+
+ // documented in qwidget.cpp
+ enum WidgetFlags {
+ WType_TopLevel = 0x00000001, // widget type flags
+ WType_Dialog = 0x00000002,
+ WType_Popup = 0x00000004,
+ WType_Desktop = 0x00000008,
+ WType_Mask = 0x0000000f,
+
+ WStyle_Customize = 0x00000010, // window style flags
+ WStyle_NormalBorder = 0x00000020,
+ WStyle_DialogBorder = 0x00000040, // MS-Windows only
+ WStyle_NoBorder = 0x00002000,
+ WStyle_Title = 0x00000080,
+ WStyle_SysMenu = 0x00000100,
+ WStyle_Minimize = 0x00000200,
+ WStyle_Maximize = 0x00000400,
+ WStyle_MinMax = WStyle_Minimize | WStyle_Maximize,
+ WStyle_Tool = 0x00000800,
+ WStyle_StaysOnTop = 0x00001000,
+ WStyle_ContextHelp = 0x00004000,
+ WStyle_Reserved = 0x00008000,
+ WStyle_Mask = 0x0000fff0,
+
+ WDestructiveClose = 0x00010000, // misc flags
+ WPaintDesktop = 0x00020000,
+ WPaintUnclipped = 0x00040000,
+ WPaintClever = 0x00080000,
+ WResizeNoErase = 0x00100000, // OBSOLETE
+ WMouseNoMask = 0x00200000,
+ WStaticContents = 0x00400000,
+ WRepaintNoErase = 0x00800000, // OBSOLETE
+#if defined(TQ_WS_X11)
+ WX11BypassWM = 0x01000000,
+ WWinOwnDC = 0x00000000,
+ WMacNoSheet = 0x00000000,
+ WMacDrawer = 0x00000000,
+#elif defined(TQ_WS_MAC)
+ WX11BypassWM = 0x00000000,
+ WWinOwnDC = 0x00000000,
+ WMacNoSheet = 0x01000000,
+ WMacDrawer = 0x20000000,
+#else
+ WX11BypassWM = 0x00000000,
+ WWinOwnDC = 0x01000000,
+ WMacNoSheet = 0x00000000,
+ WMacDrawer = 0x00000000,
+#endif
+ WGroupLeader = 0x02000000,
+ WShowModal = 0x04000000,
+ WNoMousePropagation = 0x08000000,
+ WSubWindow = 0x10000000,
+#if defined(TQ_WS_X11)
+ WStyle_Splash = 0x20000000,
+#else
+ WStyle_Splash = WStyle_NoBorder | WMacNoSheet | WStyle_Tool | WWinOwnDC,
+#endif
+ WNoAutoErase = WRepaintNoErase | WResizeNoErase
+#ifndef TQT_NO_COMPAT
+ ,
+ WNorthWestGravity = WStaticContents,
+ WType_Modal = WType_Dialog | WShowModal,
+ WStyle_Dialog = WType_Dialog,
+ WStyle_NoBorderEx = WStyle_NoBorder
+#endif
+ };
+
+#endif // USE_QT4
+
+ enum WindowState {
+ WindowNoState = 0x00000000,
+ WindowMinimized = 0x00000001,
+ WindowMaximized = 0x00000002,
+ WindowFullScreen = 0x00000004,
+ WindowActive = 0x00000008
+ };
+
+
+ // Image conversion flags. The unusual ordering is caused by
+ // compatibility and default requirements.
+ // Documented in qimage.cpp
+
+ enum ImageConversionFlags {
+ ColorMode_Mask = 0x00000003,
+ AutoColor = 0x00000000,
+ ColorOnly = 0x00000003,
+ MonoOnly = 0x00000002,
+ // Reserved = 0x00000001,
+
+ AlphaDither_Mask = 0x0000000c,
+ ThresholdAlphaDither = 0x00000000,
+ OrderedAlphaDither = 0x00000004,
+ DiffuseAlphaDither = 0x00000008,
+ NoAlpha = 0x0000000c, // Not supported
+
+ Dither_Mask = 0x00000030,
+ DiffuseDither = 0x00000000,
+ OrderedDither = 0x00000010,
+ ThresholdDither = 0x00000020,
+ // ReservedDither= 0x00000030,
+
+ DitherMode_Mask = 0x000000c0,
+ AutoDither = 0x00000000,
+ PreferDither = 0x00000040,
+ AvoidDither = 0x00000080
+ };
+
+ // documented in qpainter.cpp
+ enum BGMode { // background mode
+ TransparentMode,
+ OpaqueMode
+ };
+
+#ifdef USE_QT4
+
+ enum PaintUnit { // paint unit
+ PixelUnit,
+ LoMetricUnit, // obsolete
+ HiMetricUnit, // obsolete
+ LoEnglishUnit, // obsolete
+ HiEnglishUnit, // obsolete
+ TwipsUnit // obsolete
+ };
+
+ enum GUIStyle {
+ MacStyle,
+ WindowsStyle,
+ Win3Style,
+ PMStyle,
+ MotifStyle
+ };
+
+#else // USE_QT4
+
+#ifndef TQT_NO_COMPAT
+ // documented in qpainter.cpp
+ enum PaintUnit { // paint unit
+ PixelUnit,
+ LoMetricUnit, // OBSOLETE
+ HiMetricUnit, // OBSOLETE
+ LoEnglishUnit, // OBSOLETE
+ HiEnglishUnit, // OBSOLETE
+ TwipsUnit // OBSOLETE
+ };
+#endif
+
+ // documented in qstyle.cpp
+#ifdef TQT_NO_COMPAT
+ enum GUIStyle {
+ WindowsStyle = 1, // ### TQt 4.0: either remove the obsolete enums or clean up compat vs.
+ MotifStyle = 4 // ### TQT_NO_COMPAT by reordering or combination into one enum.
+ };
+#else
+ enum GUIStyle {
+ MacStyle, // OBSOLETE
+ WindowsStyle,
+ Win3Style, // OBSOLETE
+ PMStyle, // OBSOLETE
+ MotifStyle
+ };
+#endif
+
+#endif // USE_QT4
+
+ // documented in qkeysequence.cpp
+ enum SequenceMatch {
+ NoMatch,
+ PartialMatch,
+ Identical
+ };
+
+#ifdef USE_QT4
+ //shorter names for shortcuts
+ enum Modifier {
+ META = Qt::MetaModifier,
+ SHIFT = Qt::ShiftModifier,
+ CTRL = Qt::ControlModifier,
+ ALT = Qt::AltModifier,
+ MODIFIER_MASK = Qt::KeyboardModifierMask,
+ UNICODE_ACCEL = 0x00000000,
+
+ ASCII_ACCEL = UNICODE_ACCEL // 1.x compat
+ };
+#else // USE_QT4
+ // documented in qevent.cpp
+ enum Modifier { // accelerator modifiers
+ META = 0x00100000,
+ SHIFT = 0x00200000,
+ CTRL = 0x00400000,
+ ALT = 0x00800000,
+ MODIFIER_MASK = 0x00f00000,
+ UNICODE_ACCEL = 0x10000000,
+
+ ASCII_ACCEL = UNICODE_ACCEL // 1.x compat
+ };
+#endif // USE_QT4
+
+ // documented in tqevent.cpp
+ enum Key {
+ Key_Escape = (int)Qt::Key_Escape, // misc keys
+ Key_Tab = (int)Qt::Key_Tab,
+ Key_Backtab = (int)Qt::Key_Backtab, Key_BackTab = Key_Backtab,
+ Key_Backspace = (int)Qt::Key_Backspace, Key_BackSpace = Key_Backspace,
+ Key_Return = (int)Qt::Key_Return,
+ Key_Enter = (int)Qt::Key_Enter,
+ Key_Insert = (int)Qt::Key_Insert,
+ Key_Delete = (int)Qt::Key_Delete,
+ Key_Pause = (int)Qt::Key_Pause,
+ Key_Print = (int)Qt::Key_Print,
+ Key_SysReq = (int)Qt::Key_SysReq,
+ Key_Clear = (int)Qt::Key_Clear,
+ Key_Home = (int)Qt::Key_Home, // cursor movement
+ Key_End = (int)Qt::Key_End,
+ Key_Left = (int)Qt::Key_Left,
+ Key_Up = (int)Qt::Key_Up,
+ Key_Right = (int)Qt::Key_Right,
+ Key_Down = (int)Qt::Key_Down,
+ Key_Prior = (int)Qt::Key_PageUp, Key_PageUp = Key_Prior,
+ Key_Next = (int)Qt::Key_PageDown, Key_PageDown = Key_Next,
+ Key_Shift = (int)Qt::Key_Shift, // modifiers
+ Key_Control = (int)Qt::Key_Control,
+ Key_Meta = (int)Qt::Key_Meta,
+ Key_Alt = (int)Qt::Key_Alt,
+ Key_CapsLock = (int)Qt::Key_CapsLock,
+ Key_NumLock = (int)Qt::Key_NumLock,
+ Key_ScrollLock = (int)Qt::Key_ScrollLock,
+ Key_F1 = (int)Qt::Key_F1, // function keys
+ Key_F2 = (int)Qt::Key_F2,
+ Key_F3 = (int)Qt::Key_F3,
+ Key_F4 = (int)Qt::Key_F4,
+ Key_F5 = (int)Qt::Key_F5,
+ Key_F6 = (int)Qt::Key_F6,
+ Key_F7 = (int)Qt::Key_F7,
+ Key_F8 = (int)Qt::Key_F8,
+ Key_F9 = (int)Qt::Key_F9,
+ Key_F10 = (int)Qt::Key_F10,
+ Key_F11 = (int)Qt::Key_F11,
+ Key_F12 = (int)Qt::Key_F12,
+ Key_F13 = (int)Qt::Key_F13,
+ Key_F14 = (int)Qt::Key_F14,
+ Key_F15 = (int)Qt::Key_F15,
+ Key_F16 = (int)Qt::Key_F16,
+ Key_F17 = (int)Qt::Key_F17,
+ Key_F18 = (int)Qt::Key_F18,
+ Key_F19 = (int)Qt::Key_F19,
+ Key_F20 = (int)Qt::Key_F20,
+ Key_F21 = (int)Qt::Key_F21,
+ Key_F22 = (int)Qt::Key_F22,
+ Key_F23 = (int)Qt::Key_F23,
+ Key_F24 = (int)Qt::Key_F24,
+ Key_F25 = (int)Qt::Key_F25, // F25 .. F35 only on X11
+ Key_F26 = (int)Qt::Key_F26,
+ Key_F27 = (int)Qt::Key_F27,
+ Key_F28 = (int)Qt::Key_F28,
+ Key_F29 = (int)Qt::Key_F29,
+ Key_F30 = (int)Qt::Key_F30,
+ Key_F31 = (int)Qt::Key_F31,
+ Key_F32 = (int)Qt::Key_F32,
+ Key_F33 = (int)Qt::Key_F33,
+ Key_F34 = (int)Qt::Key_F34,
+ Key_F35 = (int)Qt::Key_F35,
+ Key_Super_L = (int)Qt::Key_Super_L, // extra keys
+ Key_Super_R = (int)Qt::Key_Super_R,
+ Key_Menu = (int)Qt::Key_Menu,
+ Key_Hyper_L = (int)Qt::Key_Hyper_L,
+ Key_Hyper_R = (int)Qt::Key_Hyper_R,
+ Key_Help = (int)Qt::Key_Help,
+ Key_Direction_L = (int)Qt::Key_Direction_L,
+ Key_Direction_R = (int)Qt::Key_Direction_R,
+ Key_Space = (int)Qt::Key_Space, // 7 bit printable ASCII
+ Key_Any = Key_Space,
+ Key_Exclam = (int)Qt::Key_Exclam,
+ Key_QuoteDbl = (int)Qt::Key_QuoteDbl,
+ Key_NumberSign = (int)Qt::Key_NumberSign,
+ Key_Dollar = (int)Qt::Key_Dollar,
+ Key_Percent = (int)Qt::Key_Percent,
+ Key_Ampersand = (int)Qt::Key_Ampersand,
+ Key_Apostrophe = (int)Qt::Key_Apostrophe,
+ Key_ParenLeft = (int)Qt::Key_ParenLeft,
+ Key_ParenRight = (int)Qt::Key_ParenRight,
+ Key_Asterisk = (int)Qt::Key_Asterisk,
+ Key_Plus = (int)Qt::Key_Plus,
+ Key_Comma = (int)Qt::Key_Comma,
+ Key_Minus = (int)Qt::Key_Minus,
+ Key_Period = (int)Qt::Key_Period,
+ Key_Slash = (int)Qt::Key_Slash,
+ Key_0 = (int)Qt::Key_0,
+ Key_1 = (int)Qt::Key_1,
+ Key_2 = (int)Qt::Key_2,
+ Key_3 = (int)Qt::Key_3,
+ Key_4 = (int)Qt::Key_4,
+ Key_5 = (int)Qt::Key_5,
+ Key_6 = (int)Qt::Key_6,
+ Key_7 = (int)Qt::Key_7,
+ Key_8 = (int)Qt::Key_8,
+ Key_9 = (int)Qt::Key_9,
+ Key_Colon = (int)Qt::Key_Colon,
+ Key_Semicolon = (int)Qt::Key_Semicolon,
+ Key_Less = (int)Qt::Key_Less,
+ Key_Equal = (int)Qt::Key_Equal,
+ Key_Greater = (int)Qt::Key_Greater,
+ Key_Question = (int)Qt::Key_Question,
+ Key_At = (int)Qt::Key_At,
+ Key_A = (int)Qt::Key_A,
+ Key_B = (int)Qt::Key_B,
+ Key_C = (int)Qt::Key_C,
+ Key_D = (int)Qt::Key_D,
+ Key_E = (int)Qt::Key_E,
+ Key_F = (int)Qt::Key_F,
+ Key_G = (int)Qt::Key_G,
+ Key_H = (int)Qt::Key_H,
+ Key_I = (int)Qt::Key_I,
+ Key_J = (int)Qt::Key_J,
+ Key_K = (int)Qt::Key_K,
+ Key_L = (int)Qt::Key_L,
+ Key_M = (int)Qt::Key_M,
+ Key_N = (int)Qt::Key_N,
+ Key_O = (int)Qt::Key_O,
+ Key_P = (int)Qt::Key_P,
+ Key_Q = (int)Qt::Key_Q,
+ Key_R = (int)Qt::Key_R,
+ Key_S = (int)Qt::Key_S,
+ Key_T = (int)Qt::Key_T,
+ Key_U = (int)Qt::Key_U,
+ Key_V = (int)Qt::Key_V,
+ Key_W = (int)Qt::Key_W,
+ Key_X = (int)Qt::Key_X,
+ Key_Y = (int)Qt::Key_Y,
+ Key_Z = (int)Qt::Key_Z,
+ Key_BracketLeft = (int)Qt::Key_BracketLeft,
+ Key_Backslash = (int)Qt::Key_Backslash,
+ Key_BracketRight = (int)Qt::Key_BracketRight,
+ Key_AsciiCircum = (int)Qt::Key_AsciiCircum,
+ Key_Underscore = (int)Qt::Key_Underscore,
+ Key_QuoteLeft = (int)Qt::Key_QuoteLeft,
+ Key_BraceLeft = (int)Qt::Key_BraceLeft,
+ Key_Bar = (int)Qt::Key_Bar,
+ Key_BraceRight = (int)Qt::Key_BraceRight,
+ Key_AsciiTilde = (int)Qt::Key_AsciiTilde,
+
+ // Latin 1 codes adapted from X: keysymdef.h,v 1.21 94/08/28 16:17:06
+
+ Key_nobreakspace = (int)Qt::Key_nobreakspace,
+ Key_exclamdown = (int)Qt::Key_exclamdown,
+ Key_cent = (int)Qt::Key_cent,
+ Key_sterling = (int)Qt::Key_sterling,
+ Key_currency = (int)Qt::Key_currency,
+ Key_yen = (int)Qt::Key_yen,
+ Key_brokenbar = (int)Qt::Key_brokenbar,
+ Key_section = (int)Qt::Key_section,
+ Key_diaeresis = (int)Qt::Key_diaeresis,
+ Key_copyright = (int)Qt::Key_copyright,
+ Key_ordfeminine = (int)Qt::Key_ordfeminine,
+ Key_guillemotleft = (int)Qt::Key_guillemotleft, // left angle quotation mark
+ Key_notsign = (int)Qt::Key_notsign,
+ Key_hyphen = (int)Qt::Key_hyphen,
+ Key_registered = (int)Qt::Key_registered,
+ Key_macron = (int)Qt::Key_macron,
+ Key_degree = (int)Qt::Key_degree,
+ Key_plusminus = (int)Qt::Key_plusminus,
+ Key_twosuperior = (int)Qt::Key_twosuperior,
+ Key_threesuperior = (int)Qt::Key_threesuperior,
+ Key_acute = (int)Qt::Key_acute,
+ Key_mu = (int)Qt::Key_mu,
+ Key_paragraph = (int)Qt::Key_paragraph,
+ Key_periodcentered = (int)Qt::Key_periodcentered,
+ Key_cedilla = (int)Qt::Key_cedilla,
+ Key_onesuperior = (int)Qt::Key_onesuperior,
+ Key_masculine = (int)Qt::Key_masculine,
+ Key_guillemotright = (int)Qt::Key_guillemotright, // right angle quotation mark
+ Key_onequarter = (int)Qt::Key_onequarter,
+ Key_onehalf = (int)Qt::Key_onehalf,
+ Key_threequarters = (int)Qt::Key_threequarters,
+ Key_questiondown = (int)Qt::Key_questiondown,
+ Key_Agrave = (int)Qt::Key_Agrave,
+ Key_Aacute = (int)Qt::Key_Aacute,
+ Key_Acircumflex = (int)Qt::Key_Acircumflex,
+ Key_Atilde = (int)Qt::Key_Atilde,
+ Key_Adiaeresis = (int)Qt::Key_Adiaeresis,
+ Key_Aring = (int)Qt::Key_Aring,
+ Key_AE = (int)Qt::Key_AE,
+ Key_Ccedilla = (int)Qt::Key_Ccedilla,
+ Key_Egrave = (int)Qt::Key_Egrave,
+ Key_Eacute = (int)Qt::Key_Eacute,
+ Key_Ecircumflex = (int)Qt::Key_Ecircumflex,
+ Key_Ediaeresis = (int)Qt::Key_Ediaeresis,
+ Key_Igrave = (int)Qt::Key_Igrave,
+ Key_Iacute = (int)Qt::Key_Iacute,
+ Key_Icircumflex = (int)Qt::Key_Icircumflex,
+ Key_Idiaeresis = (int)Qt::Key_Idiaeresis,
+ Key_ETH = (int)Qt::Key_ETH,
+ Key_Ntilde = (int)Qt::Key_Ntilde,
+ Key_Ograve = (int)Qt::Key_Ograve,
+ Key_Oacute = (int)Qt::Key_Oacute,
+ Key_Ocircumflex = (int)Qt::Key_Ocircumflex,
+ Key_Otilde = (int)Qt::Key_Otilde,
+ Key_Odiaeresis = (int)Qt::Key_Odiaeresis,
+ Key_multiply = (int)Qt::Key_multiply,
+ Key_Ooblique = (int)Qt::Key_Ooblique,
+ Key_Ugrave = (int)Qt::Key_Ugrave,
+ Key_Uacute = (int)Qt::Key_Uacute,
+ Key_Ucircumflex = (int)Qt::Key_Ucircumflex,
+ Key_Udiaeresis = (int)Qt::Key_Udiaeresis,
+ Key_Yacute = (int)Qt::Key_Yacute,
+ Key_THORN = (int)Qt::Key_THORN,
+ Key_ssharp = (int)Qt::Key_ssharp,
+ Key_agrave = (int)Qt::Key_Agrave,
+ Key_aacute = (int)Qt::Key_Aacute,
+ Key_acircumflex = (int)Qt::Key_Acircumflex,
+ Key_atilde = (int)Qt::Key_Atilde,
+ Key_adiaeresis = (int)Qt::Key_Adiaeresis,
+ Key_aring = (int)Qt::Key_Aring,
+ Key_ae = (int)Qt::Key_AE,
+ Key_ccedilla = (int)Qt::Key_Ccedilla,
+ Key_egrave = (int)Qt::Key_Egrave,
+ Key_eacute = (int)Qt::Key_Eacute,
+ Key_ecircumflex = (int)Qt::Key_Ecircumflex,
+ Key_ediaeresis = (int)Qt::Key_Ediaeresis,
+ Key_igrave = (int)Qt::Key_Igrave,
+ Key_iacute = (int)Qt::Key_Iacute,
+ Key_icircumflex = (int)Qt::Key_Icircumflex,
+ Key_idiaeresis = (int)Qt::Key_Idiaeresis,
+ Key_eth = (int)Qt::Key_ETH ,
+ Key_ntilde = (int)Qt::Key_Ntilde,
+ Key_ograve = (int)Qt::Key_Ograve,
+ Key_oacute = (int)Qt::Key_Oacute,
+ Key_ocircumflex = (int)Qt::Key_Ocircumflex,
+ Key_otilde = (int)Qt::Key_Otilde,
+ Key_odiaeresis = (int)Qt::Key_Odiaeresis,
+ Key_division = (int)Qt::Key_division,
+ Key_oslash = (int)Qt::Key_Ooblique,
+ Key_ugrave = (int)Qt::Key_Ugrave,
+ Key_uacute = (int)Qt::Key_Uacute,
+ Key_ucircumflex = (int)Qt::Key_Ucircumflex,
+ Key_udiaeresis = (int)Qt::Key_Udiaeresis,
+ Key_yacute = (int)Qt::Key_Yacute,
+ Key_thorn = (int)Qt::Key_THORN,
+ Key_ydiaeresis = (int)Qt::Key_ydiaeresis,
+
+ // multimedia/internet keys - ignored by default - see TQKeyEvent c'tor
+
+ Key_Back = (int)Qt::Key_Back,
+ Key_Forward = (int)Qt::Key_Forward,
+ Key_Stop = (int)Qt::Key_Stop,
+ Key_Refresh = (int)Qt::Key_Refresh,
+
+ Key_VolumeDown = (int)Qt::Key_VolumeDown,
+ Key_VolumeMute = (int)Qt::Key_VolumeMute,
+ Key_VolumeUp = (int)Qt::Key_VolumeUp,
+ Key_BassBoost = (int)Qt::Key_BassBoost,
+ Key_BassUp = (int)Qt::Key_BassUp,
+ Key_BassDown = (int)Qt::Key_BassDown,
+ Key_TrebleUp = (int)Qt::Key_TrebleUp,
+ Key_TrebleDown = (int)Qt::Key_TrebleDown,
+
+ Key_MediaPlay = (int)Qt::Key_MediaPlay,
+ Key_MediaStop = (int)Qt::Key_MediaStop,
+ Key_MediaPrev = (int)Qt::Key_MediaPrevious,
+ Key_MediaNext = (int)Qt::Key_MediaNext,
+ Key_MediaRecord = (int)Qt::Key_MediaRecord,
+
+ Key_HomePage = (int)Qt::Key_HomePage,
+ Key_Favorites = (int)Qt::Key_Favorites,
+ Key_Search = (int)Qt::Key_Search,
+ Key_Standby = (int)Qt::Key_Standby,
+ Key_OpenUrl = (int)Qt::Key_OpenUrl,
+
+ Key_LaunchMail = (int)Qt::Key_LaunchMail,
+ Key_LaunchMedia = (int)Qt::Key_LaunchMedia,
+ Key_Launch0 = (int)Qt::Key_Launch0,
+ Key_Launch1 = (int)Qt::Key_Launch1,
+ Key_Launch2 = (int)Qt::Key_Launch2,
+ Key_Launch3 = (int)Qt::Key_Launch3,
+ Key_Launch4 = (int)Qt::Key_Launch4,
+ Key_Launch5 = (int)Qt::Key_Launch5,
+ Key_Launch6 = (int)Qt::Key_Launch6,
+ Key_Launch7 = (int)Qt::Key_Launch7,
+ Key_Launch8 = (int)Qt::Key_Launch8,
+ Key_Launch9 = (int)Qt::Key_Launch9,
+ Key_LaunchA = (int)Qt::Key_LaunchA,
+ Key_LaunchB = (int)Qt::Key_LaunchB,
+ Key_LaunchC = (int)Qt::Key_LaunchC,
+ Key_LaunchD = (int)Qt::Key_LaunchD,
+ Key_LaunchE = (int)Qt::Key_LaunchE,
+ Key_LaunchF = (int)Qt::Key_LaunchF,
+
+ Key_MediaLast = (int)Qt::Key_MediaLast,
+
+ Key_unknown = (int)Qt::Key_unknown
+ };
+
+ // documented in qcommonstyle.cpp
+ enum ArrowType {
+ UpArrow,
+ DownArrow,
+ LeftArrow,
+ RightArrow
+ };
+
+ // documented in qpainter.cpp
+ enum RasterOp { // raster op mode
+ CopyROP,
+ OrROP,
+ XorROP,
+ NotAndROP, EraseROP=NotAndROP,
+ NotCopyROP,
+ NotOrROP,
+ NotXorROP,
+ AndROP, NotEraseROP=AndROP,
+ NotROP,
+ ClearROP,
+ SetROP,
+ NopROP,
+ AndNotROP,
+ OrNotROP,
+ NandROP,
+ NorROP, LastROP=NorROP
+ };
+
+ // documented in qpainter.cpp
+ enum PenStyle { // pen style
+ NoPen,
+ SolidLine,
+ DashLine,
+ DotLine,
+ DashDotLine,
+ DashDotDotLine,
+ MPenStyle = 0x0f
+ };
+
+ // documented in qpainter.cpp
+ enum PenCapStyle { // line endcap style
+ FlatCap = 0x00,
+ SquareCap = 0x10,
+ RoundCap = 0x20,
+ MPenCapStyle = 0x30
+ };
+
+ // documented in qpainter.cpp
+ enum PenJoinStyle { // line join style
+ MiterJoin = 0x00,
+ BevelJoin = 0x40,
+ RoundJoin = 0x80,
+ MPenJoinStyle = 0xc0
+ };
+
+ // documented in qpainter.cpp
+ enum BrushStyle { // brush style
+ NoBrush,
+ SolidPattern,
+ Dense1Pattern,
+ Dense2Pattern,
+ Dense3Pattern,
+ Dense4Pattern,
+ Dense5Pattern,
+ Dense6Pattern,
+ Dense7Pattern,
+ HorPattern,
+ VerPattern,
+ CrossPattern,
+ BDiagPattern,
+ FDiagPattern,
+ DiagCrossPattern,
+ CustomPattern=24
+ };
+
+ // documented in qapplication_mac.cpp
+ enum MacintoshVersion {
+ //Unknown
+ MV_Unknown = 0x0000,
+
+ //Version numbers
+ MV_9 = 0x0001,
+ MV_10_DOT_0 = 0x0002,
+ MV_10_DOT_1 = 0x0003,
+ MV_10_DOT_2 = 0x0004,
+ MV_10_DOT_3 = 0x0005,
+ MV_10_DOT_4 = 0x0006,
+
+ //Code names
+ MV_CHEETAH = MV_10_DOT_0,
+ MV_PUMA = MV_10_DOT_1,
+ MV_JAGUAR = MV_10_DOT_2,
+ MV_PANTHER = MV_10_DOT_3,
+ MV_TIGER = MV_10_DOT_4
+ };
+
+ // documented in qapplication_win.cpp
+ enum WindowsVersion {
+ WV_32s = 0x0001,
+ WV_95 = 0x0002,
+ WV_98 = 0x0003,
+ WV_Me = 0x0004,
+ WV_DOS_based = 0x000f,
+
+ WV_NT = 0x0010,
+ WV_2000 = 0x0020,
+ WV_XP = 0x0030,
+ WV_2003 = 0x0040,
+ WV_VISTA = 0x0080,
+ WV_NT_based = 0x00f0,
+
+ WV_CE = 0x0100,
+ WV_CENET = 0x0200,
+ WV_CE_based = 0x0f00
+ };
+
+ // documented in qstyle.cpp
+ enum UIEffect {
+ UI_General,
+ UI_AnimateMenu,
+ UI_FadeMenu,
+ UI_AnimateCombo,
+ UI_AnimateTooltip,
+ UI_FadeTooltip,
+ UI_AnimateToolBox
+ };
+
+ // documented in qcursor.cpp
+ enum tqCursorShape {
+ ArrowCursor,
+ UpArrowCursor,
+ CrossCursor,
+ WaitCursor,
+ IbeamCursor,
+ SizeVerCursor,
+ SizeHorCursor,
+ SizeBDiagCursor,
+ SizeFDiagCursor,
+ SizeAllCursor,
+ BlankCursor,
+ SplitVCursor,
+ SplitHCursor,
+ PointingHandCursor,
+ ForbiddenCursor,
+ WhatsThisCursor,
+ BusyCursor,
+ LastCursor = BusyCursor,
+ BitmapCursor = 24
+ };
+
+ // Global cursors
+ TQT_STATIC_CONST TQCursor & arrowCursor; // standard arrow cursor
+ TQT_STATIC_CONST TQCursor & upArrowCursor; // upwards arrow
+ TQT_STATIC_CONST TQCursor & crossCursor; // crosshair
+ TQT_STATIC_CONST TQCursor & waitCursor; // hourglass/watch
+ TQT_STATIC_CONST TQCursor & ibeamCursor; // ibeam/text entry
+ TQT_STATIC_CONST TQCursor & sizeVerCursor; // vertical resize
+ TQT_STATIC_CONST TQCursor & sizeHorCursor; // horizontal resize
+ TQT_STATIC_CONST TQCursor & sizeBDiagCursor; // diagonal resize (/)
+ TQT_STATIC_CONST TQCursor & sizeFDiagCursor; // diagonal resize (\)
+ TQT_STATIC_CONST TQCursor & sizeAllCursor; // all directions resize
+ TQT_STATIC_CONST TQCursor & blankCursor; // blank/invisible cursor
+ TQT_STATIC_CONST TQCursor & splitVCursor; // vertical bar with left-right
+ // arrows
+ TQT_STATIC_CONST TQCursor & splitHCursor; // horizontal bar with up-down
+ // arrows
+ TQT_STATIC_CONST TQCursor & pointingHandCursor; // pointing hand
+ TQT_STATIC_CONST TQCursor & forbiddenCursor; // forbidden cursor (slashed circle)
+ TQT_STATIC_CONST TQCursor & whatsThisCursor; // arrow with a question mark
+ TQT_STATIC_CONST TQCursor & busyCursor; // arrow with hourglass
+
+ enum TextFormat {
+ PlainText,
+ RichText,
+ AutoText,
+ LogText
+ };
+
+ // Documented in qtextedit.cpp
+ enum AnchorAttribute {
+ AnchorName,
+ AnchorHref
+ };
+
+ // Documented in qmainwindow.cpp
+ enum Dock {
+ DockUnmanaged,
+ DockTornOff,
+ DockTop,
+ DockBottom,
+ DockRight,
+ DockLeft,
+ DockMinimized
+#ifndef TQT_NO_COMPAT
+ ,
+ Unmanaged = DockUnmanaged,
+ TornOff = DockTornOff,
+ Top = DockTop,
+ Bottom = DockBottom,
+ Right = DockRight,
+ Left = DockLeft,
+ Minimized = DockMinimized
+#endif
+ };
+ // compatibility
+ typedef Dock ToolBarDock;
+
+#ifdef USE_QT4
+ enum DateFormat_NewTypes {
+ TextDate = Qt::TextDate,
+ ISODate = Qt::ISODate,
+ LocalDate = Qt::LocalDate
+ };
+// typedef TQTInheritEnum< DateFormat_NewTypes, Qt::DateFormat > DateFormat;
+ typedef int DateFormat_NewTypes;
+#else // USE_QT4
+ // documented in qdatetime.cpp
+ enum DateFormat {
+ TextDate, // default TQt
+ ISODate, // ISO 8601
+ LocalDate // locale dependent
+ };
+#endif
+
+ // documented in qdatetime.cpp
+ enum TimeSpec {
+ LocalTime,
+ UTC
+ };
+
+ // documented in qwidget.cpp
+ enum BackgroundMode {
+ FixedColor,
+ FixedPixmap,
+ NoBackground,
+ PaletteForeground,
+ PaletteButton,
+ PaletteLight,
+ PaletteMidlight,
+ PaletteDark,
+ PaletteMid,
+ PaletteText,
+ PaletteBrightText,
+ PaletteBase,
+ PaletteBackground,
+ PaletteShadow,
+ PaletteHighlight,
+ PaletteHighlightedText,
+ PaletteButtonText,
+ PaletteLink,
+ PaletteLinkVisited,
+ X11ParentRelative
+ };
+
+ typedef uint ComparisonFlags;
+
+ // Documented in qstring.cpp
+ enum StringComparisonMode {
+ CaseSensitive = 0x00001, // 0 0001
+ BeginsWith = 0x00002, // 0 0010
+ EndsWith = 0x00004, // 0 0100
+ Contains = 0x00008, // 0 1000
+ ExactMatch = 0x00010 // 1 0000
+ };
+
+ // Documented in qtabwidget.cpp
+ enum Corner {
+ TopLeft = 0x00000,
+ TopRight = 0x00001,
+ BottomLeft = 0x00002,
+ BottomRight = 0x00003
+ };
+
+ // "handle" type for system objects. Documented as \internal in
+ // qapplication.cpp
+#if defined(TQ_WS_MAC)
+ typedef void * HANDLE;
+#elif defined(TQ_WS_WIN)
+ typedef void *HANDLE;
+#elif defined(TQ_WS_X11)
+ typedef unsigned long HANDLE;
+#elif defined(TQ_WS_TQWS)
+ typedef void * HANDLE;
+#endif
+};
+
+
+class TQ_EXPORT TQInternal {
+public:
+ enum PaintDeviceFlags {
+ UndefinedDevice = 0x00,
+ Widget = 0x01,
+ Pixmap = 0x02,
+ Printer = 0x03,
+ Picture = 0x04,
+ System = 0x05,
+ DeviceTypeMask = 0x0f,
+ ExternalDevice = 0x10,
+ // used to emulate some of the behaviour different between TQt2 and TQt3 (mainly for printing)
+ CompatibilityMode = 0x20
+ };
+};
+
+#endif // TQNAMESPACE_H
diff --git a/tqtinterface/qt4/src/kernel/tqnetworkprotocol.cpp b/tqtinterface/qt4/src/kernel/tqnetworkprotocol.cpp
new file mode 100644
index 0000000..83cc094
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqnetworkprotocol.cpp
@@ -0,0 +1,1265 @@
+/****************************************************************************
+**
+** Implementation of TQNetworkProtocol class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqnetworkprotocol.h"
+
+#ifndef TQT_NO_NETWORKPROTOCOL
+
+#include "tqlocalfs.h"
+#include "tqurloperator.h"
+#include "tqtimer.h"
+#include "tqmap.h"
+#include "tqptrqueue.h"
+
+//#define TQNETWORKPROTOCOL_DEBUG
+#define NETWORK_OP_DELAY 1000
+
+extern TQ_EXPORT TQNetworkProtocolDict *qNetworkProtocolRegister;
+
+TQNetworkProtocolDict *qNetworkProtocolRegister = 0;
+
+class TQNetworkProtocolPrivate
+{
+public:
+ TQNetworkProtocolPrivate( TQNetworkProtocol *p )
+ {
+ url = 0;
+ opInProgress = 0;
+ opStartTimer = new TQTimer( p );
+ removeTimer = new TQTimer( p );
+ operationQueue.setAutoDelete( FALSE );
+ autoDelete = FALSE;
+ removeInterval = 10000;
+ oldOps.setAutoDelete( FALSE );
+ }
+
+ ~TQNetworkProtocolPrivate()
+ {
+ removeTimer->stop();
+ if ( opInProgress ) {
+ if ( opInProgress == operationQueue.head() )
+ operationQueue.dequeue();
+ opInProgress->free();
+ }
+ while ( operationQueue.head() ) {
+ operationQueue.head()->free();
+ operationQueue.dequeue();
+ }
+ while ( oldOps.first() ) {
+ oldOps.first()->free();
+ oldOps.removeFirst();
+ }
+ delete opStartTimer;
+ }
+
+ TQUrlOperator *url;
+ TQPtrQueue< TQNetworkOperation > operationQueue;
+ TQNetworkOperation *opInProgress;
+ TQTimer *opStartTimer, *removeTimer;
+ int removeInterval;
+ bool autoDelete;
+ TQPtrList< TQNetworkOperation > oldOps;
+};
+
+/*!
+ \class TQNetworkProtocol tqnetworkprotocol.h
+ \brief The TQNetworkProtocol class provides a common API for network protocols.
+\if defined(commercial)
+ It is part of the <a href="commercialeditions.html">TQt Enterprise Edition</a>.
+\endif
+
+ \module network
+ \ingroup io
+ \module network
+ \mainclass
+
+ This is a base class which should be used for network protocols
+ implementations that can then be used in TQt (e.g. in the file
+ dialog) together with the TQUrlOperator.
+
+ The easiest way to implement a new network protocol is to
+ reimplement the operation*() methods, e.g. operationGet(), etc.
+ Only the supported operations should be reimplemented. To specify
+ which operations are supported, also reimplement
+ supportedOperations() and return an int that is OR'd together
+ using the supported operations from the \l
+ TQNetworkProtocol::Operation enum.
+
+ When you implement a network protocol this way, it is important to
+ emit the correct Q_SIGNALS. Also, always emit the finished() signal
+ when an operation is done (on success \e and on failure). TQt
+ relies on correctly emitted finished() Q_SIGNALS.
+
+ For a detailed description of the TQt Network Architecture and how
+ to implement and use network protocols in TQt, see the \link
+ network.html TQt Network Documentation\endlink.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::newChildren( const TQValueList<TQUrlInfo> &i, TQNetworkOperation *op )
+
+ This signal is emitted after listChildren() was called and new
+ tqchildren (files) have been read from the list of files. \a i holds
+ the information about the new tqchildren. \a op is the pointer to
+ the operation object which tqcontains all the information about the
+ operation, including the state, etc.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator, which is used by the network
+ protocol, emit its corresponding signal.
+
+ When implementing your own network protocol and reading tqchildren,
+ you usually don't read one child at once, but rather a list of
+ them. That's why this signal takes a list of TQUrlInfo objects. If
+ you prefer to read just one child at a time you can use the
+ convenience signal newChild(), which takes a single TQUrlInfo
+ object.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::newChild( const TQUrlInfo &i, TQNetworkOperation *op )
+
+ This signal is emitted if a new child (file) has been read.
+ TQNetworkProtocol automatically connects it to a slot which creates
+ a list of TQUrlInfo objects (with just one TQUrlInfo \a i) and emits
+ the newChildren() signal with this list. \a op is the pointer to
+ the operation object which tqcontains all the information about the
+ operation that has finished, including the state, etc.
+
+ This is just a convenience signal useful for implementing your own
+ network protocol. In all other cases connect to the newChildren()
+ signal with its list of TQUrlInfo objects.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::finished( TQNetworkOperation *op )
+
+ This signal is emitted when an operation finishes. This signal is
+ always emitted, for both success and failure. \a op is the pointer
+ to the operation object which tqcontains all the information about
+ the operation, including the state, etc. Check the state and error
+ code of the operation object to determine whether or not the
+ operation was successful.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator, which is used by the network
+ protocol, emit its corresponding signal.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::start( TQNetworkOperation *op )
+
+ Some operations (such as listChildren()) emit this signal when
+ they start processing the operation. \a op is the pointer to the
+ operation object which tqcontains all the information about the
+ operation, including the state, etc.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator, which is used by the network
+ protocol, emit its corresponding signal.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::createdDirectory( const TQUrlInfo &i, TQNetworkOperation *op )
+
+ This signal is emitted when mkdir() has been succesful and the
+ directory has been created. \a i holds the information about the
+ new directory. \a op is the pointer to the operation object which
+ tqcontains all the information about the operation, including the
+ state, etc. Using op->arg( 0 ), you can get the file name of the
+ new directory.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator, which is used by the network
+ protocol, emit its corresponding signal.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::removed( TQNetworkOperation *op )
+
+ This signal is emitted when remove() has been succesful and the
+ file has been removed. \a op holds the file name of the removed
+ file in the first argument, accessible with op->arg( 0 ). \a op is
+ the pointer to the operation object which tqcontains all the
+ information about the operation, including the state, etc.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator, which is used by the network
+ protocol, emit its corresponding signal.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::itemChanged( TQNetworkOperation *op )
+
+ This signal is emitted whenever a file which is a child of this
+ URL has been changed, e.g. by successfully calling rename(). \a op
+ holds the original and the new file names in the first and second
+ arguments, accessible with op->arg( 0 ) and op->arg( 1 )
+ respectively. \a op is the pointer to the operation object which
+ tqcontains all the information about the operation, including the
+ state, etc.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator, which is used by the network
+ protocol, emit its corresponding signal.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::data( const TQByteArray &data,
+ TQNetworkOperation *op )
+
+ This signal is emitted when new \a data has been received after
+ calling get() or put(). \a op holds the name of the file from
+ which data is retrieved or uploaded in its first argument, and the
+ (raw) data in its second argument. You can get them with
+ op->arg( 0 ) and op->rawArg( 1 ). \a op is the pointer to the
+ operation object, which tqcontains all the information about the
+ operation, including the state, etc.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator (which is used by the network
+ protocol) emit its corresponding signal.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::dataTransferProgress( int bytesDone, int bytesTotal, TQNetworkOperation *op )
+
+ This signal is emitted during the transfer of data (using put() or
+ get()). \a bytesDone is how many bytes of \a bytesTotal have been
+ transferred. \a bytesTotal may be -1, which means that the total
+ number of bytes is not known. \a op is the pointer to the
+ operation object which tqcontains all the information about the
+ operation, including the state, etc.
+
+ When a protocol emits this signal, TQNetworkProtocol is smart
+ enough to let the TQUrlOperator, which is used by the network
+ protocol, emit its corresponding signal.
+*/
+
+/*!
+ \fn void TQNetworkProtocol::connectionStateChanged( int state, const TQString &data )
+
+ This signal is emitted whenever the state of the connection of the
+ network protocol is changed. \a state describes the new state,
+ which is one of, \c ConHostFound, \c ConConnected or \c ConClosed.
+ \a data is a message text.
+*/
+
+/*!
+ \enum TQNetworkProtocol::State
+
+ This enum tqcontains the state that a TQNetworkOperation can have.
+
+ \value StWaiting The operation is in the TQNetworkProtocol's queue
+ waiting to be prcessed.
+
+ \value StInProgress The operation is being processed.
+
+ \value StDone The operation has been processed succesfully.
+
+ \value StFailed The operation has been processed but an error occurred.
+
+ \value StStopped The operation has been processed but has been
+ stopped before it finished, and is waiting to be processed.
+
+*/
+
+/*!
+ \enum TQNetworkProtocol::Operation
+
+ This enum lists the possible operations that a network protocol
+ can support. supportedOperations() returns an int of these that is
+ OR'd together. Also, the type() of a TQNetworkOperation is always
+ one of these values.
+
+ \value OpListChildren List the tqchildren of a URL, e.g. of a directory.
+ \value OpMkDir Create a directory.
+ \value OpRemove Remove a child (e.g. a file).
+ \value OpRename Rename a child (e.g. a file).
+ \value OpGet Get data from a location.
+ \value OpPut Put data to a location.
+*/
+
+/*!
+ \enum TQNetworkProtocol::ConnectionState
+
+ When the connection state of a network protocol changes it emits
+ the signal connectionStateChanged(). The first argument is one of
+ the following values:
+
+ \value ConHostFound Host has been found.
+ \value ConConnected Connection to the host has been established.
+ \value ConClosed Connection has been closed.
+*/
+
+/*!
+ \enum TQNetworkProtocol::Error
+
+ When an operation fails (finishes unsuccessfully), the
+ TQNetworkOperation of the operation returns an error code which has
+ one of the following values:
+
+ \value NoError No error occurred.
+
+ \value ErrValid The URL you are operating on is not valid.
+
+ \value ErrUnknownProtocol There is no protocol implementation
+ available for the protocol of the URL you are operating on (e.g.
+ if the protocol is http and no http implementation has been
+ registered).
+
+ \value ErrUnsupported The operation is not supported by the
+ protocol.
+
+ \value ErrParse The URL could not be parsed correctly.
+
+ \value ErrLoginIncorrect You needed to login but the username
+ or password is wrong.
+
+ \value ErrHostNotFound The specified host (in the URL) couldn't
+ be found.
+
+ \value ErrListChildren An error occurred while listing the
+ tqchildren (files).
+
+ \value ErrMkDir An error occurred when creating a directory.
+
+ \value ErrRemove An error occurred when removing a child (file).
+
+ \value ErrRename An error occurred when renaming a child (file).
+
+ \value ErrGet An error occurred while getting (retrieving) data.
+
+ \value ErrPut An error occurred while putting (uploading) data.
+
+ \value ErrFileNotExisting A file which is needed by the operation
+ doesn't exist.
+
+ \value ErrPermissionDenied Permission for doing the operation has
+ been denied.
+
+ You should also use these error codes when implementing custom
+ network protocols. If this is not possible, you can define your own
+ error codes by using integer values that don't conflict with any
+ of these values.
+*/
+
+/*!
+ Constructor of the network protocol base class. Does some
+ initialization and connecting of Q_SIGNALS and Q_SLOTS.
+*/
+
+TQNetworkProtocol::TQNetworkProtocol()
+ : TQObject()
+{
+ d = new TQNetworkProtocolPrivate( this );
+
+ connect( d->opStartTimer, TQT_SIGNAL( timeout() ),
+ this, TQT_SLOT( startOps() ) );
+ connect( d->removeTimer, TQT_SIGNAL( timeout() ),
+ this, TQT_SLOT( removeMe() ) );
+
+ if ( url() ) {
+ connect( this, TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( finished(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( start(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( start(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ),
+ url(), TQT_SLOT( addEntry(const TQValueList<TQUrlInfo>&) ) );
+ connect( this, TQT_SIGNAL( createdDirectory(const TQUrlInfo&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( createdDirectory(const TQUrlInfo&,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( removed(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( removed(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( itemChanged(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( itemChanged(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( connectionStateChanged(int,const TQString&) ),
+ url(), TQT_SIGNAL( connectionStateChanged(int,const TQString&) ) );
+ }
+
+ connect( this, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ this, TQT_SLOT( processNextOperation(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( newChild(const TQUrlInfo&,TQNetworkOperation*) ),
+ this, TQT_SLOT( emitNewChildren(const TQUrlInfo&,TQNetworkOperation*) ) );
+
+}
+
+/*!
+ Destructor.
+*/
+
+TQNetworkProtocol::~TQNetworkProtocol()
+{
+ delete d;
+}
+
+/*!
+ Sets the TQUrlOperator, on which the protocol works, to \a u.
+
+ \sa TQUrlOperator
+*/
+
+void TQNetworkProtocol::setUrl( TQUrlOperator *u )
+{
+ if ( url() ) {
+ disconnect( this, TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( finished(TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( start(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( start(TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ),
+ url(), TQT_SLOT( addEntry(const TQValueList<TQUrlInfo>&) ) );
+ disconnect( this, TQT_SIGNAL( createdDirectory(const TQUrlInfo&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( createdDirectory(const TQUrlInfo&,TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( removed(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( removed(TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( itemChanged(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( itemChanged(TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ) );
+ disconnect( this, TQT_SIGNAL( connectionStateChanged(int,const TQString&) ),
+ url(), TQT_SIGNAL( connectionStateChanged(int,const TQString&) ) );
+ }
+
+
+ // ### if autoDelete is TRUE, we should delete the TQUrlOperator (something
+ // like below; but that is not possible since it would delete this, too).
+ //if ( d->autoDelete && (d->url!=u) ) {
+ // delete d->url; // destructor deletes the network protocol
+ //}
+ d->url = u;
+
+ if ( url() ) {
+ connect( this, TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( finished(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( start(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( start(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( newChildren(const TQValueList<TQUrlInfo>&,TQNetworkOperation*) ),
+ url(), TQT_SLOT( addEntry(const TQValueList<TQUrlInfo>&) ) );
+ connect( this, TQT_SIGNAL( createdDirectory(const TQUrlInfo&,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( createdDirectory(const TQUrlInfo&,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( removed(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( removed(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( itemChanged(TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( itemChanged(TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ),
+ url(), TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ) );
+ connect( this, TQT_SIGNAL( connectionStateChanged(int,const TQString&) ),
+ url(), TQT_SIGNAL( connectionStateChanged(int,const TQString&) ) );
+ }
+
+ if ( !d->opInProgress && !d->operationQueue.isEmpty() )
+ d->opStartTimer->start( 0, TRUE );
+}
+
+/*!
+ For processing operations the network protocol base class calls
+ this method quite often. This should be reimplemented by new
+ network protocols. It should return TRUE if the connection is OK
+ (open); otherwise it should return FALSE. If the connection is not
+ open the protocol should open it.
+
+ If the connection can't be opened (e.g. because you already tried
+ but the host couldn't be found), set the state of \a op to
+ TQNetworkProtocol::StFailed and emit the finished() signal with
+ this TQNetworkOperation as argument.
+
+ \a op is the operation that needs an open connection.
+*/
+
+bool TQNetworkProtocol::checkConnection( TQNetworkOperation * )
+{
+ return TRUE;
+}
+
+/*!
+ Returns an int that is OR'd together using the enum values of
+ \l{TQNetworkProtocol::Operation}, which describes which operations
+ are supported by the network protocol. Should be reimplemented by
+ new network protocols.
+*/
+
+int TQNetworkProtocol::supportedOperations() const
+{
+ return 0;
+}
+
+/*!
+ Adds the operation \a op to the operation queue. The operation
+ will be processed as soon as possible. This method returns
+ immediately.
+*/
+
+void TQNetworkProtocol::addOperation( TQNetworkOperation *op )
+{
+#ifdef TQNETWORKPROTOCOL_DEBUG
+ qDebug( "TQNetworkOperation: addOperation: %p %d", op, op->operation() );
+#endif
+ d->operationQueue.enqueue( op );
+ if ( !d->opInProgress )
+ d->opStartTimer->start( 0, TRUE );
+}
+
+/*!
+ Static method to register a network protocol for TQt. For example,
+ if you have an implementation of NNTP (called Nntp) which is
+ derived from TQNetworkProtocol, call:
+ \code
+ TQNetworkProtocol::registerNetworkProtocol( "nntp", new TQNetworkProtocolFactory<Nntp> );
+ \endcode
+ after which your implementation is registered for future nntp
+ operations.
+
+ The name of the protocol is given in \a protocol and a pointer to
+ the protocol factory is given in \a protocolFactory.
+*/
+
+void TQNetworkProtocol::registerNetworkProtocol( const TQString &protocol,
+ TQNetworkProtocolFactoryBase *protocolFactory )
+{
+ if ( !qNetworkProtocolRegister ) {
+ qNetworkProtocolRegister = new TQNetworkProtocolDict;
+ TQNetworkProtocol::registerNetworkProtocol( "file", new TQNetworkProtocolFactory< TQLocalFs > );
+ }
+
+ qNetworkProtocolRegister->insert( protocol, protocolFactory );
+}
+
+/*!
+ Static method to get a new instance of the network protocol \a
+ protocol. For example, if you need to do some FTP operations, do
+ the following:
+ \code
+ TQFtp *ftp = TQNetworkProtocol::getNetworkProtocol( "ftp" );
+ \endcode
+ This returns a pointer to a new instance of an ftp implementation
+ or null if no protocol for ftp was registered. The ownership of
+ the pointer is transferred to you, so you must delete it if you
+ don't need it anymore.
+
+ Normally you should not work directly with network protocols, so
+ you will not need to call this method yourself. Instead, use
+ TQUrlOperator, which makes working with network protocols much more
+ convenient.
+
+ \sa TQUrlOperator
+*/
+
+TQNetworkProtocol *TQNetworkProtocol::getNetworkProtocol( const TQString &protocol )
+{
+ if ( !qNetworkProtocolRegister ) {
+ qNetworkProtocolRegister = new TQNetworkProtocolDict;
+ TQNetworkProtocol::registerNetworkProtocol( "file", new TQNetworkProtocolFactory< TQLocalFs > );
+ }
+
+ if ( protocol.isNull() )
+ return 0;
+
+ TQNetworkProtocolFactoryBase *factory = qNetworkProtocolRegister->tqfind( protocol );
+ if ( factory )
+ return factory->createObject();
+
+ return 0;
+}
+
+/*!
+ Returns TRUE if the only protocol registered is for working on the
+ local filesystem; returns FALSE if other network protocols are
+ also registered.
+*/
+
+bool TQNetworkProtocol::hasOnlyLocalFileSystem()
+{
+ if ( !qNetworkProtocolRegister )
+ return FALSE;
+
+ TQDictIterator< TQNetworkProtocolFactoryBase > it( *qNetworkProtocolRegister );
+ for ( ; it.current(); ++it )
+ if ( it.currentKey() != "file" )
+ return FALSE;
+ return TRUE;
+}
+
+/*!
+ \internal
+ Starts processing network operations.
+*/
+
+void TQNetworkProtocol::startOps()
+{
+#ifdef TQNETWORKPROTOCOL_DEBUG
+ qDebug( "TQNetworkOperation: start processing operations" );
+#endif
+ processNextOperation( 0 );
+}
+
+/*!
+ \internal
+ Processes the operation \a op. It calls the
+ corresponding operation[something]( TQNetworkOperation * )
+ methods.
+*/
+
+void TQNetworkProtocol::processOperation( TQNetworkOperation *op )
+{
+ if ( !op )
+ return;
+
+ switch ( op->operation() ) {
+ case OpListChildren:
+ operationListChildren( op );
+ break;
+ case OpMkDir:
+ operationMkDir( op );
+ break;
+ case OpRemove:
+ operationRemove( op );
+ break;
+ case OpRename:
+ operationRename( op );
+ break;
+ case OpGet:
+ operationGet( op );
+ break;
+ case OpPut:
+ operationPut( op );
+ break;
+ }
+}
+
+/*!
+ When implementing a new network protocol, this method should be
+ reimplemented if the protocol supports listing tqchildren (files);
+ this method should then process this TQNetworkOperation.
+
+ When you reimplement this method it's very important that you emit
+ the correct Q_SIGNALS at the correct time (especially the finished()
+ signal after processing an operation). Take a look at the \link
+ network.html TQt Network Documentation\endlink which describes in
+ detail how to reimplement this method. You may also want to look
+ at the example implementation in
+ examples/network/networkprotocol/nntp.cpp.
+
+ \a op is the pointer to the operation object which tqcontains all
+ the information on the operation that has finished, including the
+ state, etc.
+*/
+
+void TQNetworkProtocol::operationListChildren( TQNetworkOperation * )
+{
+}
+
+/*!
+ When implementing a new network protocol, this method should be
+ reimplemented if the protocol supports making directories; this
+ method should then process this TQNetworkOperation.
+
+ When you reimplement this method it's very important that you emit
+ the correct Q_SIGNALS at the correct time (especially the finished()
+ signal after processing an operation). Take a look at the \link
+ network.html TQt Network Documentation\endlink which describes in
+ detail how to reimplement this method. You may also want to look
+ at the example implementation in
+ examples/network/networkprotocol/nntp.cpp.
+
+ \a op is the pointer to the operation object which tqcontains all
+ the information on the operation that has finished, including the
+ state, etc.
+*/
+
+void TQNetworkProtocol::operationMkDir( TQNetworkOperation * )
+{
+}
+
+/*!
+ When implementing a new network protocol, this method should be
+ reimplemented if the protocol supports removing tqchildren (files);
+ this method should then process this TQNetworkOperation.
+
+ When you reimplement this method it's very important that you emit
+ the correct Q_SIGNALS at the correct time (especially the finished()
+ signal after processing an operation). Take a look at the \link
+ network.html TQt Network Documentation\endlink which is describes
+ in detail how to reimplement this method. You may also want to
+ look at the example implementation in
+ examples/network/networkprotocol/nntp.cpp.
+
+ \a op is the pointer to the operation object which tqcontains all
+ the information on the operation that has finished, including the
+ state, etc.
+*/
+
+void TQNetworkProtocol::operationRemove( TQNetworkOperation * )
+{
+}
+
+/*!
+ When implementing a new newtork protocol, this method should be
+ reimplemented if the protocol supports renaming tqchildren (files);
+ this method should then process this TQNetworkOperation.
+
+ When you reimplement this method it's very important that you emit
+ the correct Q_SIGNALS at the correct time (especially the finished()
+ signal after processing an operation). Take a look at the \link
+ network.html TQt Network Documentation\endlink which describes in
+ detail how to reimplement this method. You may also want to look
+ at the example implementation in
+ examples/network/networkprotocol/nntp.cpp.
+
+ \a op is the pointer to the operation object which tqcontains all
+ the information on the operation that has finished, including the
+ state, etc.
+*/
+
+void TQNetworkProtocol::operationRename( TQNetworkOperation * )
+{
+}
+
+/*!
+ When implementing a new network protocol, this method should be
+ reimplemented if the protocol supports getting data; this method
+ should then process the TQNetworkOperation.
+
+ When you reimplement this method it's very important that you emit
+ the correct Q_SIGNALS at the correct time (especially the finished()
+ signal after processing an operation). Take a look at the \link
+ network.html TQt Network Documentation\endlink which describes in
+ detail how to reimplement this method. You may also want to look
+ at the example implementation in
+ examples/network/networkprotocol/nntp.cpp.
+
+ \a op is the pointer to the operation object which tqcontains all
+ the information on the operation that has finished, including the
+ state, etc.
+*/
+
+void TQNetworkProtocol::operationGet( TQNetworkOperation * )
+{
+}
+
+/*!
+ When implementing a new network protocol, this method should be
+ reimplemented if the protocol supports putting (uploading) data;
+ this method should then process the TQNetworkOperation.
+
+ When you reimplement this method it's very important that you emit
+ the correct Q_SIGNALS at the correct time (especially the finished()
+ signal after processing an operation). Take a look at the \link
+ network.html TQt Network Documentation\endlink which describes in
+ detail how to reimplement this method. You may also want to look
+ at the example implementation in
+ examples/network/networkprotocol/nntp.cpp.
+
+ \a op is the pointer to the operation object which tqcontains all
+ the information on the operation that has finished, including the
+ state, etc.
+*/
+
+void TQNetworkProtocol::operationPut( TQNetworkOperation * )
+{
+}
+
+/*! \internal
+*/
+
+void TQNetworkProtocol::operationPutChunk( TQNetworkOperation * )
+{
+}
+
+/*!
+ \internal
+ Handles operations. Deletes the previous operation object and
+ tries to process the next operation. It also checks the connection state
+ and only processes the next operation, if the connection of the protocol
+ is open. Otherwise it waits until the protocol opens the connection.
+*/
+
+void TQNetworkProtocol::processNextOperation( TQNetworkOperation *old )
+{
+#ifdef TQNETWORKPROTOCOL_DEBUG
+ qDebug( "TQNetworkOperation: process next operation, old: %p", old );
+#endif
+ d->removeTimer->stop();
+
+ if ( old )
+ d->oldOps.append( old );
+ if ( d->opInProgress && d->opInProgress!=old )
+ d->oldOps.append( d->opInProgress );
+
+ if ( d->operationQueue.isEmpty() ) {
+ d->opInProgress = 0;
+ if ( d->autoDelete )
+ d->removeTimer->start( d->removeInterval, TRUE );
+ return;
+ }
+
+ TQNetworkOperation *op = d->operationQueue.head();
+
+ d->opInProgress = op;
+
+ if ( !checkConnection( op ) ) {
+ if ( op->state() != TQNetworkProtocol::StFailed ) {
+ d->opStartTimer->start( 0, TRUE );
+ } else {
+ d->operationQueue.dequeue();
+ clearOperationQueue();
+ emit finished( op );
+ }
+
+ return;
+ }
+
+ d->opInProgress = op;
+ d->operationQueue.dequeue();
+ processOperation( op );
+}
+
+/*!
+ Returns the TQUrlOperator on which the protocol works.
+*/
+
+TQUrlOperator *TQNetworkProtocol::url() const
+{
+ return d->url;
+}
+
+/*!
+ Returns the operation, which is being processed, or 0 of no
+ operation is being processed at the moment.
+*/
+
+TQNetworkOperation *TQNetworkProtocol::operationInProgress() const
+{
+ return d->opInProgress;
+}
+
+/*!
+ Clears the operation queue.
+*/
+
+void TQNetworkProtocol::clearOperationQueue()
+{
+ d->operationQueue.dequeue();
+ d->operationQueue.setAutoDelete( TRUE );
+ d->operationQueue.clear();
+}
+
+/*!
+ Stops the current operation that is being processed and clears all
+ waiting operations.
+*/
+
+void TQNetworkProtocol::stop()
+{
+ TQNetworkOperation *op = d->opInProgress;
+ clearOperationQueue();
+ if ( op ) {
+ op->setState( StStopped );
+ op->setProtocolDetail( tr( "Operation stopped by the user" ) );
+ emit finished( op );
+ setUrl( 0 );
+ op->free();
+ }
+}
+
+/*!
+ Because it's sometimes hard to take care of removing network
+ protocol instances, TQNetworkProtocol provides an auto-delete
+ mechanism. If you set \a b to TRUE, the network protocol instance
+ is removed after it has been inactive for \a i milliseconds (i.e.
+ \a i milliseconds after the last operation has been processed).
+ If you set \a b to FALSE the auto-delete mechanism is switched
+ off.
+
+ If you switch on auto-delete, the TQNetworkProtocol also deletes
+ its TQUrlOperator.
+*/
+
+void TQNetworkProtocol::setAutoDelete( bool b, int i )
+{
+ d->autoDelete = b;
+ d->removeInterval = i;
+}
+
+/*!
+ Returns TRUE if auto-deleting is enabled; otherwise returns FALSE.
+
+ \sa TQNetworkProtocol::setAutoDelete()
+*/
+
+bool TQNetworkProtocol::autoDelete() const
+{
+ return d->autoDelete;
+}
+
+/*!
+ \internal
+*/
+
+void TQNetworkProtocol::removeMe()
+{
+ if ( d->autoDelete ) {
+#ifdef TQNETWORKPROTOCOL_DEBUG
+ qDebug( "TQNetworkOperation: autodelete of TQNetworkProtocol %p", this );
+#endif
+ delete d->url; // destructor deletes the network protocol
+ }
+}
+
+void TQNetworkProtocol::emitNewChildren( const TQUrlInfo &i, TQNetworkOperation *op )
+{
+ TQValueList<TQUrlInfo> lst;
+ lst << i;
+ emit newChildren( lst, op );
+}
+
+class TQNetworkOperationPrivate
+{
+public:
+ TQNetworkProtocol::Operation operation;
+ TQNetworkProtocol::State state;
+ TQMap<int, TQString> args;
+ TQMap<int, TQByteArray> rawArgs;
+ TQString protocolDetail;
+ int errorCode;
+ TQTimer *deleteTimer;
+};
+
+/*!
+ \class TQNetworkOperation
+
+ \brief The TQNetworkOperation class provides common operations for network protocols.
+\if defined(commercial)
+ It is part of the <a href="commercialeditions.html">TQt Enterprise Edition</a>.
+\endif
+
+ \module network
+ \ingroup io
+
+ An object is created to describe the operation and the current
+ state for each operation that a network protocol should process.
+
+ For a detailed description of the TQt Network Architecture and how
+ to implement and use network protocols in TQt, see the \link
+ network.html TQt Network Documentation\endlink.
+
+ \sa TQNetworkProtocol
+*/
+
+/*!
+ Constructs a network operation object. \a operation is the type of
+ the operation, and \a arg0, \a arg1 and \a arg2 are the first
+ three arguments of the operation. The state is initialized to
+ TQNetworkProtocol::StWaiting.
+
+ \sa TQNetworkProtocol::Operation TQNetworkProtocol::State
+*/
+
+TQNetworkOperation::TQNetworkOperation( TQNetworkProtocol::Operation operation,
+ const TQString &arg0, const TQString &arg1,
+ const TQString &arg2 )
+{
+ d = new TQNetworkOperationPrivate;
+ d->deleteTimer = new TQTimer( this );
+ connect( d->deleteTimer, TQT_SIGNAL( timeout() ),
+ this, TQT_SLOT( deleteMe() ) );
+ d->operation = operation;
+ d->state = TQNetworkProtocol::StWaiting;
+ d->args[ 0 ] = arg0;
+ d->args[ 1 ] = arg1;
+ d->args[ 2 ] = arg2;
+ d->rawArgs[ 0 ] = TQByteArray( 0 );
+ d->rawArgs[ 1 ] = TQByteArray( 0 );
+ d->rawArgs[ 2 ] = TQByteArray( 0 );
+ d->protocolDetail = TQString::null;
+ d->errorCode = (int)TQNetworkProtocol::NoError;
+}
+
+/*!
+ Constructs a network operation object. \a operation is the type of
+ the operation, and \a arg0, \a arg1 and \a arg2 are the first
+ three raw data arguments of the operation. The state is
+ initialized to TQNetworkProtocol::StWaiting.
+
+ \sa TQNetworkProtocol::Operation TQNetworkProtocol::State
+*/
+
+TQNetworkOperation::TQNetworkOperation( TQNetworkProtocol::Operation operation,
+ const TQByteArray &arg0, const TQByteArray &arg1,
+ const TQByteArray &arg2 )
+{
+ d = new TQNetworkOperationPrivate;
+ d->deleteTimer = new TQTimer( this );
+ connect( d->deleteTimer, TQT_SIGNAL( timeout() ),
+ this, TQT_SLOT( deleteMe() ) );
+ d->operation = operation;
+ d->state = TQNetworkProtocol::StWaiting;
+ d->args[ 0 ] = TQString::null;
+ d->args[ 1 ] = TQString::null;
+ d->args[ 2 ] = TQString::null;
+ d->rawArgs[ 0 ] = arg0;
+ d->rawArgs[ 1 ] = arg1;
+ d->rawArgs[ 2 ] = arg2;
+ d->protocolDetail = TQString::null;
+ d->errorCode = (int)TQNetworkProtocol::NoError;
+}
+
+/*!
+ Destructor.
+*/
+
+TQNetworkOperation::~TQNetworkOperation()
+{
+ delete d;
+}
+
+/*!
+ Sets the \a state of the operation object. This should be done by
+ the network protocol during processing; at the end it should be
+ set to TQNetworkProtocol::StDone or TQNetworkProtocol::StFailed,
+ depending on success or failure.
+
+ \sa TQNetworkProtocol::State
+*/
+
+void TQNetworkOperation::setState( TQNetworkProtocol::State state )
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ d->state = state;
+}
+
+/*!
+ If the operation failed, the error message can be specified as \a
+ detail.
+*/
+
+void TQNetworkOperation::setProtocolDetail( const TQString &detail )
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ d->protocolDetail = detail;
+}
+
+/*!
+ Sets the error code to \a ec.
+
+ If the operation failed, the protocol should set an error code to
+ describe the error in more detail. If possible, one of the error
+ codes defined in TQNetworkProtocol should be used.
+
+ \sa setProtocolDetail() TQNetworkProtocol::Error
+*/
+
+void TQNetworkOperation::setErrorCode( int ec )
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ d->errorCode = ec;
+}
+
+/*!
+ Sets the network operation's \a{num}-th argument to \a arg.
+*/
+
+void TQNetworkOperation::setArg( int num, const TQString &arg )
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ d->args[ num ] = arg;
+}
+
+/*!
+ Sets the network operation's \a{num}-th raw data argument to \a arg.
+*/
+
+void TQNetworkOperation::setRawArg( int num, const TQByteArray &arg )
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ d->rawArgs[ num ] = arg;
+}
+
+/*!
+ Returns the type of the operation.
+*/
+
+TQNetworkProtocol::Operation TQNetworkOperation::operation() const
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ return d->operation;
+}
+
+/*!
+ Returns the state of the operation. You can determine whether an
+ operation is still waiting to be processed, is being processed,
+ has been processed successfully, or failed.
+*/
+
+TQNetworkProtocol::State TQNetworkOperation::state() const
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ return d->state;
+}
+
+/*!
+ Returns the operation's \a{num}-th argument. If this argument was
+ not already set, an empty string is returned.
+*/
+
+TQString TQNetworkOperation::arg( int num ) const
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ return d->args[ num ];
+}
+
+/*!
+ Returns the operation's \a{num}-th raw data argument. If this
+ argument was not already set, an empty bytearray is returned.
+*/
+
+TQByteArray TQNetworkOperation::rawArg( int num ) const
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ return d->rawArgs[ num ];
+}
+
+/*!
+ Returns a detailed error message for the last error. This must
+ have been set using setProtocolDetail().
+*/
+
+TQString TQNetworkOperation::protocolDetail() const
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ return d->protocolDetail;
+}
+
+/*!
+ Returns the error code for the last error that occurred.
+*/
+
+int TQNetworkOperation::errorCode() const
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ return d->errorCode;
+}
+
+/*!
+ \internal
+*/
+
+TQByteArray& TQNetworkOperation::raw( int num ) const
+{
+ if ( d->deleteTimer->isActive() ) {
+ d->deleteTimer->stop();
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+ }
+ return d->rawArgs[ num ];
+}
+
+/*!
+ Sets this object to delete itself when it hasn't been used for one
+ second.
+
+ Because TQNetworkOperation pointers are passed around a lot the
+ TQNetworkProtocol generally does not have enough knowledge to
+ delete these at the correct time. If a TQNetworkProtocol doesn't
+ need an operation any more it will call this function instead.
+
+ Note: you should never need to call the method yourself.
+*/
+
+void TQNetworkOperation::free()
+{
+ d->deleteTimer->start( NETWORK_OP_DELAY );
+}
+
+/*!
+ \internal
+ Internal slot for auto-deletion.
+*/
+
+void TQNetworkOperation::deleteMe()
+{
+ delete this;
+}
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqnetworkprotocol.h b/tqtinterface/qt4/src/kernel/tqnetworkprotocol.h
new file mode 100644
index 0000000..e0594a6
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqnetworkprotocol.h
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Definition of TQNetworkProtocol class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQNETWORKPROTOCOL_H
+#define TQNETWORKPROTOCOL_H
+
+#ifndef TQT_H
+#include "tqurlinfo.h"
+#include "tqstring.h"
+#include "tqdict.h"
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_NETWORKPROTOCOL
+
+#if __GNUC__ - 0 > 3
+#pragma GCC system_header
+#endif
+
+class TQNetworkProtocol;
+class TQNetworkOperation;
+class TQTimer;
+class TQUrlOperator;
+class TQNetworkProtocolPrivate;
+template <class T> class TQValueList;
+
+class TQ_EXPORT TQNetworkProtocolFactoryBase
+{
+public:
+ virtual TQNetworkProtocol *createObject() = 0;
+
+};
+
+template< class T >
+class TQNetworkProtocolFactory : public TQNetworkProtocolFactoryBase
+{
+public:
+ TQNetworkProtocol *createObject() {
+ return new T;
+ }
+
+};
+
+typedef TQDict< TQNetworkProtocolFactoryBase > TQNetworkProtocolDict;
+
+class TQ_EXPORT TQNetworkProtocol : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ enum State {
+ StWaiting = 0,
+ StInProgress,
+ StDone,
+ StFailed,
+ StStopped
+ };
+
+ enum Operation {
+ OpListChildren = 1,
+ OpMkDir = 2,
+ OpMkdir = OpMkDir, // ### remove in 4.0
+ OpRemove = 4,
+ OpRename = 8,
+ OpGet = 32,
+ OpPut = 64
+ };
+
+ enum ConnectionState {
+ ConHostFound,
+ ConConnected,
+ ConClosed
+ };
+
+ enum Error {
+ // no error
+ NoError = 0,
+ // general errors
+ ErrValid,
+ ErrUnknownProtocol,
+ ErrUnsupported,
+ ErrParse,
+ // errors on connect
+ ErrLoginIncorrect,
+ ErrHostNotFound,
+ // protocol errors
+ ErrListChildren,
+ ErrListChlidren = ErrListChildren, // ### remove in 4.0
+ ErrMkDir,
+ ErrMkdir = ErrMkDir, // ### remove in 4.0
+ ErrRemove,
+ ErrRename,
+ ErrGet,
+ ErrPut,
+ ErrFileNotExisting,
+ ErrPermissionDenied
+ };
+
+ TQNetworkProtocol();
+ virtual ~TQNetworkProtocol();
+
+ virtual void setUrl( TQUrlOperator *u );
+
+ virtual void setAutoDelete( bool b, int i = 10000 );
+ bool autoDelete() const;
+
+ static void registerNetworkProtocol( const TQString &protocol,
+ TQNetworkProtocolFactoryBase *protocolFactory );
+ static TQNetworkProtocol *getNetworkProtocol( const TQString &protocol );
+ static bool hasOnlyLocalFileSystem();
+
+ virtual int supportedOperations() const;
+ virtual void addOperation( TQNetworkOperation *op );
+
+ TQUrlOperator *url() const;
+ TQNetworkOperation *operationInProgress() const;
+ virtual void clearOperationQueue();
+ virtual void stop();
+
+Q_SIGNALS:
+ void data( const TQByteArray &, TQNetworkOperation *res );
+ void connectionStateChanged( int state, const TQString &data );
+ void finished( TQNetworkOperation *res );
+ void start( TQNetworkOperation *res );
+ void newChildren( const TQValueList<TQUrlInfo> &, TQNetworkOperation *res );
+ void newChild( const TQUrlInfo &, TQNetworkOperation *res );
+ void createdDirectory( const TQUrlInfo &, TQNetworkOperation *res );
+ void removed( TQNetworkOperation *res );
+ void itemChanged( TQNetworkOperation *res );
+ void dataTransferProgress( int bytesDone, int bytesTotal, TQNetworkOperation *res );
+
+protected:
+ virtual void processOperation( TQNetworkOperation *op );
+ virtual void operationListChildren( TQNetworkOperation *op );
+ virtual void operationMkDir( TQNetworkOperation *op );
+ virtual void operationRemove( TQNetworkOperation *op );
+ virtual void operationRename( TQNetworkOperation *op );
+ virtual void operationGet( TQNetworkOperation *op );
+ virtual void operationPut( TQNetworkOperation *op );
+ virtual void operationPutChunk( TQNetworkOperation *op );
+ virtual bool checkConnection( TQNetworkOperation *op );
+
+private:
+ TQNetworkProtocolPrivate *d;
+
+private Q_SLOTS:
+ void processNextOperation( TQNetworkOperation *old );
+ void startOps();
+ void emitNewChildren( const TQUrlInfo &i, TQNetworkOperation *op );
+
+ void removeMe();
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQNetworkProtocol( const TQNetworkProtocol & );
+ TQNetworkProtocol &operator=( const TQNetworkProtocol & );
+#endif
+};
+
+class TQNetworkOperationPrivate;
+
+class TQ_EXPORT TQNetworkOperation : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+ friend class TQUrlOperator;
+
+public:
+ TQNetworkOperation( TQNetworkProtocol::Operation operation,
+ const TQString &arg0, const TQString &arg1,
+ const TQString &arg2 );
+ TQNetworkOperation( TQNetworkProtocol::Operation operation,
+ const TQByteArray &arg0, const TQByteArray &arg1,
+ const TQByteArray &arg2 );
+ ~TQNetworkOperation();
+
+ void setState( TQNetworkProtocol::State state );
+ void setProtocolDetail( const TQString &detail );
+ void setErrorCode( int ec );
+ void setArg( int num, const TQString &arg );
+ void setRawArg( int num, const TQByteArray &arg );
+
+ TQNetworkProtocol::Operation operation() const;
+ TQNetworkProtocol::State state() const;
+ TQString arg( int num ) const;
+ TQByteArray rawArg( int num ) const;
+ TQString protocolDetail() const;
+ int errorCode() const;
+
+ void free();
+
+private Q_SLOTS:
+ void deleteMe();
+
+private:
+ TQByteArray &raw( int num ) const;
+ TQNetworkOperationPrivate *d;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQNetworkOperation( const TQNetworkOperation & );
+ TQNetworkOperation &operator=( const TQNetworkOperation & );
+#endif
+};
+
+#endif // TQT_NO_NETWORKPROTOCOL
+
+#endif // TQNETWORKPROTOCOL_H
diff --git a/tqtinterface/qt4/src/kernel/tqobject.cpp b/tqtinterface/qt4/src/kernel/tqobject.cpp
new file mode 100644
index 0000000..9bec024
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqobject.cpp
@@ -0,0 +1,3666 @@
+/****************************************************************************
+**
+** Implementation of TQObject class
+**
+****************************************************************************/
+
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+#include "tqobject.h"
+#include "tqwidget.h"
+
+#include "tqvariant.h"
+#include "tqapplication.h"
+#include "tqobject.h"
+#include "tqobjectlist.h"
+#include "tqsignalslotimp.h"
+#include "tqregexp.h"
+#include "tqmetaobject.h"
+#include <private/tqucom_p.h>
+#include "tqucomextra_p.h"
+#include "tqptrvector.h"
+#include "tqlayout.h"
+#include <Qt/qabstracteventdispatcher.h>
+
+#ifdef TQT_THREAD_SUPPORT
+#include <tqmutex.h>
+#include <private/tqmutexpool_p.h>
+#endif
+
+#include <ctype.h>
+
+// Event functions, implemented in qapplication_xxx.cpp
+
+// int qStartTimer( int interval, TQObject *obj );
+// bool tqKillTimer( int id );
+// bool tqKillTimer( TQObject *obj );
+
+#ifndef TQT_NO_USERDATA
+class TQObjectPrivate : public TQPtrVector<TQObjectUserData>
+{
+public:
+ TQObjectPrivate( uint s ) : TQPtrVector<TQObjectUserData>(s){ setAutoDelete( TRUE ); }
+};
+#else
+class TQObjectPrivate {
+}
+#endif
+
+class TQSenderObjectList : public TQObjectList, public TQShared
+{
+public:
+ TQSenderObjectList() : currentSender( 0 ) { }
+ TQObject *currentSender;
+};
+
+/*!
+ \class TQt tqnamespace.h
+
+ \brief The TQt class is a namespace for miscellaneous identifiers
+ that need to be global-like.
+
+ \ingroup misc
+
+ Normally, you can ignore this class. TQObject and a few other
+ classes inherit it, so all the identifiers in the TQt namespace are
+ normally usable without qualification.
+
+ However, you may occasionally need to say \c TQt::black instead of
+ just \c black, particularly in static utility functions (such as
+ many class factories).
+
+*/
+
+TQObject::TQObject( TQT_BASE_OBJECT_NAME *tqparent, const char *name ) : TQT_BASE_OBJECT_NAME ( tqparent ) {
+ setObjectName(QString::fromAscii(name));
+ TQT_TQOBJECT_REQUIRED_INITIALIZATION(tqparent)
+}
+
+const char * TQObject::name(const char *defaultName) const {
+ TQString s = objectName();
+ return s.isEmpty()?defaultName:s.latin1_helper();
+}
+
+void TQObject::insertChild( TQObject *object ) {
+ TQChildEvent *e = new TQChildEvent( (QEvent::Type)TQEvent::ChildInserted, object );
+ QApplication::postEvent( this, e );
+ object->setParent(this);
+}
+
+void TQObject::removeChild( TQObject *object ) {
+ object->setParent(0);
+}
+
+void TQObject::setName(const char *aName) {
+ setObjectName(aName);
+}
+
+TQVariant TQObject::property( const char *name ) const {
+ return TQT_TQVARIANT_OBJECT(TQT_BASE_OBJECT_NAME::property(name));
+}
+
+// Qt4 handler interface
+bool TQObject::eventFilter( QObject *q, QEvent *e ) {
+ return eventFilter(static_cast<TQObject*>(q), static_cast<TQEvent*>(e));
+}
+
+bool TQObject::event( QEvent *e ) {
+ return event(static_cast<TQEvent*>(e));
+}
+
+bool TQObject::checkConnectArgs(const char *signal, const TQT_BASE_OBJECT_NAME*, const char *member) {
+ return QMetaObject::checkConnectArgs(signal, member);
+}
+
+void TQObject::timerEvent(QTimerEvent *e) {
+ timerEvent(static_cast<TQTimerEvent*>(e));
+}
+
+void TQObject::childEvent(QChildEvent *e) {
+ TQT_TQOBJECT_CHILDEVENT_CONDITIONAL childEvent(static_cast<TQChildEvent*>(e));
+}
+
+void TQObject::customEvent(QEvent *e) {
+ customEvent(static_cast<TQCustomEvent*>(e));
+}
+
+// [FIXME]
+// Verify that this is truly equivalent to its Qt3 counterpart!
+void TQObject::activate_signal( int signal ) {
+ QMetaMethod method = metaObject()->method(signal);
+ method.invoke(this, Qt::QueuedConnection);
+}
+
+void TQObject::tqt_handle_qt_destroyed(QObject* obj) {
+ emit destroyed(TQT_TQOBJECT(obj));
+}
+
+bool TQObject::tqsignalsBlocked() const {
+ return signalsBlocked();
+}
+
+/*!
+ \enum Orientation
+
+ This type is used to signify an object's orientation.
+
+ \value Horizontal
+ \value Vertical
+
+ Orientation is used with TQScrollBar for example.
+*/
+
+// See http://doc.trolltech.com/4.0/porting4.html#qobject
+// [FIXME] Yet ANOTHER feature missing in Qt4...kinda gets old doesn't it?
+// Just think of having to "fix" it 50 times in the Trinity source code (without TQt), each and every time the Qt API changes!
+
+const TQObjectList *objectTrees() {
+ printf("[WARNING] static const TQObjectList *objectTrees() unimplemented\n\r");
+ return 0;
+}
+
+const TQObjectList TQObject::objectTreesListObject() {
+ printf("[WARNING] const TQObjectList *objectTreesListObject() unimplemented\n\r");
+ return TQObjectList();
+}
+
+TQObject *TQObject::tqparent() const {
+ return static_cast<TQObject*>(parent());
+}
+
+TQObjectList TQObject::childrenListObject() {
+ QObjectList qlr;
+ TQObjectList tqt_tqobject_list;
+ qlr = this->children();
+ tqt_tqobject_list.clear();
+ for (int i = 0; i < qlr.size(); ++i) {
+ tqt_tqobject_list.append(static_cast<TQObject*>(qlr.at(i)));
+ }
+ return tqt_tqobject_list;
+}
+
+const TQObjectList TQObject::childrenListObject() const {
+ QObjectList qlr;
+ TQObjectList tqt_tqobject_list;
+ qlr = this->children();
+ tqt_tqobject_list.clear();
+ for (int i = 0; i < qlr.size(); ++i) {
+ tqt_tqobject_list.append(static_cast<TQObject*>(qlr.at(i)));
+ }
+ return tqt_tqobject_list;
+}
+
+const char *TQObject::tqname() const {
+ if (dynamic_cast<const TQObject*>(static_cast<const QObject*>(this))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ if (dynamic_cast<const TQWidget*>(static_cast<const QWidget*>(static_cast<const QObject*>(this)))) {
+ return TQT_TQWIDGET_CONST(this)->tqname();
+ }
+ else if (dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))) {
+ return dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))->tqname();
+ }
+ else if (dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))) {
+ return dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))->tqname();
+ }
+ printf("[WARNING] Attempted to call TQObject::tqname() on an object without a constructed TQObject object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+const char *TQObject::name() const {
+ if (dynamic_cast<const TQObject*>(static_cast<const QObject*>(this))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ if (dynamic_cast<const TQWidget*>(static_cast<const QWidget*>(static_cast<const QObject*>(this)))) {
+ return TQT_TQWIDGET_CONST(this)->name();
+ }
+ else if (dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))) {
+ return dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))->name();
+ }
+ else if (dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))) {
+ return dynamic_cast<const TQApplication*>(static_cast<const QApplication*>(static_cast<const QObject*>(this)))->name();
+ }
+ printf("[WARNING] Attempted to call TQObject::name() on an object without a constructed TQObject object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+/*! \internal
+ TQT_BASE_OBJECT_NAME::child is compat but needs to call itself recursively,
+ that's why we need this helper.
+*/
+static TQT_BASE_OBJECT_NAME *qChildHelper(const char *objName, const char *inheritsClass,
+ bool recursiveSearch, const QObjectList &children)
+{
+ if (children.isEmpty())
+ return 0;
+
+ bool onlyWidgets = (inheritsClass && qstrcmp(inheritsClass, "QWidget") == 0);
+ const QLatin1String oName(objName);
+ for (int i = 0; i < children.size(); ++i) {
+ TQT_BASE_OBJECT_NAME *obj = children.at(i);
+ if (onlyWidgets) {
+ if (obj->isWidgetType() && (!objName || obj->objectName() == oName))
+ return obj;
+ } else if ((!inheritsClass || obj->inherits(inheritsClass))
+ && (!objName || obj->objectName() == oName))
+ return obj;
+ if (recursiveSearch && (obj = qChildHelper(objName, inheritsClass,
+ recursiveSearch, obj->children())))
+ return obj;
+ }
+ return 0;
+}
+
+TQObject *TQObject::child( const char *objName, const char *inheritsClass, bool recursiveSearch ) {
+ return static_cast<TQObject*>(qChildHelper(objName, inheritsClass, recursiveSearch, children()));
+}
+
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+/*
+ Preliminary signal spy
+ */
+TQ_EXPORT TQObject* qt_preliminary_signal_spy = 0;
+static TQObject* qt_spy_signal_sender = 0;
+
+// static void qt_spy_signal( TQObject* sender, int signal, TQUObject* o )
+// {
+// QMetaObject* mo = sender->metaObject();
+// while ( mo && signal - mo->signalOffset() < 0 )
+// mo = mo->superClass();
+// if ( !mo )
+// return;
+// const TQMetaData* sigData = mo->signal( signal - mo->signalOffset() );
+// if ( !sigData )
+// return;
+// TQCString s;
+// mo = sender->tqmetaObject();
+// while ( mo ) {
+// s.sprintf( "%s_%s", mo->className(), sigData->name );
+// int slot = qt_preliminary_signal_spy->tqmetaObject()->tqfindSlot( s, TRUE );
+// if ( slot >= 0 ) {
+// #ifdef TQT_THREAD_SUPPORT
+// // protect access to qt_spy_signal_sender
+// void * const address = &qt_spy_signal_sender;
+// TQMutexLocker locker( tqt_global_mutexpool ?
+// tqt_global_mutexpool->get( address ) : 0 );
+// #endif // TQT_THREAD_SUPPORT
+//
+// TQObject* old_sender = qt_spy_signal_sender;
+// qt_spy_signal_sender = sender;
+// qt_preliminary_signal_spy->qt_invoke( slot, o );
+// qt_spy_signal_sender = old_sender;
+// break;
+// }
+// mo = mo->superClass();
+// }
+// }
+
+/*
+ End Preliminary signal spy
+ */
+#endif // TQT_NO_PRELIMINARY_SIGNAL_SPY
+
+//
+// Remove white space from TQT_SIGNAL and TQT_SLOT names.
+// Internal for TQObject::connect() and TQObject::disconnect()
+//
+
+static inline bool isIdentChar( char x )
+{ // Avoid bug in isalnum
+ return x == '_' || (x >= '0' && x <= '9') ||
+ (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z');
+}
+
+static inline bool isSpace( char x )
+{
+#if defined(TQ_CC_BOR)
+ /*
+ Borland C++ 4.5 has a weird isspace() bug.
+ isspace() usually works, but not here.
+ This implementation is sufficient for our internal use: rmWS()
+ */
+ return (uchar) x <= 32;
+#else
+ return isspace( (uchar) x );
+#endif
+}
+
+static TQCString qt_rmWS( const char *s )
+{
+ TQCString result( tqstrlen(s)+1 );
+ char *d = result.data();
+ char last = 0;
+ while( *s && isSpace(*s) ) // skip leading space
+ s++;
+ while ( *s ) {
+ while ( *s && !isSpace(*s) )
+ last = *d++ = *s++;
+ while ( *s && isSpace(*s) )
+ s++;
+ if ( *s && isIdentChar(*s) && isIdentChar(last) )
+ last = *d++ = ' ';
+ }
+ *d = '\0';
+ result.truncate( (int)(d - result.data()) );
+ int void_pos = result.tqfind("(void)");
+ if ( void_pos >= 0 )
+ result.remove( void_pos+1, (uint)strlen("void") );
+ return result;
+}
+
+TQConnectionList *TQObject::tqreceivers( const char* signal ) const
+{
+ TQConnectionList* clist = new TQConnectionList;
+ clist->setAutoDelete( TRUE );
+ if (receivers(signal) > 0) {
+ printf("[WARNING] TQConnectionList *TQObject::tqreceivers( const char* signal ) is UNIMPLEMENTED and connected signals were detected!\n\r");
+ }
+ return clist;
+}
+
+TQConnectionList *TQObject::tqreceivers( int signal ) const
+{
+ TQConnectionList* clist = new TQConnectionList;
+ clist->setAutoDelete( TRUE );
+ printf("[WARNING] TQConnectionList *TQObject::tqreceivers( int signal ) const UNIMPLEMENTED\n\r");
+ return clist;
+}
+
+/*! \internal
+
+ Returns a list of objects/slot pairs that are connected to the
+ \a signal, or 0 if nothing is connected to it.
+*/
+
+// TQConnectionList *TQObject::tqreceivers( const char* signal ) const
+// {
+// if ( connections && signal ) {
+// if ( *signal == '2' ) { // tag == 2, i.e. signal
+// TQCString s = qt_rmWS( signal+1 );
+// return tqreceivers( metaObject()->indexOfSignal( (const char*)s ) );
+// } else {
+// return tqreceivers( metaObject()->indexOfSignal(signal ) );
+// }
+// }
+// return 0;
+// }
+
+/*! \internal
+
+ Returns a list of objects/slot pairs that are connected to the
+ signal, or 0 if nothing is connected to it.
+*/
+
+// TQConnectionList *TQObject::tqreceivers( int signal ) const
+// {
+// #ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+// if ( qt_preliminary_signal_spy && signal >= 0 ) {
+// if ( !connections ) {
+// TQObject* that = (TQObject*) this;
+// that->connections = new TQSignalVec( signal+1 );
+// that->connections->setAutoDelete( TRUE );
+// }
+// if ( !connections->at( signal ) ) {
+// TQConnectionList* clist = new TQConnectionList;
+// clist->setAutoDelete( TRUE );
+// connections->insert( signal, clist );
+// return clist;
+// }
+// }
+// #endif
+// if ( connections && signal >= 0 )
+// return connections->at( signal );
+// return 0;
+// }
+
+#if 0
+
+/*!
+ \internal
+
+ Signal activation with the most frequently used parameter/argument
+ types. All other combinations are generated by the meta object
+ compiler.
+ */
+void TQObject::activate_signal( int signal )
+{
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+ if ( qt_preliminary_signal_spy ) {
+ if ( !tqsignalsBlocked() && signal >= 0 &&
+ ( !connections || !connections->at( signal ) ) ) {
+ TQUObject o[1];
+ qt_spy_signal( this, signal, o );
+ return;
+ }
+ }
+#endif
+
+ if ( !connections || tqsignalsBlocked() || signal < 0 )
+ return;
+ TQConnectionList *clist = connections->at( signal );
+ if ( !clist )
+ return;
+ TQUObject o[1];
+ activate_signal( clist, o );
+}
+
+#endif
+
+/*! \internal */
+
+void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
+{
+ if ( !clist )
+ return;
+
+// #ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+// if ( qt_preliminary_signal_spy )
+// qt_spy_signal( this, connections->tqfindRef( clist), o );
+// #endif
+
+ TQObject *object;
+ TQSenderObjectList* sol;
+ TQObject* oldSender = 0;
+ TQConnection *c;
+ if ( clist->count() == 1 ) { // save iterator
+ c = clist->first();
+ object = c->object();
+ sol = object->senderObjects;
+ if ( sol ) {
+ oldSender = sol->currentSender;
+ sol->ref();
+ sol->currentSender = this;
+ }
+ if ( c->memberType() == TQSIGNAL_CODE ) {
+// object->qt_emit( c->member(), o );
+ QMetaMethod method = metaObject()->method(c->member());
+ method.invoke(this, Qt::QueuedConnection);
+ }
+ else {
+// object->qt_invoke( c->member(), o );
+ QMetaMethod method = metaObject()->method(c->member());
+ method.invoke(this, Qt::QueuedConnection);
+ }
+ if ( sol ) {
+ sol->currentSender = oldSender;
+ if ( sol->deref() )
+ delete sol;
+ }
+ } else {
+ TQConnection *cd = 0;
+ TQConnectionListIt it(*clist);
+ while ( (c=it.current()) ) {
+ ++it;
+ if ( c == cd )
+ continue;
+ cd = c;
+ object = c->object();
+ sol = object->senderObjects;
+ if ( sol ) {
+ oldSender = sol->currentSender;
+ sol->ref();
+ sol->currentSender = this;
+ }
+ if ( c->memberType() == TQSIGNAL_CODE ) {
+// object->qt_emit( c->member(), o );
+ QMetaMethod method = metaObject()->method(c->member());
+ method.invoke(this, Qt::QueuedConnection);
+ }
+ else {
+// object->qt_invoke( c->member(), o );
+ QMetaMethod method = metaObject()->method(c->member());
+ method.invoke(this, Qt::QueuedConnection);
+ }
+ if (sol ) {
+ sol->currentSender = oldSender;
+ if ( sol->deref() )
+ delete sol;
+ }
+ }
+ }
+}
+
+/*!
+ \overload void TQObject::activate_signal( int signal, int )
+*/
+
+/*!
+ \overload void TQObject::activate_signal( int signal, double )
+*/
+
+/*!
+ \overload void TQObject::activate_signal( int signal, TQString )
+*/
+
+/*!
+ \fn void TQObject::activate_signal_bool( int signal, bool )
+ \internal
+
+ Like the above functions, but since bool is sometimes
+ only a typedef it cannot be a simple overload.
+*/
+
+// #ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+// #define ACTIVATE_SIGNAL_WITH_PARAM(FNAME,TYPE) \
+// void TQObject::FNAME( int signal, TYPE param ) \
+// { \
+// if ( qt_preliminary_signal_spy ) { \
+// if ( !tqsignalsBlocked() && signal >= 0 && \
+// ( !connections || !connections->at( signal ) ) ) { \
+// TQUObject o[2]; \
+// static_TQUType_##TYPE.set( o+1, param ); \
+// qt_spy_signal( this, signal, o ); \
+// return; \
+// } \
+// } \
+// if ( !connections || tqsignalsBlocked() || signal < 0 ) \
+// return; \
+// TQConnectionList *clist = connections->at( signal ); \
+// if ( !clist ) \
+// return; \
+// TQUObject o[2]; \
+// static_TQUType_##TYPE.set( o+1, param ); \
+// activate_signal( clist, o ); \
+// }
+// #else
+// #define ACTIVATE_SIGNAL_WITH_PARAM(FNAME,TYPE) \
+// void TQObject::FNAME( int signal, TYPE param ) \
+// { \
+// if ( !connections || tqsignalsBlocked() || signal < 0 ) \
+// return; \
+// TQConnectionList *clist = connections->at( signal ); \
+// if ( !clist ) \
+// return; \
+// TQUObject o[2]; \
+// static_TQUType_##TYPE.set( o+1, param ); \
+// activate_signal( clist, o ); \
+// }
+//
+// #endif
+// // We don't want to duplicate too much text so...
+//
+// ACTIVATE_SIGNAL_WITH_PARAM( activate_signal, int )
+// ACTIVATE_SIGNAL_WITH_PARAM( activate_signal, double )
+// ACTIVATE_SIGNAL_WITH_PARAM( activate_signal, TQString )
+// ACTIVATE_SIGNAL_WITH_PARAM( activate_signal_bool, bool )
+
+static void objSearch( TQObjectList *result,
+ TQObjectList *list,
+ const char *inheritsClass,
+ bool onlyWidgets,
+ const char *objName,
+ TQRegExp *rx,
+ bool recurse )
+{
+ if ( !list || list->isEmpty() ) // nothing to search
+ return;
+ TQObject *obj = list->first();
+ while ( obj ) {
+ bool ok = TRUE;
+ if ( onlyWidgets )
+ ok = obj->isWidgetType();
+ else if ( inheritsClass && !obj->inherits(inheritsClass) )
+ ok = FALSE;
+ if ( ok ) {
+ if ( objName )
+ ok = ( qstrcmp(objName,obj->name()) == 0 );
+#ifndef TQT_NO_REGEXP
+ else if ( rx )
+ ok = ( rx->search(TQString::tqfromLatin1(obj->name())) != -1 );
+#endif
+ }
+ if ( ok ) // match!
+ result->append( obj );
+ if ( recurse && !obj->childrenListObject().isEmpty() ) {
+ TQObjectList tqlist = obj->childrenListObject();
+ objSearch( result, &tqlist, inheritsClass,
+ onlyWidgets, objName, rx, recurse );
+ }
+ obj = list->next();
+ }
+}
+
+/*!
+ Searches the tqchildren and optionally grandtqchildren of this object,
+ and returns a list of those objects that are named or that match
+ \a objName and inherit \a inheritsClass. If \a inheritsClass is 0
+ (the default), all classes match. If \a objName is 0 (the
+ default), all object names match.
+
+ If \a regexpMatch is TRUE (the default), \a objName is a regular
+ expression that the objects's names must match. The syntax is that
+ of a TQRegExp. If \a regexpMatch is FALSE, \a objName is a string
+ and object names must match it exactly.
+
+ Note that \a inheritsClass uses single inheritance from TQObject,
+ the way inherits() does. According to inherits(), TQMenuBar
+ inherits TQWidget but not TQMenuData. This does not quite match
+ reality, but is the best that can be done on the wide variety of
+ compilers TQt supports.
+
+ Finally, if \a recursiveSearch is TRUE (the default), queryList()
+ searches \e{n}th-generation as well as first-generation tqchildren.
+
+ If all this seems a bit complex for your needs, the simpler
+ child() function may be what you want.
+
+ This somewhat contrived example disables all the buttons in this
+ window:
+ \code
+ TQObjectList *l = tqtopLevelWidget()->queryList( "TQButton" );
+ TQObjectListIt it( *l ); // iterate over the buttons
+ TQObject *obj;
+
+ while ( (obj = it.current()) != 0 ) {
+ // for each found object...
+ ++it;
+ ((TQButton*)obj)->setEnabled( FALSE );
+ }
+ delete l; // delete the list, not the objects
+ \endcode
+
+ The TQObjectList class is defined in the \c tqobjectlist.h header
+ file.
+
+ \warning Delete the list as soon you have finished using it. The
+ list tqcontains pointers that may become invalid at almost any time
+ without notice (as soon as the user closes a window you may have
+ dangling pointers, for example).
+
+ \sa child() childrenListObject(), tqparent(), inherits(), name(), TQRegExp
+*/
+
+TQObjectList *TQObject::queryList( const char *inheritsClass,
+ const char *objName,
+ bool regexpMatch,
+ bool recursiveSearch ) const
+{
+ TQObjectList *list = new TQObjectList;
+ TQ_CHECK_PTR( list );
+ bool onlyWidgets = ( inheritsClass && qstrcmp(inheritsClass, "TQWidget") == 0 );
+#ifndef TQT_NO_REGEXP
+ if ( regexpMatch && objName ) { // regexp matching
+ TQRegExp rx(TQString::tqfromLatin1(objName));
+ TQObjectList tqlist = childrenListObject();
+ objSearch( list, &tqlist, inheritsClass, onlyWidgets,
+ 0, &rx, recursiveSearch );
+ } else
+#endif
+ {
+ TQObjectList tqlist = childrenListObject();
+ objSearch( list, &tqlist, inheritsClass, onlyWidgets,
+ objName, 0, recursiveSearch );
+ }
+ return list;
+}
+
+/*!
+ Normlizes the signal or slot definition \a signalSlot by removing
+ unnecessary whitespace.
+*/
+
+TQCString TQObject::normalizeSignalSlot( const char *signalSlot )
+{
+ if ( !signalSlot )
+ return TQCString();
+ return qt_rmWS( signalSlot );
+}
+
+TQMetaObject *TQObject::tqmetaObject() const {
+ return const_cast<TQMetaObject*>(static_cast<const TQMetaObject*>(metaObject()));
+}
+
+// TQMetaObject* TQObject::tqstaticMetaObject()
+// {
+// return const_cast<TQMetaObject*>(static_cast<const TQMetaObject*>(&TQT_BASE_OBJECT_NAME::staticMetaObject));
+// }
+
+TQMetaObject* tqstaticMetaObject_helper(const QMetaObject* mobj)
+{
+ return const_cast<TQMetaObject*>(static_cast<const TQMetaObject*>(mobj));
+}
+
+/*!
+ This virtual function receives events to an object and should
+ return TRUE if the event \a e was recognized and processed.
+
+ The event() function can be reimplemented to customize the
+ behavior of an object.
+
+ \sa installEventFilter(), timerEvent(), TQApplication::sendEvent(),
+ TQApplication::postEvent(), TQWidget::event()
+*/
+
+bool TQObject::event( TQEvent *e )
+{
+#if defined(TQT_CHECK_NULL)
+ if ( e == 0 )
+ qWarning( "TQObject::event: Null events are not permitted" );
+#endif
+// if ( eventFilters ) { // try filters
+// if ( activate_filters(e) ) // stopped by a filter
+// return TRUE;
+// }
+//
+ switch ( e->type() ) {
+// case TQEvent::Timer:
+// timerEvent( (TQTimerEvent*)e );
+// return TRUE;
+//
+// case TQEvent::DeferredDelete:
+// delete this;
+// return TRUE;
+//
+// default:
+// if ( e->type() >= TQEvent::User ) {
+// customEvent( (TQCustomEvent*) e );
+// return TRUE;
+// }
+// break;
+// }
+
+ case TQEvent::ChildInserted:
+// case TQEvent::ChildRemoved: // Causes a recursion loop if uncommented
+ childEvent( (TQChildEvent*)e );
+ return TRUE;
+
+ default:
+ return QObject::event(e);
+ }
+
+ return FALSE;
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ timer events for the object.
+
+ TQTimer provides a higher-level interface to the timer
+ functionality, and also more general information about timers.
+
+ \sa startTimer(), killTimer(), killTimers(), event()
+*/
+
+void TQObject::timerEvent( TQTimerEvent * )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ child events.
+
+ Child events are sent to objects when tqchildren are inserted or
+ removed.
+
+ Note that events with TQEvent::type() \c TQEvent::ChildInserted are
+ posted (with \l{TQApplication::postEvent()}) to make sure that the
+ child's construction is completed before this function is called.
+
+ If a child is removed immediately after it is inserted, the \c
+ ChildInserted event may be suppressed, but the \c ChildRemoved
+ event will always be sent. In such cases it is possible that there
+ will be a \c ChildRemoved event without a corresponding \c
+ ChildInserted event.
+
+ If you change state based on \c ChildInserted events, call
+ TQWidget::constPolish(), or do
+ \code
+ TQApplication::sendPostedEvents( this, TQEvent::ChildInserted );
+ \endcode
+ in functions that depend on the state. One notable example is
+ TQWidget::tqsizeHint().
+
+ \sa event(), TQChildEvent
+*/
+
+void TQObject::childEvent( TQChildEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ custom events. Custom events are user-defined events with a type
+ value at least as large as the "User" item of the \l TQEvent::Type
+ enum, and is typically a TQCustomEvent or TQCustomEvent subclass.
+
+ \sa event(), TQCustomEvent
+*/
+void TQObject::customEvent( TQCustomEvent * )
+{
+}
+
+/*!
+ Filters events if this object has been installed as an event
+ filter for the \a watched object.
+
+ In your reimplementation of this function, if you want to filter
+ the event \a e, out, i.e. stop it being handled further, return
+ TRUE; otherwise return FALSE.
+
+ Example:
+ \code
+ class MyMainWindow : public TQMainWindow
+ {
+ public:
+ MyMainWindow( TQWidget *tqparent = 0, const char *name = 0 );
+
+ protected:
+ bool eventFilter( TQObject *obj, TQEvent *ev );
+
+ private:
+ TQTextEdit *textEdit;
+ };
+
+ MyMainWindow::MyMainWindow( TQWidget *tqparent, const char *name )
+ : TQMainWindow( tqparent, name )
+ {
+ textEdit = new TQTextEdit( this );
+ setCentralWidget( textEdit );
+ textEdit->installEventFilter( this );
+ }
+
+ bool MyMainWindow::eventFilter( TQObject *obj, TQEvent *ev )
+ {
+ if ( obj == textEdit ) {
+ if ( e->type() == TQEvent::KeyPress ) {
+ TQKeyEvent *k = (TQKeyEvent*)ev;
+ qDebug( "Ate key press %d", k->key() );
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ // pass the event on to the tqparent class
+ return TQMainWindow::eventFilter( obj, ev );
+ }
+ }
+ \endcode
+
+ Notice in the example above that unhandled events are passed to
+ the base class's eventFilter() function, since the base class
+ might have reimplemented eventFilter() for its own internal
+ purposes.
+
+ \warning If you delete the receiver object in this function, be
+ sure to return TRUE. Otherwise, TQt will forward the event to the
+ deleted object and the program might crash.
+
+ \sa installEventFilter()
+*/
+
+bool TQObject::eventFilter( TQObject * /* watched */, TQEvent * /* e */ )
+{
+ return FALSE;
+}
+
+/*!
+ \relates TQObject
+
+ Returns a pointer to the object named \a name that inherits \a
+ type and with a given \a tqparent.
+
+ Returns 0 if there is no such child.
+
+ \code
+ TQListBox *c = (TQListBox *) qt_tqfind_obj_child( myWidget, "TQListBox",
+ "my list box" );
+ if ( c )
+ c->insertItem( "another string" );
+ \endcode
+*/
+
+void *qt_tqfind_obj_child( TQObject *tqparent, const char *type, const char *name )
+{
+ if ( !tqparent->childrenListObject().isEmpty() ) {
+ TQObjectListIt it( tqparent->childrenListObject() );
+ TQObject *obj;
+ while ( (obj = it.current()) ) {
+ ++it;
+ if ( qstrcmp(name,obj->name()) == 0 &&
+ obj->inherits(type) )
+ return obj;
+ }
+ }
+ return 0;
+}
+
+/*!
+ Kills all timers that this object has started.
+
+ \warning Using this function can cause hard-to-find bugs: it kills
+ timers started by sub- and superclasses as well as those started
+ by you, which is often not what you want. We recommend using a
+ TQTimer or perhaps killTimer().
+
+ \sa timerEvent(), startTimer(), killTimer()
+*/
+
+void TQObject::killTimers()
+{
+ QAbstractEventDispatcher *qed = QAbstractEventDispatcher::instance();
+ qed->unregisterTimers(this);
+}
+
+bool TQObject::isA( const char *classname ) const
+{
+ if (tqstrcmp(classname, metaObject()->className()) == 0) return true;
+ else {
+ TQString cn = metaObject()->className();
+ if (cn[0] == 'T')
+ cn = cn.remove(0,1);
+ return (tqstrcmp(classname, cn.ascii()) == 0);
+ }
+}
+
+bool TQObject::inherits( const char *classname ) const {
+ if (QObject::inherits(classname)) return true;
+ else {
+ TQString cn = classname;
+ if (cn[0] != 'T')
+ cn = cn.prepend('T');
+ return QObject::inherits(cn.ascii());
+ }
+}
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of TQObject class
+**
+** Created : 930418
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqvariant.h"
+#include "tqapplication.h"
+#include "tqobject.h"
+#include "tqobjectlist.h"
+#include "tqsignalslotimp.h"
+#include "tqregexp.h"
+#include "tqmetaobject.h"
+#include <private/tqucom_p.h>
+#include "tqucomextra_p.h"
+#include "tqptrvector.h"
+
+#ifdef TQT_THREAD_SUPPORT
+#include <tqmutex.h>
+#include <private/tqmutexpool_p.h>
+#endif
+
+#include <ctype.h>
+
+
+#ifndef TQT_NO_USERDATA
+class TQObjectPrivate : public TQPtrVector<TQObjectUserData>
+{
+public:
+ TQObjectPrivate( uint s ) : TQPtrVector<TQObjectUserData>(s){ setAutoDelete( TRUE ); }
+};
+#else
+class TQObjectPrivate {
+}
+#endif
+
+class TQSenderObjectList : public TQObjectList, public TQShared
+{
+public:
+ TQSenderObjectList() : currentSender( 0 ) { }
+ TQObject *currentSender;
+};
+
+/*!
+ \class TQt tqnamespace.h
+
+ \brief The TQt class is a namespace for miscellaneous identifiers
+ that need to be global-like.
+
+ \ingroup misc
+
+ Normally, you can ignore this class. TQObject and a few other
+ classes inherit it, so all the identifiers in the TQt namespace are
+ normally usable without qualification.
+
+ However, you may occasionally need to say \c TQt::black instead of
+ just \c black, particularly in static utility functions (such as
+ many class factories).
+
+*/
+
+/*!
+ \enum Orientation
+
+ This type is used to signify an object's orientation.
+
+ \value Horizontal
+ \value Vertical
+
+ Orientation is used with TQScrollBar for example.
+*/
+
+
+/*!
+ \class TQObject tqobject.h
+ \brief The TQObject class is the base class of all TQt objects.
+
+ \ingroup objectmodel
+ \mainclass
+ \reentrant
+
+ TQObject is the heart of the \link object.html TQt object model.
+ \endlink The central feature in this model is a very powerful
+ mechanism for seamless object communication called \link
+ Q_SIGNALSandQ_SLOTS.html Q_SIGNALS and Q_SLOTS \endlink. You can
+ connect a signal to a slot with connect() and destroy the
+ connection with disconnect(). To avoid never ending notification
+ loops you can temporarily block Q_SIGNALS with blockSignals(). The
+ protected functions connectNotify() and disconnectNotify() make it
+ possible to track connections.
+
+ TQObjects organize themselves in object trees. When you create a
+ TQObject with another object as tqparent, the object will
+ automatically do an insertChild() on the tqparent and thus show up
+ in the tqparent's childrenListObject() list. The tqparent takes ownership of the
+ object i.e. it will automatically delete its tqchildren in its
+ destructor. You can look for an object by name and optionally type
+ using child() or queryList(), and get the list of tree roots using
+ objectTrees().
+
+ Every object has an object name() and can report its className()
+ and whether it inherits() another class in the TQObject inheritance
+ hierarchy.
+
+ When an object is deleted, it emits a destroyed() signal. You can
+ catch this signal to avoid dangling references to TQObjects. The
+ TQGuardedPtr class provides an elegant way to use this feature.
+
+ TQObjects can receive events through event() and filter the events
+ of other objects. See installEventFilter() and eventFilter() for
+ details. A convenience handler, childEvent(), can be reimplemented
+ to catch child events.
+
+ Last but not least, TQObject provides the basic timer support in
+ TQt; see TQTimer for high-level support for timers.
+
+ Notice that the TQ_OBJECT macro is mandatory for any object that
+ implements Q_SIGNALS, Q_SLOTS or properties. You also need to run the
+ \link tqmoc.html tqmoc program (Meta Object Compiler) \endlink on the
+ source file. We strongly recommend the use of this macro in \e all
+ subclasses of TQObject regardless of whether or not they actually
+ use Q_SIGNALS, Q_SLOTS and properties, since failure to do so may lead
+ certain functions to exhibit undefined behaviour.
+
+ All TQt widgets inherit TQObject. The convenience function
+ isWidgetType() returns whether an object is actually a widget. It
+ is much faster than inherits( "TQWidget" ).
+
+ Some TQObject functions, e.g. childrenListObject(), objectTrees() and
+ queryList() return a TQObjectList. A TQObjectList is a TQPtrList of
+ TQObjects. TQObjectLists support the same operations as TQPtrLists
+ and have an iterator class, TQObjectListIt.
+*/
+
+
+//
+// Remove white space from TQT_SIGNAL and TQT_SLOT names.
+// Internal for TQObject::connect() and TQObject::disconnect()
+//
+
+static inline bool isIdentChar( char x )
+{ // Avoid bug in isalnum
+ return x == '_' || (x >= '0' && x <= '9') ||
+ (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z');
+}
+
+static inline bool isSpace( char x )
+{
+#if defined(TQ_CC_BOR)
+ /*
+ Borland C++ 4.5 has a weird isspace() bug.
+ isspace() usually works, but not here.
+ This implementation is sufficient for our internal use: rmWS()
+ */
+ return (uchar) x <= 32;
+#else
+ return isspace( (uchar) x );
+#endif
+}
+
+static TQCString qt_rmWS( const char *s )
+{
+ TQCString result( tqstrlen(s)+1 );
+ char *d = result.data();
+ char last = 0;
+ while( *s && isSpace(*s) ) // skip leading space
+ s++;
+ while ( *s ) {
+ while ( *s && !isSpace(*s) )
+ last = *d++ = *s++;
+ while ( *s && isSpace(*s) )
+ s++;
+ if ( *s && isIdentChar(*s) && isIdentChar(last) )
+ last = *d++ = ' ';
+ }
+ *d = '\0';
+ result.truncate( (int)(d - result.data()) );
+ int void_pos = result.tqfind("(void)");
+ if ( void_pos >= 0 )
+ result.remove( void_pos+1, (uint)strlen("void") );
+ return result;
+}
+
+
+// Event functions, implemented in qapplication_xxx.cpp
+
+int qStartTimer( int interval, TQObject *obj );
+bool qKillTimer( int id );
+bool qKillTimer( TQObject *obj );
+
+static void removeObjFromList( TQObjectList *objList, const TQObject *obj,
+ bool single=FALSE )
+{
+ if ( !objList )
+ return;
+ int index = objList->tqfindRef( obj );
+ while ( index >= 0 ) {
+ objList->remove();
+ if ( single )
+ return;
+ index = objList->tqfindNextRef( obj );
+ }
+}
+
+
+/*!
+ \relates TQObject
+
+ Returns a pointer to the object named \a name that inherits \a
+ type and with a given \a tqparent.
+
+ Returns 0 if there is no such child.
+
+ \code
+ TQListBox *c = (TQListBox *) qt_tqfind_obj_child( myWidget, "TQListBox",
+ "my list box" );
+ if ( c )
+ c->insertItem( "another string" );
+ \endcode
+*/
+
+void *qt_tqfind_obj_child( TQObject *tqparent, const char *type, const char *name )
+{
+ if ( !tqparent->childrenListObject().isEmpty() ) {
+ TQObjectListIt it( tqparent->childrenListObject() );
+ TQObject *obj;
+ while ( (obj = it.current()) ) {
+ ++it;
+ if ( qstrcmp(name,obj->name()) == 0 &&
+ obj->inherits(type) )
+ return obj;
+ }
+ }
+ return 0;
+}
+
+
+
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+/*
+ Preliminary signal spy
+ */
+TQ_EXPORT TQObject* qt_preliminary_signal_spy = 0;
+static TQObject* qt_spy_signal_sender = 0;
+
+static void qt_spy_signal( TQObject* sender, int signal, TQUObject* o )
+{
+ TQMetaObject* mo = sender->tqmetaObject();
+ while ( mo && signal - mo->signalOffset() < 0 )
+ mo = mo->superClass();
+ if ( !mo )
+ return;
+ const TQMetaData* sigData = mo->signal( signal - mo->signalOffset() );
+ if ( !sigData )
+ return;
+ TQCString s;
+ mo = sender->tqmetaObject();
+ while ( mo ) {
+ s.sprintf( "%s_%s", mo->className(), sigData->name );
+ int slot = qt_preliminary_signal_spy->tqmetaObject()->tqfindSlot( s, TRUE );
+ if ( slot >= 0 ) {
+#ifdef TQT_THREAD_SUPPORT
+ // protect access to qt_spy_signal_sender
+ void * const address = &qt_spy_signal_sender;
+ TQMutexLocker locker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( address ) : 0 );
+#endif // TQT_THREAD_SUPPORT
+
+ TQObject* old_sender = qt_spy_signal_sender;
+ qt_spy_signal_sender = sender;
+ qt_preliminary_signal_spy->qt_invoke( slot, o );
+ qt_spy_signal_sender = old_sender;
+ break;
+ }
+ mo = mo->superClass();
+ }
+}
+
+/*
+ End Preliminary signal spy
+ */
+#endif // TQT_NO_PRELIMINARY_SIGNAL_SPY
+
+static TQObjectList* object_trees = 0;
+
+#ifdef TQT_THREAD_SUPPORT
+static TQMutex *obj_trees_mutex = 0;
+#endif
+
+static void cleanup_object_trees()
+{
+ delete object_trees;
+ object_trees = 0;
+#ifdef TQT_THREAD_SUPPORT
+ delete obj_trees_mutex;
+ obj_trees_mutex = 0;
+#endif
+}
+
+static void ensure_object_trees()
+{
+ object_trees = new TQObjectList;
+ qAddPostRoutine( cleanup_object_trees );
+}
+
+static void insert_tree( TQObject* obj )
+{
+#ifdef TQT_THREAD_SUPPORT
+ if ( !obj_trees_mutex )
+ obj_trees_mutex = new TQMutex();
+ TQMutexLocker locker( obj_trees_mutex );
+#endif
+ if ( !object_trees )
+ ensure_object_trees();
+ object_trees->insert(0, obj );
+}
+
+static void remove_tree( TQObject* obj )
+{
+ if ( object_trees ) {
+#ifdef TQT_THREAD_SUPPORT
+ TQMutexLocker locker( obj_trees_mutex );
+#endif
+ object_trees->removeRef( obj );
+ }
+}
+
+
+/*****************************************************************************
+ TQObject member functions
+ *****************************************************************************/
+
+/*!
+ Constructs an object called \a name with tqparent object, \a tqparent.
+
+ The tqparent of an object may be viewed as the object's owner. For
+ instance, a \link TQDialog dialog box\endlink is the tqparent of the
+ "OK" and "Cancel" buttons it tqcontains.
+
+ The destructor of a tqparent object destroys all child objects.
+
+ Setting \a tqparent to 0 constructs an object with no tqparent. If the
+ object is a widget, it will become a top-level window.
+
+ The object name is some text that can be used to identify a
+ TQObject. It's particularly useful in conjunction with \link
+ designer-manual.book <i>TQt Designer</i>\endlink. You can tqfind an
+ object by name (and type) using child(). To tqfind several objects
+ use queryList().
+
+ \sa tqparent(), name(), child(), queryList()
+*/
+
+TQObject::TQObject( TQObject *tqparent, const char *name )
+ :
+ isSignal( FALSE ), // assume not a signal object
+ isWidget( FALSE ), // assume not a widget object
+ pendTimer( FALSE ), // no timers yet
+ blockSig( FALSE ), // not blocking Q_SIGNALS
+ wasDeleted( FALSE ), // double-delete catcher
+ isTree( FALSE ), // no tree yet
+ objname( name ? qstrdup(name) : 0 ), // set object name
+ parentObj( 0 ), // no tqparent yet. It is set by insertChild()
+ childObjects( 0 ), // no tqchildren yet
+ connections( 0 ), // no connections yet
+ senderObjects( 0 ), // no Q_SIGNALS connected yet
+ eventFilters( 0 ), // no filters installed
+ postedEvents( 0 ), // no events posted
+ d( 0 )
+{
+ if ( !metaObj ) // will create object dict
+ (void) staticMetaObject();
+
+ if ( tqparent ) { // add object to tqparent
+ tqparent->insertChild( this );
+ } else {
+ insert_tree( this );
+ isTree = TRUE;
+ }
+}
+
+
+/*!
+ Destroys the object, deleting all its child objects.
+
+ All Q_SIGNALS to and from the object are automatically disconnected.
+
+ \warning All child objects are deleted. If any of these objects
+ are on the stack or global, sooner or later your program will
+ crash. We do not recommend holding pointers to child objects from
+ outside the tqparent. If you still do, the TQObject::destroyed()
+ signal gives you an opportunity to detect when an object is
+ destroyed.
+
+ \warning Deleting a TQObject while pending events are waiting to be
+ delivered can cause a crash. You must not delete the TQObject
+ directly from a thread that is not the GUI thread. Use the
+ TQObject::deleteLater() method instead, which will cause the event
+ loop to delete the object after all pending events have been
+ delivered to the object.
+*/
+
+TQObject::~TQObject()
+{
+ if ( wasDeleted ) {
+#if defined(TQT_DEBUG)
+ qWarning( "Double TQObject deletion detected." );
+#endif
+ return;
+ }
+ wasDeleted = 1;
+ blockSig = 0; // unblock Q_SIGNALS to keep TQGuardedPtr happy
+ emit destroyed( this );
+ emit destroyed();
+ if ( objname )
+ delete [] (char*)objname;
+ objname = 0;
+ if ( pendTimer ) // might be pending timers
+ qKillTimer( this );
+ TQApplication::removePostedEvents( this );
+ if ( isTree ) {
+ remove_tree( this ); // remove from global root list
+ isTree = FALSE;
+ }
+ if ( parentObj ) // remove it from tqparent object
+ parentObj->removeChild( this );
+ register TQObject *obj;
+ if ( senderObjects ) { // disconnect from senders
+ TQSenderObjectList *tmp = senderObjects;
+ senderObjects = 0;
+ obj = tmp->first();
+ while ( obj ) { // for all senders...
+ obj->disconnect( this );
+ obj = tmp->next();
+ }
+ if ( tmp->deref() )
+ delete tmp;
+ }
+ if ( connections ) { // disconnect tqreceivers
+ for ( int i = 0; i < (int) connections->size(); i++ ) {
+ TQConnectionList* clist = (*connections)[i]; // for each signal...
+ if ( !clist )
+ continue;
+ register TQConnection *c;
+ TQConnectionListIt cit(*clist);
+ while( (c=cit.current()) ) { // for each connected slot...
+ ++cit;
+ if ( (obj=c->object()) )
+ removeObjFromList( obj->senderObjects, this );
+ }
+ }
+ delete connections;
+ connections = 0;
+ }
+ if ( eventFilters ) {
+ delete eventFilters;
+ eventFilters = 0;
+ }
+ if ( childObjects ) { // delete tqchildren objects
+ TQObjectListIt it(*childObjects);
+ while ( (obj=it.current()) ) {
+ ++it;
+ obj->parentObj = 0;
+ childObjects->removeRef( obj );
+ delete obj;
+ }
+ delete childObjects;
+ }
+
+ delete d;
+}
+
+
+/*!
+ \fn TQMetaObject *TQObject::tqmetaObject() const
+
+ Returns a pointer to the meta object of this object.
+
+ A meta object tqcontains information about a class that inherits
+ TQObject, e.g. class name, superclass name, properties, Q_SIGNALS and
+ Q_SLOTS. Every class that tqcontains the TQ_OBJECT macro will also have
+ a meta object.
+
+ The meta object information is required by the signal/slot
+ connection mechanism and the property system. The functions isA()
+ and inherits() also make use of the meta object.
+*/
+
+/*!
+ \fn const char *TQObject::className() const
+
+ Returns the class name of this object.
+
+ This function is generated by the \link metaobjects.html Meta
+ Object Compiler. \endlink
+
+ \warning This function will return the wrong name if the class
+ definition lacks the TQ_OBJECT macro.
+
+ \sa name(), inherits(), isA(), isWidgetType()
+*/
+
+/*!
+ Returns TRUE if this object is an instance of the class \a clname;
+ otherwise returns FALSE.
+
+ Example:
+ \code
+ TQTimer *t = new TQTimer; // TQTimer inherits TQObject
+ t->isA( "TQTimer" ); // returns TRUE
+ t->isA( "TQObject" ); // returns FALSE
+ \endcode
+
+ \sa inherits() tqmetaObject()
+*/
+
+bool TQObject::isA( const char *clname ) const
+{
+ return qstrcmp( clname, className() ) == 0;
+}
+
+/*!
+ Returns TRUE if this object is an instance of a class that
+ inherits \a clname, and \a clname inherits TQObject; otherwise
+ returns FALSE.
+
+ A class is considered to inherit itself.
+
+ Example:
+ \code
+ TQTimer *t = new TQTimer; // TQTimer inherits TQObject
+ t->inherits( "TQTimer" ); // returns TRUE
+ t->inherits( "TQObject" ); // returns TRUE
+ t->inherits( "TQButton" ); // returns FALSE
+
+ // TQScrollBar inherits TQWidget and TQRangeControl
+ TQScrollBar *s = new TQScrollBar( 0 );
+ s->inherits( "TQWidget" ); // returns TRUE
+ s->inherits( "TQRangeControl" ); // returns FALSE
+ \endcode
+
+ (\l TQRangeControl is not a TQObject.)
+
+ \sa isA(), tqmetaObject()
+*/
+
+bool TQObject::inherits( const char *clname ) const
+{
+ return tqmetaObject()->inherits( clname );
+}
+
+/*!
+ \internal
+
+ Returns TRUE if \a object inherits \a superClass within
+ the meta object inheritance chain; otherwise returns FALSE.
+
+ \sa inherits()
+*/
+void *qt_inheritedBy( TQMetaObject *superClass, const TQObject *object )
+{
+ if (!object)
+ return 0;
+ register TQMetaObject *mo = object->tqmetaObject();
+ while (mo) {
+ if (mo == superClass)
+ return (void*)object;
+ mo = mo->superClass();
+ }
+ return 0;
+}
+
+/*!
+ \property TQObject::name
+
+ \brief the name of this object
+
+ You can tqfind an object by name (and type) using child(). You can
+ tqfind a set of objects with queryList().
+
+ The object name is set by the constructor or by the setName()
+ function. The object name is not very useful in the current
+ version of TQt, but will become increasingly important in the
+ future.
+
+ If the object does not have a name, the name() function returns
+ "unnamed", so printf() (used in qDebug()) will not be asked to
+ output a null pointer. If you want a null pointer to be returned
+ for unnamed objects, you can call name( 0 ).
+
+ \code
+ qDebug( "MyClass::setPrecision(): (%s) invalid precision %f",
+ name(), newPrecision );
+ \endcode
+
+ \sa className(), child(), queryList()
+*/
+
+const char * TQObject::name() const
+{
+ // If you change the name here, the builder will be broken
+ return objname ? objname : "unnamed";
+}
+
+/*!
+ Sets the object's name to \a name.
+*/
+void TQObject::setName( const char *name )
+{
+ if ( objname )
+ delete [] (char*) objname;
+ objname = name ? qstrdup(name) : 0;
+}
+
+/*!
+ \overload
+
+ Returns the name of this object, or \a defaultName if the object
+ does not have a name.
+*/
+
+const char * TQObject::name( const char * defaultName ) const
+{
+ return objname ? objname : defaultName;
+}
+
+
+/*!
+ Searches the tqchildren and optionally grandtqchildren of this object,
+ and returns a child that is called \a objName that inherits \a
+ inheritsClass. If \a inheritsClass is 0 (the default), any class
+ matches.
+
+ If \a recursiveSearch is TRUE (the default), child() performs a
+ depth-first search of the object's tqchildren.
+
+ If there is no such object, this function returns 0. If there are
+ more than one, the first one found is retured; if you need all of
+ them, use queryList().
+*/
+TQObject* TQObject::child( const char *objName, const char *inheritsClass,
+ bool recursiveSearch )
+{
+ if ( childrenListObject().isEmpty() )
+ return 0;
+
+ bool onlyWidgets = ( inheritsClass && qstrcmp( inheritsClass, "TQWidget" ) == 0 );
+ TQObjectListIt it( childrenListObject() );
+ TQObject *obj;
+ while ( ( obj = it.current() ) ) {
+ ++it;
+ if ( onlyWidgets ) {
+ if ( obj->isWidgetType() && ( !objName || qstrcmp( objName, obj->name() ) == 0 ) )
+ break;
+ } else if ( ( !inheritsClass || obj->inherits(inheritsClass) ) && ( !objName || qstrcmp( objName, obj->name() ) == 0 ) )
+ break;
+ if ( recursiveSearch && (obj = obj->child( objName, inheritsClass, recursiveSearch ) ) )
+ break;
+ }
+ return obj;
+}
+
+/*!
+ \fn bool TQObject::isWidgetType() const
+
+ Returns TRUE if the object is a widget; otherwise returns FALSE.
+
+ Calling this function is equivalent to calling
+ inherits("TQWidget"), except that it is much faster.
+*/
+
+/*!
+ \fn bool TQObject::highPriority() const
+
+ Returns TRUE if the object is a high-priority object, or FALSE if
+ it is a standard-priority object.
+
+ High-priority objects are placed first in TQObject's list of
+ tqchildren on the assumption that they will be referenced very
+ often.
+*/
+
+
+/*!
+ This virtual function receives events to an object and should
+ return TRUE if the event \a e was recognized and processed.
+
+ The event() function can be reimplemented to customize the
+ behavior of an object.
+
+ \sa installEventFilter(), timerEvent(), TQApplication::sendEvent(),
+ TQApplication::postEvent(), TQWidget::event()
+*/
+
+bool TQObject::event( TQEvent *e )
+{
+#if defined(TQT_CHECK_NULL)
+ if ( e == 0 )
+ qWarning( "TQObject::event: Null events are not permitted" );
+#endif
+ if ( eventFilters ) { // try filters
+ if ( activate_filters(e) ) // stopped by a filter
+ return TRUE;
+ }
+
+ switch ( e->type() ) {
+ case TQEvent::Timer:
+ timerEvent( (TQTimerEvent*)e );
+ return TRUE;
+
+ case TQEvent::ChildInserted:
+ case TQEvent::ChildRemoved:
+ childEvent( (TQChildEvent*)e );
+ return TRUE;
+
+ case TQEvent::DeferredDelete:
+ delete this;
+ return TRUE;
+
+ default:
+ if ( e->type() >= TQEvent::User ) {
+ customEvent( (TQCustomEvent*) e );
+ return TRUE;
+ }
+ break;
+ }
+ return FALSE;
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ timer events for the object.
+
+ TQTimer provides a higher-level interface to the timer
+ functionality, and also more general information about timers.
+
+ \sa startTimer(), killTimer(), killTimers(), event()
+*/
+
+void TQObject::timerEvent( TQTimerEvent * )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ child events.
+
+ Child events are sent to objects when tqchildren are inserted or
+ removed.
+
+ Note that events with TQEvent::type() \c TQEvent::ChildInserted are
+ posted (with \l{TQApplication::postEvent()}) to make sure that the
+ child's construction is completed before this function is called.
+
+ If a child is removed immediately after it is inserted, the \c
+ ChildInserted event may be suppressed, but the \c ChildRemoved
+ event will always be sent. In such cases it is possible that there
+ will be a \c ChildRemoved event without a corresponding \c
+ ChildInserted event.
+
+ If you change state based on \c ChildInserted events, call
+ TQWidget::constPolish(), or do
+ \code
+ TQApplication::sendPostedEvents( this, TQEvent::ChildInserted );
+ \endcode
+ in functions that depend on the state. One notable example is
+ TQWidget::tqsizeHint().
+
+ \sa event(), TQChildEvent
+*/
+
+void TQObject::childEvent( TQChildEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ custom events. Custom events are user-defined events with a type
+ value at least as large as the "User" item of the \l TQEvent::Type
+ enum, and is typically a TQCustomEvent or TQCustomEvent subclass.
+
+ \sa event(), TQCustomEvent
+*/
+void TQObject::customEvent( TQCustomEvent * )
+{
+}
+
+
+
+/*!
+ Filters events if this object has been installed as an event
+ filter for the \a watched object.
+
+ In your reimplementation of this function, if you want to filter
+ the event \a e, out, i.e. stop it being handled further, return
+ TRUE; otherwise return FALSE.
+
+ Example:
+ \code
+ class MyMainWindow : public TQMainWindow
+ {
+ public:
+ MyMainWindow( TQWidget *tqparent = 0, const char *name = 0 );
+
+ protected:
+ bool eventFilter( TQObject *obj, TQEvent *ev );
+
+ private:
+ TQTextEdit *textEdit;
+ };
+
+ MyMainWindow::MyMainWindow( TQWidget *tqparent, const char *name )
+ : TQMainWindow( tqparent, name )
+ {
+ textEdit = new TQTextEdit( this );
+ setCentralWidget( textEdit );
+ textEdit->installEventFilter( this );
+ }
+
+ bool MyMainWindow::eventFilter( TQObject *obj, TQEvent *ev )
+ {
+ if ( obj == textEdit ) {
+ if ( e->type() == TQEvent::KeyPress ) {
+ TQKeyEvent *k = (TQKeyEvent*)ev;
+ qDebug( "Ate key press %d", k->key() );
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ // pass the event on to the tqparent class
+ return TQMainWindow::eventFilter( obj, ev );
+ }
+ }
+ \endcode
+
+ Notice in the example above that unhandled events are passed to
+ the base class's eventFilter() function, since the base class
+ might have reimplemented eventFilter() for its own internal
+ purposes.
+
+ \warning If you delete the receiver object in this function, be
+ sure to return TRUE. Otherwise, TQt will forward the event to the
+ deleted object and the program might crash.
+
+ \sa installEventFilter()
+*/
+
+bool TQObject::eventFilter( TQObject * /* watched */, TQEvent * /* e */ )
+{
+ return FALSE;
+}
+
+
+/*!
+ \internal
+ Activates all event filters for this object.
+ This function is normally called from TQObject::event() or TQWidget::event().
+*/
+
+bool TQObject::activate_filters( TQEvent *e )
+{
+ if ( !eventFilters ) // no event filter
+ return FALSE;
+ TQObjectListIt it( *eventFilters );
+ register TQObject *obj = it.current();
+ while ( obj ) { // send to all filters
+ ++it; // until one returns TRUE
+ if ( obj->eventFilter(this,e) ) {
+ return TRUE;
+ }
+ obj = it.current();
+ }
+ return FALSE; // don't do anything with it
+}
+
+
+/*!
+ \fn bool TQObject::tqsignalsBlocked() const
+
+ Returns TRUE if Q_SIGNALS are blocked; otherwise returns FALSE.
+
+ Signals are not blocked by default.
+
+ \sa blockSignals()
+*/
+
+/*!
+ Blocks Q_SIGNALS if \a block is TRUE, or unblocks Q_SIGNALS if \a
+ block is FALSE.
+
+ Emitted Q_SIGNALS disappear into hyperspace if Q_SIGNALS are blocked.
+ Note that the destroyed() Q_SIGNALS will be emitted even if the Q_SIGNALS
+ for this object have been blocked.
+*/
+
+void TQObject::blockSignals( bool block )
+{
+ blockSig = block;
+}
+
+
+//
+// The timer flag hasTimer is set when startTimer is called.
+// It is not reset when killing the timer because more than
+// one timer might be active.
+//
+
+/*!
+ Starts a timer and returns a timer identifier, or returns zero if
+ it could not start a timer.
+
+ A timer event will occur every \a interval milliseconds until
+ killTimer() or killTimers() is called. If \a interval is 0, then
+ the timer event occurs once every time there are no more window
+ system events to process.
+
+ The virtual timerEvent() function is called with the TQTimerEvent
+ event parameter class when a timer event occurs. Reimplement this
+ function to get timer events.
+
+ If multiple timers are running, the TQTimerEvent::timerId() can be
+ used to tqfind out which timer was activated.
+
+ Example:
+ \code
+ class MyObject : public TQObject
+ {
+ TQ_OBJECT
+ public:
+ MyObject( TQObject *tqparent = 0, const char *name = 0 );
+
+ protected:
+ void timerEvent( TQTimerEvent * );
+ };
+
+ MyObject::MyObject( TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name )
+ {
+ startTimer( 50 ); // 50-millisecond timer
+ startTimer( 1000 ); // 1-second timer
+ startTimer( 60000 ); // 1-minute timer
+ }
+
+ void MyObject::timerEvent( TQTimerEvent *e )
+ {
+ qDebug( "timer event, id %d", e->timerId() );
+ }
+ \endcode
+
+ Note that TQTimer's accuracy depends on the underlying operating
+ system and hardware. Most platforms support an accuracy of 20 ms;
+ some provide more. If TQt is unable to deliver the requested
+ number of timer clicks, it will silently discard some.
+
+ The TQTimer class provides a high-level programming interface with
+ one-shot timers and timer Q_SIGNALS instead of events.
+
+ \sa timerEvent(), killTimer(), killTimers(), TQEventLoop::awake(),
+ TQEventLoop::aboutToBlock()
+*/
+
+int TQObject::startTimer( int interval )
+{
+ pendTimer = TRUE; // set timer flag
+ return qStartTimer( interval, (TQObject *)this );
+}
+
+/*!
+ Kills the timer with timer identifier, \a id.
+
+ The timer identifier is returned by startTimer() when a timer
+ event is started.
+
+ \sa timerEvent(), startTimer(), killTimers()
+*/
+
+void TQObject::killTimer( int id )
+{
+ qKillTimer( id );
+}
+
+/*!
+ Kills all timers that this object has started.
+
+ \warning Using this function can cause hard-to-tqfind bugs: it kills
+ timers started by sub- and superclasses as well as those started
+ by you, which is often not what you want. We recommend using a
+ TQTimer or perhaps killTimer().
+
+ \sa timerEvent(), startTimer(), killTimer()
+*/
+
+void TQObject::killTimers()
+{
+ qKillTimer( this );
+}
+
+static void objSearch( TQObjectList *result,
+ TQObjectList *list,
+ const char *inheritsClass,
+ bool onlyWidgets,
+ const char *objName,
+ TQRegExp *rx,
+ bool recurse )
+{
+ if ( !list || list->isEmpty() ) // nothing to search
+ return;
+ TQObject *obj = list->first();
+ while ( obj ) {
+ bool ok = TRUE;
+ if ( onlyWidgets )
+ ok = obj->isWidgetType();
+ else if ( inheritsClass && !obj->inherits(inheritsClass) )
+ ok = FALSE;
+ if ( ok ) {
+ if ( objName )
+ ok = ( qstrcmp(objName,obj->name()) == 0 );
+#ifndef TQT_NO_REGEXP
+ else if ( rx )
+ ok = ( rx->search(TQString::tqfromLatin1(obj->name())) != -1 );
+#endif
+ }
+ if ( ok ) // match!
+ result->append( obj );
+ if ( recurse && !obj->childrenListObject().isEmpty ) {
+ TQObjectList tqlist = obj->childrenListObject();
+ objSearch( result, &tqlist, inheritsClass,
+ onlyWidgets, objName, rx, recurse );
+ }
+ obj = list->next();
+ }
+}
+
+/*!
+ \fn TQObject *TQObject::tqparent() const
+
+ Returns a pointer to the tqparent object.
+
+ \sa childrenListObject()
+*/
+
+/*!
+ \fn const TQObjectList *TQObject::childrenListObject() const
+
+ Returns a list of child objects, or 0 if this object has no
+ tqchildren.
+
+ The TQObjectList class is defined in the \c tqobjectlist.h header
+ file.
+
+ The first child added is the \link TQPtrList::first() first\endlink
+ object in the list and the last child added is the \link
+ TQPtrList::last() last\endlink object in the list, i.e. new
+ tqchildren are appended at the end.
+
+ Note that the list order changes when TQWidget tqchildren are \link
+ TQWidget::raise() raised\endlink or \link TQWidget::lower()
+ lowered.\endlink A widget that is raised becomes the last object
+ in the list, and a widget that is lowered becomes the first object
+ in the list.
+
+ \sa child(), queryList(), tqparent(), insertChild(), removeChild()
+*/
+
+
+/*!
+ Returns a pointer to the list of all object trees (their root
+ objects), or 0 if there are no objects.
+
+ The TQObjectList class is defined in the \c tqobjectlist.h header
+ file.
+
+ The most recent root object created is the \link TQPtrList::first()
+ first\endlink object in the list and the first root object added
+ is the \link TQPtrList::last() last\endlink object in the list.
+
+ \sa childrenListObject(), tqparent(), insertChild(), removeChild()
+*/
+const TQObjectList *TQObject::objectTrees()
+{
+ return object_trees;
+}
+
+
+/*!
+ Searches the tqchildren and optionally grandtqchildren of this object,
+ and returns a list of those objects that are named or that match
+ \a objName and inherit \a inheritsClass. If \a inheritsClass is 0
+ (the default), all classes match. If \a objName is 0 (the
+ default), all object names match.
+
+ If \a regexpMatch is TRUE (the default), \a objName is a regular
+ expression that the objects's names must match. The syntax is that
+ of a TQRegExp. If \a regexpMatch is FALSE, \a objName is a string
+ and object names must match it exactly.
+
+ Note that \a inheritsClass uses single inheritance from TQObject,
+ the way inherits() does. According to inherits(), TQMenuBar
+ inherits TQWidget but not TQMenuData. This does not quite match
+ reality, but is the best that can be done on the wide variety of
+ compilers TQt supports.
+
+ Finally, if \a recursiveSearch is TRUE (the default), queryList()
+ searches \e{n}th-generation as well as first-generation tqchildren.
+
+ If all this seems a bit complex for your needs, the simpler
+ child() function may be what you want.
+
+ This somewhat contrived example disables all the buttons in this
+ window:
+ \code
+ TQObjectList *l = tqtopLevelWidget()->queryList( "TQButton" );
+ TQObjectListIt it( *l ); // iterate over the buttons
+ TQObject *obj;
+
+ while ( (obj = it.current()) != 0 ) {
+ // for each found object...
+ ++it;
+ ((TQButton*)obj)->setEnabled( FALSE );
+ }
+ delete l; // delete the list, not the objects
+ \endcode
+
+ The TQObjectList class is defined in the \c tqobjectlist.h header
+ file.
+
+ \warning Delete the list as soon you have finished using it. The
+ list tqcontains pointers that may become invalid at almost any time
+ without notice (as soon as the user closes a window you may have
+ dangling pointers, for example).
+
+ \sa child() childrenListObject(), tqparent(), inherits(), name(), TQRegExp
+*/
+
+TQObjectList *TQObject::queryList( const char *inheritsClass,
+ const char *objName,
+ bool regexpMatch,
+ bool recursiveSearch ) const
+{
+ TQObjectList *list = new TQObjectList;
+ TQ_CHECK_PTR( list );
+ bool onlyWidgets = ( inheritsClass && qstrcmp(inheritsClass, "TQWidget") == 0 );
+#ifndef TQT_NO_REGEXP
+ if ( regexpMatch && objName ) { // regexp matching
+ TQRegExp rx(TQString::tqfromLatin1(objName));
+ TQObjectList tqlist = childrenListObject();
+ objSearch( list, &tqlist, inheritsClass, onlyWidgets,
+ 0, &rx, recursiveSearch );
+ } else
+#endif
+ {
+ TQObjectList tqlist = childrenListObject();
+ objSearch( list, &tqlist, inheritsClass, onlyWidgets,
+ objName, 0, recursiveSearch );
+ }
+ return list;
+}
+
+/*! \internal
+
+ Returns a list of objects/slot pairs that are connected to the
+ \a signal, or 0 if nothing is connected to it.
+*/
+
+TQConnectionList *TQObject::tqreceivers( const char* signal ) const
+{
+ if ( connections && signal ) {
+ if ( *signal == '2' ) { // tag == 2, i.e. signal
+ TQCString s = qt_rmWS( signal+1 );
+ return tqreceivers( tqmetaObject()->tqfindSignal( (const char*)s, TRUE ) );
+ } else {
+ return tqreceivers( tqmetaObject()->tqfindSignal(signal, TRUE ) );
+ }
+ }
+ return 0;
+}
+
+/*! \internal
+
+ Returns a list of objects/slot pairs that are connected to the
+ signal, or 0 if nothing is connected to it.
+*/
+
+TQConnectionList *TQObject::tqreceivers( int signal ) const
+{
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+ if ( qt_preliminary_signal_spy && signal >= 0 ) {
+ if ( !connections ) {
+ TQObject* that = (TQObject*) this;
+ that->connections = new TQSignalVec( signal+1 );
+ that->connections->setAutoDelete( TRUE );
+ }
+ if ( !connections->at( signal ) ) {
+ TQConnectionList* clist = new TQConnectionList;
+ clist->setAutoDelete( TRUE );
+ connections->insert( signal, clist );
+ return clist;
+ }
+ }
+#endif
+ if ( connections && signal >= 0 )
+ return connections->at( signal );
+ return 0;
+}
+
+
+/*!
+ Inserts an object \a obj into the list of child objects.
+
+ \warning This function cannot be used to make one widget the child
+ widget of another widget. Child widgets can only be created by
+ setting the tqparent widget in the constructor or by calling
+ TQWidget::reparent().
+
+ \sa removeChild(), TQWidget::reparent()
+*/
+
+void TQObject::insertChild( TQObject *obj )
+{
+ if ( obj->isTree ) {
+ remove_tree( obj );
+ obj->isTree = FALSE;
+ }
+ if ( obj->parentObj && obj->parentObj != this ) {
+#if defined(TQT_CHECK_STATE)
+ if ( obj->parentObj != this && obj->isWidgetType() )
+ qWarning( "TQObject::insertChild: Cannot reparent a widget, "
+ "use TQWidget::reparent() instead" );
+#endif
+ obj->parentObj->removeChild( obj );
+ }
+
+ if ( !childObjects ) {
+ childObjects = new TQObjectList;
+ TQ_CHECK_PTR( childObjects );
+ } else if ( obj->parentObj == this ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQObject::insertChild: Object %s::%s already in list",
+ obj->className(), obj->name( "unnamed" ) );
+#endif
+ return;
+ }
+ obj->parentObj = this;
+ childObjects->append( obj );
+
+ TQChildEvent *e = new TQChildEvent( TQEvent::ChildInserted, obj );
+ TQApplication::postEvent( this, e );
+}
+
+/*!
+ Removes the child object \a obj from the list of tqchildren.
+
+ \warning This function will not remove a child widget from the
+ screen. It will only remove it from the tqparent widget's list of
+ tqchildren.
+
+ \sa insertChild(), TQWidget::reparent()
+*/
+
+void TQObject::removeChild( TQObject *obj )
+{
+ if ( childObjects && childObjects->removeRef(obj) ) {
+ obj->parentObj = 0;
+ if ( !obj->wasDeleted ) {
+ insert_tree( obj ); // it's a root object now
+ obj->isTree = TRUE;
+ }
+ if ( childObjects->isEmpty() ) {
+ delete childObjects; // last child removed
+ childObjects = 0; // reset tqchildren list
+ }
+
+ // remove events must be sent, not posted!!!
+ TQChildEvent ce( TQEvent::ChildRemoved, obj );
+ TQApplication::sendEvent( this, &ce );
+ }
+}
+
+
+/*!
+ \fn void TQObject::installEventFilter( const TQObject *filterObj )
+
+ Installs an event filter \a filterObj on this object. For example:
+ \code
+ monitoredObj->installEventFilter( filterObj );
+ \endcode
+
+ An event filter is an object that receives all events that are
+ sent to this object. The filter can either stop the event or
+ forward it to this object. The event filter \a filterObj receives
+ events via its eventFilter() function. The eventFilter() function
+ must return TRUE if the event should be filtered, (i.e. stopped);
+ otherwise it must return FALSE.
+
+ If multiple event filters are installed on a single object, the
+ filter that was installed last is activated first.
+
+ Here's a \c KeyPressEater class that eats the key presses of its
+ monitored objects:
+ \code
+ class KeyPressEater : public TQObject
+ {
+ ...
+ protected:
+ bool eventFilter( TQObject *o, TQEvent *e );
+ };
+
+ bool KeyPressEater::eventFilter( TQObject *o, TQEvent *e )
+ {
+ if ( e->type() == TQEvent::KeyPress ) {
+ // special processing for key press
+ TQKeyEvent *k = (TQKeyEvent *)e;
+ qDebug( "Ate key press %d", k->key() );
+ return TRUE; // eat event
+ } else {
+ // standard event processing
+ return FALSE;
+ }
+ }
+ \endcode
+
+ And here's how to install it on two widgets:
+ \code
+ KeyPressEater *keyPressEater = new KeyPressEater( this );
+ TQPushButton *pushButton = new TQPushButton( this );
+ TQListView *listView = new TQListView( this );
+
+ pushButton->installEventFilter( keyPressEater );
+ listView->installEventFilter( keyPressEater );
+ \endcode
+
+ The TQAccel class, for example, uses this technique to intercept
+ accelerator key presses.
+
+ \warning If you delete the receiver object in your eventFilter()
+ function, be sure to return TRUE. If you return FALSE, TQt sends
+ the event to the deleted object and the program will crash.
+
+ \sa removeEventFilter(), eventFilter(), event()
+*/
+
+void TQObject::installEventFilter( const TQObject *obj )
+{
+ if ( !obj )
+ return;
+ if ( eventFilters ) {
+ int c = eventFilters->tqfindRef( obj );
+ if ( c >= 0 )
+ eventFilters->take( c );
+ disconnect( obj, TQT_SIGNAL(destroyed(TQObject*)),
+ this, TQT_SLOT(cleanupEventFilter(TQObject*)) );
+ } else {
+ eventFilters = new TQObjectList;
+ TQ_CHECK_PTR( eventFilters );
+ }
+ eventFilters->insert( 0, obj );
+ connect( obj, TQT_SIGNAL(destroyed(TQObject*)), this, TQT_SLOT(cleanupEventFilter(TQObject*)) );
+}
+
+/*!
+ Removes an event filter object \a obj from this object. The
+ request is ignored if such an event filter has not been installed.
+
+ All event filters for this object are automatically removed when
+ this object is destroyed.
+
+ It is always safe to remove an event filter, even during event
+ filter activation (i.e. from the eventFilter() function).
+
+ \sa installEventFilter(), eventFilter(), event()
+*/
+
+void TQObject::removeEventFilter( const TQObject *obj )
+{
+ if ( eventFilters && eventFilters->removeRef(obj) ) {
+ if ( eventFilters->isEmpty() ) { // last event filter removed
+ delete eventFilters;
+ eventFilters = 0; // reset event filter list
+ }
+ disconnect( obj, TQT_SIGNAL(destroyed(TQObject*)),
+ this, TQT_SLOT(cleanupEventFilter(TQObject*)) );
+ }
+}
+
+
+/*****************************************************************************
+ Signal connection management
+ *****************************************************************************/
+
+#if defined(TQT_CHECK_RANGE)
+
+static bool check_signal_macro( const TQObject *sender, const char *signal,
+ const char *func, const char *op )
+{
+ int sigcode = (int)(*signal) - '0';
+ if ( sigcode != TQSIGNAL_CODE ) {
+ if ( sigcode == TQSLOT_CODE )
+ qWarning( "TQObject::%s: Attempt to %s non-signal %s::%s",
+ func, op, sender->className(), signal+1 );
+ else
+ qWarning( "TQObject::%s: Use the TQT_SIGNAL macro to %s %s::%s",
+ func, op, sender->className(), signal );
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static bool check_member_code( int code, const TQObject *object,
+ const char *member, const char *func )
+{
+ if ( code != TQSLOT_CODE && code != TQSIGNAL_CODE ) {
+ qWarning( "TQObject::%s: Use the TQT_SLOT or TQT_SIGNAL macro to "
+ "%s %s::%s", func, func, object->className(), member );
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void err_member_notfound( int code, const TQObject *object,
+ const char *member, const char *func )
+{
+ const char *type = 0;
+ switch ( code ) {
+ case TQSLOT_CODE: type = "slot"; break;
+ case TQSIGNAL_CODE: type = "signal"; break;
+ }
+ if ( strchr(member,')') == 0 ) // common typing mistake
+ qWarning( "TQObject::%s: Parentheses expected, %s %s::%s",
+ func, type, object->className(), member );
+ else
+ qWarning( "TQObject::%s: No such %s %s::%s",
+ func, type, object->className(), member );
+}
+
+
+static void err_info_about_objects( const char * func,
+ const TQObject * sender,
+ const TQObject * receiver )
+{
+ const char * a = sender->name(), * b = receiver->name();
+ if ( a )
+ qWarning( "TQObject::%s: (sender name: '%s')", func, a );
+ if ( b )
+ qWarning( "TQObject::%s: (receiver name: '%s')", func, b );
+}
+
+static void err_info_about_candidates( int code,
+ const TQMetaObject* mo,
+ const char* member,
+ const char *func )
+{
+ if ( strstr(member,"const char*") ) {
+ // porting help
+ TQCString newname = member;
+ int p;
+ while ( (p=newname.tqfind("const char*")) >= 0 ) {
+ newname.tqreplace(p, 11, "const TQString&");
+ }
+ const TQMetaData *rm = 0;
+ switch ( code ) {
+ case TQSLOT_CODE:
+ rm = mo->slot( mo->tqfindSlot( newname, TRUE ), TRUE );
+ break;
+ case TQSIGNAL_CODE:
+ rm = mo->signal( mo->tqfindSignal( newname, TRUE ), TRUE );
+ break;
+ }
+ if ( rm ) {
+ qWarning("TQObject::%s: Candidate: %s", func, newname.data());
+ }
+ }
+}
+
+
+#endif // TQT_CHECK_RANGE
+
+
+/*!
+ Returns a pointer to the object that sent the signal, if called in
+ a slot activated by a signal; otherwise it returns 0. The pointer
+ is valid only during the execution of the slot that calls this
+ function.
+
+ The pointer returned by this function becomes invalid if the
+ sender is destroyed, or if the slot is disconnected from the
+ sender's signal.
+
+ \warning This function violates the object-oriented principle of
+ modularity. However, getting access to the sender might be useful
+ when many Q_SIGNALS are connected to a single slot. The sender is
+ undefined if the slot is called as a normal C++ function.
+*/
+
+const TQObject *TQObject::sender()
+{
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+ if ( this == qt_preliminary_signal_spy ) {
+# ifdef TQT_THREAD_SUPPORT
+ // protect access to qt_spy_signal_sender
+ void * const address = &qt_spy_signal_sender;
+ TQMutexLocker locker( tqt_global_mutexpool ?
+ tqt_global_mutexpool->get( address ) : 0 );
+# endif // TQT_THREAD_SUPPORT
+ return qt_spy_signal_sender;
+ }
+#endif
+ if ( senderObjects &&
+ senderObjects->currentSender &&
+ /*
+ * currentSender may be a dangling pointer in case the object
+ * it was pointing to was destructed from inside a slot. Thus
+ * verify it still is contained inside the senderObjects list
+ * which gets cleaned on both destruction and disconnect.
+ */
+
+ senderObjects->tqfindRef( senderObjects->currentSender ) != -1 )
+ return senderObjects->currentSender;
+ return 0;
+}
+
+
+/*!
+ \fn void TQObject::connectNotify( const char *signal )
+
+ This virtual function is called when something has been connected
+ to \a signal in this object.
+
+ \warning This function violates the object-oriented principle of
+ modularity. However, it might be useful when you need to perform
+ expensive initialization only if something is connected to a
+ signal.
+
+ \sa connect(), disconnectNotify()
+*/
+
+void TQObject::connectNotify( const char * )
+{
+}
+
+/*!
+ \fn void TQObject::disconnectNotify( const char *signal )
+
+ This virtual function is called when something has been
+ disconnected from \a signal in this object.
+
+ \warning This function violates the object-oriented principle of
+ modularity. However, it might be useful for optimizing access to
+ expensive resources.
+
+ \sa disconnect(), connectNotify()
+*/
+
+void TQObject::disconnectNotify( const char * )
+{
+}
+
+
+/*!
+ \fn bool TQObject::checkConnectArgs( const char *signal, const TQObject *receiver, const char *member )
+
+ Returns TRUE if the \a signal and the \a member arguments are
+ compatible; otherwise returns FALSE. (The \a receiver argument is
+ currently ignored.)
+
+ \warning We recommend that you use the default implementation and
+ do not reimplement this function.
+
+ \omit
+ TRUE: "signal(<anything>)", "member()"
+ TRUE: "signal(a,b,c)", "member(a,b,c)"
+ TRUE: "signal(a,b,c)", "member(a,b)", "member(a)" etc.
+ FALSE: "signal(const a)", "member(a)"
+ FALSE: "signal(a)", "member(const a)"
+ FALSE: "signal(a)", "member(b)"
+ FALSE: "signal(a)", "member(a,b)"
+ \endomit
+*/
+
+bool TQObject::checkConnectArgs( const char *signal,
+ const TQObject *,
+ const char *member )
+{
+ const char *s1 = signal;
+ const char *s2 = member;
+ while ( *s1++ != '(' ) { } // scan to first '('
+ while ( *s2++ != '(' ) { }
+ if ( *s2 == ')' || qstrcmp(s1,s2) == 0 ) // member has no args or
+ return TRUE; // exact match
+ int s1len = tqstrlen(s1);
+ int s2len = tqstrlen(s2);
+ if ( s2len < s1len && tqstrncmp(s1,s2,s2len-1)==0 && s1[s2len-1]==',' )
+ return TRUE; // member has less args
+ return FALSE;
+}
+
+/*!
+ Normlizes the signal or slot definition \a signalSlot by removing
+ unnecessary whitespace.
+*/
+
+TQCString TQObject::normalizeSignalSlot( const char *signalSlot )
+{
+ if ( !signalSlot )
+ return TQCString();
+ return qt_rmWS( signalSlot );
+}
+
+
+
+/*!
+ \overload bool TQObject::connect( const TQObject *sender, const char *signal, const char *member ) const
+
+ Connects \a signal from the \a sender object to this object's \a
+ member.
+
+ Equivalent to: \c{TQObject::connect(sender, signal, this, member)}.
+
+ \sa disconnect()
+*/
+
+/*!
+ Connects \a signal from the \a sender object to \a member in object
+ \a receiver, and returns TRUE if the connection succeeds; otherwise
+ returns FALSE.
+
+ You must use the TQT_SIGNAL() and TQT_SLOT() macros when specifying the \a signal
+ and the \a member, for example:
+ \code
+ TQLabel *label = new TQLabel;
+ TQScrollBar *scroll = new TQScrollBar;
+ TQObject::connect( scroll, TQT_SIGNAL(valueChanged(int)),
+ label, TQT_SLOT(setNum(int)) );
+ \endcode
+
+ This example ensures that the label always displays the current
+ scroll bar value. Note that the signal and Q_SLOTS parameters must not
+ contain any variable names, only the type. E.g. the following would
+ not work and return FALSE:
+ TQObject::connect( scroll, TQT_SIGNAL(valueChanged(int v)),
+ label, TQT_SLOT(setNum(int v)) );
+
+ A signal can also be connected to another signal:
+
+ \code
+ class MyWidget : public TQWidget
+ {
+ TQ_OBJECT
+ public:
+ MyWidget();
+
+ Q_SIGNALS:
+ void myUsefulSignal();
+
+ private:
+ TQPushButton *aButton;
+ };
+
+ MyWidget::MyWidget()
+ {
+ aButton = new TQPushButton( this );
+ connect( aButton, TQT_SIGNAL(clicked()), TQT_SIGNAL(myUsefulSignal()) );
+ }
+ \endcode
+
+ In this example, the MyWidget constructor relays a signal from a
+ private member variable, and makes it available under a name that
+ relates to MyWidget.
+
+ A signal can be connected to many Q_SLOTS and Q_SIGNALS. Many Q_SIGNALS
+ can be connected to one slot.
+
+ If a signal is connected to several Q_SLOTS, the Q_SLOTS are activated
+ in an arbitrary order when the signal is emitted.
+
+ The function returns TRUE if it successfully connects the signal
+ to the slot. It will return FALSE if it cannot create the
+ connection, for example, if TQObject is unable to verify the
+ existence of either \a signal or \a member, or if their signatures
+ aren't compatible.
+
+ A signal is emitted for \e{every} connection you make, so if you
+ duplicate a connection, two Q_SIGNALS will be emitted. You can
+ always break a connection using \c{disconnect()}.
+
+ \sa disconnect()
+*/
+
+bool TQObject::connect( const TQObject *sender, const char *signal,
+ const TQObject *receiver, const char *member )
+{
+#if defined(TQT_CHECK_NULL)
+ if ( sender == 0 || receiver == 0 || signal == 0 || member == 0 ) {
+ qWarning( "TQObject::connect: Cannot connect %s::%s to %s::%s",
+ sender ? sender->className() : "(null)",
+ signal ? signal+1 : "(null)",
+ receiver ? receiver->className() : "(null)",
+ member ? member+1 : "(null)" );
+ return FALSE;
+ }
+#endif
+ TQMetaObject *smeta = sender->tqmetaObject();
+
+#if defined(TQT_CHECK_RANGE)
+ if ( !check_signal_macro( sender, signal, "connect", "bind" ) )
+ return FALSE;
+#endif
+ TQCString nw_signal(signal); // Assume already normalized
+ ++signal; // skip member type code
+
+ int signal_index = smeta->tqfindSignal( signal, TRUE );
+ if ( signal_index < 0 ) { // normalize and retry
+ nw_signal = qt_rmWS( signal-1 ); // remove whitespace
+ signal = nw_signal.data()+1; // skip member type code
+ signal_index = smeta->tqfindSignal( signal, TRUE );
+ }
+
+ if ( signal_index < 0 ) { // no such signal
+#if defined(TQT_CHECK_RANGE)
+ err_member_notfound( TQSIGNAL_CODE, sender, signal, "connect" );
+ err_info_about_candidates( TQSIGNAL_CODE, smeta, signal, "connect" );
+ err_info_about_objects( "connect", sender, receiver );
+#endif
+ return FALSE;
+ }
+ const TQMetaData *sm = smeta->signal( signal_index, TRUE );
+ signal = sm->name; // use name from meta object
+
+ int membcode = member[0] - '0'; // get member code
+
+ TQObject *s = (TQObject *)sender; // we need to change them
+ TQObject *r = (TQObject *)receiver; // internally
+
+#if defined(TQT_CHECK_RANGE)
+ if ( !check_member_code( membcode, r, member, "connect" ) )
+ return FALSE;
+#endif
+ member++; // skip code
+
+ TQCString nw_member ;
+ TQMetaObject *rmeta = r->tqmetaObject();
+ int member_index = -1;
+ switch ( membcode ) { // get receiver member
+ case TQSLOT_CODE:
+ member_index = rmeta->tqfindSlot( member, TRUE );
+ if ( member_index < 0 ) { // normalize and retry
+ nw_member = qt_rmWS(member); // remove whitespace
+ member = nw_member;
+ member_index = rmeta->tqfindSlot( member, TRUE );
+ }
+ break;
+ case TQSIGNAL_CODE:
+ member_index = rmeta->tqfindSignal( member, TRUE );
+ if ( member_index < 0 ) { // normalize and retry
+ nw_member = qt_rmWS(member); // remove whitespace
+ member = nw_member;
+ member_index = rmeta->tqfindSignal( member, TRUE );
+ }
+ break;
+ }
+ if ( member_index < 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ err_member_notfound( membcode, r, member, "connect" );
+ err_info_about_candidates( membcode, rmeta, member, "connect" );
+ err_info_about_objects( "connect", sender, receiver );
+#endif
+ return FALSE;
+ }
+#if defined(TQT_CHECK_RANGE)
+ if ( !s->checkConnectArgs(signal,receiver,member) ) {
+ qWarning( "TQObject::connect: Incompatible sender/receiver arguments"
+ "\n\t%s::%s --> %s::%s",
+ s->className(), signal,
+ r->className(), member );
+ return FALSE;
+ } else {
+ const TQMetaData *rm = membcode == TQSLOT_CODE ?
+ rmeta->slot( member_index, TRUE ) :
+ rmeta->signal( member_index, TRUE );
+ if ( rm ) {
+ int si = 0;
+ int ri = 0;
+ while ( si < sm->method->count && ri < rm->method->count ) {
+ if ( sm->method->parameters[si].inOut == TQUParameter::Out )
+ si++;
+ else if ( rm->method->parameters[ri].inOut == TQUParameter::Out )
+ ri++;
+ else if ( !TQUType::isEqual( sm->method->parameters[si++].type,
+ rm->method->parameters[ri++].type ) ) {
+ if ( ( TQUType::isEqual( sm->method->parameters[si-1].type, &static_TQUType_ptr )
+ && TQUType::isEqual( rm->method->parameters[ri-1].type, &static_TQUType_varptr ) )
+ || ( TQUType::isEqual( sm->method->parameters[si-1].type, &static_TQUType_varptr )
+ && TQUType::isEqual( rm->method->parameters[ri-1].type, &static_TQUType_ptr ) ) )
+ continue; // varptr got introduced in 3.1 and is binary compatible with ptr
+ qWarning( "TQObject::connect: Incompatible sender/receiver marshalling"
+ "\n\t%s::%s --> %s::%s",
+ s->className(), signal,
+ r->className(), member );
+ return FALSE;
+ }
+ }
+ }
+ }
+#endif
+ connectInternal( sender, signal_index, receiver, membcode, member_index );
+ s->connectNotify( nw_signal );
+ return TRUE;
+}
+
+/*! \internal */
+
+void TQObject::connectInternal( const TQObject *sender, int signal_index, const TQObject *receiver,
+ int membcode, int member_index )
+{
+ TQObject *s = (TQObject*)sender;
+ TQObject *r = (TQObject*)receiver;
+
+ if ( !s->connections ) { // create connections lookup table
+ s->connections = new TQSignalVec( signal_index+1 );
+ TQ_CHECK_PTR( s->connections );
+ s->connections->setAutoDelete( TRUE );
+ }
+
+ TQConnectionList *clist = s->connections->at( signal_index );
+ if ( !clist ) { // create receiver list
+ clist = new TQConnectionList;
+ TQ_CHECK_PTR( clist );
+ clist->setAutoDelete( TRUE );
+ s->connections->insert( signal_index, clist );
+ }
+
+ TQMetaObject *rmeta = r->tqmetaObject();
+ const TQMetaData *rm = 0;
+
+ switch ( membcode ) { // get receiver member
+ case TQSLOT_CODE:
+ rm = rmeta->slot( member_index, TRUE );
+ break;
+ case TQSIGNAL_CODE:
+ rm = rmeta->signal( member_index, TRUE );
+ break;
+ }
+
+ TQConnection *c = new TQConnection( r, member_index, rm ? rm->name : "qt_invoke", membcode );
+ TQ_CHECK_PTR( c );
+ clist->append( c );
+ if ( !r->senderObjects ) // create list of senders
+ r->senderObjects = new TQSenderObjectList;
+ r->senderObjects->append( s ); // add sender to list
+}
+
+
+/*!
+ \overload bool TQObject::disconnect( const char *signal, const TQObject *receiver, const char *member )
+
+ Disconnects \a signal from \a member of \a receiver.
+
+ A signal-slot connection is removed when either of the objects
+ involved are destroyed.
+*/
+
+/*!
+ \overload bool TQObject::disconnect( const TQObject *receiver, const char *member )
+
+ Disconnects all Q_SIGNALS in this object from \a receiver's \a
+ member.
+
+ A signal-slot connection is removed when either of the objects
+ involved are destroyed.
+*/
+
+/*!
+ Disconnects \a signal in object \a sender from \a member in object
+ \a receiver.
+
+ A signal-slot connection is removed when either of the objects
+ involved are destroyed.
+
+ disconnect() is typically used in three ways, as the following
+ examples demonstrate.
+ \list 1
+ \i Disconnect everything connected to an object's Q_SIGNALS:
+ \code
+ disconnect( myObject, 0, 0, 0 );
+ \endcode
+ equivalent to the non-static overloaded function
+ \code
+ myObject->disconnect();
+ \endcode
+ \i Disconnect everything connected to a specific signal:
+ \code
+ disconnect( myObject, TQT_SIGNAL(mySignal()), 0, 0 );
+ \endcode
+ equivalent to the non-static overloaded function
+ \code
+ myObject->disconnect( TQT_SIGNAL(mySignal()) );
+ \endcode
+ \i Disconnect a specific receiver:
+ \code
+ disconnect( myObject, 0, myReceiver, 0 );
+ \endcode
+ equivalent to the non-static overloaded function
+ \code
+ myObject->disconnect( myReceiver );
+ \endcode
+ \endlist
+
+ 0 may be used as a wildcard, meaning "any signal", "any receiving
+ object", or "any slot in the receiving object", respectively.
+
+ The \a sender may never be 0. (You cannot disconnect Q_SIGNALS from
+ more than one object in a single call.)
+
+ If \a signal is 0, it disconnects \a receiver and \a member from
+ any signal. If not, only the specified signal is disconnected.
+
+ If \a receiver is 0, it disconnects anything connected to \a
+ signal. If not, Q_SLOTS in objects other than \a receiver are not
+ disconnected.
+
+ If \a member is 0, it disconnects anything that is connected to \a
+ receiver. If not, only Q_SLOTS named \a member will be disconnected,
+ and all other Q_SLOTS are left alone. The \a member must be 0 if \a
+ receiver is left out, so you cannot disconnect a
+ specifically-named slot on all objects.
+
+ \sa connect()
+*/
+
+bool TQObject::disconnect( const TQObject *sender, const char *signal,
+ const TQObject *receiver, const char *member )
+{
+#if defined(TQT_CHECK_NULL)
+ if ( sender == 0 || (receiver == 0 && member != 0) ) {
+ qWarning( "TQObject::disconnect: Unexpected null parameter" );
+ return FALSE;
+ }
+#endif
+ if ( !sender->connections ) // no connected Q_SIGNALS
+ return FALSE;
+ TQObject *s = (TQObject *)sender;
+ TQObject *r = (TQObject *)receiver;
+ int member_index = -1;
+ int membcode = -1;
+ TQCString nw_member;
+ if ( member ) {
+ membcode = member[0] - '0';
+#if defined(TQT_CHECK_RANGE)
+ if ( !check_member_code( membcode, r, member, "disconnect" ) )
+ return FALSE;
+#endif
+ ++member;
+ TQMetaObject *rmeta = r->tqmetaObject();
+
+ switch ( membcode ) { // get receiver member
+ case TQSLOT_CODE:
+ member_index = rmeta->tqfindSlot( member, TRUE );
+ if ( member_index < 0 ) { // normalize and retry
+ nw_member = qt_rmWS(member); // remove whitespace
+ member = nw_member;
+ member_index = rmeta->tqfindSlot( member, TRUE );
+ }
+ break;
+ case TQSIGNAL_CODE:
+ member_index = rmeta->tqfindSignal( member, TRUE );
+ if ( member_index < 0 ) { // normalize and retry
+ nw_member = qt_rmWS(member); // remove whitespace
+ member = nw_member;
+ member_index = rmeta->tqfindSignal( member, TRUE );
+ }
+ break;
+ }
+ if ( member_index < 0 ) { // no such member
+#if defined(TQT_CHECK_RANGE)
+ err_member_notfound( membcode, r, member, "disconnect" );
+ err_info_about_candidates( membcode, rmeta, member, "connect" );
+ err_info_about_objects( "disconnect", sender, receiver );
+#endif
+ return FALSE;
+ }
+ }
+
+ if ( signal == 0 ) { // any/all Q_SIGNALS
+ if ( disconnectInternal( s, -1, r, membcode, member_index ) )
+ s->disconnectNotify( 0 );
+ else
+ return FALSE;
+ } else { // specific signal
+#if defined(TQT_CHECK_RANGE)
+ if ( !check_signal_macro( s, signal, "disconnect", "unbind" ) )
+ return FALSE;
+#endif
+ TQCString nw_signal(signal); // Assume already normalized
+ ++signal; // skip member type code
+
+ TQMetaObject *smeta = s->tqmetaObject();
+ if ( !smeta ) // no meta object
+ return FALSE;
+ int signal_index = smeta->tqfindSignal( signal, TRUE );
+ if ( signal_index < 0 ) { // normalize and retry
+ nw_signal = qt_rmWS( signal-1 ); // remove whitespace
+ signal = nw_signal.data()+1; // skip member type code
+ signal_index = smeta->tqfindSignal( signal, TRUE );
+ }
+ if ( signal_index < 0 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQObject::disconnect: No such signal %s::%s",
+ s->className(), signal );
+#endif
+ return FALSE;
+ }
+
+ /* compatibility and safety: If a receiver has several Q_SLOTS
+ * with the same name, disconnect them all*/
+ bool res = FALSE;
+ if ( membcode == TQSLOT_CODE && r ) {
+ TQMetaObject * rmeta = r->tqmetaObject();
+ do {
+ int mi = rmeta->tqfindSlot( member );
+ if ( mi != -1 )
+ res |= disconnectInternal( s, signal_index, r, membcode, mi );
+ } while ( (rmeta = rmeta->superClass()) );
+ } else {
+ res = disconnectInternal( s, signal_index, r, membcode, member_index );
+ }
+ if ( res )
+ s->disconnectNotify( nw_signal );
+ return res;
+ }
+ return TRUE;
+}
+
+/*! \internal */
+
+bool TQObject::disconnectInternal( const TQObject *sender, int signal_index,
+ const TQObject *receiver, int membcode, int member_index )
+{
+ TQObject *s = (TQObject*)sender;
+ TQObject *r = (TQObject*)receiver;
+
+ if ( !s->connections )
+ return FALSE;
+
+ bool success = FALSE;
+ TQConnectionList *clist;
+ register TQConnection *c;
+ if ( signal_index == -1 ) {
+ for ( int i = 0; i < (int) s->connections->size(); i++ ) {
+ clist = (*s->connections)[i]; // for all Q_SIGNALS...
+ if ( !clist )
+ continue;
+ c = clist->first();
+ while ( c ) { // for all tqreceivers...
+ if ( r == 0 ) { // remove all tqreceivers
+ removeObjFromList( c->object()->senderObjects, s );
+ success = TRUE;
+ c = clist->next();
+ } else if ( r == c->object() &&
+ ( member_index == -1 ||
+ member_index == c->member() && c->memberType() == membcode ) ) {
+ removeObjFromList( c->object()->senderObjects, s, TRUE );
+ success = TRUE;
+ clist->remove();
+ c = clist->current();
+ } else {
+ c = clist->next();
+ }
+ }
+ if ( r == 0 ) // disconnect all tqreceivers
+ s->connections->insert( i, 0 );
+ }
+ } else {
+ clist = s->connections->at( signal_index );
+ if ( !clist )
+ return FALSE;
+
+ c = clist->first();
+ while ( c ) { // for all tqreceivers...
+ if ( r == 0 ) { // remove all tqreceivers
+ removeObjFromList( c->object()->senderObjects, s, TRUE );
+ success = TRUE;
+ c = clist->next();
+ } else if ( r == c->object() &&
+ ( member_index == -1 ||
+ member_index == c->member() && c->memberType() == membcode ) ) {
+ removeObjFromList( c->object()->senderObjects, s, TRUE );
+ success = TRUE;
+ clist->remove();
+ c = clist->current();
+ } else {
+ c = clist->next();
+ }
+ }
+ if ( r == 0 ) // disconnect all tqreceivers
+ s->connections->insert( signal_index, 0 );
+ }
+ return success;
+}
+
+/*!
+ \fn TQObject::destroyed()
+
+ This signal is emitted when the object is being destroyed.
+
+ Note that the signal is emitted by the TQObject destructor, so
+ the object's virtual table is already degenerated at this point,
+ and it is not safe to call any functions on the object emitting
+ the signal. This signal can not be blocked.
+
+ All the objects's tqchildren are destroyed immediately after this
+ signal is emitted.
+*/
+
+/*!
+ \overload TQObject::destroyed( TQObject* obj)
+
+ This signal is emitted immediately before the object \a obj is
+ destroyed, and can not be blocked.
+
+ All the objects's tqchildren are destroyed immediately after this
+ signal is emitted.
+*/
+
+/*!
+ Performs a deferred deletion of this object.
+
+ Instead of an immediate deletion this function schedules a
+ deferred delete event for processing when TQt returns to the main
+ event loop.
+*/
+void TQObject::deleteLater()
+{
+ TQApplication::postEvent( this, new TQEvent( TQEvent::DeferredDelete) );
+}
+
+/*!
+ This slot is connected to the destroyed() signal of other objects
+ that have installed event filters on this object. When the other
+ object, \a obj, is destroyed, we want to remove its event filter.
+*/
+
+void TQObject::cleanupEventFilter(TQObject* obj)
+{
+ removeEventFilter( obj );
+}
+
+
+/*!
+ \fn TQString TQObject::tr( const char *sourceText, const char * comment )
+ \reentrant
+
+ Returns a translated version of \a sourceText, or \a sourceText
+ itself if there is no appropriate translated version. The
+ translation context is TQObject with \a comment (0 by default).
+ All TQObject subclasses using the TQ_OBJECT macro automatically have
+ a reimplementation of this function with the subclass name as
+ context.
+
+ \warning This method is reentrant only if all translators are
+ installed \e before calling this method. Installing or removing
+ translators while performing translations is not supported. Doing
+ so will probably result in crashes or other undesirable behavior.
+
+ \sa trUtf8() TQApplication::translate()
+ \link i18n.html Internationalization with TQt\endlink
+*/
+
+/*!
+ \fn TQString TQObject::trUtf8( const char *sourceText,
+ const char *comment )
+ \reentrant
+
+ Returns a translated version of \a sourceText, or
+ TQString::fromUtf8(\a sourceText) if there is no appropriate
+ version. It is otherwise identical to tr(\a sourceText, \a
+ comment).
+
+ \warning This method is reentrant only if all translators are
+ installed \e before calling this method. Installing or removing
+ translators while performing translations is not supported. Doing
+ so will probably result in crashes or other undesirable behavior.
+
+ \sa tr() TQApplication::translate()
+*/
+
+static TQMetaObjectCleanUp cleanUp_TQt = TQMetaObjectCleanUp( "TQObject", &TQObject::staticMetaObject );
+
+TQMetaObject* TQObject::staticTQtMetaObject()
+{
+ static TQMetaObject* qtMetaObject = 0;
+ if ( qtMetaObject )
+ return qtMetaObject;
+
+#ifndef TQT_NO_PROPERTIES
+ static const TQMetaEnum::Item enum_0[] = {
+ { "AlignLeft", (int) TQt::AlignLeft },
+ { "AlignRight", (int) TQt::AlignRight },
+ { "AlignHCenter", (int) TQt::AlignHCenter },
+ { "AlignTop", (int) TQt::AlignTop },
+ { "AlignBottom", (int) TQt::AlignBottom },
+ { "AlignVCenter", (int) TQt::AlignVCenter },
+ { "AlignCenter", (int) TQt::AlignCenter },
+ { "AlignAuto", (int) TQt::AlignAuto },
+ { "AlignJustify", (int) TQt::AlignJustify },
+ { "WordBreak", (int) TQt::WordBreak }
+ };
+
+ static const TQMetaEnum::Item enum_1[] = {
+ { "Horizontal", (int) Qt::Horizontal },
+ { "Vertical", (int) Qt::Vertical }
+ };
+
+ static const TQMetaEnum::Item enum_2[] = {
+ { "PlainText", (int) TQt::PlainText },
+ { "RichText", (int) TQt::RichText },
+ { "AutoText", (int) TQt::AutoText },
+ { "LogText", (int) TQt::LogText }
+ };
+
+ static const TQMetaEnum::Item enum_3[] = {
+ { "NoBackground", (int) TQt::NoBackground },
+ { "PaletteForeground", (int) TQt::PaletteForeground },
+ { "PaletteButton", (int) TQt::PaletteButton },
+ { "PaletteLight", (int) TQt::PaletteLight },
+ { "PaletteMidlight", (int) TQt::PaletteMidlight },
+ { "PaletteDark", (int) TQt::PaletteDark },
+ { "PaletteMid", (int) TQt::PaletteMid },
+ { "PaletteText", (int) TQt::PaletteText },
+ { "PaletteBrightText", (int) TQt::PaletteBrightText },
+ { "PaletteBase", (int) TQt::PaletteBase },
+ { "PaletteBackground", (int) TQt::PaletteBackground },
+ { "PaletteShadow", (int) TQt::PaletteShadow },
+ { "PaletteHighlight", (int) TQt::PaletteHighlight },
+ { "PaletteHighlightedText", (int) TQt::PaletteHighlightedText },
+ { "PaletteButtonText", (int) TQt::PaletteButtonText },
+ { "PaletteLink", (int) TQt::PaletteLink },
+ { "PaletteLinkVisited", (int) TQt::PaletteLinkVisited }
+ };
+
+ static const TQMetaEnum::Item enum_4[] = {
+ { "TextDate", (int) TQt::TextDate },
+ { "ISODate", (int) TQt::ISODate },
+ { "LocalDate", (int) TQt::LocalDate }
+ };
+
+
+ static const TQMetaEnum enum_tbl[] = {
+ { "Alignment", 10, enum_0, TRUE },
+ { "Orientation", 2, enum_1, FALSE },
+ { "TextFormat", 4, enum_2, FALSE },
+ { "BackgroundMode", 17, enum_3, FALSE },
+ { "DateFormat", 3, enum_4, FALSE }
+ };
+#endif
+
+ qtMetaObject = new TQMetaObject( "TQt", 0,
+ 0, 0,
+ 0, 0,
+#ifndef TQT_NO_PROPERTIES
+ 0, 0,
+ enum_tbl, 5,
+#endif
+ 0, 0 );
+ cleanUp_TQt.setMetaObject( qtMetaObject );
+
+ return qtMetaObject;
+}
+
+/*!
+ \internal
+
+ Signal activation with the most frequently used parameter/argument
+ types. All other combinations are generated by the meta object
+ compiler.
+ */
+void TQObject::activate_signal( int signal )
+{
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+ if ( qt_preliminary_signal_spy ) {
+ if ( !tqsignalsBlocked() && signal >= 0 &&
+ ( !connections || !connections->at( signal ) ) ) {
+ TQUObject o[1];
+ qt_spy_signal( this, signal, o );
+ return;
+ }
+ }
+#endif
+
+ if ( !connections || tqsignalsBlocked() || signal < 0 )
+ return;
+ TQConnectionList *clist = connections->at( signal );
+ if ( !clist )
+ return;
+ TQUObject o[1];
+ activate_signal( clist, o );
+}
+
+/*! \internal */
+
+void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
+{
+ if ( !clist )
+ return;
+
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+ if ( qt_preliminary_signal_spy )
+ qt_spy_signal( this, connections->tqfindRef( clist), o );
+#endif
+
+ TQObject *object;
+ TQSenderObjectList* sol;
+ TQObject* oldSender = 0;
+ TQConnection *c;
+ if ( clist->count() == 1 ) { // save iterator
+ c = clist->first();
+ object = c->object();
+ sol = object->senderObjects;
+ if ( sol ) {
+ oldSender = sol->currentSender;
+ sol->ref();
+ sol->currentSender = this;
+ }
+ if ( c->memberType() == TQSIGNAL_CODE )
+ object->qt_emit( c->member(), o );
+ else
+ object->qt_invoke( c->member(), o );
+ if ( sol ) {
+ sol->currentSender = oldSender;
+ if ( sol->deref() )
+ delete sol;
+ }
+ } else {
+ TQConnection *cd = 0;
+ TQConnectionListIt it(*clist);
+ while ( (c=it.current()) ) {
+ ++it;
+ if ( c == cd )
+ continue;
+ cd = c;
+ object = c->object();
+ sol = object->senderObjects;
+ if ( sol ) {
+ oldSender = sol->currentSender;
+ sol->ref();
+ sol->currentSender = this;
+ }
+ if ( c->memberType() == TQSIGNAL_CODE )
+ object->qt_emit( c->member(), o );
+ else
+ object->qt_invoke( c->member(), o );
+ if (sol ) {
+ sol->currentSender = oldSender;
+ if ( sol->deref() )
+ delete sol;
+ }
+ }
+ }
+}
+
+/*!
+ \overload void TQObject::activate_signal( int signal, int )
+*/
+
+/*!
+ \overload void TQObject::activate_signal( int signal, double )
+*/
+
+/*!
+ \overload void TQObject::activate_signal( int signal, TQString )
+*/
+
+/*!
+ \fn void TQObject::activate_signal_bool( int signal, bool )
+ \internal
+
+ Like the above functions, but since bool is sometimes
+ only a typedef it cannot be a simple overload.
+*/
+
+#ifndef TQT_NO_PRELIMINARY_SIGNAL_SPY
+#define ACTIVATE_SIGNAL_WITH_PARAM(FNAME,TYPE) \
+void TQObject::FNAME( int signal, TYPE param ) \
+{ \
+ if ( qt_preliminary_signal_spy ) { \
+ if ( !tqsignalsBlocked() && signal >= 0 && \
+ ( !connections || !connections->at( signal ) ) ) { \
+ TQUObject o[2]; \
+ static_TQUType_##TYPE.set( o+1, param ); \
+ qt_spy_signal( this, signal, o ); \
+ return; \
+ } \
+ } \
+ if ( !connections || tqsignalsBlocked() || signal < 0 ) \
+ return; \
+ TQConnectionList *clist = connections->at( signal ); \
+ if ( !clist ) \
+ return; \
+ TQUObject o[2]; \
+ static_TQUType_##TYPE.set( o+1, param ); \
+ activate_signal( clist, o ); \
+}
+#else
+#define ACTIVATE_SIGNAL_WITH_PARAM(FNAME,TYPE) \
+void TQObject::FNAME( int signal, TYPE param ) \
+{ \
+ if ( !connections || tqsignalsBlocked() || signal < 0 ) \
+ return; \
+ TQConnectionList *clist = connections->at( signal ); \
+ if ( !clist ) \
+ return; \
+ TQUObject o[2]; \
+ static_TQUType_##TYPE.set( o+1, param ); \
+ activate_signal( clist, o ); \
+}
+
+#endif
+// We don't want to duplicate too much text so...
+
+ACTIVATE_SIGNAL_WITH_PARAM( activate_signal, int )
+ACTIVATE_SIGNAL_WITH_PARAM( activate_signal, double )
+ACTIVATE_SIGNAL_WITH_PARAM( activate_signal, TQString )
+ACTIVATE_SIGNAL_WITH_PARAM( activate_signal_bool, bool )
+
+
+/*****************************************************************************
+ TQObject debugging output routines.
+ *****************************************************************************/
+
+static void dumpRecursive( int level, TQObject *object )
+{
+#if defined(TQT_DEBUG)
+ if ( object ) {
+ TQString buf;
+ buf.fill( '\t', level/2 );
+ if ( level % 2 )
+ buf += " ";
+ const char *name = object->name();
+ TQString flags="";
+ if ( tqApp->tqfocusWidget() == object )
+ flags += 'F';
+ if ( object->isWidgetType() ) {
+ TQWidget * w = (TQWidget *)object;
+ if ( w->isVisible() ) {
+ TQString t( "<%1,%2,%3,%4>" );
+ flags += t.arg(w->x()).arg(w->y()).arg(w->width()).arg(w->height());
+ } else {
+ flags += 'I';
+ }
+ }
+ qDebug( "%s%s::%s %s", (const char*)buf, object->className(), name,
+ flags.latin1() );
+ if ( !object->childrenListObject().isEmpty() ) {
+ TQObjectListIt it(object->childrenListObject());
+ TQObject * c;
+ while ( (c=it.current()) != 0 ) {
+ ++it;
+ dumpRecursive( level+1, c );
+ }
+ }
+ }
+#else
+ TQ_UNUSED( level )
+ TQ_UNUSED( object )
+#endif
+}
+
+/*!
+ Dumps a tree of tqchildren to the debug output.
+
+ This function is useful for debugging, but does nothing if the
+ library has been compiled in release mode (i.e. without debugging
+ information).
+*/
+
+void TQObject::dumpObjectTree()
+{
+ dumpRecursive( 0, this );
+}
+
+/*!
+ Dumps information about signal connections, etc. for this object
+ to the debug output.
+
+ This function is useful for debugging, but does nothing if the
+ library has been compiled in release mode (i.e. without debugging
+ information).
+*/
+
+void TQObject::dumpObjectInfo()
+{
+#if defined(TQT_DEBUG)
+ qDebug( "OBJECT %s::%s", className(), name( "unnamed" ) );
+ int n = 0;
+ qDebug( " SIGNALS OUT" );
+ if ( connections ) {
+ TQConnectionList *clist;
+ for ( uint i = 0; i < connections->size(); i++ ) {
+ if ( ( clist = connections->at( i ) ) ) {
+ qDebug( "\t%s", tqmetaObject()->signal( i, TRUE )->name );
+ n++;
+ register TQConnection *c;
+ TQConnectionListIt cit(*clist);
+ while ( (c=cit.current()) ) {
+ ++cit;
+ qDebug( "\t --> %s::%s %s", c->object()->className(),
+ c->object()->name( "unnamed" ), c->memberName() );
+ }
+ }
+ }
+ }
+ if ( n == 0 )
+ qDebug( "\t<None>" );
+
+ qDebug( " SIGNALS IN" );
+ n = 0;
+ if ( senderObjects ) {
+ TQObject *sender = senderObjects->first();
+ while ( sender ) {
+ qDebug( "\t%s::%s",
+ sender->className(), sender->name( "unnamed" ) );
+ n++;
+ sender = senderObjects->next();
+ }
+ }
+ if ( n == 0 )
+ qDebug( "\t<None>" );
+#endif
+}
+
+#ifndef TQT_NO_PROPERTIES
+
+/*!
+ Sets the value of the object's \a name property to \a value.
+
+ Returns TRUE if the operation was successful; otherwise returns
+ FALSE.
+
+ Information about all available properties is provided through the
+ tqmetaObject().
+
+ \sa property(), tqmetaObject(), TQMetaObject::propertyNames(), TQMetaObject::property()
+*/
+bool TQObject::setProperty( const char *name, const TQVariant& value )
+{
+ if ( !value.isValid() )
+ return FALSE;
+
+ TQVariant v = value;
+
+ TQMetaObject* meta = tqmetaObject();
+ if ( !meta )
+ return FALSE;
+ int id = meta->tqfindProperty( name, TRUE );
+ const TQMetaProperty* p = meta->property( id, TRUE );
+ if ( !p || !p->isValid() || !p->writable() ) {
+ qWarning( "%s::setProperty( \"%s\", value ) failed: property invalid, read-only or does not exist",
+ className(), name );
+ return FALSE;
+ }
+
+ if ( p->isEnumType() ) {
+ if ( v.type() == TQVariant::String || v.type() == TQVariant::CString ) {
+ if ( p->isSetType() ) {
+ TQString s = value.toString();
+ // TQStrList does not support split, use TQStringList for that.
+ TQStringList l = TQStringList::split( '|', s );
+ TQStrList keys;
+ for ( TQStringList::Iterator it = l.begin(); it != l.end(); ++it )
+ keys.append( (*it).stripWhiteSpace().latin1() );
+ v = TQVariant( p->keysToValue( keys ) );
+ } else {
+ v = TQVariant( p->keyToValue( value.toCString().data() ) );
+ }
+ } else if ( v.type() != TQVariant::Int && v.type() != TQVariant::UInt ) {
+ return FALSE;
+ }
+ return qt_property( id, 0, &v );
+ }
+
+ TQVariant::Type type = (TQVariant::Type)(p->flags >> 24);
+ if ( type == TQVariant::Invalid )
+ type = TQVariant::nameToType( p->type() );
+ if ( type != TQVariant::Invalid && !v.canCast( type ) )
+ return FALSE;
+ return qt_property( id, 0, &v );
+}
+
+/*!
+ Returns the value of the object's \a name property.
+
+ If no such property exists, the returned variant is invalid.
+
+ Information about all available properties are provided through
+ the tqmetaObject().
+
+ \sa setProperty(), TQVariant::isValid(), tqmetaObject(),
+ TQMetaObject::propertyNames(), TQMetaObject::property()
+*/
+TQVariant TQObject::property( const char *name ) const
+{
+ TQVariant v;
+ TQMetaObject* meta = tqmetaObject();
+ if ( !meta )
+ return v;
+ int id = meta->tqfindProperty( name, TRUE );
+ const TQMetaProperty* p = meta->property( id, TRUE );
+ if ( !p || !p->isValid() ) {
+ qWarning( "%s::property( \"%s\" ) failed: property invalid or does not exist",
+ className(), name );
+ return v;
+ }
+ TQObject* that = (TQObject*) this; // tqmoc ensures constness for the qt_property call
+ that->qt_property( id, 1, &v );
+ return v;
+}
+
+#endif // TQT_NO_PROPERTIES
+
+#ifndef TQT_NO_USERDATA
+/*!\internal
+ */
+uint TQObject::registerUserData()
+{
+ static int user_data_registration = 0;
+ return user_data_registration++;
+}
+
+/*!\internal
+ */
+TQObjectUserData::~TQObjectUserData()
+{
+}
+
+/*!\internal
+ */
+void TQObject::setUserData( uint id, TQObjectUserData* data)
+{
+ if ( !d )
+ d = new TQObjectPrivate( id+1 );
+ if ( id >= d->size() )
+ d->resize( id+1 );
+ d->insert( id, data );
+}
+
+/*!\internal
+ */
+TQObjectUserData* TQObject::userData( uint id ) const
+{
+ if ( d && id < d->size() )
+ return d->at( id );
+ return 0;
+}
+
+#endif // TQT_NO_USERDATA
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqobject.h b/tqtinterface/qt4/src/kernel/tqobject.h
new file mode 100644
index 0000000..347cafe
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqobject.h
@@ -0,0 +1,417 @@
+/****************************************************************************
+**
+** Definition of TQObject class
+**
+** Created : 930418
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQOBJECT_H
+#define TQOBJECT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqobjectdefs.h"
+#include "tqwindowdefs.h"
+#include "tqstring.h"
+#include "tqevent.h"
+#include "tqnamespace.h"
+#include "tqobjectlist.h"
+#endif // TQT_H
+
+#define TQT_TR_NOOP(x) (x)
+#define TQT_TRANSLATE_NOOP(scope,x) (x)
+
+class TQMetaObject;
+class TQVariant;
+class TQMetaProperty;
+class TQPostEventList;
+class TQSenderObjectList;
+class TQObjectPrivate;
+#ifndef TQT_NO_USERDATA
+class TQObjectUserData;
+#endif
+struct TQUObject;
+
+#ifdef USE_QT4
+
+#include <Qt/qobject.h>
+#include <Qt/qapplication.h>
+
+#define TQT_TQOBJECT_REQUIRED_INITIALIZATION(x) connect(this, SIGNAL(destroyed(QObject*)), SLOT(tqt_handle_qt_destroyed(QObject*)));
+
+#define TQT_TQOBJECT_CHILDEVENT_REQUIRED_HANDLER(x) \
+ if (x->type() == QEvent::ChildAdded) { \
+ QChildEvent *tqce = new QChildEvent( (QEvent::Type)TQEvent::ChildInserted, ((QChildEvent*)x)->child() ); \
+ QApplication::postEvent( this, tqce ); \
+ }
+
+#define TQT_TQOBJECT_CHILDEVENT_CONDITIONAL if ((e->type() != QEvent::ChildAdded) && (e->type() != QEvent::ChildPolished))
+
+// Defined in tqwidget.cpp
+extern TQObject* convertFromTQT_BASE_OBJECT_NAMEPointer( TQT_BASE_OBJECT_NAME* x );
+extern const TQObject* convertFromTQT_BASE_OBJECT_NAMEPointerConst( const TQT_BASE_OBJECT_NAME* x );
+
+// Defined in tqobject.cpp
+extern TQMetaObject* tqstaticMetaObject_helper(const QMetaObject* mobj);
+
+class TQObject: public QObject, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQObject( TQT_BASE_OBJECT_NAME *tqparent=0, const char *name=0 );
+
+ TQObject *tqparent() const;
+ TQObjectList childrenListObject();
+ const TQObjectList childrenListObject() const;
+ const char *tqname() const;
+ const char *name() const;
+ const char *name(const char *defaultName) const;
+ TQObject *child( const char *objName, const char *inheritsClass = 0, bool recursiveSearch = TRUE );
+ bool tqsignalsBlocked() const;
+
+ virtual bool event( TQEvent * );
+ void killTimers();
+
+ void insertChild( TQObject *object );
+ void removeChild( TQObject *object );
+ bool isA(const char *classname) const;
+ bool inherits( const char * ) const;
+
+ void setName(const char *aName);
+
+ TQObjectList *queryList( const char *inheritsClass = 0, const char *objName = 0, bool regexpMatch = TRUE, bool recursiveSearch = TRUE ) const;
+
+ TQMetaObject *tqmetaObject() const;
+
+ virtual TQVariant property( const char *name ) const;
+
+ static const TQObjectList *objectTrees();
+ static const TQObjectList objectTreesListObject();
+
+ // TQt handler
+ virtual bool eventFilter( TQObject *, TQEvent * );
+
+ // Qt4 handler interface
+ virtual bool eventFilter( QObject *q, QEvent *e );
+ bool event( QEvent *e );
+
+ // Interoperability
+ static const TQObject& convertFromTQT_BASE_OBJECT_NAME( TQT_BASE_OBJECT_NAME& ql );
+
+protected:
+ bool checkConnectArgs(const char *signal, const TQT_BASE_OBJECT_NAME*, const char *member);
+
+// TQt event handlers
+protected:
+ virtual void timerEvent( TQTimerEvent * );
+ virtual void childEvent( TQChildEvent * );
+ virtual void customEvent( TQCustomEvent * );
+
+// Qt4 event handler interface
+protected:
+ virtual void timerEvent(QTimerEvent *e);
+ virtual void childEvent(QChildEvent *e);
+ virtual void customEvent(QEvent *e);
+
+public:
+ friend class TQApplication;
+ friend class TQBaseApplication;
+ friend class TQWidget;
+ friend class TQSignal;
+ friend class TQDialog;
+
+//protected:
+public:
+// // [FIXME]
+// // All of these need to be defined in terms of the Qt4 signal/slot mechanism somehow!
+// // It is possible that the tqmoc needs to remain completely separate from the Qt moc
+// // However, I am concerned that signal/slot mechanisms would then not work at all from TQt to Qt
+ TQConnectionList *tqreceivers( const char* signal ) const;
+ TQConnectionList *tqreceivers( int signal ) const;
+
+ // [FIXME]
+ // Verify that these are truly equivalent to their Qt3 counterparts!
+ void activate_signal( int signal );
+// void activate_signal( int signal, int );
+// void activate_signal( int signal, double );
+// void activate_signal( int signal, TQString );
+// void activate_signal_bool( int signal, bool );
+ void activate_signal( TQConnectionList *clist, TQUObject *o );
+
+ static TQCString normalizeSignalSlot( const char *signalSlot );
+
+public Q_SLOTS:
+ void tqt_handle_qt_destroyed(QObject* obj);
+
+Q_SIGNALS:
+ void destroyed( TQObject* obj );
+
+private:
+ TQSignalVec *connections;
+ TQSenderObjectList *senderObjects;
+ mutable TQString static_object_name;
+
+// Will these work as-is or do they need serious help?
+private:
+ uint isSignal : 1;
+ uint isWidget : 1;
+ uint pendTimer : 1;
+ uint blockSig : 1;
+ uint wasDeleted : 1;
+ uint isTree : 1;
+};
+
+// Interoperability
+inline static const TQObject& convertFromTQT_BASE_OBJECT_NAME( const TQT_BASE_OBJECT_NAME& qo ) {
+ return (*static_cast<const TQObject*>(&qo));
+}
+
+#else // USE_QT4
+
+#define TQT_TR_NOOP(x) (x)
+#define TQT_TRANSLATE_NOOP(scope,x) (x)
+
+class TQMetaObject;
+class TQVariant;
+class TQMetaProperty;
+class TQPostEventList;
+class TQSenderObjectList;
+class TQObjectPrivate;
+#ifndef TQT_NO_USERDATA
+class TQObjectUserData;
+#endif
+struct TQUObject;
+
+class TQ_EXPORT TQObject: public TQt
+{
+ TQ_OBJECT
+ Q_PROPERTY( TQCString name READ name WRITE setName )
+
+public:
+ TQObject( TQObject *tqparent=0, const char *name=0 );
+ virtual ~TQObject();
+
+#ifdef TQ_TQDOC
+ virtual const char *className() const;
+ static TQString tr( const char *, const char * );
+ static TQString trUtf8( const char *, const char * );
+ virtual TQMetaObject *tqmetaObject() const;
+#endif
+
+ virtual bool event( TQEvent * );
+ virtual bool eventFilter( TQObject *, TQEvent * );
+
+ bool isA( const char * ) const;
+ bool inherits( const char * ) const;
+
+ const char *name() const;
+ const char *name( const char * defaultName ) const;
+
+ virtual void setName( const char *name );
+ bool isWidgetType() const { return isWidget; }
+ bool highPriority() const { return FALSE; }
+
+ bool tqsignalsBlocked() const { return blockSig; }
+ void blockSignals( bool b );
+
+ int startTimer( int interval );
+ void killTimer( int id );
+ void killTimers();
+
+ TQObject *child( const char *objName, const char *inheritsClass = 0, bool recursiveSearch = TRUE ); //### const in 4.0
+ const TQObjectList *childrenListObject() const { return childObjects; }
+
+ static const TQObjectList *objectTrees();
+
+ TQObjectList *queryList( const char *inheritsClass = 0,
+ const char *objName = 0,
+ bool regexpMatch = TRUE,
+ bool recursiveSearch = TRUE ) const;
+
+ virtual void insertChild( TQObject * );
+ virtual void removeChild( TQObject * );
+
+ void installEventFilter( const TQObject * );
+ void removeEventFilter( const TQObject * );
+
+ static bool connect( const TQObject *sender, const char *signal,
+ const TQObject *receiver, const char *member );
+ bool connect( const TQObject *sender, const char *signal,
+ const char *member ) const;
+ static bool disconnect( const TQObject *sender, const char *signal,
+ const TQObject *receiver, const char *member );
+ bool disconnect( const char *signal=0,
+ const TQObject *receiver=0, const char *member=0 );
+ bool disconnect( const TQObject *receiver, const char *member=0 );
+ static void connectInternal( const TQObject *sender, int signal_index,
+ const TQObject *receiver, int membcode, int member_index );
+ static bool disconnectInternal( const TQObject *sender, int signal_index,
+ const TQObject *receiver, int membcode, int member_index );
+
+ void dumpObjectTree();
+ void dumpObjectInfo();
+
+#ifndef TQT_NO_PROPERTIES
+ virtual bool setProperty( const char *name, const TQVariant& value );
+ virtual TQVariant property( const char *name ) const;
+#endif // TQT_NO_PROPERTIES
+#ifdef TQT_NO_TRANSLATION
+ static TQString tr( const char *sourceText, const char * = 0);
+#ifndef TQT_NO_TEXTCODEC
+ static TQString trUtf8( const char *sourceText, const char * = 0);
+#endif
+#endif //TQT_NO_TRANSLATION
+
+#ifndef TQT_NO_USERDATA
+ static uint registerUserData();
+ void setUserData( uint id, TQObjectUserData* data);
+ TQObjectUserData* userData( uint id ) const;
+#endif // TQT_NO_USERDATA
+
+Q_SIGNALS:
+ void destroyed();
+ void destroyed( TQObject* obj );
+
+public:
+ TQObject *tqparent() const { return parentObj; }
+
+public Q_SLOTS:
+ void deleteLater();
+
+private Q_SLOTS:
+ void cleanupEventFilter( TQObject* );
+
+protected:
+ bool activate_filters( TQEvent * );
+ TQConnectionList *tqreceivers( const char* signal ) const;
+ TQConnectionList *tqreceivers( int signal ) const;
+ void activate_signal( int signal );
+ void activate_signal( int signal, int );
+ void activate_signal( int signal, double );
+ void activate_signal( int signal, TQString );
+ void activate_signal_bool( int signal, bool );
+ void activate_signal( TQConnectionList *clist, TQUObject *o );
+
+ const TQObject *sender();
+
+ virtual void timerEvent( TQTimerEvent * );
+ virtual void childEvent( TQChildEvent * );
+ virtual void customEvent( TQCustomEvent * );
+
+ virtual void connectNotify( const char *signal );
+ virtual void disconnectNotify( const char *signal );
+ virtual bool checkConnectArgs( const char *signal, const TQObject *receiver,
+ const char *member );
+ static TQCString normalizeSignalSlot( const char *signalSlot );
+
+private:
+ uint isSignal : 1;
+ uint isWidget : 1;
+ uint pendTimer : 1;
+ uint blockSig : 1;
+ uint wasDeleted : 1;
+ uint isTree : 1;
+
+ const char *objname;
+ TQObject *parentObj;
+ TQObjectList *childObjects;
+ TQSignalVec *connections;
+ TQSenderObjectList *senderObjects;
+ TQObjectList *eventFilters;
+ TQPostEventList *postedEvents;
+ TQObjectPrivate* d;
+
+ static TQMetaObject* staticTQtMetaObject();
+
+ friend class TQApplication;
+ friend class TQBaseApplication;
+ friend class TQWidget;
+ friend class TQSignal;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQObject( const TQObject & );
+ TQObject &operator=( const TQObject & );
+#endif
+};
+
+
+#ifndef TQT_NO_USERDATA
+class TQ_EXPORT TQObjectUserData {
+public:
+ virtual ~TQObjectUserData();
+};
+#endif
+
+
+inline bool TQObject::connect( const TQObject *sender, const char *signal,
+ const char *member ) const
+{
+ return connect( sender, signal, this, member );
+}
+
+
+inline bool TQObject::disconnect( const char *signal,
+ const TQObject *receiver, const char *member )
+{
+ return disconnect( this, signal, receiver, member );
+}
+
+
+inline bool TQObject::disconnect( const TQObject *receiver, const char *member )
+{
+ return disconnect( this, 0, receiver, member );
+}
+
+
+#ifdef TQT_NO_TRANSLATION
+inline TQString TQObject::tr( const char *sourceText, const char * ) {
+ return TQString::tqfromLatin1( sourceText );
+}
+#ifndef TQT_NO_TEXTCODEC
+inline TQString TQObject::trUtf8( const char *sourceText, const char * ) {
+ return TQString::fromUtf8( sourceText );
+}
+#endif
+#endif //TQT_NO_TRANSLATION
+
+
+#define TQ_DEFINED_TQOBJECT
+#include "tqwinexport.h"
+#endif // USE_QT4
+#endif // TQOBJECT_H
diff --git a/tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.cpp b/tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.cpp
new file mode 100644
index 0000000..fdee282
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Implementation of TQObjectCleanupHandler class
+**
+** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqobjectcleanuphandler.h"
+#include "tqobjectlist.h"
+
+/*!
+ \class TQObjectCleanupHandler tqobjectcleanuphandler.h
+ \brief The TQObjectCleanupHandler class watches the lifetime of multiple TQObjects.
+
+ \ingroup objectmodel
+
+ A TQObjectCleanupHandler is useful whenever you need to know when a
+ number of \l{TQObject}s that are owned by someone else have been
+ deleted. This is important, for example, when referencing memory
+ in an application that has been allocated in a shared library.
+
+ Example:
+
+ \code
+ class FactoryComponent : public FactoryInterface, public TQLibraryInterface
+ {
+ public:
+ ...
+
+ TQObject *createObject();
+
+ bool init();
+ void cleanup();
+ bool canUnload() const;
+
+ private:
+ TQObjectCleanupHandler objects;
+ };
+
+ // allocate a new object, and add it to the cleanup handler
+ TQObject *FactoryComponent::createObject()
+ {
+ return objects.add( new TQObject() );
+ }
+
+ // TQLibraryInterface implementation
+ bool FactoryComponent::init()
+ {
+ return TRUE;
+ }
+
+ void FactoryComponent::cleanup()
+ {
+ }
+
+ // it is only safe to unload the library when all TQObject's have been destroyed
+ bool FactoryComponent::canUnload() const
+ {
+ return objects.isEmpty();
+ }
+ \endcode
+*/
+
+/*!
+ Constructs an empty TQObjectCleanupHandler.
+*/
+TQObjectCleanupHandler::TQObjectCleanupHandler()
+: TQObject(), cleanupObjects( 0 )
+{
+}
+
+/*!
+ Destroys the cleanup handler. All objects in this cleanup handler
+ will be deleted.
+*/
+TQObjectCleanupHandler::~TQObjectCleanupHandler()
+{
+ clear();
+}
+
+/*!
+ Adds \a object to this cleanup handler and returns the pointer to
+ the object.
+*/
+TQObject* TQObjectCleanupHandler::add( TQObject* object )
+{
+ if ( !object )
+ return 0;
+
+ if ( !cleanupObjects ) {
+ cleanupObjects = new TQObjectList;
+ cleanupObjects->setAutoDelete( TRUE );
+ }
+ connect( object, TQT_SIGNAL(destroyed(TQObject*)), this, TQT_SLOT(objectDestroyed(TQObject*)) );
+ cleanupObjects->insert( 0, object );
+ return object;
+}
+
+/*!
+ Removes the \a object from this cleanup handler. The object will
+ not be destroyed.
+*/
+void TQObjectCleanupHandler::remove( TQObject *object )
+{
+ if ( !cleanupObjects )
+ return;
+ if ( cleanupObjects->tqfindRef( object ) >= 0 ) {
+ (void) cleanupObjects->take();
+ disconnect( object, TQT_SIGNAL(destroyed(TQObject*)), this, TQT_SLOT(objectDestroyed(TQObject*)) );
+ }
+}
+
+/*!
+ Returns TRUE if this cleanup handler is empty or if all objects in
+ this cleanup handler have been destroyed; otherwise return FALSE.
+*/
+bool TQObjectCleanupHandler::isEmpty() const
+{
+ return cleanupObjects ? cleanupObjects->isEmpty() : TRUE;
+}
+
+/*!
+ Deletes all objects in this cleanup handler. The cleanup handler
+ becomes empty.
+*/
+void TQObjectCleanupHandler::clear()
+{
+ delete cleanupObjects;
+ cleanupObjects = 0;
+}
+
+void TQObjectCleanupHandler::objectDestroyed( TQObject*object )
+{
+ if ( cleanupObjects )
+ cleanupObjects->setAutoDelete( FALSE );
+
+ remove( object );
+
+ if ( cleanupObjects )
+ cleanupObjects->setAutoDelete( TRUE );
+}
diff --git a/tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.h b/tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.h
new file mode 100644
index 0000000..0069167
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqobjectcleanuphandler.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Definition of ???
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQOBJECTCLEANUPHANDLER_H
+#define TQOBJECTCLEANUPHANDLER_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+class TQObjectList;
+
+class TQ_EXPORT TQObjectCleanupHandler : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ TQObjectCleanupHandler();
+ ~TQObjectCleanupHandler();
+
+ TQObject* add( TQObject* object );
+ void remove( TQObject *object );
+ bool isEmpty() const;
+ void clear();
+
+private:
+ TQObjectList *cleanupObjects;
+
+private Q_SLOTS:
+ void objectDestroyed( TQObject * );
+};
+
+#endif // TQOBJECTCLEANUPHANDLER_H
diff --git a/tqtinterface/qt4/src/kernel/tqobjectdefs.h b/tqtinterface/qt4/src/kernel/tqobjectdefs.h
new file mode 100644
index 0000000..794d1f0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqobjectdefs.h
@@ -0,0 +1,277 @@
+/****************************************************************************
+**
+** Macros and definitions related to TQObject
+**
+** Created : 930419
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQOBJECTDEFS_H
+#define TQOBJECTDEFS_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqglobal.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qobject.h>
+#include <Qt/qmetaobject.h>
+#undef TQT_H
+#include "tqvariant.h"
+
+#endif
+
+
+#ifndef TQT_NO_TRANSLATION
+# ifndef TQT_NO_TEXTCODEC
+// full set of tr functions
+# define TQT_TR_FUNCTIONS \
+ static TQString tr( const char *, const char * = 0 ); \
+ static TQString trUtf8( const char *, const char * = 0 );
+# else
+// no TQTextCodec, no utf8
+# define TQT_TR_FUNCTIONS \
+ static TQString tr( const char *, const char * = 0 );
+# endif
+#else
+// inherit the ones from TQObject
+# define TQT_TR_FUNCTIONS
+#endif
+
+#ifdef USE_QT4
+
+#ifndef TQT_NO_PROPERTIES
+# define TQT_PROP_FUNCTIONS \
+ inline virtual bool qt_property( int id, int f, TQVariant* v) { \
+ /* f==0 is write and f==1 is read */ \
+ QMetaProperty p = metaObject()->property(id); \
+ switch (f) { \
+ case 0: \
+ p.write(this, *v); \
+ break; \
+ case 1: \
+ *static_cast<QVariant*>(v) = p.read(this); \
+ break; \
+ } \
+ return true; /* Always assume success */ \
+ } \
+ //static bool qt_static_property( TQObject* , int, int, TQVariant* );
+#else
+# define TQT_PROP_FUNCTIONS
+#endif
+
+#else // USE_QT4
+
+#ifndef TQT_NO_PROPERTIES
+# define TQT_PROP_FUNCTIONS \
+ virtual bool qt_property( int id, int f, TQVariant* v); \
+ static bool qt_static_property( TQObject* , int, int, TQVariant* );
+#else
+# define TQT_PROP_FUNCTIONS
+#endif
+
+#endif // USE_QT4
+
+// The following macros are our "extensions" to C++
+// They are used, strictly speaking, only by the tqmoc.
+struct TQUObject;
+
+#ifdef TQT_TQMOC_CPP
+#define Q_SLOTS Q_SLOTS
+#define Q_SIGNALS Q_SIGNALS
+#define TQ_CLASSINFO( name, value ) TQ_CLASSINFO( name, value )
+#define TQ_PROPERTY( text ) TQ_PROPERTY( text )
+#define TQ_OVERRIDE( text ) TQ_OVERRIDE( text )
+#define TQ_ENUMS( x ) TQ_ENUMS( x )
+#define TQ_SETS( x ) TQ_SETS( x )
+
+#ifdef USE_QT4
+// /* tmake ignore TQ_OBJECT */
+#define TQ_OBJECT //
+// /* tmake ignore TQ_OBJECT */
+#define TQ_OBJECT_FAKE //
+#else // USE_QT4
+ /* tmake ignore TQ_OBJECT */
+#define TQ_OBJECT TQ_OBJECT
+ /* tmake ignore TQ_OBJECT */
+#define TQ_OBJECT_FAKE TQ_OBJECT_FAKE
+#endif // USE_QT4
+
+#else
+#define Q_SLOTS // Q_SLOTS: in class
+#define Q_SIGNALS protected // Q_SIGNALS: in class
+#ifndef TQT_NO_EMIT
+#define emit // emit signal
+#endif
+#define TQ_CLASSINFO( name, value ) // class info
+#define TQ_PROPERTY( text ) // property
+#define TQ_OVERRIDE( text ) // override property
+#define TQ_ENUMS( x )
+#define TQ_SETS( x )
+
+#ifdef USE_QT4
+
+# ifndef TQT_NO_TEXTCODEC
+// full set of tr functions
+# define TQT_TR_FUNCTIONS_QT4 \
+ inline static TQString tqtr( const char *ch1, const char *ch2 = 0 ) { return TQT_TQSTRING(tr(ch1, ch2)); } \
+ inline static TQString tqtrUtf8( const char *ch1, const char *ch2 = 0 ) { return TQT_TQSTRING(tr(ch1, ch2)); }
+# else
+// no TQTextCodec, no utf8
+# define TQT_TR_FUNCTIONS_QT4 \
+ inline static TQString tqtr( const char *ch1, const char *ch2 = 0 ) { return TQT_TQSTRING(tr(ch1, ch2)); }
+# endif
+
+#define TQ_OBJECT \
+public: \
+ inline static TQMetaObject* tqstaticMetaObject() \
+ { return tqstaticMetaObject_helper(&staticMetaObject); } \
+ inline virtual const char *className() const \
+ { return metaObject()->className(); } \
+ inline virtual void* tqqt_cast( const char* ctname ) \
+ { if (inherits(ctname)) \
+ return const_cast<TQT_BASE_OBJECT_NAME *>(reinterpret_cast<TQT_BASE_OBJECT_NAME *>(0)->staticMetaObject.cast(const_cast<QObject *>(static_cast<const QObject*>(TQT_TQOBJECT_CONST(this))))); \
+ return 0; } /* [FIXME] VERIFY THIS!!! */ \
+ inline void* qt_cast( const char* ctname ) \
+ { if (inherits(ctname)) \
+ return const_cast<TQT_BASE_OBJECT_NAME *>(reinterpret_cast<TQT_BASE_OBJECT_NAME *>(0)->staticMetaObject.cast(const_cast<QObject *>(static_cast<const QObject*>(TQT_TQOBJECT_CONST(this))))); \
+ return 0; } /* [FIXME] VERIFY THIS!!! */ \
+ inline virtual bool qt_invoke( int, TQUObject* ) \
+ { printf("[WARNING] qt_invoke unimplemented\n\r"); return false; } \
+ inline virtual bool qt_emit( int, TQUObject* ) \
+ { printf("[WARNING] qt_emit unimplemented\n\r"); return false; } \
+ TQT_PROP_FUNCTIONS \
+ TQT_TR_FUNCTIONS_QT4
+
+#else // USE_QT4
+/* tmake ignore TQ_OBJECT */
+#define TQ_OBJECT \
+public: \
+ virtual TQMetaObject *tqmetaObject() const { \
+ return staticMetaObject(); \
+ } \
+ virtual const char *className() const; \
+ virtual void* tqqt_cast( const char* ); \
+ virtual bool qt_invoke( int, TQUObject* ); \
+ virtual bool qt_emit( int, TQUObject* ); \
+ TQT_PROP_FUNCTIONS \
+ static TQMetaObject* staticMetaObject(); \
+ TQObject* qObject() { return (TQObject*)this; } \
+ TQT_TR_FUNCTIONS \
+private: \
+ static TQMetaObject *metaObj;
+
+#endif // USE_QT4
+
+/* tmake ignore TQ_OBJECT */
+#define TQ_OBJECT_FAKE TQ_OBJECT
+
+#endif
+
+// macro for naming members
+#ifdef TQT_METHOD
+#undef TQT_METHOD
+#endif
+#ifdef TQT_SLOT
+#undef TQT_SLOT
+#endif
+#ifdef TQT_SIGNAL
+#undef TQT_SIGNAL
+#endif
+
+#if defined(_OLD_CPP_)
+#define TQT_METHOD(a) "0""a"
+#define TQT_SLOT(a) "1""a"
+#define TQT_SIGNAL(a) "2""a"
+#else
+#define TQT_METHOD(a) "0"#a
+#define TQT_SLOT(a) "1"#a
+#define TQT_SIGNAL(a) "2"#a
+#endif
+
+#ifndef TQT_CLEAN_NAMESPACE
+#define METHOD_CODE 0 // member type codes
+#define SLOT_CODE 1
+#define SIGNAL_CODE 2
+#endif
+
+#define TQMETHOD_CODE 0 // member type codes
+#define TQSLOT_CODE 1
+#define TQSIGNAL_CODE 2
+
+class TQObject;
+class TQMetaObject;
+class TQSignal;
+class TQConnection;
+class TQEvent;
+struct TQMetaData;
+class TQConnectionList;
+class TQConnectionListIt;
+class TQSignalVec;
+class TQObjectList;
+class TQObjectListIt;
+class TQMemberDict;
+
+TQ_EXPORT void *qt_tqfind_obj_child( TQObject *, const char *, const char * );
+#define TQ_CHILD(tqparent,type,name) \
+ ((type*)qt_tqfind_obj_child(tqparent,#type,name))
+
+TQ_EXPORT void *qt_inheritedBy( TQMetaObject *super, const TQObject *cls );
+
+// template <typename T>
+// TQ_INLINE_TEMPLATES T tqqt_cast(const TQObject *object)
+// { return (T)qt_inheritedBy( ((T)0)->staticMetaObject(), object ); }
+
+// template <typename T>
+// TQ_INLINE_TEMPLATES T tqqt_cast(const TQT_BASE_OBJECT_NAME *object)
+// { return (T)qt_inheritedBy( ((T)0)->staticMetaObject(), TQT_TQOBJECT_CONST(object) ); }
+
+template <typename T>
+TQ_INLINE_TEMPLATES T tqqt_cast(const TQT_BASE_OBJECT_NAME *object)
+//{ return (const T)qobject_cast<const T>(object); }
+{
+// // this will cause a compilation error if T is not const
+// register T ptr = static_cast<T>(object);
+// Q_UNUSED(ptr);
+
+#if !defined(QT_NO_MEMBER_TEMPLATES) && !defined(QT_NO_QOBJECT_CHECK)
+ reinterpret_cast<T>(0)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(const_cast<TQT_BASE_OBJECT_NAME *>(object)));
+#endif
+ return static_cast<T>(const_cast<TQT_BASE_OBJECT_NAME *>(reinterpret_cast<T>(0)->staticMetaObject.cast(const_cast<TQT_BASE_OBJECT_NAME *>(object))));
+}
+#endif // TQOBJECTDEFS_H
diff --git a/tqtinterface/qt4/src/kernel/tqobjectdict.h b/tqtinterface/qt4/src/kernel/tqobjectdict.h
new file mode 100644
index 0000000..1e9e93e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqobjectdict.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Definition of TQObjectDictionary
+**
+** Created : 940807
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQOBJECTDICT_H
+#define TQOBJECTDICT_H
+
+#ifndef TQT_H
+#include "tqmetaobject.h"
+#include "tqasciidict.h"
+#endif // TQT_H
+
+
+//
+// The object dictionary is a collection of TQMetaObjects
+//
+
+class TQ_EXPORT TQObjectDictionary : public TQAsciiDict<TQMetaObject>
+{
+public:
+ TQObjectDictionary(int size=17,bool cs=TRUE,bool ck=TRUE)
+ : TQAsciiDict<TQMetaObject>(size,cs,ck) {}
+ TQObjectDictionary( const TQObjectDictionary &dict )
+ : TQAsciiDict<TQMetaObject>(dict) {}
+ ~TQObjectDictionary() { clear(); }
+ TQObjectDictionary &operator=(const TQObjectDictionary &dict)
+ { return (TQObjectDictionary&)TQAsciiDict<TQMetaObject>::operator=(dict);}
+};
+
+#endif // TQOBJECTDICT_H
diff --git a/tqtinterface/qt4/src/kernel/tqobjectlist.h b/tqtinterface/qt4/src/kernel/tqobjectlist.h
new file mode 100644
index 0000000..337a795
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqobjectlist.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Definition of TQObjectList
+**
+** Created : 940807
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQOBJECTLIST_H
+#define TQOBJECTLIST_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqptrlist.h"
+#endif // TQT_H
+
+
+#if defined(TQ_TEMPLATEDLL)
+//TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrList<TQObject>;
+//TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrListIterator<TQObject>;
+#endif
+
+
+class TQ_EXPORT TQObjectList : public TQPtrList<TQObject>
+{
+public:
+ TQObjectList() : TQPtrList<TQObject>() {}
+ TQObjectList( const TQObjectList &list ) : TQPtrList<TQObject>(list) {}
+ ~TQObjectList() { clear(); }
+ TQObjectList &operator=(const TQObjectList &list)
+ { return (TQObjectList&)TQPtrList<TQObject>::operator=(list); }
+};
+
+class TQ_EXPORT TQObjectListIterator : public TQPtrListIterator<TQObject>
+{
+public:
+ TQObjectListIterator( const TQObjectList &l )
+ : TQPtrListIterator<TQObject>( l ) { }
+ TQObjectListIterator &operator=( const TQObjectListIterator &i )
+ { return (TQObjectListIterator&)
+ TQPtrListIterator<TQObject>::operator=( i ); }
+};
+
+#if (TQT_VERSION-0 >= 0x040000)
+#if defined(TQ_CC_GNU)
+#warning "remove the TQObjectListIt class"
+#warning "remove the typedef too, maybe"
+#endif
+typedef TQObjectListIterator TQObjectListIt;
+#else
+class TQ_EXPORT TQObjectListIt : public TQPtrListIterator<TQObject>
+{
+public:
+ TQObjectListIt( const TQObjectList &l ) : TQPtrListIterator<TQObject>(l) {}
+ TQObjectListIt &operator=(const TQObjectListIt &i)
+ { return (TQObjectListIt&)TQPtrListIterator<TQObject>::operator=(i); }
+};
+#endif
+
+#endif // TQOBJECTLIST_H
diff --git a/tqtinterface/qt4/src/kernel/tqpaintdevice.h b/tqtinterface/qt4/src/kernel/tqpaintdevice.h
new file mode 100644
index 0000000..5c7a2c7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpaintdevice.h
@@ -0,0 +1,688 @@
+/****************************************************************************
+**
+** Definition of TQPaintDevice class
+**
+** Created : 940721
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPAINTDEVICE_H
+#define TQPAINTDEVICE_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqrect.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qapplication.h>
+#include <Qt/qx11info_x11.h>
+#include <Qt/qpaintdevice.h>
+#include <Qt/qpaintengine.h>
+
+#endif // USE_QT4
+
+#if defined(TQ_WS_TQWS)
+class TQWSDisplay;
+class TQGfx;
+#endif
+
+class TQIODevice;
+class TQString;
+class TQTextItem;
+
+#ifdef USE_QT4
+
+#if defined(TQ_WS_X11)
+struct TQPaintDeviceX11Data;
+#endif
+
+// There does not seem to be a Qt4 equivalent for this
+union TQPDevCmdParam {
+ int ival;
+ int *ivec;
+ TQString *str;
+ const TQPoint *point;
+ const TQRect *rect;
+ const TQPointArray *ptarr;
+ const TQPixmap *pixmap;
+ const TQImage *image;
+ const TQColor *color;
+ const TQFont *font;
+ const TQPen *pen;
+ const TQBrush *brush;
+ const TQRegion *rgn;
+ const TQWMatrix *matrix;
+ const TQTextItem *textItem;
+ TQIODevice *tqdevice;
+};
+
+class TQPaintDevice;
+
+class TQ_EXPORT TQPaintDeviceEngineTranslator : public QPaintEngine
+{
+public:
+ TQPaintDeviceEngineTranslator() : QPaintEngine() {}
+ TQPaintDeviceEngineTranslator(TQPaintDevice* tqpd) : QPaintEngine() { parent_paintdevice = tqpd; }
+
+ inline void setPaintDevice(TQPaintDevice* tqpd) { parent_paintdevice = tqpd; }
+
+ // Reimplemented QPaintEngine methods
+ virtual bool begin(QPaintDevice*);
+ virtual bool end();
+ virtual void updateState(const QPaintEngineState&);
+ virtual void drawPixmap(const QRectF&, const QPixmap&, const QRectF&);
+ virtual QPaintEngine::Type type() const;
+
+private:
+ TQPaintDevice* parent_paintdevice;
+};
+
+class TQ_EXPORT TQPaintDevice : public QPaintDevice, virtual public TQt
+{
+public:
+ TQPaintDevice() : QPaintDevice() { tqpet.setPaintDevice(this); }
+// TQPaintDevice( const QPaintDevice &pd ) : QPaintDevice( pd ) {}
+
+ inline static void *x11AppVisual( void ) { return x11AppVisual(-1); }
+ inline static void *x11AppVisual( int screen ) { return QX11Info::appVisual(screen); }
+ inline static int x11AppCells( void ) { return x11AppCells(-1); }
+ inline static int x11AppCells( int screen ) { return QX11Info::appCells(screen); }
+ inline static int x11AppDepth( void ) { return x11AppDepth(-1); }
+ inline static int x11AppDepth( int screen ) { return QX11Info::appDepth(screen); }
+ inline static Display *x11AppDisplay( void ) { return QX11Info::display(); }
+ inline static int x11AppScreen( void ) { return QX11Info::appScreen(); }
+ inline static bool x11AppDefaultVisual( void ) { return x11AppDefaultVisual(-1); }
+ inline static bool x11AppDefaultVisual( int screen ) { return QX11Info::appDefaultVisual(screen); }
+ inline static TQt::HANDLE x11AppColormap( void ) { return x11AppColormap(-1); }
+ inline static TQt::HANDLE x11AppColormap( int screen ) { return QX11Info::appColormap(screen); }
+ inline static bool x11AppDefaultColormap( void ) { return x11AppDefaultColormap(-1); }
+ inline static bool x11AppDefaultColormap( int screen ) { return QX11Info::appDefaultColormap(screen); }
+ inline static TQt::HANDLE x11AppRootWindow( void ) { return x11AppRootWindow(-1); }
+ inline static TQt::HANDLE x11AppRootWindow( int screen ) { return QX11Info::appRootWindow(screen); }
+
+ bool isExtDev() const;
+
+ // Windows: get tqdevice context
+ // X-Windows: get drawable
+#if defined(TQ_WS_WIN)
+// virtual HDC handle() const;
+#elif defined(TQ_WS_X11)
+ virtual TQt::HANDLE handle() const;
+ virtual TQt::HANDLE x11RenderHandle() const;
+#elif defined(TQ_WS_MAC)
+// virtual TQt::HANDLE handle() const;
+#elif defined(TQ_WS_TQWS)
+// virtual TQt::HANDLE handle() const;
+#endif
+
+#if defined(TQ_WS_X11)
+ Display *x11Display() const;
+ int x11Screen() const;
+ int x11Depth() const;
+ int x11Cells() const;
+ Qt::HANDLE x11Colormap() const;
+ bool x11DefaultColormap() const;
+ void *x11Visual() const;
+ bool x11DefaultVisual() const;
+
+ static int x11AppDpiX(int screen = -1);
+ static int x11AppDpiY(int screen = -1);
+ static void x11SetAppDpiX(int, int);
+ static void x11SetAppDpiY(int, int);
+#endif
+
+public:
+ // There does not seem to be a Qt4 equivalent for this
+ enum PDevCmd {
+ PdcNOP = 0, // <void>
+ PdcDrawPoint = 1, // point
+ PdcDrawFirst = PdcDrawPoint,
+ PdcMoveTo = 2, // point
+ PdcLineTo = 3, // point
+ PdcDrawLine = 4, // point,point
+ PdcDrawRect = 5, // rect
+ PdcDrawRoundRect = 6, // rect,ival,ival
+ PdcDrawEllipse = 7, // rect
+ PdcDrawArc = 8, // rect,ival,ival
+ PdcDrawPie = 9, // rect,ival,ival
+ PdcDrawChord = 10, // rect,ival,ival
+ PdcDrawLineSegments = 11, // ptarr
+ PdcDrawPolyline = 12, // ptarr
+ PdcDrawPolygon = 13, // ptarr,ival
+ PdcDrawCubicBezier = 14, // ptarr
+ PdcDrawText = 15, // point,str
+ PdcDrawTextFormatted = 16, // rect,ival,str
+ PdcDrawPixmap = 17, // rect,pixmap
+ PdcDrawImage = 18, // rect,image
+ PdcDrawText2 = 19, // point,str
+ PdcDrawText2Formatted = 20, // rect,ival,str
+ PdcDrawTextItem = 21,
+ PdcDrawLast = PdcDrawTextItem,
+
+ // no painting commands below PdcDrawLast.
+
+ PdcBegin = 30, // <void>
+ PdcEnd = 31, // <void>
+ PdcSave = 32, // <void>
+ PdcRestore = 33, // <void>
+ PdcSetdev = 34, // tqdevice - PRIVATE
+ PdcSetBkColor = 40, // color
+ PdcSetBkMode = 41, // ival
+ PdcSetROP = 42, // ival
+ PdcSetBrushOrigin = 43, // point
+ PdcSetFont = 45, // font
+ PdcSetPen = 46, // pen
+ PdcSetBrush = 47, // brush
+ PdcSetTabStops = 48, // ival
+ PdcSetTabArray = 49, // ival,ivec
+ PdcSetUnit = 50, // ival
+ PdcSetVXform = 51, // ival
+ PdcSetWindow = 52, // rect
+ PdcSetViewport = 53, // rect
+ PdcSetWXform = 54, // ival
+ PdcSetWMatrix = 55, // matrix,ival
+ PdcSaveWMatrix = 56,
+ PdcRestoreWMatrix = 57,
+ PdcSetClip = 60, // ival
+ PdcSetClipRegion = 61, // rgn
+
+ PdcReservedStart = 0, // codes 0-199 are reserved
+ PdcReservedStop = 199 // for TQt
+ };
+
+protected:
+ TQPaintDevice( uint devflags );
+#if defined(TQ_WS_X11)
+ friend void qt_init_internal( int *, char **, Display *, TQt::HANDLE, TQt::HANDLE );
+ friend void qt_cleanup();
+ virtual bool cmd( int, TQPainter *, TQPDevCmdParam * );
+ virtual QPaintEngine* paintEngine() const;
+#endif
+
+private:
+#if defined(TQ_WS_X11)
+ static Display *x_appdisplay;
+ static int x_appscreen;
+
+ static int x_appdepth;
+ static int x_appcells;
+ static TQt::HANDLE x_approotwindow;
+ static TQt::HANDLE x_appcolormap;
+ static bool x_appdefcolormap;
+ static void *x_appvisual;
+ static bool x_appdefvisual;
+
+ // ### in 4.0, remove the above, and tqreplace with the below
+ static int *x_appdepth_arr;
+ static int *x_appcells_arr;
+ static TQt::HANDLE *x_approotwindow_arr;
+ static TQt::HANDLE *x_appcolormap_arr;
+ static bool *x_appdefcolormap_arr;
+ static void **x_appvisual_arr;
+ static bool *x_appdefvisual_arr;
+
+ TQPaintDeviceX11Data* x11Data;
+
+ TQPaintDeviceEngineTranslator tqpet;
+#endif
+
+public:
+ // Interoperability
+ static const TQPaintDevice& convertFromQPaintDevice( QPaintDevice& qpd );
+};
+
+// Interoperability
+inline static const TQPaintDevice& convertFromQPaintDevice( const QPaintDevice& qpd ) {
+ return (*static_cast<const TQPaintDevice*>(&qpd));
+}
+
+void bitBlt(QPaintDevice *dst, int dx, int dy,
+ const QPaintDevice *src, int sx=0, int sy=0, int sw=-1, int sh=-1,
+ bool ignoreMask=false);
+
+void bitBlt(QPaintDevice *dst, int dx, int dy,
+ const QImage *src, int sx=0, int sy=0, int sw=-1, int sh=-1,
+ int conversion_flags=0);
+
+void bitBlt(QPaintDevice *dst, const QPoint &dp,
+ const QPaintDevice *src, const QRect &sr=QRect(0,0,-1,-1),
+ bool ignoreMask=false);
+
+TQ_EXPORT void bitBlt( TQPaintDevice *dst, int dx, int dy, const TQPaintDevice *src, int sx=0, int sy=0, int sw=-1, int sh=-1, TQt::RasterOp = TQt::CopyROP, bool ignoreMask=FALSE );
+
+// [FIXME]
+inline bool TQPaintDevice::isExtDev() const
+//{ return (devFlags & TQInternal::ExternalDevice) != 0; }
+{ return false; }
+
+#if defined(TQ_WS_X11)
+
+struct TQ_EXPORT TQPaintDeviceX11Data : public TQShared {
+ Display* x_display;
+ int x_screen;
+ int x_depth;
+ int x_cells;
+ TQt::HANDLE x_colormap;
+ bool x_defcolormap;
+ void* x_visual;
+ bool x_defvisual;
+};
+
+#endif
+
+// This provides a default interface from the old Qt3 cmd based API to the new Qt4 QPaintEngine based API
+// It can (obviously) be overridden if someone desires to use QPaintEngine instead of the cmd based API!
+inline QPaintEngine* TQPaintDevice::paintEngine() const {
+ // Provide the address of the translator class...
+ return const_cast<TQPaintDeviceEngineTranslator*>(&tqpet);
+}
+
+TQ_EXPORT
+inline void bitBlt( TQPaintDevice *dst, const TQPoint &dp,
+ const TQPaintDevice *src, const TQRect &sr =TQRect(0,0,-1,-1),
+ TQt::RasterOp rop=TQt::CopyROP, bool ignoreMask=FALSE )
+{
+ bitBlt( dst, dp.x(), dp.y(), src, sr.x(), sr.y(), sr.width(), sr.height(),
+ rop, ignoreMask );
+}
+
+#else // USE_QT4
+
+#if defined(TQ_WS_X11)
+struct TQPaintDeviceX11Data;
+#endif
+
+union TQPDevCmdParam {
+ int ival;
+ int *ivec;
+ TQString *str;
+ const TQPoint *point;
+ const TQRect *rect;
+ const TQPointArray *ptarr;
+ const TQPixmap *pixmap;
+ const TQImage *image;
+ const TQColor *color;
+ const TQFont *font;
+ const TQPen *pen;
+ const TQBrush *brush;
+ const TQRegion *rgn;
+ const TQWMatrix *matrix;
+ const TQTextItem *textItem;
+ TQIODevice *tqdevice;
+};
+
+
+
+class TQ_EXPORT TQPaintDevice // tqdevice for TQPainter
+{
+public:
+ virtual ~TQPaintDevice();
+
+ int devType() const;
+ bool isExtDev() const;
+ bool paintingActive() const;
+
+ virtual void setResolution( int );
+ virtual int resolution() const;
+
+ // Windows: get tqdevice context
+ // X-Windows: get drawable
+#if defined(TQ_WS_WIN)
+ virtual HDC handle() const;
+#elif defined(TQ_WS_X11)
+ virtual TQt::HANDLE handle() const;
+ virtual TQt::HANDLE x11RenderHandle() const;
+#elif defined(TQ_WS_MAC)
+ virtual TQt::HANDLE handle() const;
+#elif defined(TQ_WS_TQWS)
+ virtual TQt::HANDLE handle() const;
+#endif
+
+#if defined(TQ_WS_X11)
+ Display *x11Display() const;
+ int x11Screen() const;
+ int x11Depth() const;
+ int x11Cells() const;
+ TQt::HANDLE x11Colormap() const;
+ bool x11DefaultColormap() const;
+ void *x11Visual() const;
+ bool x11DefaultVisual() const;
+
+ static Display *x11AppDisplay();
+ static int x11AppScreen();
+
+ static int x11AppDpiX();
+ static int x11AppDpiY();
+ static void x11SetAppDpiX(int);
+ static void x11SetAppDpiY(int);
+ static int x11AppDepth();
+ static int x11AppCells();
+ static TQt::HANDLE x11AppRootWindow();
+ static TQt::HANDLE x11AppColormap();
+ static bool x11AppDefaultColormap();
+ static void *x11AppVisual();
+ static bool x11AppDefaultVisual();
+
+ // ### in 4.0, the above need to go away, the below needs to take a -1 default
+ // argument, signifying the default screen...
+ static int x11AppDepth( int screen );
+ static int x11AppCells( int screen );
+ static TQt::HANDLE x11AppRootWindow( int screen );
+ static TQt::HANDLE x11AppColormap( int screen );
+ static void *x11AppVisual( int screen );
+ static bool x11AppDefaultColormap( int screen );
+ static bool x11AppDefaultVisual( int screen );
+ static int x11AppDpiX( int );
+ static int x11AppDpiY( int );
+ static void x11SetAppDpiX( int, int );
+ static void x11SetAppDpiY( int, int );
+#endif
+
+#if defined(TQ_WS_TQWS)
+ static TQWSDisplay *qwsDisplay();
+ virtual unsigned char * scanLine(int) const;
+ virtual int bytesPerLine() const;
+ virtual TQGfx * graphicsContext(bool clip_tqchildren=TRUE) const;
+#endif
+
+ enum PDevCmd {
+ PdcNOP = 0, // <void>
+ PdcDrawPoint = 1, // point
+ PdcDrawFirst = PdcDrawPoint,
+ PdcMoveTo = 2, // point
+ PdcLineTo = 3, // point
+ PdcDrawLine = 4, // point,point
+ PdcDrawRect = 5, // rect
+ PdcDrawRoundRect = 6, // rect,ival,ival
+ PdcDrawEllipse = 7, // rect
+ PdcDrawArc = 8, // rect,ival,ival
+ PdcDrawPie = 9, // rect,ival,ival
+ PdcDrawChord = 10, // rect,ival,ival
+ PdcDrawLineSegments = 11, // ptarr
+ PdcDrawPolyline = 12, // ptarr
+ PdcDrawPolygon = 13, // ptarr,ival
+ PdcDrawCubicBezier = 14, // ptarr
+ PdcDrawText = 15, // point,str
+ PdcDrawTextFormatted = 16, // rect,ival,str
+ PdcDrawPixmap = 17, // rect,pixmap
+ PdcDrawImage = 18, // rect,image
+ PdcDrawText2 = 19, // point,str
+ PdcDrawText2Formatted = 20, // rect,ival,str
+ PdcDrawTextItem = 21,
+ PdcDrawLast = PdcDrawTextItem,
+
+ // no painting commands below PdcDrawLast.
+
+ PdcBegin = 30, // <void>
+ PdcEnd = 31, // <void>
+ PdcSave = 32, // <void>
+ PdcRestore = 33, // <void>
+ PdcSetdev = 34, // tqdevice - PRIVATE
+ PdcSetBkColor = 40, // color
+ PdcSetBkMode = 41, // ival
+ PdcSetROP = 42, // ival
+ PdcSetBrushOrigin = 43, // point
+ PdcSetFont = 45, // font
+ PdcSetPen = 46, // pen
+ PdcSetBrush = 47, // brush
+ PdcSetTabStops = 48, // ival
+ PdcSetTabArray = 49, // ival,ivec
+ PdcSetUnit = 50, // ival
+ PdcSetVXform = 51, // ival
+ PdcSetWindow = 52, // rect
+ PdcSetViewport = 53, // rect
+ PdcSetWXform = 54, // ival
+ PdcSetWMatrix = 55, // matrix,ival
+ PdcSaveWMatrix = 56,
+ PdcRestoreWMatrix = 57,
+ PdcSetClip = 60, // ival
+ PdcSetClipRegion = 61, // rgn
+
+ PdcReservedStart = 0, // codes 0-199 are reserved
+ PdcReservedStop = 199 // for TQt
+ };
+
+protected:
+ TQPaintDevice( uint devflags );
+
+#if defined(TQ_WS_WIN)
+ HDC hdc; // tqdevice context
+#elif defined(TQ_WS_X11)
+ TQt::HANDLE hd; // handle to drawable
+ TQt::HANDLE rendhd; // handle to RENDER pict
+
+ void copyX11Data( const TQPaintDevice * );
+ void cloneX11Data( const TQPaintDevice * );
+ virtual void setX11Data( const TQPaintDeviceX11Data* );
+ TQPaintDeviceX11Data* getX11Data( bool def=FALSE ) const;
+#elif defined(TQ_WS_MAC)
+#if !defined( TQMAC_NO_TQUARTZ )
+ CGContextRef ctx;
+#endif
+ void * hd;
+#elif defined(TQ_WS_TQWS)
+ TQt::HANDLE hd;
+#endif
+
+ virtual bool cmd( int, TQPainter *, TQPDevCmdParam * );
+ virtual int metric( int ) const;
+ virtual int fontMet( TQFont *, int, const char * = 0, int = 0 ) const;
+ virtual int fontInf( TQFont *, int ) const;
+
+ ushort devFlags; // tqdevice flags
+ ushort painters; // refcount
+
+ friend class TQPainter;
+ friend class TQPaintDeviceMetrics;
+#if defined(TQ_WS_MAC)
+#ifndef TQMAC_NO_TQUARTZ
+ virtual CGContextRef macCGContext(bool clipped=TRUE) const;
+#endif
+ friend TQ_EXPORT void unclippedScaledBitBlt( TQPaintDevice *, int, int, int, int,
+ const TQPaintDevice *, int, int, int, int, TQt::RasterOp, bool, bool );
+#else
+ friend TQ_EXPORT void bitBlt( TQPaintDevice *, int, int,
+ const TQPaintDevice *,
+ int, int, int, int, TQt::RasterOp, bool );
+#endif
+#if defined(TQ_WS_X11)
+ friend void qt_init_internal( int *, char **, Display *, TQt::HANDLE, TQt::HANDLE );
+ friend void qt_cleanup();
+#endif
+
+private:
+#if defined(TQ_WS_X11)
+ static Display *x_appdisplay;
+ static int x_appscreen;
+
+ static int x_appdepth;
+ static int x_appcells;
+ static TQt::HANDLE x_approotwindow;
+ static TQt::HANDLE x_appcolormap;
+ static bool x_appdefcolormap;
+ static void *x_appvisual;
+ static bool x_appdefvisual;
+
+ // ### in 4.0, remove the above, and tqreplace with the below
+ static int *x_appdepth_arr;
+ static int *x_appcells_arr;
+ static TQt::HANDLE *x_approotwindow_arr;
+ static TQt::HANDLE *x_appcolormap_arr;
+ static bool *x_appdefcolormap_arr;
+ static void **x_appvisual_arr;
+ static bool *x_appdefvisual_arr;
+
+ TQPaintDeviceX11Data* x11Data;
+#endif
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQPaintDevice( const TQPaintDevice & );
+ TQPaintDevice &operator=( const TQPaintDevice & );
+#endif
+};
+
+
+TQ_EXPORT
+void bitBlt( TQPaintDevice *dst, int dx, int dy,
+ const TQPaintDevice *src, int sx=0, int sy=0, int sw=-1, int sh=-1,
+ TQt::RasterOp = TQt::CopyROP, bool ignoreMask=FALSE );
+
+TQ_EXPORT
+void bitBlt( TQPaintDevice *dst, int dx, int dy,
+ const TQImage *src, int sx=0, int sy=0, int sw=-1, int sh=-1,
+ int conversion_flags=0 );
+
+
+#if defined(TQ_WS_X11)
+
+struct TQ_EXPORT TQPaintDeviceX11Data : public TQShared {
+ Display* x_display;
+ int x_screen;
+ int x_depth;
+ int x_cells;
+ TQt::HANDLE x_colormap;
+ bool x_defcolormap;
+ void* x_visual;
+ bool x_defvisual;
+};
+
+#endif
+
+/*****************************************************************************
+ Inline functions
+ *****************************************************************************/
+
+inline int TQPaintDevice::devType() const
+{ return devFlags & TQInternal::DeviceTypeMask; }
+
+inline bool TQPaintDevice::isExtDev() const
+{ return (devFlags & TQInternal::ExternalDevice) != 0; }
+
+inline bool TQPaintDevice::paintingActive() const
+{ return painters != 0; }
+
+#if defined(TQ_WS_X11)
+inline Display *TQPaintDevice::x11Display() const
+{ return x11Data ? x11Data->x_display : x_appdisplay; }
+
+inline int TQPaintDevice::x11Screen() const
+{ return x11Data ? x11Data->x_screen : x_appscreen; }
+
+inline int TQPaintDevice::x11Depth() const
+{ return x11Data ? x11Data->x_depth : x_appdepth; }
+
+inline int TQPaintDevice::x11Cells() const
+{ return x11Data ? x11Data->x_cells : x_appcells; }
+
+inline TQt::HANDLE TQPaintDevice::x11Colormap() const
+{ return x11Data ? x11Data->x_colormap : x_appcolormap; }
+
+inline bool TQPaintDevice::x11DefaultColormap() const
+{ return x11Data ? x11Data->x_defcolormap : x_appdefcolormap; }
+
+inline void *TQPaintDevice::x11Visual() const
+{ return x11Data ? x11Data->x_visual : x_appvisual; }
+
+inline bool TQPaintDevice::x11DefaultVisual() const
+{ return x11Data ? x11Data->x_defvisual : x_appdefvisual; }
+
+inline Display *TQPaintDevice::x11AppDisplay()
+{ return x_appdisplay; }
+
+inline int TQPaintDevice::x11AppScreen()
+{ return x_appscreen; }
+
+inline int TQPaintDevice::x11AppDepth( int screen )
+{ return x_appdepth_arr[ screen == -1 ? x_appscreen : screen ]; }
+
+inline int TQPaintDevice::x11AppCells( int screen )
+{ return x_appcells_arr[ screen == -1 ? x_appscreen : screen ]; }
+
+inline TQt::HANDLE TQPaintDevice::x11AppRootWindow( int screen )
+{ return x_approotwindow_arr[ screen == -1 ? x_appscreen : screen ]; }
+
+inline TQt::HANDLE TQPaintDevice::x11AppColormap( int screen )
+{ return x_appcolormap_arr[ screen == -1 ? x_appscreen : screen ]; }
+
+inline bool TQPaintDevice::x11AppDefaultColormap( int screen )
+{ return x_appdefcolormap_arr[ screen == -1 ? x_appscreen : screen ]; }
+
+inline void *TQPaintDevice::x11AppVisual( int screen )
+{ return x_appvisual_arr[ screen == -1 ? x_appscreen : screen ]; }
+
+inline bool TQPaintDevice::x11AppDefaultVisual( int screen )
+{ return x_appdefvisual_arr[ screen == -1 ? x_appscreen : screen ]; }
+
+inline int TQPaintDevice::x11AppDepth()
+{ return x_appdepth; }
+
+inline int TQPaintDevice::x11AppCells()
+{ return x_appcells; }
+
+inline TQt::HANDLE TQPaintDevice::x11AppRootWindow()
+{ return x_approotwindow; }
+
+inline TQt::HANDLE TQPaintDevice::x11AppColormap()
+{ return x_appcolormap; }
+
+inline bool TQPaintDevice::x11AppDefaultColormap()
+{ return x_appdefcolormap; }
+
+inline void *TQPaintDevice::x11AppVisual()
+{ return x_appvisual; }
+
+inline bool TQPaintDevice::x11AppDefaultVisual()
+{ return x_appdefvisual; }
+
+#endif // TQ_WS_X11
+
+
+TQ_EXPORT
+inline void bitBlt( TQPaintDevice *dst, const TQPoint &dp,
+ const TQPaintDevice *src, const TQRect &sr =TQRect(0,0,-1,-1),
+ TQt::RasterOp rop=TQt::CopyROP, bool ignoreMask=FALSE )
+{
+ bitBlt( dst, dp.x(), dp.y(), src, sr.x(), sr.y(), sr.width(), sr.height(),
+ rop, ignoreMask );
+}
+
+#endif // USE_QT4
+
+#endif // TQPAINTDEVICE_H
diff --git a/tqtinterface/qt4/src/kernel/tqpaintdevice_x11.cpp b/tqtinterface/qt4/src/kernel/tqpaintdevice_x11.cpp
new file mode 100644
index 0000000..2432607
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpaintdevice_x11.cpp
@@ -0,0 +1,1746 @@
+/****************************************************************************
+**
+** Implementation of TQPaintDevice class for X11
+**
+** Created : 940721
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpaintdevice.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqpainter.h"
+#include "tqwidget.h"
+#include "tqbitmap.h"
+#include "tqapplication.h"
+#include "tqt_x11_p.h"
+
+#ifdef USE_QT4
+
+//
+// Some global variables - these are initialized by TQColor::initialize()
+//
+
+Display *TQPaintDevice::x_appdisplay = 0;
+int TQPaintDevice::x_appscreen;
+
+int TQPaintDevice::x_appdepth;
+int TQPaintDevice::x_appcells;
+TQt::HANDLE TQPaintDevice::x_approotwindow;
+TQt::HANDLE TQPaintDevice::x_appcolormap;
+bool TQPaintDevice::x_appdefcolormap;
+void *TQPaintDevice::x_appvisual;
+bool TQPaintDevice::x_appdefvisual;
+
+// ### in 4.0, remove the above, and use the below
+int *TQPaintDevice::x_appdepth_arr;
+int *TQPaintDevice::x_appcells_arr;
+TQt::HANDLE *TQPaintDevice::x_approotwindow_arr;
+TQt::HANDLE *TQPaintDevice::x_appcolormap_arr;
+bool *TQPaintDevice::x_appdefcolormap_arr;
+void **TQPaintDevice::x_appvisual_arr;
+bool *TQPaintDevice::x_appdefvisual_arr;
+
+/*!
+ Constructs a paint tqdevice with internal flags \a devflags. This
+ constructor can be invoked only from TQPaintDevice subclasses.
+*/
+
+TQPaintDevice::TQPaintDevice( uint devflags )
+{
+ if ( !tqApp ) { // global constructor
+#if defined(TQT_CHECK_STATE)
+ qFatal( "TQPaintDevice: Must construct a TQApplication before a "
+ "TQPaintDevice" );
+#endif
+ return;
+ }
+
+ // [FIXME]
+ printf("[WARNING] TQPaintDevice::TQPaintDevice( uint devflags ) unimplemented\n\r");
+// devFlags = devflags;
+// painters = 0;
+// hd = 0;
+// rendhd = 0;
+// x11Data = 0;
+}
+
+/*!
+ Returns the window system handle of the paint tqdevice, for
+ low-level access. Using this function is not portable.
+
+ The HANDLE type varies with platform; see \c tqpaintdevice.h and
+ \c tqwindowdefs.h for details.
+
+ \sa x11Display()
+*/
+TQt::HANDLE TQPaintDevice::handle() const
+{
+// return hd;
+
+ // [FIXME]
+ printf("[WARNING] TQPaintDevice::handle() const unimplemented\n\r");
+ return 0;
+}
+
+/*!
+ Returns the window system handle of the paint tqdevice for XRender
+ support. Use of this function is not portable. This function will
+ return 0 if XRender support is not compiled into TQt, if the
+ XRender extension is not supported on the X11 display, or if the
+ handle could not be created.
+*/
+TQt::HANDLE TQPaintDevice::x11RenderHandle() const
+{
+// #ifndef TQT_NO_XFTFREETYPE
+// return rendhd ? XftDrawPicture( (XftDraw *) rendhd ) : 0;
+// #else
+// return 0;
+// #endif // TQT_NO_XFTFREETYPE
+
+ // [FIXME]
+ printf("[WARNING] TQPaintDevice::x11RenderHandle() const unimplemented\n\r");
+ return 0;
+}
+
+/*!
+ \relates QPaintDevice
+
+ Returns the QX11Info structure for the \a pd paint device. 0 is
+ returned if it can't be obtained.
+*/
+const Q_GUI_EXPORT QX11Info *qt_x11Info(const QPaintDevice *pd)
+{
+ if (!pd) return 0;
+ if (pd->devType() == QInternal::Widget)
+ return &static_cast<const QWidget *>(pd)->x11Info();
+ else if (pd->devType() == QInternal::Pixmap)
+ return &static_cast<const QPixmap *>(pd)->x11Info();
+ return 0;
+}
+
+Display *TQPaintDevice::x11Display() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->display();
+ return QX11Info::display();
+}
+
+int TQPaintDevice::x11Screen() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->screen();
+ return QX11Info::appScreen();
+}
+
+void *TQPaintDevice::x11Visual() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->visual();
+ return QX11Info::appVisual();
+}
+
+int TQPaintDevice::x11Depth() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->depth();
+ return QX11Info::appDepth();
+}
+
+int TQPaintDevice::x11Cells() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->cells();
+ return QX11Info::appCells();
+}
+
+Qt::HANDLE TQPaintDevice::x11Colormap() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->colormap();
+ return QX11Info::appColormap();
+}
+
+bool TQPaintDevice::x11DefaultColormap() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->defaultColormap();
+ return QX11Info::appDefaultColormap();
+}
+
+bool TQPaintDevice::x11DefaultVisual() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->defaultVisual();
+ return QX11Info::appDefaultVisual();
+}
+
+void TQPaintDevice::x11SetAppDpiX(int dpi, int screen)
+{
+ QX11Info::setAppDpiX(dpi, screen);
+}
+
+void TQPaintDevice::x11SetAppDpiY(int dpi, int screen)
+{
+ QX11Info::setAppDpiY(dpi, screen);
+}
+
+int TQPaintDevice::x11AppDpiX(int screen)
+{
+ return QX11Info::appDpiX(screen);
+}
+
+int TQPaintDevice::x11AppDpiY(int screen)
+{
+ return QX11Info::appDpiY(screen);
+}
+
+/*!
+ \relates TQPaintDevice
+
+ Copies a block of pixels from \a src to \a dst, perhaps merging
+ each pixel according to the \link TQt::RasterOp raster operation \endlink
+ \a rop. \a sx, \a sy
+ is the top-left pixel in \a src (0, 0) by default, \a dx, \a dy is
+ the top-left position in \a dst and \a sw, \a sh is the size of
+ the copied block (all of \a src by default).
+
+ The most common values for \a rop are CopyROP and XorROP; the \l
+ TQt::RasterOp documentation defines all the possible values.
+
+ If \a ignoreMask is FALSE (the default) and \a src is a
+ masked TQPixmap, the entire blit is masked by \a{src}->tqmask().
+
+ If \a src, \a dst, \a sw or \a sh is 0, bitBlt() does nothing. If
+ \a sw or \a sh is negative bitBlt() copies starting at \a sx (and
+ respectively, \a sy) and ending at the right end (respectively,
+ bottom) of \a src.
+
+ \a src must be a TQWidget or TQPixmap. You cannot blit from a
+ TQPrinter, for example. bitBlt() does nothing if you attempt to
+ blit from an unsupported tqdevice.
+
+ bitBlt() does nothing if \a src has a greater depth than \e dst.
+ If you need to for example, draw a 24-bit pixmap on an 8-bit
+ widget, you must use drawPixmap().
+*/
+
+void bitBlt( TQPaintDevice *dst, int dx, int dy,
+ const TQPaintDevice *src, int sx, int sy, int sw, int sh,
+ TQt::RasterOp rop, bool ignoreMask )
+{
+// [FIXME] Implement this for Qt4!
+printf("[WARNING] bitBlt( TQPaintDevice *dst, int dx, int dy, const TQPaintDevice *src, int sx, int sy, int sw, int sh, TQt::RasterOp rop, bool ignoreMask ) unimplemented\n\r");
+
+// if ( !src || !dst ) {
+// #if defined(TQT_CHECK_NULL)
+// TQ_ASSERT( src != 0 );
+// TQ_ASSERT( dst != 0 );
+// #endif
+// return;
+// }
+// if ( !src->handle() || src->isExtDev() )
+// return;
+//
+// TQPaintDevice *pdev = TQPainter::redirect( dst );
+// if ( pdev )
+// dst = pdev;
+//
+// int ts = src->devType(); // from tqdevice type
+// int td = dst->devType(); // to tqdevice type
+// Display *dpy = src->x11Display();
+//
+// if ( sw <= 0 ) { // special width
+// if ( sw < 0 )
+// sw = src->metric( TQPaintDeviceMetrics::PdmWidth ) - sx;
+// else
+// return;
+// }
+// if ( sh <= 0 ) { // special height
+// if ( sh < 0 )
+// sh = src->metric( TQPaintDeviceMetrics::PdmHeight ) - sy;
+// else
+// return;
+// }
+//
+// if ( dst->paintingActive() && dst->isExtDev() ) {
+// TQPixmap *pm; // output to picture/printer
+// bool tmp_pm = TRUE;
+// if ( ts == TQInternal::Pixmap ) {
+// pm = (TQPixmap*)src;
+// if ( sx != 0 || sy != 0 ||
+// sw != pm->width() || sh != pm->height() || ignoreMask ) {
+// TQPixmap *tmp = new TQPixmap( sw, sh, pm->depth() );
+// bitBlt( tmp, 0, 0, pm, sx, sy, sw, sh, TQt::CopyROP, TRUE );
+// if ( pm->tqmask() && !ignoreMask ) {
+// TQBitmap tqmask( sw, sh );
+// bitBlt( &tqmask, 0, 0, pm->tqmask(), sx, sy, sw, sh,
+// TQt::CopyROP, TRUE );
+// tmp->setMask( tqmask );
+// }
+// pm = tmp;
+// } else {
+// tmp_pm = FALSE;
+// }
+// } else if ( ts == TQInternal::Widget ) {// bitBlt to temp pixmap
+// pm = new TQPixmap( sw, sh );
+// TQ_CHECK_PTR( pm );
+// bitBlt( pm, 0, 0, src, sx, sy, sw, sh );
+// } else {
+// #if defined(TQT_CHECK_RANGE)
+// qWarning( "bitBlt: Cannot bitBlt from tqdevice" );
+// #endif
+// return;
+// }
+// TQPDevCmdParam param[3];
+// TQRect r(dx, dy, pm->width(), pm->height());
+// param[0].rect = &r;
+// param[1].pixmap = pm;
+// dst->cmd( TQPaintDevice::PdcDrawPixmap, 0, param );
+// if ( tmp_pm )
+// delete pm;
+// return;
+// }
+//
+// switch ( ts ) {
+// case TQInternal::Widget:
+// case TQInternal::Pixmap:
+// case TQInternal::System: // OK, can blt from these
+// break;
+// default:
+// #if defined(TQT_CHECK_RANGE)
+// qWarning( "bitBlt: Cannot bitBlt from tqdevice type %x", ts );
+// #endif
+// return;
+// }
+// switch ( td ) {
+// case TQInternal::Widget:
+// case TQInternal::Pixmap:
+// case TQInternal::System: // OK, can blt to these
+// break;
+// default:
+// #if defined(TQT_CHECK_RANGE)
+// qWarning( "bitBlt: Cannot bitBlt to tqdevice type %x", td );
+// #endif
+// return;
+// }
+//
+// static const short ropCodes[] = { // ROP translation table
+// GXcopy, GXor, GXxor, GXandInverted,
+// GXcopyInverted, GXorInverted, GXequiv, GXand,
+// GXinvert, GXclear, GXset, GXnoop,
+// GXandReverse, GXorReverse, GXnand, GXnor
+// };
+// if ( rop > TQt::LastROP ) {
+// #if defined(TQT_CHECK_RANGE)
+// qWarning( "bitBlt: Invalid ROP code" );
+// #endif
+// return;
+// }
+//
+// if ( dst->handle() == 0 ) {
+// #if defined(TQT_CHECK_NULL)
+// qWarning( "bitBlt: Cannot bitBlt to tqdevice" );
+// #endif
+// return;
+// }
+//
+// bool mono_src;
+// bool mono_dst;
+// bool include_inferiors = FALSE;
+// bool graphics_exposure = FALSE;
+// TQPixmap *src_pm;
+// TQBitmap *tqmask;
+//
+// if ( ts == TQInternal::Pixmap ) {
+// src_pm = (TQPixmap*)src;
+// if ( src_pm->x11Screen() != dst->x11Screen() )
+// src_pm->x11SetScreen( dst->x11Screen() );
+// mono_src = src_pm->depth() == 1;
+// tqmask = ignoreMask ? 0 : src_pm->data->tqmask;
+// } else {
+// src_pm = 0;
+// mono_src = FALSE;
+// tqmask = 0;
+// include_inferiors = ((TQWidget*)src)->testWFlags(TQt::WPaintUnclipped);
+// graphics_exposure = td == TQInternal::Widget;
+// }
+// if ( td == TQInternal::Pixmap ) {
+// if ( dst->x11Screen() != src->x11Screen() )
+// ((TQPixmap*)dst)->x11SetScreen( src->x11Screen() );
+// mono_dst = ((TQPixmap*)dst)->depth() == 1;
+// ((TQPixmap*)dst)->detach(); // changes shared pixmap
+// } else {
+// mono_dst = FALSE;
+// include_inferiors = include_inferiors ||
+// ((TQWidget*)dst)->testWFlags(TQt::WPaintUnclipped);
+// }
+//
+// if ( mono_dst && !mono_src ) { // dest is 1-bit pixmap, source is not
+// #if defined(TQT_CHECK_RANGE)
+// qWarning( "bitBlt: Incompatible destination pixmap" );
+// #endif
+// return;
+// }
+//
+// #ifndef TQT_NO_XRENDER
+// if (src_pm && !mono_src && src_pm->data->alphapm && !ignoreMask ) {
+// // use RENDER to do the blit
+// TQPixmap *alpha = src_pm->data->alphapm;
+// if (src->x11RenderHandle() &&
+// alpha->x11RenderHandle() &&
+// dst->x11RenderHandle()) {
+// XRenderPictureAttributes pattr;
+// ulong pictqmask = 0;
+// if (include_inferiors) {
+// pattr.subwindow_mode = IncludeInferiors;
+// pictqmask |= CPSubwindowMode;
+// }
+// if (graphics_exposure) {
+// pattr.graphics_exposures = TRUE;
+// pictqmask |= CPGraphicsExposure;
+// }
+// if (pictqmask)
+// XRenderChangePicture(dpy, dst->x11RenderHandle(), pictqmask, &pattr);
+// XRenderComposite(dpy, PictOpOver, src->x11RenderHandle(),
+// alpha->x11RenderHandle(), dst->x11RenderHandle(),
+// sx, sy, sx, sy, dx, dy, sw, sh);
+// // restore attributes
+// pattr.subwindow_mode = ClipByChildren;
+// pattr.graphics_exposures = FALSE;
+// if (pictqmask)
+// XRenderChangePicture(dpy, dst->x11RenderHandle(), pictqmask, &pattr);
+// return;
+// }
+// }
+// #endif
+//
+// GC gc;
+//
+// if ( tqmask && !mono_src ) { // fast masked blt
+// bool temp_gc = FALSE;
+// if ( tqmask->data->maskgc ) {
+// gc = (GC)tqmask->data->maskgc; // we have a premade tqmask GC
+// } else {
+// if ( FALSE && src_pm->optimization() == TQPixmap::NormalOptim ) { // #### cache disabled
+// // Compete for the global cache
+// gc = cache_mask_gc( dpy, dst->handle(),
+// tqmask->data->ser_no,
+// tqmask->handle() );
+// } else {
+// // Create a new tqmask GC. If BestOptim, we store the tqmask GC
+// // with the tqmask (not at the pixmap). This way, many pixmaps
+// // which have a common tqmask will be optimized at no extra cost.
+// gc = XCreateGC( dpy, dst->handle(), 0, 0 );
+// XSetGraphicsExposures( dpy, gc, False );
+// XSetClipMask( dpy, gc, tqmask->handle() );
+// if ( src_pm->optimization() == TQPixmap::BestOptim ) {
+// tqmask->data->maskgc = gc;
+// } else {
+// temp_gc = TRUE;
+// }
+// }
+// }
+// XSetClipOrigin( dpy, gc, dx-sx, dy-sy );
+// if ( rop != TQt::CopyROP ) // use non-default ROP code
+// XSetFunction( dpy, gc, ropCodes[rop] );
+// if ( include_inferiors ) {
+// XSetSubwindowMode( dpy, gc, IncludeInferiors );
+// XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+// dx, dy );
+// XSetSubwindowMode( dpy, gc, ClipByChildren );
+// } else {
+// XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+// dx, dy );
+// }
+//
+// if ( temp_gc ) // delete temporary GC
+// XFreeGC( dpy, gc );
+// else if ( rop != TQt::CopyROP ) // restore ROP
+// XSetFunction( dpy, gc, GXcopy );
+// return;
+// }
+//
+// gc = qt_xget_temp_gc( dst->x11Screen(), mono_dst ); // get a reusable GC
+//
+// if ( rop != TQt::CopyROP ) // use non-default ROP code
+// XSetFunction( dpy, gc, ropCodes[rop] );
+//
+// if ( mono_src && mono_dst && src == dst ) { // dst and src are the same bitmap
+// XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, dx, dy );
+// } else if ( mono_src ) { // src is bitmap
+// XGCValues gcvals;
+// ulong valtqmask = GCBackground | GCForeground | GCFillStyle |
+// GCStipple | GCTileStipXOrigin | GCTileStipYOrigin;
+// if ( td == TQInternal::Widget ) { // set GC colors
+// TQWidget *w = (TQWidget *)dst;
+// gcvals.background = w->backgroundColor().pixel( dst->x11Screen() );
+// gcvals.foreground = w->foregroundColor().pixel( dst->x11Screen() );
+// if ( include_inferiors ) {
+// valtqmask |= GCSubwindowMode;
+// gcvals.subwindow_mode = IncludeInferiors;
+// }
+// } else if ( mono_dst ) {
+// gcvals.background = 0;
+// gcvals.foreground = 1;
+// } else {
+// gcvals.background = TQt::white.pixel( dst->x11Screen() );
+// gcvals.foreground = TQt::black.pixel( dst->x11Screen() );
+// }
+//
+// gcvals.fill_style = FillOpaqueStippled;
+// gcvals.stipple = src->handle();
+// gcvals.ts_x_origin = dx - sx;
+// gcvals.ts_y_origin = dy - sy;
+//
+// bool cliptqmask = FALSE;
+// if ( tqmask ) {
+// if ( ((TQPixmap*)src)->data->selfmask ) {
+// gcvals.fill_style = FillStippled;
+// } else {
+// XSetClipMask( dpy, gc, tqmask->handle() );
+// XSetClipOrigin( dpy, gc, dx-sx, dy-sy );
+// cliptqmask = TRUE;
+// }
+// }
+//
+// XChangeGC( dpy, gc, valtqmask, &gcvals );
+// XFillRectangle( dpy,dst->handle(), gc, dx, dy, sw, sh );
+//
+// valtqmask = GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
+// gcvals.fill_style = FillSolid;
+// gcvals.ts_x_origin = 0;
+// gcvals.ts_y_origin = 0;
+// if ( include_inferiors ) {
+// valtqmask |= GCSubwindowMode;
+// gcvals.subwindow_mode = ClipByChildren;
+// }
+// XChangeGC( dpy, gc, valtqmask, &gcvals );
+//
+// if ( cliptqmask ) {
+// XSetClipOrigin( dpy, gc, 0, 0 );
+// XSetClipMask( dpy, gc, None );
+// }
+//
+// } else { // src is pixmap/widget
+//
+// if ( graphics_exposure ) // widget to widget
+// XSetGraphicsExposures( dpy, gc, True );
+// if ( include_inferiors ) {
+// XSetSubwindowMode( dpy, gc, IncludeInferiors );
+// XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+// dx, dy );
+// XSetSubwindowMode( dpy, gc, ClipByChildren );
+// } else {
+// XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+// dx, dy );
+// }
+// if ( graphics_exposure ) // reset graphics exposure
+// XSetGraphicsExposures( dpy, gc, False );
+// }
+//
+// if ( rop != TQt::CopyROP ) // restore ROP
+// XSetFunction( dpy, gc, GXcopy );
+}
+
+/*!
+ Internal virtual function that interprets drawing commands from
+ the painter.
+
+ Implemented by subclasses that have no direct support for drawing
+ graphics (external paint tqdevices, for example, TQPicture).
+*/
+
+bool TQPaintDevice::cmd( int, TQPainter *, TQPDevCmdParam * )
+{
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPaintDevice::cmd: Device has no command interface" );
+#endif
+ return FALSE;
+}
+
+// Reimplemented QPaintEngine methods
+// These need to call their equivalent Qt3 cmd methods
+bool TQPaintDeviceEngineTranslator::begin(QPaintDevice* qpd) {
+ printf("[WARNING] TQPaintDeviceEngineTranslator::begin() unimplemented\n\r");
+}
+
+bool TQPaintDeviceEngineTranslator::end() {
+ printf("[WARNING] TQPaintDeviceEngineTranslator::end() unimplemented\n\r");
+}
+
+void TQPaintDeviceEngineTranslator::updateState(const QPaintEngineState& qpes) {
+ printf("[WARNING] TQPaintDeviceEngineTranslator::updateState() unimplemented\n\r");
+}
+
+void TQPaintDeviceEngineTranslator::drawPixmap(const QRectF& rect1, const QPixmap& pixmap, const QRectF& rect2) {
+ printf("[WARNING] TQPaintDeviceEngineTranslator::drawPixmap() unimplemented\n\r");
+}
+
+QPaintEngine::Type TQPaintDeviceEngineTranslator::type() const {
+ printf("[WARNING] TQPaintDeviceEngineTranslator::type() unimplemented\n\r");
+ return QPaintEngine::X11;
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQPaintDevice tqpaintdevice.h
+ \brief The TQPaintDevice class is the base class of objects that
+ can be painted.
+
+ \ingroup graphics
+ \ingroup images
+
+ A paint tqdevice is an abstraction of a two-dimensional space that
+ can be drawn using a TQPainter. The drawing capabilities are
+ implemented by the subclasses TQWidget, TQPixmap, TQPicture and
+ TQPrinter.
+
+ The default coordinate system of a paint tqdevice has its origin
+ located at the top-left position. X increases to the right and Y
+ increases downward. The unit is one pixel. There are several ways
+ to set up a user-defined coordinate system using the painter, for
+ example, using TQPainter::setWorldMatrix().
+
+ Example (draw on a paint tqdevice):
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p; // our painter
+ p.begin( this ); // start painting the widget
+ p.setPen( red ); // red outline
+ p.setBrush( yellow ); // yellow fill
+ p.drawEllipse( 10, 20, 100,100 ); // 100x100 ellipse at position (10, 20)
+ p.end(); // painting done
+ }
+ \endcode
+
+ The bit block transfer is an extremely useful operation for
+ copying pixels from one paint tqdevice to another (or to itself). It
+ is implemented as the global function bitBlt().
+
+ Example (scroll widget contents 10 pixels to the right):
+ \code
+ bitBlt( myWidget, 10, 0, myWidget );
+ \endcode
+
+ \warning TQt requires that a TQApplication object exists before
+ any paint tqdevices can be created. Paint tqdevices access window
+ system resources, and these resources are not initialized before
+ an application object is created.
+*/
+
+
+//
+// Some global variables - these are initialized by TQColor::initialize()
+//
+
+Display *TQPaintDevice::x_appdisplay = 0;
+int TQPaintDevice::x_appscreen;
+
+int TQPaintDevice::x_appdepth;
+int TQPaintDevice::x_appcells;
+TQt::HANDLE TQPaintDevice::x_approotwindow;
+TQt::HANDLE TQPaintDevice::x_appcolormap;
+bool TQPaintDevice::x_appdefcolormap;
+void *TQPaintDevice::x_appvisual;
+bool TQPaintDevice::x_appdefvisual;
+
+// ### in 4.0, remove the above, and use the below
+int *TQPaintDevice::x_appdepth_arr;
+int *TQPaintDevice::x_appcells_arr;
+TQt::HANDLE *TQPaintDevice::x_approotwindow_arr;
+TQt::HANDLE *TQPaintDevice::x_appcolormap_arr;
+bool *TQPaintDevice::x_appdefcolormap_arr;
+void **TQPaintDevice::x_appvisual_arr;
+bool *TQPaintDevice::x_appdefvisual_arr;
+
+/*!
+ \enum TQPaintDevice::PDevCmd
+ \internal
+*/
+
+/*!
+ Constructs a paint tqdevice with internal flags \a devflags. This
+ constructor can be invoked only from TQPaintDevice subclasses.
+*/
+
+TQPaintDevice::TQPaintDevice( uint devflags )
+{
+ if ( !tqApp ) { // global constructor
+#if defined(TQT_CHECK_STATE)
+ qFatal( "TQPaintDevice: Must construct a TQApplication before a "
+ "TQPaintDevice" );
+#endif
+ return;
+ }
+ devFlags = devflags;
+ painters = 0;
+ hd = 0;
+ rendhd = 0;
+ x11Data = 0;
+}
+
+/*!
+ Destroys the paint tqdevice and frees window system resources.
+*/
+
+TQPaintDevice::~TQPaintDevice()
+{
+#if defined(TQT_CHECK_STATE)
+ if ( paintingActive() )
+ qWarning( "TQPaintDevice: Cannot destroy paint tqdevice that is being "
+ "painted" );
+#endif
+ if ( x11Data && x11Data->deref() ) {
+ delete x11Data;
+ x11Data = 0;
+ }
+}
+
+
+/*
+ \internal
+ Makes a shallow copy of the X11-specific data of \a fromDevice, if it is not
+ null. Otherwise this function sets it to null.
+*/
+
+void TQPaintDevice::copyX11Data( const TQPaintDevice *fromDevice )
+{
+ setX11Data( fromDevice ? fromDevice->x11Data : 0 );
+}
+
+/*
+ \internal
+ Makes a deep copy of the X11-specific data of \a fromDevice, if it is not
+ null. Otherwise this function sets it to null.
+*/
+
+void TQPaintDevice::cloneX11Data( const TQPaintDevice *fromDevice )
+{
+ if ( fromDevice && fromDevice->x11Data ) {
+ TQPaintDeviceX11Data *d = new TQPaintDeviceX11Data;
+ *d = *fromDevice->x11Data;
+ d->count = 0;
+ setX11Data( d );
+ } else {
+ setX11Data( 0 );
+ }
+}
+
+/*
+ \internal
+ Makes a shallow copy of the X11-specific data \a d and assigns it to this
+ class. This function increments the reference code of \a d.
+*/
+
+void TQPaintDevice::setX11Data( const TQPaintDeviceX11Data* d )
+{
+ if ( x11Data && x11Data->deref() )
+ delete x11Data;
+ x11Data = (TQPaintDeviceX11Data*)d;
+ if ( x11Data )
+ x11Data->ref();
+}
+
+
+/*
+ \internal
+ If \a def is FALSE, returns a deep copy of the x11Data, or 0 if x11Data is 0.
+ If \a def is TRUE, makes a TQPaintDeviceX11Data struct filled with the default
+ values.
+
+ In either case the caller is responsible for deleting the returned
+ struct. But notice that the struct is a shared class, so other
+ classes might also have a reference to it. The reference count of
+ the returned TQPaintDeviceX11Data* is 0.
+*/
+
+TQPaintDeviceX11Data* TQPaintDevice::getX11Data( bool def ) const
+{
+ TQPaintDeviceX11Data* res = 0;
+ if ( def ) {
+ res = new TQPaintDeviceX11Data;
+ res->x_display = x11AppDisplay();
+ res->x_screen = x11AppScreen();
+ res->x_depth = x11AppDepth();
+ res->x_cells = x11AppCells();
+ res->x_colormap = x11Colormap();
+ res->x_defcolormap = x11AppDefaultColormap();
+ res->x_visual = x11AppVisual();
+ res->x_defvisual = x11AppDefaultVisual();
+ res->deref();
+ } else if ( x11Data ) {
+ res = new TQPaintDeviceX11Data;
+ *res = *x11Data;
+ res->count = 0;
+ }
+ return res;
+}
+
+
+/*!
+ \fn int TQPaintDevice::devType() const
+
+ \internal
+
+ Returns the tqdevice type identifier, which is \c TQInternal::Widget
+ if the tqdevice is a TQWidget, \c TQInternal::Pixmap if it's a
+ TQPixmap, \c TQInternal::Printer if it's a TQPrinter, \c
+ TQInternal::Picture if it's a TQPicture or \c
+ TQInternal::UndefinedDevice in other cases (which should never
+ happen).
+*/
+
+/*!
+ \fn bool TQPaintDevice::isExtDev() const
+
+ Returns TRUE if the tqdevice is an external paint tqdevice; otherwise
+ returns FALSE.
+
+ External paint tqdevices cannot be bitBlt()'ed from. TQPicture and
+ TQPrinter are external paint tqdevices.
+*/
+
+/*!
+ Returns the window system handle of the paint tqdevice, for
+ low-level access. Using this function is not portable.
+
+ The HANDLE type varies with platform; see \c tqpaintdevice.h and
+ \c tqwindowdefs.h for details.
+
+ \sa x11Display()
+*/
+TQt::HANDLE TQPaintDevice::handle() const
+{
+ return hd;
+}
+
+/*!
+ Returns the window system handle of the paint tqdevice for XRender
+ support. Use of this function is not portable. This function will
+ return 0 if XRender support is not compiled into TQt, if the
+ XRender extension is not supported on the X11 display, or if the
+ handle could not be created.
+*/
+TQt::HANDLE TQPaintDevice::x11RenderHandle() const
+{
+#ifndef TQT_NO_XFTFREETYPE
+ return rendhd ? XftDrawPicture( (XftDraw *) rendhd ) : 0;
+#else
+ return 0;
+#endif // TQT_NO_XFTFREETYPE
+}
+
+
+/*!
+ \fn Display *TQPaintDevice::x11AppDisplay()
+
+ Returns a pointer to the X display global to the application (X11
+ only). Using this function is not portable.
+
+ \sa handle()
+*/
+
+/*!
+ \fn int TQPaintDevice::x11AppScreen()
+
+ Returns the screen number on the X display global to the
+ application (X11 only). Using this function is not portable.
+*/
+
+/*!
+ \overload
+ \fn int TQPaintDevice::x11AppDepth()
+
+ Returns the depth for the default screen of the X display global
+ to the application (X11 only). Using this function is not
+ portable.
+
+ \sa TQPixmap::defaultDepth()
+*/
+
+/*!
+ \fn int TQPaintDevice::x11AppCells()
+
+ Returns the number of entries in the colormap for the default
+ screen of the X display global to the application (X11
+ only). Using this function is not portable.
+
+ \sa x11Colormap()
+*/
+
+/*!
+ \fn HANDLE TQPaintDevice::x11AppRootWindow()
+
+ Returns the root window for the default screen of the X display
+ global to the applicatoin (X11 only). Using this function is not
+ portable.
+*/
+
+/*!
+ \fn HANDLE TQPaintDevice::x11AppColormap()
+
+ Returns the colormap for the default screen of the X display
+ global to the application (X11 only). Using this function is not
+ portable.
+
+ \sa x11Cells()
+*/
+
+/*!
+ \fn bool TQPaintDevice::x11AppDefaultColormap ()
+
+ Returns the default colormap for the default screen of the X
+ display global to the application (X11 only). Using this function
+ is not portable.
+
+ \sa x11Cells()
+*/
+
+/*!
+ \fn void* TQPaintDevice::x11AppVisual ()
+
+ Returns the Visual for the default screen of the X display global
+ to the application (X11 only). Using this function is not
+ portable.
+*/
+
+/*!
+ \fn bool TQPaintDevice::x11AppDefaultVisual ()
+
+ Returns TRUE if the Visual used is the default for the default
+ screen of the X display global to the application (X11 only);
+ otherwise returns FALSE. Using this function is not portable.
+*/
+
+/*!
+ \fn int TQPaintDevice::x11AppDepth( int screen )
+
+ Returns the depth for screen \a screen of the X display global to
+ the application (X11 only). Using this function is not portable.
+
+ \sa TQPixmap::defaultDepth()
+*/
+
+/*!
+ \overload
+ \fn int TQPaintDevice::x11AppCells( int screen )
+
+ Returns the number of entries in the colormap for screen \a screen
+ of the X display global to the application (X11 only). Using this
+ function is not portable.
+
+ \sa x11Colormap()
+*/
+
+/*!
+ \overload
+ \fn HANDLE TQPaintDevice::x11AppRootWindow( int screen )
+
+ Returns the root window for screen \a screen of the X display
+ global to the applicatoin (X11 only). Using this function is not
+ portable.
+*/
+
+/*!
+ \overload
+ \fn HANDLE TQPaintDevice::x11AppColormap( int screen )
+
+ Returns the colormap for screen \a screen of the X display global
+ to the application (X11 only). Using this function is not
+ portable.
+
+ \sa x11Cells()
+*/
+
+/*!
+ \overload
+ \fn bool TQPaintDevice::x11AppDefaultColormap( int screen )
+
+ Returns the default colormap for screen \a screen of the X display
+ global to the application (X11 only). Using this function is not
+ portable.
+
+ \sa x11Cells()
+*/
+
+/*!
+ \overload
+ \fn void* TQPaintDevice::x11AppVisual( int screen )
+
+ Returns the Visual for screen \a screen of the X display global to
+ the application (X11 only). Using this function is not portable.
+*/
+
+/*!
+ \overload
+ \fn bool TQPaintDevice::x11AppDefaultVisual( int screen )
+
+ Returns TRUE if the Visual used is the default for screen
+ \a screen of the X display global to the application (X11 only);
+ otherwise returns FALSE. Using this function is not portable.
+*/
+
+
+/*!
+ \fn Display *TQPaintDevice::x11Display() const
+
+ Returns a pointer to the X display for the paint tqdevice (X11
+ only). Using this function is not portable.
+
+ \sa handle()
+*/
+
+/*!
+ \fn int TQPaintDevice::x11Screen () const
+
+ Returns the screen number on the X display for the paint tqdevice
+ (X11 only). Using this function is not portable.
+*/
+
+/*!
+ \fn int TQPaintDevice::x11Depth () const
+
+ Returns the depth of the X display for the paint tqdevice (X11
+ only). Using this function is not portable.
+
+ \sa TQPixmap::defaultDepth()
+*/
+
+/*!
+ \fn int TQPaintDevice::x11Cells () const
+
+ Returns the number of entries in the colormap of the X display for
+ the paint tqdevice (X11 only). Using this function is not portable.
+
+ \sa x11Colormap()
+*/
+
+/*!
+ \fn HANDLE TQPaintDevice::x11Colormap () const
+
+ Returns the colormap of the X display for the paint tqdevice (X11
+ only). Using this function is not portable.
+
+ \sa x11Cells()
+*/
+
+/*!
+ \fn bool TQPaintDevice::x11DefaultColormap () const
+
+ Returns the default colormap of the X display for the paint tqdevice
+ (X11 only). Using this function is not portable.
+
+ \sa x11Cells()
+*/
+
+/*!
+ \fn void* TQPaintDevice::x11Visual () const
+
+ Returns the Visual of the X display for the paint tqdevice (X11
+ only). Using this function is not portable.
+*/
+
+/*!
+ \fn bool TQPaintDevice::x11DefaultVisual () const
+
+ Returns the default Visual of the X display for the paint tqdevice
+ (X11 only). Using this function is not portable.
+*/
+
+static int *dpisX=0, *dpisY=0;
+static void create_dpis()
+{
+ if ( dpisX )
+ return;
+
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ if ( ! dpy )
+ return;
+
+ int i, screens = ScreenCount( dpy );
+ dpisX = new int[ screens ];
+ dpisY = new int[ screens ];
+ TQ_CHECK_PTR( dpisX );
+ TQ_CHECK_PTR( dpisY );
+ for ( i = 0; i < screens; i++ ) {
+ dpisX[ i ] = (DisplayWidth(dpy,i) * 254 + DisplayWidthMM(dpy,i)*5)
+
+ / (DisplayWidthMM(dpy,i)*10);
+ dpisY[ i ] = (DisplayHeight(dpy,i) * 254 + DisplayHeightMM(dpy,i)*5)
+ / (DisplayHeightMM(dpy,i)*10);
+ }
+}
+
+/*!
+ Sets the value returned by x11AppDpiX() to \a dpi for screen
+ \a screen. The default is determined by the display configuration.
+ Changing this value will alter the scaling of fonts and many other
+ metrics and is not recommended. Using this function is not
+ portable.
+
+ \sa x11SetAppDpiY()
+*/
+void TQPaintDevice::x11SetAppDpiX(int dpi, int screen)
+{
+ create_dpis();
+ if ( ! dpisX )
+ return;
+ if ( screen < 0 )
+ screen = TQPaintDevice::x11AppScreen();
+ if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) )
+ return;
+ dpisX[ screen ] = dpi;
+}
+
+/*!
+ \overload
+
+ Sets the value returned by x11AppDpiX() to \a dpi for the default
+ screen. The default is determined by the display configuration.
+ Changing this value will alter the scaling of fonts and many other
+ metrics and is not recommended. Using this function is not
+ portable.
+
+*/
+// ### REMOVE 4.0
+void TQPaintDevice::x11SetAppDpiX( int dpi )
+{
+ TQPaintDevice::x11SetAppDpiX( dpi, -1 );
+}
+
+/*!
+ Sets the value returned by x11AppDpiY() to \a dpi for screen
+ \a screen. The default is determined by the display configuration.
+ Changing this value will alter the scaling of fonts and many other
+ metrics and is not recommended. Using this function is not
+ portable.
+
+ \sa x11SetAppDpiX()
+*/
+void TQPaintDevice::x11SetAppDpiY(int dpi, int screen)
+{
+ create_dpis();
+ if ( ! dpisY )
+ return;
+ if ( screen < 0 )
+ screen = TQPaintDevice::x11AppScreen();
+ if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) )
+ return;
+ dpisY[ screen ] = dpi;
+}
+
+/*!
+ \overload
+
+ Sets the value returned by x11AppDpiY() to \a dpi for the default
+ screen. The default is determined by the display configuration.
+ Changing this value will alter the scaling of fonts and many other
+ metrics and is not recommended. Using this function is not
+ portable.
+*/
+// ### REMOVE 4.0
+void TQPaintDevice::x11SetAppDpiY( int dpi )
+{
+ TQPaintDevice::x11SetAppDpiY( dpi, -1 );
+}
+
+/*!
+ Returns the horizontal DPI of the X display (X11 only) for screen
+ \a screen. Using this function is not portable. See
+ TQPaintDeviceMetrics for portable access to related information.
+ Using this function is not portable.
+
+ \sa x11AppDpiY(), x11SetAppDpiX(), TQPaintDeviceMetrics::logicalDpiX()
+*/
+int TQPaintDevice::x11AppDpiX(int screen)
+{
+ create_dpis();
+ if ( ! dpisX )
+ return 0;
+ if ( screen < 0 )
+ screen = TQPaintDevice::x11AppScreen();
+ if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) )
+ return 0;
+ return dpisX[ screen ];
+}
+
+/*!
+ \overload
+
+ Returns the horizontal DPI of the X display (X11 only) for the
+ default screen. Using this function is not portable. See
+ TQPaintDeviceMetrics for portable access to related information.
+ Using this function is not portable.
+*/
+int TQPaintDevice::x11AppDpiX()
+{
+ return TQPaintDevice::x11AppDpiX( -1 );
+}
+
+/*!
+ Returns the vertical DPI of the X11 display (X11 only) for screen
+ \a screen. Using this function is not portable. See
+ TQPaintDeviceMetrics for portable access to related information.
+ Using this function is not portable.
+
+ \sa x11AppDpiX(), x11SetAppDpiY(), TQPaintDeviceMetrics::logicalDpiY()
+*/
+int TQPaintDevice::x11AppDpiY( int screen )
+{
+ create_dpis();
+ if ( ! dpisY )
+ return 0;
+ if ( screen < 0 )
+ screen = TQPaintDevice::x11AppScreen();
+ if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) )
+ return 0;
+ return dpisY[ screen ];
+}
+
+/*!
+ \overload
+
+ Returns the vertical DPI of the X11 display (X11 only) for the
+ default screen. Using this function is not portable. See
+ TQPaintDeviceMetrics for portable access to related information.
+ Using this function is not portable.
+
+ \sa x11AppDpiX(), x11SetAppDpiY(), TQPaintDeviceMetrics::logicalDpiY()
+*/
+int TQPaintDevice::x11AppDpiY()
+{
+ return TQPaintDevice::x11AppDpiY( -1 );
+}
+
+/*!
+ \fn bool TQPaintDevice::paintingActive() const
+
+ Returns TRUE if the tqdevice is being painted, i.e. someone has
+ called TQPainter::begin() but not yet called TQPainter::end() for
+ this tqdevice; otherwise returns FALSE.
+
+ \sa TQPainter::isActive()
+*/
+
+/*!
+ Internal virtual function that interprets drawing commands from
+ the painter.
+
+ Implemented by subclasses that have no direct support for drawing
+ graphics (external paint tqdevices, for example, TQPicture).
+*/
+
+bool TQPaintDevice::cmd( int, TQPainter *, TQPDevCmdParam * )
+{
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPaintDevice::cmd: Device has no command interface" );
+#endif
+ return FALSE;
+}
+
+/*!
+ \internal
+
+ Internal virtual function that returns paint tqdevice metrics.
+
+ Please use the TQPaintDeviceMetrics class instead.
+*/
+
+int TQPaintDevice::metric( int ) const
+{
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPaintDevice::metrics: Device has no metric information" );
+#endif
+ return 0;
+}
+
+/*!
+ \internal
+
+ Internal virtual function. Reserved for future use.
+
+ Please use the TQFontMetrics class instead.
+*/
+
+int TQPaintDevice::fontMet( TQFont *, int, const char *, int ) const
+{
+ return 0;
+}
+
+/*!
+ \internal
+
+ Internal virtual function. Reserved for future use.
+
+ Please use the TQFontInfo class instead.
+*/
+
+int TQPaintDevice::fontInf( TQFont *, int ) const
+{
+ return 0;
+}
+
+
+//
+// Internal functions for simple GC caching for blt'ing masked pixmaps.
+// This cache is used when the pixmap optimization is set to Normal
+// and the pixmap size doesn't exceed 128x128.
+//
+
+static bool init_mask_gc = FALSE;
+static const int max_mask_gcs = 11; // suitable for hashing
+
+struct mask_gc {
+ GC gc;
+ int mask_no;
+};
+
+static mask_gc gc_vec[max_mask_gcs];
+
+
+static void cleanup_mask_gc()
+{
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ init_mask_gc = FALSE;
+ for ( int i=0; i<max_mask_gcs; i++ ) {
+ if ( gc_vec[i].gc )
+ XFreeGC( dpy, gc_vec[i].gc );
+ }
+}
+
+static GC cache_mask_gc( Display *dpy, Drawable hd, int mask_no, Pixmap tqmask )
+{
+ if ( !init_mask_gc ) { // first time initialization
+ init_mask_gc = TRUE;
+ qAddPostRoutine( cleanup_mask_gc );
+ for ( int i=0; i<max_mask_gcs; i++ )
+ gc_vec[i].gc = 0;
+ }
+ mask_gc *p = &gc_vec[mask_no % max_mask_gcs];
+ if ( !p->gc || p->mask_no != mask_no ) { // not a perfect match
+ if ( !p->gc ) { // no GC
+ p->gc = XCreateGC( dpy, hd, 0, 0 );
+ XSetGraphicsExposures( dpy, p->gc, False );
+ }
+ XSetClipMask( dpy, p->gc, tqmask );
+ p->mask_no = mask_no;
+ }
+ return p->gc;
+}
+
+
+/*!
+ \relates TQPaintDevice
+
+ Copies a block of pixels from \a src to \a dst, perhaps merging
+ each pixel according to the \link TQt::RasterOp raster operation \endlink
+ \a rop. \a sx, \a sy
+ is the top-left pixel in \a src (0, 0) by default, \a dx, \a dy is
+ the top-left position in \a dst and \a sw, \a sh is the size of
+ the copied block (all of \a src by default).
+
+ The most common values for \a rop are CopyROP and XorROP; the \l
+ TQt::RasterOp documentation defines all the possible values.
+
+ If \a ignoreMask is FALSE (the default) and \a src is a
+ masked TQPixmap, the entire blit is masked by \a{src}->tqmask().
+
+ If \a src, \a dst, \a sw or \a sh is 0, bitBlt() does nothing. If
+ \a sw or \a sh is negative bitBlt() copies starting at \a sx (and
+ respectively, \a sy) and ending at the right end (respectively,
+ bottom) of \a src.
+
+ \a src must be a TQWidget or TQPixmap. You cannot blit from a
+ TQPrinter, for example. bitBlt() does nothing if you attempt to
+ blit from an unsupported tqdevice.
+
+ bitBlt() does nothing if \a src has a greater depth than \e dst.
+ If you need to for example, draw a 24-bit pixmap on an 8-bit
+ widget, you must use drawPixmap().
+*/
+
+void bitBlt( TQPaintDevice *dst, int dx, int dy,
+ const TQPaintDevice *src, int sx, int sy, int sw, int sh,
+ TQt::RasterOp rop, bool ignoreMask )
+{
+ if ( !src || !dst ) {
+#if defined(TQT_CHECK_NULL)
+ TQ_ASSERT( src != 0 );
+ TQ_ASSERT( dst != 0 );
+#endif
+ return;
+ }
+ if ( !src->handle() || src->isExtDev() )
+ return;
+
+ TQPaintDevice *pdev = TQPainter::redirect( dst );
+ if ( pdev )
+ dst = pdev;
+
+ int ts = src->devType(); // from tqdevice type
+ int td = dst->devType(); // to tqdevice type
+ Display *dpy = src->x11Display();
+
+ if ( sw <= 0 ) { // special width
+ if ( sw < 0 )
+ sw = src->metric( TQPaintDeviceMetrics::PdmWidth ) - sx;
+ else
+ return;
+ }
+ if ( sh <= 0 ) { // special height
+ if ( sh < 0 )
+ sh = src->metric( TQPaintDeviceMetrics::PdmHeight ) - sy;
+ else
+ return;
+ }
+
+ if ( dst->paintingActive() && dst->isExtDev() ) {
+ TQPixmap *pm; // output to picture/printer
+ bool tmp_pm = TRUE;
+ if ( ts == TQInternal::Pixmap ) {
+ pm = (TQPixmap*)src;
+ if ( sx != 0 || sy != 0 ||
+ sw != pm->width() || sh != pm->height() || ignoreMask ) {
+ TQPixmap *tmp = new TQPixmap( sw, sh, pm->depth() );
+ bitBlt( tmp, 0, 0, pm, sx, sy, sw, sh, TQt::CopyROP, TRUE );
+ if ( pm->tqmask() && !ignoreMask ) {
+ TQBitmap tqmask( sw, sh );
+ bitBlt( &tqmask, 0, 0, pm->tqmask(), sx, sy, sw, sh,
+ TQt::CopyROP, TRUE );
+ tmp->setMask( tqmask );
+ }
+ pm = tmp;
+ } else {
+ tmp_pm = FALSE;
+ }
+ } else if ( ts == TQInternal::Widget ) {// bitBlt to temp pixmap
+ pm = new TQPixmap( sw, sh );
+ TQ_CHECK_PTR( pm );
+ bitBlt( pm, 0, 0, src, sx, sy, sw, sh );
+ } else {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "bitBlt: Cannot bitBlt from tqdevice" );
+#endif
+ return;
+ }
+ TQPDevCmdParam param[3];
+ TQRect r(dx, dy, pm->width(), pm->height());
+ param[0].rect = &r;
+ param[1].pixmap = pm;
+ dst->cmd( TQPaintDevice::PdcDrawPixmap, 0, param );
+ if ( tmp_pm )
+ delete pm;
+ return;
+ }
+
+ switch ( ts ) {
+ case TQInternal::Widget:
+ case TQInternal::Pixmap:
+ case TQInternal::System: // OK, can blt from these
+ break;
+ default:
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "bitBlt: Cannot bitBlt from tqdevice type %x", ts );
+#endif
+ return;
+ }
+ switch ( td ) {
+ case TQInternal::Widget:
+ case TQInternal::Pixmap:
+ case TQInternal::System: // OK, can blt to these
+ break;
+ default:
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "bitBlt: Cannot bitBlt to tqdevice type %x", td );
+#endif
+ return;
+ }
+
+ static const short ropCodes[] = { // ROP translation table
+ GXcopy, GXor, GXxor, GXandInverted,
+ GXcopyInverted, GXorInverted, GXequiv, GXand,
+ GXinvert, GXclear, GXset, GXnoop,
+ GXandReverse, GXorReverse, GXnand, GXnor
+ };
+ if ( rop > TQt::LastROP ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "bitBlt: Invalid ROP code" );
+#endif
+ return;
+ }
+
+ if ( dst->handle() == 0 ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "bitBlt: Cannot bitBlt to tqdevice" );
+#endif
+ return;
+ }
+
+ bool mono_src;
+ bool mono_dst;
+ bool include_inferiors = FALSE;
+ bool graphics_exposure = FALSE;
+ TQPixmap *src_pm;
+ TQBitmap *tqmask;
+
+ if ( ts == TQInternal::Pixmap ) {
+ src_pm = (TQPixmap*)src;
+ if ( src_pm->x11Screen() != dst->x11Screen() )
+ src_pm->x11SetScreen( dst->x11Screen() );
+ mono_src = src_pm->depth() == 1;
+ tqmask = ignoreMask ? 0 : src_pm->data->tqmask;
+ } else {
+ src_pm = 0;
+ mono_src = FALSE;
+ tqmask = 0;
+ include_inferiors = ((TQWidget*)src)->testWFlags(TQt::WPaintUnclipped);
+ graphics_exposure = td == TQInternal::Widget;
+ }
+ if ( td == TQInternal::Pixmap ) {
+ if ( dst->x11Screen() != src->x11Screen() )
+ ((TQPixmap*)dst)->x11SetScreen( src->x11Screen() );
+ mono_dst = ((TQPixmap*)dst)->depth() == 1;
+ ((TQPixmap*)dst)->detach(); // changes shared pixmap
+ } else {
+ mono_dst = FALSE;
+ include_inferiors = include_inferiors ||
+ ((TQWidget*)dst)->testWFlags(TQt::WPaintUnclipped);
+ }
+
+ if ( mono_dst && !mono_src ) { // dest is 1-bit pixmap, source is not
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "bitBlt: Incompatible destination pixmap" );
+#endif
+ return;
+ }
+
+#ifndef TQT_NO_XRENDER
+ if (src_pm && !mono_src && src_pm->data->alphapm && !ignoreMask ) {
+ // use RENDER to do the blit
+ TQPixmap *alpha = src_pm->data->alphapm;
+ if (src->x11RenderHandle() &&
+ alpha->x11RenderHandle() &&
+ dst->x11RenderHandle()) {
+ XRenderPictureAttributes pattr;
+ ulong pictqmask = 0;
+ if (include_inferiors) {
+ pattr.subwindow_mode = IncludeInferiors;
+ pictqmask |= CPSubwindowMode;
+ }
+ if (graphics_exposure) {
+ pattr.graphics_exposures = TRUE;
+ pictqmask |= CPGraphicsExposure;
+ }
+ if (pictqmask)
+ XRenderChangePicture(dpy, dst->x11RenderHandle(), pictqmask, &pattr);
+ XRenderComposite(dpy, PictOpOver, src->x11RenderHandle(),
+ alpha->x11RenderHandle(), dst->x11RenderHandle(),
+ sx, sy, sx, sy, dx, dy, sw, sh);
+ // restore attributes
+ pattr.subwindow_mode = ClipByChildren;
+ pattr.graphics_exposures = FALSE;
+ if (pictqmask)
+ XRenderChangePicture(dpy, dst->x11RenderHandle(), pictqmask, &pattr);
+ return;
+ }
+ }
+#endif
+
+ GC gc;
+
+ if ( tqmask && !mono_src ) { // fast masked blt
+ bool temp_gc = FALSE;
+ if ( tqmask->data->maskgc ) {
+ gc = (GC)tqmask->data->maskgc; // we have a premade tqmask GC
+ } else {
+ if ( FALSE && src_pm->optimization() == TQPixmap::NormalOptim ) { // #### cache disabled
+ // Compete for the global cache
+ gc = cache_mask_gc( dpy, dst->handle(),
+ tqmask->data->ser_no,
+ tqmask->handle() );
+ } else {
+ // Create a new tqmask GC. If BestOptim, we store the tqmask GC
+ // with the tqmask (not at the pixmap). This way, many pixmaps
+ // which have a common tqmask will be optimized at no extra cost.
+ gc = XCreateGC( dpy, dst->handle(), 0, 0 );
+ XSetGraphicsExposures( dpy, gc, False );
+ XSetClipMask( dpy, gc, tqmask->handle() );
+ if ( src_pm->optimization() == TQPixmap::BestOptim ) {
+ tqmask->data->maskgc = gc;
+ } else {
+ temp_gc = TRUE;
+ }
+ }
+ }
+ XSetClipOrigin( dpy, gc, dx-sx, dy-sy );
+ if ( rop != TQt::CopyROP ) // use non-default ROP code
+ XSetFunction( dpy, gc, ropCodes[rop] );
+ if ( include_inferiors ) {
+ XSetSubwindowMode( dpy, gc, IncludeInferiors );
+ XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+ dx, dy );
+ XSetSubwindowMode( dpy, gc, ClipByChildren );
+ } else {
+ XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+ dx, dy );
+ }
+
+ if ( temp_gc ) // delete temporary GC
+ XFreeGC( dpy, gc );
+ else if ( rop != TQt::CopyROP ) // restore ROP
+ XSetFunction( dpy, gc, GXcopy );
+ return;
+ }
+
+ gc = qt_xget_temp_gc( dst->x11Screen(), mono_dst ); // get a reusable GC
+
+ if ( rop != TQt::CopyROP ) // use non-default ROP code
+ XSetFunction( dpy, gc, ropCodes[rop] );
+
+ if ( mono_src && mono_dst && src == dst ) { // dst and src are the same bitmap
+ XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, dx, dy );
+ } else if ( mono_src ) { // src is bitmap
+ XGCValues gcvals;
+ ulong valtqmask = GCBackground | GCForeground | GCFillStyle |
+ GCStipple | GCTileStipXOrigin | GCTileStipYOrigin;
+ if ( td == TQInternal::Widget ) { // set GC colors
+ TQWidget *w = (TQWidget *)dst;
+ gcvals.background = w->backgroundColor().pixel( dst->x11Screen() );
+ gcvals.foreground = w->foregroundColor().pixel( dst->x11Screen() );
+ if ( include_inferiors ) {
+ valtqmask |= GCSubwindowMode;
+ gcvals.subwindow_mode = IncludeInferiors;
+ }
+ } else if ( mono_dst ) {
+ gcvals.background = 0;
+ gcvals.foreground = 1;
+ } else {
+ gcvals.background = TQt::white.pixel( dst->x11Screen() );
+ gcvals.foreground = TQt::black.pixel( dst->x11Screen() );
+ }
+
+ gcvals.fill_style = FillOpaqueStippled;
+ gcvals.stipple = src->handle();
+ gcvals.ts_x_origin = dx - sx;
+ gcvals.ts_y_origin = dy - sy;
+
+ bool cliptqmask = FALSE;
+ if ( tqmask ) {
+ if ( ((TQPixmap*)src)->data->selfmask ) {
+ gcvals.fill_style = FillStippled;
+ } else {
+ XSetClipMask( dpy, gc, tqmask->handle() );
+ XSetClipOrigin( dpy, gc, dx-sx, dy-sy );
+ cliptqmask = TRUE;
+ }
+ }
+
+ XChangeGC( dpy, gc, valtqmask, &gcvals );
+ XFillRectangle( dpy,dst->handle(), gc, dx, dy, sw, sh );
+
+ valtqmask = GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
+ gcvals.fill_style = FillSolid;
+ gcvals.ts_x_origin = 0;
+ gcvals.ts_y_origin = 0;
+ if ( include_inferiors ) {
+ valtqmask |= GCSubwindowMode;
+ gcvals.subwindow_mode = ClipByChildren;
+ }
+ XChangeGC( dpy, gc, valtqmask, &gcvals );
+
+ if ( cliptqmask ) {
+ XSetClipOrigin( dpy, gc, 0, 0 );
+ XSetClipMask( dpy, gc, None );
+ }
+
+ } else { // src is pixmap/widget
+
+ if ( graphics_exposure ) // widget to widget
+ XSetGraphicsExposures( dpy, gc, True );
+ if ( include_inferiors ) {
+ XSetSubwindowMode( dpy, gc, IncludeInferiors );
+ XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+ dx, dy );
+ XSetSubwindowMode( dpy, gc, ClipByChildren );
+ } else {
+ XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh,
+ dx, dy );
+ }
+ if ( graphics_exposure ) // reset graphics exposure
+ XSetGraphicsExposures( dpy, gc, False );
+ }
+
+ if ( rop != TQt::CopyROP ) // restore ROP
+ XSetFunction( dpy, gc, GXcopy );
+}
+
+
+/*!
+ \relates TQPaintDevice
+
+ \overload void bitBlt( TQPaintDevice *dst, const TQPoint &dp, const TQPaintDevice *src, const TQRect &sr, RasterOp rop )
+
+ Overloaded bitBlt() with the destination point \a dp and source
+ rectangle \a sr.
+*/
+
+
+/*!
+ \internal
+*/
+// makes it possible to add a setResolution as we have in TQPrinter for all
+// painttqdevices without breaking bin compatibility.
+void TQPaintDevice::setResolution( int )
+{
+}
+
+/*!\internal
+*/
+int TQPaintDevice::resolution() const
+{
+ return metric( TQPaintDeviceMetrics::PdmDpiY );
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpaintdevicedefs.h b/tqtinterface/qt4/src/kernel/tqpaintdevicedefs.h
new file mode 100644
index 0000000..e36bedc
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpaintdevicedefs.h
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Definition of TQPaintDevice constants and flags
+**
+** Created : 940721
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPAINTDEVICEDEFS_H
+#define TQPAINTDEVICEDEFS_H
+
+#error "this file is gone. the #defines it contained are in"
+#error "tq1xcompatibility.h; the functionality is in TQPaintDevice"
+#error "and TQPaintDeviceMetrics."
+
+#endif // TQPAINTDEVICEDEFS_H
diff --git a/tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.cpp b/tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.cpp
new file mode 100644
index 0000000..6013062
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.cpp
@@ -0,0 +1,304 @@
+#include "tqpaintdevicemetrics.h"
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class TQPaintDeviceMetrics
+ \brief The TQPaintDeviceMetrics class provides information about a
+ paint tqdevice.
+
+ \compat
+
+ Sometimes when drawing graphics it is necessary to obtain
+ information about the physical characteristics of a paint tqdevice.
+ This class provides the information. For example, to compute the
+ aspect ratio of a paint tqdevice:
+
+ \snippet doc/src/snippets/code/src_qt3support_painting_q3painttqdevicemetrics.cpp 0
+
+ TQPaintDeviceMetrics tqcontains methods to provide the width and
+ height of a tqdevice in both pixels (width() and height()) and
+ millimeters (widthMM() and heightMM()), the number of colors the
+ tqdevice supports (numColors()), the number of bit planes (depth()),
+ and the resolution of the tqdevice (logicalDpiX() and
+ logicalDpiY()).
+
+ It is not always possible for TQPaintDeviceMetrics to compute the
+ values you ask for, particularly for external tqdevices. The
+ ultimate example is asking for the resolution of of a QPrinter
+ that is set to "print to file": who knows what printer that file
+ will end up on?
+*/
+
+/*!
+ \fn TQPaintDeviceMetrics::TQPaintDeviceMetrics(const QPaintDevice *pd)
+
+ Constructs a metric for the paint tqdevice \a pd.
+*/
+
+
+/*!
+ \fn int TQPaintDeviceMetrics::width() const
+
+ Returns the width of the paint tqdevice in default coordinate system
+ units (e.g. pixels for QPixmap and QWidget).
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::height() const
+
+ Returns the height of the paint tqdevice in default coordinate
+ system units (e.g. pixels for QPixmap and QWidget).
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::widthMM() const
+
+ Returns the width of the paint tqdevice, measured in millimeters.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::heightMM() const
+
+ Returns the height of the paint tqdevice, measured in millimeters.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::numColors() const
+
+ Returns the number of different colors available for the paint
+ tqdevice. Since this value is an int will not be sufficient to represent
+ the number of colors on 32 bit displays, in which case INT_MAX is
+ returned instead.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::depth() const
+
+ Returns the bit depth (number of bit planes) of the paint tqdevice.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::logicalDpiX() const
+
+ Returns the horizontal resolution of the tqdevice in dots per inch,
+ which is used when computing font sizes. For X, this is usually
+ the same as could be computed from widthMM(), but it varies on
+ Windows.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::logicalDpiY() const
+
+ Returns the vertical resolution of the tqdevice in dots per inch,
+ which is used when computing font sizes. For X, this is usually
+ the same as could be computed from heightMM(), but it varies on
+ Windows.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::physicalDpiX() const
+ \internal
+*/
+/*!
+ \fn int TQPaintDeviceMetrics::physicalDpiY() const
+ \internal
+*/
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of TQPaintDeviceMetrics class
+**
+** Created : 941109
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+/*!
+ \class TQPaintDeviceMetrics tqpaintdevicemetrics.h
+ \brief The TQPaintDeviceMetrics class provides information about a
+ paint tqdevice.
+
+ \ingroup graphics
+ \ingroup images
+
+ Sometimes when drawing graphics it is necessary to obtain
+ information about the physical characteristics of a paint tqdevice.
+ This class provides the information. For example, to compute the
+ aspect ratio of a paint tqdevice:
+
+ \code
+ TQPaintDeviceMetrics pdm( myWidget );
+ double aspect = (double)pdm.widthMM() / (double)pdm.heightMM();
+ \endcode
+
+ TQPaintDeviceMetrics tqcontains methods to provide the width and
+ height of a tqdevice in both pixels (width() and height()) and
+ millimeters (widthMM() and heightMM()), the number of colors the
+ tqdevice supports (numColors()), the number of bit planes (depth()),
+ and the resolution of the tqdevice (logicalDpiX() and
+ logicalDpiY()).
+
+ It is not always possible for TQPaintDeviceMetrics to compute the
+ values you ask for, particularly for external tqdevices. The
+ ultimate example is asking for the resolution of of a TQPrinter
+ that is set to "print to file": who knows what printer that file
+ will end up on?
+*/
+
+/*!
+ Constructs a metric for the paint tqdevice \a pd.
+*/
+TQPaintDeviceMetrics::TQPaintDeviceMetrics( const TQPaintDevice *pd )
+{
+ pdev = (TQPaintDevice *)pd;
+}
+
+
+/*!
+ \fn int TQPaintDeviceMetrics::width() const
+
+ Returns the width of the paint tqdevice in default coordinate system
+ units (e.g. pixels for TQPixmap and TQWidget).
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::height() const
+
+ Returns the height of the paint tqdevice in default coordinate
+ system units (e.g. pixels for TQPixmap and TQWidget).
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::widthMM() const
+
+ Returns the width of the paint tqdevice, measured in millimeters.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::heightMM() const
+
+ Returns the height of the paint tqdevice, measured in millimeters.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::numColors() const
+
+ Returns the number of different colors available for the paint
+ tqdevice. Since this value is an int will not be sufficient to represent
+ the number of colors on 32 bit displays, in which case INT_MAX is
+ returned instead.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::depth() const
+
+ Returns the bit depth (number of bit planes) of the paint tqdevice.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::logicalDpiX() const
+
+ Returns the horizontal resolution of the tqdevice in dots per inch,
+ which is used when computing font sizes. For X, this is usually
+ the same as could be computed from widthMM(), but it varies on
+ Windows.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::logicalDpiY() const
+
+ Returns the vertical resolution of the tqdevice in dots per inch,
+ which is used when computing font sizes. For X, this is usually
+ the same as could be computed from heightMM(), but it varies on
+ Windows.
+*/
+
+/*!
+ \fn int TQPaintDeviceMetrics::physicalDpiX() const
+ \internal
+*/
+/*!
+ \fn int TQPaintDeviceMetrics::physicalDpiY() const
+ \internal
+*/
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.h b/tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.h
new file mode 100644
index 0000000..4db2a39
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpaintdevicemetrics.h
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Definition of TQPaintDeviceMetrics class
+**
+** Created : 941109
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPAINTDEVICEMETRICS_H
+#define TQPAINTDEVICEMETRICS_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpaintdevice.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef Q3PAINTDEVICEMETRICS_H
+#define Q3PAINTDEVICEMETRICS_H
+
+#include <QtGui/qpaintdevice.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Qt3SupportLight)
+
+class Q_COMPAT_EXPORT TQPaintDeviceMetrics // paint tqdevice metrics
+{
+public:
+ TQPaintDeviceMetrics(const QPaintDevice *tqdevice) : pdev(tqdevice) {}
+
+ // [FIXME] Integrate with Qt4 enum
+ enum {
+ PdmWidth = 1,
+ PdmHeight,
+ PdmWidthMM,
+ PdmHeightMM,
+ PdmNumColors,
+ PdmDepth,
+ PdmDpiX,
+ PdmDpiY,
+ PdmPhysicalDpiX,
+ PdmPhysicalDpiY
+ };
+
+ int width() const { return pdev->width(); }
+ int height() const { return pdev->height(); }
+ int widthMM() const { return pdev->widthMM(); }
+ int heightMM() const { return pdev->heightMM(); }
+ int logicalDpiX() const { return pdev->logicalDpiX(); }
+ int logicalDpiY() const { return pdev->logicalDpiY(); }
+ int physicalDpiX() const { return pdev->physicalDpiX(); }
+ int physicalDpiY() const { return pdev->physicalDpiY(); }
+ int numColors() const { return pdev->colorCount(); }
+ int depth() const { return pdev->depth(); }
+
+private:
+ const QPaintDevice *pdev;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // Q3PAINTDEVICEMETRICS_H
+
+#else // USE_QT4
+
+class TQ_EXPORT TQPaintDeviceMetrics // paint tqdevice metrics
+{
+public:
+ TQPaintDeviceMetrics( const TQPaintDevice * );
+
+ enum {
+ PdmWidth = 1,
+ PdmHeight,
+ PdmWidthMM,
+ PdmHeightMM,
+ PdmNumColors,
+ PdmDepth,
+ PdmDpiX,
+ PdmDpiY,
+ PdmPhysicalDpiX,
+ PdmPhysicalDpiY
+ };
+
+ int width() const { return (int)pdev->metric(PdmWidth); }
+ int height() const { return (int)pdev->metric(PdmHeight); }
+ int widthMM() const { return (int)pdev->metric(PdmWidthMM); }
+ int heightMM() const { return (int)pdev->metric(PdmHeightMM); }
+ int logicalDpiX() const { return (int)pdev->metric(PdmDpiX); }
+ int logicalDpiY() const { return (int)pdev->metric(PdmDpiY); }
+ int physicalDpiX()const { return (int)pdev->metric(PdmPhysicalDpiX); }
+ int physicalDpiY()const { return (int)pdev->metric(PdmPhysicalDpiY); }
+ int numColors() const { return (int)pdev->metric(PdmNumColors); }
+ int depth() const { return (int)pdev->metric(PdmDepth); }
+
+private:
+ TQPaintDevice *pdev;
+};
+
+#endif // USE_QT4
+
+#endif // TQPAINTDEVICEMETRICS_H
diff --git a/tqtinterface/qt4/src/kernel/tqpainter.cpp b/tqtinterface/qt4/src/kernel/tqpainter.cpp
new file mode 100644
index 0000000..66596f5
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpainter.cpp
@@ -0,0 +1,5382 @@
+#include "tqpainter.h"
+
+#include "tqpicture.h"
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqpainter.h"
+#include "tqimage.h"
+#include "Qt/qpaintengine.h"
+
+// #include <private/qpainter_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// TAKEN FROM QT4 qbrush.cpp
+// THIS BLOCK MAY NEED TO BE UPDATED FROM TIME TO TIME
+// BEGIN BLOCK
+struct QTexturedBrushData : public QBrushData
+{
+ QTexturedBrushData() {
+ m_has_pixmap_texture = false;
+ m_pixmap = 0;
+ }
+ ~QTexturedBrushData() {
+ delete m_pixmap;
+ }
+
+ void setPixmap(const QPixmap &pm) {
+ delete m_pixmap;
+
+ if (pm.isNull()) {
+ m_pixmap = 0;
+ m_has_pixmap_texture = false;
+ } else {
+ m_pixmap = new QPixmap(pm);
+ m_has_pixmap_texture = true;
+ }
+
+ m_image = QImage();
+ }
+
+ void setImage(const QImage &image) {
+ m_image = image;
+ delete m_pixmap;
+ m_pixmap = 0;
+ m_has_pixmap_texture = false;
+ }
+
+ QPixmap &pixmap() {
+ if (!m_pixmap) {
+ m_pixmap = new QPixmap(QPixmap::fromImage(m_image));
+ }
+ return *m_pixmap;
+ }
+
+ QImage &image() {
+ if (m_image.isNull() && m_pixmap)
+ m_image = m_pixmap->toImage();
+ return m_image;
+ }
+
+ QPixmap *m_pixmap;
+ QImage m_image;
+ bool m_has_pixmap_texture;
+};
+// END BLOCK
+
+/*!
+ \class TQPainter
+ \brief The TQPainter class is a Qt 3 compatibility wrapper for QPainter.
+
+ \compat
+
+ Prior to Qt 4, QPainter specialized the pen drawing for rectangle
+ based functions (in particular: drawRect, drawEllipse,
+ drawRoundRect, drawArc, drawChord and drawPie). When stroking a
+ rectangle of width 10, the pen would draw a rectangle of width 10.
+ Drawing a polygon defined by the corner points of the same
+ rectangle the stroke would have a width of 11.
+
+ The reason for this is best explained using the picture below:
+
+ \img q3painter_rationale.png
+
+ As we can see, stroking the rectangle so it gets a width of 10,
+ means the pen is drawn on a rectangle on width 9. The polygon,
+ however follows a consistent model.
+
+ In Qt 4, all rectangle based functions have changed to follow the
+ polygon approach, which means that the rectangle defines the size of
+ the fill, and the pen follows the edges of the shape. For pen widths
+ of 0 and 1 this means that the stroke will be inside the shape on the
+ left and the top and outside on the bottom and right.
+
+ The reason for the change in Qt 4 is so that we provide consistency
+ for all drawing functions even with complex transformations.
+*/
+
+TQPainter::TQPainter() : QPainter(), has_qwidget(FALSE), current_penpos(0,0) {
+}
+
+TQPainter::TQPainter( const QWidget *pdev, bool unclipped) : QPainter((QWidget*)pdev), has_qwidget(TRUE), current_penpos(0,0) {
+ qwidget_ptr = (QWidget*)pdev;
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+TQPainter::TQPainter( QPaintDevice *pdev, bool unclipped) : QPainter(pdev), has_qwidget(FALSE), current_penpos(0,0) {
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+TQPainter::TQPainter( QWidget *pdev, const QWidget *w, bool unclipped) : QPainter(pdev), has_qwidget(TRUE), current_penpos(0,0) {
+ qwidget_ptr = pdev;
+ initFrom(w);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+TQPainter::TQPainter( QPaintDevice *pdev, const QWidget *w, bool unclipped ) : QPainter(pdev), has_qwidget(FALSE), current_penpos(0,0) {
+ initFrom(w);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+// [FIXME]
+void TQPainter::flush() {
+ printf("[WARNING] void TQPainter::flush() unimplemented\n\r");
+}
+
+// [FIXME]
+void TQPainter::flush( const TQRegion &region, TQPainter::CoordinateMode cm ) {
+ printf("[WARNING] void TQPainter::flush( const TQRegion &region, CoordinateMode cm = CoordDevice ) unimplemented\n\r");
+}
+
+void TQPainter::setBrush(const QBrush &brush) {
+ return QPainter::setBrush(brush);
+}
+
+void TQPainter::setBrush(Qt::BrushStyle style) {
+ return QPainter::setBrush(style);
+}
+
+void TQPainter::setBrush(TQt::BrushStyle style) {
+ this->QPainter::setBrush((Qt::BrushStyle)style);
+}
+
+TQPoint TQPainter::pos() const {
+ return current_penpos;
+}
+
+bool TQPainter::tqbegin( QPaintDevice *pdev, bool unclipped ) {
+ bool ret = begin(pdev);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+ return ret;
+}
+
+bool TQPainter::tqbegin( QPaintDevice *pdev, const QWidget *init, bool unclipped ) {
+ bool ret = begin(pdev);
+ initFrom(init);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+ return ret;
+}
+
+QRectF TQPainter::boundingRect(const QRectF &rect, int flags, const QString &text) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRectF tqbr = QPainter::boundingRect(rect, flags, text);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+QRect TQPainter::boundingRect(const QRect &rect, int flags, const QString &text) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRect tqbr = QPainter::boundingRect(rect, flags, text);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+QRect TQPainter::boundingRect(int x, int y, int w, int h, int flags, const QString &text) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRect tqbr = QPainter::boundingRect(x, y, w, h, flags, text);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+QRectF TQPainter::boundingRect(const QRectF &rect, const QString &text, const QTextOption &o) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRectF tqbr = QPainter::boundingRect(rect, text, o);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+TQRect TQPainter::boundingRect(const QRect &rect, int flags, const QString &text, int len) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ TQRect tqbr = QPainter::boundingRect(rect, flags, text.left(len));
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+TQRect TQPainter::boundingRect(int x, int y, int w, int h, int flags, const QString &text, int len) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ TQRect tqbr = QPainter::boundingRect(QRect(x, y, w, h), flags, text.left(len));
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+void TQPainter::drawText(const QPointF &p, const QString &s) {
+ QPainter::drawText(p, s);
+}
+
+void TQPainter::drawText(const QPoint &p, const QString &s) {
+ QPainter::drawText(p, s);
+}
+
+void TQPainter::drawText(int x, int y, const QString &s) {
+ QPainter::drawText(x, y, s);
+}
+
+void TQPainter::drawText(const QPointF &p, const QString &str, int tf, int justificationPadding) {
+ QPainter::drawText(p, str, tf, justificationPadding);
+}
+
+void TQPainter::drawText(const QRectF &r, int flags, const QString &text, QRectF *br) {
+ QPainter::drawText(r, flags, text, br);
+}
+
+void TQPainter::drawText(const QRect &r, int flags, const QString &text, QRect *br) {
+ QPainter::drawText(r, flags, text, br);
+}
+
+void TQPainter::drawText(int x, int y, int w, int h, int flags, const QString &text, QRect *br) {
+ QPainter::drawText(x, y, w, h, flags, text, br);
+}
+
+void TQPainter::drawText(const QRectF &r, const QString &text, const QTextOption &o) {
+ QPainter::drawText(r, text, o);
+}
+
+void TQPainter::drawText( int x, int y, const TQString &s, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(x, y, s.left(len));
+ setLayoutDirection(old);
+}
+void TQPainter::drawText( const TQPoint &p, const TQString &s, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(p, s.left(len));
+ setLayoutDirection(old);
+}
+void TQPainter::drawText( int x, int y, const TQString &s, int pos, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(x, y, s.mid(pos, len));
+ setLayoutDirection(old);
+}
+void TQPainter::drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(p, s.mid(pos, len));
+ setLayoutDirection(old);
+}
+
+void TQPainter::drawText(int x, int y, const QString &s, int pos, int len) {
+ drawText(x, y, s.mid(pos, len));
+}
+
+void TQPainter::drawText(const QPoint &p, const QString &s, int pos, int len) {
+ drawText(p, s.mid(pos, len));
+}
+
+void TQPainter::drawText(int x, int y, const QString &s, int len) {
+ drawText(x, y, s.left(len));
+}
+
+void TQPainter::drawText(const QPoint &p, const QString &s, int len) {
+ drawText(p, s.left(len));
+}
+
+void TQPainter::drawText(const QRect &r, int flags, const QString &str, int len, QRect *br) {
+ drawText(r, flags, str.left(len), br);
+}
+
+void TQPainter::drawText(int x, int y, int w, int h, int flags, const QString &text, int len, QRect *br) {
+ drawText(QRect(x, y, w, h), flags, text.left(len), br);
+}
+
+int TQPainter::tabStops() const
+{
+ printf("[WARNING] TQPainter::tabStops unimplemented!\n\r");
+}
+
+void TQPainter::setTabStops( int ts )
+{
+ printf("[WARNING] TQPainter::setTabStops unimplemented!\n\r");
+
+// #if defined(TQT_CHECK_STATE)
+// if ( !isActive() )
+// qWarning( "TQPainter::setTabStops: Will be reset by begin()" );
+// #endif
+// tabstops = ts;
+// if ( isActive() && testf(ExtDev) ) { // tell extended tqdevice
+// TQPDevCmdParam param[1];
+// param[0].ival = ts;
+// pdev->cmd( TQPaintDevice::PdcSetTabStops, this, param );
+// }
+}
+
+int *TQPainter::tabArray() const
+{
+ printf("[WARNING] TQPainter::tabArray unimplemented!\n\r");
+}
+
+void TQPainter::setTabArray( int *ta )
+{
+ printf("[WARNING] TQPainter::setTabArray unimplemented!\n\r");
+
+// #if defined(TQT_CHECK_STATE)
+// if ( !isActive() )
+// qWarning( "TQPainter::setTabArray: Will be reset by begin()" );
+// #endif
+// if ( ta != tabarray ) {
+// tabarraylen = 0;
+// if ( tabarray ) // Avoid purify complaint
+// delete [] tabarray; // delete old array
+// if ( ta ) { // tabarray = copy of 'ta'
+// while ( ta[tabarraylen] )
+// tabarraylen++;
+// tabarraylen++; // and 0 terminator
+// tabarray = new int[tabarraylen]; // duplicate ta
+// memcpy( tabarray, ta, sizeof(int)*tabarraylen );
+// } else {
+// tabarray = 0;
+// }
+// }
+// if ( isActive() && testf(ExtDev) ) { // tell extended tqdevice
+// TQPDevCmdParam param[2];
+// param[0].ival = tabarraylen;
+// param[1].ivec = tabarray;
+// pdev->cmd( TQPaintDevice::PdcSetTabArray, this, param );
+// }
+}
+
+void TQPainter::drawImage( int x, int y, const TQImage image, int sx, int sy, int sw, int sh, int conversionFlags ) {
+ QPainter::drawImage(x, y, image, sx, sy, sw, sh, (Qt::ImageConversionFlags)conversionFlags);
+}
+
+void TQPainter::drawImage( const TQPoint p, const TQImage image, const TQRect sr, int conversionFlags ) {
+ QPainter::drawImage(p, image, sr, (Qt::ImageConversionFlags)conversionFlags);
+}
+
+void TQPainter::drawImage( const TQPoint p, const TQImage image, int conversion_flags ) {
+ TQ_UNUSED(conversion_flags);
+ QPainter::drawImage(p, image);
+}
+
+void TQPainter::drawImage( const TQRect r, const TQImage image ) {
+ QPainter::drawImage(r, image);
+}
+
+void TQPainter::resetXForm() {
+ resetTransform();
+}
+
+// [FIXME] The drawWinFocusRect methods below probably need tweaking to exactly match the old Qt3 behaviour
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h ) {
+ drawWinFocusRect( x, y, w, h, TRUE, TQt::color0 );
+}
+
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h, const TQColor &bgColor ) {
+ drawWinFocusRect( x, y, w, h, FALSE, bgColor );
+}
+
+void TQPainter::drawWinFocusRect( const TQRect &tqr ) {
+ drawWinFocusRect( tqr.x(), tqr.y(), tqr.width(), tqr.height() );
+}
+
+void TQPainter::drawWinFocusRect( const TQRect &tqr, const TQColor &bgColor ) {
+ drawWinFocusRect( tqr.x(), tqr.y(), tqr.width(), tqr.height(), bgColor );
+}
+
+void TQPainter::setBackgroundColor(const QColor &color) {
+ setBackground(color);
+}
+
+const QColor &TQPainter::backgroundColor() const {
+ return background().color();
+}
+
+void TQPainter::setClipRect(const QRectF &qrf, Qt::ClipOperation op) {
+ QPainter::setClipRect(qrf, op);
+}
+
+void TQPainter::setClipRect(const QRect &qr, Qt::ClipOperation op) {
+ QPainter::setClipRect(qr, op);
+}
+
+void TQPainter::setClipRect( int x, int y, int w, int h, TQPainter::CoordinateMode cm ) {
+ TQRect r(x, y, w, h);
+ setClipRect(r, cm);
+}
+
+void TQPainter::redirect(QPaintDevice *pdev, QPaintDevice *replacement) {
+ if (replacement == 0) {
+ restoreRedirected(pdev);
+ }
+ else {
+ setRedirected(pdev, replacement);
+ }
+}
+
+TQPaintDevice *TQPainter::redirect(QPaintDevice *pdev) {
+ return static_cast<TQPaintDevice*>(const_cast<QPaintDevice*>(redirected(pdev)));
+}
+
+void TQPainter::setWorldXForm(bool enabled) {
+ setMatrixEnabled(enabled);
+}
+
+bool TQPainter::hasWorldXForm() const {
+ return matrixEnabled();
+}
+
+void TQPainter::setViewXForm(bool enabled) {
+ setViewTransformEnabled(enabled);
+}
+
+bool TQPainter::hasViewXForm() const {
+ return viewTransformEnabled();
+}
+
+// [FIXME]
+void TQPainter::initialize() {
+ printf("[WARNING] TQColor static void initialize() not implemented\n\r");
+}
+
+// [FIXME]
+void TQPainter::cleanup() {
+ printf("[WARNING] TQColor static void cleanup() not implemented\n\r");
+}
+
+void TQPainter::moveTo( const TQPoint &p )
+{
+ moveTo( p.x(), p.y() );
+}
+
+void TQPainter::lineTo( const TQPoint &p )
+{
+ lineTo( p.x(), p.y() );
+}
+
+void TQPainter::drawRect(const QRect &r)
+{
+ QPainter::drawRect(adjustedRectangle(r));
+}
+
+void TQPainter::drawEllipse(const QRect &r)
+{
+ QPainter::drawEllipse(adjustedRectangle(r));
+}
+
+void TQPainter::drawRoundRect(const QRect &r, int xrnd, int yrnd)
+{
+ QPainter::drawRoundRect(adjustedRectangle(r), xrnd, yrnd);
+}
+
+void TQPainter::drawArc(const QRect &r, int angle, int arcLength)
+{
+ QPainter::drawArc(adjustedRectangle(r), angle, arcLength);
+}
+
+void TQPainter::drawPie(const QRect &r, int angle, int arcLength)
+{
+ QPainter::drawPie(adjustedRectangle(r), angle, arcLength);
+}
+
+void TQPainter::drawChord(const QRect &r, int angle, int arcLength)
+{
+ QPainter::drawChord(adjustedRectangle(r), angle, arcLength);
+}
+
+void TQPainter::tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags )
+{
+ tqdrawTextItem( p.x(), p.y(), ti, textflags );
+}
+
+// [FIXME]
+// Verify these mappings...
+// They will need to be kept in sync with the code inside tqpainter_x11.cpp
+TQt::RasterOp TQPainter::rasterOp() const
+{
+ TQt::RasterOp cm;
+ switch (rop) {
+ case QPainter::CompositionMode_SourceOver:
+ cm=CopyROP;
+ break;
+ case QPainter::RasterOp_SourceOrDestination:
+ cm=OrROP;
+ break;
+ case QPainter::RasterOp_SourceXorDestination:
+ cm=XorROP;
+ break;
+ case QPainter::RasterOp_NotSourceAndDestination:
+ cm=NotAndROP;
+ break;
+ case QPainter::RasterOp_NotSource:
+ cm=NotCopyROP;
+ break;
+ case QPainter::RasterOp_NotSourceXorDestination:
+ cm=NotXorROP;
+ break;
+ case QPainter::RasterOp_SourceAndDestination:
+ cm=AndROP;
+ break;
+ case QPainter::CompositionMode_Clear:
+ cm=ClearROP;
+ break;
+ case QPainter::CompositionMode_Destination:
+ cm=NopROP;
+ break;
+ case QPainter::RasterOp_SourceAndNotDestination:
+ cm=AndNotROP;
+ break;
+ case QPainter::RasterOp_NotSourceOrNotDestination:
+ cm=NandROP;
+ break;
+ case QPainter::RasterOp_NotSourceAndNotDestination:
+ cm=NorROP;
+ break;
+ default:
+ cm=CopyROP;
+ break;
+ }
+ return cm;
+}
+
+/*!
+ \fn TQPainter::TQPainter()
+
+ Constructs a TQPainter.
+*/
+
+/*!
+ \fn TQPainter::TQPainter(QPaintDevice *pdev)
+
+ Constructs a TQPainter that operates on tqdevice \a pdev.
+*/
+
+/*!
+ \internal
+*/
+
+int TQPainter::rectSubtraction() const {
+ return pen().style() != Qt::NoPen && pen().width() == 0 ? 1 : 0;
+}
+
+/*!
+ \internal
+*/
+QRect TQPainter::adjustedRectangle(const QRect &r)
+{
+ QRect rect = r.normalized();
+ int subtract = rectSubtraction();
+ if (subtract != 0)
+ rect.setSize(QSize(rect.width() - subtract, rect.height() - subtract));
+ return rect;
+}
+
+
+/*!
+ \fn void TQPainter::drawRect(int x, int y, int w, int h)
+
+ \overload
+
+ Draws the rectangle that fits inside the bounds specified by \a x,
+ \a y, \a w and \a h using the current pen and brush.
+*/
+
+/*!
+ \fn void TQPainter::drawRect(const QRect &r)
+
+ Draws a rectangle that fits inside the rectangle \a r using the
+ current pen and brush.
+
+*/
+
+
+
+/*!
+ \fn TQPainter::drawEllipse(const QRect &r)
+
+ Draws the ellipse that fits inside the bounds \a r using the
+ current pen and brush.
+
+*/
+
+/*!
+ \fn TQPainter::drawEllipse(int x, int y, int width, int height)
+
+ \overload
+
+ Draws an ellipse that fits inside the bounds specified by \a x,
+ \a y, \a width and \a height using the current pen and brush.
+
+*/
+
+/*!
+ \fn void TQPainter::drawPie(int x, int y, int w, int h, int
+ startAngle, int spanAngle)
+
+ \overload
+
+ Draws a pie segment that fits inside the bounds (\a{x}, \a{y},
+ \a{w}, \a{h}) with the given \a startAngle and \a spanAngle.
+*/
+
+/*!
+ \fn void TQPainter::drawPie(const QRect &r, int a, int alen)
+
+ Draws a pie defined by the rectangle \a r, the start angle \a a
+ and the arc length \a alen.
+
+ The pie is filled with the current brush().
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ \sa drawArc(), drawChord()
+*/
+
+/*!
+ \fn void TQPainter::drawArc(int x, int y, int w, int h, int
+ startAngle, int spanAngle)
+
+ \overload
+
+ Draws the arc that fits inside the rectangle (\a{x}, \a{y}, \a{w},
+ \a{h}), with the given \a startAngle and \a spanAngle.
+*/
+
+/*!
+ \fn void TQPainter::drawArc(const QRect &r, int a, int alen)
+
+ Draws an arc defined by the rectangle \a r, the start angle \a a
+ and the arc length \a alen.
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ Example:
+ \snippet doc/src/snippets/code/src_qt3support_painting_q3painter.cpp 0
+
+ \sa drawPie(), drawChord()
+*/
+
+/*!
+ \fn void TQPainter::drawChord(int x, int y, int w, int h, int
+ startAngle, int spanAngle)
+
+ \overload
+
+ Draws a chord that fits inside the rectangle (\a{x}, \a{y}, \a{w},
+ \a{h}) with the given \a startAngle and \a spanAngle.
+*/
+
+
+/*!
+ \fn void TQPainter::drawChord(const QRect &r, int a, int alen)
+
+ Draws a chord defined by the rectangle \a r, the start angle \a a
+ and the arc length \a alen.
+
+ The chord is filled with the current brush().
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ \sa drawArc(), drawPie()
+*/
+
+/*!
+ \fn void TQPainter::drawRoundRect(const QRect &r, int xrnd, int yrnd)
+
+ Draws a rounded rect that fits into the bounds \a r using the current
+ pen and brush. The parameters \a xrnd and \a yrnd specifies the roundness
+ in x and y direction.
+*/
+
+/*!
+ \fn void TQPainter::drawRoundRect(int x, int y, int w, int h, int xrnd, int yrnd)
+
+ \overload
+
+ Draws a rounded rect that fits into the bounds \a x, \a y, \a w
+ and \a h using the current pen and brush. The parameters \a xrnd
+ and \a yrnd specifies the roundness in x and y direction.
+*/
+
+/*!
+ \fn void QPainter::drawLineSegments(const QPolygon &polygon, int
+ index, int count)
+
+ Draws \a count separate lines from points defined by the \a
+ polygon, starting at \a{polygon}\e{[index]} (\a index defaults to
+ 0). If \a count is -1 (the default) all points until the end of
+ the array are used.
+
+ Use drawLines() combined with QPolygon::constData() instead.
+
+ \oldcode
+ QPainter painter(this);
+ painter.drawLineSegments(polygon, index, count);
+ \newcode
+ int lineCount = (count == -1) ? (polygon.size() - index) / 2 : count;
+
+ QPainter painter(this);
+ painter.drawLines(polygon.constData() + index * 2, lineCount);
+ \endcode
+*/
+
+void TQPainter::drawLineSegments(const QPolygon &polygon, int index, int count)
+{
+ int lineCount = (count == -1) ? (polygon.size() - index) / 2 : count;
+
+ drawLines(polygon.constData() + index * 2, lineCount);
+}
+
+/*!
+ \obsolete
+
+ Use the worldTransform() combined with QTransform::dx() instead.
+
+ \oldcode
+ QPainter painter(this);
+ qreal x = painter.translationX();
+ \newcode
+ QPainter painter(this);
+ qreal x = painter.worldTransform().dx();
+ \endcode
+*/
+qreal TQPainter::translationX() const
+{
+ return worldTransform().dx();
+}
+
+/*!
+ \obsolete
+
+ Use the worldTransform() combined with QTransform::dy() instead.
+
+ \oldcode
+ QPainter painter(this);
+ qreal y = painter.translationY();
+ \newcode
+ QPainter painter(this);
+ qreal y = painter.worldTransform().dy();
+ \endcode
+*/
+qreal TQPainter::translationY() const
+{
+ return worldTransform().dy();
+}
+
+/*!
+ \fn void TQPainter::map(int x, int y, int *rx, int *ry) const
+
+ \internal
+
+ Sets (\a{rx}, \a{ry}) to the point that results from applying the
+ painter's current transformation on the point (\a{x}, \a{y}).
+*/
+void TQPainter::map(int x, int y, int *rx, int *ry) const
+{
+ QPoint p(x, y);
+ p = p * combinedMatrix();
+ *rx = p.x();
+ *ry = p.y();
+}
+
+/*!
+ \internal
+ Maps a rectangle from logical coordinates to device coordinates.
+ This internal function does not handle rotation and/or shear.
+*/
+
+void TQPainter::map( int x, int y, int w, int h, int *rx, int *ry, int *rw, int *rh ) const
+{
+ TQRect qr(x, y, w, h);
+ QTransform dtrans = combinedTransform();
+ TQRect tqr = dtrans.mapRect(qr);
+ *rx = tqr.x();
+ *ry = tqr.y();
+ *rw = tqr.width();
+ *rh = tqr.height();
+}
+
+/*!
+ \fn TQPoint TQPainter::xForm(const QPoint &point) const
+
+ Use combinedTransform() instead.
+*/
+
+TQPoint TQPainter::xForm(const QPoint &p) const
+{
+ if (combinedTransform().type() == QTransform::TxNone)
+ return p;
+ return p * combinedMatrix();
+}
+
+
+/*!
+ \fn TQRect TQPainter::xForm(const QRect &rectangle) const
+ \overload
+
+ Use combinedTransform() instead of this function and call
+ mapRect() on the result to obtain a QRect.
+*/
+
+TQRect TQPainter::xForm(const QRect &r) const
+{
+ if (combinedTransform().type() == QTransform::TxNone)
+ return r;
+ return combinedMatrix().mapRect(r);
+}
+
+bool TQPainter::testf( uint b ) const {
+// printf("[WARNING] QPainter::testf() disabled\n\r");
+// return 0;
+
+ // Map to Qt4 flags and functions...
+ if ((b&IsActive)!=0) {
+ if (QPainter::isActive()) return TRUE;
+ }
+// if ((b&ExtDev)!=0) {
+// printf("[WARNING] Assuming ExtDev==false in QPainter::testf()\n\r");
+// }
+// if ((b&IsStartingUp)!=0) {
+// }
+// if ((b&NoCache)!=0) {
+// }
+ if ((b&VxF)!=0) {
+ if (QPainter::viewTransformEnabled()) return TRUE;
+ }
+ if ((b&WxF)!=0) {
+ if (QPainter::worldMatrixEnabled()) return TRUE;
+ }
+ if ((b&ClipOn)!=0) {
+ if (QPainter::hasClipping()) return TRUE;
+ }
+
+ printf("[WARNING] Assuming test flag 0x%x == false in QPainter::testf()\n\r", b);
+ return 0;
+}
+
+/*!
+ \fn TQPolygon TQPainter::xForm(const QPolygon &polygon) const
+ \overload
+
+ Use combinedTransform() instead.
+*/
+
+// TQPolygon TQPainter::xForm(const QPolygon &a) const
+// {
+// Q_D(const QPainter);
+// if (!d->engine) {
+// qWarning("QPainter::xForm: Painter not active");
+// return QPolygon();
+// }
+// if (d->state->matrix.type() == QTransform::TxNone)
+// return a;
+// return a * combinedMatrix();
+// }
+
+/*!
+ \fn TQPolygon TQPainter::xForm(const QPolygon &polygon, int index, int count) const
+ \overload
+
+ Use combinedTransform() combined with QPolygon::mid() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPolygon transformed = painter.xForm(polygon, index, count)
+ \newcode
+ QPainter painter(this);
+ QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform();
+ \endcode
+*/
+
+// TQPolygon TQPainter::xForm(const QPolygon &av, int index, int npoints) const
+// {
+// int lastPoint = npoints < 0 ? av.size() : index+npoints;
+// QPolygon a(lastPoint-index);
+// memcpy(a.data(), av.data()+index, (lastPoint-index)*sizeof(QPoint));
+// return a * combinedMatrix();
+// }
+
+/*!
+ \fn TQPoint TQPainter::xFormDev(const QPoint &point) const
+ \overload
+ \obsolete
+
+ Use combinedTransform() combined with QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPoint transformed = painter.xFormDev(point);
+ \newcode
+ QPainter painter(this);
+ QPoint transformed = point * painter.combinedTransform().inverted();
+ \endcode
+*/
+
+TQPoint TQPainter::xFormDev(const QPoint &p) const
+{
+ if(combinedTransform().type() == QTransform::TxNone)
+ return p;
+ return p * combinedMatrix().inverted();
+}
+
+/*!
+ \fn TQRect TQPainter::xFormDev(const QRect &rectangle) const
+ \overload
+ \obsolete
+
+ Use combinedTransform() combined with QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QRect transformed = painter.xFormDev(rectangle);
+ \newcode
+ QPainter painter(this);
+ QRegion region = QRegion(rectangle) * painter.combinedTransform().inverted();
+ QRect transformed = region.boundingRect();
+ \endcode
+*/
+
+TQRect TQPainter::xFormDev(const QRect &r) const
+{
+ if (combinedTransform().type() == QTransform::TxNone)
+ return r;
+ return combinedMatrix().inverted().mapRect(r);
+}
+
+/*!
+ \overload
+
+ \fn TQPoint TQPainter::xFormDev(const QPolygon &polygon) const
+ \obsolete
+
+ Use combinedTransform() combined with QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPolygon transformed = painter.xFormDev(rectangle);
+ \newcode
+ QPainter painter(this);
+ QPolygon transformed = polygon * painter.combinedTransform().inverted();
+ \endcode
+*/
+
+// TQPolygon TQPainter::xFormDev(const QPolygon &a) const
+// {
+// Q_D(const QPainter);
+// if (!d->engine) {
+// qWarning("QPainter::xFormDev: Painter not active");
+// return QPolygon();
+// }
+// if (d->state->matrix.type() == QTransform::TxNone)
+// return a;
+// return a * combinedMatrix().inverted();
+// }
+
+/*!
+ \fn TQPolygon TQPainter::xFormDev(const QPolygon &polygon, int index, int count) const
+ \overload
+ \obsolete
+
+ Use combinedTransform() combined with QPolygon::mid() and QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPolygon transformed = painter.xFormDev(polygon, index, count);
+ \newcode
+ QPainter painter(this);
+ QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform().inverted();
+ \endcode
+*/
+
+// TQPolygon TQPainter::xFormDev(const QPolygon &ad, int index, int npoints) const
+// {
+// Q_D(const QPainter);
+// int lastPoint = npoints < 0 ? ad.size() : index+npoints;
+// QPolygon a(lastPoint-index);
+// memcpy(a.data(), ad.data()+index, (lastPoint-index)*sizeof(QPoint));
+// if (d->state->matrix.type() == QTransform::TxNone)
+// return a;
+// return a * combinedMatrix().inverted();
+// }
+
+/*! \obsolete
+ Sets the current pen position to \a (x, y)
+
+ \sa lineTo(), pos()
+*/
+
+void TQPainter::moveTo( int x, int y )
+{
+ QPainterPath path;
+ path.moveTo(x, y);
+ drawPath(path);
+ current_penpos = QPoint(x, y);
+}
+
+/*! \obsolete
+ Use drawLine() instead.
+
+ Draws a line from the current pen position to \a (x, y) and sets
+ \a (x, y) to be the new current pen position.
+
+ \sa TQPen moveTo(), drawLine(), pos()
+*/
+
+void TQPainter::lineTo( int x, int y )
+{
+ QPainterPath path;
+ path.moveTo(current_penpos.x(), current_penpos.y());
+ path.lineTo(x, y);
+ drawPath(path);
+ current_penpos = QPoint(x, y);
+}
+
+static void bitBlt_helper(QPaintDevice *dst, const QPoint &dp,
+ const QPaintDevice *src, const QRect &sr, bool)
+{
+ Q_ASSERT(dst);
+ Q_ASSERT(src);
+
+ if (src->devType() == QInternal::Pixmap) {
+ const QPixmap *pixmap = static_cast<const QPixmap *>(src);
+ QPainter pt(dst);
+ pt.drawPixmap(dp, *pixmap, sr);
+
+ } else {
+ qWarning("QPainter: bitBlt only works when source is of type pixmap");
+ }
+}
+
+void bitBlt(QPaintDevice *dst, int dx, int dy,
+ const QPaintDevice *src, int sx, int sy, int sw, int sh,
+ bool ignoreMask )
+{
+ bitBlt_helper(dst, QPoint(dx, dy), src, QRect(sx, sy, sw, sh), ignoreMask);
+}
+
+void bitBlt(QPaintDevice *dst, const QPoint &dp, const QPaintDevice *src, const QRect &sr, bool ignoreMask)
+{
+ bitBlt_helper(dst, dp, src, sr, ignoreMask);
+}
+
+void bitBlt(QPaintDevice *dst, int dx, int dy,
+ const QImage *src, int sx, int sy, int sw, int sh, int fl)
+{
+ Qt::ImageConversionFlags flags(fl);
+ QPixmap srcPixmap = QPixmap::fromImage(*src, flags);
+ bitBlt_helper(dst, QPoint(dx, dy), &srcPixmap, QRect(sx, sy, sw, sh), false);
+}
+
+const TQWMatrix &TQPainter::tqworldMatrix() const {
+ return (*(static_cast<const TQWMatrix*>(&worldMatrix())));
+}
+
+/*!
+ \fn void TQPainter::tqdrawTextItem(const TQPoint &, const TQTextItem &, int)
+ \internal
+*/
+
+static inline void fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ if ( *w < 0 ) {
+ *w = -*w + 2;
+ *x -= *w - 1;
+ }
+ if ( *h < 0 ) {
+ *h = -*h + 2;
+ *y -= *h - 1;
+ }
+}
+void TQPainter::fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ ::fix_neg_rect(x,y,w,h);
+}
+
+TQRegion TQPainter::clipRegion( CoordinateMode cm ) const {
+ QRegion qr = QPainter::clipRegion();
+ QRegion tqr = qr;
+ if (cm == CoordDevice) {
+ // Convert to device coordinates
+ QTransform dtrans = combinedTransform();
+ tqr = dtrans.map(qr);
+ }
+ return tqr;
+}
+
+void TQPainter::setClipRegion( const QRegion &qr, CoordinateMode cm ) {
+ QRegion tqr = qr;
+
+ if (cm == CoordDevice) {
+ // Convert from device coordinates
+ QTransform itrans = combinedTransform().inverted();
+ tqr = itrans.map(qr);
+
+ QPainter::setClipRegion( tqr, Qt::ReplaceClip );
+ }
+ else {
+ QPainter::setClipRegion( tqr, Qt::ReplaceClip );
+ }
+}
+
+void TQPainter::setClipRect( const TQRect &qr, CoordinateMode cm ) {
+ QRect tqr = qr;
+
+ if (cm == CoordDevice) {
+ // Convert from device coordinates
+ QTransform itrans = combinedTransform().inverted();
+ tqr = itrans.mapRect(qr);
+
+ QPainter::setClipRect( tqr, Qt::ReplaceClip );
+ }
+ else {
+ QPainter::setClipRect( tqr, Qt::ReplaceClip );
+ }
+}
+
+#ifndef TQT_NO_BEZIER
+void TQPainter::drawCubicBezier(const TQPointArray &a, int index)
+{
+ if ((int)a.size() - index < 4) {
+ qWarning("QPainter::drawCubicBezier: Cubic Bezier needs 4 control "
+ "points");
+ return;
+ }
+
+ QPainterPath path;
+ path.moveTo(a.at(index));
+ path.cubicTo(a.at(index+1), a.at(index+2), a.at(index+3));
+ strokePath(path, pen());
+}
+#endif // TQT_NO_BEZIER
+
+#ifndef TQT_NO_PICTURE
+void TQPainter::drawPicture( const QPicture pic ) {
+ QPainter::drawPicture(0, 0, pic);
+}
+
+void TQPainter::drawPicture( int x, int y, const QPicture pic ) {
+ QPainter::drawPicture(x, y, pic);
+}
+
+void TQPainter::drawPicture( const QPoint point, const QPicture pic ) {
+ QPainter::drawPicture(point.x(), point.y(), pic);
+}
+#endif // TQT_NO_PICTURE
+
+/*! \obsolete
+
+ We recommend using save() instead.
+*/
+
+void TQPainter::saveWorldMatrix() {
+ save();
+}
+
+/*! \obsolete
+ We recommend using restore() instead.
+*/
+
+void TQPainter::restoreWorldMatrix() {
+ restore();
+}
+
+/*!
+ \overload
+
+ Returns the point array \a av transformed from model coordinates
+ to tqdevice coordinates.
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xForm( const TQPointArray &av ) const
+{
+ TQPointArray a = av;
+ if ( combinedTransform().type() != QTransform::TxNone )
+ {
+ return TQT_TQWMATRIX_OBJECT(combinedMatrix()) * av;
+ }
+ return a;
+}
+
+/*!
+ \overload
+
+ Returns the point array \a av transformed from model coordinates
+ to tqdevice coordinates. The \a index is the first point in the
+ array and \a npoints denotes the number of points to be
+ transformed. If \a npoints is negative, all points from \a
+ av[index] until the last point in the array are transformed.
+
+ The returned point array consists of the number of points that
+ were transformed.
+
+ Example:
+ \code
+ TQPointArray a(10);
+ TQPointArray b;
+ b = painter.xForm(a, 2, 4); // b.size() == 4
+ b = painter.xForm(a, 2, -1); // b.size() == 8
+ \endcode
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xForm( const TQPointArray &av, int index,
+ int npoints ) const
+{
+ int lastPoint = npoints < 0 ? av.size() : index+npoints;
+ TQPointArray a( lastPoint-index );
+ memcpy( a.data(), av.data()+index, (lastPoint-index)*sizeof( TQPoint ) );
+ return TQT_TQWMATRIX_OBJECT(combinedMatrix()) * a;
+}
+
+/*!
+ \overload
+
+ Returns the point array \a ad transformed from tqdevice coordinates
+ to model coordinates.
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xFormDev( const TQPointArray &ad ) const
+{
+ if ( combinedTransform().type() == QTransform::TxNone )
+ return ad;
+ return TQT_TQWMATRIX_OBJECT(combinedMatrix().inverted()) * ad;
+}
+
+/*!
+ \overload
+
+ Returns the point array \a ad transformed from tqdevice coordinates
+ to model coordinates. The \a index is the first point in the array
+ and \a npoints denotes the number of points to be transformed. If
+ \a npoints is negative, all points from \a ad[index] until the
+ last point in the array are transformed.
+
+ The returned point array consists of the number of points that
+ were transformed.
+
+ Example:
+ \code
+ TQPointArray a(10);
+ TQPointArray b;
+ b = painter.xFormDev(a, 1, 3); // b.size() == 3
+ b = painter.xFormDev(a, 1, -1); // b.size() == 9
+ \endcode
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xFormDev( const TQPointArray &ad, int index, int npoints ) const
+{
+ int lastPoint = npoints < 0 ? ad.size() : index+npoints;
+ TQPointArray a( lastPoint-index );
+ memcpy( a.data(), ad.data()+index, (lastPoint-index)*sizeof( TQPoint ) );
+ if ( combinedTransform().type() == QTransform::TxNone )
+ return a;
+ return TQT_TQWMATRIX_OBJECT(combinedMatrix().inverted()) * a;
+}
+
+/*!
+ Draws/plots an array of points, \a a, using the current pen.
+
+ If \a index is non-zero (the default is zero) only points from \a
+ index are drawn. If \a npoints is negative (the default) the rest
+ of the points from \a index are drawn. If \a npoints is zero or
+ greater, \a npoints points are drawn.
+
+ \warning On X11, coordinates that do not fit into 16-bit signed
+ values are truncated. This limitation is expected to go away in
+ TQt 4.
+*/
+
+void TQPainter::drawPoints( const TQPointArray& a, int index, int npoints )
+{
+ if ( npoints < 0 )
+ npoints = a.size() - index;
+ if ( index + npoints > (int)a.size() )
+ npoints = a.size() - index;
+ if ( !isActive() || npoints < 1 || index < 0 )
+ return;
+ TQPointArray pa = a;
+ for (int i=0; i<npoints; i++) {
+ TQPoint p( pa[index+i].x(), pa[index+i].y() );
+ drawPoint(p);
+ }
+}
+
+/*!
+ Returns the font info for the painter, if the painter is active.
+ It is not possible to obtain font information for an inactive
+ painter, so the return value is undefined if the painter is not
+ active.
+
+ \sa fontMetrics(), isActive()
+*/
+
+TQFontInfo TQPainter::fontInfo() const
+{
+ printf("[WARNING] TQFontInfo TQPainter::fontInfo() partially implemented!\n\r");
+
+ QFontInfo qfi = QPainter::fontInfo();
+ TQFontInfo tqfi = TQFontInfo(*static_cast<TQFontInfo*>(&qfi));
+ return tqfi;
+
+// if ( pdev && pdev->devType() == TQInternal::Picture )
+// return TQFontInfo( cfont );
+//
+// return TQFontInfo(this);
+}
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of TQPainter, TQPen and TQBrush classes
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpainter_p.h"
+#include "tqbitmap.h"
+#include "tqptrstack.h"
+#include "tqptrdict.h"
+#include "tqdatastream.h"
+#include "tqwidget.h"
+#include "tqimage.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqapplication.h"
+#include "tqrichtext_p.h"
+#include "tqregexp.h"
+#include "tqcleanuphandler.h"
+#ifdef TQ_WS_TQWS
+#include "tqgfx_qws.h"
+#endif
+#include <string.h>
+
+#include "tqtextlayout_p.h"
+#include "tqfontengine_p.h"
+
+#ifndef TQT_NO_TRANSFORMATIONS
+typedef TQPtrStack<TQWMatrix> TQWMatrixStack;
+#endif
+
+// POSIX Large File Support redefines truncate -> truncate64
+#if defined(truncate)
+# undef truncate
+#endif
+
+/*!
+ \class TQPainter tqpainter.h
+ \brief The TQPainter class does low-level painting e.g. on widgets.
+
+ \ingroup graphics
+ \ingroup images
+ \mainclass
+
+ The painter provides highly optimized functions to do most of the
+ drawing GUI programs require. TQPainter can draw everything from
+ simple lines to complex tqshapes like pies and chords. It can also
+ draw aligned text and pixmaps. Normally, it draws in a "natural"
+ coordinate system, but it can also do view and world
+ transformation.
+
+ The typical use of a painter is:
+
+ \list
+ \i Construct a painter.
+ \i Set a pen, a brush etc.
+ \i Draw.
+ \i Destroy the painter.
+ \endlist
+
+ Mostly, all this is done inside a paint event. (In fact, 99% of
+ all TQPainter use is in a reimplementation of
+ TQWidget::paintEvent(), and the painter is heavily optimized for
+ such use.) Here's one very simple example:
+
+ \code
+ void SimpleExampleWidget::paintEvent()
+ {
+ TQPainter paint( this );
+ paint.setPen( TQt::blue );
+ paint.drawText( rect(), AlignCenter, "The Text" );
+ }
+ \endcode
+
+ Usage is simple, and there are many settings you can use:
+
+ \list
+
+ \i font() is the currently set font. If you set a font that isn't
+ available, TQt tqfinds a close match. In fact font() returns what
+ you set using setFont() and fontInfo() returns the font actually
+ being used (which may be the same).
+
+ \i brush() is the currently set brush; the color or pattern that's
+ used for filling e.g. circles.
+
+ \i pen() is the currently set pen; the color or stipple that's
+ used for drawing lines or boundaries.
+
+ \i backgroundMode() is \c Opaque or \c Transtqparent, i.e. whether
+ backgroundColor() is used or not.
+
+ \i backgroundColor() only applies when backgroundMode() is Opaque
+ and pen() is a stipple. In that case, it describes the color of
+ the background pixels in the stipple.
+
+ \i rasterOp() is how pixels drawn interact with the pixels already
+ there.
+
+ \i brushOrigin() is the origin of the tiled brushes, normally the
+ origin of the window.
+
+ \i viewport(), window(), tqworldMatrix() and many more make up the
+ painter's coordinate transformation system. See \link
+ coordsys.html The Coordinate System \endlink for an explanation of
+ this, or see below for a very brief overview of the functions.
+
+ \i hasClipping() is whether the painter clips at all. (The paint
+ tqdevice clips, too.) If the painter clips, it clips to clipRegion().
+
+ \i pos() is the current position, set by moveTo() and used by
+ lineTo().
+
+ \endlist
+
+ Note that some of these settings mirror settings in some paint
+ tqdevices, e.g. TQWidget::font(). TQPainter::begin() (or the TQPainter
+ constructor) copies these attributes from the paint tqdevice.
+ Calling, for example, TQWidget::setFont() doesn't take effect until
+ the next time a painter begins painting on it.
+
+ save() saves all of these settings on an internal stack, restore()
+ pops them back.
+
+ The core functionality of TQPainter is drawing, and there are
+ functions to draw most primitives: drawPoint(), drawPoints(),
+ drawLine(), drawRect(), drawWinFocusRect(), drawRoundRect(),
+ drawEllipse(), drawArc(), drawPie(), drawChord(),
+ drawLineSegments(), drawPolyline(), drawPolygon(),
+ drawConvexPolygon() and drawCubicBezier(). All of these functions
+ take integer coordinates; there are no floating-point versions
+ since we want drawing to be as fast as possible.
+
+ There are functions to draw pixmaps/images, namely drawPixmap(),
+ drawImage() and drawTiledPixmap(). drawPixmap() and drawImage()
+ produce the same result, except that drawPixmap() is faster
+ on-screen and drawImage() faster and sometimes better on TQPrinter
+ and TQPicture.
+
+ Text drawing is done using drawText(), and when you need
+ fine-grained positioning, boundingRect() tells you where a given
+ drawText() command would draw.
+
+ There is a drawPicture() function that draws the contents of an
+ entire TQPicture using this painter. drawPicture() is the only
+ function that disregards all the painter's settings: the TQPicture
+ has its own settings.
+
+ Normally, the TQPainter operates on the tqdevice's own coordinate
+ system (usually pixels), but TQPainter has good support for
+ coordinate transformation. See \link coordsys.html The Coordinate
+ System \endlink for a more general overview and a simple example.
+
+ The most common functions used are scale(), rotate(), translate()
+ and shear(), all of which operate on the tqworldMatrix().
+ setWorldMatrix() can tqreplace or add to the currently set
+ tqworldMatrix().
+
+ setViewport() sets the rectangle on which TQPainter operates. The
+ default is the entire tqdevice, which is usually fine, except on
+ printers. setWindow() sets the coordinate system, that is, the
+ rectangle that maps to viewport(). What's drawn inside the
+ window() ends up being inside the viewport(). The window's
+ default is the same as the viewport, and if you don't use the
+ transformations, they are optimized away, gaining another little
+ bit of speed.
+
+ After all the coordinate transformation is done, TQPainter can clip
+ the drawing to an arbitrary rectangle or region. hasClipping() is
+ TRUE if TQPainter clips, and clipRegion() returns the clip region.
+ You can set it using either setClipRegion() or setClipRect().
+ Note that the clipping can be slow. It's all system-dependent,
+ but as a rule of thumb, you can assume that drawing speed is
+ inversely proportional to the number of rectangles in the clip
+ region.
+
+ After TQPainter's clipping, the paint tqdevice may also clip. For
+ example, most widgets clip away the pixels used by child widgets,
+ and most printers clip away an area near the edges of the paper.
+ This additional clipping is not reflected by the return value of
+ clipRegion() or hasClipping().
+
+ TQPainter also includes some less-used functions that are very
+ useful on those occasions when they're needed.
+
+ isActive() indicates whether the painter is active. begin() (and
+ the most usual constructor) makes it active. end() (and the
+ destructor) deactivates it. If the painter is active, tqdevice()
+ returns the paint tqdevice on which the painter paints.
+
+ Sometimes it is desirable to make someone else paint on an unusual
+ TQPaintDevice. TQPainter supports a static function to do this,
+ redirect(). We recommend not using it, but for some hacks it's
+ perfect.
+
+ setTabStops() and setTabArray() can change where the tab stops
+ are, but these are very seldomly used.
+
+ \warning Note that TQPainter does not attempt to work around
+ coordinate limitations in the underlying window system. Some
+ platforms may behave incorrectly with coordinates as small as
+ +/-4000.
+
+ \headerfile tqdrawutil.h
+
+ \sa TQPaintDevice TQWidget TQPixmap TQPrinter TQPicture
+ \link simple-application.html Application Walkthrough \endlink
+ \link coordsys.html Coordinate System Overview \endlink
+*/
+
+/*!
+ \fn TQGfx * TQPainter::internalGfx()
+
+ \internal
+*/
+
+/*!
+ \enum TQPainter::CoordinateMode
+ \value CoordDevice
+ \value CoordPainter
+
+ \sa clipRegion()
+*/
+/*!
+ \enum TQPainter::TextDirection
+ \value Auto
+ \value RTL right to left
+ \value LTR left to right
+
+ \sa drawText()
+*/
+
+/*!
+ \enum TQt::PaintUnit
+ \value PixelUnit
+ \value LoMetricUnit \e obsolete
+ \value HiMetricUnit \e obsolete
+ \value LoEnglishUnit \e obsolete
+ \value HiEnglishUnit \e obsolete
+ \value TwipsUnit \e obsolete
+*/
+
+/*!
+ \enum TQt::BrushStyle
+
+ \value NoBrush
+ \value SolidPattern
+ \value Dense1Pattern
+ \value Dense2Pattern
+ \value Dense3Pattern
+ \value Dense4Pattern
+ \value Dense5Pattern
+ \value Dense6Pattern
+ \value Dense7Pattern
+ \value HorPattern
+ \value VerPattern
+ \value CrossPattern
+ \value BDiagPattern
+ \value FDiagPattern
+ \value DiagCrossPattern
+ \value CustomPattern
+
+ \img brush-styles.png Brush Styles
+
+*/
+
+/*!
+ \enum TQt::RasterOp
+
+ This enum type is used to describe the way things are written to
+ the paint tqdevice. Each bit of the \e src (what you write)
+ interacts with the corresponding bit of the \e dst pixel.
+
+ \value CopyROP dst = src
+ \value OrROP dst = src OR dst
+ \value XorROP dst = src XOR dst
+ \value NotAndROP dst = (NOT src) AND dst
+ \value EraseROP an alias for \c NotAndROP
+ \value NotCopyROP dst = NOT src
+ \value NotOrROP dst = (NOT src) OR dst
+ \value NotXorROP dst = (NOT src) XOR dst
+ \value AndROP dst = src AND dst
+ \value NotEraseROP an alias for \c AndROP
+ \value NotROP dst = NOT dst
+ \value ClearROP dst = 0
+ \value SetROP dst = 1
+ \value NopROP dst = dst
+ \value AndNotROP dst = src AND (NOT dst)
+ \value OrNotROP dst = src OR (NOT dst)
+ \value NandROP dst = NOT (src AND dst)
+ \value NorROP dst = NOT (src OR dst)
+
+ By far the most useful ones are \c CopyROP and \c XorROP.
+
+ On TQt/Embedded, only \c CopyROP, \c XorROP, and \c NotROP are supported.
+*/
+
+/*!
+ \enum TQt::AlignmentFlags
+
+ This enum type is used to describe tqalignment. It tqcontains
+ horizontal and vertical flags.
+
+ The horizontal flags are:
+
+ \value AlignAuto Aligns according to the language. Left for most,
+ right for Arabic and Hebrew.
+ \value AlignLeft Aligns with the left edge.
+ \value AlignRight Aligns with the right edge.
+ \value AlignHCenter Centers horizontally in the available space.
+ \value AlignJustify Justifies the text in the available space.
+ Does not work for everything and may be interpreted as
+ AlignAuto in some cases.
+
+ The vertical flags are:
+
+ \value AlignTop Aligns with the top.
+ \value AlignBottom Aligns with the bottom.
+ \value AlignVCenter Centers vertically in the available space.
+
+ You can use only one of the horizontal flags at a time. There is
+ one two-dimensional flag:
+
+ \value AlignCenter Centers in both dimensions.
+
+ You can use at most one horizontal and one vertical flag at a time. \c
+ AlignCenter counts as both horizontal and vertical.
+
+ Masks:
+
+ \value AlignHorizontal_Mask
+ \value AlignVertical_Mask
+
+ Conflicting combinations of flags have undefined meanings.
+*/
+
+/*!
+ \enum TQt::TextFlags
+
+ This enum type is used to define some modifier flags. Some of
+ these flags only make sense in the context of printing:
+
+ \value SingleLine Treats all whitespace as spaces and prints just
+ one line.
+ \value DontClip If it's impossible to stay within the given bounds,
+ it prints outside.
+ \value ExpandTabs Makes the U+0009 (ASCII tab) character move to
+ the next tab stop.
+ \value ShowPrefix Displays the string "\&P" as <u>P</u>
+ (see TQButton for an example). For an ampersand, use "\&\&".
+ \value WordBreak Breaks lines at appropriate points, e.g. at word
+ boundaries.
+ \value BreakAnywhere Breaks lines anywhere, even within words.
+ \value NoAccel Same as ShowPrefix but doesn't draw the underlines.
+
+ You can use as many modifier flags as you want, except that \c
+ SingleLine and \c WordBreak cannot be combined.
+
+ Flags that are inappropriate for a given use (e.g. ShowPrefix to
+ TQGridLayout::addWidget()) are generally ignored.
+
+*/
+
+/*!
+ \enum TQt::PenStyle
+
+ This enum type defines the pen styles that can be drawn using
+ TQPainter. The styles are
+
+ \value NoPen no line at all. For example, TQPainter::drawRect()
+ fills but does not draw any boundary line.
+
+ \value SolidLine a simple line.
+
+ \value DashLine dashes separated by a few pixels.
+
+ \value DotLine dots separated by a few pixels.
+
+ \value DashDotLine alternate dots and dashes.
+
+ \value DashDotDotLine one dash, two dots, one dash, two dots.
+
+ \value MPenStyle tqmask of the pen styles.
+
+ \img pen-styles.png Pen Styles
+*/
+
+/*!
+ \enum TQt::PenCapStyle
+
+ This enum type defines the pen cap styles supported by TQt, i.e.
+ the line end caps that can be drawn using TQPainter.
+
+ \value FlatCap a square line end that does not cover the end
+ point of the line.
+ \value SquareCap a square line end that covers the end point and
+ extends beyond it with half the line width.
+ \value RoundCap a rounded line end.
+ \value MPenCapStyle tqmask of the pen cap styles.
+
+ \img pen-cap-styles.png Pen Cap Styles
+*/
+
+/*!
+ \enum TQt::PenJoinStyle
+
+ This enum type defines the pen join styles supported by TQt, i.e.
+ which joins between two connected lines can be drawn using
+ TQPainter.
+
+ \value MiterJoin The outer edges of the lines are extended to
+ meet at an angle, and this area is filled.
+ \value BevelJoin The triangular notch between the two lines is filled.
+ \value RoundJoin A circular arc between the two lines is filled.
+ \value MPenJoinStyle tqmask of the pen join styles.
+
+ \img pen-join-styles.png Pen Join Styles
+*/
+
+/*!
+ \enum TQt::BGMode
+
+ Background mode
+
+ \value TransparentMode
+ \value OpaqueMode
+*/
+
+/*!
+ Constructs a painter.
+
+ Notice that all painter settings (setPen, setBrush etc.) are reset
+ to default values when begin() is called.
+
+ \sa begin(), end()
+*/
+
+TQPainter::TQPainter()
+{
+ init();
+}
+
+
+/*!
+ Constructs a painter that begins painting the paint tqdevice \a pd
+ immediately. Depending on the underlying graphic system the
+ painter will paint over tqchildren of the painttqdevice if \a
+ unclipped is TRUE.
+
+ This constructor is convenient for short-lived painters, e.g. in a
+ \link TQWidget::paintEvent() paint event\endlink and should be used
+ only once. The constructor calls begin() for you and the TQPainter
+ destructor automatically calls end().
+
+ Here's an example using begin() and end():
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p;
+ p.begin( this );
+ p.drawLine( ... ); // drawing code
+ p.end();
+ }
+ \endcode
+
+ The same example using this constructor:
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p( this );
+ p.drawLine( ... ); // drawing code
+ }
+ \endcode
+
+ Since the constructor cannot provide feedback when the initialization
+ of the painter failed you should rather use begin() and end() to paint
+ on external tqdevices, e.g. printers.
+
+ \sa begin(), end()
+*/
+
+TQPainter::TQPainter( const TQPaintDevice *pd, bool unclipped )
+{
+ init();
+ if ( begin( pd, unclipped ) )
+ flags |= CtorBegin;
+}
+
+
+/*!
+ Constructs a painter that begins painting the paint tqdevice \a pd
+ immediately, with the default arguments taken from \a
+ copyAttributes. The painter will paint over tqchildren of the paint
+ tqdevice if \a unclipped is TRUE (although this is not supported on
+ all platforms).
+
+ \sa begin()
+*/
+
+TQPainter::TQPainter( const TQPaintDevice *pd,
+ const TQWidget *copyAttributes, bool unclipped )
+{
+ init();
+ if ( begin( pd, copyAttributes, unclipped ) )
+ flags |= CtorBegin;
+}
+
+
+/*!
+ Destroys the painter.
+*/
+
+TQPainter::~TQPainter()
+{
+ if ( isActive() )
+ end();
+ else
+ killPStack();
+ if ( tabarray ) // delete tab array
+ delete [] tabarray;
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( wm_stack )
+ delete (TQWMatrixStack *)wm_stack;
+#endif
+ destroy();
+}
+
+
+/*!
+ \overload bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped )
+
+ This version opens the painter on a paint tqdevice \a pd and sets
+ the initial pen, background color and font from \a copyAttributes,
+ painting over the paint tqdevice's tqchildren when \a unclipped is
+ TRUE. This is equivalent to:
+
+ \code
+ TQPainter p;
+ p.begin( pd );
+ p.setPen( copyAttributes->foregroundColor() );
+ p.setBackgroundColor( copyAttributes->backgroundColor() );
+ p.setFont( copyAttributes->font() );
+ \endcode
+
+ This begin function is convenient for double buffering. When you
+ draw in a pixmap instead of directly in a widget (to later bitBlt
+ the pixmap into the widget) you will need to set the widget's
+ font etc. This function does exactly that.
+
+ Example:
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPixmap pm(size());
+ TQPainter p;
+ p.begin(&pm, this);
+ // ... potentially flickering paint operation ...
+ p.end();
+ bitBlt(this, 0, 0, &pm);
+ }
+ \endcode
+
+ \sa end()
+*/
+
+bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped )
+{
+ if ( copyAttributes == 0 ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQPainter::begin: The widget to copy attributes from cannot "
+ "be null" );
+#endif
+ return FALSE;
+ }
+ if ( begin( pd, unclipped ) ) {
+ setPen( copyAttributes->foregroundColor() );
+ setBackgroundColor( copyAttributes->backgroundColor() );
+ setFont( copyAttributes->font() );
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+/*!
+ \internal
+ Sets or clears a pointer flag.
+*/
+
+void TQPainter::setf( uint b, bool v )
+{
+ if ( v )
+ setf( b );
+ else
+ clearf( b );
+}
+
+
+/*!
+ \fn bool TQPainter::isActive() const
+
+ Returns TRUE if the painter is active painting, i.e. begin() has
+ been called and end() has not yet been called; otherwise returns
+ FALSE.
+
+ \sa TQPaintDevice::paintingActive()
+*/
+
+/*!
+ \fn TQPaintDevice *TQPainter::tqdevice() const
+
+ Returns the paint tqdevice on which this painter is currently
+ painting, or 0 if the painter is not active.
+
+ \sa TQPaintDevice::paintingActive()
+*/
+
+
+struct TQPState { // painter state
+ TQFont font;
+ TQPen pen;
+ TQPoint curPt;
+ TQBrush brush;
+ TQColor bgc;
+ uchar bgm;
+ uchar rop;
+ TQPoint bro;
+ TQRect wr, vr;
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix wm;
+#else
+ int xlatex;
+ int xlatey;
+#endif
+ bool vxf;
+ bool wxf;
+ TQRegion rgn;
+ bool clip;
+ int ts;
+ int *ta;
+ void* wm_stack;
+};
+
+//TODO lose the worldmatrix stack
+
+typedef TQPtrStack<TQPState> TQPStateStack;
+
+
+void TQPainter::killPStack()
+{
+#if defined(TQT_CHECK_STATE)
+ if ( ps_stack && !((TQPStateStack *)ps_stack)->isEmpty() )
+ qWarning( "TQPainter::killPStack: non-empty save/restore stack when "
+ "end() was called" );
+#endif
+ delete (TQPStateStack *)ps_stack;
+ ps_stack = 0;
+}
+
+/*!
+ Saves the current painter state (pushes the state onto a stack). A
+ save() must be followed by a corresponding restore(). end()
+ unwinds the stack.
+
+ \sa restore()
+*/
+
+void TQPainter::save()
+{
+ if ( testf(ExtDev) ) {
+ if ( testf(DirtyFont) )
+ updateFont();
+ if ( testf(DirtyPen) )
+ updatePen();
+ if ( testf(DirtyBrush) )
+ updateBrush();
+ pdev->cmd( TQPaintDevice::PdcSave, this, 0 );
+ }
+ TQPStateStack *pss = (TQPStateStack *)ps_stack;
+ if ( pss == 0 ) {
+ pss = new TQPtrStack<TQPState>;
+ TQ_CHECK_PTR( pss );
+ pss->setAutoDelete( TRUE );
+ ps_stack = pss;
+ }
+ TQPState *ps = new TQPState;
+ TQ_CHECK_PTR( ps );
+ ps->font = cfont;
+ ps->pen = cpen;
+ ps->curPt = pos();
+ ps->brush = cbrush;
+ ps->bgc = bg_col;
+ ps->bgm = bg_mode;
+ ps->rop = rop;
+ ps->bro = bro;
+#ifndef TQT_NO_TRANSFORMATIONS
+ ps->wr = TQRect( wx, wy, ww, wh );
+ ps->vr = TQRect( vx, vy, vw, vh );
+ ps->wm = wxmat;
+ ps->vxf = testf(VxF);
+ ps->wxf = testf(WxF);
+#else
+ ps->xlatex = xlatex;
+ ps->xlatey = xlatey;
+#endif
+ ps->rgn = crgn;
+ ps->clip = testf(ClipOn);
+ ps->ts = tabstops;
+ ps->ta = tabarray;
+ ps->wm_stack = wm_stack;
+ wm_stack = 0;
+ pss->push( ps );
+}
+
+/*!
+ Restores the current painter state (pops a saved state off the
+ stack).
+
+ \sa save()
+*/
+
+void TQPainter::restore()
+{
+ if ( testf(ExtDev) ) {
+ pdev->cmd( TQPaintDevice::PdcRestore, this, 0 );
+ if ( pdev->devType() == TQInternal::Picture )
+ block_ext = TRUE;
+ }
+ TQPStateStack *pss = (TQPStateStack *)ps_stack;
+ if ( pss == 0 || pss->isEmpty() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::restore: Empty stack error" );
+#endif
+ return;
+ }
+ TQPState *ps = pss->pop();
+ bool hardRestore = testf(VolatileDC);
+
+ if ( ps->font != cfont || hardRestore )
+ setFont( ps->font );
+ if ( ps->pen != cpen || hardRestore )
+ setPen( ps->pen );
+ if ( ps->brush != cbrush || hardRestore )
+ setBrush( ps->brush );
+ if ( ps->bgc != bg_col || hardRestore )
+ setBackgroundColor( ps->bgc );
+ if ( ps->bgm != bg_mode || hardRestore )
+ setBackgroundMode( (BGMode)ps->bgm );
+ if ( ps->rop != rop || hardRestore )
+ setRasterOp( (RasterOp)ps->rop );
+ if ( ps->bro != bro || hardRestore )
+ setBrushOrigin( ps->bro );
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQRect wr( wx, wy, ww, wh );
+ TQRect vr( vx, vy, vw, vh );
+ if ( ps->wr != wr || hardRestore )
+ setWindow( ps->wr );
+ if ( ps->vr != vr || hardRestore )
+ setViewport( ps->vr );
+ if ( ps->wm != wxmat || hardRestore )
+ setWorldMatrix( ps->wm );
+ if ( ps->vxf != testf(VxF) || hardRestore )
+ setViewXForm( ps->vxf );
+ if ( ps->wxf != testf(WxF) || hardRestore )
+ setWorldXForm( ps->wxf );
+#else
+ xlatex = ps->xlatex;
+ xlatey = ps->xlatey;
+ setf( VxF, xlatex || xlatey );
+#endif
+ if ( ps->curPt != pos() || hardRestore )
+ moveTo( ps->curPt );
+ if ( ps->rgn != crgn || hardRestore )
+ setClipRegion( ps->rgn );
+ if ( ps->clip != testf(ClipOn) || hardRestore )
+ setClipping( ps->clip );
+ tabstops = ps->ts;
+ tabarray = ps->ta;
+
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( wm_stack )
+ delete (TQWMatrixStack *)wm_stack;
+ wm_stack = ps->wm_stack;
+#endif
+ delete ps;
+ block_ext = FALSE;
+}
+
+typedef TQPtrDict<TQPaintDevice> TQPaintDeviceDict;
+static TQPaintDeviceDict *pdev_dict = 0;
+
+/*!
+ Redirects all paint commands for a paint tqdevice, \a pdev, to
+ another paint tqdevice, \a tqreplacement, unless \a tqreplacement is 0.
+ If \a tqreplacement is 0, the redirection for \a pdev is removed.
+
+ In general, you'll probably tqfind calling TQPixmap::grabWidget() or
+ TQPixmap::grabWindow() is an easier solution.
+*/
+
+void TQPainter::redirect( TQPaintDevice *pdev, TQPaintDevice *tqreplacement )
+{
+ if ( pdev_dict == 0 ) {
+ if ( tqreplacement == 0 )
+ return;
+ pdev_dict = new TQPaintDeviceDict;
+ TQ_CHECK_PTR( pdev_dict );
+ }
+#if defined(TQT_CHECK_NULL)
+ if ( pdev == 0 )
+ qWarning( "TQPainter::redirect: The pdev argument cannot be 0" );
+#endif
+ if ( tqreplacement ) {
+ pdev_dict->insert( pdev, tqreplacement );
+ } else {
+ pdev_dict->remove( pdev );
+ if ( pdev_dict->count() == 0 ) {
+ delete pdev_dict;
+ pdev_dict = 0;
+ }
+ }
+}
+
+/*!
+ \internal
+ Returns the tqreplacement for \a pdev, or 0 if there is no tqreplacement.
+*/
+TQPaintDevice *TQPainter::redirect( TQPaintDevice *pdev )
+{
+ return pdev_dict ? pdev_dict->tqfind( pdev ) : 0;
+}
+
+/*!
+ Returns the font metrics for the painter, if the painter is
+ active. It is not possible to obtain metrics for an inactive
+ painter, so the return value is undefined if the painter is not
+ active.
+
+ \sa fontInfo(), isActive()
+*/
+
+TQFontMetrics TQPainter::fontMetrics() const
+{
+ if ( pdev && pdev->devType() == TQInternal::Picture )
+ return TQFontMetrics( cfont );
+
+ return TQFontMetrics(this);
+}
+
+/*!
+ Returns the font info for the painter, if the painter is active.
+ It is not possible to obtain font information for an inactive
+ painter, so the return value is undefined if the painter is not
+ active.
+
+ \sa fontMetrics(), isActive()
+*/
+
+TQFontInfo TQPainter::fontInfo() const
+{
+ if ( pdev && pdev->devType() == TQInternal::Picture )
+ return TQFontInfo( cfont );
+
+ return TQFontInfo(this);
+}
+
+
+/*!
+ \fn const TQPen &TQPainter::pen() const
+
+ Returns the painter's current pen.
+
+ \sa setPen()
+*/
+
+/*!
+ Sets a new painter pen.
+
+ The \a pen defines how to draw lines and outlines, and it also
+ defines the text color.
+
+ \sa pen()
+*/
+
+void TQPainter::setPen( const TQPen &pen )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setPen: Will be reset by begin()" );
+#endif
+ if ( cpen == pen )
+ return;
+ cpen = pen;
+ updatePen();
+}
+
+/*!
+ \overload
+
+ Sets the painter's pen to have style \a style, width 0 and black
+ color.
+
+ \sa pen(), TQPen
+*/
+
+void TQPainter::setPen( PenStyle style )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setPen: Will be reset by begin()" );
+#endif
+ TQPen::TQPenData *d = cpen.data; // low level access
+ if ( d->style == style && d->linest == style && !d->width && d->color == TQt::black )
+ return;
+ if ( d->count != 1 ) {
+ cpen.detach();
+ d = cpen.data;
+ }
+ d->style = style;
+ d->width = 0;
+ d->color = TQt::black;
+ d->linest = style;
+ updatePen();
+}
+
+/*!
+ \overload
+
+ Sets the painter's pen to have style \c SolidLine, width 0 and the
+ specified \a color.
+
+ \sa pen(), TQPen
+*/
+
+void TQPainter::setPen( const TQColor &color )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setPen: Will be reset by begin()" );
+#endif
+ TQPen::TQPenData *d = cpen.data; // low level access
+ if ( d->color == color && !d->width && d->style == SolidLine && d->linest == SolidLine )
+ return;
+ if ( d->count != 1 ) {
+ cpen.detach();
+ d = cpen.data;
+ }
+ d->style = SolidLine;
+ d->width = 0;
+ d->color = color;
+ d->linest = SolidLine;
+ updatePen();
+}
+
+/*!
+ \fn const TQBrush &TQPainter::brush() const
+
+ Returns the painter's current brush.
+
+ \sa TQPainter::setBrush()
+*/
+
+/*!
+ \overload
+
+ Sets the painter's brush to \a brush.
+
+ The \a brush defines how tqshapes are filled.
+
+ \sa brush()
+*/
+
+void TQPainter::setBrush( const TQBrush &brush )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setBrush: Will be reset by begin()" );
+#endif
+ if ( cbrush == brush )
+ return;
+ cbrush = brush;
+ updateBrush();
+}
+
+/*!
+ Sets the painter's brush to black color and the specified \a
+ style.
+
+ \sa brush(), TQBrush
+*/
+
+void TQPainter::setBrush( BrushStyle style )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setBrush: Will be reset by begin()" );
+#endif
+ TQBrush::TQBrushData *d = cbrush.data; // low level access
+ if ( d->style == style && d->color == TQt::black && !d->pixmap )
+ return;
+ if ( d->count != 1 ) {
+ cbrush.detach();
+ d = cbrush.data;
+ }
+ d->style = style;
+ d->color = TQt::black;
+ if ( d->pixmap ) {
+ delete d->pixmap;
+ d->pixmap = 0;
+ }
+ updateBrush();
+}
+
+/*!
+ \overload
+
+ Sets the painter's brush to have style \c SolidPattern and the
+ specified \a color.
+
+ \sa brush(), TQBrush
+*/
+
+void TQPainter::setBrush( const TQColor &color )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setBrush: Will be reset by begin()" );
+#endif
+ TQBrush::TQBrushData *d = cbrush.data; // low level access
+ if ( d->color == color && d->style == SolidPattern && !d->pixmap )
+ return;
+ if ( d->count != 1 ) {
+ cbrush.detach();
+ d = cbrush.data;
+ }
+ d->style = SolidPattern;
+ d->color = color;
+ if ( d->pixmap ) {
+ delete d->pixmap;
+ d->pixmap = 0;
+ }
+ updateBrush();
+}
+
+
+/*!
+ \fn const TQColor &TQPainter::backgroundColor() const
+
+ Returns the current background color.
+
+ \sa setBackgroundColor() TQColor
+*/
+
+/*!
+ \fn BGMode TQPainter::backgroundMode() const
+
+ Returns the current background mode.
+
+ \sa setBackgroundMode() BGMode
+*/
+
+/*!
+ \fn RasterOp TQPainter::rasterOp() const
+
+ Returns the current \link TQt::RasterOp raster operation \endlink.
+
+ \sa setRasterOp() RasterOp
+*/
+
+/*!
+ \fn const TQPoint &TQPainter::brushOrigin() const
+
+ Returns the brush origin currently set.
+
+ \sa setBrushOrigin()
+*/
+
+
+/*!
+ \fn int TQPainter::tabStops() const
+
+ Returns the tab stop setting.
+
+ \sa setTabStops()
+*/
+
+/*!
+ Set the tab stop width to \a ts, i.e. locates tab stops at \a ts,
+ 2*\a ts, 3*\a ts and so on.
+
+ Tab stops are used when drawing formatted text with \c ExpandTabs
+ set. This fixed tab stop value is used only if no tab array is set
+ (which is the default case).
+
+ A value of 0 (the default) implies a tabstop setting of 8 times the width of the
+ character 'x' in the font currently set on the painter.
+
+ \sa tabStops(), setTabArray(), drawText(), fontMetrics()
+*/
+
+void TQPainter::setTabStops( int ts )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setTabStops: Will be reset by begin()" );
+#endif
+ tabstops = ts;
+ if ( isActive() && testf(ExtDev) ) { // tell extended tqdevice
+ TQPDevCmdParam param[1];
+ param[0].ival = ts;
+ pdev->cmd( TQPaintDevice::PdcSetTabStops, this, param );
+ }
+}
+
+/*!
+ \fn int *TQPainter::tabArray() const
+
+ Returns the currently set tab stop array.
+
+ \sa setTabArray()
+*/
+
+/*!
+ Sets the tab stop array to \a ta. This puts tab stops at \a ta[0],
+ \a ta[1] and so on. The array is null-terminated.
+
+ If both a tab array and a tab top size is set, the tab array wins.
+
+ \sa tabArray(), setTabStops(), drawText(), fontMetrics()
+*/
+
+void TQPainter::setTabArray( int *ta )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setTabArray: Will be reset by begin()" );
+#endif
+ if ( ta != tabarray ) {
+ tabarraylen = 0;
+ if ( tabarray ) // Avoid purify complaint
+ delete [] tabarray; // delete old array
+ if ( ta ) { // tabarray = copy of 'ta'
+ while ( ta[tabarraylen] )
+ tabarraylen++;
+ tabarraylen++; // and 0 terminator
+ tabarray = new int[tabarraylen]; // duplicate ta
+ memcpy( tabarray, ta, sizeof(int)*tabarraylen );
+ } else {
+ tabarray = 0;
+ }
+ }
+ if ( isActive() && testf(ExtDev) ) { // tell extended tqdevice
+ TQPDevCmdParam param[2];
+ param[0].ival = tabarraylen;
+ param[1].ivec = tabarray;
+ pdev->cmd( TQPaintDevice::PdcSetTabArray, this, param );
+ }
+}
+
+
+/*!
+ \fn HANDLE TQPainter::handle() const
+
+ Returns the platform-dependent handle used for drawing. Using this
+ function is not portable.
+*/
+
+
+/*****************************************************************************
+ TQPainter xform settings
+ *****************************************************************************/
+
+#ifndef TQT_NO_TRANSFORMATIONS
+
+/*!
+ Enables view transformations if \a enable is TRUE, or disables
+ view transformations if \a enable is FALSE.
+
+ \sa hasViewXForm(), setWindow(), setViewport(), setWorldMatrix(),
+ setWorldXForm(), xForm()
+*/
+
+void TQPainter::setViewXForm( bool enable )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setViewXForm: Will be reset by begin()" );
+#endif
+ if ( !isActive() || enable == testf(VxF) )
+ return;
+ setf( VxF, enable );
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].ival = enable;
+ pdev->cmd( TQPaintDevice::PdcSetVXform, this, param );
+ }
+ updateXForm();
+}
+
+/*!
+ \fn bool TQPainter::hasViewXForm() const
+
+ Returns TRUE if view transformation is enabled; otherwise returns
+ FALSE.
+
+ \sa setViewXForm(), xForm()
+*/
+
+/*!
+ Returns the window rectangle.
+
+ \sa setWindow(), setViewXForm()
+*/
+
+TQRect TQPainter::window() const
+{
+ return TQRect( wx, wy, ww, wh );
+}
+
+/*!
+ Sets the window rectangle view transformation for the painter and
+ enables view transformation.
+
+ The window rectangle is part of the view transformation. The
+ window specifies the logical coordinate system and is specified by
+ the \a x, \a y, \a w width and \a h height parameters. Its sister,
+ the viewport(), specifies the tqdevice coordinate system.
+
+ The default window rectangle is the same as the tqdevice's
+ rectangle. See the \link coordsys.html Coordinate System Overview
+ \endlink for an overview of coordinate transformation.
+
+ \sa window(), setViewport(), setViewXForm(), setWorldMatrix(),
+ setWorldXForm()
+*/
+
+void TQPainter::setWindow( int x, int y, int w, int h )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setWindow: Will be reset by begin()" );
+#endif
+ wx = x;
+ wy = y;
+ ww = w;
+ wh = h;
+ if ( testf(ExtDev) ) {
+ TQRect r( x, y, w, h );
+ TQPDevCmdParam param[1];
+ param[0].rect = (TQRect*)&r;
+ pdev->cmd( TQPaintDevice::PdcSetWindow, this, param );
+ }
+ if ( testf(VxF) )
+ updateXForm();
+ else
+ setViewXForm( TRUE );
+}
+
+/*!
+ Returns the viewport rectangle.
+
+ \sa setViewport(), setViewXForm()
+*/
+
+TQRect TQPainter::viewport() const // get viewport
+{
+ return TQRect( vx, vy, vw, vh );
+}
+
+/*!
+ Sets the viewport rectangle view transformation for the painter
+ and enables view transformation.
+
+ The viewport rectangle is part of the view transformation. The
+ viewport specifies the tqdevice coordinate system and is specified
+ by the \a x, \a y, \a w width and \a h height parameters. Its
+ sister, the window(), specifies the logical coordinate system.
+
+ The default viewport rectangle is the same as the tqdevice's
+ rectangle. See the \link coordsys.html Coordinate System Overview
+ \endlink for an overview of coordinate transformation.
+
+ \sa viewport(), setWindow(), setViewXForm(), setWorldMatrix(),
+ setWorldXForm(), xForm()
+*/
+
+void TQPainter::setViewport( int x, int y, int w, int h )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setViewport: Will be reset by begin()" );
+#endif
+ vx = x;
+ vy = y;
+ vw = w;
+ vh = h;
+ if ( testf(ExtDev) ) {
+ TQRect r( x, y, w, h );
+ TQPDevCmdParam param[1];
+ param[0].rect = (TQRect*)&r;
+ pdev->cmd( TQPaintDevice::PdcSetViewport, this, param );
+ }
+ if ( testf(VxF) )
+ updateXForm();
+ else
+ setViewXForm( TRUE );
+}
+
+
+/*!
+ Enables world transformations if \a enable is TRUE, or disables
+ world transformations if \a enable is FALSE. The world
+ transformation matrix is not changed.
+
+ \sa setWorldMatrix(), setWindow(), setViewport(), setViewXForm(),
+ xForm()
+*/
+
+void TQPainter::setWorldXForm( bool enable )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setWorldXForm: Will be reset by begin()" );
+#endif
+ if ( !isActive() || enable == testf(WxF) )
+ return;
+ setf( WxF, enable );
+ if ( testf(ExtDev) && !block_ext ) {
+ TQPDevCmdParam param[1];
+ param[0].ival = enable;
+ pdev->cmd( TQPaintDevice::PdcSetWXform, this, param );
+ }
+ updateXForm();
+}
+
+/*!
+ \fn bool TQPainter::hasWorldXForm() const
+
+ Returns TRUE if world transformation is enabled; otherwise returns
+ FALSE.
+
+ \sa setWorldXForm()
+*/
+
+/*!
+ Returns the world transformation matrix.
+
+ \sa setWorldMatrix()
+*/
+
+const TQWMatrix &TQPainter::tqworldMatrix() const
+{
+ return wxmat;
+}
+
+/*!
+ Sets the world transformation matrix to \a m and enables world
+ transformation.
+
+ If \a combine is TRUE, then \a m is combined with the current
+ transformation matrix, otherwise \a m tqreplaces the current
+ transformation matrix.
+
+ If \a m is the identity matrix and \a combine is FALSE, this
+ function calls setWorldXForm(FALSE). (The identity matrix is the
+ matrix where TQWMatrix::m11() and TQWMatrix::m22() are 1.0 and the
+ rest are 0.0.)
+
+ World transformations are applied after the view transformations
+ (i.e. \link setWindow() window\endlink and \link setViewport()
+ viewport\endlink).
+
+ The following functions can transform the coordinate system without using
+ a TQWMatrix:
+ \list
+ \i translate()
+ \i scale()
+ \i shear()
+ \i rotate()
+ \endlist
+
+ They operate on the painter's tqworldMatrix() and are implemented like this:
+
+ \code
+ void TQPainter::rotate( double a )
+ {
+ TQWMatrix m;
+ m.rotate( a );
+ setWorldMatrix( m, TRUE );
+ }
+ \endcode
+
+ Note that you should always use \a combine when you are drawing
+ into a TQPicture. Otherwise it may not be possible to replay the
+ picture with additional transformations. Using translate(),
+ scale(), etc., is safe.
+
+ For a brief overview of coordinate transformation, see the \link
+ coordsys.html Coordinate System Overview. \endlink
+
+ \sa tqworldMatrix() setWorldXForm() setWindow() setViewport()
+ setViewXForm() xForm() TQWMatrix
+*/
+
+void TQPainter::setWorldMatrix( const TQWMatrix &m, bool combine )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setWorldMatrix: Will be reset by begin()" );
+#endif
+ return;
+ }
+ if ( combine )
+ wxmat = m * wxmat; // combines
+ else
+ wxmat = m; // set new matrix
+ bool identity = wxmat.m11() == 1.0F && wxmat.m22() == 1.0F &&
+ wxmat.m12() == 0.0F && wxmat.m21() == 0.0F &&
+ wxmat.dx() == 0.0F && wxmat.dy() == 0.0F;
+ if ( testf(ExtDev) && !block_ext ) {
+ TQPDevCmdParam param[2];
+ param[0].matrix = &m;
+ param[1].ival = combine;
+ pdev->cmd( TQPaintDevice::PdcSetWMatrix, this, param );
+ }
+ if ( identity && pdev->devType() != TQInternal::Picture )
+ setWorldXForm( FALSE );
+ else if ( !testf(WxF) )
+ setWorldXForm( TRUE );
+ else
+ updateXForm();
+}
+
+/*! \obsolete
+
+ We recommend using save() instead.
+*/
+
+void TQPainter::saveWorldMatrix()
+{
+ TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack;
+ if ( stack == 0 ) {
+ stack = new TQPtrStack<TQWMatrix>;
+ TQ_CHECK_PTR( stack );
+ stack->setAutoDelete( TRUE );
+ wm_stack = stack;
+ }
+
+ stack->push( new TQWMatrix( wxmat ) );
+
+}
+
+/*! \obsolete
+ We recommend using restore() instead.
+*/
+
+void TQPainter::restoreWorldMatrix()
+{
+ TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack;
+ if ( stack == 0 || stack->isEmpty() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::restoreWorldMatrix: Empty stack error" );
+#endif
+ return;
+ }
+ TQWMatrix* m = stack->pop();
+ setWorldMatrix( *m );
+ delete m;
+}
+
+#endif // TQT_NO_TRANSFORMATIONS
+
+/*!
+ Translates the coordinate system by \a (dx, dy). After this call,
+ \a (dx, dy) is added to points.
+
+ For example, the following code draws the same point twice:
+ \code
+ void MyWidget::paintEvent()
+ {
+ TQPainter paint( this );
+
+ paint.drawPoint( 0, 0 );
+
+ paint.translate( 100.0, 40.0 );
+ paint.drawPoint( -100, -40 );
+ }
+ \endcode
+
+ \sa scale(), shear(), rotate(), resetXForm(), setWorldMatrix(), xForm()
+*/
+
+void TQPainter::translate( double dx, double dy )
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix m;
+ m.translate( dx, dy );
+ setWorldMatrix( m, TRUE );
+#else
+ xlatex += (int)dx;
+ xlatey += (int)dy;
+ setf( VxF, xlatex || xlatey );
+#endif
+}
+
+
+#ifndef TQT_NO_TRANSFORMATIONS
+/*!
+ Scales the coordinate system by \a (sx, sy).
+
+ \sa translate(), shear(), rotate(), resetXForm(), setWorldMatrix(),
+ xForm()
+*/
+
+void TQPainter::scale( double sx, double sy )
+{
+ TQWMatrix m;
+ m.scale( sx, sy );
+ setWorldMatrix( m, TRUE );
+}
+
+/*!
+ Shears the coordinate system by \a (sh, sv).
+
+ \sa translate(), scale(), rotate(), resetXForm(), setWorldMatrix(),
+ xForm()
+*/
+
+void TQPainter::shear( double sh, double sv )
+{
+ TQWMatrix m;
+ m.shear( sv, sh );
+ setWorldMatrix( m, TRUE );
+}
+
+/*!
+ Rotates the coordinate system \a a degrees counterclockwise.
+
+ \sa translate(), scale(), shear(), resetXForm(), setWorldMatrix(),
+ xForm()
+*/
+
+void TQPainter::rotate( double a )
+{
+ TQWMatrix m;
+ m.rotate( a );
+ setWorldMatrix( m, TRUE );
+}
+
+
+/*!
+ Resets any transformations that were made using translate(), scale(),
+ shear(), rotate(), setWorldMatrix(), setViewport() and
+ setWindow().
+
+ \sa tqworldMatrix(), viewport(), window()
+*/
+
+void TQPainter::resetXForm()
+{
+ if ( !isActive() )
+ return;
+ wx = wy = vx = vy = 0; // default view origins
+ ww = vw = pdev->metric( TQPaintDeviceMetrics::PdmWidth );
+ wh = vh = pdev->metric( TQPaintDeviceMetrics::PdmHeight );
+ wxmat = TQWMatrix();
+ setWorldXForm( FALSE );
+ setViewXForm( FALSE );
+}
+
+/*!
+ \internal
+ Updates an internal integer transformation matrix.
+*/
+
+void TQPainter::updateXForm()
+{
+ TQWMatrix m;
+ if ( testf(VxF) ) {
+ double scaleW = (double)vw/(double)ww;
+ double scaleH = (double)vh/(double)wh;
+ m.setMatrix( scaleW, 0, 0, scaleH, vx - wx*scaleW, vy - wy*scaleH );
+ }
+ if ( testf(WxF) ) {
+ if ( testf(VxF) )
+ m = wxmat * m;
+ else
+ m = wxmat;
+ }
+ xmat = m;
+
+ txinv = FALSE; // no inverted matrix
+ txop = TxNone;
+ if ( m12()==0.0 && m21()==0.0 && m11() >= 0.0 && m22() >= 0.0 ) {
+ if ( m11()==1.0 && m22()==1.0 ) {
+ if ( dx()!=0.0 || dy()!=0.0 )
+ txop = TxTranslate;
+ } else {
+ txop = TxScale;
+#if defined(TQ_WS_WIN)
+ setf(DirtyFont);
+#endif
+ }
+ } else {
+ txop = TxRotShear;
+#if defined(TQ_WS_WIN)
+ setf(DirtyFont);
+#endif
+ }
+}
+
+
+/*!
+ \internal
+ Updates an internal integer inverse transformation matrix.
+*/
+
+void TQPainter::updateInvXForm()
+{
+#if defined(TQT_CHECK_STATE)
+ TQ_ASSERT( txinv == FALSE );
+#endif
+ txinv = TRUE; // creating inverted matrix
+ bool invertible;
+ TQWMatrix m;
+ if ( testf(VxF) ) {
+ m.translate( vx, vy );
+ m.scale( 1.0*vw/ww, 1.0*vh/wh );
+ m.translate( -wx, -wy );
+ }
+ if ( testf(WxF) ) {
+ if ( testf(VxF) )
+ m = wxmat * m;
+ else
+ m = wxmat;
+ }
+ ixmat = m.invert( &invertible ); // invert matrix
+}
+
+#else
+void TQPainter::resetXForm()
+{
+ xlatex = 0;
+ xlatey = 0;
+ clearf( VxF );
+}
+#endif // TQT_NO_TRANSFORMATIONS
+
+
+extern bool qt_old_transformations;
+
+/*!
+ \internal
+ Maps a point from logical coordinates to tqdevice coordinates.
+*/
+
+void TQPainter::map( int x, int y, int *rx, int *ry ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( qt_old_transformations ) {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x; *ry = y;
+ break;
+ case TxTranslate:
+ // #### "Why no rounding here?", Warwick asked of Haavard.
+ *rx = int(x + dx());
+ *ry = int(y + dy());
+ break;
+ case TxScale: {
+ double tx = m11()*x + dx();
+ double ty = m22()*y + dy();
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ } break;
+ default: {
+ double tx = m11()*x + m21()*y+dx();
+ double ty = m12()*x + m22()*y+dy();
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ } break;
+ }
+ } else {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x;
+ *ry = y;
+ break;
+ case TxTranslate:
+ *rx = tqRound( x + dx() );
+ *ry = tqRound( y + dy() );
+ break;
+ case TxScale:
+ *rx = tqRound( m11()*x + dx() );
+ *ry = tqRound( m22()*y + dy() );
+ break;
+ default:
+ *rx = tqRound( m11()*x + m21()*y+dx() );
+ *ry = tqRound( m12()*x + m22()*y+dy() );
+ break;
+ }
+ }
+#else
+ *rx = x + xlatex;
+ *ry = y + xlatey;
+#endif
+}
+
+/*!
+ \internal
+ Maps a rectangle from logical coordinates to tqdevice coordinates.
+ This internal function does not handle rotation and/or shear.
+*/
+
+void TQPainter::map( int x, int y, int w, int h,
+ int *rx, int *ry, int *rw, int *rh ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( qt_old_transformations ) {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x; *ry = y;
+ *rw = w; *rh = h;
+ break;
+ case TxTranslate:
+ // #### "Why no rounding here?", Warwick asked of Haavard.
+ *rx = int(x + dx());
+ *ry = int(y + dy());
+ *rw = w; *rh = h;
+ break;
+ case TxScale: {
+ double tx1 = m11()*x + dx();
+ double ty1 = m22()*y + dy();
+ double tx2 = m11()*(x + w - 1) + dx();
+ double ty2 = m22()*(y + h - 1) + dy();
+ *rx = tqRound( tx1 );
+ *ry = tqRound( ty1 );
+ *rw = tqRound( tx2 ) - *rx + 1;
+ *rh = tqRound( ty2 ) - *ry + 1;
+ } break;
+ default:
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::map: Internal error" );
+#endif
+ break;
+ }
+ } else {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x; *ry = y;
+ *rw = w; *rh = h;
+ break;
+ case TxTranslate:
+ *rx = tqRound(x + dx() );
+ *ry = tqRound(y + dy() );
+ *rw = w; *rh = h;
+ break;
+ case TxScale:
+ *rx = tqRound( m11()*x + dx() );
+ *ry = tqRound( m22()*y + dy() );
+ *rw = tqRound( m11()*w );
+ *rh = tqRound( m22()*h );
+ break;
+ default:
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::map: Internal error" );
+#endif
+ break;
+ }
+ }
+#else
+ *rx = x + xlatex;
+ *ry = y + xlatey;
+ *rw = w; *rh = h;
+#endif
+}
+
+/*!
+ \internal
+ Maps a point from tqdevice coordinates to logical coordinates.
+*/
+
+void TQPainter::mapInv( int x, int y, int *rx, int *ry ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+#if defined(TQT_CHECK_STATE)
+ if ( !txinv )
+ qWarning( "TQPainter::mapInv: Internal error" );
+#endif
+ if ( qt_old_transformations ) {
+ double tx = im11()*x + im21()*y+idx();
+ double ty = im12()*x + im22()*y+idy();
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ } else {
+ *rx = tqRound( im11()*x + im21()*y + idx() );
+ *ry = tqRound( im12()*x + im22()*y + idy() );
+ }
+#else
+ *rx = x - xlatex;
+ *ry = y - xlatey;
+#endif
+}
+
+/*!
+ \internal
+ Maps a rectangle from tqdevice coordinates to logical coordinates.
+ Cannot handle rotation and/or shear.
+*/
+
+void TQPainter::mapInv( int x, int y, int w, int h,
+ int *rx, int *ry, int *rw, int *rh ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+#if defined(TQT_CHECK_STATE)
+ if ( !txinv || txop == TxRotShear )
+ qWarning( "TQPainter::mapInv: Internal error" );
+#endif
+ if ( qt_old_transformations ) {
+ double tx = im11()*x + idx();
+ double ty = im22()*y + idy();
+ double tw = im11()*w;
+ double th = im22()*h;
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ *rw = tw >= 0 ? int(tw + 0.5) : int(tw - 0.5);
+ *rh = th >= 0 ? int(th + 0.5) : int(th - 0.5);
+ } else {
+ *rx = tqRound( im11()*x + idx() );
+ *ry = tqRound( im22()*y + idy() );
+ *rw = tqRound( im11()*w );
+ *rh = tqRound( im22()*h );
+ }
+#else
+ *rx = x - xlatex;
+ *ry = y - xlatey;
+ *rw = w;
+ *rh = h;
+#endif
+}
+
+
+/*!
+ Returns the point \a pv transformed from model coordinates to
+ tqdevice coordinates.
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPoint TQPainter::xForm( const TQPoint &pv ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return pv;
+ int x=pv.x(), y=pv.y();
+ map( x, y, &x, &y );
+ return TQPoint( x, y );
+#else
+ return TQPoint( pv.x()+xlatex, pv.y()+xlatey );
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the rectangle \a rv transformed from model coordinates to
+ tqdevice coordinates.
+
+ If world transformation is enabled and rotation or shearing has
+ been specified, then the bounding rectangle is returned.
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQRect TQPainter::xForm( const TQRect &rv ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return rv;
+ if ( txop == TxRotShear ) { // rotation/shear
+ return xmat.mapRect( rv );
+ }
+ // Just translation/scale
+ int x, y, w, h;
+ rv.rect( &x, &y, &w, &h );
+ map( x, y, w, h, &x, &y, &w, &h );
+ return TQRect( x, y, w, h );
+#else
+ return TQRect( rv.x()+xlatex, rv.y()+xlatey, rv.width(), rv.height() );
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the point array \a av transformed from model coordinates
+ to tqdevice coordinates.
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xForm( const TQPointArray &av ) const
+{
+ TQPointArray a = av;
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop != TxNone )
+ {
+ return xmat * av;
+ }
+#else
+ a.translate( xlatex, xlatey );
+#endif
+ return a;
+}
+
+/*!
+ \overload
+
+ Returns the point array \a av transformed from model coordinates
+ to tqdevice coordinates. The \a index is the first point in the
+ array and \a npoints denotes the number of points to be
+ transformed. If \a npoints is negative, all points from \a
+ av[index] until the last point in the array are transformed.
+
+ The returned point array consists of the number of points that
+ were transformed.
+
+ Example:
+ \code
+ TQPointArray a(10);
+ TQPointArray b;
+ b = painter.xForm(a, 2, 4); // b.size() == 4
+ b = painter.xForm(a, 2, -1); // b.size() == 8
+ \endcode
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xForm( const TQPointArray &av, int index,
+ int npoints ) const
+{
+ int lastPoint = npoints < 0 ? av.size() : index+npoints;
+ TQPointArray a( lastPoint-index );
+ memcpy( a.data(), av.data()+index, (lastPoint-index)*sizeof( TQPoint ) );
+#ifndef TQT_NO_TRANSFORMATIONS
+ return xmat*a;
+#else
+ a.translate( xlatex, xlatey );
+ return a;
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the point \a pd transformed from tqdevice coordinates to
+ model coordinates.
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPoint TQPainter::xFormDev( const TQPoint &pd ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return pd;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+#endif
+ int x=pd.x(), y=pd.y();
+ mapInv( x, y, &x, &y );
+ return TQPoint( x, y );
+}
+
+/*!
+ Returns the rectangle \a rd transformed from tqdevice coordinates to
+ model coordinates.
+
+ If world transformation is enabled and rotation or shearing is
+ used, then the bounding rectangle is returned.
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQRect TQPainter::xFormDev( const TQRect &rd ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return rd;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+ if ( txop == TxRotShear ) { // rotation/shear
+ return ixmat.mapRect( rd );
+ }
+#endif
+ // Just translation/scale
+ int x, y, w, h;
+ rd.rect( &x, &y, &w, &h );
+ mapInv( x, y, w, h, &x, &y, &w, &h );
+ return TQRect( x, y, w, h );
+}
+
+/*!
+ \overload
+
+ Returns the point array \a ad transformed from tqdevice coordinates
+ to model coordinates.
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xFormDev( const TQPointArray &ad ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return ad;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+ return ixmat * ad;
+#else
+ // ###
+ return ad;
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the point array \a ad transformed from tqdevice coordinates
+ to model coordinates. The \a index is the first point in the array
+ and \a npoints denotes the number of points to be transformed. If
+ \a npoints is negative, all points from \a ad[index] until the
+ last point in the array are transformed.
+
+ The returned point array consists of the number of points that
+ were transformed.
+
+ Example:
+ \code
+ TQPointArray a(10);
+ TQPointArray b;
+ b = painter.xFormDev(a, 1, 3); // b.size() == 3
+ b = painter.xFormDev(a, 1, -1); // b.size() == 9
+ \endcode
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xFormDev( const TQPointArray &ad, int index,
+ int npoints ) const
+{
+ int lastPoint = npoints < 0 ? ad.size() : index+npoints;
+ TQPointArray a( lastPoint-index );
+ memcpy( a.data(), ad.data()+index, (lastPoint-index)*sizeof( TQPoint ) );
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return a;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+ return ixmat * a;
+#else
+ // ###
+ return a;
+#endif
+}
+
+
+/*!
+ Fills the rectangle \a (x, y, w, h) with the \a brush.
+
+ You can specify a TQColor as \a brush, since there is a TQBrush
+ constructor that takes a TQColor argument and creates a solid
+ pattern brush.
+
+ \sa drawRect()
+*/
+
+void TQPainter::fillRect( int x, int y, int w, int h, const TQBrush &brush )
+{
+ TQPen oldPen = pen(); // save pen
+ TQBrush oldBrush = this->brush(); // save brush
+ setPen( NoPen );
+ setBrush( brush );
+ drawRect( x, y, w, h ); // draw filled rect
+ setBrush( oldBrush ); // restore brush
+ setPen( oldPen ); // restore pen
+}
+
+
+/*!
+ \overload void TQPainter::setBrushOrigin( const TQPoint &p )
+
+ Sets the brush origin to point \a p.
+*/
+
+/*!
+ \overload void TQPainter::setWindow( const TQRect &r )
+
+ Sets the painter's window to rectangle \a r.
+*/
+
+
+/*!
+ \overload void TQPainter::setViewport( const TQRect &r )
+
+ Sets the painter's viewport to rectangle \a r.
+*/
+
+
+/*!
+ \fn bool TQPainter::hasClipping() const
+
+ Returns TRUE if clipping has been set; otherwise returns FALSE.
+
+ \sa setClipping()
+*/
+
+/*!
+ Returns the currently set clip region. Note that the clip region
+ is given in physical tqdevice coordinates and \e not subject to any
+ \link coordsys.html coordinate transformation \endlink if \a m is
+ equal to \c CoordDevice (the default). If \a m equals \c
+ CoordPainter the returned region is in model coordinates.
+
+ \sa setClipRegion(), setClipRect(), setClipping() TQPainter::CoordinateMode
+*/
+TQRegion TQPainter::clipRegion( CoordinateMode m ) const
+{
+ // ### FIXME in 4.0:
+ // If the transformation mode is CoordPainter, we should transform the
+ // clip region with painter transformations.
+
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQRegion r;
+ if ( m == CoordDevice ) {
+ r = crgn;
+ } else {
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+
+ r = ixmat * crgn;
+ }
+ return r;
+#else
+ return crgn;
+#endif
+}
+
+/*!
+ \fn void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m)
+
+ Sets the clip region to the rectangle \a x, \a y, \a w, \a h and
+ enables clipping. The clip mode is set to \a m.
+
+ If \a m is \c CoordDevice (the default), the coordinates given for
+ the clip region are taken to be physical tqdevice coordinates and
+ are \e not subject to any \link coordsys.html coordinate
+ transformations\endlink. If \a m is \c CoordPainter, the
+ coordinates given for the clip region are taken to be model
+ coordinates.
+
+ \sa setClipRegion(), clipRegion(), setClipping() TQPainter::CoordinateMode
+*/
+
+/*!
+ \overload void TQPainter::drawPoint( const TQPoint &p )
+
+ Draws the point \a p.
+*/
+
+
+/*!
+ \overload void TQPainter::moveTo( const TQPoint &p )
+
+ Moves to the point \a p.
+*/
+
+/*!
+ \overload void TQPainter::lineTo( const TQPoint &p )
+
+ Draws a line to the point \a p.
+*/
+
+/*!
+ \overload void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 )
+
+ Draws a line from point \a p1 to point \a p2.
+*/
+
+/*!
+ \overload void TQPainter::drawRect( const TQRect &r )
+
+ Draws the rectangle \a r.
+*/
+
+/*!
+ \overload void TQPainter::drawWinFocusRect( const TQRect &r )
+
+ Draws rectangle \a r as a window focus rectangle.
+*/
+
+/*!
+ \overload void TQPainter::drawWinFocusRect( const TQRect &r, const TQColor &bgColor )
+
+ Draws rectangle \a r as a window focus rectangle using background
+ color \a bgColor.
+*/
+
+
+#if !defined(TQ_WS_X11) && !defined(TQ_WS_TQWS) && !defined(TQ_WS_MAC)
+// The doc and X implementation of this functions is in qpainter_x11.cpp
+void TQPainter::drawWinFocusRect( int, int, int, int,
+ bool, const TQColor & )
+{
+ // do nothing, only called from X11 specific functions
+}
+#endif
+
+
+/*!
+ \overload void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd )
+
+ Draws a rounded rectangle \a r, rounding to the x position \a xRnd
+ and the y position \a yRnd on each corner.
+*/
+
+/*!
+ \overload void TQPainter::drawEllipse( const TQRect &r )
+
+ Draws the ellipse that fits inside rectangle \a r.
+*/
+
+/*!
+ \overload void TQPainter::drawArc( const TQRect &r, int a, int alen )
+
+ Draws the arc that fits inside the rectangle \a r with start angle
+ \a a and arc length \a alen.
+*/
+
+/*!
+ \overload void TQPainter::drawPie( const TQRect &r, int a, int alen )
+
+ Draws a pie segment that fits inside the rectangle \a r with start
+ angle \a a and arc length \a alen.
+*/
+
+/*!
+ \overload void TQPainter::drawChord( const TQRect &r, int a, int alen )
+
+ Draws a chord that fits inside the rectangle \a r with start angle
+ \a a and arc length \a alen.
+*/
+
+/*!
+ \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm, const TQRect &sr )
+
+ Draws the rectangle \a sr of pixmap \a pm with its origin at point
+ \a p.
+*/
+
+/*!
+ \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm )
+
+ Draws the pixmap \a pm with its origin at point \a p.
+*/
+
+void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm )
+{
+ drawPixmap( p.x(), p.y(), pm, 0, 0, pm.width(), pm.height() );
+}
+
+#if !defined(TQT_NO_IMAGE_SMOOTHSCALE) || !defined(TQT_NO_PIXMAP_TRANSFORMATION)
+
+/*!
+ \overload
+
+ Draws the pixmap \a pm into the rectangle \a r. The pixmap is
+ scaled to fit the rectangle, if image and rectangle size disagree.
+*/
+void TQPainter::drawPixmap( const TQRect &r, const TQPixmap &pm )
+{
+ int rw = r.width();
+ int rh = r.height();
+ int iw= pm.width();
+ int ih = pm.height();
+ if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 )
+ return;
+ bool scale = ( rw != iw || rh != ih );
+ float scaleX = (float)rw/(float)iw;
+ float scaleY = (float)rh/(float)ih;
+ bool smooth = ( scaleX < 1.5 || scaleY < 1.5 );
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ param[0].rect = &r;
+ param[1].pixmap = &pm;
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hdc )
+ return;
+#elif defined(TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param );
+ return;
+#elif defined(TQ_WS_MAC)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !pdev->handle())
+ return;
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hd )
+ return;
+#endif
+ }
+
+ TQPixmap pixmap = pm;
+
+ if ( scale ) {
+#ifndef TQT_NO_IMAGE_SMOOTHSCALE
+# ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ if ( smooth )
+# endif
+ {
+ TQImage i = pm.convertToImage();
+ pixmap = TQPixmap( i.smoothScale( rw, rh ) );
+ }
+# ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ else
+# endif
+#endif
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ {
+ pixmap = pm.xForm( TQWMatrix( scaleX, 0, 0, scaleY, 0, 0 ) );
+ }
+#endif
+ }
+ drawPixmap( r.x(), r.y(), pixmap );
+}
+
+#endif
+
+/*!
+ \overload void TQPainter::drawImage( const TQPoint &, const TQImage &, const TQRect &sr, int conversionFlags = 0 );
+
+ Draws the rectangle \a sr from the image at the given point.
+*/
+
+/*
+ Draws at point \a p the \sr rect from image \a pm, using \a
+ conversionFlags if the image needs to be converted to a pixmap.
+ The default value for \a conversionFlags is 0; see
+ convertFromImage() for information about what other values do.
+
+ This function may convert \a image to a pixmap and then draw it, if
+ tqdevice() is a TQPixmap or a TQWidget, or else draw it directly, if
+ tqdevice() is a TQPrinter or TQPicture.
+*/
+
+/*!
+ Draws at (\a x, \a y) the \a sw by \a sh area of pixels from (\a
+ sx, \a sy) in \a image, using \a conversionFlags if the image
+ needs to be converted to a pixmap. The default value for \a
+ conversionFlags is 0; see convertFromImage() for information about
+ what other values do.
+
+ This function may convert \a image to a pixmap and then draw it,
+ if tqdevice() is a TQPixmap or a TQWidget, or else draw it directly,
+ if tqdevice() is a TQPrinter or TQPicture.
+
+ Currently alpha masks of the image are ignored when painting on a TQPrinter.
+
+ \sa drawPixmap() TQPixmap::convertFromImage()
+*/
+void TQPainter::drawImage( int x, int y, const TQImage & image,
+ int sx, int sy, int sw, int sh,
+ int conversionFlags )
+{
+#ifdef TQ_WS_TQWS
+ //### Hackish
+# ifndef TQT_NO_TRANSFORMATIONS
+ if ( !image.isNull() && gfx &&
+ (txop==TxNone||txop==TxTranslate) && !testf(ExtDev) )
+# else
+ if ( !image.isNull() && gfx && !testf(ExtDev) )
+# endif
+ {
+ if(sw<0)
+ sw=image.width();
+ if(sh<0)
+ sh=image.height();
+
+ TQImage image2 = qt_screen->mapToDevice( image );
+
+ // This is a bit dubious
+ if(image2.depth()==1) {
+ image2.setNumColors( 2 );
+ image2.setColor( 0, tqRgb(255,255,255) );
+ image2.setColor( 1, tqRgb(0,0,0) );
+ }
+ if ( image2.hasAlphaBuffer() )
+ gfx->setAlphaType(TQGfx::InlineAlpha);
+ else
+ gfx->setAlphaType(TQGfx::IgnoreAlpha);
+ gfx->setSource(&image2);
+ if ( testf(VxF|WxF) ) {
+ map( x, y, &x, &y );
+ }
+ gfx->blt(x,y,sw,sh,sx,sy);
+ return;
+ }
+#endif
+
+ if ( !isActive() || image.isNull() )
+ return;
+
+ // right/bottom
+ if ( sw < 0 )
+ sw = image.width() - sx;
+ if ( sh < 0 )
+ sh = image.height() - sy;
+
+ // Sanity-check clipping
+ if ( sx < 0 ) {
+ x -= sx;
+ sw += sx;
+ sx = 0;
+ }
+ if ( sw + sx > image.width() )
+ sw = image.width() - sx;
+ if ( sy < 0 ) {
+ y -= sy;
+ sh += sy;
+ sy = 0;
+ }
+ if ( sh + sy > image.height() )
+ sh = image.height() - sy;
+
+ if ( sw <= 0 || sh <= 0 )
+ return;
+
+ bool all = image.rect().intersect(TQRect(sx,sy,sw,sh)) == image.rect();
+ TQImage subimage = all ? image : image.copy(sx,sy,sw,sh);
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ TQRect r( x, y, subimage.width(), subimage.height() );
+ param[0].rect = &r;
+ param[1].image = &subimage;
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc )
+ return;
+#elif defined (TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawImage, this, param );
+ return;
+#elif defined(TQ_WS_MAC)
+ if(!pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() )
+ return;
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd )
+ return;
+#endif
+ }
+
+ TQPixmap pm;
+ pm.convertFromImage( subimage, conversionFlags );
+ drawPixmap( x, y, pm );
+}
+
+/*!
+ \overload void TQPainter::drawImage( const TQPoint &p, const TQImage &i, int conversion_flags )
+
+ Draws the image \a i at point \a p.
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a
+ conversion_flags to specify how you'd prefer this to happen.
+
+ \sa TQt::ImageConversionFlags
+*/
+void TQPainter::drawImage( const TQPoint & p, const TQImage & i,
+ int conversion_flags )
+{
+ drawImage(p, i, i.rect(), conversion_flags);
+}
+
+#if !defined(TQT_NO_IMAGE_TRANSFORMATION) || !defined(TQT_NO_IMAGE_SMOOTHSCALE)
+
+/*!
+ \overload
+
+ Draws the image \a i into the rectangle \a r. The image will be
+ scaled to fit the rectangle if image and rectangle dimensions
+ differ.
+*/
+void TQPainter::drawImage( const TQRect &r, const TQImage &i )
+{
+ int rw = r.width();
+ int rh = r.height();
+ int iw= i.width();
+ int ih = i.height();
+ if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 )
+ return;
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ param[0].rect = &r;
+ param[1].image = &i;
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc )
+ return;
+#elif defined(TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawImage, this, param );
+ return;
+#elif defined(TQ_WS_MAC)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() )
+ return;
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd )
+ return;
+#endif
+ }
+
+
+ bool scale = ( rw != iw || rh != ih );
+ float scaleX = (float)rw/(float)iw;
+ float scaleY = (float)rh/(float)ih;
+ bool smooth = ( scaleX < 1.5 || scaleY < 1.5 );
+
+ TQImage img = scale
+ ? (
+#if defined(TQT_NO_IMAGE_TRANSFORMATION)
+ i.smoothScale( rw, rh )
+#elif defined(TQT_NO_IMAGE_SMOOTHSCALE)
+ i.scale( rw, rh )
+#else
+ smooth ? i.smoothScale( rw, rh ) : i.scale( rw, rh )
+#endif
+ )
+ : i;
+
+ drawImage( r.x(), r.y(), img );
+}
+
+#endif
+
+
+void bitBlt( TQPaintDevice *dst, int dx, int dy,
+ const TQImage *src, int sx, int sy, int sw, int sh,
+ int conversion_flags )
+{
+ TQPixmap tmp;
+ if ( sx == 0 && sy == 0
+ && (sw<0 || sw==src->width()) && (sh<0 || sh==src->height()) )
+ {
+ tmp.convertFromImage( *src, conversion_flags );
+ } else {
+ tmp.convertFromImage( src->copy( sx, sy, sw, sh, conversion_flags),
+ conversion_flags );
+ }
+ bitBlt( dst, dx, dy, &tmp );
+}
+
+
+/*!
+ \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm, const TQPoint &sp )
+
+ Draws a tiled pixmap, \a pm, inside rectangle \a r with its origin
+ at point \a sp.
+*/
+
+/*!
+ \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm )
+
+ Draws a tiled pixmap, \a pm, inside rectangle \a r.
+*/
+
+/*!
+ \overload void TQPainter::fillRect( const TQRect &r, const TQBrush &brush )
+
+ Fills the rectangle \a r using brush \a brush.
+*/
+
+/*!
+ \fn void TQPainter::eraseRect( int x, int y, int w, int h )
+
+ Erases the area inside \a x, \a y, \a w, \a h. Equivalent to
+ \c{fillRect( x, y, w, h, backgroundColor() )}.
+*/
+
+/*!
+ \overload void TQPainter::eraseRect( const TQRect &r )
+
+ Erases the area inside the rectangle \a r.
+*/
+
+/*!
+ \fn TQPainter::drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto )
+
+ \overload
+
+ Draws the given text at position \a x, \a y. If \a len is -1 (the
+ default) all the text is drawn, otherwise the first \a len
+ characters are drawn. The text's direction is given by \a dir.
+
+ \sa TQPainter::TextDirection
+*/
+
+/*!
+ \fn void TQPainter::drawText( int x, int y, int w, int h, int flags,
+ const TQString&, int len = -1, TQRect *br=0,
+ TQTextParag **internal=0 )
+
+ \overload
+
+ Draws the given text within the rectangle starting at \a x, \a y,
+ with width \a w and height \a h. If \a len is -1 (the default) all
+ the text is drawn, otherwise the first \a len characters are
+ drawn. The text's flags that are given in the \a flags parameter
+ are \l{TQt::AlignmentFlags} and \l{TQt::TextFlags} OR'd together. \a
+ br (if not null) is set to the actual bounding rectangle of the
+ output. The \a internal parameter is for internal use only.
+*/
+
+/*!
+ \fn void TQPainter::drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto );
+
+ \overload
+
+ Draws the text at the given point.
+
+ \sa TQPainter::TextDirection
+*/
+
+/*
+ Draws the text in \a s at point \a p. If \a len is -1 the entire
+ string is drawn, otherwise just the first \a len characters. The
+ text's direction is specified by \a dir.
+*/
+
+
+/*!
+ \fn void TQPainter::drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto );
+
+ \overload
+
+ Draws the text from position \a pos, at point \a (x, y). If \a len is
+ -1 the entire string is drawn, otherwise just the first \a len
+ characters. The text's direction is specified by \a dir.
+*/
+
+/*!
+ \fn void TQPainter::drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto );
+
+ Draws the text from position \a pos, at point \a p. If \a len is
+ -1 the entire string is drawn, otherwise just the first \a len
+ characters. The text's direction is specified by \a dir.
+
+ Note that the meaning of \e y is not the same for the two
+ drawText() varieties. For overloads that take a simple \e x, \e y
+ pair (or a point), the \e y value is the text's baseline; for
+ overloads that take a rectangle, \e rect.y() is the top of the
+ rectangle and the text is aligned within that rectangle in
+ accordance with the tqalignment flags.
+
+ \sa TQPainter::TextDirection
+*/
+
+/*!
+ \fn void TQPainter::tqdrawTextItem(const TQPoint &, const TQTextItem &, int)
+ \internal
+*/
+
+static inline void fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ if ( *w < 0 ) {
+ *w = -*w + 2;
+ *x -= *w - 1;
+ }
+ if ( *h < 0 ) {
+ *h = -*h + 2;
+ *y -= *h - 1;
+ }
+}
+void TQPainter::fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ ::fix_neg_rect(x,y,w,h);
+}
+
+//
+// The drawText function takes two special parameters; 'internal' and 'brect'.
+//
+// The 'internal' parameter tqcontains a pointer to an array of encoded
+// information that keeps internal tqgeometry data.
+// If the drawText function is called repeatedly to display the same text,
+// it makes sense to calculate text width and linebreaks the first time,
+// and use these parameters later to print the text because we save a lot of
+// CPU time.
+// The 'internal' parameter will not be used if it is a null pointer.
+// The 'internal' parameter will be generated if it is not null, but points
+// to a null pointer, i.e. internal != 0 && *internal == 0.
+// The 'internal' parameter will be used if it tqcontains a non-null pointer.
+//
+// If the 'brect parameter is a non-null pointer, then the bounding rectangle
+// of the text will be returned in 'brect'.
+//
+
+/*!
+ \overload
+
+ Draws at most \a len characters from \a str in the rectangle \a r.
+
+ This function draws formatted text. The \a tf text format is
+ really of type \l TQt::AlignmentFlags and \l TQt::TextFlags OR'd
+ together.
+
+ Horizontal tqalignment defaults to AlignAuto and vertical tqalignment
+ defaults to AlignTop.
+
+ \a brect (if not null) is set to the actual bounding rectangle of
+ the output. \a internal is, yes, internal.
+
+ \sa boundingRect()
+*/
+
+void TQPainter::drawText( const TQRect &r, int tf,
+ const TQString& str, int len, TQRect *brect,
+ TQTextParag **internal )
+{
+ if ( !isActive() )
+ return;
+ if ( len < 0 )
+ len = str.length();
+ if ( len == 0 ) // empty string
+ return;
+
+ if ( testf(DirtyFont|ExtDev) ) {
+ if ( testf(DirtyFont) )
+ updateFont();
+ if ( testf(ExtDev) && (tf & DontPrint) == 0 ) {
+ TQPDevCmdParam param[3];
+ TQString newstr = str;
+ newstr.truncate( len );
+ param[0].rect = &r;
+ param[1].ival = tf;
+ param[2].str = &newstr;
+ if ( pdev->devType() != TQInternal::Printer ) {
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted,
+ this, param) ||
+ !hdc )
+ return; // TQPrinter wants PdcDrawText2
+#elif defined(TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, this, param);
+ return;
+#elif defined(TQ_WS_MAC)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, this, param) ||
+ !pdev->handle())
+ return; // TQPrinter wants PdcDrawText2
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted,
+ this, param) ||
+ !hd )
+ return; // TQPrinter wants PdcDrawText2
+#endif
+ }
+ }
+ }
+
+ qt_format_text(font(), r, tf, str, len, brect,
+ tabstops, tabarray, tabarraylen, internal, this);
+}
+
+//#define TQT_FORMAT_TEXT_DEBUG
+
+#define TQChar_linesep TQChar(0x2028U)
+
+void qt_format_text( const TQFont& font, const TQRect &_r,
+ int tf, const TQString& str, int len, TQRect *brect,
+ int tabstops, int* tabarray, int tabarraylen,
+ TQTextParag **, TQPainter* painter )
+{
+ // we need to copy r here to protect against the case (&r == brect).
+ TQRect r( _r );
+
+ bool dontclip = (tf & TQt::DontClip) == TQt::DontClip;
+ bool wordbreak = (tf & TQt::WordBreak) == TQt::WordBreak;
+ bool singleline = (tf & TQt::SingleLine) == TQt::SingleLine;
+ bool showprefix = (tf & TQt::ShowPrefix) == TQt::ShowPrefix;
+ bool noaccel = ( tf & TQt::NoAccel ) == TQt::NoAccel;
+
+ bool isRightToLeft = str.isRightToLeft();
+ if ( ( tf & TQt::AlignHorizontal_Mask ) == TQt::AlignAuto )
+ tf |= isRightToLeft ? TQt::AlignRight : TQt::AlignLeft;
+
+ bool expandtabs = ( (tf & TQt::ExpandTabs) &&
+ ( ( (tf & TQt::AlignLeft) && !isRightToLeft ) ||
+ ( (tf & TQt::AlignRight) && isRightToLeft ) ) );
+
+ if ( !painter )
+ tf |= TQt::DontPrint;
+
+ int maxUnderlines = 0;
+ int numUnderlines = 0;
+ int underlinePositionStack[32];
+ int *underlinePositions = underlinePositionStack;
+
+ TQFont fnt(painter ? (painter->pfont ? *painter->pfont : painter->cfont) : font);
+ TQFontMetrics fm( fnt );
+
+ TQString text = str;
+ // str.setLength() always does a deep copy, so the tqreplacement
+ // code below is safe.
+ text.setLength( len );
+ // compatible behaviour to the old implementation. Replace
+ // tabs by spaces
+ TQChar *chr = (TQChar*)text.tqunicode();
+ const TQChar *end = chr + len;
+ bool haveLineSep = FALSE;
+ while ( chr != end ) {
+ if ( *chr == '\r' || ( singleline && *chr == '\n' ) ) {
+ *chr = ' ';
+ } else if ( *chr == '\n' ) {
+ *chr = TQChar_linesep;
+ haveLineSep = TRUE;
+ } else if ( *chr == '&' ) {
+ ++maxUnderlines;
+ }
+ ++chr;
+ }
+ if ( !expandtabs ) {
+ chr = (TQChar*)text.tqunicode();
+ while ( chr != end ) {
+ if ( *chr == '\t' )
+ *chr = ' ';
+ ++chr;
+ }
+ } else if (!tabarraylen && !tabstops) {
+ tabstops = fm.width('x')*8;
+ }
+
+ if ( noaccel || showprefix ) {
+ if ( maxUnderlines > 32 )
+ underlinePositions = new int[maxUnderlines];
+ TQChar *cout = (TQChar*)text.tqunicode();
+ TQChar *cin = cout;
+ int l = len;
+ while ( l ) {
+ if ( *cin == '&' ) {
+ ++cin;
+ --l;
+ if ( !l )
+ break;
+ if ( *cin != '&' )
+ underlinePositions[numUnderlines++] = cout - text.tqunicode();
+ }
+ *cout = *cin;
+ ++cout;
+ ++cin;
+ --l;
+ }
+ uint newlen = cout - text.tqunicode();
+ if ( newlen != text.length())
+ text.setLength( newlen );
+ }
+
+ // no need to do extra work for underlines if we don't paint
+ if ( tf & TQt::DontPrint )
+ numUnderlines = 0;
+
+ int height = 0;
+ int left = r.width();
+ int right = 0;
+
+ TQTextLayout textLayout( text, fnt );
+ int rb = TQMAX( 0, -fm.minRightBearing() );
+ int lb = TQMAX( 0, -fm.minLeftBearing() );
+
+ if ( text.isEmpty() ) {
+ height = fm.height();
+ left = right = 0;
+ tf |= TQPainter::DontPrint;
+ } else {
+ textLayout.beginLayout((haveLineSep || expandtabs || wordbreak) ?
+ TQTextLayout::MultiLine :
+ (tf & TQt::DontPrint) ? TQTextLayout::NoBidi : TQTextLayout::SingleLine );
+
+ // break underline chars into items of their own
+ for( int i = 0; i < numUnderlines; i++ ) {
+ textLayout.setBoundary( underlinePositions[i] );
+ textLayout.setBoundary( underlinePositions[i]+1 );
+ }
+
+ int lineWidth = wordbreak ? TQMAX(0, r.width()-rb-lb) : INT_MAX;
+ if(!wordbreak)
+ tf |= TQt::IncludeTrailingSpaces;
+
+ int leading = fm.leading();
+ int asc = fm.ascent();
+ int desc = fm.descent();
+ height = -leading;
+
+ //qDebug("\n\nbeginLayout: lw = %d, rectwidth=%d", lineWidth , r.width());
+ while ( !textLayout.atEnd() ) {
+ height += leading;
+ textLayout.beginLine( lineWidth == INT_MAX ? lineWidth : lineWidth );
+ //qDebug("-----beginLine( %d )-----", lineWidth );
+ bool linesep = FALSE;
+ while ( 1 ) {
+ TQTextItem ti = textLayout.currentItem();
+ //qDebug("item: from=%d, ch=%x", ti.from(), text.tqunicode()[ti.from()].tqunicode() );
+ if ( expandtabs && ti.isTab() ) {
+ int tw = 0;
+ int x = textLayout.widthUsed();
+ if ( tabarraylen ) {
+// qDebug("tabarraylen=%d", tabarraylen );
+ int tab = 0;
+ while ( tab < tabarraylen ) {
+ if ( tabarray[tab] > x ) {
+ tw = tabarray[tab] - x;
+ break;
+ }
+ ++tab;
+ }
+ } else {
+ tw = tabstops - (x % tabstops);
+ }
+ //qDebug("tw = %d", tw );
+ if ( tw )
+ ti.setWidth( tw );
+ }
+ if ( ti.isObject() && text.tqunicode()[ti.from()] == TQChar_linesep )
+ linesep = TRUE;
+
+ if ( linesep || textLayout.addCurrentItem() != TQTextLayout::Ok || textLayout.atEnd() )
+ break;
+ }
+
+ int ascent = asc, descent = desc, lineLeft, lineRight;
+ textLayout.setLineWidth( r.width()-rb-lb );
+ textLayout.endLine( 0, height, tf, &ascent, &descent,
+ &lineLeft, &lineRight );
+ //qDebug("finalizing line: lw=%d ascent = %d, descent=%d lineleft=%d lineright=%d", lineWidth, ascent, descent,lineLeft, lineRight );
+ left = TQMIN( left, lineLeft );
+ right = TQMAX( right, lineRight );
+ height += ascent + descent + 1;
+ if ( linesep )
+ textLayout.nextItem();
+ }
+ }
+
+ int yoff = 0;
+ if ( tf & TQt::AlignBottom )
+ yoff = r.height() - height;
+ else if ( tf & TQt::AlignVCenter )
+ yoff = (r.height() - height)/2;
+
+ if ( brect ) {
+ *brect = TQRect( r.x() + left, r.y() + yoff, right-left + lb+rb, height );
+ //qDebug("br = %d %d %d/%d, left=%d, right=%d", brect->x(), brect->y(), brect->width(), brect->height(), left, right);
+ }
+
+ if (!(tf & TQPainter::DontPrint)) {
+ bool restoreClipping = FALSE;
+ bool painterHasClip = FALSE;
+ TQRegion painterClipRegion;
+ if ( !dontclip ) {
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQRegion reg = painter->xmat * r;
+#else
+ TQRegion reg = r;
+ reg.translate( painter->xlatex, painter->xlatey );
+#endif
+ if ( painter->hasClipping() )
+ reg &= painter->clipRegion();
+
+ painterHasClip = painter->hasClipping();
+ painterClipRegion = painter->clipRegion();
+ restoreClipping = TRUE;
+ painter->setClipRegion( reg );
+ } else {
+ if ( painter->hasClipping() ){
+ painterHasClip = painter->hasClipping();
+ painterClipRegion = painter->clipRegion();
+ restoreClipping = TRUE;
+ painter->setClipping( FALSE );
+ }
+ }
+
+ int cUlChar = 0;
+ int _tf = 0;
+ if (fnt.underline()) _tf |= TQt::Underline;
+ if (fnt.overline()) _tf |= TQt::Overline;
+ if (fnt.strikeOut()) _tf |= TQt::StrikeOut;
+
+ //qDebug("have %d items",textLayout.numItems());
+ for ( int i = 0; i < textLayout.numItems(); i++ ) {
+ TQTextItem ti = textLayout.itemAt( i );
+ //qDebug("Item %d: from=%d, length=%d, space=%d x=%d", i, ti.from(), ti.length(), ti.isSpace(), ti.x() );
+ if ( ti.isTab() || ti.isObject() )
+ continue;
+ int textFlags = _tf;
+ if ( !noaccel && numUnderlines > cUlChar && ti.from() == underlinePositions[cUlChar] ) {
+ textFlags |= TQt::Underline;
+ cUlChar++;
+ }
+#if defined(TQ_WS_X11) || defined(TQ_WS_TQWS)
+ if ( painter->bg_mode == TQt::OpaqueMode ) {
+ int h = ti.ascent() + ti.descent() + 1;
+ if (ti.y() + h < height)
+ // don't add leading to last line
+ h += fm.leading();
+ qt_draw_background( painter, r.x()+lb + ti.x(), r.y() + yoff + ti.y() - ti.ascent(),
+ ti.width(), h);
+ }
+#endif
+ painter->tqdrawTextItem( r.x()+lb, r.y() + yoff, ti, textFlags );
+ }
+
+ if ( restoreClipping ) {
+ painter->setClipRegion( painterClipRegion );
+ painter->setClipping( painterHasClip );
+ }
+ }
+
+ if ( underlinePositions != underlinePositionStack )
+ delete [] underlinePositions;
+}
+
+/*!
+ \overload
+
+ Returns the bounding rectangle of the aligned text that would be
+ printed with the corresponding drawText() function using the first
+ \a len characters from \a str if \a len is > -1, or the whole of
+ \a str if \a len is -1. The drawing, and hence the bounding
+ rectangle, is constrained to the rectangle \a r, or to the
+ rectangle required to draw the text, whichever is the larger.
+
+ The \a internal parameter should not be used.
+
+ \sa drawText(), fontMetrics(), TQFontMetrics::boundingRect(), TQt::TextFlags
+*/
+
+TQRect TQPainter::boundingRect( const TQRect &r, int flags,
+ const TQString& str, int len, TQTextParag **internal )
+{
+ TQRect brect;
+ if ( str.isEmpty() )
+ brect.setRect( r.x(),r.y(), 0,0 );
+ else
+ drawText( r, flags | DontPrint, str, len, &brect, internal );
+ return brect;
+}
+
+/*!
+ \fn TQRect TQPainter::boundingRect( int x, int y, int w, int h, int flags, const TQString&, int len = -1, TQTextParag **intern=0 );
+
+ Returns the bounding rectangle of the aligned text that would be
+ printed with the corresponding drawText() function using the first
+ \a len characters of the string if \a len is > -1, or the whole of
+ the string if \a len is -1. The drawing, and hence the bounding
+ rectangle, is constrained to the rectangle that begins at point \a
+ (x, y) with width \a w and hight \a h, or to the
+ rectangle required to draw the text, whichever is the larger.
+
+ The \a flags argument is
+ the bitwise OR of the following flags:
+ \table
+ \header \i Flag \i Meaning
+ \row \i \c AlignAuto \i aligns according to the language, usually left.
+ \row \i \c AlignLeft \i aligns to the left border.
+ \row \i \c AlignRight \i aligns to the right border.
+ \row \i \c AlignHCenter \i aligns horizontally centered.
+ \row \i \c AlignTop \i aligns to the top border.
+ \row \i \c AlignBottom \i aligns to the bottom border.
+ \row \i \c AlignVCenter \i aligns vertically centered.
+ \row \i \c AlignCenter \i (== \c AlignHCenter | \c AlignVCenter).
+ \row \i \c SingleLine \i ignores newline characters in the text.
+ \row \i \c ExpandTabs \i expands tabs.
+ \row \i \c ShowPrefix \i interprets "&x" as "<u>x</u>".
+ \row \i \c WordBreak \i breaks the text to fit the rectangle.
+ \endtable
+
+ Horizontal tqalignment defaults to \c AlignLeft and vertical
+ tqalignment defaults to \c AlignTop.
+
+ If several of the horizontal or several of the vertical tqalignment flags
+ are set, the resulting tqalignment is undefined.
+
+ The \a intern parameter should not be used.
+
+ \sa TQt::TextFlags
+*/
+
+
+
+/*****************************************************************************
+ TQPen member functions
+ *****************************************************************************/
+
+/*!
+ \class TQPen tqpen.h
+ \brief The TQPen class defines how a TQPainter should draw lines and outlines
+ of tqshapes.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+ \mainclass
+
+ A pen has a style, width, color, cap style and join style.
+
+ The pen style defines the line type. The default pen style is \c
+ TQt::SolidLine. Setting the style to \c NoPen tells the painter to
+ not draw lines or outlines.
+
+ When drawing 1 pixel wide diagonal lines you can either use a very
+ fast algorithm (specified by a line width of 0, which is the
+ default), or a slower but more accurate algorithm (specified by a
+ line width of 1). For horizontal and vertical lines a line width
+ of 0 is the same as a line width of 1. The cap and join style have
+ no effect on 0-width lines.
+
+ The pen color defines the color of lines and text. The default
+ line color is black. The TQColor documentation lists predefined
+ colors.
+
+ The cap style defines how the end points of lines are drawn. The
+ join style defines how the joins between two lines are drawn when
+ multiple connected lines are drawn (TQPainter::drawPolyline()
+ etc.). The cap and join styles only apply to wide lines, i.e. when
+ the width is 1 or greater.
+
+ Use the TQBrush class to specify fill styles.
+
+ Example:
+ \code
+ TQPainter painter;
+ TQPen pen( red, 2 ); // red solid line, 2 pixels wide
+ painter.begin( &anyPaintDevice ); // paint something
+ painter.setPen( pen ); // set the red, wide pen
+ painter.drawRect( 40,30, 200,100 ); // draw a rectangle
+ painter.setPen( blue ); // set blue pen, 0 pixel width
+ painter.drawLine( 40,30, 240,130 ); // draw a diagonal in rectangle
+ painter.end(); // painting done
+ \endcode
+
+ See the \l TQt::PenStyle enum type for a complete list of pen
+ styles.
+
+ With reference to the end points of lines, for wide (non-0-width)
+ pens it depends on the cap style whether the end point is drawn or
+ not. TQPainter will try to make sure that the end point is drawn
+ for 0-width pens, but this cannot be absolutely guaranteed because
+ the underlying drawing engine is free to use any (typically
+ accelerated) algorithm for drawing 0-width lines. On all tested
+ systems, however, the end point of at least all non-diagonal lines
+ are drawn.
+
+ A pen's color(), width(), style(), capStyle() and joinStyle() can
+ be set in the constructor or later with setColor(), setWidth(),
+ setStyle(), setCapStyle() and setJoinStyle(). Pens may also be
+ compared and streamed.
+
+ \img pen-styles.png Pen styles
+
+ \sa TQPainter, TQPainter::setPen()
+*/
+
+
+/*!
+ \internal
+ Initializes the pen.
+*/
+
+void TQPen::init( const TQColor &color, uint width, uint linestyle )
+{
+ data = new TQPenData;
+ TQ_CHECK_PTR( data );
+ data->style = (PenStyle)(linestyle & MPenStyle);
+ data->width = width;
+ data->color = color;
+ data->linest = linestyle;
+}
+
+/*!
+ Constructs a default black solid line pen with 0 width, which
+ renders lines 1 pixel wide (fast diagonals).
+*/
+
+TQPen::TQPen()
+{
+ init( TQt::black, 0, SolidLine ); // default pen
+}
+
+/*!
+ Constructs a black pen with 0 width (fast diagonals) and style \a
+ style.
+
+ \sa setStyle()
+*/
+
+TQPen::TQPen( PenStyle style )
+{
+ init( TQt::black, 0, style );
+}
+
+/*!
+ Constructs a pen with the specified \a color, \a width and \a
+ style.
+
+ \sa setWidth(), setStyle(), setColor()
+*/
+
+TQPen::TQPen( const TQColor &color, uint width, PenStyle style )
+{
+ init( color, width, style );
+}
+
+/*!
+ Constructs a pen with the specified color \a cl and width \a w.
+ The pen style is set to \a s, the pen cap style to \a c and the
+ pen join style to \a j.
+
+ A line width of 0 will produce a 1 pixel wide line using a fast
+ algorithm for diagonals. A line width of 1 will also produce a 1
+ pixel wide line, but uses a slower more accurate algorithm for
+ diagonals. For horizontal and vertical lines a line width of 0 is
+ the same as a line width of 1. The cap and join style have no
+ effect on 0-width lines.
+
+ \sa setWidth(), setStyle(), setColor()
+*/
+
+TQPen::TQPen( const TQColor &cl, uint w, PenStyle s, PenCapStyle c,
+ PenJoinStyle j )
+{
+ init( cl, w, s | c | j );
+}
+
+/*!
+ Constructs a pen that is a copy of \a p.
+*/
+
+TQPen::TQPen( const TQPen &p )
+{
+ data = p.data;
+ data->ref();
+}
+
+/*!
+ Destroys the pen.
+*/
+
+TQPen::~TQPen()
+{
+ if ( data->deref() )
+ delete data;
+}
+
+
+/*!
+ Detaches from shared pen data to make sure that this pen is the
+ only one referring the data.
+
+ If multiple pens share common data, this pen dereferences the data
+ and gets a copy of the data. Nothing is done if there is just a
+ single reference.
+*/
+
+void TQPen::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+}
+
+
+/*!
+ Assigns \a p to this pen and returns a reference to this pen.
+*/
+
+TQPen &TQPen::operator=( const TQPen &p )
+{
+ p.data->ref();
+ if ( data->deref() )
+ delete data;
+ data = p.data;
+ return *this;
+}
+
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the pen.
+*/
+
+TQPen TQPen::copy() const
+{
+ TQPen p( data->color, data->width, data->style, capStyle(), joinStyle() );
+ return p;
+}
+
+
+/*!
+ \fn PenStyle TQPen::style() const
+
+ Returns the pen style.
+
+ \sa setStyle()
+*/
+
+/*!
+ Sets the pen style to \a s.
+
+ See the \l TQt::PenStyle documentation for a list of all the
+ styles.
+
+ \warning On Mac OS X the style setting (other than \c NoPen and \c
+ SolidLine) have no effect as they are not implemented by the
+ underlying system.
+
+ \warning On Windows 95/98, the style setting (other than \c NoPen
+ and \c SolidLine) has no effect for lines with width greater than
+ 1.
+
+ \sa style()
+*/
+
+void TQPen::setStyle( PenStyle s )
+{
+ if ( data->style == s )
+ return;
+ detach();
+ data->style = s;
+ data->linest = (data->linest & ~MPenStyle) | s;
+}
+
+
+/*!
+ \fn uint TQPen::width() const
+
+ Returns the pen width.
+
+ \sa setWidth()
+*/
+
+/*!
+ Sets the pen width to \a w.
+
+ A line width of 0 will produce a 1 pixel wide line using a fast
+ algorithm for diagonals. A line width of 1 will also produce a 1
+ pixel wide line, but uses a slower more accurate algorithm for
+ diagonals. For horizontal and vertical lines a line width of 0 is
+ the same as a line width of 1. The cap and join style have no
+ effect on 0-width lines.
+
+ \sa width()
+*/
+
+void TQPen::setWidth( uint w )
+{
+ if ( data->width == w )
+ return;
+ detach();
+ data->width = w;
+}
+
+
+/*!
+ Returns the pen's cap style.
+
+ \sa setCapStyle()
+*/
+TQt::PenCapStyle TQPen::capStyle() const
+{
+ return (PenCapStyle)(data->linest & MPenCapStyle);
+}
+
+/*!
+ Sets the pen's cap style to \a c.
+
+ The default value is \c FlatCap. The cap style has no effect on
+ 0-width pens.
+
+ \img pen-cap-styles.png Pen Cap Styles
+
+ \warning On Windows 95/98 and Macintosh, the cap style setting has
+ no effect. Wide lines are rendered as if the cap style was \c
+ SquareCap.
+
+ \sa capStyle()
+*/
+
+void TQPen::setCapStyle( PenCapStyle c )
+{
+ if ( (data->linest & MPenCapStyle) == c )
+ return;
+ detach();
+ data->linest = (data->linest & ~MPenCapStyle) | c;
+}
+
+/*!
+ Returns the pen's join style.
+
+ \sa setJoinStyle()
+*/
+TQt::PenJoinStyle TQPen::joinStyle() const
+{
+ return (PenJoinStyle)(data->linest & MPenJoinStyle);
+}
+
+/*!
+ Sets the pen's join style to \a j.
+
+ The default value is \c MiterJoin. The join style has no effect on
+ 0-width pens.
+
+ \img pen-join-styles.png Pen Join Styles
+
+ \warning On Windows 95/98 and Macintosh, the join style setting
+ has no effect. Wide lines are rendered as if the join style was \c
+ BevelJoin.
+
+ \sa joinStyle()
+*/
+
+void TQPen::setJoinStyle( PenJoinStyle j )
+{
+ if ( (data->linest & MPenJoinStyle) == j )
+ return;
+ detach();
+ data->linest = (data->linest & ~MPenJoinStyle) | j;
+}
+
+/*!
+ \fn const TQColor &TQPen::color() const
+
+ Returns the pen color.
+
+ \sa setColor()
+*/
+
+/*!
+ Sets the pen color to \a c.
+
+ \sa color()
+*/
+
+void TQPen::setColor( const TQColor &c )
+{
+ detach();
+ data->color = c;
+}
+
+
+/*!
+ \fn bool TQPen::operator!=( const TQPen &p ) const
+
+ Returns TRUE if the pen is different from \a p; otherwise returns
+ FALSE.
+
+ Two pens are different if they have different styles, widths or
+ colors.
+
+ \sa operator==()
+*/
+
+/*!
+ Returns TRUE if the pen is equal to \a p; otherwise returns FALSE.
+
+ Two pens are equal if they have equal styles, widths and colors.
+
+ \sa operator!=()
+*/
+
+bool TQPen::operator==( const TQPen &p ) const
+{
+ return (p.data == data) || (p.data->linest == data->linest &&
+ p.data->width == data->width && p.data->color == data->color);
+}
+
+
+/*****************************************************************************
+ TQPen stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQPen
+
+ Writes the pen \a p to the stream \a s and returns a reference to
+ the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQPen &p )
+{
+ // ### width() should not be restricted to 8-bit values
+ if ( s.version() < 3 )
+ return s << (TQ_UINT8)p.style() << (TQ_UINT8)p.width() << p.color();
+ else
+ return s << (TQ_UINT8)( p.style() | p.capStyle() | p.joinStyle() )
+ << (TQ_UINT8)p.width() << p.color();
+}
+
+/*!
+ \relates TQPen
+
+ Reads a pen from the stream \a s into \a p and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQPen &p )
+{
+ TQ_UINT8 style, width;
+ TQColor color;
+ s >> style;
+ s >> width;
+ s >> color;
+ p = TQPen( color, (uint)width, (TQt::PenStyle)style ); // owl
+ return s;
+}
+#endif //TQT_NO_DATASTREAM
+
+/*****************************************************************************
+ TQBrush member functions
+ *****************************************************************************/
+
+/*!
+ \class TQBrush tqbrush.h
+
+ \brief The TQBrush class defines the fill pattern of tqshapes drawn by a TQPainter.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+
+ A brush has a style and a color. One of the brush styles is a
+ custom pattern, which is defined by a TQPixmap.
+
+ The brush style defines the fill pattern. The default brush style
+ is \c NoBrush (depending on how you construct a brush). This style
+ tells the painter to not fill tqshapes. The standard style for
+ filling is \c SolidPattern.
+
+ The brush color defines the color of the fill pattern. The TQColor
+ documentation lists the predefined colors.
+
+ Use the TQPen class for specifying line/outline styles.
+
+ Example:
+ \code
+ TQPainter painter;
+ TQBrush brush( yellow ); // yellow solid pattern
+ painter.begin( &anyPaintDevice ); // paint something
+ painter.setBrush( brush ); // set the yellow brush
+ painter.setPen( NoPen ); // do not draw outline
+ painter.drawRect( 40,30, 200,100 ); // draw filled rectangle
+ painter.setBrush( NoBrush ); // do not fill
+ painter.setPen( black ); // set black pen, 0 pixel width
+ painter.drawRect( 10,10, 30,20 ); // draw rectangle outline
+ painter.end(); // painting done
+ \endcode
+
+ See the setStyle() function for a complete list of brush styles.
+
+ \img brush-styles.png Brush Styles
+
+ \sa TQPainter, TQPainter::setBrush(), TQPainter::setBrushOrigin()
+*/
+
+inline TQPixmap *TQBrush::pixmap() const {
+ if (style() != Qt::TexturePattern)
+ return 0;
+ QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d.data());
+ QPixmap &pixmap = data->pixmap();
+ return pixmap.isNull() ? 0 : &pixmap;
+}
+
+/*!
+ \internal
+ Initializes the brush.
+*/
+
+void TQBrush::init( const TQColor &color, BrushStyle style )
+{
+ data = new TQBrushData;
+ TQ_CHECK_PTR( data );
+ data->style = style;
+ data->color = color;
+ data->pixmap = 0;
+}
+
+/*!
+ Constructs a default black brush with the style \c NoBrush (will
+ not fill tqshapes).
+*/
+
+TQBrush::TQBrush()
+{
+ static TQBrushData* defBrushData = 0;
+ if ( !defBrushData ) {
+ static TQSharedCleanupHandler<TQBrushData> defBrushCleanup;
+ defBrushData = new TQBrushData;
+ defBrushData->style = NoBrush;
+ defBrushData->color = TQt::black;
+ defBrushData->pixmap = 0;
+ defBrushCleanup.set( &defBrushData );
+ }
+ data = defBrushData;
+ data->ref();
+}
+
+/*!
+ Constructs a black brush with the style \a style.
+
+ \sa setStyle()
+*/
+
+TQBrush::TQBrush( BrushStyle style )
+{
+ init( TQt::black, style );
+}
+
+/*!
+ Constructs a brush with the color \a color and the style \a style.
+
+ \sa setColor(), setStyle()
+*/
+
+TQBrush::TQBrush( const TQColor &color, BrushStyle style )
+{
+ init( color, style );
+}
+
+/*!
+ Constructs a brush with the color \a color and a custom pattern
+ stored in \a pixmap.
+
+ The color will only have an effect for monochrome pixmaps, i.e.
+ for TQPixmap::depth() == 1.
+
+ Pixmap brushes are currently not supported when printing on X11.
+
+ \sa setColor(), setPixmap()
+*/
+
+TQBrush::TQBrush( const TQColor &color, const TQPixmap &pixmap )
+{
+ init( color, CustomPattern );
+ setPixmap( pixmap );
+}
+
+/*!
+ Constructs a brush that is a \link shclass.html shallow
+ copy\endlink of \a b.
+*/
+
+TQBrush::TQBrush( const TQBrush &b )
+{
+ data = b.data;
+ data->ref();
+}
+
+/*!
+ Destroys the brush.
+*/
+
+TQBrush::~TQBrush()
+{
+ if ( data->deref() ) {
+ delete data->pixmap;
+ delete data;
+ }
+}
+
+
+/*!
+ Detaches from shared brush data to make sure that this brush is
+ the only one referring the data.
+
+ If multiple brushes share common data, this brush dereferences the
+ data and gets a copy of the data. Nothing is done if there is just
+ a single reference.
+*/
+
+void TQBrush::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+}
+
+
+/*!
+ Assigns \a b to this brush and returns a reference to this brush.
+*/
+
+TQBrush &TQBrush::operator=( const TQBrush &b )
+{
+ b.data->ref(); // beware of b = b
+ if ( data->deref() ) {
+ delete data->pixmap;
+ delete data;
+ }
+ data = b.data;
+ return *this;
+}
+
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the brush.
+*/
+
+TQBrush TQBrush::copy() const
+{
+ if ( data->style == CustomPattern ) { // brush has pixmap
+ TQBrush b( data->color, *data->pixmap );
+ return b;
+ } else { // brush has std pattern
+ TQBrush b( data->color, data->style );
+ return b;
+ }
+}
+
+
+/*!
+ \fn BrushStyle TQBrush::style() const
+
+ Returns the brush style.
+
+ \sa setStyle()
+*/
+
+/*!
+ Sets the brush style to \a s.
+
+ The brush styles are:
+ \table
+ \header \i Pattern \i Meaning
+ \row \i NoBrush \i will not fill tqshapes (default).
+ \row \i SolidPattern \i solid (100%) fill pattern.
+ \row \i Dense1Pattern \i11 94% fill pattern.
+ \row \i Dense2Pattern \i11 88% fill pattern.
+ \row \i Dense3Pattern \i11 63% fill pattern.
+ \row \i Dense4Pattern \i11 50% fill pattern.
+ \row \i Dense5Pattern \i11 37% fill pattern.
+ \row \i Dense6Pattern \i11 12% fill pattern.
+ \row \i Dense7Pattern \i11 6% fill pattern.
+ \row \i HorPattern \i horizontal lines pattern.
+ \row \i VerPattern \i vertical lines pattern.
+ \row \i CrossPattern \i crossing lines pattern.
+ \row \i BDiagPattern \i diagonal lines (directed /) pattern.
+ \row \i FDiagPattern \i diagonal lines (directed \) pattern.
+ \row \i DiagCrossPattern \i diagonal crossing lines pattern.
+ \row \i CustomPattern \i set when a pixmap pattern is being used.
+ \endtable
+
+ On Windows, dense and custom patterns cannot be transtqparent.
+
+ See the \link #details Detailed Description\endlink for a picture
+ of all the styles.
+
+ \sa style()
+*/
+
+void TQBrush::setStyle( BrushStyle s ) // set brush style
+{
+ if ( data->style == s )
+ return;
+#if defined(TQT_CHECK_RANGE)
+ if ( s == CustomPattern )
+ qWarning( "TQBrush::setStyle: CustomPattern is for internal use" );
+#endif
+ detach();
+ data->style = s;
+}
+
+
+/*!
+ \fn const TQColor &TQBrush::color() const
+
+ Returns the brush color.
+
+ \sa setColor()
+*/
+
+/*!
+ Sets the brush color to \a c.
+
+ \sa color(), setStyle()
+*/
+
+void TQBrush::setColor( const TQColor &c )
+{
+ detach();
+ data->color = c;
+}
+
+
+/*!
+ \fn TQPixmap *TQBrush::pixmap() const
+
+ Returns a pointer to the custom brush pattern, or 0 if no custom
+ brush pattern has been set.
+
+ \sa setPixmap()
+*/
+
+/*!
+ Sets the brush pixmap to \a pixmap. The style is set to \c
+ CustomPattern.
+
+ The current brush color will only have an effect for monochrome
+ pixmaps, i.e. for TQPixmap::depth() == 1.
+
+ Pixmap brushes are currently not supported when printing on X11.
+
+ \sa pixmap(), color()
+*/
+
+void TQBrush::setPixmap( const TQPixmap &pixmap )
+{
+ detach();
+ if ( data->pixmap )
+ delete data->pixmap;
+ if ( pixmap.isNull() ) {
+ data->style = NoBrush;
+ data->pixmap = 0;
+ } else {
+ data->style = CustomPattern;
+ data->pixmap = new TQPixmap( pixmap );
+ if ( data->pixmap->optimization() == TQPixmap::MemoryOptim )
+ data->pixmap->setOptimization( TQPixmap::NormalOptim );
+ }
+}
+
+
+/*!
+ \fn bool TQBrush::operator!=( const TQBrush &b ) const
+
+ Returns TRUE if the brush is different from \a b; otherwise
+ returns FALSE.
+
+ Two brushes are different if they have different styles, colors or
+ pixmaps.
+
+ \sa operator==()
+*/
+
+/*!
+ Returns TRUE if the brush is equal to \a b; otherwise returns
+ FALSE.
+
+ Two brushes are equal if they have equal styles, colors and
+ pixmaps.
+
+ \sa operator!=()
+*/
+
+bool TQBrush::operator==( const TQBrush &b ) const
+{
+ return (b.data == data) || (b.data->style == data->style &&
+ b.data->color == data->color &&
+ b.data->pixmap == data->pixmap);
+}
+
+
+/*!
+ \fn inline double TQPainter::translationX() const
+ \internal
+*/
+
+/*!
+ \fn inline double TQPainter::translationY() const
+ \internal
+*/
+
+
+/*****************************************************************************
+ TQBrush stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQBrush
+
+ Writes the brush \a b to the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQBrush &b )
+{
+ s << (TQ_UINT8)b.style() << b.color();
+ if ( b.style() == TQt::CustomPattern )
+#ifndef TQT_NO_IMAGEIO
+ s << *b.pixmap();
+#else
+ qWarning("No Image Brush I/O");
+#endif
+ return s;
+}
+
+/*!
+ \relates TQBrush
+
+ Reads the brush \a b from the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQBrush &b )
+{
+ TQ_UINT8 style;
+ TQColor color;
+ s >> style;
+ s >> color;
+ if ( style == TQt::CustomPattern ) {
+#ifndef TQT_NO_IMAGEIO
+ TQPixmap pm;
+ s >> pm;
+ b = TQBrush( color, pm );
+#else
+ qWarning("No Image Brush I/O");
+#endif
+ }
+ else
+ b = TQBrush( color, (TQt::BrushStyle)style );
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqpainter.cpp~ b/tqtinterface/qt4/src/kernel/tqpainter.cpp~
new file mode 100644
index 0000000..44e7577
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpainter.cpp~
@@ -0,0 +1,5161 @@
+#include "tqpainter.h"
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqpainter.h"
+#include "tqimage.h"
+#include "Qt/qpaintengine.h"
+
+// #include <private/qpainter_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// TAKEN FROM QT4 qbrush.cpp
+// THIS BLOCK MAY NEED TO BE UPDATED FROM TIME TO TIME
+// BEGIN BLOCK
+struct QTexturedBrushData : public QBrushData
+{
+ QTexturedBrushData() {
+ m_has_pixmap_texture = false;
+ m_pixmap = 0;
+ }
+ ~QTexturedBrushData() {
+ delete m_pixmap;
+ }
+
+ void setPixmap(const QPixmap &pm) {
+ delete m_pixmap;
+
+ if (pm.isNull()) {
+ m_pixmap = 0;
+ m_has_pixmap_texture = false;
+ } else {
+ m_pixmap = new QPixmap(pm);
+ m_has_pixmap_texture = true;
+ }
+
+ m_image = QImage();
+ }
+
+ void setImage(const QImage &image) {
+ m_image = image;
+ delete m_pixmap;
+ m_pixmap = 0;
+ m_has_pixmap_texture = false;
+ }
+
+ QPixmap &pixmap() {
+ if (!m_pixmap) {
+ m_pixmap = new QPixmap(QPixmap::fromImage(m_image));
+ }
+ return *m_pixmap;
+ }
+
+ QImage &image() {
+ if (m_image.isNull() && m_pixmap)
+ m_image = m_pixmap->toImage();
+ return m_image;
+ }
+
+ QPixmap *m_pixmap;
+ QImage m_image;
+ bool m_has_pixmap_texture;
+};
+// END BLOCK
+
+/*!
+ \class TQPainter
+ \brief The TQPainter class is a Qt 3 compatibility wrapper for QPainter.
+
+ \compat
+
+ Prior to Qt 4, QPainter specialized the pen drawing for rectangle
+ based functions (in particular: drawRect, drawEllipse,
+ drawRoundRect, drawArc, drawChord and drawPie). When stroking a
+ rectangle of width 10, the pen would draw a rectangle of width 10.
+ Drawing a polygon defined by the corner points of the same
+ rectangle the stroke would have a width of 11.
+
+ The reason for this is best explained using the picture below:
+
+ \img q3painter_rationale.png
+
+ As we can see, stroking the rectangle so it gets a width of 10,
+ means the pen is drawn on a rectangle on width 9. The polygon,
+ however follows a consistent model.
+
+ In Qt 4, all rectangle based functions have changed to follow the
+ polygon approach, which means that the rectangle defines the size of
+ the fill, and the pen follows the edges of the shape. For pen widths
+ of 0 and 1 this means that the stroke will be inside the shape on the
+ left and the top and outside on the bottom and right.
+
+ The reason for the change in Qt 4 is so that we provide consistency
+ for all drawing functions even with complex transformations.
+*/
+
+TQPainter::TQPainter() : QPainter(), has_qwidget(FALSE), current_penpos(0,0) {
+}
+
+TQPainter::TQPainter( const QWidget *pdev, bool unclipped) : QPainter((QWidget*)pdev), has_qwidget(TRUE), current_penpos(0,0) {
+ qwidget_ptr = (QWidget*)pdev;
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+TQPainter::TQPainter( QPaintDevice *pdev, bool unclipped) : QPainter(pdev), has_qwidget(FALSE), current_penpos(0,0) {
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+TQPainter::TQPainter( QWidget *pdev, const QWidget *w, bool unclipped) : QPainter(pdev), has_qwidget(TRUE), current_penpos(0,0) {
+ qwidget_ptr = pdev;
+ initFrom(w);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+TQPainter::TQPainter( QPaintDevice *pdev, const QWidget *w, bool unclipped ) : QPainter(pdev), has_qwidget(FALSE), current_penpos(0,0) {
+ initFrom(w);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+}
+
+// [FIXME]
+void TQPainter::flush() {
+ printf("[WARNING] void TQPainter::flush() unimplemented\n\r");
+}
+
+// [FIXME]
+void TQPainter::flush( const TQRegion &region, TQPainter::CoordinateMode cm ) {
+ printf("[WARNING] void TQPainter::flush( const TQRegion &region, CoordinateMode cm = CoordDevice ) unimplemented\n\r");
+}
+
+void TQPainter::setBrush(const QBrush &brush) {
+ return QPainter::setBrush(brush);
+}
+
+void TQPainter::setBrush(Qt::BrushStyle style) {
+ return QPainter::setBrush(style);
+}
+
+void TQPainter::setBrush(TQt::BrushStyle style) {
+ this->QPainter::setBrush((Qt::BrushStyle)style);
+}
+
+TQPoint TQPainter::pos() const {
+ return current_penpos;
+}
+
+bool TQPainter::tqbegin( QPaintDevice *pdev, bool unclipped ) {
+ bool ret = begin(pdev);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+ return ret;
+}
+
+bool TQPainter::tqbegin( QPaintDevice *pdev, const QWidget *init, bool unclipped ) {
+ bool ret = begin(pdev);
+ initFrom(init);
+ if (unclipped) {
+ printf("[WARNING] Qt4 does not support drawing under child widgets in TQPainter via the unclipped==TRUE flag in any form! Blame Nokia and change your code...\n\r");
+ fflush(stdout);
+ }
+ return ret;
+}
+
+QRectF TQPainter::boundingRect(const QRectF &rect, int flags, const QString &text) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRectF tqbr = QPainter::boundingRect(rect, flags, text);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+QRect TQPainter::boundingRect(const QRect &rect, int flags, const QString &text) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRect tqbr = QPainter::boundingRect(rect, flags, text);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+QRect TQPainter::boundingRect(int x, int y, int w, int h, int flags, const QString &text) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRect tqbr = QPainter::boundingRect(x, y, w, h, flags, text);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+QRectF TQPainter::boundingRect(const QRectF &rect, const QString &text, const QTextOption &o) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ QRectF tqbr = QPainter::boundingRect(rect, text, o);
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+TQRect TQPainter::boundingRect(const QRect &rect, int flags, const QString &text, int len) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ TQRect tqbr = QPainter::boundingRect(rect, flags, text.left(len));
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+TQRect TQPainter::boundingRect(int x, int y, int w, int h, int flags, const QString &text, int len) {
+ TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ TQRect tqbr = QPainter::boundingRect(QRect(x, y, w, h), flags, text.left(len));
+ TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL
+ return tqbr;
+}
+
+void TQPainter::drawText(const QPointF &p, const QString &s) {
+ QPainter::drawText(p, s);
+}
+
+void TQPainter::drawText(const QPoint &p, const QString &s) {
+ QPainter::drawText(p, s);
+}
+
+void TQPainter::drawText(int x, int y, const QString &s) {
+ QPainter::drawText(x, y, s);
+}
+
+void TQPainter::drawText(const QPointF &p, const QString &str, int tf, int justificationPadding) {
+ QPainter::drawText(p, str, tf, justificationPadding);
+}
+
+void TQPainter::drawText(const QRectF &r, int flags, const QString &text, QRectF *br) {
+ QPainter::drawText(r, flags, text, br);
+}
+
+void TQPainter::drawText(const QRect &r, int flags, const QString &text, QRect *br) {
+ QPainter::drawText(r, flags, text, br);
+}
+
+void TQPainter::drawText(int x, int y, int w, int h, int flags, const QString &text, QRect *br) {
+ QPainter::drawText(x, y, w, h, flags, text, br);
+}
+
+void TQPainter::drawText(const QRectF &r, const QString &text, const QTextOption &o) {
+ QPainter::drawText(r, text, o);
+}
+
+void TQPainter::drawText( int x, int y, const TQString &s, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(x, y, s.left(len));
+ setLayoutDirection(old);
+}
+void TQPainter::drawText( const TQPoint &p, const TQString &s, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(p, s.left(len));
+ setLayoutDirection(old);
+}
+void TQPainter::drawText( int x, int y, const TQString &s, int pos, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(x, y, s.mid(pos, len));
+ setLayoutDirection(old);
+}
+void TQPainter::drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir ) {
+ Qt::LayoutDirection old = layoutDirection();
+ if (dir == RTL)
+ setLayoutDirection(Qt::RightToLeft);
+ else if (dir == LTR)
+ setLayoutDirection(Qt::LeftToRight);
+ QPainter::drawText(p, s.mid(pos, len));
+ setLayoutDirection(old);
+}
+
+void TQPainter::drawText(int x, int y, const QString &s, int pos, int len) {
+ drawText(x, y, s.mid(pos, len));
+}
+
+void TQPainter::drawText(const QPoint &p, const QString &s, int pos, int len) {
+ drawText(p, s.mid(pos, len));
+}
+
+void TQPainter::drawText(int x, int y, const QString &s, int len) {
+ drawText(x, y, s.left(len));
+}
+
+void TQPainter::drawText(const QPoint &p, const QString &s, int len) {
+ drawText(p, s.left(len));
+}
+
+void TQPainter::drawText(const QRect &r, int flags, const QString &str, int len, QRect *br) {
+ drawText(r, flags, str.left(len), br);
+}
+
+void TQPainter::drawText(int x, int y, int w, int h, int flags, const QString &text, int len, QRect *br) {
+ drawText(QRect(x, y, w, h), flags, text.left(len), br);
+}
+
+int *TQPainter::tabArray() const
+{
+ printf("[WARNING] TQPainter::tabArray unimplemented!\n\r");
+}
+
+void TQPainter::setTabArray( int *ta )
+{
+ printf("[WARNING] TQPainter::setTabArray unimplemented!\n\r");
+
+// #if defined(TQT_CHECK_STATE)
+// if ( !isActive() )
+// qWarning( "TQPainter::setTabArray: Will be reset by begin()" );
+// #endif
+// if ( ta != tabarray ) {
+// tabarraylen = 0;
+// if ( tabarray ) // Avoid purify complaint
+// delete [] tabarray; // delete old array
+// if ( ta ) { // tabarray = copy of 'ta'
+// while ( ta[tabarraylen] )
+// tabarraylen++;
+// tabarraylen++; // and 0 terminator
+// tabarray = new int[tabarraylen]; // duplicate ta
+// memcpy( tabarray, ta, sizeof(int)*tabarraylen );
+// } else {
+// tabarray = 0;
+// }
+// }
+// if ( isActive() && testf(ExtDev) ) { // tell extended tqdevice
+// TQPDevCmdParam param[2];
+// param[0].ival = tabarraylen;
+// param[1].ivec = tabarray;
+// pdev->cmd( TQPaintDevice::PdcSetTabArray, this, param );
+// }
+}
+
+void TQPainter::drawImage( int x, int y, const TQImage image, int sx, int sy, int sw, int sh, int conversionFlags ) {
+ QPainter::drawImage(x, y, image, sx, sy, sw, sh, (Qt::ImageConversionFlags)conversionFlags);
+}
+
+void TQPainter::drawImage( const TQPoint p, const TQImage image, const TQRect sr, int conversionFlags ) {
+ QPainter::drawImage(p, image, sr, (Qt::ImageConversionFlags)conversionFlags);
+}
+
+void TQPainter::drawImage( const TQPoint p, const TQImage image, int conversion_flags ) {
+ TQ_UNUSED(conversion_flags);
+ QPainter::drawImage(p, image);
+}
+
+void TQPainter::drawImage( const TQRect r, const TQImage image ) {
+ QPainter::drawImage(r, image);
+}
+
+void TQPainter::resetXForm() {
+ resetTransform();
+}
+
+// [FIXME] The drawWinFocusRect methods below probably need tweaking to exactly match the old Qt3 behaviour
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h ) {
+ drawWinFocusRect( x, y, w, h, TRUE, TQt::color0 );
+}
+
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h, const TQColor &bgColor ) {
+ drawWinFocusRect( x, y, w, h, FALSE, bgColor );
+}
+
+void TQPainter::drawWinFocusRect( const TQRect &tqr ) {
+ drawWinFocusRect( tqr.x(), tqr.y(), tqr.width(), tqr.height() );
+}
+
+void TQPainter::drawWinFocusRect( const TQRect &tqr, const TQColor &bgColor ) {
+ drawWinFocusRect( tqr.x(), tqr.y(), tqr.width(), tqr.height(), bgColor );
+}
+
+void TQPainter::setBackgroundColor(const QColor &color) {
+ setBackground(color);
+}
+
+const QColor &TQPainter::backgroundColor() const {
+ return background().color();
+}
+
+void TQPainter::setClipRect(const QRectF &qrf, Qt::ClipOperation op) {
+ QPainter::setClipRect(qrf, op);
+}
+
+void TQPainter::setClipRect(const QRect &qr, Qt::ClipOperation op) {
+ QPainter::setClipRect(qr, op);
+}
+
+void TQPainter::setClipRect( int x, int y, int w, int h, TQPainter::CoordinateMode cm ) {
+ TQRect r(x, y, w, h);
+ setClipRect(r, cm);
+}
+
+void TQPainter::redirect(QPaintDevice *pdev, QPaintDevice *replacement) {
+ if (replacement == 0) {
+ restoreRedirected(pdev);
+ }
+ else {
+ setRedirected(pdev, replacement);
+ }
+}
+
+TQPaintDevice *TQPainter::redirect(QPaintDevice *pdev) {
+ return static_cast<TQPaintDevice*>(const_cast<QPaintDevice*>(redirected(pdev)));
+}
+
+void TQPainter::setWorldXForm(bool enabled) {
+ setMatrixEnabled(enabled);
+}
+
+bool TQPainter::hasWorldXForm() const {
+ return matrixEnabled();
+}
+
+void TQPainter::setViewXForm(bool enabled) {
+ setViewTransformEnabled(enabled);
+}
+
+bool TQPainter::hasViewXForm() const {
+ return viewTransformEnabled();
+}
+
+// [FIXME]
+void TQPainter::initialize() {
+ printf("[WARNING] TQColor static void initialize() not implemented\n\r");
+}
+
+// [FIXME]
+void TQPainter::cleanup() {
+ printf("[WARNING] TQColor static void cleanup() not implemented\n\r");
+}
+
+void TQPainter::moveTo( const TQPoint &p )
+{
+ moveTo( p.x(), p.y() );
+}
+
+void TQPainter::lineTo( const TQPoint &p )
+{
+ lineTo( p.x(), p.y() );
+}
+
+void TQPainter::drawRect(const QRect &r)
+{
+ QPainter::drawRect(adjustedRectangle(r));
+}
+
+void TQPainter::drawEllipse(const QRect &r)
+{
+ QPainter::drawEllipse(adjustedRectangle(r));
+}
+
+void TQPainter::drawRoundRect(const QRect &r, int xrnd, int yrnd)
+{
+ QPainter::drawRoundRect(adjustedRectangle(r), xrnd, yrnd);
+}
+
+void TQPainter::drawArc(const QRect &r, int angle, int arcLength)
+{
+ QPainter::drawArc(adjustedRectangle(r), angle, arcLength);
+}
+
+void TQPainter::drawPie(const QRect &r, int angle, int arcLength)
+{
+ QPainter::drawPie(adjustedRectangle(r), angle, arcLength);
+}
+
+void TQPainter::drawChord(const QRect &r, int angle, int arcLength)
+{
+ QPainter::drawChord(adjustedRectangle(r), angle, arcLength);
+}
+
+void TQPainter::tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags )
+{
+ tqdrawTextItem( p.x(), p.y(), ti, textflags );
+}
+
+// [FIXME]
+// Verify these mappings...
+// They will need to be kept in sync with the code inside tqpainter_x11.cpp
+TQt::RasterOp TQPainter::rasterOp() const
+{
+ TQt::RasterOp cm;
+ switch (rop) {
+ case QPainter::CompositionMode_SourceOver:
+ cm=CopyROP;
+ break;
+ case QPainter::RasterOp_SourceOrDestination:
+ cm=OrROP;
+ break;
+ case QPainter::RasterOp_SourceXorDestination:
+ cm=XorROP;
+ break;
+ case QPainter::RasterOp_NotSourceAndDestination:
+ cm=NotAndROP;
+ break;
+ case QPainter::RasterOp_NotSource:
+ cm=NotCopyROP;
+ break;
+ case QPainter::RasterOp_NotSourceXorDestination:
+ cm=NotXorROP;
+ break;
+ case QPainter::RasterOp_SourceAndDestination:
+ cm=AndROP;
+ break;
+ case QPainter::CompositionMode_Clear:
+ cm=ClearROP;
+ break;
+ case QPainter::CompositionMode_Destination:
+ cm=NopROP;
+ break;
+ case QPainter::RasterOp_SourceAndNotDestination:
+ cm=AndNotROP;
+ break;
+ case QPainter::RasterOp_NotSourceOrNotDestination:
+ cm=NandROP;
+ break;
+ case QPainter::RasterOp_NotSourceAndNotDestination:
+ cm=NorROP;
+ break;
+ default:
+ cm=CopyROP;
+ break;
+ }
+ return cm;
+}
+
+/*!
+ \fn TQPainter::TQPainter()
+
+ Constructs a TQPainter.
+*/
+
+/*!
+ \fn TQPainter::TQPainter(QPaintDevice *pdev)
+
+ Constructs a TQPainter that operates on tqdevice \a pdev.
+*/
+
+/*!
+ \internal
+*/
+
+int TQPainter::rectSubtraction() const {
+ return pen().style() != Qt::NoPen && pen().width() == 0 ? 1 : 0;
+}
+
+/*!
+ \internal
+*/
+QRect TQPainter::adjustedRectangle(const QRect &r)
+{
+ QRect rect = r.normalized();
+ int subtract = rectSubtraction();
+ if (subtract != 0)
+ rect.setSize(QSize(rect.width() - subtract, rect.height() - subtract));
+ return rect;
+}
+
+
+/*!
+ \fn void TQPainter::drawRect(int x, int y, int w, int h)
+
+ \overload
+
+ Draws the rectangle that fits inside the bounds specified by \a x,
+ \a y, \a w and \a h using the current pen and brush.
+*/
+
+/*!
+ \fn void TQPainter::drawRect(const QRect &r)
+
+ Draws a rectangle that fits inside the rectangle \a r using the
+ current pen and brush.
+
+*/
+
+
+
+/*!
+ \fn TQPainter::drawEllipse(const QRect &r)
+
+ Draws the ellipse that fits inside the bounds \a r using the
+ current pen and brush.
+
+*/
+
+/*!
+ \fn TQPainter::drawEllipse(int x, int y, int width, int height)
+
+ \overload
+
+ Draws an ellipse that fits inside the bounds specified by \a x,
+ \a y, \a width and \a height using the current pen and brush.
+
+*/
+
+/*!
+ \fn void TQPainter::drawPie(int x, int y, int w, int h, int
+ startAngle, int spanAngle)
+
+ \overload
+
+ Draws a pie segment that fits inside the bounds (\a{x}, \a{y},
+ \a{w}, \a{h}) with the given \a startAngle and \a spanAngle.
+*/
+
+/*!
+ \fn void TQPainter::drawPie(const QRect &r, int a, int alen)
+
+ Draws a pie defined by the rectangle \a r, the start angle \a a
+ and the arc length \a alen.
+
+ The pie is filled with the current brush().
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ \sa drawArc(), drawChord()
+*/
+
+/*!
+ \fn void TQPainter::drawArc(int x, int y, int w, int h, int
+ startAngle, int spanAngle)
+
+ \overload
+
+ Draws the arc that fits inside the rectangle (\a{x}, \a{y}, \a{w},
+ \a{h}), with the given \a startAngle and \a spanAngle.
+*/
+
+/*!
+ \fn void TQPainter::drawArc(const QRect &r, int a, int alen)
+
+ Draws an arc defined by the rectangle \a r, the start angle \a a
+ and the arc length \a alen.
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ Example:
+ \snippet doc/src/snippets/code/src_qt3support_painting_q3painter.cpp 0
+
+ \sa drawPie(), drawChord()
+*/
+
+/*!
+ \fn void TQPainter::drawChord(int x, int y, int w, int h, int
+ startAngle, int spanAngle)
+
+ \overload
+
+ Draws a chord that fits inside the rectangle (\a{x}, \a{y}, \a{w},
+ \a{h}) with the given \a startAngle and \a spanAngle.
+*/
+
+
+/*!
+ \fn void TQPainter::drawChord(const QRect &r, int a, int alen)
+
+ Draws a chord defined by the rectangle \a r, the start angle \a a
+ and the arc length \a alen.
+
+ The chord is filled with the current brush().
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ \sa drawArc(), drawPie()
+*/
+
+/*!
+ \fn void TQPainter::drawRoundRect(const QRect &r, int xrnd, int yrnd)
+
+ Draws a rounded rect that fits into the bounds \a r using the current
+ pen and brush. The parameters \a xrnd and \a yrnd specifies the roundness
+ in x and y direction.
+*/
+
+/*!
+ \fn void TQPainter::drawRoundRect(int x, int y, int w, int h, int xrnd, int yrnd)
+
+ \overload
+
+ Draws a rounded rect that fits into the bounds \a x, \a y, \a w
+ and \a h using the current pen and brush. The parameters \a xrnd
+ and \a yrnd specifies the roundness in x and y direction.
+*/
+
+/*!
+ \fn void QPainter::drawLineSegments(const QPolygon &polygon, int
+ index, int count)
+
+ Draws \a count separate lines from points defined by the \a
+ polygon, starting at \a{polygon}\e{[index]} (\a index defaults to
+ 0). If \a count is -1 (the default) all points until the end of
+ the array are used.
+
+ Use drawLines() combined with QPolygon::constData() instead.
+
+ \oldcode
+ QPainter painter(this);
+ painter.drawLineSegments(polygon, index, count);
+ \newcode
+ int lineCount = (count == -1) ? (polygon.size() - index) / 2 : count;
+
+ QPainter painter(this);
+ painter.drawLines(polygon.constData() + index * 2, lineCount);
+ \endcode
+*/
+
+void TQPainter::drawLineSegments(const QPolygon &polygon, int index, int count)
+{
+ int lineCount = (count == -1) ? (polygon.size() - index) / 2 : count;
+
+ drawLines(polygon.constData() + index * 2, lineCount);
+}
+
+/*!
+ \obsolete
+
+ Use the worldTransform() combined with QTransform::dx() instead.
+
+ \oldcode
+ QPainter painter(this);
+ qreal x = painter.translationX();
+ \newcode
+ QPainter painter(this);
+ qreal x = painter.worldTransform().dx();
+ \endcode
+*/
+qreal TQPainter::translationX() const
+{
+ return worldTransform().dx();
+}
+
+/*!
+ \obsolete
+
+ Use the worldTransform() combined with QTransform::dy() instead.
+
+ \oldcode
+ QPainter painter(this);
+ qreal y = painter.translationY();
+ \newcode
+ QPainter painter(this);
+ qreal y = painter.worldTransform().dy();
+ \endcode
+*/
+qreal TQPainter::translationY() const
+{
+ return worldTransform().dy();
+}
+
+/*!
+ \fn void TQPainter::map(int x, int y, int *rx, int *ry) const
+
+ \internal
+
+ Sets (\a{rx}, \a{ry}) to the point that results from applying the
+ painter's current transformation on the point (\a{x}, \a{y}).
+*/
+void TQPainter::map(int x, int y, int *rx, int *ry) const
+{
+ QPoint p(x, y);
+ p = p * combinedMatrix();
+ *rx = p.x();
+ *ry = p.y();
+}
+
+/*!
+ \internal
+ Maps a rectangle from logical coordinates to device coordinates.
+ This internal function does not handle rotation and/or shear.
+*/
+
+void TQPainter::map( int x, int y, int w, int h, int *rx, int *ry, int *rw, int *rh ) const
+{
+ TQRect qr(x, y, w, h);
+ QTransform dtrans = combinedTransform();
+ TQRect tqr = dtrans.mapRect(qr);
+ *rx = tqr.x();
+ *ry = tqr.y();
+ *rw = tqr.width();
+ *rh = tqr.height();
+}
+
+/*!
+ \fn TQPoint TQPainter::xForm(const QPoint &point) const
+
+ Use combinedTransform() instead.
+*/
+
+TQPoint TQPainter::xForm(const QPoint &p) const
+{
+ if (combinedTransform().type() == QTransform::TxNone)
+ return p;
+ return p * combinedMatrix();
+}
+
+
+/*!
+ \fn TQRect TQPainter::xForm(const QRect &rectangle) const
+ \overload
+
+ Use combinedTransform() instead of this function and call
+ mapRect() on the result to obtain a QRect.
+*/
+
+TQRect TQPainter::xForm(const QRect &r) const
+{
+ if (combinedTransform().type() == QTransform::TxNone)
+ return r;
+ return combinedMatrix().mapRect(r);
+}
+
+bool TQPainter::testf( uint b ) const {
+// printf("[WARNING] QPainter::testf() disabled\n\r");
+// return 0;
+
+ // Map to Qt4 flags and functions...
+ if ((b&IsActive)!=0) {
+ if (QPainter::isActive()) return TRUE;
+ }
+// if ((b&ExtDev)!=0) {
+// printf("[WARNING] Assuming ExtDev==false in QPainter::testf()\n\r");
+// }
+// if ((b&IsStartingUp)!=0) {
+// }
+// if ((b&NoCache)!=0) {
+// }
+ if ((b&VxF)!=0) {
+ if (QPainter::viewTransformEnabled()) return TRUE;
+ }
+ if ((b&WxF)!=0) {
+ if (QPainter::worldMatrixEnabled()) return TRUE;
+ }
+ if ((b&ClipOn)!=0) {
+ if (QPainter::hasClipping()) return TRUE;
+ }
+
+ printf("[WARNING] Assuming test flag 0x%x == false in QPainter::testf()\n\r", b);
+ return 0;
+}
+
+/*!
+ \fn TQPolygon TQPainter::xForm(const QPolygon &polygon) const
+ \overload
+
+ Use combinedTransform() instead.
+*/
+
+// TQPolygon TQPainter::xForm(const QPolygon &a) const
+// {
+// Q_D(const QPainter);
+// if (!d->engine) {
+// qWarning("QPainter::xForm: Painter not active");
+// return QPolygon();
+// }
+// if (d->state->matrix.type() == QTransform::TxNone)
+// return a;
+// return a * combinedMatrix();
+// }
+
+/*!
+ \fn TQPolygon TQPainter::xForm(const QPolygon &polygon, int index, int count) const
+ \overload
+
+ Use combinedTransform() combined with QPolygon::mid() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPolygon transformed = painter.xForm(polygon, index, count)
+ \newcode
+ QPainter painter(this);
+ QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform();
+ \endcode
+*/
+
+// TQPolygon TQPainter::xForm(const QPolygon &av, int index, int npoints) const
+// {
+// int lastPoint = npoints < 0 ? av.size() : index+npoints;
+// QPolygon a(lastPoint-index);
+// memcpy(a.data(), av.data()+index, (lastPoint-index)*sizeof(QPoint));
+// return a * combinedMatrix();
+// }
+
+/*!
+ \fn TQPoint TQPainter::xFormDev(const QPoint &point) const
+ \overload
+ \obsolete
+
+ Use combinedTransform() combined with QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPoint transformed = painter.xFormDev(point);
+ \newcode
+ QPainter painter(this);
+ QPoint transformed = point * painter.combinedTransform().inverted();
+ \endcode
+*/
+
+TQPoint TQPainter::xFormDev(const QPoint &p) const
+{
+ if(combinedTransform().type() == QTransform::TxNone)
+ return p;
+ return p * combinedMatrix().inverted();
+}
+
+/*!
+ \fn TQRect TQPainter::xFormDev(const QRect &rectangle) const
+ \overload
+ \obsolete
+
+ Use combinedTransform() combined with QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QRect transformed = painter.xFormDev(rectangle);
+ \newcode
+ QPainter painter(this);
+ QRegion region = QRegion(rectangle) * painter.combinedTransform().inverted();
+ QRect transformed = region.boundingRect();
+ \endcode
+*/
+
+TQRect TQPainter::xFormDev(const QRect &r) const
+{
+ if (combinedTransform().type() == QTransform::TxNone)
+ return r;
+ return combinedMatrix().inverted().mapRect(r);
+}
+
+/*!
+ \overload
+
+ \fn TQPoint TQPainter::xFormDev(const QPolygon &polygon) const
+ \obsolete
+
+ Use combinedTransform() combined with QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPolygon transformed = painter.xFormDev(rectangle);
+ \newcode
+ QPainter painter(this);
+ QPolygon transformed = polygon * painter.combinedTransform().inverted();
+ \endcode
+*/
+
+// TQPolygon TQPainter::xFormDev(const QPolygon &a) const
+// {
+// Q_D(const QPainter);
+// if (!d->engine) {
+// qWarning("QPainter::xFormDev: Painter not active");
+// return QPolygon();
+// }
+// if (d->state->matrix.type() == QTransform::TxNone)
+// return a;
+// return a * combinedMatrix().inverted();
+// }
+
+/*!
+ \fn TQPolygon TQPainter::xFormDev(const QPolygon &polygon, int index, int count) const
+ \overload
+ \obsolete
+
+ Use combinedTransform() combined with QPolygon::mid() and QTransform::inverted() instead.
+
+ \oldcode
+ QPainter painter(this);
+ QPolygon transformed = painter.xFormDev(polygon, index, count);
+ \newcode
+ QPainter painter(this);
+ QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform().inverted();
+ \endcode
+*/
+
+// TQPolygon TQPainter::xFormDev(const QPolygon &ad, int index, int npoints) const
+// {
+// Q_D(const QPainter);
+// int lastPoint = npoints < 0 ? ad.size() : index+npoints;
+// QPolygon a(lastPoint-index);
+// memcpy(a.data(), ad.data()+index, (lastPoint-index)*sizeof(QPoint));
+// if (d->state->matrix.type() == QTransform::TxNone)
+// return a;
+// return a * combinedMatrix().inverted();
+// }
+
+/*! \obsolete
+ Sets the current pen position to \a (x, y)
+
+ \sa lineTo(), pos()
+*/
+
+void TQPainter::moveTo( int x, int y )
+{
+ QPainterPath path;
+ path.moveTo(x, y);
+ drawPath(path);
+ current_penpos = QPoint(x, y);
+}
+
+/*! \obsolete
+ Use drawLine() instead.
+
+ Draws a line from the current pen position to \a (x, y) and sets
+ \a (x, y) to be the new current pen position.
+
+ \sa TQPen moveTo(), drawLine(), pos()
+*/
+
+void TQPainter::lineTo( int x, int y )
+{
+ QPainterPath path;
+ path.moveTo(current_penpos.x(), current_penpos.y());
+ path.lineTo(x, y);
+ drawPath(path);
+ current_penpos = QPoint(x, y);
+}
+
+static void bitBlt_helper(QPaintDevice *dst, const QPoint &dp,
+ const QPaintDevice *src, const QRect &sr, bool)
+{
+ Q_ASSERT(dst);
+ Q_ASSERT(src);
+
+ if (src->devType() == QInternal::Pixmap) {
+ const QPixmap *pixmap = static_cast<const QPixmap *>(src);
+ QPainter pt(dst);
+ pt.drawPixmap(dp, *pixmap, sr);
+
+ } else {
+ qWarning("QPainter: bitBlt only works when source is of type pixmap");
+ }
+}
+
+void bitBlt(QPaintDevice *dst, int dx, int dy,
+ const QPaintDevice *src, int sx, int sy, int sw, int sh,
+ bool ignoreMask )
+{
+ bitBlt_helper(dst, QPoint(dx, dy), src, QRect(sx, sy, sw, sh), ignoreMask);
+}
+
+void bitBlt(QPaintDevice *dst, const QPoint &dp, const QPaintDevice *src, const QRect &sr, bool ignoreMask)
+{
+ bitBlt_helper(dst, dp, src, sr, ignoreMask);
+}
+
+void bitBlt(QPaintDevice *dst, int dx, int dy,
+ const QImage *src, int sx, int sy, int sw, int sh, int fl)
+{
+ Qt::ImageConversionFlags flags(fl);
+ QPixmap srcPixmap = QPixmap::fromImage(*src, flags);
+ bitBlt_helper(dst, QPoint(dx, dy), &srcPixmap, QRect(sx, sy, sw, sh), false);
+}
+
+const TQWMatrix &TQPainter::tqworldMatrix() const {
+ return (*(static_cast<const TQWMatrix*>(&worldMatrix())));
+}
+
+/*!
+ \fn void TQPainter::tqdrawTextItem(const TQPoint &, const TQTextItem &, int)
+ \internal
+*/
+
+static inline void fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ if ( *w < 0 ) {
+ *w = -*w + 2;
+ *x -= *w - 1;
+ }
+ if ( *h < 0 ) {
+ *h = -*h + 2;
+ *y -= *h - 1;
+ }
+}
+void TQPainter::fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ ::fix_neg_rect(x,y,w,h);
+}
+
+TQRegion TQPainter::clipRegion( CoordinateMode cm ) const {
+ QRegion qr = QPainter::clipRegion();
+ QRegion tqr = qr;
+ if (cm == CoordDevice) {
+ // Convert to device coordinates
+ QTransform dtrans = combinedTransform();
+ tqr = dtrans.map(qr);
+ }
+ return tqr;
+}
+
+void TQPainter::setClipRegion( const QRegion &qr, CoordinateMode cm ) {
+ QRegion tqr = qr;
+
+ if (cm == CoordDevice) {
+ // Convert from device coordinates
+ QTransform itrans = combinedTransform().inverted();
+ tqr = itrans.map(qr);
+
+ QPainter::setClipRegion( tqr, Qt::ReplaceClip );
+ }
+ else {
+ QPainter::setClipRegion( tqr, Qt::ReplaceClip );
+ }
+}
+
+void TQPainter::setClipRect( const TQRect &qr, CoordinateMode cm ) {
+ QRect tqr = qr;
+
+ if (cm == CoordDevice) {
+ // Convert from device coordinates
+ QTransform itrans = combinedTransform().inverted();
+ tqr = itrans.mapRect(qr);
+
+ QPainter::setClipRect( tqr, Qt::ReplaceClip );
+ }
+ else {
+ QPainter::setClipRect( tqr, Qt::ReplaceClip );
+ }
+}
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of TQPainter, TQPen and TQBrush classes
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpainter_p.h"
+#include "tqbitmap.h"
+#include "tqptrstack.h"
+#include "tqptrdict.h"
+#include "tqdatastream.h"
+#include "tqwidget.h"
+#include "tqimage.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqapplication.h"
+#include "tqrichtext_p.h"
+#include "tqregexp.h"
+#include "tqcleanuphandler.h"
+#ifdef TQ_WS_TQWS
+#include "tqgfx_qws.h"
+#endif
+#include <string.h>
+
+#include "tqtextlayout_p.h"
+#include "tqfontengine_p.h"
+
+#ifndef TQT_NO_TRANSFORMATIONS
+typedef TQPtrStack<TQWMatrix> TQWMatrixStack;
+#endif
+
+// POSIX Large File Support redefines truncate -> truncate64
+#if defined(truncate)
+# undef truncate
+#endif
+
+/*!
+ \class TQPainter tqpainter.h
+ \brief The TQPainter class does low-level painting e.g. on widgets.
+
+ \ingroup graphics
+ \ingroup images
+ \mainclass
+
+ The painter provides highly optimized functions to do most of the
+ drawing GUI programs require. TQPainter can draw everything from
+ simple lines to complex tqshapes like pies and chords. It can also
+ draw aligned text and pixmaps. Normally, it draws in a "natural"
+ coordinate system, but it can also do view and world
+ transformation.
+
+ The typical use of a painter is:
+
+ \list
+ \i Construct a painter.
+ \i Set a pen, a brush etc.
+ \i Draw.
+ \i Destroy the painter.
+ \endlist
+
+ Mostly, all this is done inside a paint event. (In fact, 99% of
+ all TQPainter use is in a reimplementation of
+ TQWidget::paintEvent(), and the painter is heavily optimized for
+ such use.) Here's one very simple example:
+
+ \code
+ void SimpleExampleWidget::paintEvent()
+ {
+ TQPainter paint( this );
+ paint.setPen( TQt::blue );
+ paint.drawText( rect(), AlignCenter, "The Text" );
+ }
+ \endcode
+
+ Usage is simple, and there are many settings you can use:
+
+ \list
+
+ \i font() is the currently set font. If you set a font that isn't
+ available, TQt tqfinds a close match. In fact font() returns what
+ you set using setFont() and fontInfo() returns the font actually
+ being used (which may be the same).
+
+ \i brush() is the currently set brush; the color or pattern that's
+ used for filling e.g. circles.
+
+ \i pen() is the currently set pen; the color or stipple that's
+ used for drawing lines or boundaries.
+
+ \i backgroundMode() is \c Opaque or \c Transtqparent, i.e. whether
+ backgroundColor() is used or not.
+
+ \i backgroundColor() only applies when backgroundMode() is Opaque
+ and pen() is a stipple. In that case, it describes the color of
+ the background pixels in the stipple.
+
+ \i rasterOp() is how pixels drawn interact with the pixels already
+ there.
+
+ \i brushOrigin() is the origin of the tiled brushes, normally the
+ origin of the window.
+
+ \i viewport(), window(), tqworldMatrix() and many more make up the
+ painter's coordinate transformation system. See \link
+ coordsys.html The Coordinate System \endlink for an explanation of
+ this, or see below for a very brief overview of the functions.
+
+ \i hasClipping() is whether the painter clips at all. (The paint
+ tqdevice clips, too.) If the painter clips, it clips to clipRegion().
+
+ \i pos() is the current position, set by moveTo() and used by
+ lineTo().
+
+ \endlist
+
+ Note that some of these settings mirror settings in some paint
+ tqdevices, e.g. TQWidget::font(). TQPainter::begin() (or the TQPainter
+ constructor) copies these attributes from the paint tqdevice.
+ Calling, for example, TQWidget::setFont() doesn't take effect until
+ the next time a painter begins painting on it.
+
+ save() saves all of these settings on an internal stack, restore()
+ pops them back.
+
+ The core functionality of TQPainter is drawing, and there are
+ functions to draw most primitives: drawPoint(), drawPoints(),
+ drawLine(), drawRect(), drawWinFocusRect(), drawRoundRect(),
+ drawEllipse(), drawArc(), drawPie(), drawChord(),
+ drawLineSegments(), drawPolyline(), drawPolygon(),
+ drawConvexPolygon() and drawCubicBezier(). All of these functions
+ take integer coordinates; there are no floating-point versions
+ since we want drawing to be as fast as possible.
+
+ There are functions to draw pixmaps/images, namely drawPixmap(),
+ drawImage() and drawTiledPixmap(). drawPixmap() and drawImage()
+ produce the same result, except that drawPixmap() is faster
+ on-screen and drawImage() faster and sometimes better on TQPrinter
+ and TQPicture.
+
+ Text drawing is done using drawText(), and when you need
+ fine-grained positioning, boundingRect() tells you where a given
+ drawText() command would draw.
+
+ There is a drawPicture() function that draws the contents of an
+ entire TQPicture using this painter. drawPicture() is the only
+ function that disregards all the painter's settings: the TQPicture
+ has its own settings.
+
+ Normally, the TQPainter operates on the tqdevice's own coordinate
+ system (usually pixels), but TQPainter has good support for
+ coordinate transformation. See \link coordsys.html The Coordinate
+ System \endlink for a more general overview and a simple example.
+
+ The most common functions used are scale(), rotate(), translate()
+ and shear(), all of which operate on the tqworldMatrix().
+ setWorldMatrix() can tqreplace or add to the currently set
+ tqworldMatrix().
+
+ setViewport() sets the rectangle on which TQPainter operates. The
+ default is the entire tqdevice, which is usually fine, except on
+ printers. setWindow() sets the coordinate system, that is, the
+ rectangle that maps to viewport(). What's drawn inside the
+ window() ends up being inside the viewport(). The window's
+ default is the same as the viewport, and if you don't use the
+ transformations, they are optimized away, gaining another little
+ bit of speed.
+
+ After all the coordinate transformation is done, TQPainter can clip
+ the drawing to an arbitrary rectangle or region. hasClipping() is
+ TRUE if TQPainter clips, and clipRegion() returns the clip region.
+ You can set it using either setClipRegion() or setClipRect().
+ Note that the clipping can be slow. It's all system-dependent,
+ but as a rule of thumb, you can assume that drawing speed is
+ inversely proportional to the number of rectangles in the clip
+ region.
+
+ After TQPainter's clipping, the paint tqdevice may also clip. For
+ example, most widgets clip away the pixels used by child widgets,
+ and most printers clip away an area near the edges of the paper.
+ This additional clipping is not reflected by the return value of
+ clipRegion() or hasClipping().
+
+ TQPainter also includes some less-used functions that are very
+ useful on those occasions when they're needed.
+
+ isActive() indicates whether the painter is active. begin() (and
+ the most usual constructor) makes it active. end() (and the
+ destructor) deactivates it. If the painter is active, tqdevice()
+ returns the paint tqdevice on which the painter paints.
+
+ Sometimes it is desirable to make someone else paint on an unusual
+ TQPaintDevice. TQPainter supports a static function to do this,
+ redirect(). We recommend not using it, but for some hacks it's
+ perfect.
+
+ setTabStops() and setTabArray() can change where the tab stops
+ are, but these are very seldomly used.
+
+ \warning Note that TQPainter does not attempt to work around
+ coordinate limitations in the underlying window system. Some
+ platforms may behave incorrectly with coordinates as small as
+ +/-4000.
+
+ \headerfile tqdrawutil.h
+
+ \sa TQPaintDevice TQWidget TQPixmap TQPrinter TQPicture
+ \link simple-application.html Application Walkthrough \endlink
+ \link coordsys.html Coordinate System Overview \endlink
+*/
+
+/*!
+ \fn TQGfx * TQPainter::internalGfx()
+
+ \internal
+*/
+
+/*!
+ \enum TQPainter::CoordinateMode
+ \value CoordDevice
+ \value CoordPainter
+
+ \sa clipRegion()
+*/
+/*!
+ \enum TQPainter::TextDirection
+ \value Auto
+ \value RTL right to left
+ \value LTR left to right
+
+ \sa drawText()
+*/
+
+/*!
+ \enum TQt::PaintUnit
+ \value PixelUnit
+ \value LoMetricUnit \e obsolete
+ \value HiMetricUnit \e obsolete
+ \value LoEnglishUnit \e obsolete
+ \value HiEnglishUnit \e obsolete
+ \value TwipsUnit \e obsolete
+*/
+
+/*!
+ \enum TQt::BrushStyle
+
+ \value NoBrush
+ \value SolidPattern
+ \value Dense1Pattern
+ \value Dense2Pattern
+ \value Dense3Pattern
+ \value Dense4Pattern
+ \value Dense5Pattern
+ \value Dense6Pattern
+ \value Dense7Pattern
+ \value HorPattern
+ \value VerPattern
+ \value CrossPattern
+ \value BDiagPattern
+ \value FDiagPattern
+ \value DiagCrossPattern
+ \value CustomPattern
+
+ \img brush-styles.png Brush Styles
+
+*/
+
+/*!
+ \enum TQt::RasterOp
+
+ This enum type is used to describe the way things are written to
+ the paint tqdevice. Each bit of the \e src (what you write)
+ interacts with the corresponding bit of the \e dst pixel.
+
+ \value CopyROP dst = src
+ \value OrROP dst = src OR dst
+ \value XorROP dst = src XOR dst
+ \value NotAndROP dst = (NOT src) AND dst
+ \value EraseROP an alias for \c NotAndROP
+ \value NotCopyROP dst = NOT src
+ \value NotOrROP dst = (NOT src) OR dst
+ \value NotXorROP dst = (NOT src) XOR dst
+ \value AndROP dst = src AND dst
+ \value NotEraseROP an alias for \c AndROP
+ \value NotROP dst = NOT dst
+ \value ClearROP dst = 0
+ \value SetROP dst = 1
+ \value NopROP dst = dst
+ \value AndNotROP dst = src AND (NOT dst)
+ \value OrNotROP dst = src OR (NOT dst)
+ \value NandROP dst = NOT (src AND dst)
+ \value NorROP dst = NOT (src OR dst)
+
+ By far the most useful ones are \c CopyROP and \c XorROP.
+
+ On TQt/Embedded, only \c CopyROP, \c XorROP, and \c NotROP are supported.
+*/
+
+/*!
+ \enum TQt::AlignmentFlags
+
+ This enum type is used to describe tqalignment. It tqcontains
+ horizontal and vertical flags.
+
+ The horizontal flags are:
+
+ \value AlignAuto Aligns according to the language. Left for most,
+ right for Arabic and Hebrew.
+ \value AlignLeft Aligns with the left edge.
+ \value AlignRight Aligns with the right edge.
+ \value AlignHCenter Centers horizontally in the available space.
+ \value AlignJustify Justifies the text in the available space.
+ Does not work for everything and may be interpreted as
+ AlignAuto in some cases.
+
+ The vertical flags are:
+
+ \value AlignTop Aligns with the top.
+ \value AlignBottom Aligns with the bottom.
+ \value AlignVCenter Centers vertically in the available space.
+
+ You can use only one of the horizontal flags at a time. There is
+ one two-dimensional flag:
+
+ \value AlignCenter Centers in both dimensions.
+
+ You can use at most one horizontal and one vertical flag at a time. \c
+ AlignCenter counts as both horizontal and vertical.
+
+ Masks:
+
+ \value AlignHorizontal_Mask
+ \value AlignVertical_Mask
+
+ Conflicting combinations of flags have undefined meanings.
+*/
+
+/*!
+ \enum TQt::TextFlags
+
+ This enum type is used to define some modifier flags. Some of
+ these flags only make sense in the context of printing:
+
+ \value SingleLine Treats all whitespace as spaces and prints just
+ one line.
+ \value DontClip If it's impossible to stay within the given bounds,
+ it prints outside.
+ \value ExpandTabs Makes the U+0009 (ASCII tab) character move to
+ the next tab stop.
+ \value ShowPrefix Displays the string "\&P" as <u>P</u>
+ (see TQButton for an example). For an ampersand, use "\&\&".
+ \value WordBreak Breaks lines at appropriate points, e.g. at word
+ boundaries.
+ \value BreakAnywhere Breaks lines anywhere, even within words.
+ \value NoAccel Same as ShowPrefix but doesn't draw the underlines.
+
+ You can use as many modifier flags as you want, except that \c
+ SingleLine and \c WordBreak cannot be combined.
+
+ Flags that are inappropriate for a given use (e.g. ShowPrefix to
+ TQGridLayout::addWidget()) are generally ignored.
+
+*/
+
+/*!
+ \enum TQt::PenStyle
+
+ This enum type defines the pen styles that can be drawn using
+ TQPainter. The styles are
+
+ \value NoPen no line at all. For example, TQPainter::drawRect()
+ fills but does not draw any boundary line.
+
+ \value SolidLine a simple line.
+
+ \value DashLine dashes separated by a few pixels.
+
+ \value DotLine dots separated by a few pixels.
+
+ \value DashDotLine alternate dots and dashes.
+
+ \value DashDotDotLine one dash, two dots, one dash, two dots.
+
+ \value MPenStyle tqmask of the pen styles.
+
+ \img pen-styles.png Pen Styles
+*/
+
+/*!
+ \enum TQt::PenCapStyle
+
+ This enum type defines the pen cap styles supported by TQt, i.e.
+ the line end caps that can be drawn using TQPainter.
+
+ \value FlatCap a square line end that does not cover the end
+ point of the line.
+ \value SquareCap a square line end that covers the end point and
+ extends beyond it with half the line width.
+ \value RoundCap a rounded line end.
+ \value MPenCapStyle tqmask of the pen cap styles.
+
+ \img pen-cap-styles.png Pen Cap Styles
+*/
+
+/*!
+ \enum TQt::PenJoinStyle
+
+ This enum type defines the pen join styles supported by TQt, i.e.
+ which joins between two connected lines can be drawn using
+ TQPainter.
+
+ \value MiterJoin The outer edges of the lines are extended to
+ meet at an angle, and this area is filled.
+ \value BevelJoin The triangular notch between the two lines is filled.
+ \value RoundJoin A circular arc between the two lines is filled.
+ \value MPenJoinStyle tqmask of the pen join styles.
+
+ \img pen-join-styles.png Pen Join Styles
+*/
+
+/*!
+ \enum TQt::BGMode
+
+ Background mode
+
+ \value TransparentMode
+ \value OpaqueMode
+*/
+
+/*!
+ Constructs a painter.
+
+ Notice that all painter settings (setPen, setBrush etc.) are reset
+ to default values when begin() is called.
+
+ \sa begin(), end()
+*/
+
+TQPainter::TQPainter()
+{
+ init();
+}
+
+
+/*!
+ Constructs a painter that begins painting the paint tqdevice \a pd
+ immediately. Depending on the underlying graphic system the
+ painter will paint over tqchildren of the painttqdevice if \a
+ unclipped is TRUE.
+
+ This constructor is convenient for short-lived painters, e.g. in a
+ \link TQWidget::paintEvent() paint event\endlink and should be used
+ only once. The constructor calls begin() for you and the TQPainter
+ destructor automatically calls end().
+
+ Here's an example using begin() and end():
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p;
+ p.begin( this );
+ p.drawLine( ... ); // drawing code
+ p.end();
+ }
+ \endcode
+
+ The same example using this constructor:
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p( this );
+ p.drawLine( ... ); // drawing code
+ }
+ \endcode
+
+ Since the constructor cannot provide feedback when the initialization
+ of the painter failed you should rather use begin() and end() to paint
+ on external tqdevices, e.g. printers.
+
+ \sa begin(), end()
+*/
+
+TQPainter::TQPainter( const TQPaintDevice *pd, bool unclipped )
+{
+ init();
+ if ( begin( pd, unclipped ) )
+ flags |= CtorBegin;
+}
+
+
+/*!
+ Constructs a painter that begins painting the paint tqdevice \a pd
+ immediately, with the default arguments taken from \a
+ copyAttributes. The painter will paint over tqchildren of the paint
+ tqdevice if \a unclipped is TRUE (although this is not supported on
+ all platforms).
+
+ \sa begin()
+*/
+
+TQPainter::TQPainter( const TQPaintDevice *pd,
+ const TQWidget *copyAttributes, bool unclipped )
+{
+ init();
+ if ( begin( pd, copyAttributes, unclipped ) )
+ flags |= CtorBegin;
+}
+
+
+/*!
+ Destroys the painter.
+*/
+
+TQPainter::~TQPainter()
+{
+ if ( isActive() )
+ end();
+ else
+ killPStack();
+ if ( tabarray ) // delete tab array
+ delete [] tabarray;
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( wm_stack )
+ delete (TQWMatrixStack *)wm_stack;
+#endif
+ destroy();
+}
+
+
+/*!
+ \overload bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped )
+
+ This version opens the painter on a paint tqdevice \a pd and sets
+ the initial pen, background color and font from \a copyAttributes,
+ painting over the paint tqdevice's tqchildren when \a unclipped is
+ TRUE. This is equivalent to:
+
+ \code
+ TQPainter p;
+ p.begin( pd );
+ p.setPen( copyAttributes->foregroundColor() );
+ p.setBackgroundColor( copyAttributes->backgroundColor() );
+ p.setFont( copyAttributes->font() );
+ \endcode
+
+ This begin function is convenient for double buffering. When you
+ draw in a pixmap instead of directly in a widget (to later bitBlt
+ the pixmap into the widget) you will need to set the widget's
+ font etc. This function does exactly that.
+
+ Example:
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPixmap pm(size());
+ TQPainter p;
+ p.begin(&pm, this);
+ // ... potentially flickering paint operation ...
+ p.end();
+ bitBlt(this, 0, 0, &pm);
+ }
+ \endcode
+
+ \sa end()
+*/
+
+bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped )
+{
+ if ( copyAttributes == 0 ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQPainter::begin: The widget to copy attributes from cannot "
+ "be null" );
+#endif
+ return FALSE;
+ }
+ if ( begin( pd, unclipped ) ) {
+ setPen( copyAttributes->foregroundColor() );
+ setBackgroundColor( copyAttributes->backgroundColor() );
+ setFont( copyAttributes->font() );
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+/*!
+ \internal
+ Sets or clears a pointer flag.
+*/
+
+void TQPainter::setf( uint b, bool v )
+{
+ if ( v )
+ setf( b );
+ else
+ clearf( b );
+}
+
+
+/*!
+ \fn bool TQPainter::isActive() const
+
+ Returns TRUE if the painter is active painting, i.e. begin() has
+ been called and end() has not yet been called; otherwise returns
+ FALSE.
+
+ \sa TQPaintDevice::paintingActive()
+*/
+
+/*!
+ \fn TQPaintDevice *TQPainter::tqdevice() const
+
+ Returns the paint tqdevice on which this painter is currently
+ painting, or 0 if the painter is not active.
+
+ \sa TQPaintDevice::paintingActive()
+*/
+
+
+struct TQPState { // painter state
+ TQFont font;
+ TQPen pen;
+ TQPoint curPt;
+ TQBrush brush;
+ TQColor bgc;
+ uchar bgm;
+ uchar rop;
+ TQPoint bro;
+ TQRect wr, vr;
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix wm;
+#else
+ int xlatex;
+ int xlatey;
+#endif
+ bool vxf;
+ bool wxf;
+ TQRegion rgn;
+ bool clip;
+ int ts;
+ int *ta;
+ void* wm_stack;
+};
+
+//TODO lose the worldmatrix stack
+
+typedef TQPtrStack<TQPState> TQPStateStack;
+
+
+void TQPainter::killPStack()
+{
+#if defined(TQT_CHECK_STATE)
+ if ( ps_stack && !((TQPStateStack *)ps_stack)->isEmpty() )
+ qWarning( "TQPainter::killPStack: non-empty save/restore stack when "
+ "end() was called" );
+#endif
+ delete (TQPStateStack *)ps_stack;
+ ps_stack = 0;
+}
+
+/*!
+ Saves the current painter state (pushes the state onto a stack). A
+ save() must be followed by a corresponding restore(). end()
+ unwinds the stack.
+
+ \sa restore()
+*/
+
+void TQPainter::save()
+{
+ if ( testf(ExtDev) ) {
+ if ( testf(DirtyFont) )
+ updateFont();
+ if ( testf(DirtyPen) )
+ updatePen();
+ if ( testf(DirtyBrush) )
+ updateBrush();
+ pdev->cmd( TQPaintDevice::PdcSave, this, 0 );
+ }
+ TQPStateStack *pss = (TQPStateStack *)ps_stack;
+ if ( pss == 0 ) {
+ pss = new TQPtrStack<TQPState>;
+ TQ_CHECK_PTR( pss );
+ pss->setAutoDelete( TRUE );
+ ps_stack = pss;
+ }
+ TQPState *ps = new TQPState;
+ TQ_CHECK_PTR( ps );
+ ps->font = cfont;
+ ps->pen = cpen;
+ ps->curPt = pos();
+ ps->brush = cbrush;
+ ps->bgc = bg_col;
+ ps->bgm = bg_mode;
+ ps->rop = rop;
+ ps->bro = bro;
+#ifndef TQT_NO_TRANSFORMATIONS
+ ps->wr = TQRect( wx, wy, ww, wh );
+ ps->vr = TQRect( vx, vy, vw, vh );
+ ps->wm = wxmat;
+ ps->vxf = testf(VxF);
+ ps->wxf = testf(WxF);
+#else
+ ps->xlatex = xlatex;
+ ps->xlatey = xlatey;
+#endif
+ ps->rgn = crgn;
+ ps->clip = testf(ClipOn);
+ ps->ts = tabstops;
+ ps->ta = tabarray;
+ ps->wm_stack = wm_stack;
+ wm_stack = 0;
+ pss->push( ps );
+}
+
+/*!
+ Restores the current painter state (pops a saved state off the
+ stack).
+
+ \sa save()
+*/
+
+void TQPainter::restore()
+{
+ if ( testf(ExtDev) ) {
+ pdev->cmd( TQPaintDevice::PdcRestore, this, 0 );
+ if ( pdev->devType() == TQInternal::Picture )
+ block_ext = TRUE;
+ }
+ TQPStateStack *pss = (TQPStateStack *)ps_stack;
+ if ( pss == 0 || pss->isEmpty() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::restore: Empty stack error" );
+#endif
+ return;
+ }
+ TQPState *ps = pss->pop();
+ bool hardRestore = testf(VolatileDC);
+
+ if ( ps->font != cfont || hardRestore )
+ setFont( ps->font );
+ if ( ps->pen != cpen || hardRestore )
+ setPen( ps->pen );
+ if ( ps->brush != cbrush || hardRestore )
+ setBrush( ps->brush );
+ if ( ps->bgc != bg_col || hardRestore )
+ setBackgroundColor( ps->bgc );
+ if ( ps->bgm != bg_mode || hardRestore )
+ setBackgroundMode( (BGMode)ps->bgm );
+ if ( ps->rop != rop || hardRestore )
+ setRasterOp( (RasterOp)ps->rop );
+ if ( ps->bro != bro || hardRestore )
+ setBrushOrigin( ps->bro );
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQRect wr( wx, wy, ww, wh );
+ TQRect vr( vx, vy, vw, vh );
+ if ( ps->wr != wr || hardRestore )
+ setWindow( ps->wr );
+ if ( ps->vr != vr || hardRestore )
+ setViewport( ps->vr );
+ if ( ps->wm != wxmat || hardRestore )
+ setWorldMatrix( ps->wm );
+ if ( ps->vxf != testf(VxF) || hardRestore )
+ setViewXForm( ps->vxf );
+ if ( ps->wxf != testf(WxF) || hardRestore )
+ setWorldXForm( ps->wxf );
+#else
+ xlatex = ps->xlatex;
+ xlatey = ps->xlatey;
+ setf( VxF, xlatex || xlatey );
+#endif
+ if ( ps->curPt != pos() || hardRestore )
+ moveTo( ps->curPt );
+ if ( ps->rgn != crgn || hardRestore )
+ setClipRegion( ps->rgn );
+ if ( ps->clip != testf(ClipOn) || hardRestore )
+ setClipping( ps->clip );
+ tabstops = ps->ts;
+ tabarray = ps->ta;
+
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( wm_stack )
+ delete (TQWMatrixStack *)wm_stack;
+ wm_stack = ps->wm_stack;
+#endif
+ delete ps;
+ block_ext = FALSE;
+}
+
+typedef TQPtrDict<TQPaintDevice> TQPaintDeviceDict;
+static TQPaintDeviceDict *pdev_dict = 0;
+
+/*!
+ Redirects all paint commands for a paint tqdevice, \a pdev, to
+ another paint tqdevice, \a tqreplacement, unless \a tqreplacement is 0.
+ If \a tqreplacement is 0, the redirection for \a pdev is removed.
+
+ In general, you'll probably tqfind calling TQPixmap::grabWidget() or
+ TQPixmap::grabWindow() is an easier solution.
+*/
+
+void TQPainter::redirect( TQPaintDevice *pdev, TQPaintDevice *tqreplacement )
+{
+ if ( pdev_dict == 0 ) {
+ if ( tqreplacement == 0 )
+ return;
+ pdev_dict = new TQPaintDeviceDict;
+ TQ_CHECK_PTR( pdev_dict );
+ }
+#if defined(TQT_CHECK_NULL)
+ if ( pdev == 0 )
+ qWarning( "TQPainter::redirect: The pdev argument cannot be 0" );
+#endif
+ if ( tqreplacement ) {
+ pdev_dict->insert( pdev, tqreplacement );
+ } else {
+ pdev_dict->remove( pdev );
+ if ( pdev_dict->count() == 0 ) {
+ delete pdev_dict;
+ pdev_dict = 0;
+ }
+ }
+}
+
+/*!
+ \internal
+ Returns the tqreplacement for \a pdev, or 0 if there is no tqreplacement.
+*/
+TQPaintDevice *TQPainter::redirect( TQPaintDevice *pdev )
+{
+ return pdev_dict ? pdev_dict->tqfind( pdev ) : 0;
+}
+
+/*!
+ Returns the font metrics for the painter, if the painter is
+ active. It is not possible to obtain metrics for an inactive
+ painter, so the return value is undefined if the painter is not
+ active.
+
+ \sa fontInfo(), isActive()
+*/
+
+TQFontMetrics TQPainter::fontMetrics() const
+{
+ if ( pdev && pdev->devType() == TQInternal::Picture )
+ return TQFontMetrics( cfont );
+
+ return TQFontMetrics(this);
+}
+
+/*!
+ Returns the font info for the painter, if the painter is active.
+ It is not possible to obtain font information for an inactive
+ painter, so the return value is undefined if the painter is not
+ active.
+
+ \sa fontMetrics(), isActive()
+*/
+
+TQFontInfo TQPainter::fontInfo() const
+{
+ if ( pdev && pdev->devType() == TQInternal::Picture )
+ return TQFontInfo( cfont );
+
+ return TQFontInfo(this);
+}
+
+
+/*!
+ \fn const TQPen &TQPainter::pen() const
+
+ Returns the painter's current pen.
+
+ \sa setPen()
+*/
+
+/*!
+ Sets a new painter pen.
+
+ The \a pen defines how to draw lines and outlines, and it also
+ defines the text color.
+
+ \sa pen()
+*/
+
+void TQPainter::setPen( const TQPen &pen )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setPen: Will be reset by begin()" );
+#endif
+ if ( cpen == pen )
+ return;
+ cpen = pen;
+ updatePen();
+}
+
+/*!
+ \overload
+
+ Sets the painter's pen to have style \a style, width 0 and black
+ color.
+
+ \sa pen(), TQPen
+*/
+
+void TQPainter::setPen( PenStyle style )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setPen: Will be reset by begin()" );
+#endif
+ TQPen::TQPenData *d = cpen.data; // low level access
+ if ( d->style == style && d->linest == style && !d->width && d->color == TQt::black )
+ return;
+ if ( d->count != 1 ) {
+ cpen.detach();
+ d = cpen.data;
+ }
+ d->style = style;
+ d->width = 0;
+ d->color = TQt::black;
+ d->linest = style;
+ updatePen();
+}
+
+/*!
+ \overload
+
+ Sets the painter's pen to have style \c SolidLine, width 0 and the
+ specified \a color.
+
+ \sa pen(), TQPen
+*/
+
+void TQPainter::setPen( const TQColor &color )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setPen: Will be reset by begin()" );
+#endif
+ TQPen::TQPenData *d = cpen.data; // low level access
+ if ( d->color == color && !d->width && d->style == SolidLine && d->linest == SolidLine )
+ return;
+ if ( d->count != 1 ) {
+ cpen.detach();
+ d = cpen.data;
+ }
+ d->style = SolidLine;
+ d->width = 0;
+ d->color = color;
+ d->linest = SolidLine;
+ updatePen();
+}
+
+/*!
+ \fn const TQBrush &TQPainter::brush() const
+
+ Returns the painter's current brush.
+
+ \sa TQPainter::setBrush()
+*/
+
+/*!
+ \overload
+
+ Sets the painter's brush to \a brush.
+
+ The \a brush defines how tqshapes are filled.
+
+ \sa brush()
+*/
+
+void TQPainter::setBrush( const TQBrush &brush )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setBrush: Will be reset by begin()" );
+#endif
+ if ( cbrush == brush )
+ return;
+ cbrush = brush;
+ updateBrush();
+}
+
+/*!
+ Sets the painter's brush to black color and the specified \a
+ style.
+
+ \sa brush(), TQBrush
+*/
+
+void TQPainter::setBrush( BrushStyle style )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setBrush: Will be reset by begin()" );
+#endif
+ TQBrush::TQBrushData *d = cbrush.data; // low level access
+ if ( d->style == style && d->color == TQt::black && !d->pixmap )
+ return;
+ if ( d->count != 1 ) {
+ cbrush.detach();
+ d = cbrush.data;
+ }
+ d->style = style;
+ d->color = TQt::black;
+ if ( d->pixmap ) {
+ delete d->pixmap;
+ d->pixmap = 0;
+ }
+ updateBrush();
+}
+
+/*!
+ \overload
+
+ Sets the painter's brush to have style \c SolidPattern and the
+ specified \a color.
+
+ \sa brush(), TQBrush
+*/
+
+void TQPainter::setBrush( const TQColor &color )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setBrush: Will be reset by begin()" );
+#endif
+ TQBrush::TQBrushData *d = cbrush.data; // low level access
+ if ( d->color == color && d->style == SolidPattern && !d->pixmap )
+ return;
+ if ( d->count != 1 ) {
+ cbrush.detach();
+ d = cbrush.data;
+ }
+ d->style = SolidPattern;
+ d->color = color;
+ if ( d->pixmap ) {
+ delete d->pixmap;
+ d->pixmap = 0;
+ }
+ updateBrush();
+}
+
+
+/*!
+ \fn const TQColor &TQPainter::backgroundColor() const
+
+ Returns the current background color.
+
+ \sa setBackgroundColor() TQColor
+*/
+
+/*!
+ \fn BGMode TQPainter::backgroundMode() const
+
+ Returns the current background mode.
+
+ \sa setBackgroundMode() BGMode
+*/
+
+/*!
+ \fn RasterOp TQPainter::rasterOp() const
+
+ Returns the current \link TQt::RasterOp raster operation \endlink.
+
+ \sa setRasterOp() RasterOp
+*/
+
+/*!
+ \fn const TQPoint &TQPainter::brushOrigin() const
+
+ Returns the brush origin currently set.
+
+ \sa setBrushOrigin()
+*/
+
+
+/*!
+ \fn int TQPainter::tabStops() const
+
+ Returns the tab stop setting.
+
+ \sa setTabStops()
+*/
+
+/*!
+ Set the tab stop width to \a ts, i.e. locates tab stops at \a ts,
+ 2*\a ts, 3*\a ts and so on.
+
+ Tab stops are used when drawing formatted text with \c ExpandTabs
+ set. This fixed tab stop value is used only if no tab array is set
+ (which is the default case).
+
+ A value of 0 (the default) implies a tabstop setting of 8 times the width of the
+ character 'x' in the font currently set on the painter.
+
+ \sa tabStops(), setTabArray(), drawText(), fontMetrics()
+*/
+
+void TQPainter::setTabStops( int ts )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setTabStops: Will be reset by begin()" );
+#endif
+ tabstops = ts;
+ if ( isActive() && testf(ExtDev) ) { // tell extended tqdevice
+ TQPDevCmdParam param[1];
+ param[0].ival = ts;
+ pdev->cmd( TQPaintDevice::PdcSetTabStops, this, param );
+ }
+}
+
+/*!
+ \fn int *TQPainter::tabArray() const
+
+ Returns the currently set tab stop array.
+
+ \sa setTabArray()
+*/
+
+/*!
+ Sets the tab stop array to \a ta. This puts tab stops at \a ta[0],
+ \a ta[1] and so on. The array is null-terminated.
+
+ If both a tab array and a tab top size is set, the tab array wins.
+
+ \sa tabArray(), setTabStops(), drawText(), fontMetrics()
+*/
+
+void TQPainter::setTabArray( int *ta )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setTabArray: Will be reset by begin()" );
+#endif
+ if ( ta != tabarray ) {
+ tabarraylen = 0;
+ if ( tabarray ) // Avoid purify complaint
+ delete [] tabarray; // delete old array
+ if ( ta ) { // tabarray = copy of 'ta'
+ while ( ta[tabarraylen] )
+ tabarraylen++;
+ tabarraylen++; // and 0 terminator
+ tabarray = new int[tabarraylen]; // duplicate ta
+ memcpy( tabarray, ta, sizeof(int)*tabarraylen );
+ } else {
+ tabarray = 0;
+ }
+ }
+ if ( isActive() && testf(ExtDev) ) { // tell extended tqdevice
+ TQPDevCmdParam param[2];
+ param[0].ival = tabarraylen;
+ param[1].ivec = tabarray;
+ pdev->cmd( TQPaintDevice::PdcSetTabArray, this, param );
+ }
+}
+
+
+/*!
+ \fn HANDLE TQPainter::handle() const
+
+ Returns the platform-dependent handle used for drawing. Using this
+ function is not portable.
+*/
+
+
+/*****************************************************************************
+ TQPainter xform settings
+ *****************************************************************************/
+
+#ifndef TQT_NO_TRANSFORMATIONS
+
+/*!
+ Enables view transformations if \a enable is TRUE, or disables
+ view transformations if \a enable is FALSE.
+
+ \sa hasViewXForm(), setWindow(), setViewport(), setWorldMatrix(),
+ setWorldXForm(), xForm()
+*/
+
+void TQPainter::setViewXForm( bool enable )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setViewXForm: Will be reset by begin()" );
+#endif
+ if ( !isActive() || enable == testf(VxF) )
+ return;
+ setf( VxF, enable );
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].ival = enable;
+ pdev->cmd( TQPaintDevice::PdcSetVXform, this, param );
+ }
+ updateXForm();
+}
+
+/*!
+ \fn bool TQPainter::hasViewXForm() const
+
+ Returns TRUE if view transformation is enabled; otherwise returns
+ FALSE.
+
+ \sa setViewXForm(), xForm()
+*/
+
+/*!
+ Returns the window rectangle.
+
+ \sa setWindow(), setViewXForm()
+*/
+
+TQRect TQPainter::window() const
+{
+ return TQRect( wx, wy, ww, wh );
+}
+
+/*!
+ Sets the window rectangle view transformation for the painter and
+ enables view transformation.
+
+ The window rectangle is part of the view transformation. The
+ window specifies the logical coordinate system and is specified by
+ the \a x, \a y, \a w width and \a h height parameters. Its sister,
+ the viewport(), specifies the tqdevice coordinate system.
+
+ The default window rectangle is the same as the tqdevice's
+ rectangle. See the \link coordsys.html Coordinate System Overview
+ \endlink for an overview of coordinate transformation.
+
+ \sa window(), setViewport(), setViewXForm(), setWorldMatrix(),
+ setWorldXForm()
+*/
+
+void TQPainter::setWindow( int x, int y, int w, int h )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setWindow: Will be reset by begin()" );
+#endif
+ wx = x;
+ wy = y;
+ ww = w;
+ wh = h;
+ if ( testf(ExtDev) ) {
+ TQRect r( x, y, w, h );
+ TQPDevCmdParam param[1];
+ param[0].rect = (TQRect*)&r;
+ pdev->cmd( TQPaintDevice::PdcSetWindow, this, param );
+ }
+ if ( testf(VxF) )
+ updateXForm();
+ else
+ setViewXForm( TRUE );
+}
+
+/*!
+ Returns the viewport rectangle.
+
+ \sa setViewport(), setViewXForm()
+*/
+
+TQRect TQPainter::viewport() const // get viewport
+{
+ return TQRect( vx, vy, vw, vh );
+}
+
+/*!
+ Sets the viewport rectangle view transformation for the painter
+ and enables view transformation.
+
+ The viewport rectangle is part of the view transformation. The
+ viewport specifies the tqdevice coordinate system and is specified
+ by the \a x, \a y, \a w width and \a h height parameters. Its
+ sister, the window(), specifies the logical coordinate system.
+
+ The default viewport rectangle is the same as the tqdevice's
+ rectangle. See the \link coordsys.html Coordinate System Overview
+ \endlink for an overview of coordinate transformation.
+
+ \sa viewport(), setWindow(), setViewXForm(), setWorldMatrix(),
+ setWorldXForm(), xForm()
+*/
+
+void TQPainter::setViewport( int x, int y, int w, int h )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setViewport: Will be reset by begin()" );
+#endif
+ vx = x;
+ vy = y;
+ vw = w;
+ vh = h;
+ if ( testf(ExtDev) ) {
+ TQRect r( x, y, w, h );
+ TQPDevCmdParam param[1];
+ param[0].rect = (TQRect*)&r;
+ pdev->cmd( TQPaintDevice::PdcSetViewport, this, param );
+ }
+ if ( testf(VxF) )
+ updateXForm();
+ else
+ setViewXForm( TRUE );
+}
+
+
+/*!
+ Enables world transformations if \a enable is TRUE, or disables
+ world transformations if \a enable is FALSE. The world
+ transformation matrix is not changed.
+
+ \sa setWorldMatrix(), setWindow(), setViewport(), setViewXForm(),
+ xForm()
+*/
+
+void TQPainter::setWorldXForm( bool enable )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setWorldXForm: Will be reset by begin()" );
+#endif
+ if ( !isActive() || enable == testf(WxF) )
+ return;
+ setf( WxF, enable );
+ if ( testf(ExtDev) && !block_ext ) {
+ TQPDevCmdParam param[1];
+ param[0].ival = enable;
+ pdev->cmd( TQPaintDevice::PdcSetWXform, this, param );
+ }
+ updateXForm();
+}
+
+/*!
+ \fn bool TQPainter::hasWorldXForm() const
+
+ Returns TRUE if world transformation is enabled; otherwise returns
+ FALSE.
+
+ \sa setWorldXForm()
+*/
+
+/*!
+ Returns the world transformation matrix.
+
+ \sa setWorldMatrix()
+*/
+
+const TQWMatrix &TQPainter::tqworldMatrix() const
+{
+ return wxmat;
+}
+
+/*!
+ Sets the world transformation matrix to \a m and enables world
+ transformation.
+
+ If \a combine is TRUE, then \a m is combined with the current
+ transformation matrix, otherwise \a m tqreplaces the current
+ transformation matrix.
+
+ If \a m is the identity matrix and \a combine is FALSE, this
+ function calls setWorldXForm(FALSE). (The identity matrix is the
+ matrix where TQWMatrix::m11() and TQWMatrix::m22() are 1.0 and the
+ rest are 0.0.)
+
+ World transformations are applied after the view transformations
+ (i.e. \link setWindow() window\endlink and \link setViewport()
+ viewport\endlink).
+
+ The following functions can transform the coordinate system without using
+ a TQWMatrix:
+ \list
+ \i translate()
+ \i scale()
+ \i shear()
+ \i rotate()
+ \endlist
+
+ They operate on the painter's tqworldMatrix() and are implemented like this:
+
+ \code
+ void TQPainter::rotate( double a )
+ {
+ TQWMatrix m;
+ m.rotate( a );
+ setWorldMatrix( m, TRUE );
+ }
+ \endcode
+
+ Note that you should always use \a combine when you are drawing
+ into a TQPicture. Otherwise it may not be possible to replay the
+ picture with additional transformations. Using translate(),
+ scale(), etc., is safe.
+
+ For a brief overview of coordinate transformation, see the \link
+ coordsys.html Coordinate System Overview. \endlink
+
+ \sa tqworldMatrix() setWorldXForm() setWindow() setViewport()
+ setViewXForm() xForm() TQWMatrix
+*/
+
+void TQPainter::setWorldMatrix( const TQWMatrix &m, bool combine )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setWorldMatrix: Will be reset by begin()" );
+#endif
+ return;
+ }
+ if ( combine )
+ wxmat = m * wxmat; // combines
+ else
+ wxmat = m; // set new matrix
+ bool identity = wxmat.m11() == 1.0F && wxmat.m22() == 1.0F &&
+ wxmat.m12() == 0.0F && wxmat.m21() == 0.0F &&
+ wxmat.dx() == 0.0F && wxmat.dy() == 0.0F;
+ if ( testf(ExtDev) && !block_ext ) {
+ TQPDevCmdParam param[2];
+ param[0].matrix = &m;
+ param[1].ival = combine;
+ pdev->cmd( TQPaintDevice::PdcSetWMatrix, this, param );
+ }
+ if ( identity && pdev->devType() != TQInternal::Picture )
+ setWorldXForm( FALSE );
+ else if ( !testf(WxF) )
+ setWorldXForm( TRUE );
+ else
+ updateXForm();
+}
+
+/*! \obsolete
+
+ We recommend using save() instead.
+*/
+
+void TQPainter::saveWorldMatrix()
+{
+ TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack;
+ if ( stack == 0 ) {
+ stack = new TQPtrStack<TQWMatrix>;
+ TQ_CHECK_PTR( stack );
+ stack->setAutoDelete( TRUE );
+ wm_stack = stack;
+ }
+
+ stack->push( new TQWMatrix( wxmat ) );
+
+}
+
+/*! \obsolete
+ We recommend using restore() instead.
+*/
+
+void TQPainter::restoreWorldMatrix()
+{
+ TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack;
+ if ( stack == 0 || stack->isEmpty() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::restoreWorldMatrix: Empty stack error" );
+#endif
+ return;
+ }
+ TQWMatrix* m = stack->pop();
+ setWorldMatrix( *m );
+ delete m;
+}
+
+#endif // TQT_NO_TRANSFORMATIONS
+
+/*!
+ Translates the coordinate system by \a (dx, dy). After this call,
+ \a (dx, dy) is added to points.
+
+ For example, the following code draws the same point twice:
+ \code
+ void MyWidget::paintEvent()
+ {
+ TQPainter paint( this );
+
+ paint.drawPoint( 0, 0 );
+
+ paint.translate( 100.0, 40.0 );
+ paint.drawPoint( -100, -40 );
+ }
+ \endcode
+
+ \sa scale(), shear(), rotate(), resetXForm(), setWorldMatrix(), xForm()
+*/
+
+void TQPainter::translate( double dx, double dy )
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix m;
+ m.translate( dx, dy );
+ setWorldMatrix( m, TRUE );
+#else
+ xlatex += (int)dx;
+ xlatey += (int)dy;
+ setf( VxF, xlatex || xlatey );
+#endif
+}
+
+
+#ifndef TQT_NO_TRANSFORMATIONS
+/*!
+ Scales the coordinate system by \a (sx, sy).
+
+ \sa translate(), shear(), rotate(), resetXForm(), setWorldMatrix(),
+ xForm()
+*/
+
+void TQPainter::scale( double sx, double sy )
+{
+ TQWMatrix m;
+ m.scale( sx, sy );
+ setWorldMatrix( m, TRUE );
+}
+
+/*!
+ Shears the coordinate system by \a (sh, sv).
+
+ \sa translate(), scale(), rotate(), resetXForm(), setWorldMatrix(),
+ xForm()
+*/
+
+void TQPainter::shear( double sh, double sv )
+{
+ TQWMatrix m;
+ m.shear( sv, sh );
+ setWorldMatrix( m, TRUE );
+}
+
+/*!
+ Rotates the coordinate system \a a degrees counterclockwise.
+
+ \sa translate(), scale(), shear(), resetXForm(), setWorldMatrix(),
+ xForm()
+*/
+
+void TQPainter::rotate( double a )
+{
+ TQWMatrix m;
+ m.rotate( a );
+ setWorldMatrix( m, TRUE );
+}
+
+
+/*!
+ Resets any transformations that were made using translate(), scale(),
+ shear(), rotate(), setWorldMatrix(), setViewport() and
+ setWindow().
+
+ \sa tqworldMatrix(), viewport(), window()
+*/
+
+void TQPainter::resetXForm()
+{
+ if ( !isActive() )
+ return;
+ wx = wy = vx = vy = 0; // default view origins
+ ww = vw = pdev->metric( TQPaintDeviceMetrics::PdmWidth );
+ wh = vh = pdev->metric( TQPaintDeviceMetrics::PdmHeight );
+ wxmat = TQWMatrix();
+ setWorldXForm( FALSE );
+ setViewXForm( FALSE );
+}
+
+/*!
+ \internal
+ Updates an internal integer transformation matrix.
+*/
+
+void TQPainter::updateXForm()
+{
+ TQWMatrix m;
+ if ( testf(VxF) ) {
+ double scaleW = (double)vw/(double)ww;
+ double scaleH = (double)vh/(double)wh;
+ m.setMatrix( scaleW, 0, 0, scaleH, vx - wx*scaleW, vy - wy*scaleH );
+ }
+ if ( testf(WxF) ) {
+ if ( testf(VxF) )
+ m = wxmat * m;
+ else
+ m = wxmat;
+ }
+ xmat = m;
+
+ txinv = FALSE; // no inverted matrix
+ txop = TxNone;
+ if ( m12()==0.0 && m21()==0.0 && m11() >= 0.0 && m22() >= 0.0 ) {
+ if ( m11()==1.0 && m22()==1.0 ) {
+ if ( dx()!=0.0 || dy()!=0.0 )
+ txop = TxTranslate;
+ } else {
+ txop = TxScale;
+#if defined(TQ_WS_WIN)
+ setf(DirtyFont);
+#endif
+ }
+ } else {
+ txop = TxRotShear;
+#if defined(TQ_WS_WIN)
+ setf(DirtyFont);
+#endif
+ }
+}
+
+
+/*!
+ \internal
+ Updates an internal integer inverse transformation matrix.
+*/
+
+void TQPainter::updateInvXForm()
+{
+#if defined(TQT_CHECK_STATE)
+ TQ_ASSERT( txinv == FALSE );
+#endif
+ txinv = TRUE; // creating inverted matrix
+ bool invertible;
+ TQWMatrix m;
+ if ( testf(VxF) ) {
+ m.translate( vx, vy );
+ m.scale( 1.0*vw/ww, 1.0*vh/wh );
+ m.translate( -wx, -wy );
+ }
+ if ( testf(WxF) ) {
+ if ( testf(VxF) )
+ m = wxmat * m;
+ else
+ m = wxmat;
+ }
+ ixmat = m.invert( &invertible ); // invert matrix
+}
+
+#else
+void TQPainter::resetXForm()
+{
+ xlatex = 0;
+ xlatey = 0;
+ clearf( VxF );
+}
+#endif // TQT_NO_TRANSFORMATIONS
+
+
+extern bool qt_old_transformations;
+
+/*!
+ \internal
+ Maps a point from logical coordinates to tqdevice coordinates.
+*/
+
+void TQPainter::map( int x, int y, int *rx, int *ry ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( qt_old_transformations ) {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x; *ry = y;
+ break;
+ case TxTranslate:
+ // #### "Why no rounding here?", Warwick asked of Haavard.
+ *rx = int(x + dx());
+ *ry = int(y + dy());
+ break;
+ case TxScale: {
+ double tx = m11()*x + dx();
+ double ty = m22()*y + dy();
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ } break;
+ default: {
+ double tx = m11()*x + m21()*y+dx();
+ double ty = m12()*x + m22()*y+dy();
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ } break;
+ }
+ } else {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x;
+ *ry = y;
+ break;
+ case TxTranslate:
+ *rx = tqRound( x + dx() );
+ *ry = tqRound( y + dy() );
+ break;
+ case TxScale:
+ *rx = tqRound( m11()*x + dx() );
+ *ry = tqRound( m22()*y + dy() );
+ break;
+ default:
+ *rx = tqRound( m11()*x + m21()*y+dx() );
+ *ry = tqRound( m12()*x + m22()*y+dy() );
+ break;
+ }
+ }
+#else
+ *rx = x + xlatex;
+ *ry = y + xlatey;
+#endif
+}
+
+/*!
+ \internal
+ Maps a rectangle from logical coordinates to tqdevice coordinates.
+ This internal function does not handle rotation and/or shear.
+*/
+
+void TQPainter::map( int x, int y, int w, int h,
+ int *rx, int *ry, int *rw, int *rh ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( qt_old_transformations ) {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x; *ry = y;
+ *rw = w; *rh = h;
+ break;
+ case TxTranslate:
+ // #### "Why no rounding here?", Warwick asked of Haavard.
+ *rx = int(x + dx());
+ *ry = int(y + dy());
+ *rw = w; *rh = h;
+ break;
+ case TxScale: {
+ double tx1 = m11()*x + dx();
+ double ty1 = m22()*y + dy();
+ double tx2 = m11()*(x + w - 1) + dx();
+ double ty2 = m22()*(y + h - 1) + dy();
+ *rx = tqRound( tx1 );
+ *ry = tqRound( ty1 );
+ *rw = tqRound( tx2 ) - *rx + 1;
+ *rh = tqRound( ty2 ) - *ry + 1;
+ } break;
+ default:
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::map: Internal error" );
+#endif
+ break;
+ }
+ } else {
+ switch ( txop ) {
+ case TxNone:
+ *rx = x; *ry = y;
+ *rw = w; *rh = h;
+ break;
+ case TxTranslate:
+ *rx = tqRound(x + dx() );
+ *ry = tqRound(y + dy() );
+ *rw = w; *rh = h;
+ break;
+ case TxScale:
+ *rx = tqRound( m11()*x + dx() );
+ *ry = tqRound( m22()*y + dy() );
+ *rw = tqRound( m11()*w );
+ *rh = tqRound( m22()*h );
+ break;
+ default:
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::map: Internal error" );
+#endif
+ break;
+ }
+ }
+#else
+ *rx = x + xlatex;
+ *ry = y + xlatey;
+ *rw = w; *rh = h;
+#endif
+}
+
+/*!
+ \internal
+ Maps a point from tqdevice coordinates to logical coordinates.
+*/
+
+void TQPainter::mapInv( int x, int y, int *rx, int *ry ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+#if defined(TQT_CHECK_STATE)
+ if ( !txinv )
+ qWarning( "TQPainter::mapInv: Internal error" );
+#endif
+ if ( qt_old_transformations ) {
+ double tx = im11()*x + im21()*y+idx();
+ double ty = im12()*x + im22()*y+idy();
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ } else {
+ *rx = tqRound( im11()*x + im21()*y + idx() );
+ *ry = tqRound( im12()*x + im22()*y + idy() );
+ }
+#else
+ *rx = x - xlatex;
+ *ry = y - xlatey;
+#endif
+}
+
+/*!
+ \internal
+ Maps a rectangle from tqdevice coordinates to logical coordinates.
+ Cannot handle rotation and/or shear.
+*/
+
+void TQPainter::mapInv( int x, int y, int w, int h,
+ int *rx, int *ry, int *rw, int *rh ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+#if defined(TQT_CHECK_STATE)
+ if ( !txinv || txop == TxRotShear )
+ qWarning( "TQPainter::mapInv: Internal error" );
+#endif
+ if ( qt_old_transformations ) {
+ double tx = im11()*x + idx();
+ double ty = im22()*y + idy();
+ double tw = im11()*w;
+ double th = im22()*h;
+ *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5);
+ *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5);
+ *rw = tw >= 0 ? int(tw + 0.5) : int(tw - 0.5);
+ *rh = th >= 0 ? int(th + 0.5) : int(th - 0.5);
+ } else {
+ *rx = tqRound( im11()*x + idx() );
+ *ry = tqRound( im22()*y + idy() );
+ *rw = tqRound( im11()*w );
+ *rh = tqRound( im22()*h );
+ }
+#else
+ *rx = x - xlatex;
+ *ry = y - xlatey;
+ *rw = w;
+ *rh = h;
+#endif
+}
+
+
+/*!
+ Returns the point \a pv transformed from model coordinates to
+ tqdevice coordinates.
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPoint TQPainter::xForm( const TQPoint &pv ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return pv;
+ int x=pv.x(), y=pv.y();
+ map( x, y, &x, &y );
+ return TQPoint( x, y );
+#else
+ return TQPoint( pv.x()+xlatex, pv.y()+xlatey );
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the rectangle \a rv transformed from model coordinates to
+ tqdevice coordinates.
+
+ If world transformation is enabled and rotation or shearing has
+ been specified, then the bounding rectangle is returned.
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQRect TQPainter::xForm( const TQRect &rv ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return rv;
+ if ( txop == TxRotShear ) { // rotation/shear
+ return xmat.mapRect( rv );
+ }
+ // Just translation/scale
+ int x, y, w, h;
+ rv.rect( &x, &y, &w, &h );
+ map( x, y, w, h, &x, &y, &w, &h );
+ return TQRect( x, y, w, h );
+#else
+ return TQRect( rv.x()+xlatex, rv.y()+xlatey, rv.width(), rv.height() );
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the point array \a av transformed from model coordinates
+ to tqdevice coordinates.
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xForm( const TQPointArray &av ) const
+{
+ TQPointArray a = av;
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop != TxNone )
+ {
+ return xmat * av;
+ }
+#else
+ a.translate( xlatex, xlatey );
+#endif
+ return a;
+}
+
+/*!
+ \overload
+
+ Returns the point array \a av transformed from model coordinates
+ to tqdevice coordinates. The \a index is the first point in the
+ array and \a npoints denotes the number of points to be
+ transformed. If \a npoints is negative, all points from \a
+ av[index] until the last point in the array are transformed.
+
+ The returned point array consists of the number of points that
+ were transformed.
+
+ Example:
+ \code
+ TQPointArray a(10);
+ TQPointArray b;
+ b = painter.xForm(a, 2, 4); // b.size() == 4
+ b = painter.xForm(a, 2, -1); // b.size() == 8
+ \endcode
+
+ \sa xFormDev(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xForm( const TQPointArray &av, int index,
+ int npoints ) const
+{
+ int lastPoint = npoints < 0 ? av.size() : index+npoints;
+ TQPointArray a( lastPoint-index );
+ memcpy( a.data(), av.data()+index, (lastPoint-index)*sizeof( TQPoint ) );
+#ifndef TQT_NO_TRANSFORMATIONS
+ return xmat*a;
+#else
+ a.translate( xlatex, xlatey );
+ return a;
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the point \a pd transformed from tqdevice coordinates to
+ model coordinates.
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPoint TQPainter::xFormDev( const TQPoint &pd ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return pd;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+#endif
+ int x=pd.x(), y=pd.y();
+ mapInv( x, y, &x, &y );
+ return TQPoint( x, y );
+}
+
+/*!
+ Returns the rectangle \a rd transformed from tqdevice coordinates to
+ model coordinates.
+
+ If world transformation is enabled and rotation or shearing is
+ used, then the bounding rectangle is returned.
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQRect TQPainter::xFormDev( const TQRect &rd ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return rd;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+ if ( txop == TxRotShear ) { // rotation/shear
+ return ixmat.mapRect( rd );
+ }
+#endif
+ // Just translation/scale
+ int x, y, w, h;
+ rd.rect( &x, &y, &w, &h );
+ mapInv( x, y, w, h, &x, &y, &w, &h );
+ return TQRect( x, y, w, h );
+}
+
+/*!
+ \overload
+
+ Returns the point array \a ad transformed from tqdevice coordinates
+ to model coordinates.
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xFormDev( const TQPointArray &ad ) const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return ad;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+ return ixmat * ad;
+#else
+ // ###
+ return ad;
+#endif
+}
+
+/*!
+ \overload
+
+ Returns the point array \a ad transformed from tqdevice coordinates
+ to model coordinates. The \a index is the first point in the array
+ and \a npoints denotes the number of points to be transformed. If
+ \a npoints is negative, all points from \a ad[index] until the
+ last point in the array are transformed.
+
+ The returned point array consists of the number of points that
+ were transformed.
+
+ Example:
+ \code
+ TQPointArray a(10);
+ TQPointArray b;
+ b = painter.xFormDev(a, 1, 3); // b.size() == 3
+ b = painter.xFormDev(a, 1, -1); // b.size() == 9
+ \endcode
+
+ \sa xForm(), TQWMatrix::map()
+*/
+
+TQPointArray TQPainter::xFormDev( const TQPointArray &ad, int index,
+ int npoints ) const
+{
+ int lastPoint = npoints < 0 ? ad.size() : index+npoints;
+ TQPointArray a( lastPoint-index );
+ memcpy( a.data(), ad.data()+index, (lastPoint-index)*sizeof( TQPoint ) );
+#ifndef TQT_NO_TRANSFORMATIONS
+ if ( txop == TxNone )
+ return a;
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+ return ixmat * a;
+#else
+ // ###
+ return a;
+#endif
+}
+
+
+/*!
+ Fills the rectangle \a (x, y, w, h) with the \a brush.
+
+ You can specify a TQColor as \a brush, since there is a TQBrush
+ constructor that takes a TQColor argument and creates a solid
+ pattern brush.
+
+ \sa drawRect()
+*/
+
+void TQPainter::fillRect( int x, int y, int w, int h, const TQBrush &brush )
+{
+ TQPen oldPen = pen(); // save pen
+ TQBrush oldBrush = this->brush(); // save brush
+ setPen( NoPen );
+ setBrush( brush );
+ drawRect( x, y, w, h ); // draw filled rect
+ setBrush( oldBrush ); // restore brush
+ setPen( oldPen ); // restore pen
+}
+
+
+/*!
+ \overload void TQPainter::setBrushOrigin( const TQPoint &p )
+
+ Sets the brush origin to point \a p.
+*/
+
+/*!
+ \overload void TQPainter::setWindow( const TQRect &r )
+
+ Sets the painter's window to rectangle \a r.
+*/
+
+
+/*!
+ \overload void TQPainter::setViewport( const TQRect &r )
+
+ Sets the painter's viewport to rectangle \a r.
+*/
+
+
+/*!
+ \fn bool TQPainter::hasClipping() const
+
+ Returns TRUE if clipping has been set; otherwise returns FALSE.
+
+ \sa setClipping()
+*/
+
+/*!
+ Returns the currently set clip region. Note that the clip region
+ is given in physical tqdevice coordinates and \e not subject to any
+ \link coordsys.html coordinate transformation \endlink if \a m is
+ equal to \c CoordDevice (the default). If \a m equals \c
+ CoordPainter the returned region is in model coordinates.
+
+ \sa setClipRegion(), setClipRect(), setClipping() TQPainter::CoordinateMode
+*/
+TQRegion TQPainter::clipRegion( CoordinateMode m ) const
+{
+ // ### FIXME in 4.0:
+ // If the transformation mode is CoordPainter, we should transform the
+ // clip region with painter transformations.
+
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQRegion r;
+ if ( m == CoordDevice ) {
+ r = crgn;
+ } else {
+ if ( !txinv ) {
+ TQPainter *that = (TQPainter*)this; // mutable
+ that->updateInvXForm();
+ }
+
+ r = ixmat * crgn;
+ }
+ return r;
+#else
+ return crgn;
+#endif
+}
+
+/*!
+ \fn void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m)
+
+ Sets the clip region to the rectangle \a x, \a y, \a w, \a h and
+ enables clipping. The clip mode is set to \a m.
+
+ If \a m is \c CoordDevice (the default), the coordinates given for
+ the clip region are taken to be physical tqdevice coordinates and
+ are \e not subject to any \link coordsys.html coordinate
+ transformations\endlink. If \a m is \c CoordPainter, the
+ coordinates given for the clip region are taken to be model
+ coordinates.
+
+ \sa setClipRegion(), clipRegion(), setClipping() TQPainter::CoordinateMode
+*/
+
+/*!
+ \overload void TQPainter::drawPoint( const TQPoint &p )
+
+ Draws the point \a p.
+*/
+
+
+/*!
+ \overload void TQPainter::moveTo( const TQPoint &p )
+
+ Moves to the point \a p.
+*/
+
+/*!
+ \overload void TQPainter::lineTo( const TQPoint &p )
+
+ Draws a line to the point \a p.
+*/
+
+/*!
+ \overload void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 )
+
+ Draws a line from point \a p1 to point \a p2.
+*/
+
+/*!
+ \overload void TQPainter::drawRect( const TQRect &r )
+
+ Draws the rectangle \a r.
+*/
+
+/*!
+ \overload void TQPainter::drawWinFocusRect( const TQRect &r )
+
+ Draws rectangle \a r as a window focus rectangle.
+*/
+
+/*!
+ \overload void TQPainter::drawWinFocusRect( const TQRect &r, const TQColor &bgColor )
+
+ Draws rectangle \a r as a window focus rectangle using background
+ color \a bgColor.
+*/
+
+
+#if !defined(TQ_WS_X11) && !defined(TQ_WS_TQWS) && !defined(TQ_WS_MAC)
+// The doc and X implementation of this functions is in qpainter_x11.cpp
+void TQPainter::drawWinFocusRect( int, int, int, int,
+ bool, const TQColor & )
+{
+ // do nothing, only called from X11 specific functions
+}
+#endif
+
+
+/*!
+ \overload void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd )
+
+ Draws a rounded rectangle \a r, rounding to the x position \a xRnd
+ and the y position \a yRnd on each corner.
+*/
+
+/*!
+ \overload void TQPainter::drawEllipse( const TQRect &r )
+
+ Draws the ellipse that fits inside rectangle \a r.
+*/
+
+/*!
+ \overload void TQPainter::drawArc( const TQRect &r, int a, int alen )
+
+ Draws the arc that fits inside the rectangle \a r with start angle
+ \a a and arc length \a alen.
+*/
+
+/*!
+ \overload void TQPainter::drawPie( const TQRect &r, int a, int alen )
+
+ Draws a pie segment that fits inside the rectangle \a r with start
+ angle \a a and arc length \a alen.
+*/
+
+/*!
+ \overload void TQPainter::drawChord( const TQRect &r, int a, int alen )
+
+ Draws a chord that fits inside the rectangle \a r with start angle
+ \a a and arc length \a alen.
+*/
+
+/*!
+ \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm, const TQRect &sr )
+
+ Draws the rectangle \a sr of pixmap \a pm with its origin at point
+ \a p.
+*/
+
+/*!
+ \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm )
+
+ Draws the pixmap \a pm with its origin at point \a p.
+*/
+
+void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm )
+{
+ drawPixmap( p.x(), p.y(), pm, 0, 0, pm.width(), pm.height() );
+}
+
+#if !defined(TQT_NO_IMAGE_SMOOTHSCALE) || !defined(TQT_NO_PIXMAP_TRANSFORMATION)
+
+/*!
+ \overload
+
+ Draws the pixmap \a pm into the rectangle \a r. The pixmap is
+ scaled to fit the rectangle, if image and rectangle size disagree.
+*/
+void TQPainter::drawPixmap( const TQRect &r, const TQPixmap &pm )
+{
+ int rw = r.width();
+ int rh = r.height();
+ int iw= pm.width();
+ int ih = pm.height();
+ if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 )
+ return;
+ bool scale = ( rw != iw || rh != ih );
+ float scaleX = (float)rw/(float)iw;
+ float scaleY = (float)rh/(float)ih;
+ bool smooth = ( scaleX < 1.5 || scaleY < 1.5 );
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ param[0].rect = &r;
+ param[1].pixmap = &pm;
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hdc )
+ return;
+#elif defined(TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param );
+ return;
+#elif defined(TQ_WS_MAC)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !pdev->handle())
+ return;
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hd )
+ return;
+#endif
+ }
+
+ TQPixmap pixmap = pm;
+
+ if ( scale ) {
+#ifndef TQT_NO_IMAGE_SMOOTHSCALE
+# ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ if ( smooth )
+# endif
+ {
+ TQImage i = pm.convertToImage();
+ pixmap = TQPixmap( i.smoothScale( rw, rh ) );
+ }
+# ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ else
+# endif
+#endif
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ {
+ pixmap = pm.xForm( TQWMatrix( scaleX, 0, 0, scaleY, 0, 0 ) );
+ }
+#endif
+ }
+ drawPixmap( r.x(), r.y(), pixmap );
+}
+
+#endif
+
+/*!
+ \overload void TQPainter::drawImage( const TQPoint &, const TQImage &, const TQRect &sr, int conversionFlags = 0 );
+
+ Draws the rectangle \a sr from the image at the given point.
+*/
+
+/*
+ Draws at point \a p the \sr rect from image \a pm, using \a
+ conversionFlags if the image needs to be converted to a pixmap.
+ The default value for \a conversionFlags is 0; see
+ convertFromImage() for information about what other values do.
+
+ This function may convert \a image to a pixmap and then draw it, if
+ tqdevice() is a TQPixmap or a TQWidget, or else draw it directly, if
+ tqdevice() is a TQPrinter or TQPicture.
+*/
+
+/*!
+ Draws at (\a x, \a y) the \a sw by \a sh area of pixels from (\a
+ sx, \a sy) in \a image, using \a conversionFlags if the image
+ needs to be converted to a pixmap. The default value for \a
+ conversionFlags is 0; see convertFromImage() for information about
+ what other values do.
+
+ This function may convert \a image to a pixmap and then draw it,
+ if tqdevice() is a TQPixmap or a TQWidget, or else draw it directly,
+ if tqdevice() is a TQPrinter or TQPicture.
+
+ Currently alpha masks of the image are ignored when painting on a TQPrinter.
+
+ \sa drawPixmap() TQPixmap::convertFromImage()
+*/
+void TQPainter::drawImage( int x, int y, const TQImage & image,
+ int sx, int sy, int sw, int sh,
+ int conversionFlags )
+{
+#ifdef TQ_WS_TQWS
+ //### Hackish
+# ifndef TQT_NO_TRANSFORMATIONS
+ if ( !image.isNull() && gfx &&
+ (txop==TxNone||txop==TxTranslate) && !testf(ExtDev) )
+# else
+ if ( !image.isNull() && gfx && !testf(ExtDev) )
+# endif
+ {
+ if(sw<0)
+ sw=image.width();
+ if(sh<0)
+ sh=image.height();
+
+ TQImage image2 = qt_screen->mapToDevice( image );
+
+ // This is a bit dubious
+ if(image2.depth()==1) {
+ image2.setNumColors( 2 );
+ image2.setColor( 0, tqRgb(255,255,255) );
+ image2.setColor( 1, tqRgb(0,0,0) );
+ }
+ if ( image2.hasAlphaBuffer() )
+ gfx->setAlphaType(TQGfx::InlineAlpha);
+ else
+ gfx->setAlphaType(TQGfx::IgnoreAlpha);
+ gfx->setSource(&image2);
+ if ( testf(VxF|WxF) ) {
+ map( x, y, &x, &y );
+ }
+ gfx->blt(x,y,sw,sh,sx,sy);
+ return;
+ }
+#endif
+
+ if ( !isActive() || image.isNull() )
+ return;
+
+ // right/bottom
+ if ( sw < 0 )
+ sw = image.width() - sx;
+ if ( sh < 0 )
+ sh = image.height() - sy;
+
+ // Sanity-check clipping
+ if ( sx < 0 ) {
+ x -= sx;
+ sw += sx;
+ sx = 0;
+ }
+ if ( sw + sx > image.width() )
+ sw = image.width() - sx;
+ if ( sy < 0 ) {
+ y -= sy;
+ sh += sy;
+ sy = 0;
+ }
+ if ( sh + sy > image.height() )
+ sh = image.height() - sy;
+
+ if ( sw <= 0 || sh <= 0 )
+ return;
+
+ bool all = image.rect().intersect(TQRect(sx,sy,sw,sh)) == image.rect();
+ TQImage subimage = all ? image : image.copy(sx,sy,sw,sh);
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ TQRect r( x, y, subimage.width(), subimage.height() );
+ param[0].rect = &r;
+ param[1].image = &subimage;
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc )
+ return;
+#elif defined (TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawImage, this, param );
+ return;
+#elif defined(TQ_WS_MAC)
+ if(!pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() )
+ return;
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd )
+ return;
+#endif
+ }
+
+ TQPixmap pm;
+ pm.convertFromImage( subimage, conversionFlags );
+ drawPixmap( x, y, pm );
+}
+
+/*!
+ \overload void TQPainter::drawImage( const TQPoint &p, const TQImage &i, int conversion_flags )
+
+ Draws the image \a i at point \a p.
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a
+ conversion_flags to specify how you'd prefer this to happen.
+
+ \sa TQt::ImageConversionFlags
+*/
+void TQPainter::drawImage( const TQPoint & p, const TQImage & i,
+ int conversion_flags )
+{
+ drawImage(p, i, i.rect(), conversion_flags);
+}
+
+#if !defined(TQT_NO_IMAGE_TRANSFORMATION) || !defined(TQT_NO_IMAGE_SMOOTHSCALE)
+
+/*!
+ \overload
+
+ Draws the image \a i into the rectangle \a r. The image will be
+ scaled to fit the rectangle if image and rectangle dimensions
+ differ.
+*/
+void TQPainter::drawImage( const TQRect &r, const TQImage &i )
+{
+ int rw = r.width();
+ int rh = r.height();
+ int iw= i.width();
+ int ih = i.height();
+ if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 )
+ return;
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ param[0].rect = &r;
+ param[1].image = &i;
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc )
+ return;
+#elif defined(TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawImage, this, param );
+ return;
+#elif defined(TQ_WS_MAC)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() )
+ return;
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd )
+ return;
+#endif
+ }
+
+
+ bool scale = ( rw != iw || rh != ih );
+ float scaleX = (float)rw/(float)iw;
+ float scaleY = (float)rh/(float)ih;
+ bool smooth = ( scaleX < 1.5 || scaleY < 1.5 );
+
+ TQImage img = scale
+ ? (
+#if defined(TQT_NO_IMAGE_TRANSFORMATION)
+ i.smoothScale( rw, rh )
+#elif defined(TQT_NO_IMAGE_SMOOTHSCALE)
+ i.scale( rw, rh )
+#else
+ smooth ? i.smoothScale( rw, rh ) : i.scale( rw, rh )
+#endif
+ )
+ : i;
+
+ drawImage( r.x(), r.y(), img );
+}
+
+#endif
+
+
+void bitBlt( TQPaintDevice *dst, int dx, int dy,
+ const TQImage *src, int sx, int sy, int sw, int sh,
+ int conversion_flags )
+{
+ TQPixmap tmp;
+ if ( sx == 0 && sy == 0
+ && (sw<0 || sw==src->width()) && (sh<0 || sh==src->height()) )
+ {
+ tmp.convertFromImage( *src, conversion_flags );
+ } else {
+ tmp.convertFromImage( src->copy( sx, sy, sw, sh, conversion_flags),
+ conversion_flags );
+ }
+ bitBlt( dst, dx, dy, &tmp );
+}
+
+
+/*!
+ \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm, const TQPoint &sp )
+
+ Draws a tiled pixmap, \a pm, inside rectangle \a r with its origin
+ at point \a sp.
+*/
+
+/*!
+ \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm )
+
+ Draws a tiled pixmap, \a pm, inside rectangle \a r.
+*/
+
+/*!
+ \overload void TQPainter::fillRect( const TQRect &r, const TQBrush &brush )
+
+ Fills the rectangle \a r using brush \a brush.
+*/
+
+/*!
+ \fn void TQPainter::eraseRect( int x, int y, int w, int h )
+
+ Erases the area inside \a x, \a y, \a w, \a h. Equivalent to
+ \c{fillRect( x, y, w, h, backgroundColor() )}.
+*/
+
+/*!
+ \overload void TQPainter::eraseRect( const TQRect &r )
+
+ Erases the area inside the rectangle \a r.
+*/
+
+/*!
+ \fn TQPainter::drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto )
+
+ \overload
+
+ Draws the given text at position \a x, \a y. If \a len is -1 (the
+ default) all the text is drawn, otherwise the first \a len
+ characters are drawn. The text's direction is given by \a dir.
+
+ \sa TQPainter::TextDirection
+*/
+
+/*!
+ \fn void TQPainter::drawText( int x, int y, int w, int h, int flags,
+ const TQString&, int len = -1, TQRect *br=0,
+ TQTextParag **internal=0 )
+
+ \overload
+
+ Draws the given text within the rectangle starting at \a x, \a y,
+ with width \a w and height \a h. If \a len is -1 (the default) all
+ the text is drawn, otherwise the first \a len characters are
+ drawn. The text's flags that are given in the \a flags parameter
+ are \l{TQt::AlignmentFlags} and \l{TQt::TextFlags} OR'd together. \a
+ br (if not null) is set to the actual bounding rectangle of the
+ output. The \a internal parameter is for internal use only.
+*/
+
+/*!
+ \fn void TQPainter::drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto );
+
+ \overload
+
+ Draws the text at the given point.
+
+ \sa TQPainter::TextDirection
+*/
+
+/*
+ Draws the text in \a s at point \a p. If \a len is -1 the entire
+ string is drawn, otherwise just the first \a len characters. The
+ text's direction is specified by \a dir.
+*/
+
+
+/*!
+ \fn void TQPainter::drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto );
+
+ \overload
+
+ Draws the text from position \a pos, at point \a (x, y). If \a len is
+ -1 the entire string is drawn, otherwise just the first \a len
+ characters. The text's direction is specified by \a dir.
+*/
+
+/*!
+ \fn void TQPainter::drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto );
+
+ Draws the text from position \a pos, at point \a p. If \a len is
+ -1 the entire string is drawn, otherwise just the first \a len
+ characters. The text's direction is specified by \a dir.
+
+ Note that the meaning of \e y is not the same for the two
+ drawText() varieties. For overloads that take a simple \e x, \e y
+ pair (or a point), the \e y value is the text's baseline; for
+ overloads that take a rectangle, \e rect.y() is the top of the
+ rectangle and the text is aligned within that rectangle in
+ accordance with the tqalignment flags.
+
+ \sa TQPainter::TextDirection
+*/
+
+/*!
+ \fn void TQPainter::tqdrawTextItem(const TQPoint &, const TQTextItem &, int)
+ \internal
+*/
+
+static inline void fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ if ( *w < 0 ) {
+ *w = -*w + 2;
+ *x -= *w - 1;
+ }
+ if ( *h < 0 ) {
+ *h = -*h + 2;
+ *y -= *h - 1;
+ }
+}
+void TQPainter::fix_neg_rect( int *x, int *y, int *w, int *h )
+{
+ ::fix_neg_rect(x,y,w,h);
+}
+
+//
+// The drawText function takes two special parameters; 'internal' and 'brect'.
+//
+// The 'internal' parameter tqcontains a pointer to an array of encoded
+// information that keeps internal tqgeometry data.
+// If the drawText function is called repeatedly to display the same text,
+// it makes sense to calculate text width and linebreaks the first time,
+// and use these parameters later to print the text because we save a lot of
+// CPU time.
+// The 'internal' parameter will not be used if it is a null pointer.
+// The 'internal' parameter will be generated if it is not null, but points
+// to a null pointer, i.e. internal != 0 && *internal == 0.
+// The 'internal' parameter will be used if it tqcontains a non-null pointer.
+//
+// If the 'brect parameter is a non-null pointer, then the bounding rectangle
+// of the text will be returned in 'brect'.
+//
+
+/*!
+ \overload
+
+ Draws at most \a len characters from \a str in the rectangle \a r.
+
+ This function draws formatted text. The \a tf text format is
+ really of type \l TQt::AlignmentFlags and \l TQt::TextFlags OR'd
+ together.
+
+ Horizontal tqalignment defaults to AlignAuto and vertical tqalignment
+ defaults to AlignTop.
+
+ \a brect (if not null) is set to the actual bounding rectangle of
+ the output. \a internal is, yes, internal.
+
+ \sa boundingRect()
+*/
+
+void TQPainter::drawText( const TQRect &r, int tf,
+ const TQString& str, int len, TQRect *brect,
+ TQTextParag **internal )
+{
+ if ( !isActive() )
+ return;
+ if ( len < 0 )
+ len = str.length();
+ if ( len == 0 ) // empty string
+ return;
+
+ if ( testf(DirtyFont|ExtDev) ) {
+ if ( testf(DirtyFont) )
+ updateFont();
+ if ( testf(ExtDev) && (tf & DontPrint) == 0 ) {
+ TQPDevCmdParam param[3];
+ TQString newstr = str;
+ newstr.truncate( len );
+ param[0].rect = &r;
+ param[1].ival = tf;
+ param[2].str = &newstr;
+ if ( pdev->devType() != TQInternal::Printer ) {
+#if defined(TQ_WS_WIN)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted,
+ this, param) ||
+ !hdc )
+ return; // TQPrinter wants PdcDrawText2
+#elif defined(TQ_WS_TQWS)
+ pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, this, param);
+ return;
+#elif defined(TQ_WS_MAC)
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, this, param) ||
+ !pdev->handle())
+ return; // TQPrinter wants PdcDrawText2
+#else
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted,
+ this, param) ||
+ !hd )
+ return; // TQPrinter wants PdcDrawText2
+#endif
+ }
+ }
+ }
+
+ qt_format_text(font(), r, tf, str, len, brect,
+ tabstops, tabarray, tabarraylen, internal, this);
+}
+
+//#define TQT_FORMAT_TEXT_DEBUG
+
+#define TQChar_linesep TQChar(0x2028U)
+
+void qt_format_text( const TQFont& font, const TQRect &_r,
+ int tf, const TQString& str, int len, TQRect *brect,
+ int tabstops, int* tabarray, int tabarraylen,
+ TQTextParag **, TQPainter* painter )
+{
+ // we need to copy r here to protect against the case (&r == brect).
+ TQRect r( _r );
+
+ bool dontclip = (tf & TQt::DontClip) == TQt::DontClip;
+ bool wordbreak = (tf & TQt::WordBreak) == TQt::WordBreak;
+ bool singleline = (tf & TQt::SingleLine) == TQt::SingleLine;
+ bool showprefix = (tf & TQt::ShowPrefix) == TQt::ShowPrefix;
+ bool noaccel = ( tf & TQt::NoAccel ) == TQt::NoAccel;
+
+ bool isRightToLeft = str.isRightToLeft();
+ if ( ( tf & TQt::AlignHorizontal_Mask ) == TQt::AlignAuto )
+ tf |= isRightToLeft ? TQt::AlignRight : TQt::AlignLeft;
+
+ bool expandtabs = ( (tf & TQt::ExpandTabs) &&
+ ( ( (tf & TQt::AlignLeft) && !isRightToLeft ) ||
+ ( (tf & TQt::AlignRight) && isRightToLeft ) ) );
+
+ if ( !painter )
+ tf |= TQt::DontPrint;
+
+ int maxUnderlines = 0;
+ int numUnderlines = 0;
+ int underlinePositionStack[32];
+ int *underlinePositions = underlinePositionStack;
+
+ TQFont fnt(painter ? (painter->pfont ? *painter->pfont : painter->cfont) : font);
+ TQFontMetrics fm( fnt );
+
+ TQString text = str;
+ // str.setLength() always does a deep copy, so the tqreplacement
+ // code below is safe.
+ text.setLength( len );
+ // compatible behaviour to the old implementation. Replace
+ // tabs by spaces
+ TQChar *chr = (TQChar*)text.tqunicode();
+ const TQChar *end = chr + len;
+ bool haveLineSep = FALSE;
+ while ( chr != end ) {
+ if ( *chr == '\r' || ( singleline && *chr == '\n' ) ) {
+ *chr = ' ';
+ } else if ( *chr == '\n' ) {
+ *chr = TQChar_linesep;
+ haveLineSep = TRUE;
+ } else if ( *chr == '&' ) {
+ ++maxUnderlines;
+ }
+ ++chr;
+ }
+ if ( !expandtabs ) {
+ chr = (TQChar*)text.tqunicode();
+ while ( chr != end ) {
+ if ( *chr == '\t' )
+ *chr = ' ';
+ ++chr;
+ }
+ } else if (!tabarraylen && !tabstops) {
+ tabstops = fm.width('x')*8;
+ }
+
+ if ( noaccel || showprefix ) {
+ if ( maxUnderlines > 32 )
+ underlinePositions = new int[maxUnderlines];
+ TQChar *cout = (TQChar*)text.tqunicode();
+ TQChar *cin = cout;
+ int l = len;
+ while ( l ) {
+ if ( *cin == '&' ) {
+ ++cin;
+ --l;
+ if ( !l )
+ break;
+ if ( *cin != '&' )
+ underlinePositions[numUnderlines++] = cout - text.tqunicode();
+ }
+ *cout = *cin;
+ ++cout;
+ ++cin;
+ --l;
+ }
+ uint newlen = cout - text.tqunicode();
+ if ( newlen != text.length())
+ text.setLength( newlen );
+ }
+
+ // no need to do extra work for underlines if we don't paint
+ if ( tf & TQt::DontPrint )
+ numUnderlines = 0;
+
+ int height = 0;
+ int left = r.width();
+ int right = 0;
+
+ TQTextLayout textLayout( text, fnt );
+ int rb = TQMAX( 0, -fm.minRightBearing() );
+ int lb = TQMAX( 0, -fm.minLeftBearing() );
+
+ if ( text.isEmpty() ) {
+ height = fm.height();
+ left = right = 0;
+ tf |= TQPainter::DontPrint;
+ } else {
+ textLayout.beginLayout((haveLineSep || expandtabs || wordbreak) ?
+ TQTextLayout::MultiLine :
+ (tf & TQt::DontPrint) ? TQTextLayout::NoBidi : TQTextLayout::SingleLine );
+
+ // break underline chars into items of their own
+ for( int i = 0; i < numUnderlines; i++ ) {
+ textLayout.setBoundary( underlinePositions[i] );
+ textLayout.setBoundary( underlinePositions[i]+1 );
+ }
+
+ int lineWidth = wordbreak ? TQMAX(0, r.width()-rb-lb) : INT_MAX;
+ if(!wordbreak)
+ tf |= TQt::IncludeTrailingSpaces;
+
+ int leading = fm.leading();
+ int asc = fm.ascent();
+ int desc = fm.descent();
+ height = -leading;
+
+ //qDebug("\n\nbeginLayout: lw = %d, rectwidth=%d", lineWidth , r.width());
+ while ( !textLayout.atEnd() ) {
+ height += leading;
+ textLayout.beginLine( lineWidth == INT_MAX ? lineWidth : lineWidth );
+ //qDebug("-----beginLine( %d )-----", lineWidth );
+ bool linesep = FALSE;
+ while ( 1 ) {
+ TQTextItem ti = textLayout.currentItem();
+ //qDebug("item: from=%d, ch=%x", ti.from(), text.tqunicode()[ti.from()].tqunicode() );
+ if ( expandtabs && ti.isTab() ) {
+ int tw = 0;
+ int x = textLayout.widthUsed();
+ if ( tabarraylen ) {
+// qDebug("tabarraylen=%d", tabarraylen );
+ int tab = 0;
+ while ( tab < tabarraylen ) {
+ if ( tabarray[tab] > x ) {
+ tw = tabarray[tab] - x;
+ break;
+ }
+ ++tab;
+ }
+ } else {
+ tw = tabstops - (x % tabstops);
+ }
+ //qDebug("tw = %d", tw );
+ if ( tw )
+ ti.setWidth( tw );
+ }
+ if ( ti.isObject() && text.tqunicode()[ti.from()] == TQChar_linesep )
+ linesep = TRUE;
+
+ if ( linesep || textLayout.addCurrentItem() != TQTextLayout::Ok || textLayout.atEnd() )
+ break;
+ }
+
+ int ascent = asc, descent = desc, lineLeft, lineRight;
+ textLayout.setLineWidth( r.width()-rb-lb );
+ textLayout.endLine( 0, height, tf, &ascent, &descent,
+ &lineLeft, &lineRight );
+ //qDebug("finalizing line: lw=%d ascent = %d, descent=%d lineleft=%d lineright=%d", lineWidth, ascent, descent,lineLeft, lineRight );
+ left = TQMIN( left, lineLeft );
+ right = TQMAX( right, lineRight );
+ height += ascent + descent + 1;
+ if ( linesep )
+ textLayout.nextItem();
+ }
+ }
+
+ int yoff = 0;
+ if ( tf & TQt::AlignBottom )
+ yoff = r.height() - height;
+ else if ( tf & TQt::AlignVCenter )
+ yoff = (r.height() - height)/2;
+
+ if ( brect ) {
+ *brect = TQRect( r.x() + left, r.y() + yoff, right-left + lb+rb, height );
+ //qDebug("br = %d %d %d/%d, left=%d, right=%d", brect->x(), brect->y(), brect->width(), brect->height(), left, right);
+ }
+
+ if (!(tf & TQPainter::DontPrint)) {
+ bool restoreClipping = FALSE;
+ bool painterHasClip = FALSE;
+ TQRegion painterClipRegion;
+ if ( !dontclip ) {
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQRegion reg = painter->xmat * r;
+#else
+ TQRegion reg = r;
+ reg.translate( painter->xlatex, painter->xlatey );
+#endif
+ if ( painter->hasClipping() )
+ reg &= painter->clipRegion();
+
+ painterHasClip = painter->hasClipping();
+ painterClipRegion = painter->clipRegion();
+ restoreClipping = TRUE;
+ painter->setClipRegion( reg );
+ } else {
+ if ( painter->hasClipping() ){
+ painterHasClip = painter->hasClipping();
+ painterClipRegion = painter->clipRegion();
+ restoreClipping = TRUE;
+ painter->setClipping( FALSE );
+ }
+ }
+
+ int cUlChar = 0;
+ int _tf = 0;
+ if (fnt.underline()) _tf |= TQt::Underline;
+ if (fnt.overline()) _tf |= TQt::Overline;
+ if (fnt.strikeOut()) _tf |= TQt::StrikeOut;
+
+ //qDebug("have %d items",textLayout.numItems());
+ for ( int i = 0; i < textLayout.numItems(); i++ ) {
+ TQTextItem ti = textLayout.itemAt( i );
+ //qDebug("Item %d: from=%d, length=%d, space=%d x=%d", i, ti.from(), ti.length(), ti.isSpace(), ti.x() );
+ if ( ti.isTab() || ti.isObject() )
+ continue;
+ int textFlags = _tf;
+ if ( !noaccel && numUnderlines > cUlChar && ti.from() == underlinePositions[cUlChar] ) {
+ textFlags |= TQt::Underline;
+ cUlChar++;
+ }
+#if defined(TQ_WS_X11) || defined(TQ_WS_TQWS)
+ if ( painter->bg_mode == TQt::OpaqueMode ) {
+ int h = ti.ascent() + ti.descent() + 1;
+ if (ti.y() + h < height)
+ // don't add leading to last line
+ h += fm.leading();
+ qt_draw_background( painter, r.x()+lb + ti.x(), r.y() + yoff + ti.y() - ti.ascent(),
+ ti.width(), h);
+ }
+#endif
+ painter->tqdrawTextItem( r.x()+lb, r.y() + yoff, ti, textFlags );
+ }
+
+ if ( restoreClipping ) {
+ painter->setClipRegion( painterClipRegion );
+ painter->setClipping( painterHasClip );
+ }
+ }
+
+ if ( underlinePositions != underlinePositionStack )
+ delete [] underlinePositions;
+}
+
+/*!
+ \overload
+
+ Returns the bounding rectangle of the aligned text that would be
+ printed with the corresponding drawText() function using the first
+ \a len characters from \a str if \a len is > -1, or the whole of
+ \a str if \a len is -1. The drawing, and hence the bounding
+ rectangle, is constrained to the rectangle \a r, or to the
+ rectangle required to draw the text, whichever is the larger.
+
+ The \a internal parameter should not be used.
+
+ \sa drawText(), fontMetrics(), TQFontMetrics::boundingRect(), TQt::TextFlags
+*/
+
+TQRect TQPainter::boundingRect( const TQRect &r, int flags,
+ const TQString& str, int len, TQTextParag **internal )
+{
+ TQRect brect;
+ if ( str.isEmpty() )
+ brect.setRect( r.x(),r.y(), 0,0 );
+ else
+ drawText( r, flags | DontPrint, str, len, &brect, internal );
+ return brect;
+}
+
+/*!
+ \fn TQRect TQPainter::boundingRect( int x, int y, int w, int h, int flags, const TQString&, int len = -1, TQTextParag **intern=0 );
+
+ Returns the bounding rectangle of the aligned text that would be
+ printed with the corresponding drawText() function using the first
+ \a len characters of the string if \a len is > -1, or the whole of
+ the string if \a len is -1. The drawing, and hence the bounding
+ rectangle, is constrained to the rectangle that begins at point \a
+ (x, y) with width \a w and hight \a h, or to the
+ rectangle required to draw the text, whichever is the larger.
+
+ The \a flags argument is
+ the bitwise OR of the following flags:
+ \table
+ \header \i Flag \i Meaning
+ \row \i \c AlignAuto \i aligns according to the language, usually left.
+ \row \i \c AlignLeft \i aligns to the left border.
+ \row \i \c AlignRight \i aligns to the right border.
+ \row \i \c AlignHCenter \i aligns horizontally centered.
+ \row \i \c AlignTop \i aligns to the top border.
+ \row \i \c AlignBottom \i aligns to the bottom border.
+ \row \i \c AlignVCenter \i aligns vertically centered.
+ \row \i \c AlignCenter \i (== \c AlignHCenter | \c AlignVCenter).
+ \row \i \c SingleLine \i ignores newline characters in the text.
+ \row \i \c ExpandTabs \i expands tabs.
+ \row \i \c ShowPrefix \i interprets "&x" as "<u>x</u>".
+ \row \i \c WordBreak \i breaks the text to fit the rectangle.
+ \endtable
+
+ Horizontal tqalignment defaults to \c AlignLeft and vertical
+ tqalignment defaults to \c AlignTop.
+
+ If several of the horizontal or several of the vertical tqalignment flags
+ are set, the resulting tqalignment is undefined.
+
+ The \a intern parameter should not be used.
+
+ \sa TQt::TextFlags
+*/
+
+
+
+/*****************************************************************************
+ TQPen member functions
+ *****************************************************************************/
+
+/*!
+ \class TQPen tqpen.h
+ \brief The TQPen class defines how a TQPainter should draw lines and outlines
+ of tqshapes.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+ \mainclass
+
+ A pen has a style, width, color, cap style and join style.
+
+ The pen style defines the line type. The default pen style is \c
+ TQt::SolidLine. Setting the style to \c NoPen tells the painter to
+ not draw lines or outlines.
+
+ When drawing 1 pixel wide diagonal lines you can either use a very
+ fast algorithm (specified by a line width of 0, which is the
+ default), or a slower but more accurate algorithm (specified by a
+ line width of 1). For horizontal and vertical lines a line width
+ of 0 is the same as a line width of 1. The cap and join style have
+ no effect on 0-width lines.
+
+ The pen color defines the color of lines and text. The default
+ line color is black. The TQColor documentation lists predefined
+ colors.
+
+ The cap style defines how the end points of lines are drawn. The
+ join style defines how the joins between two lines are drawn when
+ multiple connected lines are drawn (TQPainter::drawPolyline()
+ etc.). The cap and join styles only apply to wide lines, i.e. when
+ the width is 1 or greater.
+
+ Use the TQBrush class to specify fill styles.
+
+ Example:
+ \code
+ TQPainter painter;
+ TQPen pen( red, 2 ); // red solid line, 2 pixels wide
+ painter.begin( &anyPaintDevice ); // paint something
+ painter.setPen( pen ); // set the red, wide pen
+ painter.drawRect( 40,30, 200,100 ); // draw a rectangle
+ painter.setPen( blue ); // set blue pen, 0 pixel width
+ painter.drawLine( 40,30, 240,130 ); // draw a diagonal in rectangle
+ painter.end(); // painting done
+ \endcode
+
+ See the \l TQt::PenStyle enum type for a complete list of pen
+ styles.
+
+ With reference to the end points of lines, for wide (non-0-width)
+ pens it depends on the cap style whether the end point is drawn or
+ not. TQPainter will try to make sure that the end point is drawn
+ for 0-width pens, but this cannot be absolutely guaranteed because
+ the underlying drawing engine is free to use any (typically
+ accelerated) algorithm for drawing 0-width lines. On all tested
+ systems, however, the end point of at least all non-diagonal lines
+ are drawn.
+
+ A pen's color(), width(), style(), capStyle() and joinStyle() can
+ be set in the constructor or later with setColor(), setWidth(),
+ setStyle(), setCapStyle() and setJoinStyle(). Pens may also be
+ compared and streamed.
+
+ \img pen-styles.png Pen styles
+
+ \sa TQPainter, TQPainter::setPen()
+*/
+
+
+/*!
+ \internal
+ Initializes the pen.
+*/
+
+void TQPen::init( const TQColor &color, uint width, uint linestyle )
+{
+ data = new TQPenData;
+ TQ_CHECK_PTR( data );
+ data->style = (PenStyle)(linestyle & MPenStyle);
+ data->width = width;
+ data->color = color;
+ data->linest = linestyle;
+}
+
+/*!
+ Constructs a default black solid line pen with 0 width, which
+ renders lines 1 pixel wide (fast diagonals).
+*/
+
+TQPen::TQPen()
+{
+ init( TQt::black, 0, SolidLine ); // default pen
+}
+
+/*!
+ Constructs a black pen with 0 width (fast diagonals) and style \a
+ style.
+
+ \sa setStyle()
+*/
+
+TQPen::TQPen( PenStyle style )
+{
+ init( TQt::black, 0, style );
+}
+
+/*!
+ Constructs a pen with the specified \a color, \a width and \a
+ style.
+
+ \sa setWidth(), setStyle(), setColor()
+*/
+
+TQPen::TQPen( const TQColor &color, uint width, PenStyle style )
+{
+ init( color, width, style );
+}
+
+/*!
+ Constructs a pen with the specified color \a cl and width \a w.
+ The pen style is set to \a s, the pen cap style to \a c and the
+ pen join style to \a j.
+
+ A line width of 0 will produce a 1 pixel wide line using a fast
+ algorithm for diagonals. A line width of 1 will also produce a 1
+ pixel wide line, but uses a slower more accurate algorithm for
+ diagonals. For horizontal and vertical lines a line width of 0 is
+ the same as a line width of 1. The cap and join style have no
+ effect on 0-width lines.
+
+ \sa setWidth(), setStyle(), setColor()
+*/
+
+TQPen::TQPen( const TQColor &cl, uint w, PenStyle s, PenCapStyle c,
+ PenJoinStyle j )
+{
+ init( cl, w, s | c | j );
+}
+
+/*!
+ Constructs a pen that is a copy of \a p.
+*/
+
+TQPen::TQPen( const TQPen &p )
+{
+ data = p.data;
+ data->ref();
+}
+
+/*!
+ Destroys the pen.
+*/
+
+TQPen::~TQPen()
+{
+ if ( data->deref() )
+ delete data;
+}
+
+
+/*!
+ Detaches from shared pen data to make sure that this pen is the
+ only one referring the data.
+
+ If multiple pens share common data, this pen dereferences the data
+ and gets a copy of the data. Nothing is done if there is just a
+ single reference.
+*/
+
+void TQPen::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+}
+
+
+/*!
+ Assigns \a p to this pen and returns a reference to this pen.
+*/
+
+TQPen &TQPen::operator=( const TQPen &p )
+{
+ p.data->ref();
+ if ( data->deref() )
+ delete data;
+ data = p.data;
+ return *this;
+}
+
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the pen.
+*/
+
+TQPen TQPen::copy() const
+{
+ TQPen p( data->color, data->width, data->style, capStyle(), joinStyle() );
+ return p;
+}
+
+
+/*!
+ \fn PenStyle TQPen::style() const
+
+ Returns the pen style.
+
+ \sa setStyle()
+*/
+
+/*!
+ Sets the pen style to \a s.
+
+ See the \l TQt::PenStyle documentation for a list of all the
+ styles.
+
+ \warning On Mac OS X the style setting (other than \c NoPen and \c
+ SolidLine) have no effect as they are not implemented by the
+ underlying system.
+
+ \warning On Windows 95/98, the style setting (other than \c NoPen
+ and \c SolidLine) has no effect for lines with width greater than
+ 1.
+
+ \sa style()
+*/
+
+void TQPen::setStyle( PenStyle s )
+{
+ if ( data->style == s )
+ return;
+ detach();
+ data->style = s;
+ data->linest = (data->linest & ~MPenStyle) | s;
+}
+
+
+/*!
+ \fn uint TQPen::width() const
+
+ Returns the pen width.
+
+ \sa setWidth()
+*/
+
+/*!
+ Sets the pen width to \a w.
+
+ A line width of 0 will produce a 1 pixel wide line using a fast
+ algorithm for diagonals. A line width of 1 will also produce a 1
+ pixel wide line, but uses a slower more accurate algorithm for
+ diagonals. For horizontal and vertical lines a line width of 0 is
+ the same as a line width of 1. The cap and join style have no
+ effect on 0-width lines.
+
+ \sa width()
+*/
+
+void TQPen::setWidth( uint w )
+{
+ if ( data->width == w )
+ return;
+ detach();
+ data->width = w;
+}
+
+
+/*!
+ Returns the pen's cap style.
+
+ \sa setCapStyle()
+*/
+TQt::PenCapStyle TQPen::capStyle() const
+{
+ return (PenCapStyle)(data->linest & MPenCapStyle);
+}
+
+/*!
+ Sets the pen's cap style to \a c.
+
+ The default value is \c FlatCap. The cap style has no effect on
+ 0-width pens.
+
+ \img pen-cap-styles.png Pen Cap Styles
+
+ \warning On Windows 95/98 and Macintosh, the cap style setting has
+ no effect. Wide lines are rendered as if the cap style was \c
+ SquareCap.
+
+ \sa capStyle()
+*/
+
+void TQPen::setCapStyle( PenCapStyle c )
+{
+ if ( (data->linest & MPenCapStyle) == c )
+ return;
+ detach();
+ data->linest = (data->linest & ~MPenCapStyle) | c;
+}
+
+/*!
+ Returns the pen's join style.
+
+ \sa setJoinStyle()
+*/
+TQt::PenJoinStyle TQPen::joinStyle() const
+{
+ return (PenJoinStyle)(data->linest & MPenJoinStyle);
+}
+
+/*!
+ Sets the pen's join style to \a j.
+
+ The default value is \c MiterJoin. The join style has no effect on
+ 0-width pens.
+
+ \img pen-join-styles.png Pen Join Styles
+
+ \warning On Windows 95/98 and Macintosh, the join style setting
+ has no effect. Wide lines are rendered as if the join style was \c
+ BevelJoin.
+
+ \sa joinStyle()
+*/
+
+void TQPen::setJoinStyle( PenJoinStyle j )
+{
+ if ( (data->linest & MPenJoinStyle) == j )
+ return;
+ detach();
+ data->linest = (data->linest & ~MPenJoinStyle) | j;
+}
+
+/*!
+ \fn const TQColor &TQPen::color() const
+
+ Returns the pen color.
+
+ \sa setColor()
+*/
+
+/*!
+ Sets the pen color to \a c.
+
+ \sa color()
+*/
+
+void TQPen::setColor( const TQColor &c )
+{
+ detach();
+ data->color = c;
+}
+
+
+/*!
+ \fn bool TQPen::operator!=( const TQPen &p ) const
+
+ Returns TRUE if the pen is different from \a p; otherwise returns
+ FALSE.
+
+ Two pens are different if they have different styles, widths or
+ colors.
+
+ \sa operator==()
+*/
+
+/*!
+ Returns TRUE if the pen is equal to \a p; otherwise returns FALSE.
+
+ Two pens are equal if they have equal styles, widths and colors.
+
+ \sa operator!=()
+*/
+
+bool TQPen::operator==( const TQPen &p ) const
+{
+ return (p.data == data) || (p.data->linest == data->linest &&
+ p.data->width == data->width && p.data->color == data->color);
+}
+
+
+/*****************************************************************************
+ TQPen stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQPen
+
+ Writes the pen \a p to the stream \a s and returns a reference to
+ the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQPen &p )
+{
+ // ### width() should not be restricted to 8-bit values
+ if ( s.version() < 3 )
+ return s << (TQ_UINT8)p.style() << (TQ_UINT8)p.width() << p.color();
+ else
+ return s << (TQ_UINT8)( p.style() | p.capStyle() | p.joinStyle() )
+ << (TQ_UINT8)p.width() << p.color();
+}
+
+/*!
+ \relates TQPen
+
+ Reads a pen from the stream \a s into \a p and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQPen &p )
+{
+ TQ_UINT8 style, width;
+ TQColor color;
+ s >> style;
+ s >> width;
+ s >> color;
+ p = TQPen( color, (uint)width, (TQt::PenStyle)style ); // owl
+ return s;
+}
+#endif //TQT_NO_DATASTREAM
+
+/*****************************************************************************
+ TQBrush member functions
+ *****************************************************************************/
+
+/*!
+ \class TQBrush tqbrush.h
+
+ \brief The TQBrush class defines the fill pattern of tqshapes drawn by a TQPainter.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+
+ A brush has a style and a color. One of the brush styles is a
+ custom pattern, which is defined by a TQPixmap.
+
+ The brush style defines the fill pattern. The default brush style
+ is \c NoBrush (depending on how you construct a brush). This style
+ tells the painter to not fill tqshapes. The standard style for
+ filling is \c SolidPattern.
+
+ The brush color defines the color of the fill pattern. The TQColor
+ documentation lists the predefined colors.
+
+ Use the TQPen class for specifying line/outline styles.
+
+ Example:
+ \code
+ TQPainter painter;
+ TQBrush brush( yellow ); // yellow solid pattern
+ painter.begin( &anyPaintDevice ); // paint something
+ painter.setBrush( brush ); // set the yellow brush
+ painter.setPen( NoPen ); // do not draw outline
+ painter.drawRect( 40,30, 200,100 ); // draw filled rectangle
+ painter.setBrush( NoBrush ); // do not fill
+ painter.setPen( black ); // set black pen, 0 pixel width
+ painter.drawRect( 10,10, 30,20 ); // draw rectangle outline
+ painter.end(); // painting done
+ \endcode
+
+ See the setStyle() function for a complete list of brush styles.
+
+ \img brush-styles.png Brush Styles
+
+ \sa TQPainter, TQPainter::setBrush(), TQPainter::setBrushOrigin()
+*/
+
+inline TQPixmap *TQBrush::pixmap() const {
+ if (style() != Qt::TexturePattern)
+ return 0;
+ QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d.data());
+ QPixmap &pixmap = data->pixmap();
+ return pixmap.isNull() ? 0 : &pixmap;
+}
+
+/*!
+ \internal
+ Initializes the brush.
+*/
+
+void TQBrush::init( const TQColor &color, BrushStyle style )
+{
+ data = new TQBrushData;
+ TQ_CHECK_PTR( data );
+ data->style = style;
+ data->color = color;
+ data->pixmap = 0;
+}
+
+/*!
+ Constructs a default black brush with the style \c NoBrush (will
+ not fill tqshapes).
+*/
+
+TQBrush::TQBrush()
+{
+ static TQBrushData* defBrushData = 0;
+ if ( !defBrushData ) {
+ static TQSharedCleanupHandler<TQBrushData> defBrushCleanup;
+ defBrushData = new TQBrushData;
+ defBrushData->style = NoBrush;
+ defBrushData->color = TQt::black;
+ defBrushData->pixmap = 0;
+ defBrushCleanup.set( &defBrushData );
+ }
+ data = defBrushData;
+ data->ref();
+}
+
+/*!
+ Constructs a black brush with the style \a style.
+
+ \sa setStyle()
+*/
+
+TQBrush::TQBrush( BrushStyle style )
+{
+ init( TQt::black, style );
+}
+
+/*!
+ Constructs a brush with the color \a color and the style \a style.
+
+ \sa setColor(), setStyle()
+*/
+
+TQBrush::TQBrush( const TQColor &color, BrushStyle style )
+{
+ init( color, style );
+}
+
+/*!
+ Constructs a brush with the color \a color and a custom pattern
+ stored in \a pixmap.
+
+ The color will only have an effect for monochrome pixmaps, i.e.
+ for TQPixmap::depth() == 1.
+
+ Pixmap brushes are currently not supported when printing on X11.
+
+ \sa setColor(), setPixmap()
+*/
+
+TQBrush::TQBrush( const TQColor &color, const TQPixmap &pixmap )
+{
+ init( color, CustomPattern );
+ setPixmap( pixmap );
+}
+
+/*!
+ Constructs a brush that is a \link shclass.html shallow
+ copy\endlink of \a b.
+*/
+
+TQBrush::TQBrush( const TQBrush &b )
+{
+ data = b.data;
+ data->ref();
+}
+
+/*!
+ Destroys the brush.
+*/
+
+TQBrush::~TQBrush()
+{
+ if ( data->deref() ) {
+ delete data->pixmap;
+ delete data;
+ }
+}
+
+
+/*!
+ Detaches from shared brush data to make sure that this brush is
+ the only one referring the data.
+
+ If multiple brushes share common data, this brush dereferences the
+ data and gets a copy of the data. Nothing is done if there is just
+ a single reference.
+*/
+
+void TQBrush::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+}
+
+
+/*!
+ Assigns \a b to this brush and returns a reference to this brush.
+*/
+
+TQBrush &TQBrush::operator=( const TQBrush &b )
+{
+ b.data->ref(); // beware of b = b
+ if ( data->deref() ) {
+ delete data->pixmap;
+ delete data;
+ }
+ data = b.data;
+ return *this;
+}
+
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the brush.
+*/
+
+TQBrush TQBrush::copy() const
+{
+ if ( data->style == CustomPattern ) { // brush has pixmap
+ TQBrush b( data->color, *data->pixmap );
+ return b;
+ } else { // brush has std pattern
+ TQBrush b( data->color, data->style );
+ return b;
+ }
+}
+
+
+/*!
+ \fn BrushStyle TQBrush::style() const
+
+ Returns the brush style.
+
+ \sa setStyle()
+*/
+
+/*!
+ Sets the brush style to \a s.
+
+ The brush styles are:
+ \table
+ \header \i Pattern \i Meaning
+ \row \i NoBrush \i will not fill tqshapes (default).
+ \row \i SolidPattern \i solid (100%) fill pattern.
+ \row \i Dense1Pattern \i11 94% fill pattern.
+ \row \i Dense2Pattern \i11 88% fill pattern.
+ \row \i Dense3Pattern \i11 63% fill pattern.
+ \row \i Dense4Pattern \i11 50% fill pattern.
+ \row \i Dense5Pattern \i11 37% fill pattern.
+ \row \i Dense6Pattern \i11 12% fill pattern.
+ \row \i Dense7Pattern \i11 6% fill pattern.
+ \row \i HorPattern \i horizontal lines pattern.
+ \row \i VerPattern \i vertical lines pattern.
+ \row \i CrossPattern \i crossing lines pattern.
+ \row \i BDiagPattern \i diagonal lines (directed /) pattern.
+ \row \i FDiagPattern \i diagonal lines (directed \) pattern.
+ \row \i DiagCrossPattern \i diagonal crossing lines pattern.
+ \row \i CustomPattern \i set when a pixmap pattern is being used.
+ \endtable
+
+ On Windows, dense and custom patterns cannot be transtqparent.
+
+ See the \link #details Detailed Description\endlink for a picture
+ of all the styles.
+
+ \sa style()
+*/
+
+void TQBrush::setStyle( BrushStyle s ) // set brush style
+{
+ if ( data->style == s )
+ return;
+#if defined(TQT_CHECK_RANGE)
+ if ( s == CustomPattern )
+ qWarning( "TQBrush::setStyle: CustomPattern is for internal use" );
+#endif
+ detach();
+ data->style = s;
+}
+
+
+/*!
+ \fn const TQColor &TQBrush::color() const
+
+ Returns the brush color.
+
+ \sa setColor()
+*/
+
+/*!
+ Sets the brush color to \a c.
+
+ \sa color(), setStyle()
+*/
+
+void TQBrush::setColor( const TQColor &c )
+{
+ detach();
+ data->color = c;
+}
+
+
+/*!
+ \fn TQPixmap *TQBrush::pixmap() const
+
+ Returns a pointer to the custom brush pattern, or 0 if no custom
+ brush pattern has been set.
+
+ \sa setPixmap()
+*/
+
+/*!
+ Sets the brush pixmap to \a pixmap. The style is set to \c
+ CustomPattern.
+
+ The current brush color will only have an effect for monochrome
+ pixmaps, i.e. for TQPixmap::depth() == 1.
+
+ Pixmap brushes are currently not supported when printing on X11.
+
+ \sa pixmap(), color()
+*/
+
+void TQBrush::setPixmap( const TQPixmap &pixmap )
+{
+ detach();
+ if ( data->pixmap )
+ delete data->pixmap;
+ if ( pixmap.isNull() ) {
+ data->style = NoBrush;
+ data->pixmap = 0;
+ } else {
+ data->style = CustomPattern;
+ data->pixmap = new TQPixmap( pixmap );
+ if ( data->pixmap->optimization() == TQPixmap::MemoryOptim )
+ data->pixmap->setOptimization( TQPixmap::NormalOptim );
+ }
+}
+
+
+/*!
+ \fn bool TQBrush::operator!=( const TQBrush &b ) const
+
+ Returns TRUE if the brush is different from \a b; otherwise
+ returns FALSE.
+
+ Two brushes are different if they have different styles, colors or
+ pixmaps.
+
+ \sa operator==()
+*/
+
+/*!
+ Returns TRUE if the brush is equal to \a b; otherwise returns
+ FALSE.
+
+ Two brushes are equal if they have equal styles, colors and
+ pixmaps.
+
+ \sa operator!=()
+*/
+
+bool TQBrush::operator==( const TQBrush &b ) const
+{
+ return (b.data == data) || (b.data->style == data->style &&
+ b.data->color == data->color &&
+ b.data->pixmap == data->pixmap);
+}
+
+
+/*!
+ \fn inline double TQPainter::translationX() const
+ \internal
+*/
+
+/*!
+ \fn inline double TQPainter::translationY() const
+ \internal
+*/
+
+
+/*****************************************************************************
+ TQBrush stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQBrush
+
+ Writes the brush \a b to the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQBrush &b )
+{
+ s << (TQ_UINT8)b.style() << b.color();
+ if ( b.style() == TQt::CustomPattern )
+#ifndef TQT_NO_IMAGEIO
+ s << *b.pixmap();
+#else
+ qWarning("No Image Brush I/O");
+#endif
+ return s;
+}
+
+/*!
+ \relates TQBrush
+
+ Reads the brush \a b from the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQBrush &b )
+{
+ TQ_UINT8 style;
+ TQColor color;
+ s >> style;
+ s >> color;
+ if ( style == TQt::CustomPattern ) {
+#ifndef TQT_NO_IMAGEIO
+ TQPixmap pm;
+ s >> pm;
+ b = TQBrush( color, pm );
+#else
+ qWarning("No Image Brush I/O");
+#endif
+ }
+ else
+ b = TQBrush( color, (TQt::BrushStyle)style );
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqpainter.h b/tqtinterface/qt4/src/kernel/tqpainter.h
new file mode 100644
index 0000000..c491f8b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpainter.h
@@ -0,0 +1,1019 @@
+/****************************************************************************
+**
+** Definition of TQPainter class
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPAINTER_H
+#define TQPAINTER_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqcolor.h"
+#include "tqfontmetrics.h"
+#include "tqfontinfo.h"
+#include "tqregion.h"
+#include "tqpen.h"
+#include "tqbrush.h"
+#include "tqpointarray.h"
+#include "tqwmatrix.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqwidget.h"
+#include "tqpaintdevice.h"
+#include <QtGui/qpainter.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class Q_COMPAT_EXPORT TQPainter : public QPainter, virtual public TQt
+{
+public:
+ enum TextDirection {
+ Auto,
+ RTL,
+ LTR
+ };
+
+ enum CoordinateMode { CoordDevice, CoordPainter };
+
+ TQPainter();
+ TQPainter( const QWidget *pdev, bool unclipped = FALSE);
+ TQPainter( QPaintDevice *pdev, bool unclipped = FALSE);
+ TQPainter( QWidget *pdev, const QWidget *w, bool unclipped = FALSE );
+ TQPainter( QPaintDevice *pdev, const QWidget *w, bool unclipped = FALSE );
+
+ void flush();
+ void flush( const TQRegion &region, CoordinateMode cm = CoordDevice );
+
+ void drawRect(const QRect &rect);
+ inline void drawRect(int x1, int y1, int w, int h)
+ { drawRect(QRect(x1, y1, w, h)); }
+
+ void drawRoundRect(const QRect &r, int xround = 25, int yround = 25);
+ inline void drawRoundRect(int x, int y, int w, int h, int xround = 25, int yround = 25)
+ { drawRoundRect(QRect(x, y, w, h), xround, yround); }
+
+ void drawEllipse(const QRect &r);
+ inline void drawEllipse(int x, int y, int w, int h)
+ { drawEllipse(QRect(x, y, w, h)); }
+
+ void drawArc(const QRect &r, int a, int alen);
+ inline void drawArc(int x, int y, int w, int h, int a, int alen)
+ { drawArc(QRect(x, y, w, h), a, alen); }
+
+ void drawPie(const QRect &r, int a, int alen);
+ inline void drawPie(int x, int y, int w, int h, int a, int alen)
+ { drawPie(QRect(x, y, w, h), a, alen); }
+
+ void drawChord(const QRect &r, int a, int alen);
+ inline void drawChord(int x, int y, int w, int h, int a, int alen)
+ { drawChord(QRect(x, y, w, h), a, alen); }
+
+ void drawImage( int x, int y, const TQImage image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, int conversionFlags = 0 );
+ void drawImage( const TQPoint p, const TQImage image, const TQRect sr, int conversionFlags = 0 );
+ void drawImage( const TQPoint p, const TQImage image, int conversion_flags = 0 );
+ void drawImage( const TQRect r, const TQImage image );
+
+ void drawLineSegments(const QPolygon &points, int index = 0, int nlines = -1);
+
+ void setBrush(const QBrush &brush);
+ void setBrush(Qt::BrushStyle style);
+ void setBrush(TQt::BrushStyle style);
+
+ inline void tqdrawPixmap( int x, int y, const TQPixmap &tqpm, int sx=0, int sy=0, int sw=-1, int sh=-1 ) { drawPixmap(x, y, tqpm, sx, sy, sw, sh); }
+
+ TQPoint pos() const;
+
+ // Qt4 requires the QPainter to have a valid QPaintDevice (engine) for boundingRect() to work
+ // So, we create one off-screen!
+ #define TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL \
+ bool neededEngine = FALSE; \
+ if (QPainter::isActive() == 0) { \
+ printf("[WARNING] Painter was inactive when TQPainter::boundingRect was called; this indicates a likely problem in painting within your application (check Qt::WA_PaintOutsidePaintEvent == true)\n\r"); \
+ QImage image(1,1,QImage::Format_RGB32); \
+ neededEngine = TRUE; \
+ QPainter::begin(&image); \
+ }
+
+ #define TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL \
+ if (neededEngine == TRUE) { \
+ QPainter::end(); \
+ }
+
+ QRectF boundingRect(const QRectF &rect, int flags, const QString &text);
+ QRect boundingRect(const QRect &rect, int flags, const QString &text);
+ QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text);
+ QRectF boundingRect(const QRectF &rect, const QString &text, const QTextOption &o = QTextOption());
+
+ TQRect boundingRect(const QRect &rect, int flags, const QString &text, int len);
+ TQRect boundingRect(int x, int y, int w, int h, int flags, const QString &text, int len);
+
+ void drawText(const QPointF &p, const QString &s);
+ void drawText(const QPoint &p, const QString &s);
+ void drawText(int x, int y, const QString &s);
+ void drawText(const QPointF &p, const QString &str, int tf, int justificationPadding);
+ void drawText(const QRectF &r, int flags, const QString &text, QRectF *br=0);
+ void drawText(const QRect &r, int flags, const QString &text, QRect *br=0);
+ void drawText(int x, int y, int w, int h, int flags, const QString &text, QRect *br=0);
+ void drawText(const QRectF &r, const QString &text, const QTextOption &o = QTextOption());
+
+ void drawText( int x, int y, const TQString &s, int len = -1, TextDirection dir = Auto );
+ void drawText( const TQPoint &p, const TQString &s, int len = -1, TextDirection dir = Auto );
+ void drawText( int x, int y, const TQString &s, int pos, int len, TextDirection dir = Auto );
+ void drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir = Auto );
+
+ void drawText(int x, int y, const QString &s, int pos, int len);
+ void drawText(const QPoint &p, const QString &s, int pos, int len);
+ void drawText(int x, int y, const QString &s, int len);
+ void drawText(const QPoint &p, const QString &s, int len);
+ void drawText(const QRect &r, int flags, const QString &str, int len, QRect *br=0);
+ void drawText(int x, int y, int w, int h, int flags, const QString &text, int len, QRect *br=0);
+
+#ifndef TQT_NO_PICTURE
+ void drawPicture( const QPicture );
+ void drawPicture( int x, int y, const QPicture );
+ void drawPicture( const QPoint, const QPicture );
+#endif
+
+ void drawPoints( const TQPointArray& a, int index=0, int npoints=-1 );
+
+ int tabStops() const;
+ void setTabStops( int );
+ int *tabArray() const;
+ void setTabArray( int * );
+
+ TQFontInfo fontInfo() const;
+
+ void map(int x, int y, int *rx, int *ry) const;
+ void map( int, int, int, int, int *, int *, int *, int * ) const;
+ TQPoint xForm(const QPoint &) const; // map virtual -> deviceb
+ TQRect xForm(const QRect &) const;
+// TQPolygon xForm(const QPolygon &) const;
+// TQPolygon xForm(const QPolygon &, int index, int npoints) const;
+ TQPoint xFormDev(const QPoint &) const; // map device -> virtual
+ TQRect xFormDev(const QRect &) const;
+ TQPointArray xForm( const TQPointArray & ) const;
+ TQPointArray xForm( const TQPointArray &, int index, int npoints ) const;
+// TQPolygon xFormDev(const QPolygon &) const;
+// TQPolygon xFormDev(const QPolygon &, int index, int npoints) const;
+ TQPointArray xFormDev( const TQPointArray & ) const;
+ TQPointArray xFormDev( const TQPointArray &, int index, int npoints ) const;
+ qreal translationX() const;
+ qreal translationY() const;
+
+ void resetXForm();
+
+ // [FIXME] The drawWinFocusRect methods below probably need tweaking to exactly match the old Qt3 behaviour
+ void drawWinFocusRect( int x, int y, int w, int h );
+ void drawWinFocusRect( int x, int y, int w, int h, const TQColor &bgColor );
+ void drawWinFocusRect( const TQRect &tqr );
+ void drawWinFocusRect( const TQRect &tqr, const TQColor &bgColor );
+
+// inline const TQWMatrix &tqworldMatrix() const { return (*(static_cast<const TQWMatrix*>(&worldMatrix()))); }
+ const TQWMatrix &tqworldMatrix() const;
+
+ void saveWorldMatrix();
+ void restoreWorldMatrix();
+
+ inline TQPaintDevice *tqdevice() const { return static_cast<TQPaintDevice*>(device()); }
+
+ TQRegion clipRegion( CoordinateMode cm = CoordDevice ) const;
+
+ void setClipRegion( const QRegion &qr, CoordinateMode cm = CoordDevice );
+
+ void setBackgroundColor(const QColor &color);
+ const QColor &backgroundColor() const;
+
+ void setClipRect(const QRectF &qrf, Qt::ClipOperation op = Qt::ReplaceClip);
+ void setClipRect(const QRect &qr, Qt::ClipOperation op = Qt::ReplaceClip);
+ void setClipRect( const TQRect &qr, CoordinateMode cm = CoordDevice );
+ void setClipRect( int x, int y, int w, int h, CoordinateMode cm = CoordDevice );
+
+ inline double m11() const { return deviceTransform().m11(); }
+ inline double m12() const { return deviceTransform().m12(); }
+ inline double m21() const { return deviceTransform().m21(); }
+ inline double m22() const { return deviceTransform().m22(); }
+ inline double dx() const { return deviceTransform().dx(); }
+ inline double dy() const { return deviceTransform().dy(); }
+ inline double im11() const { return deviceTransform().inverted().m11(); }
+ inline double im12() const { return deviceTransform().inverted().m12(); }
+ inline double im21() const { return deviceTransform().inverted().m21(); }
+ inline double im22() const { return deviceTransform().inverted().m22(); }
+ inline double idx() const { return deviceTransform().inverted().dx(); }
+ inline double idy() const { return deviceTransform().inverted().dy(); }
+
+ void moveTo( int x, int y );
+ void moveTo( const TQPoint & );
+ void lineTo( int x, int y );
+ void lineTo( const TQPoint & );
+
+ void tqdrawTextItem( int x, int y, const TQTextItem &ti, int textflags = 0 );
+ void tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags = 0 );
+
+ static void redirect(QPaintDevice *pdev, QPaintDevice *replacement);
+ static TQPaintDevice *redirect(QPaintDevice *pdev);
+
+ TQt::RasterOp rasterOp() const;
+ void setRasterOp( TQt::RasterOp );
+
+ bool tqbegin( QPaintDevice *pdev, bool unclipped = FALSE );
+ bool tqbegin( QPaintDevice *pdev, const QWidget *init, bool unclipped = FALSE );
+
+ inline void tqdrawPolyline(const QPolygon &pa, int index, int npoints = -1) { drawPolyline(pa.constData() + index, npoints == -1 ? pa.size() - index : npoints); }
+ inline void tqdrawPolygon(const QPolygon &pa, bool winding, int index = 0, int npoints = -1) { drawPolygon(pa.constData() + index, npoints == -1 ? pa.size() - index : npoints, winding ? Qt::WindingFill : Qt::OddEvenFill); }
+ inline void tqdrawPolygon(const QPolygonF &polygon, bool winding, int index = 0, int npoints = -1) { drawPolygon(polygon.constData() + index, npoints == -1 ? polygon.size() - index : npoints, winding ? Qt::WindingFill : Qt::OddEvenFill); }
+ inline void tqdrawConvexPolygon(const QPolygonF &polygon, int index, int npoints = -1) { drawConvexPolygon(polygon.constData() + index, npoints == -1 ? polygon.size() - index : npoints); }
+ inline void tqdrawConvexPolygon(const QPolygon &pa, int index, int npoints = -1) { drawConvexPolygon(pa.constData() + index, npoints == -1 ? pa.size() - index : npoints); }
+// static inline void redirect(QPaintDevice *pdev, QPaintDevice *replacement) { setRedirected(pdev, replacement); }
+// static inline TQPaintDevice *redirect(QPaintDevice *pdev) { return const_cast<QPaintDevice*>(redirected(pdev)); }
+ void setWorldXForm(bool enabled);
+ bool hasWorldXForm() const;
+// inline void resetXForm() { resetTransform(); }
+ void setViewXForm(bool enabled);
+ bool hasViewXForm() const;
+
+#ifndef TQT_NO_BEZIER
+ void drawCubicBezier( const TQPointArray &, int index=0 );
+#endif
+
+ // [FIXME]
+ static void initialize();
+ static void cleanup();
+
+ bool has_qwidget;
+ mutable QWidget* qwidget_ptr;
+
+private:
+ QRect adjustedRectangle(const QRect &r);
+ int rectSubtraction() const;
+ uchar rop;
+ enum { IsActive=0x01, ExtDev=0x02, IsStartingUp=0x04, NoCache=0x08,
+ VxF=0x10, WxF=0x20, ClipOn=0x40, SafePolygon=0x80, MonoDev=0x100,
+ DirtyFont=0x200, DirtyPen=0x400, DirtyBrush=0x800,
+ RGBColor=0x1000, FontMet=0x2000, FontInf=0x4000, CtorBegin=0x8000,
+ UsePrivateCx = 0x10000, VolatileDC = 0x20000, TQt2Compat = 0x40000 };
+// uint flags;
+// bool testf( uint b ) const { return (flags&b)!=0; }
+ bool testf( uint b ) const;
+ void drawWinFocusRect( int x, int y, int w, int h, bool xorPaint, const QColor &penColor );
+ void fix_neg_rect( int *x, int *y, int *w, int *h );
+
+ TQPoint current_penpos;
+
+ Q_DISABLE_COPY(TQPainter)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#else // USE_QT4
+
+class TQGfx;
+class TQTextCodec;
+class TQTextParag;
+class TQPaintDevice;
+class TQTextItem;
+#if defined( TQ_WS_MAC )
+class TQMacSavedPortInfo;
+#endif
+class TQPainterPrivate;
+
+#if defined(TQ_WS_TQWS)
+class TQScreen;
+#endif
+
+class TQ_EXPORT TQPainter : public TQt
+{
+public:
+ enum CoordinateMode { CoordDevice, CoordPainter };
+
+ TQPainter();
+ TQPainter( const TQPaintDevice *, bool unclipped = FALSE );
+ TQPainter( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE );
+ ~TQPainter();
+
+ bool begin( const TQPaintDevice *, bool unclipped = FALSE );
+ bool begin( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE );
+ bool end();
+ TQPaintDevice *tqdevice() const;
+
+#ifdef TQ_WS_TQWS
+ TQGfx * internalGfx();
+#ifdef TQT_TQWS_EXPERIMENTAL_SCREENPAINTER
+ bool begin(TQScreen *screen);
+#endif
+#endif
+
+ static void redirect( TQPaintDevice *pdev, TQPaintDevice *tqreplacement );
+ static TQPaintDevice *redirect( TQPaintDevice *pdev );
+
+ bool isActive() const;
+
+ void flush( const TQRegion &region, CoordinateMode cm = CoordDevice );
+ void flush();
+ void save();
+ void restore();
+
+ // Drawing tools
+
+ TQFontMetrics fontMetrics() const;
+ TQFontInfo fontInfo() const;
+
+ const TQFont &font() const;
+ void setFont( const TQFont & );
+ const TQPen &pen() const;
+ void setPen( const TQPen & );
+ void setPen( PenStyle );
+ void setPen( const TQColor & );
+ const TQBrush &brush() const;
+ void setBrush( const TQBrush & );
+ void setBrush( BrushStyle );
+ void setBrush( const TQColor & );
+ TQPoint pos() const;
+
+ // Drawing attributes/modes
+
+ const TQColor &backgroundColor() const;
+ void setBackgroundColor( const TQColor & );
+ BGMode backgroundMode() const;
+ void setBackgroundMode( BGMode );
+ RasterOp rasterOp() const;
+ void setRasterOp( RasterOp );
+ const TQPoint &brushOrigin() const;
+ void setBrushOrigin( int x, int y );
+ void setBrushOrigin( const TQPoint & );
+
+ // Scaling and transformations
+
+// PaintUnit unit() const; // get set painter unit
+// void setUnit( PaintUnit ); // NOT IMPLEMENTED!!!
+
+ bool hasViewXForm() const;
+ bool hasWorldXForm() const;
+
+#ifndef TQT_NO_TRANSFORMATIONS
+ void setViewXForm( bool ); // set xform on/off
+ TQRect window() const; // get window
+ void setWindow( const TQRect & ); // set window
+ void setWindow( int x, int y, int w, int h );
+ TQRect viewport() const; // get viewport
+ void setViewport( const TQRect & ); // set viewport
+ void setViewport( int x, int y, int w, int h );
+
+ void setWorldXForm( bool ); // set world xform on/off
+ const TQWMatrix &tqworldMatrix() const; // get/set world xform matrix
+ void setWorldMatrix( const TQWMatrix &, bool combine=FALSE );
+
+ void saveWorldMatrix();
+ void restoreWorldMatrix();
+
+ void scale( double sx, double sy );
+ void shear( double sh, double sv );
+ void rotate( double a );
+#endif
+ void translate( double dx, double dy );
+ void resetXForm();
+ double translationX() const;
+ double translationY() const;
+
+ TQPoint xForm( const TQPoint & ) const; // map virtual -> tqdevice
+ TQRect xForm( const TQRect & ) const;
+ TQPointArray xForm( const TQPointArray & ) const;
+ TQPointArray xForm( const TQPointArray &, int index, int npoints ) const;
+ TQPoint xFormDev( const TQPoint & ) const; // map tqdevice -> virtual
+ TQRect xFormDev( const TQRect & ) const;
+ TQPointArray xFormDev( const TQPointArray & ) const;
+ TQPointArray xFormDev( const TQPointArray &, int index, int npoints ) const;
+
+ // Clipping
+
+ void setClipping( bool ); // set clipping on/off
+ bool hasClipping() const;
+ TQRegion clipRegion( CoordinateMode = CoordDevice ) const;
+ void setClipRect( const TQRect &, CoordinateMode = CoordDevice ); // set clip rectangle
+ void setClipRect( int x, int y, int w, int h, CoordinateMode = CoordDevice );
+ void setClipRegion( const TQRegion &, CoordinateMode = CoordDevice );// set clip region
+
+ // Graphics drawing functions
+
+ void drawPoint( int x, int y );
+ void drawPoint( const TQPoint & );
+ void drawPoints( const TQPointArray& a,
+ int index=0, int npoints=-1 );
+ void moveTo( int x, int y );
+ void moveTo( const TQPoint & );
+ void lineTo( int x, int y );
+ void lineTo( const TQPoint & );
+ void drawLine( int x1, int y1, int x2, int y2 );
+ void drawLine( const TQPoint &, const TQPoint & );
+ void drawRect( int x, int y, int w, int h );
+ void drawRect( const TQRect & );
+ void drawWinFocusRect( int x, int y, int w, int h );
+ void drawWinFocusRect( int x, int y, int w, int h,
+ const TQColor &bgColor );
+ void drawWinFocusRect( const TQRect & );
+ void drawWinFocusRect( const TQRect &,
+ const TQColor &bgColor );
+ void drawRoundRect( int x, int y, int w, int h, int = 25, int = 25 );
+ void drawRoundRect( const TQRect &, int = 25, int = 25 );
+ void drawEllipse( int x, int y, int w, int h );
+ void drawEllipse( const TQRect & );
+ void drawArc( int x, int y, int w, int h, int a, int alen );
+ void drawArc( const TQRect &, int a, int alen );
+ void drawPie( int x, int y, int w, int h, int a, int alen );
+ void drawPie( const TQRect &, int a, int alen );
+ void drawChord( int x, int y, int w, int h, int a, int alen );
+ void drawChord( const TQRect &, int a, int alen );
+ void drawLineSegments( const TQPointArray &,
+ int index=0, int nlines=-1 );
+ void drawPolyline( const TQPointArray &,
+ int index=0, int npoints=-1 );
+ void drawPolygon( const TQPointArray &, bool winding=FALSE,
+ int index=0, int npoints=-1 );
+ void drawConvexPolygon( const TQPointArray &,
+ int index=0, int npoints=-1 );
+#ifndef TQT_NO_BEZIER
+ void drawCubicBezier( const TQPointArray &, int index=0 );
+#endif
+ void drawPixmap( int x, int y, const TQPixmap &,
+ int sx=0, int sy=0, int sw=-1, int sh=-1 );
+ void drawPixmap( const TQPoint &, const TQPixmap &,
+ const TQRect &sr );
+ void drawPixmap( const TQPoint &, const TQPixmap & );
+ void drawPixmap( const TQRect &, const TQPixmap & );
+ void drawImage( int x, int y, const TQImage &,
+ int sx = 0, int sy = 0, int sw = -1, int sh = -1,
+ int conversionFlags = 0 );
+ void drawImage( const TQPoint &, const TQImage &,
+ const TQRect &sr, int conversionFlags = 0 );
+ void drawImage( const TQPoint &, const TQImage &,
+ int conversion_flags = 0 );
+ void drawImage( const TQRect &, const TQImage & );
+ void drawTiledPixmap( int x, int y, int w, int h, const TQPixmap &,
+ int sx=0, int sy=0 );
+ void drawTiledPixmap( const TQRect &, const TQPixmap &,
+ const TQPoint & );
+ void drawTiledPixmap( const TQRect &, const TQPixmap & );
+#ifndef TQT_NO_PICTURE
+ void drawPicture( const TQPicture & );
+ void drawPicture( int x, int y, const TQPicture & );
+ void drawPicture( const TQPoint &, const TQPicture & );
+#endif
+
+ void fillRect( int x, int y, int w, int h, const TQBrush & );
+ void fillRect( const TQRect &, const TQBrush & );
+ void eraseRect( int x, int y, int w, int h );
+ void eraseRect( const TQRect & );
+
+ // Text drawing functions
+
+ enum TextDirection {
+ Auto,
+ RTL,
+ LTR
+ };
+
+ void drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto );
+ void drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto );
+
+ void drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto );
+ void drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto );
+
+ void drawText( int x, int y, int w, int h, int flags,
+ const TQString&, int len = -1, TQRect *br=0,
+ TQTextParag **intern=0 );
+ void drawText( const TQRect &, int flags,
+ const TQString&, int len = -1, TQRect *br=0,
+ TQTextParag **intern=0 );
+
+ void tqdrawTextItem( int x, int y, const TQTextItem &ti, int textflags = 0 );
+ void tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags = 0 );
+
+ TQRect boundingRect( int x, int y, int w, int h, int flags,
+ const TQString&, int len = -1, TQTextParag **intern=0 );
+ TQRect boundingRect( const TQRect &, int flags,
+ const TQString&, int len = -1, TQTextParag **intern=0 );
+
+ int tabStops() const;
+ void setTabStops( int );
+ int *tabArray() const;
+ void setTabArray( int * );
+
+ // Other functions
+
+#if defined(TQ_WS_WIN)
+ HDC handle() const;
+#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC)
+ HANDLE handle() const;
+#endif
+
+
+ static void initialize();
+ static void cleanup();
+
+private:
+ void init();
+ void destroy();
+ void updateFont();
+ void updatePen();
+ void updateBrush();
+#ifndef TQT_NO_TRANSFORMATIONS
+ void updateXForm();
+ void updateInvXForm();
+#endif
+ void map( int, int, int *rx, int *ry ) const;
+ void map( int, int, int, int, int *, int *, int *, int * ) const;
+ void mapInv( int, int, int *, int * ) const;
+ void mapInv( int, int, int, int, int *, int *, int *, int * ) const;
+ void drawPolyInternal( const TQPointArray &, bool close=TRUE );
+ void drawWinFocusRect( int x, int y, int w, int h, bool xorPaint,
+ const TQColor &penColor );
+
+ enum { IsActive=0x01, ExtDev=0x02, IsStartingUp=0x04, NoCache=0x08,
+ VxF=0x10, WxF=0x20, ClipOn=0x40, SafePolygon=0x80, MonoDev=0x100,
+ DirtyFont=0x200, DirtyPen=0x400, DirtyBrush=0x800,
+ RGBColor=0x1000, FontMet=0x2000, FontInf=0x4000, CtorBegin=0x8000,
+ UsePrivateCx = 0x10000, VolatileDC = 0x20000, TQt2Compat = 0x40000 };
+ uint flags;
+ bool testf( uint b ) const { return (flags&b)!=0; }
+ void setf( uint b ) { flags |= b; }
+ void setf( uint b, bool v );
+ void clearf( uint b ) { flags &= (uint)(~b); }
+ void fix_neg_rect( int *x, int *y, int *w, int *h );
+
+ TQPainterPrivate *d;
+ TQPaintDevice *pdev;
+ TQColor bg_col;
+ uchar bg_mode;
+ uchar rop;
+ uchar pu;
+ TQPoint bro;
+ TQFont cfont;
+ TQFont *pfont; // font used for metrics (might be different for printers)
+ TQPen cpen;
+ TQBrush cbrush;
+ TQRegion crgn;
+ int tabstops;
+ int *tabarray;
+ int tabarraylen;
+ bool block_ext; // for temporary blocking of external tqdevices
+
+ // Transformations
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQCOORD wx, wy, ww, wh;
+ TQCOORD vx, vy, vw, vh;
+ TQWMatrix wxmat;
+
+ // Cached composition (and inverse) of transformations
+ TQWMatrix xmat;
+ TQWMatrix ixmat;
+
+
+
+ double m11() const { return xmat.m11(); }
+ double m12() const { return xmat.m12(); }
+ double m21() const { return xmat.m21(); }
+ double m22() const { return xmat.m22(); }
+ double dx() const { return xmat.dx(); }
+ double dy() const { return xmat.dy(); }
+ double im11() const { return ixmat.m11(); }
+ double im12() const { return ixmat.m12(); }
+ double im21() const { return ixmat.m21(); }
+ double im22() const { return ixmat.m22(); }
+ double idx() const { return ixmat.dx(); }
+ double idy() const { return ixmat.dy(); }
+
+ int txop;
+ bool txinv;
+
+#else
+ // even without transformations we still have translations
+ int xlatex;
+ int xlatey;
+#endif
+
+ void *penRef; // pen cache ref
+ void *brushRef; // brush cache ref
+ void *ps_stack;
+ void *wm_stack;
+ void killPStack();
+
+protected:
+#ifdef TQ_OS_TEMP
+ TQPoint internalCurrentPos;
+ uint old_pix; // ### All win platforms in 4.0
+#endif
+#if defined(TQ_WS_WIN)
+ friend class TQFontEngineWin;
+ friend class TQFontEngineBox;
+ TQT_WIN_PAINTER_MEMBERS
+#elif defined(TQ_WS_X11)
+ friend class TQFontEngineXLFD;
+ friend class TQFontEngineXft;
+ friend class TQFontEngineBox;
+ Display *dpy; // current display
+ int scrn; // current screen
+ TQt::HANDLE hd; // handle to drawable
+ TQt::HANDLE rendhd; // handle to Xft draw
+ GC gc; // graphics context (standard)
+ GC gc_brush; // graphics contect for brush
+ TQPoint curPt; // current point
+ uint clip_serial; // clipping serial number
+#elif defined(TQ_WS_MAC)
+ TQt::HANDLE hd; // handle to drawable
+ void initPaintDevice(bool force=FALSE, TQPoint *off=NULL, TQRegion *rgn=NULL);
+ friend const TQRegion &qt_mac_update_painter(TQPainter *, bool);
+ friend class TQFontEngineMac;
+ friend class TQMacPainter;
+#elif defined(TQ_WS_TQWS)
+ friend class TQFontEngine;
+ TQGfx * gfx;
+ friend void qwsUpdateActivePainters();
+#endif
+ friend class TQFontMetrics;
+ friend class TQFontInfo;
+ friend class TQTextLayout;
+ friend void qt_format_text( const TQFont &, const TQRect &r,
+ int tf, const TQString& str, int len, TQRect *brect,
+ int tabstops, int* tabarray, int tabarraylen,
+ TQTextParag **internal, TQPainter* painter );
+ friend void qt_draw_background( TQPainter *p, int x, int y, int w, int h );
+ friend void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill );
+ friend class TQPrinter;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQPainter( const TQPainter & );
+ TQPainter &operator=( const TQPainter & );
+#endif
+
+ enum TransformationCodes {
+ TxNone = 0, // transformation codes
+ TxTranslate = 1, // copy in qpainter_*.cpp
+ TxScale = 2,
+ TxRotShear = 3
+ };
+};
+
+
+/*****************************************************************************
+ TQPainter member functions
+ *****************************************************************************/
+
+inline TQPaintDevice *TQPainter::tqdevice() const
+{
+ return pdev;
+}
+
+inline bool TQPainter::isActive() const
+{
+ return testf(IsActive);
+}
+
+inline const TQFont &TQPainter::font() const
+{
+ return cfont;
+}
+
+inline const TQPen &TQPainter::pen() const
+{
+ return cpen;
+}
+
+inline const TQBrush &TQPainter::brush() const
+{
+ return cbrush;
+}
+
+/*
+inline PaintUnit TQPainter::unit() const
+{
+ return (PaintUnit)pu;
+}
+*/
+
+inline const TQColor &TQPainter::backgroundColor() const
+{
+ return bg_col;
+}
+
+inline TQt::BGMode TQPainter::backgroundMode() const
+{
+ return (BGMode)bg_mode;
+}
+
+inline TQt::RasterOp TQPainter::rasterOp() const
+{
+ return (RasterOp)rop;
+}
+
+inline const TQPoint &TQPainter::brushOrigin() const
+{
+ return bro;
+}
+
+inline bool TQPainter::hasViewXForm() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return testf(VxF);
+#else
+ return xlatex || xlatey;
+#endif
+}
+
+inline bool TQPainter::hasWorldXForm() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return testf(WxF);
+#else
+ return xlatex || xlatey;
+#endif
+}
+
+inline double TQPainter::translationX() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return tqworldMatrix().dx();
+#else
+ return xlatex;
+#endif
+}
+
+inline double TQPainter::translationY() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return tqworldMatrix().dy();
+#else
+ return xlatey;
+#endif
+}
+
+
+inline bool TQPainter::hasClipping() const
+{
+ return testf(ClipOn);
+}
+
+inline int TQPainter::tabStops() const
+{
+ return tabstops;
+}
+
+inline int *TQPainter::tabArray() const
+{
+ return tabarray;
+}
+
+#if defined(TQ_WS_WIN)
+inline HDC TQPainter::handle() const
+{
+ return hdc;
+}
+#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC)
+inline TQt::HANDLE TQPainter::handle() const
+{
+ return hd;
+}
+#endif
+
+inline void TQPainter::setBrushOrigin( const TQPoint &p )
+{
+ setBrushOrigin( p.x(), p.y() );
+}
+
+#ifndef TQT_NO_TRANSFORMATIONS
+inline void TQPainter::setWindow( const TQRect &r )
+{
+ setWindow( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::setViewport( const TQRect &r )
+{
+ setViewport( r.x(), r.y(), r.width(), r.height() );
+}
+#endif
+
+inline void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m )
+{
+ setClipRect( TQRect(x,y,w,h), m );
+}
+
+inline void TQPainter::drawPoint( const TQPoint &p )
+{
+ drawPoint( p.x(), p.y() );
+}
+
+inline void TQPainter::moveTo( const TQPoint &p )
+{
+ moveTo( p.x(), p.y() );
+}
+
+inline void TQPainter::lineTo( const TQPoint &p )
+{
+ lineTo( p.x(), p.y() );
+}
+
+inline void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 )
+{
+ drawLine( p1.x(), p1.y(), p2.x(), p2.y() );
+}
+
+inline void TQPainter::drawRect( const TQRect &r )
+{
+ drawRect( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::drawWinFocusRect( const TQRect &r )
+{
+ drawWinFocusRect( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::drawWinFocusRect( const TQRect &r,const TQColor &penColor )
+{
+ drawWinFocusRect( r.x(), r.y(), r.width(), r.height(), penColor );
+}
+
+inline void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd )
+{
+ drawRoundRect( r.x(), r.y(), r.width(), r.height(), xRnd, yRnd );
+}
+
+inline void TQPainter::drawEllipse( const TQRect &r )
+{
+ drawEllipse( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::drawArc( const TQRect &r, int a, int alen )
+{
+ drawArc( r.x(), r.y(), r.width(), r.height(), a, alen );
+}
+
+inline void TQPainter::drawPie( const TQRect &r, int a, int alen )
+{
+ drawPie( r.x(), r.y(), r.width(), r.height(), a, alen );
+}
+
+inline void TQPainter::drawChord( const TQRect &r, int a, int alen )
+{
+ drawChord( r.x(), r.y(), r.width(), r.height(), a, alen );
+}
+
+inline void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm,
+ const TQRect &sr )
+{
+ drawPixmap( p.x(), p.y(), pm, sr.x(), sr.y(), sr.width(), sr.height() );
+}
+
+inline void TQPainter::drawImage( const TQPoint &p, const TQImage &pm,
+ const TQRect &sr, int conversionFlags )
+{
+ drawImage( p.x(), p.y(), pm,
+ sr.x(), sr.y(), sr.width(), sr.height(), conversionFlags );
+}
+
+inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm,
+ const TQPoint &sp )
+{
+ drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, sp.x(), sp.y() );
+}
+
+inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm )
+{
+ drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, 0, 0 );
+}
+
+inline void TQPainter::fillRect( const TQRect &r, const TQBrush &brush )
+{
+ fillRect( r.x(), r.y(), r.width(), r.height(), brush );
+}
+
+inline void TQPainter::eraseRect( int x, int y, int w, int h )
+{
+ fillRect( x, y, w, h, backgroundColor() );
+}
+
+inline void TQPainter::eraseRect( const TQRect &r )
+{
+ fillRect( r.x(), r.y(), r.width(), r.height(), backgroundColor() );
+}
+
+inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int len, TextDirection dir )
+{
+ drawText( p.x(), p.y(), s, 0, len, dir );
+}
+
+inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir )
+{
+ drawText( p.x(), p.y(), s, pos, len, dir );
+}
+
+inline void TQPainter::drawText( int x, int y, int w, int h, int tf,
+ const TQString& str, int len, TQRect *br, TQTextParag **i )
+{
+ TQRect r(x, y, w, h);
+ drawText( r, tf, str, len, br, i );
+}
+
+inline void TQPainter::tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags )
+{
+ tqdrawTextItem( p.x(), p.y(), ti, textflags );
+}
+
+inline TQRect TQPainter::boundingRect( int x, int y, int w, int h, int tf,
+ const TQString& str, int len, TQTextParag **i )
+{
+ TQRect r(x, y, w, h);
+ return boundingRect( r, tf, str, len, i );
+}
+
+#if defined(TQ_WS_TQWS)
+inline TQGfx * TQPainter::internalGfx()
+{
+ return gfx;
+}
+#endif
+
+#endif // USE_QT4
+
+#endif // TQPAINTER_H
diff --git a/tqtinterface/qt4/src/kernel/tqpainter.h~ b/tqtinterface/qt4/src/kernel/tqpainter.h~
new file mode 100644
index 0000000..f391c79
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpainter.h~
@@ -0,0 +1,993 @@
+/****************************************************************************
+**
+** Definition of TQPainter class
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPAINTER_H
+#define TQPAINTER_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqcolor.h"
+#include "tqfontmetrics.h"
+#include "tqfontinfo.h"
+#include "tqregion.h"
+#include "tqpen.h"
+#include "tqbrush.h"
+#include "tqpointarray.h"
+#include "tqwmatrix.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqwidget.h"
+#include "tqpaintdevice.h"
+#include <QtGui/qpainter.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class Q_COMPAT_EXPORT TQPainter : public QPainter, virtual public TQt
+{
+public:
+ enum TextDirection {
+ Auto,
+ RTL,
+ LTR
+ };
+
+ enum CoordinateMode { CoordDevice, CoordPainter };
+
+ TQPainter();
+ TQPainter( const QWidget *pdev, bool unclipped = FALSE);
+ TQPainter( QPaintDevice *pdev, bool unclipped = FALSE);
+ TQPainter( QWidget *pdev, const QWidget *w, bool unclipped = FALSE );
+ TQPainter( QPaintDevice *pdev, const QWidget *w, bool unclipped = FALSE );
+
+ void flush();
+ void flush( const TQRegion &region, CoordinateMode cm = CoordDevice );
+
+ void drawRect(const QRect &rect);
+ inline void drawRect(int x1, int y1, int w, int h)
+ { drawRect(QRect(x1, y1, w, h)); }
+
+ void drawRoundRect(const QRect &r, int xround = 25, int yround = 25);
+ inline void drawRoundRect(int x, int y, int w, int h, int xround = 25, int yround = 25)
+ { drawRoundRect(QRect(x, y, w, h), xround, yround); }
+
+ void drawEllipse(const QRect &r);
+ inline void drawEllipse(int x, int y, int w, int h)
+ { drawEllipse(QRect(x, y, w, h)); }
+
+ void drawArc(const QRect &r, int a, int alen);
+ inline void drawArc(int x, int y, int w, int h, int a, int alen)
+ { drawArc(QRect(x, y, w, h), a, alen); }
+
+ void drawPie(const QRect &r, int a, int alen);
+ inline void drawPie(int x, int y, int w, int h, int a, int alen)
+ { drawPie(QRect(x, y, w, h), a, alen); }
+
+ void drawChord(const QRect &r, int a, int alen);
+ inline void drawChord(int x, int y, int w, int h, int a, int alen)
+ { drawChord(QRect(x, y, w, h), a, alen); }
+
+ void drawImage( int x, int y, const TQImage image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, int conversionFlags = 0 );
+ void drawImage( const TQPoint &p, const TQImage image, const TQRect &sr, int conversionFlags = 0 );
+ void drawImage( const TQPoint &p, const TQImage image, int conversion_flags = 0 );
+ void drawImage( const TQRect &r, const TQImage image );
+
+ void drawLineSegments(const QPolygon &points, int index = 0, int nlines = -1);
+
+ void setBrush(const QBrush &brush);
+ void setBrush(Qt::BrushStyle style);
+ void setBrush(TQt::BrushStyle style);
+
+ inline void tqdrawPixmap( int x, int y, const TQPixmap &tqpm, int sx=0, int sy=0, int sw=-1, int sh=-1 ) { drawPixmap(x, y, tqpm, sx, sy, sw, sh); }
+
+ TQPoint pos() const;
+
+ // Qt4 requires the QPainter to have a valid QPaintDevice (engine) for boundingRect() to work
+ // So, we create one off-screen!
+ #define TQT_INITIALIZE_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL \
+ bool neededEngine = FALSE; \
+ if (QPainter::isActive() == 0) { \
+ printf("[WARNING] Painter was inactive when TQPainter::boundingRect was called; this indicates a likely problem in painting within your application (check Qt::WA_PaintOutsidePaintEvent == true)\n\r"); \
+ QImage image(1,1,QImage::Format_RGB32); \
+ neededEngine = TRUE; \
+ QPainter::begin(&image); \
+ }
+
+ #define TQT_DESTROY_QPAINTER_TEMPORARY_ENGINE_CONDITIONAL \
+ if (neededEngine == TRUE) { \
+ QPainter::end(); \
+ }
+
+ QRectF boundingRect(const QRectF &rect, int flags, const QString &text);
+ QRect boundingRect(const QRect &rect, int flags, const QString &text);
+ QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text);
+ QRectF boundingRect(const QRectF &rect, const QString &text, const QTextOption &o = QTextOption());
+
+ TQRect boundingRect(const QRect &rect, int flags, const QString &text, int len);
+ TQRect boundingRect(int x, int y, int w, int h, int flags, const QString &text, int len);
+
+ void drawText(const QPointF &p, const QString &s);
+ void drawText(const QPoint &p, const QString &s);
+ void drawText(int x, int y, const QString &s);
+ void drawText(const QPointF &p, const QString &str, int tf, int justificationPadding);
+ void drawText(const QRectF &r, int flags, const QString &text, QRectF *br=0);
+ void drawText(const QRect &r, int flags, const QString &text, QRect *br=0);
+ void drawText(int x, int y, int w, int h, int flags, const QString &text, QRect *br=0);
+ void drawText(const QRectF &r, const QString &text, const QTextOption &o = QTextOption());
+
+ void drawText( int x, int y, const TQString &s, int len = -1, TextDirection dir = Auto );
+ void drawText( const TQPoint &p, const TQString &s, int len = -1, TextDirection dir = Auto );
+ void drawText( int x, int y, const TQString &s, int pos, int len, TextDirection dir = Auto );
+ void drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir = Auto );
+
+ void drawText(int x, int y, const QString &s, int pos, int len);
+ void drawText(const QPoint &p, const QString &s, int pos, int len);
+ void drawText(int x, int y, const QString &s, int len);
+ void drawText(const QPoint &p, const QString &s, int len);
+ void drawText(const QRect &r, int flags, const QString &str, int len, QRect *br=0);
+ void drawText(int x, int y, int w, int h, int flags, const QString &text, int len, QRect *br=0);
+
+ void map(int x, int y, int *rx, int *ry) const;
+ void map( int, int, int, int, int *, int *, int *, int * ) const;
+ TQPoint xForm(const QPoint &) const; // map virtual -> deviceb
+ TQRect xForm(const QRect &) const;
+// TQPolygon xForm(const QPolygon &) const;
+// TQPolygon xForm(const QPolygon &, int index, int npoints) const;
+ TQPoint xFormDev(const QPoint &) const; // map device -> virtual
+ TQRect xFormDev(const QRect &) const;
+// TQPolygon xFormDev(const QPolygon &) const;
+// TQPolygon xFormDev(const QPolygon &, int index, int npoints) const;
+ qreal translationX() const;
+ qreal translationY() const;
+
+ void resetXForm();
+
+ // [FIXME] The drawWinFocusRect methods below probably need tweaking to exactly match the old Qt3 behaviour
+ void drawWinFocusRect( int x, int y, int w, int h );
+ void drawWinFocusRect( int x, int y, int w, int h, const TQColor &bgColor );
+ void drawWinFocusRect( const TQRect &tqr );
+ void drawWinFocusRect( const TQRect &tqr, const TQColor &bgColor );
+
+// inline const TQWMatrix &tqworldMatrix() const { return (*(static_cast<const TQWMatrix*>(&worldMatrix()))); }
+ const TQWMatrix &tqworldMatrix() const;
+
+ inline TQPaintDevice *tqdevice() const { return static_cast<TQPaintDevice*>(device()); }
+
+ TQRegion clipRegion( CoordinateMode cm = CoordDevice ) const;
+
+ void setClipRegion( const QRegion &qr, CoordinateMode cm = CoordDevice );
+
+ void setBackgroundColor(const QColor &color);
+ const QColor &backgroundColor() const;
+
+ void setClipRect(const QRectF &qrf, Qt::ClipOperation op = Qt::ReplaceClip);
+ void setClipRect(const QRect &qr, Qt::ClipOperation op = Qt::ReplaceClip);
+ void setClipRect( const TQRect &qr, CoordinateMode cm = CoordDevice );
+ void setClipRect( int x, int y, int w, int h, CoordinateMode cm = CoordDevice );
+
+ inline double m11() const { return deviceTransform().m11(); }
+ inline double m12() const { return deviceTransform().m12(); }
+ inline double m21() const { return deviceTransform().m21(); }
+ inline double m22() const { return deviceTransform().m22(); }
+ inline double dx() const { return deviceTransform().dx(); }
+ inline double dy() const { return deviceTransform().dy(); }
+ inline double im11() const { return deviceTransform().inverted().m11(); }
+ inline double im12() const { return deviceTransform().inverted().m12(); }
+ inline double im21() const { return deviceTransform().inverted().m21(); }
+ inline double im22() const { return deviceTransform().inverted().m22(); }
+ inline double idx() const { return deviceTransform().inverted().dx(); }
+ inline double idy() const { return deviceTransform().inverted().dy(); }
+
+ void moveTo( int x, int y );
+ void moveTo( const TQPoint & );
+ void lineTo( int x, int y );
+ void lineTo( const TQPoint & );
+
+ void tqdrawTextItem( int x, int y, const TQTextItem &ti, int textflags = 0 );
+ void tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags = 0 );
+
+ static void redirect(QPaintDevice *pdev, QPaintDevice *replacement);
+ static TQPaintDevice *redirect(QPaintDevice *pdev);
+
+ TQt::RasterOp rasterOp() const;
+ void setRasterOp( TQt::RasterOp );
+
+ bool tqbegin( QPaintDevice *pdev, bool unclipped = FALSE );
+ bool tqbegin( QPaintDevice *pdev, const QWidget *init, bool unclipped = FALSE );
+
+ inline void tqdrawPolyline(const QPolygon &pa, int index, int npoints = -1) { drawPolyline(pa.constData() + index, npoints == -1 ? pa.size() - index : npoints); }
+ inline void tqdrawPolygon(const QPolygon &pa, bool winding, int index = 0, int npoints = -1) { drawPolygon(pa.constData() + index, npoints == -1 ? pa.size() - index : npoints, winding ? Qt::WindingFill : Qt::OddEvenFill); }
+ inline void tqdrawPolygon(const QPolygonF &polygon, bool winding, int index = 0, int npoints = -1) { drawPolygon(polygon.constData() + index, npoints == -1 ? polygon.size() - index : npoints, winding ? Qt::WindingFill : Qt::OddEvenFill); }
+ inline void tqdrawConvexPolygon(const QPolygonF &polygon, int index, int npoints = -1) { drawConvexPolygon(polygon.constData() + index, npoints == -1 ? polygon.size() - index : npoints); }
+ inline void tqdrawConvexPolygon(const QPolygon &pa, int index, int npoints = -1) { drawConvexPolygon(pa.constData() + index, npoints == -1 ? pa.size() - index : npoints); }
+// static inline void redirect(QPaintDevice *pdev, QPaintDevice *replacement) { setRedirected(pdev, replacement); }
+// static inline TQPaintDevice *redirect(QPaintDevice *pdev) { return const_cast<QPaintDevice*>(redirected(pdev)); }
+ void setWorldXForm(bool enabled);
+ bool hasWorldXForm() const;
+// inline void resetXForm() { resetTransform(); }
+ void setViewXForm(bool enabled);
+ bool hasViewXForm() const;
+
+ // [FIXME]
+ static void initialize();
+ static void cleanup();
+
+ bool has_qwidget;
+ mutable QWidget* qwidget_ptr;
+
+private:
+ QRect adjustedRectangle(const QRect &r);
+ int rectSubtraction() const;
+ uchar rop;
+ enum { IsActive=0x01, ExtDev=0x02, IsStartingUp=0x04, NoCache=0x08,
+ VxF=0x10, WxF=0x20, ClipOn=0x40, SafePolygon=0x80, MonoDev=0x100,
+ DirtyFont=0x200, DirtyPen=0x400, DirtyBrush=0x800,
+ RGBColor=0x1000, FontMet=0x2000, FontInf=0x4000, CtorBegin=0x8000,
+ UsePrivateCx = 0x10000, VolatileDC = 0x20000, TQt2Compat = 0x40000 };
+// uint flags;
+// bool testf( uint b ) const { return (flags&b)!=0; }
+ bool testf( uint b ) const;
+ void drawWinFocusRect( int x, int y, int w, int h, bool xorPaint, const QColor &penColor );
+ void fix_neg_rect( int *x, int *y, int *w, int *h );
+
+ TQPoint current_penpos;
+
+ Q_DISABLE_COPY(TQPainter)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#else // USE_QT4
+
+class TQGfx;
+class TQTextCodec;
+class TQTextParag;
+class TQPaintDevice;
+class TQTextItem;
+#if defined( TQ_WS_MAC )
+class TQMacSavedPortInfo;
+#endif
+class TQPainterPrivate;
+
+#if defined(TQ_WS_TQWS)
+class TQScreen;
+#endif
+
+class TQ_EXPORT TQPainter : public TQt
+{
+public:
+ enum CoordinateMode { CoordDevice, CoordPainter };
+
+ TQPainter();
+ TQPainter( const TQPaintDevice *, bool unclipped = FALSE );
+ TQPainter( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE );
+ ~TQPainter();
+
+ bool begin( const TQPaintDevice *, bool unclipped = FALSE );
+ bool begin( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE );
+ bool end();
+ TQPaintDevice *tqdevice() const;
+
+#ifdef TQ_WS_TQWS
+ TQGfx * internalGfx();
+#ifdef TQT_TQWS_EXPERIMENTAL_SCREENPAINTER
+ bool begin(TQScreen *screen);
+#endif
+#endif
+
+ static void redirect( TQPaintDevice *pdev, TQPaintDevice *tqreplacement );
+ static TQPaintDevice *redirect( TQPaintDevice *pdev );
+
+ bool isActive() const;
+
+ void flush( const TQRegion &region, CoordinateMode cm = CoordDevice );
+ void flush();
+ void save();
+ void restore();
+
+ // Drawing tools
+
+ TQFontMetrics fontMetrics() const;
+ TQFontInfo fontInfo() const;
+
+ const TQFont &font() const;
+ void setFont( const TQFont & );
+ const TQPen &pen() const;
+ void setPen( const TQPen & );
+ void setPen( PenStyle );
+ void setPen( const TQColor & );
+ const TQBrush &brush() const;
+ void setBrush( const TQBrush & );
+ void setBrush( BrushStyle );
+ void setBrush( const TQColor & );
+ TQPoint pos() const;
+
+ // Drawing attributes/modes
+
+ const TQColor &backgroundColor() const;
+ void setBackgroundColor( const TQColor & );
+ BGMode backgroundMode() const;
+ void setBackgroundMode( BGMode );
+ RasterOp rasterOp() const;
+ void setRasterOp( RasterOp );
+ const TQPoint &brushOrigin() const;
+ void setBrushOrigin( int x, int y );
+ void setBrushOrigin( const TQPoint & );
+
+ // Scaling and transformations
+
+// PaintUnit unit() const; // get set painter unit
+// void setUnit( PaintUnit ); // NOT IMPLEMENTED!!!
+
+ bool hasViewXForm() const;
+ bool hasWorldXForm() const;
+
+#ifndef TQT_NO_TRANSFORMATIONS
+ void setViewXForm( bool ); // set xform on/off
+ TQRect window() const; // get window
+ void setWindow( const TQRect & ); // set window
+ void setWindow( int x, int y, int w, int h );
+ TQRect viewport() const; // get viewport
+ void setViewport( const TQRect & ); // set viewport
+ void setViewport( int x, int y, int w, int h );
+
+ void setWorldXForm( bool ); // set world xform on/off
+ const TQWMatrix &tqworldMatrix() const; // get/set world xform matrix
+ void setWorldMatrix( const TQWMatrix &, bool combine=FALSE );
+
+ void saveWorldMatrix();
+ void restoreWorldMatrix();
+
+ void scale( double sx, double sy );
+ void shear( double sh, double sv );
+ void rotate( double a );
+#endif
+ void translate( double dx, double dy );
+ void resetXForm();
+ double translationX() const;
+ double translationY() const;
+
+ TQPoint xForm( const TQPoint & ) const; // map virtual -> tqdevice
+ TQRect xForm( const TQRect & ) const;
+ TQPointArray xForm( const TQPointArray & ) const;
+ TQPointArray xForm( const TQPointArray &, int index, int npoints ) const;
+ TQPoint xFormDev( const TQPoint & ) const; // map tqdevice -> virtual
+ TQRect xFormDev( const TQRect & ) const;
+ TQPointArray xFormDev( const TQPointArray & ) const;
+ TQPointArray xFormDev( const TQPointArray &, int index, int npoints ) const;
+
+ // Clipping
+
+ void setClipping( bool ); // set clipping on/off
+ bool hasClipping() const;
+ TQRegion clipRegion( CoordinateMode = CoordDevice ) const;
+ void setClipRect( const TQRect &, CoordinateMode = CoordDevice ); // set clip rectangle
+ void setClipRect( int x, int y, int w, int h, CoordinateMode = CoordDevice );
+ void setClipRegion( const TQRegion &, CoordinateMode = CoordDevice );// set clip region
+
+ // Graphics drawing functions
+
+ void drawPoint( int x, int y );
+ void drawPoint( const TQPoint & );
+ void drawPoints( const TQPointArray& a,
+ int index=0, int npoints=-1 );
+ void moveTo( int x, int y );
+ void moveTo( const TQPoint & );
+ void lineTo( int x, int y );
+ void lineTo( const TQPoint & );
+ void drawLine( int x1, int y1, int x2, int y2 );
+ void drawLine( const TQPoint &, const TQPoint & );
+ void drawRect( int x, int y, int w, int h );
+ void drawRect( const TQRect & );
+ void drawWinFocusRect( int x, int y, int w, int h );
+ void drawWinFocusRect( int x, int y, int w, int h,
+ const TQColor &bgColor );
+ void drawWinFocusRect( const TQRect & );
+ void drawWinFocusRect( const TQRect &,
+ const TQColor &bgColor );
+ void drawRoundRect( int x, int y, int w, int h, int = 25, int = 25 );
+ void drawRoundRect( const TQRect &, int = 25, int = 25 );
+ void drawEllipse( int x, int y, int w, int h );
+ void drawEllipse( const TQRect & );
+ void drawArc( int x, int y, int w, int h, int a, int alen );
+ void drawArc( const TQRect &, int a, int alen );
+ void drawPie( int x, int y, int w, int h, int a, int alen );
+ void drawPie( const TQRect &, int a, int alen );
+ void drawChord( int x, int y, int w, int h, int a, int alen );
+ void drawChord( const TQRect &, int a, int alen );
+ void drawLineSegments( const TQPointArray &,
+ int index=0, int nlines=-1 );
+ void drawPolyline( const TQPointArray &,
+ int index=0, int npoints=-1 );
+ void drawPolygon( const TQPointArray &, bool winding=FALSE,
+ int index=0, int npoints=-1 );
+ void drawConvexPolygon( const TQPointArray &,
+ int index=0, int npoints=-1 );
+#ifndef TQT_NO_BEZIER
+ void drawCubicBezier( const TQPointArray &, int index=0 );
+#endif
+ void drawPixmap( int x, int y, const TQPixmap &,
+ int sx=0, int sy=0, int sw=-1, int sh=-1 );
+ void drawPixmap( const TQPoint &, const TQPixmap &,
+ const TQRect &sr );
+ void drawPixmap( const TQPoint &, const TQPixmap & );
+ void drawPixmap( const TQRect &, const TQPixmap & );
+ void drawImage( int x, int y, const TQImage &,
+ int sx = 0, int sy = 0, int sw = -1, int sh = -1,
+ int conversionFlags = 0 );
+ void drawImage( const TQPoint &, const TQImage &,
+ const TQRect &sr, int conversionFlags = 0 );
+ void drawImage( const TQPoint &, const TQImage &,
+ int conversion_flags = 0 );
+ void drawImage( const TQRect &, const TQImage & );
+ void drawTiledPixmap( int x, int y, int w, int h, const TQPixmap &,
+ int sx=0, int sy=0 );
+ void drawTiledPixmap( const TQRect &, const TQPixmap &,
+ const TQPoint & );
+ void drawTiledPixmap( const TQRect &, const TQPixmap & );
+#ifndef TQT_NO_PICTURE
+ void drawPicture( const TQPicture & );
+ void drawPicture( int x, int y, const TQPicture & );
+ void drawPicture( const TQPoint &, const TQPicture & );
+#endif
+
+ void fillRect( int x, int y, int w, int h, const TQBrush & );
+ void fillRect( const TQRect &, const TQBrush & );
+ void eraseRect( int x, int y, int w, int h );
+ void eraseRect( const TQRect & );
+
+ // Text drawing functions
+
+ enum TextDirection {
+ Auto,
+ RTL,
+ LTR
+ };
+
+ void drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto );
+ void drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto );
+
+ void drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto );
+ void drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto );
+
+ void drawText( int x, int y, int w, int h, int flags,
+ const TQString&, int len = -1, TQRect *br=0,
+ TQTextParag **intern=0 );
+ void drawText( const TQRect &, int flags,
+ const TQString&, int len = -1, TQRect *br=0,
+ TQTextParag **intern=0 );
+
+ void tqdrawTextItem( int x, int y, const TQTextItem &ti, int textflags = 0 );
+ void tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags = 0 );
+
+ TQRect boundingRect( int x, int y, int w, int h, int flags,
+ const TQString&, int len = -1, TQTextParag **intern=0 );
+ TQRect boundingRect( const TQRect &, int flags,
+ const TQString&, int len = -1, TQTextParag **intern=0 );
+
+ int tabStops() const;
+ void setTabStops( int );
+ int *tabArray() const;
+ void setTabArray( int * );
+
+ // Other functions
+
+#if defined(TQ_WS_WIN)
+ HDC handle() const;
+#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC)
+ HANDLE handle() const;
+#endif
+
+
+ static void initialize();
+ static void cleanup();
+
+private:
+ void init();
+ void destroy();
+ void updateFont();
+ void updatePen();
+ void updateBrush();
+#ifndef TQT_NO_TRANSFORMATIONS
+ void updateXForm();
+ void updateInvXForm();
+#endif
+ void map( int, int, int *rx, int *ry ) const;
+ void map( int, int, int, int, int *, int *, int *, int * ) const;
+ void mapInv( int, int, int *, int * ) const;
+ void mapInv( int, int, int, int, int *, int *, int *, int * ) const;
+ void drawPolyInternal( const TQPointArray &, bool close=TRUE );
+ void drawWinFocusRect( int x, int y, int w, int h, bool xorPaint,
+ const TQColor &penColor );
+
+ enum { IsActive=0x01, ExtDev=0x02, IsStartingUp=0x04, NoCache=0x08,
+ VxF=0x10, WxF=0x20, ClipOn=0x40, SafePolygon=0x80, MonoDev=0x100,
+ DirtyFont=0x200, DirtyPen=0x400, DirtyBrush=0x800,
+ RGBColor=0x1000, FontMet=0x2000, FontInf=0x4000, CtorBegin=0x8000,
+ UsePrivateCx = 0x10000, VolatileDC = 0x20000, TQt2Compat = 0x40000 };
+ uint flags;
+ bool testf( uint b ) const { return (flags&b)!=0; }
+ void setf( uint b ) { flags |= b; }
+ void setf( uint b, bool v );
+ void clearf( uint b ) { flags &= (uint)(~b); }
+ void fix_neg_rect( int *x, int *y, int *w, int *h );
+
+ TQPainterPrivate *d;
+ TQPaintDevice *pdev;
+ TQColor bg_col;
+ uchar bg_mode;
+ uchar rop;
+ uchar pu;
+ TQPoint bro;
+ TQFont cfont;
+ TQFont *pfont; // font used for metrics (might be different for printers)
+ TQPen cpen;
+ TQBrush cbrush;
+ TQRegion crgn;
+ int tabstops;
+ int *tabarray;
+ int tabarraylen;
+ bool block_ext; // for temporary blocking of external tqdevices
+
+ // Transformations
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQCOORD wx, wy, ww, wh;
+ TQCOORD vx, vy, vw, vh;
+ TQWMatrix wxmat;
+
+ // Cached composition (and inverse) of transformations
+ TQWMatrix xmat;
+ TQWMatrix ixmat;
+
+
+
+ double m11() const { return xmat.m11(); }
+ double m12() const { return xmat.m12(); }
+ double m21() const { return xmat.m21(); }
+ double m22() const { return xmat.m22(); }
+ double dx() const { return xmat.dx(); }
+ double dy() const { return xmat.dy(); }
+ double im11() const { return ixmat.m11(); }
+ double im12() const { return ixmat.m12(); }
+ double im21() const { return ixmat.m21(); }
+ double im22() const { return ixmat.m22(); }
+ double idx() const { return ixmat.dx(); }
+ double idy() const { return ixmat.dy(); }
+
+ int txop;
+ bool txinv;
+
+#else
+ // even without transformations we still have translations
+ int xlatex;
+ int xlatey;
+#endif
+
+ void *penRef; // pen cache ref
+ void *brushRef; // brush cache ref
+ void *ps_stack;
+ void *wm_stack;
+ void killPStack();
+
+protected:
+#ifdef TQ_OS_TEMP
+ TQPoint internalCurrentPos;
+ uint old_pix; // ### All win platforms in 4.0
+#endif
+#if defined(TQ_WS_WIN)
+ friend class TQFontEngineWin;
+ friend class TQFontEngineBox;
+ TQT_WIN_PAINTER_MEMBERS
+#elif defined(TQ_WS_X11)
+ friend class TQFontEngineXLFD;
+ friend class TQFontEngineXft;
+ friend class TQFontEngineBox;
+ Display *dpy; // current display
+ int scrn; // current screen
+ TQt::HANDLE hd; // handle to drawable
+ TQt::HANDLE rendhd; // handle to Xft draw
+ GC gc; // graphics context (standard)
+ GC gc_brush; // graphics contect for brush
+ TQPoint curPt; // current point
+ uint clip_serial; // clipping serial number
+#elif defined(TQ_WS_MAC)
+ TQt::HANDLE hd; // handle to drawable
+ void initPaintDevice(bool force=FALSE, TQPoint *off=NULL, TQRegion *rgn=NULL);
+ friend const TQRegion &qt_mac_update_painter(TQPainter *, bool);
+ friend class TQFontEngineMac;
+ friend class TQMacPainter;
+#elif defined(TQ_WS_TQWS)
+ friend class TQFontEngine;
+ TQGfx * gfx;
+ friend void qwsUpdateActivePainters();
+#endif
+ friend class TQFontMetrics;
+ friend class TQFontInfo;
+ friend class TQTextLayout;
+ friend void qt_format_text( const TQFont &, const TQRect &r,
+ int tf, const TQString& str, int len, TQRect *brect,
+ int tabstops, int* tabarray, int tabarraylen,
+ TQTextParag **internal, TQPainter* painter );
+ friend void qt_draw_background( TQPainter *p, int x, int y, int w, int h );
+ friend void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill );
+ friend class TQPrinter;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQPainter( const TQPainter & );
+ TQPainter &operator=( const TQPainter & );
+#endif
+
+ enum TransformationCodes {
+ TxNone = 0, // transformation codes
+ TxTranslate = 1, // copy in qpainter_*.cpp
+ TxScale = 2,
+ TxRotShear = 3
+ };
+};
+
+
+/*****************************************************************************
+ TQPainter member functions
+ *****************************************************************************/
+
+inline TQPaintDevice *TQPainter::tqdevice() const
+{
+ return pdev;
+}
+
+inline bool TQPainter::isActive() const
+{
+ return testf(IsActive);
+}
+
+inline const TQFont &TQPainter::font() const
+{
+ return cfont;
+}
+
+inline const TQPen &TQPainter::pen() const
+{
+ return cpen;
+}
+
+inline const TQBrush &TQPainter::brush() const
+{
+ return cbrush;
+}
+
+/*
+inline PaintUnit TQPainter::unit() const
+{
+ return (PaintUnit)pu;
+}
+*/
+
+inline const TQColor &TQPainter::backgroundColor() const
+{
+ return bg_col;
+}
+
+inline TQt::BGMode TQPainter::backgroundMode() const
+{
+ return (BGMode)bg_mode;
+}
+
+inline TQt::RasterOp TQPainter::rasterOp() const
+{
+ return (RasterOp)rop;
+}
+
+inline const TQPoint &TQPainter::brushOrigin() const
+{
+ return bro;
+}
+
+inline bool TQPainter::hasViewXForm() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return testf(VxF);
+#else
+ return xlatex || xlatey;
+#endif
+}
+
+inline bool TQPainter::hasWorldXForm() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return testf(WxF);
+#else
+ return xlatex || xlatey;
+#endif
+}
+
+inline double TQPainter::translationX() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return tqworldMatrix().dx();
+#else
+ return xlatex;
+#endif
+}
+
+inline double TQPainter::translationY() const
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ return tqworldMatrix().dy();
+#else
+ return xlatey;
+#endif
+}
+
+
+inline bool TQPainter::hasClipping() const
+{
+ return testf(ClipOn);
+}
+
+inline int TQPainter::tabStops() const
+{
+ return tabstops;
+}
+
+inline int *TQPainter::tabArray() const
+{
+ return tabarray;
+}
+
+#if defined(TQ_WS_WIN)
+inline HDC TQPainter::handle() const
+{
+ return hdc;
+}
+#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC)
+inline TQt::HANDLE TQPainter::handle() const
+{
+ return hd;
+}
+#endif
+
+inline void TQPainter::setBrushOrigin( const TQPoint &p )
+{
+ setBrushOrigin( p.x(), p.y() );
+}
+
+#ifndef TQT_NO_TRANSFORMATIONS
+inline void TQPainter::setWindow( const TQRect &r )
+{
+ setWindow( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::setViewport( const TQRect &r )
+{
+ setViewport( r.x(), r.y(), r.width(), r.height() );
+}
+#endif
+
+inline void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m )
+{
+ setClipRect( TQRect(x,y,w,h), m );
+}
+
+inline void TQPainter::drawPoint( const TQPoint &p )
+{
+ drawPoint( p.x(), p.y() );
+}
+
+inline void TQPainter::moveTo( const TQPoint &p )
+{
+ moveTo( p.x(), p.y() );
+}
+
+inline void TQPainter::lineTo( const TQPoint &p )
+{
+ lineTo( p.x(), p.y() );
+}
+
+inline void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 )
+{
+ drawLine( p1.x(), p1.y(), p2.x(), p2.y() );
+}
+
+inline void TQPainter::drawRect( const TQRect &r )
+{
+ drawRect( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::drawWinFocusRect( const TQRect &r )
+{
+ drawWinFocusRect( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::drawWinFocusRect( const TQRect &r,const TQColor &penColor )
+{
+ drawWinFocusRect( r.x(), r.y(), r.width(), r.height(), penColor );
+}
+
+inline void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd )
+{
+ drawRoundRect( r.x(), r.y(), r.width(), r.height(), xRnd, yRnd );
+}
+
+inline void TQPainter::drawEllipse( const TQRect &r )
+{
+ drawEllipse( r.x(), r.y(), r.width(), r.height() );
+}
+
+inline void TQPainter::drawArc( const TQRect &r, int a, int alen )
+{
+ drawArc( r.x(), r.y(), r.width(), r.height(), a, alen );
+}
+
+inline void TQPainter::drawPie( const TQRect &r, int a, int alen )
+{
+ drawPie( r.x(), r.y(), r.width(), r.height(), a, alen );
+}
+
+inline void TQPainter::drawChord( const TQRect &r, int a, int alen )
+{
+ drawChord( r.x(), r.y(), r.width(), r.height(), a, alen );
+}
+
+inline void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm,
+ const TQRect &sr )
+{
+ drawPixmap( p.x(), p.y(), pm, sr.x(), sr.y(), sr.width(), sr.height() );
+}
+
+inline void TQPainter::drawImage( const TQPoint &p, const TQImage &pm,
+ const TQRect &sr, int conversionFlags )
+{
+ drawImage( p.x(), p.y(), pm,
+ sr.x(), sr.y(), sr.width(), sr.height(), conversionFlags );
+}
+
+inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm,
+ const TQPoint &sp )
+{
+ drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, sp.x(), sp.y() );
+}
+
+inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm )
+{
+ drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, 0, 0 );
+}
+
+inline void TQPainter::fillRect( const TQRect &r, const TQBrush &brush )
+{
+ fillRect( r.x(), r.y(), r.width(), r.height(), brush );
+}
+
+inline void TQPainter::eraseRect( int x, int y, int w, int h )
+{
+ fillRect( x, y, w, h, backgroundColor() );
+}
+
+inline void TQPainter::eraseRect( const TQRect &r )
+{
+ fillRect( r.x(), r.y(), r.width(), r.height(), backgroundColor() );
+}
+
+inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int len, TextDirection dir )
+{
+ drawText( p.x(), p.y(), s, 0, len, dir );
+}
+
+inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir )
+{
+ drawText( p.x(), p.y(), s, pos, len, dir );
+}
+
+inline void TQPainter::drawText( int x, int y, int w, int h, int tf,
+ const TQString& str, int len, TQRect *br, TQTextParag **i )
+{
+ TQRect r(x, y, w, h);
+ drawText( r, tf, str, len, br, i );
+}
+
+inline void TQPainter::tqdrawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags )
+{
+ tqdrawTextItem( p.x(), p.y(), ti, textflags );
+}
+
+inline TQRect TQPainter::boundingRect( int x, int y, int w, int h, int tf,
+ const TQString& str, int len, TQTextParag **i )
+{
+ TQRect r(x, y, w, h);
+ return boundingRect( r, tf, str, len, i );
+}
+
+#if defined(TQ_WS_TQWS)
+inline TQGfx * TQPainter::internalGfx()
+{
+ return gfx;
+}
+#endif
+
+#endif // USE_QT4
+
+#endif // TQPAINTER_H
diff --git a/tqtinterface/qt4/src/kernel/tqpainter_p.h b/tqtinterface/qt4/src/kernel/tqpainter_p.h
new file mode 100644
index 0000000..85dedc0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpainter_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Definition of some TQt private functions.
+**
+** Created : 000909
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPAINTER_P_H
+#define TQPAINTER_P_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of qpainter.cpp and qfont.cpp. This header file may change
+// from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#endif // TQT_H
+
+extern void qt_format_text( const TQFont& f, const TQRect &r,
+ int tf, const TQString& str, int len, TQRect *brect,
+ int tabstops, int* tabarray, int tabarraylen,
+ TQTextParag **internal, TQPainter* painter );
+
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqpainter_x11.cpp b/tqtinterface/qt4/src/kernel/tqpainter_x11.cpp
new file mode 100644
index 0000000..ac788d4
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpainter_x11.cpp
@@ -0,0 +1,3348 @@
+/****************************************************************************
+**
+** Implementation of TQPainter class for X11
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+#ifdef USE_QT4
+#include <Qt/qtextstream.h>
+#endif // USE_QT4
+
+#include "tqfont.h"
+#include "tqpainter.h"
+#include "tqwidget.h"
+#include "tqbitmap.h"
+#include "tqpixmapcache.h"
+#include "tqtextcodec.h"
+#include "tqpaintdevicemetrics.h"
+
+#include "tqt_x11_p.h"
+
+#include "tqtextlayout_p.h"
+#include "tqfontdata_p.h"
+#include "tqfontengine_p.h"
+#include "tqtextengine_p.h"
+
+#include <math.h>
+
+#ifdef USE_QT4
+
+/*! \internal
+ Draws the text item \a ti at position \a (x, y ).
+
+ This method ignores the painters background mode and
+ color. drawText and qt_format_text have to do it themselves, as
+ only they know the extents of the complete string.
+
+ It ignores the font set on the painter as the text item has one of its own.
+
+ The underline and strikeout parameters of the text items font are
+ ignored as well. You'll need to pass in the correct flags to get
+ underlining and strikeout.
+*/
+void TQPainter::tqdrawTextItem( int x, int y, const TQTextItem &ti, int textFlags )
+{
+ ti.tqt_tqdrawTextItem( const_cast<TQPainter*>(this), x, y, ti, textFlags );
+}
+
+/*!
+ Sets the \link TQt::RasterOp raster operation \endlink to \a r.
+ The default is \c CopyROP.
+
+ \sa rasterOp() TQt::RasterOp
+*/
+
+void TQPainter::setRasterOp( TQt::RasterOp r )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setRasterOp: Call begin() first" );
+#endif
+ return;
+ }
+ if ( (uint)r > TQt::LastROP ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPainter::setRasterOp: Invalid ROP code" );
+#endif
+ return;
+ }
+ rop = r;
+
+// [FIXME]
+// This needs to be implemented for Qt4
+// See http://lists.trolltech.com/qt-interest/2007-05/thread00975-0.html
+// printf("[WARNING] TQPainter::setRasterOp( TQt::RasterOp r ) unimplemented [Was attempting to use raster operation %d\n\r", rop);
+
+// An attempt to work around this on X11 only
+// See http://doc.qt.nokia.com/latest/qpainter.html#CompositionMode-enum
+
+ QPainter::CompositionMode cm;
+ switch (rop) {
+ case CopyROP:
+ cm=QPainter::CompositionMode_SourceOver;
+ break;
+ case OrROP:
+ cm=QPainter::RasterOp_SourceOrDestination;
+ break;
+ case XorROP:
+ cm=QPainter::RasterOp_SourceXorDestination;
+ break;
+ case NotAndROP:
+ cm=QPainter::RasterOp_NotSourceAndDestination;
+ break;
+// case EraseROP:
+// cm=QPainter::RasterOp_NotSourceAndDestination;
+// break;
+ case NotCopyROP:
+ cm=QPainter::RasterOp_NotSource;
+ break;
+ case NotOrROP:
+ printf("[WARNING] TQPainter::setRasterOp( TQt::RasterOp r ) unimplemented [Was attempting to use raster operation %d\n\r", rop);
+ return;
+ break;
+ case NotXorROP:
+ cm=QPainter::RasterOp_NotSourceXorDestination;
+ break;
+ case AndROP:
+ cm=QPainter::RasterOp_SourceAndDestination;
+ break;
+// case NotEraseROP:
+// cm=QPainter::RasterOp_SourceAndDestination;
+// break;
+ case NotROP:
+ cm=QPainter::RasterOp_SourceAndNotDestination; // [WARNING] This may not be a correct substitute for NotROP!
+ break;
+ case ClearROP:
+ cm=QPainter::CompositionMode_Clear;
+ break;
+ case SetROP:
+ printf("[WARNING] TQPainter::setRasterOp( TQt::RasterOp r ) unimplemented [Was attempting to use raster operation %d\n\r", rop);
+ return;
+ break;
+ case NopROP:
+ cm=QPainter::CompositionMode_Destination;
+ break;
+ case AndNotROP:
+ cm=QPainter::RasterOp_SourceAndNotDestination;
+ break;
+ case OrNotROP:
+ printf("[WARNING] TQPainter::setRasterOp( TQt::RasterOp r ) unimplemented [Was attempting to use raster operation %d\n\r", rop);
+ return;
+ break;
+ case NandROP:
+ cm=QPainter::RasterOp_NotSourceOrNotDestination;
+ break;
+ case NorROP:
+ cm=QPainter::RasterOp_NotSourceAndNotDestination;
+ break;
+ }
+
+ setCompositionMode(cm);
+
+// if ( testf(ExtDev) ) {
+// TQPDevCmdParam param[1];
+// param[0].ival = r;
+// if ( !pdev->cmd( TQPaintDevice::PdcSetROP, this, param ) || !hd )
+// return;
+// }
+// if ( penRef )
+// updatePen(); // get non-cached pen GC
+// if ( brushRef )
+// updateBrush(); // get non-cached brush GC
+// XSetFunction( dpy, gc, ropCodes[rop] );
+// XSetFunction( dpy, gc_brush, ropCodes[rop] );
+}
+
+/*!
+ \internal
+*/
+
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h, bool xorPaint, const QColor &bgColor )
+{
+ if ( !isActive() /*|| txop == TxRotShear*/ )
+ return;
+ static char winfocus_line[] = { 1, 1 };
+
+ TQPen old_pen = pen();
+ RasterOp old_rop = (RasterOp)rasterOp();
+
+ if ( xorPaint ) {
+ if ( TQColor::numBitPlanes() <= 8 )
+ setPen( color1 );
+ else
+ setPen( white );
+ setRasterOp( XorROP );
+ } else {
+ if ( tqGray( bgColor.rgb() ) < 128 )
+ setPen( white );
+ else
+ setPen( black );
+ }
+
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+// TQPDevCmdParam param[1];
+// TQRect r( x, y, w, h );
+// param[0].rect = &r;
+// if ( !pdev->cmd( TQPaintDevice::PdcDrawRect, this, param ) || !hd) {
+// setRasterOp( old_rop );
+// setPen( old_pen );
+// return;
+// }
+ printf("[FIXME] TQPainter::drawWinFocusRect not yet supported on external paint devices\n\r");
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+// if ( w <= 0 || h <= 0 ) {
+// if ( w == 0 || h == 0 )
+// return;
+// fix_neg_rect( &x, &y, &w, &h );
+// }
+
+// XSetDashes( dpy, gc, 0, winfocus_line, 2 );
+// XSetLineAttributes( dpy, gc, 1, LineOnOffDash, CapButt, JoinMiter );
+// XDrawRectangle( dpy, hd, gc, x, y, w-1, h-1 );
+// XSetLineAttributes( dpy, gc, 0, LineSolid, CapButt, JoinMiter );
+
+ printf("[WARNING] TQPainter::drawWinFocusRect may not draw the correct rectangle in all cases [due to shift from Xorg to Qt painting]\n\r");
+// drawRect( x, y, w-1, h-1 );
+ drawRect( x, y, w, h );
+
+ setRasterOp( old_rop );
+ setPen( old_pen );
+}
+
+#else // USE_QT4
+
+// paintevent magic to provide Windows semantics on X11
+static TQRegion* paintEventClipRegion = 0;
+static TQPaintDevice* paintEventDevice = 0;
+
+void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region)
+{
+ if ( !paintEventClipRegion )
+ paintEventClipRegion = new TQRegion( region );
+ else
+ *paintEventClipRegion = region;
+ paintEventDevice = dev;
+}
+
+void qt_clear_paintevent_clipping()
+{
+ delete paintEventClipRegion;
+ paintEventClipRegion = 0;
+ paintEventDevice = 0;
+}
+
+class TQWFlagWidget : public TQWidget
+{
+public:
+ void setWState( WFlags f ) { TQWidget::setWState(f); }
+ void clearWState( WFlags f ) { TQWidget::clearWState(f); }
+ void setWFlags( WFlags f ) { TQWidget::setWFlags(f); }
+ void clearWFlags( WFlags f ) { TQWidget::clearWFlags(f); }
+};
+
+void qt_erase_region( TQWidget* w, const TQRegion& region)
+{
+ TQRegion reg = region;
+
+ if ( TQPainter::redirect(w) || (!w->isTopLevel() && w->backgroundPixmap()
+ && w->backgroundOrigin() != TQWidget::WidgetOrigin) ) {
+ TQPoint offset = w->backgroundOffset();
+ int ox = offset.x();
+ int oy = offset.y();
+
+ bool unclipped = w->testWFlags( TQt::WPaintUnclipped );
+ if ( unclipped )
+ ((TQWFlagWidget*)w)->clearWFlags( TQt::WPaintUnclipped );
+ TQPainter p( w );
+ p.setClipRegion( region ); // automatically includes paintEventDevice if required
+ if ( w->backgroundPixmap() )
+ p.drawTiledPixmap( 0, 0, w->width(), w->height(),
+ *w->backgroundPixmap(), ox, oy );
+ else
+ p.fillRect( w->rect(), w->eraseColor() );
+ if ( unclipped )
+ ((TQWFlagWidget*)w)->setWFlags( TQt::WPaintUnclipped );
+ return;
+ }
+
+ if ( w == paintEventDevice && paintEventClipRegion )
+ reg = paintEventClipRegion->intersect( reg );
+
+ TQMemArray<TQRect> r = reg.rects();
+ for (uint i=0; i<r.size(); i++) {
+ const TQRect& rr = r[(int)i];
+ XClearArea( w->x11Display(), w->winId(),
+ rr.x(), rr.y(), rr.width(), rr.height(), False );
+ }
+}
+
+void qt_erase_rect( TQWidget* w, const TQRect& r)
+{
+ if ( TQPainter::redirect(w) || w == paintEventDevice
+ || w->backgroundOrigin() != TQWidget::WidgetOrigin )
+ qt_erase_region( w, r );
+ else
+ XClearArea( w->x11Display(), w->winId(), r.x(), r.y(), r.width(), r.height(), False );
+
+}
+
+#ifdef TQT_NO_XFTFREETYPE
+static const TQt::HANDLE rendhd = 0;
+#endif
+
+// hack, so we don't have to make TQRegion::clipRectangles() public or include
+// X11 headers in tqregion.h
+inline void *qt_getClipRects( const TQRegion &r, int &num )
+{
+ return r.clipRectangles( num );
+}
+
+static inline void x11SetClipRegion(Display *dpy, GC gc, GC gc2, TQt::HANDLE draw, const TQRegion &r)
+{
+ int num;
+ XRectangle *rects = (XRectangle *)qt_getClipRects( r, num );
+
+ if (gc)
+ XSetClipRectangles( dpy, gc, 0, 0, rects, num, YXBanded );
+ if (gc2)
+ XSetClipRectangles( dpy, gc2, 0, 0, rects, num, YXBanded );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (draw)
+ XftDrawSetClipRectangles((XftDraw *) draw, 0, 0, rects, num);
+#else
+ TQ_UNUSED(draw);
+#endif // TQT_NO_XFTFREETYPE
+}
+
+static inline void x11ClearClipRegion(Display *dpy, GC gc, GC gc2, TQt::HANDLE draw)
+{
+ if (gc)
+ XSetClipMask(dpy, gc, None);
+ if (gc2)
+ XSetClipMask(dpy, gc2, None);
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (draw) {
+# ifdef TQT_XFT2
+ XftDrawSetClip((XftDraw *) draw, None);
+# else
+ // stupid Xft1
+ Picture pict = XftDrawPicture((XftDraw *) draw);
+ XRenderPictureAttributes pattr;
+ pattr.clip_mask = None;
+ XRenderChangePicture(dpy, pict, CPClipMask, &pattr);
+# endif // TQT_XFT2
+ }
+#else
+ TQ_UNUSED(draw);
+#endif // TQT_NO_XFTFREETYPE
+}
+
+
+/*****************************************************************************
+ Trigonometric function for TQPainter
+
+ We have implemented simple sine and cosine function that are called from
+ TQPainter::drawPie() and TQPainter::drawChord() when drawing the outline of
+ pies and chords.
+ These functions are slower and less accurate than math.h sin() and cos(),
+ but with still around 1/70000th sec. execution time (on a 486DX2-66) and
+ 8 digits accuracy, it should not be the bottleneck in drawing these tqshapes.
+ The advantage is that you don't have to link in the math library.
+ *****************************************************************************/
+
+const double TQ_PI = 3.14159265358979323846; // pi
+const double TQ_2PI = 6.28318530717958647693; // 2*pi
+const double TQ_PI2 = 1.57079632679489661923; // pi/2
+
+
+#if defined(TQ_CC_GNU) && defined(TQ_OS_AIX)
+// AIX 4.2 gcc 2.7.2.3 gets internal error.
+static int tqRoundAIX( double d )
+{
+ return tqRound(d);
+}
+#define tqRound tqRoundAIX
+#endif
+
+
+#if defined(TQ_CC_GNU) && defined(__i386__)
+
+inline double qcos( double a )
+{
+ double r;
+ __asm__ (
+ "fcos"
+ : "=t" (r) : "0" (a) );
+ return(r);
+}
+
+inline double qsin( double a )
+{
+ double r;
+ __asm__ (
+ "fsin"
+ : "=t" (r) : "0" (a) );
+ return(r);
+}
+
+double qsincos( double a, bool calcCos=FALSE )
+{
+ return calcCos ? qcos(a) : qsin(a);
+}
+
+#else
+
+double qsincos( double a, bool calcCos=FALSE )
+{
+ if ( calcCos ) // calculate cosine
+ a -= TQ_PI2;
+ if ( a >= TQ_2PI || a <= -TQ_2PI ) { // fix range: -2*pi < a < 2*pi
+ int m = (int)(a/TQ_2PI);
+ a -= TQ_2PI*m;
+ }
+ if ( a < 0.0 ) // 0 <= a < 2*pi
+ a += TQ_2PI;
+ int sign = a > TQ_PI ? -1 : 1;
+ if ( a >= TQ_PI )
+ a = TQ_2PI - a;
+ if ( a >= TQ_PI2 )
+ a = TQ_PI - a;
+ if ( calcCos )
+ sign = -sign;
+ double a2 = a*a; // here: 0 <= a < pi/4
+ double a3 = a2*a; // make taylor sin sum
+ double a5 = a3*a2;
+ double a7 = a5*a2;
+ double a9 = a7*a2;
+ double a11 = a9*a2;
+ return (a-a3/6+a5/120-a7/5040+a9/362880-a11/39916800)*sign;
+}
+
+inline double qsin( double a ) { return qsincos(a, FALSE); }
+inline double qcos( double a ) { return qsincos(a, TRUE); }
+
+#endif
+
+
+/*****************************************************************************
+ TQPainter internal GC (Graphics Context) allocator.
+
+ The GC allocator offers two functions; alloc_gc() and free_gc() that
+ reuse GC objects instead of calling XCreateGC() and XFreeGC(), which
+ are a whole lot slower.
+ *****************************************************************************/
+
+struct TQGC
+{
+ GC gc;
+ char in_use;
+ bool mono;
+ int scrn;
+};
+
+const int gc_array_size = 256;
+static TQGC gc_array[gc_array_size]; // array of GCs
+static bool gc_array_init = FALSE;
+
+
+static void init_gc_array()
+{
+ if ( !gc_array_init ) {
+ memset( gc_array, 0, gc_array_size*sizeof(TQGC) );
+ gc_array_init = TRUE;
+ }
+}
+
+static void cleanup_gc_array( Display *dpy )
+{
+ register TQGC *p = gc_array;
+ int i = gc_array_size;
+ if ( gc_array_init ) {
+ while ( i-- ) {
+ if ( p->gc ) // destroy GC
+ XFreeGC( dpy, p->gc );
+ p++;
+ }
+ gc_array_init = FALSE;
+ }
+}
+
+// #define DONT_USE_GC_ARRAY
+
+static GC alloc_gc( Display *dpy, int scrn, Drawable hd, bool monochrome=FALSE,
+ bool privateGC = FALSE )
+{
+#if defined(DONT_USE_GC_ARRAY)
+ privateGC = TRUE; // will be slower
+#endif
+ if ( privateGC ) {
+ GC gc = XCreateGC( dpy, hd, 0, 0 );
+ XSetGraphicsExposures( dpy, gc, False );
+ return gc;
+ }
+ register TQGC *p = gc_array;
+ int i = gc_array_size;
+ if ( !gc_array_init ) // not initialized
+ init_gc_array();
+ while ( i-- ) {
+ if ( !p->gc ) { // create GC (once)
+ p->gc = XCreateGC( dpy, hd, 0, 0 );
+ p->scrn = scrn;
+ XSetGraphicsExposures( dpy, p->gc, False );
+ p->in_use = FALSE;
+ p->mono = monochrome;
+ }
+ if ( !p->in_use && p->mono == monochrome && p->scrn == scrn ) {
+ p->in_use = TRUE; // available/compatible GC
+ return p->gc;
+ }
+ p++;
+ }
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQPainter: Internal error; no available GC" );
+#endif
+ GC gc = XCreateGC( dpy, hd, 0, 0 );
+ XSetGraphicsExposures( dpy, gc, False );
+ return gc;
+}
+
+static void free_gc( Display *dpy, GC gc, bool privateGC = FALSE )
+{
+#if defined(DONT_USE_GC_ARRAY)
+ privateGC = TRUE; // will be slower
+#endif
+ if ( privateGC ) {
+ TQ_ASSERT( dpy != 0 );
+ XFreeGC( dpy, gc );
+ return;
+ }
+ register TQGC *p = gc_array;
+ int i = gc_array_size;
+ if ( gc_array_init ) {
+ while ( i-- ) {
+ if ( p->gc == gc ) {
+ p->in_use = FALSE; // set available
+ XSetClipMask( dpy, gc, None ); // make it reusable
+ XSetFunction( dpy, gc, GXcopy );
+ XSetFillStyle( dpy, gc, FillSolid );
+ XSetTSOrigin( dpy, gc, 0, 0 );
+ return;
+ }
+ p++;
+ }
+ }
+
+ // not found in gc_array
+ XFreeGC(dpy, gc);
+}
+
+
+/*****************************************************************************
+ TQPainter internal GC (Graphics Context) cache for solid pens and
+ brushes.
+
+ The GC cache makes a significant contribution to speeding up
+ drawing. Setting new pen and brush colors will make the painter
+ look for another GC with the same color instead of changing the
+ color value of the GC currently in use. The cache structure is
+ optimized for fast lookup. Only solid line pens with line width 0
+ and solid brushes are cached.
+
+ In addition, stored GCs may have an implicit clipping region
+ set. This prevents any drawing outside paint events. Both
+ updatePen() and updateBrush() keep track of the validity of this
+ clipping region by storing the clip_serial number in the cache.
+
+*****************************************************************************/
+
+struct TQGCC // cached GC
+{
+ GC gc;
+ uint pix;
+ int count;
+ int hits;
+ uint clip_serial;
+ int scrn;
+};
+
+const int gc_cache_size = 29; // multiply by 4
+static TQGCC *gc_cache_buf;
+static TQGCC *gc_cache[4*gc_cache_size];
+static bool gc_cache_init = FALSE;
+static uint gc_cache_clip_serial = 0;
+
+
+static void init_gc_cache()
+{
+ if ( !gc_cache_init ) {
+ gc_cache_init = TRUE;
+ gc_cache_clip_serial = 0;
+ TQGCC *g = gc_cache_buf = new TQGCC[4*gc_cache_size];
+ memset( g, 0, 4*gc_cache_size*sizeof(TQGCC) );
+ for ( int i=0; i<4*gc_cache_size; i++ )
+ gc_cache[i] = g++;
+ }
+}
+
+
+// #define GC_CACHE_STAT
+#if defined(GC_CACHE_STAT)
+#include "tqtextstream.h"
+#include "tqbuffer.h"
+
+static int g_numhits = 0;
+static int g_numcreates = 0;
+static int g_numfaults = 0;
+#endif
+
+
+static void cleanup_gc_cache()
+{
+ if ( !gc_cache_init )
+ return;
+#if defined(GC_CACHE_STAT)
+ qDebug( "Number of cache hits = %d", g_numhits );
+ qDebug( "Number of cache creates = %d", g_numcreates );
+ qDebug( "Number of cache faults = %d", g_numfaults );
+ for ( int i=0; i<gc_cache_size; i++ ) {
+ TQCString str;
+ TQBuffer buf( str );
+ buf.open(IO_ReadWrite);
+ TQTextStream s(&buf);
+ s << i << ": ";
+ for ( int j=0; j<4; j++ ) {
+ TQGCC *g = gc_cache[i*4+j];
+ s << (g->gc ? 'X' : '-') << ',' << g->hits << ','
+ << g->count << '\t';
+ }
+ s << '\0';
+ qDebug( str );
+ buf.close();
+ }
+#endif
+ delete [] gc_cache_buf;
+ gc_cache_init = FALSE;
+}
+
+
+static bool obtain_gc( void **ref, GC *gc, uint pix, Display *dpy, int scrn,
+ TQt::HANDLE hd, uint painter_clip_serial )
+{
+ if ( !gc_cache_init )
+ init_gc_cache();
+
+ int k = (pix % gc_cache_size) * 4;
+ TQGCC *g = gc_cache[k];
+ TQGCC *prev = 0;
+
+#define NOMATCH (g->gc && (g->pix != pix || g->scrn != scrn || \
+ (g->clip_serial > 0 && g->clip_serial != painter_clip_serial)))
+
+ if ( NOMATCH ) {
+ prev = g;
+ g = gc_cache[++k];
+ if ( NOMATCH ) {
+ prev = g;
+ g = gc_cache[++k];
+ if ( NOMATCH ) {
+ prev = g;
+ g = gc_cache[++k];
+ if ( NOMATCH ) {
+ if ( g->count == 0 && g->scrn == scrn) { // steal this GC
+ g->pix = pix;
+ g->count = 1;
+ g->hits = 1;
+ g->clip_serial = 0;
+ XSetForeground( dpy, g->gc, pix );
+ XSetClipMask(dpy, g->gc, None);
+ gc_cache[k] = prev;
+ gc_cache[k-1] = g;
+ *ref = (void *)g;
+ *gc = g->gc;
+ return TRUE;
+ } else { // all GCs in use
+#if defined(GC_CACHE_STAT)
+ g_numfaults++;
+#endif
+ *ref = 0;
+ return FALSE;
+ }
+ }
+ }
+ }
+ }
+
+#undef NOMATCH
+
+ *ref = (void *)g;
+
+ if ( g->gc ) { // reuse existing GC
+#if defined(GC_CACHE_STAT)
+ g_numhits++;
+#endif
+ *gc = g->gc;
+ g->count++;
+ g->hits++;
+ if ( prev && g->hits > prev->hits ) { // maintain LRU order
+ gc_cache[k] = prev;
+ gc_cache[k-1] = g;
+ }
+ return TRUE;
+ } else { // create new GC
+#if defined(GC_CACHE_STAT)
+ g_numcreates++;
+#endif
+ g->gc = alloc_gc( dpy, scrn, hd, FALSE );
+ g->scrn = scrn;
+ g->pix = pix;
+ g->count = 1;
+ g->hits = 1;
+ g->clip_serial = 0;
+ *gc = g->gc;
+ return FALSE;
+ }
+}
+
+static inline void release_gc( void *ref )
+{
+ ((TQGCC*)ref)->count--;
+}
+
+/*****************************************************************************
+ TQPainter member functions
+ *****************************************************************************/
+
+/*!
+ \internal
+
+ Internal function that initializes the painter.
+*/
+
+void TQPainter::initialize()
+{
+ init_gc_array();
+ init_gc_cache();
+}
+
+/*!
+ \internal
+
+ Internal function that cleans up the painter.
+*/
+
+void TQPainter::cleanup()
+{
+ cleanup_gc_cache();
+ cleanup_gc_array( TQPaintDevice::x11AppDisplay() );
+ TQPointArray::cleanBuffers();
+}
+
+/*!
+ \internal
+
+ Internal function that destroys up the painter.
+*/
+
+void TQPainter::destroy()
+{
+
+}
+
+void TQPainter::init()
+{
+ d = 0;
+ flags = IsStartingUp;
+ bg_col = white; // default background color
+ bg_mode = TransparentMode; // default background mode
+ rop = CopyROP; // default ROP
+ tabstops = 0; // default tabbing
+ tabarray = 0;
+ tabarraylen = 0;
+ ps_stack = 0;
+ wm_stack = 0;
+ gc = gc_brush = 0;
+ pdev = 0;
+ dpy = 0;
+ txop = txinv = 0;
+ penRef = brushRef = 0;
+ clip_serial = 0;
+ pfont = 0;
+ block_ext = FALSE;
+}
+
+
+/*!
+ \fn const TQFont &TQPainter::font() const
+
+ Returns the currently set painter font.
+
+ \sa setFont(), TQFont
+*/
+
+/*!
+ Sets the painter's font to \a font.
+
+ This font is used by subsequent drawText() functions. The text
+ color is the same as the pen color.
+
+ \sa font(), drawText()
+*/
+
+void TQPainter::setFont( const TQFont &font )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setFont: Will be reset by begin()" );
+#endif
+ if ( cfont.d != font.d ) {
+ cfont = font;
+ cfont.x11SetScreen( scrn );
+ setf(DirtyFont);
+ }
+}
+
+
+void TQPainter::updateFont()
+{
+ if (!isActive())
+ return;
+
+ clearf(DirtyFont);
+ if ( testf(ExtDev) ) {
+ if (pdev->devType() == TQInternal::Printer) {
+ if ( pfont ) delete pfont;
+ pfont = new TQFont( cfont.d, pdev );
+ }
+ TQPDevCmdParam param[1];
+ param[0].font = &cfont;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetFont, this, param ) || !hd )
+ return;
+ }
+ setf(NoCache);
+ if ( penRef )
+ updatePen(); // force a non-cached GC
+}
+
+
+void TQPainter::updatePen()
+{
+ if (!isActive())
+ return;
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].pen = &cpen;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetPen, this, param ) || !hd )
+ return;
+ }
+
+ int ps = cpen.style();
+ bool cacheIt = !testf(ClipOn|MonoDev|NoCache) &&
+ (ps == NoPen || ps == SolidLine) &&
+ cpen.width() == 0 && rop == CopyROP;
+
+ bool obtained = FALSE;
+ bool internclipok = hasClipping();
+ if ( cacheIt ) {
+ if ( gc ) {
+ if ( penRef )
+ release_gc( penRef );
+ else
+ free_gc( dpy, gc );
+ }
+ obtained = obtain_gc(&penRef, &gc, cpen.color().pixel(scrn), dpy, scrn,
+ hd, clip_serial);
+ if ( !obtained && !penRef )
+ gc = alloc_gc( dpy, scrn, hd, FALSE );
+ } else {
+ if ( gc ) {
+ if ( penRef ) {
+ release_gc( penRef );
+ penRef = 0;
+ gc = alloc_gc( dpy, scrn, hd, testf(MonoDev) );
+ } else {
+ internclipok = TRUE;
+ }
+ } else {
+ gc = alloc_gc( dpy, scrn, hd, testf(MonoDev), testf(UsePrivateCx) );
+ }
+ }
+
+ if ( !internclipok ) {
+ if ( pdev == paintEventDevice && paintEventClipRegion ) {
+ if ( penRef &&((TQGCC*)penRef)->clip_serial < gc_cache_clip_serial ) {
+ x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion );
+ ((TQGCC*)penRef)->clip_serial = gc_cache_clip_serial;
+ } else if ( !penRef ) {
+ x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion );
+ }
+ } else if (penRef && ((TQGCC*)penRef)->clip_serial ) {
+ x11ClearClipRegion(dpy, gc, 0, rendhd);
+ ((TQGCC*)penRef)->clip_serial = 0;
+ }
+ }
+
+ if ( obtained )
+ return;
+
+ char dashes[10]; // custom pen dashes
+ int dash_len = 0; // length of dash list
+ int s = LineSolid;
+ int cp = CapButt;
+ int jn = JoinMiter;
+
+ /*
+ We are emulating Windows here. Windows treats cpen.width() == 1
+ (or 0) as a very special case. The fudge variable unifies this
+ case with the general case.
+ */
+ int dot = cpen.width(); // width of a dot
+ int fudge = 1;
+ bool allow_zero_lw = TRUE;
+ if ( dot <= 1 ) {
+ dot = 3;
+ fudge = 2;
+ }
+
+ switch( ps ) {
+ case NoPen:
+ case SolidLine:
+ s = LineSolid;
+ break;
+ case DashLine:
+ dashes[0] = fudge * 3 * dot;
+ dashes[1] = fudge * dot;
+ dash_len = 2;
+ allow_zero_lw = FALSE;
+ break;
+ case DotLine:
+ dashes[0] = dot;
+ dashes[1] = dot;
+ dash_len = 2;
+ allow_zero_lw = FALSE;
+ break;
+ case DashDotLine:
+ dashes[0] = 3 * dot;
+ dashes[1] = fudge * dot;
+ dashes[2] = dot;
+ dashes[3] = fudge * dot;
+ dash_len = 4;
+ allow_zero_lw = FALSE;
+ break;
+ case DashDotDotLine:
+ dashes[0] = 3 * dot;
+ dashes[1] = dot;
+ dashes[2] = dot;
+ dashes[3] = dot;
+ dashes[4] = dot;
+ dashes[5] = dot;
+ dash_len = 6;
+ allow_zero_lw = FALSE;
+ }
+ TQ_ASSERT( dash_len <= (int) sizeof(dashes) );
+
+ switch ( cpen.capStyle() ) {
+ case SquareCap:
+ cp = CapProjecting;
+ break;
+ case RoundCap:
+ cp = CapRound;
+ break;
+ case FlatCap:
+ default:
+ cp = CapButt;
+ break;
+ }
+ switch ( cpen.joinStyle() ) {
+ case BevelJoin:
+ jn = JoinBevel;
+ break;
+ case RoundJoin:
+ jn = JoinRound;
+ break;
+ case MiterJoin:
+ default:
+ jn = JoinMiter;
+ break;
+ }
+
+ XSetForeground( dpy, gc, cpen.color().pixel(scrn) );
+ XSetBackground( dpy, gc, bg_col.pixel(scrn) );
+
+ if ( dash_len ) { // make dash list
+ XSetDashes( dpy, gc, 0, dashes, dash_len );
+ s = bg_mode == TransparentMode ? LineOnOffDash : LineDoubleDash;
+ }
+ XSetLineAttributes( dpy, gc,
+ (! allow_zero_lw && cpen.width() == 0) ? 1 : cpen.width(),
+ s, cp, jn );
+}
+
+
+void TQPainter::updateBrush()
+{
+ if (!isActive())
+ return;
+
+ static const uchar dense1_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff };
+ static const uchar dense2_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff };
+ static const uchar dense3_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee };
+ static const uchar dense4_pat[] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa };
+ static const uchar dense5_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 };
+ static const uchar dense6_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 };
+ static const uchar dense7_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 };
+ static const uchar hor_pat[] = { // horizontal pattern
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ static const uchar ver_pat[] = { // vertical pattern
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20 };
+ static const uchar cross_pat[] = { // cross pattern
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0xff, 0xff, 0xff,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0xff, 0xff, 0xff,
+ 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20,
+ 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20 };
+ static const uchar bdiag_pat[] = { // backward diagonal pattern
+ 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01,
+ 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04,
+ 0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40 };
+ static const uchar fdiag_pat[] = { // forward diagonal pattern
+ 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40,
+ 0x80, 0x80, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10,
+ 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x01, 0x01 };
+ static const uchar dcross_pat[] = { // diagonal cross pattern
+ 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14, 0x22, 0x22, 0x41, 0x41,
+ 0x80, 0x80, 0x41, 0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14,
+ 0x22, 0x22, 0x41, 0x41, 0x80, 0x80, 0x41, 0x41 };
+ static const uchar * const pat_tbl[] = {
+ dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat,
+ dense6_pat, dense7_pat,
+ hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat };
+
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].brush = &cbrush;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetBrush, this, param ) || !hd )
+ return;
+ }
+
+ int bs = cbrush.style();
+ bool cacheIt = !testf(ClipOn|MonoDev|NoCache) &&
+ (bs == NoBrush || bs == SolidPattern) &&
+ bro.x() == 0 && bro.y() == 0 && rop == CopyROP;
+
+ bool obtained = FALSE;
+ bool internclipok = hasClipping();
+ if ( cacheIt ) {
+ if ( gc_brush ) {
+ if ( brushRef )
+ release_gc( brushRef );
+ else
+ free_gc( dpy, gc_brush );
+ }
+ obtained = obtain_gc(&brushRef, &gc_brush, cbrush.color().pixel(scrn), dpy,
+ scrn, hd, clip_serial);
+ if ( !obtained && !brushRef )
+ gc_brush = alloc_gc( dpy, scrn, hd, FALSE );
+ } else {
+ if ( gc_brush ) {
+ if ( brushRef ) {
+ release_gc( brushRef );
+ brushRef = 0;
+ gc_brush = alloc_gc( dpy, scrn, hd, testf(MonoDev) );
+ } else {
+ internclipok = TRUE;
+ }
+ } else {
+ gc_brush = alloc_gc( dpy, scrn, hd, testf(MonoDev), testf(UsePrivateCx));
+ }
+ }
+
+ if ( !internclipok ) {
+ if ( pdev == paintEventDevice && paintEventClipRegion ) {
+ if ( brushRef &&((TQGCC*)brushRef)->clip_serial < gc_cache_clip_serial ) {
+ x11SetClipRegion( dpy, gc_brush, 0, rendhd, *paintEventClipRegion );
+ ((TQGCC*)brushRef)->clip_serial = gc_cache_clip_serial;
+ } else if ( !brushRef ){
+ x11SetClipRegion( dpy, gc_brush, 0, rendhd, *paintEventClipRegion );
+ }
+ } else if (brushRef && ((TQGCC*)brushRef)->clip_serial ) {
+ x11ClearClipRegion(dpy, gc_brush, 0, rendhd);
+ ((TQGCC*)brushRef)->clip_serial = 0;
+ }
+ }
+
+ if ( obtained )
+ return;
+
+ const uchar *pat = 0; // pattern
+ int d = 0; // defalt pattern size: d*d
+ int s = FillSolid;
+ if ( bs >= Dense1Pattern && bs <= DiagCrossPattern ) {
+ pat = pat_tbl[ bs-Dense1Pattern ];
+ if ( bs <= Dense7Pattern )
+ d = 8;
+ else if ( bs <= CrossPattern )
+ d = 24;
+ else
+ d = 16;
+ }
+
+ XSetLineAttributes( dpy, gc_brush, 0, LineSolid, CapButt, JoinMiter );
+ XSetForeground( dpy, gc_brush, cbrush.color().pixel(scrn) );
+ XSetBackground( dpy, gc_brush, bg_col.pixel(scrn) );
+
+ if ( bs == CustomPattern || pat ) {
+ TQPixmap *pm;
+ if ( pat ) {
+ TQString key;
+ key.sprintf( "$qt-brush$%d", bs );
+ pm = TQPixmapCache::tqfind( key );
+ bool del = FALSE;
+ if ( !pm ) { // not already in pm dict
+ pm = new TQBitmap( d, d, pat, TRUE );
+ TQ_CHECK_PTR( pm );
+ del = !TQPixmapCache::insert( key, pm );
+ }
+ if ( cbrush.data->pixmap )
+ delete cbrush.data->pixmap;
+ cbrush.data->pixmap = new TQPixmap( *pm );
+ if (del) delete pm;
+ }
+ pm = cbrush.data->pixmap;
+ pm->x11SetScreen( scrn );
+ if ( pm->depth() == 1 ) {
+ XSetStipple( dpy, gc_brush, pm->handle() );
+ s = bg_mode == TransparentMode ? FillStippled : FillOpaqueStippled;
+ } else {
+ XSetTile( dpy, gc_brush, pm->handle() );
+ s = FillTiled;
+ }
+ }
+ XSetFillStyle( dpy, gc_brush, s );
+}
+
+
+/*!
+ Begins painting the paint tqdevice \a pd and returns TRUE if
+ successful; otherwise returns FALSE. If \a unclipped is TRUE, the
+ painting will not be clipped at the paint tqdevice's boundaries,
+ (although this is not supported by all platforms).
+
+ The errors that can occur are serious problems, such as these:
+
+ \code
+ p->begin( 0 ); // impossible - paint tqdevice cannot be 0
+
+ TQPixmap pm( 0, 0 );
+ p->begin( pm ); // impossible - pm.isNull();
+
+ p->begin( myWidget );
+ p2->begin( myWidget ); // impossible - only one painter at a time
+ \endcode
+
+ Note that most of the time, you can use one of the constructors
+ instead of begin(), and that end() is automatically done at
+ destruction.
+
+ \warning A paint tqdevice can only be painted by one painter at a
+ time.
+
+ \sa end(), flush()
+*/
+
+bool TQPainter::begin( const TQPaintDevice *pd, bool unclipped )
+{
+ if ( isActive() ) { // already active painting
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::begin: Painter is already active."
+ "\n\tYou must end() the painter before a second begin()" );
+#endif
+ return FALSE;
+ }
+ if ( pd == 0 ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQPainter::begin: Paint tqdevice cannot be null" );
+#endif
+ return FALSE;
+ }
+
+ TQPixmap::x11SetDefaultScreen( pd->x11Screen() );
+
+ const TQWidget *copyFrom = 0;
+ pdev = redirect( (TQPaintDevice*)pd );
+ if ( pdev ) { // redirected paint tqdevice?
+ if ( pd->devType() == TQInternal::Widget )
+ copyFrom = (const TQWidget *)pd; // copy widget settings
+ } else {
+ pdev = (TQPaintDevice*)pd;
+ }
+
+ if ( pdev->isExtDev() && pdev->paintingActive() ) {
+ // somebody else is already painting
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::begin: Another TQPainter is already painting "
+ "this tqdevice;\n\tAn extended paint tqdevice can only be "
+ "painted by one TQPainter at a time." );
+#endif
+ return FALSE;
+ }
+
+ bool reinit = flags != IsStartingUp; // 2nd or 3rd etc. time called
+ flags = IsActive | DirtyFont; // init flags
+ int dt = pdev->devType(); // get the tqdevice type
+
+ if ( (pdev->devFlags & TQInternal::ExternalDevice) != 0 )
+ setf(ExtDev);
+ else if ( dt == TQInternal::Pixmap ) // tqdevice is a pixmap
+ ((TQPixmap*)pdev)->detach(); // will modify it
+
+ dpy = pdev->x11Display(); // get display variable
+ scrn = pdev->x11Screen(); // get screen variable
+ hd = pdev->handle(); // get handle to drawable
+ rendhd = pdev->rendhd;
+
+ if ( testf(ExtDev) ) { // external tqdevice
+ if ( !pdev->cmd( TQPaintDevice::PdcBegin, this, 0 ) ) {
+ // could not begin painting
+ if ( reinit )
+ clearf( IsActive | DirtyFont );
+ else
+ flags = IsStartingUp;
+ pdev = 0;
+ return FALSE;
+ }
+ if ( tabstops ) // update tabstops for tqdevice
+ setTabStops( tabstops );
+ if ( tabarray ) // update tabarray for tqdevice
+ setTabArray( tabarray );
+ }
+
+ if ( pdev->x11Depth() != pdev->x11AppDepth( scrn ) ) { // non-standard depth
+ setf(NoCache);
+ setf(UsePrivateCx);
+ }
+
+ pdev->painters++; // also tell paint tqdevice
+ bro = curPt = TQPoint( 0, 0 );
+ if ( reinit ) {
+ bg_mode = TransparentMode; // default background mode
+ rop = CopyROP; // default ROP
+ wxmat.reset(); // reset world xform matrix
+ xmat.reset();
+ ixmat.reset();
+ txop = txinv = 0;
+ if ( dt != TQInternal::Widget ) {
+ TQFont defaultFont; // default drawing tools
+ TQPen defaultPen;
+ TQBrush defaultBrush;
+ cfont = defaultFont; // set these drawing tools
+ cpen = defaultPen;
+ cbrush = defaultBrush;
+ bg_col = white; // default background color
+ }
+ }
+ wx = wy = vx = vy = 0; // default view origins
+
+ if ( dt == TQInternal::Widget ) { // tqdevice is a widget
+ TQWidget *w = (TQWidget*)pdev;
+ cfont = w->font(); // use widget font
+ cpen = TQPen( w->foregroundColor() ); // use widget fg color
+ if ( reinit ) {
+ TQBrush defaultBrush;
+ cbrush = defaultBrush;
+ }
+ bg_col = w->backgroundColor(); // use widget bg color
+ ww = vw = w->width(); // default view size
+ wh = vh = w->height();
+ if ( unclipped || w->testWFlags( WPaintUnclipped ) ) { // paint direct on tqdevice
+ setf( NoCache );
+ setf(UsePrivateCx);
+ updatePen();
+ updateBrush();
+ XSetSubwindowMode( dpy, gc, IncludeInferiors );
+ XSetSubwindowMode( dpy, gc_brush, IncludeInferiors );
+#ifndef TQT_NO_XFTFREETYPE
+ if (rendhd)
+ XftDrawSetSubwindowMode((XftDraw *) rendhd, IncludeInferiors);
+#endif
+ }
+ } else if ( dt == TQInternal::Pixmap ) { // tqdevice is a pixmap
+ TQPixmap *pm = (TQPixmap*)pdev;
+ if ( pm->isNull() ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQPainter::begin: Cannot paint null pixmap" );
+#endif
+ end();
+ return FALSE;
+ }
+ bool mono = pm->depth() == 1; // monochrome bitmap
+ if ( mono ) {
+ setf( MonoDev );
+ bg_col = color0;
+ cpen.setColor( color1 );
+ }
+ ww = vw = pm->width(); // default view size
+ wh = vh = pm->height();
+ } else if ( testf(ExtDev) ) { // external tqdevice
+ ww = vw = pdev->metric( TQPaintDeviceMetrics::PdmWidth );
+ wh = vh = pdev->metric( TQPaintDeviceMetrics::PdmHeight );
+ }
+ if ( ww == 0 )
+ ww = wh = vw = vh = 1024;
+ if ( copyFrom ) { // copy redirected widget
+ cfont = copyFrom->font();
+ cpen = TQPen( copyFrom->foregroundColor() );
+ bg_col = copyFrom->backgroundColor();
+ }
+ if ( testf(ExtDev) ) { // external tqdevice
+ setBackgroundColor( bg_col ); // default background color
+ setBackgroundMode( TransparentMode ); // default background mode
+ setRasterOp( CopyROP ); // default raster operation
+ }
+ clip_serial = gc_cache_clip_serial++;
+ updateBrush();
+ updatePen();
+ return TRUE;
+}
+
+/*!
+ Ends painting. Any resources used while painting are released.
+
+ Note that while you mostly don't need to call end(), the
+ destructor will do it, there is at least one common case when it
+ is needed, namely double buffering.
+
+ \code
+ TQPainter p( myPixmap, this )
+ // ...
+ p.end(); // stops drawing on myPixmap
+ p.begin( this );
+ p.drawPixmap( 0, 0, myPixmap );
+ \endcode
+
+ Since you can't draw a TQPixmap while it is being painted, it is
+ necessary to close the active painter.
+
+ \sa begin(), isActive()
+*/
+
+bool TQPainter::end() // end painting
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::end: Missing begin() or begin() failed" );
+#endif
+ return FALSE;
+ }
+ killPStack();
+
+ //#### This should not be necessary:
+ if ( pdev->devType() == TQInternal::Widget && // #####
+ ((TQWidget*)pdev)->testWFlags(WPaintUnclipped) ) {
+ if ( gc )
+ XSetSubwindowMode( dpy, gc, ClipByChildren );
+ if ( gc_brush )
+ XSetSubwindowMode( dpy, gc_brush, ClipByChildren );
+ }
+
+ if ( gc_brush ) { // restore brush gc
+ if ( brushRef ) {
+ release_gc( brushRef );
+ brushRef = 0;
+ } else {
+ free_gc( dpy, gc_brush, testf(UsePrivateCx) );
+ }
+ gc_brush = 0;
+
+ }
+ if ( gc ) { // restore pen gc
+ if ( penRef ) {
+ release_gc( penRef );
+ penRef = 0;
+ } else {
+ free_gc( dpy, gc, testf(UsePrivateCx) );
+ }
+ gc = 0;
+ }
+
+ if ( testf(ExtDev) )
+ pdev->cmd( TQPaintDevice::PdcEnd, this, 0 );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (rendhd) {
+ // reset clipping/subwindow mode on our render picture
+ XftDrawSetClip((XftDraw *) rendhd, None);
+ XftDrawSetSubwindowMode((XftDraw *) rendhd, ClipByChildren);
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ if ( pfont ) {
+ delete pfont;
+ pfont = 0;
+ }
+
+ flags = 0;
+ pdev->painters--;
+ pdev = 0;
+ dpy = 0;
+ return TRUE;
+}
+
+/*!
+ Flushes any buffered drawing operations inside the region \a
+ region using clipping mode \a cm.
+
+ The flush may update the whole tqdevice if the platform does not
+ support flushing to a specified region.
+
+ \sa flush() CoordinateMode
+*/
+
+void TQPainter::flush(const TQRegion &, CoordinateMode)
+{
+ flush();
+}
+
+
+/*!
+ \overload
+
+ Flushes any buffered drawing operations.
+*/
+
+void TQPainter::flush()
+{
+ if ( isActive() && dpy )
+ XFlush( dpy );
+}
+
+
+/*!
+ Sets the background color of the painter to \a c.
+
+ The background color is the color that is filled in when drawing
+ opaque text, stippled lines and bitmaps. The background color has
+ no effect in transtqparent background mode (which is the default).
+
+ \sa backgroundColor() setBackgroundMode() BackgroundMode
+*/
+
+void TQPainter::setBackgroundColor( const TQColor &c )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setBackgroundColor: Call begin() first" );
+#endif
+ return;
+ }
+ bg_col = c;
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].color = &bg_col;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetBkColor, this, param ) || !hd )
+ return;
+ }
+ if ( !penRef )
+ updatePen(); // update pen setting
+ if ( !brushRef )
+ updateBrush(); // update brush setting
+}
+
+/*!
+ Sets the background mode of the painter to \a m, which must be
+ either \c TransparentMode (the default) or \c OpaqueMode.
+
+ Transtqparent mode draws stippled lines and text without setting the
+ background pixels. Opaque mode fills these space with the current
+ background color.
+
+ Note that in order to draw a bitmap or pixmap transparently, you
+ must use TQPixmap::setMask().
+
+ \sa backgroundMode(), setBackgroundColor()
+*/
+
+void TQPainter::setBackgroundMode( BGMode m )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setBackgroundMode: Call begin() first" );
+#endif
+ return;
+ }
+ if ( m != TransparentMode && m != OpaqueMode ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPainter::setBackgroundMode: Invalid mode" );
+#endif
+ return;
+ }
+ bg_mode = m;
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].ival = m;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetBkMode, this, param ) || !hd )
+ return;
+ }
+ if ( !penRef )
+ updatePen(); // update pen setting
+ if ( !brushRef )
+ updateBrush(); // update brush setting
+}
+
+static const short ropCodes[] = { // ROP translation table
+ GXcopy, // CopyROP
+ GXor, // OrROP
+ GXxor, // XorROP
+ GXandInverted, // NotAndROP EraseROP
+ GXcopyInverted, // NotCopyROP
+ GXorInverted, // NotOrROP
+ GXequiv, // NotXorROP
+ GXand, // AndROP
+ GXinvert, // NotROP
+ GXclear, // ClearROP
+ GXset, // SetROP
+ GXnoop, // NopROP
+ GXandReverse, // AndNotROP
+ GXorReverse, // OrNotROP
+ GXnand, // NandROP
+ GXnor // NorROP
+};
+
+
+/*!
+ Sets the \link TQt::RasterOp raster operation \endlink to \a r.
+ The default is \c CopyROP.
+
+ \sa rasterOp() TQt::RasterOp
+*/
+
+void TQPainter::setRasterOp( RasterOp r )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setRasterOp: Call begin() first" );
+#endif
+ return;
+ }
+ if ( (uint)r > LastROP ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPainter::setRasterOp: Invalid ROP code" );
+#endif
+ return;
+ }
+ rop = r;
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].ival = r;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetROP, this, param ) || !hd )
+ return;
+ }
+ if ( penRef )
+ updatePen(); // get non-cached pen GC
+ if ( brushRef )
+ updateBrush(); // get non-cached brush GC
+ XSetFunction( dpy, gc, ropCodes[rop] );
+ XSetFunction( dpy, gc_brush, ropCodes[rop] );
+}
+
+// ### matthias - true?
+
+/*!
+ Sets the brush origin to \a (x, y).
+
+ The brush origin specifies the (0, 0) coordinate of the painter's
+ brush. This setting only applies to pattern brushes and pixmap
+ brushes.
+
+ \sa brushOrigin()
+*/
+
+void TQPainter::setBrushOrigin( int x, int y )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setBrushOrigin: Call begin() first" );
+#endif
+ return;
+ }
+ bro = TQPoint(x, y);
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].point = &bro;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetBrushOrigin, this, param ) ||
+ !hd )
+ return;
+ }
+ if ( brushRef )
+ updateBrush(); // get non-cached brush GC
+ XSetTSOrigin( dpy, gc_brush, x, y );
+}
+
+
+/*!
+ Enables clipping if \a enable is TRUE, or disables clipping if \a
+ enable is FALSE.
+
+ \sa hasClipping(), setClipRect(), setClipRegion()
+*/
+
+void TQPainter::setClipping( bool enable )
+{
+ if ( !isActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPainter::setClipping: Will be reset by begin()" );
+#endif
+ return;
+ }
+
+ if ( enable == testf(ClipOn) )
+ return;
+
+ setf( ClipOn, enable );
+ if ( testf(ExtDev) ) {
+ if ( block_ext )
+ return;
+ TQPDevCmdParam param[1];
+ param[0].ival = enable;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetClip, this, param ) || !hd )
+ return;
+ }
+ if ( enable ) {
+ TQRegion rgn = crgn;
+ if ( pdev == paintEventDevice && paintEventClipRegion )
+ rgn = rgn.intersect( *paintEventClipRegion );
+ if ( penRef )
+ updatePen();
+ if ( brushRef )
+ updateBrush();
+ x11SetClipRegion( dpy, gc, gc_brush, rendhd, rgn );
+ } else {
+ if ( pdev == paintEventDevice && paintEventClipRegion ) {
+ x11SetClipRegion( dpy, gc, gc_brush , rendhd, *paintEventClipRegion );
+ } else {
+ x11ClearClipRegion(dpy, gc, gc_brush, rendhd);
+ }
+ }
+}
+
+
+/*!
+ \overload
+
+ Sets the clip region to the rectangle \a r and enables clipping.
+ The clip mode is set to \a m.
+
+ \sa CoordinateMode
+*/
+
+void TQPainter::setClipRect( const TQRect &r, CoordinateMode m )
+{
+ setClipRegion( TQRegion( r ), m );
+}
+
+/*!
+ Sets the clip region to \a rgn and enables clipping. The clip mode
+ is set to \a m.
+
+ Note that the clip region is given in physical tqdevice coordinates
+ and \e not subject to any \link coordsys.html coordinate
+ transformation.\endlink
+
+ \sa setClipRect(), clipRegion(), setClipping() CoordinateMode
+*/
+
+void TQPainter::setClipRegion( const TQRegion &rgn, CoordinateMode m )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( !isActive() )
+ qWarning( "TQPainter::setClipRegion: Will be reset by begin()" );
+#endif
+ if ( m == CoordDevice )
+ crgn = rgn;
+ else
+ crgn = xmat * rgn;
+
+ if ( testf(ExtDev) ) {
+ if ( block_ext )
+ return;
+ TQPDevCmdParam param[2];
+ param[0].rgn = &rgn;
+ param[1].ival = m;
+ if ( !pdev->cmd( TQPaintDevice::PdcSetClipRegion, this, param ) )
+ return; // tqdevice cannot clip
+ }
+ clearf( ClipOn ); // be sure to update clip rgn
+ setClipping( TRUE );
+}
+
+
+/*!
+ \internal
+
+ Internal function for drawing a polygon.
+*/
+
+void TQPainter::drawPolyInternal( const TQPointArray &a, bool close )
+{
+ if ( a.size() < 2 )
+ return;
+
+ int x1, y1, x2, y2; // connect last to first point
+ a.point( a.size()-1, &x1, &y1 );
+ a.point( 0, &x2, &y2 );
+ bool do_close = close && !(x1 == x2 && y1 == y2);
+
+ if ( close && cbrush.style() != NoBrush ) { // draw filled polygon
+ XFillPolygon( dpy, hd, gc_brush, (XPoint*)a.shortPoints(), a.size(),
+ Nonconvex, CoordModeOrigin );
+ if ( cpen.style() == NoPen ) { // draw fake outline
+ XDrawLines( dpy, hd, gc_brush, (XPoint*)a.shortPoints(), a.size(),
+ CoordModeOrigin );
+ if ( do_close )
+ XDrawLine( dpy, hd, gc_brush, x1, y1, x2, y2 );
+ }
+ }
+ if ( cpen.style() != NoPen ) { // draw outline
+ XDrawLines( dpy, hd, gc, (XPoint*)a.shortPoints(), a.size(),
+ CoordModeOrigin);
+ if ( do_close )
+ XDrawLine( dpy, hd, gc, x1, y1, x2, y2 );
+ }
+}
+
+
+/*!
+ Draws/plots a single point at \a (x, y) using the current pen.
+
+ \sa TQPen
+*/
+
+void TQPainter::drawPoint( int x, int y )
+{
+ if ( !isActive() )
+ return;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ TQPoint p( x, y );
+ param[0].point = &p;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPoint, this, param ) ||
+ !hd )
+ return;
+ }
+ map( x, y, &x, &y );
+ }
+ if ( cpen.style() != NoPen )
+ XDrawPoint( dpy, hd, gc, x, y );
+}
+
+
+/*!
+ Draws/plots an array of points, \a a, using the current pen.
+
+ If \a index is non-zero (the default is zero) only points from \a
+ index are drawn. If \a npoints is negative (the default) the rest
+ of the points from \a index are drawn. If \a npoints is zero or
+ greater, \a npoints points are drawn.
+
+ \warning On X11, coordinates that do not fit into 16-bit signed
+ values are truncated. This limitation is expected to go away in
+ TQt 4.
+*/
+
+void TQPainter::drawPoints( const TQPointArray& a, int index, int npoints )
+{
+ if ( npoints < 0 )
+ npoints = a.size() - index;
+ if ( index + npoints > (int)a.size() )
+ npoints = a.size() - index;
+ if ( !isActive() || npoints < 1 || index < 0 )
+ return;
+ TQPointArray pa = a;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ for (int i=0; i<npoints; i++) {
+ TQPoint p( pa[index+i].x(), pa[index+i].y() );
+ param[0].point = &p;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPoint, this, param ))
+ return;
+ }
+ if ( !hd ) return;
+ }
+ if ( txop != TxNone ) {
+ pa = xForm( a, index, npoints );
+ if ( pa.size() != a.size() ) {
+ index = 0;
+ npoints = pa.size();
+ }
+ }
+ }
+ if ( cpen.style() != NoPen )
+ XDrawPoints( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )),
+ npoints, CoordModeOrigin );
+}
+
+
+/*! \obsolete
+ Sets the current pen position to \a (x, y)
+
+ \sa lineTo(), pos()
+*/
+
+void TQPainter::moveTo( int x, int y )
+{
+ if ( !isActive() )
+ return;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ TQPoint p( x, y );
+ param[0].point = &p;
+ if ( !pdev->cmd( TQPaintDevice::PdcMoveTo, this, param ) || !hd )
+ return;
+ }
+ }
+ curPt = TQPoint( x, y );
+}
+
+/*! \obsolete
+ Use drawLine() instead.
+
+ Draws a line from the current pen position to \a (x, y) and sets
+ \a (x, y) to be the new current pen position.
+
+ \sa TQPen moveTo(), drawLine(), pos()
+*/
+
+void TQPainter::lineTo( int x, int y )
+{
+ if ( !isActive() )
+ return;
+ int cx = curPt.x(), cy = curPt.y();
+ curPt = TQPoint( x, y );
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ TQPoint p( x, y );
+ param[0].point = &p;
+ if ( !pdev->cmd( TQPaintDevice::PdcLineTo, this, param ) || !hd )
+ return;
+ }
+ map( x, y, &x, &y );
+ map( cx, cy, &cx, &cy );
+ }
+ if ( cpen.style() != NoPen )
+ XDrawLine( dpy, hd, gc, cx, cy, x, y );
+}
+
+/*!
+ Draws a line from (\a x1, \a y1) to (\a x2, \a y2) and sets the
+ current pen position to (\a x2, \a y2).
+
+ \sa pen()
+*/
+
+void TQPainter::drawLine( int x1, int y1, int x2, int y2 )
+{
+ if ( !isActive() )
+ return;
+ curPt = TQPoint( x2, y2 );
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ TQPoint p1(x1, y1), p2(x2, y2);
+ param[0].point = &p1;
+ param[1].point = &p2;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawLine, this, param ) || !hd )
+ return;
+ }
+ map( x1, y1, &x1, &y1 );
+ map( x2, y2, &x2, &y2 );
+ }
+ if ( cpen.style() != NoPen )
+ XDrawLine( dpy, hd, gc, x1, y1, x2, y2 );
+}
+
+
+
+/*!
+ Draws a rectangle with upper left corner at \a (x, y) and with
+ width \a w and height \a h.
+
+ \sa TQPen, drawRoundRect()
+*/
+
+void TQPainter::drawRect( int x, int y, int w, int h )
+{
+ if ( !isActive() )
+ return;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ TQRect r( x, y, w, h );
+ param[0].rect = &r;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawRect, this, param ) || !hd )
+ return;
+ }
+ if ( txop == TxRotShear ) { // rotate/shear polygon
+ TQPointArray pa = xmat.mapToPolygon( TQRect(x, y, w, h) );
+ pa.resize( 5 );
+ pa.setPoint( 4, pa.point( 0 ) );
+ drawPolyInternal( pa );
+ return;
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 )
+ return;
+ fix_neg_rect( &x, &y, &w, &h );
+ }
+ if ( cbrush.style() != NoBrush ) {
+ if ( cpen.style() == NoPen ) {
+ XFillRectangle( dpy, hd, gc_brush, x, y, w, h );
+ return;
+ }
+ int lw = cpen.width();
+ int lw2 = (lw+1)/2;
+ if ( w > lw && h > lw )
+ XFillRectangle( dpy, hd, gc_brush, x+lw2, y+lw2, w-lw-1, h-lw-1 );
+ }
+ if ( cpen.style() != NoPen )
+ XDrawRectangle( dpy, hd, gc, x, y, w-1, h-1 );
+}
+
+/*!
+ \overload
+
+ Draws a Windows focus rectangle with upper left corner at (\a x,
+ \a y) and with width \a w and height \a h.
+
+ This function draws a stippled XOR rectangle that is used to
+ indicate keyboard focus (when TQApplication::style() is \c
+ WindowStyle).
+
+ \warning This function draws nothing if the coordinate system has
+ been \link rotate() rotated\endlink or \link shear()
+ sheared\endlink.
+
+ \sa drawRect(), TQApplication::style()
+*/
+
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h )
+{
+ drawWinFocusRect( x, y, w, h, TRUE, color0 );
+}
+
+/*!
+ Draws a Windows focus rectangle with upper left corner at (\a x,
+ \a y) and with width \a w and height \a h using a pen color that
+ contrasts with \a bgColor.
+
+ This function draws a stippled rectangle (XOR is not used) that is
+ used to indicate keyboard focus (when the TQApplication::style() is
+ \c WindowStyle).
+
+ The pen color used to draw the rectangle is either white or black
+ depending on the color of \a bgColor (see TQColor::gray()).
+
+ \warning This function draws nothing if the coordinate system has
+ been \link rotate() rotated\endlink or \link shear()
+ sheared\endlink.
+
+ \sa drawRect(), TQApplication::style()
+*/
+
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h,
+ const TQColor &bgColor )
+{
+ drawWinFocusRect( x, y, w, h, FALSE, bgColor );
+}
+
+
+/*!
+ \internal
+*/
+
+void TQPainter::drawWinFocusRect( int x, int y, int w, int h,
+ bool xorPaint, const TQColor &bgColor )
+{
+ if ( !isActive() || txop == TxRotShear )
+ return;
+ static char winfocus_line[] = { 1, 1 };
+
+ TQPen old_pen = cpen;
+ RasterOp old_rop = (RasterOp)rop;
+
+ if ( xorPaint ) {
+ if ( TQColor::numBitPlanes() <= 8 )
+ setPen( color1 );
+ else
+ setPen( white );
+ setRasterOp( XorROP );
+ } else {
+ if ( tqGray( bgColor.rgb() ) < 128 )
+ setPen( white );
+ else
+ setPen( black );
+ }
+
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ TQRect r( x, y, w, h );
+ param[0].rect = &r;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawRect, this, param ) || !hd) {
+ setRasterOp( old_rop );
+ setPen( old_pen );
+ return;
+ }
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 )
+ return;
+ fix_neg_rect( &x, &y, &w, &h );
+ }
+ XSetDashes( dpy, gc, 0, winfocus_line, 2 );
+ XSetLineAttributes( dpy, gc, 1, LineOnOffDash, CapButt, JoinMiter );
+
+ XDrawRectangle( dpy, hd, gc, x, y, w-1, h-1 );
+ XSetLineAttributes( dpy, gc, 0, LineSolid, CapButt, JoinMiter );
+ setRasterOp( old_rop );
+ setPen( old_pen );
+}
+
+
+/*!
+ Draws a rectangle with rounded corners at \a (x, y), with width \a
+ w and height \a h.
+
+ The \a xRnd and \a yRnd arguments specify how rounded the corners
+ should be. 0 is angled corners, 99 is maximum roundedness.
+
+ The width and height include all of the drawn lines.
+
+ \sa drawRect(), TQPen
+*/
+
+void TQPainter::drawRoundRect( int x, int y, int w, int h, int xRnd, int yRnd )
+{
+ if ( !isActive() )
+ return;
+ if ( xRnd <= 0 || yRnd <= 0 ) {
+ drawRect( x, y, w, h ); // draw normal rectangle
+ return;
+ }
+ if ( xRnd >= 100 ) // fix ranges
+ xRnd = 99;
+ if ( yRnd >= 100 )
+ yRnd = 99;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[3];
+ TQRect r( x, y, w, h );
+ param[0].rect = &r;
+ param[1].ival = xRnd;
+ param[2].ival = yRnd;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawRoundRect, this, param ) ||
+ !hd )
+ return;
+ }
+ if ( txop == TxRotShear ) { // rotate/shear polygon
+ if ( w <= 0 || h <= 0 )
+ fix_neg_rect( &x, &y, &w, &h );
+ w--;
+ h--;
+ int rxx = w*xRnd/200;
+ int ryy = h*yRnd/200;
+ // were there overflows?
+ if ( rxx < 0 )
+ rxx = w/200*xRnd;
+ if ( ryy < 0 )
+ ryy = h/200*yRnd;
+ int rxx2 = 2*rxx;
+ int ryy2 = 2*ryy;
+ TQPointArray a[4];
+ a[0].makeArc( x, y, rxx2, ryy2, 1*16*90, 16*90, xmat );
+ a[1].makeArc( x, y+h-ryy2, rxx2, ryy2, 2*16*90, 16*90, xmat );
+ a[2].makeArc( x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*16*90, 16*90, xmat );
+ a[3].makeArc( x+w-rxx2, y, rxx2, ryy2, 0*16*90, 16*90, xmat );
+ // ### is there a better way to join TQPointArrays?
+ TQPointArray aa;
+ aa.resize( a[0].size() + a[1].size() + a[2].size() + a[3].size() );
+ uint j = 0;
+ for ( int k=0; k<4; k++ ) {
+ for ( uint i=0; i<a[k].size(); i++ ) {
+ aa.setPoint( j, a[k].point(i) );
+ j++;
+ }
+ }
+ drawPolyInternal( aa );
+ return;
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+ w--;
+ h--;
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 )
+ return;
+ fix_neg_rect( &x, &y, &w, &h );
+ }
+ int rx = (w*xRnd)/200;
+ int ry = (h*yRnd)/200;
+ int rx2 = 2*rx;
+ int ry2 = 2*ry;
+ if ( cbrush.style() != NoBrush ) { // draw filled round rect
+ int dp, ds;
+ if ( cpen.style() == NoPen ) {
+ dp = 0;
+ ds = 1;
+ }
+ else {
+ dp = 1;
+ ds = 0;
+ }
+#define SET_ARC(px, py, w, h, a1, a2) \
+ a->x=px; a->y=py; a->width=w; a->height=h; a->angle1=a1; a->angle2=a2; a++
+ XArc arcs[4];
+ XArc *a = arcs;
+ SET_ARC( x+w-rx2, y, rx2, ry2, 0, 90*64 );
+ SET_ARC( x, y, rx2, ry2, 90*64, 90*64 );
+ SET_ARC( x, y+h-ry2, rx2, ry2, 180*64, 90*64 );
+ SET_ARC( x+w-rx2, y+h-ry2, rx2, ry2, 270*64, 90*64 );
+ XFillArcs( dpy, hd, gc_brush, arcs, 4 );
+#undef SET_ARC
+#define SET_RCT(px, py, w, h) \
+ r->x=px; r->y=py; r->width=w; r->height=h; r++
+ XRectangle rects[3];
+ XRectangle *r = rects;
+ SET_RCT( x+rx, y+dp, w-rx2, ry );
+ SET_RCT( x+dp, y+ry, w+ds, h-ry2 );
+ SET_RCT( x+rx, y+h-ry, w-rx2, ry+ds );
+ XFillRectangles( dpy, hd, gc_brush, rects, 3 );
+#undef SET_RCT
+ }
+ if ( cpen.style() != NoPen ) { // draw outline
+#define SET_ARC(px, py, w, h, a1, a2) \
+ a->x=px; a->y=py; a->width=w; a->height=h; a->angle1=a1; a->angle2=a2; a++
+ XArc arcs[4];
+ XArc *a = arcs;
+ SET_ARC( x+w-rx2, y, rx2, ry2, 0, 90*64 );
+ SET_ARC( x, y, rx2, ry2, 90*64, 90*64 );
+ SET_ARC( x, y+h-ry2, rx2, ry2, 180*64, 90*64 );
+ SET_ARC( x+w-rx2, y+h-ry2, rx2, ry2, 270*64, 90*64 );
+ XDrawArcs( dpy, hd, gc, arcs, 4 );
+#undef SET_ARC
+#define SET_SEG(xp1, yp1, xp2, yp2) \
+ s->x1=xp1; s->y1=yp1; s->x2=xp2; s->y2=yp2; s++
+ XSegment segs[4];
+ XSegment *s = segs;
+ SET_SEG( x+rx, y, x+w-rx, y );
+ SET_SEG( x+rx, y+h, x+w-rx, y+h );
+ SET_SEG( x, y+ry, x, y+h-ry );
+ SET_SEG( x+w, y+ry, x+w, y+h-ry );
+ XDrawSegments( dpy, hd, gc, segs, 4 );
+#undef SET_SET
+ }
+}
+
+/*!
+ Draws an ellipse with center at \a (x + w/2, y + h/2) and size \a
+ (w, h).
+*/
+
+void TQPainter::drawEllipse( int x, int y, int w, int h )
+{
+ if ( !isActive() )
+ return;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ TQRect r( x, y, w, h );
+ param[0].rect = &r;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawEllipse, this, param ) ||
+ !hd )
+ return;
+ }
+ if ( txop == TxRotShear ) { // rotate/shear polygon
+ TQPointArray a;
+ a.makeArc( x, y, w, h, 0, 360*16, xmat );
+ drawPolyInternal( a );
+ return;
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 )
+ return;
+ fix_neg_rect( &x, &y, &w, &h );
+ }
+ if ( w == 1 && h == 1 ) {
+ XDrawPoint( dpy, hd, (cpen.style() == NoPen)?gc_brush:gc, x, y );
+ return;
+ }
+ w--;
+ h--;
+ if ( cbrush.style() != NoBrush ) { // draw filled ellipse
+ XFillArc( dpy, hd, gc_brush, x, y, w, h, 0, 360*64 );
+ if ( cpen.style() == NoPen ) {
+ XDrawArc( dpy, hd, gc_brush, x, y, w, h, 0, 360*64 );
+ return;
+ }
+ }
+ if ( cpen.style() != NoPen ) // draw outline
+ XDrawArc( dpy, hd, gc, x, y, w, h, 0, 360*64 );
+}
+
+
+/*!
+ Draws an arc defined by the rectangle \a (x, y, w, h), the start
+ angle \a a and the arc length \a alen.
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ Example:
+ \code
+ TQPainter p( myWidget );
+ p.drawArc( 10,10, 70,100, 100*16, 160*16 ); // draws a "(" arc
+ \endcode
+
+ \sa drawPie(), drawChord()
+*/
+
+void TQPainter::drawArc( int x, int y, int w, int h, int a, int alen )
+{
+ if ( !isActive() )
+ return;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[3];
+ TQRect r( x, y, w, h );
+ param[0].rect = &r;
+ param[1].ival = a;
+ param[2].ival = alen;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawArc, this, param ) ||
+ !hd )
+ return;
+ }
+ if ( txop == TxRotShear ) { // rotate/shear
+ TQPointArray pa;
+ pa.makeArc( x, y, w, h, a, alen, xmat ); // arc polyline
+ drawPolyInternal( pa, FALSE );
+ return;
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+ w--;
+ h--;
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 )
+ return;
+ fix_neg_rect( &x, &y, &w, &h );
+ }
+ if ( cpen.style() != NoPen )
+ XDrawArc( dpy, hd, gc, x, y, w, h, a*4, alen*4 );
+}
+
+
+/*!
+ Draws a pie defined by the rectangle \a (x, y, w, h), the start
+ angle \a a and the arc length \a alen.
+
+ The pie is filled with the current brush().
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ \sa drawArc(), drawChord()
+*/
+
+void TQPainter::drawPie( int x, int y, int w, int h, int a, int alen )
+{
+ // Make sure "a" is 0..360*16, as otherwise a*4 may overflow 16 bits.
+ if ( a > (360*16) ) {
+ a = a % (360*16);
+ } else if ( a < 0 ) {
+ a = a % (360*16);
+ if ( a < 0 ) a += (360*16);
+ }
+
+ if ( !isActive() )
+ return;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[3];
+ TQRect r( x, y, w, h );
+ param[0].rect = &r;
+ param[1].ival = a;
+ param[2].ival = alen;
+ if ( !pdev->cmd( TQPaintDevice::PdcDrawPie, this, param ) || !hd )
+ return;
+ }
+ if ( txop == TxRotShear ) { // rotate/shear
+ TQPointArray pa;
+ pa.makeArc( x, y, w, h, a, alen, xmat ); // arc polyline
+ int n = pa.size();
+ int cx, cy;
+ xmat.map(x+w/2, y+h/2, &cx, &cy);
+ pa.resize( n+2 );
+ pa.setPoint( n, cx, cy ); // add legs
+ pa.setPoint( n+1, pa.at(0) );
+ drawPolyInternal( pa );
+ return;
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+ XSetArcMode( dpy, gc_brush, ArcPieSlice );
+ w--;
+ h--;
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 )
+ return;
+ fix_neg_rect( &x, &y, &w, &h );
+ }
+
+ GC g = gc;
+ bool nopen = cpen.style() == NoPen;
+
+ if ( cbrush.style() != NoBrush ) { // draw filled pie
+ XFillArc( dpy, hd, gc_brush, x, y, w, h, a*4, alen*4 );
+ if ( nopen ) {
+ g = gc_brush;
+ nopen = FALSE;
+ }
+ }
+ if ( !nopen ) { // draw pie outline
+ double w2 = 0.5*w; // with, height in ellipsis
+ double h2 = 0.5*h;
+ double xc = (double)x+w2;
+ double yc = (double)y+h2;
+ double ra1 = TQ_PI/2880.0*a; // convert a, alen to radians
+ double ra2 = ra1 + TQ_PI/2880.0*alen;
+ int xic = tqRound(xc);
+ int yic = tqRound(yc);
+ XDrawLine( dpy, hd, g, xic, yic,
+ tqRound(xc + qcos(ra1)*w2), tqRound(yc - qsin(ra1)*h2));
+ XDrawLine( dpy, hd, g, xic, yic,
+ tqRound(xc + qcos(ra2)*w2), tqRound(yc - qsin(ra2)*h2));
+ XDrawArc( dpy, hd, g, x, y, w, h, a*4, alen*4 );
+ }
+}
+
+
+/*!
+ Draws a chord defined by the rectangle \a (x, y, w, h), the start
+ angle \a a and the arc length \a alen.
+
+ The chord is filled with the current brush().
+
+ The angles \a a and \a alen are 1/16th of a degree, i.e. a full
+ circle equals 5760 (16*360). Positive values of \a a and \a alen
+ mean counter-clockwise while negative values mean the clockwise
+ direction. Zero degrees is at the 3 o'clock position.
+
+ \sa drawArc(), drawPie()
+*/
+
+void TQPainter::drawChord( int x, int y, int w, int h, int a, int alen )
+{
+ if ( !isActive() )
+ return;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[3];
+ TQRect r( x, y, w, h );
+ param[0].rect = &r;
+ param[1].ival = a;
+ param[2].ival = alen;
+ if ( !pdev->cmd(TQPaintDevice::PdcDrawChord, this, param) || !hd )
+ return;
+ }
+ if ( txop == TxRotShear ) { // rotate/shear
+ TQPointArray pa;
+ pa.makeArc( x, y, w-1, h-1, a, alen, xmat ); // arc polygon
+ int n = pa.size();
+ pa.resize( n+1 );
+ pa.setPoint( n, pa.at(0) ); // connect endpoints
+ drawPolyInternal( pa );
+ return;
+ }
+ map( x, y, w, h, &x, &y, &w, &h );
+ }
+ XSetArcMode( dpy, gc_brush, ArcChord );
+ w--;
+ h--;
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 )
+ return;
+ fix_neg_rect( &x, &y, &w, &h );
+ }
+
+ GC g = gc;
+ bool nopen = cpen.style() == NoPen;
+
+ if ( cbrush.style() != NoBrush ) { // draw filled chord
+ XFillArc( dpy, hd, gc_brush, x, y, w, h, a*4, alen*4 );
+ if ( nopen ) {
+ g = gc_brush;
+ nopen = FALSE;
+ }
+ }
+ if ( !nopen ) { // draw chord outline
+ double w2 = 0.5*w; // with, height in ellipsis
+ double h2 = 0.5*h;
+ double xc = (double)x+w2;
+ double yc = (double)y+h2;
+ double ra1 = TQ_PI/2880.0*a; // convert a, alen to radians
+ double ra2 = ra1 + TQ_PI/2880.0*alen;
+ XDrawLine( dpy, hd, g,
+ tqRound(xc + qcos(ra1)*w2), tqRound(yc - qsin(ra1)*h2),
+ tqRound(xc + qcos(ra2)*w2), tqRound(yc - qsin(ra2)*h2));
+ XDrawArc( dpy, hd, g, x, y, w, h, a*4, alen*4 );
+ }
+ XSetArcMode( dpy, gc_brush, ArcPieSlice );
+}
+
+
+/*!
+ Draws \a nlines separate lines from points defined in \a a,
+ starting at \a a[index] (\a index defaults to 0). If \a nlines is
+ -1 (the default) all points until the end of the array are used
+ (i.e. (a.size()-index)/2 lines are drawn).
+
+ Draws the 1st line from \a a[index] to \a a[index+1]. Draws the
+ 2nd line from \a a[index+2] to \a a[index+3] etc.
+
+ \warning On X11, coordinates that do not fit into 16-bit signed
+ values are truncated. This limitation is expected to go away in
+ TQt 4.
+
+ \sa drawPolyline(), drawPolygon(), TQPen
+*/
+
+void TQPainter::drawLineSegments( const TQPointArray &a, int index, int nlines )
+{
+ if ( nlines < 0 )
+ nlines = a.size()/2 - index/2;
+ if ( index + nlines*2 > (int)a.size() )
+ nlines = (a.size() - index)/2;
+ if ( !isActive() || nlines < 1 || index < 0 )
+ return;
+ TQPointArray pa = a;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ if ( 2*nlines != (int)pa.size() ) {
+ pa = TQPointArray( nlines*2 );
+ for ( int i=0; i<nlines*2; i++ )
+ pa.setPoint( i, a.point(index+i) );
+ index = 0;
+ }
+ TQPDevCmdParam param[1];
+ param[0].ptarr = (TQPointArray*)&pa;
+ if ( !pdev->cmd(TQPaintDevice::PdcDrawLineSegments, this, param) ||
+ !hd )
+ return;
+ }
+ if ( txop != TxNone ) {
+ pa = xForm( a, index, nlines*2 );
+ if ( pa.size() != a.size() ) {
+ index = 0;
+ nlines = pa.size()/2;
+ }
+ }
+ }
+ if ( cpen.style() != NoPen )
+ XDrawSegments( dpy, hd, gc,
+ (XSegment*)(pa.shortPoints( index, nlines*2 )), nlines );
+}
+
+
+/*!
+ Draws the polyline defined by the \a npoints points in \a a
+ starting at \a a[index]. (\a index defaults to 0.)
+
+ If \a npoints is -1 (the default) all points until the end of the
+ array are used (i.e. a.size()-index-1 line segments are drawn).
+
+ \warning On X11, coordinates that do not fit into 16-bit signed
+ values are truncated. This limitation is expected to go away in
+ TQt 4.
+
+ \sa drawLineSegments(), drawPolygon(), TQPen
+*/
+
+void TQPainter::drawPolyline( const TQPointArray &a, int index, int npoints )
+{
+ if ( npoints < 0 )
+ npoints = a.size() - index;
+ if ( index + npoints > (int)a.size() )
+ npoints = a.size() - index;
+ if ( !isActive() || npoints < 2 || index < 0 )
+ return;
+ TQPointArray pa = a;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ if ( npoints != (int)pa.size() ) {
+ pa = TQPointArray( npoints );
+ for ( int i=0; i<npoints; i++ )
+ pa.setPoint( i, a.point(index+i) );
+ index = 0;
+ }
+ TQPDevCmdParam param[1];
+ param[0].ptarr = (TQPointArray*)&pa;
+ if ( !pdev->cmd(TQPaintDevice::PdcDrawPolyline, this, param) || !hd )
+ return;
+ }
+ if ( txop != TxNone ) {
+ pa = xForm( pa, index, npoints );
+ if ( pa.size() != a.size() ) {
+ index = 0;
+ npoints = pa.size();
+ }
+ }
+ }
+ if ( cpen.style() != NoPen ) {
+ while(npoints>65535) {
+ XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, 65535 )),
+ 65535, CoordModeOrigin );
+ npoints-=65535;
+ index+=65535;
+ }
+ XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )),
+ npoints, CoordModeOrigin );
+ }
+}
+
+static int global_polygon_tqshape = Complex;
+
+/*!
+ Draws the polygon defined by the \a npoints points in \a a
+ starting at \a a[index]. (\a index defaults to 0.)
+
+ If \a npoints is -1 (the default) all points until the end of the
+ array are used (i.e. a.size()-index line segments define the
+ polygon).
+
+ The first point is always connected to the last point.
+
+ The polygon is filled with the current brush(). If \a winding is
+ TRUE, the polygon is filled using the winding fill algorithm. If
+ \a winding is FALSE, the polygon is filled using the even-odd
+ (alternative) fill algorithm.
+
+ \warning On X11, coordinates that do not fit into 16-bit signed
+ values are truncated. This limitation is expected to go away in
+ TQt 4.
+
+ \sa drawLineSegments(), drawPolyline(), TQPen
+*/
+
+void TQPainter::drawPolygon( const TQPointArray &a, bool winding,
+ int index, int npoints )
+{
+ if ( npoints < 0 )
+ npoints = a.size() - index;
+ if ( index + npoints > (int)a.size() )
+ npoints = a.size() - index;
+ if ( !isActive() || npoints < 2 || index < 0 )
+ return;
+ TQPointArray pa = a;
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ if ( npoints != (int)a.size() ) {
+ pa = TQPointArray( npoints );
+ for ( int i=0; i<npoints; i++ )
+ pa.setPoint( i, a.point(index+i) );
+ index = 0;
+ }
+ TQPDevCmdParam param[2];
+ param[0].ptarr = (TQPointArray*)&pa;
+ param[1].ival = winding;
+ if ( !pdev->cmd(TQPaintDevice::PdcDrawPolygon, this, param) || !hd )
+ return;
+ }
+ if ( txop != TxNone ) {
+ pa = xForm( a, index, npoints );
+ if ( pa.size() != a.size() ) {
+ index = 0;
+ npoints = pa.size();
+ }
+ }
+ }
+ if ( winding ) // set to winding fill rule
+ XSetFillRule( dpy, gc_brush, WindingRule );
+
+ if ( pa[index] != pa[index+npoints-1] ){ // close open pointarray
+ pa.detach();
+ pa.resize( index+npoints+1 );
+ pa.setPoint( index+npoints, pa[index] );
+ npoints++;
+ }
+
+ if ( cbrush.style() != NoBrush ) { // draw filled polygon
+ XFillPolygon( dpy, hd, gc_brush,
+ (XPoint*)(pa.shortPoints( index, npoints )),
+ npoints, global_polygon_tqshape, CoordModeOrigin );
+ }
+ if ( cpen.style() != NoPen ) { // draw outline
+ XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )),
+ npoints, CoordModeOrigin );
+ }
+ if ( winding ) // set to normal fill rule
+ XSetFillRule( dpy, gc_brush, EvenOddRule );
+}
+
+/*!
+ Draws the convex polygon defined by the \a npoints points in \a pa
+ starting at \a pa[index] (\a index defaults to 0).
+
+ If the supplied polygon is not convex, the results are undefined.
+
+ On some platforms (e.g. X Window), this is faster than
+ drawPolygon().
+
+ \warning On X11, coordinates that do not fit into 16-bit signed
+ values are truncated. This limitation is expected to go away in
+ TQt 4.
+*/
+void TQPainter::drawConvexPolygon( const TQPointArray &pa,
+ int index, int npoints )
+{
+ global_polygon_tqshape = Convex;
+ drawPolygon(pa, FALSE, index, npoints);
+ global_polygon_tqshape = Complex;
+}
+
+
+
+/*!
+ Draws a cubic Bezier curve defined by the control points in \a a,
+ starting at \a a[index] (\a index defaults to 0).
+
+ Control points after \a a[index + 3] are ignored. Nothing happens
+ if there aren't enough control points.
+
+ \warning On X11, coordinates that do not fit into 16-bit signed
+ values are truncated. This limitation is expected to go away in
+ TQt 4.
+*/
+
+void TQPainter::drawCubicBezier( const TQPointArray &a, int index )
+{
+ if ( !isActive() )
+ return;
+ if ( a.size() - index < 4 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPainter::drawCubicBezier: Cubic Bezier needs 4 control "
+ "points" );
+#endif
+ return;
+ }
+ TQPointArray pa( a );
+ if ( index != 0 || a.size() > 4 ) {
+ pa = TQPointArray( 4 );
+ for ( int i=0; i<4; i++ )
+ pa.setPoint( i, a.point(index+i) );
+ }
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[1];
+ param[0].ptarr = (TQPointArray*)&pa;
+ if ( !pdev->cmd(TQPaintDevice::PdcDrawCubicBezier, this, param) ||
+ !hd )
+ return;
+ }
+ if ( txop != TxNone )
+ pa = xForm( pa );
+ }
+ if ( cpen.style() != NoPen ) {
+ pa = pa.cubicBezier();
+ XDrawLines( dpy, hd, gc, (XPoint*)pa.shortPoints(), pa.size(),
+ CoordModeOrigin );
+ }
+}
+
+
+/*!
+ Draws a pixmap at \a (x, y) by copying a part of \a pixmap into
+ the paint tqdevice.
+
+ \a (x, y) specifies the top-left point in the paint tqdevice that is
+ to be drawn onto. \a (sx, sy) specifies the top-left point in \a
+ pixmap that is to be drawn. The default is (0, 0).
+
+ \a (sw, sh) specifies the size of the pixmap that is to be drawn.
+ The default, (-1, -1), means all the way to the bottom right of
+ the pixmap.
+
+ Currently the tqmask of the pixmap or it's alpha channel are ignored
+ when painting on a TQPrinter.
+
+ \sa bitBlt(), TQPixmap::setMask()
+*/
+
+void TQPainter::drawPixmap( int x, int y, const TQPixmap &pixmap,
+ int sx, int sy, int sw, int sh )
+{
+ if ( !isActive() || pixmap.isNull() )
+ return;
+
+ // right/bottom
+ if ( sw < 0 )
+ sw = pixmap.width() - sx;
+ if ( sh < 0 )
+ sh = pixmap.height() - sy;
+
+ // Sanity-check clipping
+ if ( sx < 0 ) {
+ x -= sx;
+ sw += sx;
+ sx = 0;
+ }
+ if ( sw + sx > pixmap.width() )
+ sw = pixmap.width() - sx;
+ if ( sy < 0 ) {
+ y -= sy;
+ sh += sy;
+ sy = 0;
+ }
+ if ( sh + sy > pixmap.height() )
+ sh = pixmap.height() - sy;
+
+ if ( sw <= 0 || sh <= 0 )
+ return;
+
+ if ( pdev->x11Screen() != pixmap.x11Screen() ) {
+ TQPixmap* p = (TQPixmap*) &pixmap;
+ p->x11SetScreen( pdev->x11Screen() );
+ }
+
+ TQPixmap::x11SetDefaultScreen( pixmap.x11Screen() );
+
+ if ( testf(ExtDev|VxF|WxF) ) {
+ if ( testf(ExtDev) || txop == TxScale || txop == TxRotShear ) {
+ if ( sx != 0 || sy != 0 ||
+ sw != pixmap.width() || sh != pixmap.height() ) {
+ TQPixmap tmp( sw, sh, pixmap.depth() );
+ bitBlt( &tmp, 0, 0, &pixmap, sx, sy, sw, sh, CopyROP, TRUE );
+ if ( pixmap.tqmask() ) {
+ TQBitmap tqmask( sw, sh );
+ bitBlt( &tqmask, 0, 0, pixmap.tqmask(), sx, sy, sw, sh,
+ CopyROP, TRUE );
+ tmp.setMask( tqmask );
+ }
+ drawPixmap( x, y, tmp );
+ return;
+ }
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ TQRect r(x, y, pixmap.width(), pixmap.height());
+ param[0].rect = &r;
+ param[1].pixmap = &pixmap;
+ if ( !pdev->cmd(TQPaintDevice::PdcDrawPixmap, this, param) || !hd )
+ return;
+ }
+ if ( txop == TxScale || txop == TxRotShear ) {
+ TQWMatrix mat( m11(), m12(),
+ m21(), m22(),
+ dx(), dy() );
+ mat = TQPixmap::trueMatrix( mat, sw, sh );
+ TQPixmap pm = pixmap.xForm( mat );
+ if ( !pm.tqmask() && txop == TxRotShear ) {
+ TQBitmap bm_clip( sw, sh, 1 );
+ bm_clip.fill( color1 );
+ pm.setMask( bm_clip.xForm(mat) );
+ }
+ map( x, y, &x, &y ); // compute position of pixmap
+ int dx, dy;
+ mat.map( 0, 0, &dx, &dy );
+ uint save_flags = flags;
+ flags = IsActive | (save_flags & ClipOn);
+ drawPixmap( x-dx, y-dy, pm );
+ flags = save_flags;
+ return;
+ }
+ }
+ map( x, y, &x, &y );
+ }
+
+ TQBitmap *tqmask = (TQBitmap *)pixmap.tqmask();
+ bool mono = pixmap.depth() == 1;
+
+ if ( tqmask && !hasClipping() && pdev != paintEventDevice ) {
+ if ( mono ) { // needs GCs pen color
+ bool selfmask = pixmap.data->selfmask;
+ if ( selfmask ) {
+ XSetFillStyle( dpy, gc, FillStippled );
+ XSetStipple( dpy, gc, pixmap.handle() );
+ } else {
+ XSetFillStyle( dpy, gc, FillOpaqueStippled );
+ XSetStipple( dpy, gc, pixmap.handle() );
+ XSetClipMask( dpy, gc, tqmask->handle() );
+ XSetClipOrigin( dpy, gc, x-sx, y-sy );
+ }
+ XSetTSOrigin( dpy, gc, x-sx, y-sy );
+ XFillRectangle( dpy, hd, gc, x, y, sw, sh );
+ XSetTSOrigin( dpy, gc, 0, 0 );
+ XSetFillStyle( dpy, gc, FillSolid );
+ if ( !selfmask ) {
+ if ( pdev == paintEventDevice && paintEventClipRegion ) {
+ x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion );
+ } else {
+ x11ClearClipRegion(dpy, gc, 0, rendhd);
+ }
+ }
+ } else {
+ bitBlt( pdev, x, y, &pixmap, sx, sy, sw, sh, (RasterOp)rop );
+ }
+ return;
+ }
+
+ TQRegion rgn = crgn;
+
+ if ( tqmask ) { // pixmap has clip tqmask
+ // Implies that clipping is on, either explicit or implicit
+ // Create a new tqmask that combines the tqmask with the clip region
+
+ if ( pdev == paintEventDevice && paintEventClipRegion ) {
+ if ( hasClipping() )
+ rgn = rgn.intersect( *paintEventClipRegion );
+ else
+ rgn = *paintEventClipRegion;
+ }
+
+ TQBitmap *comb = new TQBitmap( sw, sh );
+ comb->detach();
+ GC cgc = qt_xget_temp_gc( pixmap.x11Screen(), TRUE ); // get temporary mono GC
+ XSetForeground( dpy, cgc, 0 );
+ XFillRectangle( dpy, comb->handle(), cgc, 0, 0, sw, sh );
+ XSetBackground( dpy, cgc, 0 );
+ XSetForeground( dpy, cgc, 1 );
+ int num;
+ XRectangle *rects = (XRectangle *)qt_getClipRects( rgn, num );
+ XSetClipRectangles( dpy, cgc, -x, -y, rects, num, YXBanded );
+ XSetFillStyle( dpy, cgc, FillOpaqueStippled );
+ XSetStipple( dpy, cgc, tqmask->handle() );
+ XSetTSOrigin( dpy, cgc, -sx, -sy );
+ XFillRectangle( dpy, comb->handle(), cgc, 0, 0, sw, sh );
+ XSetTSOrigin( dpy, cgc, 0, 0 ); // restore cgc
+ XSetFillStyle( dpy, cgc, FillSolid );
+ XSetClipMask( dpy, cgc, None );
+ tqmask = comb; // it's deleted below
+
+ XSetClipMask( dpy, gc, tqmask->handle() );
+ XSetClipOrigin( dpy, gc, x, y );
+ }
+
+ if ( mono ) {
+ XSetBackground( dpy, gc, bg_col.pixel(scrn) );
+ XSetFillStyle( dpy, gc, FillOpaqueStippled );
+ XSetStipple( dpy, gc, pixmap.handle() );
+ XSetTSOrigin( dpy, gc, x-sx, y-sy );
+ XFillRectangle( dpy, hd, gc, x, y, sw, sh );
+ XSetTSOrigin( dpy, gc, 0, 0 );
+ XSetFillStyle( dpy, gc, FillSolid );
+ } else {
+#if !defined(TQT_NO_XFTFREETYPE) && !defined(TQT_NO_XRENDER)
+ Picture pict = rendhd ? XftDrawPicture((XftDraw *) rendhd) : None;
+ TQPixmap *alpha = pixmap.data->alphapm;
+
+ if ( pict && pixmap.x11RenderHandle() &&
+ alpha && alpha->x11RenderHandle()) {
+ XRenderComposite(dpy, PictOpOver, pixmap.x11RenderHandle(),
+ alpha->x11RenderHandle(), pict,
+ sx, sy, sx, sy, x, y, sw, sh);
+ } else
+#endif // !TQT_NO_XFTFREETYPE && !TQT_NO_XRENDER
+ {
+ XCopyArea( dpy, pixmap.handle(), hd, gc, sx, sy, sw, sh, x, y );
+ }
+ }
+
+ if ( tqmask ) { // restore clipping
+ XSetClipOrigin( dpy, gc, 0, 0 );
+ XSetRegion( dpy, gc, rgn.handle() );
+ delete tqmask; // delete comb, created above
+ }
+}
+
+
+/* Internal, used by drawTiledPixmap */
+
+static void drawTile( TQPainter *p, int x, int y, int w, int h,
+ const TQPixmap &pixmap, int xOffset, int yOffset )
+{
+ int yPos, xPos, drawH, drawW, yOff, xOff;
+ yPos = y;
+ yOff = yOffset;
+ while( yPos < y + h ) {
+ drawH = pixmap.height() - yOff; // Cropping first row
+ if ( yPos + drawH > y + h ) // Cropping last row
+ drawH = y + h - yPos;
+ xPos = x;
+ xOff = xOffset;
+ while( xPos < x + w ) {
+ drawW = pixmap.width() - xOff; // Cropping first column
+ if ( xPos + drawW > x + w ) // Cropping last column
+ drawW = x + w - xPos;
+ p->drawPixmap( xPos, yPos, pixmap, xOff, yOff, drawW, drawH );
+ xPos += drawW;
+ xOff = 0;
+ }
+ yPos += drawH;
+ yOff = 0;
+ }
+}
+
+#if 0 // see comment in drawTiledPixmap
+/* Internal, used by drawTiledPixmap */
+
+static void fillTile( TQPixmap *tile, const TQPixmap &pixmap )
+{
+ bitBlt( tile, 0, 0, &pixmap, 0, 0, -1, -1, TQt::CopyROP, TRUE );
+ int x = pixmap.width();
+ while ( x < tile->width() ) {
+ bitBlt( tile, x,0, tile, 0,0, x,pixmap.height(), TQt::CopyROP, TRUE );
+ x *= 2;
+ }
+ int y = pixmap.height();
+ while ( y < tile->height() ) {
+ bitBlt( tile, 0,y, tile, 0,0, tile->width(),y, TQt::CopyROP, TRUE );
+ y *= 2;
+ }
+}
+#endif
+
+/*!
+ Draws a tiled \a pixmap in the specified rectangle.
+
+ \a (x, y) specifies the top-left point in the paint tqdevice that is
+ to be drawn onto; with the width and height given by \a w and \a
+ h. \a (sx, sy) specifies the top-left point in \a pixmap that is
+ to be drawn. The default is (0, 0).
+
+ Calling drawTiledPixmap() is similar to calling drawPixmap()
+ several times to fill (tile) an area with a pixmap, but is
+ potentially much more efficient depending on the underlying window
+ system.
+
+ \sa drawPixmap()
+*/
+
+void TQPainter::drawTiledPixmap( int x, int y, int w, int h,
+ const TQPixmap &pixmap, int sx, int sy )
+{
+ int sw = pixmap.width();
+ int sh = pixmap.height();
+ if (!sw || !sh )
+ return;
+ if ( sx < 0 )
+ sx = sw - -sx % sw;
+ else
+ sx = sx % sw;
+ if ( sy < 0 )
+ sy = sh - -sy % sh;
+ else
+ sy = sy % sh;
+ /*
+ Requirements for optimizing tiled pixmaps:
+ - not an external tqdevice
+ - not scale or rotshear
+ - not mono pixmap
+ - no tqmask
+ */
+ TQBitmap *tqmask = (TQBitmap *)pixmap.tqmask();
+ if ( !testf(ExtDev) && txop <= TxTranslate && pixmap.depth() > 1 &&
+ tqmask == 0 ) {
+ if ( txop == TxTranslate )
+ map( x, y, &x, &y );
+
+#if !defined(TQT_NO_XFTFREETYPE) && !defined(TQT_NO_XRENDER)
+ Picture pict = rendhd ? XftDrawPicture((XftDraw *) rendhd) : None;
+ TQPixmap *alpha = pixmap.data->alphapm;
+
+ if (pict && pixmap.x11RenderHandle() && alpha && alpha->x11RenderHandle()) {
+ // this is essentially drawTile() from above, inlined for
+ // the XRenderComposite call
+ int yPos, xPos, drawH, drawW, yOff, xOff;
+ yPos = y;
+ yOff = sy;
+ while( yPos < y + h ) {
+ drawH = pixmap.height() - yOff; // Cropping first row
+ if ( yPos + drawH > y + h ) // Cropping last row
+ drawH = y + h - yPos;
+ xPos = x;
+ xOff = sx;
+ while( xPos < x + w ) {
+ drawW = pixmap.width() - xOff; // Cropping first column
+ if ( xPos + drawW > x + w ) // Cropping last column
+ drawW = x + w - xPos;
+ XRenderComposite(dpy, PictOpOver, pixmap.x11RenderHandle(),
+ alpha->x11RenderHandle(), pict,
+ xOff, yOff, xOff, yOff, xPos, yPos, drawW, drawH);
+ xPos += drawW;
+ xOff = 0;
+ }
+ yPos += drawH;
+ yOff = 0;
+ }
+ return;
+ }
+#endif // !TQT_NO_XFTFREETYPE && !TQT_NO_XRENDER
+
+ XSetTile( dpy, gc, pixmap.handle() );
+ XSetFillStyle( dpy, gc, FillTiled );
+ XSetTSOrigin( dpy, gc, x-sx, y-sy );
+ XFillRectangle( dpy, hd, gc, x, y, w, h );
+ XSetTSOrigin( dpy, gc, 0, 0 );
+ XSetFillStyle( dpy, gc, FillSolid );
+ return;
+ }
+
+#if 0
+ // maybe there'll be point in this again, but for the time all it
+ // does is make trouble for the postscript code.
+ if ( sw*sh < 8192 && sw*sh < 16*w*h ) {
+ int tw = sw;
+ int th = sh;
+ while( th * tw < 4096 && ( th < h || tw < w ) ) {
+ if ( h/th > w/tw )
+ th *= 2;
+ else
+ tw *= 2;
+ }
+ TQPixmap tile( tw, th, pixmap.depth(), TQPixmap::NormalOptim );
+ fillTile( &tile, pixmap );
+ if ( tqmask ) {
+ TQBitmap tiletqmask( tw, th, TQPixmap::NormalOptim );
+ fillTile( &tiletqmask, *tqmask );
+ tile.setMask( tiletqmask );
+ }
+ drawTile( this, x, y, w, h, tile, sx, sy );
+ } else {
+ drawTile( this, x, y, w, h, pixmap, sx, sy );
+ }
+#else
+ // for now we'll just output the original and let the postscript
+ // code make what it can of it. qpicture will be unhappy.
+ drawTile( this, x, y, w, h, pixmap, sx, sy );
+#endif
+}
+
+#if 0
+//
+// Generate a string that describes a transformed bitmap. This string is used
+// to insert and tqfind bitmaps in the global pixmap cache.
+//
+
+static TQString gen_text_bitmap_key( const TQWMatrix &m, const TQFont &font,
+ const TQString &str, int pos, int len )
+{
+ TQString fk = font.key();
+ int sz = 4*2 + len*2 + fk.length()*2 + sizeof(double)*6;
+ TQByteArray buf(sz);
+ uchar *p = (uchar *)buf.data();
+ *((double*)p)=m.m11(); p+=sizeof(double);
+ *((double*)p)=m.m12(); p+=sizeof(double);
+ *((double*)p)=m.m21(); p+=sizeof(double);
+ *((double*)p)=m.m22(); p+=sizeof(double);
+ *((double*)p)=m.dx(); p+=sizeof(double);
+ *((double*)p)=m.dy(); p+=sizeof(double);
+ TQChar h1( '$' );
+ TQChar h2( 'q' );
+ TQChar h3( 't' );
+ TQChar h4( '$' );
+ *((TQChar*)p)=h1; p+=2;
+ *((TQChar*)p)=h2; p+=2;
+ *((TQChar*)p)=h3; p+=2;
+ *((TQChar*)p)=h4; p+=2;
+ memcpy( (char*)p, (char*)(str.tqunicode()+pos), len*2 ); p += len*2;
+ memcpy( (char*)p, (char*)fk.tqunicode(), fk.length()*2 ); p += fk.length()*2;
+ return TQString( (TQChar*)buf.data(), buf.size()/2 );
+}
+
+static TQBitmap *get_text_bitmap( const TQString &key )
+{
+ return (TQBitmap*)TQPixmapCache::tqfind( key );
+}
+
+static void ins_text_bitmap( const TQString &key, TQBitmap *bm )
+{
+ if ( !TQPixmapCache::insert(key, bm) ) // cannot insert pixmap
+ delete bm;
+}
+#endif
+
+void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill )
+{
+ XPoint points[5];
+ int xp = x, yp = y;
+ p->map( xp, yp, &xp, &yp );
+ points[0].x = xp;
+ points[0].y = yp;
+ xp = x + w; yp = y;
+ p->map( xp, yp, &xp, &yp );
+ points[1].x = xp;
+ points[1].y = yp;
+ xp = x + w; yp = y + h;
+ p->map( xp, yp, &xp, &yp );
+ points[2].x = xp;
+ points[2].y = yp;
+ xp = x; yp = y + h;
+ p->map( xp, yp, &xp, &yp );
+ points[3].x = xp;
+ points[3].y = yp;
+ points[4] = points[0];
+
+ if ( fill )
+ XFillPolygon( p->dpy, p->hd, p->gc, points, 4, Convex, CoordModeOrigin );
+ else
+ XDrawLines( p->dpy, p->hd, p->gc, points, 5, CoordModeOrigin );
+}
+
+void qt_draw_background( TQPainter *p, int x, int y, int w, int h )
+{
+ if (p->testf(TQPainter::ExtDev)) {
+ if (p->pdev->devType() == TQInternal::Printer)
+ p->fillRect(x, y, w, h, p->bg_col);
+ return;
+ }
+ XSetForeground( p->dpy, p->gc, p->bg_col.pixel(p->scrn) );
+ qt_draw_transformed_rect( p, x, y, w, h, TRUE);
+ XSetForeground( p->dpy, p->gc, p->cpen.color().pixel(p->scrn) );
+}
+
+/*!
+ Draws at most \a len characters of the string \a str at position
+ \a (x, y).
+
+ \a (x, y) is the base line position. Note that the meaning of \a y
+ is not the same for the two drawText() varieties.
+*/
+void TQPainter::drawText( int x, int y, const TQString &str, int len, TQPainter::TextDirection dir )
+{
+ drawText( x, y, str, 0, len, dir );
+}
+
+/*!
+ Draws at most \a len characters starting at position \a pos from the
+ string \a str to position \a (x, y).
+
+ \a (x, y) is the base line position. Note that the meaning of \a y
+ is not the same for the two drawText() varieties.
+*/
+void TQPainter::drawText( int x, int y, const TQString &str, int pos, int len, TQPainter::TextDirection dir )
+{
+ if ( !isActive() )
+ return;
+ if (len < 0)
+ len = str.length() - pos;
+ if ( len <= 0 || pos >= (int)str.length() ) // empty string
+ return;
+ if ( pos + len > (int)str.length() )
+ len = str.length() - pos;
+
+ if ( testf(DirtyFont) ) {
+ updateFont();
+ }
+
+ if ( testf(ExtDev) && pdev->devType() != TQInternal::Printer ) {
+ TQPDevCmdParam param[3];
+ TQPoint p(x, y);
+ TQString string = str.mid( pos, len );
+ param[0].point = &p;
+ param[1].str = &string;
+ param[2].ival = TQFont::Latin;
+ if ( !pdev->cmd(TQPaintDevice::PdcDrawText2, this, param) || !hd )
+ return;
+ }
+
+ bool simple = (dir == TQPainter::Auto) && str.simpleText();
+ // we can't take the complete string here as we would otherwise
+ // get quadratic behaviour when drawing long strings in parts.
+ // we do however need some chars around the part we paint to get arabic shaping correct.
+ // ### maybe possible to remove after cursor restrictions work in TQRT
+ int start;
+ int end;
+ if ( simple ) {
+ start = pos;
+ end = pos+len;
+ } else {
+ start = TQMAX( 0, pos - 8 );
+ end = TQMIN( (int)str.length(), pos + len + 8 );
+ }
+ TQConstString cstr( str.tqunicode() + start, end - start );
+ pos -= start;
+
+ TQTextEngine engine( cstr.string(), pfont ? pfont->d : cfont.d );
+ TQTextLayout tqlayout( &engine );
+
+ // this is actually what beginLayout does. Inlined here, so we can
+ // avoid the bidi algorithm if we don't need it.
+ engine.itemize( simple ? TQTextEngine::NoBidi|TQTextEngine::SingleLine : TQTextEngine::Full|TQTextEngine::SingleLine );
+ engine.currentItem = 0;
+ engine.firstItemInLine = -1;
+
+ if ( dir != Auto ) {
+ int level = dir == RTL ? 1 : 0;
+ for ( int i = engine.items.size(); i >= 0; i-- )
+ engine.items[i].analysis.bidiLevel = level;
+ }
+
+ if ( !simple ) {
+ tqlayout.setBoundary( pos );
+ tqlayout.setBoundary( pos + len );
+ }
+
+ // small hack to force skipping of unneeded items
+ start = 0;
+ while ( engine.items[start].position < pos )
+ ++start;
+ engine.currentItem = start;
+ tqlayout.beginLine( 0xfffffff );
+ end = start;
+ while ( !tqlayout.atEnd() && tqlayout.currentItem().from() < pos + len ) {
+ tqlayout.addCurrentItem();
+ end++;
+ }
+ TQFontMetrics fm(fontMetrics());
+ int ascent = fm.ascent(), descent = fm.descent();
+ int left, right;
+ tqlayout.endLine( 0, 0, TQt::SingleLine|TQt::AlignLeft, &ascent, &descent, &left, &right );
+
+ // do _not_ call endLayout() here, as it would clean up the tqshaped items and we would do shaping another time
+ // for painting.
+
+ int textFlags = 0;
+ if ( cfont.d->underline ) textFlags |= TQt::Underline;
+ if ( cfont.d->overline ) textFlags |= TQt::Overline;
+ if ( cfont.d->strikeOut ) textFlags |= TQt::StrikeOut;
+
+ if ( bg_mode == OpaqueMode )
+ qt_draw_background( this, x, y-ascent, right-left, ascent+descent+1);
+
+ for ( int i = start; i < end; i++ ) {
+ TQTextItem ti;
+ ti.item = i;
+ ti.engine = &engine;
+
+ tqdrawTextItem( x, y - ascent, ti, textFlags );
+ }
+ tqlayout.d = 0;
+}
+
+
+/*! \internal
+ Draws the text item \a ti at position \a (x, y ).
+
+ This method ignores the painters background mode and
+ color. drawText and qt_format_text have to do it themselves, as
+ only they know the extents of the complete string.
+
+ It ignores the font set on the painter as the text item has one of its own.
+
+ The underline and strikeout parameters of the text items font are
+ ignored aswell. You'll need to pass in the correct flags to get
+ underlining and strikeout.
+*/
+void TQPainter::tqdrawTextItem( int x, int y, const TQTextItem &ti, int textFlags )
+{
+ if ( testf(ExtDev) ) {
+ TQPDevCmdParam param[2];
+ TQPoint p(x, y);
+ param[0].point = &p;
+ param[1].textItem = &ti;
+ bool retval = pdev->cmd(TQPaintDevice::PdcDrawTextItem, this, param);
+ if ( !retval || !hd )
+ return;
+ }
+
+ TQTextEngine *engine = ti.engine;
+ TQScriptItem *si = &engine->items[ti.item];
+
+ engine->tqshape( ti.item );
+ TQFontEngine *fe = si->fontEngine;
+ assert( fe != 0 );
+
+ x += si->x;
+ y += si->y;
+
+ fe->draw( this, x, y, engine, si, textFlags );
+}
+
+#if TQT_VERSION >= 0x040000
+#error "remove current position and associated methods"
+#endif
+/*!
+ \obsolete
+ Returns the current position of the pen.
+
+ \sa moveTo()
+ */
+TQPoint TQPainter::pos() const
+{
+ return curPt;
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpalette.cpp b/tqtinterface/qt4/src/kernel/tqpalette.cpp
new file mode 100644
index 0000000..2e9e49e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpalette.cpp
@@ -0,0 +1,1348 @@
+/****************************************************************************
+**
+** Implementation of TQColorGroup and TQPalette classes
+**
+** Created : 950323
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+// Nasty, nasty horrid HACK to get access to QPalette's private members
+// This is TERRIBLE and I wish there was a way around it
+// This is a good example of the new, broken & irritating Qt4 API,
+// and the corresponding loss in functionality versus Qt3.
+// See also tqrect.cpp
+#define private protected
+#include <Qt/qpalette.h>
+#undef private
+
+#include "tqpalette.h"
+
+#ifndef TQT_NO_PALETTE
+#include "tqdatastream.h"
+#include "tqcleanuphandler.h"
+
+#ifdef USE_QT4
+
+#include <Qt/qvariant.h>
+
+/*!
+ Constructs a palette with the specified \a active, \a disabled and
+ \a inactive color groups.
+*/
+TQPalette::TQPalette(const TQColorGroup &active, const TQColorGroup &disabled, const TQColorGroup &inactive) : QPalette()
+{
+ Q_ASSERT(TQPalette::NColorRoles == TQPalette::ToolTipText + 1);
+ tqsetColorGroup(Active, active);
+ tqsetColorGroup(Disabled, disabled);
+ tqsetColorGroup(Inactive, inactive);
+}
+
+TQColorGroup TQPalette::createColorGroup(ColorGroup cr) const
+{
+ TQColorGroup ret(*this);
+ ret.setCurrentColorGroup(cr);
+ return ret;
+}
+
+void TQPalette::tqsetColorGroup(ColorGroup cg, const TQColorGroup &g)
+{
+ setColorGroup(cg, g.brush(WindowText), g.brush(Button), g.brush(Light),
+ g.brush(Dark), g.brush(Mid), g.brush(Text), g.brush(BrightText),
+ g.brush(Base), g.brush(AlternateBase), g.brush(Window),
+ g.brush(Midlight), g.brush(ButtonText), g.brush(Shadow),
+ g.brush(Highlight), g.brush(HighlightedText), g.brush(Link),
+ g.brush(LinkVisited), g.brush(ToolTipBase), g.brush(ToolTipText));
+}
+
+bool TQColorGroup::operator==(const TQColorGroup &other) const
+{
+ if (isCopyOf(other))
+ return true;
+ for (int role = 0; role < int(NColorRoles); role++) {
+ if (brush(currentColorGroup(), (QPalette::ColorRole)role) != other.brush((QPalette::ColorGroup)(other.currentColorGroup()), (QPalette::ColorRole)role))
+ return false;
+ }
+ return true;
+}
+
+/*!
+ Returns the color group as a QVariant
+*/
+// TQColorGroup::operator QVariant() const
+// {
+// return QVariant(QVariant::ColorGroup, this);
+// }
+
+/*!\internal*/
+TQPalette::ColorRole TQPalette::foregroundRoleFromMode( TQt::BackgroundMode mode )
+{
+ switch (mode) {
+ case TQt::PaletteButton:
+ return TQColorGroup::ButtonText;
+ case TQt::PaletteBase:
+ return TQColorGroup::Text;
+ case TQt::PaletteDark:
+ case TQt::PaletteShadow:
+ return TQColorGroup::Light;
+ case TQt::PaletteHighlight:
+ return TQColorGroup::HighlightedText;
+ case TQt::PaletteBackground:
+ default:
+ return TQColorGroup::Foreground;
+ }
+}
+
+/*!\internal*/
+TQPalette::ColorRole TQPalette::backgroundRoleFromMode( TQt::BackgroundMode mode)
+{
+ switch (mode) {
+ case TQt::PaletteForeground:
+ return TQColorGroup::Foreground;
+ case TQt::PaletteButton:
+ return TQColorGroup::Button;
+ case TQt::PaletteLight:
+ return TQColorGroup::Light;
+ case TQt::PaletteMidlight:
+ return TQColorGroup::Midlight;
+ case TQt::PaletteDark:
+ return TQColorGroup::Dark;
+ case TQt::PaletteMid:
+ return TQColorGroup::Mid;
+ case TQt::PaletteText:
+ return TQColorGroup::Text;
+ case TQt::PaletteBrightText:
+ return TQColorGroup::BrightText;
+ case TQt::PaletteButtonText:
+ return TQColorGroup::ButtonText;
+ case TQt::PaletteBase:
+ return TQColorGroup::Base;
+ case TQt::PaletteShadow:
+ return TQColorGroup::Shadow;
+ case TQt::PaletteHighlight:
+ return TQColorGroup::Highlight;
+ case TQt::PaletteHighlightedText:
+ return TQColorGroup::HighlightedText;
+ case TQt::PaletteLink:
+ return TQColorGroup::Link;
+ case TQt::PaletteLinkVisited:
+ return TQColorGroup::LinkVisited;
+ case TQt::PaletteBackground:
+ default:
+ return TQColorGroup::Background;
+ }
+}
+
+#else // USE_QT4
+
+/*****************************************************************************
+ TQColorGroup member functions
+ *****************************************************************************/
+
+/*!
+ \class TQColorGroup tqpalette.h
+ \brief The TQColorGroup class tqcontains a group of widget colors.
+
+ \ingroup appearance
+ \ingroup graphics
+ \ingroup images
+
+ A color group tqcontains a group of colors used by widgets for
+ drawing themselves. We recommend that widgets use color group
+ roles such as "foreground" and "base" rather than literal colors
+ like "red" or "turquoise". The color roles are enumerated and
+ defined in the \l ColorRole documentation.
+
+ The most common use of TQColorGroup is like this:
+
+ \code
+ TQPainter p;
+ ...
+ p.setPen( tqcolorGroup().foreground() );
+ p.drawLine( ... )
+ \endcode
+
+ It is also possible to modify color groups or create new color
+ groups from scratch.
+
+ The color group class can be created using three different
+ constructors or by modifying one supplied by TQt. The default
+ constructor creates an all-black color group, which can then be
+ modified using set functions; there's also a constructor for
+ specifying all the color group colors. And there is also a copy
+ constructor.
+
+ We strongly recommend using a system-supplied color group and
+ modifying that as necessary.
+
+ You modify a color group by calling the access functions
+ setColor() and setBrush(), depending on whether you want a pure
+ color or a pixmap pattern.
+
+ There are also corresponding color() and brush() getters, and a
+ commonly used convenience function to get each ColorRole:
+ background(), foreground(), base(), etc.
+
+ \sa TQColor TQPalette TQWidget::tqcolorGroup()
+*/
+
+
+/*!
+ \enum TQColorGroup::ColorRole
+
+ The ColorRole enum defines the different symbolic color roles used
+ in current GUIs.
+
+ The central roles are:
+
+ \value Background general background color.
+
+ \value Foreground general foreground color.
+
+ \value Base used as background color for text entry widgets, for example;
+ usually white or another light color.
+
+ \value Text the foreground color used with \c Base. Usually this
+ is the same as the \c Foreground, in which case it must provide good
+ contrast with \c Background and \c Base.
+
+ \value Button general button background color in which buttons need a
+ background different from \c Background, as in the Macintosh style.
+
+ \value ButtonText a foreground color used with the \c Button color.
+
+ There are some color roles used mostly for 3D bevel and shadow
+ effects:
+
+ \value Light lighter than \c Button color.
+
+ \value Midlight between \c Button and \c Light.
+
+ \value Dark darker than \c Button.
+
+ \value Mid between \c Button and \c Dark.
+
+ \value Shadow a very dark color.
+ By default, the shadow color is \c TQt::black.
+
+ All of these are normally derived from \c Background and used in
+ ways that depend on that relationship. For example, buttons depend
+ on it to make the bevels look attractive, and Motif scroll bars
+ depend on \c Mid to be slightly different from \c Background.
+
+ Selected (marked) items have two roles:
+
+ \value Highlight a color to indicate a selected item or the
+ current item. By default, the highlight color is \c TQt::darkBlue.
+
+ \value HighlightedText a text color that contrasts with \c Highlight.
+ By default, the highlighted text color is \c TQt::white.
+
+ Finally, there is a special role for text that needs to be
+ drawn where \c Text or \c Foreground would give poor contrast,
+ such as on pressed push buttons:
+
+ \value BrightText a text color that is very different from \c
+ Foreground and contrasts well with e.g. \c Dark.
+
+ \value Link a text color used for unvisited hyperlinks.
+ By default, the link color is \c TQt::blue.
+
+ \value LinkVisited a text color used for already visited hyperlinks.
+ By default, the linkvisited color is \c TQt::magenta.
+
+ \value NColorRoles Internal.
+
+ Note that text colors can be used for things other than just
+ words; text colors are \e usually used for text, but it's quite
+ common to use the text color roles for lines, icons, etc.
+
+ This image shows most of the color roles in use:
+ \img palette.png Color Roles
+*/
+
+
+class TQColorGroupPrivate : public TQShared
+{
+public:
+ TQBrush br[TQColorGroup::NColorRoles];
+ TQColorGroupPrivate* detach() {
+ if ( count > 1 ) {
+ deref();
+ TQColorGroupPrivate* d = new TQColorGroupPrivate;
+ for (int i=0; i<TQColorGroup::NColorRoles; i++)
+ d->br[i] = br[i];
+ return d;
+ }
+ return this;
+ }
+};
+
+/*!
+ Constructs a color group with all colors set to black.
+*/
+
+TQColorGroup::TQColorGroup()
+{
+ static TQColorGroupPrivate* defColorGroupData = 0;
+ if ( !defColorGroupData ) {
+ static TQSharedCleanupHandler<TQColorGroupPrivate> defColorGroupCleanup;
+ defColorGroupData = new TQColorGroupPrivate;
+ defColorGroupCleanup.set( &defColorGroupData );
+ }
+ d = defColorGroupData;
+ br = d->br;
+ d->ref();
+}
+
+/*!
+ Constructs a color group that is an independent copy of \a other.
+*/
+TQColorGroup::TQColorGroup( const TQColorGroup& other )
+{
+ d = other.d;
+ d->ref();
+ br = d->br;
+}
+
+/*!
+ Copies the colors of \a other to this color group.
+*/
+TQColorGroup& TQColorGroup::operator =(const TQColorGroup& other)
+{
+ if ( d != other.d ) {
+ if ( d->deref() )
+ delete d;
+ d = other.d;
+ br = d->br;
+ d->ref();
+ }
+ return *this;
+}
+
+static TQColor qt_mix_colors( TQColor a, TQColor b)
+{
+ return TQColor( (a.red() + b.red()) / 2, (a.green() + b.green()) / 2, (a.blue() + b.blue()) / 2 );
+}
+
+
+/*!
+ Constructs a color group. You can pass either brushes, pixmaps or
+ plain colors for \a foreground, \a button, \a light, \a dark, \a
+ mid, \a text, \a bright_text, \a base and \a background.
+
+ \sa TQBrush
+*/
+ TQColorGroup::TQColorGroup( const TQBrush &foreground, const TQBrush &button,
+ const TQBrush &light, const TQBrush &dark,
+ const TQBrush &mid, const TQBrush &text,
+ const TQBrush &bright_text, const TQBrush &base,
+ const TQBrush &background)
+{
+ d = new TQColorGroupPrivate;
+ br = d->br;
+ br[Foreground] = foreground;
+ br[Button] = button;
+ br[Light] = light;
+ br[Dark] = dark;
+ br[Mid] = mid;
+ br[Text] = text;
+ br[BrightText] = bright_text;
+ br[ButtonText] = text;
+ br[Base] = base;
+ br[Background] = background;
+ br[Midlight] = qt_mix_colors( br[Button].color(), br[Light].color() );
+ br[Shadow] = TQt::black;
+ br[Highlight] = TQt::darkBlue;
+ br[HighlightedText] = TQt::white;
+ br[Link] = TQt::blue;
+ br[LinkVisited] = TQt::magenta;
+}
+
+
+/*!\obsolete
+
+ Constructs a color group with the specified colors. The button
+ color will be set to the background color.
+*/
+
+TQColorGroup::TQColorGroup( const TQColor &foreground, const TQColor &background,
+ const TQColor &light, const TQColor &dark,
+ const TQColor &mid,
+ const TQColor &text, const TQColor &base )
+{
+ d = new TQColorGroupPrivate;
+ br = d->br;
+ br[Foreground] = TQBrush(foreground);
+ br[Button] = TQBrush(background);
+ br[Light] = TQBrush(light);
+ br[Dark] = TQBrush(dark);
+ br[Mid] = TQBrush(mid);
+ br[Text] = TQBrush(text);
+ br[BrightText] = br[Light];
+ br[ButtonText] = br[Text];
+ br[Base] = TQBrush(base);
+ br[Background] = TQBrush(background);
+ br[Midlight] = qt_mix_colors( br[Button].color(), br[Light].color() );
+ br[Shadow] = TQt::black;
+ br[Highlight] = TQt::darkBlue;
+ br[HighlightedText] = TQt::white;
+ br[Link] = TQt::blue;
+ br[LinkVisited] = TQt::magenta;
+}
+
+/*!
+ Destroys the color group.
+*/
+
+TQColorGroup::~TQColorGroup()
+{
+ if ( d->deref() )
+ delete d;
+}
+
+/*!
+ Returns the color that has been set for color role \a r.
+
+ \sa brush() ColorRole
+ */
+const TQColor &TQColorGroup::color( ColorRole r ) const
+{
+ return br[r].color();
+}
+
+/*!
+ Returns the brush that has been set for color role \a r.
+
+ \sa color() setBrush() ColorRole
+*/
+const TQBrush &TQColorGroup::brush( ColorRole r ) const
+{
+ return br[r];
+}
+
+/*!
+ Sets the brush used for color role \a r to a solid color \a c.
+
+ \sa brush() setColor() ColorRole
+*/
+void TQColorGroup::setColor( ColorRole r, const TQColor &c )
+{
+ setBrush( r, TQBrush(c) );
+}
+
+/*!
+ Sets the brush used for color role \a r to \a b.
+
+ \sa brush() setColor() ColorRole
+*/
+void TQColorGroup::setBrush( ColorRole r, const TQBrush &b )
+{
+ d = d->detach();
+ br = d->br;
+ br[r] = b;
+}
+
+
+/*!
+ \fn const TQColor & TQColorGroup::foreground() const
+
+ Returns the foreground color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::button() const
+
+ Returns the button color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::light() const
+
+ Returns the light color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor& TQColorGroup::midlight() const
+
+ Returns the midlight color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::dark() const
+
+ Returns the dark color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::mid() const
+
+ Returns the mid color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::text() const
+
+ Returns the text foreground color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::brightText() const
+
+ Returns the bright text foreground color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::buttonText() const
+
+ Returns the button text foreground color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::base() const
+
+ Returns the base color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::background() const
+
+ Returns the background color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::shadow() const
+
+ Returns the shadow color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::highlight() const
+
+ Returns the highlight color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::highlightedText() const
+
+ Returns the highlighted text color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::link() const
+
+ Returns the unvisited link text color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn const TQColor & TQColorGroup::linkVisited() const
+
+ Returns the visited link text color of the color group.
+
+ \sa ColorRole
+*/
+
+/*!
+ \fn bool TQColorGroup::operator!=( const TQColorGroup &g ) const
+
+ Returns TRUE if this color group is different from \a g; otherwise
+ returns FALSE.
+
+ \sa operator!=()
+*/
+
+/*!
+ Returns TRUE if this color group is equal to \a g; otherwise
+ returns FALSE.
+
+ \sa operator==()
+*/
+
+bool TQColorGroup::operator==( const TQColorGroup &g ) const
+{
+ if ( d == g.d )
+ return TRUE;
+ for( int r = 0 ; r < NColorRoles ; r++ )
+ if ( br[r] != g.br[r] )
+ return FALSE;
+ return TRUE;
+}
+
+/*****************************************************************************
+ TQPalette member functions
+ *****************************************************************************/
+
+/*!
+ \class TQPalette tqpalette.h
+
+ \brief The TQPalette class tqcontains color groups for each widget state.
+
+ \ingroup appearance
+ \ingroup shared
+ \ingroup graphics
+ \ingroup images
+ \mainclass
+
+ A palette consists of three color groups: \e active, \e disabled,
+ and \e inactive. All widgets contain a palette, and all widgets in
+ TQt use their palette to draw themselves. This makes the user
+ interface easily configurable and easier to keep consistent.
+
+ If you create a new widget we strongly recommend that you use the
+ colors in the palette rather than hard-coding specific colors.
+
+ The color groups:
+ \list
+ \i The active() group is used for the window that has keyboard focus.
+ \i The inactive() group is used for other windows.
+ \i The disabled() group is used for widgets (not windows) that are
+ disabled for some reason.
+ \endlist
+
+ Both active and inactive windows can contain disabled widgets.
+ (Disabled widgets are often called \e inaccessible or \e{grayed
+ out}.)
+
+ In Motif style, active() and inactive() look the same. In Windows
+ 2000 style and Macintosh Platinum style, the two styles look
+ slightly different.
+
+ There are setActive(), setInactive(), and setDisabled() functions
+ to modify the palette. (TQt also supports a normal() group; this is
+ an obsolete alias for active(), supported for backwards
+ compatibility.)
+
+ Colors and brushes can be set for particular roles in any of a
+ palette's color groups with setColor() and setBrush().
+
+ You can copy a palette using the copy constructor and test to see
+ if two palettes are \e identical using isCopyOf().
+
+ \sa TQApplication::setPalette(), TQWidget::setPalette(), TQColorGroup, TQColor
+*/
+
+/*!
+ \enum TQPalette::ColorGroup
+
+ \value Disabled
+ \value Active
+ \value Inactive
+ \value NColorGroups
+ \value Normal synonym for Active
+*/
+
+/*!
+ \obsolete
+
+ \fn const TQColorGroup &TQPalette::normal() const
+
+ Returns the active color group. Use active() instead.
+
+ \sa setActive() active()
+*/
+
+/*!
+ \obsolete
+
+ \fn void TQPalette::setNormal( const TQColorGroup & cg )
+
+ Sets the active color group to \a cg. Use setActive() instead.
+
+ \sa setActive() active()
+*/
+
+
+static int palette_count = 1;
+
+/*!
+ Constructs a palette that consists of color groups with only black
+ colors.
+*/
+
+TQPalette::TQPalette()
+{
+ static TQPalData *defPalData = 0;
+ if ( !defPalData ) { // create common palette data
+ defPalData = new TQPalData; // for the default palette
+ static TQSharedCleanupHandler<TQPalData> defPalCleanup;
+ defPalCleanup.set( &defPalData );
+ defPalData->ser_no = palette_count++;
+ }
+ data = defPalData;
+ data->ref();
+}
+
+/*!\obsolete
+ Constructs a palette from the \a button color. The other colors are
+ automatically calculated, based on this color. Background will be
+ the button color as well.
+*/
+
+TQPalette::TQPalette( const TQColor &button )
+{
+ data = new TQPalData;
+ TQ_CHECK_PTR( data );
+ data->ser_no = palette_count++;
+ TQColor bg = button, btn = button, fg, base, disfg;
+ int h, s, v;
+ bg.hsv( &h, &s, &v );
+ if ( v > 128 ) { // light background
+ fg = TQt::black;
+ base = TQt::white;
+ disfg = TQt::darkGray;
+ } else { // dark background
+ fg = TQt::white;
+ base = TQt::black;
+ disfg = TQt::darkGray;
+ }
+ data->active = TQColorGroup( fg, btn, btn.light(150), btn.dark(),
+ btn.dark(150), fg, TQt::white, base, bg );
+ data->disabled = TQColorGroup( disfg, btn, btn.light(150), btn.dark(),
+ btn.dark(150), disfg, TQt::white, base, bg );
+ data->inactive = data->active;
+}
+
+/*!
+ Constructs a palette from a \a button color and a \a background.
+ The other colors are automatically calculated, based on these
+ colors.
+*/
+
+TQPalette::TQPalette( const TQColor &button, const TQColor &background )
+{
+ data = new TQPalData;
+ TQ_CHECK_PTR( data );
+ data->ser_no = palette_count++;
+ TQColor bg = background, btn = button, fg, base, disfg;
+ int h, s, v;
+ bg.hsv( &h, &s, &v );
+ if ( v > 128 ) { // light background
+ fg = TQt::black;
+ base = TQt::white;
+ disfg = TQt::darkGray;
+ } else { // dark background
+ fg = TQt::white;
+ base = TQt::black;
+ disfg = TQt::darkGray;
+ }
+ data->active = TQColorGroup( fg, btn, btn.light(150), btn.dark(),
+ btn.dark(150), fg, TQt::white, base, bg );
+ data->disabled = TQColorGroup( disfg, btn, btn.light(150), btn.dark(),
+ btn.dark(150), disfg, TQt::white, base, bg );
+ data->inactive = data->active;
+}
+
+/*!
+ Constructs a palette that consists of the three color groups \a
+ active, \a disabled and \a inactive. See the \link #details
+ Detailed Description\endlink for definitions of the color groups
+ and \l TQColorGroup::ColorRole for definitions of each color role
+ in the three groups.
+
+ \sa TQColorGroup TQColorGroup::ColorRole TQPalette
+*/
+
+TQPalette::TQPalette( const TQColorGroup &active, const TQColorGroup &disabled,
+ const TQColorGroup &inactive )
+{
+ data = new TQPalData;
+ TQ_CHECK_PTR( data );
+ data->ser_no = palette_count++;
+ data->active = active;
+ data->disabled = disabled;
+ data->inactive = inactive;
+}
+
+/*!
+ Constructs a copy of \a p.
+
+ This constructor is fast (it uses copy-on-write).
+*/
+
+TQPalette::TQPalette( const TQPalette &p )
+{
+ data = p.data;
+ data->ref();
+}
+
+/*!
+ Destroys the palette.
+*/
+
+TQPalette::~TQPalette()
+{
+ if ( data->deref() )
+ delete data;
+}
+
+/*!
+ Assigns \a p to this palette and returns a reference to this
+ palette.
+
+ This is fast (it uses copy-on-write).
+
+ \sa copy()
+*/
+
+TQPalette &TQPalette::operator=( const TQPalette &p )
+{
+ p.data->ref();
+ if ( data->deref() )
+ delete data;
+ data = p.data;
+ return *this;
+}
+
+
+/*!
+ Returns the color in color group \a gr, used for color role \a r.
+
+ \sa brush() setColor() TQColorGroup::ColorRole
+*/
+const TQColor &TQPalette::color( ColorGroup gr, TQColorGroup::ColorRole r ) const
+{
+ return directBrush( gr, r ).color();
+}
+
+/*!
+ Returns the brush in color group \a gr, used for color role \a r.
+
+ \sa color() setBrush() TQColorGroup::ColorRole
+*/
+const TQBrush &TQPalette::brush( ColorGroup gr, TQColorGroup::ColorRole r ) const
+{
+ return directBrush( gr, r );
+}
+
+/*!
+ Sets the brush in color group \a gr, used for color role \a r, to
+ the solid color \a c.
+
+ \sa setBrush() color() TQColorGroup::ColorRole
+*/
+void TQPalette::setColor( ColorGroup gr, TQColorGroup::ColorRole r,
+ const TQColor &c)
+{
+ setBrush( gr, r, TQBrush(c) );
+}
+
+/*!
+ Sets the brush in color group \a gr, used for color role \a r, to
+ \a b.
+
+ \sa brush() setColor() TQColorGroup::ColorRole
+*/
+void TQPalette::setBrush( ColorGroup gr, TQColorGroup::ColorRole r,
+ const TQBrush &b)
+{
+ detach();
+ data->ser_no = palette_count++;
+ directSetBrush( gr, r, b);
+}
+
+/*!
+ \overload
+
+ Sets the brush color used for color role \a r to color \a c in all
+ three color groups.
+
+ \sa color() setBrush() TQColorGroup::ColorRole
+*/
+void TQPalette::setColor( TQColorGroup::ColorRole r, const TQColor &c )
+{
+ setBrush( r, TQBrush(c) );
+}
+
+/*!
+ \overload
+
+ Sets the brush in for color role \a r in all three color groups to
+ \a b.
+
+ \sa brush() setColor() TQColorGroup::ColorRole active() inactive() disabled()
+*/
+void TQPalette::setBrush( TQColorGroup::ColorRole r, const TQBrush &b )
+{
+ detach();
+ data->ser_no = palette_count++;
+ directSetBrush( Active, r, b );
+ directSetBrush( Disabled, r, b );
+ directSetBrush( Inactive, r, b );
+}
+
+
+/*!
+ Returns a deep copy of this palette.
+
+ \warning This is slower than the copy constructor and assignment
+ operator and offers no benefits.
+*/
+
+TQPalette TQPalette::copy() const
+{
+ TQPalette p( data->active, data->disabled, data->inactive );
+ return p;
+}
+
+
+/*!
+ Detaches this palette from any other TQPalette objects with which
+ it might implicitly share TQColorGroup objects. In essence, does
+ the copying part of copy-on-write.
+
+ Calling this should generally not be necessary; TQPalette calls it
+ itself when necessary.
+*/
+
+void TQPalette::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+}
+
+/*!
+ \fn const TQColorGroup & TQPalette::disabled() const
+
+ Returns the disabled color group of this palette.
+
+ \sa TQColorGroup, setDisabled(), active(), inactive()
+*/
+
+/*!
+ Sets the \c Disabled color group to \a g.
+
+ \sa disabled() setActive() setInactive()
+*/
+
+void TQPalette::setDisabled( const TQColorGroup &g )
+{
+ detach();
+ data->ser_no = palette_count++;
+ data->disabled = g;
+}
+
+/*!
+ \fn const TQColorGroup & TQPalette::active() const
+
+ Returns the active color group of this palette.
+
+ \sa TQColorGroup, setActive(), inactive(), disabled()
+*/
+
+/*!
+ Sets the \c Active color group to \a g.
+
+ \sa active() setDisabled() setInactive() TQColorGroup
+*/
+
+void TQPalette::setActive( const TQColorGroup &g )
+{
+ detach();
+ data->ser_no = palette_count++;
+ data->active = g;
+}
+
+/*!
+ \fn const TQColorGroup & TQPalette::inactive() const
+
+ Returns the inactive color group of this palette.
+
+ \sa TQColorGroup, setInactive(), active(), disabled()
+*/
+
+/*!
+ Sets the \c Inactive color group to \a g.
+
+ \sa active() setDisabled() setActive() TQColorGroup
+*/
+
+void TQPalette::setInactive( const TQColorGroup &g )
+{
+ detach();
+ data->ser_no = palette_count++;
+ data->inactive = g;
+}
+
+
+/*!
+ \fn bool TQPalette::operator!=( const TQPalette &p ) const
+
+ Returns TRUE (slowly) if this palette is different from \a p;
+ otherwise returns FALSE (usually quickly).
+*/
+
+/*!
+ Returns TRUE (usually quickly) if this palette is equal to \a p;
+ otherwise returns FALSE (slowly).
+*/
+
+bool TQPalette::operator==( const TQPalette &p ) const
+{
+ return data->active == p.data->active &&
+ data->disabled == p.data->disabled &&
+ data->inactive == p.data->inactive;
+}
+
+
+/*!
+ \fn int TQPalette::serialNumber() const
+
+ Returns a number that uniquely identifies this TQPalette object.
+ The serial number is intended for caching. Its value may not be
+ used for anything other than equality testing.
+
+ Note that TQPalette uses copy-on-write, and the serial number
+ changes during the lazy copy operation (detach()), not during a
+ shallow copy (copy constructor or assignment).
+
+ \sa TQPixmap TQPixmapCache TQCache
+*/
+
+
+/*****************************************************************************
+ TQColorGroup/TQPalette stream functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQColorGroup
+
+ Writes color group, \a g to the stream \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQColorGroup &g )
+{
+ if ( s.version() == 1 ) {
+ // TQt 1.x
+ s << g.foreground()
+ << g.background()
+ << g.light()
+ << g.dark()
+ << g.mid()
+ << g.text()
+ << g.base();
+ } else {
+ int max = TQColorGroup::NColorRoles;
+ if ( s.version() <= 3) // TQt 2.x
+ max = 14;
+
+ for( int r = 0 ; r < max ; r++ )
+ s << g.brush( (TQColorGroup::ColorRole)r);
+ }
+ return s;
+}
+
+/*!
+ \related TQColorGroup
+
+ Reads a color group from the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQColorGroup &g )
+{
+ if ( s.version() == 1 ) {
+ // TQt 1.x
+ TQColor fg, bg, light, dark, mid, text, base;
+ s >> fg >> bg >> light >> dark >> mid >> text >> base;
+ TQPalette p( bg );
+ TQColorGroup n( p.active() );
+ n.setColor( TQColorGroup::Foreground, fg );
+ n.setColor( TQColorGroup::Light, light );
+ n.setColor( TQColorGroup::Dark, dark );
+ n.setColor( TQColorGroup::Mid, mid );
+ n.setColor( TQColorGroup::Text, text );
+ n.setColor( TQColorGroup::Base, base );
+ g = n;
+ } else {
+ int max = TQColorGroup::NColorRoles;
+ if (s.version() <= 3) // TQt 2.x
+ max = 14;
+
+ TQBrush tmp;
+ for( int r = 0 ; r < max; r++ ) {
+ s >> tmp;
+ g.setBrush( (TQColorGroup::ColorRole)r, tmp);
+ }
+ }
+ return s;
+}
+
+
+/*!
+ \relates TQPalette
+
+ Writes the palette, \a p to the stream \a s and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQPalette &p )
+{
+ return s << p.active()
+ << p.disabled()
+ << p.inactive();
+}
+
+
+static void readV1ColorGroup( TQDataStream &s, TQColorGroup &g,
+ TQPalette::ColorGroup r )
+{
+ TQColor fg, bg, light, dark, mid, text, base;
+ s >> fg >> bg >> light >> dark >> mid >> text >> base;
+ TQPalette p( bg );
+ TQColorGroup n;
+ switch ( r ) {
+ case TQPalette::Disabled:
+ n = p.disabled();
+ break;
+ case TQPalette::Inactive:
+ n = p.inactive();
+ break;
+ default:
+ n = p.active();
+ break;
+ }
+ n.setColor( TQColorGroup::Foreground, fg );
+ n.setColor( TQColorGroup::Light, light );
+ n.setColor( TQColorGroup::Dark, dark );
+ n.setColor( TQColorGroup::Mid, mid );
+ n.setColor( TQColorGroup::Text, text );
+ n.setColor( TQColorGroup::Base, base );
+ g = n;
+}
+
+
+/*!
+ \relates TQPalette
+
+ Reads a palette from the stream, \a s into the palette \a p, and
+ returns a reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQPalette &p )
+{
+ TQColorGroup active, disabled, inactive;
+ if ( s.version() == 1 ) {
+ readV1ColorGroup( s, active, TQPalette::Active );
+ readV1ColorGroup( s, disabled, TQPalette::Disabled );
+ readV1ColorGroup( s, inactive, TQPalette::Inactive );
+ } else {
+ s >> active >> disabled >> inactive;
+ }
+ TQPalette newpal( active, disabled, inactive );
+ p = newpal;
+ return s;
+}
+#endif //TQT_NO_DATASTREAM
+
+/*!
+ Returns TRUE if this palette and \a p are copies of each other,
+ i.e. one of them was created as a copy of the other and neither
+ was subsequently modified; otherwise returns FALSE. This is much
+ stricter than equality.
+
+ \sa operator=() operator==()
+*/
+
+bool TQPalette::isCopyOf( const TQPalette & p )
+{
+ return data && data == p.data;
+}
+
+const TQBrush &TQPalette::directBrush( ColorGroup gr, TQColorGroup::ColorRole r ) const
+{
+ if ( (uint)gr > (uint)TQPalette::NColorGroups ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPalette::directBrush: tqcolorGroup(%i) out of range", gr );
+#endif
+ return data->active.br[TQColorGroup::Foreground];
+ }
+ if ( (uint)r >= (uint)TQColorGroup::NColorRoles ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPalette::directBrush: colorRole(%i) out of range", r );
+#endif
+ return data->active.br[TQColorGroup::Foreground];
+ }
+ switch( gr ) {
+ case Active:
+ return data->active.br[r];
+ //break;
+ case Disabled:
+ return data->disabled.br[r];
+ //break;
+ case Inactive:
+ return data->inactive.br[r];
+ //break;
+ default:
+ break;
+ }
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPalette::directBrush: tqcolorGroup(%i) internal error", gr );
+#endif
+ return data->active.br[TQColorGroup::Foreground]; // Satisfy compiler
+}
+
+void TQPalette::directSetBrush( ColorGroup gr, TQColorGroup::ColorRole r, const TQBrush& b)
+{
+ if ( (uint)gr > (uint)TQPalette::NColorGroups ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPalette::directBrush: tqcolorGroup(%i) out of range", gr );
+#endif
+ return;
+ }
+ if ( (uint)r >= (uint)TQColorGroup::NColorRoles ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPalette::directBrush: colorRole(%i) out of range", r );
+#endif
+ return;
+ }
+ switch( gr ) {
+ case Active:
+ data->active.setBrush(r,b);
+ break;
+ case Disabled:
+ data->disabled.setBrush(r,b);
+ break;
+ case Inactive:
+ data->inactive.setBrush(r,b);
+ break;
+ default:
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPalette::directBrush: tqcolorGroup(%i) internal error", gr );
+#endif
+ break;
+ }
+}
+
+
+/*!\internal*/
+TQColorGroup::ColorRole TQPalette::foregroundRoleFromMode( TQt::BackgroundMode mode )
+{
+ switch (mode) {
+ case TQt::PaletteButton:
+ return TQColorGroup::ButtonText;
+ case TQt::PaletteBase:
+ return TQColorGroup::Text;
+ case TQt::PaletteDark:
+ case TQt::PaletteShadow:
+ return TQColorGroup::Light;
+ case TQt::PaletteHighlight:
+ return TQColorGroup::HighlightedText;
+ case TQt::PaletteBackground:
+ default:
+ return TQColorGroup::Foreground;
+ }
+}
+
+/*!\internal*/
+TQColorGroup::ColorRole TQPalette::backgroundRoleFromMode( TQt::BackgroundMode mode)
+{
+ switch (mode) {
+ case TQt::PaletteForeground:
+ return TQColorGroup::Foreground;
+ case TQt::PaletteButton:
+ return TQColorGroup::Button;
+ case TQt::PaletteLight:
+ return TQColorGroup::Light;
+ case TQt::PaletteMidlight:
+ return TQColorGroup::Midlight;
+ case TQt::PaletteDark:
+ return TQColorGroup::Dark;
+ case TQt::PaletteMid:
+ return TQColorGroup::Mid;
+ case TQt::PaletteText:
+ return TQColorGroup::Text;
+ case TQt::PaletteBrightText:
+ return TQColorGroup::BrightText;
+ case TQt::PaletteButtonText:
+ return TQColorGroup::ButtonText;
+ case TQt::PaletteBase:
+ return TQColorGroup::Base;
+ case TQt::PaletteShadow:
+ return TQColorGroup::Shadow;
+ case TQt::PaletteHighlight:
+ return TQColorGroup::Highlight;
+ case TQt::PaletteHighlightedText:
+ return TQColorGroup::HighlightedText;
+ case TQt::PaletteLink:
+ return TQColorGroup::Link;
+ case TQt::PaletteLinkVisited:
+ return TQColorGroup::LinkVisited;
+ case TQt::PaletteBackground:
+ default:
+ return TQColorGroup::Background;
+ }
+}
+
+#endif // USE_QT4
+
+#endif // TQT_NO_PALETTE \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpalette.h b/tqtinterface/qt4/src/kernel/tqpalette.h
new file mode 100644
index 0000000..19bf08a
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpalette.h
@@ -0,0 +1,295 @@
+/****************************************************************************
+**
+** Definition of TQColorGroup and TQPalette classes
+**
+** Created : 950323
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPALETTE_H
+#define TQPALETTE_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqcolor.h"
+#include "tqshared.h"
+#include "tqbrush.h" // TQColor->TQBrush conversion
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qpalette.h>
+
+#endif // USE_QT4
+
+#ifndef TQT_NO_PALETTE
+
+#ifdef USE_QT4
+
+class Q_GUI_EXPORT TQPalette : public QPalette, virtual public TQt
+{
+public:
+ TQPalette() : QPalette() {}
+ TQPalette( const QColor &button ) : QPalette( button ) {}
+ TQPalette( const QColor &button, const QColor &background ) : QPalette( button, background ) {}
+ TQPalette( const TQColorGroup &active, const TQColorGroup &disabled, const TQColorGroup &inactive );
+ TQPalette( const QPalette &pa ) : QPalette( pa ) {}
+ TQPalette(const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window) : QPalette( windowText, button, light, dark, mid, text, bright_text, base, window ) {}
+ TQPalette(const QColor &windowText, const QColor &window, const QColor &light, const QColor &dark, const QColor &mid, const QColor &text, const QColor &base) : QPalette( windowText, window, light, dark, mid, text, base ) {}
+
+ TQColorGroup normal() const;
+ inline void setNormal(const TQColorGroup &cg) { tqsetColorGroup(Active, cg); }
+
+ TQColorGroup active() const;
+ TQColorGroup disabled() const;
+ TQColorGroup inactive() const;
+// inline void setActive(const TQColorGroup &cg) { tqsetColorGroup(Active, cg); }
+// inline void setDisabled(const TQColorGroup &cg) { tqsetColorGroup(Disabled, cg); }
+// inline void setInactive(const TQColorGroup &cg) { tqsetColorGroup(Inactive, cg); }
+
+ static ColorRole foregroundRoleFromMode( TQt::BackgroundMode mode );
+ static ColorRole backgroundRoleFromMode( TQt::BackgroundMode mode );
+
+// inline QPalette copy() const { QPalette p = *this; p.detach(); return p; }
+
+ inline void setActive(const TQColorGroup &cg) { tqsetColorGroup(Active, cg); }
+ inline void setDisabled(const TQColorGroup &cg) { tqsetColorGroup(Disabled, cg); }
+ inline void setInactive(const TQColorGroup &cg) { tqsetColorGroup(Inactive, cg); }
+
+private:
+ friend class TQColorGroup;
+ void tqsetColorGroup(ColorGroup, const TQColorGroup &);
+ TQColorGroup createColorGroup(ColorGroup) const;
+
+public:
+ // Interoperability
+ static const TQPalette& convertFromQPaletteh( QPalette& qp );
+};
+
+// Interoperability
+inline static const TQPalette& convertFromQPalette( const QPalette& qp ) {
+ return (*static_cast<const TQPalette*>(&qp));
+}
+
+class Q_GUI_EXPORT TQColorGroup : public TQPalette
+{
+public:
+ inline TQColorGroup() : TQPalette() {}
+ inline TQColorGroup(const QBrush &foreground, const QBrush &button, const QBrush &light,
+ const QBrush &dark, const QBrush &mid, const QBrush &text,
+ const QBrush &bright_text, const QBrush &base, const QBrush &background)
+ : TQPalette(foreground, button, light, dark, mid, text, bright_text, base, background)
+ {}
+ inline TQColorGroup(const QColor &foreground, const QColor &background, const QColor &light,
+ const QColor &dark, const QColor &mid, const QColor &text, const QColor &base)
+ : TQPalette(foreground, background, light, dark, mid, text, base) {}
+ inline TQColorGroup(const TQColorGroup &cg) : TQPalette(cg) {}
+ inline TQColorGroup(const QPalette &pal) : TQPalette(pal) {}
+ bool operator==(const TQColorGroup &other) const;
+ inline bool operator!=(const TQColorGroup &other) const { return !(operator==(other)); }
+// operator QVariant() const;
+
+ inline const TQColor &foreground() const { return TQT_TQCOLOR_OBJECT(color(WindowText)); }
+ inline const TQColor &button() const { return TQT_TQCOLOR_OBJECT(color(Button)); }
+ inline const TQColor &light() const { return TQT_TQCOLOR_OBJECT(color(Light)); }
+ inline const TQColor &dark() const { return TQT_TQCOLOR_OBJECT(color(Dark)); }
+ inline const TQColor &mid() const { return TQT_TQCOLOR_OBJECT(color(Mid)); }
+ inline const TQColor &text() const { return TQT_TQCOLOR_OBJECT(color(Text)); }
+ inline const TQColor &base() const { return TQT_TQCOLOR_OBJECT(color(Base)); }
+ inline const TQColor &background() const { return TQT_TQCOLOR_OBJECT(color(Window)); }
+ inline const TQColor &midlight() const { return TQT_TQCOLOR_OBJECT(color(Midlight)); }
+ inline const TQColor &brightText() const { return TQT_TQCOLOR_OBJECT(color(BrightText)); }
+ inline const TQColor &buttonText() const { return TQT_TQCOLOR_OBJECT(color(ButtonText)); }
+ inline const TQColor &shadow() const { return TQT_TQCOLOR_OBJECT(color(Shadow)); }
+ inline const TQColor &highlight() const { return TQT_TQCOLOR_OBJECT(color(Highlight)); }
+ inline const TQColor &highlightedText() const { return TQT_TQCOLOR_OBJECT(color(HighlightedText)); }
+ inline const TQColor &link() const { return TQT_TQCOLOR_OBJECT(color(Link)); }
+ inline const TQColor &linkVisited() const { return TQT_TQCOLOR_OBJECT(color(LinkVisited)); }
+
+ inline const TQBrush &tqbrush( ColorRole cr ) const { return TQT_TQBRUSH_OBJECT(TQPalette::brush(cr)); }
+};
+
+// #ifndef QT_NO_DATASTREAM
+// QDataStream &operator<<(QDataStream &ds, const TQColorGroup &cg);
+// QDataStream &operator>>(QDataStream &ds, TQColorGroup &cg);
+// #endif
+
+inline TQColorGroup TQPalette::inactive() const { return createColorGroup(Inactive); }
+inline TQColorGroup TQPalette::disabled() const { return createColorGroup(Disabled); }
+inline TQColorGroup TQPalette::active() const { return createColorGroup(Active); }
+inline TQColorGroup TQPalette::normal() const { return createColorGroup(Active); }
+
+#else // USE_QT4
+
+class TQColorGroupPrivate;
+
+class TQ_EXPORT TQColorGroup
+{
+public:
+ TQColorGroup();
+ TQColorGroup( const TQColor &foreground, const TQColor &button,
+ const TQColor &light, const TQColor &dark, const TQColor &mid,
+ const TQColor &text, const TQColor &base );
+ TQColorGroup( const TQBrush &foreground, const TQBrush &button,
+ const TQBrush &light, const TQBrush &dark, const TQBrush &mid,
+ const TQBrush &text, const TQBrush &bright_text,
+ const TQBrush &base, const TQBrush &background);
+ TQColorGroup( const TQColorGroup & );
+
+ ~TQColorGroup();
+
+ TQColorGroup& operator =(const TQColorGroup&);
+
+ // Do not change the order, the serialization format depends on it
+ enum ColorRole { Foreground, Button, Light, Midlight, Dark, Mid,
+ Text, BrightText, ButtonText, Base, Background, Shadow,
+ Highlight, HighlightedText, Link, LinkVisited,
+ NColorRoles };
+
+ const TQColor &color( ColorRole ) const;
+ const TQBrush &brush( ColorRole ) const;
+ void setColor( ColorRole, const TQColor & );
+ void setBrush( ColorRole, const TQBrush & );
+
+ const TQColor &foreground() const { return br[Foreground].color(); }
+ const TQColor &button() const { return br[Button].color(); }
+ const TQColor &light() const { return br[Light].color(); }
+ const TQColor &dark() const { return br[Dark].color(); }
+ const TQColor &mid() const { return br[Mid].color(); }
+ const TQColor &text() const { return br[Text].color(); }
+ const TQColor &base() const { return br[Base].color(); }
+ const TQColor &background() const { return br[Background].color(); }
+
+ const TQColor &midlight() const { return br[Midlight].color(); }
+ const TQColor &brightText() const { return br[BrightText].color(); }
+ const TQColor &buttonText() const { return br[ButtonText].color(); }
+ const TQColor &shadow() const { return br[Shadow].color(); }
+ const TQColor &highlight() const { return br[Highlight].color(); }
+ const TQColor &highlightedText() const{return br[HighlightedText].color(); }
+ const TQColor &link() const { return br[Link].color(); }
+ const TQColor &linkVisited() const { return br[LinkVisited].color(); }
+
+ bool operator==( const TQColorGroup &g ) const;
+ bool operator!=( const TQColorGroup &g ) const
+ { return !(operator==(g)); }
+
+private:
+ TQBrush *br;
+ TQColorGroupPrivate * d;
+
+ friend class TQPalette;
+};
+
+
+class TQ_EXPORT TQPalette
+{
+public:
+ TQPalette();
+ TQPalette( const TQColor &button );
+ TQPalette( const TQColor &button, const TQColor &background );
+ TQPalette( const TQColorGroup &active, const TQColorGroup &disabled,
+ const TQColorGroup &inactive );
+ TQPalette( const TQPalette & );
+ ~TQPalette();
+ TQPalette &operator=( const TQPalette & );
+
+ enum ColorGroup { Disabled, Active, Inactive, NColorGroups, Normal=Active };
+
+ const TQColor &color( ColorGroup, TQColorGroup::ColorRole ) const;
+ const TQBrush &brush( ColorGroup, TQColorGroup::ColorRole ) const;
+ void setColor( ColorGroup, TQColorGroup::ColorRole, const TQColor & );
+ void setBrush( ColorGroup, TQColorGroup::ColorRole, const TQBrush & );
+
+ void setColor( TQColorGroup::ColorRole, const TQColor & );
+ void setBrush( TQColorGroup::ColorRole, const TQBrush & );
+
+ TQPalette copy() const;
+
+ const TQColorGroup &active() const { return data->active; }
+ const TQColorGroup &disabled() const { return data->disabled; }
+ const TQColorGroup &inactive() const { return data->inactive; }
+#ifndef TQT_NO_COMPAT
+ const TQColorGroup &normal() const { return active(); }
+#endif
+
+ void setActive( const TQColorGroup & );
+ void setDisabled( const TQColorGroup & );
+ void setInactive( const TQColorGroup & );
+#ifndef TQT_NO_COMPAT
+ void setNormal( const TQColorGroup & cg ) { setActive(cg); }
+#endif
+
+ bool operator==( const TQPalette &p ) const;
+ bool operator!=( const TQPalette &p ) const
+ { return !(operator==(p)); }
+ bool isCopyOf( const TQPalette & );
+
+ int serialNumber() const { return data->ser_no; }
+
+
+ static TQColorGroup::ColorRole foregroundRoleFromMode( TQt::BackgroundMode mode );
+ static TQColorGroup::ColorRole backgroundRoleFromMode( TQt::BackgroundMode mode);
+
+private:
+ void detach();
+ const TQBrush &directBrush( ColorGroup, TQColorGroup::ColorRole ) const;
+ void directSetBrush( ColorGroup, TQColorGroup::ColorRole, const TQBrush& );
+
+ struct TQPalData : public TQShared {
+ TQColorGroup disabled;
+ TQColorGroup active;
+ int ser_no;
+ TQColorGroup inactive;
+ } *data;
+};
+
+
+/*****************************************************************************
+ TQColorGroup/TQPalette stream functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQColorGroup & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQColorGroup & );
+
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQPalette & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQPalette & );
+#endif // TQT_NO_DATASTREAM
+
+#endif // TQT_NO_PALETTE
+#endif // USE_QT4
+#endif // TQPALETTE_H
diff --git a/tqtinterface/qt4/src/kernel/tqpen.h b/tqtinterface/qt4/src/kernel/tqpen.h
new file mode 100644
index 0000000..c6d4d75
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpen.h
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Definition of TQPen class
+**
+** Created : 940112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPEN_H
+#define TQPEN_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqcolor.h"
+#include "tqshared.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qpen.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQPen: public QPen, virtual public TQt
+{
+public:
+ TQPen() : QPen() {}
+ TQPen( Qt::PenStyle ps ) : QPen( ps ) {}
+ TQPen( const QColor &color, uint width=0, Qt::PenStyle style=Qt::SolidLine ) : QPen( color, width, style ) {}
+ TQPen( const QColor &color, uint width, TQt::PenStyle style ) : QPen( color, width, (Qt::PenStyle)style ) {}
+ TQPen( const QColor &cl, uint w, Qt::PenStyle s, Qt::PenCapStyle c, Qt::PenJoinStyle j) : QPen( cl, w, s, c, j ) {}
+ TQPen( const QPen &p ) : QPen( p ) {}
+
+ inline void tqsetStyle( TQt::PenStyle tqps ) { setStyle((Qt::PenStyle)tqps); }
+ inline void tqsetCapStyle( TQt::PenCapStyle tqps ) { setCapStyle((Qt::PenCapStyle)tqps); }
+ inline void tqsetJoinStyle( TQt::PenJoinStyle tqps ) { setJoinStyle((Qt::PenJoinStyle)tqps); }
+
+ using QPen::operator=;
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQPen: public TQt
+{
+public:
+ TQPen();
+ TQPen( PenStyle );
+ TQPen( const TQColor &color, uint width=0, PenStyle style=SolidLine );
+ TQPen( const TQColor &cl, uint w, PenStyle s, PenCapStyle c, PenJoinStyle j);
+ TQPen( const TQPen & );
+ ~TQPen();
+ TQPen &operator=( const TQPen & );
+
+ PenStyle style() const { return data->style; }
+ void setStyle( PenStyle );
+ uint width() const { return data->width; }
+ void setWidth( uint );
+ const TQColor &color() const { return data->color; }
+ void setColor( const TQColor & );
+ PenCapStyle capStyle() const;
+ void setCapStyle( PenCapStyle );
+ PenJoinStyle joinStyle() const;
+ void setJoinStyle( PenJoinStyle );
+
+ bool operator==( const TQPen &p ) const;
+ bool operator!=( const TQPen &p ) const
+ { return !(operator==(p)); }
+
+private:
+ friend class TQPainter;
+#ifdef TQ_WS_WIN
+ friend class TQFontEngineWin;
+#endif
+
+ TQPen copy() const;
+ void detach();
+ void init( const TQColor &, uint, uint );
+ struct TQPenData : public TQShared { // pen data
+ PenStyle style;
+ uint width;
+ TQColor color;
+ TQ_UINT16 linest;
+ } *data;
+};
+
+
+/*****************************************************************************
+ TQPen stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQPen & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQPen & );
+#endif
+
+#endif // USE_QT4
+
+#endif // TQPEN_H
diff --git a/tqtinterface/qt4/src/kernel/tqpicture.cpp b/tqtinterface/qt4/src/kernel/tqpicture.cpp
new file mode 100644
index 0000000..c9c5c0e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpicture.cpp
@@ -0,0 +1,1235 @@
+/****************************************************************************
+**
+** Implementation of TQPicture class
+**
+** Created : 940802
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpicture.h"
+
+#ifndef TQT_NO_PICTURE
+
+#include "tqpainter.h"
+#include "tqpixmap.h"
+#include "tqimage.h"
+#include "tqfile.h"
+#include "tqdatastream.h"
+#include "tqpaintdevicemetrics.h"
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+#ifndef TQT_NO_SVG
+#include "private/tqsvgdevice_p.h"
+#endif
+
+/*!
+ \class TQPicture tqpicture.h
+ \brief The TQPicture class is a paint tqdevice that records and
+ replays TQPainter commands.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+
+ A picture serializes painter commands to an IO tqdevice in a
+ platform-independent format. For example, a picture created under
+ Windows can be read on a Sun SPARC.
+
+ Pictures are called meta-files on some platforms.
+
+ TQt pictures use a proprietary binary format. Unlike native picture
+ (meta-file) formats on many window systems, TQt pictures have no
+ limitations regarding their contents. Everything that can be
+ painted can also be stored in a picture, e.g. fonts, pixmaps,
+ regions, transformed graphics, etc.
+
+ TQPicture is an \link shclass.html implicitly shared\endlink class.
+
+ Example of how to record a picture:
+ \code
+ TQPicture pic;
+ TQPainter p;
+ p.begin( &pic ); // paint in picture
+ p.drawEllipse( 10,20, 80,70 ); // draw an ellipse
+ p.end(); // painting done
+ pic.save( "drawing.pic" ); // save picture
+ \endcode
+
+ Example of how to replay a picture:
+ \code
+ TQPicture pic;
+ pic.load( "drawing.pic" ); // load picture
+ TQPainter p;
+ p.begin( &myWidget ); // paint in myWidget
+ p.drawPicture( pic ); // draw the picture
+ p.end(); // painting done
+ \endcode
+
+ Pictures can also be drawn using play(). Some basic data about a
+ picture is available, for example, size(), isNull() and
+ boundingRect().
+
+*/
+
+
+static const char *mfhdr_tag = "TQPIC"; // header tag
+static const TQ_UINT16 mfhdr_maj = 5; // major version #
+static const TQ_UINT16 mfhdr_min = 0; // minor version #
+
+
+/*!
+ Constructs an empty picture.
+
+ The \a formatVersion parameter may be used to \e create a TQPicture
+ that can be read by applications that are compiled with earlier
+ versions of TQt.
+ \list
+ \i \a formatVersion == 1 is binary compatible with TQt 1.x and later.
+ \i \a formatVersion == 2 is binary compatible with TQt 2.0.x and later.
+ \i \a formatVersion == 3 is binary compatible with TQt 2.1.x and later.
+ \i \a formatVersion == 4 is binary compatible with TQt 3.0.x and later.
+ \i \a formatVersion == 5 is binary compatible with TQt 3.1.
+ \endlist
+
+ Note that the default formatVersion is -1 which signifies the
+ current release, i.e. for TQt 3.1 a formatVersion of 5 is the same
+ as the default formatVersion of -1.
+
+ Reading pictures generated by earlier versions of TQt is supported
+ and needs no special coding; the format is automatically detected.
+*/
+
+TQPicture::TQPicture( int formatVersion )
+ : TQPaintDevice( TQInternal::Picture | TQInternal::ExternalDevice )
+ // set tqdevice type
+{
+ d = new TQPicturePrivate;
+
+#if defined(TQT_CHECK_RANGE)
+ if ( formatVersion == 0 )
+ qWarning( "TQPicture: invalid format version 0" );
+#endif
+
+ // still accept the 0 default from before TQt 3.0.
+ if ( formatVersion > 0 && formatVersion != (int)mfhdr_maj ) {
+ d->formatMajor = formatVersion;
+ d->formatMinor = 0;
+ d->formatOk = FALSE;
+ }
+ else {
+ d->resetFormat();
+ }
+}
+
+/*!
+ Constructs a \link shclass.html shallow copy\endlink of \a pic.
+*/
+
+TQPicture::TQPicture( const TQPicture &pic )
+ : TQPaintDevice( TQInternal::Picture | TQInternal::ExternalDevice )
+{
+ d = pic.d;
+ d->ref();
+}
+
+/*!
+ Destroys the picture.
+*/
+TQPicture::~TQPicture()
+{
+ if ( d->deref() )
+ delete d;
+}
+
+
+/*!
+ \fn bool TQPicture::isNull() const
+
+ Returns TRUE if the picture tqcontains no data; otherwise returns
+ FALSE.
+*/
+
+/*!
+ \fn uint TQPicture::size() const
+
+ Returns the size of the picture data.
+
+ \sa data()
+*/
+
+/*!
+ \fn const char* TQPicture::data() const
+
+ Returns a pointer to the picture data. The pointer is only valid
+ until the next non-const function is called on this picture. The
+ returned pointer is 0 if the picture tqcontains no data.
+
+ \sa size(), isNull()
+*/
+
+/*!
+ Sets the picture data directly from \a data and \a size. This
+ function copies the input data.
+
+ \sa data(), size()
+*/
+
+void TQPicture::setData( const char* data, uint size )
+{
+ detach();
+ TQByteArray a( size );
+ memcpy( a.data(), data, size );
+ d->pictb.setBuffer( a ); // set byte array in buffer
+ d->resetFormat(); // we'll have to check
+}
+
+
+/*!
+ Loads a picture from the file specified by \a fileName and returns
+ TRUE if successful; otherwise returns FALSE.
+
+ By default, the file will be interpreted as being in the native
+ TQPicture format. Specifying the \a format string is optional and
+ is only needed for importing picture data stored in a different
+ format.
+
+ Currently, the only external format supported is the \link
+ http://www.w3.org/Graphics/SVG/ W3C SVG \endlink format which
+ requires the \link xml.html TQt XML module \endlink. The
+ corresponding \a format string is "svg".
+
+ \sa save()
+*/
+
+bool TQPicture::load( const TQString &fileName, const char *format )
+{
+ TQFile f( fileName );
+ if ( !f.open(IO_ReadOnly) )
+ return FALSE;
+ return load( &f, format );
+}
+
+/*!
+ \overload
+
+ \a dev is the tqdevice to use for loading.
+*/
+
+bool TQPicture::load( TQIODevice *dev, const char *format )
+{
+#ifndef TQT_NO_SVG
+ if ( qstrcmp( format, "svg" ) == 0 ) {
+ TQSvgDevice svg;
+ if ( !svg.load( dev ) )
+ return FALSE;
+ TQPainter p( this );
+ bool b = svg.play( &p );
+ d->brect = svg.boundingRect();
+ return b;
+ }
+#endif
+ if ( format ) {
+ qWarning( "TQPicture::load: No such picture format: %s", format );
+ return FALSE;
+ }
+
+ detach();
+ TQByteArray a = dev->readAll();
+ d->pictb.setBuffer( a ); // set byte array in buffer
+ return d->checkFormat();
+}
+
+/*!
+ Saves a picture to the file specified by \a fileName and returns
+ TRUE if successful; otherwise returns FALSE.
+
+ Specifying the file \a format string is optional. It's not
+ recommended unless you intend to export the picture data for
+ use by a third party reader. By default the data will be saved in
+ the native TQPicture file format.
+
+ Currently, the only external format supported is the \link
+ http://www.w3.org/Graphics/SVG/ W3C SVG \endlink format which
+ requires the \link xml.html TQt XML module \endlink. The
+ corresponding \a format string is "svg".
+
+ \sa load()
+*/
+
+bool TQPicture::save( const TQString &fileName, const char *format )
+{
+ if ( paintingActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPicture::save: still being painted on. "
+ "Call TQPainter::end() first" );
+#endif
+ return FALSE;
+ }
+
+#ifndef TQT_NO_SVG
+ // identical to TQIODevice* code below but the file name
+ // makes a difference when it comes to saving pixmaps
+ if ( qstricmp( format, "svg" ) == 0 ) {
+ TQSvgDevice svg;
+ TQPainter p( &svg );
+ if ( !play( &p ) )
+ return FALSE;
+ svg.setBoundingRect( boundingRect() );
+ return svg.save( fileName );
+ }
+#endif
+
+ TQFile f( fileName );
+ if ( !f.open(IO_WriteOnly) )
+ return FALSE;
+ return save( &f, format );
+}
+
+/*!
+ \overload
+
+ \a dev is the tqdevice to use for saving.
+*/
+
+bool TQPicture::save( TQIODevice *dev, const char *format )
+{
+ if ( paintingActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPicture::save: still being painted on. "
+ "Call TQPainter::end() first" );
+#endif
+ return FALSE;
+ }
+
+#ifndef TQT_NO_SVG
+ if ( qstricmp( format, "svg" ) == 0 ) {
+ TQSvgDevice svg;
+ TQPainter p( &svg );
+ if ( !play( &p ) )
+ return FALSE;
+ svg.setBoundingRect( boundingRect() );
+ return svg.save( dev );
+ }
+#endif
+ if ( format ) {
+ qWarning( "TQPicture::save: No such picture format: %s", format );
+ return FALSE;
+ }
+
+ dev->writeBlock( d->pictb.buffer().data(), d->pictb.buffer().size() );
+ return TRUE;
+}
+
+/*!
+ Returns the picture's bounding rectangle or an invalid rectangle
+ if the picture tqcontains no data.
+*/
+
+TQRect TQPicture::boundingRect() const
+{
+ if ( !d->formatOk )
+ d->checkFormat();
+ return d->brect;
+}
+
+/*!
+ Sets the picture's bounding rectangle to \a r. The automatically
+ calculated value is overriden.
+*/
+
+void TQPicture::setBoundingRect( const TQRect &r )
+{
+ if ( !d->formatOk )
+ d->checkFormat();
+ d->brect = r;
+}
+
+/*!
+ Replays the picture using \a painter, and returns TRUE if
+ successful; otherwise returns FALSE.
+
+ This function does exactly the same as TQPainter::drawPicture()
+ with (x, y) = (0, 0).
+*/
+
+bool TQPicture::play( TQPainter *painter )
+{
+ if ( d->pictb.size() == 0 ) // nothing recorded
+ return TRUE;
+
+ if ( !d->formatOk && !d->checkFormat() )
+ return FALSE;
+
+ d->pictb.open( IO_ReadOnly ); // open buffer tqdevice
+ TQDataStream s;
+ s.setDevice( &d->pictb ); // attach data stream to buffer
+ s.tqdevice()->at( 10 ); // go directly to the data
+ s.setVersion( d->formatMajor == 4 ? 3 : d->formatMajor );
+
+ TQ_UINT8 c, clen;
+ TQ_UINT32 nrecords;
+ s >> c >> clen;
+ TQ_ASSERT( c == PdcBegin );
+ // bounding rect was introduced in ver 4. Read in checkFormat().
+ if ( d->formatMajor >= 4 ) {
+ TQ_INT32 dummy;
+ s >> dummy >> dummy >> dummy >> dummy;
+ }
+ s >> nrecords;
+ if ( !exec( painter, s, nrecords ) ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPicture::play: Format error" );
+#endif
+ d->pictb.close();
+ return FALSE;
+ }
+ d->pictb.close();
+ return TRUE; // no end-command
+}
+
+
+/*!
+ \internal
+ Iterates over the internal picture data and draws the picture using
+ \a painter.
+*/
+
+bool TQPicture::exec( TQPainter *painter, TQDataStream &s, int nrecords )
+{
+#if defined(TQT_DEBUG)
+ int strm_pos;
+#endif
+ TQ_UINT8 c; // command id
+ TQ_UINT8 tiny_len; // 8-bit length descriptor
+ TQ_INT32 len; // 32-bit length descriptor
+ TQ_INT16 i_16, i1_16, i2_16; // parameters...
+ TQ_INT8 i_8;
+ TQ_UINT32 ul;
+ TQCString str1;
+ TQString str;
+ TQPoint p, p1, p2;
+ TQRect r;
+ TQPointArray a;
+ TQColor color;
+ TQFont font;
+ TQPen pen;
+ TQBrush brush;
+ TQRegion rgn;
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix matrix;
+#endif
+
+ while ( nrecords-- && !s.eof() ) {
+ s >> c; // read cmd
+ s >> tiny_len; // read param length
+ if ( tiny_len == 255 ) // longer than 254 bytes
+ s >> len;
+ else
+ len = tiny_len;
+#if defined(TQT_DEBUG)
+ strm_pos = s.tqdevice()->at();
+#endif
+ switch ( c ) { // exec cmd
+ case PdcNOP:
+ break;
+ case PdcDrawPoint:
+ s >> p;
+ painter->drawPoint( p );
+ break;
+ case PdcMoveTo:
+ s >> p;
+ painter->moveTo( p );
+ break;
+ case PdcLineTo:
+ s >> p;
+ painter->lineTo( p );
+ break;
+ case PdcDrawLine:
+ s >> p1 >> p2;
+ painter->drawLine( p1, p2 );
+ break;
+ case PdcDrawRect:
+ s >> r;
+ painter->drawRect( r );
+ break;
+ case PdcDrawRoundRect:
+ s >> r >> i1_16 >> i2_16;
+ painter->drawRoundRect( r, i1_16, i2_16 );
+ break;
+ case PdcDrawEllipse:
+ s >> r;
+ painter->drawEllipse( r );
+ break;
+ case PdcDrawArc:
+ s >> r >> i1_16 >> i2_16;
+ painter->drawArc( r, i1_16, i2_16 );
+ break;
+ case PdcDrawPie:
+ s >> r >> i1_16 >> i2_16;
+ painter->drawPie( r, i1_16, i2_16 );
+ break;
+ case PdcDrawChord:
+ s >> r >> i1_16 >> i2_16;
+ painter->drawChord( r, i1_16, i2_16 );
+ break;
+ case PdcDrawLineSegments:
+ s >> a;
+ painter->drawLineSegments( a );
+ break;
+ case PdcDrawPolyline:
+ s >> a;
+ painter->drawPolyline( a );
+ break;
+ case PdcDrawPolygon:
+ s >> a >> i_8;
+ painter->drawPolygon( a, i_8 );
+ break;
+ case PdcDrawCubicBezier:
+ s >> a;
+#ifndef TQT_NO_BEZIER
+ painter->drawCubicBezier( a );
+#endif
+ break;
+ case PdcDrawText:
+ s >> p >> str1;
+ painter->drawText( p, str1 );
+ break;
+ case PdcDrawTextFormatted:
+ s >> r >> i_16 >> str1;
+ painter->drawText( r, i_16, str1 );
+ break;
+ case PdcDrawText2:
+ s >> p >> str;
+ painter->drawText( p, str );
+ break;
+ case PdcDrawText2Formatted:
+ s >> r >> i_16 >> str;
+ painter->drawText( r, i_16, str );
+ break;
+ case PdcDrawPixmap: {
+ TQPixmap pixmap;
+ if ( d->formatMajor < 4 ) {
+ s >> p >> pixmap;
+ painter->drawPixmap( p, pixmap );
+ } else {
+ s >> r >> pixmap;
+ painter->drawPixmap( r, pixmap );
+ }
+ }
+ break;
+ case PdcDrawImage: {
+ TQImage image;
+ if ( d->formatMajor < 4 ) {
+ s >> p >> image;
+ painter->drawImage( p, image );
+ } else {
+ s >> r >> image;
+ painter->drawImage( r, image );
+ }
+ }
+ break;
+ case PdcBegin:
+ s >> ul; // number of records
+ if ( !exec( painter, s, ul ) )
+ return FALSE;
+ break;
+ case PdcEnd:
+ if ( nrecords == 0 )
+ return TRUE;
+ break;
+ case PdcSave:
+ painter->save();
+ break;
+ case PdcRestore:
+ painter->restore();
+ break;
+ case PdcSetBkColor:
+ s >> color;
+ painter->setBackgroundColor( color );
+ break;
+ case PdcSetBkMode:
+ s >> i_8;
+ painter->setBackgroundMode( (TQt::BGMode)i_8 );
+ break;
+ case PdcSetROP:
+ s >> i_8;
+ painter->setRasterOp( (TQt::RasterOp)i_8 );
+ break;
+ case PdcSetBrushOrigin:
+ s >> p;
+ painter->setBrushOrigin( p );
+ break;
+ case PdcSetFont:
+ s >> font;
+ painter->setFont( font );
+ break;
+ case PdcSetPen:
+ s >> pen;
+ painter->setPen( pen );
+ break;
+ case PdcSetBrush:
+ s >> brush;
+ painter->setBrush( brush );
+ break;
+ case PdcSetTabStops:
+ s >> i_16;
+ painter->setTabStops( i_16 );
+ break;
+ case PdcSetTabArray:
+ s >> i_16;
+ if ( i_16 == 0 ) {
+ painter->setTabArray( 0 );
+ } else {
+ int *ta = new int[i_16];
+ TQ_CHECK_PTR( ta );
+ for ( int i=0; i<i_16; i++ ) {
+ s >> i1_16;
+ ta[i] = i1_16;
+ }
+ painter->setTabArray( ta );
+ delete [] ta;
+ }
+ break;
+ case PdcSetVXform:
+ s >> i_8;
+#ifndef TQT_NO_TRANSFORMATIONS
+ painter->setViewXForm( i_8 );
+#endif
+ break;
+ case PdcSetWindow:
+ s >> r;
+#ifndef TQT_NO_TRANSFORMATIONS
+ painter->setWindow( r );
+#endif
+ break;
+ case PdcSetViewport:
+ s >> r;
+#ifndef TQT_NO_TRANSFORMATIONS
+ painter->setViewport( r );
+#endif
+ break;
+ case PdcSetWXform:
+ s >> i_8;
+#ifndef TQT_NO_TRANSFORMATIONS
+ painter->setWorldXForm( i_8 );
+#endif
+ break;
+ case PdcSetWMatrix:
+#ifndef TQT_NO_TRANSFORMATIONS // #### fix me!
+ s >> matrix >> i_8;
+ painter->setWorldMatrix( matrix, i_8 );
+#endif
+ break;
+#ifndef TQT_NO_TRANSFORMATIONS
+ case PdcSaveWMatrix:
+ painter->saveWorldMatrix();
+ break;
+ case PdcRestoreWMatrix:
+ painter->restoreWorldMatrix();
+ break;
+#endif
+ case PdcSetClip:
+ s >> i_8;
+ painter->setClipping( i_8 );
+ break;
+ case PdcSetClipRegion:
+ s >> rgn >> i_8;
+ painter->setClipRegion( rgn, (TQPainter::CoordinateMode)i_8 );
+ break;
+ default:
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPicture::play: Invalid command %d", c );
+#endif
+ if ( len ) // skip unknown command
+ s.tqdevice()->at( s.tqdevice()->at()+len );
+ }
+#if defined(TQT_DEBUG)
+ //qDebug( "tqdevice->at(): %i, strm_pos: %i len: %i", s.tqdevice()->at(), strm_pos, len );
+ TQ_ASSERT( TQ_INT32(s.tqdevice()->at() - strm_pos) == len );
+#endif
+ }
+ return FALSE;
+}
+
+
+/*!
+ \internal
+ Records painter commands and stores them in the pictb buffer.
+*/
+
+bool TQPicture::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
+{
+ detach();
+ return d->cmd( c, pt, p );
+}
+
+/*!
+ \internal
+ Implementation of the function forwarded above to the internal data struct.
+*/
+
+bool TQPicture::TQPicturePrivate::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
+{
+ TQDataStream s;
+ s.setDevice( &pictb );
+ // when moving up to 4 the TQDataStream version remained at 3
+ s.setVersion( formatMajor != 4 ? formatMajor : 3 );
+ if ( c == PdcBegin ) { // begin; write header
+ TQByteArray empty( 0 );
+ pictb.setBuffer( empty ); // reset byte array in buffer
+ pictb.open( IO_WriteOnly );
+ s.writeRawBytes( mfhdr_tag, 4 );
+ s << (TQ_UINT16)0 << (TQ_UINT16)formatMajor << (TQ_UINT16)formatMinor;
+ s << (TQ_UINT8)c << (TQ_UINT8)sizeof(TQ_INT32);
+ brect = TQRect();
+ if ( formatMajor >= 4 ) {
+ s << (TQ_INT32)brect.left() << (TQ_INT32)brect.top()
+ << (TQ_INT32)brect.width() << (TQ_INT32)brect.height();
+ }
+ trecs = 0;
+ s << (TQ_UINT32)trecs; // total number of records
+ formatOk = FALSE;
+ return TRUE;
+ } else if ( c == PdcEnd ) { // end; calc checksum and close
+ trecs++;
+ s << (TQ_UINT8)c << (TQ_UINT8)0;
+ TQByteArray buf = pictb.buffer();
+ int cs_start = sizeof(TQ_UINT32); // pos of checksum word
+ int data_start = cs_start + sizeof(TQ_UINT16);
+ int brect_start = data_start + 2*sizeof(TQ_INT16) + 2*sizeof(TQ_UINT8);
+ int pos = pictb.at();
+ pictb.at( brect_start );
+ if ( formatMajor >= 4 ) { // bounding rectangle
+ s << (TQ_INT32)brect.left() << (TQ_INT32)brect.top()
+ << (TQ_INT32)brect.width() << (TQ_INT32)brect.height();
+ }
+ s << (TQ_UINT32)trecs; // write number of records
+ pictb.at( cs_start );
+ TQ_UINT16 cs = (TQ_UINT16)qChecksum( buf.data()+data_start, pos-data_start );
+ s << cs; // write checksum
+ pictb.close();
+ return TRUE;
+ }
+ trecs++;
+ s << (TQ_UINT8)c; // write cmd to stream
+ s << (TQ_UINT8)0; // write dummy length info
+ int pos = (int)pictb.at(); // save position
+ TQRect br; // bounding rect addition
+ bool corr = FALSE; // correction for pen width
+
+ switch ( c ) {
+ case PdcDrawPoint:
+ case PdcMoveTo:
+ case PdcLineTo:
+ case PdcSetBrushOrigin:
+ s << *p[0].point;
+ br = TQRect( *p[0].point, TQSize( 1, 1 ) );
+ corr = TRUE;
+ break;
+ case PdcDrawLine:
+ s << *p[0].point << *p[1].point;
+ br = TQRect( *p[0].point, *p[1].point ).normalize();
+ corr = TRUE;
+ break;
+ case PdcDrawRect:
+ case PdcDrawEllipse:
+ s << *p[0].rect;
+ br = *p[0].rect;
+ corr = TRUE;
+ break;
+ case PdcDrawRoundRect:
+ case PdcDrawArc:
+ case PdcDrawPie:
+ case PdcDrawChord:
+ s << *p[0].rect << (TQ_INT16)p[1].ival << (TQ_INT16)p[2].ival;
+ br = *p[0].rect;
+ corr = TRUE;
+ break;
+ case PdcDrawLineSegments:
+ case PdcDrawPolyline:
+ s << *p[0].ptarr;
+ br = p[0].ptarr->boundingRect();
+ corr = TRUE;
+ break;
+#ifndef TQT_NO_BEZIER
+ case PdcDrawCubicBezier:
+ s << *p[0].ptarr;
+ br = p[0].ptarr->cubicBezier().boundingRect();
+ corr = TRUE;
+ break;
+#endif
+ case PdcDrawPolygon:
+ s << *p[0].ptarr << (TQ_INT8)p[1].ival;
+ br = p[0].ptarr->boundingRect();
+ corr = TRUE;
+ break;
+ case PdcDrawText2:
+ if ( formatMajor == 1 ) {
+ pictb.at( pos - 2 );
+ s << (TQ_UINT8)PdcDrawText << (TQ_UINT8)0;
+ TQCString str1( (*p[1].str).latin1() );
+ s << *p[0].point << str1;
+ }
+ else {
+ s << *p[0].point << *p[1].str;
+ }
+ br = pt->fontMetrics().boundingRect( *p[1].str );
+ br.moveBy( p[0].point->x(), p[0].point->y() );
+ break;
+ case PdcDrawText2Formatted:
+ if ( formatMajor == 1 ) {
+ pictb.at( pos - 2 );
+ s << (TQ_UINT8)PdcDrawTextFormatted << (TQ_UINT8)0;
+ TQCString str1( (*p[2].str).latin1() );
+ s << *p[0].rect << (TQ_INT16)p[1].ival << str1;
+ }
+ else {
+ s << *p[0].rect << (TQ_INT16)p[1].ival << *p[2].str;
+ }
+ br = *p[0].rect;
+ break;
+ case PdcDrawPixmap:
+ if ( formatMajor < 4 ) {
+ s << *p[0].point;
+ s << *p[1].pixmap;
+ br = TQRect( *p[0].point, p[1].pixmap->size() );
+ } else {
+ s << *p[0].rect;
+ s << *p[1].pixmap;
+ br = *p[0].rect;
+ }
+ break;
+ case PdcDrawImage:
+ if ( formatMajor < 4 ) {
+ TQPoint pt( p[0].point->x(), p[0].point->y() );
+ s << pt;
+ s << *p[1].image;
+ br = TQRect( *p[0].point, p[1].image->size() );
+ } else {
+ s << *p[0].rect;
+ s << *p[1].image;
+ br = *p[0].rect;
+ }
+ break;
+ case PdcSave:
+ case PdcRestore:
+ break;
+ case PdcSetBkColor:
+ s << *p[0].color;
+ break;
+ case PdcSetBkMode:
+ case PdcSetROP:
+ s << (TQ_INT8)p[0].ival;
+ break;
+ case PdcSetFont: {
+ TQFont fnt = *p[0].font;
+ if (fnt.pointSize() > 0)
+ // we have to store pixels to get correct replay.
+ // the resolution is 72 dpi, so points == pixels
+ fnt.setPixelSize(TQFontInfo(fnt).pixelSize());
+ s << fnt;
+ }
+ break;
+ case PdcSetPen:
+ s << *p[0].pen;
+ break;
+ case PdcSetBrush:
+ s << *p[0].brush;
+ break;
+ case PdcSetTabStops:
+ s << (TQ_INT16)p[0].ival;
+ break;
+ case PdcSetTabArray:
+ s << (TQ_INT16)p[0].ival;
+ if ( p[0].ival ) {
+ int *ta = p[1].ivec;
+ for ( int i=0; i<p[0].ival; i++ )
+ s << (TQ_INT16)ta[i];
+ }
+ break;
+ case PdcSetUnit:
+ case PdcSetVXform:
+ case PdcSetWXform:
+ case PdcSetClip:
+ s << (TQ_INT8)p[0].ival;
+ break;
+#ifndef TQT_NO_TRANSFORMATIONS
+ case PdcSetWindow:
+ case PdcSetViewport:
+ s << *p[0].rect;
+ break;
+ case PdcSetWMatrix:
+ s << *p[0].matrix << (TQ_INT8)p[1].ival;
+ break;
+#endif
+ case PdcSetClipRegion:
+ s << *p[0].rgn;
+ s << (TQ_INT8)p[1].ival;
+ break;
+#if defined(TQT_CHECK_RANGE)
+ default:
+ qWarning( "TQPicture::cmd: Command %d not recognized", c );
+#endif
+ }
+ int newpos = (int)pictb.at(); // new position
+ int length = newpos - pos;
+ if ( length < 255 ) { // write 8-bit length
+ pictb.at(pos - 1); // position to right index
+ s << (TQ_UINT8)length;
+ } else { // write 32-bit length
+ s << (TQ_UINT32)0; // extend the buffer
+ pictb.at(pos - 1); // position to right index
+ s << (TQ_UINT8)255; // indicate 32-bit length
+ char *p = pictb.buffer().data();
+ memmove( p+pos+4, p+pos, length ); // make room for 4 byte
+ s << (TQ_UINT32)length;
+ newpos += 4;
+ }
+ pictb.at( newpos ); // set to new position
+
+ if ( br.isValid() ) {
+ if ( corr ) { // widen bounding rect
+ int w2 = pt->pen().width() / 2;
+ br.setCoords( br.left() - w2, br.top() - w2,
+ br.right() + w2, br.bottom() + w2 );
+ }
+#ifndef TQT_NO_TRANSFORMATIONS
+ br = pt->tqworldMatrix().map( br );
+#endif
+ if ( pt->hasClipping() ) {
+ TQRect cr = pt->clipRegion().boundingRect();
+ br &= cr;
+ }
+ if ( br.isValid() )
+ brect |= br; // merge with existing rect
+ }
+
+ return TRUE;
+}
+
+
+/*!
+ Internal implementation of the virtual TQPaintDevice::metric()
+ function.
+
+ Use the TQPaintDeviceMetrics class instead.
+
+ A picture has the following hard-coded values: dpi=72,
+ numcolors=16777216 and depth=24.
+
+ \a m is the metric to get.
+*/
+
+int TQPicture::metric( int m ) const
+{
+ int val;
+ switch ( m ) {
+ // ### hard coded dpi and color depth values !
+ case TQPaintDeviceMetrics::PdmWidth:
+ val = d->brect.width();
+ break;
+ case TQPaintDeviceMetrics::PdmHeight:
+ val = d->brect.height();
+ break;
+ case TQPaintDeviceMetrics::PdmWidthMM:
+ val = int(25.4/72.0*d->brect.width());
+ break;
+ case TQPaintDeviceMetrics::PdmHeightMM:
+ val = int(25.4/72.0*d->brect.height());
+ break;
+ case TQPaintDeviceMetrics::PdmDpiX:
+ case TQPaintDeviceMetrics::PdmPhysicalDpiX:
+ val = 72;
+ break;
+ case TQPaintDeviceMetrics::PdmDpiY:
+ case TQPaintDeviceMetrics::PdmPhysicalDpiY:
+ val = 72;
+ break;
+ case TQPaintDeviceMetrics::PdmNumColors:
+ val = 16777216;
+ break;
+ case TQPaintDeviceMetrics::PdmDepth:
+ val = 24;
+ break;
+ default:
+ val = 0;
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPicture::metric: Invalid metric command" );
+#endif
+ }
+ return val;
+}
+
+/*!
+ Detaches from shared picture data and makes sure that this picture
+ is the only one referring to the data.
+
+ If multiple pictures share common data, this picture makes a copy
+ of the data and detaches itself from the sharing mechanism.
+ Nothing is done if there is just a single reference.
+*/
+
+void TQPicture::detach()
+{
+ if ( d->count != 1 )
+ *this = copy();
+}
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the picture.
+*/
+
+TQPicture TQPicture::copy() const
+{
+ TQPicture p;
+ TQByteArray a( size() );
+ memcpy( a.data(), data(), size() );
+ p.d->pictb.setBuffer( a ); // set byte array in buffer
+ if ( d->pictb.isOpen() ) { // copy buffer state
+ p.d->pictb.open( d->pictb.mode() );
+ p.d->pictb.at( d->pictb.at() );
+ }
+ p.d->trecs = d->trecs;
+ p.d->formatOk = d->formatOk;
+ p.d->formatMinor = d->formatMajor;
+ p.d->brect = boundingRect();
+ return p;
+}
+
+/*****************************************************************************
+ TQPainter member functions
+ *****************************************************************************/
+
+/*!
+ Replays the picture \a pic translated by (\a x, \a y).
+
+ This function does exactly the same as TQPicture::play() when
+ called with (\a x, \a y) = (0, 0).
+*/
+
+void TQPainter::drawPicture( int x, int y, const TQPicture &pic )
+{
+ save();
+ translate( x, y );
+ ((TQPicture*)&pic)->play( (TQPainter*)this );
+ restore();
+}
+
+/*!
+ \overload void TQPainter::drawPicture( const TQPoint &p, const TQPicture &pic )
+
+ Draws picture \a pic at point \a p.
+*/
+
+void TQPainter::drawPicture( const TQPoint &p, const TQPicture &pic )
+{
+ drawPicture( p.x(), p.y(), pic );
+}
+
+/*!
+ \obsolete
+
+ Use one of the other TQPainter::drawPicture() functions with a (0, 0)
+ offset instead.
+*/
+
+void TQPainter::drawPicture( const TQPicture &pic )
+{
+ drawPicture( 0, 0, pic );
+}
+
+/*!
+ Assigns a \link shclass.html shallow copy\endlink of \a p to this
+ picture and returns a reference to this picture.
+*/
+
+TQPicture& TQPicture::operator= (const TQPicture& p)
+{
+ p.d->ref(); // avoid 'x = x'
+ if ( d->deref() )
+ delete d;
+ d = p.d;
+ return *this;
+}
+
+
+/*!
+ \internal
+
+ Sets formatOk to FALSE and resets the format version numbers to default
+*/
+
+void TQPicture::TQPicturePrivate::resetFormat()
+{
+ formatOk = FALSE;
+ formatMajor = mfhdr_maj;
+ formatMinor = mfhdr_min;
+}
+
+/*!
+ \internal
+
+ Checks data integrity and format version number. Set formatOk to TRUE
+ on success, to FALSE otherwise. Returns the resulting formatOk value.
+*/
+
+bool TQPicture::TQPicturePrivate::checkFormat()
+{
+ resetFormat();
+
+ // can't check anything in an empty buffer
+ if ( pictb.size() == 0 )
+ return FALSE;
+
+ pictb.open( IO_ReadOnly ); // open buffer tqdevice
+ TQDataStream s;
+ s.setDevice( &pictb ); // attach data stream to buffer
+
+ char mf_id[4]; // picture header tag
+ s.readRawBytes( mf_id, 4 ); // read actual tag
+ if ( memcmp(mf_id, mfhdr_tag, 4) != 0 ) { // wrong header id
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPicture::checkFormat: Incorrect header" );
+#endif
+ pictb.close();
+ return FALSE;
+ }
+
+ int cs_start = sizeof(TQ_UINT32); // pos of checksum word
+ int data_start = cs_start + sizeof(TQ_UINT16);
+ TQ_UINT16 cs,ccs;
+ TQByteArray buf = pictb.buffer(); // pointer to data
+ s >> cs; // read checksum
+ ccs = qChecksum( buf.data() + data_start, buf.size() - data_start );
+ if ( ccs != cs ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPicture::checkFormat: Invalid checksum %x, %x expected",
+ ccs, cs );
+#endif
+ pictb.close();
+ return FALSE;
+ }
+
+ TQ_UINT16 major, minor;
+ s >> major >> minor; // read version number
+ if ( major > mfhdr_maj ) { // new, incompatible version
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPicture::checkFormat: Incompatible version %d.%d",
+ major, minor);
+#endif
+ pictb.close();
+ return FALSE;
+ }
+ s.setVersion( major != 4 ? major : 3 );
+
+ TQ_UINT8 c, clen;
+ s >> c >> clen;
+ if ( c == PdcBegin ) {
+ if ( !( major >= 1 && major <= 3 )) {
+ TQ_INT32 l, t, w, h;
+ s >> l >> t >> w >> h;
+ brect = TQRect( l, t, w, h );
+ }
+ } else {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPicture::checkFormat: Format error" );
+#endif
+ pictb.close();
+ return FALSE;
+ }
+ pictb.close();
+
+ formatOk = TRUE; // picture seems to be ok
+ formatMajor = major;
+ formatMinor = minor;
+ return TRUE;
+}
+
+/*****************************************************************************
+ TQPicture stream functions
+ *****************************************************************************/
+
+/*!
+ \relates TQPicture
+
+ Writes picture \a r to the stream \a s and returns a reference to
+ the stream.
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQPicture &r )
+{
+ TQ_UINT32 size = r.d->pictb.buffer().size();
+ s << size;
+ // null picture ?
+ if ( size == 0 )
+ return s;
+ // just write the whole buffer to the stream
+ return s.writeRawBytes ( r.d->pictb.buffer().data(),
+ r.d->pictb.buffer().size() );
+}
+
+/*!
+ \relates TQPicture
+
+ Reads a picture from the stream \a s into picture \a r and returns
+ a reference to the stream.
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQPicture &r )
+{
+ TQDataStream sr;
+
+ // "init"; this code is similar to the beginning of TQPicture::cmd()
+ sr.setDevice( &r.d->pictb );
+ sr.setVersion( r.d->formatMajor );
+ TQ_UINT32 len;
+ s >> len;
+ TQByteArray data( len );
+ if ( len > 0 )
+ s.readRawBytes( data.data(), len );
+
+ r.d->pictb.setBuffer( data );
+ r.d->resetFormat();
+
+ return s;
+}
+
+#endif // USE_QT4
+
+#endif // TQT_NO_PICTURE
+
diff --git a/tqtinterface/qt4/src/kernel/tqpicture.h b/tqtinterface/qt4/src/kernel/tqpicture.h
new file mode 100644
index 0000000..6dfc9cd
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpicture.h
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Definition of TQPicture class
+**
+** Created : 940729
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPICTURE_H
+#define TQPICTURE_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpaintdevice.h"
+#include "tqbuffer.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_PICTURE
+
+#ifdef USE_QT4
+
+#include <Qt/qpicture.h>
+
+class TQ_EXPORT TQPicture : public QPicture, virtual public TQt
+{
+public:
+ TQPicture( int formatVersion = -1 ) : QPicture( formatVersion ) {}
+ TQPicture( const TQPicture &tqp ) : QPicture( tqp ) {}
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQPicture : public TQPaintDevice // picture class
+{
+public:
+ TQPicture( int formatVersion = -1 );
+ TQPicture( const TQPicture & );
+ ~TQPicture();
+
+ bool isNull() const;
+
+ uint size() const;
+ const char* data() const;
+ virtual void setData( const char* data, uint size );
+
+ bool play( TQPainter * );
+
+ bool load( TQIODevice *dev, const char *format = 0 );
+ bool load( const TQString &fileName, const char *format = 0 );
+ bool save( TQIODevice *dev, const char *format = 0 );
+ bool save( const TQString &fileName, const char *format = 0 );
+
+ TQRect boundingRect() const;
+ void setBoundingRect( const TQRect &r );
+
+ TQPicture& operator= (const TQPicture&);
+
+ friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQPicture & );
+ friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQPicture & );
+
+protected:
+ bool cmd( int, TQPainter *, TQPDevCmdParam * );
+ int metric( int ) const;
+ void detach();
+ TQPicture copy() const;
+
+private:
+ bool exec( TQPainter *, TQDataStream &, int );
+
+ struct TQPicturePrivate : public TQShared {
+ bool cmd( int, TQPainter *, TQPDevCmdParam * );
+ bool checkFormat();
+ void resetFormat();
+
+ TQBuffer pictb;
+ int trecs;
+ bool formatOk;
+ int formatMajor;
+ int formatMinor;
+ TQRect brect;
+ } *d;
+};
+
+
+inline bool TQPicture::isNull() const
+{
+ return d->pictb.buffer().isNull();
+}
+
+inline uint TQPicture::size() const
+{
+ return d->pictb.buffer().size();
+}
+
+inline const char* TQPicture::data() const
+{
+ return d->pictb.buffer().data();
+}
+
+/*****************************************************************************
+ TQPicture stream functions
+ *****************************************************************************/
+
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQPicture & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQPicture & );
+
+#endif // USE_QT4
+
+#endif // TQT_NO_PICTURE
+
+#endif // TQPICTURE_H
diff --git a/tqtinterface/qt4/src/kernel/tqpixmap.cpp b/tqtinterface/qt4/src/kernel/tqpixmap.cpp
new file mode 100644
index 0000000..f47fb38
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpixmap.cpp
@@ -0,0 +1,1882 @@
+/****************************************************************************
+**
+** Implementation of TQPixmap class
+**
+** Created : 950301
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpixmap.h"
+
+#include "tqbitmap.h"
+#include "tqimage.h"
+#include "tqwidget.h"
+#include "tqpainter.h"
+#include "tqdatastream.h"
+#include "tqbuffer.h"
+#include "tqobjectlist.h"
+#include "tqapplication.h"
+#include <private/tqinternal_p.h>
+#include "tqmime.h"
+#include "tqdragobject.h"
+#include "tqfile.h"
+
+#ifdef USE_QT4
+
+#include <Qt/qpaintengine.h>
+#include "tqbitmap.h"
+
+#define VERIFY_TQPIXMAP_OBJECT_FUNCTION(x) \
+if (!dynamic_cast<const TQPixmap*>(static_cast<const QPixmap*>(this))) { \
+ printf("[WARNING] An attempt was made to access the TQPixmap::tqmask method from an object not of type TQPixmap [possibly QPixmap]\n\r\tThis may indicate creation and subsequent [illegal] downcasting of a QPixmap object to a TQPixmap object within your application\n\r\tNo pixmap was returned\n\r"); \
+ return x; \
+}
+
+TQPixmap::TQPixmap() : QPixmap(), tqt_tqbitmap_ptr(0) {
+}
+
+TQPixmap::TQPixmap( const QImage& image ) : QPixmap( QPixmap::fromImage(image) ), tqt_tqbitmap_ptr(0) {
+}
+
+// [FIXME] Set depth correctly (in Qt4 is that even possible/wise?)
+TQPixmap::TQPixmap( int w, int h, int depth, Optimization o ) : QPixmap( w, h ), tqt_tqbitmap_ptr(0) {
+ TQ_UNUSED(o);
+ TQ_UNUSED(depth);
+}
+
+// [FIXME] Set depth correctly (in Qt4 is that even possible/wise?)
+TQPixmap::TQPixmap( const QSize &s, int depth, Optimization o ) : QPixmap( s ), tqt_tqbitmap_ptr(0) {
+ TQ_UNUSED(o);
+ TQ_UNUSED(depth);
+}
+
+#ifndef TQT_NO_IMAGEIO
+TQPixmap::TQPixmap( const QString& fileName, const char *format, TQPixmap::ColorMode mode ) : QPixmap( fileName, format ), tqt_tqbitmap_ptr(0) {
+ TQ_UNUSED(mode);
+}
+
+TQPixmap::TQPixmap( const QString& fileName, const char *format, int conversion_flags ) : QPixmap( fileName, format, (Qt::ImageConversionFlags)conversion_flags), tqt_tqbitmap_ptr(0) {
+}
+
+TQPixmap::TQPixmap( const char *xpm[] ) : QPixmap( xpm ), tqt_tqbitmap_ptr(0) {
+}
+
+TQPixmap::TQPixmap( const QByteArray &data ) : QPixmap( data ), tqt_tqbitmap_ptr(0) {
+}
+#endif
+TQPixmap::TQPixmap( const TQPixmap &p ) : QPixmap( p ), tqt_tqbitmap_ptr(0) {
+}
+
+TQPixmap::TQPixmap( const QPixmap p ) : QPixmap( p ), tqt_tqbitmap_ptr(0) {
+}
+
+TQPixmap::~TQPixmap() {
+ // HACK
+ // Make absolutely sure that this is a TQPixmap object!
+ VERIFY_TQPIXMAP_OBJECT_FUNCTION( )
+// printf("[WARNING] Memory leak likely at TQPixmap destruction [tqt_tqbitmap_ptr was %p]\n\r", (void*)tqt_tqbitmap_ptr); fflush(stdout); // [FIXME] [CRITICAL] [MEMORY LEAK]
+ if (tqt_tqbitmap_ptr) delete tqt_tqbitmap_ptr;
+}
+
+bool TQPixmap::selfMask() const {
+ return false;
+}
+
+bool TQPixmap::convertFromImage(const QImage &img, Qt::ImageConversionFlags flags) {
+ *this = fromImage(img, flags);
+ return true;
+}
+
+bool TQPixmap::convertFromImage(const QImage &img, int flags) {
+ return QPixmap::convertFromImage(img, (Qt::ImageConversionFlag)flags);
+}
+
+void TQPixmap::setOptimization( TQPixmap::Optimization ) {
+}
+
+void TQPixmap::setDefaultOptimization( TQPixmap::Optimization ) {
+}
+
+void TQPixmap::resize(const QSize s) {
+ resize_helper(s);
+}
+
+void TQPixmap::resize(int width, int height) {
+ resize_helper(QSize(width, height));
+}
+
+void *TQPixmap::x11AppVisual( void ) {
+ return x11AppVisual(-1);
+}
+
+void *TQPixmap::x11AppVisual( int screen ) {
+ return QX11Info::appVisual(screen);
+}
+
+int TQPixmap::x11AppCells( void ) {
+ return x11AppCells(-1);
+}
+
+int TQPixmap::x11AppCells( int screen ) {
+ return QX11Info::appCells(screen);
+}
+
+int TQPixmap::x11AppDepth( void ) {
+ return x11AppDepth(-1);
+}
+
+int TQPixmap::x11AppDepth( int screen ) {
+ return QX11Info::appDepth(screen);
+}
+
+Display *TQPixmap::x11AppDisplay( void ) {
+ return QX11Info::display();
+}
+
+int TQPixmap::x11AppScreen( void ) {
+ return QX11Info::appScreen();
+}
+
+bool TQPixmap::x11AppDefaultVisual( void ) {
+ return x11AppDefaultVisual(-1);
+}
+
+bool TQPixmap::x11AppDefaultVisual( int screen ) {
+ return QX11Info::appDefaultVisual(screen);
+}
+
+TQt::HANDLE TQPixmap::x11AppColormap( void ) {
+ return x11AppColormap(-1);
+}
+
+TQt::HANDLE TQPixmap::x11AppColormap( int screen ) {
+ return QX11Info::appColormap(screen);
+}
+
+bool TQPixmap::x11AppDefaultColormap( void ) {
+ return x11AppDefaultColormap(-1);
+}
+
+bool TQPixmap::x11AppDefaultColormap( int screen ) {
+ return QX11Info::appDefaultColormap(screen);
+}
+
+TQt::HANDLE TQPixmap::x11AppRootWindow( void ) {
+ return x11AppRootWindow(-1);
+}
+
+TQt::HANDLE TQPixmap::x11AppRootWindow( int screen ) {
+ return QX11Info::appRootWindow(screen);
+}
+
+const TQBitmap *TQPixmap::tqmask() const {
+ // HACK
+ // Make absolutely sure that this is a TQPixmap object!
+ VERIFY_TQPIXMAP_OBJECT_FUNCTION(0)
+
+ const QBitmap& ptrRef = mask();
+ if (ptrRef.isNull() == true) {
+ return 0;
+ }
+ if (tqt_tqbitmap_ptr) {
+ delete tqt_tqbitmap_ptr;
+ }
+ tqt_tqbitmap_ptr = new TQBitmap(ptrRef);
+ return tqt_tqbitmap_ptr;
+}
+
+void TQPixmap::resize_helper(const QSize s)
+{
+ int w = s.width();
+ int h = s.height();
+
+ if (w < 1 || h < 1) {
+ *this = TQPixmap();
+ return;
+ }
+
+ if (size() == s)
+ return;
+
+ TQPixmap pm(QSize(w, h));
+ if (!isNull()) {
+ // Copy old pixmap
+ if (hasAlphaChannel())
+ pm.fill(Qt::transparent);
+ QPainter p(&pm);
+ p.drawPixmap(0, 0, *this, 0, 0, qMin(width(), w), qMin(height(), h));
+ p.end();
+ }
+
+ // Mask too....
+ if (!mask().isNull()) {
+ TQBitmap m = mask();
+ if (m.size() != QSize(w,h)) {
+ TQBitmap pmr(QSize(w, h));
+ pmr.fill(Qt::color0);
+ QPainter pr(&pmr);
+ pr.setBrush(Qt::color1);
+ pr.drawPixmap(0, 0, m, 0, 0, qMin(m.width(), w), qMin(m.height(), h));
+ pr.end();
+ pm.setMask(pmr);
+ }
+ else {
+ pm.setMask(m);
+ }
+ }
+
+ // [FIXME]
+ // Note that the Xorg pixmap and/or gc (if any) is not created via the above process
+ // Therefore resize is more of a copy operation than a true resize
+ #warning TQPixmap::resize() partially implemented
+
+ *this = pm;
+}
+
+TQImage TQPixmap::convertToImage() const {
+ return TQImage(toImage());
+}
+
+TQPixmap::operator TQImage() const {
+ return TQImage(toImage());
+}
+
+TQPixmap TQPixmap::xForm(const QMatrix &matrix) const {
+ return TQPixmap(transformed(QTransform(matrix)));
+}
+
+void copyBlt(QPixmap *dst, int dx, int dy,
+ const QPixmap *src, int sx, int sy, int sw, int sh)
+{
+ Q_ASSERT_X(dst, "::copyBlt", "Destination pixmap must be non-null");
+ Q_ASSERT_X(src, "::copyBlt", "Source pixmap must be non-null");
+
+ if (src->hasAlphaChannel()) {
+ if (dst->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) {
+ QPainter p(dst);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.drawPixmap(dx, dy, *src, sx, sy, sw, sh);
+ } else {
+ QImage image = dst->toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ QPainter p(&image);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.drawPixmap(dx, dy, *src, sx, sy, sw, sh);
+ p.end();
+ *dst = QPixmap::fromImage(image);
+ }
+ } else {
+ QPainter p(dst);
+ p.drawPixmap(dx, dy, *src, sx, sy, sw, sh);
+ }
+
+}
+
+extern const Q_GUI_EXPORT QX11Info *qt_x11Info(const QPaintDevice *pd); // Defined in tqpaintdevice_x11.cpp
+
+Display *TQPixmap::x11Display() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->display();
+ return QX11Info::display();
+}
+
+int TQPixmap::x11Screen() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->screen();
+ return QX11Info::appScreen();
+}
+
+void *TQPixmap::x11Visual() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->visual();
+ return QX11Info::appVisual();
+}
+
+int TQPixmap::x11Depth() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->depth();
+ return QX11Info::appDepth();
+}
+
+int TQPixmap::x11Cells() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->cells();
+ return QX11Info::appCells();
+}
+
+Qt::HANDLE TQPixmap::x11Colormap() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->colormap();
+ return QX11Info::appColormap();
+}
+
+bool TQPixmap::x11DefaultColormap() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->defaultColormap();
+ return QX11Info::appDefaultColormap();
+}
+
+bool TQPixmap::x11DefaultVisual() const
+{
+ const QX11Info *info = qt_x11Info(this);
+ if (info)
+ return info->defaultVisual();
+ return QX11Info::appDefaultVisual();
+}
+
+void TQPixmap::x11SetAppDpiX(int dpi, int screen)
+{
+ QX11Info::setAppDpiX(dpi, screen);
+}
+
+void TQPixmap::x11SetAppDpiY(int dpi, int screen)
+{
+ QX11Info::setAppDpiY(dpi, screen);
+}
+
+int TQPixmap::x11AppDpiX(int screen)
+{
+ return QX11Info::appDpiX(screen);
+}
+
+int TQPixmap::x11AppDpiY(int screen)
+{
+ return QX11Info::appDpiY(screen);
+}
+
+/*! Convenience function. Gets the data associated with the absolute
+ name \a abs_name from the default mime source factory and decodes it
+ to a pixmap.
+
+ \sa TQMimeSourceFactory, TQImage::fromMimeSource(), TQImageDrag::decode()
+*/
+
+#ifndef TQT_NO_MIME
+TQPixmap TQPixmap::fromMimeSource( const TQString &abs_name )
+{
+ const TQMimeSource *m = TQT_TQMIMESOURCE_CONST(TQMimeSourceFactory::defaultFactory()->data( abs_name ));
+ if ( !m ) {
+ if ( TQFile::exists( abs_name ) )
+ return TQPixmap( abs_name );
+#if defined(TQT_CHECK_STATE)
+ if ( !abs_name.isEmpty() )
+ qWarning( "TQPixmap::fromMimeSource: Cannot find pixmap \"%s\" in the mime source factory",
+ abs_name.latin1() );
+#endif
+ return TQPixmap();
+ }
+ TQPixmap pix;
+ TQImageDrag::decode( m, pix );
+ return pix;
+}
+#endif
+
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+TQBitmap TQPixmap::createHeuristicMask( bool clipTight ) const {
+ return TQBitmap(QPixmap::createHeuristicMask(clipTight));
+}
+#endif
+
+#else // USE_QT4
+
+/*!
+ \class TQPixmap tqpixmap.h
+ \brief The TQPixmap class is an off-screen, pixel-based paint tqdevice.
+
+ \ingroup graphics
+ \ingroup images
+ \ingroup shared
+ \mainclass
+
+ TQPixmap is one of the two classes TQt provides for dealing with
+ images; the other is TQImage. TQPixmap is designed and optimized
+ for drawing; TQImage is designed and optimized for I/O and for
+ direct pixel access/manipulation. There are (slow) functions to
+ convert between TQImage and TQPixmap: convertToImage() and
+ convertFromImage().
+
+ One common use of the TQPixmap class is to enable smooth updating
+ of widgets. Whenever something complex needs to be drawn, you can
+ use a pixmap to obtain flicker-free drawing, like this:
+
+ \list 1
+ \i Create a pixmap with the same size as the widget.
+ \i Fill the pixmap with the widget background color.
+ \i Paint the pixmap.
+ \i bitBlt() the pixmap contents onto the widget.
+ \endlist
+
+ Pixel data in a pixmap is internal and is managed by the
+ underlying window system. Pixels can be accessed only through
+ TQPainter functions, through bitBlt(), and by converting the
+ TQPixmap to a TQImage.
+
+ You can easily display a TQPixmap on the screen using
+ TQLabel::setPixmap(). For example, all the TQButton subclasses
+ support pixmap use.
+
+ The TQPixmap class uses \link shclass.html copy-on-write\endlink,
+ so it is practical to pass TQPixmap objects by value.
+
+ You can retrieve the width(), height(), depth() and size() of a
+ pixmap. The enclosing rectangle is given by rect(). Pixmaps can be
+ filled with fill() and resized with resize(). You can create and
+ set a tqmask with createHeuristicMask() and setMask(). Use
+ selfMask() to see if the pixmap is identical to its tqmask.
+
+ In addition to loading a pixmap from file using load() you can
+ also loadFromData(). You can control optimization with
+ setOptimization() and obtain a transformed version of the pixmap
+ using xForm()
+
+ Note regarding Windows 95 and 98: on Windows 9x the system crashes
+ if you create more than about 1000 pixmaps, independent of the
+ size of the pixmaps or installed RAM. Windows NT-systems (including
+ 2000, XP and following versions) do not have the same limitation,
+ but depending on the graphics equipment the system will fail to
+ allocate pixmap objects at some point (due to system running out of
+ GDI resources).
+
+ TQt tries to work around the resource limitation. If you set the
+ pixmap optimization to \c TQPixmap::MemoryOptim and the width of
+ your pixmap is less than or equal to 128 pixels, TQt stores the
+ pixmap in a way that is very memory-efficient when there are many
+ pixmaps.
+
+ If your application uses dozens or hundreds of pixmaps (for
+ example on tool bar buttons and in popup menus), and you plan to
+ run it on Windows 95 or Windows 98, we recommend using code like
+ this:
+
+ \code
+ TQPixmap::setDefaultOptimization( TQPixmap::MemoryOptim );
+ while ( ... ) {
+ // load tool bar pixmaps etc.
+ TQPixmap *pixmap = new TQPixmap(fileName);
+ }
+ TQPixmap::setDefaultOptimization( TQPixmap::NormalOptim );
+ \endcode
+
+ In general it is recommended to make as much use of TQPixmap's
+ implicit sharing and the TQPixmapCache as possible.
+
+ \sa TQBitmap, TQImage, TQImageIO, \link shclass.html Shared Classes\endlink
+*/
+
+/*!
+ \enum TQPixmap::ColorMode
+
+ This enum type defines the color modes that exist for converting
+ TQImage objects to TQPixmap.
+
+ \value Auto Select \c Color or \c Mono on a case-by-case basis.
+ \value Color Always create colored pixmaps.
+ \value Mono Always create bitmaps.
+*/
+
+/*!
+ \enum TQPixmap::Optimization
+
+ TQPixmap has the choice of optimizing for speed or memory in a few
+ places; the best choice varies from pixmap to pixmap but can
+ generally be derived heuristically. This enum type defines a
+ number of optimization modes that you can set for any pixmap to
+ tweak the speed/memory tradeoffs:
+
+ \value DefaultOptim Whatever TQPixmap::defaultOptimization()
+ returns. A pixmap with this optimization will have whatever
+ the current default optimization is. If the default
+ optimization is changed using setDefaultOptimization(), then
+ this will not effect any pixmaps that have already been
+ created.
+
+ \value NoOptim No optimization (currently the same as \c
+ MemoryOptim).
+
+ \value MemoryOptim Optimize for minimal memory use on Windows
+ 9x and X11 systems.
+
+ \value NormalOptim Optimize for typical usage. Often uses more
+ memory than \c MemoryOptim, and is often faster.
+
+ \value BestOptim Optimize for pixmaps that are drawn very often
+ and where performance is critical. Generally uses more memory
+ than \c NormalOptim and may provide a little more speed.
+
+ We recommend using \c DefaultOptim.
+
+*/
+
+
+TQPixmap::Optimization TQPixmap::defOptim = TQPixmap::NormalOptim;
+
+
+/*!
+ \internal
+ Private constructor which takes the bitmap flag, the optimization.and a screen.
+*/
+
+TQPixmap::TQPixmap( int w, int h, int depth, bool bitmap,
+ Optimization optimization )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( w, h, depth, bitmap, optimization );
+}
+
+
+/*!
+ Constructs a null pixmap.
+
+ \sa isNull()
+*/
+
+TQPixmap::TQPixmap()
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( 0, 0, 0, FALSE, defOptim );
+}
+
+/*!
+ Constructs a pixmap from the TQImage \a image.
+
+ \sa convertFromImage()
+*/
+
+TQPixmap::TQPixmap( const TQImage& image )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( 0, 0, 0, FALSE, defOptim );
+ convertFromImage( image );
+}
+
+/*!
+ Constructs a pixmap with \a w width, \a h height and \a depth bits
+ per pixel. The pixmap is optimized in accordance with the \a
+ optimization value.
+
+ The contents of the pixmap is uninitialized.
+
+ The \a depth can be either 1 (monochrome) or the depth of the
+ current video mode. If \a depth is negative, then the hardware
+ depth of the current video mode will be used.
+
+ If either \a w or \a h is zero, a null pixmap is constructed.
+
+ \sa isNull() TQPixmap::Optimization
+*/
+
+TQPixmap::TQPixmap( int w, int h, int depth, Optimization optimization )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( w, h, depth, FALSE, optimization );
+}
+
+/*!
+ \overload TQPixmap::TQPixmap( const TQSize &size, int depth, Optimization optimization )
+
+ Constructs a pixmap of size \a size, \a depth bits per pixel,
+ optimized in accordance with the \a optimization value.
+*/
+
+TQPixmap::TQPixmap( const TQSize &size, int depth, Optimization optimization )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( size.width(), size.height(), depth, FALSE, optimization );
+}
+
+#ifndef TQT_NO_IMAGEIO
+/*!
+ Constructs a pixmap from the file \a fileName. If the file does
+ not exist or is of an unknown format, the pixmap becomes a null
+ pixmap.
+
+ The \a fileName, \a format and \a conversion_flags parameters are
+ passed on to load(). This means that the data in \a fileName is
+ not compiled into the binary. If \a fileName tqcontains a relative
+ path (e.g. the filename only) the relevant file must be found
+ relative to the runtime working directory.
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a
+ conversion_flags to specify how you'd prefer this to happen.
+
+ \sa TQt::ImageConversionFlags isNull(), load(), loadFromData(), save(), imageFormat()
+*/
+
+TQPixmap::TQPixmap( const TQString& fileName, const char *format,
+ int conversion_flags )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( 0, 0, 0, FALSE, defOptim );
+ load( fileName, format, conversion_flags );
+}
+
+/*!
+ Constructs a pixmap from the file \a fileName. If the file does
+ not exist or is of an unknown format, the pixmap becomes a null
+ pixmap.
+
+ The \a fileName, \a format and \a mode parameters are passed on to
+ load(). This means that the data in \a fileName is not compiled
+ into the binary. If \a fileName tqcontains a relative path (e.g. the
+ filename only) the relevant file must be found relative to the
+ runtime working directory.
+
+ \sa TQPixmap::ColorMode isNull(), load(), loadFromData(), save(), imageFormat()
+*/
+
+TQPixmap::TQPixmap( const TQString& fileName, const char *format, ColorMode mode )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( 0, 0, 0, FALSE, defOptim );
+ load( fileName, format, mode );
+}
+
+/*!
+ Constructs a pixmap from \a xpm, which must be a valid XPM image.
+
+ Errors are silently ignored.
+
+ Note that it's possible to squeeze the XPM variable a little bit
+ by using an unusual declaration:
+
+ \code
+ static const char * const start_xpm[]={
+ "16 15 8 1",
+ "a c #cec6bd",
+ ....
+ \endcode
+
+ The extra \c const makes the entire definition read-only, which is
+ slightly more efficient (for example, when the code is in a shared
+ library) and ROMable when the application is to be stored in ROM.
+
+ In order to use that sort of declaration you must cast the
+ variable back to \c{const char **} when you create the TQPixmap.
+*/
+
+TQPixmap::TQPixmap( const char *xpm[] )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( 0, 0, 0, FALSE, defOptim );
+ TQImage image( xpm );
+ if ( !image.isNull() )
+ convertFromImage( image );
+}
+
+/*!
+ Constructs a pixmaps by loading from \a img_data. The data can be
+ in any image format supported by TQt.
+
+ \sa loadFromData()
+*/
+
+TQPixmap::TQPixmap( const TQByteArray & img_data )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ init( 0, 0, 0, FALSE, defOptim );
+ loadFromData( img_data );
+}
+#endif //TQT_NO_IMAGEIO
+
+/*!
+ Constructs a pixmap that is a copy of \a pixmap.
+*/
+
+TQPixmap::TQPixmap( const TQPixmap &pixmap )
+ : TQPaintDevice( TQInternal::Pixmap )
+{
+ if ( pixmap.paintingActive() ) { // make a deep copy
+ data = 0;
+ operator=( pixmap.copy() );
+ } else {
+ data = pixmap.data;
+ data->ref();
+ devFlags = pixmap.devFlags; // copy TQPaintDevice flags
+#if defined(TQ_WS_WIN)
+ hdc = pixmap.hdc; // copy Windows tqdevice context
+#elif defined(TQ_WS_X11)
+ hd = pixmap.hd; // copy X11 drawable
+ rendhd = pixmap.rendhd;
+ copyX11Data( &pixmap ); // copy x11Data
+#elif defined(TQ_WS_MAC)
+ hd = pixmap.hd;
+#endif
+ }
+}
+
+
+/*!
+ Destroys the pixmap.
+*/
+
+TQPixmap::~TQPixmap()
+{
+ deref();
+}
+
+/*! Convenience function. Gets the data associated with the absolute
+ name \a abs_name from the default mime source factory and decodes it
+ to a pixmap.
+
+ \sa TQMimeSourceFactory, TQImage::fromMimeSource(), TQImageDrag::decode()
+*/
+
+#ifndef TQT_NO_MIME
+TQPixmap TQPixmap::fromMimeSource( const TQString &abs_name )
+{
+ const TQMimeSource *m = TQMimeSourceFactory::defaultFactory()->data( abs_name );
+ if ( !m ) {
+ if ( TQFile::exists( abs_name ) )
+ return TQPixmap( abs_name );
+#if defined(TQT_CHECK_STATE)
+ if ( !abs_name.isEmpty() )
+ qWarning( "TQPixmap::fromMimeSource: Cannot find pixmap \"%s\" in the mime source factory",
+ abs_name.latin1() );
+#endif
+ return TQPixmap();
+ }
+ TQPixmap pix;
+ TQImageDrag::decode( m, pix );
+ return pix;
+}
+#endif
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the pixmap using
+ the bitBlt() function to copy the pixels.
+
+ \sa operator=()
+*/
+
+TQPixmap TQPixmap::copy( bool ignoreMask ) const
+{
+#if defined(TQ_WS_X11)
+ int old = x11SetDefaultScreen( x11Screen() );
+#endif // TQ_WS_X11
+
+ TQPixmap pm( data->w, data->h, data->d, data->bitmap, data->optim );
+
+ if ( !pm.isNull() ) { // copy the bitmap
+#if defined(TQ_WS_X11)
+ pm.cloneX11Data( this );
+#endif // TQ_WS_X11
+
+ if ( ignoreMask )
+ bitBlt( &pm, 0, 0, this, 0, 0, data->w, data->h, TQt::CopyROP, TRUE );
+ else
+ copyBlt( &pm, 0, 0, this, 0, 0, data->w, data->h );
+ }
+
+#if defined(TQ_WS_X11)
+ x11SetDefaultScreen( old );
+#endif // TQ_WS_X11
+
+ return pm;
+}
+
+
+/*!
+ Assigns the pixmap \a pixmap to this pixmap and returns a
+ reference to this pixmap.
+*/
+
+TQPixmap &TQPixmap::operator=( const TQPixmap &pixmap )
+{
+ if ( paintingActive() ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning("TQPixmap::operator=: Cannot assign to pixmap during painting");
+#endif
+ return *this;
+ }
+ pixmap.data->ref(); // avoid 'x = x'
+ deref();
+ if ( pixmap.paintingActive() ) { // make a deep copy
+ init( pixmap.width(), pixmap.height(), pixmap.depth(),
+ pixmap.data->bitmap, pixmap.data->optim );
+ data->uninit = FALSE;
+ if ( !isNull() )
+ copyBlt( this, 0, 0, &pixmap, 0, 0, pixmap.width(), pixmap.height() );
+ pixmap.data->deref();
+ } else {
+ data = pixmap.data;
+ devFlags = pixmap.devFlags; // copy TQPaintDevice flags
+#if defined(TQ_WS_WIN)
+ hdc = pixmap.hdc;
+#elif defined(TQ_WS_X11)
+ hd = pixmap.hd; // copy TQPaintDevice drawable
+ rendhd = pixmap.rendhd;
+ copyX11Data( &pixmap ); // copy x11Data
+#elif defined(TQ_WS_MACX) || defined(TQ_OS_MAC9)
+ hd = pixmap.hd;
+#endif
+ }
+ return *this;
+}
+
+
+/*!
+ \overload
+
+ Converts the image \a image to a pixmap that is assigned to this
+ pixmap. Returns a reference to the pixmap.
+
+ \sa convertFromImage().
+*/
+
+TQPixmap &TQPixmap::operator=( const TQImage &image )
+{
+ convertFromImage( image );
+ return *this;
+}
+
+
+/*!
+ \fn bool TQPixmap::isTQBitmap() const
+
+ Returns TRUE if this is a TQBitmap; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQPixmap::isNull() const
+
+ Returns TRUE if this is a null pixmap; otherwise returns FALSE.
+
+ A null pixmap has zero width, zero height and no contents. You
+ cannot draw in a null pixmap or bitBlt() anything to it.
+
+ Resizing an existing pixmap to (0, 0) makes a pixmap into a null
+ pixmap.
+
+ \sa resize()
+*/
+
+/*!
+ \fn int TQPixmap::width() const
+
+ Returns the width of the pixmap.
+
+ \sa height(), size(), rect()
+*/
+
+/*!
+ \fn int TQPixmap::height() const
+
+ Returns the height of the pixmap.
+
+ \sa width(), size(), rect()
+*/
+
+/*!
+ \fn TQSize TQPixmap::size() const
+
+ Returns the size of the pixmap.
+
+ \sa width(), height(), rect()
+*/
+
+/*!
+ \fn TQRect TQPixmap::rect() const
+
+ Returns the enclosing rectangle (0,0,width(),height()) of the pixmap.
+
+ \sa width(), height(), size()
+*/
+
+/*!
+ \fn int TQPixmap::depth() const
+
+ Returns the depth of the pixmap.
+
+ The pixmap depth is also called bits per pixel (bpp) or bit planes
+ of a pixmap. A null pixmap has depth 0.
+
+ \sa defaultDepth(), isNull(), TQImage::convertDepth()
+*/
+
+
+/*!
+ \overload void TQPixmap::fill( const TQWidget *widget, const TQPoint &ofs )
+
+ Fills the pixmap with the \a widget's background color or pixmap.
+ If the background is empty, nothing is done.
+
+ The \a ofs point is an offset in the widget.
+
+ The point \a ofs is a point in the widget's coordinate system. The
+ pixmap's top-left pixel will be mapped to the point \a ofs in the
+ widget. This is significant if the widget has a background pixmap;
+ otherwise the pixmap will simply be filled with the background
+ color of the widget.
+
+ Example:
+ \code
+ void CuteWidget::paintEvent( TQPaintEvent *e )
+ {
+ TQRect ur = e->rect(); // rectangle to update
+ TQPixmap pix( ur.size() ); // Pixmap for double-buffering
+ pix.fill( this, ur.topLeft() ); // fill with widget background
+
+ TQPainter p( &pix );
+ p.translate( -ur.x(), -ur.y() ); // use widget coordinate system
+ // when drawing on pixmap
+ // ... draw on pixmap ...
+
+ p.end();
+
+ bitBlt( this, ur.topLeft(), &pix );
+ }
+ \endcode
+*/
+
+/*!
+ \overload void TQPixmap::fill( const TQWidget *widget, int xofs, int yofs )
+
+ Fills the pixmap with the \a widget's background color or pixmap.
+ If the background is empty, nothing is done. \a xofs, \a yofs is
+ an offset in the widget.
+*/
+
+void TQPixmap::fill( const TQWidget *widget, int xofs, int yofs )
+{
+ const TQPixmap* bgpm = widget->backgroundPixmap();
+ fill( widget->backgroundColor() );
+ if ( bgpm ) {
+ if ( !bgpm->isNull() ) {
+ TQPoint ofs = widget->backgroundOffset();
+ xofs += ofs.x();
+ yofs += ofs.y();
+
+ TQPainter p;
+ p.begin( this );
+ p.setPen( NoPen );
+ p.drawTiledPixmap( 0, 0, width(), height(), *widget->backgroundPixmap(), xofs, yofs );
+ p.end();
+ }
+ }
+}
+
+
+/*!
+ \overload void TQPixmap::resize( const TQSize &size )
+
+ Resizes the pixmap to size \a size.
+*/
+
+/*!
+ Resizes the pixmap to \a w width and \a h height. If either \a w
+ or \a h is 0, the pixmap becomes a null pixmap.
+
+ If both \a w and \a h are greater than 0, a valid pixmap is
+ created. New pixels will be uninitialized (random) if the pixmap
+ is expanded.
+*/
+
+void TQPixmap::resize( int w, int h )
+{
+ if ( w < 1 || h < 1 ) { // becomes null
+ TQPixmap pm( 0, 0, 0, data->bitmap, data->optim );
+ *this = pm;
+ return;
+ }
+ int d;
+ if ( depth() > 0 )
+ d = depth();
+ else
+ d = isTQBitmap() ? 1 : -1;
+ // Create new pixmap
+ TQPixmap pm( w, h, d, data->bitmap, data->optim );
+#ifdef TQ_WS_X11
+ pm.x11SetScreen( x11Screen() );
+#endif // TQ_WS_X11
+ if ( !data->uninit && !isNull() ) // has existing pixmap
+ bitBlt( &pm, 0, 0, this, 0, 0, // copy old pixmap
+ TQMIN(width(), w),
+ TQMIN(height(),h), CopyROP, TRUE );
+#if defined(TQ_WS_MAC)
+ if(data->alphapm) {
+ data->alphapm->resize(w, h);
+ } else
+#elif defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+ if (data->alphapm)
+ qWarning("TQPixmap::resize: TODO: resize alpha data");
+ else
+#endif // TQ_WS_X11
+ if ( data->tqmask ) { // resize tqmask as well
+ if ( data->selfmask ) { // preserve self-tqmask
+ pm.setMask( *((TQBitmap*)&pm) );
+ } else { // independent tqmask
+ TQBitmap m = *data->tqmask;
+ m.resize( w, h );
+ pm.setMask( m );
+ }
+ }
+ *this = pm;
+}
+
+
+/*!
+ \fn const TQBitmap *TQPixmap::tqmask() const
+
+ Returns the tqmask bitmap, or 0 if no tqmask has been set.
+
+ \sa setMask(), TQBitmap, hasAlpha()
+*/
+
+/*!
+ Sets a tqmask bitmap.
+
+ The \a newtqmask bitmap defines the clip tqmask for this pixmap. Every
+ pixel in \a newtqmask corresponds to a pixel in this pixmap. Pixel
+ value 1 means opaque and pixel value 0 means transtqparent. The tqmask
+ must have the same size as this pixmap.
+
+ \warning Setting the tqmask on a pixmap will cause any alpha channel
+ data to be cleared. For example:
+ \code
+ TQPixmap alpha( "image-with-alpha.png" );
+ TQPixmap alphacopy = alpha;
+ alphacopy.setMask( *alphacopy.tqmask() );
+ \endcode
+ Now, alpha and alphacopy are visually different.
+
+ Setting a \link isNull() null\endlink tqmask resets the tqmask.
+
+ \sa tqmask(), createHeuristicMask(), TQBitmap
+*/
+
+void TQPixmap::setMask( const TQBitmap &newtqmask )
+{
+ const TQPixmap *tmp = &newtqmask; // dec cxx bug
+ if ( (data == tmp->data) ||
+ ( newtqmask.handle() && newtqmask.handle() == handle() ) ) {
+ TQPixmap m = tmp->copy( TRUE );
+ setMask( *((TQBitmap*)&m) );
+ data->selfmask = TRUE; // tqmask == pixmap
+ return;
+ }
+
+ if ( newtqmask.isNull() ) { // reset the tqmask
+ if (data->tqmask) {
+ detach();
+ data->selfmask = FALSE;
+
+ delete data->tqmask;
+ data->tqmask = 0;
+ }
+ return;
+ }
+
+ detach();
+ data->selfmask = FALSE;
+
+ if ( newtqmask.width() != width() || newtqmask.height() != height() ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPixmap::setMask: The pixmap and the tqmask must have "
+ "the same size" );
+#endif
+ return;
+ }
+#if defined(TQ_WS_MAC) || (defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE))
+ // when setting the tqmask, we get rid of the alpha channel completely
+ delete data->alphapm;
+ data->alphapm = 0;
+#endif // TQ_WS_X11 && !TQT_NO_XFTFREETYPE
+
+ delete data->tqmask;
+ TQBitmap* newmaskcopy;
+ if ( newtqmask.tqmask() )
+ newmaskcopy = (TQBitmap*)new TQPixmap( tmp->copy( TRUE ) );
+ else
+ newmaskcopy = new TQBitmap( newtqmask );
+#ifdef TQ_WS_X11
+ newmaskcopy->x11SetScreen( x11Screen() );
+#endif
+ data->tqmask = newmaskcopy;
+}
+
+
+/*!
+ \fn bool TQPixmap::selfMask() const
+
+ Returns TRUE if the pixmap's tqmask is identical to the pixmap
+ itself; otherwise returns FALSE.
+
+ \sa tqmask()
+*/
+
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+/*!
+ Creates and returns a heuristic tqmask for this pixmap. It works by
+ selecting a color from one of the corners and then chipping away
+ pixels of that color, starting at all the edges.
+
+ The tqmask may not be perfect but it should be reasonable, so you
+ can do things such as the following:
+ \code
+ pm->setMask( pm->createHeuristicMask() );
+ \endcode
+
+ This function is slow because it involves transformation to a
+ TQImage, non-trivial computations and a transformation back to a
+ TQBitmap.
+
+ If \a clipTight is TRUE the tqmask is just large enough to cover the
+ pixels; otherwise, the tqmask is larger than the data pixels.
+
+ \sa TQImage::createHeuristicMask()
+*/
+
+TQBitmap TQPixmap::createHeuristicMask( bool clipTight ) const
+{
+ TQBitmap m;
+ m.convertFromImage( convertToImage().createHeuristicMask(clipTight) );
+ return m;
+}
+#endif
+#ifndef TQT_NO_IMAGEIO
+/*!
+ Returns a string that specifies the image format of the file \a
+ fileName, or 0 if the file cannot be read or if the format cannot
+ be recognized.
+
+ The TQImageIO documentation lists the supported image formats.
+
+ \sa load(), save()
+*/
+
+const char* TQPixmap::imageFormat( const TQString &fileName )
+{
+ return TQImageIO::imageFormat(fileName);
+}
+
+/*!
+ Loads a pixmap from the file \a fileName at runtime. Returns TRUE
+ if successful; otherwise returns FALSE.
+
+ If \a format is specified, the loader attempts to read the pixmap
+ using the specified format. If \a format is not specified
+ (default), the loader reads a few bytes from the header to guess
+ the file's format.
+
+ See the convertFromImage() documentation for a description of the
+ \a conversion_flags argument.
+
+ The TQImageIO documentation lists the supported image formats and
+ explains how to add extra formats.
+
+ \sa loadFromData(), save(), imageFormat(), TQImage::load(),
+ TQImageIO
+*/
+
+bool TQPixmap::load( const TQString &fileName, const char *format,
+ int conversion_flags )
+{
+ TQImageIO io( fileName, format );
+ bool result = io.read();
+ if ( result ) {
+ detach(); // ###hanord: Why detach here, convertFromImage does it
+ result = convertFromImage( io.image(), conversion_flags );
+ }
+ return result;
+}
+
+/*!
+ \overload
+
+ Loads a pixmap from the file \a fileName at runtime.
+
+ If \a format is specified, the loader attempts to read the pixmap
+ using the specified format. If \a format is not specified
+ (default), the loader reads a few bytes from the header to guess
+ the file's format.
+
+ The \a mode is used to specify the color mode of the pixmap.
+
+ \sa TQPixmap::ColorMode
+*/
+
+bool TQPixmap::load( const TQString &fileName, const char *format,
+ ColorMode mode )
+{
+ int conversion_flags = 0;
+ switch (mode) {
+ case Color:
+ conversion_flags |= ColorOnly;
+ break;
+ case Mono:
+ conversion_flags |= MonoOnly;
+ break;
+ default:
+ break;// Nothing.
+ }
+ return load( fileName, format, conversion_flags );
+}
+#endif //TQT_NO_IMAGEIO
+
+/*!
+ \overload
+
+ Converts \a image and sets this pixmap using color mode \a mode.
+ Returns TRUE if successful; otherwise returns FALSE.
+
+ \sa TQPixmap::ColorMode
+*/
+
+bool TQPixmap::convertFromImage( const TQImage &image, ColorMode mode )
+{
+ if ( image.isNull() ) {
+ // convert null image to null pixmap
+ *this = TQPixmap();
+ return TRUE;
+ }
+
+ int conversion_flags = 0;
+ switch (mode) {
+ case Color:
+ conversion_flags |= ColorOnly;
+ break;
+ case Mono:
+ conversion_flags |= MonoOnly;
+ break;
+ default:
+ break;// Nothing.
+ }
+ return convertFromImage( image, conversion_flags );
+}
+
+#ifndef TQT_NO_IMAGEIO
+/*!
+ Loads a pixmap from the binary data in \a buf (\a len bytes).
+ Returns TRUE if successful; otherwise returns FALSE.
+
+ If \a format is specified, the loader attempts to read the pixmap
+ using the specified format. If \a format is not specified
+ (default), the loader reads a few bytes from the header to guess
+ the file's format.
+
+ See the convertFromImage() documentation for a description of the
+ \a conversion_flags argument.
+
+ The TQImageIO documentation lists the supported image formats and
+ explains how to add extra formats.
+
+ \sa load(), save(), imageFormat(), TQImage::loadFromData(),
+ TQImageIO
+*/
+
+bool TQPixmap::loadFromData( const uchar *buf, uint len, const char *format,
+ int conversion_flags )
+{
+ TQByteArray a;
+ a.setRawData( (char *)buf, len );
+ TQBuffer b( a );
+ b.open( IO_ReadOnly );
+ TQImageIO io( &b, format );
+ bool result = io.read();
+ b.close();
+ a.resetRawData( (char *)buf, len );
+ if ( result ) {
+ detach();
+ result = convertFromImage( io.image(), conversion_flags );
+ }
+ return result;
+}
+
+/*!
+ \overload
+
+ Loads a pixmap from the binary data in \a buf (\a len bytes) using
+ color mode \a mode. Returns TRUE if successful; otherwise returns
+ FALSE.
+
+ If \a format is specified, the loader attempts to read the pixmap
+ using the specified format. If \a format is not specified
+ (default), the loader reads a few bytes from the header to guess
+ the file's format.
+
+ \sa TQPixmap::ColorMode
+*/
+
+bool TQPixmap::loadFromData( const uchar *buf, uint len, const char *format,
+ ColorMode mode )
+{
+ int conversion_flags = 0;
+ switch (mode) {
+ case Color:
+ conversion_flags |= ColorOnly;
+ break;
+ case Mono:
+ conversion_flags |= MonoOnly;
+ break;
+ default:
+ break;// Nothing.
+ }
+ return loadFromData( buf, len, format, conversion_flags );
+}
+
+/*!
+ \overload
+*/
+
+bool TQPixmap::loadFromData( const TQByteArray &buf, const char *format,
+ int conversion_flags )
+{
+ return loadFromData( (const uchar *)(buf.data()), buf.size(),
+ format, conversion_flags );
+}
+
+
+/*!
+ Saves the pixmap to the file \a fileName using the image file
+ format \a format and a quality factor \a quality. \a quality must
+ be in the range [0,100] or -1. Specify 0 to obtain small
+ compressed files, 100 for large uncompressed files, and -1 to use
+ the default settings. Returns TRUE if successful; otherwise
+ returns FALSE.
+
+ \sa load(), loadFromData(), imageFormat(), TQImage::save(),
+ TQImageIO
+*/
+
+bool TQPixmap::save( const TQString &fileName, const char *format, int quality ) const
+{
+ if ( isNull() )
+ return FALSE; // nothing to save
+ TQImageIO io( fileName, format );
+ return doImageIO( &io, quality );
+}
+
+/*!
+ \overload
+
+ This function writes a TQPixmap to the TQIODevice, \a tqdevice. This
+ can be used, for example, to save a pixmap directly into a
+ TQByteArray:
+ \code
+ TQPixmap pixmap;
+ TQByteArray ba;
+ TQBuffer buffer( ba );
+ buffer.open( IO_WriteOnly );
+ pixmap.save( &buffer, "PNG" ); // writes pixmap into ba in PNG format
+ \endcode
+*/
+
+bool TQPixmap::save( TQIODevice* tqdevice, const char* format, int quality ) const
+{
+ if ( isNull() )
+ return FALSE; // nothing to save
+ TQImageIO io( tqdevice, format );
+ return doImageIO( &io, quality );
+}
+
+/*! \internal
+*/
+
+bool TQPixmap::doImageIO( TQImageIO* io, int quality ) const
+{
+ if ( !io )
+ return FALSE;
+ io->setImage( convertToImage() );
+#if defined(TQT_CHECK_RANGE)
+ if ( quality > 100 || quality < -1 )
+ qWarning( "TQPixmap::save: quality out of range [-1,100]" );
+#endif
+ if ( quality >= 0 )
+ io->setQuality( TQMIN(quality,100) );
+ return io->write();
+}
+
+#endif //TQT_NO_IMAGEIO
+
+/*!
+ \fn int TQPixmap::serialNumber() const
+
+ Returns a number that uniquely identifies the contents of this
+ TQPixmap object. This means that multiple TQPixmap objects can have
+ the same serial number as long as they refer to the same contents.
+
+ An example of where this is useful is for caching TQPixmaps.
+
+ \sa TQPixmapCache
+*/
+
+
+/*!
+ Returns the default pixmap optimization setting.
+
+ \sa setDefaultOptimization(), setOptimization(), optimization()
+*/
+
+TQPixmap::Optimization TQPixmap::defaultOptimization()
+{
+ return defOptim;
+}
+
+/*!
+ Sets the default pixmap optimization.
+
+ All \e new pixmaps that are created will use this default
+ optimization. You may also set optimization for individual pixmaps
+ using the setOptimization() function.
+
+ The initial default \a optimization setting is \c TQPixmap::Normal.
+
+ \sa defaultOptimization(), setOptimization(), optimization()
+*/
+
+void TQPixmap::setDefaultOptimization( Optimization optimization )
+{
+ if ( optimization != DefaultOptim )
+ defOptim = optimization;
+}
+
+
+// helper for next function.
+static TQPixmap grabChildWidgets( TQWidget * w )
+{
+ TQPixmap res( w->width(), w->height() );
+ if ( res.isNull() && w->width() )
+ return res;
+ res.fill( w, TQPoint( 0, 0 ) );
+ TQPaintDevice *oldRedirect = TQPainter::redirect( w );
+ TQPainter::redirect( w, &res );
+ bool dblbfr = TQSharedDoubleBuffer::isDisabled();
+ TQSharedDoubleBuffer::setDisabled( TRUE );
+ TQPaintEvent e( w->rect(), FALSE );
+ TQApplication::sendEvent( w, &e );
+ TQSharedDoubleBuffer::setDisabled( dblbfr );
+ TQPainter::redirect( w, oldRedirect );
+
+ if ( !w->childrenListObject().isEmpty() ) {
+ TQPainter p( &res );
+ TQObjectListIt it( w->childrenListObject() );
+ TQObject * child;
+ while( (child=it.current()) != 0 ) {
+ ++it;
+ if ( child->isWidgetType() &&
+ !((TQWidget *)child)->isHidden() &&
+ !((TQWidget *)child)->isTopLevel() &&
+ ((TQWidget *)child)->tqgeometry().intersects( w->rect() ) ) {
+ // those conditions aren't quite right, it's possible
+ // to have a grandchild completely outside its
+ // grandtqparent, but partially inside its tqparent. no
+ // point in optimizing for that.
+
+ // make sure to evaluate pos() first - who knows what
+ // the paint event(s) inside grabChildWidgets() will do.
+ TQPoint childpos = ((TQWidget *)child)->pos();
+ TQPixmap cpm = grabChildWidgets( (TQWidget *)child );
+ if ( cpm.isNull() ) {
+ // Some child pixmap failed - abort and reset
+ res.resize( 0, 0 );
+ break;
+ }
+ p.drawPixmap( childpos, cpm);
+ }
+ }
+ }
+ return res;
+}
+
+
+/*!
+ Creates a pixmap and paints \a widget in it.
+
+ If the \a widget has any tqchildren, then they are also painted in
+ the appropriate positions.
+
+ If you specify \a x, \a y, \a w or \a h, only the rectangle you
+ specify is painted. The defaults are 0, 0 (top-left corner) and
+ -1,-1 (which means the entire widget).
+
+ (If \a w is negative, the function copies everything to the right
+ border of the window. If \a h is negative, the function copies
+ everything to the bottom of the window.)
+
+ If \a widget is 0, or if the rectangle defined by \a x, \a y, the
+ modified \a w and the modified \a h does not overlap the \a
+ {widget}->rect(), this function will return a null TQPixmap.
+
+ This function actually asks \a widget to paint itself (and its
+ tqchildren to paint themselves). TQPixmap::grabWindow() grabs pixels
+ off the screen, which is a bit faster and picks up \e exactly
+ what's on-screen. This function works by calling paintEvent() with
+ painter redirection turned on. If there are overlaying windows,
+ grabWindow() will see them, but not this function.
+
+ If there is overlap, it returns a pixmap of the size you want,
+ containing a rendering of \a widget. If the rectangle you ask for
+ is a superset of \a widget, the areas outside \a widget are
+ covered with the widget's background.
+
+ If an error occurs when trying to grab the widget, such as the
+ size of the widget being too large to fit in memory, an isNull()
+ pixmap is returned.
+
+ \sa grabWindow() TQPainter::redirect() TQWidget::paintEvent()
+*/
+
+TQPixmap TQPixmap::grabWidget( TQWidget * widget, int x, int y, int w, int h )
+{
+ TQPixmap res;
+ if ( !widget )
+ return res;
+
+ if ( w < 0 )
+ w = widget->width() - x;
+ if ( h < 0 )
+ h = widget->height() - y;
+
+ TQRect wr( x, y, w, h );
+ if ( wr == widget->rect() )
+ return grabChildWidgets( widget );
+ if ( !wr.intersects( widget->rect() ) )
+ return res;
+
+ res.resize( w, h );
+ if( res.isNull() )
+ return res;
+ res.fill( widget, TQPoint( w,h ) );
+ TQPixmap tmp( grabChildWidgets( widget ) );
+ if( tmp.isNull() )
+ return tmp;
+ ::bitBlt( &res, 0, 0, &tmp, x, y, w, h );
+ return res;
+}
+
+/*!
+ Returns the actual matrix used for transforming a pixmap with \a w
+ width and \a h height and matrix \a matrix.
+
+ When transforming a pixmap with xForm(), the transformation matrix
+ is internally adjusted to compensate for unwanted translation,
+ i.e. xForm() returns the smallest pixmap containing all
+ transformed points of the original pixmap.
+
+ This function returns the modified matrix, which maps points
+ correctly from the original pixmap into the new pixmap.
+
+ \sa xForm(), TQWMatrix
+*/
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+TQWMatrix TQPixmap::trueMatrix( const TQWMatrix &matrix, int w, int h )
+{
+ const double dt = (double)0.;
+ double x1,y1, x2,y2, x3,y3, x4,y4; // get corners
+ double xx = (double)w;
+ double yy = (double)h;
+
+ TQWMatrix mat( matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), 0., 0. );
+
+ mat.map( dt, dt, &x1, &y1 );
+ mat.map( xx, dt, &x2, &y2 );
+ mat.map( xx, yy, &x3, &y3 );
+ mat.map( dt, yy, &x4, &y4 );
+
+ double ymin = y1; // lowest y value
+ if ( y2 < ymin ) ymin = y2;
+ if ( y3 < ymin ) ymin = y3;
+ if ( y4 < ymin ) ymin = y4;
+ double xmin = x1; // lowest x value
+ if ( x2 < xmin ) xmin = x2;
+ if ( x3 < xmin ) xmin = x3;
+ if ( x4 < xmin ) xmin = x4;
+
+ double ymax = y1; // lowest y value
+ if ( y2 > ymax ) ymax = y2;
+ if ( y3 > ymax ) ymax = y3;
+ if ( y4 > ymax ) ymax = y4;
+ double xmax = x1; // lowest x value
+ if ( x2 > xmax ) xmax = x2;
+ if ( x3 > xmax ) xmax = x3;
+ if ( x4 > xmax ) xmax = x4;
+
+ if ( xmax-xmin > 1.0 )
+ xmin -= xmin/(xmax-xmin);
+ if ( ymax-ymin > 1.0 )
+ ymin -= ymin/(ymax-ymin);
+
+ mat.setMatrix( matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), -xmin, -ymin );
+ return mat;
+}
+#endif // TQT_NO_WMATRIX
+
+
+
+
+
+/*****************************************************************************
+ TQPixmap stream functions
+ *****************************************************************************/
+#if !defined(TQT_NO_DATASTREAM) && !defined(TQT_NO_IMAGEIO)
+/*!
+ \relates TQPixmap
+
+ Writes the pixmap \a pixmap to the stream \a s as a PNG image.
+
+ Note that writing the stream to a file will not produce a valid image file.
+
+ \sa TQPixmap::save()
+ \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQPixmap &pixmap )
+{
+ s << pixmap.convertToImage();
+ return s;
+}
+
+/*!
+ \relates TQPixmap
+
+ Reads a pixmap from the stream \a s into the pixmap \a pixmap.
+
+ \sa TQPixmap::load()
+ \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQPixmap &pixmap )
+{
+ TQImage img;
+ s >> img;
+ pixmap.convertFromImage( img );
+ return s;
+}
+
+#endif //TQT_NO_DATASTREAM
+
+
+
+
+/*****************************************************************************
+ TQPixmap (and TQImage) helper functions
+ *****************************************************************************/
+/*
+ This internal function tqcontains the common (i.e. platform independent) code
+ to do a transformation of pixel data. It is used by TQPixmap::xForm() and by
+ TQImage::xForm().
+
+ \a trueMat is the true transformation matrix (see TQPixmap::trueMatrix()) and
+ \a xoffset is an offset to the matrix.
+
+ \a msbfirst specifies for 1bpp images, if the MSB or LSB comes first and \a
+ depth specifies the colordepth of the data.
+
+ \a dptr is a pointer to the destination data, \a dbpl specifies the bits per
+ line for the destination data, \a p_inc is the offset that we advance for
+ every scanline and \a dHeight is the height of the destination image.
+
+ \a sprt is the pointer to the source data, \a sbpl specifies the bits per
+ line of the source data, \a sWidth and \a sHeight are the width and height of
+ the source data.
+*/
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+#undef IWX_MSB
+#define IWX_MSB(b) if ( trigx < maxws && trigy < maxhs ) { \
+ if ( *(sptr+sbpl*(trigy>>16)+(trigx>>19)) & \
+ (1 << (7-((trigx>>16)&7))) ) \
+ *dptr |= b; \
+ } \
+ trigx += m11; \
+ trigy += m12;
+ // END OF MACRO
+#undef IWX_LSB
+#define IWX_LSB(b) if ( trigx < maxws && trigy < maxhs ) { \
+ if ( *(sptr+sbpl*(trigy>>16)+(trigx>>19)) & \
+ (1 << ((trigx>>16)&7)) ) \
+ *dptr |= b; \
+ } \
+ trigx += m11; \
+ trigy += m12;
+ // END OF MACRO
+#undef IWX_PIX
+#define IWX_PIX(b) if ( trigx < maxws && trigy < maxhs ) { \
+ if ( (*(sptr+sbpl*(trigy>>16)+(trigx>>19)) & \
+ (1 << (7-((trigx>>16)&7)))) == 0 ) \
+ *dptr &= ~b; \
+ } \
+ trigx += m11; \
+ trigy += m12;
+ // END OF MACRO
+bool qt_xForm_helper( const TQWMatrix &trueMat, int xoffset,
+ int type, int depth,
+ uchar *dptr, int dbpl, int p_inc, int dHeight,
+ uchar *sptr, int sbpl, int sWidth, int sHeight
+ )
+{
+ int m11 = int(trueMat.m11()*65536.0 + 1.);
+ int m12 = int(trueMat.m12()*65536.0 + 1.);
+ int m21 = int(trueMat.m21()*65536.0 + 1.);
+ int m22 = int(trueMat.m22()*65536.0 + 1.);
+ int dx = tqRound(trueMat.dx() *65536.0);
+ int dy = tqRound(trueMat.dy() *65536.0);
+
+ int m21ydx = dx + (xoffset<<16);
+ int m22ydy = dy;
+ uint trigx;
+ uint trigy;
+ uint maxws = sWidth<<16;
+ uint maxhs = sHeight<<16;
+
+ for ( int y=0; y<dHeight; y++ ) { // for each target scanline
+ trigx = m21ydx;
+ trigy = m22ydy;
+ uchar *maxp = dptr + dbpl;
+ if ( depth != 1 ) {
+ switch ( depth ) {
+ case 8: // 8 bpp transform
+ while ( dptr < maxp ) {
+ if ( trigx < maxws && trigy < maxhs )
+ *dptr = *(sptr+sbpl*(trigy>>16)+(trigx>>16));
+ trigx += m11;
+ trigy += m12;
+ dptr++;
+ }
+ break;
+
+ case 16: // 16 bpp transform
+ while ( dptr < maxp ) {
+ if ( trigx < maxws && trigy < maxhs )
+ *((ushort*)dptr) = *((ushort *)(sptr+sbpl*(trigy>>16) +
+ ((trigx>>16)<<1)));
+ trigx += m11;
+ trigy += m12;
+ dptr++;
+ dptr++;
+ }
+ break;
+
+ case 24: { // 24 bpp transform
+ uchar *p2;
+ while ( dptr < maxp ) {
+ if ( trigx < maxws && trigy < maxhs ) {
+ p2 = sptr+sbpl*(trigy>>16) + ((trigx>>16)*3);
+ dptr[0] = p2[0];
+ dptr[1] = p2[1];
+ dptr[2] = p2[2];
+ }
+ trigx += m11;
+ trigy += m12;
+ dptr += 3;
+ }
+ }
+ break;
+
+ case 32: // 32 bpp transform
+ while ( dptr < maxp ) {
+ if ( trigx < maxws && trigy < maxhs )
+ *((uint*)dptr) = *((uint *)(sptr+sbpl*(trigy>>16) +
+ ((trigx>>16)<<2)));
+ trigx += m11;
+ trigy += m12;
+ dptr += 4;
+ }
+ break;
+
+ default: {
+ return FALSE;
+ }
+ }
+ } else {
+ switch ( type ) {
+ case TQT_XFORM_TYPE_MSBFIRST:
+ while ( dptr < maxp ) {
+ IWX_MSB(128);
+ IWX_MSB(64);
+ IWX_MSB(32);
+ IWX_MSB(16);
+ IWX_MSB(8);
+ IWX_MSB(4);
+ IWX_MSB(2);
+ IWX_MSB(1);
+ dptr++;
+ }
+ break;
+ case TQT_XFORM_TYPE_LSBFIRST:
+ while ( dptr < maxp ) {
+ IWX_LSB(1);
+ IWX_LSB(2);
+ IWX_LSB(4);
+ IWX_LSB(8);
+ IWX_LSB(16);
+ IWX_LSB(32);
+ IWX_LSB(64);
+ IWX_LSB(128);
+ dptr++;
+ }
+ break;
+# if defined(TQ_WS_WIN)
+ case TQT_XFORM_TYPE_WINDOWSPIXMAP:
+ while ( dptr < maxp ) {
+ IWX_PIX(128);
+ IWX_PIX(64);
+ IWX_PIX(32);
+ IWX_PIX(16);
+ IWX_PIX(8);
+ IWX_PIX(4);
+ IWX_PIX(2);
+ IWX_PIX(1);
+ dptr++;
+ }
+ break;
+# endif
+ }
+ }
+ m21ydx += m21;
+ m22ydy += m22;
+ dptr += p_inc;
+ }
+ return TRUE;
+}
+#undef IWX_MSB
+#undef IWX_LSB
+#undef IWX_PIX
+#endif // TQT_NO_PIXMAP_TRANSFORMATION
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqpixmap.h b/tqtinterface/qt4/src/kernel/tqpixmap.h
new file mode 100644
index 0000000..13a0a2c
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpixmap.h
@@ -0,0 +1,496 @@
+/****************************************************************************
+**
+** Definition of TQPixmap class
+**
+** Created : 940501
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPIXMAP_H
+#define TQPIXMAP_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpaintdevice.h"
+#include "tqcolor.h" // char*->TQColor conversion
+#include "tqstring.h" // char*->TQString conversion
+#include "tqnamespace.h"
+#endif // TQT_H
+
+class TQGfx;
+class TQPixmapPrivate;
+
+#if defined(TQ_WS_WIN)
+// Internal pixmap memory optimization class for Windows 9x
+class TQMultiCellPixmap;
+#endif
+
+#ifdef USE_QT4
+
+#include <Qt/qpixmap.h>
+#include <Qt/qbitmap.h>
+
+class TQBitmap;
+
+// #include "tqimage.h"
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQPixmap : public QPixmap, virtual public TQt
+{
+public:
+ enum ColorMode { Auto, Color, Mono };
+ enum Optimization { DefaultOptim, NoOptim, MemoryOptim=NoOptim, NormalOptim, BestOptim };
+
+ TQPixmap();
+ TQPixmap( const QImage& image );
+ TQPixmap( int w, int h, int depth = -1, Optimization o=DefaultOptim );
+ TQPixmap( const QSize &s, int depth = -1, Optimization o=DefaultOptim );
+#ifndef TQT_NO_IMAGEIO
+ TQPixmap( const QString& fileName, const char *format=0, ColorMode mode=Auto );
+ TQPixmap( const QString& fileName, const char *format, int conversion_flags );
+ TQPixmap( const char *xpm[] );
+ TQPixmap( const QByteArray &data );
+#endif
+ TQPixmap( const TQPixmap &p );
+ TQPixmap( const QPixmap p );
+ virtual ~TQPixmap();
+
+#ifndef TQT_NO_MIME
+ static TQPixmap fromMimeSource( const TQString& abs_name );
+#endif
+
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+ TQBitmap createHeuristicMask( bool clipTight = TRUE ) const;
+#endif
+
+ const TQBitmap *tqmask() const;
+ TQImage convertToImage() const;
+ bool selfMask() const;
+
+// inline QImage convertToImage() const { return toImage(); }
+// bool convertFromImage(const QImage &, ColorMode mode); // Needs some code in the cpp file...
+ bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor);
+ bool convertFromImage(const QImage &img, int flags);
+
+ operator TQImage() const;
+// inline operator TQImage() const { return toImage(); }
+ TQPixmap xForm(const QMatrix &matrix) const;
+
+ // These four functions no longer have any purpose
+// inline Optimization optimization() const {}
+ void setOptimization( Optimization );
+// inline static Optimization defaultOptimization() {}
+ static void setDefaultOptimization( Optimization );
+
+private:
+ void resize_helper(const QSize s);
+public:
+ void resize(const QSize s);
+ void resize(int width, int height);
+
+ // From TQQPaintDevice
+public:
+ static void *x11AppVisual( void );
+ static void *x11AppVisual( int screen );
+ static int x11AppCells( void );
+ static int x11AppCells( int screen );
+ static int x11AppDepth( void );
+ static int x11AppDepth( int screen );
+ static Display *x11AppDisplay( void );
+ static int x11AppScreen( void );
+ static bool x11AppDefaultVisual( void );
+ static bool x11AppDefaultVisual( int screen );
+ static TQt::HANDLE x11AppColormap( void );
+ static TQt::HANDLE x11AppColormap( int screen );
+ static bool x11AppDefaultColormap( void );
+ static bool x11AppDefaultColormap( int screen );
+ static TQt::HANDLE x11AppRootWindow( void );
+ static TQt::HANDLE x11AppRootWindow( int screen );
+
+#if defined(TQ_WS_X11)
+ Display *x11Display() const;
+ int x11Screen() const;
+ int x11Depth() const;
+ int x11Cells() const;
+ Qt::HANDLE x11Colormap() const;
+ bool x11DefaultColormap() const;
+ void *x11Visual() const;
+ bool x11DefaultVisual() const;
+
+ static int x11AppDpiX(int screen = -1);
+ static int x11AppDpiY(int screen = -1);
+ static void x11SetAppDpiX(int, int);
+ static void x11SetAppDpiY(int, int);
+#endif
+
+ // Windows: get tqdevice context
+ // X-Windows: get drawable
+#if defined(TQ_WS_WIN)
+// virtual HDC handle() const;
+#elif defined(TQ_WS_X11)
+ virtual TQt::HANDLE handle() const;
+ virtual TQt::HANDLE x11RenderHandle() const;
+#elif defined(TQ_WS_MAC)
+// virtual TQt::HANDLE handle() const;
+#elif defined(TQ_WS_TQWS)
+// virtual TQt::HANDLE handle() const;
+#endif
+
+private:
+ mutable TQBitmap* tqt_tqbitmap_ptr;
+
+public:
+ // Interoperability
+ static const TQPixmap& convertFromQPixmap( QPixmap& qpm );
+};
+
+// Interoperability
+inline static const TQPixmap& convertFromQPixmap( const QPixmap& qpm ) {
+ return (*static_cast<const TQPixmap*>(&qpm));
+}
+
+void copyBlt(QPixmap *dst, int dx, int dy, const QPixmap *src, int sx=0, int sy=0, int sw=-1, int sh=-1);
+
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+# define TQT_XFORM_TYPE_MSBFIRST 0
+# define TQT_XFORM_TYPE_LSBFIRST 1
+# if defined(TQ_WS_WIN)
+# define TQT_XFORM_TYPE_WINDOWSPIXMAP 2
+# endif
+#endif
+
+#else // USE_QT4
+
+class TQ_EXPORT TQPixmap : public TQPaintDevice, public TQt
+{
+public:
+ enum ColorMode { Auto, Color, Mono };
+ enum Optimization { DefaultOptim, NoOptim, MemoryOptim=NoOptim,
+ NormalOptim, BestOptim };
+
+ TQPixmap();
+ TQPixmap( const TQImage& image );
+ TQPixmap( int w, int h, int depth = -1, Optimization = DefaultOptim );
+ TQPixmap( const TQSize &, int depth = -1, Optimization = DefaultOptim );
+#ifndef TQT_NO_IMAGEIO
+ TQPixmap( const TQString& fileName, const char *format=0,
+ ColorMode mode=Auto );
+ TQPixmap( const TQString& fileName, const char *format,
+ int conversion_flags );
+ TQPixmap( const char *xpm[] ); // ### in 4.0, 'const char * const xpm[]'?
+ TQPixmap( const TQByteArray &data );
+#endif
+ TQPixmap( const TQPixmap & );
+ ~TQPixmap();
+
+ TQPixmap &operator=( const TQPixmap & );
+ TQPixmap &operator=( const TQImage & );
+
+ bool isNull() const;
+
+ int width() const { return data->w; }
+ int height() const { return data->h; }
+ TQSize size() const { return TQSize(data->w,data->h); }
+ TQRect rect() const { return TQRect(0,0,data->w,data->h); }
+ int depth() const { return data->d; }
+ static int defaultDepth();
+
+ void fill( const TQColor &fillColor = TQt::white );
+ void fill( const TQWidget *, int xofs, int yofs );
+ void fill( const TQWidget *, const TQPoint &ofs );
+ void resize( int width, int height );
+ void resize( const TQSize & );
+
+ const TQBitmap *tqmask() const;
+ void setMask( const TQBitmap & );
+ bool selfMask() const;
+ bool hasAlpha() const;
+ bool hasAlphaChannel() const;
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+ TQBitmap createHeuristicMask( bool clipTight = TRUE ) const;
+#endif
+#ifndef TQT_NO_MIME
+ static TQPixmap fromMimeSource( const TQString& abs_name );
+#endif
+ static TQPixmap grabWindow( WId, int x=0, int y=0, int w=-1, int h=-1 );
+ static TQPixmap grabWidget( TQWidget * widget,
+ int x=0, int y=0, int w=-1, int h=-1 );
+
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+ TQPixmap xForm( const TQWMatrix & ) const;
+ static TQWMatrix trueMatrix( const TQWMatrix &, int w, int h );
+#endif
+
+ TQImage convertToImage() const;
+ bool convertFromImage( const TQImage &, ColorMode mode=Auto );
+ bool convertFromImage( const TQImage &, int conversion_flags );
+#ifndef TQT_NO_IMAGEIO
+ static const char* imageFormat( const TQString &fileName );
+ bool load( const TQString& fileName, const char *format=0,
+ ColorMode mode=Auto );
+ bool load( const TQString& fileName, const char *format,
+ int conversion_flags );
+ bool loadFromData( const uchar *buf, uint len,
+ const char* format=0,
+ ColorMode mode=Auto );
+ bool loadFromData( const uchar *buf, uint len,
+ const char* format,
+ int conversion_flags );
+ bool loadFromData( const TQByteArray &data,
+ const char* format=0,
+ int conversion_flags=0 );
+ bool save( const TQString& fileName, const char* format, int quality = -1 ) const;
+ bool save( TQIODevice* tqdevice, const char* format, int quality = -1 ) const;
+#endif
+
+#if defined(TQ_WS_WIN)
+ HBITMAP hbm() const;
+#endif
+
+ int serialNumber() const;
+
+ Optimization optimization() const;
+ void setOptimization( Optimization );
+ static Optimization defaultOptimization();
+ static void setDefaultOptimization( Optimization );
+
+ virtual void detach();
+
+ bool isTQBitmap() const;
+
+#if defined(TQ_WS_WIN)
+ // These functions are internal and used by Windows 9x only
+ bool isMultiCellPixmap() const;
+ HDC multiCellHandle() const;
+ HBITMAP multiCellBitmap() const;
+ int multiCellOffset() const;
+ int allocCell();
+ void freeCell( bool = FALSE );
+#endif
+
+#if defined(TQ_WS_TQWS)
+ virtual TQGfx * graphicsContext(bool clip_tqchildren=TRUE) const;
+ virtual unsigned char * scanLine(int) const;
+ virtual int bytesPerLine() const;
+ TQRgb * clut() const;
+ int numCols() const;
+#elif defined(TQ_WS_X11)
+ static int x11SetDefaultScreen( int screen );
+ void x11SetScreen( int screen );
+#endif
+
+#ifndef TQ_TQDOC
+ TQ_DUMMY_COMPARISON_OPERATOR(TQPixmap)
+#endif
+
+protected:
+ TQPixmap( int w, int h, const uchar *data, bool isXbitmap );
+ int metric( int ) const;
+
+#if defined(TQ_WS_WIN)
+ struct TQMCPI { // mem optim for win9x
+ TQMultiCellPixmap *mcp;
+ int offset;
+ };
+#endif
+
+ struct TQPixmapData : public TQShared { // internal pixmap data
+ TQCOORD w, h;
+ short d;
+ uint uninit : 1;
+ uint bitmap : 1;
+ uint selfmask : 1;
+#if defined(TQ_WS_WIN)
+ uint mcp : 1;
+#endif
+ int ser_no;
+ TQBitmap *tqmask;
+#if defined(TQ_WS_WIN)
+ TQPixmap *maskpm;
+ union {
+ HBITMAP hbm; // if mcp == FALSE
+ TQMCPI *mcpi; // if mcp == TRUE
+ } hbm_or_mcpi;
+ uchar *realAlphaBits;
+#ifdef TQ_OS_TEMP
+ uchar* ppvBits; // Pointer to DIBSection bits
+#endif
+#elif defined(TQ_WS_X11)
+ void *ximage;
+ void *maskgc;
+ TQPixmap *alphapm;
+#elif defined(TQ_WS_MAC)
+ ColorTable *clut;
+ TQPixmap *alphapm;
+#elif defined(TQ_WS_TQWS)
+ int id; // ### should use TQPaintDevice::hd, since it is there
+ TQRgb * clut;
+ int numcols;
+ int rw;
+ int rh;
+ bool hasAlpha;
+#endif
+ Optimization optim;
+#if defined(TQ_WS_WIN)
+ HBITMAP old_hbm;
+#endif
+ } *data;
+private:
+#ifndef TQT_NO_IMAGEIO
+ bool doImageIO( TQImageIO* io, int quality ) const;
+#endif
+ TQPixmap( int w, int h, int depth, bool, Optimization );
+ void init( int, int, int, bool, Optimization );
+ void deref();
+ TQPixmap copy( bool ignoreMask = FALSE ) const;
+#if defined(TQ_WS_WIN)
+ void initAlphaPixmap( uchar *bytes, int length, struct tagBITMAPINFO *bmi );
+ void convertToAlphaPixmap( bool initAlpha=TRUE );
+ static void bitBltAlphaPixmap( TQPixmap *dst, int dx, int dy,
+ const TQPixmap *src, int sx, int sy,
+ int sw, int sh, bool useDstAlpha );
+#endif
+ static Optimization defOptim;
+ friend TQ_EXPORT void bitBlt( TQPaintDevice *, int, int,
+ const TQPaintDevice *,
+ int, int, int, int, RasterOp, bool );
+ friend TQ_EXPORT void bitBlt( TQPaintDevice *, int, int,
+ const TQImage* src,
+ int, int, int, int, int conversion_flags );
+ friend TQ_EXPORT void copyBlt( TQPixmap *dst, int dx, int dy,
+ const TQPixmap *src, int sx, int sy,
+ int sw, int sh );
+
+#if defined(TQ_WS_MAC)
+ friend void unclippedScaledBitBlt(TQPaintDevice *, int, int, int, int,
+ const TQPaintDevice *, int, int, int, int,
+ TQt::RasterOp, bool, bool);
+#endif
+
+ friend class TQBitmap;
+ friend class TQPaintDevice;
+ friend class TQPainter;
+ friend class TQGLWidget;
+};
+
+
+inline bool TQPixmap::isNull() const
+{
+ return data->w == 0;
+}
+
+inline void TQPixmap::fill( const TQWidget *w, const TQPoint &ofs )
+{
+ fill( w, ofs.x(), ofs.y() );
+}
+
+inline void TQPixmap::resize( const TQSize &s )
+{
+ resize( s.width(), s.height() );
+}
+
+inline const TQBitmap *TQPixmap::tqmask() const
+{
+ return data->tqmask;
+}
+
+inline bool TQPixmap::selfMask() const
+{
+ return data->selfmask;
+}
+
+#if defined(TQ_WS_WIN)
+inline HBITMAP TQPixmap::hbm() const
+{
+ return data->mcp ? 0 : data->hbm_or_mcpi.hbm;
+}
+#endif
+
+inline int TQPixmap::serialNumber() const
+{
+ return data->ser_no;
+}
+
+inline TQPixmap::Optimization TQPixmap::optimization() const
+{
+ return data->optim;
+}
+
+inline bool TQPixmap::isTQBitmap() const
+{
+ return data->bitmap;
+}
+
+#if defined(TQ_WS_WIN)
+inline bool TQPixmap::isMultiCellPixmap() const
+{
+ return data->mcp;
+}
+#endif
+
+
+/*****************************************************************************
+ TQPixmap stream functions
+ *****************************************************************************/
+
+#if !defined(TQT_NO_DATASTREAM) && !defined(TQT_NO_IMAGEIO)
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQPixmap & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQPixmap & );
+#endif
+
+/*****************************************************************************
+ TQPixmap (and TQImage) helper functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_PIXMAP_TRANSFORMATION
+# define TQT_XFORM_TYPE_MSBFIRST 0
+# define TQT_XFORM_TYPE_LSBFIRST 1
+# if defined(TQ_WS_WIN)
+# define TQT_XFORM_TYPE_WINDOWSPIXMAP 2
+# endif
+bool qt_xForm_helper( const TQWMatrix&, int, int, int, uchar*, int, int, int, uchar*, int, int, int );
+#endif
+
+TQ_EXPORT void copyBlt( TQPixmap *dst, int dx, int dy,
+ const TQPixmap *src, int sx = 0, int sy = 0,
+ int sw = -1, int sh = -1 );
+
+#endif // USE_QT4
+
+#endif // TQPIXMAP_H
diff --git a/tqtinterface/qt4/src/kernel/tqpixmap_x11.cpp b/tqtinterface/qt4/src/kernel/tqpixmap_x11.cpp
new file mode 100644
index 0000000..974f23c
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpixmap_x11.cpp
@@ -0,0 +1,2155 @@
+/****************************************************************************
+**
+** Implementation of TQPixmap class for X11
+**
+** Created : 940501
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+// NOT REVISED
+
+// Uncomment the next line to enable the MIT Shared Memory extension
+//
+// WARNING: This has some problems:
+//
+// 1. Consumes a 800x600 pixmap
+// 2. TQt does not handle the ShmCompletion message, so you will
+// get strange effects if you xForm() repeatedly.
+//
+// #define TQT_MITSHM
+
+#if defined(TQ_OS_WIN32) && defined(TQT_MITSHM)
+#undef TQT_MITSHM
+#endif
+
+#include "tqplatformdefs.h"
+
+#include "tqbitmap.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqimage.h"
+#include "tqwmatrix.h"
+#include "tqapplication.h"
+#include "tqt_x11_p.h"
+
+#include <stdlib.h>
+
+#if defined(TQ_CC_MIPS)
+# define for if(0){}else for
+#endif
+
+#ifdef USE_QT4
+
+/*!
+ Returns the window system handle of the paint tqdevice, for
+ low-level access. Using this function is not portable.
+
+ The HANDLE type varies with platform; see \c tqpaintdevice.h and
+ \c tqwindowdefs.h for details.
+
+ \sa x11Display()
+*/
+TQt::HANDLE TQPixmap::handle() const
+{
+ return QPixmap::handle();
+}
+
+/*!
+ Returns the window system handle of the paint tqdevice for XRender
+ support. Use of this function is not portable. This function will
+ return 0 if XRender support is not compiled into TQt, if the
+ XRender extension is not supported on the X11 display, or if the
+ handle could not be created.
+*/
+TQt::HANDLE TQPixmap::x11RenderHandle() const
+{
+// #ifndef TQT_NO_XFTFREETYPE
+// return rendhd ? XftDrawPicture( (XftDraw *) rendhd ) : 0;
+// #else
+// return 0;
+// #endif // TQT_NO_XFTFREETYPE
+
+ // [FIXME]
+ printf("[WARNING] TQPixmap::x11RenderHandle() const unimplemented\n\r");
+ return 0;
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQPixmap::TQPixmapData
+ \brief The TQPixmap::TQPixmapData class is an internal class.
+ \internal
+*/
+
+
+// For thread-safety:
+// image->data does not belong to X11, so we must free it ourselves.
+
+inline static void qSafeXDestroyImage( XImage *x )
+{
+ if ( x->data ) {
+ free( x->data );
+ x->data = 0;
+ }
+ XDestroyImage( x );
+}
+
+
+/*****************************************************************************
+ MIT Shared Memory Extension support: makes xForm noticeably (~20%) faster.
+ *****************************************************************************/
+
+#if defined(TQT_MITSHM)
+
+static bool xshminit = FALSE;
+static XShmSegmentInfo xshminfo;
+static XImage *xshmimg = 0;
+static Pixmap xshmpm = 0;
+
+static void qt_cleanup_mitshm()
+{
+ if ( xshmimg == 0 )
+ return;
+ Display *dpy = TQPaintDevice::x11AppDisplay();
+ if ( xshmpm ) {
+ XFreePixmap( dpy, xshmpm );
+ xshmpm = 0;
+ }
+ XShmDetach( dpy, &xshminfo ); xshmimg->data = 0;
+ qSafeXDestroyImage( xshmimg ); xshmimg = 0;
+ shmdt( xshminfo.shmaddr );
+ shmctl( xshminfo.shmid, IPC_RMID, 0 );
+}
+
+
+static bool qt_create_mitshm_buffer( const TQPaintDevice* dev, int w, int h )
+{
+ static int major, minor;
+ static Bool pixmaps_ok;
+ Display *dpy = dev->x11Display();
+ int dd = dev->x11Depth();
+ Visual *vis = (Visual*)dev->x11Visual();
+
+ if ( xshminit ) {
+ qt_cleanup_mitshm();
+ } else {
+ if ( !XShmQueryVersion(dpy, &major, &minor, &pixmaps_ok) )
+ return FALSE; // MIT Shm not supported
+ qAddPostRoutine( qt_cleanup_mitshm );
+ xshminit = TRUE;
+ }
+
+ xshmimg = XShmCreateImage( dpy, vis, dd, ZPixmap, 0, &xshminfo, w, h );
+ if ( !xshmimg )
+ return FALSE;
+
+ bool ok;
+ xshminfo.shmid = shmget( IPC_PRIVATE,
+ xshmimg->bytes_per_line * xshmimg->height,
+ IPC_CREAT | 0777 );
+ ok = xshminfo.shmid != -1;
+ if ( ok ) {
+ xshmimg->data = (char*)shmat( xshminfo.shmid, 0, 0 );
+ xshminfo.shmaddr = xshmimg->data;
+ ok = ( xshminfo.shmaddr != (char*)-1 );
+ }
+ xshminfo.readOnly = FALSE;
+ if ( ok )
+ ok = XShmAttach( dpy, &xshminfo );
+ if ( !ok ) {
+ qSafeXDestroyImage( xshmimg );
+ xshmimg = 0;
+ if ( xshminfo.shmaddr )
+ shmdt( xshminfo.shmaddr );
+ if ( xshminfo.shmid != -1 )
+ shmctl( xshminfo.shmid, IPC_RMID, 0 );
+ return FALSE;
+ }
+ if ( pixmaps_ok )
+ xshmpm = XShmCreatePixmap( dpy, DefaultRootWindow(dpy), xshmimg->data,
+ &xshminfo, w, h, dd );
+
+ return TRUE;
+}
+
+#else
+
+// If extern, need a dummy.
+//
+// static bool qt_create_mitshm_buffer( TQPaintDevice*, int, int )
+// {
+// return FALSE;
+// }
+
+#endif // TQT_MITSHM
+
+
+/*****************************************************************************
+ Internal functions
+ *****************************************************************************/
+
+extern const uchar *qt_get_bitflip_array(); // defined in qimage.cpp
+
+static uchar *flip_bits( const uchar *bits, int len )
+{
+ register const uchar *p = bits;
+ const uchar *end = p + len;
+ uchar *newdata = new uchar[len];
+ uchar *b = newdata;
+ const uchar *f = qt_get_bitflip_array();
+ while ( p < end )
+ *b++ = f[*p++];
+ return newdata;
+}
+
+// Returns position of highest bit set or -1 if none
+static int highest_bit( uint v )
+{
+ int i;
+ uint b = (uint)1 << 31;
+ for ( i=31; ((b & v) == 0) && i>=0; i-- )
+ b >>= 1;
+ return i;
+}
+
+// Returns position of lowest set bit in 'v' as an integer (0-31), or -1
+static int lowest_bit( uint v )
+{
+ int i;
+ ulong lb;
+ lb = 1;
+ for (i=0; ((v & lb) == 0) && i<32; i++, lb<<=1);
+ return i==32 ? -1 : i;
+}
+
+// Counts the number of bits set in 'v'
+static uint n_bits( uint v )
+{
+ int i = 0;
+ while ( v ) {
+ v = v & (v - 1);
+ i++;
+ }
+ return i;
+}
+
+static uint *red_scale_table = 0;
+static uint *green_scale_table = 0;
+static uint *blue_scale_table = 0;
+
+static void cleanup_scale_tables()
+{
+ delete[] red_scale_table;
+ delete[] green_scale_table;
+ delete[] blue_scale_table;
+}
+
+/*
+ Could do smart bitshifting, but the "obvious" algorithm only works for
+ nBits >= 4. This is more robust.
+*/
+static void build_scale_table( uint **table, uint nBits )
+{
+ if ( nBits > 7 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "build_scale_table: internal error, nBits = %i", nBits );
+#endif
+ return;
+ }
+ if (!*table) {
+ static bool firstTable = TRUE;
+ if ( firstTable ) {
+ qAddPostRoutine( cleanup_scale_tables );
+ firstTable = FALSE;
+ }
+ *table = new uint[256];
+ }
+ int maxVal = (1 << nBits) - 1;
+ int valShift = 8 - nBits;
+ int i;
+ for( i = 0 ; i < maxVal + 1 ; i++ )
+ (*table)[i << valShift] = i*255/maxVal;
+}
+
+static int defaultScreen = -1;
+
+extern bool qt_use_xrender; // defined in qapplication_x11.cpp
+extern bool qt_has_xft; // defined in qfont_x11.cpp
+
+#ifndef TQT_NO_XFTFREETYPE
+#ifndef TQT_XFT2
+// Xft1 doesn't have XftDrawCreateAlpha, so we fake it in qtaddons_x11.cpp
+extern "C" XftDraw *XftDrawCreateAlpha( Display *, TQt::HANDLE, int );
+#endif // TQT_XFT2
+#endif // TQT_NO_XFTFREETYPE
+
+/*****************************************************************************
+ TQPixmap member functions
+ *****************************************************************************/
+
+/*!
+ \internal
+ Initializes the pixmap data.
+*/
+
+void TQPixmap::init( int w, int h, int d, bool bitmap, Optimization optim )
+{
+#if defined(TQT_CHECK_STATE)
+ if ( tqApp->type() == TQApplication::Tty ) {
+ qWarning( "TQPixmap: Cannot create a TQPixmap when no GUI "
+ "is being used" );
+ }
+#endif
+
+ static int serial = 0;
+
+ if ( defaultScreen >= 0 && defaultScreen != x11Screen() ) {
+ TQPaintDeviceX11Data* xd = getX11Data( TRUE );
+ xd->x_screen = defaultScreen;
+ xd->x_depth = TQPaintDevice::x11AppDepth( xd->x_screen );
+ xd->x_cells = TQPaintDevice::x11AppCells( xd->x_screen );
+ xd->x_colormap = TQPaintDevice::x11AppColormap( xd->x_screen );
+ xd->x_defcolormap = TQPaintDevice::x11AppDefaultColormap( xd->x_screen );
+ xd->x_visual = TQPaintDevice::x11AppVisual( xd->x_screen );
+ xd->x_defvisual = TQPaintDevice::x11AppDefaultVisual( xd->x_screen );
+ setX11Data( xd );
+ }
+
+ int dd = x11Depth();
+
+ if ( d != -1 )
+ dd = d;
+
+ if ( optim == DefaultOptim ) // use default optimization
+ optim = defOptim;
+
+ data = new TQPixmapData;
+ TQ_CHECK_PTR( data );
+
+ memset( data, 0, sizeof(TQPixmapData) );
+ data->count = 1;
+ data->uninit = TRUE;
+ data->bitmap = bitmap;
+ data->ser_no = ++serial;
+ data->optim = optim;
+
+ bool make_null = w == 0 || h == 0; // create null pixmap
+ if ( d == 1 ) // monocrome pixmap
+ data->d = 1;
+ else if ( d < 0 || d == dd ) // def depth pixmap
+ data->d = dd;
+ if ( make_null || w < 0 || h < 0 || data->d == 0 ) {
+ hd = 0;
+ rendhd = 0;
+#if defined(TQT_CHECK_RANGE)
+ if ( !make_null )
+ qWarning( "TQPixmap: Invalid pixmap parameters" );
+#endif
+ return;
+ }
+ data->w = w;
+ data->h = h;
+ hd = (HANDLE)XCreatePixmap( x11Display(), RootWindow(x11Display(), x11Screen() ),
+ w, h, data->d );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( qt_has_xft ) {
+ if ( data->d == 1 ) {
+ rendhd = (HANDLE) XftDrawCreateBitmap( x11Display(), hd );
+ } else {
+ rendhd = (HANDLE) XftDrawCreate( x11Display(), hd,
+ (Visual *) x11Visual(),
+ x11Colormap() );
+ }
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+}
+
+
+void TQPixmap::deref()
+{
+ if ( data && data->deref() ) { // last reference lost
+ delete data->tqmask;
+ delete data->alphapm;
+ if ( data->ximage )
+ qSafeXDestroyImage( (XImage*)data->ximage );
+ if ( data->maskgc )
+ XFreeGC( x11Display(), (GC)data->maskgc );
+ if ( tqApp && hd) {
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (rendhd) {
+ XftDrawDestroy( (XftDraw *) rendhd );
+ rendhd = 0;
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ XFreePixmap( x11Display(), hd );
+ hd = 0;
+ }
+ delete data;
+ }
+}
+
+
+/*!
+ Constructs a monochrome pixmap, with width \a w and height \a h,
+ that is initialized with the data in \a bits. The \a isXbitmap
+ indicates whether the data is an X bitmap and defaults to FALSE.
+ This constructor is protected and used by the TQBitmap class.
+*/
+
+TQPixmap::TQPixmap( int w, int h, const uchar *bits, bool isXbitmap)
+ : TQPaintDevice( TQInternal::Pixmap )
+{ // for bitmaps only
+ init( 0, 0, 0, FALSE, defOptim );
+ if ( w <= 0 || h <= 0 ) // create null pixmap
+ return;
+
+ data->uninit = FALSE;
+ data->w = w;
+ data->h = h;
+ data->d = 1;
+ uchar *flipped_bits;
+ if ( isXbitmap ) {
+ flipped_bits = 0;
+ } else { // not X bitmap -> flip bits
+ flipped_bits = flip_bits( bits, ((w+7)/8)*h );
+ bits = flipped_bits;
+ }
+ hd = (HANDLE)XCreateBitmapFromData( x11Display(),
+ RootWindow(x11Display(), x11Screen() ),
+ (char *)bits, w, h );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( qt_has_xft )
+ rendhd = (HANDLE) XftDrawCreateBitmap (x11Display (), hd);
+#endif // TQT_NO_XFTFREETYPE
+
+ if ( flipped_bits ) // Avoid purify complaint
+ delete [] flipped_bits;
+}
+
+
+/*!
+ This is a special-purpose function that detaches the pixmap from
+ shared pixmap data.
+
+ A pixmap is automatically detached by TQt whenever its contents is
+ about to change. This is done in all TQPixmap member functions
+ that modify the pixmap (fill(), resize(), convertFromImage(),
+ load(), etc.), in bitBlt() for the destination pixmap and in
+ TQPainter::begin() on a pixmap.
+
+ It is possible to modify a pixmap without letting TQt know. You can
+ first obtain the system-dependent handle() and then call
+ system-specific functions (for instance, BitBlt under Windows)
+ that modify the pixmap contents. In such cases, you can call
+ detach() to cut the pixmap loose from other pixmaps that share
+ data with this one.
+
+ detach() returns immediately if there is just a single reference
+ or if the pixmap has not been initialized yet.
+*/
+
+void TQPixmap::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+ data->uninit = FALSE;
+
+ // reset cached data
+ if ( data->ximage ) {
+ qSafeXDestroyImage( (XImage*)data->ximage );
+ data->ximage = 0;
+ }
+ if ( data->maskgc ) {
+ XFreeGC( x11Display(), (GC)data->maskgc );
+ data->maskgc = 0;
+ }
+}
+
+
+/*!
+ Returns the default pixmap depth, i.e. the depth a pixmap gets if
+ -1 is specified.
+
+ \sa depth()
+*/
+
+int TQPixmap::defaultDepth()
+{
+ return x11AppDepth();
+}
+
+
+/*!
+ \fn TQPixmap::Optimization TQPixmap::optimization() const
+
+ Returns the optimization setting for this pixmap.
+
+ The default optimization setting is \c TQPixmap::NormalOptim. You
+ can change this setting in two ways:
+ \list
+ \i Call setDefaultOptimization() to set the default optimization
+ for all new pixmaps.
+ \i Call setOptimization() to set the optimization for individual
+ pixmaps.
+ \endlist
+
+ \sa setOptimization(), setDefaultOptimization(), defaultOptimization()
+*/
+
+/*!
+ Sets pixmap drawing optimization for this pixmap.
+
+ The \a optimization setting affects pixmap operations, in
+ particular drawing of transtqparent pixmaps (bitBlt() a pixmap with
+ a tqmask set) and pixmap transformations (the xForm() function).
+
+ Pixmap optimization involves keeping intermediate results in a
+ cache buffer and using the cache to speed up bitBlt() and xForm().
+ The cost is more memory consumption, up to twice as much as an
+ unoptimized pixmap.
+
+ Use the setDefaultOptimization() to change the default
+ optimization for all new pixmaps.
+
+ \sa optimization(), setDefaultOptimization(), defaultOptimization()
+*/
+
+void TQPixmap::setOptimization( Optimization optimization )
+{
+ if ( optimization == data->optim )
+ return;
+ detach();
+ data->optim = optimization == DefaultOptim ?
+ defOptim : optimization;
+ if ( data->optim == MemoryOptim && data->ximage ) {
+ qSafeXDestroyImage( (XImage*)data->ximage );
+ data->ximage = 0;
+ }
+}
+
+
+/*!
+ Fills the pixmap with the color \a fillColor.
+*/
+
+void TQPixmap::fill( const TQColor &fillColor )
+{
+ if ( isNull() )
+ return;
+ detach(); // detach other references
+ GC gc = qt_xget_temp_gc( x11Screen(), depth()==1 );
+ XSetForeground( x11Display(), gc, fillColor.pixel(x11Screen()) );
+ XFillRectangle( x11Display(), hd, gc, 0, 0, width(), height() );
+}
+
+
+/*!
+ Internal implementation of the virtual TQPaintDevice::metric() function.
+
+ Use the TQPaintDeviceMetrics class instead.
+
+ \a m is the metric to get.
+*/
+
+int TQPixmap::metric( int m ) const
+{
+ int val;
+ if ( m == TQPaintDeviceMetrics::PdmWidth )
+ val = width();
+ else if ( m == TQPaintDeviceMetrics::PdmHeight ) {
+ val = height();
+ } else {
+ Display *dpy = x11Display();
+ int scr = x11Screen();
+ switch ( m ) {
+ case TQPaintDeviceMetrics::PdmDpiX:
+ case TQPaintDeviceMetrics::PdmPhysicalDpiX:
+ val = TQPaintDevice::x11AppDpiX( scr );
+ break;
+ case TQPaintDeviceMetrics::PdmDpiY:
+ case TQPaintDeviceMetrics::PdmPhysicalDpiY:
+ val = TQPaintDevice::x11AppDpiY( scr );
+ break;
+ case TQPaintDeviceMetrics::PdmWidthMM:
+ val = (DisplayWidthMM(dpy,scr)*width())/
+ DisplayWidth(dpy,scr);
+ break;
+ case TQPaintDeviceMetrics::PdmHeightMM:
+ val = (DisplayHeightMM(dpy,scr)*height())/
+ DisplayHeight(dpy,scr);
+ break;
+ case TQPaintDeviceMetrics::PdmNumColors:
+ val = 1 << depth();
+ break;
+ case TQPaintDeviceMetrics::PdmDepth:
+ val = depth();
+ break;
+ default:
+ val = 0;
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPixmap::metric: Invalid metric command" );
+#endif
+ }
+ }
+ return val;
+}
+
+/*!
+ Converts the pixmap to a TQImage. Returns a null image if it fails.
+
+ If the pixmap has 1-bit depth, the returned image will also be 1
+ bit deep. If the pixmap has 2- to 8-bit depth, the returned image
+ has 8-bit depth. If the pixmap has greater than 8-bit depth, the
+ returned image has 32-bit depth.
+
+ Note that for the moment, alpha masks on monochrome images are
+ ignored.
+
+ \sa convertFromImage()
+*/
+
+TQImage TQPixmap::convertToImage() const
+{
+ TQImage image;
+ if ( isNull() )
+ return image; // null image
+
+ int w = width();
+ int h = height();
+ int d = depth();
+ bool mono = d == 1;
+ Visual *visual = (Visual *)x11Visual();
+ bool trucol = (visual->c_class == TrueColor || visual->c_class == DirectColor) && !mono && d > 8;
+
+ if ( d > 1 && d <= 8 ) // set to nearest valid depth
+ d = 8; // 2..8 ==> 8
+ // we could run into the situation where d == 8 AND trucol is true, which can
+ // cause problems when converting to and from images. in this case, always treat
+ // the depth as 32... from Klaus Schmidinger and qt-bugs/arc-15/31333.
+ if ( d > 8 || trucol )
+ d = 32; // > 8 ==> 32
+
+ XImage *xi = (XImage *)data->ximage; // any cached ximage?
+ if ( !xi ) // fetch data from X server
+ xi = XGetImage( x11Display(), hd, 0, 0, w, h, AllPlanes,
+ mono ? XYPixmap : ZPixmap );
+ TQ_CHECK_PTR( xi );
+ if (!xi)
+ return image; // null image
+
+ TQImage::Endian bitOrder = TQImage::IgnoreEndian;
+ if ( mono ) {
+ bitOrder = xi->bitmap_bit_order == LSBFirst ?
+ TQImage::LittleEndian : TQImage::BigEndian;
+ }
+ image.create( w, h, d, 0, bitOrder );
+ if ( image.isNull() ) // could not create image
+ return image;
+
+ const TQPixmap* msk = tqmask();
+ const TQPixmap *alf = data->alphapm;
+
+ TQImage alpha;
+ if (alf) {
+ XImage *axi = XGetImage(x11Display(), alf->hd, 0, 0, w, h, AllPlanes, ZPixmap);
+
+ if (axi) {
+ image.setAlphaBuffer( TRUE );
+ alpha.create(w, h, 8);
+
+ // copy each scanline
+ char *src = axi->data;
+ int bpl = TQMIN(alpha.bytesPerLine(), axi->bytes_per_line);
+ for (int y = 0; y < h; y++ ) {
+ memcpy( alpha.scanLine(y), src, bpl );
+ src += axi->bytes_per_line;
+ }
+
+ qSafeXDestroyImage( axi );
+ }
+ } else if (msk) {
+ image.setAlphaBuffer( TRUE );
+ alpha = msk->convertToImage();
+ }
+ bool ale = alpha.bitOrder() == TQImage::LittleEndian;
+
+ if ( trucol ) { // truecolor
+ const uint red_mask = (uint)visual->red_mask;
+ const uint green_mask = (uint)visual->green_mask;
+ const uint blue_mask = (uint)visual->blue_mask;
+ const int red_shift = highest_bit( red_mask ) - 7;
+ const int green_shift = highest_bit( green_mask ) - 7;
+ const int blue_shift = highest_bit( blue_mask ) - 7;
+
+ const uint red_bits = n_bits( red_mask );
+ const uint green_bits = n_bits( green_mask );
+ const uint blue_bits = n_bits( blue_mask );
+
+ static uint red_table_bits = 0;
+ static uint green_table_bits = 0;
+ static uint blue_table_bits = 0;
+
+ if ( red_bits < 8 && red_table_bits != red_bits) {
+ build_scale_table( &red_scale_table, red_bits );
+ red_table_bits = red_bits;
+ }
+ if ( blue_bits < 8 && blue_table_bits != blue_bits) {
+ build_scale_table( &blue_scale_table, blue_bits );
+ blue_table_bits = blue_bits;
+ }
+ if ( green_bits < 8 && green_table_bits != green_bits) {
+ build_scale_table( &green_scale_table, green_bits );
+ green_table_bits = green_bits;
+ }
+
+ int r, g, b;
+
+ TQRgb *dst;
+ uchar *src;
+ uint pixel;
+ int bppc = xi->bits_per_pixel;
+
+ if ( bppc > 8 && xi->byte_order == LSBFirst )
+ bppc++;
+
+ for ( int y=0; y<h; y++ ) {
+ uchar* asrc = alf || msk ? alpha.scanLine( y ) : 0;
+ dst = (TQRgb *)image.scanLine( y );
+ src = (uchar *)xi->data + xi->bytes_per_line*y;
+ for ( int x=0; x<w; x++ ) {
+ switch ( bppc ) {
+ case 8:
+ pixel = *src++;
+ break;
+ case 16: // 16 bit MSB
+ pixel = src[1] | (ushort)src[0] << 8;
+ src += 2;
+ break;
+ case 17: // 16 bit LSB
+ pixel = src[0] | (ushort)src[1] << 8;
+ src += 2;
+ break;
+ case 24: // 24 bit MSB
+ pixel = src[2] | (ushort)src[1] << 8 |
+ (uint)src[0] << 16;
+ src += 3;
+ break;
+ case 25: // 24 bit LSB
+ pixel = src[0] | (ushort)src[1] << 8 |
+ (uint)src[2] << 16;
+ src += 3;
+ break;
+ case 32: // 32 bit MSB
+ pixel = src[3] | (ushort)src[2] << 8 |
+ (uint)src[1] << 16 | (uint)src[0] << 24;
+ src += 4;
+ break;
+ case 33: // 32 bit LSB
+ pixel = src[0] | (ushort)src[1] << 8 |
+ (uint)src[2] << 16 | (uint)src[3] << 24;
+ src += 4;
+ break;
+ default: // should not really happen
+ x = w; // leave loop
+ y = h;
+ pixel = 0; // eliminate compiler warning
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPixmap::convertToImage: Invalid depth %d",
+ bppc );
+#endif
+ }
+ if ( red_shift > 0 )
+ r = (pixel & red_mask) >> red_shift;
+ else
+ r = (pixel & red_mask) << -red_shift;
+ if ( green_shift > 0 )
+ g = (pixel & green_mask) >> green_shift;
+ else
+ g = (pixel & green_mask) << -green_shift;
+ if ( blue_shift > 0 )
+ b = (pixel & blue_mask) >> blue_shift;
+ else
+ b = (pixel & blue_mask) << -blue_shift;
+
+ if ( red_bits < 8 )
+ r = red_scale_table[r];
+ if ( green_bits < 8 )
+ g = green_scale_table[g];
+ if ( blue_bits < 8 )
+ b = blue_scale_table[b];
+
+ if (alf) {
+ *dst++ = tqRgba(r, g, b, asrc[x]);
+ } else if (msk) {
+ if ( ale ) {
+ *dst++ = (asrc[x >> 3] & (1 << (x & 7)))
+ ? tqRgba(r, g, b, 0xff) : tqRgba(r, g, b, 0x00);
+ } else {
+ *dst++ = (asrc[x >> 3] & (1 << (7 -(x & 7))))
+ ? tqRgba(r, g, b, 0xff) : tqRgba(r, g, b, 0x00);
+ }
+ } else {
+ *dst++ = tqRgb(r, g, b);
+ }
+ }
+ }
+ } else if ( xi->bits_per_pixel == d ) { // compatible depth
+ char *xidata = xi->data; // copy each scanline
+ int bpl = TQMIN(image.bytesPerLine(),xi->bytes_per_line);
+ for ( int y=0; y<h; y++ ) {
+ memcpy( image.scanLine(y), xidata, bpl );
+ xidata += xi->bytes_per_line;
+ }
+ } else {
+ /* Typically 2 or 4 bits display depth */
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPixmap::convertToImage: Display not supported (bpp=%d)",
+ xi->bits_per_pixel );
+#endif
+ image.reset();
+ return image;
+ }
+
+ if ( mono ) { // bitmap
+ image.setNumColors( 2 );
+ image.setColor( 0, tqRgb(255,255,255) );
+ image.setColor( 1, tqRgb(0,0,0) );
+ } else if ( !trucol ) { // pixmap with colormap
+ register uchar *p;
+ uchar *end;
+ uchar use[256]; // pixel-in-use table
+ uchar pix[256]; // pixel translation table
+ int ncols, i, bpl;
+ memset( use, 0, 256 );
+ memset( pix, 0, 256 );
+ bpl = image.bytesPerLine();
+
+ if (msk) { // which pixels are used?
+ for ( i=0; i<h; i++ ) {
+ uchar* asrc = alpha.scanLine( i );
+ p = image.scanLine( i );
+ for ( int x = 0; x < w; x++ ) {
+ if ( ale ) {
+ if (asrc[x >> 3] & (1 << (x & 7)))
+ use[*p] = 1;
+ } else {
+ if (asrc[x >> 3] & (1 << (7 -(x & 7))))
+ use[*p] = 1;
+ }
+ ++p;
+ }
+ }
+ } else {
+ for ( i=0; i<h; i++ ) {
+ p = image.scanLine( i );
+ end = p + bpl;
+ while ( p < end )
+ use[*p++] = 1;
+ }
+ }
+ ncols = 0;
+ for ( i=0; i<256; i++ ) { // build translation table
+ if ( use[i] )
+ pix[i] = ncols++;
+ }
+ for ( i=0; i<h; i++ ) { // translate pixels
+ p = image.scanLine( i );
+ end = p + bpl;
+ while ( p < end ) {
+ *p = pix[*p];
+ p++;
+ }
+ }
+
+ Colormap cmap = x11Colormap();
+ int ncells = x11Cells();
+ XColor *carr = new XColor[ncells];
+ for ( i=0; i<ncells; i++ )
+ carr[i].pixel = i;
+ // Get default colormap
+ XQueryColors( x11Display(), cmap, carr, ncells );
+
+ if (msk) {
+ int trans;
+ if (ncols < 256) {
+ trans = ncols++;
+ image.setNumColors( ncols ); // create color table
+ image.setColor( trans, 0x00000000 );
+ } else {
+ image.setNumColors( ncols ); // create color table
+ // oh dear... no spare "transtqparent" pixel.
+ // use first pixel in image (as good as any).
+ trans = image.scanLine( i )[0];
+ }
+ for ( i=0; i<h; i++ ) {
+ uchar* asrc = alpha.scanLine( i );
+ p = image.scanLine( i );
+ for ( int x = 0; x < w; x++ ) {
+ if ( ale ) {
+ if (!(asrc[x >> 3] & (1 << (x & 7))))
+ *p = trans;
+ } else {
+ if (!(asrc[x >> 3] & (1 << (7 -(x & 7)))))
+ *p = trans;
+ }
+ ++p;
+ }
+ }
+ } else {
+ image.setNumColors( ncols ); // create color table
+ }
+ int j = 0;
+ for ( i=0; i<256; i++ ) { // translate pixels
+ if ( use[i] ) {
+ image.setColor( j++,
+ ( msk ? 0xff000000 : 0 )
+ | tqRgb( (carr[i].red >> 8) & 255,
+ (carr[i].green >> 8) & 255,
+ (carr[i].blue >> 8) & 255 ) );
+ }
+ }
+
+ delete [] carr;
+ }
+ if ( data->optim != BestOptim ) { // throw away image data
+ qSafeXDestroyImage( xi );
+ ((TQPixmap*)this)->data->ximage = 0;
+ } else // keep ximage data
+ ((TQPixmap*)this)->data->ximage = xi;
+
+ return image;
+}
+
+
+/*!
+ Converts image \a img and sets this pixmap. Returns TRUE if
+ successful; otherwise returns FALSE.
+
+ The \a conversion_flags argument is a bitwise-OR of the
+ \l{TQt::ImageConversionFlags}. Passing 0 for \a conversion_flags
+ sets all the default options.
+
+ Note that even though a TQPixmap with depth 1 behaves much like a
+ TQBitmap, isTQBitmap() returns FALSE.
+
+ If a pixmap with depth 1 is painted with color0 and color1 and
+ converted to an image, the pixels painted with color0 will produce
+ pixel index 0 in the image and those painted with color1 will
+ produce pixel index 1.
+
+ \sa convertToImage(), isTQBitmap(), TQImage::convertDepth(),
+ defaultDepth(), TQImage::hasAlphaBuffer()
+*/
+
+bool TQPixmap::convertFromImage( const TQImage &img, int conversion_flags )
+{
+ if ( img.isNull() ) {
+#if defined(TQT_CHECK_NULL)
+ qWarning( "TQPixmap::convertFromImage: Cannot convert a null image" );
+#endif
+ return FALSE;
+ }
+ detach(); // detach other references
+ TQImage image = img;
+ const uint w = image.width();
+ const uint h = image.height();
+ int d = image.depth();
+ const int dd = x11Depth();
+ bool force_mono = (dd == 1 || isTQBitmap() ||
+ (conversion_flags & ColorMode_Mask)==MonoOnly );
+
+ if ( w >= 32768 || h >= 32768 )
+ return FALSE;
+
+ // get rid of the tqmask
+ delete data->tqmask;
+ data->tqmask = 0;
+
+ // get rid of alpha pixmap
+ delete data->alphapm;
+ data->alphapm = 0;
+
+ // must be monochrome
+ if ( force_mono ) {
+ if ( d != 1 ) {
+ // dither
+ image = image.convertDepth( 1, conversion_flags );
+ d = 1;
+ }
+ } else { // can be both
+ bool conv8 = FALSE;
+ if ( d > 8 && dd <= 8 ) { // convert to 8 bit
+ if ( (conversion_flags & DitherMode_Mask) == AutoDither )
+ conversion_flags = (conversion_flags & ~DitherMode_Mask)
+ | PreferDither;
+ conv8 = TRUE;
+ } else if ( (conversion_flags & ColorMode_Mask) == ColorOnly ) {
+ conv8 = d == 1; // native depth wanted
+ } else if ( d == 1 ) {
+ if ( image.numColors() == 2 ) {
+ TQRgb c0 = image.color(0); // Auto: convert to best
+ TQRgb c1 = image.color(1);
+ conv8 = TQMIN(c0,c1) != tqRgb(0,0,0) || TQMAX(c0,c1) != tqRgb(255,255,255);
+ } else {
+ // eg. 1-color monochrome images (they do exist).
+ conv8 = TRUE;
+ }
+ }
+ if ( conv8 ) {
+ image = image.convertDepth( 8, conversion_flags );
+ d = 8;
+ }
+ }
+
+ if ( d == 1 ) { // 1 bit pixmap (bitmap)
+ if ( hd ) { // delete old X pixmap
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (rendhd) {
+ XftDrawDestroy( (XftDraw *) rendhd );
+ rendhd = 0;
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ XFreePixmap( x11Display(), hd );
+ }
+
+ // make sure image.color(0) == color0 (white) and image.color(1) == color1 (black)
+ if (image.color(0) == TQt::black.rgb() && image.color(1) == TQt::white.rgb()) {
+ image.invertPixels();
+ image.setColor(0, TQt::white.rgb());
+ image.setColor(1, TQt::black.rgb());
+ }
+
+ char *bits;
+ uchar *tmp_bits;
+ int bpl = (w+7)/8;
+ int ibpl = image.bytesPerLine();
+ if ( image.bitOrder() == TQImage::BigEndian || bpl != ibpl ) {
+ tmp_bits = new uchar[bpl*h];
+ TQ_CHECK_PTR( tmp_bits );
+ bits = (char *)tmp_bits;
+ uchar *p, *b, *end;
+ uint y, count;
+ if ( image.bitOrder() == TQImage::BigEndian ) {
+ const uchar *f = qt_get_bitflip_array();
+ b = tmp_bits;
+ for ( y=0; y<h; y++ ) {
+ p = image.scanLine( y );
+ end = p + bpl;
+ count = bpl;
+ while ( count > 4 ) {
+ *b++ = f[*p++];
+ *b++ = f[*p++];
+ *b++ = f[*p++];
+ *b++ = f[*p++];
+ count -= 4;
+ }
+ while ( p < end )
+ *b++ = f[*p++];
+ }
+ } else { // just copy
+ b = tmp_bits;
+ p = image.scanLine( 0 );
+ for ( y=0; y<h; y++ ) {
+ memcpy( b, p, bpl );
+ b += bpl;
+ p += ibpl;
+ }
+ }
+ } else {
+ bits = (char *)image.bits();
+ tmp_bits = 0;
+ }
+ hd = (HANDLE)XCreateBitmapFromData( x11Display(),
+ RootWindow(x11Display(), x11Screen() ),
+ bits, w, h );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( qt_has_xft )
+ rendhd = (HANDLE) XftDrawCreateBitmap( x11Display(), hd );
+#endif // TQT_NO_XFTFREETYPE
+
+ if ( tmp_bits ) // Avoid purify complaint
+ delete [] tmp_bits;
+ data->w = w; data->h = h; data->d = 1;
+
+ if ( image.hasAlphaBuffer() ) {
+ TQBitmap m;
+ m = image.createAlphaMask( conversion_flags );
+ setMask( m );
+ }
+ return TRUE;
+ }
+
+ Display *dpy = x11Display();
+ Visual *visual = (Visual *)x11Visual();
+ XImage *xi = 0;
+ bool trucol = (visual->c_class == TrueColor || visual->c_class == DirectColor);
+ int nbytes = image.numBytes();
+ uchar *newbits= 0;
+
+ if ( trucol ) { // truecolor display
+ TQRgb pix[256]; // pixel translation table
+ const bool d8 = d == 8;
+ const uint red_mask = (uint)visual->red_mask;
+ const uint green_mask = (uint)visual->green_mask;
+ const uint blue_mask = (uint)visual->blue_mask;
+ const int red_shift = highest_bit( red_mask ) - 7;
+ const int green_shift = highest_bit( green_mask ) - 7;
+ const int blue_shift = highest_bit( blue_mask ) - 7;
+ const uint rbits = highest_bit(red_mask) - lowest_bit(red_mask) + 1;
+ const uint gbits = highest_bit(green_mask) - lowest_bit(green_mask) + 1;
+ const uint bbits = highest_bit(blue_mask) - lowest_bit(blue_mask) + 1;
+
+ if ( d8 ) { // setup pixel translation
+ TQRgb *ctable = image.colorTable();
+ for ( int i=0; i<image.numColors(); i++ ) {
+ int r = tqRed (ctable[i]);
+ int g = tqGreen(ctable[i]);
+ int b = tqBlue (ctable[i]);
+ r = red_shift > 0 ? r << red_shift : r >> -red_shift;
+ g = green_shift > 0 ? g << green_shift : g >> -green_shift;
+ b = blue_shift > 0 ? b << blue_shift : b >> -blue_shift;
+ pix[i] = (b & blue_mask) | (g & green_mask) | (r & red_mask)
+ | ~(blue_mask | green_mask | red_mask);
+ }
+ }
+
+ xi = XCreateImage( dpy, visual, dd, ZPixmap, 0, 0, w, h, 32, 0 );
+ TQ_CHECK_PTR( xi );
+ if (!xi)
+ return false;
+ newbits = (uchar *)malloc( xi->bytes_per_line*h );
+ TQ_CHECK_PTR( newbits );
+ if ( !newbits ) // no memory
+ return FALSE;
+ int bppc = xi->bits_per_pixel;
+
+ if ( bppc > 8 && xi->byte_order == LSBFirst )
+ bppc++;
+
+ bool contig_bits = n_bits(red_mask) == rbits &&
+ n_bits(green_mask) == gbits &&
+ n_bits(blue_mask) == bbits;
+ bool dither_tc =
+ // Want it?
+ (conversion_flags & Dither_Mask) != ThresholdDither &&
+ (conversion_flags & DitherMode_Mask) != AvoidDither &&
+ // Need it?
+ bppc < 24 && !d8 &&
+ // Can do it? (Contiguous bits?)
+ contig_bits;
+
+ static bool init=FALSE;
+ static int D[16][16];
+ if ( dither_tc && !init ) {
+ // I also contributed this code to XV - WWA.
+ /*
+ The dither matrix, D, is obtained with this formula:
+
+ D2 = [ 0 2 ]
+ [ 3 1 ]
+
+
+ D2*n = [ 4*Dn 4*Dn+2*Un ]
+ [ 4*Dn+3*Un 4*Dn+1*Un ]
+ */
+ int n,i,j;
+ init=1;
+
+ /* Set D2 */
+ D[0][0]=0;
+ D[1][0]=2;
+ D[0][1]=3;
+ D[1][1]=1;
+
+ /* Expand using recursive definition given above */
+ for (n=2; n<16; n*=2) {
+ for (i=0; i<n; i++) {
+ for (j=0; j<n; j++) {
+ D[i][j]*=4;
+ D[i+n][j]=D[i][j]+2;
+ D[i][j+n]=D[i][j]+3;
+ D[i+n][j+n]=D[i][j]+1;
+ }
+ }
+ }
+ init=TRUE;
+ }
+
+ for ( uint y=0; y<h; y++ ) {
+ uchar* src = image.scanLine( y );
+ uchar* dst = newbits + xi->bytes_per_line*y;
+ TQRgb* p = (TQRgb *)src;
+
+#define GET_RGB \
+ int r = tqRed ( *p ); \
+ int g = tqGreen( *p ); \
+ int b = tqBlue ( *p++ ); \
+ r = red_shift > 0 \
+ ? r << red_shift : r >> -red_shift; \
+ g = green_shift > 0 \
+ ? g << green_shift : g >> -green_shift; \
+ b = blue_shift > 0 \
+ ? b << blue_shift : b >> -blue_shift;
+
+#define GET_PIXEL \
+ int pixel; \
+ if ( d8 ) pixel = pix[*src++]; \
+ else { \
+ GET_RGB \
+ pixel = (b & blue_mask)|(g & green_mask) | (r & red_mask) \
+ | ~(blue_mask | green_mask | red_mask); \
+ }
+
+#define GET_PIXEL_DITHER_TC \
+ int r = tqRed ( *p ); \
+ int g = tqGreen( *p ); \
+ int b = tqBlue ( *p++ ); \
+ const int thres = D[x%16][y%16]; \
+ if ( r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \
+ > thres) \
+ r += (1<<(8-rbits)); \
+ if ( g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \
+ > thres) \
+ g += (1<<(8-gbits)); \
+ if ( b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \
+ > thres) \
+ b += (1<<(8-bbits)); \
+ r = red_shift > 0 \
+ ? r << red_shift : r >> -red_shift; \
+ g = green_shift > 0 \
+ ? g << green_shift : g >> -green_shift; \
+ b = blue_shift > 0 \
+ ? b << blue_shift : b >> -blue_shift; \
+ int pixel = (b & blue_mask)|(g & green_mask) | (r & red_mask);
+
+ if ( dither_tc ) {
+ uint x;
+ switch ( bppc ) {
+ case 16: // 16 bit MSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL_DITHER_TC
+ *dst++ = (pixel >> 8);
+ *dst++ = pixel;
+ }
+ break;
+ case 17: // 16 bit LSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL_DITHER_TC
+ *dst++ = pixel;
+ *dst++ = pixel >> 8;
+ }
+ break;
+ default:
+ qFatal("Logic error");
+ }
+ } else {
+ uint x;
+ switch ( bppc ) {
+ case 8: // 8 bit
+ for ( x=0; x<w; x++ ) {
+ int pixel = pix[*src++];
+ *dst++ = pixel;
+ }
+ break;
+ case 16: // 16 bit MSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL
+ *dst++ = (pixel >> 8);
+ *dst++ = pixel;
+ }
+ break;
+ case 17: // 16 bit LSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL
+ *dst++ = pixel;
+ *dst++ = pixel >> 8;
+ }
+ break;
+ case 24: // 24 bit MSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL
+ *dst++ = pixel >> 16;
+ *dst++ = pixel >> 8;
+ *dst++ = pixel;
+ }
+ break;
+ case 25: // 24 bit LSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL
+ *dst++ = pixel;
+ *dst++ = pixel >> 8;
+ *dst++ = pixel >> 16;
+ }
+ break;
+ case 32: // 32 bit MSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL
+ *dst++ = pixel >> 24;
+ *dst++ = pixel >> 16;
+ *dst++ = pixel >> 8;
+ *dst++ = pixel;
+ }
+ break;
+ case 33: // 32 bit LSB
+ for ( x=0; x<w; x++ ) {
+ GET_PIXEL
+ *dst++ = pixel;
+ *dst++ = pixel >> 8;
+ *dst++ = pixel >> 16;
+ *dst++ = pixel >> 24;
+ }
+ break;
+ default:
+ qFatal("Logic error 2");
+ }
+ }
+ }
+ xi->data = (char *)newbits;
+ }
+
+ if ( d == 8 && !trucol ) { // 8 bit pixmap
+ int pop[256]; // pixel popularity
+
+ if ( image.numColors() == 0 )
+ image.setNumColors( 1 );
+
+ memset( pop, 0, sizeof(int)*256 ); // reset popularity array
+ uint i;
+ for ( i=0; i<h; i++ ) { // for each scanline...
+ uchar* p = image.scanLine( i );
+ uchar *end = p + w;
+ while ( p < end ) // compute popularity
+ pop[*p++]++;
+ }
+
+ newbits = (uchar *)malloc( nbytes ); // copy image into newbits
+ TQ_CHECK_PTR( newbits );
+ if ( !newbits ) // no memory
+ return FALSE;
+ uchar* p = newbits;
+ memcpy( p, image.bits(), nbytes ); // copy image data into newbits
+
+ /*
+ * The code below picks the most important colors. It is based on the
+ * diversity algorithm, implemented in XV 3.10. XV is (C) by John Bradley.
+ */
+
+ struct PIX { // pixel sort element
+ uchar r,g,b,n; // color + pad
+ int use; // popularity
+ int index; // index in colormap
+ int mindist;
+ };
+ int ncols = 0;
+ for ( i=0; i< (uint) image.numColors(); i++ ) { // compute number of colors
+ if ( pop[i] > 0 )
+ ncols++;
+ }
+ for ( i=image.numColors(); i<256; i++ ) // ignore out-of-range pixels
+ pop[i] = 0;
+
+ // works since we make sure above to have at least
+ // one color in the image
+ if ( ncols == 0 )
+ ncols = 1;
+
+ PIX pixarr[256]; // pixel array
+ PIX pixarr_sorted[256]; // pixel array (sorted)
+ memset( pixarr, 0, ncols*sizeof(PIX) );
+ PIX *px = &pixarr[0];
+ int maxpop = 0;
+ int maxpix = 0;
+ TQ_CHECK_PTR( pixarr );
+ uint j = 0;
+ TQRgb* ctable = image.colorTable();
+ for ( i=0; i<256; i++ ) { // init pixel array
+ if ( pop[i] > 0 ) {
+ px->r = tqRed ( ctable[i] );
+ px->g = tqGreen( ctable[i] );
+ px->b = tqBlue ( ctable[i] );
+ px->n = 0;
+ px->use = pop[i];
+ if ( pop[i] > maxpop ) { // select most popular entry
+ maxpop = pop[i];
+ maxpix = j;
+ }
+ px->index = i;
+ px->mindist = 1000000;
+ px++;
+ j++;
+ }
+ }
+ pixarr_sorted[0] = pixarr[maxpix];
+ pixarr[maxpix].use = 0;
+
+ for ( i=1; i< (uint) ncols; i++ ) { // sort pixels
+ int minpix = -1, mindist = -1;
+ px = &pixarr_sorted[i-1];
+ int r = px->r;
+ int g = px->g;
+ int b = px->b;
+ int dist;
+ if ( (i & 1) || i<10 ) { // sort on max distance
+ for ( int j=0; j<ncols; j++ ) {
+ px = &pixarr[j];
+ if ( px->use ) {
+ dist = (px->r - r)*(px->r - r) +
+ (px->g - g)*(px->g - g) +
+ (px->b - b)*(px->b - b);
+ if ( px->mindist > dist )
+ px->mindist = dist;
+ if ( px->mindist > mindist ) {
+ mindist = px->mindist;
+ minpix = j;
+ }
+ }
+ }
+ } else { // sort on max popularity
+ for ( int j=0; j<ncols; j++ ) {
+ px = &pixarr[j];
+ if ( px->use ) {
+ dist = (px->r - r)*(px->r - r) +
+ (px->g - g)*(px->g - g) +
+ (px->b - b)*(px->b - b);
+ if ( px->mindist > dist )
+ px->mindist = dist;
+ if ( px->use > mindist ) {
+ mindist = px->use;
+ minpix = j;
+ }
+ }
+ }
+ }
+ pixarr_sorted[i] = pixarr[minpix];
+ pixarr[minpix].use = 0;
+ }
+
+ uint pix[256]; // pixel translation table
+ px = &pixarr_sorted[0];
+ for ( i=0; i< (uint) ncols; i++ ) { // allocate colors
+ TQColor c( px->r, px->g, px->b );
+ pix[px->index] = c.pixel(x11Screen());
+ px++;
+ }
+
+ p = newbits;
+ for ( i=0; i< (uint) nbytes; i++ ) { // translate pixels
+ *p = pix[*p];
+ p++;
+ }
+ }
+
+ if ( !xi ) { // X image not created
+ xi = XCreateImage( dpy, visual, dd, ZPixmap, 0, 0, w, h, 32, 0 );
+ if ( xi->bits_per_pixel == 16 ) { // convert 8 bpp ==> 16 bpp
+ ushort *p2;
+ int p2inc = xi->bytes_per_line/sizeof(ushort);
+ ushort *newerbits = (ushort *)malloc( xi->bytes_per_line * h );
+ TQ_CHECK_PTR( newerbits );
+ if ( !newerbits ) // no memory
+ return FALSE;
+ uchar* p = newbits;
+ for ( uint y=0; y<h; y++ ) { // OOPS: Do right byte order!!
+ p2 = newerbits + p2inc*y;
+ for ( uint x=0; x<w; x++ )
+ *p2++ = *p++;
+ }
+ free( newbits );
+ newbits = (uchar *)newerbits;
+ } else if ( xi->bits_per_pixel != 8 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPixmap::convertFromImage: Display not supported "
+ "(bpp=%d)", xi->bits_per_pixel );
+#endif
+ }
+ xi->data = (char *)newbits;
+ }
+
+ if ( hd && (width() != (int)w || height() != (int)h || this->depth() != dd) ) {
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (rendhd) {
+ XftDrawDestroy( (XftDraw *) rendhd );
+ rendhd = 0;
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ XFreePixmap( dpy, hd ); // don't reuse old pixmap
+ hd = 0;
+ }
+ if ( !hd ) { // create new pixmap
+ hd = (HANDLE)XCreatePixmap( x11Display(),
+ RootWindow(x11Display(), x11Screen() ),
+ w, h, dd );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( qt_has_xft ) {
+ if ( data->d == 1 ) {
+ rendhd = (HANDLE) XftDrawCreateBitmap( x11Display (), hd );
+ } else {
+ rendhd = (HANDLE) XftDrawCreate( x11Display (), hd,
+ (Visual *) x11Visual(), x11Colormap() );
+ }
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ }
+
+ XPutImage( dpy, hd, qt_xget_readonly_gc( x11Screen(), FALSE ),
+ xi, 0, 0, 0, 0, w, h );
+
+ if ( data->optim != BestOptim ) { // throw away image
+ qSafeXDestroyImage( xi );
+ data->ximage = 0;
+ } else { // keep ximage that we created
+ data->ximage = xi;
+ }
+ data->w = w;
+ data->h = h;
+ data->d = dd;
+
+ if ( image.hasAlphaBuffer() ) {
+ TQBitmap m;
+ m = image.createAlphaMask( conversion_flags );
+ setMask( m );
+
+#ifndef TQT_NO_XFTFREETYPE
+ // does this image have an alphamap (and not just a 1bpp tqmask)?
+ bool alphamap = image.depth() == 32;
+ if (image.depth() == 8) {
+ const TQRgb * const rgb = image.colorTable();
+ for (int i = 0, count = image.numColors(); i < count; ++i) {
+ const int alpha = tqAlpha(rgb[i]);
+ if (alpha != 0 && alpha != 0xff) {
+ alphamap = TRUE;
+ break;
+ }
+ }
+ }
+
+ if (qt_use_xrender && qt_has_xft && alphamap) {
+ data->alphapm = new TQPixmap; // create a null pixmap
+
+ // setup pixmap data
+ data->alphapm->data->w = w;
+ data->alphapm->data->h = h;
+ data->alphapm->data->d = 8;
+
+ // create 8bpp pixmap and render picture
+ data->alphapm->hd =
+ XCreatePixmap(x11Display(), RootWindow(x11Display(), x11Screen()),
+ w, h, 8);
+
+ data->alphapm->rendhd =
+ (HANDLE) XftDrawCreateAlpha( x11Display(), data->alphapm->hd, 8 );
+
+ XImage *axi = XCreateImage(x11Display(), (Visual *) x11Visual(),
+ 8, ZPixmap, 0, 0, w, h, 8, 0);
+
+ if (axi) {
+ // the data is deleted by qSafeXDestroyImage
+ axi->data = (char *) malloc(h * axi->bytes_per_line);
+ TQ_CHECK_PTR( axi->data );
+ char *aptr = axi->data;
+
+ if (image.depth() == 32) {
+ const int *iptr = (const int *) image.bits();
+ int max = w * h;
+ while (max--)
+ *aptr++ = *iptr++ >> 24; // squirt
+ } else if (image.depth() == 8) {
+ const TQRgb * const rgb = image.colorTable();
+ for (uint y = 0; y < h; ++y) {
+ const uchar *iptr = image.scanLine(y);
+ for (uint x = 0; x < w; ++x)
+ *aptr++ = tqAlpha(rgb[*iptr++]);
+ }
+ }
+
+ GC gc = XCreateGC(x11Display(), data->alphapm->hd, 0, 0);
+ XPutImage(dpy, data->alphapm->hd, gc, axi, 0, 0, 0, 0, w, h);
+ XFreeGC(x11Display(), gc);
+ qSafeXDestroyImage(axi);
+ }
+ }
+#endif // TQT_NO_XFTFREETYPE
+ }
+
+ return TRUE;
+}
+
+
+/*!
+ Grabs the contents of the window \a window and makes a pixmap out
+ of it. Returns the pixmap.
+
+ The arguments \a (x, y) specify the offset in the window, whereas
+ \a (w, h) specify the width and height of the area to be copied.
+
+ If \a w is negative, the function copies everything to the right
+ border of the window. If \a h is negative, the function copies
+ everything to the bottom of the window.
+
+ Note that grabWindow() grabs pixels from the screen, not from the
+ window. If there is another window partially or entirely over the
+ one you grab, you get pixels from the overlying window, too.
+
+ Note also that the mouse cursor is generally not grabbed.
+
+ The reason we use a window identifier and not a TQWidget is to
+ enable grabbing of windows that are not part of the application,
+ window system frames, and so on.
+
+ \warning Grabbing an area outside the screen is not safe in
+ general. This depends on the underlying window system.
+
+ \warning X11 only: If \a window is not the same depth as the root
+ window and another window partially or entirely obscures the one
+ you grab, you will \e not get pixels from the overlying window.
+ The contests of the obscured areas in the pixmap are undefined and
+ uninitialized.
+
+ \sa grabWidget()
+*/
+
+TQPixmap TQPixmap::grabWindow( WId window, int x, int y, int w, int h )
+{
+ if ( w == 0 || h == 0 )
+ return TQPixmap();
+
+ Display *dpy = x11AppDisplay();
+ XWindowAttributes window_attr;
+ if ( ! XGetWindowAttributes( dpy, window, &window_attr ) )
+ return TQPixmap();
+
+ if ( w < 0 )
+ w = window_attr.width - x;
+ if ( h < 0 )
+ h = window_attr.height - y;
+
+ // determine the screen
+ int scr;
+ for ( scr = 0; scr < ScreenCount( dpy ); ++scr ) {
+ if ( window_attr.root == RootWindow( dpy, scr ) ) // found it
+ break;
+ }
+ if ( scr >= ScreenCount( dpy ) ) // sanity check
+ return TQPixmap();
+
+
+ // get the depth of the root window
+ XWindowAttributes root_attr;
+ if ( ! XGetWindowAttributes( dpy, window_attr.root, &root_attr ) )
+ return TQPixmap();
+
+ if ( window_attr.depth == root_attr.depth ) {
+ // if the depth of the specified window and the root window are the
+ // same, grab pixels from the root window (so that we get the any
+ // overlapping windows and window manager frames)
+
+ // map x and y to the root window
+ WId unused;
+ if ( ! XTranslateCoordinates( dpy, window, window_attr.root, x, y,
+ &x, &y, &unused ) )
+ return TQPixmap();
+
+ window = window_attr.root;
+ }
+
+ TQPixmap pm( w, h );
+ pm.data->uninit = FALSE;
+ pm.x11SetScreen( scr );
+
+ GC gc = qt_xget_temp_gc( scr, FALSE );
+ XSetSubwindowMode( dpy, gc, IncludeInferiors );
+ XCopyArea( dpy, window, pm.handle(), gc, x, y, w, h, 0, 0 );
+ XSetSubwindowMode( dpy, gc, ClipByChildren );
+
+ return pm;
+}
+
+/*!
+ Returns a copy of the pixmap that is transformed using \a matrix.
+ The original pixmap is not changed.
+
+ The transformation \a matrix is internally adjusted to compensate
+ for unwanted translation, i.e. xForm() returns the smallest image
+ that tqcontains all the transformed points of the original image.
+
+ This function is slow because it involves transformation to a
+ TQImage, non-trivial computations and a transformation back to a
+ TQPixmap.
+
+ \sa trueMatrix(), TQWMatrix, TQPainter::setWorldMatrix() TQImage::xForm()
+*/
+
+TQPixmap TQPixmap::xForm( const TQWMatrix &matrix ) const
+{
+ uint w = 0;
+ uint h = 0; // size of target pixmap
+ uint ws, hs; // size of source pixmap
+ uchar *dptr; // data in target pixmap
+ uint dbpl, dbytes; // bytes per line/bytes total
+ uchar *sptr; // data in original pixmap
+ int sbpl; // bytes per line in original
+ int bpp; // bits per pixel
+ bool depth1 = depth() == 1;
+ Display *dpy = x11Display();
+
+ if ( isNull() ) // this is a null pixmap
+ return copy();
+
+ ws = width();
+ hs = height();
+
+ TQWMatrix mat( matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), 0., 0. );
+
+ double scaledWidth;
+ double scaledHeight;
+
+ if ( matrix.m12() == 0.0F && matrix.m21() == 0.0F ) {
+ if ( matrix.m11() == 1.0F && matrix.m22() == 1.0F )
+ return *this; // identity matrix
+ scaledHeight = matrix.m22()*hs;
+ scaledWidth = matrix.m11()*ws;
+ h = TQABS( tqRound( scaledHeight ) );
+ w = TQABS( tqRound( scaledWidth ) );
+ } else { // rotation or shearing
+ TQPointArray a( TQRect(0,0,ws+1,hs+1) );
+ a = mat.map( a );
+ TQRect r = a.boundingRect().normalize();
+ w = r.width()-1;
+ h = r.height()-1;
+ scaledWidth = w;
+ scaledHeight = h;
+ }
+
+ mat = trueMatrix( mat, ws, hs ); // true matrix
+
+
+ bool invertible;
+ mat = mat.invert( &invertible ); // invert matrix
+
+ if ( h == 0 || w == 0 || !invertible
+ || TQABS(scaledWidth) >= 32768 || TQABS(scaledHeight) >= 32768 ) { // error, return null pixmap
+ TQPixmap pm;
+ pm.data->bitmap = data->bitmap;
+ return pm;
+ }
+
+#if defined(TQT_MITSHM)
+ static bool try_once = TRUE;
+ if (try_once) {
+ try_once = FALSE;
+ if ( !xshminit )
+ qt_create_mitshm_buffer( this, 800, 600 );
+ }
+
+ bool use_mitshm = xshmimg && !depth1 &&
+ xshmimg->width >= w && xshmimg->height >= h;
+#endif
+ XImage *xi = (XImage*)data->ximage; // any cached ximage?
+ if ( !xi )
+ xi = XGetImage( x11Display(), handle(), 0, 0, ws, hs, AllPlanes,
+ depth1 ? XYPixmap : ZPixmap );
+
+ if ( !xi ) { // error, return null pixmap
+ TQPixmap pm;
+ pm.data->bitmap = data->bitmap;
+ pm.data->alphapm = data->alphapm;
+ return pm;
+ }
+
+ sbpl = xi->bytes_per_line;
+ sptr = (uchar *)xi->data;
+ bpp = xi->bits_per_pixel;
+
+ if ( depth1 )
+ dbpl = (w+7)/8;
+ else
+ dbpl = ((w*bpp+31)/32)*4;
+ dbytes = dbpl*h;
+
+#if defined(TQT_MITSHM)
+ if ( use_mitshm ) {
+ dptr = (uchar *)xshmimg->data;
+ uchar fillbyte = bpp == 8 ? white.pixel() : 0xff;
+ for ( int y=0; y<h; y++ )
+ memset( dptr + y*xshmimg->bytes_per_line, fillbyte, dbpl );
+ } else {
+#endif
+ dptr = (uchar *)malloc( dbytes ); // create buffer for bits
+ TQ_CHECK_PTR( dptr );
+ if ( depth1 ) // fill with zeros
+ memset( dptr, 0, dbytes );
+ else if ( bpp == 8 ) // fill with background color
+ memset( dptr, TQt::white.pixel( x11Screen() ), dbytes );
+ else
+ memset( dptr, 0xff, dbytes );
+#if defined(TQT_MITSHM)
+ }
+#endif
+
+ // #define TQT_DEBUG_XIMAGE
+#if defined(TQT_DEBUG_XIMAGE)
+ qDebug( "----IMAGE--INFO--------------" );
+ qDebug( "width............. %d", xi->width );
+ qDebug( "height............ %d", xi->height );
+ qDebug( "xoffset........... %d", xi->xoffset );
+ qDebug( "format............ %d", xi->format );
+ qDebug( "byte order........ %d", xi->byte_order );
+ qDebug( "bitmap unit....... %d", xi->bitmap_unit );
+ qDebug( "bitmap bit order.. %d", xi->bitmap_bit_order );
+ qDebug( "depth............. %d", xi->depth );
+ qDebug( "bytes per line.... %d", xi->bytes_per_line );
+ qDebug( "bits per pixel.... %d", xi->bits_per_pixel );
+#endif
+
+ int type;
+ if ( xi->bitmap_bit_order == MSBFirst )
+ type = TQT_XFORM_TYPE_MSBFIRST;
+ else
+ type = TQT_XFORM_TYPE_LSBFIRST;
+ int xbpl, p_inc;
+ if ( depth1 ) {
+ xbpl = (w+7)/8;
+ p_inc = dbpl - xbpl;
+ } else {
+ xbpl = (w*bpp)/8;
+ p_inc = dbpl - xbpl;
+#if defined(TQT_MITSHM)
+ if ( use_mitshm )
+ p_inc = xshmimg->bytes_per_line - xbpl;
+#endif
+ }
+
+ if ( !qt_xForm_helper( mat, xi->xoffset, type, bpp, dptr, xbpl, p_inc, h, sptr, sbpl, ws, hs ) ){
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPixmap::xForm: display not supported (bpp=%d)",bpp);
+#endif
+ TQPixmap pm;
+ return pm;
+ }
+
+ if ( data->optim == NoOptim ) { // throw away ximage
+ qSafeXDestroyImage( xi );
+ data->ximage = 0;
+ } else { // keep ximage that we fetched
+ data->ximage = xi;
+ }
+
+ if ( depth1 ) { // mono bitmap
+ TQPixmap pm( w, h, dptr, TQImage::systemBitOrder() != TQImage::BigEndian );
+ pm.data->bitmap = data->bitmap;
+ free( dptr );
+ if ( data->tqmask ) {
+ if ( data->selfmask ) // pixmap == tqmask
+ pm.setMask( *((TQBitmap*)(&pm)) );
+ else
+ pm.setMask( data->tqmask->xForm(matrix) );
+ }
+ return pm;
+ } else { // color pixmap
+ GC gc = qt_xget_readonly_gc( x11Screen(), FALSE );
+ TQPixmap pm( w, h );
+ pm.data->uninit = FALSE;
+ pm.x11SetScreen( x11Screen() );
+#if defined(TQT_MITSHM)
+ if ( use_mitshm ) {
+ XCopyArea( dpy, xshmpm, pm.handle(), gc, 0, 0, w, h, 0, 0 );
+ } else {
+#endif
+ xi = XCreateImage( dpy, (Visual *)x11Visual(), x11Depth(),
+ ZPixmap, 0, (char *)dptr, w, h, 32, 0 );
+ XPutImage( dpy, pm.handle(), gc, xi, 0, 0, 0, 0, w, h);
+ qSafeXDestroyImage( xi );
+#if defined(TQT_MITSHM)
+ }
+#endif
+
+ if ( data->tqmask ) // xform tqmask, too
+ pm.setMask( data->tqmask->xForm(matrix) );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( qt_use_xrender && qt_has_xft && data->alphapm ) { // xform the alpha channel
+ XImage *axi = 0;
+ if ((axi = XGetImage(x11Display(), data->alphapm->handle(),
+ 0, 0, ws, hs, AllPlanes, ZPixmap))) {
+ sbpl = axi->bytes_per_line;
+ sptr = (uchar *) axi->data;
+ bpp = axi->bits_per_pixel;
+ dbytes = dbpl * h;
+ dptr = (uchar *) malloc(dbytes);
+ TQ_CHECK_PTR( dptr );
+ memset(dptr, 0, dbytes);
+ if ( axi->bitmap_bit_order == MSBFirst )
+ type = TQT_XFORM_TYPE_MSBFIRST;
+ else
+ type = TQT_XFORM_TYPE_LSBFIRST;
+
+ if (qt_xForm_helper( mat, axi->xoffset, type, bpp, dptr, w,
+ 0, h, sptr, sbpl, ws, hs )) {
+ delete pm.data->alphapm;
+ pm.data->alphapm = new TQPixmap; // create a null pixmap
+
+ // setup pixmap data
+ pm.data->alphapm->data->w = w;
+ pm.data->alphapm->data->h = h;
+ pm.data->alphapm->data->d = 8;
+
+ // create 8bpp pixmap and render picture
+ pm.data->alphapm->hd =
+ XCreatePixmap(x11Display(),
+ RootWindow(x11Display(), x11Screen()),
+ w, h, 8);
+
+ pm.data->alphapm->rendhd =
+ (HANDLE) XftDrawCreateAlpha( x11Display(),
+ pm.data->alphapm->hd, 8 );
+
+ XImage *axi2 = XCreateImage(x11Display(), (Visual *) x11Visual(),
+ 8, ZPixmap, 0, (char *)dptr, w, h, 8, 0);
+
+ if (axi2) {
+ // the data is deleted by qSafeXDestroyImage
+ GC gc = XCreateGC(x11Display(), pm.data->alphapm->hd, 0, 0);
+ XPutImage(dpy, pm.data->alphapm->hd, gc, axi2, 0, 0, 0, 0, w, h);
+ XFreeGC(x11Display(), gc);
+ qSafeXDestroyImage(axi2);
+ }
+ }
+ qSafeXDestroyImage(axi);
+ }
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ return pm;
+ }
+}
+
+
+/*!
+ \internal
+*/
+int TQPixmap::x11SetDefaultScreen( int screen )
+{
+ int old = defaultScreen;
+ defaultScreen = screen;
+ return old;
+}
+
+/*!
+ \internal
+*/
+void TQPixmap::x11SetScreen( int screen )
+{
+ if ( screen < 0 )
+ screen = x11AppScreen();
+
+ if ( screen == x11Screen() )
+ return; // nothing to do
+
+ if ( isNull() ) {
+ TQPaintDeviceX11Data* xd = getX11Data( TRUE );
+ xd->x_screen = screen;
+ xd->x_depth = TQPaintDevice::x11AppDepth( screen );
+ xd->x_cells = TQPaintDevice::x11AppCells( screen );
+ xd->x_colormap = TQPaintDevice::x11AppColormap( screen );
+ xd->x_defcolormap = TQPaintDevice::x11AppDefaultColormap( screen );
+ xd->x_visual = TQPaintDevice::x11AppVisual( screen );
+ xd->x_defvisual = TQPaintDevice::x11AppDefaultVisual( screen );
+ setX11Data( xd );
+ return;
+ }
+#if 0
+ qDebug("TQPixmap::x11SetScreen for %p from %d to %d. Size is %d/%d", data, x11Screen(), screen, width(), height() );
+#endif
+
+ TQImage img = convertToImage();
+ resize(0,0);
+ TQPaintDeviceX11Data* xd = getX11Data( TRUE );
+ xd->x_screen = screen;
+ xd->x_depth = TQPaintDevice::x11AppDepth( screen );
+ xd->x_cells = TQPaintDevice::x11AppCells( screen );
+ xd->x_colormap = TQPaintDevice::x11AppColormap( screen );
+ xd->x_defcolormap = TQPaintDevice::x11AppDefaultColormap( screen );
+ xd->x_visual = TQPaintDevice::x11AppVisual( screen );
+ xd->x_defvisual = TQPaintDevice::x11AppDefaultVisual( screen );
+ setX11Data( xd );
+ convertFromImage( img );
+}
+
+/*!
+ Returns TRUE this pixmap has an alpha channel or a tqmask.
+
+ \sa hasAlphaChannel() tqmask()
+*/
+bool TQPixmap::hasAlpha() const
+{
+ return data->alphapm || data->tqmask;
+}
+
+/*!
+ Returns TRUE if the pixmap has an alpha channel; otherwise it
+ returns FALSE.
+
+ NOTE: If the pixmap has a tqmask but not alpha channel, this
+ function returns FALSE.
+
+ \sa hasAlpha() tqmask()
+*/
+bool TQPixmap::hasAlphaChannel() const
+{
+ return data->alphapm != 0;
+}
+
+/*!
+ \relates TQPixmap
+
+ Copies a block of pixels from \a src to \a dst. The alpha channel
+ and tqmask data (if any) is also copied from \a src. NOTE: \a src
+ is \e not alpha blended or masked when copied to \a dst. Use
+ bitBlt() or TQPainter::drawPixmap() to perform alpha blending or
+ masked drawing.
+
+ \a sx, \a sy is the top-left pixel in \a src (0, 0 by default), \a
+ dx, \a dy is the top-left position in \a dst and \a sw, \sh is the
+ size of the copied block (all of \a src by default).
+
+ If \a src, \a dst, \a sw or \a sh is 0 (zero), copyBlt() does
+ nothing. If \a sw or \a sh is negative, copyBlt() copies starting
+ at \a sx (and respectively, \a sy) and ending at the right edge
+ (and respectively, the bottom edge) of \a src.
+
+ copyBlt() does nothing if \a src and \a dst have different depths.
+*/
+TQ_EXPORT void copyBlt( TQPixmap *dst, int dx, int dy,
+ const TQPixmap *src, int sx, int sy, int sw, int sh )
+{
+ if ( ! dst || ! src || sw == 0 || sh == 0 || dst->depth() != src->depth() ) {
+#ifdef TQT_CHECK_NULL
+ TQ_ASSERT( dst != 0 );
+ TQ_ASSERT( src != 0 );
+#endif
+ return;
+ }
+
+ // copy pixel data
+ bitBlt( dst, dx, dy, src, sx, sy, sw, sh, TQt::CopyROP, TRUE );
+
+ // copy tqmask data
+ if ( src->data->tqmask ) {
+ if ( ! dst->data->tqmask ) {
+ dst->data->tqmask = new TQBitmap( dst->width(), dst->height() );
+
+ // new masks are fully opaque by default
+ dst->data->tqmask->fill( TQt::color1 );
+ }
+
+ bitBlt( dst->data->tqmask, dx, dy,
+ src->data->tqmask, sx, sy, sw, sh, TQt::CopyROP, TRUE );
+ }
+
+#ifndef TQT_NO_XFTFREETYPE
+ // copy alpha data
+ extern bool qt_use_xrender; // from qapplication_x11.cpp
+ if ( ! qt_use_xrender || ! src->data->alphapm )
+ return;
+
+ if ( sw < 0 )
+ sw = src->width() - sx;
+ else
+ sw = TQMIN( src->width()-sx, sw );
+ sw = TQMIN( dst->width()-dx, sw );
+
+ if ( sh < 0 )
+ sh = src->height() - sy ;
+ else
+ sh = TQMIN( src->height()-sy, sh );
+ sh = TQMIN( dst->height()-dy, sh );
+
+ if ( sw <= 0 || sh <= 0 )
+ return;
+
+ // create an alpha pixmap for dst if it doesn't exist
+ bool do_init = FALSE;
+ if ( ! dst->data->alphapm ) {
+ dst->data->alphapm = new TQPixmap;
+
+ // setup pixmap d
+ dst->data->alphapm->data->w = dst->width();
+ dst->data->alphapm->data->h = dst->height();
+ dst->data->alphapm->data->d = 8;
+
+ // create 8bpp pixmap and render picture
+ dst->data->alphapm->hd =
+ XCreatePixmap(dst->x11Display(),
+ RootWindow(dst->x11Display(), dst->x11Screen()),
+ dst->width(), dst->height(), 8);
+
+ // new alpha pixmaps should be fully opaque by default
+ do_init = TRUE;
+
+ dst->data->alphapm->rendhd =
+ (TQt::HANDLE) XftDrawCreateAlpha( dst->x11Display(),
+ dst->data->alphapm->hd, 8 );
+ }
+
+ GC gc = XCreateGC(dst->x11Display(), dst->data->alphapm->hd, 0, 0);
+
+ if ( do_init ) {
+ // the alphapm was just created, make it fully opaque
+ XSetForeground( dst->x11Display(), gc, 255 );
+ XSetBackground( dst->x11Display(), gc, 255 );
+ XFillRectangle( dst->x11Display(), dst->data->alphapm->hd, gc,
+ 0, 0, dst->data->alphapm->data->w,
+ dst->data->alphapm->data->h );
+ }
+
+ XCopyArea(dst->x11Display(), src->data->alphapm->hd, dst->data->alphapm->hd, gc,
+ sx, sy, sw, sh, dx, dy);
+ XFreeGC(dst->x11Display(), gc);
+#endif // TQT_NO_XFTFREETYPE
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpixmapcache.cpp b/tqtinterface/qt4/src/kernel/tqpixmapcache.cpp
new file mode 100644
index 0000000..6724d82
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpixmapcache.cpp
@@ -0,0 +1,336 @@
+/****************************************************************************
+**
+** Implementation of TQPixmapCache class
+**
+** Created : 950504
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpixmapcache.h"
+#include "tqcache.h"
+#include "tqobject.h"
+#include "tqcleanuphandler.h"
+
+
+// REVISED: paul
+/*!
+ \class TQPixmapCache tqpixmapcache.h
+
+ \brief The TQPixmapCache class provides an application-global cache for
+ pixmaps.
+
+ \ingroup environment
+ \ingroup graphics
+ \ingroup images
+
+ This class is a tool for optimized drawing with TQPixmap. You can
+ use it to store temporary pixmaps that are expensive to generate
+ without using more storage space than cacheLimit(). Use insert()
+ to insert pixmaps, tqfind() to tqfind them and clear() to empty the
+ cache.
+
+ For example, TQRadioButton has a non-trivial visual representation
+ so we don't want to regenerate a pixmap whenever a radio button is
+ displayed or changes state. In the function
+ TQRadioButton::drawButton(), we do not draw the radio button
+ directly. Instead, we first check the global pixmap cache for a
+ pixmap with the key "$qt_radio_nnn_", where \c nnn is a numerical
+ value that specifies the the radio button state. If a pixmap is
+ found, we bitBlt() it onto the widget and return. Otherwise, we
+ create a new pixmap, draw the radio button in the pixmap, and
+ finally insert the pixmap in the global pixmap cache, using the
+ key above. The bitBlt() is ten times faster than drawing the
+ radio button. All radio buttons in the program share the cached
+ pixmap since TQPixmapCache is application-global.
+
+ TQPixmapCache tqcontains no member data, only static functions to
+ access the global pixmap cache. It creates an internal TQCache for
+ caching the pixmaps.
+
+ The cache associates a pixmap with a string (key). If two pixmaps
+ are inserted into the cache using equal keys, then the last pixmap
+ will hide the first pixmap. The TQDict and TQCache classes do
+ exactly the same.
+
+ The cache becomes full when the total size of all pixmaps in the
+ cache exceeds cacheLimit(). The initial cache limit is 1024 KByte
+ (1 MByte); it is changed with setCacheLimit(). A pixmap takes
+ roughly width*height*depth/8 bytes of memory.
+
+ See the \l TQCache documentation for more details about the cache
+ mechanism.
+*/
+
+
+static const int cache_size = 149; // size of internal hash array
+#ifdef TQ_WS_MAC9
+static int cache_limit = 256; // 256 KB cache limit
+#else
+static int cache_limit = 1024; // 1024 KB cache limit
+#endif
+
+class TQPMCache: public TQObject, public TQCache<TQPixmap>
+{
+public:
+ TQPMCache():
+ TQObject( 0, "global pixmap cache" ),
+ TQCache<TQPixmap>( cache_limit * 1024, cache_size ),
+ id( 0 ), ps( 0 ), t( FALSE )
+ {
+ setAutoDelete( TRUE );
+ }
+ ~TQPMCache() {}
+ void timerEvent( TQTimerEvent * );
+ bool insert( const TQString& k, const TQPixmap *d, int c, int p = 0 );
+private:
+ int id;
+ int ps;
+ bool t;
+};
+
+
+/*
+ This is supposed to cut the cache size down by about 80-90% in a
+ minute once the application becomes idle, to let any inserted pixmap
+ remain in the cache for some time before it becomes a candidate for
+ cleaning-up, and to not cut down the size of the cache while the
+ cache is in active use.
+
+ When the last pixmap has been deleted from the cache, kill the
+ timer so TQt won't keep the CPU from going into sleep mode.
+*/
+
+void TQPMCache::timerEvent( TQTimerEvent * )
+{
+ int mc = maxCost();
+ bool nt = totalCost() == ps;
+ setMaxCost( nt ? totalCost() * 3 / 4 : totalCost() -1 );
+ setMaxCost( mc );
+ ps = totalCost();
+
+ if ( !count() ) {
+ killTimer( id );
+ id = 0;
+ } else if ( nt != t ) {
+ killTimer( id );
+ id = startTimer( nt ? 10000 : 30000 );
+ t = nt;
+ }
+}
+
+bool TQPMCache::insert( const TQString& k, const TQPixmap *d, int c, int p )
+{
+ bool r = TQCache<TQPixmap>::insert( k, d, c, p );
+ if ( r && !id ) {
+ id = startTimer( 30000 );
+ t = FALSE;
+ }
+ return r;
+}
+
+static TQPMCache *pm_cache = 0; // global pixmap cache
+
+static TQSingleCleanupHandler<TQPMCache> qpm_cleanup_cache;
+
+/*!
+ Returns the pixmap associated with the \a key in the cache, or
+ null if there is no such pixmap.
+
+ \warning If valid, you should copy the pixmap immediately (this is
+ fast). Subsequent insertions into the cache could cause the
+ pointer to become invalid. For this reason, we recommend you use
+ tqfind(const TQString&, TQPixmap&) instead.
+
+ Example:
+ \code
+ TQPixmap* pp;
+ TQPixmap p;
+ if ( (pp=TQPixmapCache::tqfind("my_big_image", pm)) ) {
+ p = *pp;
+ } else {
+ p.load("bigimage.png");
+ TQPixmapCache::insert("my_big_image", new TQPixmap(p));
+ }
+ painter->drawPixmap(0, 0, p);
+ \endcode
+*/
+
+TQPixmap *TQPixmapCache::tqfind( const TQString &key )
+{
+ return pm_cache ? pm_cache->tqfind(key) : 0;
+}
+
+
+/*!
+ \overload
+
+ Looks for a cached pixmap associated with the \a key in the cache.
+ If a pixmap is found, the function sets \a pm to that pixmap and
+ returns TRUE; otherwise leaves \a pm alone and returns FALSE.
+
+ Example:
+ \code
+ TQPixmap p;
+ if ( !TQPixmapCache::tqfind("my_big_image", pm) ) {
+ pm.load("bigimage.png");
+ TQPixmapCache::insert("my_big_image", pm);
+ }
+ painter->drawPixmap(0, 0, p);
+ \endcode
+*/
+
+bool TQPixmapCache::tqfind( const TQString &key, TQPixmap& pm )
+{
+ TQPixmap* p = pm_cache ? pm_cache->tqfind(key) : 0;
+ if ( p ) pm = *p;
+ return !!p;
+}
+
+
+/*!
+ \obsolete
+ Inserts the pixmap \a pm associated with \a key into the cache.
+ Returns TRUE if successful, or FALSE if the pixmap is too big for the cache.
+
+ <strong>
+ Note: \a pm must be allocated on the heap (using \c new).
+
+ If this function returns FALSE, you must delete \a pm yourself.
+
+ If this function returns TRUE, do not use \a pm afterwards or
+ keep references to it because any other insertions into the cache,
+ whether from anywhere in the application or within TQt itself, could cause
+ the pixmap to be discarded from the cache and the pointer to
+ become invalid.
+
+ Due to these dangers, we strongly recommend that you use
+ insert(const TQString&, const TQPixmap&) instead.
+ </strong>
+*/
+
+bool TQPixmapCache::insert( const TQString &key, TQPixmap *pm )
+{
+ if ( !pm_cache ) { // create pixmap cache
+ pm_cache = new TQPMCache;
+ TQ_CHECK_PTR( pm_cache );
+ qpm_cleanup_cache.set( &pm_cache );
+ }
+ return pm_cache->insert( key, pm, pm->width()*pm->height()*pm->depth()/8 );
+}
+
+/*!
+ Inserts a copy of the pixmap \a pm associated with the \a key into
+ the cache.
+
+ All pixmaps inserted by the TQt library have a key starting with
+ "$qt", so your own pixmap keys should never begin "$qt".
+
+ When a pixmap is inserted and the cache is about to exceed its
+ limit, it removes pixmaps until there is enough room for the
+ pixmap to be inserted.
+
+ The oldest pixmaps (least recently accessed in the cache) are
+ deleted when more space is needed.
+
+ \sa setCacheLimit().
+*/
+
+bool TQPixmapCache::insert( const TQString &key, const TQPixmap& pm )
+{
+ if ( !pm_cache ) { // create pixmap cache
+ pm_cache = new TQPMCache;
+ TQ_CHECK_PTR( pm_cache );
+ qpm_cleanup_cache.set( &pm_cache );
+ }
+ TQPixmap *p = new TQPixmap(pm);
+ bool rt = pm_cache->insert( key, p, p->width()*p->height()*p->depth()/8 );
+ if ( !rt )
+ delete p;
+
+ return rt;
+}
+
+/*!
+ Returns the cache limit (in kilobytes).
+
+ The default setting is 1024 kilobytes.
+
+ \sa setCacheLimit().
+*/
+
+int TQPixmapCache::cacheLimit()
+{
+ return cache_limit;
+}
+
+/*!
+ Sets the cache limit to \a n kilobytes.
+
+ The default setting is 1024 kilobytes.
+
+ \sa cacheLimit()
+*/
+
+void TQPixmapCache::setCacheLimit( int n )
+{
+#ifdef TQ_WS_MAC9
+ if(n > 256)
+ qWarning("TQPixmapCache::setCacheLimit: Setting cache limits high is harmfull to mac9's health");
+#endif
+ cache_limit = n;
+ if ( pm_cache )
+ pm_cache->setMaxCost( 1024*cache_limit );
+}
+
+
+/*!
+ Removes the pixmap associated with \a key from the cache.
+*/
+void TQPixmapCache::remove( const TQString &key )
+{
+ if ( pm_cache )
+ pm_cache->remove( key );
+}
+
+
+/*!
+ Removes all pixmaps from the cache.
+*/
+
+void TQPixmapCache::clear()
+{
+ if ( pm_cache )
+ pm_cache->clear();
+}
diff --git a/tqtinterface/qt4/src/kernel/tqpixmapcache.h b/tqtinterface/qt4/src/kernel/tqpixmapcache.h
new file mode 100644
index 0000000..ba543ac
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpixmapcache.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Definition of TQPixmapCache class
+**
+** Created : 950501
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPIXMAPCACHE_H
+#define TQPIXMAPCACHE_H
+
+#ifndef TQT_H
+#include "tqpixmap.h"
+#endif // TQT_H
+
+
+class TQ_EXPORT TQPixmapCache // global pixmap cache
+{
+public:
+ static int cacheLimit();
+ static void setCacheLimit( int );
+ static TQPixmap *tqfind( const TQString &key );
+ static bool tqfind( const TQString &key, TQPixmap& );
+ static bool insert( const TQString &key, TQPixmap * );
+ static bool insert( const TQString &key, const TQPixmap& );
+ static void remove( const TQString &key );
+ static void clear();
+};
+
+
+#endif // TQPIXMAPCACHE_H
diff --git a/tqtinterface/qt4/src/kernel/tqpngio.cpp b/tqtinterface/qt4/src/kernel/tqpngio.cpp
new file mode 100644
index 0000000..7c8cf1d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpngio.cpp
@@ -0,0 +1,1250 @@
+/****************************************************************************
+**
+** Implementation of PNG TQImage IOHandler
+**
+** Created : 970521
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpngio.h"
+
+#ifndef TQT_NO_IMAGEIO_PNG
+
+#include "tqasyncimageio.h"
+#include "tqiodevice.h"
+
+#include <png.h>
+
+
+#ifdef TQ_OS_TEMP
+#define CALLBACK_CALL_TYPE __cdecl
+#else
+#define CALLBACK_CALL_TYPE
+#endif
+
+
+/*
+ All PNG files load to the minimal TQImage equivalent.
+
+ All TQImage formats output to reasonably efficient PNG equivalents.
+ Never to grayscale.
+*/
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static
+void CALLBACK_CALL_TYPE iod_read_fn(png_structp png_ptr, png_bytep data, png_size_t length)
+{
+ TQImageIO* iio = (TQImageIO*)png_get_io_ptr(png_ptr);
+ TQIODevice* in = iio->ioDevice();
+
+ while (length) {
+ int nr = in->readBlock((char*)data, length);
+ if (nr <= 0) {
+ png_error(png_ptr, "Read Error");
+ return;
+ }
+ length -= nr;
+ }
+}
+
+
+static
+void CALLBACK_CALL_TYPE qpiw_write_fn( png_structp png_ptr, png_bytep data, png_size_t length )
+{
+ TQPNGImageWriter* qpiw = (TQPNGImageWriter*)png_get_io_ptr( png_ptr );
+ TQIODevice* out = qpiw->tqdevice();
+
+ uint nr = out->writeBlock( (char*)data, length );
+ if ( nr != length ) {
+ png_error( png_ptr, "Write Error" );
+ return;
+ }
+}
+
+
+static
+void CALLBACK_CALL_TYPE qpiw_flush_fn( png_structp png_ptr )
+{
+ TQPNGImageWriter* qpiw = (TQPNGImageWriter*)png_get_io_ptr( png_ptr );
+ TQIODevice* out = qpiw->tqdevice();
+
+ out->flush();
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+static
+void setup_qt( TQImage& image, png_structp png_ptr, png_infop info_ptr, float screen_gamma=0.0 )
+{
+ if ( screen_gamma != 0.0 && png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA) ) {
+ double file_gamma;
+ png_get_gAMA(png_ptr, info_ptr, &file_gamma);
+ png_set_gamma( png_ptr, screen_gamma, file_gamma );
+ }
+
+ png_uint_32 width;
+ png_uint_32 height;
+ int bit_depth;
+ int color_type;
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
+ 0, 0, 0);
+
+ if ( color_type == PNG_COLOR_TYPE_GRAY ) {
+ // Black & White or 8-bit grayscale
+ if ( bit_depth == 1 && info_ptr->channels == 1 ) {
+ png_set_invert_mono( png_ptr );
+ png_read_update_info( png_ptr, info_ptr );
+ if (!image.create( width, height, 1, 2, TQImage::BigEndian ))
+ return;
+ image.setColor( 1, tqRgb(0,0,0) );
+ image.setColor( 0, tqRgb(255,255,255) );
+ } else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ png_set_expand(png_ptr);
+ png_set_strip_16(png_ptr);
+ png_set_gray_to_rgb(png_ptr);
+
+ if (!image.create(width, height, 32))
+ return;
+ image.setAlphaBuffer(TRUE);
+
+ if (TQImage::systemByteOrder() == TQImage::BigEndian)
+ png_set_swap_alpha(png_ptr);
+
+ png_read_update_info(png_ptr, info_ptr);
+ } else {
+ if ( bit_depth == 16 )
+ png_set_strip_16(png_ptr);
+ else if ( bit_depth < 8 )
+ png_set_packing(png_ptr);
+ int ncols = bit_depth < 8 ? 1 << bit_depth : 256;
+ png_read_update_info(png_ptr, info_ptr);
+ if (!image.create(width, height, 8, ncols))
+ return;
+ for (int i=0; i<ncols; i++) {
+ int c = i*255/(ncols-1);
+ image.setColor( i, tqRgba(c,c,c,0xff) );
+ }
+ if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
+ const int g = info_ptr->trans_values.gray;
+ if (g < ncols) {
+ image.setAlphaBuffer(TRUE);
+ image.setColor(g, image.color(g) & TQRGB_MASK);
+ }
+ }
+ }
+ } else if ( color_type == PNG_COLOR_TYPE_PALETTE
+ && png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)
+ && info_ptr->num_palette <= 256 )
+ {
+ // 1-bit and 8-bit color
+ if ( bit_depth != 1 )
+ png_set_packing( png_ptr );
+ png_read_update_info( png_ptr, info_ptr );
+ png_get_IHDR(png_ptr, info_ptr,
+ &width, &height, &bit_depth, &color_type, 0, 0, 0);
+ if (!image.create(width, height, bit_depth, info_ptr->num_palette,
+ TQImage::BigEndian))
+ return;
+ int i = 0;
+ if ( png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ) {
+ image.setAlphaBuffer( TRUE );
+ while ( i < info_ptr->num_trans ) {
+ image.setColor(i, tqRgba(
+ info_ptr->palette[i].red,
+ info_ptr->palette[i].green,
+ info_ptr->palette[i].blue,
+ info_ptr->trans[i]
+ )
+ );
+ i++;
+ }
+ }
+ while ( i < info_ptr->num_palette ) {
+ image.setColor(i, tqRgba(
+ info_ptr->palette[i].red,
+ info_ptr->palette[i].green,
+ info_ptr->palette[i].blue,
+ 0xff
+ )
+ );
+ i++;
+ }
+ } else {
+ // 32-bit
+ if ( bit_depth == 16 )
+ png_set_strip_16(png_ptr);
+
+ png_set_expand(png_ptr);
+
+ if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
+ png_set_gray_to_rgb(png_ptr);
+
+ if (!image.create(width, height, 32))
+ return;
+
+ // Only add filler if no alpha, or we can get 5 channel data.
+ if (!(color_type & PNG_COLOR_MASK_ALPHA)
+ && !png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ png_set_filler(png_ptr, 0xff,
+ TQImage::systemByteOrder() == TQImage::BigEndian ?
+ PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
+ // We want 4 bytes, but it isn't an alpha channel
+ } else {
+ image.setAlphaBuffer(TRUE);
+ }
+
+ if ( TQImage::systemByteOrder() == TQImage::BigEndian ) {
+ png_set_swap_alpha(png_ptr);
+ }
+
+ png_read_update_info(png_ptr, info_ptr);
+ }
+
+ // TQt==ARGB==Big(ARGB)==Little(BGRA)
+ if ( TQImage::systemByteOrder() == TQImage::LittleEndian ) {
+ png_set_bgr(png_ptr);
+ }
+}
+
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+static void CALLBACK_CALL_TYPE qt_png_warning(png_structp /*png_ptr*/, png_const_charp message)
+{
+ qWarning("libpng warning: %s", message);
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+static
+void read_png_image(TQImageIO* iio)
+{
+ png_structp png_ptr;
+ png_infop info_ptr;
+ png_infop end_info;
+ png_bytep* row_pointers;
+
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
+ if (!png_ptr) {
+ iio->setqStatus(-1);
+ return;
+ }
+
+ png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
+ png_destroy_read_struct(&png_ptr, 0, 0);
+ iio->setqStatus(-2);
+ return;
+ }
+
+ end_info = png_create_info_struct(png_ptr);
+ if (!end_info) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+ iio->setqStatus(-3);
+ return;
+ }
+
+ if (setjmp(png_ptr->jmpbuf)) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ iio->setqStatus(-4);
+ return;
+ }
+
+ png_set_read_fn(png_ptr, (void*)iio, iod_read_fn);
+ png_read_info(png_ptr, info_ptr);
+
+ TQImage image;
+ setup_qt(image, png_ptr, info_ptr, iio->gamma());
+ if (image.isNull()) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ iio->setqStatus(-5);
+ return;
+ }
+
+ png_uint_32 width;
+ png_uint_32 height;
+ int bit_depth;
+ int color_type;
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
+ 0, 0, 0);
+
+#if 0 // Jump tables in Qt4 can't be used this way
+ uchar** jt = image.jumpTable();
+ row_pointers=new png_bytep[height];
+
+ for (uint y=0; y<height; y++) {
+ row_pointers[y]=jt[y];
+ }
+#else
+ row_pointers=new png_bytep[height];
+
+ for (uint y=0; y<height; y++) {
+ row_pointers[y]=image.scanLine(y);
+ }
+#endif
+
+ png_read_image(png_ptr, row_pointers);
+
+#if 0 // libpng takes care of this.
+png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)
+ if (image.depth()==32 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ TQRgb trans = 0xFF000000 | tqRgb(
+ (info_ptr->trans_values.red << 8 >> bit_depth)&0xff,
+ (info_ptr->trans_values.green << 8 >> bit_depth)&0xff,
+ (info_ptr->trans_values.blue << 8 >> bit_depth)&0xff);
+ for (uint y=0; y<height; y++) {
+ for (uint x=0; x<info_ptr->width; x++) {
+ if (((uint**)jt)[y][x] == trans) {
+ ((uint**)jt)[y][x] &= 0x00FFFFFF;
+ } else {
+ }
+ }
+ }
+ }
+#endif
+
+ image.setDotsPerMeterX(png_get_x_pixels_per_meter(png_ptr,info_ptr));
+ image.setDotsPerMeterY(png_get_y_pixels_per_meter(png_ptr,info_ptr));
+
+#ifndef TQT_NO_IMAGE_TEXT
+ png_textp text_ptr;
+ int num_text=0;
+ png_get_text(png_ptr,info_ptr,&text_ptr,&num_text);
+ while (num_text--) {
+ image.setText(text_ptr->key,0,text_ptr->text);
+ text_ptr++;
+ }
+#endif
+
+ delete [] row_pointers;
+
+ if ( image.hasAlphaBuffer() ) {
+ // Many PNG files lie (eg. from PhotoShop). Fortunately this loop will
+ // usually be quick to find those that tell the truth.
+ TQRgb* c;
+ int n;
+ if (image.depth()==32) {
+ c = (TQRgb*)image.bits();
+ n = image.bytesPerLine() * image.height() / 4;
+ } else {
+ c = image.tqcolorTable();
+ n = image.numColors();
+ }
+ while ( n-- && tqAlpha(*c++)==0xff )
+ ;
+ if ( n<0 ) // LIAR!
+ image.setAlphaBuffer(FALSE);
+ }
+
+ iio->setImage(image);
+
+ png_read_end(png_ptr, end_info);
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+
+ iio->setqStatus(0);
+}
+
+TQPNGImageWriter::TQPNGImageWriter(TQIODevice* iod) :
+ dev(iod),
+ frames_written(0),
+ disposal(Unspecified),
+ looping(-1),
+ ms_delay(-1),
+ gamma(0.0)
+{
+}
+
+TQPNGImageWriter::~TQPNGImageWriter()
+{
+}
+
+void TQPNGImageWriter::setDisposalMethod(DisposalMethod dm)
+{
+ disposal = dm;
+}
+
+void TQPNGImageWriter::setLooping(int loops)
+{
+ looping = loops;
+}
+
+void TQPNGImageWriter::setFrameDelay(int msecs)
+{
+ ms_delay = msecs;
+}
+
+void TQPNGImageWriter::setGamma(float g)
+{
+ gamma = g;
+}
+
+
+#ifndef TQT_NO_IMAGE_TEXT
+static void set_text(const TQImage& image, png_structp png_ptr, png_infop info_ptr, bool short_not_long)
+{
+ TQValueList<TQImageTextKeyLang> keys = image.tqtextList();
+ if ( keys.count() ) {
+ png_textp text_ptr = new png_text[keys.count()];
+ int i=0;
+ for (TQValueList<TQImageTextKeyLang>::Iterator it=keys.begin();
+ it != keys.end(); ++it)
+ {
+ TQString t = image.text(*it);
+ if ( (t.length() <= 200) == short_not_long ) {
+ if ( t.length() < 40 )
+ text_ptr[i].compression = PNG_TEXT_COMPRESSION_NONE;
+ else
+ text_ptr[i].compression = PNG_TEXT_COMPRESSION_zTXt;
+ text_ptr[i].key = (png_charp)(*it).key.data();
+ text_ptr[i].text = (png_charp)t.latin1();
+ //text_ptr[i].text = qstrdup(t.latin1());
+ i++;
+ }
+ }
+ png_set_text(png_ptr, info_ptr, text_ptr, i);
+ //for (int j=0; j<i; j++)
+ //free(text_ptr[i].text);
+ delete [] text_ptr;
+ }
+}
+#endif
+
+bool TQPNGImageWriter::writeImage(const TQImage& image, int off_x, int off_y)
+{
+ return writeImage(image, -1, off_x, off_y);
+}
+
+bool TQPNGImageWriter::writeImage(const TQImage& image, int quality_in, int off_x_in, int off_y_in)
+{
+ TQPoint offset = image.offset();
+ int off_x = off_x_in + offset.x();
+ int off_y = off_y_in + offset.y();
+
+ png_structp png_ptr;
+ png_infop info_ptr;
+ png_bytep* row_pointers;
+
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
+ if (!png_ptr) {
+ return FALSE;
+ }
+
+ png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
+ png_destroy_write_struct(&png_ptr, 0);
+ return FALSE;
+ }
+
+ if (setjmp(png_ptr->jmpbuf)) {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ return FALSE;
+ }
+
+ int quality = quality_in;
+ if (quality >= 0) {
+ if (quality > 9) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "PNG: Quality %d out of range", quality );
+#endif
+ quality = 9;
+ }
+ png_set_compression_level(png_ptr, quality);
+ }
+
+ if (gamma != 0.0) {
+ png_set_gAMA(png_ptr, info_ptr, 1.0/gamma);
+ }
+
+ png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn);
+
+ info_ptr->channels =
+ (image.depth() == 32)
+ ? (image.hasAlphaBuffer() ? 4 : 3)
+ : 1;
+
+ png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
+ image.depth() == 1 ? 1 : 8 /* per channel */,
+ image.depth() == 32
+ ? image.hasAlphaBuffer()
+ ? PNG_COLOR_TYPE_RGB_ALPHA
+ : PNG_COLOR_TYPE_RGB
+ : PNG_COLOR_TYPE_PALETTE, 0, 0, 0);
+
+
+ //png_set_sBIT(png_ptr, info_ptr, 8);
+ info_ptr->sig_bit.red = 8;
+ info_ptr->sig_bit.green = 8;
+ info_ptr->sig_bit.blue = 8;
+
+ if (image.depth() == 1 && image.bitOrder() == TQImage::LittleEndian)
+ png_set_packswap(png_ptr);
+
+ png_colorp palette = 0;
+ png_bytep copy_trans = 0;
+ if (image.numColors()) {
+ // Paletted
+ int num_palette = image.numColors();
+ palette = new png_color[num_palette];
+ png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
+ int* trans = new int[num_palette];
+ int num_trans = 0;
+ for (int i=0; i<num_palette; i++) {
+ TQRgb rgb=image.color(i);
+ info_ptr->palette[i].red = tqRed(rgb);
+ info_ptr->palette[i].green = tqGreen(rgb);
+ info_ptr->palette[i].blue = tqBlue(rgb);
+ if (image.hasAlphaBuffer()) {
+ trans[i] = rgb >> 24;
+ if (trans[i] < 255) {
+ num_trans = i+1;
+ }
+ }
+ }
+ if (num_trans) {
+ copy_trans = new png_byte[num_trans];
+ for (int i=0; i<num_trans; i++)
+ copy_trans[i] = trans[i];
+ png_set_tRNS(png_ptr, info_ptr, copy_trans, num_trans, 0);
+ }
+ delete [] trans;
+ }
+
+ if ( image.hasAlphaBuffer() ) {
+ info_ptr->sig_bit.alpha = 8;
+ }
+
+ // Swap ARGB to RGBA (normal PNG format) before saving on
+ // BigEndian machines
+ if ( TQImage::systemByteOrder() == TQImage::BigEndian ) {
+ png_set_swap_alpha(png_ptr);
+ }
+
+ // TQt==ARGB==Big(ARGB)==Little(BGRA)
+ if ( TQImage::systemByteOrder() == TQImage::LittleEndian ) {
+ png_set_bgr(png_ptr);
+ }
+
+ if (off_x || off_y) {
+ png_set_oFFs(png_ptr, info_ptr, off_x, off_y, PNG_OFFSET_PIXEL);
+ }
+
+ if ( frames_written > 0 )
+ png_set_sig_bytes(png_ptr, 8);
+
+ if ( image.dotsPerMeterX() > 0 || image.dotsPerMeterY() > 0 ) {
+ png_set_pHYs(png_ptr, info_ptr,
+ image.dotsPerMeterX(), image.dotsPerMeterY(),
+ PNG_RESOLUTION_METER);
+ }
+
+#ifndef TQT_NO_IMAGE_TEXT
+ // Write short texts early.
+ set_text(image,png_ptr,info_ptr,TRUE);
+#endif
+
+ png_write_info(png_ptr, info_ptr);
+
+#ifndef TQT_NO_IMAGE_TEXT
+ // Write long texts later.
+ set_text(image,png_ptr,info_ptr,FALSE);
+#endif
+
+ if ( image.depth() != 1 )
+ png_set_packing(png_ptr);
+
+ if ( image.depth() == 32 && !image.hasAlphaBuffer() )
+ png_set_filler(png_ptr, 0,
+ TQImage::systemByteOrder() == TQImage::BigEndian ?
+ PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
+
+ if ( looping >= 0 && frames_written == 0 ) {
+ uchar data[13] = "NETSCAPE2.0";
+ // 0123456789aBC
+ data[0xB] = looping%0x100;
+ data[0xC] = looping/0x100;
+ png_write_chunk(png_ptr, (png_byte*)"gIFx", data, 13);
+ }
+ if ( ms_delay >= 0 || disposal!=Unspecified ) {
+ uchar data[4];
+ data[0] = disposal;
+ data[1] = 0;
+ data[2] = (ms_delay/10)/0x100; // hundredths
+ data[3] = (ms_delay/10)%0x100;
+ png_write_chunk(png_ptr, (png_byte*)"gIFg", data, 4);
+ }
+
+ png_uint_32 width;
+ png_uint_32 height;
+ int bit_depth;
+ int color_type;
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
+ 0, 0, 0);
+
+ uchar** jt = const_cast<TQImage*>(&image)->jumpTable();
+ row_pointers=new png_bytep[height];
+ uint y;
+ for (y=0; y<height; y++) {
+ row_pointers[y]=jt[y];
+ }
+ png_write_image(png_ptr, row_pointers);
+ delete [] row_pointers;
+
+ png_write_end(png_ptr, info_ptr);
+ frames_written++;
+
+ if ( palette )
+ delete [] palette;
+ if ( copy_trans )
+ delete [] copy_trans;
+
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+ return TRUE;
+}
+
+static
+void write_png_image(TQImageIO* iio)
+{
+ TQPNGImageWriter writer(iio->ioDevice());
+ int quality = iio->quality();
+ if ( quality >= 0 ) {
+ quality = TQMIN( quality, 100 );
+ quality = (100-quality) * 9 / 91; // map [0,100] -> [9,0]
+ }
+ writer.setGamma(iio->gamma());
+ bool ok = writer.writeImage( iio->image(), quality );
+ iio->setqStatus( ok ? 0 : -1 );
+}
+
+/*!
+ \class TQPNGImagePacker tqpngio.h
+ \brief The TQPNGImagePacker class creates well-compressed PNG animations.
+
+ \ingroup images
+ \ingroup graphics
+
+ By using transparency, TQPNGImagePacker allows you to build a PNG
+ image from a sequence of TQImages.
+
+ Images are added using packImage().
+*/
+
+
+/*!
+ Creates an image packer that writes PNG data to IO tqdevice \a iod
+ using a \a storage_depth bit encoding (use 8 or 32, depending on
+ the desired quality and compression requirements).
+
+ If the image needs to be modified to fit in a lower-resolution
+ result (e.g. converting from 32-bit to 8-bit), use the \a
+ conversionflags to specify how you'd prefer this to happen.
+
+ \sa TQt::ImageConversionFlags
+*/
+TQPNGImagePacker::TQPNGImagePacker(TQIODevice* iod, int storage_depth,
+ int conversionflags) :
+ TQPNGImageWriter(iod),
+ depth(storage_depth),
+ convflags(conversionflags),
+ alignx(1)
+{
+}
+
+/*!
+ Aligns pixel differences to \a x pixels. For example, using 8 can
+ improve playback on certain hardware. Normally the default of
+ 1-pixel tqalignment (i.e. no tqalignment) gives better compression and
+ performance.
+*/
+void TQPNGImagePacker::setPixelAlignment(int x)
+{
+ alignx = x;
+}
+
+/*!
+ Adds the image \a img to the PNG animation, analyzing the
+ differences between this and the previous image to improve
+ compression.
+*/
+bool TQPNGImagePacker::packImage(const TQImage& img)
+{
+ TQImage image = img.convertDepth(32);
+ if ( previous.isNull() ) {
+ // First image
+ writeImage(image.convertDepth(depth,(Qt::ImageConversionFlag)convflags));
+ } else {
+ bool done;
+ int minx, maxx, miny, maxy;
+ int w = image.width();
+ int h = image.height();
+
+ TQRgb** jt = (TQRgb**)image.jumpTable();
+ TQRgb** pjt = (TQRgb**)previous.jumpTable();
+
+ // Find left edge of change
+ done = FALSE;
+ for (minx = 0; minx < w && !done; minx++) {
+ for (int ty = 0; ty < h; ty++) {
+ if ( jt[ty][minx] != pjt[ty][minx] ) {
+ done = TRUE;
+ break;
+ }
+ }
+ }
+ minx--;
+
+ // Find right edge of change
+ done = FALSE;
+ for (maxx = w-1; maxx >= 0 && !done; maxx--) {
+ for (int ty = 0; ty < h; ty++) {
+ if ( jt[ty][maxx] != pjt[ty][maxx] ) {
+ done = TRUE;
+ break;
+ }
+ }
+ }
+ maxx++;
+
+ // Find top edge of change
+ done = FALSE;
+ for (miny = 0; miny < h && !done; miny++) {
+ for (int tx = 0; tx < w; tx++) {
+ if ( jt[miny][tx] != pjt[miny][tx] ) {
+ done = TRUE;
+ break;
+ }
+ }
+ }
+ miny--;
+
+ // Find right edge of change
+ done = FALSE;
+ for (maxy = h-1; maxy >= 0 && !done; maxy--) {
+ for (int tx = 0; tx < w; tx++) {
+ if ( jt[maxy][tx] != pjt[maxy][tx] ) {
+ done = TRUE;
+ break;
+ }
+ }
+ }
+ maxy++;
+
+ if ( minx > maxx ) minx=maxx=0;
+ if ( miny > maxy ) miny=maxy=0;
+
+ if ( alignx > 1 ) {
+ minx -= minx % alignx;
+ maxx = maxx - maxx % alignx + alignx - 1;
+ }
+
+ int dw = maxx-minx+1;
+ int dh = maxy-miny+1;
+
+ TQImage diff(dw, dh, 32);
+
+ diff.setAlphaBuffer(TRUE);
+ int x, y;
+ if ( alignx < 1 )
+ alignx = 1;
+ for (y = 0; y < dh; y++) {
+ TQRgb* li = (TQRgb*)image.scanLine(y+miny)+minx;
+ TQRgb* lp = (TQRgb*)previous.scanLine(y+miny)+minx;
+ TQRgb* ld = (TQRgb*)diff.scanLine(y);
+ if ( alignx ) {
+ for (x = 0; x < dw; x+=alignx) {
+ int i;
+ for (i=0; i<alignx; i++) {
+ if ( li[x+i] != lp[x+i] )
+ break;
+ }
+ if ( i == alignx ) {
+ // All the same
+ for (i=0; i<alignx; i++) {
+ ld[x+i] = tqRgba(0,0,0,0);
+ }
+ } else {
+ // Some different
+ for (i=0; i<alignx; i++) {
+ ld[x+i] = 0xff000000 | li[x+i];
+ }
+ }
+ }
+ } else {
+ for (x = 0; x < dw; x++) {
+ if ( li[x] != lp[x] )
+ ld[x] = 0xff000000 | li[x];
+ else
+ ld[x] = tqRgba(0,0,0,0);
+ }
+ }
+ }
+
+ diff = diff.convertDepth(depth,(Qt::ImageConversionFlag)convflags);
+ if ( !writeImage(diff, minx, miny) )
+ return FALSE;
+ }
+ previous = image;
+ return TRUE;
+}
+
+
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+
+class TQPNGFormat : public TQImageFormat {
+public:
+ TQPNGFormat();
+ virtual ~TQPNGFormat();
+
+ int decode(TQImage& img, TQImageConsumer* consumer,
+ const uchar* buffer, int length);
+
+ void info(png_structp png_ptr, png_infop info);
+ void row(png_structp png_ptr, png_bytep new_row,
+ png_uint_32 row_num, int pass);
+ void end(png_structp png_ptr, png_infop info);
+#ifdef PNG_USER_CHUNKS_SUPPORTED
+ int user_chunk(png_structp png_ptr,
+ png_bytep data, png_uint_32 length);
+#endif
+
+private:
+ // Animation-level information
+ enum { MovieStart, FrameStart, Inside, End } state;
+ int first_frame;
+ int base_offx;
+ int base_offy;
+
+ // Image-level information
+ png_structp png_ptr;
+ png_infop info_ptr;
+
+ // Temporary locals during single data-chunk processing
+ TQImageConsumer* consumer;
+ TQImage* image;
+ int unused_data;
+};
+
+class TQPNGFormatType : public TQImageFormatType
+{
+ TQImageFormat* decoderFor(const uchar* buffer, int length);
+ const char* formatName() const;
+};
+
+
+/*
+ \class TQPNGFormat tqpngio.h
+ \brief The TQPNGFormat class provides an incremental image decoder for PNG
+ image format.
+
+ \ingroup images
+ \ingroup graphics
+
+ This subclass of TQImageFormat decodes PNG format images,
+ including animated PNGs.
+
+ Animated PNG images are standard PNG images. The PNG standard
+ defines two extension chunks that are useful for animations:
+
+ \list
+ \i gIFg - GIF-like Graphic Control Extension.
+ This includes frame disposal, user input flag (we ignore this),
+ and inter-frame delay.
+ \i gIFx - GIF-like Application Extension.
+ This is multi-purpose, but we just use the Netscape extension
+ which specifies looping.
+ \endlist
+
+ The subimages usually contain a offset chunk (oFFs) but need not.
+
+ The first image defines the "screen" size. Any subsequent image that
+ doesn't fit is clipped.
+*/
+/* ###TODO: decide on this point. gIFg gives disposal types, so it can be done.
+ All images paste (\e not composite, just place all-channel copying)
+ over the previous image to produce a subsequent frame.
+*/
+
+/*
+ \class TQPNGFormatType tqasyncimageio.h
+ \brief The TQPNGFormatType class provides an incremental image decoder
+ for PNG image format.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup io
+
+ This subclass of TQImageFormatType recognizes PNG format images, creating
+ a TQPNGFormat when required. An instance of this class is created
+ automatically before any other factories, so you should have no need for
+ such objects.
+*/
+
+TQImageFormat* TQPNGFormatType::decoderFor(
+ const uchar* buffer, int length)
+{
+ if (length < 8) return 0;
+ if (buffer[0]==137
+ && buffer[1]=='P'
+ && buffer[2]=='N'
+ && buffer[3]=='G'
+ && buffer[4]==13
+ && buffer[5]==10
+ && buffer[6]==26
+ && buffer[7]==10)
+ return new TQPNGFormat;
+ return 0;
+}
+
+const char* TQPNGFormatType::formatName() const
+{
+ return "PNG";
+}
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+static void
+CALLBACK_CALL_TYPE info_callback(png_structp png_ptr, png_infop info)
+{
+ TQPNGFormat* that = (TQPNGFormat*)png_get_progressive_ptr(png_ptr);
+ that->info(png_ptr,info);
+}
+
+static void
+CALLBACK_CALL_TYPE row_callback(png_structp png_ptr, png_bytep new_row,
+ png_uint_32 row_num, int pass)
+{
+ TQPNGFormat* that = (TQPNGFormat*)png_get_progressive_ptr(png_ptr);
+ that->row(png_ptr,new_row,row_num,pass);
+}
+
+static void
+CALLBACK_CALL_TYPE end_callback(png_structp png_ptr, png_infop info)
+{
+ TQPNGFormat* that = (TQPNGFormat*)png_get_progressive_ptr(png_ptr);
+ that->end(png_ptr,info);
+}
+
+#if 0
+#ifdef PNG_USER_CHUNKS_SUPPORTED
+static int
+CALLBACK_CALL_TYPE user_chunk_callback(png_structp png_ptr,
+ png_unknown_chunkp chunk)
+{
+ TQPNGFormat* that = (TQPNGFormat*)png_get_progressive_ptr(png_ptr);
+ return that->user_chunk(png_ptr,chunk->data,chunk->size);
+}
+#endif
+#endif
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+/*!
+ Constructs a TQPNGFormat object.
+*/
+TQPNGFormat::TQPNGFormat()
+{
+ state = MovieStart;
+ first_frame = 1;
+ base_offx = 0;
+ base_offy = 0;
+ png_ptr = 0;
+ info_ptr = 0;
+}
+
+
+/*!
+ Destroys a TQPNGFormat object.
+*/
+TQPNGFormat::~TQPNGFormat()
+{
+ if ( png_ptr )
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+}
+
+
+/*!
+ This function decodes some data into image changes.
+
+ Returns the number of bytes consumed.
+*/
+int TQPNGFormat::decode(TQImage& img, TQImageConsumer* cons,
+ const uchar* buffer, int length)
+{
+ consumer = cons;
+ image = &img;
+
+ if ( state != Inside ) {
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
+ if (!png_ptr) {
+ info_ptr = 0;
+ image = 0;
+ return -1;
+ }
+
+ png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
+ png_set_compression_level(png_ptr, 9);
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+ image = 0;
+ return -1;
+ }
+
+ if (setjmp((png_ptr)->jmpbuf)) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+ image = 0;
+ return -1;
+ }
+
+ png_set_progressive_read_fn(png_ptr, (void *)this,
+ info_callback, row_callback, end_callback);
+
+#ifdef PNG_USER_CHUNKS_SUPPORTED
+ // Can't do this yet. libpng has a crash bug with unknown (user) chunks.
+ // Warwick has sent them a patch.
+ // png_set_read_user_chunk_fn(png_ptr, 0, user_chunk_callback);
+ // png_set_keep_unknown_chunks(png_ptr, 2/*HANDLE_CHUNK_IF_SAFE*/, 0, 0);
+#endif
+
+ if ( state != MovieStart && *buffer != 0211 ) {
+ // Good, no signature - the preferred way to concat PNG images.
+ // Skip them.
+ png_set_sig_bytes(png_ptr, 8);
+ }
+
+ state = Inside;
+ }
+
+ if ( !png_ptr ) return 0;
+
+ if (setjmp(png_ptr->jmpbuf)) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+ image = 0;
+ state = MovieStart;
+ return -1;
+ }
+ unused_data = 0;
+ png_process_data(png_ptr, info_ptr, (png_bytep)buffer, length);
+ int l = length - unused_data;
+
+ // TODO: send incremental stuff to consumer (optional)
+
+ if ( state != Inside ) {
+ if ( png_ptr )
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+ }
+
+ image = 0;
+ return l;
+}
+
+void TQPNGFormat::info(png_structp png, png_infop)
+{
+ png_set_interlace_handling(png);
+ setup_qt(*image, png, info_ptr);
+}
+
+void TQPNGFormat::row(png_structp png, png_bytep new_row,
+ png_uint_32 row_num, int)
+{
+ uchar* old_row = image->scanLine(row_num);
+ png_progressive_combine_row(png, old_row, new_row);
+}
+
+
+void TQPNGFormat::end(png_structp png, png_infop info)
+{
+ int offx = png_get_x_offset_pixels(png,info) - base_offx;
+ int offy = png_get_y_offset_pixels(png,info) - base_offy;
+ if ( first_frame ) {
+ base_offx = offx;
+ base_offy = offy;
+ first_frame = 0;
+ }
+ image->setOffset(TQPoint(offx,offy));
+ image->setDotsPerMeterX(png_get_x_pixels_per_meter(png,info));
+ image->setDotsPerMeterY(png_get_y_pixels_per_meter(png,info));
+#ifndef TQT_NO_IMAGE_TEXT
+ png_textp text_ptr;
+ int num_text=0;
+ png_get_text(png,info,&text_ptr,&num_text);
+ while (num_text--) {
+ image->setText(text_ptr->key,0,text_ptr->text);
+ text_ptr++;
+ }
+#endif
+ TQRect r(0,0,image->width(),image->height());
+ consumer->frameDone(TQPoint(offx,offy),r);
+ consumer->end();
+ state = FrameStart;
+ unused_data = (int)png->buffer_size; // Since libpng doesn't tell us
+}
+
+#ifdef PNG_USER_CHUNKS_SUPPORTED
+
+/*
+#ifndef TQT_NO_IMAGE_TEXT
+static bool skip(png_uint_32& max, png_bytep& data)
+{
+ while (*data) {
+ if ( !max ) return FALSE;
+ max--;
+ data++;
+ }
+ if ( !max ) return FALSE;
+ max--;
+ data++; // skip to after NUL
+ return TRUE;
+}
+#endif
+*/
+
+int TQPNGFormat::user_chunk(png_structp png,
+ png_bytep data, png_uint_32 length)
+{
+#if 0 // NOT SUPPORTED: experimental PNG animation.
+ // qDebug("Got %ld-byte %s chunk", length, png->chunk_name);
+ if ( 0==qstrcmp((char*)png->chunk_name, "gIFg")
+ && length == 4 ) {
+
+ //TQPNGImageWriter::DisposalMethod disposal =
+ // (TQPNGImageWriter::DisposalMethod)data[0];
+ // ### TODO: use the disposal method
+ int ms_delay = ((data[2] << 8) | data[3])*10;
+ consumer->setFramePeriod(ms_delay);
+ return 1;
+ } else if ( 0==qstrcmp((char*)png->chunk_name, "gIFx")
+ && length == 13 ) {
+ if ( tqstrncmp((char*)data,"NETSCAPE2.0",11)==0 ) {
+ int looping = (data[0xC]<<8)|data[0xB];
+ consumer->setLooping(looping);
+ return 1;
+ }
+ }
+#else
+ TQ_UNUSED( png )
+ TQ_UNUSED( data )
+ TQ_UNUSED( length )
+#endif
+
+#ifndef TQT_NO_IMAGE_TEXT
+ /*
+
+ libpng now supports this chunk.
+
+
+ if ( 0==qstrcmp((char*)png->chunk_name, "iTXt") && length>=6 ) {
+ const char* keyword = (const char*)data;
+ if ( !skip(length,data) ) return 0;
+ if ( length >= 4 ) {
+ char compression_flag = *data++;
+ char compression_method = *data++;
+ if ( compression_flag == compression_method ) {
+ // fool the compiler into thinking they're used
+ }
+ const char* lang = (const char*)data;
+ if ( !skip(length,data) ) return 0;
+ // const char* keyword_utf8 = (const char*)data;
+ if ( !skip(length,data) ) return 0;
+ const char* text_utf8 = (const char*)data;
+ if ( !skip(length,data) ) return 0;
+ TQString text = TQString::fromUtf8(text_utf8);
+ image->setText(keyword,lang[0] ? lang : 0,text);
+ return 1;
+ }
+ }
+ */
+#endif
+
+ return 0;
+}
+#endif
+
+
+static TQPNGFormatType* globalPngFormatTypeObject = 0;
+
+#endif // TQT_NO_ASYNC_IMAGE_IO
+
+static bool done = FALSE;
+void qCleanupPngIO()
+{
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ if ( globalPngFormatTypeObject ) {
+ delete globalPngFormatTypeObject;
+ globalPngFormatTypeObject = 0;
+ }
+#endif
+ done = FALSE;
+}
+
+void qInitPngIO()
+{
+ if ( !done ) {
+ done = TRUE;
+ TQImageIO::defineIOHandler( "PNG", "^.PNG\r", 0, read_png_image,
+ write_png_image);
+#ifndef TQT_NO_ASYNC_IMAGE_IO
+ globalPngFormatTypeObject = new TQPNGFormatType;
+#endif
+ qAddPostRoutine( qCleanupPngIO );
+ }
+}
+
+void qt_zlib_compression_hack()
+{
+ compress(0,0,0,0);
+ uncompress(0,0,0,0);
+}
+
+#endif // TQT_NO_IMAGEIO_PNG
diff --git a/tqtinterface/qt4/src/kernel/tqpngio.h b/tqtinterface/qt4/src/kernel/tqpngio.h
new file mode 100644
index 0000000..43e669f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpngio.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Definition of PNG TQImage IOHandler
+**
+** Created : 970521
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPNGIO_H
+#define TQPNGIO_H
+
+#ifndef TQT_H
+#include "tqimage.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_IMAGEIO_PNG
+
+void qInitPngIO();
+
+class TQIODevice;
+
+#ifndef TQ_PNGEXPORT
+#if !defined(TQT_PLUGIN)
+#define TQ_PNGEXPORT TQ_EXPORT
+#else
+#define TQ_PNGEXPORT
+#endif
+#endif
+
+class TQ_PNGEXPORT TQPNGImageWriter {
+public:
+ TQPNGImageWriter(TQIODevice*);
+ ~TQPNGImageWriter();
+
+ enum DisposalMethod { Unspecified, NoDisposal, RestoreBackground, RestoreImage };
+ void setDisposalMethod(DisposalMethod);
+ void setLooping(int loops=0); // 0 == infinity
+ void setFrameDelay(int msecs);
+ void setGamma(float);
+
+ bool writeImage(const TQImage& img, int x, int y);
+ bool writeImage(const TQImage& img, int quality, int x, int y);
+ bool writeImage(const TQImage& img)
+ { return writeImage(img, 0, 0); }
+ bool writeImage(const TQImage& img, int quality)
+ { return writeImage(img, quality, 0, 0); }
+
+ TQIODevice* tqdevice() { return dev; }
+
+private:
+ TQIODevice* dev;
+ int frames_written;
+ DisposalMethod disposal;
+ int looping;
+ int ms_delay;
+ float gamma;
+};
+
+class TQ_PNGEXPORT TQPNGImagePacker : public TQPNGImageWriter {
+public:
+ TQPNGImagePacker(TQIODevice*, int depth, int convflags);
+
+ void setPixelAlignment(int x);
+ bool packImage(const TQImage& img);
+
+private:
+ TQImage previous;
+ int depth;
+ int convflags;
+ int alignx;
+};
+
+#endif // TQT_NO_IMAGEIO_PNG
+
+#endif // TQPNGIO_H
diff --git a/tqtinterface/qt4/src/kernel/tqpoint.cpp b/tqtinterface/qt4/src/kernel/tqpoint.cpp
new file mode 100644
index 0000000..cf8422e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpoint.cpp
@@ -0,0 +1,448 @@
+/****************************************************************************
+**
+** Implementation of TQPoint class
+**
+** Created : 931028
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpoint.h"
+#include "tqdatastream.h"
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ \class TQPoint tqpoint.h
+ \brief The TQPoint class defines a point in the plane.
+
+ \ingroup images
+ \ingroup graphics
+ \mainclass
+
+ A point is specified by an x coordinate and a y coordinate.
+
+ The coordinate type is \c TQCOORD (a 32-bit integer). The minimum
+ value of \c TQCOORD is \c TQCOORD_MIN (-2147483648) and the maximum
+ value is \c TQCOORD_MAX (2147483647).
+
+ The coordinates are accessed by the functions x() and y(); they
+ can be set by setX() and setY() or by the reference functions rx()
+ and ry().
+
+ Given a point \e p, the following statements are all equivalent:
+ \code
+ p.setX( p.x() + 1 );
+ p += TQPoint( 1, 0 );
+ p.rx()++;
+ \endcode
+
+ A TQPoint can also be used as a vector. Addition and subtraction
+ of TQPoints are defined as for vectors (each component is added
+ separately). You can divide or multiply a TQPoint by an \c int or a
+ \c double. The function manhattanLength() gives an inexpensive
+ approximation of the length of the TQPoint interpreted as a vector.
+
+ Example:
+ \code
+ //TQPoint oldPos is defined somewhere else
+ MyWidget::mouseMoveEvent( TQMouseEvent *e )
+ {
+ TQPoint vector = e->pos() - oldPos;
+ if ( vector.manhattanLength() > 3 )
+ ... //mouse has moved more than 3 pixels since oldPos
+ }
+ \endcode
+
+ TQPoints can be compared for equality or inequality, and they can
+ be written to and read from a TQStream.
+
+ \sa TQPointArray TQSize, TQRect
+*/
+
+
+/*****************************************************************************
+ TQPoint member functions
+ *****************************************************************************/
+
+/*!
+ \fn TQPoint::TQPoint()
+
+ Constructs a point with coordinates (0, 0) (isNull() returns TRUE).
+*/
+
+/*!
+ \fn TQPoint::TQPoint( int xpos, int ypos )
+
+ Constructs a point with x value \a xpos and y value \a ypos.
+*/
+
+/*!
+ \fn bool TQPoint::isNull() const
+
+ Returns TRUE if both the x value and the y value are 0; otherwise
+ returns FALSE.
+*/
+
+/*!
+ \fn int TQPoint::x() const
+
+ Returns the x coordinate of the point.
+
+ \sa setX() y()
+*/
+
+/*!
+ \fn int TQPoint::y() const
+
+ Returns the y coordinate of the point.
+
+ \sa setY() x()
+*/
+
+/*!
+ \fn void TQPoint::setX( int x )
+
+ Sets the x coordinate of the point to \a x.
+
+ \sa x() setY()
+*/
+
+/*!
+ \fn void TQPoint::setY( int y )
+
+ Sets the y coordinate of the point to \a y.
+
+ \sa y() setX()
+*/
+
+
+/*!
+ \fn TQCOORD &TQPoint::rx()
+
+ Returns a reference to the x coordinate of the point.
+
+ Using a reference makes it possible to directly manipulate x.
+
+ Example:
+ \code
+ TQPoint p( 1, 2 );
+ p.rx()--; // p becomes (0, 2)
+ \endcode
+
+ \sa ry()
+*/
+
+/*!
+ \fn TQCOORD &TQPoint::ry()
+
+ Returns a reference to the y coordinate of the point.
+
+ Using a reference makes it possible to directly manipulate y.
+
+ Example:
+ \code
+ TQPoint p( 1, 2 );
+ p.ry()++; // p becomes (1, 3)
+ \endcode
+
+ \sa rx()
+*/
+
+
+/*!
+ \fn TQPoint &TQPoint::operator+=( const TQPoint &p )
+
+ Adds point \a p to this point and returns a reference to this
+ point.
+
+ Example:
+ \code
+ TQPoint p( 3, 7 );
+ TQPoint q( -1, 4 );
+ p += q; // p becomes (2,11)
+ \endcode
+*/
+
+/*!
+ \fn TQPoint &TQPoint::operator-=( const TQPoint &p )
+
+ Subtracts point \a p from this point and returns a reference to
+ this point.
+
+ Example:
+ \code
+ TQPoint p( 3, 7 );
+ TQPoint q( -1, 4 );
+ p -= q; // p becomes (4,3)
+ \endcode
+*/
+
+/*!
+ \fn TQPoint &TQPoint::operator*=( int c )
+
+ Multiplies this point's x and y by \a c, and returns a reference
+ to this point.
+
+ Example:
+ \code
+ TQPoint p( -1, 4 );
+ p *= 2; // p becomes (-2,8)
+ \endcode
+*/
+
+/*!
+ \overload TQPoint &TQPoint::operator*=( double c )
+
+ Multiplies this point's x and y by \a c, and returns a reference
+ to this point.
+
+ Example:
+ \code
+ TQPoint p( -1, 4 );
+ p *= 2.5; // p becomes (-3,10)
+ \endcode
+
+ Note that the result is truncated because points are held as
+ integers.
+*/
+
+
+/*!
+ \fn bool operator==( const TQPoint &p1, const TQPoint &p2 )
+
+ \relates TQPoint
+
+ Returns TRUE if \a p1 and \a p2 are equal; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool operator!=( const TQPoint &p1, const TQPoint &p2 )
+
+ \relates TQPoint
+
+ Returns TRUE if \a p1 and \a p2 are not equal; otherwise returns FALSE.
+*/
+
+/*!
+ \fn const TQPoint operator+( const TQPoint &p1, const TQPoint &p2 )
+
+ \relates TQPoint
+
+ Returns the sum of \a p1 and \a p2; each component is added separately.
+*/
+
+/*!
+ \fn const TQPoint operator-( const TQPoint &p1, const TQPoint &p2 )
+
+ \relates TQPoint
+
+ Returns \a p2 subtracted from \a p1; each component is subtracted
+ separately.
+*/
+
+/*!
+ \fn const TQPoint operator*( const TQPoint &p, int c )
+
+ \relates TQPoint
+
+ Returns the TQPoint formed by multiplying both components of \a p
+ by \a c.
+*/
+
+/*!
+ \overload const TQPoint operator*( int c, const TQPoint &p )
+
+ \relates TQPoint
+
+ Returns the TQPoint formed by multiplying both components of \a p
+ by \a c.
+*/
+
+/*!
+ \overload const TQPoint operator*( const TQPoint &p, double c )
+
+ \relates TQPoint
+
+ Returns the TQPoint formed by multiplying both components of \a p
+ by \a c.
+
+ Note that the result is truncated because points are held as
+ integers.
+*/
+
+/*!
+ \overload const TQPoint operator*( double c, const TQPoint &p )
+
+ \relates TQPoint
+
+ Returns the TQPoint formed by multiplying both components of \a p
+ by \a c.
+
+ Note that the result is truncated because points are held as
+ integers.
+*/
+
+/*!
+ \overload const TQPoint operator-( const TQPoint &p )
+
+ \relates TQPoint
+
+ Returns the TQPoint formed by changing the sign of both components
+ of \a p, equivalent to \c{TQPoint(0,0) - p}.
+*/
+
+/*!
+ \fn TQPoint &TQPoint::operator/=( int c )
+
+ Divides both x and y by \a c, and returns a reference to this
+ point.
+
+ Example:
+ \code
+ TQPoint p( -2, 8 );
+ p /= 2; // p becomes (-1,4)
+ \endcode
+*/
+
+/*!
+ \overload TQPoint &TQPoint::operator/=( double c )
+
+ Divides both x and y by \a c, and returns a reference to this
+ point.
+
+ Example:
+ \code
+ TQPoint p( -3, 10 );
+ p /= 2.5; // p becomes (-1,4)
+ \endcode
+
+ Note that the result is truncated because points are held as
+ integers.
+*/
+
+/*!
+ \fn const TQPoint operator/( const TQPoint &p, int c )
+
+ \relates TQPoint
+
+ Returns the TQPoint formed by dividing both components of \a p by
+ \a c.
+*/
+
+/*!
+ \overload const TQPoint operator/( const TQPoint &p, double c )
+
+ \relates TQPoint
+
+ Returns the TQPoint formed by dividing both components of \a p
+ by \a c.
+
+ Note that the result is truncated because points are held as
+ integers.
+*/
+
+
+void TQPoint::warningDivByZero()
+{
+#if defined(TQT_CHECK_MATH)
+ qWarning( "TQPoint: Division by zero error" );
+#endif
+}
+
+
+/*****************************************************************************
+ TQPoint stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQPoint
+
+ Writes point \a p to the stream \a s and returns a reference to
+ the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQPoint &p )
+{
+ if ( s.version() == 1 )
+ s << (TQ_INT16)p.x() << (TQ_INT16)p.y();
+ else
+ s << (TQ_INT32)p.x() << (TQ_INT32)p.y();
+ return s;
+}
+
+/*!
+ \relates TQPoint
+
+ Reads a TQPoint from the stream \a s into point \a p and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQPoint &p )
+{
+ if ( s.version() == 1 ) {
+ TQ_INT16 x, y;
+ s >> x; p.rx() = x;
+ s >> y; p.ry() = y;
+ }
+ else {
+ TQ_INT32 x, y;
+ s >> x; p.rx() = x;
+ s >> y; p.ry() = y;
+ }
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+/*!
+ Returns the sum of the absolute values of x() and y(),
+ traditionally known as the "Manhattan length" of the vector from
+ the origin to the point. The tradition arises because such
+ distances apply to travelers who can only travel on a rectangular
+ grid, like the streets of Manhattan.
+
+ This is a useful, and quick to calculate, approximation to the
+ true length: sqrt(pow(x(),2)+pow(y(),2)).
+*/
+int TQPoint::manhattanLength() const
+{
+ return TQABS(x())+TQABS(y());
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpoint.h b/tqtinterface/qt4/src/kernel/tqpoint.h
new file mode 100644
index 0000000..dc9a5bb
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpoint.h
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Definition of TQPoint class
+**
+** Created : 931028
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPOINT_H
+#define TQPOINT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qrect.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQPoint : public QPoint, virtual public TQt
+{
+public:
+ TQPoint() : QPoint() {}
+ TQPoint( int xpos, int ypos ) : QPoint(xpos, ypos) {}
+
+ // Interoperability
+ TQPoint(QPoint a) {
+ setX(a.x());
+ setY(a.y());
+ }
+
+ // Interoperability
+ static const TQPoint& convertFromQPoint( QPoint& qp );
+};
+
+// Interoperability
+inline static const TQPoint& convertFromQPoint( const QPoint& qp ) {
+ return (*static_cast<const TQPoint*>(&qp));
+}
+
+#else // USE_QT4
+
+class TQ_EXPORT TQPoint
+{
+public:
+ TQPoint();
+ TQPoint( int xpos, int ypos );
+
+ bool isNull() const;
+
+ int x() const;
+ int y() const;
+ void setX( int x );
+ void setY( int y );
+
+ int manhattanLength() const;
+
+ TQCOORD &rx();
+ TQCOORD &ry();
+
+ TQPoint &operator+=( const TQPoint &p );
+ TQPoint &operator-=( const TQPoint &p );
+ TQPoint &operator*=( int c );
+ TQPoint &operator*=( double c );
+ TQPoint &operator/=( int c );
+ TQPoint &operator/=( double c );
+
+ friend inline bool operator==( const TQPoint &, const TQPoint & );
+ friend inline bool operator!=( const TQPoint &, const TQPoint & );
+ friend inline const TQPoint operator+( const TQPoint &, const TQPoint & );
+ friend inline const TQPoint operator-( const TQPoint &, const TQPoint & );
+ friend inline const TQPoint operator*( const TQPoint &, int );
+ friend inline const TQPoint operator*( int, const TQPoint & );
+ friend inline const TQPoint operator*( const TQPoint &, double );
+ friend inline const TQPoint operator*( double, const TQPoint & );
+ friend inline const TQPoint operator-( const TQPoint & );
+ friend inline const TQPoint operator/( const TQPoint &, int );
+ friend inline const TQPoint operator/( const TQPoint &, double );
+
+private:
+ static void warningDivByZero();
+
+#if defined(TQ_OS_MAC)
+ TQCOORD yp;
+ TQCOORD xp;
+#else
+ TQCOORD xp;
+ TQCOORD yp;
+#endif
+};
+
+
+/*****************************************************************************
+ TQPoint stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQPoint & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQPoint & );
+#endif
+
+/*****************************************************************************
+ TQPoint inline functions
+ *****************************************************************************/
+
+inline TQPoint::TQPoint()
+{ xp=0; yp=0; }
+
+inline TQPoint::TQPoint( int xpos, int ypos )
+{ xp=(TQCOORD)xpos; yp=(TQCOORD)ypos; }
+
+inline bool TQPoint::isNull() const
+{ return xp == 0 && yp == 0; }
+
+inline int TQPoint::x() const
+{ return xp; }
+
+inline int TQPoint::y() const
+{ return yp; }
+
+inline void TQPoint::setX( int x )
+{ xp = (TQCOORD)x; }
+
+inline void TQPoint::setY( int y )
+{ yp = (TQCOORD)y; }
+
+inline TQCOORD &TQPoint::rx()
+{ return xp; }
+
+inline TQCOORD &TQPoint::ry()
+{ return yp; }
+
+inline TQPoint &TQPoint::operator+=( const TQPoint &p )
+{ xp+=p.xp; yp+=p.yp; return *this; }
+
+inline TQPoint &TQPoint::operator-=( const TQPoint &p )
+{ xp-=p.xp; yp-=p.yp; return *this; }
+
+inline TQPoint &TQPoint::operator*=( int c )
+{ xp*=(TQCOORD)c; yp*=(TQCOORD)c; return *this; }
+
+inline TQPoint &TQPoint::operator*=( double c )
+{ xp=(TQCOORD)(xp*c); yp=(TQCOORD)(yp*c); return *this; }
+
+inline bool operator==( const TQPoint &p1, const TQPoint &p2 )
+{ return p1.xp == p2.xp && p1.yp == p2.yp; }
+
+inline bool operator!=( const TQPoint &p1, const TQPoint &p2 )
+{ return p1.xp != p2.xp || p1.yp != p2.yp; }
+
+inline const TQPoint operator+( const TQPoint &p1, const TQPoint &p2 )
+{ return TQPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
+
+inline const TQPoint operator-( const TQPoint &p1, const TQPoint &p2 )
+{ return TQPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
+
+inline const TQPoint operator*( const TQPoint &p, int c )
+{ return TQPoint(p.xp*c, p.yp*c); }
+
+inline const TQPoint operator*( int c, const TQPoint &p )
+{ return TQPoint(p.xp*c, p.yp*c); }
+
+inline const TQPoint operator*( const TQPoint &p, double c )
+{ return TQPoint((TQCOORD)(p.xp*c), (TQCOORD)(p.yp*c)); }
+
+inline const TQPoint operator*( double c, const TQPoint &p )
+{ return TQPoint((TQCOORD)(p.xp*c), (TQCOORD)(p.yp*c)); }
+
+inline const TQPoint operator-( const TQPoint &p )
+{ return TQPoint(-p.xp, -p.yp); }
+
+inline TQPoint &TQPoint::operator/=( int c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0 )
+ warningDivByZero();
+#endif
+ xp/=(TQCOORD)c;
+ yp/=(TQCOORD)c;
+ return *this;
+}
+
+inline TQPoint &TQPoint::operator/=( double c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0.0 )
+ warningDivByZero();
+#endif
+ xp=(TQCOORD)(xp/c);
+ yp=(TQCOORD)(yp/c);
+ return *this;
+}
+
+inline const TQPoint operator/( const TQPoint &p, int c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0 )
+ TQPoint::warningDivByZero();
+#endif
+ return TQPoint(p.xp/c, p.yp/c);
+}
+
+inline const TQPoint operator/( const TQPoint &p, double c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0.0 )
+ TQPoint::warningDivByZero();
+#endif
+ return TQPoint((TQCOORD)(p.xp/c), (TQCOORD)(p.yp/c));
+}
+
+#endif // USE_QT4
+
+#define TQ_DEFINED_TQPOINT
+#include "tqwinexport.h"
+#endif // TQPOINT_H
diff --git a/tqtinterface/qt4/src/kernel/tqpointarray.cpp b/tqtinterface/qt4/src/kernel/tqpointarray.cpp
new file mode 100644
index 0000000..f5d0016
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpointarray.cpp
@@ -0,0 +1,1311 @@
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqpointarray.h"
+#include "private/qt4_qbezier_p.h"
+
+// Normally declared in private/qpainterpath_p.h
+void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length, QPointF* startPoint, QPointF *endPoint);
+
+#include <Qt/qpainterpath.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class TQPointArray
+ The TQPointArray class provides an array of points.
+
+ \compat
+
+ TQPointArray is a QPolygon subclass that provides functions
+ to make it more source compatible with the \c QPointArray class
+ in Qt 3.
+
+ In Qt 4, we recommend that you use QPainterPath for representing
+ arcs, ellipses, and Bezier curves, rather than QPolygon.
+*/
+
+/*!
+ Sets the points of the array to those describing an arc of an
+ ellipse with size, width \a w by height \a h, and position (\a x,
+ \a y), starting from angle \a a1 and spanning by angle \a a2. The
+ resulting array has sufficient resolution for pixel accuracy (see
+ the overloaded function which takes an additional QMatrix
+ parameter).
+
+ Angles are specified in 16ths of a degree, i.e. a full circle
+ equals 5760 (16*360). Positive values mean counter-clockwise,
+ whereas negative values mean the clockwise direction. Zero degrees
+ is at the 3 o'clock position.
+*/
+#ifndef QT_NO_WMATRIX
+void TQPointArray::makeArc(int x, int y, int w, int h, int a1, int a2)
+{
+ QRectF r(x, y, w, h);
+ QPointF startPoint;
+ qt_find_ellipse_coords(r, a1 / 16.0, a2 / 16.0, &startPoint, 0);
+
+ QPainterPath path(startPoint);
+ path.arcTo(r, a1 / 16.0, a2 / 16.0);
+
+ if (path.isEmpty())
+ *this = TQPointArray();
+ else
+ *this = path.toSubpathPolygons().at(0).toPolygon();
+}
+#endif
+
+#ifndef QT_NO_TRANSFORMATIONS
+/*!
+ \overload
+
+ Sets the points of the array to those describing an arc of an
+ ellipse with width \a w and height \a h and position (\a x, \a y),
+ starting from angle \a a1, and spanning angle by \a a2, and
+ transformed by the matrix \a xf. The resulting array has
+ sufficient resolution for pixel accuracy.
+
+ Angles are specified in 16ths of a degree, i.e. a full circle
+ equals 5760 (16 * 360). Positive values mean counter-clockwise,
+ whereas negative values mean the clockwise direction. Zero
+ degrees is at the 3 o'clock position.
+*/
+void TQPointArray::makeArc(int x, int y, int w, int h, int a1, int a2, const QMatrix &xf)
+{
+ QRectF r(x, y, w, h);
+ QPointF startPoint;
+ qt_find_ellipse_coords(r, a1 / 16.0, a2 / 16.0, &startPoint, 0);
+
+ QPainterPath path(startPoint);
+ path.arcTo(r, a1 / 16.0, a2 / 16.0);
+ path = path * xf;
+ if (path.isEmpty())
+ *this = TQPointArray();
+ else
+ *this = path.toSubpathPolygons().at(0).toPolygon();
+}
+
+#endif // QT_NO_TRANSFORMATIONS
+
+/*!
+ \fn TQPointArray::TQPointArray()
+
+ Constructs an empty TQPointArray.
+*/
+
+/*!
+ \fn TQPointArray::TQPointArray(const QRect &r, bool closed)
+
+ Constructs a point array from the rectangle \a r.
+
+ If \a closed is false, then the point array just contains the
+ following four points of the rectangle ordered clockwise. The
+ bottom-right point is located at (r.x() + r.width(), r.y() +
+ r.height()).
+*/
+
+/*!
+ \fn TQPointArray::TQPointArray(const QPolygon& other)
+
+ Constructs a copy of \a other.
+*/
+
+/*!
+ \fn TQPointArray TQPointArray::copy() const
+
+ Returns a copy of this TQPointArray.
+*/
+
+/*!
+ \fn bool TQPointArray::isNull()
+
+ Returns isEmpty(). Use isEmpty() instead.
+*/
+
+/*!
+ Sets the points of the array to those describing an ellipse with
+ size, width \a w by height \a h, and position (\a x, \a y).
+
+ The returned array has sufficient resolution for use as pixels.
+*/
+void TQPointArray::makeEllipse(int x, int y, int w, int h)
+{
+ QPainterPath path;
+ path.addEllipse(x, y, w, h);
+ *this = path.toSubpathPolygons().at(0).toPolygon();
+}
+
+#ifndef QT_NO_BEZIER
+
+/*!
+ Returns the Bezier points for the four control points in this
+ array.
+*/
+TQPointArray TQPointArray::cubicBezier() const
+{
+ if (size() != 4) {
+ qWarning( "TQPointArray::bezier: The array must have 4 control points" );
+ return QPolygon();
+ }
+ QPolygonF polygon = QBezier::fromPoints(at(0), at(1), at(2), at(3)).toPolygon();
+ return polygon.toPolygon();
+}
+#endif //QT_NO_BEZIER
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of TQPointArray class
+**
+** Created : 940213
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpointarray.h"
+#include "tqrect.h"
+#include "tqdatastream.h"
+#include "tqwmatrix.h"
+#include <stdarg.h>
+
+const double TQ_PI = 3.14159265358979323846; // pi // one more useful comment
+
+
+/*!
+ \class TQPointArray tqpointarray.h
+ \brief The TQPointArray class provides an array of points.
+
+ \ingroup images
+ \ingroup graphics
+ \ingroup shared
+
+ A TQPointArray is an array of TQPoint objects. In addition to the
+ functions provided by TQMemArray, TQPointArray provides some
+ point-specific functions.
+
+ For convenient reading and writing of the point data use
+ setPoints(), putPoints(), point(), and setPoint().
+
+ For tqgeometry operations use boundingRect() and translate(). There
+ is also the TQWMatrix::map() function for more general
+ transformations of TQPointArrays. You can also create arcs and
+ ellipses with makeArc() and makeEllipse().
+
+ Among others, TQPointArray is used by TQPainter::drawLineSegments(),
+ TQPainter::drawPolyline(), TQPainter::drawPolygon() and
+ TQPainter::drawCubicBezier().
+
+ Note that because this class is a TQMemArray, copying an array and
+ modifying the copy modifies the original as well, i.e. a shallow
+ copy. If you need a deep copy use copy() or detach(), for example:
+
+ \code
+ void drawGiraffe( const TQPointArray & r, TQPainter * p )
+ {
+ TQPointArray tmp = r;
+ tmp.detach();
+ // some code that modifies tmp
+ p->drawPoints( tmp );
+ }
+ \endcode
+
+ If you forget the tmp.detach(), the const array will be modified.
+
+ \sa TQPainter TQWMatrix TQMemArray
+*/
+
+
+/*****************************************************************************
+ TQPointArray member functions
+ *****************************************************************************/
+
+/*!
+ \fn TQPointArray::TQPointArray()
+
+ Constructs a null point array.
+
+ \sa isNull()
+*/
+
+/*!
+ \fn TQPointArray::TQPointArray( int size )
+
+ Constructs a point array with room for \a size points. Makes a
+ null array if \a size == 0.
+
+ \sa resize(), isNull()
+*/
+
+/*!
+ \fn TQPointArray::TQPointArray( const TQPointArray &a )
+
+ Constructs a shallow copy of the point array \a a.
+
+ \sa copy() detach()
+*/
+
+/*!
+ Constructs a point array from the rectangle \a r.
+
+ If \a closed is FALSE, then the point array just tqcontains the
+ following four points in the listed order: r.topLeft(),
+ r.topRight(), r.bottomRight() and r.bottomLeft().
+
+ If \a closed is TRUE, then a fifth point is set to r.topLeft().
+*/
+
+TQPointArray::TQPointArray( const TQRect &r, bool closed )
+{
+ setPoints( 4, r.left(), r.top(),
+ r.right(), r.top(),
+ r.right(), r.bottom(),
+ r.left(), r.bottom() );
+ if ( closed ) {
+ resize( 5 );
+ setPoint( 4, r.left(), r.top() );
+ }
+}
+
+/*!
+ \internal
+ Constructs a point array with \a nPoints points, taken from the
+ \a points array.
+
+ Equivalent to setPoints(nPoints, points).
+*/
+
+TQPointArray::TQPointArray( int nPoints, const TQCOORD *points )
+{
+ setPoints( nPoints, points );
+}
+
+
+/*!
+ \fn TQPointArray::~TQPointArray()
+
+ Destroys the point array.
+*/
+
+
+/*!
+ \fn TQPointArray &TQPointArray::operator=( const TQPointArray &a )
+
+ Assigns a shallow copy of \a a to this point array and returns a
+ reference to this point array.
+
+ Equivalent to assign(a).
+
+ \sa copy() detach()
+*/
+
+/*!
+ \fn TQPointArray TQPointArray::copy() const
+
+ Creates a deep copy of the array.
+
+ \sa detach()
+*/
+
+
+
+/*!
+ Translates all points in the array by \a (dx, dy).
+*/
+
+void TQPointArray::translate( int dx, int dy )
+{
+ register TQPoint *p = data();
+ register int i = size();
+ TQPoint pt( dx, dy );
+ while ( i-- ) {
+ *p += pt;
+ p++;
+ }
+}
+
+
+/*!
+ Reads the coordinates of the point at position \a index within the
+ array and writes them into \a *x and \a *y.
+*/
+
+void TQPointArray::point( uint index, int *x, int *y ) const
+{
+ TQPoint p = TQMemArray<TQPoint>::at( index );
+ if ( x )
+ *x = (int)p.x();
+ if ( y )
+ *y = (int)p.y();
+}
+
+/*!
+ \overload
+
+ Returns the point at position \a index within the array.
+*/
+
+TQPoint TQPointArray::point( uint index ) const
+{ // #### index out of bounds
+ return TQMemArray<TQPoint>::at( index );
+}
+
+/*!
+ \fn void TQPointArray::setPoint( uint i, const TQPoint &p )
+
+ \overload
+
+ Sets the point at array index \a i to \a p.
+*/
+
+/*!
+ Sets the point at position \a index in the array to \a (x, y).
+*/
+
+void TQPointArray::setPoint( uint index, int x, int y )
+{ // #### index out of bounds
+ TQMemArray<TQPoint>::at( index ) = TQPoint( x, y );
+}
+
+/*!
+ \internal
+ Resizes the array to \a nPoints and sets the points in the array to
+ the values taken from \a points.
+
+ Returns TRUE if successful, or FALSE if the array could not be
+ resized (normally due to lack of memory).
+
+ The example code creates an array with two points (1,2) and (3,4):
+ \code
+ static TQCOORD points[] = { 1,2, 3,4 };
+ TQPointArray a;
+ a.setPoints( 2, points );
+ \endcode
+
+ \sa resize(), putPoints()
+*/
+
+bool TQPointArray::setPoints( int nPoints, const TQCOORD *points )
+{
+ if ( !resize(nPoints) )
+ return FALSE;
+ int i = 0;
+ while ( nPoints-- ) { // make array of points
+ setPoint( i++, *points, *(points+1) );
+ points++;
+ points++;
+ }
+ return TRUE;
+}
+
+/*!
+ \overload
+
+ Resizes the array to \a nPoints and sets the points in the array
+ to the values taken from the variable argument list.
+
+ Returns TRUE if successful, or FALSE if the array could not be
+ resized (typically due to lack of memory).
+
+ The example code creates an array with two points (1,2) and (3,4):
+
+ \code
+ TQPointArray a;
+ a.setPoints( 2, 1,2, 3,4 );
+ \endcode
+
+ The points are given as a sequence of integers, starting with \a
+ firstx then \a firsty, and so on.
+
+ \sa resize(), putPoints()
+*/
+
+bool TQPointArray::setPoints( int nPoints, int firstx, int firsty, ... )
+{
+ va_list ap;
+ if ( !resize(nPoints) )
+ return FALSE;
+ setPoint( 0, firstx, firsty ); // set first point
+ int i = 1, x, y;
+ nPoints--;
+ va_start( ap, firsty );
+ while ( nPoints-- ) {
+ x = va_arg( ap, int );
+ y = va_arg( ap, int );
+ setPoint( i++, x, y );
+ }
+ va_end( ap );
+ return TRUE;
+}
+
+/*! \overload
+ \internal
+ Copies \a nPoints points from the \a points coord array into
+ this point array, and resizes the point array if
+ \c{index+nPoints} exceeds the size of the array.
+
+ Returns TRUE if successful, or FALSE if the array could not be
+ resized (typically due to lack of memory).
+
+*/
+
+bool TQPointArray::putPoints( int index, int nPoints, const TQCOORD *points )
+{
+ if ( index + nPoints > (int)size() ) { // extend array
+ if ( !resize( index + nPoints ) )
+ return FALSE;
+ }
+ int i = index;
+ while ( nPoints-- ) { // make array of points
+ setPoint( i++, *points, *(points+1) );
+ points++;
+ points++;
+ }
+ return TRUE;
+}
+
+/*!
+ Copies \a nPoints points from the variable argument list into this
+ point array from position \a index, and resizes the point array if
+ \c{index+nPoints} exceeds the size of the array.
+
+ Returns TRUE if successful, or FALSE if the array could not be
+ resized (typically due to lack of memory).
+
+ The example code creates an array with three points (4,5), (6,7)
+ and (8,9), by expanding the array from 1 to 3 points:
+
+ \code
+ TQPointArray a( 1 );
+ a[0] = TQPoint( 4, 5 );
+ a.putPoints( 1, 2, 6,7, 8,9 ); // index == 1, points == 2
+ \endcode
+
+ This has the same result, but here putPoints overwrites rather
+ than extends:
+ \code
+ TQPointArray a( 3 );
+ a.putPoints( 0, 3, 4,5, 0,0, 8,9 );
+ a.putPoints( 1, 1, 6,7 );
+ \endcode
+
+ The points are given as a sequence of integers, starting with \a
+ firstx then \a firsty, and so on.
+
+ \sa resize()
+*/
+
+bool TQPointArray::putPoints( int index, int nPoints, int firstx, int firsty,
+ ... )
+{
+ va_list ap;
+ if ( index + nPoints > (int)size() ) { // extend array
+ if ( !resize(index + nPoints) )
+ return FALSE;
+ }
+ if ( nPoints <= 0 )
+ return TRUE;
+ setPoint( index, firstx, firsty ); // set first point
+ int i = index + 1, x, y;
+ nPoints--;
+ va_start( ap, firsty );
+ while ( nPoints-- ) {
+ x = va_arg( ap, int );
+ y = va_arg( ap, int );
+ setPoint( i++, x, y );
+ }
+ va_end( ap );
+ return TRUE;
+}
+
+
+/*!
+ \overload
+
+ This version of the function copies \a nPoints from \a from into
+ this array, starting at \a index in this array and \a fromIndex in
+ \a from. \a fromIndex is 0 by default.
+
+ \code
+ TQPointArray a;
+ a.putPoints( 0, 3, 1,2, 0,0, 5,6 );
+ // a is now the three-point array ( 1,2, 0,0, 5,6 );
+ TQPointArray b;
+ b.putPoints( 0, 3, 4,4, 5,5, 6,6 );
+ // b is now ( 4,4, 5,5, 6,6 );
+ a.putPoints( 2, 3, b );
+ // a is now ( 1,2, 0,0, 4,4, 5,5, 6,6 );
+ \endcode
+*/
+
+bool TQPointArray::putPoints( int index, int nPoints,
+ const TQPointArray & from, int fromIndex )
+{
+ if ( index + nPoints > (int)size() ) { // extend array
+ if ( !resize(index + nPoints) )
+ return FALSE;
+ }
+ if ( nPoints <= 0 )
+ return TRUE;
+ int n = 0;
+ while( n < nPoints ) {
+ setPoint( index+n, from[fromIndex+n] );
+ n++;
+ }
+ return TRUE;
+}
+
+
+/*!
+ Returns the bounding rectangle of the points in the array, or
+ TQRect(0,0,0,0) if the array is empty.
+*/
+
+TQRect TQPointArray::boundingRect() const
+{
+ if ( isEmpty() )
+ return TQRect( 0, 0, 0, 0 ); // null rectangle
+ register TQPoint *pd = data();
+ int minx, maxx, miny, maxy;
+ minx = maxx = pd->x();
+ miny = maxy = pd->y();
+ pd++;
+ for ( int i=1; i<(int)size(); i++ ) { // tqfind min+max x and y
+ if ( pd->x() < minx )
+ minx = pd->x();
+ else if ( pd->x() > maxx )
+ maxx = pd->x();
+ if ( pd->y() < miny )
+ miny = pd->y();
+ else if ( pd->y() > maxy )
+ maxy = pd->y();
+ pd++;
+ }
+ return TQRect( TQPoint(minx,miny), TQPoint(maxx,maxy) );
+}
+
+
+static inline int fix_angle( int a )
+{
+ if ( a > 16*360 )
+ a %= 16*360;
+ else if ( a < -16*360 ) {
+ a = -( (-a) % (16*360) );
+ }
+ return a;
+}
+
+/*!
+ Sets the points of the array to those describing an arc of an
+ ellipse with size, width \a w by height \a h, and position (\a x,
+ \a y), starting from angle \a a1 and spanning by angle \a a2. The
+ resulting array has sufficient resolution for pixel accuracy (see
+ the overloaded function which takes an additional TQWMatrix
+ parameter).
+
+ Angles are specified in 16ths of a degree, i.e. a full circle
+ equals 5760 (16*360). Positive values mean counter-clockwise,
+ whereas negative values mean the clockwise direction. Zero degrees
+ is at the 3 o'clock position.
+
+ See the \link qcanvasellipse.html#anglediagram angle diagram\endlink.
+*/
+
+void TQPointArray::makeArc( int x, int y, int w, int h, int a1, int a2 )
+{
+#if !defined(TQT_OLD_MAKEELLIPSE) && !defined(TQT_NO_TRANSFORMATIONS)
+ TQWMatrix unit;
+ makeArc(x,y,w,h,a1,a2,unit);
+#else
+ a1 = fix_angle( a1 );
+ if ( a1 < 0 )
+ a1 += 16*360;
+ a2 = fix_angle( a2 );
+ int a3 = a2 > 0 ? a2 : -a2; // abs angle
+ makeEllipse( x, y, w, h );
+ int npts = a3*size()/(16*360); // # points in arc array
+ TQPointArray a(npts);
+ int i = a1*size()/(16*360);
+ int j = 0;
+ if ( a2 > 0 ) {
+ while ( npts-- ) {
+ if ( i >= (int)size() ) // wrap index
+ i = 0;
+ a.TQMemArray<TQPoint>::at( j++ ) = TQMemArray<TQPoint>::at( i++ );
+ }
+ } else {
+ while ( npts-- ) {
+ if ( i < 0 ) // wrap index
+ i = (int)size()-1;
+ a.TQMemArray<TQPoint>::at( j++ ) = TQMemArray<TQPoint>::at( i-- );
+ }
+ }
+ *this = a;
+ return;
+#endif
+}
+
+#ifndef TQT_NO_TRANSFORMATIONS
+// Based upon:
+// parelarc.c from Graphics Gems III
+// VanAken / Simar, "A Parametric Elliptical Arc Algorithm"
+//
+static void
+qtr_elips(TQPointArray& a, int off, double dxP, double dyP, double dxQ, double dyQ, double dxK, double dyK, int m)
+{
+#define PIV2 102944 /* fixed point PI/2 */
+#define TWOPI 411775 /* fixed point 2*PI */
+#define HALF 32768 /* fixed point 1/2 */
+
+ int xP, yP, xQ, yQ, xK, yK;
+ xP = int(dxP * 65536.0); yP = int(dyP * 65536.0);
+ xQ = int(dxQ * 65536.0); yQ = int(dyQ * 65536.0);
+ xK = int(dxK * 65536.0); yK = int(dyK * 65536.0);
+
+ int i;
+ int vx, ux, vy, uy, xJ, yJ;
+
+ vx = xK - xQ; /* displacements from center */
+ ux = xK - xP;
+ vy = yK - yQ;
+ uy = yK - yP;
+ xJ = xP - vx + HALF; /* center of ellipse J */
+ yJ = yP - vy + HALF;
+
+ int r;
+ ux -= (r = ux >> (2*m + 3)); /* cancel 2nd-order error */
+ ux -= (r >>= (2*m + 4)); /* cancel 4th-order error */
+ ux -= r >> (2*m + 3); /* cancel 6th-order error */
+ ux += vx >> (m + 1); /* cancel 1st-order error */
+ uy -= (r = uy >> (2*m + 3)); /* cancel 2nd-order error */
+ uy -= (r >>= (2*m + 4)); /* cancel 4th-order error */
+ uy -= r >> (2*m + 3); /* cancel 6th-order error */
+ uy += vy >> (m + 1); /* cancel 1st-order error */
+
+ const int qn = a.size()/4;
+ for (i = 0; i < qn; i++) {
+ a[off+i] = TQPoint((xJ + vx) >> 16, (yJ + vy) >> 16);
+ ux -= vx >> m;
+ vx += ux >> m;
+ uy -= vy >> m;
+ vy += uy >> m;
+ }
+
+#undef PIV2
+#undef TWOPI
+#undef HALF
+}
+
+
+/*!
+ \overload
+
+ Sets the points of the array to those describing an arc of an
+ ellipse with width \a w and height \a h and position (\a x, \a y),
+ starting from angle \a a1, and spanning angle by \a a2, and
+ transformed by the matrix \a xf. The resulting array has
+ sufficient resolution for pixel accuracy.
+
+ Angles are specified in 16ths of a degree, i.e. a full circle
+ equals 5760 (16*360). Positive values mean counter-clockwise,
+ whereas negative values mean the clockwise direction. Zero degrees
+ is at the 3 o'clock position.
+
+ See the \link qcanvasellipse.html#anglediagram angle diagram\endlink.
+*/
+void TQPointArray::makeArc( int x, int y, int w, int h,
+ int a1, int a2,
+ const TQWMatrix& xf )
+{
+#define PIV2 102944 /* fixed point PI/2 */
+ if ( --w < 0 || --h < 0 || !a2 ) {
+ resize( 0 );
+ return;
+ }
+
+ bool rev = a2 < 0;
+ if ( rev ) {
+ a1 += a2;
+ a2 = -a2;
+ }
+ a1 = fix_angle( a1 );
+ if ( a1 < 0 )
+ a1 += 16*360;
+ a2 = fix_angle( a2 );
+
+ bool arc = a1 != 0 || a2 != 360*16 || rev;
+
+ double xP, yP, xQ, yQ, xK, yK;
+
+ xf.map(x+w, y+h/2.0, &xP, &yP);
+ xf.map(x+w/2.0, y, &xQ, &yQ);
+ xf.map(x+w, y, &xK, &yK);
+
+ int m = 3;
+ int max;
+ int q = int(TQMAX(TQABS(xP-xQ),TQABS(yP-yQ)));
+ if ( arc )
+ q *= 2;
+ do {
+ m++;
+ max = 4*(1 + (PIV2 >> (16 - m)) );
+ } while (max < q && m < 16); // 16 limits memory usage on HUGE arcs
+
+ double inc = 1.0/(1<<m);
+
+ const int qn = (PIV2 >> (16 - m));
+ resize(qn*4);
+
+ qtr_elips(*this, 0, xP, yP, xQ, yQ, xK, yK, m);
+ xP = xQ; yP = yQ;
+ xf.map(x, y+h/2.0, &xQ, &yQ);
+ xf.map(x, y, &xK, &yK);
+ qtr_elips(*this, qn, xP, yP, xQ, yQ, xK, yK, m);
+ xP = xQ; yP = yQ;
+ xf.map(x+w/2.0, y+h, &xQ, &yQ);
+ xf.map(x, y+h, &xK, &yK);
+ qtr_elips(*this, qn*2, xP, yP, xQ, yQ, xK, yK, m);
+ xP = xQ; yP = yQ;
+ xf.map(x+w, y+h/2.0, &xQ, &yQ);
+ xf.map(x+w, y+h, &xK, &yK);
+ qtr_elips(*this, qn*3, xP, yP, xQ, yQ, xK, yK, m);
+
+ int n = size();
+
+ if ( arc ) {
+ double da1 = double(a1)*TQ_PI / (360*8);
+ double da3 = double(a2+a1)*TQ_PI / (360*8);
+ int i = int(da1/inc+0.5);
+ int l = int(da3/inc+0.5);
+ int k = (l-i)+1;
+ TQPointArray r(k);
+ int j = 0;
+
+ if ( rev ) {
+ while ( k-- )
+ r[j++] = at((i+k)%n);
+ } else {
+ while ( j < k ) {
+ r[j] = at((i+j)%n);
+ j++;
+ }
+ }
+ *this = r;
+ }
+#undef PIV2
+}
+
+#endif // TQT_NO_TRANSFORMATIONS
+
+/*!
+ Sets the points of the array to those describing an ellipse with
+ size, width \a w by height \a h, and position (\a x, \a y).
+
+ The returned array has sufficient resolution for use as pixels.
+*/
+void TQPointArray::makeEllipse( int x, int y, int w, int h )
+{ // midpoint, 1/4 ellipse
+#if !defined(TQT_OLD_MAKEELLIPSE) && !defined(TQT_NO_TRANSFORMATIONS)
+ TQWMatrix unit;
+ makeArc(x,y,w,h,0,360*16,unit);
+ return;
+#else
+ if ( w <= 0 || h <= 0 ) {
+ if ( w == 0 || h == 0 ) {
+ resize( 0 );
+ return;
+ }
+ if ( w < 0 ) { // negative width
+ w = -w;
+ x -= w;
+ }
+ if ( h < 0 ) { // negative height
+ h = -h;
+ y -= h;
+ }
+ }
+ int s = (w+h+2)/2; // max size of xx,yy array
+ int *px = new int[s]; // 1/4th of ellipse
+ int *py = new int[s];
+ int xx, yy, i=0;
+ double d1, d2;
+ double a2=(w/2)*(w/2), b2=(h/2)*(h/2);
+ xx = 0;
+ yy = int(h/2);
+ d1 = b2 - a2*(h/2) + 0.25*a2;
+ px[i] = xx;
+ py[i] = yy;
+ i++;
+ while ( a2*(yy-0.5) > b2*(xx+0.5) ) { // region 1
+ if ( d1 < 0 ) {
+ d1 = d1 + b2*(3.0+2*xx);
+ xx++;
+ } else {
+ d1 = d1 + b2*(3.0+2*xx) + 2.0*a2*(1-yy);
+ xx++;
+ yy--;
+ }
+ px[i] = xx;
+ py[i] = yy;
+ i++;
+ }
+ d2 = b2*(xx+0.5)*(xx+0.5) + a2*(yy-1)*(yy-1) - a2*b2;
+ while ( yy > 0 ) { // region 2
+ if ( d2 < 0 ) {
+ d2 = d2 + 2.0*b2*(xx+1) + a2*(3-2*yy);
+ xx++;
+ yy--;
+ } else {
+ d2 = d2 + a2*(3-2*yy);
+ yy--;
+ }
+ px[i] = xx;
+ py[i] = yy;
+ i++;
+ }
+ s = i;
+ resize( 4*s ); // make full point array
+ x += w/2;
+ y += h/2;
+ for ( i=0; i<s; i++ ) { // mirror
+ xx = px[i];
+ yy = py[i];
+ setPoint( s-i-1, x+xx, y-yy );
+ setPoint( s+i, x-xx, y-yy );
+ setPoint( 3*s-i-1, x-xx, y+yy );
+ setPoint( 3*s+i, x+xx, y+yy );
+ }
+ delete[] px;
+ delete[] py;
+#endif
+}
+
+#ifndef TQT_NO_BEZIER
+// Work functions for TQPointArray::cubicBezier()
+static
+void split(const double *p, double *l, double *r)
+{
+ double tmpx;
+ double tmpy;
+
+ l[0] = p[0];
+ l[1] = p[1];
+ r[6] = p[6];
+ r[7] = p[7];
+
+ l[2] = (p[0]+ p[2])/2;
+ l[3] = (p[1]+ p[3])/2;
+ tmpx = (p[2]+ p[4])/2;
+ tmpy = (p[3]+ p[5])/2;
+ r[4] = (p[4]+ p[6])/2;
+ r[5] = (p[5]+ p[7])/2;
+
+ l[4] = (l[2]+ tmpx)/2;
+ l[5] = (l[3]+ tmpy)/2;
+ r[2] = (tmpx + r[4])/2;
+ r[3] = (tmpy + r[5])/2;
+
+ l[6] = (l[4]+ r[2])/2;
+ l[7] = (l[5]+ r[3])/2;
+ r[0] = l[6];
+ r[1] = l[7];
+}
+
+// Based on:
+//
+// A Fast 2D Point-On-Line Test
+// by Alan Paeth
+// from "Graphics Gems", Academic Press, 1990
+static
+int pnt_on_line( const int* p, const int* q, const int* t )
+{
+/*
+ * given a line through P:(px,py) Q:(qx,qy) and T:(tx,ty)
+ * return 0 if T is not on the line through <--P--Q-->
+ * 1 if T is on the open ray ending at P: <--P
+ * 2 if T is on the closed interior along: P--Q
+ * 3 if T is on the open ray beginning at Q: Q-->
+ *
+ * Example: consider the line P = (3,2), Q = (17,7). A plot
+ * of the test points T(x,y) (with 0 mapped onto '.') yields:
+ *
+ * 8| . . . . . . . . . . . . . . . . . 3 3
+ * Y 7| . . . . . . . . . . . . . . 2 2 Q 3 3 Q = 2
+ * 6| . . . . . . . . . . . 2 2 2 2 2 . . .
+ * a 5| . . . . . . . . 2 2 2 2 2 2 . . . . .
+ * x 4| . . . . . 2 2 2 2 2 2 . . . . . . . .
+ * i 3| . . . 2 2 2 2 2 . . . . . . . . . . .
+ * s 2| 1 1 P 2 2 . . . . . . . . . . . . . . P = 2
+ * 1| 1 1 . . . . . . . . . . . . . . . . .
+ * +--------------------------------------
+ * 1 2 3 4 5 X-axis 10 15 19
+ *
+ * Point-Line distance is normalized with the Infinity Norm
+ * avoiding square-root code and tightening the test vs the
+ * Manhattan Norm. All math is done on the field of integers.
+ * The latter tqreplaces the initial ">= MAX(...)" test with
+ * "> (ABS(qx-px) + ABS(qy-py))" loosening both inequality
+ * and norm, yielding a broader target line for selection.
+ * The tightest test is employed here for best discrimination
+ * in merging collinear (to grid coordinates) vertex chains
+ * into a larger, spanning vectors within the Lemming editor.
+ */
+
+ // if all points are coincident, return condition 2 (on line)
+ if(q[0]==p[0] && q[1]==p[1] && q[0]==t[0] && q[1]==t[1]) {
+ return 2;
+ }
+
+ if ( TQABS((q[1]-p[1])*(t[0]-p[0])-(t[1]-p[1])*(q[0]-p[0])) >=
+ (TQMAX(TQABS(q[0]-p[0]), TQABS(q[1]-p[1])))) return 0;
+
+ if (((q[0]<p[0])&&(p[0]<t[0])) || ((q[1]<p[1])&&(p[1]<t[1])))
+ return 1 ;
+ if (((t[0]<p[0])&&(p[0]<q[0])) || ((t[1]<p[1])&&(p[1]<q[1])))
+ return 1 ;
+ if (((p[0]<q[0])&&(q[0]<t[0])) || ((p[1]<q[1])&&(q[1]<t[1])))
+ return 3 ;
+ if (((t[0]<q[0])&&(q[0]<p[0])) || ((t[1]<q[1])&&(q[1]<p[1])))
+ return 3 ;
+
+ return 2 ;
+}
+static
+void polygonizeTQBezier( double* acc, int& accsize, const double ctrl[],
+ int maxsize )
+{
+ if ( accsize > maxsize / 2 )
+ {
+ // This never happens in practice.
+
+ if ( accsize >= maxsize-4 )
+ return;
+ // Running out of space - approximate by a line.
+ acc[accsize++] = ctrl[0];
+ acc[accsize++] = ctrl[1];
+ acc[accsize++] = ctrl[6];
+ acc[accsize++] = ctrl[7];
+ return;
+ }
+
+ //intersects:
+ double l[8];
+ double r[8];
+ split( ctrl, l, r);
+
+ // convert to integers for line condition check
+ int c0[2]; c0[0] = int(ctrl[0]); c0[1] = int(ctrl[1]);
+ int c1[2]; c1[0] = int(ctrl[2]); c1[1] = int(ctrl[3]);
+ int c2[2]; c2[0] = int(ctrl[4]); c2[1] = int(ctrl[5]);
+ int c3[2]; c3[0] = int(ctrl[6]); c3[1] = int(ctrl[7]);
+
+ // #### Duplication needed?
+ if ( TQABS(c1[0]-c0[0]) <= 1 && TQABS(c1[1]-c0[1]) <= 1
+ && TQABS(c2[0]-c0[0]) <= 1 && TQABS(c2[1]-c0[1]) <= 1
+ && TQABS(c3[0]-c1[0]) <= 1 && TQABS(c3[1]-c0[1]) <= 1 )
+ {
+ // Approximate by one line.
+ // Dont need to write last pt as it is the same as first pt
+ // on the next segment
+ acc[accsize++] = l[0];
+ acc[accsize++] = l[1];
+ return;
+ }
+
+ if ( ( pnt_on_line( c0, c3, c1 ) == 2 && pnt_on_line( c0, c3, c2 ) == 2 )
+ || ( TQABS(c1[0]-c0[0]) <= 1 && TQABS(c1[1]-c0[1]) <= 1
+ && TQABS(c2[0]-c0[0]) <= 1 && TQABS(c2[1]-c0[1]) <= 1
+ && TQABS(c3[0]-c1[0]) <= 1 && TQABS(c3[1]-c0[1]) <= 1 ) )
+ {
+ // Approximate by one line.
+ // Dont need to write last pt as it is the same as first pt
+ // on the next segment
+ acc[accsize++] = l[0];
+ acc[accsize++] = l[1];
+ return;
+ }
+
+ // Too big and too curved - recusively subdivide.
+ polygonizeTQBezier( acc, accsize, l, maxsize );
+ polygonizeTQBezier( acc, accsize, r, maxsize );
+}
+
+/*!
+ Returns the Bezier points for the four control points in this
+ array.
+*/
+
+TQPointArray TQPointArray::cubicBezier() const
+{
+#ifdef USE_SIMPLE_TQBEZIER_CODE
+ if ( size() != 4 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPointArray::bezier: The array must have 4 control points" );
+#endif
+ TQPointArray p;
+ return p;
+ }
+
+ int v;
+ float xvec[4];
+ float yvec[4];
+ for ( v=0; v<4; v++ ) { // store all x,y in xvec,yvec
+ int x, y;
+ point( v, &x, &y );
+ xvec[v] = (float)x;
+ yvec[v] = (float)y;
+ }
+
+ TQRect r = boundingRect();
+ int m = TQMAX(r.width(),r.height())/2;
+ m = TQMIN(m,30); // m = number of result points
+ if ( m < 2 ) // at least two points
+ m = 2;
+ TQPointArray p( m ); // p = Bezier point array
+ register TQPointData *pd = p.data();
+
+ float x0 = xvec[0], y0 = yvec[0];
+ float dt = 1.0F/m;
+ float cx = 3.0F * (xvec[1] - x0);
+ float bx = 3.0F * (xvec[2] - xvec[1]) - cx;
+ float ax = xvec[3] - (x0 + cx + bx);
+ float cy = 3.0F * (yvec[1] - y0);
+ float by = 3.0F * (yvec[2] - yvec[1]) - cy;
+ float ay = yvec[3] - (y0 + cy + by);
+ float t = dt;
+
+ pd->rx() = (TQCOORD)xvec[0];
+ pd->ry() = (TQCOORD)yvec[0];
+ pd++;
+ m -= 2;
+
+ while ( m-- ) {
+ pd->rx() = (TQCOORD)tqRound( ((ax * t + bx) * t + cx) * t + x0 );
+ pd->ry() = (TQCOORD)tqRound( ((ay * t + by) * t + cy) * t + y0 );
+ pd++;
+ t += dt;
+ }
+
+ pd->rx() = (TQCOORD)xvec[3];
+ pd->ry() = (TQCOORD)yvec[3];
+
+ return p;
+#else
+
+ if ( size() != 4 ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPointArray::bezier: The array must have 4 control points" );
+#endif
+ TQPointArray pa;
+ return pa;
+ } else {
+ TQRect r = boundingRect();
+ int m = 4+2*TQMAX(r.width(),r.height());
+ double *p = new double[m];
+ double ctrl[8];
+ int i;
+ for (i=0; i<4; i++) {
+ ctrl[i*2] = at(i).x();
+ ctrl[i*2+1] = at(i).y();
+ }
+ int len=0;
+ polygonizeTQBezier( p, len, ctrl, m );
+ TQPointArray pa((len/2)+1); // one extra point for last point on line
+ int j=0;
+ for (i=0; j<len; i++) {
+ int x = tqRound(p[j++]);
+ int y = tqRound(p[j++]);
+ pa[i] = TQPoint(x,y);
+ }
+ // add last pt on the line, which will be at the last control pt
+ pa[(int)pa.size()-1] = at(3);
+ delete[] p;
+
+ return pa;
+ }
+
+#endif
+}
+#endif //TQT_NO_BEZIER
+
+/*****************************************************************************
+ TQPointArray stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQPointArray
+
+ Writes the point array, \a a to the stream \a s and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQPointArray &a )
+{
+ register uint i;
+ uint len = a.size();
+ s << len; // write size of array
+ for ( i=0; i<len; i++ ) // write each point
+ s << a.point( i );
+ return s;
+}
+
+/*!
+ \relates TQPointArray
+
+ Reads a point array, \a a from the stream \a s and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQPointArray &a )
+{
+ register uint i;
+ uint len;
+ s >> len; // read size of array
+ if ( !a.resize( len ) ) // no memory
+ return s;
+ TQPoint p;
+ for ( i=0; i<len; i++ ) { // read each point
+ s >> p;
+ a.setPoint( i, p );
+ }
+ return s;
+}
+#endif //TQT_NO_DATASTREAM
+
+
+
+struct TQShortPoint { // Binary compatible with XPoint
+ short x, y;
+};
+
+uint TQPointArray::splen = 0;
+void* TQPointArray::sp = 0; // Really a TQShortPoint*
+
+/*!
+ \internal
+
+ Converts the point coords to short (16bit) size, compatible with
+ X11's XPoint structure. The pointer returned points to a static
+ array, so its contents will be overwritten the next time this
+ function is called.
+*/
+
+void* TQPointArray::shortPoints( int index, int nPoints ) const
+{
+
+ if ( isNull() || !nPoints )
+ return 0;
+ TQPoint* p = data();
+ p += index;
+ uint i = nPoints < 0 ? size() : nPoints;
+ if ( splen < i ) {
+ if ( sp )
+ delete[] ((TQShortPoint*)sp);
+ sp = new TQShortPoint[i];
+ splen = i;
+ }
+ TQShortPoint* ps = (TQShortPoint*)sp;
+ while ( i-- ) {
+ ps->x = (short)p->x();
+ ps->y = (short)p->y();
+ p++;
+ ps++;
+ }
+ return sp;
+}
+
+
+/*!
+ \internal
+
+ Deallocates the internal buffer used by shortPoints().
+*/
+
+void TQPointArray::cleanBuffers()
+{
+ if ( sp )
+ delete[] ((TQShortPoint*)sp);
+ sp = 0;
+ splen = 0;
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpointarray.h b/tqtinterface/qt4/src/kernel/tqpointarray.h
new file mode 100644
index 0000000..41a31f9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpointarray.h
@@ -0,0 +1,195 @@
+/****************************************************************************
+**
+** Definition of TQPointArray class
+**
+** Created : 940213
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPOINTARRAY_H
+#define TQPOINTARRAY_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqmemarray.h"
+#include "tqpoint.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/qpolygon.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Qt3SupportLight)
+
+class Q_COMPAT_EXPORT TQPointArray : public QPolygon, virtual public TQt
+{
+public:
+ inline TQPointArray() : QPolygon() {}
+ inline TQPointArray(const QRect &r, bool closed=false) : QPolygon(r, closed) {}
+ inline TQPointArray(const QPolygon& a) : QPolygon(a) {}
+ inline TQPointArray( int nPoints, const TQCOORD *points ) : QPolygon() { setPoints( nPoints, points ); }
+
+ inline TQPointArray copy() const { return *this; }
+ inline bool isNull() { return isEmpty(); }
+ void makeEllipse(int x, int y, int w, int h);
+#ifndef QT_NO_WMATRIX
+ void makeArc(int x, int y, int w, int h, int a1, int a2);
+ void makeArc(int x, int y, int w, int h, int a1, int a2, const QMatrix &matrix);
+#endif
+ TQPointArray cubicBezier() const;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#else // USE_QT4
+
+#if defined(TQ_TEMPLATEDLL)
+//TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMemArray<TQPoint>;
+#endif
+
+class TQ_EXPORT TQPointArray : public TQMemArray<TQPoint>
+{
+public:
+ TQPointArray() {}
+ ~TQPointArray() {}
+ TQPointArray( int size ) : TQMemArray<TQPoint>( size ) {}
+ TQPointArray( const TQPointArray &a ) : TQMemArray<TQPoint>( a ) {}
+ TQPointArray( const TQRect &r, bool closed=FALSE );
+ TQPointArray( int nPoints, const TQCOORD *points );
+
+ TQPointArray &operator=( const TQPointArray &a )
+ { return (TQPointArray&)assign( a ); }
+
+ TQPointArray copy() const
+ { TQPointArray tmp; return *((TQPointArray*)&tmp.duplicate(*this)); }
+
+ void translate( int dx, int dy );
+ TQRect boundingRect() const;
+
+ void point( uint i, int *x, int *y ) const;
+ TQPoint point( uint i ) const;
+ void setPoint( uint i, int x, int y );
+ void setPoint( uint i, const TQPoint &p );
+ bool setPoints( int nPoints, const TQCOORD *points );
+ bool setPoints( int nPoints, int firstx, int firsty, ... );
+ bool putPoints( int index, int nPoints, const TQCOORD *points );
+ bool putPoints( int index, int nPoints, int firstx, int firsty, ... );
+ bool putPoints( int index, int nPoints,
+ const TQPointArray & from, int fromIndex=0 );
+
+ void makeArc( int x, int y, int w, int h, int a1, int a2 );
+ void makeEllipse( int x, int y, int w, int h );
+ void makeArc( int x, int y, int w, int h, int a1, int a2,
+ const TQWMatrix& );
+#ifndef TQT_NO_BEZIER
+ TQPointArray cubicBezier() const;
+#endif
+ void* shortPoints( int index = 0, int nPoints = -1 ) const;
+ static void cleanBuffers();
+
+protected:
+ static uint splen;
+ static void* sp;
+};
+
+
+/*****************************************************************************
+ TQPointArray stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQPointArray & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQPointArray & );
+#endif
+
+/*****************************************************************************
+ Misc. TQPointArray functions
+ *****************************************************************************/
+
+inline void TQPointArray::setPoint( uint i, const TQPoint &p )
+{
+ setPoint( i, p.x(), p.y() );
+}
+
+#endif // USE_QT4
+
+#endif // TQPOINTARRAY_H
diff --git a/tqtinterface/qt4/src/kernel/tqpolygonscanner.cpp b/tqtinterface/qt4/src/kernel/tqpolygonscanner.cpp
new file mode 100644
index 0000000..78e35ab
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpolygonscanner.cpp
@@ -0,0 +1,937 @@
+/****************************************************************************
+**
+** Implementation of TQPolygonScanner class
+**
+** Created : 000120
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqpolygonscanner.h"
+#include "tqpointarray.h"
+#include <stdlib.h>
+
+
+// Based on Xserver code miFillGeneralPoly...
+/*
+ *
+ * Written by Brian Kelleher; Oct. 1985
+ *
+ * Routine to fill a polygon. Two fill rules are
+ * supported: frWINDING and frEVENODD.
+ *
+ * See fillpoly.h for a complete description of the algorithm.
+ */
+
+/*
+ * These are the data structures needed to scan
+ * convert regions. Two different scan conversion
+ * methods are available -- the even-odd method, and
+ * the winding number method.
+ * The even-odd rule states that a point is inside
+ * the polygon if a ray drawn from that point in any
+ * direction will pass through an odd number of
+ * path segments.
+ * By the winding number rule, a point is decided
+ * to be inside the polygon if a ray drawn from that
+ * point in any direction passes through a different
+ * number of clockwise and counterclockwise path
+ * segments.
+ *
+ * These data structures are adapted somewhat from
+ * the algorithm in (Foley/Van Dam) for scan converting
+ * polygons.
+ * The basic algorithm is to start at the top (smallest y)
+ * of the polygon, stepping down to the bottom of
+ * the polygon by incrementing the y coordinate. We
+ * keep a list of edges which the current scanline crosses,
+ * sorted by x. This list is called the Active Edge Table (AET)
+ * As we change the y-coordinate, we update each entry in
+ * in the active edge table to reflect the edges new xcoord.
+ * This list must be sorted at each scanline in case
+ * two edges intersect.
+ * We also keep a data structure known as the Edge Table (ET),
+ * which keeps track of all the edges which the current
+ * scanline has not yet reached. The ET is basically a
+ * list of ScanLineList structures containing a list of
+ * edges which are entered at a given scanline. There is one
+ * ScanLineList per scanline at which an edge is entered.
+ * When we enter a new edge, we move it from the ET to the AET.
+ *
+ * From the AET, we can implement the even-odd rule as in
+ * (Foley/Van Dam).
+ * The winding number rule is a little trickier. We also
+ * keep the EdgeTableEntries in the AET linked by the
+ * nextWETE (winding EdgeTableEntry) link. This allows
+ * the edges to be linked just as before for updating
+ * purposes, but only uses the edges linked by the nextWETE
+ * link as edges representing spans of the polygon to
+ * drawn (as with the even-odd rule).
+ */
+
+/* $XConsortium: miscanfill.h,v 1.5 94/04/17 20:27:50 dpw Exp $ */
+/*
+
+Copyright (c) 1987 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+*/
+
+
+/*
+ * scanfill.h
+ *
+ * Written by Brian Kelleher; Jan 1985
+ *
+ * This file tqcontains a few macros to help track
+ * the edge of a filled object. The object is assumed
+ * to be filled in scanline order, and thus the
+ * algorithm used is an extension of Bresenham's line
+ * drawing algorithm which assumes that y is always the
+ * major axis.
+ * Since these pieces of code are the same for any filled tqshape,
+ * it is more convenient to gather the library in one
+ * place, but since these pieces of code are also in
+ * the inner loops of output primitives, procedure call
+ * overhead is out of the question.
+ * See the author for a derivation if needed.
+ */
+
+/*
+ * In scan converting polygons, we want to choose those pixels
+ * which are inside the polygon. Thus, we add .5 to the starting
+ * x coordinate for both left and right edges. Now we choose the
+ * first pixel which is inside the pgon for the left edge and the
+ * first pixel which is outside the pgon for the right edge.
+ * Draw the left pixel, but not the right.
+ *
+ * How to add .5 to the starting x coordinate:
+ * If the edge is moving to the right, then subtract dy from the
+ * error term from the general form of the algorithm.
+ * If the edge is moving to the left, then add dy to the error term.
+ *
+ * The reason for the difference between edges moving to the left
+ * and edges moving to the right is simple: If an edge is moving
+ * to the right, then we want the algorithm to flip immediately.
+ * If it is moving to the left, then we don't want it to flip until
+ * we traverse an entire pixel.
+ */
+#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
+ int dx; /* local storage */ \
+\
+ /* \
+ * if the edge is horizontal, then it is ignored \
+ * and assumed not to be processed. Otherwise, do this stuff. \
+ */ \
+ if ((dy) != 0) { \
+ xStart = (x1); \
+ dx = (x2) - xStart; \
+ if (dx < 0) { \
+ m = dx / (dy); \
+ m1 = m - 1; \
+ incr1 = -2 * dx + 2 * (dy) * m1; \
+ incr2 = -2 * dx + 2 * (dy) * m; \
+ d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
+ } else { \
+ m = dx / (dy); \
+ m1 = m + 1; \
+ incr1 = 2 * dx - 2 * (dy) * m1; \
+ incr2 = 2 * dx - 2 * (dy) * m; \
+ d = -2 * m * (dy) + 2 * dx; \
+ } \
+ } \
+}
+
+#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
+ if (m1 > 0) { \
+ if (d > 0) { \
+ minval += m1; \
+ d += incr1; \
+ } \
+ else { \
+ minval += m; \
+ d += incr2; \
+ } \
+ } else {\
+ if (d >= 0) { \
+ minval += m1; \
+ d += incr1; \
+ } \
+ else { \
+ minval += m; \
+ d += incr2; \
+ } \
+ } \
+}
+
+
+/*
+ * This structure tqcontains all of the information needed
+ * to run the bresenham algorithm.
+ * The variables may be hardcoded into the declarations
+ * instead of using this structure to make use of
+ * register declarations.
+ */
+typedef struct {
+ int minor; /* minor axis */
+ int d; /* decision variable */
+ int m, m1; /* slope and slope+1 */
+ int incr1, incr2; /* error increments */
+} BRESINFO;
+
+
+#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
+ BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \
+ bres.m, bres.m1, bres.incr1, bres.incr2)
+
+#define BRESINCRPGONSTRUCT(bres) \
+ BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2)
+
+
+typedef struct _EdgeTableEntry {
+ int ymax; /* ycoord at which we exit this edge. */
+ BRESINFO bres; /* Bresenham info to run the edge */
+ struct _EdgeTableEntry *next; /* next in the list */
+ struct _EdgeTableEntry *back; /* for insertion sort */
+ struct _EdgeTableEntry *nextWETE; /* for winding num rule */
+ int ClockWise; /* flag for winding number rule */
+} EdgeTableEntry;
+
+
+typedef struct _ScanLineList{
+ int scanline; /* the scanline represented */
+ EdgeTableEntry *edgelist; /* header node */
+ struct _ScanLineList *next; /* next in the list */
+} ScanLineList;
+
+
+typedef struct {
+ int ymax; /* ymax for the polygon */
+ int ymin; /* ymin for the polygon */
+ ScanLineList scanlines; /* header node */
+} EdgeTable;
+
+
+/*
+ * Here is a struct to help with storage allocation
+ * so we can allocate a big chunk at a time, and then take
+ * pieces from this heap when we need to.
+ */
+#define SLLSPERBLOCK 25
+
+typedef struct _ScanLineListBlock {
+ ScanLineList SLLs[SLLSPERBLOCK];
+ struct _ScanLineListBlock *next;
+} ScanLineListBlock;
+
+/*
+ * number of points to buffer before sending them off
+ * to scanlines() : Must be an even number
+ */
+#define NUMPTSTOBUFFER 200
+
+/*
+ *
+ * a few macros for the inner loops of the fill code where
+ * performance considerations don't allow a procedure call.
+ *
+ * Evaluate the given edge at the given scanline.
+ * If the edge has expired, then we leave it and fix up
+ * the active edge table; otherwise, we increment the
+ * x value to be ready for the next scanline.
+ * The winding number rule is in effect, so we must notify
+ * the caller when the edge has been removed so he
+ * can reorder the Winding Active Edge Table.
+ */
+#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
+ if (pAET->ymax == y) { /* leaving this edge */ \
+ pPrevAET->next = pAET->next; \
+ pAET = pPrevAET->next; \
+ fixWAET = 1; \
+ if (pAET) \
+ pAET->back = pPrevAET; \
+ } \
+ else { \
+ BRESINCRPGONSTRUCT(pAET->bres); \
+ pPrevAET = pAET; \
+ pAET = pAET->next; \
+ } \
+}
+
+
+/*
+ * Evaluate the given edge at the given scanline.
+ * If the edge has expired, then we leave it and fix up
+ * the active edge table; otherwise, we increment the
+ * x value to be ready for the next scanline.
+ * The even-odd rule is in effect.
+ */
+#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
+ if (pAET->ymax == y) { /* leaving this edge */ \
+ pPrevAET->next = pAET->next; \
+ pAET = pPrevAET->next; \
+ if (pAET) \
+ pAET->back = pPrevAET; \
+ } \
+ else { \
+ BRESINCRPGONSTRUCT(pAET->bres) \
+ pPrevAET = pAET; \
+ pAET = pAET->next; \
+ } \
+}
+
+/***********************************************************
+
+Copyright (c) 1987 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSETQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#define MAXINT 0x7fffffff
+#define MININT -MAXINT
+
+/*
+ * fillUtils.c
+ *
+ * Written by Brian Kelleher; Oct. 1985
+ *
+ * This module tqcontains all of the utility functions
+ * needed to scan convert a polygon.
+ *
+ */
+/*
+ * InsertEdgeInET
+ *
+ * Insert the given edge into the edge table.
+ * First we must tqfind the correct bucket in the
+ * Edge table, then tqfind the right slot in the
+ * bucket. Finally, we can insert it.
+ *
+ */
+static bool
+miInsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE,
+ int scanline, ScanLineListBlock **SLLBlock, int *iSLLBlock)
+{
+ register EdgeTableEntry *start, *prev;
+ register ScanLineList *pSLL, *pPrevSLL;
+ ScanLineListBlock *tmpSLLBlock;
+
+ /*
+ * tqfind the right bucket to put the edge into
+ */
+ pPrevSLL = &ET->scanlines;
+ pSLL = pPrevSLL->next;
+ while (pSLL && (pSLL->scanline < scanline))
+ {
+ pPrevSLL = pSLL;
+ pSLL = pSLL->next;
+ }
+
+ /*
+ * reassign pSLL (pointer to ScanLineList) if necessary
+ */
+ if ((!pSLL) || (pSLL->scanline > scanline))
+ {
+ if (*iSLLBlock > SLLSPERBLOCK-1)
+ {
+ tmpSLLBlock =
+ (ScanLineListBlock *)malloc(sizeof(ScanLineListBlock));
+ if (!tmpSLLBlock)
+ return FALSE;
+ (*SLLBlock)->next = tmpSLLBlock;
+ tmpSLLBlock->next = 0;
+ *SLLBlock = tmpSLLBlock;
+ *iSLLBlock = 0;
+ }
+ pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]);
+
+ pSLL->next = pPrevSLL->next;
+ pSLL->edgelist = 0;
+ pPrevSLL->next = pSLL;
+ }
+ pSLL->scanline = scanline;
+
+ /*
+ * now insert the edge in the right bucket
+ */
+ prev = 0;
+ start = pSLL->edgelist;
+ while (start && (start->bres.minor < ETE->bres.minor))
+ {
+ prev = start;
+ start = start->next;
+ }
+ ETE->next = start;
+
+ if (prev)
+ prev->next = ETE;
+ else
+ pSLL->edgelist = ETE;
+ return TRUE;
+}
+
+/*
+ * CreateEdgeTable
+ *
+ * This routine creates the edge table for
+ * scan converting polygons.
+ * The Edge Table (ET) looks like:
+ *
+ * EdgeTable
+ * --------
+ * | ymax | ScanLineLists
+ * |scanline|-->------------>-------------->...
+ * -------- |scanline| |scanline|
+ * |edgelist| |edgelist|
+ * --------- ---------
+ * | |
+ * | |
+ * V V
+ * list of ETEs list of ETEs
+ *
+ * where ETE is an EdgeTableEntry data structure,
+ * and there is one ScanLineList per scanline at
+ * which an edge is initially entered.
+ *
+ */
+
+typedef struct {
+#if defined(TQ_OS_MAC)
+ int y, x;
+#else
+ int x, y;
+#endif
+
+} DDXPointRec, *DDXPointPtr;
+
+/*
+ * Clean up our act.
+ */
+static void
+miFreeStorage(ScanLineListBlock *pSLLBlock)
+{
+ register ScanLineListBlock *tmpSLLBlock;
+
+ while (pSLLBlock)
+ {
+ tmpSLLBlock = pSLLBlock->next;
+ free(pSLLBlock);
+ pSLLBlock = tmpSLLBlock;
+ }
+}
+
+static bool
+miCreateETandAET(int count, DDXPointPtr pts, EdgeTable *ET,
+ EdgeTableEntry *AET, EdgeTableEntry *pETEs, ScanLineListBlock *pSLLBlock)
+{
+ register DDXPointPtr top, bottom;
+ register DDXPointPtr PrevPt, CurrPt;
+ int iSLLBlock = 0;
+
+ int dy;
+
+ if (count < 2) return TRUE;
+
+ /*
+ * initialize the Active Edge Table
+ */
+ AET->next = 0;
+ AET->back = 0;
+ AET->nextWETE = 0;
+ AET->bres.minor = MININT;
+
+ /*
+ * initialize the Edge Table.
+ */
+ ET->scanlines.next = 0;
+ ET->ymax = MININT;
+ ET->ymin = MAXINT;
+ pSLLBlock->next = 0;
+
+ PrevPt = &pts[count-1];
+
+ /*
+ * for each vertex in the array of points.
+ * In this loop we are dealing with two vertices at
+ * a time -- these make up one edge of the polygon.
+ */
+ while (count--)
+ {
+ CurrPt = pts++;
+
+ /*
+ * tqfind out which point is above and which is below.
+ */
+ if (PrevPt->y > CurrPt->y)
+ {
+ bottom = PrevPt, top = CurrPt;
+ pETEs->ClockWise = 0;
+ }
+ else
+ {
+ bottom = CurrPt, top = PrevPt;
+ pETEs->ClockWise = 1;
+ }
+
+ /*
+ * don't add horizontal edges to the Edge table.
+ */
+ if (bottom->y != top->y)
+ {
+ pETEs->ymax = bottom->y-1; /* -1 so we don't get last scanline */
+
+ /*
+ * initialize integer edge algorithm
+ */
+ dy = bottom->y - top->y;
+ BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres)
+
+ if (!miInsertEdgeInET(ET, pETEs, top->y, &pSLLBlock, &iSLLBlock))
+ {
+ miFreeStorage(pSLLBlock->next);
+ return FALSE;
+ }
+
+ ET->ymax = TQMAX(ET->ymax, PrevPt->y);
+ ET->ymin = TQMIN(ET->ymin, PrevPt->y);
+ pETEs++;
+ }
+
+ PrevPt = CurrPt;
+ }
+ return TRUE;
+}
+
+/*
+ * loadAET
+ *
+ * This routine moves EdgeTableEntries from the
+ * EdgeTable into the Active Edge Table,
+ * leaving them sorted by smaller x coordinate.
+ *
+ */
+
+static void
+miloadAET(EdgeTableEntry *AET, EdgeTableEntry *ETEs)
+{
+ register EdgeTableEntry *pPrevAET;
+ register EdgeTableEntry *tmp;
+
+ pPrevAET = AET;
+ AET = AET->next;
+ while (ETEs)
+ {
+ while (AET && (AET->bres.minor < ETEs->bres.minor))
+ {
+ pPrevAET = AET;
+ AET = AET->next;
+ }
+ tmp = ETEs->next;
+ ETEs->next = AET;
+ if (AET)
+ AET->back = ETEs;
+ ETEs->back = pPrevAET;
+ pPrevAET->next = ETEs;
+ pPrevAET = ETEs;
+
+ ETEs = tmp;
+ }
+}
+
+/*
+ * computeWAET
+ *
+ * This routine links the AET by the
+ * nextWETE (winding EdgeTableEntry) link for
+ * use by the winding number rule. The final
+ * Active Edge Table (AET) might look something
+ * like:
+ *
+ * AET
+ * ---------- --------- ---------
+ * |ymax | |ymax | |ymax |
+ * | ... | |... | |... |
+ * |next |->|next |->|next |->...
+ * |nextWETE| |nextWETE| |nextWETE|
+ * --------- --------- ^--------
+ * | | |
+ * V-------------------> V---> ...
+ *
+ */
+static void
+micomputeWAET(EdgeTableEntry *AET)
+{
+ register EdgeTableEntry *pWETE;
+ register int inside = 1;
+ register int isInside = 0;
+
+ AET->nextWETE = 0;
+ pWETE = AET;
+ AET = AET->next;
+ while (AET)
+ {
+ if (AET->ClockWise)
+ isInside++;
+ else
+ isInside--;
+
+ if ((!inside && !isInside) ||
+ ( inside && isInside))
+ {
+ pWETE->nextWETE = AET;
+ pWETE = AET;
+ inside = !inside;
+ }
+ AET = AET->next;
+ }
+ pWETE->nextWETE = 0;
+}
+
+/*
+ * InsertionSort
+ *
+ * Just a simple insertion sort using
+ * pointers and back pointers to sort the Active
+ * Edge Table.
+ *
+ */
+
+static int
+miInsertionSort(EdgeTableEntry *AET)
+{
+ register EdgeTableEntry *pETEchase;
+ register EdgeTableEntry *pETEinsert;
+ register EdgeTableEntry *pETEchaseBackTMP;
+ register int changed = 0;
+
+ AET = AET->next;
+ while (AET)
+ {
+ pETEinsert = AET;
+ pETEchase = AET;
+ while (pETEchase->back->bres.minor > AET->bres.minor)
+ pETEchase = pETEchase->back;
+
+ AET = AET->next;
+ if (pETEchase != pETEinsert)
+ {
+ pETEchaseBackTMP = pETEchase->back;
+ pETEinsert->back->next = AET;
+ if (AET)
+ AET->back = pETEinsert->back;
+ pETEinsert->next = pETEchase;
+ pETEchase->back->next = pETEinsert;
+ pETEchase->back = pETEinsert;
+ pETEinsert->back = pETEchaseBackTMP;
+ changed = 1;
+ }
+ }
+ return(changed);
+}
+
+/*!
+ \overload
+*/
+void TQPolygonScanner::scan(const TQPointArray& pa, bool winding, int index, int npoints)
+{
+ scan( pa, winding, index, npoints, TRUE );
+}
+
+/*!
+ \overload
+
+ If \a stitchable is FALSE, the right and bottom edges of the
+ polygon are included. This causes adjacent polygons to overlap.
+*/
+void TQPolygonScanner::scan(const TQPointArray& pa, bool winding, int index, int npoints, bool stitchable)
+{
+ scan( pa, winding, index, npoints,
+ stitchable ? Edge(Left+Top) : Edge(Left+Right+Top+Bottom) );
+}
+
+/*!
+ Calls processSpans() for all scanlines of the polygon defined by
+ \a npoints starting at \a index in \a pa.
+
+ If \a winding is TRUE, the Winding algorithm rather than the
+ Odd-Even rule is used.
+
+ The \a edges is any bitwise combination of:
+ \list
+ \i \c TQPolygonScanner::Left
+ \i \c TQPolygonScanner::Right
+ \i \c TQPolygonScanner::Top
+ \i \c TQPolygonScanner::Bottom
+ \endlist
+ \a edges determines which edges are included.
+
+ \warning The edges feature does not work properly.
+
+*/
+void TQPolygonScanner::scan( const TQPointArray& pa, bool winding, int index, int npoints, Edge edges )
+{
+
+
+ DDXPointPtr ptsIn = (DDXPointPtr)pa.data();
+ ptsIn += index;
+ register EdgeTableEntry *pAET; /* the Active Edge Table */
+ register int y; /* the current scanline */
+ register int nPts = 0; /* number of pts in buffer */
+ register EdgeTableEntry *pWETE; /* Winding Edge Table */
+ register ScanLineList *pSLL; /* Current ScanLineList */
+ register DDXPointPtr ptsOut; /* ptr to output buffers */
+ int *width;
+ DDXPointRec FirstPoint[NUMPTSTOBUFFER]; /* the output buffers */
+ int FirstWidth[NUMPTSTOBUFFER];
+ EdgeTableEntry *pPrevAET; /* previous AET entry */
+ EdgeTable ET; /* Edge Table header node */
+ EdgeTableEntry AET; /* Active ET header node */
+ EdgeTableEntry *pETEs; /* Edge Table Entries buff */
+ ScanLineListBlock SLLBlock; /* header for ScanLineList */
+ int fixWAET = 0;
+ int edge_l = (edges & Left) ? 1 : 0;
+ int edge_r = (edges & Right) ? 1 : 0;
+ int edge_t = 1; //#### (edges & Top) ? 1 : 0;
+ int edge_b = (edges & Bottom) ? 1 : 0;
+
+ if (npoints == -1)
+ npoints = pa.size();
+
+ if (npoints < 3)
+ return;
+
+ if(!(pETEs = (EdgeTableEntry *)
+ malloc(sizeof(EdgeTableEntry) * npoints)))
+ return;
+ ptsOut = FirstPoint;
+ width = FirstWidth;
+ if (!miCreateETandAET(npoints, ptsIn, &ET, &AET, pETEs, &SLLBlock))
+ {
+ free(pETEs);
+ return;
+ }
+ pSLL = ET.scanlines.next;
+
+ if (!winding)
+ {
+ /*
+ * for each scanline
+ */
+ for (y = ET.ymin+1-edge_t; y < ET.ymax+edge_b; y++)
+ {
+ /*
+ * Add a new edge to the active edge table when we
+ * get to the next edge.
+ */
+ if (pSLL && y == pSLL->scanline)
+ {
+ miloadAET(&AET, pSLL->edgelist);
+ pSLL = pSLL->next;
+ }
+ pPrevAET = &AET;
+ pAET = AET.next;
+
+ /*
+ * for each active edge
+ */
+ while (pAET)
+ {
+ ptsOut->x = pAET->bres.minor + 1 - edge_l;
+ ptsOut++->y = y;
+ *width++ = pAET->next->bres.minor - pAET->bres.minor
+ - 1 + edge_l + edge_r;
+ nPts++;
+
+ /*
+ * send out the buffer when its full
+ */
+ if (nPts == NUMPTSTOBUFFER)
+ {
+ processSpans( nPts, (TQPoint*)FirstPoint, FirstWidth );
+ ptsOut = FirstPoint;
+ width = FirstWidth;
+ nPts = 0;
+ }
+ EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
+ EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
+ }
+ miInsertionSort(&AET);
+ }
+ }
+ else /* default to WindingNumber */
+ {
+ /*
+ * for each scanline
+ */
+ for (y = ET.ymin+1-edge_t; y < ET.ymax+edge_b; y++)
+ {
+ /*
+ * Add a new edge to the active edge table when we
+ * get to the next edge.
+ */
+ if (pSLL && y == pSLL->scanline)
+ {
+ miloadAET(&AET, pSLL->edgelist);
+ micomputeWAET(&AET);
+ pSLL = pSLL->next;
+ }
+ pPrevAET = &AET;
+ pAET = AET.next;
+ pWETE = pAET;
+
+ /*
+ * for each active edge
+ */
+ while (pAET)
+ {
+ /*
+ * if the next edge in the active edge table is
+ * also the next edge in the winding active edge
+ * table.
+ */
+ if (pWETE == pAET)
+ {
+ ptsOut->x = pAET->bres.minor + 1 - edge_l;
+ ptsOut++->y = y;
+ *width++ = pAET->nextWETE->bres.minor - pAET->bres.minor - 1 + edge_l + edge_r;
+ nPts++;
+
+ /*
+ * send out the buffer
+ */
+ if (nPts == NUMPTSTOBUFFER)
+ {
+ processSpans( nPts, (TQPoint*)FirstPoint, FirstWidth );
+ ptsOut = FirstPoint;
+ width = FirstWidth;
+ nPts = 0;
+ }
+
+ pWETE = pWETE->nextWETE;
+ while (pWETE != pAET) {
+ EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET)
+ }
+ pWETE = pWETE->nextWETE;
+ }
+ EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET)
+ }
+
+ /*
+ * reevaluate the Winding active edge table if we
+ * just had to resort it or if we just exited an edge.
+ */
+ if (miInsertionSort(&AET) || fixWAET)
+ {
+ micomputeWAET(&AET);
+ fixWAET = 0;
+ }
+ }
+ }
+
+ /*
+ * Get any spans that we missed by buffering
+ */
+
+
+ processSpans( nPts, (TQPoint*)FirstPoint, FirstWidth );
+ free(pETEs);
+ miFreeStorage(SLLBlock.next);
+}
+/***** END OF X11-based CODE *****/
+
+
diff --git a/tqtinterface/qt4/src/kernel/tqpolygonscanner.h b/tqtinterface/qt4/src/kernel/tqpolygonscanner.h
new file mode 100644
index 0000000..433504e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpolygonscanner.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Definition of TQPolygonScanner class
+**
+** Created : 000120
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPOLYGONSCANNER_H
+#define TQPOLYGONSCANNER_H
+
+#ifndef TQT_H
+#include "tqglobal.h"
+#endif // TQT_H
+
+class TQPointArray;
+class TQPoint;
+
+class TQ_EXPORT TQPolygonScanner {
+public:
+ // BIC: fix for 3.0
+ void scan( const TQPointArray& pa, bool winding, int index=0, int npoints=-1 );
+ void scan( const TQPointArray& pa, bool winding, int index, int npoints, bool stitchable );
+ enum Edge { Left=1, Right=2, Top=4, Bottom=8 };
+ void scan( const TQPointArray& pa, bool winding, int index, int npoints, Edge edges );
+ virtual void processSpans( int n, TQPoint* point, int* width )=0;
+};
+
+#endif // TQPOLYGONSCANNER_H
diff --git a/tqtinterface/qt4/src/kernel/tqprinter.cpp b/tqtinterface/qt4/src/kernel/tqprinter.cpp
new file mode 100644
index 0000000..31c5c19
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqprinter.cpp
@@ -0,0 +1,1198 @@
+/**********************************************************************
+**
+** Implementation of TQPrinter class
+**
+** Created : 941003
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+// Nasty, nasty horrid HACK to get access to QPrinter's private members
+// This is TERRIBLE and I wish there was a way around it
+// This is a good example of the new, broken & irritating Qt4 API,
+// and the corresponding loss in functionality versus Qt3.
+// See also tqrect.cpp
+#define private protected
+#include <Qt/qprinter.h>
+#undef private
+
+#include "tqprinter.h"
+#include "tqprinter_p.h"
+
+#ifndef TQT_NO_PRINTER
+
+#ifdef USE_QT4
+
+#include "tqprintdialog.h"
+#include "private/qt4_qprinter_p.h"
+
+#ifdef Q_WS_MAC
+bool qt_compat_QPrinter_pageSetup(QPrinter *p, QWidget *parent)
+{
+ QPageSetupDialog psd(p, parent);
+ return psd.exec() != 0;
+}
+#endif // Q_WS_MAC
+
+bool qt_compat_QPrinter_printSetup(QPrinter *printer, QWidget *parent)
+{
+ TQPrintDialog dlg(TQT_TQPRINTER(printer), TQT_TQWIDGET(parent));
+ return dlg.exec() != 0;
+}
+
+#ifdef Q_WS_MAC
+/*!
+ Executes a page setup dialog so that the user can configure the type of
+ page used for printing. Returns true if the contents of the dialog are
+ accepted; returns false if the dialog is canceled.
+*/
+bool TQPrinter::pageSetup(QWidget *parent)
+{
+ return qt_compat_QPrinter_pageSetup(this, parent);
+}
+
+/*!
+ Executes a print setup dialog so that the user can configure the printing
+ process. Returns true if the contents of the dialog are accepted; returns
+ false if the dialog is canceled.
+*/
+bool TQPrinter::printSetup(QWidget *parent)
+{
+ return qt_compat_QPrinter_printSetup(this, parent);
+}
+#endif // Q_WS_MAC
+
+/*!
+ Use QPrintDialog instead.
+
+ \oldcode
+ if (printer->setup(parent))
+ ...
+ \newcode
+ QPrintDialog dialog(printer, parent);
+ if (dialog.exec())
+ ...
+ \endcode
+*/
+bool TQPrinter::setup(QWidget *parent)
+{
+ return qt_compat_QPrinter_printSetup(this, parent)
+#ifdef Q_WS_MAC
+ && qt_compat_QPrinter_pageSetup(this, parent);
+#endif
+ ;
+}
+
+/*!
+ Use QPrintDialog::minPage() instead.
+*/
+int TQPrinter::minPage() const
+{
+ return d_ptr->minPage;
+}
+
+/*!
+ Use QPrintDialog::maxPage() instead.
+*/
+int TQPrinter::maxPage() const
+{
+ return d_ptr->maxPage;
+}
+
+/*!
+ Use QPrintDialog::setMinMax() instead.
+*/
+void TQPrinter::setMinMax( int minPage, int maxPage )
+{
+ Q_ASSERT_X(minPage <= maxPage, "QPrinter::setMinMax",
+ "'min' must be less than or equal to 'max'");
+ d_ptr->minPage = minPage;
+ d_ptr->maxPage = maxPage;
+ d_ptr->options |= QPrintDialog::PrintPageRange;
+}
+
+/*!
+ Use QPrintDialog::setOption(QPrintDialog::PrintCollateCopies)
+ or QPrintDialog::setOptions(QPrintDialog::options()
+ & ~QPrintDialog::PrintCollateCopies) instead, depending on \a
+ enable.
+*/
+void TQPrinter::setCollateCopiesEnabled(bool enable)
+{
+ if (enable)
+ d_ptr->options |= QPrintDialog::PrintCollateCopies;
+ else
+ d_ptr->options &= ~QPrintDialog::PrintCollateCopies;
+}
+
+/*!
+ Returns true if the printer is set up to collate copies of printed documents;
+ otherwise returns false.
+
+ Use QPrintDialog::isOptionEnabled(QPrintDialog::PrintCollateCopies)
+ instead.
+
+ \sa collateCopies()
+*/
+bool TQPrinter::collateCopiesEnabled() const
+{
+ return (d_ptr->options & QPrintDialog::PrintCollateCopies);
+}
+
+/*!
+ Use QPrintDialog instead.
+*/
+void TQPrinter::setOptionEnabled( PrinterOption option, bool enable )
+{
+ if (enable)
+ d_ptr->options |= QPrintDialog::PrintDialogOption(1 << option);
+ else
+ d_ptr->options &= ~QPrintDialog::PrintDialogOption(1 << option);
+}
+
+/*!
+ Use QPrintDialog instead.
+*/
+bool TQPrinter::isOptionEnabled( PrinterOption option ) const
+{
+ return (d_ptr->options & QPrintDialog::PrintDialogOption(option));
+}
+
+/*!
+ \fn void QPrinter::setOutputToFile(bool enable)
+
+ Specifies whether the output should be written to a file or sent
+ directly to the printer.
+
+ Will output to a file if \a enable is true, or will output
+ directly to the printer if \a enable is false.
+
+ \sa outputToFile(), setOutputFileName()
+*/
+void TQPrinter::setOutputToFile(bool f)
+{
+ if (f) {
+ if (outputFileName().isEmpty())
+ setOutputFileName(QLatin1String("untitled_printer_document"));
+ } else {
+ setOutputFileName(QString());
+ }
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQPrinter tqprinter.h
+ \brief The TQPrinter class is a paint tqdevice that paints on a printer.
+
+ \ingroup images
+ \ingroup graphics
+ \mainclass
+
+ On Windows it uses the built-in printer drivers. On X11 it
+ generates postscript and sends that to lpr, lp, or another print
+ command.
+
+ TQPrinter is used in much the same way as TQWidget and TQPixmap are
+ used. The big difference is that you must keep track of the pages.
+
+ TQPrinter supports a number of settable parameters, most of which
+ can be changed by the end user when the application calls
+ TQPrinter::setup().
+
+ The most important parameters are:
+ \list
+ \i setOrientation() tells TQPrinter which page orientation to use (virtual).
+ \i setPageSize() tells TQPrinter what page size to expect from the
+ printer.
+ \i setResolution() tells TQPrinter what resolution you wish the
+ printer to provide (in dpi).
+ \i setFullPage() tells TQPrinter whether you want to deal with the
+ full page or just with the part the printer can draw on. The
+ default is FALSE, so that by default you should be able to paint
+ on (0,0). If TRUE the origin of the coordinate system will be in
+ the top left corner of the paper and most probably the printer
+ will not be able to paint something there due to it's physical
+ margins.
+ \i setNumCopies() tells TQPrinter how many copies of the document
+ it should print.
+ \i setMinMax() tells TQPrinter and TQPrintDialog what the allowed
+ range for fromPage() and toPage() are.
+ \endlist
+
+ Except where noted, you can only call the set functions before
+ setup(), or between TQPainter::end() and setup(). (Some may take
+ effect between setup() and begin(), or between begin() and end(),
+ but that's strictly undocumented and such behaviour may differ
+ depending on platform.)
+
+ There are also some settings that the user sets (through the
+ printer dialog) and that applications are expected to obey:
+
+ \list
+
+ \i pageOrder() tells the application program whether to print
+ first-page-first or last-page-first.
+
+ \i colorMode() tells the application program whether to print in
+ color or grayscale. (If you print in color and the printer does
+ not support color, TQt will try to approximate. The document may
+ take longer to print, but the quality should not be made visibly
+ poorer.)
+
+ \i fromPage() and toPage() indicate what pages the application
+ program should print.
+
+ \i paperSource() tells the application progam which paper source
+ to print from.
+
+ \endlist
+
+ You can of course call these functions to establish defaults
+ before you ask the user through TQPrinter::setup().
+
+ Once you start printing, calling newPage() is essential. You will
+ probably also need to look at the TQPaintDeviceMetrics for the
+ printer (see the \link simple-application.html#printersimple print
+ function\endlink in the Application walk-through). In previous versions,
+ paint tqdevice metrics were valid only after the TQPrinter has been set
+ up, i.e. after setup() has returned successfully. This is no longer
+ the case and paint tqdevice metrics can be requested safely before set up.
+
+ If you want to abort the print job, abort() will try its best to
+ stop printing. It may cancel the entire job or just some of it.
+
+ \omit Need a function to setup() without a dialog (i.e. use defaults).
+ \endomit
+
+ The TrueType font embedding for TQt's postscript driver uses code
+ by David Chappell of Trinity College Computing Center.
+
+ \legalese
+
+ Copyright 1995, Trinity College Computing Center.
+ Written by David Chappell.
+
+ Permission to use, copy, modify, and distribute this software and
+ its documentation for any purpose and without fee is hereby
+ granted, provided that the above copyright notice appear in all
+ copies and that both that copyright notice and this permission
+ notice appear in supporting documentation. This software is
+ provided "as is" without express or implied warranty.
+
+ TrueType font support. These functions allow PPR to generate
+ PostScript fonts from Microsoft compatible TrueType font files.
+
+ The functions in this file do most of the work to convert a
+ TrueType font to a type 3 PostScript font.
+
+ Most of the material in this file is derived from a program called
+ "ttf2ps" which L. S. Ng posted to the usenet news group
+ "comp.sources.postscript". The author did not provide a copyright
+ notice or indicate any restrictions on use.
+
+ Last revised 11 July 1995.
+
+*/
+
+/*!
+ \enum TQPrinter::PrinterMode
+
+ This enum describes the mode the printer should work in. It
+ basically presets a certain resolution and working mode.
+
+ \value ScreenResolution Sets the resolution of the print tqdevice to
+ the screen resolution. This has the big advantage that the results
+ obtained when painting on the printer will match more or less
+ exactly the visible output on the screen. It is the easiest to
+ use, as font metrics on the screen and on the printer are the
+ same. This is the default value. ScreenResolution will produce a
+ lower quality output than HighResolution and should only be used
+ for drafts.
+
+ \value PrinterResolution Use the physical resolution of the
+ printer on Windows. On Unix, set the postscript resolution to 72
+ dpi.
+
+ \value HighResolution Use printer resolution on windows, set the
+ resolution of the postscript driver to 600dpi.
+
+ \value Compatible Almost the same as PrinterResolution, but keeps
+ some peculiarities of the TQt 2.x printer driver. This is useful
+ for applications ported from TQt 2.x to TQt 3.x.
+*/
+
+/*!
+ \enum TQPrinter::Orientation
+
+ This enum type (not to be confused with Orientation) is used
+ to specify each page's orientation.
+
+ \value Portrait the page's height is greater than its width (the
+ default).
+
+ \value Landscape the page's width is greater than its height.
+
+ This type interacts with \l TQPrinter::PageSize and
+ TQPrinter::setFullPage() to determine the final size of the page
+ available to the application.
+*/
+
+
+/*!
+ \enum TQPrinter::PageSize
+
+ This enum type specifies what paper size TQPrinter should use.
+ TQPrinter does not check that the paper size is available; it just
+ uses this information, together with TQPrinter::Orientation and
+ TQPrinter::setFullPage(), to determine the printable area (see
+ TQPaintDeviceMetrics).
+
+ The defined sizes (with setFullPage(TRUE)) are:
+
+ \value A0 841 x 1189 mm This value is not supported on windows.
+ \value A1 594 x 841 mm This value is not supported on windows.
+ \value A2 420 x 594 mm
+ \value A3 297 x 420 mm
+ \value A4 210 x 297 mm, 8.26 x 11.7 inches
+ \value A5 148 x 210 mm
+ \value A6 105 x 148 mm
+ \value A7 74 x 105 mm
+ \value A8 52 x 74 mm
+ \value A9 37 x 52 mm
+ \value B0 1030 x 1456 mm
+ \value B1 728 x 1030 mm
+ \value B10 32 x 45 mm
+ \value B2 515 x 728 mm
+ \value B3 364 x 515 mm
+ \value B4 257 x 364 mm
+ \value B5 182 x 257 mm, 7.17 x 10.13 inches
+ \value B6 128 x 182 mm
+ \value B7 91 x 128 mm
+ \value B8 64 x 91 mm
+ \value B9 45 x 64 mm
+ \value C5E 163 x 229 mm
+ \value Comm10E 105 x 241 mm, US Common #10 Envelope
+ \value DLE 110 x 220 mm
+ \value Executive 7.5 x 10 inches, 191 x 254 mm
+ \value Folio 210 x 330 mm
+ \value Ledger 432 x 279 mm
+ \value Legal 8.5 x 14 inches, 216 x 356 mm
+ \value Letter 8.5 x 11 inches, 216 x 279 mm
+ \value Tabloid 279 x 432 mm
+ \value Custom
+ \value NPageSize (internal)
+
+ With setFullPage(FALSE) (the default), the metrics will be a bit
+ smaller; how much depends on the printer in use.
+*/
+
+
+/*!
+ \enum TQPrinter::PageOrder
+
+ This enum type is used by TQPrinter to tell the application program
+ how to print.
+
+ \value FirstPageFirst the lowest-numbered page should be printed
+ first.
+
+ \value LastPageFirst the highest-numbered page should be printed
+ first.
+*/
+
+/*!
+ \enum TQPrinter::ColorMode
+
+ This enum type is used to indicate whether TQPrinter should print
+ in color or not.
+
+ \value Color print in color if available, otherwise in grayscale.
+
+ \value GrayScale print in grayscale, even on color printers.
+ Might be a little faster than \c Color. This is the default.
+*/
+
+/*!
+ \enum TQPrinter::PaperSource
+
+ This enum type specifies what paper source TQPrinter is to use.
+ TQPrinter does not check that the paper source is available; it
+ just uses this information to try and set the paper source.
+ Whether it will set the paper source depends on whether the
+ printer has that particular source.
+
+ Note: this is currently only implemented for Windows.
+
+ \value OnlyOne
+ \value Lower
+ \value Middle
+ \value Manual
+ \value Envelope
+ \value EnvelopeManual
+ \value Auto
+ \value Tractor
+ \value SmallFormat
+ \value LargeFormat
+ \value LargeCapacity
+ \value Cassette
+ \value FormSource
+*/
+
+/*!
+ \enum TQPrinter::PrintRange
+
+ This enum is used to specify which print range the application
+ should use to print.
+
+ \value AllPages All pages should be printed
+ \value Selection Only the selection should be printed.
+ \value PageRange From page, to page option.
+
+ \sa setPrintRange(), printRange()
+*/
+
+/*!
+ \enum TQPrinter::PrinterOption
+
+ This enum describes various printer options that appear in the
+ printer setup dialog. It is used to enable and disable these
+ options in the setup dialog.
+
+ \value PrintToFile Describes if print to file should be enabled.
+ \value PrintSelection Describes if printing selections should be enabled.
+ \value PrintPageRange Describes if printing page ranges (from, to) should
+ be enabled
+
+ \sa setOptionEnabled(), isOptionEnabled()
+*/
+
+
+/*!
+ \fn TQString TQPrinter::printerName() const
+
+ Returns the printer name. This value is initially set to the name
+ of the default printer.
+
+ \sa setPrinterName()
+*/
+
+/*!
+ \fn bool TQPrinter::outputToFile() const
+
+ Returns TRUE if the output should be written to a file, or FALSE
+ if the output should be sent directly to the printer. The default
+ setting is FALSE.
+
+ This function is currently only supported under X11 and Mac OS X.
+
+ \sa setOutputToFile(), setOutputFileName()
+*/
+
+/*!
+ Specifies whether the output should be written to a file or sent
+ directly to the printer.
+
+ Will output to a file if \a enable is TRUE, or will output
+ directly to the printer if \a enable is FALSE.
+
+ This function is currently only supported under X11 and Mac OS X.
+
+ \sa outputToFile(), setOutputFileName()
+*/
+
+void TQPrinter::setOutputToFile( bool enable )
+{
+ if ( state != 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPrinter::setOutputToFile: Cannot do this during printing" );
+#endif
+ return;
+ }
+ output_file = enable;
+}
+
+
+/*!
+ \fn TQString TQPrinter::outputFileName() const
+
+ Returns the name of the output file. There is no default file
+ name.
+
+ \sa setOutputFileName(), setOutputToFile()
+*/
+
+/*!
+ Sets the name of the output file to \a fileName.
+
+ Setting a null or empty name (0 or "") disables output to a file,
+ i.e. calls setOutputToFile(FALSE). Setting a non-empty name
+ enables output to a file, i.e. calls setOutputToFile(TRUE).
+
+ This function is currently only supported under X11.
+
+ \sa outputFileName(), setOutputToFile()
+*/
+
+void TQPrinter::setOutputFileName( const TQString &fileName )
+{
+ if ( state != 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning("TQPrinter::setOutputFileName: Cannot do this during printing");
+#endif
+ return;
+ }
+ output_filename = fileName;
+ output_file = !output_filename.isEmpty();
+}
+
+
+/*!
+ \fn TQString TQPrinter::printProgram() const
+
+ Returns the name of the program that sends the print output to the
+ printer.
+
+ The default is to return a null string; meaning that TQPrinter will
+ try to be smart in a system-dependent way. On X11 only, you can
+ set it to something different to use a specific print program.
+
+ On Windows, this function returns the name of the printer tqdevice
+ driver.
+
+ \sa setPrintProgram() setPrinterSelectionOption()
+*/
+
+/*!
+ Sets the name of the program that should do the print job to \a
+ printProg.
+
+ On X11, this function sets the program to call with the PostScript
+ output. On other platforms, it has no effect.
+
+ \sa printProgram()
+*/
+
+void TQPrinter::setPrintProgram( const TQString &printProg )
+{
+ print_prog = printProg;
+}
+
+
+/*!
+ \fn TQString TQPrinter::docName() const
+
+ Returns the document name.
+
+ \sa setDocName()
+*/
+
+/*!
+ Sets the document name to \a name.
+*/
+
+void TQPrinter::setDocName( const TQString &name )
+{
+ if ( state != 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPrinter::setDocName: Cannot do this during printing" );
+#endif
+ return;
+ }
+ doc_name = name;
+}
+
+
+/*!
+ \fn TQString TQPrinter::creator() const
+
+ Returns the name of the application that created the document.
+
+ \sa setCreator()
+*/
+
+/*!
+ Sets the name of the application that created the document to \a
+ creator.
+
+ This function is only applicable to the X11 version of TQt. If no
+ creator name is specified, the creator will be set to "TQt"
+ followed by some version number.
+
+ \sa creator()
+*/
+
+void TQPrinter::setCreator( const TQString &creator )
+{
+ creator_name = creator;
+}
+
+
+/*!
+ \fn Orientation TQPrinter::orientation() const
+
+ Returns the orientation setting. The default value is \c
+ TQPrinter::Portrait.
+
+ \sa setOrientation()
+*/
+
+/*!
+ Sets the print orientation to \a orientation.
+
+ The orientation can be either \c TQPrinter::Portrait or \c
+ TQPrinter::Landscape.
+
+ The printer driver reads this setting and prints using the
+ specified orientation. On Windows this setting won't take effect
+ until the printer dialog is shown (using TQPrinter::setup()).
+
+ Windows only! This option can be changed while printing and will
+ take effect from the next call to newPage()
+
+ \sa orientation()
+*/
+
+void TQPrinter::setOrientation( Orientation orientation )
+{
+ orient = orientation;
+#if defined(TQ_WS_WIN)
+ reinit();
+#endif
+}
+
+
+/*!
+ \fn PageSize TQPrinter::pageSize() const
+
+ Returns the printer page size. The default value is system-dependent.
+
+ \sa setPageSize()
+*/
+
+
+/*!
+ Sets the printer page size to \a newPageSize if that size is
+ supported. The result if undefined if \a newPageSize is not
+ supported.
+
+ The default page size is system-dependent.
+
+ This function is useful mostly for setting a default value that
+ the user can override in the print dialog when you call setup().
+
+ \sa pageSize() PageSize setFullPage() setResolution()
+*/
+
+void TQPrinter::setPageSize( PageSize newPageSize )
+{
+ if ( newPageSize > NPageSize ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning("TQPrinter::SetPageSize: illegal page size %d", newPageSize );
+#endif
+ return;
+ }
+ page_size = newPageSize;
+#if defined(TQ_WS_WIN)
+ reinit();
+#endif
+}
+
+/*!
+ Sets the page order to \a newPageOrder.
+
+ The page order can be \c TQPrinter::FirstPageFirst or \c
+ TQPrinter::LastPageFirst. The application programmer is responsible
+ for reading the page order and printing accordingly.
+
+ This function is useful mostly for setting a default value that
+ the user can override in the print dialog when you call setup().
+
+ \bug This value is not kept in sync with the Windows or Mac OS X printer
+ dialogs.
+*/
+
+void TQPrinter::setPageOrder( PageOrder newPageOrder )
+{
+ page_order = newPageOrder;
+#if defined(TQ_WS_WIN)
+ reinit();
+#endif
+}
+
+
+/*!
+ Returns the current page order.
+
+ The default page order is \c FirstPageFirst.
+
+ \bug This value is not kept in sync with the Windows or Mac OS X printer
+ dialogs.
+*/
+
+TQPrinter::PageOrder TQPrinter::pageOrder() const
+{
+ return page_order;
+}
+
+
+/*!
+ Sets the printer's color mode to \a newColorMode, which can be
+ either \c Color or \c GrayScale (the default).
+
+ \sa colorMode()
+*/
+
+void TQPrinter::setColorMode( ColorMode newColorMode )
+{
+ color_mode = newColorMode;
+#if defined(TQ_WS_WIN)
+ reinit();
+#endif
+}
+
+
+/*!
+ Returns the current color mode. The default color mode is \c
+ Color.
+
+ \sa setColorMode()
+*/
+
+TQPrinter::ColorMode TQPrinter::colorMode() const
+{
+ return color_mode;
+}
+
+
+/*!
+ \fn int TQPrinter::fromPage() const
+
+ Returns the from-page setting. The default value is 0.
+
+ If fromPage() and toPage() both return 0 this signifies 'print the
+ whole document'.
+
+ The programmer is responsible for reading this setting and
+ printing accordingly.
+
+ \sa setFromTo(), toPage()
+*/
+
+/*!
+ \fn int TQPrinter::toPage() const
+
+ Returns the to-page setting. The default value is 0.
+
+ If fromPage() and toPage() both return 0 this signifies 'print the
+ whole document'.
+
+ The programmer is responsible for reading this setting and
+ printing accordingly.
+
+ \sa setFromTo(), fromPage()
+*/
+
+/*!
+ Sets the from-page and to-page settings to \a fromPage and \a
+ toPage respectively.
+
+ The from-page and to-page settings specify what pages to print.
+
+ If fromPage() and toPage() both return 0 this signifies 'print the
+ whole document'.
+
+ This function is useful mostly to set a default value that the
+ user can override in the print dialog when you call setup().
+
+ \sa fromPage(), toPage(), setMinMax(), setup()
+*/
+
+void TQPrinter::setFromTo( int fromPage, int toPage )
+{
+ if ( state != 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPrinter::setFromTo: Cannot do this during printing" );
+#endif
+ return;
+ }
+ from_pg = fromPage;
+ to_pg = toPage;
+}
+
+
+/*!
+ \fn int TQPrinter::minPage() const
+
+ Returns the min-page setting, i.e. the lowest page number a user
+ is allowed to choose. The default value is 0.
+
+ \sa maxPage(), setMinMax() setFromTo()
+*/
+
+/*!
+ \fn int TQPrinter::maxPage() const
+
+ Returns the max-page setting. A user can't choose a higher page
+ number than maxPage() when they select a print range. The default
+ value is 0.
+
+ \sa minPage(), setMinMax() setFromTo()
+*/
+
+/*!
+ Sets the min-page and max-page settings to \a minPage and \a
+ maxPage respectively.
+
+ The min-page and max-page restrict the from-page and to-page
+ settings. When the printer setup dialog appears, the user cannot
+ select a from page or a to page that are outside the range
+ specified by min and max pages.
+
+ \sa minPage(), maxPage(), setFromTo(), setup()
+*/
+
+void TQPrinter::setMinMax( int minPage, int maxPage )
+{
+ min_pg = minPage;
+ max_pg = maxPage;
+ if ( from_pg == 0 || from_pg < minPage )
+ from_pg = minPage;
+ if ( to_pg == 0 || to_pg > maxPage )
+ to_pg = maxPage;
+}
+
+
+/*!
+ \fn int TQPrinter::numCopies() const
+
+ Returns the number of copies to be printed. The default value is 1.
+
+ This value will return the number of times the application is
+ required to print in order to match the number specified in the
+ printer setup dialog. This has been done since some printer
+ drivers are not capable of buffering up the copies and the
+ application in those cases have to make an explicit call to the
+ print code for each copy.
+
+ \sa setNumCopies()
+*/
+
+/*!
+ \fn bool TQPrinter::collateCopiesEnabled() const
+
+ \internal
+
+ Returns TRUE if the application should provide the user with the
+ option of choosing a collated printout; otherwise returns FALSE.
+
+ Collation means that each page is printed in order, i.e. print the
+ first page, then the second page, then the third page and so on, and
+ then repeat this sequence for as many copies as have been requested.
+ If you don't collate you get several copies of the first page, then
+ several copies of the second page, then several copies of the third
+ page, and so on.
+
+ \sa setCollateCopiesEnabled() setCollateCopies() collateCopies()
+*/
+
+/*!
+ \fn void TQPrinter::setCollateCopiesEnabled(bool enable)
+
+ \internal
+
+ If \a enable is TRUE (the default) the user is given the choice of
+ whether to print out multiple copies collated in the print dialog.
+ If \a enable is FALSE, then collateCopies() will be ignored.
+
+ Collation means that each page is printed in order, i.e. print the
+ first page, then the second page, then the third page and so on, and
+ then repeat this sequence for as many copies as have been requested.
+ If you don't collate you get several copies of the first page, then
+ several copies of the second page, then several copies of the third
+ page, and so on.
+
+ \sa collateCopiesEnabled() setCollateCopies() collateCopies()
+*/
+
+/*!
+ \fn bool TQPrinter::collateCopies() const
+
+ \internal
+
+ Returns TRUE if collation is turned on when multiple copies is selected.
+ Returns FALSE if it is turned off when multiple copies is selected.
+
+ \sa collateCopiesEnabled() setCollateCopiesEnabled() setCollateCopies()
+*/
+
+/*!
+ \internal
+
+ Sets the default value for collation checkbox when the print dialog appears.
+ If \a on is TRUE, it will enable setCollateCopiesEnabled().
+ The default value is FALSE. This value will be changed by what the
+ user presses in the print dialog.
+
+ \sa collateCopiesEnabled() setCollateCopiesEnabled() collateCopies()
+*/
+
+void TQPrinter::setCollateCopies(bool on)
+{
+ if (!collateCopiesEnabled() && on)
+ setCollateCopiesEnabled(on);
+ usercolcopies = on;
+}
+
+/*!
+ Sets the number of copies to be printed to \a numCopies.
+
+ The printer driver reads this setting and prints the specified
+ number of copies.
+
+ \sa numCopies(), setup()
+*/
+
+void TQPrinter::setNumCopies( int numCopies )
+{
+ ncopies = numCopies;
+#if defined(TQ_WS_WIN)
+ reinit();
+#endif
+}
+
+
+/*!
+ Returns the printer options selection string. This is useful only
+ if the print command has been explicitly set.
+
+ The default value (a null string) implies that the printer should
+ be selected in a system-dependent manner.
+
+ Any other value implies that the given value should be used.
+
+ \sa setPrinterSelectionOption()
+*/
+
+TQString TQPrinter::printerSelectionOption() const
+{
+ return option_string;
+}
+
+
+/*!
+ Sets the printer to use \a option to select the printer. \a option
+ is null by default (which implies that TQt should be smart enough
+ to guess correctly), but it can be set to other values to use a
+ specific printer selection option.
+
+ If the printer selection option is changed while the printer is
+ active, the current print job may or may not be affected.
+
+ \sa printerSelectionOption()
+*/
+
+void TQPrinter::setPrinterSelectionOption( const TQString & option )
+{
+ option_string = option;
+}
+
+
+/*!
+ Sets TQPrinter to have the origin of the coordinate system at the
+ top-left corner of the paper if \a fp is TRUE, or where it thinks
+ the top-left corner of the printable area is if \a fp is FALSE.
+
+ The default is FALSE. You can (probably) print on (0,0), and
+ TQPaintDeviceMetrics will report something smaller than the size
+ indicated by PageSize. (Note that TQPrinter may be wrong on Unix
+ systems - it does not have perfect knowledge of the physical
+ printer.)
+
+ If you set \a fp to TRUE, TQPaintDeviceMetrics will report the
+ exact same size as indicated by \c PageSize, but you cannot print
+ on all of that - you must take care of the output margins
+ yourself.
+
+ \sa PageSize setPageSize() TQPaintDeviceMetrics fullPage()
+*/
+
+void TQPrinter::setFullPage( bool fp )
+{
+ to_edge = fp;
+}
+
+
+/*!
+ Returns TRUE if the origin of the printer's coordinate system is
+ at the corner of the sheet and FALSE if it is at the edge of the
+ printable area.
+
+ See setFullPage() for details and caveats.
+
+ \sa setFullPage() PageSize TQPaintDeviceMetrics
+*/
+
+bool TQPrinter::fullPage() const
+{
+ return to_edge;
+}
+
+
+/*!
+ Requests that the printer prints at \a dpi or as near to \a dpi as
+ possible.
+
+ This setting affects the coordinate system as returned by, for
+ example, TQPaintDeviceMetrics and TQPainter::viewport().
+
+ The value depends on the \c PrintingMode used in the TQPrinter
+ constructor. By default, the dpi value of the screen is used.
+
+ This function must be called before setup() to have an effect on
+ all platforms.
+
+ \sa resolution() setPageSize()
+*/
+
+void TQPrinter::setResolution( int dpi )
+{
+ res = dpi;
+ res_set = TRUE;
+}
+
+
+/*!
+ Returns the current assumed resolution of the printer, as set by
+ setResolution() or by the printer subsystem.
+
+ \sa setResolution()
+*/
+
+int TQPrinter::resolution() const
+{
+ return res;
+}
+
+/*!
+ Sets the paper source setting to \a source.
+
+ Windows only! This option can be changed while printing and will
+ take effect from the next call to newPage()
+
+ \sa paperSource()
+*/
+
+void TQPrinter::setPaperSource( PaperSource source )
+{
+ paper_source = source;
+#if defined(TQ_WS_WIN)
+ reinit();
+#endif
+}
+
+/*!
+ Returns the currently set paper source of the printer.
+
+ \sa setPaperSource()
+*/
+
+TQPrinter::PaperSource TQPrinter::paperSource() const
+{
+ return paper_source;
+}
+
+/*!
+ Sets the default selected page range to be used when the print setup
+ dialog is opened to \a range. If the PageRange specified by \a range is
+ currently disabled the function does nothing.
+
+ \sa printRange()
+*/
+void TQPrinter::setPrintRange( PrintRange range )
+{
+ if( range != AllPages )
+ if( range == Selection
+ && !isOptionEnabled( PrintSelection ) )
+ setOptionEnabled( PrintSelection, TRUE );
+ else if( range == PageRange
+ && !isOptionEnabled( PrintPageRange ) )
+ setOptionEnabled( PrintPageRange, TRUE );
+ d->printRange = range;
+}
+
+/*!
+ Returns the PageRange of the TQPrinter. After the print setup dialog
+ has been opened, this function returns the value selected by the user.
+
+ \sa setPrintRange()
+*/
+TQPrinter::PrintRange TQPrinter::printRange() const
+{
+ return d->printRange;
+}
+
+/*!
+ Enables the printer option with the identifier \a option if \a
+ enable is TRUE, and disables option \a option if \a enable is FALSE.
+
+ \sa isOptionEnabled()
+*/
+void TQPrinter::setOptionEnabled( PrinterOption option, bool enable )
+{
+ if( enable ) {
+ d->printerOptions |= ( 1 << option );
+ if( ( option == PrintPageRange ) && min_pg==0 && max_pg==0 )
+ max_pg = 9999;
+ } else {
+ d->printerOptions &= ( ~( 1 << option ) );
+ }
+}
+
+/*!
+ Returns TRUE if the printer option with identifier \a option is enabled;
+ otherwise returns FALSE.
+
+ \sa setOptionEnabled()
+ */
+bool TQPrinter::isOptionEnabled( PrinterOption option )
+{
+ return d->printerOptions & ( 1 << option );
+}
+
+#endif // USE_QT4
+
+#endif // TQT_NO_PRINTER
+
diff --git a/tqtinterface/qt4/src/kernel/tqprinter.h b/tqtinterface/qt4/src/kernel/tqprinter.h
new file mode 100755
index 0000000..a719a95
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqprinter.h
@@ -0,0 +1,335 @@
+/**********************************************************************
+**
+** Definition of TQPrinter class
+**
+** Created : 940927
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPRINTER_H
+#define TQPRINTER_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpaintdevice.h"
+#include "tqstring.h"
+#include "tqstringlist.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_PRINTER
+
+#ifdef USE_QT4
+
+#include <Qt/qprinter.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQPrinter : public QPrinter//, virtual public TQt
+{
+public:
+ enum PrinterOption { PrintToFile, PrintSelection, PrintPageRange };
+
+ TQPrinter( PrinterMode mode = ScreenResolution ) : QPrinter( mode ) {}
+
+#ifdef Q_WS_MAC
+ bool pageSetup(QWidget *parent = 0);
+ bool printSetup(QWidget *parent = 0);
+#endif
+
+ bool setup(QWidget *parent = 0);
+
+ void setMinMax(int minPage, int maxPage);
+ int minPage() const;
+ int maxPage() const;
+
+ void setCollateCopiesEnabled(bool);
+ bool collateCopiesEnabled() const;
+
+ void setOptionEnabled(PrinterOption, bool enable);
+ bool isOptionEnabled(PrinterOption) const;
+
+ inline TQSize margins() const { printf("[WARNING] TQPrinter::margins unimplemented\n\r"); }
+ inline void margins(uint *top, uint *left, uint *bottom, uint *right) const { printf("[WARNING] TQPrinter::margins unimplemented\n\r"); }
+
+ inline bool aborted() { return printerState() == Aborted; }
+
+ void setOutputToFile(bool);
+ inline bool outputToFile() const { return !outputFileName().isEmpty(); }
+
+protected:
+ bool cmd( int, TQPainter *, TQPDevCmdParam * );
+ inline int metric( int a ) const { return metric((QPaintDevice::PaintDeviceMetric)a); }
+ inline void setMargins( uint top, uint left, uint bottom, uint right ) { printf("[WARNING] TQPrinter::setMargins unimplemented\n\r"); }
+};
+
+#else // USE_QT4
+
+#if defined(B0)
+#undef B0 // Terminal hang-up. We assume that you do not want that.
+#endif
+
+class TQPrinterPrivate;
+
+class TQ_EXPORT TQPrinter : public TQPaintDevice
+{
+public:
+ enum PrinterMode { ScreenResolution, PrinterResolution, HighResolution, Compatible };
+
+ TQPrinter( PrinterMode mode = ScreenResolution );
+ ~TQPrinter();
+
+ enum Orientation { Portrait, Landscape };
+
+ enum PageSize { A4, B5, Letter, Legal, Executive,
+ A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
+ B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
+ DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom };
+
+ enum PageOrder { FirstPageFirst, LastPageFirst };
+
+ enum ColorMode { GrayScale, Color };
+
+ enum PaperSource { OnlyOne, Lower, Middle, Manual, Envelope,
+ EnvelopeManual, Auto, Tractor, SmallFormat,
+ LargeFormat, LargeCapacity, Cassette, FormSource };
+
+ enum PrintRange { AllPages,
+ Selection,
+ PageRange };
+
+ enum PrinterOption { PrintToFile,
+ PrintSelection,
+ PrintPageRange };
+
+ TQString printerName() const;
+ virtual void setPrinterName( const TQString &);
+ bool outputToFile() const;
+ virtual void setOutputToFile( bool );
+ TQString outputFileName()const;
+ virtual void setOutputFileName( const TQString &);
+
+ TQString printProgram() const;
+ virtual void setPrintProgram( const TQString &);
+
+ TQString printerSelectionOption() const;
+ virtual void setPrinterSelectionOption( const TQString & );
+
+ TQString docName() const;
+ virtual void setDocName( const TQString &);
+ TQString creator() const;
+ virtual void setCreator( const TQString &);
+
+ Orientation orientation() const;
+ virtual void setOrientation( Orientation );
+ PageSize pageSize() const;
+ virtual void setPageSize( PageSize );
+#ifdef TQ_WS_WIN
+ void setWinPageSize( short winPageSize );
+ short winPageSize() const;
+#endif
+#ifdef TQ_WS_MAC
+ bool printSetup();
+ bool pageSetup();
+#endif
+ virtual void setPageOrder( PageOrder );
+ PageOrder pageOrder() const;
+
+ void setResolution( int );
+ int resolution() const;
+
+ virtual void setColorMode( ColorMode );
+ ColorMode colorMode() const;
+
+ virtual void setFullPage( bool );
+ bool fullPage() const;
+ TQSize margins() const;
+ void setMargins( uint top, uint left, uint bottom, uint right );
+ void margins( uint *top, uint *left, uint *bottom, uint *right ) const;
+
+ int fromPage() const;
+ int toPage() const;
+ virtual void setFromTo( int fromPage, int toPage );
+ int minPage() const;
+ int maxPage() const;
+ virtual void setMinMax( int minPage, int maxPage );
+ int numCopies() const;
+ virtual void setNumCopies( int );
+
+ bool collateCopiesEnabled() const;
+ void setCollateCopiesEnabled(bool );
+
+ bool collateCopies() const;
+ void setCollateCopies( bool );
+
+ PrintRange printRange() const;
+ void setPrintRange( PrintRange range );
+
+ bool newPage();
+ bool abort();
+ bool aborted() const;
+
+ bool setup( TQWidget *tqparent = 0 );
+
+ PaperSource paperSource() const;
+ virtual void setPaperSource( PaperSource );
+
+ void setOptionEnabled( PrinterOption, bool enable );
+ bool isOptionEnabled( PrinterOption );
+
+protected:
+ bool cmd( int, TQPainter *, TQPDevCmdParam * );
+ int metric( int ) const;
+
+#if defined(TQ_WS_WIN)
+ virtual void setActive();
+ virtual void setIdle();
+#endif
+
+private:
+#if defined(TQ_WS_X11) || defined(TQ_WS_TQWS)
+ TQPaintDevice *pdrv;
+ int pid;
+#endif
+#if defined(TQ_WS_MAC)
+ friend class TQPrinterPrivate;
+ PMPageFormat pformat;
+ PMPrintSettings psettings;
+ PMPrintSession psession;
+ bool prepare(PMPrintSettings *);
+ bool prepare(PMPageFormat *);
+ void interpret(PMPrintSettings *);
+ void interpret(PMPageFormat *);
+#endif
+#if defined(TQ_WS_WIN)
+ void readPdlg( void* );
+ void readPdlgA( void* );
+ void writeDevmode( TQt::HANDLE );
+ void writeDevmodeA( TQt::HANDLE );
+ void reinit();
+
+ bool viewOffsetDone;
+ TQPainter* painter;
+ TQt::HANDLE hdevmode;
+ TQt::HANDLE hdevnames;
+#endif
+
+ int state;
+ TQString printer_name;
+ TQString option_string;
+ TQString output_filename;
+ bool output_file;
+ TQString print_prog;
+ TQString doc_name;
+ TQString creator_name;
+
+ PageSize page_size;
+ PaperSource paper_source;
+ PageOrder page_order;
+ ColorMode color_mode;
+ Orientation orient;
+ uint to_edge : 1;
+ uint appcolcopies : 1;
+ uint usercolcopies : 1;
+ uint res_set : 1;
+ short from_pg, to_pg;
+ short min_pg, max_pg;
+ short ncopies;
+ int res;
+ TQPrinterPrivate *d;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQPrinter( const TQPrinter & );
+ TQPrinter &operator=( const TQPrinter & );
+#endif
+};
+
+
+inline TQString TQPrinter::printerName() const
+{ return printer_name; }
+
+inline bool TQPrinter::outputToFile() const
+{ return output_file; }
+
+inline TQString TQPrinter::outputFileName() const
+{ return output_filename; }
+
+inline TQString TQPrinter::printProgram() const
+{ return print_prog; }
+
+inline TQString TQPrinter::docName() const
+{ return doc_name; }
+
+inline TQString TQPrinter::creator() const
+{ return creator_name; }
+
+inline TQPrinter::PageSize TQPrinter::pageSize() const
+{ return page_size; }
+
+inline TQPrinter::Orientation TQPrinter::orientation() const
+{ return orient; }
+
+inline int TQPrinter::fromPage() const
+{ return from_pg; }
+
+inline int TQPrinter::toPage() const
+{ return to_pg; }
+
+inline int TQPrinter::minPage() const
+{ return min_pg; }
+
+inline int TQPrinter::maxPage() const
+{ return max_pg; }
+
+inline int TQPrinter::numCopies() const
+{ return ncopies; }
+
+inline bool TQPrinter::collateCopiesEnabled() const
+{ return appcolcopies; }
+
+inline void TQPrinter::setCollateCopiesEnabled(bool v)
+{ appcolcopies = v; }
+
+inline bool TQPrinter::collateCopies() const
+{ return usercolcopies; }
+
+#endif // USE_QT4
+
+#endif // TQT_NO_PRINTER
+
+#endif // TQPRINTER_H
diff --git a/tqtinterface/qt4/src/kernel/tqprinter_p.h b/tqtinterface/qt4/src/kernel/tqprinter_p.h
new file mode 100644
index 0000000..4638252
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqprinter_p.h
@@ -0,0 +1,59 @@
+/**********************************************************************
+**
+** Definition of TQPrinter class
+**
+** Created : 940927
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPRINTER_P_H
+#define TQPRINTER_P_H
+#ifndef TQT_NO_PRINTER
+
+#ifndef TQT_H
+#include <tqshared.h>
+#include <tqstring.h>
+#include <tqsize.h>
+#endif // TQT_H
+
+class TQPrinterPrivate
+{
+public:
+ TQ_UINT32 printerOptions;
+ TQPrinter::PrintRange printRange;
+};
+
+#endif
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqprinter_unix.cpp b/tqtinterface/qt4/src/kernel/tqprinter_unix.cpp
new file mode 100644
index 0000000..f9ff932
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqprinter_unix.cpp
@@ -0,0 +1,853 @@
+/****************************************************************************
+**
+** Implementation of TQPrinter class for Unix
+**
+** Created : 950810
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+// POSIX Large File Support redefines open -> open64
+static inline int qt_open(const char *pathname, int flags, mode_t mode)
+{ return ::open(pathname, flags, mode); }
+#if defined(open)
+# undef open
+#endif
+
+#include "tqprinter.h"
+
+#ifndef TQT_NO_PRINTER
+
+#include "tqpaintdevicemetrics.h"
+#include "tqpsprinter_p.h"
+#include "tqprintdialog.h"
+#include "tqapplication.h"
+#include "tqprinter_p.h"
+
+#include <unistd.h> // For ::sleep()
+#include <stdlib.h>
+
+#ifdef USE_QT4
+
+/*!
+ \internal
+ Handles painter commands to the printer.
+*/
+
+bool TQPrinter::cmd( int c, TQPainter *paint, TQPDevCmdParam *p )
+{
+ #warning FIXME [TQPrinter::cmd]
+ // [FIXME]
+ printf("[WARNING] TQPrinter::cmd unimplemented\n\r");
+
+// if ( c == PdcBegin ) {
+// if ( state == PST_IDLE ) {
+// if ( output_file ) {
+// int fd = 0;
+// fd = qt_open( output_filename.local8Bit(),
+// O_CREAT | O_NOCTTY | O_TRUNC | O_WRONLY,
+// 0666 );
+// if ( fd >= 0 ) {
+// pdrv = new TQPSPrinter( this, fd );
+// state = PST_ACTIVE;
+// }
+// } else {
+// TQString pr;
+// if ( printer_name )
+// pr = printer_name;
+// TQApplication::flushX();
+// int fds[2];
+// if ( pipe( fds ) != 0 ) {
+// qWarning( "TQPSPrinter: could not open pipe to print" );
+// state = PST_ERROR;
+// return FALSE;
+// }
+//
+// // ### shouldn't we use TQProcess here????
+// #if 0 && defined(TQ_OS_OS2EMX)
+// // this code is still not used, and maybe it's not
+// // usable either, any more. if you want to use it,
+// // you may need to fix it first.
+//
+// // old comment:
+//
+// // this code is usable but not in use. spawn() is
+// // preferable to fork()/exec() for very large
+// // programs. if fork()/exec() is a problem and you
+// // use OS/2, remove '0 && ' from the #if.
+// int tmp;
+// tmp = dup(0);
+// dup2( fds[0], 0 );
+// ::close( fds[0] );
+// fcntl(tmp, F_SETFD, FD_CLOEXEC);
+// fcntl(fds[1], F_SETFD, FD_CLOEXEC);
+// if ( option_string )
+// pr.prepend( option_string );
+// else
+// pr.prepend( "-P" ); // ###
+// if ( spawnlp(P_NOWAIT,print_prog.data(), print_prog.data(),
+// pr.data(), output->name(), 0) == -1 ) {
+// ; // couldn't exec, ignored
+// }
+// dup2( tmp, 0 );
+// ::close( tmp );
+// pdrv = new TQPSPrinter( this, fds[1] );
+// state = PST_ACTIVE;
+// #else
+// pid = fork();
+// if ( pid == 0 ) { // child process
+// // if possible, exit quickly, so the actual lp/lpr
+// // becomes a child of init, and ::waitpid() is
+// // guaranteed not to wait.
+// if ( fork() > 0 ) {
+// closeAllOpenFds();
+//
+// // try to tqreplace this process with "true" - this prevents
+// // global destructors from being called (that could possibly
+// // do wrong things to the tqparent process)
+// (void)execlp("true", "true", (char *)0);
+// (void)execl("/bin/true", "true", (char *)0);
+// (void)execl("/usr/bin/true", "true", (char *)0);
+// ::exit( 0 );
+// }
+// dup2( fds[0], 0 );
+//
+// closeAllOpenFds();
+//
+// if ( print_prog ) {
+// if ( option_string )
+// pr.prepend( option_string );
+// else
+// pr.prepend( TQString::tqfromLatin1( "-P" ) );
+// (void)execlp( print_prog.ascii(), print_prog.ascii(),
+// pr.ascii(), (char *)0 );
+// } else {
+// // if no print program has been specified, be smart
+// // about the option string too.
+// TQStringList lprhack;
+// TQStringList lphack;
+// TQString media;
+// if ( pr || option_string ) {
+// if ( option_string ) {
+// lprhack = TQStringList::split(TQChar(' '), option_string);
+// lphack = lprhack;
+// } else {
+// lprhack.append( TQString::tqfromLatin1( "-P" ) );
+// lphack.append( TQString::tqfromLatin1( "-d" ) );
+// }
+// lprhack.append(pr);
+// lphack.append(pr);
+// }
+// char ** lpargs = new char *[lphack.size()+6];
+// lpargs[0] = "lp";
+// uint i;
+// for (i = 0; i < lphack.size(); ++i)
+// lpargs[i+1] = (char *)lphack[i].ascii();
+// #ifndef TQ_OS_OSF
+// if (psToStr[page_size]) {
+// lpargs[++i] = "-o";
+// lpargs[++i] = (char *)psToStr[page_size];
+// lpargs[++i] = "-o";
+// media = "media=";
+// media += psToStr[page_size];
+// lpargs[++i] = (char *)media.ascii();
+// }
+// #endif
+// lpargs[++i] = 0;
+// char **lprargs = new char *[lprhack.size()+1];
+// lprargs[0] = "lpr";
+// for (uint x = 0; x < lprhack.size(); ++x)
+// lprargs[x+1] = (char *)lprhack[x].ascii();
+// lprargs[lprhack.size() + 1] = 0;
+// (void)execvp( "lp", lpargs );
+// (void)execvp( "lpr", lprargs );
+// (void)execv( "/bin/lp", lpargs);
+// (void)execv( "/bin/lpr", lprargs);
+// (void)execv( "/usr/bin/lp", lpargs);
+// (void)execv( "/usr/bin/lpr", lprargs);
+// }
+// // if we couldn't exec anything, close the fd,
+// // wait for a second so the tqparent process (the
+// // child of the GUI process) has exited. then
+// // exit.
+// ::close( 0 );
+// (void)::sleep( 1 );
+// ::exit( 0 );
+// } else { // tqparent process
+// ::close( fds[0] );
+// pdrv = new TQPSPrinter( this, fds[1] );
+// state = PST_ACTIVE;
+// }
+// #endif // else part of TQ_OS_OS2EMX
+// }
+// if ( state == PST_ACTIVE && pdrv )
+// return ((TQPSPrinter*)pdrv)->cmd( c, paint, p );
+// } else {
+// // ignore it? I don't know
+// }
+// } else {
+// bool r = FALSE;
+// if ( state == PST_ACTIVE && pdrv ) {
+// r = ((TQPSPrinter*)pdrv)->cmd( c, paint, p );
+// if ( c == PdcEnd ) {
+// state = PST_IDLE;
+// delete pdrv;
+// pdrv = 0;
+// if ( pid ) {
+// (void)::waitpid( pid, 0, 0 );
+// pid = 0;
+// }
+// }
+// } else if ( state == PST_ABORTED && c == PdcEnd )
+// state = PST_IDLE;
+// return r;
+// }
+// return TRUE;
+}
+
+#else // USE_QT4
+
+// NOT REVISED
+
+
+class TQPrinterUnixPrivate : public TQPrinterPrivate
+{
+public:
+ bool marginsSpecified;
+ uint topMargin;
+ uint leftMargin;
+ uint bottomMargin;
+ uint rightMargin;
+};
+
+#define D ( (TQPrinterUnixPrivate*) d )
+
+/*****************************************************************************
+ TQPrinter member functions
+ *****************************************************************************/
+
+// TQPrinter states
+
+#define PST_IDLE 0
+#define PST_ACTIVE 1
+#define PST_ERROR 2
+#define PST_ABORTED 3
+
+// Default values for TQPrinter members
+
+struct PrinterDefaults {
+ TQString printerName;
+ bool outputToFile;
+ TQString outputFileName;
+ TQPrinter::Orientation orientation;
+ TQPrinter::PageSize pageSize;
+ TQPrinter::PageOrder pageOrder;
+ TQPrinter::ColorMode colorMode;
+ int numCopies;
+};
+
+static PrinterDefaults * globalPrinterDefaults = 0;
+
+/*!
+ Constructs a printer paint tqdevice with mode \a m.
+
+ \sa TQPrinter::PrinterMode
+*/
+
+TQPrinter::TQPrinter( PrinterMode m )
+ : TQPaintDevice( TQInternal::Printer | TQInternal::ExternalDevice )
+{
+ pdrv = 0;
+ pid = 0;
+ orient = Portrait;
+ page_size = A4;
+ page_order = FirstPageFirst;
+ color_mode = GrayScale;
+ ncopies = 1;
+ printer_name = getenv("PRINTER");
+ from_pg = to_pg = min_pg = max_pg = 0;
+ state = PST_IDLE;
+ output_file = FALSE;
+ to_edge = FALSE;
+ paper_source = OnlyOne;
+ switch ( m ) {
+ case ScreenResolution:
+#ifdef TQ_WS_TQWS
+ res = 72;
+#else
+ res = TQPaintDevice::x11AppDpiY();
+#endif
+ break;
+ case Compatible:
+ case PrinterResolution:
+ res = 72;
+ break;
+ case HighResolution:
+ res = 600;
+ }
+
+ d = new TQPrinterUnixPrivate;
+ D->marginsSpecified = FALSE;
+ d->printerOptions = 0;
+ setOptionEnabled( PrintToFile, TRUE );
+ setOptionEnabled( PrintPageRange, TRUE );
+ setPrintRange( AllPages );
+}
+
+/*!
+ Destroys the printer paint tqdevice and cleans up.
+*/
+
+TQPrinter::~TQPrinter()
+{
+ delete pdrv;
+ if ( pid ) {
+ (void)::kill( pid, 6 );
+ (void)::wait( 0 );
+ pid = 0;
+ }
+ delete d;
+}
+
+
+/*!
+ Advances to a new page on the printer. Returns TRUE if successful;
+ otherwise returns FALSE.
+*/
+
+bool TQPrinter::newPage()
+{
+ if ( state == PST_ACTIVE && pdrv )
+ return ((TQPSPrinter*)pdrv)->cmd( TQPSPrinter::NewPage, 0, 0 );
+ return FALSE;
+}
+
+
+/*!
+ Aborts the print job. Returns TRUE if successful; otherwise
+ returns FALSE.
+
+ \sa aborted()
+*/
+
+bool TQPrinter::abort()
+{
+ if ( state == PST_ACTIVE && pdrv ) {
+ ((TQPSPrinter*)pdrv)->cmd( TQPSPrinter::AbortPrinting, 0, 0 );
+ state = PST_ABORTED;
+ if ( pid ) {
+ (void)::kill( pid, 6 );
+ (void)::wait( 0 );
+ pid = 0;
+ }
+ }
+ return state == PST_ABORTED;
+}
+
+/*!
+ Returns TRUE if the print job was aborted; otherwise returns
+ FALSE.
+
+ \sa abort()
+*/
+
+bool TQPrinter::aborted() const
+{
+ return state == PST_ABORTED;
+}
+
+/*!
+ Sets the printer name to \a name.
+
+ The default printer will be used if no printer name is set.
+
+ Under X11, the \c PRINTER environment variable defines the default
+ printer. Under any other window system, the window system defines
+ the default printer.
+
+ \sa printerName()
+*/
+
+void TQPrinter::setPrinterName( const TQString &name )
+{
+ if ( state != 0 ) {
+#if defined(TQT_CHECK_STATE)
+ qWarning( "TQPrinter::setPrinterName: Cannot do this during printing" );
+#endif
+ return;
+ }
+ printer_name = name;
+}
+
+static void deleteGlobalPrinterDefaults()
+{
+ delete globalPrinterDefaults;
+ globalPrinterDefaults = 0;
+}
+
+/*!
+ Opens a printer setup dialog, with tqparent \a tqparent, and asks the
+ user to specify which printer they wish to use and what settings
+ it should have.
+
+ Returns TRUE if the user pressed "OK" to print, or FALSE if the
+ user canceled the operation.
+*/
+
+bool TQPrinter::setup( TQWidget * tqparent )
+{
+#ifndef TQT_NO_PRINTDIALOG
+ bool result = TQPrintDialog::getPrinterSetup( this, tqparent );
+#else
+ bool result = FALSE;
+#endif
+ if ( result ) {
+ if ( !globalPrinterDefaults ) {
+ globalPrinterDefaults = new PrinterDefaults;
+ qAddPostRoutine( deleteGlobalPrinterDefaults );
+ }
+ globalPrinterDefaults->printerName = printerName();
+ globalPrinterDefaults->outputToFile = outputToFile();
+ globalPrinterDefaults->outputFileName = outputFileName();
+ globalPrinterDefaults->orientation = orientation();
+ globalPrinterDefaults->pageSize = pageSize();
+ globalPrinterDefaults->pageOrder = pageOrder();
+ globalPrinterDefaults->colorMode = colorMode();
+ }
+ return result;
+}
+
+static void closeAllOpenFds()
+{
+ // hack time... getting the maximum number of open
+ // files, if possible. if not we assume it's the
+ // larger of 256 and the fd we got
+ int i;
+#if defined(TQ_OS_OS2EMX)
+ LONG req_count = 0;
+ ULONG rc, handle_count;
+ rc = DosSetRelMaxFH (&req_count, &handle_count);
+ /* if (rc != NO_ERROR) ... */
+ i = (int)handle_count;
+#elif defined(_SC_OPEN_MAX)
+ i = (int)sysconf( _SC_OPEN_MAX );
+#elif defined(_POSIX_OPEN_MAX)
+ i = (int)_POSIX_OPEN_MAX;
+#elif defined(OPEN_MAX)
+ i = (int)OPEN_MAX;
+#else
+ i = TQMAX( 256, fds[0] );
+#endif // TQ_OS_OS2EMX // ways-to-set i
+ while( --i > 0 )
+ ::close( i );
+}
+
+
+
+static const char * const psToStr[TQPrinter::NPageSize+1] =
+{ "A4", "B5", "Letter", "Legal", "Executive",
+ "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1",
+ "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E",
+ "DLE", "Folio", "Ledger", "Tabloid", 0
+};
+
+
+/*!
+ \internal
+ Handles painter commands to the printer.
+*/
+
+bool TQPrinter::cmd( int c, TQPainter *paint, TQPDevCmdParam *p )
+{
+ if ( c == PdcBegin ) {
+ if ( state == PST_IDLE ) {
+ if ( output_file ) {
+ int fd = 0;
+ fd = qt_open( output_filename.local8Bit(),
+ O_CREAT | O_NOCTTY | O_TRUNC | O_WRONLY,
+ 0666 );
+ if ( fd >= 0 ) {
+ pdrv = new TQPSPrinter( this, fd );
+ state = PST_ACTIVE;
+ }
+ } else {
+ TQString pr;
+ if ( printer_name )
+ pr = printer_name;
+ TQApplication::flushX();
+ int fds[2];
+ if ( pipe( fds ) != 0 ) {
+ qWarning( "TQPSPrinter: could not open pipe to print" );
+ state = PST_ERROR;
+ return FALSE;
+ }
+
+// ### shouldn't we use TQProcess here????
+#if 0 && defined(TQ_OS_OS2EMX)
+ // this code is still not used, and maybe it's not
+ // usable either, any more. if you want to use it,
+ // you may need to fix it first.
+
+ // old comment:
+
+ // this code is usable but not in use. spawn() is
+ // preferable to fork()/exec() for very large
+ // programs. if fork()/exec() is a problem and you
+ // use OS/2, remove '0 && ' from the #if.
+ int tmp;
+ tmp = dup(0);
+ dup2( fds[0], 0 );
+ ::close( fds[0] );
+ fcntl(tmp, F_SETFD, FD_CLOEXEC);
+ fcntl(fds[1], F_SETFD, FD_CLOEXEC);
+ if ( option_string )
+ pr.prepend( option_string );
+ else
+ pr.prepend( "-P" ); // ###
+ if ( spawnlp(P_NOWAIT,print_prog.data(), print_prog.data(),
+ pr.data(), output->name(), 0) == -1 ) {
+ ; // couldn't exec, ignored
+ }
+ dup2( tmp, 0 );
+ ::close( tmp );
+ pdrv = new TQPSPrinter( this, fds[1] );
+ state = PST_ACTIVE;
+#else
+ pid = fork();
+ if ( pid == 0 ) { // child process
+ // if possible, exit quickly, so the actual lp/lpr
+ // becomes a child of init, and ::waitpid() is
+ // guaranteed not to wait.
+ if ( fork() > 0 ) {
+ closeAllOpenFds();
+
+ // try to tqreplace this process with "true" - this prevents
+ // global destructors from being called (that could possibly
+ // do wrong things to the tqparent process)
+ (void)execlp("true", "true", (char *)0);
+ (void)execl("/bin/true", "true", (char *)0);
+ (void)execl("/usr/bin/true", "true", (char *)0);
+ ::exit( 0 );
+ }
+ dup2( fds[0], 0 );
+
+ closeAllOpenFds();
+
+ if ( print_prog ) {
+ if ( option_string )
+ pr.prepend( option_string );
+ else
+ pr.prepend( TQString::tqfromLatin1( "-P" ) );
+ (void)execlp( print_prog.ascii(), print_prog.ascii(),
+ pr.ascii(), (char *)0 );
+ } else {
+ // if no print program has been specified, be smart
+ // about the option string too.
+ TQStringList lprhack;
+ TQStringList lphack;
+ TQString media;
+ if ( pr || option_string ) {
+ if ( option_string ) {
+ lprhack = TQStringList::split(TQChar(' '), option_string);
+ lphack = lprhack;
+ } else {
+ lprhack.append( TQString::tqfromLatin1( "-P" ) );
+ lphack.append( TQString::tqfromLatin1( "-d" ) );
+ }
+ lprhack.append(pr);
+ lphack.append(pr);
+ }
+ char ** lpargs = new char *[lphack.size()+6];
+ lpargs[0] = "lp";
+ uint i;
+ for (i = 0; i < lphack.size(); ++i)
+ lpargs[i+1] = (char *)lphack[i].ascii();
+#ifndef TQ_OS_OSF
+ if (psToStr[page_size]) {
+ lpargs[++i] = "-o";
+ lpargs[++i] = (char *)psToStr[page_size];
+ lpargs[++i] = "-o";
+ media = "media=";
+ media += psToStr[page_size];
+ lpargs[++i] = (char *)media.ascii();
+ }
+#endif
+ lpargs[++i] = 0;
+ char **lprargs = new char *[lprhack.size()+1];
+ lprargs[0] = "lpr";
+ for (uint x = 0; x < lprhack.size(); ++x)
+ lprargs[x+1] = (char *)lprhack[x].ascii();
+ lprargs[lprhack.size() + 1] = 0;
+ (void)execvp( "lp", lpargs );
+ (void)execvp( "lpr", lprargs );
+ (void)execv( "/bin/lp", lpargs);
+ (void)execv( "/bin/lpr", lprargs);
+ (void)execv( "/usr/bin/lp", lpargs);
+ (void)execv( "/usr/bin/lpr", lprargs);
+ }
+ // if we couldn't exec anything, close the fd,
+ // wait for a second so the tqparent process (the
+ // child of the GUI process) has exited. then
+ // exit.
+ ::close( 0 );
+ (void)::sleep( 1 );
+ ::exit( 0 );
+ } else { // tqparent process
+ ::close( fds[0] );
+ pdrv = new TQPSPrinter( this, fds[1] );
+ state = PST_ACTIVE;
+ }
+#endif // else part of TQ_OS_OS2EMX
+ }
+ if ( state == PST_ACTIVE && pdrv )
+ return ((TQPSPrinter*)pdrv)->cmd( c, paint, p );
+ } else {
+ // ignore it? I don't know
+ }
+ } else {
+ bool r = FALSE;
+ if ( state == PST_ACTIVE && pdrv ) {
+ r = ((TQPSPrinter*)pdrv)->cmd( c, paint, p );
+ if ( c == PdcEnd ) {
+ state = PST_IDLE;
+ delete pdrv;
+ pdrv = 0;
+ if ( pid ) {
+ (void)::waitpid( pid, 0, 0 );
+ pid = 0;
+ }
+ }
+ } else if ( state == PST_ABORTED && c == PdcEnd )
+ state = PST_IDLE;
+ return r;
+ }
+ return TRUE;
+}
+
+
+#define MM(n) int((n * 720 + 127) / 254)
+#define IN(n) int(n * 72)
+
+struct PaperSize {
+ int width, height;
+};
+
+static const PaperSize paperSizes[TQPrinter::NPageSize] =
+{
+ { MM(210), MM(297) }, // A4
+ { MM(176), MM(250) }, // B5
+ { IN(8.5), IN(11) }, // Letter
+ { IN(8.5), IN(14) }, // Legal
+ { IN(7.5), IN(10) }, // Executive
+ { MM(841), MM(1189) }, // A0
+ { MM(594), MM(841) }, // A1
+ { MM(420), MM(594) }, // A2
+ { MM(297), MM(420) }, // A3
+ { MM(148), MM(210) }, // A5
+ { MM(105), MM(148) }, // A6
+ { MM(74), MM(105)}, // A7
+ { MM(52), MM(74) }, // A8
+ { MM(37), MM(52) }, // A9
+ { MM(1000), MM(1414) }, // B0
+ { MM(707), MM(1000) }, // B1
+ { MM(31), MM(44) }, // B10
+ { MM(500), MM(707) }, // B2
+ { MM(353), MM(500) }, // B3
+ { MM(250), MM(353) }, // B4
+ { MM(125), MM(176) }, // B6
+ { MM(88), MM(125) }, // B7
+ { MM(62), MM(88) }, // B8
+ { MM(44), MM(62) }, // B9
+ { MM(162), MM(229) }, // C5E
+ { IN(4.125), IN(9.5) }, // Comm10E
+ { MM(110), MM(220) }, // DLE
+ { IN(8.5), IN(13) }, // Folio
+ { IN(17), IN(11) }, // Ledger
+ { IN(11), IN(17) } // Tabloid
+};
+
+/*!
+ Internal implementation of the virtual TQPaintDevice::metric() function.
+
+ Use the TQPaintDeviceMetrics class instead.
+
+ \internal
+ Hard coded return values for PostScript under X.
+*/
+
+int TQPrinter::metric( int m ) const
+{
+ int val;
+ PageSize s = pageSize();
+#if defined(TQT_CHECK_RANGE)
+ TQ_ASSERT( (uint)s < (uint)NPageSize );
+#endif
+ switch ( m ) {
+ case TQPaintDeviceMetrics::PdmWidth:
+ val = orient == Portrait ? paperSizes[s].width : paperSizes[s].height;
+ if ( res != 72 )
+ val = (val * res + 36) / 72;
+ if ( !fullPage() ) {
+ if ( D->marginsSpecified )
+ val -= D->leftMargin + D->rightMargin;
+ else
+ val -= 2*margins().width();
+ }
+ break;
+ case TQPaintDeviceMetrics::PdmHeight:
+ val = orient == Portrait ? paperSizes[s].height : paperSizes[s].width;
+ if ( res != 72 )
+ val = (val * res + 36) / 72;
+ if ( !fullPage() ) {
+ if ( D->marginsSpecified )
+ val -= D->topMargin + D->bottomMargin;
+ else
+ val -= 2*margins().height();
+ }
+ break;
+ case TQPaintDeviceMetrics::PdmDpiX:
+ val = res;
+ break;
+ case TQPaintDeviceMetrics::PdmDpiY:
+ val = res;
+ break;
+ case TQPaintDeviceMetrics::PdmPhysicalDpiX:
+ case TQPaintDeviceMetrics::PdmPhysicalDpiY:
+ val = 72;
+ break;
+ case TQPaintDeviceMetrics::PdmWidthMM:
+ // double rounding error here. hooray.
+ val = metric( TQPaintDeviceMetrics::PdmWidth );
+ val = (val * 254 + 5*res) / (10*res);
+ break;
+ case TQPaintDeviceMetrics::PdmHeightMM:
+ val = metric( TQPaintDeviceMetrics::PdmHeight );
+ val = (val * 254 + 5*res) / (10*res);
+ break;
+ case TQPaintDeviceMetrics::PdmNumColors:
+ val = 16777216;
+ break;
+ case TQPaintDeviceMetrics::PdmDepth:
+ val = 24;
+ break;
+ default:
+ val = 0;
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQPixmap::metric: Invalid metric command" );
+#endif
+ }
+ return val;
+}
+
+
+/*!
+ Returns the width of the left margin and the height of the top
+ margin of the printer. On Unix, this is a best-effort guess, not
+ based on perfect knowledge.
+
+ If you have called setFullPage( TRUE ), margins().width() may be
+ treated as the smallest sane left margin you can use, and
+ margins().height() as the smallest sane top margin you can
+ use.
+
+ If you have called setFullPage( FALSE ) (this is the default),
+ margins() is automatically subtracted from the pageSize() by
+ TQPrinter.
+
+ \sa setFullPage() TQPaintDeviceMetrics PageSize
+*/
+TQSize TQPrinter::margins() const
+{
+ if ( D->marginsSpecified )
+ return TQSize( D->leftMargin, D->topMargin );
+
+ if (orient == Portrait)
+ return TQSize( res/2, res/3 );
+
+ return TQSize( res/3, res/2 );
+}
+
+/*!
+ \overload
+
+ Sets \a top, \a left, \a bottom and \a right to the margins of the
+ printer. On Unix, this is a best-effort guess, not based on
+ perfect knowledge.
+
+ If you have called setFullPage( TRUE ), the four values specify
+ the smallest sane margins you can use.
+
+ If you have called setFullPage( FALSE ) (this is the default),
+ the margins are automatically subtracted from the pageSize() by
+ TQPrinter.
+
+ \sa setFullPage() TQPaintDeviceMetrics PageSize
+*/
+void TQPrinter::margins( uint *top, uint *left, uint *bottom, uint *right ) const
+{
+ if ( !D->marginsSpecified ) {
+ int x = orient == Portrait ? res/2 : res/3;
+ int y = orient == Portrait ? res/3 : res/2;
+ *top = *bottom = y;
+ *left = *right = x;
+ } else {
+ *top = D->topMargin;
+ *left = D->leftMargin;
+ *bottom = D->bottomMargin;
+ *right = D->rightMargin;
+ }
+}
+
+/*!
+ Sets the printer margins to the sizes specified in \a top, \a left,
+ \a bottom and \a right.
+
+ This function currently only has an effect on Unix systems.
+
+ \sa margins()
+*/
+void TQPrinter::setMargins( uint top, uint left, uint bottom, uint right )
+{
+ D->topMargin = top;
+ D->leftMargin = left;
+ D->bottomMargin = bottom;
+ D->rightMargin = right;
+ D->marginsSpecified = TRUE;
+}
+
+#endif // USE_QT4
+
+#endif \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqprocess.cpp b/tqtinterface/qt4/src/kernel/tqprocess.cpp
new file mode 100644
index 0000000..a809996
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqprocess.cpp
@@ -0,0 +1,806 @@
+/****************************************************************************
+**
+** Implementation of TQProcess class
+**
+** Created : 20000905
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tqprocess.h"
+
+#ifndef TQT_NO_PROCESS
+
+#include "tqapplication.h"
+#include "private/tqinternal_p.h"
+
+
+//#define TQT_TQPROCESS_DEBUG
+
+
+/*!
+ \class TQProcess tqprocess.h
+
+ \brief The TQProcess class is used to start external programs and
+ to communicate with them.
+
+ \ingroup io
+ \ingroup misc
+ \mainclass
+
+ You can write to the started program's standard input, and can
+ read the program's standard output and standard error. You can
+ pass command line arguments to the program either in the
+ constructor or with setArguments() or addArgument(). The program's
+ working directory can be set with setWorkingDirectory(). If you
+ need to set up environment variables pass them to the start() or
+ launch() functions (see below). The processExited() signal is
+ emitted if the program exits. The program's exit status is
+ available from exitqStatus(), although you could simply call
+ normalExit() to see if the program terminated normally.
+
+ There are two different ways to start a process. If you just want
+ to run a program, optionally passing data to its standard input at
+ the beginning, use one of the launch() functions. If you want full
+ control of the program's standard input (especially if you don't
+ know all the data you want to send to standard input at the
+ beginning), use the start() function.
+
+ If you use start() you can write to the program's standard input
+ using writeToStdin() and you can close the standard input with
+ closeStdin(). The wroteToStdin() signal is emitted if the data
+ sent to standard input has been written. You can read from the
+ program's standard output using readStdout() or readLineStdout().
+ These functions return an empty TQByteArray if there is no data to
+ read. The readyReadStdout() signal is emitted when there is data
+ available to be read from standard output. Standard error has a
+ set of functions that correspond to the standard output functions,
+ i.e. readStderr(), readLineStderr() and readyReadStderr().
+
+ If you use one of the launch() functions the data you pass will be
+ sent to the program's standard input which will be closed once all
+ the data has been written. You should \e not use writeToStdin() or
+ closeStdin() if you use launch(). If you need to send data to the
+ program's standard input after it has started running use start()
+ instead of launch().
+
+ Both start() and launch() can accept a string list of strings each
+ of which has the format, key=value, where the keys are the names
+ of environment variables.
+
+ You can test to see if a program is running with isRunning(). The
+ program's process identifier is available from
+ processIdentifier(). If you want to terminate a running program
+ use tryTerminate(), but note that the program may ignore this. If
+ you \e really want to terminate the program, without it having any
+ chance to clean up, you can use kill().
+
+ As an example, suppose we want to start the \c uic command (a TQt
+ command line tool used with \e{TQt Designer}) and perform some
+ operations on the output (the \c uic outputs the code it generates
+ to standard output by default). Suppose further that we want to
+ run the program on the file "small_dialog.ui" with the command
+ line options "-tr i18n". On the command line we would write:
+ \code
+ uic -tr i18n small_dialog.ui
+ \endcode
+
+ \quotefile process/process.cpp
+
+ A code snippet for this with the TQProcess class might look like
+ this:
+
+ \skipto UicManager::UicManager()
+ \printline UicManager::UicManager()
+ \printline {
+ \skipto proc = new TQProcess( this );
+ \printline proc = new TQProcess( this );
+ \skipto proc->addArgument( "uic" );
+ \printuntil this, TQT_SLOT(readFromStdout()) );
+ \skipto if ( !proc->start() ) {
+ \printuntil // error handling
+ \skipto }
+ \printline }
+ \printline }
+
+ \skipto void UicManager::readFromStdout()
+ \printuntil // Bear in mind that the data might be output in chunks.
+ \skipto }
+ \printline }
+
+ Although you may need quotes for a file named on the command line
+ (e.g. if it tqcontains spaces) you shouldn't use extra quotes for
+ arguments passed to addArgument() or setArguments().
+
+ The readyReadStdout() signal is emitted when there is new data on
+ standard output. This happens asynchronously: you don't know if
+ more data will arrive later.
+
+ In the above example you could connect the processExited() signal
+ to the slot UicManager::readFromStdout() instead. If you do so,
+ you will be certain that all the data is available when the slot
+ is called. On the other hand, you must wait until the process has
+ finished before doing any processing.
+
+ Note that if you are expecting a lot of output from the process,
+ you may hit platform-dependent limits to the pipe buffer size. The
+ solution is to make sure you connect to the output, e.g. the
+ readyReadStdout() and readyReadStderr() Q_SIGNALS and read the data
+ as soon as it becomes available.
+
+ Please note that TQProcess does not emulate a shell. This means that
+ TQProcess does not do any expansion of arguments: a '*' is passed as a '*'
+ to the program and is \e not tqreplaced by all the files, a '$HOME' is also
+ passed literally and is \e not tqreplaced by the environment variable HOME
+ and the special characters for IO redirection ('>', '|', etc.) are also
+ passed literally and do \e not have the special meaning as they have in a
+ shell.
+
+ Also note that TQProcess does not emulate a terminal. This means that
+ certain programs which need direct terminal control, do not work as
+ expected with TQProcess. Such programs include console email programs (like
+ pine and mutt) but also programs which require the user to enter a password
+ (like su and ssh).
+
+ \section1 Notes for Windows users
+
+ Some Windows commands, for example, \c dir, are not provided by
+ separate applications, but by the command interpreter.
+ If you attempt to use TQProcess to execute these commands directly
+ it won't work. One possible solution is to execute the command
+ interpreter itself (\c cmd.exe on some Windows systems), and ask
+ the interpreter to execute the desired command.
+
+ Under Windows there are certain problems starting 16-bit applications
+ and capturing their output. Microsoft recommends using an intermediate
+ application to start 16-bit applications.
+
+ \sa TQSocket
+*/
+
+/*!
+ \enum TQProcess::Communication
+
+ This enum type defines the communication channels connected to the
+ process.
+
+ \value Stdin Data can be written to the process's standard input.
+
+ \value Stdout Data can be read from the process's standard
+ output.
+
+ \value Stderr Data can be read from the process's standard error.
+
+ \value DupStderr Both the process's standard error output \e and
+ its standard output are written to its standard output. (Like
+ Unix's dup2().) This means that nothing is sent to the standard
+ error output. This is especially useful if your application
+ requires that the output on standard output and on standard error
+ must be read in the same order that they are produced. This is a
+ flag, so to activate it you must pass \c{Stdout|Stderr|DupStderr},
+ or \c{Stdin|Stdout|Stderr|DupStderr} if you want to provide input,
+ to the setCommunication() call.
+
+ \sa setCommunication() communication()
+*/
+
+/*!
+ Constructs a TQProcess object. The \a tqparent and \a name parameters
+ are passed to the TQObject constructor.
+
+ \sa setArguments() addArgument() start()
+*/
+TQProcess::TQProcess( TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ),
+ wroteToStdinConnected( FALSE ),
+ readStdoutCalled( FALSE ), readStderrCalled( FALSE ),
+ comms( Stdin|Stdout|Stderr )
+{
+ init();
+}
+
+/*!
+ Constructs a TQProcess with \a arg0 as the command to be executed.
+ The \a tqparent and \a name parameters are passed to the TQObject
+ constructor.
+
+ The process is not started. You must call start() or launch() to
+ start the process.
+
+ \sa setArguments() addArgument() start()
+*/
+TQProcess::TQProcess( const TQString& arg0, TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ),
+ wroteToStdinConnected( FALSE ),
+ readStdoutCalled( FALSE ), readStderrCalled( FALSE ),
+ comms( Stdin|Stdout|Stderr )
+{
+ init();
+ addArgument( arg0 );
+}
+
+/*!
+ Constructs a TQProcess with \a args as the arguments of the
+ process. The first element in the list is the command to be
+ executed. The other elements in the list are the arguments to this
+ command. The \a tqparent and \a name parameters are passed to the
+ TQObject constructor.
+
+ The process is not started. You must call start() or launch() to
+ start the process.
+
+ \sa setArguments() addArgument() start()
+*/
+TQProcess::TQProcess( const TQStringList& args, TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ),
+ wroteToStdinConnected( FALSE ),
+ readStdoutCalled( FALSE ), readStderrCalled( FALSE ),
+ comms( Stdin|Stdout|Stderr )
+{
+ init();
+ setArguments( args );
+}
+
+
+/*!
+ Returns the list of arguments that are set for the process.
+ Arguments can be specified with the constructor or with the
+ functions setArguments() and addArgument().
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myProcess.arguments();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa setArguments() addArgument()
+*/
+TQStringList TQProcess::arguments() const
+{
+ return _arguments;
+}
+
+/*!
+ Clears the list of arguments that are set for the process.
+
+ \sa setArguments() addArgument()
+*/
+void TQProcess::clearArguments()
+{
+ _arguments.clear();
+}
+
+/*!
+ Sets \a args as the arguments for the process. The first element
+ in the list is the command to be executed. The other elements in
+ the list are the arguments to the command. Any previous arguments
+ are deleted.
+
+ TQProcess does not perform argument substitutions; for example, if you
+ specify "*" or "$DISPLAY", these values are passed to the process
+ literally. If you want to have the same behavior as the shell
+ provides, you must do the substitutions yourself; i.e. instead of
+ specifying a "*" you must specify the list of all the filenames in
+ the current directory, and instead of "$DISPLAY" you must specify
+ the value of the environment variable \c DISPLAY.
+
+ Note for Windows users. The standard Windows shells, e.g. \c
+ command.com and \c cmd.exe, do not perform file globbing, i.e.
+ they do not convert a "*" on the command line into a list of files
+ in the current directory. For this reason most Windows
+ applications implement their own file globbing, and as a result of
+ this, specifying an argument of "*" for a Windows application is
+ likely to result in the application performing a file glob and
+ ending up with a list of filenames.
+
+ \sa arguments() addArgument()
+*/
+void TQProcess::setArguments( const TQStringList& args )
+{
+ _arguments = args;
+}
+
+/*!
+ Adds \a arg to the end of the list of arguments.
+
+ The first element in the list of arguments is the command to be
+ executed; the following elements are the command's arguments.
+
+ \sa arguments() setArguments()
+*/
+void TQProcess::addArgument( const TQString& arg )
+{
+ _arguments.append( arg );
+}
+
+#ifndef TQT_NO_DIR
+/*!
+ Returns the working directory that was set with
+ setWorkingDirectory(), or the current directory if none has been
+ explicitly set.
+
+ \sa setWorkingDirectory() TQDir::current()
+*/
+TQDir TQProcess::workingDirectory() const
+{
+ return workingDir;
+}
+
+/*!
+ Sets \a dir as the working directory for processes. This does not
+ affect running processes; only processes that are started
+ afterwards are affected.
+
+ Setting the working directory is especially useful for processes
+ that try to access files with relative paths.
+
+ \sa workingDirectory() start()
+*/
+void TQProcess::setWorkingDirectory( const TQDir& dir )
+{
+ workingDir = dir;
+}
+#endif //TQT_NO_DIR
+
+/*!
+ Returns the communication required with the process, i.e. some
+ combination of the \c Communication flags.
+
+ \sa setCommunication()
+*/
+int TQProcess::communication() const
+{
+ return comms;
+}
+
+/*!
+ Sets \a commFlags as the communication required with the process.
+
+ \a commFlags is a bitwise OR of the flags defined by the \c
+ Communication enum.
+
+ The default is \c{Stdin|Stdout|Stderr}.
+
+ \sa communication()
+*/
+void TQProcess::setCommunication( int commFlags )
+{
+ comms = commFlags;
+}
+
+/*!
+ Returns TRUE if the process has exited normally; otherwise returns
+ FALSE. This implies that this function returns FALSE if the
+ process is still running.
+
+ \sa isRunning() exitqStatus() processExited()
+*/
+bool TQProcess::normalExit() const
+{
+ // isRunning() has the side effect that it determines the exit status!
+ if ( isRunning() )
+ return FALSE;
+ else
+ return exitNormal;
+}
+
+/*!
+ Returns the exit status of the process or 0 if the process is
+ still running. This function returns immediately and does not wait
+ until the process is finished.
+
+ If normalExit() is FALSE (e.g. if the program was killed or
+ crashed), this function returns 0, so you should check the return
+ value of normalExit() before relying on this value.
+
+ \sa normalExit() processExited()
+*/
+int TQProcess::exitqStatus() const
+{
+ // isRunning() has the side effect that it determines the exit status!
+ if ( isRunning() )
+ return 0;
+ else
+ return exitStat;
+}
+
+
+/*!
+ Reads the data that the process has written to standard output.
+ When new data is written to standard output, the class emits the
+ signal readyReadStdout().
+
+ If there is no data to read, this function returns a TQByteArray of
+ size 0: it does not wait until there is something to read.
+
+ \sa readyReadStdout() readLineStdout() readStderr() writeToStdin()
+*/
+TQByteArray TQProcess::readStdout()
+{
+ if ( readStdoutCalled ) {
+ return TQByteArray();
+ }
+ readStdoutCalled = TRUE;
+ TQMembuf *buf = membufStdout();
+ readStdoutCalled = FALSE;
+
+ return buf->readAll();
+}
+
+/*!
+ Reads the data that the process has written to standard error.
+ When new data is written to standard error, the class emits the
+ signal readyReadStderr().
+
+ If there is no data to read, this function returns a TQByteArray of
+ size 0: it does not wait until there is something to read.
+
+ \sa readyReadStderr() readLineStderr() readStdout() writeToStdin()
+*/
+TQByteArray TQProcess::readStderr()
+{
+ if ( readStderrCalled ) {
+ return TQByteArray();
+ }
+ readStderrCalled = TRUE;
+ TQMembuf *buf = membufStderr();
+ readStderrCalled = FALSE;
+
+ return buf->readAll();
+}
+
+/*!
+ Reads a line of text from standard output, excluding any trailing
+ newline or carriage return characters, and returns it. Returns
+ TQString::null if canReadLineStdout() returns FALSE.
+
+ By default, the text is interpreted to be in Latin-1 encoding. If you need
+ other codecs, you can set a different codec with
+ TQTextCodec::setCodecForCStrings().
+
+ \sa canReadLineStdout() readyReadStdout() readStdout() readLineStderr()
+*/
+TQString TQProcess::readLineStdout()
+{
+ TQByteArray a( 256 );
+ TQMembuf *buf = membufStdout();
+ if ( !buf->scanNewline( &a ) ) {
+ if ( !canReadLineStdout() )
+ return TQString::null;
+
+ if ( !buf->scanNewline( &a ) )
+ return TQString( buf->readAll() );
+ }
+
+ uint size = a.size();
+ buf->consumeBytes( size, 0 );
+
+ // get rid of terminating \n or \r\n
+ if ( size>0 && a.at( size - 1 ) == '\n' ) {
+ if ( size>1 && a.at( size - 2 ) == '\r' )
+ a[ size - 2 ] = '\0';
+ else
+ a[ size - 1 ] = '\0';
+ }
+ return TQString( a );
+}
+
+/*!
+ Reads a line of text from standard error, excluding any trailing
+ newline or carriage return characters and returns it. Returns
+ TQString::null if canReadLineStderr() returns FALSE.
+
+ By default, the text is interpreted to be in Latin-1 encoding. If you need
+ other codecs, you can set a different codec with
+ TQTextCodec::setCodecForCStrings().
+
+ \sa canReadLineStderr() readyReadStderr() readStderr() readLineStdout()
+*/
+TQString TQProcess::readLineStderr()
+{
+ TQByteArray a( 256 );
+ TQMembuf *buf = membufStderr();
+ if ( !buf->scanNewline( &a ) ) {
+ if ( !canReadLineStderr() )
+ return TQString::null;
+
+ if ( !buf->scanNewline( &a ) )
+ return TQString( buf->readAll() );
+ }
+
+ uint size = a.size();
+ buf->consumeBytes( size, 0 );
+
+ // get rid of terminating \n or \r\n
+ if ( size>0 && a.at( size - 1 ) == '\n' ) {
+ if ( size>1 && a.at( size - 2 ) == '\r' )
+ a[ size - 2 ] = '\0';
+ else
+ a[ size - 1 ] = '\0';
+ }
+ return TQString( a );
+}
+
+/*!
+ \fn void TQProcess::launchFinished()
+
+ This signal is emitted when the process was started with launch().
+ If the start was successful, this signal is emitted after all the
+ data has been written to standard input. If the start failed, then
+ this signal is emitted immediately.
+
+ This signal is especially useful if you want to know when you can
+ safely delete the TQProcess object when you are not interested in
+ reading from standard output or standard error.
+
+ \sa launch() TQObject::deleteLater()
+*/
+
+/*!
+ Runs the process and writes the data \a buf to the process's
+ standard input. If all the data is written to standard input,
+ standard input is closed. The command is searched for in the path
+ for executable programs; you can also use an absolute path in the
+ command itself.
+
+ If \a env is null, then the process is started with the same
+ environment as the starting process. If \a env is non-null, then
+ the values in the string list are interpreted as environment
+ setttings of the form \c {key=value} and the process is started
+ with these environment settings. For convenience, there is a small
+ exception to this rule under Unix: if \a env does not contain any
+ settings for the environment variable \c LD_LIBRARY_PATH, then
+ this variable is inherited from the starting process.
+
+ Returns TRUE if the process could be started; otherwise returns
+ FALSE.
+
+ Note that you should not use the Q_SLOTS writeToStdin() and
+ closeStdin() on processes started with launch(), since the result
+ is not well-defined. If you need these Q_SLOTS, use start() instead.
+
+ The process may or may not read the \a buf data sent to its
+ standard input.
+
+ You can call this function even when a process that was started
+ with this instance is still running. Be aware that if you do this
+ the standard input of the process that was launched first will be
+ closed, with any pending data being deleted, and the process will
+ be left to run out of your control. Similarly, if the process
+ could not be started the standard input will be closed and the
+ pending data deleted. (On operating systems that have zombie
+ processes, TQt will also wait() on the old process.)
+
+ The object emits the signal launchFinished() when this function
+ call is finished. If the start was successful, this signal is
+ emitted after all the data has been written to standard input. If
+ the start failed, then this signal is emitted immediately.
+
+ \sa start() launchFinished();
+*/
+bool TQProcess::launch( const TQByteArray& buf, TQStringList *env )
+{
+ if ( start( env ) ) {
+ if ( !buf.isEmpty() ) {
+ connect( this, TQT_SIGNAL(wroteToStdin()),
+ this, TQT_SLOT(closeStdinLaunch()) );
+ writeToStdin( buf );
+ } else {
+ closeStdin();
+ emit launchFinished();
+ }
+ return TRUE;
+ } else {
+ emit launchFinished();
+ return FALSE;
+ }
+}
+
+/*!
+ \overload
+
+ The data \a buf is written to standard input with writeToStdin()
+ using the TQString::local8Bit() representation of the strings.
+*/
+bool TQProcess::launch( const TQString& buf, TQStringList *env )
+{
+ if ( start( env ) ) {
+ if ( !buf.isEmpty() ) {
+ connect( this, TQT_SIGNAL(wroteToStdin()),
+ this, TQT_SLOT(closeStdinLaunch()) );
+ writeToStdin( buf );
+ } else {
+ closeStdin();
+ emit launchFinished();
+ }
+ return TRUE;
+ } else {
+ emit launchFinished();
+ return FALSE;
+ }
+}
+
+/*
+ This private slot is used by the launch() functions to close standard input.
+*/
+void TQProcess::closeStdinLaunch()
+{
+ disconnect( this, TQT_SIGNAL(wroteToStdin()),
+ this, TQT_SLOT(closeStdinLaunch()) );
+ closeStdin();
+ emit launchFinished();
+}
+
+
+/*!
+ \fn void TQProcess::readyReadStdout()
+
+ This signal is emitted when the process has written data to
+ standard output. You can read the data with readStdout().
+
+ Note that this signal is only emitted when there is new data and
+ not when there is old, but unread data. In the slot connected to
+ this signal, you should always read everything that is available
+ at that moment to make sure that you don't lose any data.
+
+ \sa readStdout() readLineStdout() readyReadStderr()
+*/
+
+/*!
+ \fn void TQProcess::readyReadStderr()
+
+ This signal is emitted when the process has written data to
+ standard error. You can read the data with readStderr().
+
+ Note that this signal is only emitted when there is new data and
+ not when there is old, but unread data. In the slot connected to
+ this signal, you should always read everything that is available
+ at that moment to make sure that you don't lose any data.
+
+ \sa readStderr() readLineStderr() readyReadStdout()
+*/
+
+/*!
+ \fn void TQProcess::processExited()
+
+ This signal is emitted when the process has exited.
+
+ \sa isRunning() normalExit() exitqStatus() start() launch()
+*/
+
+/*!
+ \fn void TQProcess::wroteToStdin()
+
+ This signal is emitted if the data sent to standard input (via
+ writeToStdin()) was actually written to the process. This does not
+ imply that the process really read the data, since this class only
+ detects when it was able to write the data to the operating
+ system. But it is now safe to close standard input without losing
+ pending data.
+
+ \sa writeToStdin() closeStdin()
+*/
+
+
+/*!
+ \overload
+
+ The string \a buf is handled as text using the
+ TQString::local8Bit() representation.
+*/
+void TQProcess::writeToStdin( const TQString& buf )
+{
+ TQByteArray tmp = buf.local8Bit();
+ tmp.resize( tqstrlen( tmp.data() ) );
+ writeToStdin( tmp );
+}
+
+
+/*
+ * Under Windows the implementation is not so nice: it is not that easy to
+ * detect when one of the Q_SIGNALS should be emitted; therefore there are some
+ * timers that query the information.
+ * To keep it a little efficient, use the timers only when they are needed.
+ * They are needed, if you are interested in the Q_SIGNALS. So use
+ * connectNotify() and disconnectNotify() to keep track of your interest.
+ */
+/*! \reimp
+*/
+void TQProcess::connectNotify( const char * signal )
+{
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::connectNotify(): signal %s has been connected", signal );
+#endif
+ if ( !ioRedirection )
+ if ( qstrcmp( signal, TQT_SIGNAL(readyReadStdout()) )==0 ||
+ qstrcmp( signal, TQT_SIGNAL(readyReadStderr()) )==0
+ ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::connectNotify(): set ioRedirection to TRUE" );
+#endif
+ setIoRedirection( TRUE );
+ return;
+ }
+ if ( !notifyOnExit && qstrcmp( signal, TQT_SIGNAL(processExited()) )==0 ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::connectNotify(): set notifyOnExit to TRUE" );
+#endif
+ setNotifyOnExit( TRUE );
+ return;
+ }
+ if ( !wroteToStdinConnected && qstrcmp( signal, TQT_SIGNAL(wroteToStdin()) )==0 ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::connectNotify(): set wroteToStdinConnected to TRUE" );
+#endif
+ setWroteStdinConnected( TRUE );
+ return;
+ }
+}
+
+/*! \reimp
+*/
+void TQProcess::disconnectNotify( const char * )
+{
+ if ( ioRedirection &&
+ tqreceivers( TQT_SIGNAL(readyReadStdout()) ) ==0 &&
+ tqreceivers( TQT_SIGNAL(readyReadStderr()) ) ==0
+ ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::disconnectNotify(): set ioRedirection to FALSE" );
+#endif
+ setIoRedirection( FALSE );
+ }
+ if ( notifyOnExit && tqreceivers( TQT_SIGNAL(processExited()) ) == 0 ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::disconnectNotify(): set notifyOnExit to FALSE" );
+#endif
+ setNotifyOnExit( FALSE );
+ }
+ if ( wroteToStdinConnected && tqreceivers( TQT_SIGNAL(wroteToStdin()) ) == 0 ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::disconnectNotify(): set wroteToStdinConnected to FALSE" );
+#endif
+ setWroteStdinConnected( FALSE );
+ }
+}
+
+#endif // TQT_NO_PROCESS
diff --git a/tqtinterface/qt4/src/kernel/tqprocess.h b/tqtinterface/qt4/src/kernel/tqprocess.h
new file mode 100644
index 0000000..ad00b30
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqprocess.h
@@ -0,0 +1,179 @@
+/****************************************************************************
+**
+** Implementation of TQProcess class
+**
+** Created : 20000905
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPROCESS_H
+#define TQPROCESS_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqstringlist.h"
+#include "tqdir.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_PROCESS
+
+class TQProcessPrivate;
+class TQMembuf;
+
+
+class TQ_EXPORT TQProcess : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQProcess( TQObject *tqparent=0, const char *name=0 );
+ TQProcess( const TQString& arg0, TQObject *tqparent=0, const char *name=0 );
+ TQProcess( const TQStringList& args, TQObject *tqparent=0, const char *name=0 );
+ ~TQProcess();
+
+ // set and get the arguments and working directory
+ TQStringList arguments() const;
+ void clearArguments();
+ virtual void setArguments( const TQStringList& args );
+ virtual void addArgument( const TQString& arg );
+#ifndef TQT_NO_DIR
+ TQDir workingDirectory() const;
+ virtual void setWorkingDirectory( const TQDir& dir );
+#endif
+
+ // set and get the comms wanted
+ enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 };
+ void setCommunication( int c );
+ int communication() const;
+
+ // start the execution
+ virtual bool start( TQStringList *env=0 );
+ virtual bool launch( const TQString& buf, TQStringList *env=0 );
+ virtual bool launch( const TQByteArray& buf, TQStringList *env=0 );
+
+ // inquire the status
+ bool isRunning() const;
+ bool normalExit() const;
+ int exitqStatus() const;
+
+ // reading
+ virtual TQByteArray readStdout();
+ virtual TQByteArray readStderr();
+ bool canReadLineStdout() const;
+ bool canReadLineStderr() const;
+ virtual TQString readLineStdout();
+ virtual TQString readLineStderr();
+
+ // get platform dependent process information
+#if defined(TQ_OS_WIN32)
+ typedef void* PID;
+#else
+ typedef TQ_LONG PID;
+#endif
+ PID processIdentifier();
+
+ void flushStdin();
+
+Q_SIGNALS:
+ void readyReadStdout();
+ void readyReadStderr();
+ void processExited();
+ void wroteToStdin();
+ void launchFinished();
+
+public Q_SLOTS:
+ // end the execution
+ void tryTerminate() const;
+ void kill() const;
+
+ // input
+ virtual void writeToStdin( const TQByteArray& buf );
+ virtual void writeToStdin( const TQString& buf );
+ virtual void closeStdin();
+
+protected: // ### or private?
+ void connectNotify( const char * signal );
+ void disconnectNotify( const char * signal );
+private:
+ void setIoRedirection( bool value );
+ void setNotifyOnExit( bool value );
+ void setWroteStdinConnected( bool value );
+
+ void init();
+ void reset();
+#if defined(TQ_OS_WIN32)
+ uint readStddev( HANDLE dev, char *buf, uint bytes );
+#endif
+ TQMembuf* membufStdout();
+ TQMembuf* membufStderr();
+
+private Q_SLOTS:
+ void socketRead( int fd );
+ void socketWrite( int fd );
+ void timeout();
+ void closeStdinLaunch();
+
+private:
+ TQProcessPrivate *d;
+#ifndef TQT_NO_DIR
+ TQDir workingDir;
+#endif
+ TQStringList _arguments;
+
+ int exitStat; // exit status
+ bool exitNormal; // normal exit?
+ bool ioRedirection; // automatically set be (dis)connectNotify
+ bool notifyOnExit; // automatically set be (dis)connectNotify
+ bool wroteToStdinConnected; // automatically set be (dis)connectNotify
+
+ bool readStdoutCalled;
+ bool readStderrCalled;
+ int comms;
+
+ friend class TQProcessPrivate;
+#if defined(TQ_OS_UNIX)
+ friend class TQProcessManager;
+ friend class TQProc;
+#endif
+
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQProcess( const TQProcess & );
+ TQProcess &operator=( const TQProcess & );
+#endif
+};
+
+#endif // TQT_NO_PROCESS
+
+#endif // TQPROCESS_H
diff --git a/tqtinterface/qt4/src/kernel/tqprocess_unix.cpp b/tqtinterface/qt4/src/kernel/tqprocess_unix.cpp
new file mode 100644
index 0000000..0895ae2
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqprocess_unix.cpp
@@ -0,0 +1,1410 @@
+/****************************************************************************
+**
+** Implementation of TQProcess class for Unix
+**
+** Created : 20000905
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+// Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED.
+#if defined(connect)
+#undef connect
+#endif
+
+#include "tqprocess.h"
+
+#ifndef TQT_NO_PROCESS
+
+#include "tqapplication.h"
+#include "tqptrqueue.h"
+#include "tqptrlist.h"
+#include "tqsocketnotifier.h"
+#include "tqtimer.h"
+#include "tqcleanuphandler.h"
+#include "tqregexp.h"
+#include "private/tqinternal_p.h"
+
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#ifdef __MIPSEL__
+# ifndef SOCK_DGRAM
+# define SOCK_DGRAM 1
+# endif
+# ifndef SOCK_STREAM
+# define SOCK_STREAM 2
+# endif
+#endif
+
+//#define TQT_TQPROCESS_DEBUG
+
+
+#ifdef TQ_C_CALLBACKS
+extern "C" {
+#endif // TQ_C_CALLBACKS
+
+ TQT_SIGNAL_RETTYPE qt_C_sigchldHnd(TQT_SIGNAL_ARGS);
+
+#ifdef TQ_C_CALLBACKS
+}
+#endif // TQ_C_CALLBACKS
+
+
+class TQProc;
+class TQProcessManager;
+class TQProcessPrivate
+{
+public:
+ TQProcessPrivate();
+ ~TQProcessPrivate();
+
+ void closeOpenSocketsForChild();
+ void newProc( pid_t pid, TQProcess *process );
+
+ TQMembuf bufStdout;
+ TQMembuf bufStderr;
+
+ TQPtrQueue<TQByteArray> stdinBuf;
+
+ TQSocketNotifier *notifierStdin;
+ TQSocketNotifier *notifierStdout;
+ TQSocketNotifier *notifierStderr;
+
+ ssize_t stdinBufRead;
+ TQProc *proc;
+
+ bool exitValuesCalculated;
+ bool socketReadCalled;
+
+ static TQProcessManager *procManager;
+};
+
+
+/***********************************************************************
+ *
+ * TQProc
+ *
+ **********************************************************************/
+/*
+ The class TQProcess does not necessarily map exactly to the running
+ child processes: if the process is finished, the TQProcess class may still be
+ there; furthermore a user can use TQProcess to start more than one process.
+
+ The helper-class TQProc has the semantics that one instance of this class maps
+ directly to a running child process.
+*/
+class TQProc
+{
+public:
+ TQProc( pid_t p, TQProcess *proc=0 ) : pid(p), process(proc)
+ {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProc: Constructor for pid %d and TQProcess %p", pid, process );
+#endif
+ socketStdin = 0;
+ socketStdout = 0;
+ socketStderr = 0;
+ }
+ ~TQProc()
+ {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProc: Destructor for pid %d and TQProcess %p", pid, process );
+#endif
+ if ( process ) {
+ if ( process->d->notifierStdin )
+ process->d->notifierStdin->setEnabled( FALSE );
+ if ( process->d->notifierStdout )
+ process->d->notifierStdout->setEnabled( FALSE );
+ if ( process->d->notifierStderr )
+ process->d->notifierStderr->setEnabled( FALSE );
+ process->d->proc = 0;
+ }
+ if( socketStdin )
+ ::close( socketStdin );
+ if( socketStdout )
+ ::close( socketStdout );
+ if( socketStderr )
+ ::close( socketStderr );
+ }
+
+ pid_t pid;
+ int socketStdin;
+ int socketStdout;
+ int socketStderr;
+ TQProcess *process;
+};
+
+/***********************************************************************
+ *
+ * TQProcessManager
+ *
+ **********************************************************************/
+class TQProcessManager : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ TQProcessManager();
+ ~TQProcessManager();
+
+ void append( TQProc *p );
+ void remove( TQProc *p );
+
+ void cleanup();
+
+public Q_SLOTS:
+ void removeMe();
+ void sigchldHnd( int );
+
+public:
+ struct sigaction oldactChld;
+ struct sigaction oldactPipe;
+ TQPtrList<TQProc> *procList;
+ int sigchldFd[2];
+
+private:
+ TQSocketNotifier *sn;
+};
+
+static void qprocess_cleanup()
+{
+ delete TQProcessPrivate::procManager;
+ TQProcessPrivate::procManager = 0;
+}
+
+#ifdef TQ_OS_TQNX6
+#define BAILOUT close(tmpSocket);close(socketFD[1]);return -1;
+int qnx6SocketPairReplacement (int socketFD[2]) {
+ int tmpSocket;
+ tmpSocket = socket (AF_INET, SOCK_STREAM, 0);
+ if (tmpSocket == -1)
+ return -1;
+ socketFD[1] = socket(AF_INET, SOCK_STREAM, 0);
+ if (socketFD[1] == -1) { BAILOUT };
+
+ sockaddr_in ipAddr;
+ memset(&ipAddr, 0, sizeof(ipAddr));
+ ipAddr.sin_family = AF_INET;
+ ipAddr.sin_addr.s_addr = INADDR_ANY;
+
+ int socketOptions = 1;
+ setsockopt(tmpSocket, SOL_SOCKET, SO_REUSEADDR, &socketOptions, sizeof(int));
+
+ bool found = FALSE;
+ for (int socketIP = 2000; (socketIP < 2500) && !(found); socketIP++) {
+ ipAddr.sin_port = htons(socketIP);
+ if (bind(tmpSocket, (struct sockaddr *)&ipAddr, sizeof(ipAddr)))
+ found = TRUE;
+ }
+
+ if (listen(tmpSocket, 5)) { BAILOUT };
+
+ // Select non-blocking mode
+ int originalFlags = fcntl(socketFD[1], F_GETFL, 0);
+ fcntl(socketFD[1], F_SETFL, originalFlags | O_NONBLOCK);
+
+ // Request connection
+ if (connect(socketFD[1], (struct sockaddr*)&ipAddr, sizeof(ipAddr)))
+ if (errno != EINPROGRESS) { BAILOUT };
+
+ // Accept connection
+ socketFD[0] = accept(tmpSocket, (struct sockaddr *)NULL, (size_t *)NULL);
+ if(socketFD[0] == -1) { BAILOUT };
+
+ // We're done
+ close(tmpSocket);
+
+ // Restore original flags , ie return to blocking
+ fcntl(socketFD[1], F_SETFL, originalFlags);
+ return 0;
+}
+#undef BAILOUT
+#endif
+
+TQProcessManager::TQProcessManager() : sn(0)
+{
+ procList = new TQPtrList<TQProc>;
+ procList->setAutoDelete( TRUE );
+
+ // The SIGCHLD handler writes to a socket to tell the manager that
+ // something happened. This is done to get the processing in sync with the
+ // event reporting.
+#ifndef TQ_OS_TQNX6
+ if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) {
+#else
+ if ( qnx6SocketPairReplacement (sigchldFd) ) {
+#endif
+ sigchldFd[0] = 0;
+ sigchldFd[1] = 0;
+ } else {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager: install socket notifier (%d)", sigchldFd[1] );
+#endif
+ sn = new TQSocketNotifier( sigchldFd[1],
+ TQSocketNotifier::Read, this );
+ connect( sn, TQT_SIGNAL(activated(int)),
+ this, TQT_SLOT(sigchldHnd(int)) );
+ sn->setEnabled( TRUE );
+ }
+
+ // install a SIGCHLD handler and ignore SIGPIPE
+ struct sigaction act;
+
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager: install a SIGCHLD handler" );
+#endif
+ act.sa_handler = qt_C_sigchldHnd;
+ sigemptyset( &(act.sa_mask) );
+ sigaddset( &(act.sa_mask), SIGCHLD );
+ act.sa_flags = SA_NOCLDSTOP;
+#if defined(SA_RESTART)
+ act.sa_flags |= SA_RESTART;
+#endif
+ if ( sigaction( SIGCHLD, &act, &oldactChld ) != 0 )
+ qWarning( "Error installing SIGCHLD handler" );
+
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager: install a SIGPIPE handler (SIG_IGN)" );
+#endif
+ act.sa_handler = TQT_SIGNAL_IGNORE;
+ sigemptyset( &(act.sa_mask) );
+ sigaddset( &(act.sa_mask), SIGPIPE );
+ act.sa_flags = 0;
+ if ( sigaction( SIGPIPE, &act, &oldactPipe ) != 0 )
+ qWarning( "Error installing SIGPIPE handler" );
+}
+
+TQProcessManager::~TQProcessManager()
+{
+ delete procList;
+
+ if ( sigchldFd[0] != 0 )
+ ::close( sigchldFd[0] );
+ if ( sigchldFd[1] != 0 )
+ ::close( sigchldFd[1] );
+
+ // restore SIGCHLD handler
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager: restore old sigchild handler" );
+#endif
+ if ( sigaction( SIGCHLD, &oldactChld, 0 ) != 0 )
+ qWarning( "Error restoring SIGCHLD handler" );
+
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager: restore old sigpipe handler" );
+#endif
+ if ( sigaction( SIGPIPE, &oldactPipe, 0 ) != 0 )
+ qWarning( "Error restoring SIGPIPE handler" );
+}
+
+void TQProcessManager::append( TQProc *p )
+{
+ procList->append( p );
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager: append process (procList.count(): %d)", procList->count() );
+#endif
+}
+
+void TQProcessManager::remove( TQProc *p )
+{
+ procList->remove( p );
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager: remove process (procList.count(): %d)", procList->count() );
+#endif
+ cleanup();
+}
+
+void TQProcessManager::cleanup()
+{
+ if ( procList->count() == 0 ) {
+ TQTimer::singleShot( 0, this, TQT_SLOT(removeMe()) );
+ }
+}
+
+void TQProcessManager::removeMe()
+{
+ if ( procList->count() == 0 ) {
+ qRemovePostRoutine(qprocess_cleanup);
+ TQProcessPrivate::procManager = 0;
+ delete this;
+ }
+}
+
+void TQProcessManager::sigchldHnd( int fd )
+{
+ // Disable the socket notifier to make sure that this function is not
+ // called recursively -- this can happen, if you enter the event loop in
+ // the slot connected to the processExited() signal (e.g. by showing a
+ // modal dialog) and there are more than one process which exited in the
+ // meantime.
+ if ( sn ) {
+ if ( !sn->isEnabled() )
+ return;
+ sn->setEnabled( FALSE );
+ }
+
+ char tmp;
+ ::read( fd, &tmp, sizeof(tmp) );
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager::sigchldHnd()" );
+#endif
+ TQProc *proc;
+ TQProcess *process;
+ bool removeProc;
+ proc = procList->first();
+ while ( proc != 0 ) {
+ removeProc = FALSE;
+ process = proc->process;
+ if ( process != 0 ) {
+ if ( !process->isRunning() ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager::sigchldHnd() (PID: %d): process exited (TQProcess available)", proc->pid );
+#endif
+ /*
+ Apparently, there is not consistency among different
+ operating systems on how to use FIONREAD.
+
+ FreeBSD, Linux and Solaris all expect the 3rd
+ argument to ioctl() to be an int, which is normally
+ 32-bit even on 64-bit machines.
+
+ IRIX, on the other hand, expects a size_t, which is
+ 64-bit on 64-bit machines.
+
+ So, the solution is to use size_t initialized to
+ zero to make sure all bits are set to zero,
+ preventing underflow with the FreeBSD/Linux/Solaris
+ ioctls.
+ */
+ size_t nbytes = 0;
+ // read pending data
+ if ( proc->socketStdout && ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager::sigchldHnd() (PID: %d): reading %d bytes of pending data on stdout", proc->pid, nbytes );
+#endif
+ process->socketRead( proc->socketStdout );
+ }
+ nbytes = 0;
+ if ( proc->socketStderr && ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager::sigchldHnd() (PID: %d): reading %d bytes of pending data on stderr", proc->pid, nbytes );
+#endif
+ process->socketRead( proc->socketStderr );
+ }
+ // close filedescriptors if open, and disable the
+ // socket notifiers
+ if ( proc->socketStdout ) {
+ ::close( proc->socketStdout );
+ proc->socketStdout = 0;
+ if (process->d->notifierStdout)
+ process->d->notifierStdout->setEnabled(FALSE);
+ }
+ if ( proc->socketStderr ) {
+ ::close( proc->socketStderr );
+ proc->socketStderr = 0;
+ if (process->d->notifierStderr)
+ process->d->notifierStderr->setEnabled(FALSE);
+ }
+
+ if ( process->notifyOnExit )
+ emit process->processExited();
+
+ removeProc = TRUE;
+ }
+ } else {
+ int status;
+ if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessManager::sigchldHnd() (PID: %d): process exited (TQProcess not available)", proc->pid );
+#endif
+ removeProc = TRUE;
+ }
+ }
+ if ( removeProc ) {
+ TQProc *oldproc = proc;
+ proc = procList->next();
+ remove( oldproc );
+ } else {
+ proc = procList->next();
+ }
+ }
+ if ( sn )
+ sn->setEnabled( TRUE );
+}
+
+#include "tqprocess_unix.tqmoc"
+
+
+/***********************************************************************
+ *
+ * TQProcessPrivate
+ *
+ **********************************************************************/
+TQProcessManager *TQProcessPrivate::procManager = 0;
+
+TQProcessPrivate::TQProcessPrivate()
+{
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessPrivate: Constructor" );
+#endif
+ stdinBufRead = 0;
+
+ notifierStdin = 0;
+ notifierStdout = 0;
+ notifierStderr = 0;
+
+ exitValuesCalculated = FALSE;
+ socketReadCalled = FALSE;
+
+ proc = 0;
+}
+
+TQProcessPrivate::~TQProcessPrivate()
+{
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcessPrivate: Destructor" );
+#endif
+
+ if ( proc != 0 ) {
+ if ( proc->socketStdin != 0 ) {
+ ::close( proc->socketStdin );
+ proc->socketStdin = 0;
+ }
+ proc->process = 0;
+ }
+
+ while ( !stdinBuf.isEmpty() ) {
+ delete stdinBuf.dequeue();
+ }
+ delete notifierStdin;
+ delete notifierStdout;
+ delete notifierStderr;
+}
+
+/*
+ Closes all open sockets in the child process that are not needed by the child
+ process. Otherwise one child may have an open socket on standard input, etc.
+ of another child.
+*/
+void TQProcessPrivate::closeOpenSocketsForChild()
+{
+ if ( procManager != 0 ) {
+ if ( procManager->sigchldFd[0] != 0 )
+ ::close( procManager->sigchldFd[0] );
+ if ( procManager->sigchldFd[1] != 0 )
+ ::close( procManager->sigchldFd[1] );
+
+ // close also the sockets from other TQProcess instances
+ for ( TQProc *p=procManager->procList->first(); p!=0; p=procManager->procList->next() ) {
+ ::close( p->socketStdin );
+ ::close( p->socketStdout );
+ ::close( p->socketStderr );
+ }
+ }
+}
+
+void TQProcessPrivate::newProc( pid_t pid, TQProcess *process )
+{
+ proc = new TQProc( pid, process );
+ if ( procManager == 0 ) {
+ procManager = new TQProcessManager;
+ qAddPostRoutine(qprocess_cleanup);
+ }
+ // the TQProcessManager takes care of deleting the TQProc instances
+ procManager->append( proc );
+}
+
+/***********************************************************************
+ *
+ * sigchld handler callback
+ *
+ **********************************************************************/
+TQT_SIGNAL_RETTYPE qt_C_sigchldHnd( TQT_SIGNAL_ARGS )
+{
+ if ( TQProcessPrivate::procManager == 0 )
+ return;
+ if ( TQProcessPrivate::procManager->sigchldFd[0] == 0 )
+ return;
+
+ char a = 1;
+ ::write( TQProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) );
+}
+
+
+/***********************************************************************
+ *
+ * TQProcess
+ *
+ **********************************************************************/
+/*
+ This private class does basic initialization.
+*/
+void TQProcess::init()
+{
+ d = new TQProcessPrivate();
+ exitStat = 0;
+ exitNormal = FALSE;
+}
+
+/*
+ This private class resets the process variables, etc. so that it can be used
+ for another process to start.
+*/
+void TQProcess::reset()
+{
+ delete d;
+ d = new TQProcessPrivate();
+ exitStat = 0;
+ exitNormal = FALSE;
+ d->bufStdout.clear();
+ d->bufStderr.clear();
+}
+
+TQMembuf* TQProcess::membufStdout()
+{
+ if ( d->proc && d->proc->socketStdout ) {
+ /*
+ Apparently, there is not consistency among different
+ operating systems on how to use FIONREAD.
+
+ FreeBSD, Linux and Solaris all expect the 3rd argument to
+ ioctl() to be an int, which is normally 32-bit even on
+ 64-bit machines.
+
+ IRIX, on the other hand, expects a size_t, which is 64-bit
+ on 64-bit machines.
+
+ So, the solution is to use size_t initialized to zero to
+ make sure all bits are set to zero, preventing underflow
+ with the FreeBSD/Linux/Solaris ioctls.
+ */
+ size_t nbytes = 0;
+ if ( ::ioctl(d->proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 )
+ socketRead( d->proc->socketStdout );
+ }
+ return &d->bufStdout;
+}
+
+TQMembuf* TQProcess::membufStderr()
+{
+ if ( d->proc && d->proc->socketStderr ) {
+ /*
+ Apparently, there is not consistency among different
+ operating systems on how to use FIONREAD.
+
+ FreeBSD, Linux and Solaris all expect the 3rd argument to
+ ioctl() to be an int, which is normally 32-bit even on
+ 64-bit machines.
+
+ IRIX, on the other hand, expects a size_t, which is 64-bit
+ on 64-bit machines.
+
+ So, the solution is to use size_t initialized to zero to
+ make sure all bits are set to zero, preventing underflow
+ with the FreeBSD/Linux/Solaris ioctls.
+ */
+ size_t nbytes = 0;
+ if ( ::ioctl(d->proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 )
+ socketRead( d->proc->socketStderr );
+ }
+ return &d->bufStderr;
+}
+
+/*!
+ Destroys the instance.
+
+ If the process is running, it is <b>not</b> terminated! The
+ standard input, standard output and standard error of the process
+ are closed.
+
+ You can connect the destroyed() signal to the kill() slot, if you
+ want the process to be terminated automatically when the instance
+ is destroyed.
+
+ \sa tryTerminate() kill()
+*/
+TQProcess::~TQProcess()
+{
+ delete d;
+}
+
+/*!
+ Tries to run a process for the command and arguments that were
+ specified with setArguments(), addArgument() or that were
+ specified in the constructor. The command is searched for in the
+ path for executable programs; you can also use an absolute path in
+ the command itself.
+
+ If \a env is null, then the process is started with the same
+ environment as the starting process. If \a env is non-null, then
+ the values in the stringlist are interpreted as environment
+ setttings of the form \c {key=value} and the process is started in
+ these environment settings. For convenience, there is a small
+ exception to this rule: under Unix, if \a env does not contain any
+ settings for the environment variable \c LD_LIBRARY_PATH, then
+ this variable is inherited from the starting process; under
+ Windows the same applies for the environment variable \c PATH.
+
+ Returns TRUE if the process could be started; otherwise returns
+ FALSE.
+
+ You can write data to the process's standard input with
+ writeToStdin(). You can close standard input with closeStdin() and
+ you can terminate the process with tryTerminate(), or with kill().
+
+ You can call this function even if you've used this instance to
+ create a another process which is still running. In such cases,
+ TQProcess closes the old process's standard input and deletes
+ pending data, i.e., you lose all control over the old process, but
+ the old process is not terminated. This applies also if the
+ process could not be started. (On operating systems that have
+ zombie processes, TQt will also wait() on the old process.)
+
+ \sa launch() closeStdin()
+*/
+bool TQProcess::start( TQStringList *env )
+{
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::start()" );
+#endif
+ reset();
+
+ int sStdin[2];
+ int sStdout[2];
+ int sStderr[2];
+
+ // open sockets for piping
+#ifndef TQ_OS_TQNX6
+ if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) {
+#else
+ if ( (comms & Stdin) && qnx6SocketPairReplacement(sStdin) == -1 ) {
+#endif
+ return FALSE;
+ }
+#ifndef TQ_OS_TQNX6
+ if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) {
+#else
+ if ( (comms & Stderr) && qnx6SocketPairReplacement(sStderr) == -1 ) {
+#endif
+ if ( comms & Stdin ) {
+ ::close( sStdin[0] );
+ ::close( sStdin[1] );
+ }
+ return FALSE;
+ }
+#ifndef TQ_OS_TQNX6
+ if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) {
+#else
+ if ( (comms & Stdout) && qnx6SocketPairReplacement(sStdout) == -1 ) {
+#endif
+ if ( comms & Stdin ) {
+ ::close( sStdin[0] );
+ ::close( sStdin[1] );
+ }
+ if ( comms & Stderr ) {
+ ::close( sStderr[0] );
+ ::close( sStderr[1] );
+ }
+ return FALSE;
+ }
+
+ // the following pipe is only used to determine if the process could be
+ // started
+ int fd[2];
+ if ( pipe( fd ) < 0 ) {
+ // non critical error, go on
+ fd[0] = 0;
+ fd[1] = 0;
+ }
+
+ // construct the arguments for exec
+ TQCString *arglistQ = new TQCString[ _arguments.count() + 1 ];
+ const char** arglist = new const char*[ _arguments.count() + 1 ];
+ int i = 0;
+ for ( TQStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) {
+ arglistQ[i] = (*it).local8Bit();
+ arglist[i] = arglistQ[i];
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::start(): arg %d = %s", i, arglist[i] );
+#endif
+ i++;
+ }
+#ifdef TQ_OS_MACX
+ if(i) {
+ TQCString arg_bundle = arglistQ[0];
+ TQFileInfo fi(arg_bundle);
+ if(fi.exists() && fi.isDir() && arg_bundle.right(4) == ".app") {
+ TQCString exe = arg_bundle;
+ int lslash = exe.tqfindRev('/');
+ if(lslash != -1)
+ exe = exe.mid(lslash+1);
+ exe = TQCString(arg_bundle + "/Contents/MacOS/" + exe);
+ exe = exe.left(exe.length() - 4); //chop off the .app
+ if(TQFile::exists(exe)) {
+ arglistQ[0] = exe;
+ arglist[0] = arglistQ[0];
+ }
+ }
+ }
+#endif
+ arglist[i] = 0;
+
+ // Must make sure signal handlers are installed before exec'ing
+ // in case the process exits quickly.
+ if ( d->procManager == 0 ) {
+ d->procManager = new TQProcessManager;
+ qAddPostRoutine(qprocess_cleanup);
+ }
+
+ // fork and exec
+ TQApplication::flushX();
+ pid_t pid = fork();
+ if ( pid == 0 ) {
+ // child
+ d->closeOpenSocketsForChild();
+ if ( comms & Stdin ) {
+ ::close( sStdin[1] );
+ ::dup2( sStdin[0], STDIN_FILENO );
+ }
+ if ( comms & Stdout ) {
+ ::close( sStdout[0] );
+ ::dup2( sStdout[1], STDOUT_FILENO );
+ }
+ if ( comms & Stderr ) {
+ ::close( sStderr[0] );
+ ::dup2( sStderr[1], STDERR_FILENO );
+ }
+ if ( comms & DupStderr ) {
+ ::dup2( STDOUT_FILENO, STDERR_FILENO );
+ }
+#ifndef TQT_NO_DIR
+ ::chdir( workingDir.absPath().latin1() );
+#endif
+ if ( fd[0] )
+ ::close( fd[0] );
+ if ( fd[1] )
+ ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess
+
+ if ( env == 0 ) { // inherit environment and start process
+#ifndef TQ_OS_TQNX4
+ ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice
+#else
+ ::execvp( arglist[0], (char const*const*)arglist ); // ### cast not nice
+#endif
+ } else { // start process with environment settins as specified in env
+ // construct the environment for exec
+ int numEntries = env->count();
+#if defined(TQ_OS_MACX)
+ TQString ld_library_path("DYLD_LIBRARY_PATH");
+#else
+ TQString ld_library_path("LD_LIBRARY_PATH");
+#endif
+ bool setLibraryPath =
+ env->grep( TQRegExp( "^" + ld_library_path + "=" ) ).empty() &&
+ getenv( ld_library_path ) != 0;
+ if ( setLibraryPath )
+ numEntries++;
+ TQCString *envlistQ = new TQCString[ numEntries + 1 ];
+ const char** envlist = new const char*[ numEntries + 1 ];
+ int i = 0;
+ if ( setLibraryPath ) {
+ envlistQ[i] = TQT_TQSTRING(TQString( ld_library_path + "=%1" ).arg( getenv( ld_library_path ) )).local8Bit();
+ envlist[i] = envlistQ[i];
+ i++;
+ }
+ for ( TQStringList::Iterator it = env->begin(); it != env->end(); ++it ) {
+ envlistQ[i] = (*it).local8Bit();
+ envlist[i] = envlistQ[i];
+ i++;
+ }
+ envlist[i] = 0;
+
+ // look for the executable in the search path
+ if ( _arguments.count()>0 && getenv("PATH")!=0 ) {
+ TQString command = _arguments[0];
+ if ( !command.tqcontains( '/' ) ) {
+ TQStringList pathList = TQStringList::split( ':', getenv( "PATH" ) );
+ for (TQStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it ) {
+ TQString dir = *it;
+#if defined(TQ_OS_MACX) //look in a bundle
+ if(!TQFile::exists(dir + "/" + command) && TQFile::exists(dir + "/" + command + ".app"))
+ dir += "/" + command + ".app/Contents/MacOS";
+#endif
+#ifndef TQT_NO_DIR
+ TQFileInfo fileInfo( dir, command );
+#else
+ TQFileInfo fileInfo( dir + "/" + command );
+#endif
+ if ( fileInfo.isExecutable() ) {
+#if defined(TQ_OS_MACX)
+ arglistQ[0] = fileInfo.absFilePath().local8Bit();
+#else
+ arglistQ[0] = fileInfo.filePath().local8Bit();
+#endif
+ arglist[0] = arglistQ[0];
+ break;
+ }
+ }
+ }
+ }
+#ifndef TQ_OS_TQNX4
+ ::execve( arglist[0], (char*const*)arglist, (char*const*)envlist ); // ### casts not nice
+#else
+ ::execve( arglist[0], (char const*const*)arglist,(char const*const*)envlist ); // ### casts not nice
+#endif
+ }
+ if ( fd[1] ) {
+ char buf = 0;
+ ::write( fd[1], &buf, 1 );
+ ::close( fd[1] );
+ }
+ ::_exit( -1 );
+ } else if ( pid == -1 ) {
+ // error forking
+ goto error;
+ }
+
+ // test if exec was successful
+ if ( fd[1] )
+ ::close( fd[1] );
+ if ( fd[0] ) {
+ char buf;
+ for ( ;; ) {
+ int n = ::read( fd[0], &buf, 1 );
+ if ( n==1 ) {
+ // socket was not closed => error
+ if ( ::waitpid( pid, 0, WNOHANG ) != pid ) {
+ // The wait did not succeed yet, so try again when we get
+ // the sigchild (to avoid zombies).
+ d->newProc( pid, 0 );
+ }
+ d->proc = 0;
+ goto error;
+ } else if ( n==-1 ) {
+ if ( errno==EAGAIN || errno==EINTR )
+ // try it again
+ continue;
+ }
+ break;
+ }
+ ::close( fd[0] );
+ }
+
+ d->newProc( pid, this );
+
+ if ( comms & Stdin ) {
+ ::close( sStdin[0] );
+ d->proc->socketStdin = sStdin[1];
+
+ // Select non-blocking mode
+ int originalFlags = fcntl(d->proc->socketStdin, F_GETFL, 0);
+ fcntl(d->proc->socketStdin, F_SETFL, originalFlags | O_NONBLOCK);
+
+ d->notifierStdin = new TQSocketNotifier( sStdin[1], TQSocketNotifier::Write );
+ connect( d->notifierStdin, TQT_SIGNAL(activated(int)),
+ this, TQT_SLOT(socketWrite(int)) );
+ // setup notifiers for the sockets
+ if ( !d->stdinBuf.isEmpty() ) {
+ d->notifierStdin->setEnabled( TRUE );
+ }
+ }
+ if ( comms & Stdout ) {
+ ::close( sStdout[1] );
+ d->proc->socketStdout = sStdout[0];
+ d->notifierStdout = new TQSocketNotifier( sStdout[0], TQSocketNotifier::Read );
+ connect( d->notifierStdout, TQT_SIGNAL(activated(int)),
+ this, TQT_SLOT(socketRead(int)) );
+ if ( ioRedirection )
+ d->notifierStdout->setEnabled( TRUE );
+ }
+ if ( comms & Stderr ) {
+ ::close( sStderr[1] );
+ d->proc->socketStderr = sStderr[0];
+ d->notifierStderr = new TQSocketNotifier( sStderr[0], TQSocketNotifier::Read );
+ connect( d->notifierStderr, TQT_SIGNAL(activated(int)),
+ this, TQT_SLOT(socketRead(int)) );
+ if ( ioRedirection )
+ d->notifierStderr->setEnabled( TRUE );
+ }
+
+ // cleanup and return
+ delete[] arglistQ;
+ delete[] arglist;
+ return TRUE;
+
+error:
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::start(): error starting process" );
+#endif
+ if ( d->procManager )
+ d->procManager->cleanup();
+ if ( comms & Stdin ) {
+ ::close( sStdin[1] );
+ ::close( sStdin[0] );
+ }
+ if ( comms & Stdout ) {
+ ::close( sStdout[0] );
+ ::close( sStdout[1] );
+ }
+ if ( comms & Stderr ) {
+ ::close( sStderr[0] );
+ ::close( sStderr[1] );
+ }
+ ::close( fd[0] );
+ ::close( fd[1] );
+ delete[] arglistQ;
+ delete[] arglist;
+ return FALSE;
+}
+
+
+/*!
+ Asks the process to terminate. Processes can ignore this if they
+ wish. If you want to be certain that the process really
+ terminates, you can use kill() instead.
+
+ The slot returns immediately: it does not wait until the process
+ has finished. When the process terminates, the processExited()
+ signal is emitted.
+
+ \sa kill() processExited()
+*/
+void TQProcess::tryTerminate() const
+{
+ if ( d->proc != 0 )
+ ::kill( d->proc->pid, SIGTERM );
+}
+
+/*!
+ Terminates the process. This is not a safe way to end a process
+ since the process will not be able to do any cleanup.
+ tryTerminate() is safer, but processes can ignore a
+ tryTerminate().
+
+ The nice way to end a process and to be sure that it is finished,
+ is to do something like this:
+ \code
+ process->tryTerminate();
+ TQTimer::singleShot( 5000, process, TQT_SLOT( kill() ) );
+ \endcode
+
+ This tries to terminate the process the nice way. If the process
+ is still running after 5 seconds, it terminates the process the
+ hard way. The timeout should be chosen depending on the time the
+ process needs to do all its cleanup: use a higher value if the
+ process is likely to do a lot of computation or I/O on cleanup.
+
+ The slot returns immediately: it does not wait until the process
+ has finished. When the process terminates, the processExited()
+ signal is emitted.
+
+ \sa tryTerminate() processExited()
+*/
+void TQProcess::kill() const
+{
+ if ( d->proc != 0 )
+ ::kill( d->proc->pid, SIGKILL );
+}
+
+/*!
+ Returns TRUE if the process is running; otherwise returns FALSE.
+
+ \sa normalExit() exitqStatus() processExited()
+*/
+bool TQProcess::isRunning() const
+{
+ if ( d->exitValuesCalculated ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::isRunning(): FALSE (already computed)" );
+#endif
+ return FALSE;
+ }
+ if ( d->proc == 0 )
+ return FALSE;
+ int status;
+ if ( ::waitpid( d->proc->pid, &status, WNOHANG ) == d->proc->pid ) {
+ // compute the exit values
+ TQProcess *that = (TQProcess*)this; // mutable
+ that->exitNormal = WIFEXITED( status ) != 0;
+ if ( exitNormal ) {
+ that->exitStat = (char)WEXITSTATUS( status );
+ }
+ d->exitValuesCalculated = TRUE;
+
+ // On heavy processing, the socket notifier for the sigchild might not
+ // have found time to fire yet.
+ if ( d->procManager && d->procManager->sigchldFd[1] < FD_SETSIZE ) {
+ fd_set fds;
+ struct timeval tv;
+ FD_ZERO( &fds );
+ FD_SET( d->procManager->sigchldFd[1], &fds );
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ if ( ::select( d->procManager->sigchldFd[1]+1, &fds, 0, 0, &tv ) > 0 )
+ d->procManager->sigchldHnd( d->procManager->sigchldFd[1] );
+ }
+
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::isRunning() (PID: %d): FALSE", d->proc->pid );
+#endif
+ return FALSE;
+ }
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::isRunning() (PID: %d): TRUE", d->proc->pid );
+#endif
+ return TRUE;
+}
+
+/*!
+ Returns TRUE if it's possible to read an entire line of text from
+ standard output at this time; otherwise returns FALSE.
+
+ \sa readLineStdout() canReadLineStderr()
+*/
+bool TQProcess::canReadLineStdout() const
+{
+ if ( !d->proc || !d->proc->socketStdout )
+ return d->bufStdout.size() != 0;
+
+ TQProcess *that = (TQProcess*)this;
+ return that->membufStdout()->scanNewline( 0 );
+}
+
+/*!
+ Returns TRUE if it's possible to read an entire line of text from
+ standard error at this time; otherwise returns FALSE.
+
+ \sa readLineStderr() canReadLineStdout()
+*/
+bool TQProcess::canReadLineStderr() const
+{
+ if ( !d->proc || !d->proc->socketStderr )
+ return d->bufStderr.size() != 0;
+
+ TQProcess *that = (TQProcess*)this;
+ return that->membufStderr()->scanNewline( 0 );
+}
+
+/*!
+ Writes the data \a buf to the process's standard input. The
+ process may or may not read this data.
+
+ This function always returns immediately. The data you
+ pass to writeToStdin() is copied into an internal memory buffer in
+ TQProcess, and when control goes back to the event loop, TQProcess will
+ starting transferring data from this buffer to the running process. �
+ Sometimes the data will be transferred in several payloads, depending on
+ how much data is read at a time by the process itself. When TQProcess has
+ transferred all the data from its memory buffer to the running process, it
+ emits wroteToStdin().
+
+ Note that some operating systems use a buffer to transfer
+ the data. As a result, wroteToStdin() may be emitted before the
+ running process has actually read all the data.
+
+ \sa wroteToStdin() closeStdin() readStdout() readStderr()
+*/
+void TQProcess::writeToStdin( const TQByteArray& buf )
+{
+#if defined(TQT_TQPROCESS_DEBUG)
+// qDebug( "TQProcess::writeToStdin(): write to stdin (%d)", d->socketStdin );
+#endif
+ d->stdinBuf.enqueue( new TQByteArray(buf) );
+ if ( d->notifierStdin != 0 )
+ d->notifierStdin->setEnabled( TRUE );
+}
+
+
+/*!
+ Closes the process's standard input.
+
+ This function also deletes any pending data that has not been
+ written to standard input.
+
+ \sa wroteToStdin()
+*/
+void TQProcess::closeStdin()
+{
+ if ( d->proc == 0 )
+ return;
+ if ( d->proc->socketStdin !=0 ) {
+ while ( !d->stdinBuf.isEmpty() ) {
+ delete d->stdinBuf.dequeue();
+ }
+ delete d->notifierStdin;
+ d->notifierStdin = 0;
+ if ( ::close( d->proc->socketStdin ) != 0 ) {
+ qWarning( "Could not close stdin of child process" );
+ }
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::closeStdin(): stdin (%d) closed", d->proc->socketStdin );
+#endif
+ d->proc->socketStdin = 0;
+ }
+}
+
+
+/*
+ This private slot is called when the process has outputted data to either
+ standard output or standard error.
+*/
+void TQProcess::socketRead( int fd )
+{
+ if ( d->socketReadCalled ) {
+ // the Q_SLOTS that are connected to the readyRead...() Q_SIGNALS might
+ // trigger a recursive call of socketRead(). Avoid this since you get a
+ // blocking read otherwise.
+ return;
+ }
+
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::socketRead(): %d", fd );
+#endif
+ if ( fd == 0 )
+ return;
+ if ( !d->proc )
+ return;
+ TQMembuf *buffer = 0;
+ int n;
+ if ( fd == d->proc->socketStdout ) {
+ buffer = &d->bufStdout;
+ } else if ( fd == d->proc->socketStderr ) {
+ buffer = &d->bufStderr;
+ } else {
+ // this case should never happen, but just to be safe
+ return;
+ }
+#if defined(TQT_TQPROCESS_DEBUG)
+ uint oldSize = buffer->size();
+#endif
+
+ // try to read data first (if it fails, the filedescriptor was closed)
+ const int basize = 4096;
+ TQByteArray *ba = new TQByteArray( basize );
+ n = ::read( fd, ba->data(), basize );
+ if ( n > 0 ) {
+ ba->resize( n );
+ buffer->append( ba );
+ ba = 0;
+ } else {
+ delete ba;
+ ba = 0;
+ }
+ // eof or error?
+ if ( n == 0 || n == -1 ) {
+ if ( fd == d->proc->socketStdout ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::socketRead(): stdout (%d) closed", fd );
+#endif
+ d->notifierStdout->setEnabled( FALSE );
+ delete d->notifierStdout;
+ d->notifierStdout = 0;
+ ::close( d->proc->socketStdout );
+ d->proc->socketStdout = 0;
+ return;
+ } else if ( fd == d->proc->socketStderr ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::socketRead(): stderr (%d) closed", fd );
+#endif
+ d->notifierStderr->setEnabled( FALSE );
+ delete d->notifierStderr;
+ d->notifierStderr = 0;
+ ::close( d->proc->socketStderr );
+ d->proc->socketStderr = 0;
+ return;
+ }
+ }
+
+ if ( fd < FD_SETSIZE ) {
+ fd_set fds;
+ struct timeval tv;
+ FD_ZERO( &fds );
+ FD_SET( fd, &fds );
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ while ( ::select( fd+1, &fds, 0, 0, &tv ) > 0 ) {
+ // prepare for the next round
+ FD_ZERO( &fds );
+ FD_SET( fd, &fds );
+ // read data
+ ba = new TQByteArray( basize );
+ n = ::read( fd, ba->data(), basize );
+ if ( n > 0 ) {
+ ba->resize( n );
+ buffer->append( ba );
+ ba = 0;
+ } else {
+ delete ba;
+ ba = 0;
+ break;
+ }
+ }
+ }
+
+ d->socketReadCalled = TRUE;
+ if ( fd == d->proc->socketStdout ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::socketRead(): %d bytes read from stdout (%d)",
+ buffer->size()-oldSize, fd );
+#endif
+ emit readyReadStdout();
+ } else if ( fd == d->proc->socketStderr ) {
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::socketRead(): %d bytes read from stderr (%d)",
+ buffer->size()-oldSize, fd );
+#endif
+ emit readyReadStderr();
+ }
+ d->socketReadCalled = FALSE;
+}
+
+
+/*
+ This private slot is called when the process tries to read data from standard
+ input.
+*/
+void TQProcess::socketWrite( int fd )
+{
+ while ( fd == d->proc->socketStdin && d->proc->socketStdin != 0 ) {
+ if ( d->stdinBuf.isEmpty() ) {
+ d->notifierStdin->setEnabled( FALSE );
+ return;
+ }
+ ssize_t ret = ::write( fd,
+ d->stdinBuf.head()->data() + d->stdinBufRead,
+ d->stdinBuf.head()->size() - d->stdinBufRead );
+#if defined(TQT_TQPROCESS_DEBUG)
+ qDebug( "TQProcess::socketWrite(): wrote %d bytes to stdin (%d)", ret, fd );
+#endif
+ if ( ret == -1 )
+ return;
+ d->stdinBufRead += ret;
+ if ( d->stdinBufRead == (ssize_t)d->stdinBuf.head()->size() ) {
+ d->stdinBufRead = 0;
+ delete d->stdinBuf.dequeue();
+ if ( wroteToStdinConnected && d->stdinBuf.isEmpty() )
+ emit wroteToStdin();
+ }
+ }
+}
+
+/*!
+ \internal
+ Flushes standard input. This is useful if you want to use TQProcess in a
+ synchronous manner.
+
+ This function should probably go into the public API.
+*/
+void TQProcess::flushStdin()
+{
+ if (d->proc)
+ socketWrite(d->proc->socketStdin);
+}
+
+/*
+ This private slot is only used under Windows (but tqmoc does not know about #if
+ defined()).
+*/
+void TQProcess::timeout()
+{
+}
+
+
+/*
+ This private function is used by connectNotify() and disconnectNotify() to
+ change the value of ioRedirection (and related behaviour)
+*/
+void TQProcess::setIoRedirection( bool value )
+{
+ ioRedirection = value;
+ if ( ioRedirection ) {
+ if ( d->notifierStdout )
+ d->notifierStdout->setEnabled( TRUE );
+ if ( d->notifierStderr )
+ d->notifierStderr->setEnabled( TRUE );
+ } else {
+ if ( d->notifierStdout )
+ d->notifierStdout->setEnabled( FALSE );
+ if ( d->notifierStderr )
+ d->notifierStderr->setEnabled( FALSE );
+ }
+}
+
+/*
+ This private function is used by connectNotify() and
+ disconnectNotify() to change the value of notifyOnExit (and related
+ behaviour)
+*/
+void TQProcess::setNotifyOnExit( bool value )
+{
+ notifyOnExit = value;
+}
+
+/*
+ This private function is used by connectNotify() and disconnectNotify() to
+ change the value of wroteToStdinConnected (and related behaviour)
+*/
+void TQProcess::setWroteStdinConnected( bool value )
+{
+ wroteToStdinConnected = value;
+}
+
+/*! \enum TQProcess::PID
+ \internal
+*/
+/*!
+ Returns platform dependent information about the process. This can
+ be used together with platform specific system calls.
+
+ Under Unix the return value is the PID of the process, or -1 if no
+ process belongs to this object.
+
+ Under Windows it is a pointer to the \c PROCESS_INFORMATION
+ struct, or 0 if no process is belongs to this object.
+
+ Use of this function's return value is likely to be non-portable.
+*/
+TQProcess::PID TQProcess::processIdentifier()
+{
+ if ( d->proc == 0 )
+ return -1;
+ return d->proc->pid;
+}
+
+#endif // TQT_NO_PROCESS
diff --git a/tqtinterface/qt4/src/kernel/tqpsprinter.cpp b/tqtinterface/qt4/src/kernel/tqpsprinter.cpp
new file mode 100644
index 0000000..18227cf
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpsprinter.cpp
@@ -0,0 +1,6595 @@
+/**********************************************************************
+**
+** Implementation of TQPSPrinter class
+**
+** Created : 941003
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+// POSIX Large File Support redefines open -> open64
+#if defined(open)
+# undef open
+#endif
+
+// POSIX Large File Support redefines truncate -> truncate64
+#if defined(truncate)
+# undef truncate
+#endif
+
+#include "tqpsprinter_p.h"
+
+#ifdef USE_QT4
+
+static bool qt_gen_epsf = FALSE;
+
+TQ_EXPORT void qt_generate_epsf( bool b )
+{
+ qt_gen_epsf = b;
+}
+
+#else // USE_QT4
+
+#ifndef TQT_NO_PRINTER
+
+#undef TQ_PRINTER_USE_TYPE42
+
+#include "tqpainter.h"
+#include "tqapplication.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqimage.h"
+#include "tqdatetime.h"
+#include "tqstring.h"
+#include "tqdict.h"
+#include "tqmemarray.h"
+#include "tqfile.h"
+#include "tqbuffer.h"
+#include "tqintdict.h"
+#include "tqtextcodec.h"
+#include "tqsettings.h"
+#include "tqmap.h"
+#include "tqfontdatabase.h"
+#include "tqregexp.h"
+#include "tqbitmap.h"
+#include <private/tqunicodetables_p.h>
+
+#if defined(TQ_OS_WIN32)
+#include <io.h>
+#ifdef TQ_PRINTER_USE_TYPE42
+#include <stdlib.h>
+#endif
+#else
+#include <unistd.h>
+#include <stdlib.h>
+#endif
+
+#ifdef TQ_WS_X11
+#include "tqt_x11_p.h"
+#ifdef None
+#undef None
+#endif
+#ifdef GrayScale
+#undef GrayScale
+#endif
+#endif
+
+#if defined( TQ_WS_X11 ) || defined (TQ_WS_TQWS)
+#include "tqfontdata_p.h"
+#include "tqfontengine_p.h"
+#include "tqtextlayout_p.h"
+#include "tqtextengine_p.h"
+extern bool qt_has_xft;
+#endif
+
+static bool qt_gen_epsf = FALSE;
+static bool embedFonts = TRUE;
+
+TQ_EXPORT void qt_generate_epsf( bool b )
+{
+ qt_gen_epsf = b;
+}
+
+static const char *const ps_header =
+"/d/def load def/D{bind d}bind d/d2{dup dup}D/B{0 d2}D/W{255 d2}D/ED{exch d}D\n"
+"/D0{0 ED}D/LT{lineto}D/MT{moveto}D/S{stroke}D/F{setfont}D/SW{setlinewidth}D\n"
+"/CP{closepath}D/RL{rlineto}D/NP{newpath}D/CM{currentmatrix}D/SM{setmatrix}D\n"
+"/TR{translate}D/SD{setdash}D/SC{aload pop setrgbcolor}D/CR{currentfile read\n"
+"pop}D/i{index}D/bs{bitshift}D/scs{setcolorspace}D/DB{dict dup begin}D/DE{end\n"
+"d}D/ie{ifelse}D/sp{astore pop}D/BSt 0 d/LWi 1 d/PSt 1 d/Cx 0 d/Cy 0 d/WFi\n"
+"false d/OMo false d/BCol[1 1 1]d/PCol[0 0 0]d/BkCol[1 1 1]d/BDArr[0.94 0.88\n"
+"0.63 0.50 0.37 0.12 0.06]d/defM matrix d/nS 0 d/GPS{PSt 1 ge PSt 5 le and{{\n"
+"LArr PSt 1 sub 2 mul get}{LArr PSt 2 mul 1 sub get}ie}{[]}ie}D/QS{PSt 0 ne{\n"
+"gsave LWi SW true GPS 0 SD S OMo PSt 1 ne and{BkCol SC false GPS dup 0 get\n"
+"SD S}if grestore}if}D/r28{{CR dup 32 gt{exit}if pop}loop 3{CR}repeat 0 4{7\n"
+"bs exch dup 128 gt{84 sub}if 42 sub 127 and add}repeat}D/rA 0 d/rL 0 d/rB{rL\n"
+"0 eq{/rA r28 d/rL 28 d}if dup rL gt{rA exch rL sub rL exch/rA 0 d/rL 0 d rB\n"
+"exch bs add}{dup rA 16#fffffff 3 -1 roll bs not and exch dup rL exch sub/rL\n"
+"ED neg rA exch bs/rA ED}ie}D/uc{/rL 0 d 0{dup 2 i length ge{exit}if 1 rB 1\n"
+"eq{3 rB dup 3 ge{1 add dup rB 1 i 5 ge{1 i 6 ge{1 i 7 ge{1 i 8 ge{128 add}if\n"
+"64 add}if 32 add}if 16 add}if 3 add exch pop}if 3 add exch 10 rB 1 add{dup 3\n"
+"i lt{dup}{2 i}ie 4 i 3 i 3 i sub 2 i getinterval 5 i 4 i 3 -1 roll\n"
+"putinterval dup 4 -1 roll add 3 1 roll 4 -1 roll exch sub dup 0 eq{exit}if 3\n"
+"1 roll}loop pop pop}{3 rB 1 add{2 copy 8 rB put 1 add}repeat}ie}loop pop}D\n"
+"/sl D0/TQCIgray D0/TQCIcolor D0/TQCIindex D0/TQCI{/colorimage where{pop false 3\n"
+"colorimage}{exec/TQCIcolor ED/TQCIgray TQCIcolor length 3 idiv string d 0 1\n"
+"TQCIcolor length 3 idiv 1 sub{/TQCIindex ED/x TQCIindex 3 mul d TQCIgray\n"
+"TQCIindex TQCIcolor x get 0.30 mul TQCIcolor x 1 add get 0.59 mul TQCIcolor x 2\n"
+"add get 0.11 mul add add cvi put}for TQCIgray image}ie}D/di{gsave TR 1 i 1 eq\n"
+"{false eq{pop true 3 1 roll 4 i 4 i false 4 i 4 i imagetqmask BkCol SC\n"
+"imagetqmask}{pop false 3 1 roll imagetqmask}ie}{dup false ne{/languagelevel\n"
+"where{pop languagelevel 3 ge}{false}ie}{false}ie{/ma ED 8 eq{/dc[0 1]d\n"
+"/DeviceGray}{/dc[0 1 0 1 0 1]d/DeviceRGB}ie scs/im ED/mt ED/h ED/w ED/id 7\n"
+"DB/ImageType 1 d/Width w d/Height h d/ImageMatrix mt d/DataSource im d\n"
+"/BitsPerComponent 8 d/Decode dc d DE/md 7 DB/ImageType 1 d/Width w d/Height\n"
+"h d/ImageMatrix mt d/DataSource ma d/BitsPerComponent 1 d/Decode[0 1]d DE 4\n"
+"DB/ImageType 3 d/DataDict id d/MaskDict md d/InterleaveType 3 d end image}{\n"
+"pop 8 4 1 roll 8 eq{image}{TQCI}ie}ie}ie grestore}d/BF{gsave BSt 1 eq{BCol SC\n"
+"WFi{fill}{eofill}ie}if BSt 2 ge BSt 8 le and{BDArr BSt 2 sub get/sc ED BCol{\n"
+"1. exch sub sc mul 1. exch sub}forall 3 array astore SC WFi{fill}{eofill}ie}\n"
+"if BSt 9 ge BSt 14 le and{WFi{clip}{eoclip}ie defM SM pathbbox 3 i 3 i TR 4\n"
+"2 roll 3 2 roll exch sub/h ED sub/w ED OMo{NP 0 0 MT 0 h RL w 0 RL 0 h neg\n"
+"RL CP BkCol SC fill}if BCol SC 0.3 SW NP BSt 9 eq BSt 11 eq or{0 4 h{dup 0\n"
+"exch MT w exch LT}for}if BSt 10 eq BSt 11 eq or{0 4 w{dup 0 MT h LT}for}if\n"
+"BSt 12 eq BSt 14 eq or{w h gt{0 6 w h add{dup 0 MT h sub h LT}for}{0 6 w h\n"
+"add{dup 0 exch MT w sub w exch LT}for}ie}if BSt 13 eq BSt 14 eq or{w h gt{0\n"
+"6 w h add{dup h MT h sub 0 LT}for}{0 6 w h add{dup w exch MT w sub 0 exch LT\n"
+"}for}ie}if S}if BSt 24 eq{}if grestore}D/mat matrix d/ang1 D0/ang2 D0/w D0/h\n"
+"D0/x D0/y D0/ARC{/ang2 ED/ang1 ED/h ED/w ED/y ED/x ED mat CM pop x w 2 div\n"
+"add y h 2 div add TR 1 h w div neg scale ang2 0 ge{0 0 w 2 div ang1 ang1\n"
+"ang2 add arc}{0 0 w 2 div ang1 ang1 ang2 add arcn}ie mat SM}D/C D0/P{NP MT\n"
+"0.5 0.5 rmoveto 0 -1 RL -1 0 RL 0 1 RL CP fill}D/M{/Cy ED/Cx ED}D/L{NP Cx Cy\n"
+"MT/Cy ED/Cx ED Cx Cy LT QS}D/DL{NP MT LT QS}D/HL{1 i DL}D/VL{2 i exch DL}D/R\n"
+"{/h ED/w ED/y ED/x ED NP x y MT 0 h RL w 0 RL 0 h neg RL CP BF QS}D/ACR{/h\n"
+"ED/w ED/y ED/x ED x y MT 0 h RL w 0 RL 0 h neg RL CP}D/xr D0/yr D0/rx D0/ry\n"
+"D0/rx2 D0/ry2 D0/RR{/yr ED/xr ED/h ED/w ED/y ED/x ED xr 0 le yr 0 le or{x y\n"
+"w h R}{xr 100 ge yr 100 ge or{x y w h E}{/rx xr w mul 200 div d/ry yr h mul\n"
+"200 div d/rx2 rx 2 mul d/ry2 ry 2 mul d NP x rx add y MT x y rx2 ry2 180 -90\n"
+"x y h add ry2 sub rx2 ry2 270 -90 x w add rx2 sub y h add ry2 sub rx2 ry2 0\n"
+"-90 x w add rx2 sub y rx2 ry2 90 -90 ARC ARC ARC ARC CP BF QS}ie}ie}D/E{/h\n"
+"ED/w ED/y ED/x ED mat CM pop x w 2 div add y h 2 div add TR 1 h w div scale\n"
+"NP 0 0 w 2 div 0 360 arc mat SM BF QS}D/A{16 div exch 16 div exch NP ARC QS}\n"
+"D/PIE{/ang2 ED/ang1 ED/h ED/w ED/y ED/x ED NP x w 2 div add y h 2 div add MT\n"
+"x y w h ang1 16 div ang2 16 div ARC CP BF QS}D/CH{16 div exch 16 div exch NP\n"
+"ARC CP BF QS}D/BZ{curveto QS}D/CRGB{255 div 3 1 roll 255 div 3 1 roll 255\n"
+"div 3 1 roll}D/BC{CRGB BkCol sp}D/BR{CRGB BCol sp/BSt ED}D/WB{1 W BR}D/NB{0\n"
+"B BR}D/PE{setlinejoin setlinecap CRGB PCol sp/LWi ED/PSt ED LWi 0 eq{0.25\n"
+"/LWi ED}if PCol SC}D/P1{1 0 5 2 roll 0 0 PE}D/ST{defM SM concat}D/MF{true\n"
+"exch true exch{exch pop exch pop dup 0 get dup tqfindfont dup/FontName get 3\n"
+"-1 roll eq{exit}if}forall exch dup 1 get/fxscale ED 2 get/fslant ED exch\n"
+"/fencoding ED[fxscale 0 fslant 1 0 0]makefont fencoding false eq{}{dup\n"
+"maxlength dict begin{1 i/FID ne{def}{pop pop}ifelse}forall/Encoding\n"
+"fencoding d currentdict end}ie definefont pop}D/MFEmb{tqfindfont dup length\n"
+"dict begin{1 i/FID ne{d}{pop pop}ifelse}forall/Encoding ED currentdict end\n"
+"definefont pop}D/DF{tqfindfont/fs 3 -1 roll d[fs 0 0 fs -1 mul 0 0]makefont d}\n"
+"D/ty 0 d/Y{/ty ED}D/Tl{gsave SW NP 1 i exch MT 1 i 0 RL S grestore}D/XYT{ty\n"
+"MT/xyshow where{pop pop xyshow}{exch pop 1 i dup length 2 div exch\n"
+"stringwidth pop 3 -1 roll exch sub exch div exch 0 exch ashow}ie}D/AT{ty MT\n"
+"1 i dup length 2 div exch stringwidth pop 3 -1 roll exch sub exch div exch 0\n"
+"exch ashow}D/QI{/C save d pageinit/Cx 0 d/Cy 0 d/OMo false d}D/QP{C restore\n"
+"showpage}D/SPD{/setpagetqdevice where{1 DB 3 1 roll d end setpagetqdevice}{pop\n"
+"pop}ie}D/SV{BSt LWi PSt Cx Cy WFi OMo BCol PCol BkCol/nS nS 1 add d gsave}D\n"
+"/RS{nS 0 gt{grestore/BkCol ED/PCol ED/BCol ED/OMo ED/WFi ED/Cy ED/Cx ED/PSt\n"
+"ED/LWi ED/BSt ED/nS nS 1 sub d}if}D/CLSTART{/clipTmp matrix CM d defM SM NP}\n"
+"D/CLEND{clip NP clipTmp SM}D/CLO{grestore gsave defM SM}D\n";
+
+// the next table is derived from a list provided by Adobe on its web
+// server: http://partners.adobe.com/asn/developer/typeforum/glyphlist.txt
+
+// the start of the header comment:
+//
+// Name: Adobe Glyph List
+// Table version: 1.2
+// Date: 22 Oct 1998
+//
+// Description:
+//
+// The Adobe Glyph List (AGL) list relates Unicode values (UVs) to glyph
+// names, and should be used only as described in the document "Unicode and
+// Glyph Names," at
+// http://partners.adobe.com:80/asn/developer/type/tqunicodegn.html
+//
+// IMPORTANT NOTE:
+// the list tqcontains glyphs in the private use area of tqunicode. These should get removed when regenerating the glyphlist.
+// also 0 shout be mapped to .notdef
+static const struct {
+ TQ_UINT16 u;
+ const char * g;
+} tqunicodetoglyph[] = {
+ // grep '^[0-9A-F][0-9A-F][0-9A-F][0-9A-F];' < /tmp/glyphlist.txt | sed -e 's/;/, "/' -e 's-;-" }, // -' -e 's/^/ { 0x/' | sort
+ { 0x0000, ".notdef" },
+ { 0x0020, "space" }, // SPACE
+ { 0x0021, "exclam" }, // EXCLAMATION MARK
+ { 0x0022, "quotedbl" }, // TQUOTATION MARK
+ { 0x0023, "numbersign" }, // NUMBER SIGN
+ { 0x0024, "dollar" }, // DOLLAR SIGN
+ { 0x0025, "percent" }, // PERCENT SIGN
+ { 0x0026, "ampersand" }, // AMPERSAND
+ { 0x0027, "quotesingle" }, // APOSTROPHE
+ { 0x0028, "parenleft" }, // LEFT PARENTHESIS
+ { 0x0029, "parenright" }, // RIGHT PARENTHESIS
+ { 0x002A, "asterisk" }, // ASTERISK
+ { 0x002B, "plus" }, // PLUS SIGN
+ { 0x002C, "comma" }, // COMMA
+ { 0x002D, "hyphen" }, // HYPHEN-MINUS
+ { 0x002E, "period" }, // FULL STOP
+ { 0x002F, "slash" }, // SOLIDUS
+ { 0x0030, "zero" }, // DIGIT ZERO
+ { 0x0031, "one" }, // DIGIT ONE
+ { 0x0032, "two" }, // DIGIT TWO
+ { 0x0033, "three" }, // DIGIT THREE
+ { 0x0034, "four" }, // DIGIT FOUR
+ { 0x0035, "five" }, // DIGIT FIVE
+ { 0x0036, "six" }, // DIGIT SIX
+ { 0x0037, "seven" }, // DIGIT SEVEN
+ { 0x0038, "eight" }, // DIGIT EIGHT
+ { 0x0039, "nine" }, // DIGIT NINE
+ { 0x003A, "colon" }, // COLON
+ { 0x003B, "semicolon" }, // SEMICOLON
+ { 0x003C, "less" }, // LESS-THAN SIGN
+ { 0x003D, "equal" }, // ETQUALS SIGN
+ { 0x003E, "greater" }, // GREATER-THAN SIGN
+ { 0x003F, "question" }, // TQUESTION MARK
+ { 0x0040, "at" }, // COMMERCIAL AT
+ { 0x0041, "A" }, // LATIN CAPITAL LETTER A
+ { 0x0042, "B" }, // LATIN CAPITAL LETTER B
+ { 0x0043, "C" }, // LATIN CAPITAL LETTER C
+ { 0x0044, "D" }, // LATIN CAPITAL LETTER D
+ { 0x0045, "E" }, // LATIN CAPITAL LETTER E
+ { 0x0046, "F" }, // LATIN CAPITAL LETTER F
+ { 0x0047, "G" }, // LATIN CAPITAL LETTER G
+ { 0x0048, "H" }, // LATIN CAPITAL LETTER H
+ { 0x0049, "I" }, // LATIN CAPITAL LETTER I
+ { 0x004A, "J" }, // LATIN CAPITAL LETTER J
+ { 0x004B, "K" }, // LATIN CAPITAL LETTER K
+ { 0x004C, "L" }, // LATIN CAPITAL LETTER L
+ { 0x004D, "M" }, // LATIN CAPITAL LETTER M
+ { 0x004E, "N" }, // LATIN CAPITAL LETTER N
+ { 0x004F, "O" }, // LATIN CAPITAL LETTER O
+ { 0x0050, "P" }, // LATIN CAPITAL LETTER P
+ { 0x0051, "Q" }, // LATIN CAPITAL LETTER Q
+ { 0x0052, "R" }, // LATIN CAPITAL LETTER R
+ { 0x0053, "S" }, // LATIN CAPITAL LETTER S
+ { 0x0054, "T" }, // LATIN CAPITAL LETTER T
+ { 0x0055, "U" }, // LATIN CAPITAL LETTER U
+ { 0x0056, "V" }, // LATIN CAPITAL LETTER V
+ { 0x0057, "W" }, // LATIN CAPITAL LETTER W
+ { 0x0058, "X" }, // LATIN CAPITAL LETTER X
+ { 0x0059, "Y" }, // LATIN CAPITAL LETTER Y
+ { 0x005A, "Z" }, // LATIN CAPITAL LETTER Z
+ { 0x005B, "bracketleft" }, // LEFT STQUARE BRACKET
+ { 0x005C, "backslash" }, // REVERSE SOLIDUS
+ { 0x005D, "bracketright" }, // RIGHT STQUARE BRACKET
+ { 0x005E, "asciicircum" }, // CIRCUMFLEX ACCENT
+ { 0x005F, "underscore" }, // LOW LINE
+ { 0x0060, "grave" }, // GRAVE ACCENT
+ { 0x0061, "a" }, // LATIN SMALL LETTER A
+ { 0x0062, "b" }, // LATIN SMALL LETTER B
+ { 0x0063, "c" }, // LATIN SMALL LETTER C
+ { 0x0064, "d" }, // LATIN SMALL LETTER D
+ { 0x0065, "e" }, // LATIN SMALL LETTER E
+ { 0x0066, "f" }, // LATIN SMALL LETTER F
+ { 0x0067, "g" }, // LATIN SMALL LETTER G
+ { 0x0068, "h" }, // LATIN SMALL LETTER H
+ { 0x0069, "i" }, // LATIN SMALL LETTER I
+ { 0x006A, "j" }, // LATIN SMALL LETTER J
+ { 0x006B, "k" }, // LATIN SMALL LETTER K
+ { 0x006C, "l" }, // LATIN SMALL LETTER L
+ { 0x006D, "m" }, // LATIN SMALL LETTER M
+ { 0x006E, "n" }, // LATIN SMALL LETTER N
+ { 0x006F, "o" }, // LATIN SMALL LETTER O
+ { 0x0070, "p" }, // LATIN SMALL LETTER P
+ { 0x0071, "q" }, // LATIN SMALL LETTER Q
+ { 0x0072, "r" }, // LATIN SMALL LETTER R
+ { 0x0073, "s" }, // LATIN SMALL LETTER S
+ { 0x0074, "t" }, // LATIN SMALL LETTER T
+ { 0x0075, "u" }, // LATIN SMALL LETTER U
+ { 0x0076, "v" }, // LATIN SMALL LETTER V
+ { 0x0077, "w" }, // LATIN SMALL LETTER W
+ { 0x0078, "x" }, // LATIN SMALL LETTER X
+ { 0x0079, "y" }, // LATIN SMALL LETTER Y
+ { 0x007A, "z" }, // LATIN SMALL LETTER Z
+ { 0x007B, "braceleft" }, // LEFT CURLY BRACKET
+ { 0x007C, "bar" }, // VERTICAL LINE
+ { 0x007D, "braceright" }, // RIGHT CURLY BRACKET
+ { 0x007E, "asciitilde" }, // TILDE
+ { 0x00A0, "space" }, // NO-BREAK SPACE;Duplicate
+ { 0x00A1, "exclamdown" }, // INVERTED EXCLAMATION MARK
+ { 0x00A2, "cent" }, // CENT SIGN
+ { 0x00A3, "sterling" }, // POUND SIGN
+ { 0x00A4, "currency" }, // CURRENCY SIGN
+ { 0x00A5, "yen" }, // YEN SIGN
+ { 0x00A6, "brokenbar" }, // BROKEN BAR
+ { 0x00A7, "section" }, // SECTION SIGN
+ { 0x00A8, "dieresis" }, // DIAERESIS
+ { 0x00A9, "copyright" }, // COPYRIGHT SIGN
+ { 0x00AA, "ordfeminine" }, // FEMININE ORDINAL INDICATOR
+ { 0x00AB, "guillemotleft" }, // LEFT-POINTING DOUBLE ANGLE TQUOTATION MARK
+ { 0x00AC, "logicalnot" }, // NOT SIGN
+ { 0x00AD, "hyphen" }, // SOFT HYPHEN;Duplicate
+ { 0x00AE, "registered" }, // REGISTERED SIGN
+ { 0x00AF, "macron" }, // MACRON
+ { 0x00B0, "degree" }, // DEGREE SIGN
+ { 0x00B1, "plusminus" }, // PLUS-MINUS SIGN
+ { 0x00B2, "twosuperior" }, // SUPERSCRIPT TWO
+ { 0x00B3, "threesuperior" }, // SUPERSCRIPT THREE
+ { 0x00B4, "acute" }, // ACUTE ACCENT
+ { 0x00B5, "mu" }, // MICRO SIGN
+ { 0x00B6, "paragraph" }, // PILCROW SIGN
+ { 0x00B7, "periodcentered" }, // MIDDLE DOT
+ { 0x00B8, "cedilla" }, // CEDILLA
+ { 0x00B9, "onesuperior" }, // SUPERSCRIPT ONE
+ { 0x00BA, "ordmasculine" }, // MASCULINE ORDINAL INDICATOR
+ { 0x00BB, "guillemotright" }, // RIGHT-POINTING DOUBLE ANGLE TQUOTATION MARK
+ { 0x00BC, "onequarter" }, // VULGAR FRACTION ONE TQUARTER
+ { 0x00BD, "onehalf" }, // VULGAR FRACTION ONE HALF
+ { 0x00BE, "threequarters" }, // VULGAR FRACTION THREE TQUARTERS
+ { 0x00BF, "questiondown" }, // INVERTED TQUESTION MARK
+ { 0x00C0, "Agrave" }, // LATIN CAPITAL LETTER A WITH GRAVE
+ { 0x00C1, "Aacute" }, // LATIN CAPITAL LETTER A WITH ACUTE
+ { 0x00C2, "Acircumflex" }, // LATIN CAPITAL LETTER A WITH CIRCUMFLEX
+ { 0x00C3, "Atilde" }, // LATIN CAPITAL LETTER A WITH TILDE
+ { 0x00C4, "Adieresis" }, // LATIN CAPITAL LETTER A WITH DIAERESIS
+ { 0x00C5, "Aring" }, // LATIN CAPITAL LETTER A WITH RING ABOVE
+ { 0x00C6, "AE" }, // LATIN CAPITAL LETTER AE
+ { 0x00C7, "Ccedilla" }, // LATIN CAPITAL LETTER C WITH CEDILLA
+ { 0x00C8, "Egrave" }, // LATIN CAPITAL LETTER E WITH GRAVE
+ { 0x00C9, "Eacute" }, // LATIN CAPITAL LETTER E WITH ACUTE
+ { 0x00CA, "Ecircumflex" }, // LATIN CAPITAL LETTER E WITH CIRCUMFLEX
+ { 0x00CB, "Edieresis" }, // LATIN CAPITAL LETTER E WITH DIAERESIS
+ { 0x00CC, "Igrave" }, // LATIN CAPITAL LETTER I WITH GRAVE
+ { 0x00CD, "Iacute" }, // LATIN CAPITAL LETTER I WITH ACUTE
+ { 0x00CE, "Icircumflex" }, // LATIN CAPITAL LETTER I WITH CIRCUMFLEX
+ { 0x00CF, "Idieresis" }, // LATIN CAPITAL LETTER I WITH DIAERESIS
+ { 0x00D0, "Eth" }, // LATIN CAPITAL LETTER ETH
+ { 0x00D1, "Ntilde" }, // LATIN CAPITAL LETTER N WITH TILDE
+ { 0x00D2, "Ograve" }, // LATIN CAPITAL LETTER O WITH GRAVE
+ { 0x00D3, "Oacute" }, // LATIN CAPITAL LETTER O WITH ACUTE
+ { 0x00D4, "Ocircumflex" }, // LATIN CAPITAL LETTER O WITH CIRCUMFLEX
+ { 0x00D5, "Otilde" }, // LATIN CAPITAL LETTER O WITH TILDE
+ { 0x00D6, "Odieresis" }, // LATIN CAPITAL LETTER O WITH DIAERESIS
+ { 0x00D7, "multiply" }, // MULTIPLICATION SIGN
+ { 0x00D8, "Oslash" }, // LATIN CAPITAL LETTER O WITH STROKE
+ { 0x00D9, "Ugrave" }, // LATIN CAPITAL LETTER U WITH GRAVE
+ { 0x00DA, "Uacute" }, // LATIN CAPITAL LETTER U WITH ACUTE
+ { 0x00DB, "Ucircumflex" }, // LATIN CAPITAL LETTER U WITH CIRCUMFLEX
+ { 0x00DC, "Udieresis" }, // LATIN CAPITAL LETTER U WITH DIAERESIS
+ { 0x00DD, "Yacute" }, // LATIN CAPITAL LETTER Y WITH ACUTE
+ { 0x00DE, "Thorn" }, // LATIN CAPITAL LETTER THORN
+ { 0x00DF, "germandbls" }, // LATIN SMALL LETTER SHARP S
+ { 0x00E0, "agrave" }, // LATIN SMALL LETTER A WITH GRAVE
+ { 0x00E1, "aacute" }, // LATIN SMALL LETTER A WITH ACUTE
+ { 0x00E2, "acircumflex" }, // LATIN SMALL LETTER A WITH CIRCUMFLEX
+ { 0x00E3, "atilde" }, // LATIN SMALL LETTER A WITH TILDE
+ { 0x00E4, "adieresis" }, // LATIN SMALL LETTER A WITH DIAERESIS
+ { 0x00E5, "aring" }, // LATIN SMALL LETTER A WITH RING ABOVE
+ { 0x00E6, "ae" }, // LATIN SMALL LETTER AE
+ { 0x00E7, "ccedilla" }, // LATIN SMALL LETTER C WITH CEDILLA
+ { 0x00E8, "egrave" }, // LATIN SMALL LETTER E WITH GRAVE
+ { 0x00E9, "eacute" }, // LATIN SMALL LETTER E WITH ACUTE
+ { 0x00EA, "ecircumflex" }, // LATIN SMALL LETTER E WITH CIRCUMFLEX
+ { 0x00EB, "edieresis" }, // LATIN SMALL LETTER E WITH DIAERESIS
+ { 0x00EC, "igrave" }, // LATIN SMALL LETTER I WITH GRAVE
+ { 0x00ED, "iacute" }, // LATIN SMALL LETTER I WITH ACUTE
+ { 0x00EE, "icircumflex" }, // LATIN SMALL LETTER I WITH CIRCUMFLEX
+ { 0x00EF, "idieresis" }, // LATIN SMALL LETTER I WITH DIAERESIS
+ { 0x00F0, "eth" }, // LATIN SMALL LETTER ETH
+ { 0x00F1, "ntilde" }, // LATIN SMALL LETTER N WITH TILDE
+ { 0x00F2, "ograve" }, // LATIN SMALL LETTER O WITH GRAVE
+ { 0x00F3, "oacute" }, // LATIN SMALL LETTER O WITH ACUTE
+ { 0x00F4, "ocircumflex" }, // LATIN SMALL LETTER O WITH CIRCUMFLEX
+ { 0x00F5, "otilde" }, // LATIN SMALL LETTER O WITH TILDE
+ { 0x00F6, "odieresis" }, // LATIN SMALL LETTER O WITH DIAERESIS
+ { 0x00F7, "divide" }, // DIVISION SIGN
+ { 0x00F8, "oslash" }, // LATIN SMALL LETTER O WITH STROKE
+ { 0x00F9, "ugrave" }, // LATIN SMALL LETTER U WITH GRAVE
+ { 0x00FA, "uacute" }, // LATIN SMALL LETTER U WITH ACUTE
+ { 0x00FB, "ucircumflex" }, // LATIN SMALL LETTER U WITH CIRCUMFLEX
+ { 0x00FC, "udieresis" }, // LATIN SMALL LETTER U WITH DIAERESIS
+ { 0x00FD, "yacute" }, // LATIN SMALL LETTER Y WITH ACUTE
+ { 0x00FE, "thorn" }, // LATIN SMALL LETTER THORN
+ { 0x00FF, "ydieresis" }, // LATIN SMALL LETTER Y WITH DIAERESIS
+ { 0x0100, "Amacron" }, // LATIN CAPITAL LETTER A WITH MACRON
+ { 0x0101, "amacron" }, // LATIN SMALL LETTER A WITH MACRON
+ { 0x0102, "Abreve" }, // LATIN CAPITAL LETTER A WITH BREVE
+ { 0x0103, "abreve" }, // LATIN SMALL LETTER A WITH BREVE
+ { 0x0104, "Aogonek" }, // LATIN CAPITAL LETTER A WITH OGONEK
+ { 0x0105, "aogonek" }, // LATIN SMALL LETTER A WITH OGONEK
+ { 0x0106, "Cacute" }, // LATIN CAPITAL LETTER C WITH ACUTE
+ { 0x0107, "cacute" }, // LATIN SMALL LETTER C WITH ACUTE
+ { 0x0108, "Ccircumflex" }, // LATIN CAPITAL LETTER C WITH CIRCUMFLEX
+ { 0x0109, "ccircumflex" }, // LATIN SMALL LETTER C WITH CIRCUMFLEX
+ { 0x010A, "Cdotaccent" }, // LATIN CAPITAL LETTER C WITH DOT ABOVE
+ { 0x010B, "cdotaccent" }, // LATIN SMALL LETTER C WITH DOT ABOVE
+ { 0x010C, "Ccaron" }, // LATIN CAPITAL LETTER C WITH CARON
+ { 0x010D, "ccaron" }, // LATIN SMALL LETTER C WITH CARON
+ { 0x010E, "Dcaron" }, // LATIN CAPITAL LETTER D WITH CARON
+ { 0x010F, "dcaron" }, // LATIN SMALL LETTER D WITH CARON
+ { 0x0110, "Dcroat" }, // LATIN CAPITAL LETTER D WITH STROKE
+ { 0x0111, "dcroat" }, // LATIN SMALL LETTER D WITH STROKE
+ { 0x0112, "Emacron" }, // LATIN CAPITAL LETTER E WITH MACRON
+ { 0x0113, "emacron" }, // LATIN SMALL LETTER E WITH MACRON
+ { 0x0114, "Ebreve" }, // LATIN CAPITAL LETTER E WITH BREVE
+ { 0x0115, "ebreve" }, // LATIN SMALL LETTER E WITH BREVE
+ { 0x0116, "Edotaccent" }, // LATIN CAPITAL LETTER E WITH DOT ABOVE
+ { 0x0117, "edotaccent" }, // LATIN SMALL LETTER E WITH DOT ABOVE
+ { 0x0118, "Eogonek" }, // LATIN CAPITAL LETTER E WITH OGONEK
+ { 0x0119, "eogonek" }, // LATIN SMALL LETTER E WITH OGONEK
+ { 0x011A, "Ecaron" }, // LATIN CAPITAL LETTER E WITH CARON
+ { 0x011B, "ecaron" }, // LATIN SMALL LETTER E WITH CARON
+ { 0x011C, "Gcircumflex" }, // LATIN CAPITAL LETTER G WITH CIRCUMFLEX
+ { 0x011D, "gcircumflex" }, // LATIN SMALL LETTER G WITH CIRCUMFLEX
+ { 0x011E, "Gbreve" }, // LATIN CAPITAL LETTER G WITH BREVE
+ { 0x011F, "gbreve" }, // LATIN SMALL LETTER G WITH BREVE
+ { 0x0120, "Gdotaccent" }, // LATIN CAPITAL LETTER G WITH DOT ABOVE
+ { 0x0121, "gdotaccent" }, // LATIN SMALL LETTER G WITH DOT ABOVE
+ { 0x0122, "Gcommaaccent" }, // LATIN CAPITAL LETTER G WITH CEDILLA
+ { 0x0123, "gcommaaccent" }, // LATIN SMALL LETTER G WITH CEDILLA
+ { 0x0124, "Hcircumflex" }, // LATIN CAPITAL LETTER H WITH CIRCUMFLEX
+ { 0x0125, "hcircumflex" }, // LATIN SMALL LETTER H WITH CIRCUMFLEX
+ { 0x0126, "Hbar" }, // LATIN CAPITAL LETTER H WITH STROKE
+ { 0x0127, "hbar" }, // LATIN SMALL LETTER H WITH STROKE
+ { 0x0128, "Itilde" }, // LATIN CAPITAL LETTER I WITH TILDE
+ { 0x0129, "itilde" }, // LATIN SMALL LETTER I WITH TILDE
+ { 0x012A, "Imacron" }, // LATIN CAPITAL LETTER I WITH MACRON
+ { 0x012B, "imacron" }, // LATIN SMALL LETTER I WITH MACRON
+ { 0x012C, "Ibreve" }, // LATIN CAPITAL LETTER I WITH BREVE
+ { 0x012D, "ibreve" }, // LATIN SMALL LETTER I WITH BREVE
+ { 0x012E, "Iogonek" }, // LATIN CAPITAL LETTER I WITH OGONEK
+ { 0x012F, "iogonek" }, // LATIN SMALL LETTER I WITH OGONEK
+ { 0x0130, "Idotaccent" }, // LATIN CAPITAL LETTER I WITH DOT ABOVE
+ { 0x0131, "dotlessi" }, // LATIN SMALL LETTER DOTLESS I
+ { 0x0132, "IJ" }, // LATIN CAPITAL LIGATURE IJ
+ { 0x0133, "ij" }, // LATIN SMALL LIGATURE IJ
+ { 0x0134, "Jcircumflex" }, // LATIN CAPITAL LETTER J WITH CIRCUMFLEX
+ { 0x0135, "jcircumflex" }, // LATIN SMALL LETTER J WITH CIRCUMFLEX
+ { 0x0136, "Kcommaaccent" }, // LATIN CAPITAL LETTER K WITH CEDILLA
+ { 0x0137, "kcommaaccent" }, // LATIN SMALL LETTER K WITH CEDILLA
+ { 0x0138, "kgreenlandic" }, // LATIN SMALL LETTER KRA
+ { 0x0139, "Lacute" }, // LATIN CAPITAL LETTER L WITH ACUTE
+ { 0x013A, "lacute" }, // LATIN SMALL LETTER L WITH ACUTE
+ { 0x013B, "Lcommaaccent" }, // LATIN CAPITAL LETTER L WITH CEDILLA
+ { 0x013C, "lcommaaccent" }, // LATIN SMALL LETTER L WITH CEDILLA
+ { 0x013D, "Lcaron" }, // LATIN CAPITAL LETTER L WITH CARON
+ { 0x013E, "lcaron" }, // LATIN SMALL LETTER L WITH CARON
+ { 0x013F, "Ldot" }, // LATIN CAPITAL LETTER L WITH MIDDLE DOT
+ { 0x0140, "ldot" }, // LATIN SMALL LETTER L WITH MIDDLE DOT
+ { 0x0141, "Lslash" }, // LATIN CAPITAL LETTER L WITH STROKE
+ { 0x0142, "lslash" }, // LATIN SMALL LETTER L WITH STROKE
+ { 0x0143, "Nacute" }, // LATIN CAPITAL LETTER N WITH ACUTE
+ { 0x0144, "nacute" }, // LATIN SMALL LETTER N WITH ACUTE
+ { 0x0145, "Ncommaaccent" }, // LATIN CAPITAL LETTER N WITH CEDILLA
+ { 0x0146, "ncommaaccent" }, // LATIN SMALL LETTER N WITH CEDILLA
+ { 0x0147, "Ncaron" }, // LATIN CAPITAL LETTER N WITH CARON
+ { 0x0148, "ncaron" }, // LATIN SMALL LETTER N WITH CARON
+ { 0x0149, "napostrophe" }, // LATIN SMALL LETTER N PRECEDED BY APOSTROPHE
+ { 0x014A, "Eng" }, // LATIN CAPITAL LETTER ENG
+ { 0x014B, "eng" }, // LATIN SMALL LETTER ENG
+ { 0x014C, "Omacron" }, // LATIN CAPITAL LETTER O WITH MACRON
+ { 0x014D, "omacron" }, // LATIN SMALL LETTER O WITH MACRON
+ { 0x014E, "Obreve" }, // LATIN CAPITAL LETTER O WITH BREVE
+ { 0x014F, "obreve" }, // LATIN SMALL LETTER O WITH BREVE
+ { 0x0150, "Ohungarumlaut" }, // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
+ { 0x0151, "ohungarumlaut" }, // LATIN SMALL LETTER O WITH DOUBLE ACUTE
+ { 0x0152, "OE" }, // LATIN CAPITAL LIGATURE OE
+ { 0x0153, "oe" }, // LATIN SMALL LIGATURE OE
+ { 0x0154, "Racute" }, // LATIN CAPITAL LETTER R WITH ACUTE
+ { 0x0155, "racute" }, // LATIN SMALL LETTER R WITH ACUTE
+ { 0x0156, "Rcommaaccent" }, // LATIN CAPITAL LETTER R WITH CEDILLA
+ { 0x0157, "rcommaaccent" }, // LATIN SMALL LETTER R WITH CEDILLA
+ { 0x0158, "Rcaron" }, // LATIN CAPITAL LETTER R WITH CARON
+ { 0x0159, "rcaron" }, // LATIN SMALL LETTER R WITH CARON
+ { 0x015A, "Sacute" }, // LATIN CAPITAL LETTER S WITH ACUTE
+ { 0x015B, "sacute" }, // LATIN SMALL LETTER S WITH ACUTE
+ { 0x015C, "Scircumflex" }, // LATIN CAPITAL LETTER S WITH CIRCUMFLEX
+ { 0x015D, "scircumflex" }, // LATIN SMALL LETTER S WITH CIRCUMFLEX
+ { 0x015E, "Scedilla" }, // LATIN CAPITAL LETTER S WITH CEDILLA
+ { 0x015F, "scedilla" }, // LATIN SMALL LETTER S WITH CEDILLA
+ { 0x0160, "Scaron" }, // LATIN CAPITAL LETTER S WITH CARON
+ { 0x0161, "scaron" }, // LATIN SMALL LETTER S WITH CARON
+ { 0x0162, "Tcommaaccent" }, // LATIN CAPITAL LETTER T WITH CEDILLA
+ { 0x0163, "tcommaaccent" }, // LATIN SMALL LETTER T WITH CEDILLA
+ { 0x0164, "Tcaron" }, // LATIN CAPITAL LETTER T WITH CARON
+ { 0x0165, "tcaron" }, // LATIN SMALL LETTER T WITH CARON
+ { 0x0166, "Tbar" }, // LATIN CAPITAL LETTER T WITH STROKE
+ { 0x0167, "tbar" }, // LATIN SMALL LETTER T WITH STROKE
+ { 0x0168, "Utilde" }, // LATIN CAPITAL LETTER U WITH TILDE
+ { 0x0169, "utilde" }, // LATIN SMALL LETTER U WITH TILDE
+ { 0x016A, "Umacron" }, // LATIN CAPITAL LETTER U WITH MACRON
+ { 0x016B, "umacron" }, // LATIN SMALL LETTER U WITH MACRON
+ { 0x016C, "Ubreve" }, // LATIN CAPITAL LETTER U WITH BREVE
+ { 0x016D, "ubreve" }, // LATIN SMALL LETTER U WITH BREVE
+ { 0x016E, "Uring" }, // LATIN CAPITAL LETTER U WITH RING ABOVE
+ { 0x016F, "uring" }, // LATIN SMALL LETTER U WITH RING ABOVE
+ { 0x0170, "Uhungarumlaut" }, // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
+ { 0x0171, "uhungarumlaut" }, // LATIN SMALL LETTER U WITH DOUBLE ACUTE
+ { 0x0172, "Uogonek" }, // LATIN CAPITAL LETTER U WITH OGONEK
+ { 0x0173, "uogonek" }, // LATIN SMALL LETTER U WITH OGONEK
+ { 0x0174, "Wcircumflex" }, // LATIN CAPITAL LETTER W WITH CIRCUMFLEX
+ { 0x0175, "wcircumflex" }, // LATIN SMALL LETTER W WITH CIRCUMFLEX
+ { 0x0176, "Ycircumflex" }, // LATIN CAPITAL LETTER Y WITH CIRCUMFLEX
+ { 0x0177, "ycircumflex" }, // LATIN SMALL LETTER Y WITH CIRCUMFLEX
+ { 0x0178, "Ydieresis" }, // LATIN CAPITAL LETTER Y WITH DIAERESIS
+ { 0x0179, "Zacute" }, // LATIN CAPITAL LETTER Z WITH ACUTE
+ { 0x017A, "zacute" }, // LATIN SMALL LETTER Z WITH ACUTE
+ { 0x017B, "Zdotaccent" }, // LATIN CAPITAL LETTER Z WITH DOT ABOVE
+ { 0x017C, "zdotaccent" }, // LATIN SMALL LETTER Z WITH DOT ABOVE
+ { 0x017D, "Zcaron" }, // LATIN CAPITAL LETTER Z WITH CARON
+ { 0x017E, "zcaron" }, // LATIN SMALL LETTER Z WITH CARON
+ { 0x017F, "longs" }, // LATIN SMALL LETTER LONG S
+ { 0x0192, "florin" }, // LATIN SMALL LETTER F WITH HOOK
+ { 0x01A0, "Ohorn" }, // LATIN CAPITAL LETTER O WITH HORN
+ { 0x01A1, "ohorn" }, // LATIN SMALL LETTER O WITH HORN
+ { 0x01AF, "Uhorn" }, // LATIN CAPITAL LETTER U WITH HORN
+ { 0x01B0, "uhorn" }, // LATIN SMALL LETTER U WITH HORN
+ { 0x01E6, "Gcaron" }, // LATIN CAPITAL LETTER G WITH CARON
+ { 0x01E7, "gcaron" }, // LATIN SMALL LETTER G WITH CARON
+ { 0x01FA, "Aringacute" }, // LATIN CAPITAL LETTER A WITH RING ABOVE AND ACUTE
+ { 0x01FB, "aringacute" }, // LATIN SMALL LETTER A WITH RING ABOVE AND ACUTE
+ { 0x01FC, "AEacute" }, // LATIN CAPITAL LETTER AE WITH ACUTE
+ { 0x01FD, "aeacute" }, // LATIN SMALL LETTER AE WITH ACUTE
+ { 0x01FE, "Oslashacute" }, // LATIN CAPITAL LETTER O WITH STROKE AND ACUTE
+ { 0x01FF, "oslashacute" }, // LATIN SMALL LETTER O WITH STROKE AND ACUTE
+ { 0x0218, "Scommaaccent" }, // LATIN CAPITAL LETTER S WITH COMMA BELOW
+ { 0x0219, "scommaaccent" }, // LATIN SMALL LETTER S WITH COMMA BELOW
+ { 0x021A, "Tcommaaccent" }, // LATIN CAPITAL LETTER T WITH COMMA BELOW;Duplicate
+ { 0x021B, "tcommaaccent" }, // LATIN SMALL LETTER T WITH COMMA BELOW;Duplicate
+ { 0x02BC, "afii57929" }, // MODIFIER LETTER APOSTROPHE
+ { 0x02BD, "afii64937" }, // MODIFIER LETTER REVERSED COMMA
+ { 0x02C6, "circumflex" }, // MODIFIER LETTER CIRCUMFLEX ACCENT
+ { 0x02C7, "caron" }, // CARON
+ { 0x02C9, "macron" }, // MODIFIER LETTER MACRON;Duplicate
+ { 0x02D8, "breve" }, // BREVE
+ { 0x02D9, "dotaccent" }, // DOT ABOVE
+ { 0x02DA, "ring" }, // RING ABOVE
+ { 0x02DB, "ogonek" }, // OGONEK
+ { 0x02DC, "tilde" }, // SMALL TILDE
+ { 0x02DD, "hungarumlaut" }, // DOUBLE ACUTE ACCENT
+ { 0x0300, "gravecomb" }, // COMBINING GRAVE ACCENT
+ { 0x0301, "acutecomb" }, // COMBINING ACUTE ACCENT
+ { 0x0303, "tildecomb" }, // COMBINING TILDE
+ { 0x0309, "hookabovecomb" }, // COMBINING HOOK ABOVE
+ { 0x0323, "dotbelowcomb" }, // COMBINING DOT BELOW
+ { 0x0384, "tonos" }, // GREEK TONOS
+ { 0x0385, "dieresistonos" }, // GREEK DIALYTIKA TONOS
+ { 0x0386, "Alphatonos" }, // GREEK CAPITAL LETTER ALPHA WITH TONOS
+ { 0x0387, "anoteleia" }, // GREEK ANO TELEIA
+ { 0x0388, "Epsilontonos" }, // GREEK CAPITAL LETTER EPSILON WITH TONOS
+ { 0x0389, "Etatonos" }, // GREEK CAPITAL LETTER ETA WITH TONOS
+ { 0x038A, "Iotatonos" }, // GREEK CAPITAL LETTER IOTA WITH TONOS
+ { 0x038C, "Omicrontonos" }, // GREEK CAPITAL LETTER OMICRON WITH TONOS
+ { 0x038E, "Upsilontonos" }, // GREEK CAPITAL LETTER UPSILON WITH TONOS
+ { 0x038F, "Omegatonos" }, // GREEK CAPITAL LETTER OMEGA WITH TONOS
+ { 0x0390, "iotadieresistonos" }, // GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
+ { 0x0391, "Alpha" }, // GREEK CAPITAL LETTER ALPHA
+ { 0x0392, "Beta" }, // GREEK CAPITAL LETTER BETA
+ { 0x0393, "Gamma" }, // GREEK CAPITAL LETTER GAMMA
+ { 0x0394, "Delta" }, // GREEK CAPITAL LETTER DELTA;Duplicate
+ { 0x0395, "Epsilon" }, // GREEK CAPITAL LETTER EPSILON
+ { 0x0396, "Zeta" }, // GREEK CAPITAL LETTER ZETA
+ { 0x0397, "Eta" }, // GREEK CAPITAL LETTER ETA
+ { 0x0398, "Theta" }, // GREEK CAPITAL LETTER THETA
+ { 0x0399, "Iota" }, // GREEK CAPITAL LETTER IOTA
+ { 0x039A, "Kappa" }, // GREEK CAPITAL LETTER KAPPA
+ { 0x039B, "Lambda" }, // GREEK CAPITAL LETTER LAMDA
+ { 0x039C, "Mu" }, // GREEK CAPITAL LETTER MU
+ { 0x039D, "Nu" }, // GREEK CAPITAL LETTER NU
+ { 0x039E, "Xi" }, // GREEK CAPITAL LETTER XI
+ { 0x039F, "Omicron" }, // GREEK CAPITAL LETTER OMICRON
+ { 0x03A0, "Pi" }, // GREEK CAPITAL LETTER PI
+ { 0x03A1, "Rho" }, // GREEK CAPITAL LETTER RHO
+ { 0x03A3, "Sigma" }, // GREEK CAPITAL LETTER SIGMA
+ { 0x03A4, "Tau" }, // GREEK CAPITAL LETTER TAU
+ { 0x03A5, "Upsilon" }, // GREEK CAPITAL LETTER UPSILON
+ { 0x03A6, "Phi" }, // GREEK CAPITAL LETTER PHI
+ { 0x03A7, "Chi" }, // GREEK CAPITAL LETTER CHI
+ { 0x03A8, "Psi" }, // GREEK CAPITAL LETTER PSI
+ { 0x03A9, "Omega" }, // GREEK CAPITAL LETTER OMEGA;Duplicate
+ { 0x03AA, "Iotadieresis" }, // GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
+ { 0x03AB, "Upsilondieresis" }, // GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
+ { 0x03AC, "alphatonos" }, // GREEK SMALL LETTER ALPHA WITH TONOS
+ { 0x03AD, "epsilontonos" }, // GREEK SMALL LETTER EPSILON WITH TONOS
+ { 0x03AE, "etatonos" }, // GREEK SMALL LETTER ETA WITH TONOS
+ { 0x03AF, "iotatonos" }, // GREEK SMALL LETTER IOTA WITH TONOS
+ { 0x03B0, "upsilondieresistonos" }, // GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
+ { 0x03B1, "alpha" }, // GREEK SMALL LETTER ALPHA
+ { 0x03B2, "beta" }, // GREEK SMALL LETTER BETA
+ { 0x03B3, "gamma" }, // GREEK SMALL LETTER GAMMA
+ { 0x03B4, "delta" }, // GREEK SMALL LETTER DELTA
+ { 0x03B5, "epsilon" }, // GREEK SMALL LETTER EPSILON
+ { 0x03B6, "zeta" }, // GREEK SMALL LETTER ZETA
+ { 0x03B7, "eta" }, // GREEK SMALL LETTER ETA
+ { 0x03B8, "theta" }, // GREEK SMALL LETTER THETA
+ { 0x03B9, "iota" }, // GREEK SMALL LETTER IOTA
+ { 0x03BA, "kappa" }, // GREEK SMALL LETTER KAPPA
+ { 0x03BB, "lambda" }, // GREEK SMALL LETTER LAMDA
+ { 0x03BC, "mu" }, // GREEK SMALL LETTER MU;Duplicate
+ { 0x03BD, "nu" }, // GREEK SMALL LETTER NU
+ { 0x03BE, "xi" }, // GREEK SMALL LETTER XI
+ { 0x03BF, "omicron" }, // GREEK SMALL LETTER OMICRON
+ { 0x03C0, "pi" }, // GREEK SMALL LETTER PI
+ { 0x03C1, "rho" }, // GREEK SMALL LETTER RHO
+ { 0x03C2, "sigma1" }, // GREEK SMALL LETTER FINAL SIGMA
+ { 0x03C3, "sigma" }, // GREEK SMALL LETTER SIGMA
+ { 0x03C4, "tau" }, // GREEK SMALL LETTER TAU
+ { 0x03C5, "upsilon" }, // GREEK SMALL LETTER UPSILON
+ { 0x03C6, "phi" }, // GREEK SMALL LETTER PHI
+ { 0x03C7, "chi" }, // GREEK SMALL LETTER CHI
+ { 0x03C8, "psi" }, // GREEK SMALL LETTER PSI
+ { 0x03C9, "omega" }, // GREEK SMALL LETTER OMEGA
+ { 0x03CA, "iotadieresis" }, // GREEK SMALL LETTER IOTA WITH DIALYTIKA
+ { 0x03CB, "upsilondieresis" }, // GREEK SMALL LETTER UPSILON WITH DIALYTIKA
+ { 0x03CC, "omicrontonos" }, // GREEK SMALL LETTER OMICRON WITH TONOS
+ { 0x03CD, "upsilontonos" }, // GREEK SMALL LETTER UPSILON WITH TONOS
+ { 0x03CE, "omegatonos" }, // GREEK SMALL LETTER OMEGA WITH TONOS
+ { 0x03D1, "theta1" }, // GREEK THETA SYMBOL
+ { 0x03D2, "Upsilon1" }, // GREEK UPSILON WITH HOOK SYMBOL
+ { 0x03D5, "phi1" }, // GREEK PHI SYMBOL
+ { 0x03D6, "omega1" }, // GREEK PI SYMBOL
+ { 0x0401, "afii10023" }, // CYRILLIC CAPITAL LETTER IO
+ { 0x0402, "afii10051" }, // CYRILLIC CAPITAL LETTER DJE
+ { 0x0403, "afii10052" }, // CYRILLIC CAPITAL LETTER GJE
+ { 0x0404, "afii10053" }, // CYRILLIC CAPITAL LETTER UKRAINIAN IE
+ { 0x0405, "afii10054" }, // CYRILLIC CAPITAL LETTER DZE
+ { 0x0406, "afii10055" }, // CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
+ { 0x0407, "afii10056" }, // CYRILLIC CAPITAL LETTER YI
+ { 0x0408, "afii10057" }, // CYRILLIC CAPITAL LETTER JE
+ { 0x0409, "afii10058" }, // CYRILLIC CAPITAL LETTER LJE
+ { 0x040A, "afii10059" }, // CYRILLIC CAPITAL LETTER NJE
+ { 0x040B, "afii10060" }, // CYRILLIC CAPITAL LETTER TSHE
+ { 0x040C, "afii10061" }, // CYRILLIC CAPITAL LETTER KJE
+ { 0x040E, "afii10062" }, // CYRILLIC CAPITAL LETTER SHORT U
+ { 0x040F, "afii10145" }, // CYRILLIC CAPITAL LETTER DZHE
+ { 0x0410, "afii10017" }, // CYRILLIC CAPITAL LETTER A
+ { 0x0411, "afii10018" }, // CYRILLIC CAPITAL LETTER BE
+ { 0x0412, "afii10019" }, // CYRILLIC CAPITAL LETTER VE
+ { 0x0413, "afii10020" }, // CYRILLIC CAPITAL LETTER GHE
+ { 0x0414, "afii10021" }, // CYRILLIC CAPITAL LETTER DE
+ { 0x0415, "afii10022" }, // CYRILLIC CAPITAL LETTER IE
+ { 0x0416, "afii10024" }, // CYRILLIC CAPITAL LETTER ZHE
+ { 0x0417, "afii10025" }, // CYRILLIC CAPITAL LETTER ZE
+ { 0x0418, "afii10026" }, // CYRILLIC CAPITAL LETTER I
+ { 0x0419, "afii10027" }, // CYRILLIC CAPITAL LETTER SHORT I
+ { 0x041A, "afii10028" }, // CYRILLIC CAPITAL LETTER KA
+ { 0x041B, "afii10029" }, // CYRILLIC CAPITAL LETTER EL
+ { 0x041C, "afii10030" }, // CYRILLIC CAPITAL LETTER EM
+ { 0x041D, "afii10031" }, // CYRILLIC CAPITAL LETTER EN
+ { 0x041E, "afii10032" }, // CYRILLIC CAPITAL LETTER O
+ { 0x041F, "afii10033" }, // CYRILLIC CAPITAL LETTER PE
+ { 0x0420, "afii10034" }, // CYRILLIC CAPITAL LETTER ER
+ { 0x0421, "afii10035" }, // CYRILLIC CAPITAL LETTER ES
+ { 0x0422, "afii10036" }, // CYRILLIC CAPITAL LETTER TE
+ { 0x0423, "afii10037" }, // CYRILLIC CAPITAL LETTER U
+ { 0x0424, "afii10038" }, // CYRILLIC CAPITAL LETTER EF
+ { 0x0425, "afii10039" }, // CYRILLIC CAPITAL LETTER HA
+ { 0x0426, "afii10040" }, // CYRILLIC CAPITAL LETTER TSE
+ { 0x0427, "afii10041" }, // CYRILLIC CAPITAL LETTER CHE
+ { 0x0428, "afii10042" }, // CYRILLIC CAPITAL LETTER SHA
+ { 0x0429, "afii10043" }, // CYRILLIC CAPITAL LETTER SHCHA
+ { 0x042A, "afii10044" }, // CYRILLIC CAPITAL LETTER HARD SIGN
+ { 0x042B, "afii10045" }, // CYRILLIC CAPITAL LETTER YERU
+ { 0x042C, "afii10046" }, // CYRILLIC CAPITAL LETTER SOFT SIGN
+ { 0x042D, "afii10047" }, // CYRILLIC CAPITAL LETTER E
+ { 0x042E, "afii10048" }, // CYRILLIC CAPITAL LETTER YU
+ { 0x042F, "afii10049" }, // CYRILLIC CAPITAL LETTER YA
+ { 0x0430, "afii10065" }, // CYRILLIC SMALL LETTER A
+ { 0x0431, "afii10066" }, // CYRILLIC SMALL LETTER BE
+ { 0x0432, "afii10067" }, // CYRILLIC SMALL LETTER VE
+ { 0x0433, "afii10068" }, // CYRILLIC SMALL LETTER GHE
+ { 0x0434, "afii10069" }, // CYRILLIC SMALL LETTER DE
+ { 0x0435, "afii10070" }, // CYRILLIC SMALL LETTER IE
+ { 0x0436, "afii10072" }, // CYRILLIC SMALL LETTER ZHE
+ { 0x0437, "afii10073" }, // CYRILLIC SMALL LETTER ZE
+ { 0x0438, "afii10074" }, // CYRILLIC SMALL LETTER I
+ { 0x0439, "afii10075" }, // CYRILLIC SMALL LETTER SHORT I
+ { 0x043A, "afii10076" }, // CYRILLIC SMALL LETTER KA
+ { 0x043B, "afii10077" }, // CYRILLIC SMALL LETTER EL
+ { 0x043C, "afii10078" }, // CYRILLIC SMALL LETTER EM
+ { 0x043D, "afii10079" }, // CYRILLIC SMALL LETTER EN
+ { 0x043E, "afii10080" }, // CYRILLIC SMALL LETTER O
+ { 0x043F, "afii10081" }, // CYRILLIC SMALL LETTER PE
+ { 0x0440, "afii10082" }, // CYRILLIC SMALL LETTER ER
+ { 0x0441, "afii10083" }, // CYRILLIC SMALL LETTER ES
+ { 0x0442, "afii10084" }, // CYRILLIC SMALL LETTER TE
+ { 0x0443, "afii10085" }, // CYRILLIC SMALL LETTER U
+ { 0x0444, "afii10086" }, // CYRILLIC SMALL LETTER EF
+ { 0x0445, "afii10087" }, // CYRILLIC SMALL LETTER HA
+ { 0x0446, "afii10088" }, // CYRILLIC SMALL LETTER TSE
+ { 0x0447, "afii10089" }, // CYRILLIC SMALL LETTER CHE
+ { 0x0448, "afii10090" }, // CYRILLIC SMALL LETTER SHA
+ { 0x0449, "afii10091" }, // CYRILLIC SMALL LETTER SHCHA
+ { 0x044A, "afii10092" }, // CYRILLIC SMALL LETTER HARD SIGN
+ { 0x044B, "afii10093" }, // CYRILLIC SMALL LETTER YERU
+ { 0x044C, "afii10094" }, // CYRILLIC SMALL LETTER SOFT SIGN
+ { 0x044D, "afii10095" }, // CYRILLIC SMALL LETTER E
+ { 0x044E, "afii10096" }, // CYRILLIC SMALL LETTER YU
+ { 0x044F, "afii10097" }, // CYRILLIC SMALL LETTER YA
+ { 0x0451, "afii10071" }, // CYRILLIC SMALL LETTER IO
+ { 0x0452, "afii10099" }, // CYRILLIC SMALL LETTER DJE
+ { 0x0453, "afii10100" }, // CYRILLIC SMALL LETTER GJE
+ { 0x0454, "afii10101" }, // CYRILLIC SMALL LETTER UKRAINIAN IE
+ { 0x0455, "afii10102" }, // CYRILLIC SMALL LETTER DZE
+ { 0x0456, "afii10103" }, // CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
+ { 0x0457, "afii10104" }, // CYRILLIC SMALL LETTER YI
+ { 0x0458, "afii10105" }, // CYRILLIC SMALL LETTER JE
+ { 0x0459, "afii10106" }, // CYRILLIC SMALL LETTER LJE
+ { 0x045A, "afii10107" }, // CYRILLIC SMALL LETTER NJE
+ { 0x045B, "afii10108" }, // CYRILLIC SMALL LETTER TSHE
+ { 0x045C, "afii10109" }, // CYRILLIC SMALL LETTER KJE
+ { 0x045E, "afii10110" }, // CYRILLIC SMALL LETTER SHORT U
+ { 0x045F, "afii10193" }, // CYRILLIC SMALL LETTER DZHE
+ { 0x0462, "afii10146" }, // CYRILLIC CAPITAL LETTER YAT
+ { 0x0463, "afii10194" }, // CYRILLIC SMALL LETTER YAT
+ { 0x0472, "afii10147" }, // CYRILLIC CAPITAL LETTER FITA
+ { 0x0473, "afii10195" }, // CYRILLIC SMALL LETTER FITA
+ { 0x0474, "afii10148" }, // CYRILLIC CAPITAL LETTER IZHITSA
+ { 0x0475, "afii10196" }, // CYRILLIC SMALL LETTER IZHITSA
+ { 0x0490, "afii10050" }, // CYRILLIC CAPITAL LETTER GHE WITH UPTURN
+ { 0x0491, "afii10098" }, // CYRILLIC SMALL LETTER GHE WITH UPTURN
+ { 0x04D9, "afii10846" }, // CYRILLIC SMALL LETTER SCHWA
+ { 0x05B0, "afii57799" }, // HEBREW POINT SHEVA
+ { 0x05B1, "afii57801" }, // HEBREW POINT HATAF SEGOL
+ { 0x05B2, "afii57800" }, // HEBREW POINT HATAF PATAH
+ { 0x05B3, "afii57802" }, // HEBREW POINT HATAF TQAMATS
+ { 0x05B4, "afii57793" }, // HEBREW POINT HIRIQ
+ { 0x05B5, "afii57794" }, // HEBREW POINT TSERE
+ { 0x05B6, "afii57795" }, // HEBREW POINT SEGOL
+ { 0x05B7, "afii57798" }, // HEBREW POINT PATAH
+ { 0x05B8, "afii57797" }, // HEBREW POINT TQAMATS
+ { 0x05B9, "afii57806" }, // HEBREW POINT HOLAM
+ { 0x05BB, "afii57796" }, // HEBREW POINT TQUBUTS
+ { 0x05BC, "afii57807" }, // HEBREW POINT DAGESH OR MAPIQ
+ { 0x05BD, "afii57839" }, // HEBREW POINT METEG
+ { 0x05BE, "afii57645" }, // HEBREW PUNCTUATION MATQAF
+ { 0x05BF, "afii57841" }, // HEBREW POINT RAFE
+ { 0x05C0, "afii57842" }, // HEBREW PUNCTUATION PASEQ
+ { 0x05C1, "afii57804" }, // HEBREW POINT SHIN DOT
+ { 0x05C2, "afii57803" }, // HEBREW POINT SIN DOT
+ { 0x05C3, "afii57658" }, // HEBREW PUNCTUATION SOF PASUQ
+ { 0x05D0, "afii57664" }, // HEBREW LETTER ALEF
+ { 0x05D1, "afii57665" }, // HEBREW LETTER BET
+ { 0x05D2, "afii57666" }, // HEBREW LETTER GIMEL
+ { 0x05D3, "afii57667" }, // HEBREW LETTER DALET
+ { 0x05D4, "afii57668" }, // HEBREW LETTER HE
+ { 0x05D5, "afii57669" }, // HEBREW LETTER VAV
+ { 0x05D6, "afii57670" }, // HEBREW LETTER ZAYIN
+ { 0x05D7, "afii57671" }, // HEBREW LETTER HET
+ { 0x05D8, "afii57672" }, // HEBREW LETTER TET
+ { 0x05D9, "afii57673" }, // HEBREW LETTER YOD
+ { 0x05DA, "afii57674" }, // HEBREW LETTER FINAL KAF
+ { 0x05DB, "afii57675" }, // HEBREW LETTER KAF
+ { 0x05DC, "afii57676" }, // HEBREW LETTER LAMED
+ { 0x05DD, "afii57677" }, // HEBREW LETTER FINAL MEM
+ { 0x05DE, "afii57678" }, // HEBREW LETTER MEM
+ { 0x05DF, "afii57679" }, // HEBREW LETTER FINAL NUN
+ { 0x05E0, "afii57680" }, // HEBREW LETTER NUN
+ { 0x05E1, "afii57681" }, // HEBREW LETTER SAMEKH
+ { 0x05E2, "afii57682" }, // HEBREW LETTER AYIN
+ { 0x05E3, "afii57683" }, // HEBREW LETTER FINAL PE
+ { 0x05E4, "afii57684" }, // HEBREW LETTER PE
+ { 0x05E5, "afii57685" }, // HEBREW LETTER FINAL TSADI
+ { 0x05E6, "afii57686" }, // HEBREW LETTER TSADI
+ { 0x05E7, "afii57687" }, // HEBREW LETTER TQOF
+ { 0x05E8, "afii57688" }, // HEBREW LETTER RESH
+ { 0x05E9, "afii57689" }, // HEBREW LETTER SHIN
+ { 0x05EA, "afii57690" }, // HEBREW LETTER TAV
+ { 0x05F0, "afii57716" }, // HEBREW LIGATURE YIDDISH DOUBLE VAV
+ { 0x05F1, "afii57717" }, // HEBREW LIGATURE YIDDISH VAV YOD
+ { 0x05F2, "afii57718" }, // HEBREW LIGATURE YIDDISH DOUBLE YOD
+ { 0x060C, "afii57388" }, // ARABIC COMMA
+ { 0x061B, "afii57403" }, // ARABIC SEMICOLON
+ { 0x061F, "afii57407" }, // ARABIC TQUESTION MARK
+ { 0x0621, "afii57409" }, // ARABIC LETTER HAMZA
+ { 0x0622, "afii57410" }, // ARABIC LETTER ALEF WITH MADDA ABOVE
+ { 0x0623, "afii57411" }, // ARABIC LETTER ALEF WITH HAMZA ABOVE
+ { 0x0624, "afii57412" }, // ARABIC LETTER WAW WITH HAMZA ABOVE
+ { 0x0625, "afii57413" }, // ARABIC LETTER ALEF WITH HAMZA BELOW
+ { 0x0626, "afii57414" }, // ARABIC LETTER YEH WITH HAMZA ABOVE
+ { 0x0627, "afii57415" }, // ARABIC LETTER ALEF
+ { 0x0628, "afii57416" }, // ARABIC LETTER BEH
+ { 0x0629, "afii57417" }, // ARABIC LETTER TEH MARBUTA
+ { 0x062A, "afii57418" }, // ARABIC LETTER TEH
+ { 0x062B, "afii57419" }, // ARABIC LETTER THEH
+ { 0x062C, "afii57420" }, // ARABIC LETTER JEEM
+ { 0x062D, "afii57421" }, // ARABIC LETTER HAH
+ { 0x062E, "afii57422" }, // ARABIC LETTER KHAH
+ { 0x062F, "afii57423" }, // ARABIC LETTER DAL
+ { 0x0630, "afii57424" }, // ARABIC LETTER THAL
+ { 0x0631, "afii57425" }, // ARABIC LETTER REH
+ { 0x0632, "afii57426" }, // ARABIC LETTER ZAIN
+ { 0x0633, "afii57427" }, // ARABIC LETTER SEEN
+ { 0x0634, "afii57428" }, // ARABIC LETTER SHEEN
+ { 0x0635, "afii57429" }, // ARABIC LETTER SAD
+ { 0x0636, "afii57430" }, // ARABIC LETTER DAD
+ { 0x0637, "afii57431" }, // ARABIC LETTER TAH
+ { 0x0638, "afii57432" }, // ARABIC LETTER ZAH
+ { 0x0639, "afii57433" }, // ARABIC LETTER AIN
+ { 0x063A, "afii57434" }, // ARABIC LETTER GHAIN
+ { 0x0640, "afii57440" }, // ARABIC TATWEEL
+ { 0x0641, "afii57441" }, // ARABIC LETTER FEH
+ { 0x0642, "afii57442" }, // ARABIC LETTER TQAF
+ { 0x0643, "afii57443" }, // ARABIC LETTER KAF
+ { 0x0644, "afii57444" }, // ARABIC LETTER LAM
+ { 0x0645, "afii57445" }, // ARABIC LETTER MEEM
+ { 0x0646, "afii57446" }, // ARABIC LETTER NOON
+ { 0x0647, "afii57470" }, // ARABIC LETTER HEH
+ { 0x0648, "afii57448" }, // ARABIC LETTER WAW
+ { 0x0649, "afii57449" }, // ARABIC LETTER ALEF MAKSURA
+ { 0x064A, "afii57450" }, // ARABIC LETTER YEH
+ { 0x064B, "afii57451" }, // ARABIC FATHATAN
+ { 0x064C, "afii57452" }, // ARABIC DAMMATAN
+ { 0x064D, "afii57453" }, // ARABIC KASRATAN
+ { 0x064E, "afii57454" }, // ARABIC FATHA
+ { 0x064F, "afii57455" }, // ARABIC DAMMA
+ { 0x0650, "afii57456" }, // ARABIC KASRA
+ { 0x0651, "afii57457" }, // ARABIC SHADDA
+ { 0x0652, "afii57458" }, // ARABIC SUKUN
+ { 0x0660, "afii57392" }, // ARABIC-INDIC DIGIT ZERO
+ { 0x0661, "afii57393" }, // ARABIC-INDIC DIGIT ONE
+ { 0x0662, "afii57394" }, // ARABIC-INDIC DIGIT TWO
+ { 0x0663, "afii57395" }, // ARABIC-INDIC DIGIT THREE
+ { 0x0664, "afii57396" }, // ARABIC-INDIC DIGIT FOUR
+ { 0x0665, "afii57397" }, // ARABIC-INDIC DIGIT FIVE
+ { 0x0666, "afii57398" }, // ARABIC-INDIC DIGIT SIX
+ { 0x0667, "afii57399" }, // ARABIC-INDIC DIGIT SEVEN
+ { 0x0668, "afii57400" }, // ARABIC-INDIC DIGIT EIGHT
+ { 0x0669, "afii57401" }, // ARABIC-INDIC DIGIT NINE
+ { 0x066A, "afii57381" }, // ARABIC PERCENT SIGN
+ { 0x066D, "afii63167" }, // ARABIC FIVE POINTED STAR
+ { 0x0679, "afii57511" }, // ARABIC LETTER TTEH
+ { 0x067E, "afii57506" }, // ARABIC LETTER PEH
+ { 0x0686, "afii57507" }, // ARABIC LETTER TCHEH
+ { 0x0688, "afii57512" }, // ARABIC LETTER DDAL
+ { 0x0691, "afii57513" }, // ARABIC LETTER RREH
+ { 0x0698, "afii57508" }, // ARABIC LETTER JEH
+ { 0x06A4, "afii57505" }, // ARABIC LETTER VEH
+ { 0x06AF, "afii57509" }, // ARABIC LETTER GAF
+ { 0x06BA, "afii57514" }, // ARABIC LETTER NOON GHUNNA
+ { 0x06D2, "afii57519" }, // ARABIC LETTER YEH BARREE
+ { 0x06D5, "afii57534" }, // ARABIC LETTER AE
+ { 0x1E80, "Wgrave" }, // LATIN CAPITAL LETTER W WITH GRAVE
+ { 0x1E81, "wgrave" }, // LATIN SMALL LETTER W WITH GRAVE
+ { 0x1E82, "Wacute" }, // LATIN CAPITAL LETTER W WITH ACUTE
+ { 0x1E83, "wacute" }, // LATIN SMALL LETTER W WITH ACUTE
+ { 0x1E84, "Wdieresis" }, // LATIN CAPITAL LETTER W WITH DIAERESIS
+ { 0x1E85, "wdieresis" }, // LATIN SMALL LETTER W WITH DIAERESIS
+ { 0x1EF2, "Ygrave" }, // LATIN CAPITAL LETTER Y WITH GRAVE
+ { 0x1EF3, "ygrave" }, // LATIN SMALL LETTER Y WITH GRAVE
+ { 0x200C, "afii61664" }, // ZERO WIDTH NON-JOINER
+ { 0x200D, "afii301" }, // ZERO WIDTH JOINER
+ { 0x200E, "afii299" }, // LEFT-TO-RIGHT MARK
+ { 0x200F, "afii300" }, // RIGHT-TO-LEFT MARK
+ { 0x2012, "figuredash" }, // FIGURE DASH
+ { 0x2013, "endash" }, // EN DASH
+ { 0x2014, "emdash" }, // EM DASH
+ { 0x2015, "afii00208" }, // HORIZONTAL BAR
+ { 0x2017, "underscoredbl" }, // DOUBLE LOW LINE
+ { 0x2018, "quoteleft" }, // LEFT SINGLE TQUOTATION MARK
+ { 0x2019, "quoteright" }, // RIGHT SINGLE TQUOTATION MARK
+ { 0x201A, "quotesinglbase" }, // SINGLE LOW-9 TQUOTATION MARK
+ { 0x201B, "quotereversed" }, // SINGLE HIGH-REVERSED-9 TQUOTATION MARK
+ { 0x201C, "quotedblleft" }, // LEFT DOUBLE TQUOTATION MARK
+ { 0x201D, "quotedblright" }, // RIGHT DOUBLE TQUOTATION MARK
+ { 0x201E, "quotedblbase" }, // DOUBLE LOW-9 TQUOTATION MARK
+ { 0x2020, "dagger" }, // DAGGER
+ { 0x2021, "daggerdbl" }, // DOUBLE DAGGER
+ { 0x2022, "bullet" }, // BULLET
+ { 0x2024, "onedotenleader" }, // ONE DOT LEADER
+ { 0x2025, "twodotenleader" }, // TWO DOT LEADER
+ { 0x2026, "ellipsis" }, // HORIZONTAL ELLIPSIS
+ { 0x202C, "afii61573" }, // POP DIRECTIONAL FORMATTING
+ { 0x202D, "afii61574" }, // LEFT-TO-RIGHT OVERRIDE
+ { 0x202E, "afii61575" }, // RIGHT-TO-LEFT OVERRIDE
+ { 0x2030, "perthousand" }, // PER MILLE SIGN
+ { 0x2032, "minute" }, // PRIME
+ { 0x2033, "second" }, // DOUBLE PRIME
+ { 0x2039, "guilsinglleft" }, // SINGLE LEFT-POINTING ANGLE TQUOTATION MARK
+ { 0x203A, "guilsinglright" }, // SINGLE RIGHT-POINTING ANGLE TQUOTATION MARK
+ { 0x203C, "exclamdbl" }, // DOUBLE EXCLAMATION MARK
+ { 0x2044, "fraction" }, // FRACTION SLASH
+ { 0x2070, "zerosuperior" }, // SUPERSCRIPT ZERO
+ { 0x2074, "foursuperior" }, // SUPERSCRIPT FOUR
+ { 0x2075, "fivesuperior" }, // SUPERSCRIPT FIVE
+ { 0x2076, "sixsuperior" }, // SUPERSCRIPT SIX
+ { 0x2077, "sevensuperior" }, // SUPERSCRIPT SEVEN
+ { 0x2078, "eightsuperior" }, // SUPERSCRIPT EIGHT
+ { 0x2079, "ninesuperior" }, // SUPERSCRIPT NINE
+ { 0x207D, "parenleftsuperior" }, // SUPERSCRIPT LEFT PARENTHESIS
+ { 0x207E, "parenrightsuperior" }, // SUPERSCRIPT RIGHT PARENTHESIS
+ { 0x207F, "nsuperior" }, // SUPERSCRIPT LATIN SMALL LETTER N
+ { 0x2080, "zeroinferior" }, // SUBSCRIPT ZERO
+ { 0x2081, "oneinferior" }, // SUBSCRIPT ONE
+ { 0x2082, "twoinferior" }, // SUBSCRIPT TWO
+ { 0x2083, "threeinferior" }, // SUBSCRIPT THREE
+ { 0x2084, "fourinferior" }, // SUBSCRIPT FOUR
+ { 0x2085, "fiveinferior" }, // SUBSCRIPT FIVE
+ { 0x2086, "sixinferior" }, // SUBSCRIPT SIX
+ { 0x2087, "seveninferior" }, // SUBSCRIPT SEVEN
+ { 0x2088, "eightinferior" }, // SUBSCRIPT EIGHT
+ { 0x2089, "nineinferior" }, // SUBSCRIPT NINE
+ { 0x208D, "parenleftinferior" }, // SUBSCRIPT LEFT PARENTHESIS
+ { 0x208E, "parenrightinferior" }, // SUBSCRIPT RIGHT PARENTHESIS
+ { 0x20A1, "colonmonetary" }, // COLON SIGN
+ { 0x20A3, "franc" }, // FRENCH FRANC SIGN
+ { 0x20A4, "lira" }, // LIRA SIGN
+ { 0x20A7, "peseta" }, // PESETA SIGN
+ { 0x20AA, "afii57636" }, // NEW SHETQEL SIGN
+ { 0x20AB, "dong" }, // DONG SIGN
+ { 0x20AC, "Euro" }, // EURO SIGN
+ { 0x2105, "afii61248" }, // CARE OF
+ { 0x2111, "Ifraktur" }, // BLACK-LETTER CAPITAL I
+ { 0x2113, "afii61289" }, // SCRIPT SMALL L
+ { 0x2116, "afii61352" }, // NUMERO SIGN
+ { 0x2118, "weierstrass" }, // SCRIPT CAPITAL P
+ { 0x211C, "Rfraktur" }, // BLACK-LETTER CAPITAL R
+ { 0x211E, "prescription" }, // PRESCRIPTION TAKE
+ { 0x2122, "trademark" }, // TRADE MARK SIGN
+ { 0x2126, "Omega" }, // OHM SIGN
+ { 0x212E, "estimated" }, // ESTIMATED SYMBOL
+ { 0x2135, "aleph" }, // ALEF SYMBOL
+ { 0x2153, "onethird" }, // VULGAR FRACTION ONE THIRD
+ { 0x2154, "twothirds" }, // VULGAR FRACTION TWO THIRDS
+ { 0x215B, "oneeighth" }, // VULGAR FRACTION ONE EIGHTH
+ { 0x215C, "threeeighths" }, // VULGAR FRACTION THREE EIGHTHS
+ { 0x215D, "fiveeighths" }, // VULGAR FRACTION FIVE EIGHTHS
+ { 0x215E, "seveneighths" }, // VULGAR FRACTION SEVEN EIGHTHS
+ { 0x2190, "arrowleft" }, // LEFTWARDS ARROW
+ { 0x2191, "arrowup" }, // UPWARDS ARROW
+ { 0x2192, "arrowright" }, // RIGHTWARDS ARROW
+ { 0x2193, "arrowdown" }, // DOWNWARDS ARROW
+ { 0x2194, "arrowboth" }, // LEFT RIGHT ARROW
+ { 0x2195, "arrowupdn" }, // UP DOWN ARROW
+ { 0x21A8, "arrowupdnbse" }, // UP DOWN ARROW WITH BASE
+ { 0x21B5, "carriagereturn" }, // DOWNWARDS ARROW WITH CORNER LEFTWARDS
+ { 0x21D0, "arrowdblleft" }, // LEFTWARDS DOUBLE ARROW
+ { 0x21D1, "arrowdblup" }, // UPWARDS DOUBLE ARROW
+ { 0x21D2, "arrowdblright" }, // RIGHTWARDS DOUBLE ARROW
+ { 0x21D3, "arrowdbldown" }, // DOWNWARDS DOUBLE ARROW
+ { 0x21D4, "arrowdblboth" }, // LEFT RIGHT DOUBLE ARROW
+ { 0x2200, "universal" }, // FOR ALL
+ { 0x2202, "partialdiff" }, // PARTIAL DIFFERENTIAL
+ { 0x2203, "existential" }, // THERE EXISTS
+ { 0x2205, "emptyset" }, // EMPTY SET
+ { 0x2206, "Delta" }, // INCREMENT
+ { 0x2207, "gradient" }, // NABLA
+ { 0x2208, "element" }, // ELEMENT OF
+ { 0x2209, "notelement" }, // NOT AN ELEMENT OF
+ { 0x220B, "suchthat" }, // CONTAINS AS MEMBER
+ { 0x220F, "product" }, // N-ARY PRODUCT
+ { 0x2211, "summation" }, // N-ARY SUMMATION
+ { 0x2212, "minus" }, // MINUS SIGN
+ { 0x2215, "fraction" }, // DIVISION SLASH;Duplicate
+ { 0x2217, "asteriskmath" }, // ASTERISK OPERATOR
+ { 0x2219, "periodcentered" }, // BULLET OPERATOR;Duplicate
+ { 0x221A, "radical" }, // STQUARE ROOT
+ { 0x221D, "proportional" }, // PROPORTIONAL TO
+ { 0x221E, "infinity" }, // INFINITY
+ { 0x221F, "orthogonal" }, // RIGHT ANGLE
+ { 0x2220, "angle" }, // ANGLE
+ { 0x2227, "logicaland" }, // LOGICAL AND
+ { 0x2228, "logicalor" }, // LOGICAL OR
+ { 0x2229, "intersection" }, // INTERSECTION
+ { 0x222A, "union" }, // UNION
+ { 0x222B, "integral" }, // INTEGRAL
+ { 0x2234, "therefore" }, // THEREFORE
+ { 0x223C, "similar" }, // TILDE OPERATOR
+ { 0x2245, "congruent" }, // APPROXIMATELY ETQUAL TO
+ { 0x2248, "approxequal" }, // ALMOST ETQUAL TO
+ { 0x2260, "notequal" }, // NOT ETQUAL TO
+ { 0x2261, "equivalence" }, // IDENTICAL TO
+ { 0x2264, "lessequal" }, // LESS-THAN OR ETQUAL TO
+ { 0x2265, "greaterequal" }, // GREATER-THAN OR ETQUAL TO
+ { 0x2282, "propersubset" }, // SUBSET OF
+ { 0x2283, "propersuperset" }, // SUPERSET OF
+ { 0x2284, "notsubset" }, // NOT A SUBSET OF
+ { 0x2286, "reflexsubset" }, // SUBSET OF OR ETQUAL TO
+ { 0x2287, "reflexsuperset" }, // SUPERSET OF OR ETQUAL TO
+ { 0x2295, "circleplus" }, // CIRCLED PLUS
+ { 0x2297, "circlemultiply" }, // CIRCLED TIMES
+ { 0x22A5, "perpendicular" }, // UP TACK
+ { 0x22C5, "dotmath" }, // DOT OPERATOR
+ { 0x2302, "house" }, // HOUSE
+ { 0x2310, "revlogicalnot" }, // REVERSED NOT SIGN
+ { 0x2320, "integraltp" }, // TOP HALF INTEGRAL
+ { 0x2321, "integralbt" }, // BOTTOM HALF INTEGRAL
+ { 0x2329, "angleleft" }, // LEFT-POINTING ANGLE BRACKET
+ { 0x232A, "angleright" }, // RIGHT-POINTING ANGLE BRACKET
+ { 0x2500, "SF100000" }, // BOX DRAWINGS LIGHT HORIZONTAL
+ { 0x2502, "SF110000" }, // BOX DRAWINGS LIGHT VERTICAL
+ { 0x250C, "SF010000" }, // BOX DRAWINGS LIGHT DOWN AND RIGHT
+ { 0x2510, "SF030000" }, // BOX DRAWINGS LIGHT DOWN AND LEFT
+ { 0x2514, "SF020000" }, // BOX DRAWINGS LIGHT UP AND RIGHT
+ { 0x2518, "SF040000" }, // BOX DRAWINGS LIGHT UP AND LEFT
+ { 0x251C, "SF080000" }, // BOX DRAWINGS LIGHT VERTICAL AND RIGHT
+ { 0x2524, "SF090000" }, // BOX DRAWINGS LIGHT VERTICAL AND LEFT
+ { 0x252C, "SF060000" }, // BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
+ { 0x2534, "SF070000" }, // BOX DRAWINGS LIGHT UP AND HORIZONTAL
+ { 0x253C, "SF050000" }, // BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
+ { 0x2550, "SF430000" }, // BOX DRAWINGS DOUBLE HORIZONTAL
+ { 0x2551, "SF240000" }, // BOX DRAWINGS DOUBLE VERTICAL
+ { 0x2552, "SF510000" }, // BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
+ { 0x2553, "SF520000" }, // BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
+ { 0x2554, "SF390000" }, // BOX DRAWINGS DOUBLE DOWN AND RIGHT
+ { 0x2555, "SF220000" }, // BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
+ { 0x2556, "SF210000" }, // BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
+ { 0x2557, "SF250000" }, // BOX DRAWINGS DOUBLE DOWN AND LEFT
+ { 0x2558, "SF500000" }, // BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
+ { 0x2559, "SF490000" }, // BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
+ { 0x255A, "SF380000" }, // BOX DRAWINGS DOUBLE UP AND RIGHT
+ { 0x255B, "SF280000" }, // BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
+ { 0x255C, "SF270000" }, // BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
+ { 0x255D, "SF260000" }, // BOX DRAWINGS DOUBLE UP AND LEFT
+ { 0x255E, "SF360000" }, // BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
+ { 0x255F, "SF370000" }, // BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
+ { 0x2560, "SF420000" }, // BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
+ { 0x2561, "SF190000" }, // BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
+ { 0x2562, "SF200000" }, // BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
+ { 0x2563, "SF230000" }, // BOX DRAWINGS DOUBLE VERTICAL AND LEFT
+ { 0x2564, "SF470000" }, // BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
+ { 0x2565, "SF480000" }, // BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
+ { 0x2566, "SF410000" }, // BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
+ { 0x2567, "SF450000" }, // BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
+ { 0x2568, "SF460000" }, // BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
+ { 0x2569, "SF400000" }, // BOX DRAWINGS DOUBLE UP AND HORIZONTAL
+ { 0x256A, "SF540000" }, // BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
+ { 0x256B, "SF530000" }, // BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
+ { 0x256C, "SF440000" }, // BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
+ { 0x2580, "upblock" }, // UPPER HALF BLOCK
+ { 0x2584, "dnblock" }, // LOWER HALF BLOCK
+ { 0x2588, "block" }, // FULL BLOCK
+ { 0x258C, "lfblock" }, // LEFT HALF BLOCK
+ { 0x2590, "rtblock" }, // RIGHT HALF BLOCK
+ { 0x2591, "ltshade" }, // LIGHT SHADE
+ { 0x2592, "shade" }, // MEDIUM SHADE
+ { 0x2593, "dkshade" }, // DARK SHADE
+ { 0x25A0, "filledbox" }, // BLACK STQUARE
+ { 0x25A1, "H22073" }, // WHITE STQUARE
+ { 0x25AA, "H18543" }, // BLACK SMALL STQUARE
+ { 0x25AB, "H18551" }, // WHITE SMALL STQUARE
+ { 0x25AC, "filledrect" }, // BLACK RECTANGLE
+ { 0x25B2, "triagup" }, // BLACK UP-POINTING TRIANGLE
+ { 0x25BA, "triagrt" }, // BLACK RIGHT-POINTING POINTER
+ { 0x25BC, "triagdn" }, // BLACK DOWN-POINTING TRIANGLE
+ { 0x25C4, "triaglf" }, // BLACK LEFT-POINTING POINTER
+ { 0x25CA, "lozenge" }, // LOZENGE
+ { 0x25CB, "circle" }, // WHITE CIRCLE
+ { 0x25CF, "H18533" }, // BLACK CIRCLE
+ { 0x25D8, "invbullet" }, // INVERSE BULLET
+ { 0x25D9, "invcircle" }, // INVERSE WHITE CIRCLE
+ { 0x25E6, "openbullet" }, // WHITE BULLET
+ { 0x263A, "smileface" }, // WHITE SMILING FACE
+ { 0x263B, "invsmileface" }, // BLACK SMILING FACE
+ { 0x263C, "sun" }, // WHITE SUN WITH RAYS
+ { 0x2640, "female" }, // FEMALE SIGN
+ { 0x2642, "male" }, // MALE SIGN
+ { 0x2660, "spade" }, // BLACK SPADE SUIT
+ { 0x2663, "club" }, // BLACK CLUB SUIT
+ { 0x2665, "heart" }, // BLACK HEART SUIT
+ { 0x2666, "diamond" }, // BLACK DIAMOND SUIT
+ { 0x266A, "musicalnote" }, // EIGHTH NOTE
+ { 0x266B, "musicalnotedbl" }, // BEAMED EIGHTH NOTES
+ // The names below are in the PU area of Unicode, but needed to get a correct mapping of the symbol font
+ { 0xF6D9, "copyrightserif" },
+ { 0xF6DA, "registerserif" },
+ { 0xF6DB, "trademarkserif" },
+ { 0xF8E5, "radicalex" },
+ { 0xF8E6, "arrowvertex" },
+ { 0xF8E7, "arrowhorizex" },
+ { 0xF8E8, "registersans" },
+ { 0xF8E9, "copyrightsans" },
+ { 0xF8EA, "trademarksans" },
+ { 0xF8EB, "parenlefttp" },
+ { 0xF8EC, "parenleftex" },
+ { 0xF8ED, "parenleftbt" },
+ { 0xF8EE, "bracketlefttp" },
+ { 0xF8EF, "bracketleftex" },
+ { 0xF8F0, "bracketleftbt" },
+ { 0xF8F1, "bracelefttp" },
+ { 0xF8F2, "braceleftmid" },
+ { 0xF8F3, "braceleftbt" },
+ { 0xF8F4, "braceex" },
+ { 0xF8F5, "integralex" },
+ { 0xF8F6, "parenrighttp" },
+ { 0xF8F7, "parenrightex" },
+ { 0xF8F8, "parenrightbt" },
+ { 0xF8F9, "bracketrighttp" },
+ { 0xF8FA, "bracketrightex" },
+ { 0xF8FB, "bracketrightbt" },
+ { 0xF8FC, "bracerighttp" },
+ { 0xF8FD, "bracerightmid" },
+ { 0xF8FE, "bracerightbt" },
+ // End of extensions needed for symbols
+ { 0xFB00, "ff" }, // LATIN SMALL LIGATURE FF
+ { 0xFB01, "fi" }, // LATIN SMALL LIGATURE FI
+ { 0xFB02, "fl" }, // LATIN SMALL LIGATURE FL
+ { 0xFB03, "ffi" }, // LATIN SMALL LIGATURE FFI
+ { 0xFB04, "ffl" }, // LATIN SMALL LIGATURE FFL
+ { 0xFB1F, "afii57705" }, // HEBREW LIGATURE YIDDISH YOD YOD PATAH
+ { 0xFB2A, "afii57694" }, // HEBREW LETTER SHIN WITH SHIN DOT
+ { 0xFB2B, "afii57695" }, // HEBREW LETTER SHIN WITH SIN DOT
+ { 0xFB35, "afii57723" }, // HEBREW LETTER VAV WITH DAGESH
+ { 0xFB4B, "afii57700" }, // HEBREW LETTER VAV WITH HOLAM
+ // end of stuff from glyphlist.txt
+ { 0xFFFF, 0 }
+};
+
+// ---------------------------------------------------------------------
+// postscript font substitution dictionary. We assume every postscript printer has at least
+// Helvetica, Times, Courier and Symbol
+
+struct psfont {
+ const char *psname;
+ float slant;
+ float xscale;
+};
+
+static const psfont Arial[] = {
+ {"Arial", 0, 84.04 },
+ { "Arial-Italic", 0, 84.04 },
+ { "Arial-Bold", 0, 88.65 },
+ { "Arial-BoldItalic", 0, 88.65 }
+};
+
+static const psfont AvantGarde[] = {
+ { "AvantGarde-Book", 0, 87.43 },
+ { "AvantGarde-BookOblique", 0, 88.09 },
+ { "AvantGarde-Demi", 0, 88.09 },
+ { "AvantGarde-DemiOblique", 0, 87.43 },
+};
+
+static const psfont Bookman [] = {
+ { "Bookman-Light", 0, 93.78 },
+ { "Bookman-LightItalic", 0, 91.42 },
+ { "Bookman-Demi", 0, 99.86 },
+ { "Bookman-DemiItalic", 0, 101.54 }
+};
+
+static const psfont Charter [] = {
+ { "CharterBT-Roman", 0, 84.04 },
+ { "CharterBT-Italic", 0.0, 81.92 },
+ { "CharterBT-Bold", 0, 88.99 },
+ { "CharterBT-BoldItalic", 0.0, 88.20 }
+};
+
+static const psfont Courier [] = {
+ { "Courier", 0, 100. },
+ { "Courier-Oblique", 0, 100. },
+ { "Courier-Bold", 0, 100. },
+ { "Courier-BoldOblique", 0, 100. }
+};
+
+static const psfont Garamond [] = {
+ { "Garamond-Antiqua", 0, 78.13 },
+ { "Garamond-Kursiv", 0, 78.13 },
+ { "Garamond-Halbfett", 0, 78.13 },
+ { "Garamond-KursivHalbfett", 0, 78.13 }
+};
+
+static const psfont GillSans [] = { // ### some estimated value for xstretch
+ { "GillSans", 0, 82 },
+ { "GillSans-Italic", 0, 82 },
+ { "GillSans-Bold", 0, 82 },
+ { "GillSans-BoldItalic", 0, 82 }
+};
+
+static const psfont Helvetica [] = {
+ { "Helvetica", 0, 84.04 },
+ { "Helvetica-Oblique", 0, 84.04 },
+ { "Helvetica-Bold", 0, 88.65 },
+ { "Helvetica-BoldOblique", 0, 88.65 }
+};
+
+static const psfont Letter [] = {
+ { "LetterGothic", 0, 83.32 },
+ { "LetterGothic-Italic", 0, 83.32 },
+ { "LetterGothic-Bold", 0, 83.32 },
+ { "LetterGothic-Bold", 0.2, 83.32 }
+};
+
+static const psfont LucidaSans [] = {
+ { "LucidaSans", 0, 94.36 },
+ { "LucidaSans-Oblique", 0, 94.36 },
+ { "LucidaSans-Demi", 0, 98.10 },
+ { "LucidaSans-DemiOblique", 0, 98.08 }
+};
+
+static const psfont LucidaSansTT [] = {
+ { "LucidaSans-Typewriter", 0, 100.50 },
+ { "LucidaSans-TypewriterOblique", 0, 100.50 },
+ { "LucidaSans-TypewriterBold", 0, 100.50 },
+ { "LucidaSans-TypewriterBoldOblique", 0, 100.50 }
+};
+
+static const psfont LucidaBright [] = {
+ { "LucidaBright", 0, 93.45 },
+ { "LucidaBright-Italic", 0, 91.98 },
+ { "LucidaBright-Demi", 0, 96.22 },
+ { "LucidaBright-DemiItalic", 0, 96.98 }
+};
+
+static const psfont Palatino [] = {
+ { "Palatino-Roman", 0, 82.45 },
+ { "Palatino-Italic", 0, 76.56 },
+ { "Palatino-Bold", 0, 83.49 },
+ { "Palatino-BoldItalic", 0, 81.51 }
+};
+
+static const psfont Symbol [] = {
+ { "Symbol", 0, 82.56 },
+ { "Symbol", 0.2, 82.56 },
+ { "Symbol", 0, 82.56 },
+ { "Symbol", 0.2, 82.56 }
+};
+
+static const psfont Tahoma [] = {
+ { "Tahoma", 0, 83.45 },
+ { "Tahoma", 0.2, 83.45 },
+ { "Tahoma-Bold", 0, 95.59 },
+ { "Tahoma-Bold", 0.2, 95.59 }
+};
+
+static const psfont Times [] = {
+ { "Times-Roman", 0, 82.45 },
+ { "Times-Italic", 0, 82.45 },
+ { "Times-Bold", 0, 82.45 },
+ { "Times-BoldItalic", 0, 82.45 }
+};
+
+static const psfont Verdana [] = {
+ { "Verdana", 0, 96.06 },
+ { "Verdana-Italic", 0, 96.06 },
+ { "Verdana-Bold", 0, 107.12 },
+ { "Verdana-BoldItalic", 0, 107.10 }
+};
+
+static const psfont Utopia [] = { // ###
+ { "Utopia-Regular", 0, 84.70 },
+ { "Utopia-Regular", 0.2, 84.70 },
+ { "Utopia-Bold", 0, 88.01 },
+ { "Utopia-Bold", 0.2, 88.01 }
+};
+
+static const psfont * const SansSerifReplacements[] = {
+ Helvetica, 0
+ };
+static const psfont * const SerifReplacements[] = {
+ Times, 0
+ };
+static const psfont * const FixedReplacements[] = {
+ Courier, 0
+ };
+static const psfont * const TahomaReplacements[] = {
+ Verdana, AvantGarde, Helvetica, 0
+ };
+static const psfont * const VerdanaReplacements[] = {
+ Tahoma, AvantGarde, Helvetica, 0
+ };
+
+static const struct {
+ const char * input; // spaces are stripped in here, and everything lowercase
+ const psfont * ps;
+ const psfont *const * tqreplacements;
+} postscriptFonts [] = {
+ { "arial", Arial, SansSerifReplacements },
+ { "arialmt", Arial, SansSerifReplacements },
+ { "arialtqunicodems", Arial, SansSerifReplacements },
+ { "avantgarde", AvantGarde, SansSerifReplacements },
+ { "bookman", Bookman, SerifReplacements },
+ { "charter", Charter, SansSerifReplacements },
+ { "bitstreamcharter", Charter, SansSerifReplacements },
+ { "bitstreamcyberbit", Times, SerifReplacements }, // ###
+ { "courier", Courier, 0 },
+ { "couriernew", Courier, 0 },
+ { "fixed", Courier, 0 },
+ { "garamond", Garamond, SerifReplacements },
+ { "gillsans", GillSans, SansSerifReplacements },
+ { "helvetica", Helvetica, 0 },
+ { "letter", Letter, FixedReplacements },
+ { "lucida", LucidaSans, SansSerifReplacements },
+ { "lucidasans", LucidaSans, SansSerifReplacements },
+ { "lucidabright", LucidaBright, SerifReplacements },
+ { "lucidasanstypewriter", LucidaSansTT, FixedReplacements },
+ { "luciduxsans", LucidaSans, SansSerifReplacements },
+ { "luciduxserif", LucidaBright, SerifReplacements },
+ { "luciduxmono", LucidaSansTT, FixedReplacements },
+ { "palatino", Palatino, SerifReplacements },
+ { "symbol", Symbol, 0 },
+ { "tahoma", Tahoma, TahomaReplacements },
+ { "terminal", Courier, 0 },
+ { "times", Times, 0 },
+ { "timesnewroman", Times, 0 },
+ { "verdana", Verdana, VerdanaReplacements },
+ { "utopia", Utopia, SerifReplacements },
+ { 0, 0, 0 }
+};
+
+
+// ------------------------------End of static data ----------------------------------
+
+// make sure DSC comments are not longer than 255 chars per line.
+static TQString wrapDSC( const TQString &str )
+{
+ TQString dsc = str.simplifyWhiteSpace();
+ const uint wrapAt = 254;
+ TQString wrapped;
+ if ( dsc.length() < wrapAt )
+ wrapped = dsc;
+ else {
+ wrapped = dsc.left( wrapAt );
+ TQString tmp = dsc.mid( wrapAt );
+ while ( tmp.length() > wrapAt-3 ) {
+ wrapped += "\n%%+" + tmp.left( wrapAt-3 );
+ tmp = tmp.mid( wrapAt-3 );
+ }
+ wrapped += "\n%%+" + tmp;
+ }
+ return wrapped + "\n";
+}
+
+static TQString toString( const float num )
+{
+ return TQString::number( num, 'f', 3 );
+}
+
+// ----------------------------- Internal class declarations -----------------------------
+
+class TQPSPrinterFontPrivate;
+
+class TQPSPrinterPrivate {
+public:
+ TQPSPrinterPrivate( TQPrinter *prt, int filedes );
+ ~TQPSPrinterPrivate();
+
+ void matrixSetup( TQPainter * );
+ void clippingSetup( TQPainter * );
+ void setClippingOff( TQPainter * );
+ void orientationSetup();
+ void resetDrawingTools( TQPainter * );
+ void emitHeader( bool finished );
+ void setFont( const TQFont &, int script );
+ void drawImage( TQPainter *, float x, float y, float w, float h, const TQImage &img, const TQImage &tqmask );
+ void initPage( TQPainter *paint );
+ void flushPage( bool last = FALSE );
+
+ TQPrinter *printer;
+ int pageCount;
+ bool dirtyMatrix;
+ bool dirtyNewPage;
+ bool epsf;
+ TQString fontsUsed;
+
+ // outstream is the stream the build up pages are copied to. It points to buffer
+ // at the start, and is reset to use the outDevice after emitHeader has been called.
+ TQTextStream outStream;
+
+ // stores the descriptions of the first pages. outStream operates on this buffer
+ // until we call emitHeader
+ TQBuffer *buffer;
+ int pagesInBuffer;
+
+ // the tqdevice the output is in the end streamed to.
+ TQIODevice * outDevice;
+ int fd;
+
+ // buffer for the current page. Needed becaus we might have page fonts.
+ TQBuffer *pageBuffer;
+ TQTextStream pageStream;
+
+ TQDict<TQString> headerFontNames;
+ TQDict<TQString> pageFontNames;
+ TQDict<TQPSPrinterFontPrivate> fonts;
+ TQPSPrinterFontPrivate *currentFontFile;
+ int headerFontNumber;
+ int pageFontNumber;
+ TQBuffer * fontBuffer;
+ TQTextStream fontStream;
+ bool dirtyClipping;
+ bool firstClipOnPage;
+ TQRect boundingBox;
+ TQImage * savedImage;
+ TQPen cpen;
+ TQBrush cbrush;
+ bool dirtypen;
+ bool dirtybrush;
+ TQColor bkColor;
+ bool dirtyBkColor;
+ TQt::BGMode bkMode;
+ bool dirtyBkMode;
+#ifndef TQT_NO_TEXTCODEC
+ TQTextCodec * currentFontCodec;
+#endif
+ TQString currentFont;
+ TQFontMetrics fm;
+ int textY;
+ TQFont currentUsed;
+ int scriptUsed;
+ TQFont currentSet;
+ float scale;
+
+ TQStringList fontpath;
+};
+
+
+class TQPSPrinterFontPrivate {
+public:
+ TQPSPrinterFontPrivate();
+ virtual ~TQPSPrinterFontPrivate() {}
+ virtual TQString postScriptFontName() { return psname; }
+ virtual TQString defineFont( TQTextStream &stream, const TQString &ps, const TQFont &f, const TQString &key,
+ TQPSPrinterPrivate *d );
+ virtual void download(TQTextStream& s, bool global);
+ virtual void drawText( TQTextStream &stream, const TQPoint &p, TQTextEngine *engine, int item,
+ const TQString &text, TQPSPrinterPrivate *d, TQPainter *paint);
+ virtual unsigned short mapUnicode( unsigned short tqunicode );
+ void downloadMapping( TQTextStream &s, bool global );
+ TQString glyphName( unsigned short glyphindex, bool *glyphSet = 0 );
+ virtual void restore();
+
+ virtual unsigned short tqunicode_for_glyph(int glyphindex) { return glyphindex; }
+ virtual unsigned short glyph_for_tqunicode(unsigned short tqunicode) { return tqunicode; }
+ unsigned short insertIntoSubset( unsigned short tqunicode );
+ virtual bool embedded() { return FALSE; }
+
+ bool operator == ( const TQPSPrinterFontPrivate &other ) {
+ return other.psname == psname;
+ }
+ inline void setSymbol() { symbol = TRUE; }
+
+protected:
+ TQString psname;
+ TQStringList tqreplacementList;
+
+ TQMap<unsigned short, unsigned short> subset; // tqunicode subset in the global font
+ TQMap<unsigned short, unsigned short> page_subset; // subset added in this page
+ int subsetCount;
+ int pageSubsetCount;
+ bool global_dict;
+ bool downloaded;
+ bool symbol;
+};
+
+// ------------------- end of class declarations ---------------------------
+
+// --------------------------------------------------------------
+// beginning of font related methods
+// --------------------------------------------------------------
+
+
+static int getPsFontType( const TQFontEngine *fe )
+{
+ int weight = fe->fontDef.weight;
+ bool italic = fe->fontDef.italic;
+
+ int type = 0; // used to look up in the psname array
+ // get the right modification, or build something
+ if ( weight > TQFont::Normal && italic )
+ type = 3;
+ else if ( weight > TQFont::Normal )
+ type = 2;
+ else if ( italic )
+ type = 1;
+ return type;
+}
+
+static int addPsFontNameExtension( const TQFontEngine *fe, TQString &ps, const psfont *psf = 0 )
+{
+ int type = getPsFontType( fe );
+
+ if ( psf ) {
+ ps = TQString::tqfromLatin1( psf[type].psname );
+ } else {
+ switch ( type ) {
+ case 1:
+ ps.append( TQString::tqfromLatin1("-Italic") );
+ break;
+ case 2:
+ ps.append( TQString::tqfromLatin1("-Bold") );
+ break;
+ case 3:
+ ps.append( TQString::tqfromLatin1("-BoldItalic") );
+ break;
+ case 0:
+ default:
+ break;
+ }
+ }
+ return type;
+}
+
+static TQString makePSFontName( const TQFontEngine *fe, int *listpos = 0, int *ftype = 0 )
+{
+ TQString ps;
+ int i;
+
+ TQString family = fe->fontDef.family.lower();
+
+ // try to make a "good" postscript name
+ ps = family.simplifyWhiteSpace();
+ i = 0;
+ while( (unsigned int)i < ps.length() ) {
+ if ( i != 0 && ps[i] == '[') {
+ if ( ps[i-1] == ' ' )
+ ps.truncate (i-1);
+ else
+ ps.truncate (i);
+ break;
+ }
+ if ( i == 0 || ps[i-1] == ' ' ) {
+ ps[i] = ps[i].upper();
+ if ( i )
+ ps.remove( i-1, 1 );
+ else
+ i++;
+ } else {
+ i++;
+ }
+ }
+
+ if ( ps.isEmpty() )
+ ps = "Helvetica";
+
+ // see if the table has a better name
+ i = 0;
+ TQString lowerName = ps.lower();
+ while( postscriptFonts[i].input &&
+ postscriptFonts[i].input != lowerName )
+ i++;
+ const psfont *psf = postscriptFonts[i].ps;
+
+ int type = addPsFontNameExtension( fe, ps, psf );
+
+ if ( listpos )
+ *listpos = i;
+ if ( ftype )
+ *ftype = type;
+ return ps;
+}
+
+static void appendReplacements( TQStringList &list, const psfont * const * tqreplacements, int type, float xscale = 100. )
+{
+ // iterate through the tqreplacement fonts
+ while ( *tqreplacements ) {
+ const psfont *psf = *tqreplacements;
+ TQString ps = "[ /" + TQString::tqfromLatin1( psf[type].psname ) + " " +
+ toString( xscale / psf[type].xscale ) + " " +
+ toString( psf[type].slant ) + " ]";
+ list.append( ps );
+ ++tqreplacements;
+ }
+}
+
+static TQStringList makePSFontNameList( const TQFontEngine *fe, const TQString &psname = TQString::null, bool useNameForLookup = FALSE )
+{
+ int i;
+ int type;
+ TQStringList list;
+ TQString ps = psname;
+
+ if ( !ps.isEmpty() && !useNameForLookup ) {
+ TQString best = "[ /" + ps + " 1.0 0.0 ]";
+ list.append( best );
+ }
+
+ ps = makePSFontName( fe, &i, &type );
+
+ const psfont *psf = postscriptFonts[i].ps;
+ const psfont * const * tqreplacements = postscriptFonts[i].tqreplacements;
+ float xscale = 100;
+ if ( psf ) {
+ // xscale for the "right" font is always 1. We scale the tqreplacements...
+ xscale = psf->xscale;
+ ps = "[ /" + TQString::tqfromLatin1( psf[type].psname ) + " 1.0 " +
+ toString( psf[type].slant ) + " ]";
+ } else {
+ ps = "[ /" + ps + " 1.0 0.0 ]";
+ // only add default tqreplacement fonts in case this font was unknown.
+ if ( fe->fontDef.fixedPitch ) {
+ tqreplacements = FixedReplacements;
+ } else {
+ tqreplacements = SansSerifReplacements;
+ // 100 is courier, but most fonts are not as wide as courier. Using 100
+ // here would make letters overlap for some fonts. This value is empirical.
+ xscale = 83;
+ }
+ }
+ list.append( ps );
+
+ if ( tqreplacements )
+ appendReplacements( list, tqreplacements, type, xscale);
+ return list;
+}
+
+static void emitPSFontNameList( TQTextStream &s, const TQString &psname, const TQStringList &list )
+{
+ s << "/" << psname << "List [\n";
+ s << list.join("\n ");
+ s << "\n] d\n";
+}
+
+static inline float pointSize( const TQFont &f, float scale )
+{
+ float psize;
+ if ( f.pointSize() != -1 )
+ psize = f.pointSize()/scale;
+ else
+ psize = f.pixelSize();
+ return psize;
+}
+
+
+// ========================== FONT CLASSES ===============
+
+
+TQPSPrinterFontPrivate::TQPSPrinterFontPrivate()
+{
+ global_dict = FALSE;
+ downloaded = FALSE;
+ symbol = FALSE;
+ // map 0 to .notdef
+ subset.insert( 0, 0 );
+ subsetCount = 1;
+ pageSubsetCount = 0;
+}
+
+unsigned short TQPSPrinterFontPrivate::insertIntoSubset( unsigned short u )
+{
+ unsigned short retval = 0;
+ if ( subset.tqfind(u) == subset.end() ) {
+ if ( !downloaded ) { // we need to add to the page subset
+ subset.insert( u, subsetCount ); // mark it as used
+ //printf("GLOBAL SUBSET ADDED %04x = %04x\n",u, subsetCount);
+ retval = subsetCount;
+ subsetCount++;
+ } else if ( page_subset.tqfind(u) == page_subset.end() ) {
+ page_subset.insert( u, pageSubsetCount ); // mark it as used
+ //printf("PAGE SUBSET ADDED %04x = %04x\n",u, pageSubsetCount);
+ retval = pageSubsetCount + (subsetCount/256 + 1) * 256;
+ pageSubsetCount++;
+ }
+ } else {
+ qWarning("TQPSPrinterFont::internal error");
+ }
+ return retval;
+}
+
+void TQPSPrinterFontPrivate::restore()
+{
+ page_subset.clear();
+ pageSubsetCount = 0;
+ //qDebug("restore for font %s\n",psname.latin1());
+}
+
+static inline const char *toHex( uchar u )
+{
+ static char hexVal[3];
+ int i = 1;
+ while ( i >= 0 ) {
+ ushort hex = (u & 0x000f);
+ if ( hex < 0x0a )
+ hexVal[i] = '0'+hex;
+ else
+ hexVal[i] = 'A'+(hex-0x0a);
+ u = u >> 4;
+ i--;
+ }
+ hexVal[2] = '\0';
+ return hexVal;
+}
+
+static inline const char *toHex( ushort u )
+{
+ static char hexVal[5];
+ int i = 3;
+ while ( i >= 0 ) {
+ ushort hex = (u & 0x000f);
+ if ( hex < 0x0a )
+ hexVal[i] = '0'+hex;
+ else
+ hexVal[i] = 'A'+(hex-0x0a);
+ u = u >> 4;
+ i--;
+ }
+ hexVal[4] = '\0';
+ return hexVal;
+}
+
+static inline const char * toInt( int i )
+{
+ static char intVal[20];
+ intVal[19] = 0;
+ int pos = 19;
+ if ( i == 0 ) {
+ intVal[--pos] = '0';
+ } else {
+ bool neg = FALSE;
+ if ( i < 0 ) {
+ neg = TRUE;
+ i = -i;
+ }
+ while ( i ) {
+ int dec = i%10;
+ intVal[--pos] = '0'+dec;
+ i /= 10;
+ }
+ if ( neg )
+ intVal[--pos] = '-';
+ }
+ return intVal+pos;
+}
+
+void TQPSPrinterFontPrivate::drawText( TQTextStream &stream, const TQPoint &p, TQTextEngine *engine, int item,
+ const TQString &text, TQPSPrinterPrivate *d, TQPainter *paint)
+{
+ int len = engine->length( item );
+ TQScriptItem &si = engine->items[item];
+
+ int x = p.x() + si.x;
+ int y = p.y() + si.y;
+ if ( y != d->textY || d->textY == 0 )
+ stream << y << " Y";
+ d->textY = y;
+
+ stream << "<";
+ if ( si.analysis.bidiLevel % 2 ) {
+ for ( int i = len-1; i >=0; i-- )
+ stream << toHex( mapUnicode(text.tqunicode()[i].tqunicode()) );
+ } else {
+ for ( int i = 0; i < len; i++ )
+ stream << toHex( mapUnicode(text.tqunicode()[i].tqunicode()) );
+ }
+ stream << ">";
+
+ stream << si.width << " " << x;
+
+ if ( paint->font().underline() )
+ stream << ' ' << y + d->fm.underlinePos() + d->fm.lineWidth()
+ << " " << d->fm.lineWidth() << " Tl";
+ if ( paint->font().strikeOut() )
+ stream << ' ' << y + d->fm.strikeOutPos()
+ << " " << d->fm.lineWidth() << " Tl";
+ stream << " AT\n";
+
+}
+
+
+TQString TQPSPrinterFontPrivate::defineFont( TQTextStream &stream, const TQString &ps, const TQFont &f, const TQString &key,
+ TQPSPrinterPrivate *d )
+{
+ TQString fontName;
+ fontName.sprintf( "/%s-Uni", ps.latin1());
+
+ if ( d->buffer ) {
+ ++d->headerFontNumber;
+ d->fontStream << "/F" << d->headerFontNumber << " "
+ << pointSize( f, d->scale ) << fontName << " DF\n";
+ fontName.sprintf( "F%d", d->headerFontNumber );
+ d->headerFontNames.insert( key, new TQString( fontName ) );
+ } else {
+ ++d->pageFontNumber;
+ stream << "/F" << d->pageFontNumber << " "
+ << pointSize( f, d->scale ) << fontName << " DF\n";
+ fontName.sprintf( "F%d", d->pageFontNumber );
+ d->pageFontNames.insert( key, new TQString( fontName ) );
+ }
+ return fontName;
+}
+
+unsigned short TQPSPrinterFontPrivate::mapUnicode( unsigned short tqunicode )
+{
+ TQMap<unsigned short, unsigned short>::iterator res;
+ res = subset.tqfind( tqunicode );
+ unsigned short offset = 0;
+ bool found = FALSE;
+ if ( res != subset.end() ) {
+ found = TRUE;
+ } else {
+ if ( downloaded ) {
+ res = page_subset.tqfind( tqunicode );
+ offset = (subsetCount/256 + 1) * 256;
+ if ( res != page_subset.end() )
+ found = TRUE;
+ }
+ }
+ if ( !found ) {
+ return insertIntoSubset( tqunicode );
+ }
+ //qDebug("mapping tqunicode %x to %x", tqunicode, offset+*res);
+ return offset + *res;
+}
+
+// This map is used for symbol fonts to get the correct glyph names for the latin range
+static const unsigned short symbol_map[0x100] = {
+ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
+ 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
+ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
+ 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
+ 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220b,
+ 0x0028, 0x0029, 0x2217, 0x002b, 0x002c, 0x2212, 0x002e, 0x002f,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
+
+ 0x2245, 0x0391, 0x0392, 0x03a7, 0x0394, 0x0395, 0x03a6, 0x0393,
+ 0x0397, 0x0399, 0x03d1, 0x039a, 0x039b, 0x039c, 0x039d, 0x039f,
+ 0x03a0, 0x0398, 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03c2, 0x03a9,
+ 0x039e, 0x03a8, 0x0396, 0x005b, 0x2234, 0x005d, 0x22a5, 0x005f,
+ 0xf8e5, 0x03b1, 0x03b2, 0x03c7, 0x03b4, 0x03b5, 0x03c6, 0x03b3,
+ 0x03b7, 0x03b9, 0x03d5, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03bf,
+ 0x03c0, 0x03b8, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03d6, 0x03c9,
+ 0x03be, 0x03c8, 0x03b6, 0x007b, 0x007c, 0x007d, 0x223c, 0x007f,
+
+ 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
+ 0x20ac, 0x03d2, 0x2023, 0x2264, 0x2044, 0x221e, 0x0192, 0x2263,
+ 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193,
+ 0x00b0, 0x00b1, 0x2033, 0x2265, 0x00d7, 0x221d, 0x2202, 0x2022,
+ 0x00f7, 0x2260, 0x2261, 0x2248, 0x2026, 0xf8e6, 0xf8e7, 0x21b5,
+
+ 0x2135, 0x2111, 0x211c, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229,
+ 0x222a, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209,
+ 0x2220, 0x2207, 0xf6da, 0xf6d9, 0xf6db, 0x220f, 0x221a, 0x22c5,
+ 0x00ac, 0x2227, 0x2228, 0x21d4, 0x21d0, 0x21d1, 0x21d2, 0x21d3,
+ 0x25ca, 0x2329, 0xf8e8, 0xf8e9, 0xf8ea, 0x2211, 0xf8eb, 0xf8ec,
+ 0xf8ed, 0xf8ee, 0xf8ef, 0xf8f0, 0xf8f1, 0xf8f2, 0xf8f3, 0xf8f4,
+ 0x0000, 0x232a, 0x222b, 0x2320, 0xf8f5, 0x2321, 0xf8f6, 0xf8f7,
+ 0xf8f8, 0xf8f9, 0xf8fa, 0xf8fb, 0xf8fc, 0xf8fd, 0xf8fe, 0x0000,
+};
+
+TQString TQPSPrinterFontPrivate::glyphName( unsigned short glyphindex, bool *glyphSet )
+{
+ TQString glyphname;
+ int l = 0;
+ unsigned short tqunicode = tqunicode_for_glyph( glyphindex );
+ if (symbol && tqunicode < 0x100) {
+ // map from latin1 to symbol
+ tqunicode = symbol_map[tqunicode];
+ }
+ if ( !tqunicode && glyphindex ) {
+ glyphname = "gl";
+ glyphname += toHex( glyphindex );
+ } else {
+ while( tqunicodetoglyph[l].u < tqunicode )
+ l++;
+ if ( tqunicodetoglyph[l].u == tqunicode ) {
+ glyphname = tqunicodetoglyph[l].g;
+ if ( glyphSet ) {
+ int other = 0;
+ switch ( tqunicode ) {
+ // some glyph names are duplicate in postscript. Make sure we give the
+ // duplicate a different name to avoid infinite recursion
+ case 0x0394:
+ other = 0x2206;
+ break;
+ case 0x03a9:
+ other = 0x2126;
+ break;
+ case 0x0162:
+ other = 0x021a;
+ break;
+ case 0x2215:
+ other = 0x2044;
+ break;
+ case 0x00ad:
+ other = 0x002d;
+ break;
+ case 0x02c9:
+ other = 0x00af;
+ break;
+ case 0x03bc:
+ other = 0x00b5;
+ break;
+ case 0x2219:
+ other = 0x00b7;
+ break;
+ case 0x00a0:
+ other = 0x0020;
+ break;
+ case 0x0163:
+ other = 0x021b;
+ break;
+ default:
+ break;
+ }
+ if ( other ) {
+ int oglyph = glyph_for_tqunicode( other );
+ if( oglyph && oglyph != glyphindex && glyphSet[oglyph] ) {
+ glyphname = "uni";
+ glyphname += toHex( tqunicode );
+ }
+ }
+ }
+ } else {
+ glyphname = "uni";
+ glyphname += toHex( tqunicode );
+ }
+ }
+ return glyphname;
+}
+
+void TQPSPrinterFontPrivate::download(TQTextStream &s, bool global)
+{
+ //printf("defining mapping for printer font %s\n",psname.latin1());
+ downloadMapping( s, global );
+}
+
+void TQPSPrinterFontPrivate::downloadMapping( TQTextStream &s, bool global )
+{
+ uchar rangeOffset = 0;
+ uchar numRanges = (uchar)(subsetCount/256 + 1);
+ uchar range;
+ TQMap<unsigned short, unsigned short> *subsetDict = &subset;
+ if ( !global ) {
+ rangeOffset = numRanges;
+ numRanges = pageSubsetCount/256 + 1;
+ subsetDict = &page_subset;
+ }
+ // build up inverse table
+ unsigned short *inverse = new unsigned short[numRanges * 256];
+ memset( inverse, 0, numRanges * 256 * sizeof( unsigned short ) );
+
+ TQMap<unsigned short, unsigned short>::iterator it;
+ for ( it = subsetDict->begin(); it != subsetDict->end(); ++it) {
+ const unsigned short &mapped = *it;
+ inverse[mapped] = it.key();
+ }
+
+ TQString vector;
+ TQString glyphname;
+
+ for (range=0; range < numRanges; range++) {
+ //printf("outputing range %04x\n",range*256);
+ vector = "%% Font Page ";
+ vector += toHex((uchar)(range + rangeOffset));
+ vector += "\n/";
+ vector += psname;
+ vector += "-ENC-";
+ vector += toHex((uchar)(range + rangeOffset));
+ vector += " [\n";
+
+ TQString line;
+ for(int k=0; k<256; k++ ) {
+ int c = range*256 + k;
+ unsigned short glyph = inverse[c];
+ glyphname = glyphName( glyph );
+ if ( line.length() + glyphname.length() > 76 ) {
+ vector += line;
+ vector += "\n";
+ line = "";
+ }
+ line += "/" + glyphname;
+ }
+ vector += line;
+ vector += "] def\n";
+ s << vector;
+ }
+
+ delete [] inverse;
+
+ // DEFINE BASE FONTS
+
+ for (range=0; range < numRanges; range++) {
+ s << "/";
+ s << psname;
+ s << "-Uni-";
+ s << toHex((uchar)(range + rangeOffset));
+ s << " ";
+ s << psname;
+ s << "-ENC-";
+ s << toHex((uchar)(range + rangeOffset));
+ if ( embedded() && embedFonts ) {
+ s << " /";
+ s << psname;
+ s << " MFEmb\n";
+ } else {
+ s << " " << psname << "List";
+ s << " MF\n";
+ }
+ }
+
+ // === write header ===
+ // int VMMin;
+ // int VMMax;
+
+ s << wrapDSC( "%%BeginFont: " + psname )
+ << "%!PS-AdobeFont-1.0 Composite Font\n"
+ << wrapDSC( "%%FontName: " + psname + "-Uni" )
+ << "%%Creator: Composite font created by TQt\n";
+
+ /* Start the dictionary which will eventually */
+ /* become the font. */
+ s << "25 dict begin\n"; // need to verify. Sivan
+
+ s << "/FontName /";
+ s << psname;
+ s << "-Uni";
+ s << " def\n";
+ s << "/PaintType 0 def\n";
+
+ // This is concatenated with the base fonts, so it should perform
+ // no transformation. Sivan
+ s << "/FontMatrix[1 0 0 1 0 0]def\n";
+
+ s << "/FontType ";
+ s << 0;
+ s << " def\n";
+
+ // now come composite font structures
+ // FMapTypes:
+ // 2: 8/8, 8 bits select the font, 8 the glyph
+
+ s << "/FMapType 2 def\n";
+
+ // The encoding in a composite font is used for indirection.
+ // Every char is split into a font-number and a character-selector.
+ // PostScript prints glyph number character-selector from the font
+ // FDepVector[ Encoding[ font-number ] ].
+
+ s << "/Encoding [";
+ for (range=0; range < rangeOffset + numRanges; range++) {
+ if (range % 16 == 0)
+ s << "\n";
+ else
+ s << " ";
+ s << range;
+ }
+ s << "]def\n";
+
+ // Descendent fonts
+
+ s << "/FDepVector [\n";
+ for (range=0; range < rangeOffset + numRanges; range++) {
+ s << "/";
+ s << psname;
+ s << "-Uni-";
+ s << toHex( range );
+ s << " tqfindfont\n";
+ }
+ s << "]def\n";
+
+ // === trailer ===
+
+ s << "FontName currentdict end definefont pop\n";
+ s << "%%EndFont\n";
+}
+
+
+// ================== TTF ====================
+
+typedef TQ_UINT8 BYTE;
+typedef TQ_UINT16 USHORT;
+typedef TQ_UINT16 uFWord;
+typedef TQ_INT16 SHORT;
+typedef TQ_INT16 FWord;
+typedef TQ_UINT32 ULONG;
+typedef TQ_INT32 FIXED;
+
+typedef struct {
+ TQ_INT16 whole;
+ TQ_UINT16 fraction;
+} Fixed; // 16.16 bit fixed-point number
+
+static float f2dot14( ushort s )
+{
+ float f = ((float)( s & 0x3fff ))/ 16384.;
+ f += (s & 0x8000) ? ( (s & 0x4000) ? -1 : -2 ) : ( (s & 0x4000) ? 1 : 0 );
+ return f;
+}
+
+typedef struct {
+ int* epts_ctr; /* array of contour endpoints */
+ int num_pts, num_ctr; /* number of points, number of coutours */
+ FWord* xcoor, *ycoor; /* arrays of x and y coordinates */
+ BYTE* tt_flags; /* array of TrueType flags */
+ double* area_ctr;
+ char* check_ctr;
+ int* ctrset; /* in contour index followed by out contour index */
+} charproc_data;
+
+
+class TQPSPrinterFontTTF
+ : public TQPSPrinterFontPrivate {
+public:
+ TQPSPrinterFontTTF(const TQFontEngine *f, TQByteArray& data);
+ virtual void download(TQTextStream& s, bool global);
+ virtual void drawText( TQTextStream &stream, const TQPoint &p, TQTextEngine *engine, int item,
+ const TQString &text, TQPSPrinterPrivate *d, TQPainter *paint);
+ // virtual ~TQPSPrinterFontTTF();
+
+ virtual bool embedded() { return TRUE; }
+private:
+ TQByteArray data;
+ TQMemArray<ushort> uni2glyph; // to speed up lookups
+ TQMemArray<ushort> glyph2uni; // to speed up lookups
+ bool defective; // if we can't process this file
+
+ BYTE* getTable(const char *);
+ void uni2glyphSetup();
+ unsigned short tqunicode_for_glyph(int glyphindex);
+ unsigned short glyph_for_tqunicode(unsigned short tqunicode);
+ int topost(FWord x) { return (int)( ((int)(x) * 1000 + HUPM) / unitsPerEm ); }
+
+#ifdef TQ_PRINTER_USE_TYPE42
+ void sfnts_pputBYTE(BYTE n,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string);
+ void sfnts_pputUSHORT(USHORT n,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string);
+ void sfnts_pputULONG(ULONG n,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string);
+ void sfnts_end_string(TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string);
+ void sfnts_new_table(ULONG length,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string);
+ void sfnts_glyf_table(ULONG oldoffset,
+ ULONG correct_total_length,
+ TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string);
+ void download_sfnts(TQTextStream& s);
+#endif
+
+ void subsetGlyph(int charindex,bool* glyphset);
+
+ void charproc(int charindex, TQTextStream& s, bool *glyphSet);
+ BYTE* charprocFindGlyphData(int charindex);
+ void charprocComposite(BYTE *glyph, TQTextStream& s, bool *glyphSet);
+ void charprocLoad(BYTE *glyph, charproc_data* cd);
+
+ int target_type; /* 42 or 3 */
+
+ int numTables; /* number of tables present */
+ TQString PostName; /* Font's PostScript name */
+ TQString FullName; /* Font's full name */
+ TQString FamilyName; /* Font's family name */
+ TQString Style; /* Font's style string */
+ TQString Copyright; /* Font's copyright string */
+ TQString Version; /* Font's version string */
+ TQString Trademark; /* Font's trademark string */
+ int llx,lly,urx,ury; /* bounding box */
+
+ Fixed TTVersion; /* Truetype version number from offset table */
+ Fixed MfrRevision; /* Revision number of this font */
+
+ BYTE *offset_table; /* Offset table in memory */
+ BYTE *post_table; /* 'post' table in memory */
+
+ BYTE *loca_table; /* 'loca' table in memory */
+ BYTE *glyf_table; /* 'glyf' table in memory */
+ BYTE *hmtx_table; /* 'hmtx' table in memory */
+
+ USHORT numberOfHMetrics;
+ int unitsPerEm; /* unitsPerEm converted to int */
+ int HUPM; /* half of above */
+
+ int numGlyphs; /* from 'post' table */
+
+ int indexToLocFormat; /* short or long offsets */
+
+};
+
+
+static ULONG getULONG(BYTE *p)
+{
+ int x;
+ ULONG val=0;
+
+ for(x=0; x<4; x++) {
+ val *= 0x100;
+ val += p[x];
+ }
+
+ return val;
+}
+
+static USHORT getUSHORT(BYTE *p)
+{
+ int x;
+ USHORT val=0;
+
+ for(x=0; x<2; x++) {
+ val *= 0x100;
+ val += p[x];
+ }
+
+ return val;
+}
+
+static Fixed getFixed(BYTE *s)
+{
+ Fixed val={0,0};
+
+ val.whole = ((s[0] * 256) + s[1]);
+ val.fraction = ((s[2] * 256) + s[3]);
+
+ return val;
+}
+
+static FWord getFWord(BYTE* s) { return (FWord) getUSHORT(s); }
+static uFWord getuFWord(BYTE* s) { return (uFWord) getUSHORT(s); }
+static SHORT getSHORT(BYTE* s) { return (SHORT) getUSHORT(s); }
+
+#if 0
+static const char * const Apple_CharStrings[]={
+ ".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign",
+ "dollar","percent","ampersand","quotesingle","parenleft","parenright",
+ "asterisk","plus", "comma","hyphen","period","slash","zero","one","two",
+ "three","four","five","six","seven","eight","nine","colon","semicolon",
+ "less","equal","greater","question","at","A","B","C","D","E","F","G","H","I",
+ "J","K", "L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
+ "bracketleft","backslash","bracketright","asciicircum","underscore","grave",
+ "a","b","c","d","e","f","g","h","i","j","k", "l","m","n","o","p","q","r","s",
+ "t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde",
+ "Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis",
+ "aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla",
+ "eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex",
+ "idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde",
+ "uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent",
+ "sterling","section","bullet","paragraph","germandbls","registered",
+ "copyright","trademark","acute","dieresis","notequal","AE","Oslash",
+ "infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff",
+ "summation","product","pi","integral","ordfeminine","ordmasculine","Omega",
+ "ae","oslash","questiondown","exclamdown","logicalnot","radical","florin",
+ "approxequal","Delta","guillemotleft","guillemotright","ellipsis",
+ "nobreakspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash",
+ "quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge",
+ "ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright",
+ "fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase",
+ "perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave",
+ "Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple",
+ "Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde",
+ "macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron",
+ "Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth",
+ "Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior",
+ "twosuperior","threesuperior","onehalf","onequarter","threequarters","franc",
+ "Gbreve","gbreve","Idot","Scedilla","scedilla","Cacute","cacute","Ccaron",
+ "ccaron","dmacron","markingspace","capslock","shift","propeller","enter",
+ "markingtabrtol","markingtabltor","control","markingdeleteltor",
+ "markingdeletertol","option","escape","parbreakltor","parbreakrtol",
+ "newpage","checkmark","linebreakltor","linebreakrtol","markingnobreakspace",
+ "diamond","appleoutline"};
+#endif
+
+// #define DEBUG_TRUETYPE
+
+TQPSPrinterFontTTF::TQPSPrinterFontTTF(const TQFontEngine *f, TQByteArray& d)
+{
+ data = d;
+ defective = FALSE;
+
+ BYTE *ptr;
+
+ target_type = 3; // will work on any printer
+ //target_type = 42; // works with gs, faster, better quality
+
+#ifdef TQ_PRINTER_USE_TYPE42
+ char* environment_preference = getenv("TQT_TTFTOPS");
+ if (environment_preference) {
+ if (TQString(environment_preference) == "42")
+ target_type = 42;
+ else if (TQString(environment_preference) == "3")
+ target_type = 3;
+ else
+ qWarning("The value of TQT_TTFTOPS must be 42 or 3");
+ }
+#endif
+ offset_table = (unsigned char*) data.data(); /* first 12 bytes */
+
+ /* Determine how many directory entries there are. */
+ numTables = getUSHORT( offset_table + 4 );
+
+ /* Extract information from the "Offset" table. */
+ TTVersion = getFixed( offset_table );
+
+ /* Load the "head" table and extract information from it. */
+ ptr = getTable("head");
+ if ( !ptr ) {
+ defective = TRUE;
+ return;
+ }
+ MfrRevision = getFixed( ptr + 4 ); /* font revision number */
+ unitsPerEm = getUSHORT( ptr + 18 );
+ HUPM = unitsPerEm / 2;
+#ifdef DEBUG_TRUETYPE
+ printf("unitsPerEm=%d",(int)unitsPerEm);
+#endif
+ llx = topost( getFWord( ptr + 36 ) ); /* bounding box info */
+ lly = topost( getFWord( ptr + 38 ) );
+ urx = topost( getFWord( ptr + 40 ) );
+ ury = topost( getFWord( ptr + 42 ) );
+ indexToLocFormat = getSHORT( ptr + 50 ); /* size of 'loca' data */
+ if(indexToLocFormat != 0 && indexToLocFormat != 1) {
+ qWarning("TrueType font is unusable because indexToLocFormat != 0");
+ defective = TRUE;
+ return;
+ }
+ if( getSHORT(ptr+52) != 0 ) {
+ qWarning("TrueType font is unusable because glyphDataFormat != 0");
+ defective = TRUE;
+ return;
+ }
+
+ // === Load information from the "name" table ===
+
+ /* Set default values to avoid future references to */
+ /* undefined pointers. */
+
+ psname = FullName = FamilyName = Version = Style = "unknown";
+ Copyright = "No copyright notice";
+ Trademark = "No trademark notice";
+
+ BYTE* table_ptr = getTable("name"); /* pointer to table */
+ if ( !table_ptr ) {
+ defective = TRUE;
+ qDebug("couldn't tqfind name table" );
+ return;
+ }
+ int numrecords = getUSHORT( table_ptr + 2 ); /* number of names */
+ char* strings = (char *)table_ptr + getUSHORT( table_ptr + 4 ); /* start of string storage */
+
+ BYTE* ptr2 = table_ptr + 6;
+ for(int x=0; x < numrecords; x++,ptr2+=12) {
+ int platform = getUSHORT(ptr2);
+ //int encoding = getUSHORT(ptr2+2);
+ //int language = getUSHORT(ptr2+4);
+ int nameid = getUSHORT(ptr2+6);
+ int length = getUSHORT(ptr2+8);
+ int offset = getUSHORT(ptr2+10);
+
+ if( platform == 1 && nameid == 0 )
+ Copyright.setLatin1(strings+offset,length);
+
+ if( platform == 1 && nameid == 1 )
+ FamilyName.setLatin1(strings+offset,length);
+
+ if( platform == 1 && nameid == 2 )
+ Style.setLatin1(strings+offset,length);
+
+ if( platform == 1 && nameid == 4 )
+ FullName.setLatin1(strings+offset,length);
+
+ if( platform == 1 && nameid == 5 )
+ Version.setLatin1(strings+offset,length);
+
+ if( platform == 1 && nameid == 6 )
+ psname.setLatin1(strings+offset,length);
+
+ if( platform == 1 && nameid == 7 )
+ Trademark.setLatin1(strings+offset,length);
+
+ }
+ psname.tqreplace(' ', '-');
+ psname.tqreplace("/", "");
+ if (psname.isEmpty())
+ psname = makePSFontName(f);
+
+ //read_cmap(font);
+
+ /* We need to have the PostScript table around. */
+
+ post_table = getTable("post");
+#if 0
+ if ( post_table ) {
+ Fixed post_format = getFixed( post_table );
+
+ if( post_format.whole != 2 || post_format.fraction != 0 ) {
+ qWarning("TrueType font does not have a format 2.0 'post' table");
+ qWarning("post format is %d.%d",post_format.whole,post_format.fraction);
+ // Sivan Feb 2001: no longer defective.
+ // defective = TRUE;
+ }
+ }
+#endif
+ BYTE *maxp = getTable("maxp");
+ if ( !maxp ) {
+ defective = TRUE;
+ qDebug("no maxp table in font");
+ return;
+ }
+ numGlyphs = getUSHORT( maxp + 4 );
+// qDebug("number of glyphs is %d", numGlyphs);
+ tqreplacementList = makePSFontNameList( f, psname );
+ uni2glyphSetup();
+}
+
+
+void TQPSPrinterFontTTF::drawText( TQTextStream &stream, const TQPoint &p, TQTextEngine *engine, int item,
+ const TQString &text, TQPSPrinterPrivate *d, TQPainter *paint)
+{
+ // we draw glyphs here to get correct shaping of arabic and indic
+ TQScriptItem &si = engine->items[item];
+ engine->tqshape( item );
+ int len = si.num_glyphs;
+
+ int x = p.x() + si.x;
+ int y = p.y() + si.y;
+ if ( y != d->textY || d->textY == 0 )
+ stream << y << " Y";
+ d->textY = y;
+
+ TQCString xyarray;
+ int xo = 0;
+ int yo = 0;
+
+ glyph_t *glyphs = engine->glyphs( &si );
+ advance_t *advances = engine->advances( &si );
+ qoffset_t *offsets = engine->offsets( &si );
+#ifdef TQ_WS_X11
+ int type = si.fontEngine->type();
+ bool glyphIndices = (type == TQFontEngine::Xft);
+ // This helps us get arabic for XLFD fonts working. In that case we have a Unicode
+ // cmap (== 0), and the glyphs array tqcontains the tqshaped string.
+ bool useGlyphAsUnicode = (type == TQFontEngine::XLFD && si.fontEngine->cmap() == 0);
+#else // TQ_WS_TQWS
+ const bool glyphIndices = FALSE;
+ const bool useGlyphAsUnicode = TRUE;
+#endif
+ stream << "<";
+ if ( si.analysis.bidiLevel % 2 ) {
+ for ( int i = len-1; i >=0; i-- ) {
+ // map tqunicode is not really the correct name, as we map glyphs, but we also download glyphs, so this works
+ unsigned short glyph;
+ if (glyphIndices)
+ glyph = glyphs[i];
+ else
+ glyph = glyph_for_tqunicode(useGlyphAsUnicode ? glyphs[i] : text.tqunicode()[i].tqunicode());
+ stream << toHex(mapUnicode(glyph));
+ if ( i != len-1 ) {
+ xyarray += toInt( xo + offsets[i].x + advances[i+1] );
+ xyarray += " ";
+ xyarray += toInt( yo + offsets[i].y );
+ xyarray += " ";
+ xo = -offsets[i].x;
+ yo = -offsets[i].y;
+ }
+ }
+ } else {
+ for ( int i = 0; i < len; i++ ) {
+ // map tqunicode is not really the correct name, as we map glyphs, but we also download glyphs, so this works
+ unsigned short glyph;
+ if (glyphIndices)
+ glyph = glyphs[i];
+ else
+ glyph = glyph_for_tqunicode(useGlyphAsUnicode ? glyphs[i] : text.tqunicode()[i].tqunicode());
+ stream << toHex(mapUnicode(glyph));
+ if ( i ) {
+ xyarray += toInt( xo + offsets[i].x + advances[i-1] );
+ xyarray += " ";
+ xyarray += toInt( yo + offsets[i].y );
+ xyarray += " ";
+ xo = -offsets[i].x;
+ yo = -offsets[i].y;
+ }
+ }
+ }
+ stream << ">";
+
+ stream << "[" << xyarray << "0 0]";
+ stream << si.width << " " << x;
+
+ if ( paint->font().underline() )
+ stream << ' ' << y + d->fm.underlinePos() + d->fm.lineWidth()
+ << " " << d->fm.lineWidth() << " Tl";
+ if ( paint->font().strikeOut() )
+ stream << ' ' << y + d->fm.strikeOutPos()
+ << " " << d->fm.lineWidth() << " Tl";
+ stream << " XYT\n";
+
+}
+
+
+void TQPSPrinterFontTTF::download(TQTextStream& s,bool global)
+{
+ emitPSFontNameList( s, psname, tqreplacementList);
+ if ( !embedFonts ) {
+ downloadMapping(s, global);
+ return;
+ }
+
+ //qDebug("downloading ttf font %s", psname.latin1() );
+ //qDebug("target type=%d", target_type);
+ global_dict = global;
+ TQMap<unsigned short, unsigned short> *subsetDict = &subset;
+ if ( !global )
+ subsetDict = &page_subset;
+
+ downloaded = TRUE;
+
+ if (defective) {
+ s << "% Font ";
+ s << FullName;
+ s << " cannot be downloaded\n";
+ return;
+ }
+
+ // === write header ===
+ int VMMin;
+ int VMMax;
+
+ s << wrapDSC( "%%BeginFont: " + FullName );
+ if( target_type == 42 ) {
+ s << "%!PS-TrueTypeFont-"
+ << TTVersion.whole
+ << "."
+ << TTVersion.fraction
+ << "-"
+ << MfrRevision.whole
+ << "."
+ << MfrRevision.fraction
+ << "\n";
+ } else {
+ /* If it is not a Type 42 font, we will use a different format. */
+ s << "%!PS-Adobe-3.0 Resource-Font\n";
+ } /* See RBIIp 641 */
+
+ if( Copyright != (char*)NULL ) {
+ s << wrapDSC( "%%Copyright: " + Copyright );
+ }
+
+ if( target_type == 42 )
+ s << "%%Creator: Converted from TrueType to type 42 by TQt\n";
+ else
+ s << "%%Creator: Converted from TrueType by TQt\n";
+
+ /* If VM usage information is available, print it. */
+ if( target_type == 42 && post_table)
+ {
+ VMMin = (int)getULONG( post_table + 16 );
+ VMMax = (int)getULONG( post_table + 20 );
+ if( VMMin > 0 && VMMax > 0 )
+ s << "%%VMUsage: " << VMMin << " " << VMMax << "\n";
+ }
+
+ /* Start the dictionary which will eventually */
+ /* become the font. */
+ if( target_type != 3 ) {
+ s << "15 dict begin\n";
+ } else {
+ s << "25 dict begin\n";
+
+ /* Type 3 fonts will need some subroutines here. */
+ s << "/_d{bind def}bind def\n";
+ s << "/_m{moveto}_d\n";
+ s << "/_l{lineto}_d\n";
+ s << "/_cl{closepath eofill}_d\n";
+ s << "/_c{curveto}_d\n";
+ s << "/_sc{7 -1 roll{setcachetqdevice}{pop pop pop pop pop pop}ifelse}_d\n";
+ s << "/_e{exec}_d\n";
+ }
+
+ s << "/FontName /";
+ s << psname;
+ s << " def\n";
+ s << "/PaintType 0 def\n";
+
+ if(target_type == 42)
+ s << "/FontMatrix[1 0 0 1 0 0]def\n";
+ else
+ s << "/FontMatrix[.001 0 0 .001 0 0]def\n";
+
+ s << "/FontBBox[";
+ s<< llx;
+ s << " ";
+ s<< lly;
+ s << " ";
+ s<< urx;
+ s << " ";
+ s<< ury;
+ s << "]def\n";
+
+ s << "/FontType ";
+ s<< target_type;
+ s << " def\n";
+
+ // === write encoding ===
+
+ s << "/Encoding StandardEncoding def\n";
+
+ // === write fontinfo dict ===
+
+ /* We create a sub dictionary named "FontInfo" where we */
+ /* store information which though it is not used by the */
+ /* interpreter, is useful to some programs which will */
+ /* be printing with the font. */
+ s << "/FontInfo 10 dict dup begin\n";
+
+ /* These names come from the TrueType font's "name" table. */
+ s << "/FamilyName (";
+ s << FamilyName;
+ s << ") def\n";
+
+ s << "/FullName (";
+ s << FullName;
+ s << ") def\n";
+
+ s << "/Notice (";
+ s << Copyright;
+ s << " ";
+ s << Trademark;
+ s << ") def\n";
+
+ /* This information is not quite correct. */
+ s << "/Weight (";
+ s << Style;
+ s << ") def\n";
+
+ /* Some fonts have this as "version". */
+ s << "/Version (";
+ s << Version;
+ s << ") def\n";
+
+ /* Some information from the "post" table. */
+ if ( post_table ) {
+ Fixed ItalicAngle = getFixed( post_table + 4 );
+ s << "/ItalicAngle ";
+ s << ItalicAngle.whole;
+ s << ".";
+ s << ItalicAngle.fraction;
+ s << " def\n";
+
+ s << "/isFixedPitch ";
+ s << (getULONG( post_table + 12 ) ? "true" : "false" );
+ s << " def\n";
+
+ s << "/UnderlinePosition ";
+ s << (int)getFWord( post_table + 8 );
+ s << " def\n";
+
+ s << "/UnderlineThickness ";
+ s << (int)getFWord( post_table + 10 );
+ s << " def\n";
+ }
+ s << "end readonly def\n";
+
+#ifdef TQ_PRINTER_USE_TYPE42
+ /* If we are generating a type 42 font, */
+ /* emmit the sfnts array. */
+ if( target_type == 42 )
+ download_sfnts(s);
+#endif
+ /* If we are generating a Type 3 font, we will need to */
+ /* have the 'loca' and 'glyf' tables arround while */
+ /* we are generating the CharStrings. */
+ if(target_type == 3)
+ {
+ BYTE *ptr; /* We need only one value */
+ ptr = getTable("hhea");
+ numberOfHMetrics = getUSHORT(ptr + 34);
+
+ loca_table = getTable("loca");
+ glyf_table = getTable("glyf");
+ hmtx_table = getTable("hmtx");
+ }
+
+ // === CharStrings array ===
+
+ // subsetting. We turn a char subset into a glyph subset
+ // and we mark as used the base glyphs of used composite glyphs.
+
+ bool glyphset[65536];
+ for(int c=0; c < 65536; c++)
+ glyphset[c] = FALSE;
+ glyphset[0] = TRUE; // always output .notdef
+
+ TQMap<unsigned short, unsigned short>::iterator it;
+ for( it = subsetDict->begin(); it != subsetDict->end(); ++it ) {
+ subsetGlyph( it.key(), glyphset );
+ }
+ int nGlyphs = numGlyphs;
+ if ( target_type == 3 ) {
+ nGlyphs = 0;;
+ for(int c=0; c < 65536; c++)
+ if ( glyphset[c] ) nGlyphs++;
+ }
+
+ s << "/CharStrings ";
+ s << nGlyphs;
+ s << " dict dup begin\n";
+
+ // Emmit one key-value pair for each glyph.
+ for(int x=0; x < 65536; x++) {
+ if(target_type == 42) {
+ s << "/";
+ s << glyphName( x );
+ s << " ";
+ s << x;
+ s << " def\n";
+ } else { /* type 3 */
+ if (!glyphset[x]) continue;
+
+ //qDebug("emitting charproc for glyph %d, name=%s", x, glyphName(x).latin1() );
+ s << "/";
+ s << glyphName( x, glyphset );
+ s << "{";
+ charproc(x,s, glyphset);
+ s << "}_d\n"; /* "} bind def" */
+ }
+ }
+
+ s << "end readonly def\n";
+
+ // === trailer ===
+
+ /* If we are generating a type 3 font, we need to provide */
+ /* a BuildGlyph and BuildChar proceedures. */
+ if( target_type == 3 ) {
+ s << "\n";
+
+ s << "/BuildGlyph\n";
+ s << " {exch begin\n"; /* start font dictionary */
+ s << " CharStrings exch\n";
+ s << " 2 copy known not{pop /.notdef}if\n";
+ s << " true 3 1 roll get exec\n";
+ s << " end}_d\n";
+
+ s << "\n";
+
+ /* This proceedure is for compatiblity with */
+ /* level 1 interpreters. */
+ s << "/BuildChar {\n";
+ s << " 1 index /Encoding get exch get\n";
+ s << " 1 index /BuildGlyph get exec\n";
+ s << "}_d\n";
+
+ s << "\n";
+
+ }
+
+ /* If we are generating a type 42 font, we need to check to see */
+ /* if this PostScript interpreter understands type 42 fonts. If */
+ /* it doesn't, we will hope that the Apple TrueType rasterizer */
+ /* has been loaded and we will adjust the font accordingly. */
+ /* I found out how to do this by examining a TrueType font */
+ /* generated by a Macintosh. That is where the TrueType interpreter */
+ /* setup instructions and part of BuildGlyph came from. */
+ else if( target_type == 42 ) {
+ s << "\n";
+
+ /* If we have no "resourcestatus" command, or FontType 42 */
+ /* is unknown, leave "true" on the stack. */
+ s << "systemdict/resourcestatus known\n";
+ s << " {42 /FontType resourcestatus\n";
+ s << " {pop pop false}{true}ifelse}\n";
+ s << " {true}ifelse\n";
+
+ /* If true, execute code to produce an error message if */
+ /* we can't tqfind Apple's TrueDict in VM. */
+ s << "{/TrueDict where{pop}{(%%[ Error: no TrueType rasterizer ]%%)= flush}ifelse\n";
+
+ /* Since we are expected to use Apple's TrueDict TrueType */
+ /* reasterizer, change the font type to 3. */
+ s << "/FontType 3 def\n";
+
+ /* Define a string to hold the state of the Apple */
+ /* TrueType interpreter. */
+ s << " /TrueState 271 string def\n";
+
+ /* It looks like we get information about the resolution */
+ /* of the printer and store it in the TrueState string. */
+ s << " TrueDict begin sfnts save\n";
+ s << " 72 0 matrix defaultmatrix dtransform dup\n";
+ s << " mul exch dup mul add sqrt cvi 0 72 matrix\n";
+ s << " defaultmatrix dtransform dup mul exch dup\n";
+ s << " mul add sqrt cvi 3 -1 roll restore\n";
+ s << " TrueState initer end\n";
+
+ /* This BuildGlyph procedure will look the name up in the */
+ /* CharStrings array, and then check to see if what it gets */
+ /* is a procedure. If it is, it executes it, otherwise, it */
+ /* lets the TrueType rasterizer loose on it. */
+
+ /* When this proceedure is executed the stack tqcontains */
+ /* the font dictionary and the character name. We */
+ /* exchange arguments and move the dictionary to the */
+ /* dictionary stack. */
+ s << " /BuildGlyph{exch begin\n";
+ /* stack: charname */
+
+ /* Put two copies of CharStrings on the stack and consume */
+ /* one testing to see if the charname is defined in it, */
+ /* leave the answer on the stack. */
+ s << " CharStrings dup 2 index known\n";
+ /* stack: charname CharStrings bool */
+
+ /* Exchange the CharStrings dictionary and the charname, */
+ /* but if the answer was false, tqreplace the character name */
+ /* with ".notdef". */
+ s << " {exch}{exch pop /.notdef}ifelse\n";
+ /* stack: CharStrings charname */
+
+ /* Get the value from the CharStrings dictionary and see */
+ /* if it is executable. */
+ s << " get dup xcheck\n";
+ /* stack: CharStrings_entry */
+
+ /* If is a proceedure. Execute according to RBIIp 277-278. */
+ s << " {currentdict systemdict begin begin exec end end}\n";
+
+ /* Is a TrueType character index, let the rasterizer at it. */
+ s << " {TrueDict begin /bander load cvlit exch TrueState render end}\n";
+
+ s << " ifelse\n";
+
+ /* Pop the font's dictionary off the stack. */
+ s << " end}bind def\n";
+
+ /* This is the level 1 compatibility BuildChar procedure. */
+ /* See RBIIp 281. */
+ s << " /BuildChar{\n";
+ s << " 1 index /Encoding get exch get\n";
+ s << " 1 index /BuildGlyph get exec\n";
+ s << " }bind def\n";
+
+ /* Here we close the condition which is true */
+ /* if the printer has no built-in TrueType */
+ /* rasterizer. */
+ s << "}if\n";
+ s << "\n";
+ } /* end of if Type 42 not understood. */
+
+ s << "FontName currentdict end definefont pop\n";
+
+ downloadMapping(s, global);
+ s << "%%EndFont\n";
+}
+
+BYTE* TQPSPrinterFontTTF::getTable(const char* name)
+{
+ BYTE *ptr;
+ int x;
+
+ /* We must search the table directory. */
+ ptr = offset_table + 12;
+ x=0;
+ while (x != numTables) {
+ if( strncmp((const char *)ptr,name,4) == 0 ) {
+ ULONG offset;
+ //ULONG length;
+ BYTE *table;
+
+ offset = getULONG( ptr + 8 );
+ //length = getULONG( ptr + 12 );
+
+ table = offset_table + offset;
+ return table;
+ }
+
+ x++;
+ ptr += 16;
+ }
+
+ return 0;
+}
+
+void TQPSPrinterFontTTF::uni2glyphSetup()
+{
+ uni2glyph.resize(65536);
+ int i;
+ for (i=0; i<65536; i++) uni2glyph[i] = 0x0000;
+ glyph2uni.resize(65536);
+ for (i=0; i<65536; i++) glyph2uni[i] = 0x0000;
+
+ unsigned char* cmap = getTable("cmap");
+ int pos = 0;
+
+ //USHORT version = getUSHORT(cmap + pos);
+ pos += 2;
+ USHORT nmaps = getUSHORT(cmap + pos); pos += 2;
+
+ //fprintf(stderr,"cmap version %d (should be 0), %d maps\n",version,nmaps);
+
+ ULONG offset = 0;
+ int map = -1;
+ bool symbol = TRUE;
+ for (i=0; i<nmaps; i++) {
+ USHORT platform = getUSHORT(cmap+pos); pos+=2;
+ USHORT encoding = getUSHORT(cmap+pos); pos+=2;
+ offset = getULONG( cmap+pos); pos+=4;
+ //fprintf(stderr,"[%d] plat %d enc %d\n",i,platform,encoding);
+ if (platform == 3 && encoding == 1) {
+ map = i;
+ symbol = FALSE;
+ break; // tqunicode
+ }
+ if (platform == 3 && encoding == 0) {
+ // symbol, continue looking
+ map = i;
+ }
+ }
+ if (map==nmaps) {
+ qWarning("Font does not have tqunicode encoding\n");
+ return; // no tqunicode encoding!
+ }
+
+ pos = 8*map;
+ //fprintf(stderr,"Doing Unicode encoding\n");
+
+ pos = offset;
+ USHORT format = getUSHORT(cmap+pos); pos+=2;
+ //fprintf(stderr,"Unicode cmap format %d\n",format);
+
+ if (format != 4) {
+ //qWarning("Unicode cmap format is not 4");
+ return;
+ }
+
+ pos += 2; // length
+ pos += 2; // version
+ USHORT segcount = getUSHORT(cmap+pos) / 2; pos+=2;
+
+ //fprintf(stderr,"Unicode cmap seg count %d\n",segcount);
+
+ // skip search data
+ pos += 2;
+ pos += 2;
+ pos += 2;
+
+ unsigned char* endcode = cmap + offset + 14;
+ unsigned char* startcode = cmap + offset + 16 + 2*segcount;
+ unsigned char* iddelta = cmap + offset + 16 + 4*segcount;
+ unsigned char* idrangeoff = cmap + offset + 16 + 6*segcount;
+ //unsigned char* glyphid = cmap + offset + 16 + 8*segcount;
+ for (i=0; i<segcount; i++) {
+ USHORT endcode_i = getUSHORT(endcode +2*i);
+ USHORT startcode_i = getUSHORT(startcode +2*i);
+ SHORT iddelta_i = getSHORT(iddelta +2*i);
+ USHORT idrangeoff_i = getUSHORT(idrangeoff+2*i);
+
+// fprintf(stderr,"[%d] %04x-%04x (%x %x)\n",
+// i,startcode_i,endcode_i,iddelta_i,idrangeoff_i);
+ if (endcode_i == 0xffff) break; // last dummy segment
+
+ if (idrangeoff_i == 0) {
+ for (USHORT c = startcode_i; c <= endcode_i; c++) {
+ USHORT g = c + iddelta_i; // glyph index
+ if ( g != 0 ) {
+ uni2glyph[g] = c;
+ glyph2uni[c] = g;
+ }
+ }
+ } else {
+ for (USHORT c = startcode_i; c <= endcode_i; c++) {
+ USHORT g = getUSHORT(idrangeoff+2*i
+ + 2*(c - startcode_i)
+ + idrangeoff_i);
+ if ( g != 0 ) {
+ uni2glyph[g] = c;
+ glyph2uni[c] = g;
+ }
+ }
+ }
+ }
+ if (symbol && glyph2uni[0x40] == 0 && glyph2uni[0xf040] != 0) {
+ // map 0xf000-0xf0ff into latin1 range.
+ for (int i = 0; i < 0x100; ++i) {
+ if (!glyph2uni[i])
+ glyph2uni[i] = glyph2uni[i+0xf000];
+
+ }
+ }
+}
+
+USHORT TQPSPrinterFontTTF::tqunicode_for_glyph(int glyphindex)
+{
+ return uni2glyph[glyphindex];
+}
+
+USHORT TQPSPrinterFontTTF::glyph_for_tqunicode(unsigned short tqunicode)
+{
+ return glyph2uni[tqunicode];
+}
+
+#ifdef TQ_PRINTER_USE_TYPE42
+// ****************** SNFTS ROUTINES *******
+
+/*-------------------------------------------------------------------
+** sfnts routines
+** These routines generate the PostScript "sfnts" array which
+** tqcontains one or more strings which contain a reduced version
+** of the TrueType font.
+**
+** A number of functions are required to accomplish this rather
+** complicated task.
+-------------------------------------------------------------------*/
+
+// Write a BYTE as a hexadecimal value as part of the sfnts array.
+
+void TQPSPrinterFontTTF::sfnts_pputBYTE(BYTE n,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string)
+{
+ static const char hexdigits[]="0123456789ABCDEF";
+
+ if(!in_string) {
+ s << "<";
+ string_len = 0;
+ line_len++;
+ in_string = TRUE;
+ }
+
+ s << hexdigits[ n / 16 ] ;
+ s << hexdigits[ n % 16 ] ;
+ string_len++;
+ line_len+=2;
+
+ if(line_len > 70) {
+ s << "\n";
+ line_len=0;
+ }
+}
+
+// Write a USHORT as a hexadecimal value as part of the sfnts array.
+
+void TQPSPrinterFontTTF::sfnts_pputUSHORT(USHORT n,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string)
+{
+ sfnts_pputBYTE(n / 256,s, string_len, line_len, in_string);
+ sfnts_pputBYTE(n % 256,s, string_len, line_len, in_string);
+}
+
+
+// Write a ULONG as part of the sfnts array.
+
+void TQPSPrinterFontTTF::sfnts_pputULONG(ULONG n,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string)
+{
+ int x1 = n % 256; n /= 256;
+ int x2 = n % 256; n /= 256;
+ int x3 = n % 256; n /= 256;
+
+ sfnts_pputBYTE(n,s , string_len, line_len, in_string);
+ sfnts_pputBYTE(x3,s, string_len, line_len, in_string);
+ sfnts_pputBYTE(x2,s, string_len, line_len, in_string);
+ sfnts_pputBYTE(x1,s, string_len, line_len, in_string);
+}
+
+/*
+** This is called whenever it is
+** necessary to end a string in the sfnts array.
+**
+** (The array must be broken into strings which are
+** no longer than 64K characters.)
+*/
+void TQPSPrinterFontTTF::sfnts_end_string(TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string)
+{
+ if(in_string) {
+ string_len=0; /* fool sfnts_pputBYTE() */
+
+ // s << "\n% dummy byte:\n";
+
+ // extra byte for pre-2013 compatibility
+ sfnts_pputBYTE(0, s, string_len, line_len, in_string);
+
+ s << ">";
+ line_len++;
+ }
+
+ in_string=FALSE;
+}
+
+/*
+** This is called at the start of each new table.
+** The argement is the length in bytes of the table
+** which will follow. If the new table will not fit
+** in the current string, a new one is started.
+*/
+void TQPSPrinterFontTTF::sfnts_new_table(ULONG length,TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string)
+{
+ if( (string_len + length) > 65528 )
+ sfnts_end_string(s, string_len, line_len, in_string);
+}
+
+/*
+** We may have to break up the 'glyf' table. That is the reason
+** why we provide this special routine to copy it into the sfnts
+** array.
+*/
+void TQPSPrinterFontTTF::sfnts_glyf_table(ULONG oldoffset,
+ ULONG correct_total_length,
+ TQTextStream& s,
+ int& string_len, int& line_len, bool& in_string)
+
+{
+ int x;
+ ULONG off;
+ ULONG length;
+ int c;
+ ULONG total=0; /* running total of bytes written to table */
+
+ loca_table = getTable("loca");
+
+ int font_off = oldoffset;
+
+ /* Copy the glyphs one by one */
+ for(x=0; x < numGlyphs; x++) {
+ /* Read the glyph offset from the index-to-location table. */
+ if(indexToLocFormat == 0) {
+ off = getUSHORT( loca_table + (x * 2) );
+ off *= 2;
+ length = getUSHORT( loca_table + ((x+1) * 2) );
+ length *= 2;
+ length -= off;
+ } else {
+ off = getULONG( loca_table + (x * 4) );
+ length = getULONG( loca_table + ((x+1) * 4) );
+ length -= off;
+ }
+
+ // fprintf(stderr,"glyph length=%d",(int)length);
+
+ /* Start new string if necessary. */
+ sfnts_new_table( (int)length, s, string_len, line_len, in_string );
+
+ /*
+ ** Make sure the glyph is padded out to a
+ ** two byte boundary.
+ */
+ if( length % 2 ) {
+ qWarning("TrueType font tqcontains a 'glyf' table without 2 byte padding");
+ defective = TRUE;
+ return;
+ }
+
+ /* Copy the bytes of the glyph. */
+ while( length-- ) {
+ c = offset_table[ font_off ];
+ font_off++;
+
+ sfnts_pputBYTE(c, s, string_len, line_len, in_string);
+ total++; /* add to running total */
+ }
+ }
+
+ /* Pad out to full length from table directory */
+ while( total < correct_total_length ) {
+ sfnts_pputBYTE(0, s, string_len, line_len, in_string);
+ total++;
+ }
+
+ /* Look for unexplainable descrepancies between sizes */
+ if( total != correct_total_length ) {
+ qWarning("TQPSPrinterFontTTF::sfnts_glyf_table: total != correct_total_length");
+ defective = TRUE;
+ return;
+ }
+}
+
+/*
+** Here is the routine which ties it all together.
+**
+** Create the array called "sfnts" which
+** holds the actual TrueType data.
+*/
+
+void TQPSPrinterFontTTF::download_sfnts(TQTextStream& s)
+{
+ // tables worth including in a type 42 font
+ char *table_names[]= {
+ "cvt ",
+ "fpgm",
+ "glyf",
+ "head",
+ "hhea",
+ "hmtx",
+ "loca",
+ "maxp",
+ "prep"
+ };
+
+ struct { /* The location of each of */
+ ULONG oldoffset; /* the above tables. */
+ ULONG newoffset;
+ ULONG length;
+ ULONG checksum;
+ } tables[9];
+
+ int c; /* Input character. */
+ int diff;
+ int count; /* How many `important' tables did we tqfind? */
+
+ BYTE* ptr = offset_table + 12; // original table directory
+ ULONG nextoffset=0;
+ count=0;
+
+ /*
+ ** Find the tables we want and store there vital
+ ** statistics in tables[].
+ */
+ for(int x=0; x < 9; x++ ) {
+ do {
+ diff = strncmp( (char*)ptr, table_names[x], 4 );
+
+ if( diff > 0 ) { /* If we are past it. */
+ tables[x].length = 0;
+ diff = 0;
+ }
+ else if( diff < 0 ) { /* If we haven't hit it yet. */
+ ptr += 16;
+ }
+ else if( diff == 0 ) { /* Here it is! */
+ tables[x].newoffset = nextoffset;
+ tables[x].checksum = getULONG( ptr + 4 );
+ tables[x].oldoffset = getULONG( ptr + 8 );
+ tables[x].length = getULONG( ptr + 12 );
+ nextoffset += ( ((tables[x].length + 3) / 4) * 4 );
+ count++;
+ ptr += 16;
+ }
+ } while(diff != 0);
+ } /* end of for loop which passes over the table directory */
+
+ /* Begin the sfnts array. */
+
+ s << "/sfnts[<";
+
+ bool in_string=TRUE;
+ int string_len=0;
+ int line_len=8;
+
+ /* Generate the offset table header */
+ /* Start by copying the TrueType version number. */
+ ptr = offset_table;
+ for(int x=0; x < 4; x++)
+ sfnts_pputBYTE( *(ptr++) , s, string_len, line_len, in_string );
+
+ /* Now, generate those silly numTables numbers. */
+ sfnts_pputUSHORT(count,s, string_len, line_len, in_string); /* number of tables */
+ if( count == 9 ) {
+ sfnts_pputUSHORT(7,s, string_len, line_len, in_string); /* searchRange */
+ sfnts_pputUSHORT(3,s, string_len, line_len, in_string); /* entrySelector */
+ sfnts_pputUSHORT(81,s, string_len, line_len, in_string); /* rangeShift */
+ }
+ else {
+ qWarning("Fewer than 9 tables selected");
+ }
+
+ /* Now, emmit the table directory. */
+ for(int x=0; x < 9; x++) {
+ if( tables[x].length == 0 ) /* Skip missing tables */
+ continue;
+
+ /* Name */
+ sfnts_pputBYTE( table_names[x][0], s, string_len, line_len, in_string);
+ sfnts_pputBYTE( table_names[x][1], s, string_len, line_len, in_string);
+ sfnts_pputBYTE( table_names[x][2], s, string_len, line_len, in_string);
+ sfnts_pputBYTE( table_names[x][3], s, string_len, line_len, in_string);
+
+ /* Checksum */
+ sfnts_pputULONG( tables[x].checksum, s, string_len, line_len, in_string );
+
+ /* Offset */
+ sfnts_pputULONG( tables[x].newoffset + 12 + (count * 16), s,
+ string_len, line_len, in_string );
+
+ /* Length */
+ sfnts_pputULONG( tables[x].length, s,
+ string_len, line_len, in_string );
+ }
+
+ /* Now, send the tables */
+ for(int x=0; x < 9; x++) {
+ if( tables[x].length == 0 ) /* skip tables that aren't there */
+ continue;
+
+ /* 'glyf' table gets special treatment */
+ if( strcmp(table_names[x],"glyf")==0 ) {
+ sfnts_glyf_table(tables[x].oldoffset,tables[x].length, s,
+ string_len, line_len, in_string);
+ } else { // other tables should not exceed 64K (not always true; Sivan)
+ if( tables[x].length > 65535 ) {
+ qWarning("TrueType font has a table which is too long");
+ defective = TRUE;
+ return;
+ }
+
+ /* Start new string if necessary. */
+ sfnts_new_table(tables[x].length, s,
+ string_len, line_len, in_string);
+
+ int font_off = tables[x].oldoffset;
+ /* Copy the bytes of the table. */
+ for( int y=0; y < (int)tables[x].length; y++ ) {
+ c = offset_table[ font_off ];
+ font_off++;
+
+ sfnts_pputBYTE(c, s, string_len, line_len, in_string);
+ }
+ }
+
+ /* Padd it out to a four byte boundary. */
+ int y=tables[x].length;
+ while( (y % 4) != 0 ) {
+ sfnts_pputBYTE(0, s, string_len, line_len, in_string);
+ y++;
+ }
+
+ } /* End of loop for all tables */
+
+ /* Close the array. */
+ sfnts_end_string(s, string_len, line_len, in_string);
+ s << "]def\n";
+}
+#endif
+
+// ****************** Type 3 CharProcs *******
+
+/*
+** This routine is used to break the character
+** procedure up into a number of smaller
+** procedures. This is necessary so as not to
+** overflow the stack on certain level 1 interpreters.
+**
+** Prepare to push another item onto the stack,
+** starting a new proceedure if necessary.
+**
+** Not all the stack depth calculations in this routine
+** are perfectly accurate, but they do the job.
+*/
+static int stack_depth = 0;
+static void stack(int num_pts, int newnew, TQTextStream& s)
+{
+ if( num_pts > 25 ) { /* Only do something of we will */
+ /* have a log of points. */
+ if(stack_depth == 0) {
+ s << "{";
+ stack_depth=1;
+ }
+
+ stack_depth += newnew; /* Account for what we propose to add */
+
+ if(stack_depth > 100) {
+ s << "}_e{";
+ stack_depth = 3 + newnew; /* A rough estimate */
+ }
+ }
+}
+
+static void stack_end(TQTextStream& s) /* called at end */
+{
+ if(stack_depth) {
+ s << "}_e";
+ stack_depth=0;
+ }
+}
+
+// postscript drawing commands
+
+static void PSMoveto(FWord x, FWord y, TQTextStream& ts)
+{
+ ts << x;
+ ts << " ";
+ ts << y;
+ ts << " _m\n";
+}
+
+static void PSLineto(FWord x, FWord y, TQTextStream& ts)
+{
+ ts << x;
+ ts << " ";
+ ts << y;
+ ts << " _l\n";
+}
+
+/* Emmit a PostScript "curveto" command. */
+static void PSCurveto(FWord* xcoor, FWord* ycoor,
+ FWord x, FWord y, int s, int t, TQTextStream& ts)
+{
+ int N, i;
+ double sx[3], sy[3], cx[4], cy[4];
+
+ N = t-s+2;
+ for(i=0; i<N-1; i++) {
+ sx[0] = i==0?xcoor[s-1]:(xcoor[i+s]+xcoor[i+s-1])/2;
+ sy[0] = i==0?ycoor[s-1]:(ycoor[i+s]+ycoor[i+s-1])/2;
+ sx[1] = xcoor[s+i];
+ sy[1] = ycoor[s+i];
+ sx[2] = i==N-2?x:(xcoor[s+i]+xcoor[s+i+1])/2;
+ sy[2] = i==N-2?y:(ycoor[s+i]+ycoor[s+i+1])/2;
+ cx[3] = sx[2];
+ cy[3] = sy[2];
+ cx[1] = (2*sx[1]+sx[0])/3;
+ cy[1] = (2*sy[1]+sy[0])/3;
+ cx[2] = (sx[2]+2*sx[1])/3;
+ cy[2] = (sy[2]+2*sy[1])/3;
+
+ ts << (int)cx[1];
+ ts << " ";
+ ts << (int)cy[1];
+ ts << " ";
+ ts << (int)cx[2];
+ ts << " ";
+ ts << (int)cy[2];
+ ts << " ";
+ ts << (int)cx[3];
+ ts << " ";
+ ts << (int)cy[3];
+ ts << " _c\n";
+ }
+}
+
+/* The PostScript bounding box. */
+/* Variables to hold the character data. */
+
+//void load_char(struct TTFONT *font, BYTE *glyph);
+//void clear_data();
+
+//void PSMoveto(FWord x, FWord y, TQTextStream& ts);
+//void PSLineto(FWord x, FWord y, TQTextStream& ts);
+//void PSCurveto(FWord x, FWord y, int s, int t, TQTextStream& ts);
+
+//double area(FWord *x, FWord *y, int n);
+//int nextinctr(int co, int ci);
+//int nextoutctr(int co);
+//int nearout(int ci);
+//double intest(int co, int ci);
+#define sqr(x) ((x)*(x))
+
+#define NOMOREINCTR -1
+#define NOMOREOUTCTR -1
+
+/*
+** Find the area of a contour?
+*/
+static double area(FWord *x, FWord *y, int n)
+{
+ int i;
+ double sum;
+
+ sum=x[n-1]*y[0]-y[n-1]*x[0];
+ for (i=0; i<=n-2; i++) sum += x[i]*y[i+1] - y[i]*x[i+1];
+ return sum;
+}
+
+static int nextoutctr(int /*co*/, charproc_data* cd)
+{
+ int j;
+
+ for(j=0; j<cd->num_ctr; j++)
+ if (cd->check_ctr[j]==0 && cd->area_ctr[j] < 0) {
+ cd->check_ctr[j]=1;
+ return j;
+ }
+
+ return NOMOREOUTCTR;
+} /* end of nextoutctr() */
+
+static int nextinctr(int co, int /*ci*/, charproc_data* cd)
+{
+ int j;
+
+ for(j=0; j<cd->num_ctr; j++)
+ if (cd->ctrset[2*j+1]==co)
+ if (cd->check_ctr[ cd->ctrset[2*j] ]==0) {
+ cd->check_ctr[ cd->ctrset[2*j] ]=1;
+ return cd->ctrset[2*j];
+ }
+
+ return NOMOREINCTR;
+}
+
+static double intest( int co, int ci, charproc_data *cd )
+{
+ int i, j, start, end;
+ double r1, r2;
+ FWord xi[3], yi[3];
+
+ j = start = ( co == 0 ) ? 0 : ( cd->epts_ctr[co - 1] + 1 );
+ end = cd->epts_ctr[co];
+ i = ( ci == 0 ) ? 0 : ( cd->epts_ctr[ci - 1] + 1 );
+ xi[0] = cd->xcoor[i];
+ yi[0] = cd->ycoor[i];
+ r1 = sqr( cd->xcoor[start] - xi[0] ) + sqr( cd->ycoor[start] - yi[0] );
+
+ for ( i = start; i <= end; i++ ) {
+ r2 = sqr( cd->xcoor[i] - xi[0] ) + sqr( cd->ycoor[i] - yi[0] );
+ if ( r2 < r1 ) {
+ r1 = r2;
+ j = i;
+ }
+ }
+ if ( j == start ) {
+ xi[1] = cd->xcoor[end];
+ yi[1] = cd->ycoor[end];
+ } else {
+ xi[1] = cd->xcoor[j - 1];
+ yi[1] = cd->ycoor[j - 1];
+ }
+ if ( j == end ) {
+ xi[2] = cd->xcoor[start];
+ yi[2] = cd->ycoor[start];
+ } else {
+ xi[2] = cd->xcoor[j + 1];
+ yi[2] = cd->ycoor[j + 1];
+ }
+ return area( xi, yi, 3 );
+}
+
+/*
+** tqfind the nearest out contour to a specified in contour.
+*/
+static int nearout(int ci, charproc_data* cd)
+{
+ int k = 0; /* !!! is this right? */
+ int co;
+ double a, a1=0;
+
+ for (co=0; co < cd->num_ctr; co++) {
+ if(cd->area_ctr[co] < 0) {
+ a=intest(co,ci, cd);
+ if (a<0 && a1==0) {
+ k=co;
+ a1=a;
+ }
+ if(a<0 && a1!=0 && a>a1) {
+ k=co;
+ a1=a;
+ }
+ }
+ }
+
+ return k;
+} /* end of nearout() */
+
+
+/*
+** We call this routine to emmit the PostScript code
+** for the character we have loaded with load_char().
+*/
+static void PSConvert(TQTextStream& s, charproc_data* cd)
+{
+ int i,j,k,fst,start_offpt;
+ int end_offpt=0;
+
+ cd->area_ctr = new double[cd->num_ctr];
+ memset(cd->area_ctr, 0, (cd->num_ctr*sizeof(double)));
+
+ cd->check_ctr = new char[cd->num_ctr];
+ memset(cd->check_ctr, 0, (cd->num_ctr*sizeof(char)));
+
+ cd->ctrset = new int[2*(cd->num_ctr)];
+ memset(cd->ctrset, 0, (cd->num_ctr*2*sizeof(int)));
+
+ cd->check_ctr[0]=1;
+ cd->area_ctr[0]=area(cd->xcoor, cd->ycoor, cd->epts_ctr[0]+1);
+
+ for (i=1; i<cd->num_ctr; i++)
+ cd->area_ctr[i]=area(cd->xcoor+cd->epts_ctr[i-1]+1,
+ cd->ycoor+cd->epts_ctr[i-1]+1,
+ cd->epts_ctr[i]-cd->epts_ctr[i-1]);
+
+ for (i=0; i<cd->num_ctr; i++) {
+ if (cd->area_ctr[i]>0) {
+ cd->ctrset[2*i]=i;
+ cd->ctrset[2*i+1]=nearout(i,cd);
+ } else {
+ cd->ctrset[2*i]=-1;
+ cd->ctrset[2*i+1]=-1;
+ }
+ }
+
+ /* Step thru the coutours. */
+ /* I believe that a contour is a detatched */
+ /* set of curves and lines. */
+ i=j=k=0;
+ while (i < cd->num_ctr ) {
+ fst = j = (k==0) ? 0 : (cd->epts_ctr[k-1]+1);
+
+ /* Move to the first point on the contour. */
+ stack(cd->num_pts,3,s);
+ PSMoveto(cd->xcoor[j],cd->ycoor[j],s);
+ start_offpt = 0; /* No off curve points yet. */
+
+ /* Step thru the remaining points of this contour. */
+ for(j++; j <= cd->epts_ctr[k]; j++) {
+ if (!(cd->tt_flags[j]&1)) { /* Off curve */
+ if (!start_offpt)
+ { start_offpt = end_offpt = j; }
+ else
+ end_offpt++;
+ } else { /* On Curve */
+ if (start_offpt) {
+ stack(cd->num_pts,7,s);
+ PSCurveto(cd->xcoor,cd->ycoor,
+ cd->xcoor[j],cd->ycoor[j],
+ start_offpt,end_offpt,s);
+ start_offpt = 0;
+ } else {
+ stack(cd->num_pts,3,s);
+ PSLineto(cd->xcoor[j], cd->ycoor[j],s);
+ }
+ }
+ }
+
+ /* Do the final curve or line */
+ /* of this coutour. */
+ if (start_offpt) {
+ stack(cd->num_pts,7,s);
+ PSCurveto(cd->xcoor,cd->ycoor,
+ cd->xcoor[fst],cd->ycoor[fst],
+ start_offpt,end_offpt,s);
+ } else {
+ stack(cd->num_pts,3,s);
+ PSLineto(cd->xcoor[fst],cd->ycoor[fst],s);
+ }
+
+ k=nextinctr(i,k,cd);
+
+ if (k==NOMOREINCTR)
+ i=k=nextoutctr(i,cd);
+
+ if (i==NOMOREOUTCTR)
+ break;
+ }
+
+ /* Now, we can fill the whole thing. */
+ stack(cd->num_pts,1,s);
+ s << "_cl"; /* "closepath eofill" */
+
+ /* Free our work arrays. */
+ delete [] cd->area_ctr;
+ delete [] cd->check_ctr;
+ delete [] cd->ctrset;
+}
+
+
+/*
+** Load the simple glyph data pointed to by glyph.
+** The pointer "glyph" should point 10 bytes into
+** the glyph data.
+*/
+void TQPSPrinterFontTTF::charprocLoad(BYTE *glyph, charproc_data* cd)
+{
+ int x;
+ BYTE c, ct;
+
+ /* Read the contour endpoints list. */
+ cd->epts_ctr = new int[cd->num_ctr];
+ //cd->epts_ctr = (int *)myalloc(cd->num_ctr,sizeof(int));
+ for (x = 0; x < cd->num_ctr; x++) {
+ cd->epts_ctr[x] = getUSHORT(glyph);
+ glyph += 2;
+ }
+
+ /* From the endpoint of the last contour, we can */
+ /* determine the number of points. */
+ cd->num_pts = cd->epts_ctr[cd->num_ctr-1]+1;
+#ifdef DEBUG_TRUETYPE
+ fprintf(stderr,"num_pts=%d\n",cd->num_pts);
+#endif
+
+ /* Skip the instructions. */
+ x = getUSHORT(glyph);
+ glyph += 2;
+ glyph += x;
+
+ /* Allocate space to hold the data. */
+ //cd->tt_flags = (BYTE *)myalloc(num_pts,sizeof(BYTE));
+ //cd->xcoor = (FWord *)myalloc(num_pts,sizeof(FWord));
+ //cd->ycoor = (FWord *)myalloc(num_pts,sizeof(FWord));
+ cd->tt_flags = new BYTE[cd->num_pts];
+ cd->xcoor = new FWord[cd->num_pts];
+ cd->ycoor = new FWord[cd->num_pts];
+
+ /* Read the flags array, uncompressing it as we go. */
+ /* There is danger of overflow here. */
+ for (x = 0; x < cd->num_pts; ) {
+ cd->tt_flags[x++] = c = *(glyph++);
+
+ if (c&8) { /* If next byte is repeat count, */
+ ct = *(glyph++);
+
+ if( (x + ct) > cd->num_pts ) {
+ qWarning("Fatal Error in TT flags");
+ return;
+ }
+
+ while (ct--)
+ cd->tt_flags[x++] = c;
+ }
+ }
+
+ /* Read the x coordinates */
+ for (x = 0; x < cd->num_pts; x++) {
+ if (cd->tt_flags[x] & 2) { /* one byte value with */
+ /* external sign */
+ c = *(glyph++);
+ cd->xcoor[x] = (cd->tt_flags[x] & 0x10) ? c : (-1 * (int)c);
+ } else if(cd->tt_flags[x] & 0x10) { /* repeat last */
+ cd->xcoor[x] = 0;
+ } else { /* two byte signed value */
+ cd->xcoor[x] = getFWord(glyph);
+ glyph+=2;
+ }
+ }
+
+ /* Read the y coordinates */
+ for(x = 0; x < cd->num_pts; x++) {
+ if (cd->tt_flags[x] & 4) { /* one byte value with */
+ /* external sign */
+ c = *(glyph++);
+ cd->ycoor[x] = (cd->tt_flags[x] & 0x20) ? c : (-1 * (int)c);
+ } else if (cd->tt_flags[x] & 0x20) { /* repeat last value */
+ cd->ycoor[x] = 0;
+ } else { /* two byte signed value */
+ cd->ycoor[x] = getUSHORT(glyph);
+ glyph+=2;
+ }
+ }
+
+ /* Convert delta values to absolute values. */
+ for(x = 1; x < cd->num_pts; x++) {
+ cd->xcoor[x] += cd->xcoor[x-1];
+ cd->ycoor[x] += cd->ycoor[x-1];
+ }
+
+ for(x=0; x < cd->num_pts; x++) {
+ cd->xcoor[x] = topost(cd->xcoor[x]);
+ cd->ycoor[x] = topost(cd->ycoor[x]);
+ }
+}
+
+#define ARG_1_AND_2_ARE_WORDS 1
+#define ARGS_ARE_XY_VALUES 2
+#define ROUND_XY_TO_GRID 4
+#define WE_HAVE_A_SCALE 8
+/* RESERVED 16 */
+#define MORE_COMPONENTS 32
+#define WE_HAVE_AN_X_AND_Y_SCALE 64
+#define WE_HAVE_A_TWO_BY_TWO 128
+#define WE_HAVE_INSTRUCTIONS 256
+#define USE_MY_METRICS 512
+
+void TQPSPrinterFontTTF::subsetGlyph(int charindex,bool* glyphset)
+{
+ USHORT flags;
+ USHORT glyphIndex;
+ charproc_data cd;
+
+ glyphset[charindex] = TRUE;
+ //printf("subsetting %s ==> ",glyphName(charindex).latin1());
+
+ /* Get a pointer to the data. */
+ BYTE* glyph = charprocFindGlyphData( charindex );
+
+ /* If the character is blank, it has no bounding box, */
+ /* otherwise read the bounding box. */
+ if( glyph == (BYTE*)NULL ) {
+ cd.num_ctr=0;
+ } else {
+ cd.num_ctr = getSHORT(glyph);
+ /* Advance the pointer past bounding box. */
+ glyph += 10;
+ }
+
+ if( cd.num_ctr < 0 ) { // composite
+ /* Once around this loop for each component. */
+ do {
+ flags = getUSHORT(glyph); /* read the flags word */
+ glyph += 2;
+ glyphIndex = getUSHORT(glyph); /* read the glyphindex word */
+ glyph += 2;
+
+ glyphset[ glyphIndex ] = TRUE;
+ subsetGlyph( glyphIndex, glyphset );
+ //printf("subset tqcontains: %d %s ",glyphIndex, glyphName(glyphIndex).latin1());
+
+ if(flags & ARG_1_AND_2_ARE_WORDS) {
+ glyph += 2;
+ glyph += 2;
+ } else {
+ glyph += 1;
+ glyph += 1;
+ }
+
+ if(flags & WE_HAVE_A_SCALE) {
+ glyph += 2;
+ } else if(flags & WE_HAVE_AN_X_AND_Y_SCALE) {
+ glyph += 2;
+ glyph += 2;
+ } else if(flags & WE_HAVE_A_TWO_BY_TWO) {
+ glyph += 2;
+ glyph += 2;
+ glyph += 2;
+ glyph += 2;
+ } else {
+ }
+ } while(flags & MORE_COMPONENTS);
+ }
+ //printf("\n");
+}
+
+
+/*
+** Emmit PostScript code for a composite character.
+*/
+void TQPSPrinterFontTTF::charprocComposite(BYTE *glyph, TQTextStream& s, bool *glyphSet)
+{
+ USHORT flags;
+ USHORT glyphIndex;
+ int arg1;
+ int arg2;
+ float xscale = 1;
+ float yscale = 1;
+#ifdef DEBUG_TRUETYPE
+ float scale01 = 0;
+ float scale10 = 0;
+#endif
+
+ /* Once around this loop for each component. */
+ do {
+ flags = getUSHORT(glyph); /* read the flags word */
+ glyph += 2;
+
+ glyphIndex = getUSHORT(glyph); /* read the glyphindex word */
+ glyph += 2;
+
+ if(flags & ARG_1_AND_2_ARE_WORDS) {
+ /* The tt spec. seems to say these are signed. */
+ arg1 = getSHORT(glyph);
+ glyph += 2;
+ arg2 = getSHORT(glyph);
+ glyph += 2;
+ } else { /* The tt spec. does not clearly indicate */
+ /* whether these values are signed or not. */
+ arg1 = (char)*(glyph++);
+ arg2 = (char)*(glyph++);
+ }
+
+ if(flags & WE_HAVE_A_SCALE) {
+ xscale = yscale = f2dot14( getUSHORT(glyph) );
+ glyph += 2;
+ } else if(flags & WE_HAVE_AN_X_AND_Y_SCALE) {
+ xscale = f2dot14( getUSHORT(glyph) );
+ glyph += 2;
+ yscale = f2dot14( getUSHORT(glyph) );
+ glyph += 2;
+ } else if(flags & WE_HAVE_A_TWO_BY_TWO) {
+ xscale = f2dot14( getUSHORT(glyph) );
+ glyph += 2;
+#ifdef DEBUG_TRUETYPE
+ scale01 = f2dot14( getUSHORT(glyph) );
+#endif
+ glyph += 2;
+#ifdef DEBUG_TRUETYPE
+ scale10 = f2dot14( getUSHORT(glyph) );
+#endif
+ glyph += 2;
+ yscale = f2dot14( getUSHORT(glyph) );
+ glyph += 2;
+ }
+
+ /* Debugging */
+#ifdef DEBUG_TRUETYPE
+ s << "% flags=" << flags << ", arg1=" << arg1 << ", arg2=" << arg2 << ", xscale=" << xscale << ", yscale=" << yscale <<
+ ", scale01=" << scale01 << ", scale10=" << scale10 << endl;
+#endif
+
+
+ if ( (flags & ARGS_ARE_XY_VALUES) != ARGS_ARE_XY_VALUES ) {
+ s << "% unimplemented shift, arg1=" << arg1;
+ s << ", arg2=" << arg2 << "\n";
+ arg1 = arg2 = 0;
+ }
+
+ /* If we have an (X,Y) shif and it is non-zero, */
+ /* translate the coordinate system. */
+ if ( flags & (WE_HAVE_A_TWO_BY_TWO|WE_HAVE_AN_X_AND_Y_SCALE) ) {
+#if 0
+ // code similar to this would be needed for two_by_two
+ s << "gsave [ " << xscale << " " << scale01 << " " << scale10 << " "
+ << yscale << " " << topost(arg1) << " " << topost(arg2) << "] SM\n";
+#endif
+ if ( flags & WE_HAVE_A_TWO_BY_TWO )
+ s << "% Two by two transformation, unimplemented\n";
+ s << "gsave " << topost(arg1);
+ s << " " << topost(arg2);
+ s << " translate\n";
+ s << xscale << " " << yscale << " scale\n";
+ } else if ( flags & ARGS_ARE_XY_VALUES && ( arg1 != 0 || arg2 != 0 ) ) {
+ s << "gsave " << topost(arg1);
+ s << " " << topost(arg2);
+ s << " translate\n";
+ }
+
+ /* Invoke the CharStrings procedure to print the component. */
+ s << "false CharStrings /";
+ s << glyphName( glyphIndex, glyphSet );
+ s << " get exec\n";
+
+ // printf("false CharStrings /%s get exec\n",
+ //ttfont_CharStrings_getname(font,glyphIndex));
+
+ /* If we translated the coordinate system, */
+ /* put it back the way it was. */
+ if( (flags & ARGS_ARE_XY_VALUES && (arg1 != 0 || arg2 != 0) ) ||
+ ( flags & (WE_HAVE_A_TWO_BY_TWO|WE_HAVE_AN_X_AND_Y_SCALE) ) ) {
+ s << "grestore ";
+ }
+ } while (flags & MORE_COMPONENTS);
+}
+
+/*
+** Return a pointer to a specific glyph's data.
+*/
+BYTE* TQPSPrinterFontTTF::charprocFindGlyphData(int charindex)
+{
+ ULONG off;
+ ULONG length;
+
+ /* Read the glyph offset from the index to location table. */
+ if(indexToLocFormat == 0) {
+ off = getUSHORT( loca_table + (charindex * 2) );
+ off *= 2;
+ length = getUSHORT( loca_table + ((charindex+1) * 2) );
+ length *= 2;
+ length -= off;
+ } else {
+ off = getULONG( loca_table + (charindex * 4) );
+ length = getULONG( loca_table + ((charindex+1) * 4) );
+ length -= off;
+ }
+
+ if(length > 0)
+ return glyf_table + off;
+ else
+ return (BYTE*)NULL;
+}
+
+void TQPSPrinterFontTTF::charproc(int charindex, TQTextStream& s, bool *glyphSet )
+{
+ int llx,lly,urx,ury;
+ int advance_width;
+ charproc_data cd;
+
+#ifdef DEBUG_TRUETYPE
+ s << "% tt_type3_charproc for ";
+ s << charindex;
+ s << "\n";
+#endif
+
+ /* Get a pointer to the data. */
+ BYTE* glyph = charprocFindGlyphData( charindex );
+
+ /* If the character is blank, it has no bounding box, */
+ /* otherwise read the bounding box. */
+ if( glyph == (BYTE*)NULL ) {
+ llx=lly=urx=ury=0; /* A blank char has an all zero BoundingBox */
+ cd.num_ctr=0; /* Set this for later if()s */
+ } else {
+ /* Read the number of contours. */
+ cd.num_ctr = getSHORT(glyph);
+
+ /* Read PostScript bounding box. */
+ llx = getFWord(glyph + 2);
+ lly = getFWord(glyph + 4);
+ urx = getFWord(glyph + 6);
+ ury = getFWord(glyph + 8);
+
+ /* Advance the pointer. */
+ glyph += 10;
+ }
+
+ /* If it is a simple character, load its data. */
+ if (cd.num_ctr > 0)
+ charprocLoad(glyph, &cd);
+ else
+ cd.num_pts=0;
+
+ /* Consult the horizontal metrics table to determine */
+ /* the character width. */
+ if( charindex < numberOfHMetrics )
+ advance_width = getuFWord( hmtx_table + (charindex * 4) );
+ else
+ advance_width = getuFWord( hmtx_table + ((numberOfHMetrics-1) * 4) );
+
+ /* Execute setcachetqdevice in order to inform the font machinery */
+ /* of the character bounding box and advance width. */
+ stack(cd.num_pts,7,s);
+ s << topost(advance_width);
+ s << " 0 ";
+ s << topost(llx);
+ s << " ";
+ s << topost(lly);
+ s << " ";
+ s << topost(urx);
+ s << " ";
+ s << topost(ury);
+ s << " _sc\n";
+
+ /* If it is a simple glyph, convert it, */
+ /* otherwise, close the stack business. */
+ if( cd.num_ctr > 0 ) { // simple
+ PSConvert(s,&cd);
+ delete [] cd.tt_flags;
+ delete [] cd.xcoor;
+ delete [] cd.ycoor;
+ delete [] cd.epts_ctr;
+ } else if( cd.num_ctr < 0 ) { // composite
+ charprocComposite(glyph,s, glyphSet);
+ }
+
+ stack_end(s);
+} /* end of tt_type3_charproc() */
+
+
+// ================== PFA ====================
+
+class TQPSPrinterFontPFA
+ : public TQPSPrinterFontPrivate {
+public:
+ TQPSPrinterFontPFA(const TQFontEngine *f, TQByteArray& data);
+ virtual void download(TQTextStream& s, bool global);
+ virtual bool embedded() { return TRUE; }
+private:
+ TQByteArray data;
+};
+
+TQPSPrinterFontPFA::TQPSPrinterFontPFA(const TQFontEngine *f, TQByteArray& d)
+{
+ data = d;
+
+ int pos = 0;
+ char* p = data.data();
+ TQString fontname;
+
+ if (p[ pos ] != '%' || p[ pos+1 ] != '!') { // PFA marker
+ qWarning("invalid pfa file");
+ return;
+ }
+
+ char* fontnameptr = strstr(p+pos,"/FontName");
+ if (fontnameptr == NULL)
+ return;
+
+ fontnameptr += strlen("/FontName") + 1;
+ while (*fontnameptr == ' ' || *fontnameptr == '/') fontnameptr++;
+ int l=0;
+ while (fontnameptr[l] != ' ') l++;
+
+ psname = TQString::tqfromLatin1(fontnameptr,l);
+ tqreplacementList = makePSFontNameList( f, psname );
+}
+
+void TQPSPrinterFontPFA::download(TQTextStream& s, bool global)
+{
+ emitPSFontNameList( s, psname, tqreplacementList);
+
+ if ( !embedFonts ) {
+ downloadMapping(s, global);
+ return;
+ }
+
+ //qDebug("downloading pfa font %s", psname.latin1() );
+ char* p = data.data();
+
+ s << "% Font resource\n";
+ for (int i=0; i < (int)data.size(); i++) s << p[i];
+ s << "% End of font resource\n";
+ downloadMapping( s, global );
+}
+
+// ================== PFB ====================
+
+class TQPSPrinterFontPFB
+ : public TQPSPrinterFontPrivate {
+public:
+ TQPSPrinterFontPFB(const TQFontEngine *f, TQByteArray& data);
+ virtual void download(TQTextStream& s, bool global);
+ virtual bool embedded() { return TRUE; }
+private:
+ TQByteArray data;
+};
+
+TQPSPrinterFontPFB::TQPSPrinterFontPFB(const TQFontEngine *f, TQByteArray& d)
+{
+ data = d;
+
+ int pos = 0;
+ int len;
+ // int typ;
+ unsigned char* p = (unsigned char*) data.data();
+ TQString fontname;
+
+ if (p[ pos ] != 0x80) { // PFB marker
+ qWarning("pfb file does not start with 0x80");
+ return;
+ }
+ pos++;
+ // typ = p[ pos ]; // 1=ascii 2=binary 3=done
+ pos++;
+ len = p[ pos ]; pos++;
+ len |= (p[ pos ] << 8) ; pos++;
+ len |= (p[ pos ] << 16); pos++;
+ len |= (p[ pos ] << 24); pos++;
+
+ //printf("font block type %d len %d\n",typ,len);
+
+ char* fontnameptr = strstr((char*)p+pos,"/FontName");
+ if (fontnameptr == NULL)
+ return;
+
+ fontnameptr += strlen("/FontName") + 1;
+ while (*fontnameptr == ' ' || *fontnameptr == '/') fontnameptr++;
+ int l=0;
+ while (fontnameptr[l] != ' ') l++;
+
+ psname = TQString::tqfromLatin1(fontnameptr,l);
+ tqreplacementList = makePSFontNameList( f, psname );
+}
+
+void TQPSPrinterFontPFB::download(TQTextStream& s, bool global)
+{
+ emitPSFontNameList( s, psname, tqreplacementList);
+
+ if ( !embedFonts ) {
+ downloadMapping(s, global);
+ return;
+ }
+
+ //qDebug("downloading pfb font %s", psname.latin1() );
+ unsigned char* p = (unsigned char*) data.data();
+ int pos;
+ int len;
+ int typ;
+
+ int hexcol = 0;
+ int line_length = 64;
+
+ s << "% Font resource\n";
+
+ pos = 0;
+ typ = -1;
+ while (typ != 3) { // not end of file
+ if (p[ pos ] != 0x80) // PFB marker
+ return; // pfb file does not start with 0x80
+ pos++;
+ typ = p[ pos ]; // 1=ascii 2=binary 3=done
+ pos++;
+
+ if (typ == 3) break;
+
+ len = p[ pos ]; pos++;
+ len |= (p[ pos ] << 8) ; pos++;
+ len |= (p[ pos ] << 16); pos++;
+ len |= (p[ pos ] << 24); pos++;
+
+ //qDebug("font block type %d len %d",typ,len);
+
+ int end = pos + len;
+ if (typ==1) {
+ while (pos < end) {
+ if (hexcol > 0) {
+ s << "\n";
+ hexcol = 0;
+ }
+ //qWarning(TQString::tqfromLatin1((char*)(p+pos),1));
+ if (p[pos] == '\r' || p[pos] == '\n') {
+ s << "\n";
+ while (pos < end && (p[pos] == '\r' || p[pos] == '\n'))
+ pos++;
+ } else {
+ s << TQString::tqfromLatin1((char*)(p+pos),1);
+ pos++;
+ }
+ }
+ }
+ if (typ==2) {
+ static const char *hexchar = "0123456789abcdef";
+ while (pos < end) {
+ /* trim hexadecimal lines to line_length columns */
+ if (hexcol >= line_length) {
+ s << "\n";
+ hexcol = 0;
+ }
+ s << TQString::tqfromLatin1(hexchar+((p[pos] >> 4) & 0xf),1)
+ << TQString::tqfromLatin1(hexchar+((p[pos] ) & 0xf),1);
+ pos++;
+ hexcol += 2;
+ }
+ }
+ }
+ s << "% End of font resource\n";
+ downloadMapping( s, global );
+}
+
+// ================== AFontFileNotFound ============
+
+
+
+class TQPSPrinterFontNotFound
+ : public TQPSPrinterFontPrivate {
+public:
+ TQPSPrinterFontNotFound(const TQFontEngine* f);
+ virtual void download(TQTextStream& s, bool global);
+private:
+ TQByteArray data;
+};
+
+TQPSPrinterFontNotFound::TQPSPrinterFontNotFound(const TQFontEngine* f)
+{
+ psname = makePSFontName( f );
+ tqreplacementList = makePSFontNameList( f );
+}
+
+void TQPSPrinterFontNotFound::download(TQTextStream& s, bool)
+{
+ //qDebug("downloading not found font %s", psname.latin1() );
+ emitPSFontNameList( s, psname, tqreplacementList );
+ s << "% No embeddable font for ";
+ s << psname;
+ s << " found\n";
+ TQPSPrinterFontPrivate::download(s, TRUE);
+}
+
+#ifndef TQT_NO_TEXTCODEC
+// =================== A font file for asian ============
+
+class TQPSPrinterFontAsian
+ : public TQPSPrinterFontPrivate {
+public:
+ TQPSPrinterFontAsian()
+ : TQPSPrinterFontPrivate(), codec( 0 ) {}
+ void download(TQTextStream& s, bool global);
+ TQString defineFont( TQTextStream &stream, const TQString &ps, const TQFont &f, const TQString &key,
+ TQPSPrinterPrivate *d );
+ void drawText( TQTextStream &stream, const TQPoint &p, TQTextEngine *engine, int item,
+ const TQString &text, TQPSPrinterPrivate *d, TQPainter *paint );
+
+ TQString makePSFontName( const TQFontEngine *f, int type ) const;
+ virtual TQString extension() const = 0;
+
+ TQTextCodec *codec;
+};
+
+TQString TQPSPrinterFontAsian::makePSFontName( const TQFontEngine *f, int type ) const
+{
+ TQString ps;
+ int i;
+
+ TQString family = f->fontDef.family.lower();
+
+ // try to make a "good" postscript name
+ ps = family.simplifyWhiteSpace();
+ i = 0;
+ while( (unsigned int)i < ps.length() ) {
+ if ( i != 0 && ps[i] == '[') {
+ if ( ps[i-1] == ' ' )
+ ps.truncate (i-1);
+ else
+ ps.truncate (i);
+ break;
+ }
+ if ( i == 0 || ps[i-1] == ' ' ) {
+ ps[i] = ps[i].upper();
+ if ( i )
+ ps.remove( i-1, 1 );
+ else
+ i++;
+ } else {
+ i++;
+ }
+ }
+
+ switch ( type ) {
+ case 1:
+ ps.append( TQString::tqfromLatin1("-Italic") );
+ break;
+ case 2:
+ ps.append( TQString::tqfromLatin1("-Bold") );
+ break;
+ case 3:
+ ps.append( TQString::tqfromLatin1("-BoldItalic") );
+ break;
+ case 0:
+ default:
+ break;
+ }
+
+ ps += extension();
+
+ return ps;
+}
+
+
+TQString TQPSPrinterFontAsian::defineFont( TQTextStream &stream, const TQString &ps, const TQFont &f,
+ const TQString &key, TQPSPrinterPrivate *d)
+{
+ TQString fontName;
+ TQString fontName2;
+
+ TQString *tmp = d->headerFontNames.tqfind( ps );
+
+ if ( d->buffer ) {
+ if ( tmp ) {
+ fontName = *tmp;
+ } else {
+ fontName.sprintf( "F%d", ++d->headerFontNumber );
+ d->fontStream << "/" << fontName << " false " << ps << "List MF\n";
+ d->headerFontNames.insert( ps, new TQString( fontName ) );
+ }
+ fontName2.sprintf( "F%d", ++d->headerFontNumber );
+ d->fontStream << "/" << fontName2 << " "
+ << pointSize( f, d->scale ) << "/" << fontName << " DF\n";
+ d->headerFontNames.insert( key, new TQString( fontName2 ) );
+ } else {
+ if ( tmp ) {
+ fontName = *tmp;
+ } else {
+ fontName.sprintf( "F%d", ++d->pageFontNumber );
+ stream << "/" << fontName << " false " << ps << "List MF\n";
+ d->pageFontNames.insert( ps, new TQString( fontName ) );
+ }
+ fontName2.sprintf( "F%d", ++d->pageFontNumber );
+ stream << "/" << fontName2 << " "
+ << pointSize( f, d->scale ) << "/" << fontName << " DF\n";
+ d->pageFontNames.insert( key, new TQString( fontName2 ) );
+ }
+ return fontName2;
+}
+
+
+void TQPSPrinterFontAsian::download(TQTextStream& s, bool)
+{
+ //qDebug("downloading asian font %s", psname.latin1() );
+ s << "% Asian postscript font requested. Using "
+ << psname << endl;
+ emitPSFontNameList( s, psname, tqreplacementList );
+}
+
+void TQPSPrinterFontAsian::drawText( TQTextStream &stream, const TQPoint &p, TQTextEngine *engine, int item,
+ const TQString &text, TQPSPrinterPrivate *d, TQPainter *paint)
+{
+ int len = engine->length( item );
+ TQScriptItem &si = engine->items[item];
+
+ int x = p.x() + si.x;
+ int y = p.y() + si.y;
+ if ( y != d->textY || d->textY == 0 )
+ stream << y << " Y";
+ d->textY = y;
+
+ TQString mdf;
+ if ( paint->font().underline() )
+ mdf += " " + TQString().setNum( y + d->fm.underlinePos() + d->fm.lineWidth() ) +
+ " " + toString( d->fm.lineWidth() ) + " Tl";
+ if ( paint->font().strikeOut() )
+ mdf += " " + TQString().setNum( y + d->fm.strikeOutPos() ) +
+ " " + toString( d->fm.lineWidth() ) + " Tl";
+ TQCString mb;
+ TQCString out;
+ TQString dummy( TQChar(0x20) );
+
+ if ( si.analysis.bidiLevel % 2 ) {
+ for ( int i = len-1; i >= 0; i-- ) {
+ TQChar ch = text.tqunicode()[i];
+ if ( !ch.row() ) {
+ ; // ignore, we should never get here anyway
+ } else {
+ if ( codec ) {
+ dummy[0] = ch;
+ mb = codec->fromUnicode( dummy );
+ } else
+ mb = " ";
+
+ for ( unsigned int j = 0; j < mb.length (); j++ ) {
+ if ( mb.at(j) == '(' || mb.at(j) == ')' || mb.at(j) == '\\' )
+ out += "\\";
+ out += mb.at(j);
+ }
+ }
+ }
+ } else {
+ for ( int i = 0; i < len; i++ ) {
+ TQChar ch = text.tqunicode()[i];
+ if ( !ch.row() ) {
+ ; // ignore, we should never get here anyway
+ } else {
+ if ( codec ) {
+ dummy[0] = ch;
+ mb = codec->fromUnicode( dummy );
+ } else
+ mb = " ";
+
+ for ( unsigned int j = 0; j < mb.length (); j++ ) {
+ if ( mb.at(j) == '(' || mb.at(j) == ')' || mb.at(j) == '\\' )
+ out += "\\";
+ out += mb.at(j);
+ }
+ }
+ }
+ }
+ stream << "(" << out << ")" << si.width << " " << x << mdf << " AT\n";
+}
+
+// ----------- Japanese --------------
+
+static const psfont Japanese1 [] = {
+ { "Ryumin-Light-H", 0, 100. },
+ { "Ryumin-Light-H", 0.2, 100. },
+ { "GothicBBB-Medium-H", 0, 100. },
+ { "GothicBBB-Medium-H", 0.2, 100. }
+};
+
+static const psfont Japanese1a [] = {
+ { "GothicBBB-Medium-H", 0, 100. },
+ { "GothicBBB-Medium-H", 0.2, 100. },
+ { "Ryumin-Light-H", 0, 100. },
+ { "Ryumin-Light-H", 0.2, 100. }
+};
+
+static const psfont Japanese2 [] = {
+ { "GothicBBB-Medium-H", 0, 100. },
+ { "GothicBBB-Medium-H", 0.2, 100. },
+ { "GothicBBB-Medium-H", 0, 100. },
+ { "GothicBBB-Medium-H", 0.2, 100. }
+};
+
+static const psfont Japanese2a [] = {
+ { "Ryumin-Light-H", 0, 100. },
+ { "Ryumin-Light-H", 0.2, 100. },
+ { "Ryumin-Light-H", 0, 100. },
+ { "Ryumin-Light-H", 0.2, 100. }
+};
+
+
+// Wadalab fonts
+
+static const psfont WadaMin [] = {
+ { "WadaMin-Regular-H", 0, 100. },
+ { "WadaMin-Regular-H", 0.2, 100. },
+ { "WadaMin-Bold-H", 0, 100. },
+ { "WadaMin-Bold-H", 0.2, 100. }
+};
+
+static const psfont WadaGo [] = {
+ { "WadaMaruGo-Regular-H", 0, 100. },
+ { "WadaMaruGo-Regular-H", 0.2, 100. },
+ { "WadaGo-Bold-H", 0, 100. },
+ { "WadaGo-Bold-H", 0.2, 100. }
+};
+
+// Adobe Wadalab
+
+static const psfont WadaGoAdobe [] = {
+ { "WadaMaruGo-RegularH-Hojo-H", 0, 100. },
+ { "WadaMaruGo-RegularH-Hojo-H", 0.2, 100. },
+ { "WadaMaruGo-RegularH-Hojo-H", 0, 100. },
+ { "WadaMaruGo-RegularH-Hojo-H", 0.2, 100. },
+};
+static const psfont WadaMinAdobe [] = {
+ { "WadaMin-RegularH-Hojo-H", 0, 100. },
+ { "WadaMin-RegularH-Hojo-H", 0.2, 100. },
+ { "WadaMin-RegularH-Hojo-H", 0, 100. },
+ { "WadaMin-RegularH-Hojo-H", 0.2, 100. },
+};
+
+
+static const psfont * const Japanese1Replacements[] = {
+ Japanese1, Japanese1a, WadaMin, WadaGo, WadaMinAdobe, WadaGoAdobe, 0
+};
+static const psfont * const Japanese2Replacements[] = {
+ Japanese2, Japanese2a, WadaMin, WadaGo, WadaMinAdobe, WadaGoAdobe, 0
+};
+
+class TQPSPrinterFontJapanese
+ : public TQPSPrinterFontAsian {
+public:
+ TQPSPrinterFontJapanese(const TQFontEngine* f);
+ virtual TQString extension() const;
+};
+
+TQPSPrinterFontJapanese::TQPSPrinterFontJapanese(const TQFontEngine* f)
+{
+ codec = TQTextCodec::codecForMib( 63 ); // jisx0208.1983-0
+
+ int type = getPsFontType( f );
+ psname = makePSFontName( f, type );
+ TQString best = "[ /" + psname + " 1.0 0.0 ]";
+ tqreplacementList.append( best );
+
+ const psfont *const *tqreplacements = ( psname.tqcontains( "Helvetica" ) ? Japanese2Replacements : Japanese1Replacements );
+ appendReplacements( tqreplacementList, tqreplacements, type );
+}
+
+TQString TQPSPrinterFontJapanese::extension() const
+{
+ return "-H";
+}
+
+// ----------- Korean --------------
+
+// sans serif
+static const psfont SMGothic [] = {
+ { "SMGothic-Medium-KSC-EUC-H", 0, 100. },
+ { "SMGothic-Medium-KSC-EUC-H", 0.2, 100. },
+ { "SMGothic-DemiBold-KSC-EUC-H", 0, 100. },
+ { "SMGothic-DemiBold-KSC-EUC-H", 0.2, 100. }
+};
+
+// serif
+#if 0 // ### this is never used?
+static const psfont SMMyungjo [] = {
+ { "SMMyungjo-Light-KSC-EUC-H", 0, 100. },
+ { "SMMyungjo-Light-KSC-EUC-H", 0.2, 100. },
+ { "SMMyungjo-Bold-KSC-EUC-H", 0, 100. },
+ { "SMMyungjo-Bold-KSC-EUC-H", 0.2, 100. }
+};
+#endif
+
+static const psfont MKai [] = {
+ { "MingMT-Light-KSC-EUC-H", 0, 100. },
+ { "MingMT-Light-KSC-EUC-H", 0.2, 100. },
+ { "MKai-Medium-KSC-EUC-H", 0, 100. },
+ { "MKai-Medium-KSC-EUC-H", 0.2, 100. },
+};
+
+
+static const psfont Munhwa [] = {
+ { "Munhwa-Regular-KSC-EUC-H", 0, 100. },
+ { "Munhwa-Regular-KSC-EUC-H", 0.2, 100. },
+ { "Munhwa-Bold-KSC-EUC-H", 0, 100. },
+ { "Munhwa-Bold-KSC-EUC-H", 0.2, 100. }
+};
+
+static const psfont MunhwaGothic [] = {
+ { "MunhwaGothic-Regular-KSC-EUC-H", 0, 100. },
+ { "MunhwaGothic-Regular-KSC-EUC-H", 0.2, 100. },
+ { "MunhwaGothic-Bold-KSC-EUC-H", 0, 100. },
+ { "MunhwaGothic-Bold-KSC-EUC-H", 0.2, 100. }
+};
+
+static const psfont MunhwaGungSeo [] = {
+ { "MunhwaGungSeo-Light-KSC-EUC-H", 0, 100. },
+ { "MunhwaGungSeo-Light-KSC-EUC-H", 0.2, 100. },
+ { "MunhwaGungSeo-Bold-KSC-EUC-H", 0, 100. },
+ { "MunhwaGungSeo-Bold-KSC-EUC-H", 0.2, 100. }
+};
+
+static const psfont MunhwaGungSeoHeulim [] = {
+ { "MunhwaGungSeoHeulim-Light-KSC-EUC-H", 0, 100. },
+ { "MunhwaGungSeoHeulim-Light-KSC-EUC-H", 0.2, 100. },
+ { "MunhwaGungSeoHeulim-Bold-KSC-EUC-H", 0, 100. },
+ { "MunhwaGungSeoHeulim-Bold-KSC-EUC-H", 0.2, 100. }
+};
+
+static const psfont MunhwaHoonMin [] = {
+ { "MunhwaHoonMin-Regular-KSC-EUC-H", 0, 100. },
+ { "MunhwaHoonMin-Regular-KSC-EUC-H", 0.2, 100. },
+ { "MunhwaHoonMin-Regular-KSC-EUC-H", 0, 100. },
+ { "MunhwaHoonMin-Regular-KSC-EUC-H", 0.2, 100. }
+};
+
+static const psfont BaekmukGulim [] = {
+ { "Baekmuk-Gulim-KSC-EUC-H", 0, 100. },
+ { "Baekmuk-Gulim-KSC-EUC-H", 0.2, 100. },
+ { "Baekmuk-Gulim-KSC-EUC-H", 0, 100. },
+ { "Baekmuk-Gulim-KSC-EUC-H", 0.2, 100. }
+};
+
+static const psfont * const KoreanReplacements[] = {
+ BaekmukGulim, SMGothic, Munhwa, MunhwaGothic, MKai, MunhwaGungSeo,
+ MunhwaGungSeoHeulim, MunhwaHoonMin, Helvetica, 0
+};
+
+class TQPSPrinterFontKorean
+ : public TQPSPrinterFontAsian {
+public:
+ TQPSPrinterFontKorean(const TQFontEngine* f);
+ TQString extension() const;
+};
+
+TQPSPrinterFontKorean::TQPSPrinterFontKorean(const TQFontEngine* f)
+{
+ codec = TQTextCodec::codecForMib( 38 ); // eucKR
+ int type = getPsFontType( f );
+ psname = makePSFontName( f, type );
+ TQString best = "[ /" + psname + " 1.0 0.0 ]";
+ tqreplacementList.append( best );
+ appendReplacements( tqreplacementList, KoreanReplacements, type );
+}
+
+TQString TQPSPrinterFontKorean::extension() const
+{
+ return "-KSC-EUC-H";
+}
+// ----------- traditional chinese ------------
+
+// Arphic Public License Big5 TrueType fonts (on Debian and CLE and others)
+static const psfont ShanHeiSun [] = {
+ { "ShanHeiSun-Light-ETen-B5-H", 0, 100. },
+ { "ShanHeiSun-Light-ETen-B5-H", 0.2, 100. },
+ { "ShanHeiSun-Light-ETen-B5-H", 0, 100. },
+ { "ShanHeiSun-Light-ETen-B5-H", 0.2, 100. },
+};
+static const psfont ZenKai [] = {
+ { "ZenKai-Medium-ETen-B5-H", 0, 100. },
+ { "ZenKai-Medium-Italic-ETen-B5-H", 0.2, 100. },
+ { "ZenKai-Medium-Bold-ETen-B5-H", 0, 100. },
+ { "ZenKai-Medium-BoldItalic-ETen-B5-H", 0.2, 100. },
+};
+
+// Fonts on Turbolinux
+static const psfont SongB5 [] = {
+ { "B5-MSung-Light-ETen-B5-H", 0, 100. },
+ { "B5-MSung-Italic-ETen-B5-H", 0, 100. },
+ { "B5-MSung-Bold-ETen-B5-H", 0, 100. },
+ { "B5-MSung-BoldItalic-ETen-B5-H", 0, 100. },
+};
+static const psfont KaiB5 [] = {
+ { "B5-MKai-Medium-ETen-B5-H", 0, 100. },
+ { "B5-MKai-Italic-ETen-B5-H", 0, 100. },
+ { "B5-MKai-Bold-ETen-B5-H", 0, 100. },
+ { "B5-MKai-BoldItalic-ETen-B5-H", 0, 100. },
+};
+static const psfont HeiB5 [] = {
+ { "B5-MHei-Medium-ETen-B5-H", 0, 100. },
+ { "B5-MHei-Italic-ETen-B5-H", 0, 100. },
+ { "B5-MHei-Bold-ETen-B5-H", 0, 100. },
+ { "B5-MHei-BoldItalic-ETen-B5-H", 0, 100. },
+};
+static const psfont FangSongB5 [] = {
+ { "B5-CFangSong-Light-ETen-B5-H", 0, 100. },
+ { "B5-CFangSong-Italic-ETen-B5-H", 0, 100. },
+ { "B5-CFangSong-Bold-ETen-B5-H", 0, 100. },
+ { "B5-CFangSong-BoldItalic-ETen-B5-H", 0, 100. },
+};
+
+// Arphic fonts on Thiz Linux
+static const psfont LinGothic [] = {
+ { "LinGothic-Light-ETen-B5-H", 0, 100. },
+ { "LinGothic-Light-Italic-ETen-B5-H", 0.2, 100. },
+ { "LinGothic-Light-Bold-ETen-B5-H", 0, 100. },
+ { "LinGothic-Light-BoldItalic-ETen-B5-H", 0.2, 100. },
+};
+static const psfont YenRound [] = {
+ { "YenRound-Light-ETen-B5-H", 0, 100. },
+ { "YenRound-Light-Italic-ETen-B5-H", 0.2, 100. },
+ { "YenRound-Light-Bold-ETen-B5-H", 0, 100. },
+ { "YenRound-Light-BoldItalic-ETen-B5-H", 0.2, 100. },
+};
+
+// Dr. Wang Hann-Tzong's GPL'ed Big5 TrueType fonts
+#if 0 // ### this is never used?
+static const psfont HtWFangSong [] = {
+ { "HtW-FSong-Light-ETen-B5-H", 0, 100. },
+ { "HtW-FSong-Light-Italic-ETen-B5-H", 0.2, 100. },
+ { "HtW-FSong-Light-Bold-ETen-B5-H", 0, 100. },
+ { "HtW-FSong-Light-BoldItalic-ETen-B5-H", 0.2, 100. },
+};
+#endif
+
+static const psfont MingB5 [] = {
+ { "Ming-Light-ETen-B5-H", 0, 100. },
+ { "Ming-Light-Italic-ETen-B5-H", 0.2, 100. },
+ { "Ming-Light-Bold-ETen-B5-H", 0, 100. },
+ { "Ming-Light-BoldItalic-ETen-B5-H", 0.2, 100. },
+};
+
+// Microsoft's Ming/Sung font?
+static const psfont MSung [] = {
+ { "MSung-Light-ETenms-B5-H", 0, 100. },
+ { "MSung-Light-ETenms-B5-H", 0.2, 100. },
+ { "MSung-Light-ETenms-B5-H", 0, 100. },
+ { "MSung-Light-ETenms-B5-H", 0.2, 100. },
+};
+// "Standard Sung/Ming" font by Taiwan Ministry of Education
+static const psfont MOESung [] = {
+ { "MOESung-Regular-B5-H", 0, 100. },
+ { "MOESung-Regular-B5-H", 0.2, 100. },
+ { "MOESung-Regular-B5-H", 0, 100. },
+ { "MOESung-Regular-B5-H", 0.2, 100. },
+};
+
+static const psfont MOEKai [] = {
+ { "MOEKai-Regular-B5-H", 0, 100. },
+ { "MOEKai-Regular-B5-H", 0.2, 100. },
+ { "MOEKai-Regular-B5-H", 0, 100. },
+ { "MOEKai-Regular-B5-H", 0.2, 100. },
+};
+
+static const psfont * const TraditionalReplacements[] = {
+ MOESung, SongB5, ShanHeiSun, MingB5, MSung, FangSongB5, KaiB5, ZenKai, HeiB5,
+ LinGothic, YenRound, MOEKai, Helvetica, 0
+ };
+
+#if 0 // ### these are never used?
+static const psfont * const SongB5Replacements[] = {
+ SongB5, ShanHeiSun, MingB5, MSung, MOESung, Helvetica, 0
+ };
+
+static const psfont * const FangSongB5Replacements[] = {
+ FangSongB5, HtWFangSong, Courier, 0
+ };
+static const psfont * const KaiB5Replacements[] = {
+ KaiB5, ZenKai, Times, 0
+ };
+static const psfont * const HeiB5Replacements[] = {
+ HeiB5, LinGothic, YenRound, LucidaSans, 0
+ };
+static const psfont * const YuanB5Replacements[] = {
+ YenRound, LinGothic, HeiB5, LucidaSans, 0
+ };
+#endif
+
+
+class TQPSPrinterFontTraditionalChinese
+ : public TQPSPrinterFontAsian {
+public:
+ TQPSPrinterFontTraditionalChinese(const TQFontEngine* f);
+ TQString extension() const;
+};
+
+TQPSPrinterFontTraditionalChinese::TQPSPrinterFontTraditionalChinese(const TQFontEngine* f)
+{
+ codec = TQTextCodec::codecForMib( 2026 ); // Big5-0
+ int type = getPsFontType( f );
+ psname = makePSFontName( f, type );
+ TQString best = "[ /" + psname + " 1.0 0.0 ]";
+ tqreplacementList.append( best );
+ appendReplacements( tqreplacementList, TraditionalReplacements, type );
+}
+
+TQString TQPSPrinterFontTraditionalChinese::extension() const
+{
+ return "-ETen-B5-H";
+}
+
+// ----------- simplified chinese ------------
+
+#if 0
+// GB18030 fonts on XteamLinux (?)
+static const psfont SimplifiedGBK2K [] = {
+ { "MSung-Light-GBK2K-H", 0, 100. },
+ { "MSung-Light-GBK2K-H", 0.2, 100. },
+ { "MKai-Medium-GBK2K-H", 0, 100. },
+ { "MKai-Medium-GBK2K-H", 0.2, 100. },
+};
+#endif
+
+// GB18030 fonts on Turbolinux
+static const psfont SongGBK2K [] = {
+ { "MSung-Light-GBK2K-H", 0, 100. },
+ { "MSung-Italic-GBK2K-H", 0, 100. },
+ { "MSung-Bold-GBK2K-H", 0, 100. },
+ { "MSung-BoldItalic-GBK2K-H", 0, 100. },
+};
+static const psfont KaiGBK2K [] = {
+ { "MKai-Medium-GBK2K-H", 0, 100. },
+ { "MKai-Italic-GBK2K-H", 0, 100. },
+ { "MKai-Bold-GBK2K-H", 0, 100. },
+ { "MKai-BoldItalic-GBK2K-H", 0, 100. },
+};
+static const psfont HeiGBK2K [] = {
+ { "MHei-Medium-GBK2K-H", 0, 100. },
+ { "MHei-Italic-GBK2K-H", 0, 100. },
+ { "MHei-Bold-GBK2K-H", 0, 100. },
+ { "MHei-BoldItalic-GBK2K-H", 0, 100. },
+};
+static const psfont FangSongGBK2K [] = {
+ { "CFangSong-Light-GBK2K-H", 0, 100. },
+ { "CFangSong-Italic-GBK2K-H", 0, 100. },
+ { "CFangSong-Bold-GBK2K-H", 0, 100. },
+ { "CFangSong-BoldItalic-GBK2K-H", 0, 100. },
+};
+
+static const psfont Simplified [] = {
+ { "MSung-Light-GBK-EUC-H", 0, 100. },
+ { "MSung-Light-GBK-EUC-H", 0.2, 100. },
+ { "MKai-Medium-GBK-EUC-H", 0, 100. },
+ { "MKai-Medium-GBK-EUC-H", 0.2, 100. },
+};
+
+static const psfont MSungGBK [] = {
+ { "MSung-Light-GBK-EUC-H", 0, 100. },
+ { "MSung-Light-GBK-EUC-H", 0.2, 100. },
+ { "MSung-Light-GBK-EUC-H", 0, 100. },
+ { "MSung-Light-GBK-EUC-H", 0.2, 100. },
+};
+
+static const psfont FangSong [] = {
+ { "CFangSong-Light-GBK-EUC-H", 0, 100. },
+ { "CFangSong-Light-GBK-EUC-H", 0.2, 100. },
+ { "CFangSong-Light-GBK-EUC-H", 0, 100. },
+ { "CFangSong-Light-GBK-EUC-H", 0.2, 100. },
+};
+
+// Arphic Public License GB2312 TrueType fonts (on Debian and CLE and others)
+static const psfont BousungEG [] = {
+ { "BousungEG-Light-GB-GB-EUC-H", 0, 100. },
+ { "BousungEG-Light-GB-GB-EUC-H", 0.2, 100. },
+ { "BousungEG-Light-GB-Bold-GB-EUC-H", 0, 100. },
+ { "BousungEG-Light-GB-Bold-GB-EUC-H", 0.2, 100. },
+};
+static const psfont GBZenKai [] = {
+ { "GBZenKai-Medium-GB-GB-EUC-H", 0, 100. },
+ { "GBZenKai-Medium-GB-GB-EUC-H", 0.2, 100. },
+ { "GBZenKai-Medium-GB-Bold-GB-EUC-H", 0, 100. },
+ { "GBZenKai-Medium-GB-Bold-GB-EUC-H", 0.2, 100. },
+};
+
+static const psfont * const SimplifiedReplacements[] = {
+ SongGBK2K, FangSongGBK2K, KaiGBK2K, HeiGBK2K,
+ Simplified, MSungGBK, FangSong, BousungEG, GBZenKai, Helvetica, 0
+ };
+#if 0
+static const psfont * const SongGBK2KReplacements[] = {
+ SongGBK2K, MSungGBK, BousungEG, Helvetica, 0
+ };
+#endif
+static const psfont * const FangSongGBK2KReplacements[] = {
+ FangSongGBK2K, FangSong, Courier, 0
+ };
+static const psfont * const KaiGBK2KReplacements[] = {
+ KaiGBK2K, GBZenKai, Times, 0
+ };
+static const psfont * const HeiGBK2KReplacements[] = {
+ HeiGBK2K, LucidaSans, 0
+ };
+
+class TQPSPrinterFontSimplifiedChinese
+ : public TQPSPrinterFontAsian {
+public:
+ TQPSPrinterFontSimplifiedChinese(const TQFontEngine* f);
+ TQString extension() const;
+};
+
+TQPSPrinterFontSimplifiedChinese::TQPSPrinterFontSimplifiedChinese(const TQFontEngine* f)
+{
+ codec = TQTextCodec::codecForMib( 114 ); // GB18030
+ int type = getPsFontType( f );
+ TQString family = f->fontDef.family.lower();
+ if( family.tqcontains("kai",FALSE) ) {
+ psname = KaiGBK2K[type].psname;
+ appendReplacements( tqreplacementList, KaiGBK2KReplacements, type );
+ } else if( family.tqcontains("fangsong",FALSE) ) {
+ psname = FangSongGBK2K[type].psname;
+ appendReplacements( tqreplacementList, FangSongGBK2KReplacements, type );
+ } else if( family.tqcontains("hei",FALSE) ) {
+ psname = HeiGBK2K[type].psname;
+ appendReplacements( tqreplacementList, HeiGBK2KReplacements, type );
+ } else {
+ psname = SongGBK2K[type].psname;
+ appendReplacements( tqreplacementList, SimplifiedReplacements, type );
+ }
+ //qDebug("simplified chinese: fontname is %s, psname=%s", f.family().latin1(), psname.latin1() );
+}
+
+TQString TQPSPrinterFontSimplifiedChinese::extension() const
+{
+ return "-GBK2K-H";
+}
+
+#endif
+
+
+// ================== TQPSPrinterFont ====================
+
+class TQPSPrinterFont {
+public:
+ TQPSPrinterFont(const TQFont& f, int script, TQPSPrinterPrivate *priv);
+ ~TQPSPrinterFont();
+ TQString postScriptFontName() { return p->postScriptFontName(); }
+ TQString defineFont( TQTextStream &stream, const TQString &ps, const TQFont &f, const TQString &key,
+ TQPSPrinterPrivate *d )
+ { return p->defineFont( stream, ps, f, key, d ); }
+ void download(TQTextStream& s, bool global) { p->download(s, global); }
+ TQPSPrinterFontPrivate *handle() { return p; }
+ TQString xfontname;
+private:
+ TQByteArray data;
+ TQPSPrinterFontPrivate* p;
+};
+
+TQPSPrinterFont::~TQPSPrinterFont()
+{
+ // the dict in TQFontPrivate does deletion for us.
+ // delete p;
+}
+
+
+TQPSPrinterFont::TQPSPrinterFont(const TQFont &f, int script, TQPSPrinterPrivate *priv)
+ : p(0)
+{
+ TQString fontfilename;
+ TQString fontname;
+
+ enum { NONE, PFB, PFA, TTF } type = NONE;
+
+ TQFontEngine *engine = f.d->engineForScript( (TQFont::Script) script );
+ // ### implement similar code for TQWS and WIN
+ xfontname = makePSFontName( engine );
+
+#if defined( TQ_WS_X11 )
+ bool xlfd = FALSE;
+ //qDebug("engine = %p name=%s, script=%d", engine, engine ? engine->name() : "(null)", script);
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( qt_has_xft && engine && engine->type() == TQFontEngine::Xft ) {
+ XftPattern *pattern = static_cast<TQFontEngineXft *>( engine )->pattern();
+ char *filename = 0;
+ XftPatternGetString (pattern, XFT_FILE, 0, &filename);
+ //qDebug("filename for font is '%s'", filename);
+ if ( filename ) {
+ fontfilename = TQString::fromLocal8Bit( filename );
+ xfontname = fontfilename;
+ }
+ } else
+#endif
+ {
+ TQString rawName;
+ if ( engine && engine != (TQFontEngine *)-1 )
+ rawName = engine->name();
+ int index = rawName.tqfind('-');
+ if (index == 0) {
+ // this is an XLFD font name
+ for (int i=0; i < 6; i++) {
+ index = rawName.tqfind('-',index+1);
+ }
+ xfontname = rawName.mid(0,index);
+ if ( xfontname.endsWith( "*" ) )
+ xfontname.truncate( xfontname.length() - 1 );
+ xlfd = TRUE;
+ }
+ }
+#endif // TQ_WS_X11
+#ifndef TQT_NO_TEXTCODEC
+ // map some scripts to something more useful
+ if ( script == TQFont::Han ) {
+ TQTextCodec *lc = TQTextCodec::codecForLocale();
+ switch( lc->mibEnum() ) {
+ case 36: // KS C 5601
+ case 38: // EUC KR
+ script = TQFont::Hangul;
+ break;
+
+ case 57: // gb2312.1980-0
+ case 113: // GBK
+ case -113: // gbk-0
+ case 114: // GB18030
+ case -114: // gb18030-0
+ case 2025: // GB2312
+ case 2026: // Big5
+ case -2026: // Big5-HKSCS
+ case 2101: // big5-0, big5.eten-0
+ case -2101: // big5hkscs-0, hkscs-1
+ break;
+
+ case 16: // JIS7
+ case 17: // SJIS
+ case 18: // EUC JP
+ case 63: // JIS X 0208
+ default:
+ script = TQFont::Hiragana;
+ break;
+ }
+ } else if ( script == TQFont::Katakana )
+ script = TQFont::Hiragana;
+ else if ( script == TQFont::Bopomofo )
+ script = TQFont::Han;
+#endif
+
+ TQString searchname = xfontname;
+#if defined(TQ_WS_X11)
+ // we need an extension here due to the fact that we use different
+ // fonts for different scripts
+ if ( xlfd && script >= TQFont::Han && script <= TQFont::Bopomofo )
+ xfontname += "/" + toString( script );
+#endif
+
+ //qDebug("looking for font %s in dict", xfontname.latin1() );
+ p = priv->fonts.tqfind(xfontname);
+ if ( p )
+ return;
+
+#if defined(TQ_WS_X11)
+ if ( xlfd ) {
+
+ for (TQStringList::Iterator it=priv->fontpath.begin(); it!=priv->fontpath.end() && fontfilename.isEmpty(); ++it) {
+ if ((*it).left(1) != "/") continue; // not a path name, a font server
+ TQString fontmapname;
+ int num = 0;
+ // search font.dir and font.scale for the right file
+ while ( num < 2 ) {
+ if ( num == 0 )
+ fontmapname = (*it) + "/fonts.scale";
+ else
+ fontmapname = (*it) + "/fonts.dir";
+ //qWarning(fontmapname);
+ TQFile fontmap(fontmapname);
+ if (fontmap.open(IO_ReadOnly)) {
+ while (!fontmap.atEnd()) {
+ TQString mapping;
+ fontmap.readLine(mapping,512);
+ // fold to lower (since X folds to lowercase)
+ //qWarning(xfontname);
+ //qWarning(mapping);
+ if (mapping.lower().tqcontains(searchname.lower())) {
+ int index = mapping.tqfind(' ',0);
+ TQString ffn = mapping.mid(0,index);
+ // remove the most common bitmap formats
+ if( !ffn.tqcontains( ".pcf" ) && !ffn.tqcontains( ".bdf" ) &&
+ !ffn.tqcontains( ".spd" ) && !ffn.tqcontains( ".phont" ) ) {
+ fontfilename = (*it) + TQString("/") + ffn;
+ if ( TQFile::exists(fontfilename) ) {
+ //qDebug("found font file %s", fontfilename.latin1());
+ break;
+ } else // unset fontfilename
+ fontfilename = TQString();
+ }
+ }
+ }
+ fontmap.close();
+ }
+ num++;
+ }
+ }
+ }
+#endif
+
+ //qDebug("font=%s, fontname=%s, file=%s, p=%p", f.family().latin1(), xfontname.latin1(), fontfilename.latin1(), p);
+
+ // memory mapping would be better here
+ if (fontfilename.length() > 0) { // maybe there is no file name
+ TQFile fontfile(fontfilename);
+ if ( fontfile.exists() ) {
+ //printf("font name %s size = %d\n",fontfilename.latin1(),fontfile.size());
+ data = TQByteArray( fontfile.size() );
+
+ fontfile.open(IO_Raw | IO_ReadOnly);
+ fontfile.readBlock(data.data(), fontfile.size());
+ fontfile.close();
+ }
+ }
+
+ if (!data.isNull() && data.size() > 0) {
+ unsigned char* d = (unsigned char *)data.data();
+ if (d[0] == 0x80 && d[1] == 0x01 && d[6] == '%' && d[7] == '!')
+ type = PFB;
+ else if (d[0] == '%' && d[1] == '!' && d[2] == 'P' && d[3] == 'S')
+ type = PFA;
+ else if (d[0]==0x00 && d[1]==0x01 && d[2]==0x00 && d[3]==0x00)
+ type = TTF;
+ else
+ type = NONE;
+ } else
+ type = NONE;
+
+ //qDebug("font is of type %d", type );
+ switch (type) {
+ case TTF :
+ p = new TQPSPrinterFontTTF(engine, data);
+ break;
+ case PFB:
+ p = new TQPSPrinterFontPFB(engine, data);
+ break;
+ case PFA:
+ p = new TQPSPrinterFontPFA(engine, data);
+ break;
+ case NONE:
+ default:
+
+#ifndef TQT_NO_TEXTCODEC
+
+ if ( script == TQFont::Hiragana )
+ p = new TQPSPrinterFontJapanese( engine );
+ else if ( script == TQFont::Hangul )
+ p = new TQPSPrinterFontKorean( engine );
+ else if ( script == TQFont::Han ) {
+ TQTextCodec *lc = TQTextCodec::codecForLocale();
+ switch( lc->mibEnum() ) {
+ case 2025: // GB2312
+ case 57: // gb2312.1980-0
+ case 113: // GBK
+ case -113: // gbk-0
+ case 114: // GB18030
+ case -114: // gb18030-0
+ p = new TQPSPrinterFontSimplifiedChinese( engine );
+ break;
+ case 2026: // Big5
+ case -2026: // big5-0, big5.eten-0
+ case 2101: // Big5-HKSCS
+ case -2101: // big5hkscs-0, hkscs-1
+ p = new TQPSPrinterFontTraditionalChinese( engine );
+ break;
+ default:
+ p = new TQPSPrinterFontJapanese( engine );
+ }
+ } else
+#endif
+ //qDebug("didnt tqfind font for %s", xfontname.latin1());
+ p = new TQPSPrinterFontNotFound( engine );
+ break;
+ }
+
+ if (p->postScriptFontName() == "Symbol")
+ p->setSymbol();
+
+ // this is needed to make sure we don't get the same postscriptname twice
+ TQDictIterator<TQPSPrinterFontPrivate> it( priv->fonts );
+ for( it.toFirst(); it.current(); ++it ) {
+ if ( *(*it) == *p ) {
+// qWarning("Post script driver: font already in dict");
+ delete p;
+ p = *it;
+ return;
+ }
+ }
+
+ //qDebug("inserting font %s in dict psname=%s", xfontname.latin1(), p->postScriptFontName().latin1() );
+ priv->fonts.insert( xfontname, p );
+}
+
+// ================= END OF PS FONT METHODS ============
+
+
+TQPSPrinterPrivate::TQPSPrinterPrivate( TQPrinter *prt, int filedes )
+ : buffer( 0 ), outDevice( 0 ), fd( filedes ), pageBuffer( 0 ), fonts(27, FALSE), fontBuffer(0), savedImage( 0 ),
+ dirtypen( FALSE ), dirtybrush( FALSE ), dirtyBkColor( FALSE ), bkMode( TQt::TransparentMode ), dirtyBkMode( FALSE ),
+#ifndef TQT_NO_TEXTCODEC
+ currentFontCodec( 0 ),
+#endif
+ fm( TQFont() ), textY( 0 )
+{
+ printer = prt;
+ headerFontNames.setAutoDelete( TRUE );
+ pageFontNames.setAutoDelete( TRUE );
+ fonts.setAutoDelete( TRUE );
+ currentFontFile = 0;
+ scale = 1.;
+ scriptUsed = -1;
+
+#ifdef TQ_WS_X11
+ // append qsettings fontpath
+ TQSettings settings;
+ embedFonts = settings.readBoolEntry( "/qt/embedFonts", TRUE );
+
+ int npaths;
+ char** font_path;
+ font_path = XGetFontPath( qt_xdisplay(), &npaths);
+ bool xfsconfig_read = FALSE;
+ for (int i=0; i<npaths; i++) {
+ // If we're using xfs, append font paths from /etc/X11/fs/config
+ // can't hurt, and chances are we'll get all fonts that way.
+ if (((font_path[i])[0] != '/') && !xfsconfig_read) {
+ // We're using xfs -> read its config
+ bool finished = FALSE;
+ TQFile f("/etc/X11/fs/config");
+ if ( !f.exists() )
+ f.setName("/usr/X11R6/lib/X11/fs/config");
+ if ( !f.exists() )
+ f.setName("/usr/X11/lib/X11/fs/config");
+ if ( f.exists() ) {
+ f.open(IO_ReadOnly);
+ while(f.status()==IO_Ok && !finished) {
+ TQString fs;
+ f.readLine(fs, 1024);
+ fs=fs.stripWhiteSpace();
+ if (fs.left(9)=="catalogue" && fs.tqcontains('=')) {
+ fs=fs.mid(fs.tqfind('=')+1).stripWhiteSpace();
+ bool end = FALSE;
+ while( f.status()==IO_Ok && !end ) {
+ if ( fs[int(fs.length())-1] == ',' )
+ fs = fs.left(fs.length()-1);
+ else
+ end = TRUE;
+ if (fs[0] != '#' && !fs.tqcontains(":unscaled"))
+ fontpath += fs;
+ f.readLine(fs, 1024);
+ fs=fs.stripWhiteSpace();
+ }
+ finished = TRUE;
+ }
+ }
+ f.close();
+ }
+ xfsconfig_read = TRUE;
+ } else if(!strstr(font_path[i], ":unscaled")) {
+ // Fonts paths marked :unscaled are always bitmapped fonts
+ // -> we can as well ignore them now and save time
+ fontpath += font_path[i];
+ }
+ }
+ XFreeFontPath(font_path);
+
+ // append qsettings fontpath
+ TQStringList fp = settings.readListEntry( "/qt/fontPath", ':' );
+ if ( !fp.isEmpty() )
+ fontpath += fp;
+#else
+ embedFonts = FALSE;
+#endif
+}
+
+TQPSPrinterPrivate::~TQPSPrinterPrivate()
+{
+ delete pageBuffer;
+}
+
+void TQPSPrinterPrivate::setFont( const TQFont & fnt, int script )
+{
+ TQFont f = fnt;
+ if ( f.rawMode() ) {
+ TQFont fnt( TQString::tqfromLatin1("Helvetica"), 12 );
+ setFont( fnt, TQFont::Unicode );
+ return;
+ }
+ if ( f.pointSize() == 0 ) {
+#if defined(CHECK_RANGE)
+ qWarning( "TQPrinter: Cannot set a font with zero point size." );
+#endif
+ f.setPointSize(TQApplication::font().pointSize());
+ if ( f.pointSize() == 0 )
+ f.setPointSize( 11 );
+ }
+
+ TQPSPrinterFont ff( f, script, this );
+ TQString ps = ff.postScriptFontName();
+
+ TQString s = ps;
+ s.append( ' ' );
+ s.prepend( ' ' );
+
+ TQString key = ff.xfontname;
+
+ if ( f.pointSize() != -1 )
+ key += " " + toString( f.pointSize() );
+ else
+ key += " px" + toString( f.pixelSize() );
+ TQString * tmp;
+ if ( !buffer )
+ tmp = pageFontNames.tqfind( key );
+ else
+ tmp = headerFontNames.tqfind( key );
+
+ TQString fontName;
+ if ( tmp )
+ fontName = *tmp;
+
+ if ( fontName.isEmpty() ) {
+ fontName = ff.defineFont( pageStream, ps, f, key, this );
+ }
+ pageStream << fontName << " F\n";
+
+ ps.append( ' ' );
+ ps.prepend( ' ' );
+ if ( !fontsUsed.tqcontains( ps ) )
+ fontsUsed += ps;
+
+#ifndef TQT_NO_TEXTCODEC
+ TQTextCodec * codec = 0;
+// ###
+// #ifndef TQT_NO_TEXTCODEC
+// i = 0;
+// do {
+// if ( tqunicodevalues[i].cs == f.charSet() )
+// codec = TQTextCodec::codecForMib( tqunicodevalues[i++].mib );
+// } while( codec == 0 && tqunicodevalues[i++].cs != tqunicodevalues_LAST );
+// #endif
+ currentFontCodec = codec;
+#endif
+ currentFont = fontName;
+ currentFontFile = ff.handle();
+ scriptUsed = script;
+}
+
+
+static void ps_r7( TQTextStream& stream, const char * s, int l )
+{
+ int i = 0;
+ uchar line[79];
+ int col = 0;
+
+ while( i < l ) {
+ line[col++] = s[i++];
+ if ( col >= 76 ) {
+ line[col++] = '\n';
+ line[col++] = '\0';
+ stream << (const char *)line;
+ col = 0;
+ }
+ }
+ if ( col > 0 ) {
+ while( (col&3) != 0 )
+ line[col++] = '%'; // use a comment as padding
+ line[col++] = '\n';
+ line[col++] = '\0';
+ stream << (const char *)line;
+ }
+}
+
+
+static const int quoteSize = 3; // 1-8 pixels
+static const int maxQuoteLength = 4+16+32+64+128+256; // magic extended quote
+static const int quoteReach = 10; // ... 1-1024 pixels back
+static const int tableSize = 1024; // 2 ** quoteReach;
+static const int numAttempts = 128;
+
+static const int hashSize = 71;
+
+static const int None = INT_MAX;
+
+/* puts the lowest numBits of data into the out array starting at postion (byte/bit).
+ Adjusts byte and bit to point ot the next position.
+
+ Need to make sure the out array is long enough before calling the method.
+*/
+static void emitBits( char *out, int & byte, int & bit,
+ int numBits, uint data )
+{
+ int b = 0;
+ uint d = data;
+ while( b < numBits ) {
+ if ( bit == 0 )
+ out[byte] = 0;
+ if ( d & 1 )
+ out[byte] = (uchar)out[byte] | ( 1 << bit );
+ d = d >> 1;
+ b++;
+ bit++;
+ if ( bit > 6 ) {
+ bit = 0;
+ byte++;
+ }
+ }
+}
+
+//#define DEBUG_COMPRESS
+#ifdef DEBUG_COMPRESS
+#include <tqdatetime.h>
+#endif
+
+static TQByteArray compress( const TQImage & image, bool gray ) {
+#ifdef DEBUG_COMPRESS
+ TQTime t;
+ t.start();
+ int sizeUncompressed[11];
+ for( int i = 0; i < 11; i++ )
+ sizeUncompressed[i] = 0;
+ int sizeCompressed[11];
+ for( int i = 0; i < 11; i++ )
+ sizeCompressed[i] = 0;
+#endif
+
+ int width = image.width();
+ int height = image.height();
+ int depth = image.depth();
+ int size = width*height;
+
+ int pastPixel[tableSize];
+ int mostRecentPixel[hashSize];
+ if ( depth == 1 )
+ size = (width+7)/8*height;
+ else if ( !gray )
+ size = size*3;
+
+ unsigned char *pixel = new unsigned char[size+1];
+ int i = 0;
+ if ( depth == 1 ) {
+ TQImage::Endian bitOrder = image.bitOrder();
+ memset( pixel, 0xff, size );
+ for( int y=0; y < height; y++ ) {
+ uchar * s = image.scanLine( y );
+ for( int x=0; x < width; x++ ) {
+ // need to copy bit for bit...
+ bool b = ( bitOrder == TQImage::LittleEndian ) ?
+ (*(s + (x >> 3)) >> (x & 7)) & 1 :
+ (*(s + (x >> 3)) << (x & 7)) & 0x80 ;
+ if ( b )
+ pixel[i >> 3] ^= (0x80 >> ( i & 7 ));
+ i++;
+ }
+ // we need to align to 8 bit here
+ i = (i+7) & 0xffffff8;
+ }
+ } else if ( depth == 8 ) {
+ for( int y=0; y < height; y++ ) {
+ uchar * s = image.scanLine( y );
+ for( int x=0; x < width; x++ ) {
+ TQRgb rgb = image.color( s[x] );
+ if ( gray ) {
+ pixel[i] = (unsigned char) tqGray( rgb );
+ i++;
+ } else {
+ pixel[i] = (unsigned char) tqRed( rgb );
+ pixel[i+1] = (unsigned char) tqGreen( rgb );
+ pixel[i+2] = (unsigned char) tqBlue( rgb );
+ i += 3;
+ }
+ }
+ }
+ } else {
+ bool alpha = image.hasAlphaBuffer();
+ for( int y=0; y < height; y++ ) {
+ TQRgb * s = (TQRgb*)(image.scanLine( y ));
+ for( int x=0; x < width; x++ ) {
+ TQRgb rgb = (*s++);
+ if ( alpha && tqAlpha( rgb ) < 0x40 ) // 25% alpha, convert to white -
+ rgb = tqRgb( 0xff, 0xff, 0xff );
+ if ( gray ) {
+ pixel[i] = (unsigned char) tqGray( rgb );
+ i++;
+ } else {
+ pixel[i] = (unsigned char) tqRed( rgb );
+ pixel[i+1] = (unsigned char) tqGreen( rgb );
+ pixel[i+2] = (unsigned char) tqBlue( rgb );
+ i += 3;
+ }
+ }
+ }
+ }
+
+ pixel[size] = 0;
+
+ /* this compression function emits blocks of data, where each
+ block is an unquoted series of pixels, or a quote from earlier
+ pixels. if the six-letter string "banana" were a six-pixel
+ image, it might be unquoted "ban" followed by a 3-pixel quote
+ from -2. note that the final "a" is then copied from the
+ second "a", which is copied from the first "a" in the same copy
+ operation.
+
+ the scanning for quotable blocks uses a cobol-like loop and a
+ hash table: we know how many pixels we need to quote, hash the
+ first and last pixel we need, and then go backwards in time
+ looking for some spot where those pixels of those two colours
+ occur at the right distance from each other.
+
+ when we tqfind a spot, we'll try a string-compare of all the
+ intervening pixels. we only do a maximum of 128 both-ends
+ compares or 64 full-string compares. it's more important to be
+ fast than get the ultimate in compression.
+
+ The format of the compressed stream is as follows:
+ // 2 bits step size for search and backreference ( 1 or 3 )
+ 1 bit compressed or uncompressed block follows
+
+ uncompressed block:
+ 3 bits size of block in bytes
+ size*8 bits data
+
+ compressed block:
+ 3 bits compression header
+ 0-2 size of block is 1-3 bytes
+ 3-7 size of block is bigger, 4-8 additional bits specifying size follow
+ 0/4-8 additional size fields
+ 10 location of backreference
+ */
+
+ for( i=0; i < hashSize; i++ )
+ mostRecentPixel[i] = None;
+ int index = 0;
+ int emittedUntil = 0;
+ char *out = (char *)malloc( 256 * sizeof( char ) );
+ int outLen = 256;
+ int outOffset = 0;
+ int outBit = 0;
+
+ /* we process pixels serially, emitting as necessary/possible. */
+ while( index <= size ) {
+ int bestCandidate = None;
+ int bestLength = 0;
+ i = index % tableSize;
+ int h = pixel[index] % hashSize;
+ int start, end;
+ start = end = pastPixel[i] = mostRecentPixel[h];
+ mostRecentPixel[h] = index;
+ /* if our first candidate quote is unusable, or we don't need
+ to quote because we've already emitted something for this
+ pixel, just skip. */
+ if ( start < index - tableSize || index >= size ||
+ emittedUntil > index)
+ start = end = None;
+ int attempts = 0;
+ /* scan for suitable quote candidates: not too far back, and
+ if we've found one that's as big as it can get, don't look
+ for more */
+ while( start != None && end != None &&
+ bestLength < maxQuoteLength &&
+ start >= index - tableSize &&
+ end >= index - tableSize + bestLength ) {
+ /* scan backwards, looking for something good enough to
+ try a (slow) string comparison. we maintain indexes to
+ the start and the end of the quote candidate here */
+ while( start != None && end != None &&
+ ( pixel[start] != pixel[index] ||
+ pixel[end] != pixel[index+bestLength] ) ) {
+ if ( attempts++ > numAttempts ) {
+ start = None;
+ } else if ( pixel[end] % hashSize ==
+ pixel[index+bestLength] % hashSize ) {
+ /* we move the area along the end index' chain */
+ end = pastPixel[end%tableSize];
+ start = end - bestLength;
+ } else if ( pixel[start] % hashSize ==
+ pixel[index] % hashSize ) {
+ /* ... or along the start index' chain */
+ start = pastPixel[start%tableSize];
+ end = start + bestLength;
+ } else {
+#if 0
+ /* this should never happen: both the start and
+ the end pointers ran off their tracks. */
+ qDebug( "oops! %06x %06x %06x %06x %5d %5d %5d %d",
+ pixel[start], pixel[end],
+ pixel[index], pixel[index+bestLength],
+ start, end, index, bestLength );
+#endif
+ /* but if it should happen, no problem. we'll just
+ say we found nothing, and the compression will
+ be a bit worse. */
+ start = None;
+ }
+ /* if we've moved either index too far to use the
+ quote candidate, let's just give up here. there's
+ also a guard against "start" insanity. */
+ if ( start < index - tableSize || start < 0 || start >= index )
+ start = None;
+ if ( end < index - tableSize + bestLength || end < bestLength )
+ end = None;
+ }
+ /* ok, now start and end point to an area of suitable
+ length whose first and last points match, or one/both
+ is/are set to None. */
+ if ( start != None && end != None ) {
+ /* slow string compare... */
+ int length = 0;
+ while( length < maxQuoteLength &&
+ index+length < size &&
+ pixel[start+length] == pixel[index+length] )
+ length++;
+ /* if we've found something that overlaps the index
+ point, maybe we can move the quote point back? if
+ we're copying 10 pixels from 8 pixels back (an
+ overlap of 2), that'll be faster than copying from
+ 4 pixels back (an overlap of 6). */
+ if ( start + length > index && length > 0 ) {
+ int d = index-start;
+ int equal = TRUE;
+ while( equal && start + length > index &&
+ start > d && start-d >= index-tableSize ) {
+ int i = 0;
+ while( equal && i < d ) {
+ if( pixel[start+i] != pixel[start+i-d] )
+ equal = FALSE;
+ i++;
+ }
+ if ( equal )
+ start -= d;
+ }
+ }
+ /* if what we have is longer than the best previous
+ candidate, we'll use this one. */
+ if ( length > bestLength ) {
+ attempts = 0;
+ bestCandidate = start;
+ bestLength = length;
+ if ( length < maxQuoteLength && index + length < size )
+ end = mostRecentPixel[pixel[index+length]%hashSize];
+ } else {
+ /* and if it ins't, we'll try some more. but we'll
+ count each string compare extra, since they're
+ so expensive. */
+ attempts += 2;
+ if ( attempts > numAttempts ) {
+ start = None;
+ } else if ( pastPixel[start%tableSize] + bestLength <
+ pastPixel[end%tableSize] ) {
+ start = pastPixel[start%tableSize];
+ end = start + bestLength;
+ } else {
+ end = pastPixel[end%tableSize];
+ start = end - bestLength;
+ }
+ }
+ /* again, if we can't make use of the current quote
+ candidate, we don't try any more */
+ if ( start < index - tableSize || start < 0 || start > size+1 )
+ start = None;
+ if ( end < index - tableSize + bestLength || end < 0 || end > size+1 )
+ end = None;
+ }
+ }
+ /* backreferences to 1 byte of data are actually more costly than
+ emitting the data directly, 2 bytes don't save much. */
+ if ( bestCandidate != None && bestLength < 3 )
+ bestCandidate = None;
+ /* at this point, bestCandidate is a candidate of bestLength
+ length, or else it's None. if we have such a candidate, or
+ we're at the end, we have to emit all unquoted data. */
+ if ( index == size || bestCandidate != None ) {
+ /* we need a double loop, because there's a maximum length
+ on the "unquoted data" section. */
+ while( emittedUntil < index ) {
+#ifdef DEBUG_COMPRESS
+ int x = 0;
+ int bl = emittedUntil - index;
+ while ( (bl /= 2) )
+ x++;
+ if ( x > 10 ) x = 10;
+ sizeUncompressed[x]++;
+#endif
+ int l = TQMIN( 8, index - emittedUntil );
+ if ( outOffset + l + 2 >= outLen ) {
+ outLen *= 2;
+ out = (char *) realloc( out, outLen );
+ }
+ emitBits( out, outOffset, outBit,
+ 1, 0 );
+ emitBits( out, outOffset, outBit,
+ quoteSize, l-1 );
+ while( l-- ) {
+ emitBits( out, outOffset, outBit,
+ 8, pixel[emittedUntil] );
+ emittedUntil++;
+ }
+ }
+ }
+ /* if we have some quoted data to output, do it. */
+ if ( bestCandidate != None ) {
+#ifdef DEBUG_COMPRESS
+ int x = 0;
+ int bl = bestLength;
+ while ( (bl /= 2) )
+ x++;
+ if ( x > 10 ) x = 10;
+ sizeCompressed[x]++;
+#endif
+ if ( outOffset + 4 >= outLen ) {
+ outLen *= 2;
+ out = (char *) realloc( out, outLen );
+ }
+ emitBits( out, outOffset, outBit,
+ 1, 1 );
+ int l = bestLength - 3;
+ const struct off_len {
+ int off;
+ int bits;
+ } ol_table [] = {
+ /* Warning: if you change the table here, change /uc in the PS code! */
+ { 3, 0/*dummy*/ },
+ { 16, 4 },
+ { 32, 5 },
+ { 64, 6 },
+ { 128, 7 },
+ { /*256*/ 0xfffffff, 8 },
+ };
+
+ if ( l < ol_table[0].off ) {
+ emitBits( out, outOffset, outBit,
+ quoteSize, l );
+ } else {
+ const off_len *ol = ol_table;
+ l -= ol->off;
+ ol++;
+ while ( l >= ol->off ) {
+ l -= ol->off;
+ ol++;
+ }
+ emitBits( out, outOffset, outBit,
+ quoteSize, ol->bits-1 );
+ emitBits( out, outOffset, outBit,
+ ol->bits, l );
+ }
+ emitBits( out, outOffset, outBit,
+ quoteReach, index - bestCandidate - 1 );
+ emittedUntil += bestLength;
+ }
+ index++;
+ }
+ /* we've output all the data; time to clean up and finish off the
+ last characters. */
+ if ( outBit )
+ outOffset++;
+ i = 0;
+ /* we have to make sure the data is encoded in a stylish way :) */
+ while( i < outOffset ) {
+ uchar c = out[i];
+ c += 42;
+ if ( c > 'Z' && ( c != 't' || i == 0 || out[i-1] != 'Q' ) )
+ c += 84;
+ out[i] = c;
+ i++;
+ }
+ TQByteArray outarr;
+ outarr.duplicate( out, outOffset );
+ free( out );
+ delete [] pixel;
+
+#ifdef DEBUG_COMPRESS
+ qDebug( "------------- image compression statistics ----------------" );
+ qDebug(" compression time %d", t.elapsed() );
+ qDebug( "Size dist of uncompressed blocks:" );
+ qDebug( "\t%d\t%d\t%d\t%d\t%d\t%d\n", sizeUncompressed[0], sizeUncompressed[1],
+ sizeUncompressed[2], sizeUncompressed[3], sizeUncompressed[4], sizeUncompressed[5]);
+ qDebug( "\t%d\t%d\t%d\t%d\t%d\n", sizeUncompressed[6], sizeUncompressed[7],
+ sizeUncompressed[8], sizeUncompressed[9], sizeUncompressed[10] );
+ qDebug( "Size dist of compressed blocks:" );
+ qDebug( "\t%d\t%d\t%d\t%d\t%d\t%d\n", sizeCompressed[0], sizeCompressed[1],
+ sizeCompressed[2], sizeCompressed[3], sizeCompressed[4], sizeCompressed[5]);
+ qDebug( "\t%d\t%d\t%d\t%d\t%d\n", sizeCompressed[6], sizeCompressed[7],
+ sizeCompressed[8], sizeCompressed[9], sizeCompressed[10] );
+ qDebug( "===> total compression ratio %d/%d = %f", outOffset, size, (float)outOffset/(float)size );
+ qDebug( "-----------------------------------------------------------" );
+#endif
+
+ return outarr;
+}
+
+#undef XCOORD
+#undef YCOORD
+#undef WIDTH
+#undef HEIGHT
+#undef POINT
+#undef RECT
+#undef INT_ARG
+
+#define XCOORD(x) (float)(x)
+#define YCOORD(y) (float)(y)
+#define WIDTH(w) (float)(w)
+#define HEIGHT(h) (float)(h)
+
+#define POINT(index) XCOORD(p[index].point->x()) << ' ' << \
+ YCOORD(p[index].point->y()) << ' '
+#define RECT(index) XCOORD(p[index].rect->normalize().x()) << ' ' << \
+ YCOORD(p[index].rect->normalize().y()) << ' ' << \
+ WIDTH (p[index].rect->normalize().width()) << ' ' << \
+ HEIGHT(p[index].rect->normalize().height()) << ' '
+#define INT_ARG(index) p[index].ival << ' '
+
+static char returnbuffer[13];
+static const char * color( const TQColor &c, TQPrinter * printer )
+{
+ if ( c == TQt::black )
+ qstrcpy( returnbuffer, "B " );
+ else if ( c == TQt::white )
+ qstrcpy( returnbuffer, "W " );
+ else if ( c.red() == c.green() && c.red() == c.blue() )
+ sprintf( returnbuffer, "%d d2 ", c.red() );
+ else if ( printer->colorMode() == TQPrinter::GrayScale )
+ sprintf( returnbuffer, "%d d2 ",
+ tqGray( c.red(), c.green(),c.blue() ) );
+ else
+ sprintf( returnbuffer, "%d %d %d ",
+ c.red(), c.green(), c.blue() );
+ return returnbuffer;
+}
+
+
+static const char * psCap( TQt::PenCapStyle p )
+{
+ if ( p == TQt::SquareCap )
+ return "2 ";
+ else if ( p == TQt::RoundCap )
+ return "1 ";
+ return "0 ";
+}
+
+
+static const char * psJoin( TQt::PenJoinStyle p ) {
+ if ( p == TQt::BevelJoin )
+ return "2 ";
+ else if ( p == TQt::RoundJoin )
+ return "1 ";
+ return "0 ";
+}
+
+
+
+void TQPSPrinterPrivate::drawImage( TQPainter *paint, float x, float y, float w, float h,
+ const TQImage &img, const TQImage &tqmask )
+{
+ if ( !w || !h || img.isNull() ) return;
+
+ int width = img.width();
+ int height = img.height();
+ float scaleX = (float)width/w;
+ float scaleY = (float)height/h;
+
+ bool gray = (printer->colorMode() == TQPrinter::GrayScale) ||
+ img.allGray();
+ int splitSize = 21830 * (gray ? 3 : 1 );
+ if ( width * height > splitSize ) { // 65535/3, tolerance for broken printers
+ int images, subheight;
+ images = ( width * height + splitSize - 1 ) / splitSize;
+ subheight = ( height + images-1 ) / images;
+ while ( subheight * width > splitSize ) {
+ images++;
+ subheight = ( height + images-1 ) / images;
+ }
+ int suby = 0;
+ while( suby < height ) {
+ drawImage(paint, x, y + suby/scaleY, w, TQMIN( subheight, height-suby )/scaleY,
+ img.copy( 0, suby, width, TQMIN( subheight, height-suby ) ),
+ tqmask.isNull() ? tqmask : tqmask.copy( 0, suby, width, TQMIN( subheight, height-suby ) ));
+ suby += subheight;
+ }
+ } else {
+ TQByteArray out;
+ int size = 0;
+ const char *bits;
+
+ if ( !tqmask.isNull() ) {
+ out = ::compress( tqmask, TRUE );
+ size = (width+7)/8*height;
+ pageStream << "/tqmask " << size << " string uc\n";
+ ps_r7( pageStream, out, out.size() );
+ pageStream << "d\n";
+ }
+ if ( img.depth() == 1 ) {
+ size = (width+7)/8*height;
+ bits = "1 ";
+ } else if ( gray ) {
+ size = width*height;
+ bits = "8 ";
+ } else {
+ size = width*height*3;
+ bits = "24 ";
+ }
+
+ out = ::compress( img, gray );
+ pageStream << "/sl " << size << " string uc\n";
+ ps_r7( pageStream, out, out.size() );
+ pageStream << "d\n"
+ << width << ' ' << height << "[" << scaleX << " 0 0 " << scaleY << " 0 0]sl "
+ << bits << (!tqmask.isNull() ? "tqmask " : "false ")
+ << x << ' ' << y << " di\n";
+ }
+}
+
+
+void TQPSPrinterPrivate::matrixSetup( TQPainter *paint )
+{
+#ifndef TQT_NO_TRANSFORMATIONS
+ TQWMatrix tmp;
+ if ( paint->hasViewXForm() ) {
+ TQRect viewport = paint->viewport();
+ TQRect window = paint->window();
+ tmp.translate( viewport.x(), viewport.y() );
+ tmp.scale( 1.0 * viewport.width() / window.width(),
+ 1.0 * viewport.height() / window.height() );
+ tmp.translate( -window.x(), -window.y() );
+ }
+ if ( paint->hasWorldXForm() ) {
+ tmp = paint->tqworldMatrix() * tmp;
+ }
+ pageStream << "["
+ << tmp.m11() << ' ' << tmp.m12() << ' '
+ << tmp.m21() << ' ' << tmp.m22() << ' '
+ << tmp.dx() << ' ' << tmp.dy()
+ << "]ST\n";
+#else
+ TQPoint p(0,0);
+ p = paint->xForm(p);
+ pageStream << "["
+ << 0 << ' ' << 0 << ' '
+ << 0 << ' ' << 0 << ' '
+ << p.x() << ' ' << p.y()
+ << "]ST\n";
+#endif
+ dirtyMatrix = FALSE;
+}
+
+void TQPSPrinterPrivate::orientationSetup()
+{
+ if ( printer->orientation() == TQPrinter::Landscape )
+ pageStream << "TQLS\n";
+}
+
+
+void TQPSPrinterPrivate::emitHeader( bool finished )
+{
+ TQString title = printer->docName();
+ TQString creator = printer->creator();
+ if ( !creator ) // default creator
+ creator = TQString::tqfromLatin1("TQt " TQT_VERSION_STR);
+ outDevice = new TQFile();
+ (void)((TQFile *)outDevice)->open( IO_WriteOnly, fd );
+ outStream.setDevice( outDevice );
+ outStream << "%!PS-Adobe-1.0";
+ TQPaintDeviceMetrics m( printer );
+ scale = 72. / ((float) m.logicalDpiY());
+ uint mtop, mleft, mbottom, mright;
+ printer->margins( &mtop, &mleft, &mbottom, &mright );
+ int width = m.width();
+ int height = m.height();
+ bool fullPage = printer->fullPage();
+ if ( finished && pageCount == 1 && printer->numCopies() == 1 &&
+ ( ( printer->fullPage() && qt_gen_epsf ) ||
+ ( printer->outputToFile() && printer->outputFileName().endsWith( ".eps" ) ) )
+ ) {
+ if ( !boundingBox.isValid() )
+ boundingBox.setRect( 0, 0, width, height );
+ if ( printer->orientation() == TQPrinter::Landscape ) {
+ if ( !fullPage )
+ boundingBox.moveBy( -mleft, -mtop );
+ outStream << " EPSF-3.0\n%%BoundingBox: "
+ << (int)(m.height() - boundingBox.bottom())*scale << " " // llx
+ << (int)(m.width() - boundingBox.right())*scale - 1 << " " // lly
+ << (int)(m.height() - boundingBox.top())*scale + 1 << " " // urx
+ << (int)(m.width() - boundingBox.left())*scale; // ury
+ } else {
+ if ( !fullPage )
+ boundingBox.moveBy( mleft, -mtop );
+ outStream << " EPSF-3.0\n%%BoundingBox: "
+ << (int)(boundingBox.left())*scale << " "
+ << (int)(m.height() - boundingBox.bottom())*scale - 1 << " "
+ << (int)(boundingBox.right())*scale + 1 << " "
+ << (int)(m.height() - boundingBox.top())*scale;
+ }
+ } else {
+ int w = width + (fullPage ? 0 : mleft + mright);
+ int h = height + (fullPage ? 0 : mtop + mbottom);
+ w = (int)(w*scale);
+ h = (int)(h*scale);
+ // set a bounding box according to the DSC
+ if ( printer->orientation() == TQPrinter::Landscape )
+ outStream << "\n%%BoundingBox: 0 0 " << h << " " << w;
+ else
+ outStream << "\n%%BoundingBox: 0 0 " << w << " " << h;
+ }
+ outStream << "\n" << wrapDSC( "%%Creator: " + creator );
+ if ( !!title )
+ outStream << wrapDSC( "%%Title: " + title );
+ outStream << "%%CreationDate: " << TQDateTime::tqcurrentDateTime().toString();
+ outStream << "\n%%Orientation: ";
+ if ( printer->orientation() == TQPrinter::Landscape )
+ outStream << "Landscape";
+ else
+ outStream << "Portrait";
+ if ( finished )
+ outStream << "\n%%Pages: " << pageCount << "\n"
+ << wrapDSC( "%%DocumentFonts: " + fontsUsed );
+ else
+ outStream << "%%Pages: (atend)"
+ << "\n%%DocumentFonts: (atend)";
+ outStream << "\n%%EndComments\n";
+
+ outStream << "%%BeginProlog\n";
+ const char * const prologLicense = "% Prolog copyright 1994-2006 Trolltech. "
+ "You may copy this prolog in any way\n"
+ "% that is directly related to this "
+ "document. For other use of this prolog,\n"
+ "% see your licensing agreement for TQt.\n";
+ outStream << prologLicense << ps_header << "\n";
+
+ // we have to do this here, as scaling can affect this.
+ TQString lineStyles = "/LArr[" // Pen styles:
+ " [] []" // solid line
+ " [ w s ] [ s w ]" // dash line
+ " [ s s ] [ s s ]" // dot line
+ " [ m s s s ] [ s m s s ]" // dash dot line
+ " [ m s s s s ] [ s m s s s s ]" // dash dot dot line
+ " ] d\n";
+ lineStyles.tqreplace( TQRegExp( "w" ), toString( 10./scale ) );
+ lineStyles.tqreplace( TQRegExp( "m" ), toString( 5./scale ) );
+ lineStyles.tqreplace( TQRegExp( "s" ), toString( 3./scale ) );
+
+ outStream << lineStyles;
+
+ outStream << "/pageinit {\n";
+ if ( !printer->fullPage() ) {
+ if ( printer->orientation() == TQPrinter::Portrait )
+ outStream << mleft*scale << " "
+ << mbottom*scale << " translate\n";
+ else
+ outStream << mtop*scale << " "
+ << mleft*scale << " translate\n";
+ }
+ if ( printer->orientation() == TQPrinter::Portrait ) {
+ outStream << "% " << m.widthMM() << "*" << m.heightMM()
+ << "mm (portrait)\n0 " << height*scale
+ << " translate " << scale << " -" << scale << " scale/defM matrix CM d } d\n";
+ } else {
+ outStream << "% " << m.heightMM() << "*" << m.widthMM()
+ << " mm (landscape)\n 90 rotate " << scale << " -" << scale << " scale/defM matrix CM d } d\n";
+ }
+ outStream << "%%EndProlog\n";
+
+
+ outStream << "%%BeginSetup\n";
+ if ( printer->numCopies() > 1 ) {
+ outStream << "/#copies " << printer->numCopies() << " def\n";
+ outStream << "/NumCopies " << printer->numCopies() << " SPD\n";
+ outStream << "/Collate " << (printer->collateCopies() ? "true" : "false") << " SPD\n";
+ }
+ if ( fontBuffer->buffer().size() ) {
+ if ( pageCount == 1 || finished )
+ outStream << "% Fonts and encodings used\n";
+ else
+ outStream << "% Fonts and encodings used on pages 1-"
+ << pageCount << "\n";
+ TQDictIterator<TQPSPrinterFontPrivate> it(fonts);
+ while (it.current()) {
+ it.current()->download(outStream,TRUE); // true means its global
+ ++it;
+ }
+ outStream.writeRawBytes( fontBuffer->buffer().data(),
+ fontBuffer->buffer().size() );
+ }
+ outStream << "%%EndSetup\n";
+
+ outStream.writeRawBytes( buffer->buffer().data(),
+ buffer->buffer().size() );
+
+ delete buffer;
+ buffer = 0;
+ fontStream.unsetDevice();
+ delete fontBuffer;
+ fontBuffer = 0;
+}
+
+
+/* Called whenever a restore has been done. Currently done at the top of a
+ new page and whenever clipping is turned off. */
+void TQPSPrinterPrivate::resetDrawingTools( TQPainter *paint )
+{
+ TQPen defaultPen; // default drawing tools
+ TQBrush defaultBrush;
+
+ TQColor c = paint->backgroundColor();
+ if ( c != TQt::white )
+ pageStream << color( c, printer ) << "BC\n";
+
+ if ( paint->backgroundMode() != TQt::TransparentMode )
+ pageStream << "/OMo true d\n";
+
+ //currentUsed = currentSet;
+ //setFont( currentSet );
+ currentFontFile = 0;
+
+ TQBrush b = paint->brush();
+ if ( b != defaultBrush ) {
+ if ( b == TQt::CustomPattern ) {
+#if defined(CHECK_RANGE)
+ qWarning( "TQPrinter: Pixmap brush not supported" );
+#endif
+ } else {
+ cbrush = b;
+ }
+ }
+
+ dirtypen = TRUE;
+ dirtybrush = TRUE;
+
+ if ( paint->hasViewXForm() || paint->hasWorldXForm() )
+ matrixSetup( paint );
+}
+
+
+static void putRect( TQTextStream &stream, const TQRect &r )
+{
+ stream << r.x() << " "
+ << r.y() << " "
+ << r.width() << " "
+ << r.height() << " ";
+}
+
+
+void TQPSPrinterPrivate::setClippingOff( TQPainter *paint )
+{
+ pageStream << "CLO\n"; // clipping off, includes a restore
+ resetDrawingTools( paint ); // so drawing tools must be reset
+}
+
+
+void TQPSPrinterPrivate::clippingSetup( TQPainter *paint )
+{
+ if ( paint->hasClipping() ) {
+ if ( !firstClipOnPage )
+ setClippingOff( paint );
+ const TQRegion rgn = paint->clipRegion();
+ TQMemArray<TQRect> rects = rgn.rects();
+ int i;
+ pageStream<< "CLSTART\n"; // start clipping
+ for( i = 0 ; i < (int)rects.size() ; i++ ) {
+ putRect( pageStream, rects[i] );
+ pageStream << "ACR\n"; // add clip rect
+ if ( pageCount == 1 )
+ boundingBox = boundingBox.unite( rects[i] );
+ }
+ pageStream << "CLEND\n"; // end clipping
+ firstClipOnPage = FALSE;
+ } else {
+ if ( !firstClipOnPage ) // no need to turn off if first on page
+ setClippingOff( paint );
+ // if we're painting without clipping, the bounding box must
+ // be everything. NOTE: this assumes that this function is
+ // only ever called when something is to be painted.
+ TQPaintDeviceMetrics m( printer );
+ if ( !boundingBox.isValid() )
+ boundingBox.setRect( 0, 0, m.width(), m.height() );
+ }
+ dirtyClipping = FALSE;
+}
+
+void TQPSPrinterPrivate::initPage(TQPainter *paint)
+{
+
+ // a restore undefines all the fonts that have been defined
+ // inside the scope (normally within pages) and all the glyphs that
+ // have been added in the scope.
+
+ TQDictIterator<TQPSPrinterFontPrivate> it(fonts);
+ while (it.current()) {
+ it.current()->restore();
+ ++it;
+ }
+ if ( !buffer ) {
+ pageFontNames.clear();
+ }
+
+ pageStream.unsetDevice();
+ if ( pageBuffer )
+ delete pageBuffer;
+ pageBuffer = new TQBuffer();
+ pageBuffer->open( IO_WriteOnly );
+ pageStream.setEncoding( TQTextStream::Latin1 );
+ pageStream.setDevice( pageBuffer );
+ delete savedImage;
+ savedImage = 0;
+ textY = 0;
+ dirtyClipping = TRUE;
+ firstClipOnPage = TRUE;
+
+
+ resetDrawingTools( paint );
+ dirtyNewPage = FALSE;
+ pageFontNumber = headerFontNumber;
+}
+
+void TQPSPrinterPrivate::flushPage( bool last )
+{
+ if ( last && !pageBuffer )
+ return;
+ bool pageFonts = ( buffer == 0 );
+ if ( buffer &&
+// ( last || pagesInBuffer++ > -1 ||
+// ( pagesInBuffer > 4 && buffer->size() > 262144 ) ) )
+#ifdef TQ_WS_TQWS
+ (last || buffer->size() > 2000000) // embedded is usually limited in memory
+#else
+ (last || buffer->size() > 50000000)
+#endif
+ ) {
+// qDebug("emiting header at page %d", pageCount );
+ emitHeader( last );
+ }
+ outStream << "%%Page: "
+ << pageCount << ' ' << pageCount << endl
+ << "%%BeginPageSetup\n"
+ << "QI\n";
+ if (!dirtyNewPage) {
+ if ( pageFonts ) {
+ //qDebug("page fonts for page %d", pageCount);
+ // we have already downloaded the header. Maybe we have page fonts here
+ TQDictIterator<TQPSPrinterFontPrivate> it(fonts);
+ while (it.current()) {
+ it.current()->download( outStream, FALSE ); // FALSE means its for the page only
+ ++it;
+ }
+ }
+ outStream << "%%EndPageSetup\n";
+ if ( pageBuffer )
+ outStream.writeRawBytes( pageBuffer->buffer().data(),
+ pageBuffer->buffer().size() );
+ }
+ outStream << "\nQP\n";
+ pageCount++;
+}
+
+// ================ PSPrinter class ========================
+
+TQPSPrinter::TQPSPrinter( TQPrinter *prt, int fd )
+ : TQPaintDevice( TQInternal::Printer | TQInternal::ExternalDevice )
+{
+ d = new TQPSPrinterPrivate( prt, fd );
+}
+
+
+TQPSPrinter::~TQPSPrinter()
+{
+ if ( d->fd >= 0 )
+#if defined(_OS_WIN32_)
+ ::_close( d->fd );
+#else
+ ::close( d->fd );
+#endif
+ delete d;
+}
+
+
+
+static void ignoreSigPipe(bool b)
+{
+ static struct sigaction *users_sigpipe_handler = 0;
+
+ if (b) {
+ if (users_sigpipe_handler != 0)
+ return; // already ignoring sigpipe
+
+ users_sigpipe_handler = new struct sigaction;
+ struct sigaction tmp_sigpipe_handler;
+ tmp_sigpipe_handler.sa_handler = SIG_IGN;
+ sigemptyset(&tmp_sigpipe_handler.sa_mask);
+ tmp_sigpipe_handler.sa_flags = 0;
+
+ if (sigaction(SIGPIPE, &tmp_sigpipe_handler, users_sigpipe_handler) == -1) {
+ delete users_sigpipe_handler;
+ users_sigpipe_handler = 0;
+ }
+ }
+ else {
+ if (users_sigpipe_handler == 0)
+ return; // not ignoring sigpipe
+
+ if (sigaction(SIGPIPE, users_sigpipe_handler, 0) == -1)
+ qWarning("TQPSPrinter: could not restore SIGPIPE handler");
+
+ delete users_sigpipe_handler;
+ users_sigpipe_handler = 0;
+ }
+}
+
+bool TQPSPrinter::cmd( int c , TQPainter *paint, TQPDevCmdParam *p )
+{
+ if ( c == PdcBegin ) { // start painting
+ d->pagesInBuffer = 0;
+ d->buffer = new TQBuffer();
+ d->buffer->open( IO_WriteOnly );
+ d->outStream.setEncoding( TQTextStream::Latin1 );
+ d->outStream.setDevice( d->buffer );
+ d->fontBuffer = new TQBuffer();
+ d->fontBuffer->open( IO_WriteOnly );
+ d->fontStream.setEncoding( TQTextStream::Latin1 );
+ d->fontStream.setDevice( d->fontBuffer );
+ d->headerFontNumber = 0;
+ d->pageCount = 1; // initialize state
+ d->dirtyMatrix = TRUE;
+ d->dirtyClipping = TRUE;
+ d->dirtyNewPage = TRUE;
+ d->firstClipOnPage = TRUE;
+ d->boundingBox = TQRect( 0, 0, -1, -1 );
+ d->fontsUsed = TQString::tqfromLatin1("");
+
+ TQPaintDeviceMetrics m( d->printer );
+ d->scale = 72. / ((float) m.logicalDpiY());
+
+ return TRUE;
+ }
+
+ if ( c == PdcEnd ) { // painting done
+ bool pageCountAtEnd = (d->buffer != 0);
+
+ // we're writing to lp/lpr through a pipe, we don't want to crash with SIGPIPE
+ // if lp/lpr dies
+ ignoreSigPipe(TRUE);
+ d->flushPage( TRUE );
+ d->outStream << "%%Trailer\n";
+ if ( pageCountAtEnd )
+ d->outStream << "%%Pages: " << d->pageCount - 1 << "\n" <<
+ wrapDSC( "%%DocumentFonts: " + d->fontsUsed );
+ d->outStream << "%%EOF\n";
+ ignoreSigPipe(FALSE);
+
+ d->outStream.unsetDevice();
+ if ( d->outDevice )
+ d->outDevice->close();
+ if ( d->fd >= 0 )
+ ::close( d->fd );
+ d->fd = -1;
+ delete d->outDevice;
+ d->outDevice = 0;
+ }
+
+ if ( c >= PdcDrawFirst && c <= PdcDrawLast ) {
+ if ( !paint )
+ return FALSE; // sanity
+ if ( d->dirtyNewPage )
+ d->initPage( paint );
+ if ( d->dirtyMatrix )
+ d->matrixSetup( paint );
+ if ( d->dirtyClipping ) // Must be after matrixSetup and initPage
+ d->clippingSetup( paint );
+ if ( d->dirtypen ) {
+ // we special-case for narrow solid lines with the default
+ // cap and join styles
+ if ( d->cpen.style() == TQt::SolidLine && d->cpen.width() == 0 &&
+ d->cpen.capStyle() == TQt::FlatCap &&
+ d->cpen.joinStyle() == TQt::MiterJoin )
+ d->pageStream << color( d->cpen.color(), d->printer ) << "P1\n";
+ else
+ d->pageStream << (int)d->cpen.style() << ' ' << d->cpen.width()
+ << ' ' << color( d->cpen.color(), d->printer )
+ << psCap( d->cpen.capStyle() )
+ << psJoin( d->cpen.joinStyle() ) << "PE\n";
+ d->dirtypen = FALSE;
+ }
+ if ( d->dirtybrush ) {
+ // we special-case for nobrush and solid white, since
+ // those are the two most common brushes
+ if ( d->cbrush.style() == TQt::NoBrush )
+ d->pageStream << "NB\n";
+ else if ( d->cbrush.style() == TQt::SolidPattern &&
+ d->cbrush.color() == TQt::white )
+ d->pageStream << "WB\n";
+ else
+ d->pageStream << (int)d->cbrush.style() << ' '
+ << color( d->cbrush.color(), d->printer ) << "BR\n";
+ d->dirtybrush = FALSE;
+ }
+ if ( d->dirtyBkColor ) {
+ d->pageStream << color( d->bkColor, d->printer ) << "BC\n";
+ d->dirtyBkColor = FALSE;
+ }
+ if ( d->dirtyBkMode ) {
+ if ( d->bkMode == TQt::TransparentMode )
+ d->pageStream << "/OMo false d\n";
+ else
+ d->pageStream << "/OMo true d\n";
+ d->dirtyBkMode = FALSE;
+ }
+ }
+
+ switch( c ) {
+ case PdcDrawPoint:
+ d->pageStream << POINT(0) << "P\n";
+ break;
+ case PdcMoveTo:
+ d->pageStream << POINT(0) << "M\n";
+ break;
+ case PdcLineTo:
+ d->pageStream << POINT(0) << "L\n";
+ break;
+ case PdcDrawLine:
+ if ( p[0].point->y() == p[1].point->y() )
+ d->pageStream << POINT(1) << p[0].point->x() << " HL\n";
+ else if ( p[0].point->x() == p[1].point->x() )
+ d->pageStream << POINT(1) << p[0].point->y() << " VL\n";
+ else
+ d->pageStream << POINT(1) << POINT(0) << "DL\n";
+ break;
+ case PdcDrawRect:
+ d->pageStream << RECT(0) << "R\n";
+ break;
+ case PdcDrawRoundRect:
+ d->pageStream << RECT(0) << INT_ARG(1) << INT_ARG(2) << "RR\n";
+ break;
+ case PdcDrawEllipse:
+ d->pageStream << RECT(0) << "E\n";
+ break;
+ case PdcDrawArc:
+ d->pageStream << RECT(0) << INT_ARG(1) << INT_ARG(2) << "A\n";
+ break;
+ case PdcDrawPie:
+ d->pageStream << RECT(0) << INT_ARG(1) << INT_ARG(2) << "PIE\n";
+ break;
+ case PdcDrawChord:
+ d->pageStream << RECT(0) << INT_ARG(1) << INT_ARG(2) << "CH\n";
+ break;
+ case PdcDrawLineSegments:
+ if ( p[0].ptarr->size() > 0 ) {
+ TQPointArray a = *p[0].ptarr;
+ TQPoint pt;
+ d->pageStream << "NP\n";
+ for ( int i=0; i<(int)a.size(); i+=2 ) {
+ pt = a.point( i );
+ d->pageStream << XCOORD(pt.x()) << ' '
+ << YCOORD(pt.y()) << " MT\n";
+ pt = a.point( i+1 );
+ d->pageStream << XCOORD(pt.x()) << ' '
+ << YCOORD(pt.y()) << " LT\n";
+ }
+ d->pageStream << "QS\n";
+ }
+ break;
+ case PdcDrawPolyline:
+ if ( p[0].ptarr->size() > 1 ) {
+ TQPointArray a = *p[0].ptarr;
+ TQPoint pt = a.point( 0 );
+ d->pageStream << "NP\n"
+ << XCOORD(pt.x()) << ' ' << YCOORD(pt.y()) << " MT\n";
+ for ( int i=1; i<(int)a.size(); i++ ) {
+ pt = a.point( i );
+ d->pageStream << XCOORD(pt.x()) << ' '
+ << YCOORD(pt.y()) << " LT\n";
+ }
+ d->pageStream << "QS\n";
+ }
+ break;
+ case PdcDrawPolygon:
+ if ( p[0].ptarr->size() > 2 ) {
+ TQPointArray a = *p[0].ptarr;
+ if ( p[1].ival )
+ d->pageStream << "/WFi true d\n";
+ TQPoint pt = a.point(0);
+ d->pageStream << "NP\n";
+ d->pageStream << XCOORD(pt.x()) << ' '
+ << YCOORD(pt.y()) << " MT\n";
+ for( int i=1; i<(int)a.size(); i++) {
+ pt = a.point( i );
+ d->pageStream << XCOORD(pt.x()) << ' '
+ << YCOORD(pt.y()) << " LT\n";
+ }
+ d->pageStream << "CP BF QS\n";
+ if ( p[1].ival )
+ d->pageStream << "/WFi false d\n";
+ }
+ break;
+ case PdcDrawCubicBezier:
+ if ( p[0].ptarr->size() == 4 ) {
+ d->pageStream << "NP\n";
+ TQPointArray a = *p[0].ptarr;
+ d->pageStream << XCOORD(a[0].x()) << ' '
+ << YCOORD(a[0].y()) << " MT ";
+ for ( int i=1; i<4; i++ ) {
+ d->pageStream << XCOORD(a[i].x()) << ' '
+ << YCOORD(a[i].y()) << ' ';
+ }
+ d->pageStream << "BZ\n";
+ }
+ break;
+ case PdcDrawText2:
+ // we use tqdrawTextItem instead
+ return TRUE;
+ case PdcDrawText2Formatted:
+ return TRUE;
+ case PdcDrawTextItem: {
+ const TQTextItem *ti = p[1].textItem;
+ TQScriptItem &si = ti->engine->items[ti->item];
+ int len = ti->engine->length( ti->item );
+ if ( si.isSpace || si.isObject )
+ return FALSE;
+
+ if ( d->currentSet != d->currentUsed || d->scriptUsed != si.analysis.script || !d->currentFontFile ) {
+ d->currentUsed = d->currentSet;
+ d->setFont( d->currentSet, si.analysis.script );
+ }
+ if( d->currentFontFile ) // better not crash in case somethig goes wrong.
+ d->currentFontFile->drawText( d->pageStream, *p[0].point, ti->engine, ti->item,
+ ti->engine->string.mid( si.position, len ), d, paint);
+ return FALSE;
+ }
+ case PdcDrawPixmap: {
+ if ( p[1].pixmap->isNull() )
+ break;
+ TQRect r = *p[0].rect;
+ TQImage img;
+ img = *(p[1].pixmap);
+ TQImage tqmask;
+ if ( p[1].pixmap->tqmask() )
+ tqmask = *(p[1].pixmap->tqmask());
+ d->drawImage(paint, r.x(), r.y(), r.width(), r.height(), img, tqmask);
+ break;
+ }
+ case PdcDrawImage: {
+ if ( p[1].image->isNull() )
+ break;
+ TQRect r = *(p[0].rect);
+ TQImage img = *(p[1].image);
+ TQImage tqmask;
+#ifndef TQT_NO_IMAGE_DITHER_TO_1
+ if ( img.hasAlphaBuffer() )
+ tqmask = img.createAlphaMask();
+#endif
+ d->drawImage(paint, r.x(), r.y(), r.width(), r.height(), img, tqmask);
+ break;
+ }
+ case PdcSetBkColor:
+ {
+ if ( d->bkColor != *(p[0].color) ) {
+ d->bkColor = *(p[0].color);
+ d->dirtyBkColor = TRUE;
+ }
+ break;
+ }
+ case PdcSetBkMode:
+ {
+ if ( d->bkMode != p[0].ival ) {
+ d->bkMode = (TQt::BGMode) p[0].ival;
+ d->dirtyBkMode = TRUE;
+ }
+ break;
+ }
+ case PdcSetROP:
+#if defined(CHECK_RANGE)
+ if ( p[0].ival != TQt::CopyROP )
+ qWarning( "TQPrinter: Raster operation setting not supported" );
+#endif
+ break;
+ case PdcSetBrushOrigin:
+ break;
+ case PdcSetFont:
+ d->currentSet = *(p[0].font);
+ d->fm = paint->fontMetrics();
+ // turn these off - they confuse the 'avoid font change' logic
+ d->currentSet.setUnderline( FALSE );
+ d->currentSet.setStrikeOut( FALSE );
+ break;
+ case PdcSetPen:
+ if ( d->cpen != *(p[0].pen) ) {
+ d->dirtypen = TRUE;
+ d->cpen = *(p[0].pen);
+ }
+ break;
+ case PdcSetBrush:
+ if ( p[0].brush->style() == TQt::CustomPattern ) {
+#if defined(CHECK_RANGE)
+ qWarning( "TQPrinter: Pixmap brush not supported" );
+#endif
+ return FALSE;
+ }
+ if ( d->cbrush != *(p[0].brush) ) {
+ d->dirtybrush = TRUE;
+ d->cbrush = *(p[0].brush);
+ }
+ break;
+ case PdcSetTabStops:
+ case PdcSetTabArray:
+ return FALSE;
+ case PdcSetUnit:
+ break;
+ case PdcSetVXform:
+ case PdcSetWindow:
+ case PdcSetViewport:
+ case PdcSetWXform:
+ case PdcSetWMatrix:
+ case PdcRestoreWMatrix:
+ d->dirtyMatrix = TRUE;
+ break;
+ case PdcSetClip:
+ d->dirtyClipping = TRUE;
+ break;
+ case PdcSetClipRegion:
+ d->dirtyClipping = TRUE;
+ break;
+ case NewPage:
+ // we're writing to lp/lpr through a pipe, we don't want to crash with SIGPIPE
+ // if lp/lpr dies
+ ignoreSigPipe(TRUE);
+ d->flushPage();
+ ignoreSigPipe(FALSE);
+
+ d->dirtyNewPage = TRUE;
+ break;
+ case AbortPrinting:
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+#endif // TQT_NO_PRINTER
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqpsprinter_p.h b/tqtinterface/qt4/src/kernel/tqpsprinter_p.h
new file mode 100644
index 0000000..878d9d3
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqpsprinter_p.h
@@ -0,0 +1,98 @@
+/**********************************************************************
+**
+** Definition of internal TQPSPrinter class.
+** TQPSPrinter implements PostScript (tm) output via TQPrinter.
+**
+** Created : 940927
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQPSPRINTER_P_H
+#define TQPSPRINTER_P_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of qpsprinter.cpp and qprinter_x11.cpp.
+// This header file may change from version to version without notice,
+// or even be removed.
+//
+// We mean it.
+//
+//
+
+
+#ifndef TQT_H
+#include "tqprinter.h"
+#include "tqtextstream.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_PRINTER
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+class TQPSPrinterPrivate;
+
+class TQ_EXPORT TQPSPrinter : public TQPaintDevice
+{
+private:
+ // TQPrinter uses these
+ TQPSPrinter( TQPrinter *, int );
+ ~TQPSPrinter();
+
+ bool cmd ( int, TQPainter *, TQPDevCmdParam * );
+
+ enum { NewPage = 100, AbortPrinting };
+
+ friend class TQPrinter;
+private:
+ // not used by TQPrinter
+ TQPSPrinterPrivate *d;
+
+ // Disabled copy constructor and operator=
+ TQPSPrinter( const TQPSPrinter & );
+ TQPSPrinter &operator=( const TQPSPrinter & );
+};
+
+#endif // USE_QT4
+
+#endif // TQT_NO_PRINTER
+
+#endif // TQPSPRINTER_P_H
diff --git a/tqtinterface/qt4/src/kernel/tqrect.cpp b/tqtinterface/qt4/src/kernel/tqrect.cpp
new file mode 100644
index 0000000..aa16303
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqrect.cpp
@@ -0,0 +1,1010 @@
+/****************************************************************************
+**
+** Implementation of TQRect class
+**
+** Created : 931028
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+// Nasty, nasty horrid HACK to get access to QRect's private members
+// This is TERRIBLE and I wish there was a way around it
+// This is a good example of the new, broken & irritating Qt4 API,
+// and the corresponding loss in functionality versus Qt3.
+#define private protected
+#include <Qt/qrect.h>
+#undef private
+
+#define TQRECT_C
+#include "tqrect.h"
+#include "tqdatastream.h"
+
+#ifdef USE_QT4
+
+int &TQRect::rLeft() { return x1; }
+int &TQRect::rTop() { return y1; }
+int &TQRect::rRight() { return x2; }
+int &TQRect::rBottom() { return y2; }
+
+/*!
+ Extracts the rectangle parameters as the position \a *x, \a *y and
+ width \a *w and height \a *h.
+
+ \sa setRect(), coords()
+*/
+
+void TQRect::rect( int *x, int *y, int *w, int *h ) const
+{
+ *x = x1;
+ *y = y1;
+ *w = x2-x1+1;
+ *h = y2-y1+1;
+}
+
+/*!
+ Extracts the rectangle parameters as the top-left point \a *xp1,
+ \a *yp1 and the bottom-right point \a *xp2, \a *yp2.
+
+ \sa setCoords(), rect()
+*/
+
+void TQRect::coords( int *xp1, int *yp1, int *xp2, int *yp2 ) const
+{
+ *xp1 = x1;
+ *yp1 = y1;
+ *xp2 = x2;
+ *yp2 = y2;
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQRect
+ \brief The TQRect class defines a rectangle in the plane.
+
+ \ingroup images
+ \ingroup graphics
+ \mainclass
+
+ A rectangle is internally represented as an upper-left corner and
+ a bottom-right corner, but it is normally expressed as an
+ upper-left corner and a size.
+
+ The coordinate type is TQCOORD (defined in \c tqwindowdefs.h as \c
+ int). The minimum value of TQCOORD is TQCOORD_MIN (-2147483648) and
+ the maximum value is TQCOORD_MAX (2147483647).
+
+ Note that the size (width and height) of a rectangle might be
+ different from what you are used to. If the top-left corner and
+ the bottom-right corner are the same, the height and the width of
+ the rectangle will both be 1.
+
+ Generally, \e{width = right - left + 1} and \e{height = bottom -
+ top + 1}. We designed it this way to make it correspond to
+ rectangular spaces used by drawing functions in which the width
+ and height denote a number of pixels. For example, drawing a
+ rectangle with width and height 1 draws a single pixel.
+
+ The default coordinate system has origin (0, 0) in the top-left
+ corner. The positive direction of the y axis is down, and the
+ positive x axis is from left to right.
+
+ A TQRect can be constructed with a set of left, top, width and
+ height integers, from two TQPoints or from a TQPoint and a TQSize.
+ After creation the dimensions can be changed, e.g. with setLeft(),
+ setRight(), setTop() and setBottom(), or by setting sizes, e.g.
+ setWidth(), setHeight() and setSize(). The dimensions can also be
+ changed with the move functions, e.g. moveBy(), moveCenter(),
+ moveBottomRight(), etc. You can also add coordinates to a
+ rectangle with addCoords().
+
+ You can test to see if a TQRect tqcontains a specific point with
+ tqcontains(). You can also test to see if two TQRects intersect with
+ intersects() (see also intersect()). To get the bounding rectangle
+ of two TQRects use unite().
+
+ \sa TQPoint, TQSize
+*/
+
+
+/*****************************************************************************
+ TQRect member functions
+ *****************************************************************************/
+
+/*!
+ \fn TQRect::TQRect()
+
+ Constructs an invalid rectangle.
+*/
+
+/*!
+ Constructs a rectangle with \a topLeft as the top-left corner and
+ \a bottomRight as the bottom-right corner.
+*/
+
+TQRect::TQRect( const TQPoint &topLeft, const TQPoint &bottomRight )
+{
+ x1 = (TQCOORD)topLeft.x();
+ y1 = (TQCOORD)topLeft.y();
+ x2 = (TQCOORD)bottomRight.x();
+ y2 = (TQCOORD)bottomRight.y();
+}
+
+/*!
+ Constructs a rectangle with \a topLeft as the top-left corner and
+ \a size as the rectangle size.
+*/
+
+TQRect::TQRect( const TQPoint &topLeft, const TQSize &size )
+{
+ x1 = (TQCOORD)topLeft.x();
+ y1 = (TQCOORD)topLeft.y();
+ x2 = (TQCOORD)(x1+size.width()-1);
+ y2 = (TQCOORD)(y1+size.height()-1);
+}
+
+/*!
+ \fn TQRect::TQRect( int left, int top, int width, int height )
+
+ Constructs a rectangle with the \a top, \a left corner and \a
+ width and \a height.
+
+ Example (creates three identical rectangles):
+ \code
+ TQRect r1( TQPoint(100,200), TQPoint(110,215) );
+ TQRect r2( TQPoint(100,200), TQSize(11,16) );
+ TQRect r3( 100, 200, 11, 16 );
+ \endcode
+*/
+
+
+/*!
+ \fn bool TQRect::isNull() const
+
+ Returns TRUE if the rectangle is a null rectangle; otherwise
+ returns FALSE.
+
+ A null rectangle has both the width and the height set to 0, that
+ is right() == left() - 1 and bottom() == top() - 1.
+
+ Note that if right() == left() and bottom() == top(), then the
+ rectangle has width 1 and height 1.
+
+ A null rectangle is also empty.
+
+ A null rectangle is not valid.
+
+ \sa isEmpty(), isValid()
+*/
+
+/*!
+ \fn bool TQRect::isEmpty() const
+
+ Returns TRUE if the rectangle is empty; otherwise returns FALSE.
+
+ An empty rectangle has a left() \> right() or top() \> bottom().
+
+ An empty rectangle is not valid. \c{isEmpty() == !isValid()}
+
+ \sa isNull(), isValid(), normalize()
+*/
+
+/*!
+ \fn bool TQRect::isValid() const
+
+ Returns TRUE if the rectangle is valid; otherwise returns FALSE.
+
+ A valid rectangle has a left() \<= right() and top() \<= bottom().
+
+ Note that non-trivial operations like intersections are not defined
+ for invalid rectangles.
+
+ \c{isValid() == !isEmpty()}
+
+ \sa isNull(), isEmpty(), normalize()
+*/
+
+
+/*!
+ Returns a normalized rectangle, i.e. a rectangle that has a
+ non-negative width and height.
+
+ It swaps left and right if left() \> right(), and swaps top and
+ bottom if top() \> bottom().
+
+ \sa isValid()
+*/
+
+TQRect TQRect::normalize() const
+{
+ TQRect r;
+ if ( x2 < x1 ) { // swap bad x values
+ r.x1 = x2;
+ r.x2 = x1;
+ } else {
+ r.x1 = x1;
+ r.x2 = x2;
+ }
+ if ( y2 < y1 ) { // swap bad y values
+ r.y1 = y2;
+ r.y2 = y1;
+ } else {
+ r.y1 = y1;
+ r.y2 = y2;
+ }
+ return r;
+}
+
+
+/*!
+ \fn int TQRect::left() const
+
+ Returns the left coordinate of the rectangle. Identical to x().
+
+ \sa setLeft(), right(), topLeft(), bottomLeft()
+*/
+
+/*!
+ \fn int TQRect::top() const
+
+ Returns the top coordinate of the rectangle. Identical to y().
+
+ \sa setTop(), bottom(), topLeft(), topRight()
+*/
+
+/*!
+ \fn int TQRect::right() const
+
+ Returns the right coordinate of the rectangle.
+
+ \sa setRight(), left(), topRight(), bottomRight()
+*/
+
+/*!
+ \fn int TQRect::bottom() const
+
+ Returns the bottom coordinate of the rectangle.
+
+ \sa setBottom(), top(), bottomLeft(), bottomRight()
+*/
+
+/*!
+ \fn TQCOORD &TQRect::rLeft()
+
+ Returns a reference to the left coordinate of the rectangle.
+
+ \sa rTop(), rRight(), rBottom()
+*/
+
+/*!
+ \fn TQCOORD &TQRect::rTop()
+
+ Returns a reference to the top coordinate of the rectangle.
+
+ \sa rLeft(), rRight(), rBottom()
+*/
+
+/*!
+ \fn TQCOORD &TQRect::rRight()
+
+ Returns a reference to the right coordinate of the rectangle.
+
+ \sa rLeft(), rTop(), rBottom()
+*/
+
+/*!
+ \fn TQCOORD &TQRect::rBottom()
+
+ Returns a reference to the bottom coordinate of the rectangle.
+
+ \sa rLeft(), rTop(), rRight()
+*/
+
+/*!
+ \fn int TQRect::x() const
+
+ Returns the left coordinate of the rectangle. Identical to left().
+
+ \sa left(), y(), setX()
+*/
+
+/*!
+ \fn int TQRect::y() const
+
+ Returns the top coordinate of the rectangle. Identical to top().
+
+ \sa top(), x(), setY()
+*/
+
+/*!
+ \fn void TQRect::setLeft( int pos )
+
+ Sets the left edge of the rectangle to \a pos. May change the
+ width, but will never change the right edge of the rectangle.
+
+ Identical to setX().
+
+ \sa left(), setTop(), setWidth()
+*/
+
+/*!
+ \fn void TQRect::setTop( int pos )
+
+ Sets the top edge of the rectangle to \a pos. May change the
+ height, but will never change the bottom edge of the rectangle.
+
+ Identical to setY().
+
+ \sa top(), setBottom(), setHeight()
+*/
+
+/*!
+ \fn void TQRect::setRight( int pos )
+
+ Sets the right edge of the rectangle to \a pos. May change the
+ width, but will never change the left edge of the rectangle.
+
+ \sa right(), setLeft(), setWidth()
+*/
+
+/*!
+ \fn void TQRect::setBottom( int pos )
+
+ Sets the bottom edge of the rectangle to \a pos. May change the
+ height, but will never change the top edge of the rectangle.
+
+ \sa bottom(), setTop(), setHeight()
+*/
+
+/*!
+ \fn void TQRect::setX( int x )
+
+ Sets the x position of the rectangle (its left end) to \a x. May
+ change the width, but will never change the right edge of the
+ rectangle.
+
+ Identical to setLeft().
+
+ \sa x(), setY()
+*/
+
+/*!
+ \fn void TQRect::setY( int y )
+
+ Sets the y position of the rectangle (its top) to \a y. May change
+ the height, but will never change the bottom edge of the
+ rectangle.
+
+ Identical to setTop().
+
+ \sa y(), setX()
+*/
+
+/*!
+ Set the top-left corner of the rectangle to \a p. May change
+ the size, but will the never change the bottom-right corner of
+ the rectangle.
+
+ \sa topLeft(), moveTopLeft(), setBottomRight(), setTopRight(), setBottomLeft()
+*/
+void TQRect::setTopLeft( const TQPoint &p )
+{
+ setLeft( p.x() );
+ setTop( p.y() );
+}
+
+/*!
+ Set the bottom-right corner of the rectangle to \a p. May change
+ the size, but will the never change the top-left corner of
+ the rectangle.
+
+ \sa bottomRight(), moveBottomRight(), setTopLeft(), setTopRight(), setBottomLeft()
+*/
+void TQRect::setBottomRight( const TQPoint &p )
+{
+ setRight( p.x() );
+ setBottom( p.y() );
+}
+
+/*!
+ Set the top-right corner of the rectangle to \a p. May change
+ the size, but will the never change the bottom-left corner of
+ the rectangle.
+
+ \sa topRight(), moveTopRight(), setTopLeft(), setBottomRight(), setBottomLeft()
+*/
+void TQRect::setTopRight( const TQPoint &p )
+{
+ setRight( p.x() );
+ setTop( p.y() );
+}
+
+/*!
+ Set the bottom-left corner of the rectangle to \a p. May change
+ the size, but will the never change the top-right corner of
+ the rectangle.
+
+ \sa bottomLeft(), moveBottomLeft(), setTopLeft(), setBottomRight(), setTopRight()
+*/
+void TQRect::setBottomLeft( const TQPoint &p )
+{
+ setLeft( p.x() );
+ setBottom( p.y() );
+}
+
+/*!
+ \fn TQPoint TQRect::topLeft() const
+
+ Returns the top-left position of the rectangle.
+
+ \sa setTopLeft(), moveTopLeft(), bottomRight(), left(), top()
+*/
+
+/*!
+ \fn TQPoint TQRect::bottomRight() const
+
+ Returns the bottom-right position of the rectangle.
+
+ \sa setBottomRight(), moveBottomRight(), topLeft(), right(), bottom()
+*/
+
+/*!
+ \fn TQPoint TQRect::topRight() const
+
+ Returns the top-right position of the rectangle.
+
+ \sa setTopRight(), moveTopRight(), bottomLeft(), top(), right()
+*/
+
+/*!
+ \fn TQPoint TQRect::bottomLeft() const
+
+ Returns the bottom-left position of the rectangle.
+
+ \sa setBottomLeft(), moveBottomLeft(), topRight(), bottom(), left()
+*/
+
+/*!
+ \fn TQPoint TQRect::center() const
+
+ Returns the center point of the rectangle.
+
+ \sa moveCenter(), topLeft(), bottomRight(), topRight(), bottomLeft()
+*/
+
+
+/*!
+ Extracts the rectangle parameters as the position \a *x, \a *y and
+ width \a *w and height \a *h.
+
+ \sa setRect(), coords()
+*/
+
+void TQRect::rect( int *x, int *y, int *w, int *h ) const
+{
+ *x = x1;
+ *y = y1;
+ *w = x2-x1+1;
+ *h = y2-y1+1;
+}
+
+/*!
+ Extracts the rectangle parameters as the top-left point \a *xp1,
+ \a *yp1 and the bottom-right point \a *xp2, \a *yp2.
+
+ \sa setCoords(), rect()
+*/
+
+void TQRect::coords( int *xp1, int *yp1, int *xp2, int *yp2 ) const
+{
+ *xp1 = x1;
+ *yp1 = y1;
+ *xp2 = x2;
+ *yp2 = y2;
+}
+
+
+/*!
+ Sets the left position of the rectangle to \a pos, leaving the
+ size unchanged.
+
+ \sa left(), setLeft(), moveTop(), moveRight(), moveBottom()
+*/
+void TQRect::moveLeft( int pos )
+{
+ x2 += (TQCOORD)(pos - x1);
+ x1 = (TQCOORD)pos;
+}
+
+/*!
+ Sets the top position of the rectangle to \a pos, leaving the
+ size unchanged.
+
+ \sa top(), setTop(), moveLeft(), moveRight(), moveBottom()
+*/
+
+void TQRect::moveTop( int pos )
+{
+ y2 += (TQCOORD)(pos - y1);
+ y1 = (TQCOORD)pos;
+}
+
+/*!
+ Sets the right position of the rectangle to \a pos, leaving the
+ size unchanged.
+
+ \sa right(), setRight(), moveLeft(), moveTop(), moveBottom()
+*/
+
+void TQRect::moveRight( int pos )
+{
+ x1 += (TQCOORD)(pos - x2);
+ x2 = (TQCOORD)pos;
+}
+
+/*!
+ Sets the bottom position of the rectangle to \a pos, leaving the
+ size unchanged.
+
+ \sa bottom(), setBottom(), moveLeft(), moveTop(), moveRight()
+*/
+
+void TQRect::moveBottom( int pos )
+{
+ y1 += (TQCOORD)(pos - y2);
+ y2 = (TQCOORD)pos;
+}
+
+/*!
+ Sets the top-left position of the rectangle to \a p, leaving the
+ size unchanged.
+
+ \sa topLeft(), setTopLeft(), moveBottomRight(), moveTopRight(), moveBottomLeft()
+*/
+
+void TQRect::moveTopLeft( const TQPoint &p )
+{
+ moveLeft( p.x() );
+ moveTop( p.y() );
+}
+
+/*!
+ Sets the bottom-right position of the rectangle to \a p, leaving
+ the size unchanged.
+
+ \sa bottomRight(), setBottomRight(), moveTopLeft(), moveTopRight(), moveBottomLeft()
+*/
+
+void TQRect::moveBottomRight( const TQPoint &p )
+{
+ moveRight( p.x() );
+ moveBottom( p.y() );
+}
+
+/*!
+ Sets the top-right position of the rectangle to \a p, leaving the
+ size unchanged.
+
+ \sa topRight(), setTopRight(), moveTopLeft(), moveBottomRight(), moveBottomLeft()
+*/
+
+void TQRect::moveTopRight( const TQPoint &p )
+{
+ moveRight( p.x() );
+ moveTop( p.y() );
+}
+
+/*!
+ Sets the bottom-left position of the rectangle to \a p, leaving
+ the size unchanged.
+
+ \sa bottomLeft(), setBottomLeft(), moveTopLeft(), moveBottomRight(), moveTopRight()
+*/
+
+void TQRect::moveBottomLeft( const TQPoint &p )
+{
+ moveLeft( p.x() );
+ moveBottom( p.y() );
+}
+
+
+/*!
+ Sets the center point of the rectangle to \a p, leaving the size
+ unchanged.
+
+ \sa center(), moveTopLeft(), moveBottomRight(), moveTopRight(), moveBottomLeft()
+*/
+
+void TQRect::moveCenter( const TQPoint &p )
+{
+ TQCOORD w = x2 - x1;
+ TQCOORD h = y2 - y1;
+ x1 = (TQCOORD)(p.x() - w/2);
+ y1 = (TQCOORD)(p.y() - h/2);
+ x2 = x1 + w;
+ y2 = y1 + h;
+}
+
+
+/*!
+ Moves the rectangle \a dx along the x axis and \a dy along the y
+ axis, relative to the current position. Positive values move the
+ rectangle to the right and down.
+
+ \sa moveTopLeft()
+*/
+
+void TQRect::moveBy( int dx, int dy )
+{
+ x1 += (TQCOORD)dx;
+ y1 += (TQCOORD)dy;
+ x2 += (TQCOORD)dx;
+ y2 += (TQCOORD)dy;
+}
+
+/*!
+ Sets the coordinates of the rectangle's top-left corner to \a (x,
+ y), and its size to \a (w, h).
+
+ \sa rect(), setCoords()
+*/
+
+void TQRect::setRect( int x, int y, int w, int h )
+{
+ x1 = (TQCOORD)x;
+ y1 = (TQCOORD)y;
+ x2 = (TQCOORD)(x+w-1);
+ y2 = (TQCOORD)(y+h-1);
+}
+
+/*!
+ Sets the coordinates of the rectangle's top-left corner to \a
+ (xp1, yp1), and the coordinates of its bottom-right corner to \a
+ (xp2, yp2).
+
+ \sa coords(), setRect()
+*/
+
+void TQRect::setCoords( int xp1, int yp1, int xp2, int yp2 )
+{
+ x1 = (TQCOORD)xp1;
+ y1 = (TQCOORD)yp1;
+ x2 = (TQCOORD)xp2;
+ y2 = (TQCOORD)yp2;
+}
+
+/*!
+ Adds \a xp1, \a yp1, \a xp2 and \a yp2 respectively to the
+ existing coordinates of the rectangle.
+*/
+
+void TQRect::addCoords( int xp1, int yp1, int xp2, int yp2 )
+{
+ x1 += (TQCOORD)xp1;
+ y1 += (TQCOORD)yp1;
+ x2 += (TQCOORD)xp2;
+ y2 += (TQCOORD)yp2;
+}
+
+/*!
+ \fn TQSize TQRect::size() const
+
+ Returns the size of the rectangle.
+
+ \sa width(), height()
+*/
+
+/*!
+ \fn int TQRect::width() const
+
+ Returns the width of the rectangle. The width includes both the
+ left and right edges, i.e. width = right - left + 1.
+
+ \sa height(), size(), setHeight()
+*/
+
+/*!
+ \fn int TQRect::height() const
+
+ Returns the height of the rectangle. The height includes both the
+ top and bottom edges, i.e. height = bottom - top + 1.
+
+ \sa width(), size(), setHeight()
+*/
+
+/*!
+ Sets the width of the rectangle to \a w. The right edge is
+ changed, but not the left edge.
+
+ \sa width(), setLeft(), setRight(), setSize()
+*/
+
+void TQRect::setWidth( int w )
+{
+ x2 = (TQCOORD)(x1 + w - 1);
+}
+
+/*!
+ Sets the height of the rectangle to \a h. The top edge is not
+ moved, but the bottom edge may be moved.
+
+ \sa height(), setTop(), setBottom(), setSize()
+*/
+
+void TQRect::setHeight( int h )
+{
+ y2 = (TQCOORD)(y1 + h - 1);
+}
+
+/*!
+ Sets the size of the rectangle to \a s. The top-left corner is not
+ moved.
+
+ \sa size(), setWidth(), setHeight()
+*/
+
+void TQRect::setSize( const TQSize &s )
+{
+ x2 = (TQCOORD)(s.width() +x1-1);
+ y2 = (TQCOORD)(s.height()+y1-1);
+}
+
+/*!
+ Returns TRUE if the point \a p is inside or on the edge of the
+ rectangle; otherwise returns FALSE.
+
+ If \a proper is TRUE, this function returns TRUE only if \a p is
+ inside (not on the edge).
+*/
+
+bool TQRect::tqcontains( const TQPoint &p, bool proper ) const
+{
+ if ( proper )
+ return p.x() > x1 && p.x() < x2 &&
+ p.y() > y1 && p.y() < y2;
+ else
+ return p.x() >= x1 && p.x() <= x2 &&
+ p.y() >= y1 && p.y() <= y2;
+}
+
+/*!
+ \overload bool TQRect::tqcontains( int x, int y, bool proper ) const
+
+ Returns TRUE if the point \a x, \a y is inside this rectangle;
+ otherwise returns FALSE.
+
+ If \a proper is TRUE, this function returns TRUE only if the point
+ is entirely inside (not on the edge).
+*/
+
+/*!
+ \overload bool TQRect::tqcontains( int x, int y ) const
+
+ Returns TRUE if the point \a x, \a y is inside this rectangle;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \overload
+
+ Returns TRUE if the rectangle \a r is inside this rectangle;
+ otherwise returns FALSE.
+
+ If \a proper is TRUE, this function returns TRUE only if \a r is
+ entirely inside (not on the edge).
+
+ \sa unite(), intersect(), intersects()
+*/
+
+bool TQRect::tqcontains( const TQRect &r, bool proper ) const
+{
+ if ( proper )
+ return r.x1 > x1 && r.x2 < x2 && r.y1 > y1 && r.y2 < y2;
+ else
+ return r.x1 >= x1 && r.x2 <= x2 && r.y1 >= y1 && r.y2 <= y2;
+}
+
+/*!
+ Unites this rectangle with rectangle \a r.
+*/
+TQRect& TQRect::operator|=(const TQRect &r)
+{
+ *this = *this | r;
+ return *this;
+}
+
+/*!
+ Intersects this rectangle with rectangle \a r.
+*/
+TQRect& TQRect::operator&=(const TQRect &r)
+{
+ *this = *this & r;
+ return *this;
+}
+
+
+/*!
+ Returns the bounding rectangle of this rectangle and rectangle \a
+ r.
+
+ The bounding rectangle of a nonempty rectangle and an empty or
+ invalid rectangle is defined to be the nonempty rectangle.
+
+ \sa operator|=(), operator&(), intersects(), tqcontains()
+*/
+
+TQRect TQRect::operator|(const TQRect &r) const
+{
+ if ( isValid() ) {
+ if ( r.isValid() ) {
+ TQRect tmp;
+ tmp.setLeft( TQMIN( x1, r.x1 ) );
+ tmp.setRight( TQMAX( x2, r.x2 ) );
+ tmp.setTop( TQMIN( y1, r.y1 ) );
+ tmp.setBottom( TQMAX( y2, r.y2 ) );
+ return tmp;
+ } else {
+ return *this;
+ }
+ } else {
+ return r;
+ }
+}
+
+/*!
+ Returns the bounding rectangle of this rectangle and rectangle \a
+ r. \c{r.unite(s)} is equivalent to \c{r|s}.
+*/
+TQRect TQRect::unite( const TQRect &r ) const
+{
+ return *this | r;
+}
+
+
+/*!
+ Returns the intersection of this rectangle and rectangle \a r.
+
+ Returns an empty rectangle if there is no intersection.
+
+ \sa operator&=(), operator|(), isEmpty(), intersects(), tqcontains()
+*/
+
+TQRect TQRect::operator&( const TQRect &r ) const
+{
+ TQRect tmp;
+ tmp.x1 = TQMAX( x1, r.x1 );
+ tmp.x2 = TQMIN( x2, r.x2 );
+ tmp.y1 = TQMAX( y1, r.y1 );
+ tmp.y2 = TQMIN( y2, r.y2 );
+ return tmp;
+}
+
+/*!
+ Returns the intersection of this rectangle and rectangle \a r.
+ \c{r.intersect(s)} is equivalent to \c{r&s}.
+*/
+TQRect TQRect::intersect( const TQRect &r ) const
+{
+ return *this & r;
+}
+
+/*!
+ Returns TRUE if this rectangle intersects with rectangle \a r
+ (there is at least one pixel that is within both rectangles);
+ otherwise returns FALSE.
+
+ \sa intersect(), tqcontains()
+*/
+
+bool TQRect::intersects( const TQRect &r ) const
+{
+ return ( TQMAX( x1, r.x1 ) <= TQMIN( x2, r.x2 ) &&
+ TQMAX( y1, r.y1 ) <= TQMIN( y2, r.y2 ) );
+}
+
+
+/*!
+ \relates TQRect
+
+ Returns TRUE if \a r1 and \a r2 are equal; otherwise returns FALSE.
+*/
+
+bool operator==( const TQRect &r1, const TQRect &r2 )
+{
+ return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
+}
+
+/*!
+ \relates TQRect
+
+ Returns TRUE if \a r1 and \a r2 are different; otherwise returns FALSE.
+*/
+
+bool operator!=( const TQRect &r1, const TQRect &r2 )
+{
+ return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
+}
+
+
+/*****************************************************************************
+ TQRect stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQRect
+
+ Writes the TQRect, \a r, to the stream \a s, and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQRect &r )
+{
+ if ( s.version() == 1 )
+ s << (TQ_INT16)r.left() << (TQ_INT16)r.top()
+ << (TQ_INT16)r.right() << (TQ_INT16)r.bottom();
+ else
+ s << (TQ_INT32)r.left() << (TQ_INT32)r.top()
+ << (TQ_INT32)r.right() << (TQ_INT32)r.bottom();
+ return s;
+}
+
+/*!
+ \relates TQRect
+
+ Reads a TQRect from the stream \a s into rect \a r and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQRect &r )
+{
+ if ( s.version() == 1 ) {
+ TQ_INT16 x1, y1, x2, y2;
+ s >> x1; s >> y1; s >> x2; s >> y2;
+ r.setCoords( x1, y1, x2, y2 );
+ }
+ else {
+ TQ_INT32 x1, y1, x2, y2;
+ s >> x1; s >> y1; s >> x2; s >> y2;
+ r.setCoords( x1, y1, x2, y2 );
+ }
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqrect.h b/tqtinterface/qt4/src/kernel/tqrect.h
new file mode 100644
index 0000000..e208978
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqrect.h
@@ -0,0 +1,328 @@
+/****************************************************************************
+**
+** Definition of TQRect class
+**
+** Created : 931028
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQRECT_H
+#define TQRECT_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqsize.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qrect.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+
+class TQ_EXPORT TQRect : public QRect, virtual public TQt
+{
+public:
+ TQRect() : QRect(0, 0, -1, -1) {}
+ TQRect( const TQPoint &topleft, const TQPoint &bottomright ) : QRect(topleft, bottomright) {}
+ TQRect( const TQPoint &topleft, const TQSize &size ) : QRect(topleft, size) {}
+ TQRect( int left, int top, int width, int height ) : QRect(left, top, width, height) {}
+
+ void moveBy( int dx, int dy ) { translate(dx, dy); }
+
+ inline bool tqcontains( const TQPoint &p, bool proper=FALSE ) const { return contains(p, proper); }
+ inline bool tqcontains( int x, int y ) const { return contains(x, y); }
+ inline bool tqcontains( int x, int y, bool proper ) const { return contains(x, y, proper); }
+ inline bool tqcontains( const TQRect &r, bool proper=FALSE ) const { return contains(r, proper); }
+
+ inline void addCoords( int x1, int y1, int x2, int y2 ) { adjust(x1, y1, x2, y2); }
+
+ int &rLeft();
+ int &rTop();
+ int &rRight();
+ int &rBottom();
+
+ void rect( int *x, int *y, int *w, int *h ) const;
+ void coords( int *x1, int *y1, int *x2, int *y2 ) const;
+
+ TQRect normalize() const { return normalized(); }
+
+ // Interoperability
+ TQRect(QRect a) {
+ setLeft(a.left());
+ setTop(a.top());
+ setWidth(a.width());
+ setHeight(a.height());
+ }
+};
+
+#else // USE_QT4
+
+#if defined(topLeft)
+#error "Macro definition of topLeft conflicts with TQRect"
+// don't just silently undo people's defines: #undef topLeft
+#endif
+
+class TQ_EXPORT TQRect // rectangle class
+{
+public:
+ TQRect() { x1 = y1 = 0; x2 = y2 = -1; }
+ TQRect( const TQPoint &topleft, const TQPoint &bottomright );
+ TQRect( const TQPoint &topleft, const TQSize &size );
+ TQRect( int left, int top, int width, int height );
+
+ bool isNull() const;
+ bool isEmpty() const;
+ bool isValid() const;
+ TQRect normalize() const;
+
+ int left() const;
+ int top() const;
+ int right() const;
+ int bottom() const;
+
+ TQCOORD &rLeft();
+ TQCOORD &rTop();
+ TQCOORD &rRight();
+ TQCOORD &rBottom();
+
+ int x() const;
+ int y() const;
+ void setLeft( int pos );
+ void setTop( int pos );
+ void setRight( int pos );
+ void setBottom( int pos );
+ void setX( int x );
+ void setY( int y );
+
+ void setTopLeft( const TQPoint &p );
+ void setBottomRight( const TQPoint &p );
+ void setTopRight( const TQPoint &p );
+ void setBottomLeft( const TQPoint &p );
+
+ TQPoint topLeft() const;
+ TQPoint bottomRight() const;
+ TQPoint topRight() const;
+ TQPoint bottomLeft() const;
+ TQPoint center() const;
+
+ void rect( int *x, int *y, int *w, int *h ) const;
+ void coords( int *x1, int *y1, int *x2, int *y2 ) const;
+
+ void moveLeft( int pos );
+ void moveTop( int pos );
+ void moveRight( int pos );
+ void moveBottom( int pos );
+ void moveTopLeft( const TQPoint &p );
+ void moveBottomRight( const TQPoint &p );
+ void moveTopRight( const TQPoint &p );
+ void moveBottomLeft( const TQPoint &p );
+ void moveCenter( const TQPoint &p );
+ void moveBy( int dx, int dy );
+
+ void setRect( int x, int y, int w, int h );
+ void setCoords( int x1, int y1, int x2, int y2 );
+ void addCoords( int x1, int y1, int x2, int y2 );
+
+ TQSize size() const;
+ int width() const;
+ int height() const;
+ void setWidth( int w );
+ void setHeight( int h );
+ void setSize( const TQSize &s );
+
+ TQRect operator|(const TQRect &r) const;
+ TQRect operator&(const TQRect &r) const;
+ TQRect& operator|=(const TQRect &r);
+ TQRect& operator&=(const TQRect &r);
+
+ bool tqcontains( const TQPoint &p, bool proper=FALSE ) const;
+ bool tqcontains( int x, int y ) const; // inline methods, _don't_ merge these
+ bool tqcontains( int x, int y, bool proper ) const;
+ bool tqcontains( const TQRect &r, bool proper=FALSE ) const;
+ TQRect unite( const TQRect &r ) const;
+ TQRect intersect( const TQRect &r ) const;
+ bool intersects( const TQRect &r ) const;
+
+ friend TQ_EXPORT bool operator==( const TQRect &, const TQRect & );
+ friend TQ_EXPORT bool operator!=( const TQRect &, const TQRect & );
+
+private:
+#if defined(TQ_WS_X11) || defined(TQ_OS_TEMP)
+ friend void qt_setCoords( TQRect *r, int xp1, int yp1, int xp2, int yp2 );
+#endif
+#if defined(TQ_OS_MAC)
+ TQCOORD y1;
+ TQCOORD x1;
+ TQCOORD y2;
+ TQCOORD x2;
+#else
+ TQCOORD x1;
+ TQCOORD y1;
+ TQCOORD x2;
+ TQCOORD y2;
+#endif
+};
+
+TQ_EXPORT bool operator==( const TQRect &, const TQRect & );
+TQ_EXPORT bool operator!=( const TQRect &, const TQRect & );
+
+
+/*****************************************************************************
+ TQRect stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQRect & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQRect & );
+#endif
+
+/*****************************************************************************
+ TQRect inline member functions
+ *****************************************************************************/
+
+inline TQRect::TQRect( int left, int top, int width, int height )
+{
+ x1 = (TQCOORD)left;
+ y1 = (TQCOORD)top;
+ x2 = (TQCOORD)(left+width-1);
+ y2 = (TQCOORD)(top+height-1);
+}
+
+inline bool TQRect::isNull() const
+{ return x2 == x1-1 && y2 == y1-1; }
+
+inline bool TQRect::isEmpty() const
+{ return x1 > x2 || y1 > y2; }
+
+inline bool TQRect::isValid() const
+{ return x1 <= x2 && y1 <= y2; }
+
+inline int TQRect::left() const
+{ return x1; }
+
+inline int TQRect::top() const
+{ return y1; }
+
+inline int TQRect::right() const
+{ return x2; }
+
+inline int TQRect::bottom() const
+{ return y2; }
+
+inline TQCOORD &TQRect::rLeft()
+{ return x1; }
+
+inline TQCOORD & TQRect::rTop()
+{ return y1; }
+
+inline TQCOORD & TQRect::rRight()
+{ return x2; }
+
+inline TQCOORD & TQRect::rBottom()
+{ return y2; }
+
+inline int TQRect::x() const
+{ return x1; }
+
+inline int TQRect::y() const
+{ return y1; }
+
+inline void TQRect::setLeft( int pos )
+{ x1 = (TQCOORD)pos; }
+
+inline void TQRect::setTop( int pos )
+{ y1 = (TQCOORD)pos; }
+
+inline void TQRect::setRight( int pos )
+{ x2 = (TQCOORD)pos; }
+
+inline void TQRect::setBottom( int pos )
+{ y2 = (TQCOORD)pos; }
+
+inline void TQRect::setX( int x )
+{ x1 = (TQCOORD)x; }
+
+inline void TQRect::setY( int y )
+{ y1 = (TQCOORD)y; }
+
+inline TQPoint TQRect::topLeft() const
+{ return TQPoint(x1, y1); }
+
+inline TQPoint TQRect::bottomRight() const
+{ return TQPoint(x2, y2); }
+
+inline TQPoint TQRect::topRight() const
+{ return TQPoint(x2, y1); }
+
+inline TQPoint TQRect::bottomLeft() const
+{ return TQPoint(x1, y2); }
+
+inline TQPoint TQRect::center() const
+{ return TQPoint((x1+x2)/2, (y1+y2)/2); }
+
+inline int TQRect::width() const
+{ return x2 - x1 + 1; }
+
+inline int TQRect::height() const
+{ return y2 - y1 + 1; }
+
+inline TQSize TQRect::size() const
+{ return TQSize(x2-x1+1, y2-y1+1); }
+
+inline bool TQRect::tqcontains( int x, int y, bool proper ) const
+{
+ if ( proper )
+ return x > x1 && x < x2 &&
+ y > y1 && y < y2;
+ else
+ return x >= x1 && x <= x2 &&
+ y >= y1 && y <= y2;
+}
+
+inline bool TQRect::tqcontains( int x, int y ) const
+{
+ return x >= x1 && x <= x2 &&
+ y >= y1 && y <= y2;
+}
+
+#endif // USE_QT4
+
+#define TQ_DEFINED_TQRECT
+#include "tqwinexport.h"
+#endif // TQRECT_H
diff --git a/tqtinterface/qt4/src/kernel/tqregion.cpp b/tqtinterface/qt4/src/kernel/tqregion.cpp
new file mode 100644
index 0000000..58bf4eb
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqregion.cpp
@@ -0,0 +1,398 @@
+/****************************************************************************
+**
+** Implementation of TQRegion class
+**
+** Created : 950726
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqregion.h"
+#include "tqpointarray.h"
+#include "tqbuffer.h"
+#include "tqdatastream.h"
+
+#ifdef USE_QT4
+
+/*!
+ Use the constructor tha takes a Qt::FillRule as the second
+ argument instead.
+*/
+TQRegion::TQRegion(const QPolygon &pa, bool winding)
+{
+ new (this) QRegion(pa, winding ? Qt::WindingFill : Qt::OddEvenFill);
+}
+
+#else // USE_QT4
+
+// BEING REVISED: paul
+/*!
+ \class TQRegion tqregion.h
+ \brief The TQRegion class specifies a clip region for a painter.
+
+ \ingroup images
+ \ingroup graphics
+
+ TQRegion is used with TQPainter::setClipRegion() to limit the paint
+ area to what needs to be painted. There is also a
+ TQWidget::tqrepaint() that takes a TQRegion parameter. TQRegion is the
+ best tool for reducing flicker.
+
+ A region can be created from a rectangle, an ellipse, a polygon or
+ a bitmap. Complex regions may be created by combining simple
+ regions using unite(), intersect(), subtract() or eor() (exclusive
+ or). You can move a region using translate().
+
+ You can test whether a region isNull(), isEmpty() or if it
+ tqcontains() a TQPoint or TQRect. The bounding rectangle is given by
+ boundingRect().
+
+ The function rects() gives a decomposition of the region into
+ rectangles.
+
+ Example of using complex regions:
+ \code
+ void MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p; // our painter
+ TQRegion r1( TQRect(100,100,200,80), // r1 = elliptic region
+ TQRegion::Ellipse );
+ TQRegion r2( TQRect(100,120,90,30) ); // r2 = rectangular region
+ TQRegion r3 = r1.intersect( r2 ); // r3 = intersection
+ p.begin( this ); // start painting widget
+ p.setClipRegion( r3 ); // set clip region
+ ... // paint clipped graphics
+ p.end(); // painting done
+ }
+ \endcode
+
+ TQRegion is an \link shclass.html implicitly shared\endlink class.
+
+ \warning Due to window system limitations, the whole coordinate
+ space for a region is limited to the points between -32767 and
+ 32767 on Mac OS X and Windows 95/98/ME.
+
+ \sa TQPainter::setClipRegion(), TQPainter::setClipRect()
+*/
+
+
+/*!
+ \enum TQRegion::RegionType
+
+ Specifies the tqshape of the region to be created.
+
+ \value Rectangle the region covers the entire rectangle.
+ \value Ellipse the region is an ellipse inside the rectangle.
+*/
+
+/*!
+ \fn Region TQRegion::handle() const
+
+ Returns the region's handle.
+*/
+
+/*****************************************************************************
+ TQRegion member functions
+ *****************************************************************************/
+
+/*!
+ Constructs a rectangular or elliptic region.
+
+ If \a t is \c Rectangle, the region is the filled rectangle (\a x,
+ \a y, \a w, \a h). If \a t is \c Ellipse, the region is the filled
+ ellipse with center at (\a x + \a w / 2, \a y + \a h / 2) and size
+ (\a w ,\a h ).
+*/
+TQRegion::TQRegion( int x, int y, int w, int h, RegionType t )
+{
+ TQRegion tmp(TQRect(x,y,w,h),t);
+ tmp.data->ref();
+ data = tmp.data;
+}
+
+/*!
+ Detaches from shared region data to make sure that this region is
+ the only one referring to the data.
+
+ \sa copy(), \link shclass.html shared classes\endlink
+*/
+
+void TQRegion::detach()
+{
+ if ( data->count != 1 )
+ *this = copy();
+}
+
+#ifndef TQT_NO_DATASTREAM
+/*
+ Executes region commands in the internal buffer and rebuilds the
+ original region.
+
+ We do this when we read a region from the data stream.
+
+ If \a ver is non-0, uses the format version \a ver on reading the
+ byte array.
+*/
+
+void TQRegion::exec( const TQByteArray &buffer, int ver )
+{
+ TQBuffer buf( buffer );
+ TQDataStream s( &buf );
+ if ( ver )
+ s.setVersion( ver );
+ buf.open( IO_ReadOnly );
+ TQRegion rgn;
+#if defined(TQT_CHECK_STATE)
+ int test_cnt = 0;
+#endif
+ while ( !s.eof() ) {
+ TQ_INT32 id;
+ if ( s.version() == 1 ) {
+ int id_int;
+ s >> id_int;
+ id = id_int;
+ } else {
+ s >> id;
+ }
+#if defined(TQT_CHECK_STATE)
+ if ( test_cnt > 0 && id != TQRGN_TRANSLATE )
+ qWarning( "TQRegion::exec: Internal error" );
+ test_cnt++;
+#endif
+ if ( id == TQRGN_SETRECT || id == TQRGN_SETELLIPSE ) {
+ TQRect r;
+ s >> r;
+ rgn = TQRegion( r, id == TQRGN_SETRECT ? Rectangle : Ellipse );
+ } else if ( id == TQRGN_SETPTARRAY_ALT || id == TQRGN_SETPTARRAY_WIND ) {
+ TQPointArray a;
+ s >> a;
+ rgn = TQRegion( a, id == TQRGN_SETPTARRAY_WIND );
+ } else if ( id == TQRGN_TRANSLATE ) {
+ TQPoint p;
+ s >> p;
+ rgn.translate( p.x(), p.y() );
+ } else if ( id >= TQRGN_OR && id <= TQRGN_XOR ) {
+ TQByteArray bop1, bop2;
+ TQRegion r1, r2;
+ s >> bop1; r1.exec( bop1 );
+ s >> bop2; r2.exec( bop2 );
+ switch ( id ) {
+ case TQRGN_OR:
+ rgn = r1.unite( r2 );
+ break;
+ case TQRGN_AND:
+ rgn = r1.intersect( r2 );
+ break;
+ case TQRGN_SUB:
+ rgn = r1.subtract( r2 );
+ break;
+ case TQRGN_XOR:
+ rgn = r1.eor( r2 );
+ break;
+ }
+ } else if ( id == TQRGN_RECTS ) {
+ // (This is the only form used in TQt 2.0)
+ TQ_UINT32 n;
+ s >> n;
+ TQRect r;
+ for ( int i=0; i<(int)n; i++ ) {
+ s >> r;
+ rgn = rgn.unite( TQRegion(r) );
+ }
+ }
+ }
+ buf.close();
+ *this = rgn;
+}
+
+
+/*****************************************************************************
+ TQRegion stream functions
+ *****************************************************************************/
+
+/*!
+ \relates TQRegion
+
+ Writes the region \a r to the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQRegion &r )
+{
+ TQMemArray<TQRect> a = r.rects();
+ if ( a.isEmpty() ) {
+ s << (TQ_UINT32)0;
+ } else {
+ if ( s.version() == 1 ) {
+ int i;
+ for ( i=(int)a.size()-1; i>0; i-- ) {
+ s << (TQ_UINT32)(12+i*24);
+ s << (int)TQRGN_OR;
+ }
+ for ( i=0; i<(int)a.size(); i++ ) {
+ s << (TQ_UINT32)(4+8) << (int)TQRGN_SETRECT << a[i];
+ }
+ }
+ else {
+ s << (TQ_UINT32)(4+4+16*a.size()); // 16: storage size of TQRect
+ s << (TQ_INT32)TQRGN_RECTS;
+ s << (TQ_UINT32)a.size();
+ for ( int i=0; i<(int)a.size(); i++ )
+ s << a[i];
+ }
+ }
+ return s;
+}
+
+/*!
+ \relates TQRegion
+
+ Reads a region from the stream \a s into \a r and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQRegion &r )
+{
+ TQByteArray b;
+ s >> b;
+ r.exec( b, s.version() );
+ return s;
+}
+#endif //TQT_NO_DATASTREAM
+
+// These are not inline - they can be implemented better on some platforms
+// (eg. Windows at least provides 3-variable operations). For now, simple.
+
+
+/*!
+ Applies the unite() function to this region and \a r. \c r1|r2 is
+ equivalent to \c r1.unite(r2)
+
+ \sa unite(), operator+()
+*/
+const TQRegion TQRegion::operator|( const TQRegion &r ) const
+ { return unite(r); }
+
+/*!
+ Applies the unite() function to this region and \a r. \c r1+r2 is
+ equivalent to \c r1.unite(r2)
+
+ \sa unite(), operator|()
+*/
+const TQRegion TQRegion::operator+( const TQRegion &r ) const
+ { return unite(r); }
+
+/*!
+ Applies the intersect() function to this region and \a r. \c r1&r2
+ is equivalent to \c r1.intersect(r2)
+
+ \sa intersect()
+*/
+const TQRegion TQRegion::operator&( const TQRegion &r ) const
+ { return intersect(r); }
+
+/*!
+ Applies the subtract() function to this region and \a r. \c r1-r2
+ is equivalent to \c r1.subtract(r2)
+
+ \sa subtract()
+*/
+const TQRegion TQRegion::operator-( const TQRegion &r ) const
+ { return subtract(r); }
+
+/*!
+ Applies the eor() function to this region and \a r. \c r1^r2 is
+ equivalent to \c r1.eor(r2)
+
+ \sa eor()
+*/
+const TQRegion TQRegion::operator^( const TQRegion &r ) const
+ { return eor(r); }
+
+/*!
+ Applies the unite() function to this region and \a r and assigns
+ the result to this region. \c r1|=r2 is equivalent to \c
+ r1=r1.unite(r2)
+
+ \sa unite()
+*/
+TQRegion& TQRegion::operator|=( const TQRegion &r )
+ { return *this = *this | r; }
+
+/*!
+ Applies the unite() function to this region and \a r and assigns
+ the result to this region. \c r1+=r2 is equivalent to \c
+ r1=r1.unite(r2)
+
+ \sa intersect()
+*/
+TQRegion& TQRegion::operator+=( const TQRegion &r )
+ { return *this = *this + r; }
+
+/*!
+ Applies the intersect() function to this region and \a r and
+ assigns the result to this region. \c r1&=r2 is equivalent to \c
+ r1=r1.intersect(r2)
+
+ \sa intersect()
+*/
+TQRegion& TQRegion::operator&=( const TQRegion &r )
+ { return *this = *this & r; }
+
+/*!
+ Applies the subtract() function to this region and \a r and
+ assigns the result to this region. \c r1-=r2 is equivalent to \c
+ r1=r1.subtract(r2)
+
+ \sa subtract()
+*/
+TQRegion& TQRegion::operator-=( const TQRegion &r )
+ { return *this = *this - r; }
+
+/*!
+ Applies the eor() function to this region and \a r and
+ assigns the result to this region. \c r1^=r2 is equivalent to \c
+ r1=r1.eor(r2)
+
+ \sa eor()
+*/
+TQRegion& TQRegion::operator^=( const TQRegion &r )
+ { return *this = *this ^ r; }
+
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqregion.h b/tqtinterface/qt4/src/kernel/tqregion.h
new file mode 100644
index 0000000..179d33d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqregion.h
@@ -0,0 +1,227 @@
+/****************************************************************************
+**
+** Definition of TQRegion class
+**
+** Created : 940514
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQREGION_H
+#define TQREGION_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqshared.h"
+#include "tqrect.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include "tqpointarray.h"
+#include <Qt/qregion.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQRegion : public QRegion, virtual public TQt
+{
+public:
+ TQRegion() : QRegion() {}
+ TQRegion( int x, int y, int w, int h, RegionType rt = Rectangle ) : QRegion( x, y, w, h, rt ) {}
+ TQRegion( const QRect &qr, RegionType rt = Rectangle ) : QRegion( qr, rt ) {}
+// TQRegion( const TQPointArray &qpa, bool winding=FALSE ) : QRegion( qpa, winding ) {}
+ TQRegion(const QPolygon &pa, bool winding);
+ TQRegion( const QRegion &qr ) : QRegion( qr ) {}
+ TQRegion( const QBitmap &qb ) : QRegion( qb ) {}
+
+ inline bool isNull() const { return isEmpty(); }
+
+ inline bool tqcontains( const QPoint &p ) const { return contains(p); }
+ inline bool tqcontains( const QRect &r ) const { return contains(r); }
+
+ inline TQMemArray<TQRect> tqrects() const {
+ QVector<QRect> qvr = rects();
+ TQMemArray<TQRect> tqma(qvr.size());
+
+ for (int i = 0; i < qvr.size(); i++) {
+ TQRect tr = qvr.at(i);
+ memcpy (&(tqma[i]), &tr, sizeof tqma[i]); // If this is not done we get a crash, because the assignment operator (=) expects the left hand argument to be a valid TQRect object (which it is not)
+ }
+ return tqma;
+ }
+
+ // Interoperability
+ static const TQRegion& convertFromQRegion( QRegion& qr );
+};
+
+// Interoperability
+inline static const TQRegion& convertFromQRegion( const QRegion& qr ) {
+ return (*static_cast<const TQRegion*>(&qr));
+}
+
+#else // USE_QT4
+
+#ifdef TQ_WS_X11
+struct TQRegionPrivate;
+#endif
+
+class TQ_EXPORT TQRegion
+{
+public:
+ enum RegionType { Rectangle, Ellipse };
+
+ TQRegion();
+ TQRegion( int x, int y, int w, int h, RegionType = Rectangle );
+ TQRegion( const TQRect &, RegionType = Rectangle );
+ TQRegion( const TQPointArray &, bool winding=FALSE );
+ TQRegion( const TQRegion & );
+ TQRegion( const TQBitmap & );
+ ~TQRegion();
+ TQRegion &operator=( const TQRegion & );
+
+ bool isNull() const;
+ bool isEmpty() const;
+
+ bool tqcontains( const TQPoint &p ) const;
+ bool tqcontains( const TQRect &r ) const;
+
+ void translate( int dx, int dy );
+
+ TQRegion unite( const TQRegion & ) const;
+ TQRegion intersect( const TQRegion &) const;
+ TQRegion subtract( const TQRegion & ) const;
+ TQRegion eor( const TQRegion & ) const;
+
+ TQRect boundingRect() const;
+ TQMemArray<TQRect> rects() const;
+ void setRects( const TQRect *, int );
+
+ const TQRegion operator|( const TQRegion & ) const;
+ const TQRegion operator+( const TQRegion & ) const;
+ const TQRegion operator&( const TQRegion & ) const;
+ const TQRegion operator-( const TQRegion & ) const;
+ const TQRegion operator^( const TQRegion & ) const;
+ TQRegion& operator|=( const TQRegion & );
+ TQRegion& operator+=( const TQRegion & );
+ TQRegion& operator&=( const TQRegion & );
+ TQRegion& operator-=( const TQRegion & );
+ TQRegion& operator^=( const TQRegion & );
+
+ bool operator==( const TQRegion & ) const;
+ bool operator!=( const TQRegion &r ) const
+ { return !(operator==(r)); }
+
+#if defined(TQ_WS_WIN)
+ HRGN handle() const { return data->rgn; }
+#elif defined(TQ_WS_X11)
+ Region handle() const { if(!data->rgn) updateX11Region(); return data->rgn; }
+#elif defined(TQ_WS_MAC)
+ RgnHandle handle(bool require_rgn=FALSE) const;
+#elif defined(TQ_WS_TQWS)
+ // TQGfx_TQWS needs this for region drawing
+ void * handle() const { return data->rgn; }
+#endif
+
+#ifndef TQT_NO_DATASTREAM
+ friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQRegion & );
+ friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQRegion & );
+#endif
+private:
+ TQRegion( bool );
+ TQRegion copy() const;
+ void detach();
+#if defined(TQ_WS_WIN)
+ TQRegion winCombine( const TQRegion &, int ) const;
+#endif
+#if defined(TQ_WS_X11)
+ void updateX11Region() const;
+ void *clipRectangles( int &num ) const;
+ friend void *qt_getClipRects( const TQRegion &, int & );
+#endif
+ void exec( const TQByteArray &, int ver = 0 );
+ struct TQRegionData : public TQShared {
+#if defined(TQ_WS_WIN)
+ HRGN rgn;
+#elif defined(TQ_WS_X11)
+ Region rgn;
+ void *xrectangles;
+ TQRegionPrivate *region;
+#elif defined(TQ_WS_MAC)
+ uint is_rect:1;
+ TQRect rect;
+ RgnHandle rgn;
+#elif defined(TQ_WS_TQWS)
+ void * rgn;
+#endif
+ bool is_null;
+ } *data;
+#if defined(TQ_WS_MAC)
+ friend struct qt_mac_rgn_data_cache;
+ friend TQRegionData *qt_mac_get_rgn_data();
+ friend void qt_mac_free_rgn_data(TQRegionData *);
+ void rectifyRegion();
+#elif defined(TQ_WS_WIN)
+ friend class TQETWidget;
+#endif
+
+};
+
+
+#define TQRGN_SETRECT 1 // region stream commands
+#define TQRGN_SETELLIPSE 2 // (these are internal)
+#define TQRGN_SETPTARRAY_ALT 3
+#define TQRGN_SETPTARRAY_WIND 4
+#define TQRGN_TRANSLATE 5
+#define TQRGN_OR 6
+#define TQRGN_AND 7
+#define TQRGN_SUB 8
+#define TQRGN_XOR 9
+#define TQRGN_RECTS 10
+
+
+/*****************************************************************************
+ TQRegion stream functions
+ *****************************************************************************/
+
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQRegion & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQRegion & );
+#endif
+
+#endif // USE_QT4
+
+#endif // TQREGION_H
diff --git a/tqtinterface/qt4/src/kernel/tqregion_x11.cpp b/tqtinterface/qt4/src/kernel/tqregion_x11.cpp
new file mode 100644
index 0000000..4e573c9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqregion_x11.cpp
@@ -0,0 +1,2908 @@
+/****************************************************************************
+**
+** Implementation of TQRegion class for X11
+**
+** Created : 940729
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqregion.h"
+#include "tqpointarray.h"
+#include "tqbuffer.h"
+#include "tqimage.h"
+#include "tqbitmap.h"
+#include "tqt_x11_p.h"
+
+#include <stdlib.h>
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+// inline TQRect::setCoords
+inline void qt_setCoords( TQRect *r, int xp1, int yp1, int xp2, int yp2 )
+{
+#ifdef USE_QT4
+ r->setCoords((TQCOORD)xp1, (TQCOORD)yp1, (TQCOORD)xp2, (TQCOORD)yp2);
+#else // USE_QT4
+ r->x1 = (TQCOORD)xp1;
+ r->y1 = (TQCOORD)yp1;
+ r->x2 = (TQCOORD)xp2;
+ r->y2 = (TQCOORD)yp2;
+#endif // USE_QT4
+}
+
+/*
+ * clip region
+ */
+
+struct TQRegionPrivate {
+ int numRects;
+ TQMemArray<TQRect> rects;
+ TQRect extents;
+
+ TQRegionPrivate() { numRects = 0; }
+ TQRegionPrivate( const TQRect &r ) : rects(1) {
+ numRects = 1;
+ rects[0] = r;
+ extents = r;
+ }
+
+ TQRegionPrivate( const TQRegionPrivate &r ) {
+ rects = r.rects.copy();
+ numRects = r.numRects;
+ extents = r.extents;
+ }
+
+ TQRegionPrivate &operator=( const TQRegionPrivate &r ) {
+ rects = r.rects.copy();
+ numRects = r.numRects;
+ extents = r.extents;
+ return *this;
+ }
+
+};
+
+
+static void UnionRegion(TQRegionPrivate *reg1, TQRegionPrivate *reg2, TQRegionPrivate *newReg);
+static void IntersectRegion(TQRegionPrivate *reg1, TQRegionPrivate *reg2, register TQRegionPrivate *newReg);
+static void miRegionOp(register TQRegionPrivate *newReg, TQRegionPrivate *reg1, TQRegionPrivate *reg2,
+ void (*overlapFunc)(...),
+ void (*nonOverlap1Func)(...),
+ void (*nonOverlap2Func)(...));
+#define RectangleOut 0
+#define RectangleIn 1
+#define RectanglePart 2
+#define EvenOddRule 0
+#define WindingRule 1
+
+// START OF region.h extract
+/* $XConsortium: region.h,v 11.14 94/04/17 20:22:20 rws Exp $ */
+/************************************************************************
+
+Copyright (c) 1987 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSETQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+
+#ifndef _XREGION_H
+#define _XREGION_H
+
+#include <limits.h>
+
+#ifndef MAX
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+#ifndef MIN
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+
+/* 1 if two BOXs overlap.
+ * 0 if two BOXs do not overlap.
+ * Remember, x2 and y2 are not in the region
+ */
+#define EXTENTCHECK(r1, r2) \
+ ((r1)->right() >= (r2)->left() && \
+ (r1)->left() <= (r2)->right() && \
+ (r1)->bottom() >= (r2)->top() && \
+ (r1)->top() <= (r2)->bottom())
+
+/*
+ * update region extents
+ */
+#define EXTENTS(r,idRect){\
+ if((r)->left() < (idRect)->extents.left())\
+ (idRect)->extents.setLeft( (r)->left() );\
+ if((r)->top() < (idRect)->extents.top())\
+ (idRect)->extents.setTop( (r)->top() );\
+ if((r)->right() > (idRect)->extents.right())\
+ (idRect)->extents.setRight( (r)->right() );\
+ if((r)->bottom() > (idRect)->extents.bottom())\
+ (idRect)->extents.setBottom( (r)->bottom() );\
+ }
+
+/*
+ * Check to see if there is enough memory in the present region.
+ */
+#define MEMCHECK(reg, rect, firstrect){\
+ if ((reg)->numRects >= (int)((reg)->rects.size()-1)){\
+ firstrect.resize(firstrect.size() * 2); \
+ (rect) = (firstrect).data() + (reg)->numRects;\
+ }\
+ }
+
+
+#define EMPTY_REGION(pReg) pReg->numRects = 0
+
+#define REGION_NOT_EMPTY(pReg) pReg->numRects
+
+/*
+ * number of points to buffer before sending them off
+ * to scanlines() : Must be an even number
+ */
+#define NUMPTSTOBUFFER 200
+
+/*
+ * used to allocate buffers for points and link
+ * the buffers together
+ */
+typedef struct _POINTBLOCK {
+ TQPoint pts[NUMPTSTOBUFFER];
+ struct _POINTBLOCK *next;
+} POINTBLOCK;
+
+#endif
+// END OF region.h extract
+
+// START OF Region.c extract
+/* $XConsortium: Region.c /main/30 1996/10/22 14:21:24 kaleb $ */
+/************************************************************************
+
+Copyright (c) 1987, 1988 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSETQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+/*
+ * The functions in this file implement the Region abstraction, similar to one
+ * used in the X11 sample server. A Region is simply an area, as the name
+ * implies, and is implemented as a "y-x-banded" array of rectangles. To
+ * explain: Each Region is made up of a certain number of rectangles sorted
+ * by y coordinate first, and then by x coordinate.
+ *
+ * Furthermore, the rectangles are banded such that every rectangle with a
+ * given upper-left y coordinate (y1) will have the same lower-right y
+ * coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it
+ * will span the entire vertical distance of the band. This means that some
+ * areas that could be merged into a taller rectangle will be represented as
+ * several shorter rectangles to account for shorter rectangles to its left
+ * or right but within its "vertical scope".
+ *
+ * An added constraint on the rectangles is that they must cover as much
+ * horizontal area as possible. E.g. no two rectangles in a band are allowed
+ * to touch.
+ *
+ * Whenever possible, bands will be merged together to cover a greater vertical
+ * distance (and thus reduce the number of rectangles). Two bands can be merged
+ * only if the bottom of one touches the top of the other and they have
+ * rectangles in the same places (of the same width, of course). This maintains
+ * the y-x-banding that's so nice to have...
+ */
+/* $XFree86: xc/lib/X11/Region.c,v 1.1.1.2.2.2 1998/10/04 15:22:50 hohndel Exp $ */
+
+typedef void (*voidProcp)(...);
+
+
+static
+void UnionRectWithRegion(register const TQRect *rect, TQRegionPrivate *source, TQRegionPrivate *dest)
+{
+ TQRegionPrivate region;
+
+ if (!rect->width() || !rect->height())
+ return;
+ region.rects.resize(1);
+ region.numRects = 1;
+ region.rects[0] = *rect;
+ region.extents = *rect;
+
+ UnionRegion(&region, source, dest);
+ return;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miSetExtents --
+ * Reset the extents of a region to what they should be. Called by
+ * miSubtract and miIntersect b/c they can't figure it out along the
+ * way or do so easily, as miUnion can.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * The region's 'extents' structure is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+miSetExtents (TQRegionPrivate *pReg)
+{
+ register TQRect *pBox,
+ *pBoxEnd,
+ *pExtents;
+
+ if (pReg->numRects == 0)
+ {
+ qt_setCoords(&pReg->extents, 0, 0, 0, 0);
+ return;
+ }
+
+ pExtents = &pReg->extents;
+ pBox = pReg->rects.data();
+ pBoxEnd = &pBox[pReg->numRects - 1];
+
+ /*
+ * Since pBox is the first rectangle in the region, it must have the
+ * smallest y1 and since pBoxEnd is the last rectangle in the region,
+ * it must have the largest y2, because of banding. Initialize x1 and
+ * x2 from pBox and pBoxEnd, resp., as good things to initialize them
+ * to...
+ */
+ pExtents->setLeft( pBox->left() );
+ pExtents->setTop( pBox->top() );
+ pExtents->setRight( pBoxEnd->right() );
+ pExtents->setBottom( pBoxEnd->bottom() );
+
+ TQ_ASSERT(pExtents->top() <= pExtents->bottom());
+ while (pBox <= pBoxEnd)
+ {
+ if (pBox->left() < pExtents->left())
+ {
+ pExtents->setLeft( pBox->left() );
+ }
+ if (pBox->right() > pExtents->right())
+ {
+ pExtents->setRight( pBox->right() );
+ }
+ pBox++;
+ }
+ TQ_ASSERT(pExtents->left() <= pExtents->right());
+}
+
+
+/* TranslateRegion(pRegion, x, y)
+ translates in place
+ added by raymond
+*/
+
+static
+int
+OffsetRegion(register TQRegionPrivate *pRegion, register int x, register int y)
+{
+ register int nbox;
+ register TQRect *pbox;
+
+ pbox = pRegion->rects.data();
+ nbox = pRegion->numRects;
+
+ while(nbox--)
+ {
+ pbox->moveBy(x, y);
+ pbox++;
+ }
+ pRegion->extents.moveBy(x, y);
+ return 1;
+}
+
+/*======================================================================
+ * Region Intersection
+ *====================================================================*/
+/*-
+ *-----------------------------------------------------------------------
+ * miIntersectO --
+ * Handle an overlapping band for miIntersect.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * Rectangles may be added to the region.
+ *
+ *-----------------------------------------------------------------------
+ */
+/* static void*/
+static
+int
+miIntersectO (register TQRegionPrivate *pReg, register TQRect *r1, TQRect *r1End,
+ register TQRect *r2, TQRect *r2End, int y1, int y2)
+{
+ register int x1;
+ register int x2;
+ register TQRect *pNextRect;
+
+ pNextRect = pReg->rects.data() + pReg->numRects;
+
+ while ((r1 != r1End) && (r2 != r2End))
+ {
+ x1 = TQMAX(r1->left(),r2->left());
+ x2 = TQMIN(r1->right(),r2->right());
+
+ /*
+ * If there's any overlap between the two rectangles, add that
+ * overlap to the new region.
+ * There's no need to check for subsumption because the only way
+ * such a need could arise is if some region has two rectangles
+ * right next to each other. Since that should never happen...
+ */
+ if (x1 <= x2)
+ {
+ TQ_ASSERT(y1<=y2);
+
+ MEMCHECK(pReg, pNextRect, pReg->rects)
+ qt_setCoords( pNextRect, x1, y1, x2, y2 );
+ pReg->numRects++;
+ pNextRect++;
+ }
+
+ /*
+ * Need to advance the pointers. Shift the one that extends
+ * to the right the least, since the other still has a chance to
+ * overlap with that region's next rectangle, if you see what I mean.
+ */
+ if (r1->right() < r2->right())
+ {
+ r1++;
+ }
+ else if (r2->right() < r1->right())
+ {
+ r2++;
+ }
+ else
+ {
+ r1++;
+ r2++;
+ }
+ }
+ return 0; /* lint */
+}
+
+static
+void
+IntersectRegion(TQRegionPrivate *reg1, TQRegionPrivate *reg2, register TQRegionPrivate *newReg)
+{
+ /* check for trivial reject */
+ if ( (!(reg1->numRects)) || (!(reg2->numRects)) ||
+ (!EXTENTCHECK(&reg1->extents, &reg2->extents)))
+ newReg->numRects = 0;
+ else
+ miRegionOp (newReg, reg1, reg2,
+ (voidProcp) miIntersectO, (voidProcp) NULL, (voidProcp) NULL);
+
+ /*
+ * Can't alter newReg's extents before we call miRegionOp because
+ * it might be one of the source regions and miRegionOp depends
+ * on the extents of those regions being the same. Besides, this
+ * way there's no checking against rectangles that will be nuked
+ * due to coalescing, so we have to examine fewer rectangles.
+ */
+ miSetExtents(newReg);
+ return;
+}
+
+/*======================================================================
+ * Generic Region Operator
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * miCoalesce --
+ * Attempt to merge the boxes in the current band with those in the
+ * previous one. Used only by miRegionOp.
+ *
+ * Results:
+ * The new index for the previous band.
+ *
+ * Side Effects:
+ * If coalescing takes place:
+ * - rectangles in the previous band will have their y2 fields
+ * altered.
+ * - pReg->numRects will be decreased.
+ *
+ *-----------------------------------------------------------------------
+ */
+/* static int*/
+static
+int
+miCoalesce (register TQRegionPrivate *pReg, int prevStart, int curStart)
+ //Region pReg; /* Region to coalesce */
+ //prevStart; /* Index of start of previous band */
+ //curStart; /* Index of start of current band */
+{
+ register TQRect *pPrevBox; /* Current box in previous band */
+ register TQRect *pCurBox; /* Current box in current band */
+ register TQRect *pRegEnd; /* End of region */
+ int curNumRects; /* Number of rectangles in current
+ * band */
+ int prevNumRects; /* Number of rectangles in previous
+ * band */
+ int bandY1; /* Y1 coordinate for current band */
+
+ pRegEnd = pReg->rects.data() + pReg->numRects;
+
+ pPrevBox = pReg->rects.data() + prevStart;
+ prevNumRects = curStart - prevStart;
+
+ /*
+ * Figure out how many rectangles are in the current band. Have to do
+ * this because multiple bands could have been added in miRegionOp
+ * at the end when one region has been exhausted.
+ */
+ pCurBox = pReg->rects.data() + curStart;
+ bandY1 = pCurBox->top();
+ for (curNumRects = 0;
+ (pCurBox != pRegEnd) && (pCurBox->top() == bandY1);
+ curNumRects++)
+ {
+ pCurBox++;
+ }
+
+ if (pCurBox != pRegEnd)
+ {
+ /*
+ * If more than one band was added, we have to tqfind the start
+ * of the last band added so the next coalescing job can start
+ * at the right place... (given when multiple bands are added,
+ * this may be pointless -- see above).
+ */
+ pRegEnd--;
+ while ((pRegEnd-1)->top() == pRegEnd->top())
+ {
+ pRegEnd--;
+ }
+ curStart = pRegEnd - pReg->rects.data();
+ pRegEnd = pReg->rects.data() + pReg->numRects;
+ }
+
+ if ((curNumRects == prevNumRects) && (curNumRects != 0)) {
+ pCurBox -= curNumRects;
+ /*
+ * The bands may only be coalesced if the bottom of the previous
+ * matches the top scanline of the current.
+ */
+ if (pPrevBox->bottom() == pCurBox->top() - 1)
+ {
+ /*
+ * Make sure the bands have boxes in the same places. This
+ * assumes that boxes have been added in such a way that they
+ * cover the most area possible. I.e. two boxes in a band must
+ * have some horizontal space between them.
+ */
+ do
+ {
+ if ((pPrevBox->left() != pCurBox->left()) ||
+ (pPrevBox->right() != pCurBox->right()))
+ {
+ /*
+ * The bands don't line up so they can't be coalesced.
+ */
+ return (curStart);
+ }
+ pPrevBox++;
+ pCurBox++;
+ prevNumRects -= 1;
+ } while (prevNumRects != 0);
+
+ pReg->numRects -= curNumRects;
+ pCurBox -= curNumRects;
+ pPrevBox -= curNumRects;
+
+ /*
+ * The bands may be merged, so set the bottom y of each box
+ * in the previous band to that of the corresponding box in
+ * the current band.
+ */
+ do
+ {
+ pPrevBox->setBottom( pCurBox->bottom() );
+ pPrevBox++;
+ pCurBox++;
+ curNumRects -= 1;
+ } while (curNumRects != 0);
+
+ /*
+ * If only one band was added to the region, we have to backup
+ * curStart to the start of the previous band.
+ *
+ * If more than one band was added to the region, copy the
+ * other bands down. The assumption here is that the other bands
+ * came from the same region as the current one and no further
+ * coalescing can be done on them since it's all been done
+ * already... curStart is already in the right place.
+ */
+ if (pCurBox == pRegEnd)
+ {
+ curStart = prevStart;
+ }
+ else
+ {
+ do
+ {
+ *pPrevBox++ = *pCurBox++;
+ } while (pCurBox != pRegEnd);
+ }
+
+ }
+ }
+ return (curStart);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miRegionOp --
+ * Apply an operation to two regions. Called by miUnion, miInverse,
+ * miSubtract, miIntersect...
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * The new region is overwritten.
+ *
+ * Notes:
+ * The idea behind this function is to view the two regions as sets.
+ * Together they cover a rectangle of area that this function divides
+ * into horizontal bands where points are covered only by one region
+ * or by both. For the first case, the nonOverlapFunc is called with
+ * each the band and the band's upper and lower extents. For the
+ * second, the overlapFunc is called to process the entire band. It
+ * is responsible for clipping the rectangles in the band, though
+ * this function provides the boundaries.
+ * At the end of each band, the new region is coalesced, if possible,
+ * to reduce the number of rectangles in the region.
+ *
+ *-----------------------------------------------------------------------
+ */
+/* static void*/
+static void
+miRegionOp(register TQRegionPrivate *newReg, TQRegionPrivate *reg1, TQRegionPrivate *reg2,
+ void (*overlapFunc)(...),
+ void (*nonOverlap1Func)(...),
+ void (*nonOverlap2Func)(...))
+ //register Region newReg; /* Place to store result */
+ //Region reg1; /* First region in operation */
+ //Region reg2; /* 2d region in operation */
+ //void (*overlapFunc)(); /* Function to call for over-
+ //* lapping bands */
+ //void (*nonOverlap1Func)(); /* Function to call for non-
+ //* overlapping bands in region
+ //* 1 */
+ //void (*nonOverlap2Func)(); /* Function to call for non-
+ //* overlapping bands in region
+ //* 2 */
+{
+ register TQRect *r1; /* Pointer into first region */
+ register TQRect *r2; /* Pointer into 2d region */
+ TQRect *r1End; /* End of 1st region */
+ TQRect *r2End; /* End of 2d region */
+ register int ybot; /* Bottom of intersection */
+ register int ytop; /* Top of intersection */
+ int prevBand; /* Index of start of
+ * previous band in newReg */
+ int curBand; /* Index of start of current
+ * band in newReg */
+ register TQRect *r1BandEnd; /* End of current band in r1 */
+ register TQRect *r2BandEnd; /* End of current band in r2 */
+ int top; /* Top of non-overlapping
+ * band */
+ int bot; /* Bottom of non-overlapping
+ * band */
+
+ /*
+ * Initialization:
+ * set r1, r2, r1End and r2End appropriately, preserve the important
+ * parts of the destination region until the end in case it's one of
+ * the two source regions, then mark the "new" region empty, allocating
+ * another array of rectangles for it to use.
+ */
+ r1 = reg1->rects.data();
+ r2 = reg2->rects.data();
+ r1End = r1 + reg1->numRects;
+ r2End = r2 + reg2->numRects;
+
+ TQMemArray<TQRect> oldRects = newReg->rects;
+
+ newReg->rects.detach();
+ EMPTY_REGION(newReg);
+
+ /*
+ * Allocate a reasonable number of rectangles for the new region. The idea
+ * is to allocate enough so the individual functions don't need to
+ * reallocate and copy the array, which is time consuming, yet we don't
+ * have to worry about using too much memory. I hope to be able to
+ * nuke the realloc() at the end of this function eventually.
+ */
+ newReg->rects.resize( TQMAX(reg1->numRects,reg2->numRects) * 2 );
+
+ /*
+ * Initialize ybot and ytop.
+ * In the upcoming loop, ybot and ytop serve different functions depending
+ * on whether the band being handled is an overlapping or non-overlapping
+ * band.
+ * In the case of a non-overlapping band (only one of the regions
+ * has points in the band), ybot is the bottom of the most recent
+ * intersection and thus clips the top of the rectangles in that band.
+ * ytop is the top of the next intersection between the two regions and
+ * serves to clip the bottom of the rectangles in the current band.
+ * For an overlapping band (where the two regions intersect), ytop clips
+ * the top of the rectangles of both regions and ybot clips the bottoms.
+ */
+ if (reg1->extents.top() < reg2->extents.top())
+ ybot = reg1->extents.top() - 1;
+ else
+ ybot = reg2->extents.top() - 1;
+
+ /*
+ * prevBand serves to mark the start of the previous band so rectangles
+ * can be coalesced into larger rectangles. qv. miCoalesce, above.
+ * In the beginning, there is no previous band, so prevBand == curBand
+ * (curBand is set later on, of course, but the first band will always
+ * start at index 0). prevBand and curBand must be indices because of
+ * the possible expansion, and resultant moving, of the new region's
+ * array of rectangles.
+ */
+ prevBand = 0;
+
+ do
+ {
+ curBand = newReg->numRects;
+
+ /*
+ * This algorithm proceeds one source-band (as opposed to a
+ * destination band, which is determined by where the two regions
+ * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
+ * rectangle after the last one in the current band for their
+ * respective regions.
+ */
+ r1BandEnd = r1;
+ while ((r1BandEnd != r1End) && (r1BandEnd->top() == r1->top()))
+ {
+ r1BandEnd++;
+ }
+
+ r2BandEnd = r2;
+ while ((r2BandEnd != r2End) && (r2BandEnd->top() == r2->top()))
+ {
+ r2BandEnd++;
+ }
+
+ /*
+ * First handle the band that doesn't intersect, if any.
+ *
+ * Note that attention is restricted to one band in the
+ * non-intersecting region at once, so if a region has n
+ * bands between the current position and the next place it overlaps
+ * the other, this entire loop will be passed through n times.
+ */
+ if (r1->top() < r2->top())
+ {
+ top = TQMAX(r1->top(),ybot+1);
+ bot = TQMIN(r1->bottom(),r2->top()-1);
+
+ if ((nonOverlap1Func != (voidProcp)NULL) && bot >= top)
+ {
+ (* nonOverlap1Func) (newReg, r1, r1BandEnd, top, bot);
+ }
+
+ ytop = r2->top();
+ }
+ else if (r2->top() < r1->top())
+ {
+ top = TQMAX(r2->top(),ybot+1);
+ bot = TQMIN(r2->bottom(),r1->top()-1);
+
+ if ((nonOverlap2Func != (voidProcp)NULL) && bot >= top)
+ {
+ (* nonOverlap2Func) (newReg, r2, r2BandEnd, top, bot);
+ }
+
+ ytop = r1->top();
+ }
+ else
+ {
+ ytop = r1->top();
+ }
+
+ /*
+ * If any rectangles got added to the region, try and coalesce them
+ * with rectangles from the previous band. Note we could just do
+ * this test in miCoalesce, but some machines incur a not
+ * inconsiderable cost for function calls, so...
+ */
+ if (newReg->numRects != curBand)
+ {
+ prevBand = miCoalesce (newReg, prevBand, curBand);
+ }
+
+ /*
+ * Now see if we've hit an intersecting band. The two bands only
+ * intersect if ybot >= ytop
+ */
+ ybot = TQMIN(r1->bottom(), r2->bottom());
+ curBand = newReg->numRects;
+ if (ybot >= ytop)
+ {
+ (* overlapFunc) (newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot);
+
+ }
+
+ if (newReg->numRects != curBand)
+ {
+ prevBand = miCoalesce (newReg, prevBand, curBand);
+ }
+
+ /*
+ * If we've finished with a band (y2 == ybot) we skip forward
+ * in the region to the next band.
+ */
+ if (r1->bottom() == ybot)
+ {
+ r1 = r1BandEnd;
+ }
+ if (r2->bottom() == ybot)
+ {
+ r2 = r2BandEnd;
+ }
+ } while ((r1 != r1End) && (r2 != r2End));
+
+ /*
+ * Deal with whichever region still has rectangles left.
+ */
+ curBand = newReg->numRects;
+ if (r1 != r1End)
+ {
+ if (nonOverlap1Func != (voidProcp)NULL)
+ {
+ do
+ {
+ r1BandEnd = r1;
+ while ((r1BandEnd < r1End) && (r1BandEnd->top() == r1->top()))
+ {
+ r1BandEnd++;
+ }
+ (* nonOverlap1Func) (newReg, r1, r1BandEnd,
+ TQMAX(r1->top(),ybot+1), r1->bottom());
+ r1 = r1BandEnd;
+ } while (r1 != r1End);
+ }
+ }
+ else if ((r2 != r2End) && (nonOverlap2Func != (voidProcp)NULL))
+ {
+ do
+ {
+ r2BandEnd = r2;
+ while ((r2BandEnd < r2End) && (r2BandEnd->top() == r2->top()))
+ {
+ r2BandEnd++;
+ }
+ (* nonOverlap2Func) (newReg, r2, r2BandEnd,
+ TQMAX(r2->top(),ybot+1), r2->bottom());
+ r2 = r2BandEnd;
+ } while (r2 != r2End);
+ }
+
+ if (newReg->numRects != curBand)
+ {
+ (void) miCoalesce (newReg, prevBand, curBand);
+ }
+
+ /*
+ * A bit of cleanup. To keep regions from growing without bound,
+ * we shrink the array of rectangles to match the new number of
+ * rectangles in the region. This never goes to 0, however...
+ *
+ * Only do this stuff if the number of rectangles allocated is more than
+ * twice the number of rectangles in the region (a simple optimization...).
+ */
+ if (newReg->numRects < (int)(newReg->rects.size() >> 1))
+ {
+ if (REGION_NOT_EMPTY(newReg))
+ {
+ newReg->rects.resize(newReg->numRects);
+ }
+ else
+ {
+ /*
+ * No point in doing the extra work involved in an realloc if
+ * the region is empty
+ */
+ newReg->rects.resize(1);
+ }
+ }
+ return;
+}
+
+
+/*======================================================================
+ * Region Union
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * miUnionNonO --
+ * Handle a non-overlapping band for the union operation. Just
+ * Adds the rectangles into the region. Doesn't have to check for
+ * subsumption or anything.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * pReg->numRects is incremented and the final rectangles overwritten
+ * with the rectangles we're passed.
+ *
+ *-----------------------------------------------------------------------
+ */
+/* static void*/
+static
+int
+miUnionNonO (register TQRegionPrivate *pReg, register TQRect * r,
+ TQRect * rEnd, register int y1, register int y2)
+{
+ register TQRect * pNextRect;
+
+ pNextRect = pReg->rects.data() + pReg->numRects;
+
+ TQ_ASSERT(y1 <= y2);
+
+ while (r != rEnd)
+ {
+ TQ_ASSERT(r->left() <= r->right());
+ MEMCHECK(pReg, pNextRect, pReg->rects)
+ qt_setCoords( pNextRect, r->left(), y1, r->right(), y2 );
+ pReg->numRects++;
+ pNextRect++;
+
+ r++;
+ }
+ return 0; /* lint */
+}
+
+
+/*-
+ *-----------------------------------------------------------------------
+ * miUnionO --
+ * Handle an overlapping band for the union operation. Picks the
+ * left-most rectangle each time and merges it into the region.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * Rectangles are overwritten in pReg->rects and pReg->numRects will
+ * be changed.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+/* static void*/
+static
+int
+miUnionO (register TQRegionPrivate *pReg, register TQRect *r1, TQRect *r1End,
+ register TQRect *r2, TQRect *r2End, register int y1, register int y2)
+{
+ register TQRect *pNextRect;
+
+ pNextRect = pReg->rects.data() + pReg->numRects;
+
+#define MERGERECT(r) \
+ if ((pReg->numRects != 0) && \
+ (pNextRect[-1].top() == y1) && \
+ (pNextRect[-1].bottom() == y2) && \
+ (pNextRect[-1].right() >= r->left()-1)) { \
+ if (pNextRect[-1].right() < r->right()) { \
+ pNextRect[-1].setRight( r->right() ); \
+ TQ_ASSERT(pNextRect[-1].left() <= pNextRect[-1].right()); \
+ } \
+ } else { \
+ MEMCHECK(pReg, pNextRect, pReg->rects) \
+ qt_setCoords( pNextRect, r->left(), y1, r->right(), y2 ); \
+ pReg->numRects++; \
+ pNextRect++; \
+ } \
+ r++;
+
+ TQ_ASSERT (y1<=y2);
+ while ((r1 != r1End) && (r2 != r2End)) {
+ if (r1->left() < r2->left()) {
+ MERGERECT(r1)
+ } else {
+ MERGERECT(r2)
+ }
+ }
+
+ if (r1 != r1End)
+ {
+ do
+ {
+ MERGERECT(r1)
+ } while (r1 != r1End);
+ }
+ else while (r2 != r2End)
+ {
+ MERGERECT(r2)
+ }
+ return 0; /* lint */
+}
+
+static void UnionRegion(TQRegionPrivate *reg1, TQRegionPrivate *reg2, TQRegionPrivate *newReg)
+{
+ /* checks all the simple cases */
+
+ /*
+ * Region 1 and 2 are the same or region 1 is empty
+ */
+ if ( (reg1 == reg2) || (!(reg1->numRects)) )
+ {
+ *newReg = *reg2;
+ return;
+ }
+
+ /*
+ * if nothing to union (region 2 empty)
+ */
+ if (!(reg2->numRects))
+ {
+ *newReg = *reg1;
+ return;
+ }
+
+ /*
+ * Region 1 completely subsumes region 2
+ */
+ if ((reg1->numRects == 1) &&
+ (reg1->extents.left() <= reg2->extents.left()) &&
+ (reg1->extents.top() <= reg2->extents.top()) &&
+ (reg1->extents.right() >= reg2->extents.right()) &&
+ (reg1->extents.bottom() >= reg2->extents.bottom()))
+ {
+ *newReg = *reg1;
+ return;
+ }
+
+ /*
+ * Region 2 completely subsumes region 1
+ */
+ if ((reg2->numRects == 1) &&
+ (reg2->extents.left() <= reg1->extents.left()) &&
+ (reg2->extents.top() <= reg1->extents.top()) &&
+ (reg2->extents.right() >= reg1->extents.right()) &&
+ (reg2->extents.bottom() >= reg1->extents.bottom()))
+ {
+ *newReg = *reg2;
+ return;
+ }
+
+ miRegionOp (newReg, reg1, reg2, (voidProcp) miUnionO,
+ (voidProcp) miUnionNonO, (voidProcp) miUnionNonO);
+
+ qt_setCoords( &newReg->extents,
+ TQMIN(reg1->extents.left(), reg2->extents.left()),
+ TQMIN(reg1->extents.top(), reg2->extents.top()),
+ TQMAX(reg1->extents.right(), reg2->extents.right()),
+ TQMAX(reg1->extents.bottom(), reg2->extents.bottom()) );
+
+ return;
+}
+
+/*======================================================================
+ * Region Subtraction
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * miSubtractNonO --
+ * Deal with non-overlapping band for subtraction. Any parts from
+ * region 2 we discard. Anything from region 1 we add to the region.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * pReg may be affected.
+ *
+ *-----------------------------------------------------------------------
+ */
+/* static void*/
+static
+int
+miSubtractNonO1 (register TQRegionPrivate *pReg, register TQRect *r,
+ TQRect *rEnd, register int y1, register int y2)
+{
+ register TQRect *pNextRect;
+
+ pNextRect = pReg->rects.data() + pReg->numRects;
+
+ TQ_ASSERT(y1<=y2);
+
+ while (r != rEnd)
+ {
+ TQ_ASSERT(r->left()<=r->right());
+ MEMCHECK(pReg, pNextRect, pReg->rects)
+ qt_setCoords( pNextRect, r->left(), y1, r->right(), y2 );
+ pReg->numRects++;
+ pNextRect++;
+
+ r++;
+ }
+ return 0; /* lint */
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miSubtractO --
+ * Overlapping band subtraction. x1 is the left-most point not yet
+ * checked.
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * pReg may have rectangles added to it.
+ *
+ *-----------------------------------------------------------------------
+ */
+/* static void*/
+static
+int
+miSubtractO (register TQRegionPrivate *pReg, register TQRect *r1, TQRect *r1End,
+ register TQRect *r2, TQRect *r2End, register int y1, register int y2)
+{
+ register TQRect *pNextRect;
+ register int x1;
+
+ x1 = r1->left();
+
+ TQ_ASSERT(y1<=y2);
+ pNextRect = pReg->rects.data() + pReg->numRects;
+
+ while ((r1 != r1End) && (r2 != r2End))
+ {
+ if (r2->right() < x1)
+ {
+ /*
+ * Subtrahend missed the boat: go to next subtrahend.
+ */
+ r2++;
+ }
+ else if (r2->left() <= x1)
+ {
+ /*
+ * Subtrahend precedes minuend: nuke left edge of minuend.
+ */
+ x1 = r2->right()+1;
+ if (x1 > r1->right())
+ {
+ /*
+ * Minuend completely covered: advance to next minuend and
+ * reset left fence to edge of new minuend.
+ */
+ r1++;
+ if (r1 != r1End)
+ x1 = r1->left();
+ }
+ else
+ {
+ /*
+ * Subtrahend now used up since it doesn't extend beyond
+ * minuend
+ */
+ r2++;
+ }
+ }
+ else if (r2->left() <= r1->right())
+ {
+ /*
+ * Left part of subtrahend covers part of minuend: add uncovered
+ * part of minuend to region and skip to next subtrahend.
+ */
+ TQ_ASSERT(x1<r2->left());
+ MEMCHECK(pReg, pNextRect, pReg->rects)
+ qt_setCoords( pNextRect, x1, y1, r2->left() - 1, y2 );
+ pReg->numRects++;
+ pNextRect++;
+
+ x1 = r2->right() + 1;
+ if (x1 > r1->right())
+ {
+ /*
+ * Minuend used up: advance to new...
+ */
+ r1++;
+ if (r1 != r1End)
+ x1 = r1->left();
+ }
+ else
+ {
+ /*
+ * Subtrahend used up
+ */
+ r2++;
+ }
+ }
+ else
+ {
+ /*
+ * Minuend used up: add any remaining piece before advancing.
+ */
+ if (r1->right() >= x1)
+ {
+ MEMCHECK(pReg, pNextRect, pReg->rects)
+ qt_setCoords( pNextRect, x1, y1, r1->right(), y2 );
+ pReg->numRects++;
+ pNextRect++;
+ }
+ r1++;
+ if ( r1 != r1End )
+ x1 = r1->left();
+ }
+ }
+
+ /*
+ * Add remaining minuend rectangles to region.
+ */
+ while (r1 != r1End)
+ {
+ TQ_ASSERT(x1<=r1->right());
+ MEMCHECK(pReg, pNextRect, pReg->rects)
+ qt_setCoords( pNextRect, x1, y1, r1->right(), y2 );
+ pReg->numRects++;
+ pNextRect++;
+
+ r1++;
+ if (r1 != r1End)
+ {
+ x1 = r1->left();
+ }
+ }
+ return 0; /* lint */
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * miSubtract --
+ * Subtract regS from regM and leave the result in regD.
+ * S stands for subtrahend, M for minuend and D for difference.
+ *
+ * Side Effects:
+ * regD is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+static void SubtractRegion(TQRegionPrivate *regM, TQRegionPrivate *regS, register TQRegionPrivate *regD)
+{
+ /* check for trivial reject */
+ if ( (!(regM->numRects)) || (!(regS->numRects)) ||
+ (!EXTENTCHECK(&regM->extents, &regS->extents)) )
+ {
+ *regD = *regM;
+ return;
+ }
+
+ miRegionOp (regD, regM, regS, (voidProcp) miSubtractO,
+ (voidProcp) miSubtractNonO1, (voidProcp) NULL);
+
+ /*
+ * Can't alter newReg's extents before we call miRegionOp because
+ * it might be one of the source regions and miRegionOp depends
+ * on the extents of those regions being the unaltered. Besides, this
+ * way there's no checking against rectangles that will be nuked
+ * due to coalescing, so we have to examine fewer rectangles.
+ */
+ miSetExtents (regD);
+}
+
+static void XorRegion( TQRegionPrivate *sra, TQRegionPrivate *srb, TQRegionPrivate *dr )
+{
+ TQRegionPrivate tra, trb;
+
+ SubtractRegion(sra,srb,&tra);
+ SubtractRegion(srb,sra,&trb);
+ UnionRegion(&tra,&trb,dr);
+}
+
+/*
+ * Check to see if two regions are equal
+ */
+static bool EqualRegion( TQRegionPrivate *r1, TQRegionPrivate *r2 )
+{
+ int i;
+
+ if( r1->numRects != r2->numRects ) return FALSE;
+ else if( r1->numRects == 0 ) return TRUE;
+ else if ( r1->extents.left() != r2->extents.left() ||
+ r1->extents.right() != r2->extents.right() ||
+ r1->extents.top() != r2->extents.top() ||
+ r1->extents.bottom() != r2->extents.bottom() )
+ return FALSE;
+ else {
+ TQRect *rr1 = r1->rects.data();
+ TQRect *rr2 = r2->rects.data();
+ for( i=0; i < r1->numRects; i++, rr1++, rr2++ ) {
+ if ( rr1->left() != rr2->left() ||
+ rr1->right() != rr2->right() ||
+ rr1->top() != rr2->top() ||
+ rr1->bottom() != rr2->bottom() )
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+static bool PointInRegion( TQRegionPrivate *pRegion, int x, int y )
+{
+ int i;
+
+ if (pRegion->numRects == 0)
+ return FALSE;
+ if (!pRegion->extents.contains(x, y))
+ return FALSE;
+ for (i=0; i<pRegion->numRects; i++)
+ {
+ if (pRegion->rects[i].contains(x, y))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static bool RectInRegion(register TQRegionPrivate *region,
+ int rx, int ry, unsigned int rwidth, unsigned int rheight)
+{
+ register TQRect *pbox;
+ register TQRect *pboxEnd;
+ TQRect rect(rx, ry, rwidth, rheight);
+ register TQRect *prect = &rect;
+ int partIn, partOut;
+
+ /* this is (just) a useful optimization */
+ if ((region->numRects == 0) || !EXTENTCHECK(&region->extents, prect))
+ return(RectangleOut);
+
+ partOut = FALSE;
+ partIn = FALSE;
+
+ /* can stop when both partOut and partIn are TRUE, or we reach prect->y2 */
+ for (pbox = region->rects.data(), pboxEnd = pbox + region->numRects;
+ pbox < pboxEnd;
+ pbox++)
+ {
+
+ if (pbox->bottom() < ry)
+ continue; /* getting up to speed or skipping remainder of band */
+
+ if (pbox->top() > ry)
+ {
+ partOut = TRUE; /* missed part of rectangle above */
+ if (partIn || (pbox->top() > prect->bottom()))
+ break;
+ ry = pbox->top(); /* x guaranteed to be == prect->x1 */
+ }
+
+ if (pbox->right() < rx)
+ continue; /* not far enough over yet */
+
+ if (pbox->left() > rx)
+ {
+ partOut = TRUE; /* missed part of rectangle to left */
+ if (partIn)
+ break;
+ }
+
+ if (pbox->left() <= prect->right())
+ {
+ partIn = TRUE; /* definitely overlap */
+ if (partOut)
+ break;
+ }
+
+ if (pbox->right() >= prect->right())
+ {
+ ry = pbox->bottom() + 1; /* finished with this band */
+ if (ry > prect->bottom())
+ break;
+ rx = prect->left(); /* reset x out to left again */
+ } else
+ {
+ /*
+ * Because boxes in a band are maximal width, if the first box
+ * to overlap the rectangle doesn't completely cover it in that
+ * band, the rectangle must be partially out, since some of it
+ * will be uncovered in that band. partIn will have been set true
+ * by now...
+ */
+ break;
+ }
+
+ }
+
+ return(partIn ? ((ry <= prect->bottom()) ? RectanglePart : RectangleIn) :
+ RectangleOut);
+}
+// END OF Region.c extract
+// START OF poly.h extract
+/* $XConsortium: poly.h,v 1.4 94/04/17 20:22:19 rws Exp $ */
+/************************************************************************
+
+Copyright (c) 1987 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSETQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+
+/*
+ * This file tqcontains a few macros to help track
+ * the edge of a filled object. The object is assumed
+ * to be filled in scanline order, and thus the
+ * algorithm used is an extension of Bresenham's line
+ * drawing algorithm which assumes that y is always the
+ * major axis.
+ * Since these pieces of code are the same for any filled tqshape,
+ * it is more convenient to gather the library in one
+ * place, but since these pieces of code are also in
+ * the inner loops of output primitives, procedure call
+ * overhead is out of the question.
+ * See the author for a derivation if needed.
+ */
+
+
+/*
+ * In scan converting polygons, we want to choose those pixels
+ * which are inside the polygon. Thus, we add .5 to the starting
+ * x coordinate for both left and right edges. Now we choose the
+ * first pixel which is inside the pgon for the left edge and the
+ * first pixel which is outside the pgon for the right edge.
+ * Draw the left pixel, but not the right.
+ *
+ * How to add .5 to the starting x coordinate:
+ * If the edge is moving to the right, then subtract dy from the
+ * error term from the general form of the algorithm.
+ * If the edge is moving to the left, then add dy to the error term.
+ *
+ * The reason for the difference between edges moving to the left
+ * and edges moving to the right is simple: If an edge is moving
+ * to the right, then we want the algorithm to flip immediately.
+ * If it is moving to the left, then we don't want it to flip until
+ * we traverse an entire pixel.
+ */
+#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
+ int dx; /* local storage */ \
+\
+ /* \
+ * if the edge is horizontal, then it is ignored \
+ * and assumed not to be processed. Otherwise, do this stuff. \
+ */ \
+ if ((dy) != 0) { \
+ xStart = (x1); \
+ dx = (x2) - xStart; \
+ if (dx < 0) { \
+ m = dx / (dy); \
+ m1 = m - 1; \
+ incr1 = -2 * dx + 2 * (dy) * m1; \
+ incr2 = -2 * dx + 2 * (dy) * m; \
+ d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
+ } else { \
+ m = dx / (dy); \
+ m1 = m + 1; \
+ incr1 = 2 * dx - 2 * (dy) * m1; \
+ incr2 = 2 * dx - 2 * (dy) * m; \
+ d = -2 * m * (dy) + 2 * dx; \
+ } \
+ } \
+}
+
+#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
+ if (m1 > 0) { \
+ if (d > 0) { \
+ minval += m1; \
+ d += incr1; \
+ } \
+ else { \
+ minval += m; \
+ d += incr2; \
+ } \
+ } else {\
+ if (d >= 0) { \
+ minval += m1; \
+ d += incr1; \
+ } \
+ else { \
+ minval += m; \
+ d += incr2; \
+ } \
+ } \
+}
+
+
+/*
+ * This structure tqcontains all of the information needed
+ * to run the bresenham algorithm.
+ * The variables may be hardcoded into the declarations
+ * instead of using this structure to make use of
+ * register declarations.
+ */
+typedef struct {
+ int minor_axis; /* minor axis */
+ int d; /* decision variable */
+ int m, m1; /* slope and slope+1 */
+ int incr1, incr2; /* error increments */
+} BRESINFO;
+
+
+#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
+ BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d, \
+ bres.m, bres.m1, bres.incr1, bres.incr2)
+
+#define BRESINCRPGONSTRUCT(bres) \
+ BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2)
+
+
+
+/*
+ * These are the data structures needed to scan
+ * convert regions. Two different scan conversion
+ * methods are available -- the even-odd method, and
+ * the winding number method.
+ * The even-odd rule states that a point is inside
+ * the polygon if a ray drawn from that point in any
+ * direction will pass through an odd number of
+ * path segments.
+ * By the winding number rule, a point is decided
+ * to be inside the polygon if a ray drawn from that
+ * point in any direction passes through a different
+ * number of clockwise and counter-clockwise path
+ * segments.
+ *
+ * These data structures are adapted somewhat from
+ * the algorithm in (Foley/Van Dam) for scan converting
+ * polygons.
+ * The basic algorithm is to start at the top (smallest y)
+ * of the polygon, stepping down to the bottom of
+ * the polygon by incrementing the y coordinate. We
+ * keep a list of edges which the current scanline crosses,
+ * sorted by x. This list is called the Active Edge Table (AET)
+ * As we change the y-coordinate, we update each entry in
+ * in the active edge table to reflect the edges new xcoord.
+ * This list must be sorted at each scanline in case
+ * two edges intersect.
+ * We also keep a data structure known as the Edge Table (ET),
+ * which keeps track of all the edges which the current
+ * scanline has not yet reached. The ET is basically a
+ * list of ScanLineList structures containing a list of
+ * edges which are entered at a given scanline. There is one
+ * ScanLineList per scanline at which an edge is entered.
+ * When we enter a new edge, we move it from the ET to the AET.
+ *
+ * From the AET, we can implement the even-odd rule as in
+ * (Foley/Van Dam).
+ * The winding number rule is a little trickier. We also
+ * keep the EdgeTableEntries in the AET linked by the
+ * nextWETE (winding EdgeTableEntry) link. This allows
+ * the edges to be linked just as before for updating
+ * purposes, but only uses the edges linked by the nextWETE
+ * link as edges representing spans of the polygon to
+ * drawn (as with the even-odd rule).
+ */
+
+/*
+ * for the winding number rule
+ */
+#define CLOCKWISE 1
+#define COUNTERCLOCKWISE -1
+
+typedef struct _EdgeTableEntry {
+ int ymax; /* ycoord at which we exit this edge. */
+ BRESINFO bres; /* Bresenham info to run the edge */
+ struct _EdgeTableEntry *next; /* next in the list */
+ struct _EdgeTableEntry *back; /* for insertion sort */
+ struct _EdgeTableEntry *nextWETE; /* for winding num rule */
+ int ClockWise; /* flag for winding number rule */
+} EdgeTableEntry;
+
+
+typedef struct _ScanLineList{
+ int scanline; /* the scanline represented */
+ EdgeTableEntry *edgelist; /* header node */
+ struct _ScanLineList *next; /* next in the list */
+} ScanLineList;
+
+
+typedef struct {
+ int ymax; /* ymax for the polygon */
+ int ymin; /* ymin for the polygon */
+ ScanLineList scanlines; /* header node */
+} EdgeTable;
+
+
+/*
+ * Here is a struct to help with storage allocation
+ * so we can allocate a big chunk at a time, and then take
+ * pieces from this heap when we need to.
+ */
+#define SLLSPERBLOCK 25
+
+typedef struct _ScanLineListBlock {
+ ScanLineList SLLs[SLLSPERBLOCK];
+ struct _ScanLineListBlock *next;
+} ScanLineListBlock;
+
+
+
+/*
+ *
+ * a few macros for the inner loops of the fill code where
+ * performance considerations don't allow a procedure call.
+ *
+ * Evaluate the given edge at the given scanline.
+ * If the edge has expired, then we leave it and fix up
+ * the active edge table; otherwise, we increment the
+ * x value to be ready for the next scanline.
+ * The winding number rule is in effect, so we must notify
+ * the caller when the edge has been removed so he
+ * can reorder the Winding Active Edge Table.
+ */
+#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
+ if (pAET->ymax == y) { /* leaving this edge */ \
+ pPrevAET->next = pAET->next; \
+ pAET = pPrevAET->next; \
+ fixWAET = 1; \
+ if (pAET) \
+ pAET->back = pPrevAET; \
+ } \
+ else { \
+ BRESINCRPGONSTRUCT(pAET->bres) \
+ pPrevAET = pAET; \
+ pAET = pAET->next; \
+ } \
+}
+
+
+/*
+ * Evaluate the given edge at the given scanline.
+ * If the edge has expired, then we leave it and fix up
+ * the active edge table; otherwise, we increment the
+ * x value to be ready for the next scanline.
+ * The even-odd rule is in effect.
+ */
+#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
+ if (pAET->ymax == y) { /* leaving this edge */ \
+ pPrevAET->next = pAET->next; \
+ pAET = pPrevAET->next; \
+ if (pAET) \
+ pAET->back = pPrevAET; \
+ } \
+ else { \
+ BRESINCRPGONSTRUCT(pAET->bres) \
+ pPrevAET = pAET; \
+ pAET = pAET->next; \
+ } \
+}
+// END OF poly.h extract
+// START OF PolyReg.c extract
+/* $XConsortium: PolyReg.c,v 11.23 94/11/17 21:59:37 converse Exp $ */
+/************************************************************************
+
+Copyright (c) 1987 X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSETQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+************************************************************************/
+/* $XFree86: xc/lib/X11/PolyReg.c,v 1.1.1.2.8.2 1998/10/04 15:22:49 hohndel Exp $ */
+
+#define LARGE_COORDINATE 1000000
+#define SMALL_COORDINATE -LARGE_COORDINATE
+
+/*
+ * InsertEdgeInET
+ *
+ * Insert the given edge into the edge table.
+ * First we must tqfind the correct bucket in the
+ * Edge table, then tqfind the right slot in the
+ * bucket. Finally, we can insert it.
+ *
+ */
+static void
+InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE, int scanline,
+ ScanLineListBlock **SLLBlock, int *iSLLBlock)
+{
+ register EdgeTableEntry *start, *prev;
+ register ScanLineList *pSLL, *pPrevSLL;
+ ScanLineListBlock *tmpSLLBlock;
+
+ /*
+ * tqfind the right bucket to put the edge into
+ */
+ pPrevSLL = &ET->scanlines;
+ pSLL = pPrevSLL->next;
+ while (pSLL && (pSLL->scanline < scanline))
+ {
+ pPrevSLL = pSLL;
+ pSLL = pSLL->next;
+ }
+
+ /*
+ * reassign pSLL (pointer to ScanLineList) if necessary
+ */
+ if ((!pSLL) || (pSLL->scanline > scanline))
+ {
+ if (*iSLLBlock > SLLSPERBLOCK-1)
+ {
+ tmpSLLBlock =
+ (ScanLineListBlock *)malloc(sizeof(ScanLineListBlock));
+ (*SLLBlock)->next = tmpSLLBlock;
+ tmpSLLBlock->next = (ScanLineListBlock *)NULL;
+ *SLLBlock = tmpSLLBlock;
+ *iSLLBlock = 0;
+ }
+ pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]);
+
+ pSLL->next = pPrevSLL->next;
+ pSLL->edgelist = (EdgeTableEntry *)NULL;
+ pPrevSLL->next = pSLL;
+ }
+ pSLL->scanline = scanline;
+
+ /*
+ * now insert the edge in the right bucket
+ */
+ prev = (EdgeTableEntry *)NULL;
+ start = pSLL->edgelist;
+ while (start && (start->bres.minor_axis < ETE->bres.minor_axis))
+ {
+ prev = start;
+ start = start->next;
+ }
+ ETE->next = start;
+
+ if (prev)
+ prev->next = ETE;
+ else
+ pSLL->edgelist = ETE;
+}
+
+/*
+ * CreateEdgeTable
+ *
+ * This routine creates the edge table for
+ * scan converting polygons.
+ * The Edge Table (ET) looks like:
+ *
+ * EdgeTable
+ * --------
+ * | ymax | ScanLineLists
+ * |scanline|-->------------>-------------->...
+ * -------- |scanline| |scanline|
+ * |edgelist| |edgelist|
+ * --------- ---------
+ * | |
+ * | |
+ * V V
+ * list of ETEs list of ETEs
+ *
+ * where ETE is an EdgeTableEntry data structure,
+ * and there is one ScanLineList per scanline at
+ * which an edge is initially entered.
+ *
+ */
+
+static void
+CreateETandAET(register int count, register TQPoint *pts,
+ EdgeTable *ET, EdgeTableEntry *AET, register EdgeTableEntry *pETEs,
+ ScanLineListBlock *pSLLBlock)
+{
+ register TQPoint *top, *bottom;
+ register TQPoint *PrevPt, *CurrPt;
+ int iSLLBlock = 0;
+ int dy;
+
+ if (count < 2) return;
+
+ /*
+ * initialize the Active Edge Table
+ */
+ AET->next = (EdgeTableEntry *)NULL;
+ AET->back = (EdgeTableEntry *)NULL;
+ AET->nextWETE = (EdgeTableEntry *)NULL;
+ AET->bres.minor_axis = SMALL_COORDINATE;
+
+ /*
+ * initialize the Edge Table.
+ */
+ ET->scanlines.next = (ScanLineList *)NULL;
+ ET->ymax = SMALL_COORDINATE;
+ ET->ymin = LARGE_COORDINATE;
+ pSLLBlock->next = (ScanLineListBlock *)NULL;
+
+ PrevPt = &pts[count-1];
+
+ /*
+ * for each vertex in the array of points.
+ * In this loop we are dealing with two vertices at
+ * a time -- these make up one edge of the polygon.
+ */
+ while (count--)
+ {
+ CurrPt = pts++;
+
+ /*
+ * tqfind out which point is above and which is below.
+ */
+ if (PrevPt->y() > CurrPt->y() )
+ {
+ bottom = PrevPt, top = CurrPt;
+ pETEs->ClockWise = 0;
+ }
+ else
+ {
+ bottom = CurrPt, top = PrevPt;
+ pETEs->ClockWise = 1;
+ }
+
+ /*
+ * don't add horizontal edges to the Edge table.
+ */
+ if ( bottom->y() != top->y() )
+ {
+ pETEs->ymax = bottom->y()-1; /* -1 so we don't get last scanline */
+
+ /*
+ * initialize integer edge algorithm
+ */
+ dy = bottom->y() - top->y();
+ BRESINITPGONSTRUCT(dy, top->x(), bottom->x(), pETEs->bres)
+
+ InsertEdgeInET(ET, pETEs, top->y(), &pSLLBlock, &iSLLBlock);
+
+ if (PrevPt->y() > ET->ymax)
+ ET->ymax = PrevPt->y();
+ if (PrevPt->y() < ET->ymin)
+ ET->ymin = PrevPt->y();
+ pETEs++;
+ }
+
+ PrevPt = CurrPt;
+ }
+}
+
+/*
+ * loadAET
+ *
+ * This routine moves EdgeTableEntries from the
+ * EdgeTable into the Active Edge Table,
+ * leaving them sorted by smaller x coordinate.
+ *
+ */
+
+static void
+loadAET(register EdgeTableEntry *AET, register EdgeTableEntry *ETEs)
+{
+ register EdgeTableEntry *pPrevAET;
+ register EdgeTableEntry *tmp;
+
+ pPrevAET = AET;
+ AET = AET->next;
+ while (ETEs)
+ {
+ while (AET && (AET->bres.minor_axis < ETEs->bres.minor_axis))
+ {
+ pPrevAET = AET;
+ AET = AET->next;
+ }
+ tmp = ETEs->next;
+ ETEs->next = AET;
+ if (AET)
+ AET->back = ETEs;
+ ETEs->back = pPrevAET;
+ pPrevAET->next = ETEs;
+ pPrevAET = ETEs;
+
+ ETEs = tmp;
+ }
+}
+
+/*
+ * computeWAET
+ *
+ * This routine links the AET by the
+ * nextWETE (winding EdgeTableEntry) link for
+ * use by the winding number rule. The final
+ * Active Edge Table (AET) might look something
+ * like:
+ *
+ * AET
+ * ---------- --------- ---------
+ * |ymax | |ymax | |ymax |
+ * | ... | |... | |... |
+ * |next |->|next |->|next |->...
+ * |nextWETE| |nextWETE| |nextWETE|
+ * --------- --------- ^--------
+ * | | |
+ * V-------------------> V---> ...
+ *
+ */
+static void
+computeWAET(register EdgeTableEntry *AET)
+{
+ register EdgeTableEntry *pWETE;
+ register int inside = 1;
+ register int isInside = 0;
+
+ AET->nextWETE = (EdgeTableEntry *)NULL;
+ pWETE = AET;
+ AET = AET->next;
+ while (AET)
+ {
+ if (AET->ClockWise)
+ isInside++;
+ else
+ isInside--;
+
+ if ((!inside && !isInside) ||
+ ( inside && isInside))
+ {
+ pWETE->nextWETE = AET;
+ pWETE = AET;
+ inside = !inside;
+ }
+ AET = AET->next;
+ }
+ pWETE->nextWETE = (EdgeTableEntry *)NULL;
+}
+
+/*
+ * InsertionSort
+ *
+ * Just a simple insertion sort using
+ * pointers and back pointers to sort the Active
+ * Edge Table.
+ *
+ */
+
+static int
+InsertionSort(register EdgeTableEntry *AET)
+{
+ register EdgeTableEntry *pETEchase;
+ register EdgeTableEntry *pETEinsert;
+ register EdgeTableEntry *pETEchaseBackTMP;
+ register int changed = 0;
+
+ AET = AET->next;
+ while (AET)
+ {
+ pETEinsert = AET;
+ pETEchase = AET;
+ while (pETEchase->back->bres.minor_axis > AET->bres.minor_axis)
+ pETEchase = pETEchase->back;
+
+ AET = AET->next;
+ if (pETEchase != pETEinsert)
+ {
+ pETEchaseBackTMP = pETEchase->back;
+ pETEinsert->back->next = AET;
+ if (AET)
+ AET->back = pETEinsert->back;
+ pETEinsert->next = pETEchase;
+ pETEchase->back->next = pETEinsert;
+ pETEchase->back = pETEinsert;
+ pETEinsert->back = pETEchaseBackTMP;
+ changed = 1;
+ }
+ }
+ return(changed);
+}
+
+/*
+ * Clean up our act.
+ */
+static void
+FreeStorage(register ScanLineListBlock *pSLLBlock)
+{
+ register ScanLineListBlock *tmpSLLBlock;
+
+ while (pSLLBlock)
+ {
+ tmpSLLBlock = pSLLBlock->next;
+ free((char *)pSLLBlock);
+ pSLLBlock = tmpSLLBlock;
+ }
+}
+
+/*
+ * Create an array of rectangles from a list of points.
+ * If indeed these things (POINTS, RECTS) are the same,
+ * then this proc is still needed, because it allocates
+ * storage for the array, which was allocated on the
+ * stack by the calling procedure.
+ *
+ */
+static int PtsToRegion(register int numFullPtBlocks, register int iCurPtBlock,
+ POINTBLOCK *FirstPtBlock, TQRegionPrivate *reg)
+{
+ register TQRect *rects;
+ register TQPoint *pts;
+ register POINTBLOCK *CurPtBlock;
+ register int i;
+ register TQRect *extents;
+ register int numRects;
+
+ extents = &reg->extents;
+
+ numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;
+
+ reg->rects.resize(numRects);
+
+ CurPtBlock = FirstPtBlock;
+ rects = reg->rects.data() - 1;
+ numRects = 0;
+ extents->setLeft( INT_MAX );
+ extents->setRight( INT_MIN );
+
+ for ( ; numFullPtBlocks >= 0; numFullPtBlocks--) {
+ /* the loop uses 2 points per iteration */
+ i = NUMPTSTOBUFFER >> 1;
+ if (!numFullPtBlocks)
+ i = iCurPtBlock >> 1;
+ for (pts = CurPtBlock->pts; i--; pts += 2) {
+ if ( pts->x() == pts[1].x() )
+ continue;
+ if (numRects && pts->x() == rects->left() && pts->y() == rects->bottom() + 1 &&
+ pts[1].x() == rects->right() &&
+ (numRects == 1 || rects[-1].top() != rects->top()) &&
+ (i && pts[2].y() > pts[1].y() )) {
+ rects->setBottom( pts[1].y() );
+ continue;
+ }
+ numRects++;
+ rects++;
+ qt_setCoords( rects, pts->x(), pts->y(), pts[1].x() - 1, pts[1].y() );
+ if (rects->left() < extents->left())
+ extents->setLeft( rects->left() );
+ if (rects->right() > extents->right())
+ extents->setRight( rects->right() );
+ }
+ CurPtBlock = CurPtBlock->next;
+ }
+
+ if (numRects) {
+ extents->setTop( reg->rects[0].top() );
+ extents->setBottom( rects->bottom() );
+ } else {
+ qt_setCoords(extents, 0, 0, 0, 0);
+ }
+ reg->numRects = numRects;
+
+ return(TRUE);
+}
+
+/*
+ * polytoregion
+ *
+ * Scan converts a polygon by returning a run-length
+ * encoding of the resultant bitmap -- the run-length
+ * encoding is in the form of an array of rectangles.
+ */
+static TQRegionPrivate *PolygonRegion(TQPoint *Pts, int Count, int rule)
+ //Point *Pts; /* the pts */
+ //int Count; /* number of pts */
+ //int rule; /* winding rule */
+{
+ TQRegionPrivate *region;
+ register EdgeTableEntry *pAET; /* Active Edge Table */
+ register int y; /* current scanline */
+ register int iPts = 0; /* number of pts in buffer */
+ register EdgeTableEntry *pWETE; /* Winding Edge Table Entry*/
+ register ScanLineList *pSLL; /* current scanLineList */
+ register TQPoint *pts; /* output buffer */
+ EdgeTableEntry *pPrevAET; /* ptr to previous AET */
+ EdgeTable ET; /* header node for ET */
+ EdgeTableEntry AET; /* header node for AET */
+ EdgeTableEntry *pETEs; /* EdgeTableEntries pool */
+ ScanLineListBlock SLLBlock; /* header for scanlinelist */
+ int fixWAET = FALSE;
+ POINTBLOCK FirstPtBlock, *curPtBlock; /* PtBlock buffers */
+ POINTBLOCK *tmpPtBlock;
+ int numFullPtBlocks = 0;
+
+ if ( !(region = new TQRegionPrivate) )
+ return 0;
+
+ /* special case a rectangle */
+ pts = Pts;
+ if (((Count == 4) ||
+ ((Count == 5) && (pts[4].x() == pts[0].x() ) && (pts[4].y() == pts[0].y() ))) &&
+ (((pts[0].y() == pts[1].y()) &&
+ (pts[1].x() == pts[2].x()) &&
+ (pts[2].y() == pts[3].y()) &&
+ (pts[3].x() == pts[0].x())) ||
+ ((pts[0].x() == pts[1].x()) &&
+ (pts[1].y() == pts[2].y()) &&
+ (pts[2].x() == pts[3].x()) &&
+ (pts[3].y() == pts[0].y())))) {
+ region->extents.setLeft( TQMIN(pts[0].x(), pts[2].x()) );
+ region->extents.setTop( TQMIN(pts[0].y(), pts[2].y()) );
+ region->extents.setRight( TQMAX(pts[0].x(), pts[2].x()) );
+ region->extents.setBottom( TQMAX(pts[0].y(), pts[2].y()) );
+ if ((region->extents.left() <= region->extents.right()) &&
+ (region->extents.top() <= region->extents.bottom())) {
+ region->numRects = 1;
+ region->rects.resize(1);
+ region->rects[0] = region->extents;
+ }
+ return region;
+ }
+
+ if (! (pETEs = (EdgeTableEntry *)
+ malloc((unsigned) (sizeof(EdgeTableEntry) * Count))))
+ return 0;
+
+ pts = FirstPtBlock.pts;
+ CreateETandAET(Count, Pts, &ET, &AET, pETEs, &SLLBlock);
+ pSLL = ET.scanlines.next;
+ curPtBlock = &FirstPtBlock;
+
+ if (rule == EvenOddRule) {
+ /*
+ * for each scanline
+ */
+ for (y = ET.ymin; y < ET.ymax; y++) {
+ /*
+ * Add a new edge to the active edge table when we
+ * get to the next edge.
+ */
+ if (pSLL != NULL && y == pSLL->scanline) {
+ loadAET(&AET, pSLL->edgelist);
+ pSLL = pSLL->next;
+ }
+ pPrevAET = &AET;
+ pAET = AET.next;
+
+ /*
+ * for each active edge
+ */
+ while (pAET) {
+ pts->setX( pAET->bres.minor_axis ), pts->setY( y );
+ pts++, iPts++;
+
+ /*
+ * send out the buffer
+ */
+ if (iPts == NUMPTSTOBUFFER) {
+ tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK));
+ curPtBlock->next = tmpPtBlock;
+ curPtBlock = tmpPtBlock;
+ pts = curPtBlock->pts;
+ numFullPtBlocks++;
+ iPts = 0;
+ }
+ EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
+ }
+ (void) InsertionSort(&AET);
+ }
+ }
+ else {
+ /*
+ * for each scanline
+ */
+ for (y = ET.ymin; y < ET.ymax; y++) {
+ /*
+ * Add a new edge to the active edge table when we
+ * get to the next edge.
+ */
+ if (pSLL != NULL && y == pSLL->scanline) {
+ loadAET(&AET, pSLL->edgelist);
+ computeWAET(&AET);
+ pSLL = pSLL->next;
+ }
+ pPrevAET = &AET;
+ pAET = AET.next;
+ pWETE = pAET;
+
+ /*
+ * for each active edge
+ */
+ while (pAET) {
+ /*
+ * add to the buffer only those edges that
+ * are in the Winding active edge table.
+ */
+ if (pWETE == pAET) {
+ pts->setX( pAET->bres.minor_axis), pts->setY( y );
+ pts++, iPts++;
+
+ /*
+ * send out the buffer
+ */
+ if (iPts == NUMPTSTOBUFFER) {
+ tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK));
+ curPtBlock->next = tmpPtBlock;
+ curPtBlock = tmpPtBlock;
+ pts = curPtBlock->pts;
+ numFullPtBlocks++; iPts = 0;
+ }
+ pWETE = pWETE->nextWETE;
+ }
+ EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET)
+ }
+
+ /*
+ * recompute the winding active edge table if
+ * we just resorted or have exited an edge.
+ */
+ if (InsertionSort(&AET) || fixWAET) {
+ computeWAET(&AET);
+ fixWAET = FALSE;
+ }
+ }
+ }
+ FreeStorage(SLLBlock.next);
+ (void) PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region);
+ for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) {
+ tmpPtBlock = curPtBlock->next;
+ free((char *)curPtBlock);
+ curPtBlock = tmpPtBlock;
+ }
+ free((char *)pETEs);
+ return region;
+}
+// END OF PolyReg.c extract
+
+TQRegionPrivate *qt_bitmapToRegion(const TQBitmap& bitmap)
+{
+ TQImage image = bitmap.convertToImage();
+
+ TQRegionPrivate *region = new TQRegionPrivate;
+ TQRect xr;
+
+#define AddSpan \
+ { \
+ qt_setCoords( &xr, prev1, y, x-1, y ); \
+ UnionRectWithRegion( &xr, region, region ); \
+ }
+
+ const int zero=0;
+ bool little = image.bitOrder() == TQImage::LittleEndian;
+
+ int x, y;
+ for (y=0; y<image.height(); y++) {
+ uchar *line = image.scanLine(y);
+ int w = image.width();
+ uchar all=zero;
+ int prev1 = -1;
+ for (x=0; x<w; ) {
+ uchar byte = line[x/8];
+ if ( x>w-8 || byte!=all ) {
+ if ( little ) {
+ for ( int b=8; b>0 && x<w; b-- ) {
+ if ( !(byte&0x01) == !all ) {
+ // More of the same
+ } else {
+ // A change.
+ if ( all!=zero ) {
+ AddSpan
+ all = zero;
+ } else {
+ prev1 = x;
+ all = ~zero;
+ }
+ }
+ byte >>= 1;
+ x++;
+ }
+ } else {
+ for ( int b=8; b>0 && x<w; b-- ) {
+ if ( !(byte&0x80) == !all ) {
+ // More of the same
+ } else {
+ // A change.
+ if ( all!=zero ) {
+ AddSpan
+ all = zero;
+ } else {
+ prev1 = x;
+ all = ~zero;
+ }
+ }
+ byte <<= 1;
+ x++;
+ }
+ }
+ } else {
+ x+=8;
+ }
+ }
+ if ( all != zero ) {
+ AddSpan
+ }
+ }
+
+ return region;
+}
+
+// NOT REVISED
+
+static TQRegion *empty_region = 0;
+
+static void cleanup_empty_region()
+{
+ delete empty_region;
+ empty_region = 0;
+}
+
+
+/*!
+ Constructs a null region.
+
+ \sa isNull()
+*/
+
+TQRegion::TQRegion()
+{
+ if ( !empty_region ) { // avoid too many allocs
+ qAddPostRoutine( cleanup_empty_region );
+ empty_region = new TQRegion( TRUE );
+ TQ_CHECK_PTR( empty_region );
+ }
+ data = empty_region->data;
+ data->ref();
+}
+
+/*! \internal
+ Internal constructor that creates a null region.
+*/
+
+TQRegion::TQRegion( bool is_null )
+{
+ data = new TQRegionData;
+ TQ_CHECK_PTR( data );
+ data->region = new TQRegionPrivate;
+ data->is_null = is_null;
+ data->rgn = 0;
+ data->xrectangles = 0;
+}
+
+/*!
+ \overload
+
+ Create a region based on the rectange \a r with region type \a t.
+
+ If the rectangle is invalid a null region will be created.
+
+ \sa TQRegion::RegionType
+*/
+
+TQRegion::TQRegion( const TQRect &r, RegionType t )
+{
+ if ( r.isEmpty() ) {
+ if ( !empty_region ) { // avoid too many allocs
+ qAddPostRoutine( cleanup_empty_region );
+ empty_region = new TQRegion( TRUE );
+ TQ_CHECK_PTR( empty_region );
+ }
+ data = empty_region->data;
+ data->ref();
+ } else {
+ data = new TQRegionData;
+ TQ_CHECK_PTR( data );
+ data->is_null = FALSE;
+ data->rgn = 0;
+ data->xrectangles = 0;
+ if ( t == Rectangle ) { // rectangular region
+ data->region = new TQRegionPrivate( r );
+ } else if ( t == Ellipse ) { // elliptic region
+ TQPointArray a;
+ a.makeEllipse( r.x(), r.y(), r.width(), r.height() );
+ data->region = PolygonRegion( (TQPoint*)a.data(), a.size(),
+ EvenOddRule );
+ }
+ }
+}
+
+
+/*!
+ Constructs a polygon region from the point array \a a.
+
+ If \a winding is TRUE, the polygon region is filled using the
+ winding algorithm, otherwise the default even-odd fill algorithm
+ is used.
+
+ This constructor may create complex regions that will slow down
+ painting when used.
+*/
+
+TQRegion::TQRegion( const TQPointArray &a, bool winding )
+{
+ if (a.size() > 2) {
+ data = new TQRegionData;
+ TQ_CHECK_PTR( data );
+ data->is_null = FALSE;
+ data->rgn = 0;
+ data->xrectangles = 0;
+ data->region = PolygonRegion( (TQPoint*)a.data(), a.size(),
+ winding ? WindingRule : EvenOddRule );
+ } else {
+ if ( !empty_region ) {
+ qAddPostRoutine( cleanup_empty_region );
+ empty_region = new TQRegion( TRUE );
+ TQ_CHECK_PTR( empty_region );
+ }
+ data = empty_region->data;
+ data->ref();
+ }
+}
+
+
+/*!
+ Constructs a new region which is equal to region \a r.
+*/
+
+TQRegion::TQRegion( const TQRegion &r )
+{
+ data = r.data;
+ data->ref();
+}
+
+
+/*!
+ Constructs a region from the bitmap \a bm.
+
+ The resulting region consists of the pixels in bitmap \a bm that
+ are \c color1, as if each pixel was a 1 by 1 rectangle.
+
+ This constructor may create complex regions that will slow down
+ painting when used. Note that drawing masked pixmaps can be done
+ much faster using TQPixmap::setMask().
+*/
+TQRegion::TQRegion( const TQBitmap & bm )
+{
+ if ( bm.isNull() ) {
+ if ( !empty_region ) { // avoid too many allocs
+ qAddPostRoutine( cleanup_empty_region );
+ empty_region = new TQRegion( TRUE );
+ TQ_CHECK_PTR( empty_region );
+ }
+ data = empty_region->data;
+ data->ref();
+ } else {
+ data = new TQRegionData;
+ TQ_CHECK_PTR( data );
+ data->is_null = FALSE;
+ data->rgn = 0;
+ data->xrectangles = 0;
+ data->region = qt_bitmapToRegion(bm);
+ }
+}
+
+/*!
+ Destroys the region.
+*/
+
+TQRegion::~TQRegion()
+{
+ if ( data->deref() ) {
+ delete data->region;
+ if ( data->rgn )
+ XDestroyRegion( data->rgn );
+ if ( data->xrectangles )
+ free( data->xrectangles );
+ delete data;
+ }
+}
+
+
+/*!
+ Assigns \a r to this region and returns a reference to the region.
+*/
+
+TQRegion &TQRegion::operator=( const TQRegion &r )
+{
+ r.data->ref(); // beware of r = r
+ if ( data->deref() ) {
+ delete data->region;
+ if ( data->rgn )
+ XDestroyRegion( data->rgn );
+ if ( data->xrectangles )
+ free( data->xrectangles );
+ delete data;
+ }
+ data = r.data;
+ return *this;
+}
+
+
+/*!
+ Returns a \link shclass.html deep copy\endlink of the region.
+
+ \sa detach()
+*/
+
+TQRegion TQRegion::copy() const
+{
+ TQRegion r( data->is_null );
+ *r.data->region = *data->region;
+ return r;
+}
+
+/*!
+ Returns TRUE if the region is a null region; otherwise returns
+ FALSE.
+
+ A null region is a region that has not been initialized. A null
+ region is always empty.
+
+ \sa isEmpty()
+*/
+
+bool TQRegion::isNull() const
+{
+ return data->is_null;
+}
+
+
+/*!
+ Returns TRUE if the region is empty; otherwise returns FALSE. An
+ empty region is a region that tqcontains no points.
+
+ Example:
+ \code
+ TQRegion r1( 10, 10, 20, 20 );
+ TQRegion r2( 40, 40, 20, 20 );
+ TQRegion r3;
+ r1.isNull(); // FALSE
+ r1.isEmpty(); // FALSE
+ r3.isNull(); // TRUE
+ r3.isEmpty(); // TRUE
+ r3 = r1.intersect( r2 ); // r3 = intersection of r1 and r2
+ r3.isNull(); // FALSE
+ r3.isEmpty(); // TRUE
+ r3 = r1.unite( r2 ); // r3 = union of r1 and r2
+ r3.isNull(); // FALSE
+ r3.isEmpty(); // FALSE
+ \endcode
+
+ \sa isNull()
+*/
+
+bool TQRegion::isEmpty() const
+{
+ return data->is_null || ( data->region->numRects == 0 );
+}
+
+
+/*!
+ Returns TRUE if the region tqcontains the point \a p; otherwise
+ returns FALSE.
+*/
+
+bool TQRegion::tqcontains( const TQPoint &p ) const
+{
+ return PointInRegion( data->region, p.x(), p.y() );
+}
+
+/*!
+ \overload
+
+ Returns TRUE if the region overlaps the rectangle \a r; otherwise
+ returns FALSE.
+*/
+
+bool TQRegion::tqcontains( const TQRect &r ) const
+{
+ return RectInRegion( data->region, r.left(), r.top(),
+ r.width(), r.height() ) != RectangleOut;
+}
+
+
+/*!
+ Translates (moves) the region \a dx along the X axis and \a dy
+ along the Y axis.
+*/
+
+void TQRegion::translate( int dx, int dy )
+{
+ if ( empty_region && data == empty_region->data )
+ return;
+ detach();
+ OffsetRegion( data->region, dx, dy );
+ if ( data->xrectangles ) {
+ free( data->xrectangles );
+ data->xrectangles = 0;
+ }
+}
+
+
+/*!
+ Returns a region which is the union of this region and \a r.
+
+ \img runion.png Region Union
+
+ The figure shows the union of two elliptical regions.
+*/
+
+TQRegion TQRegion::unite( const TQRegion &r ) const
+{
+ TQRegion result( FALSE );
+ UnionRegion( data->region, r.data->region, result.data->region );
+ return result;
+}
+
+/*!
+ Returns a region which is the intersection of this region and \a r.
+
+ \img rintersect.png Region Intersection
+
+ The figure shows the intersection of two elliptical regions.
+*/
+
+TQRegion TQRegion::intersect( const TQRegion &r ) const
+{
+ TQRegion result( FALSE );
+ IntersectRegion( data->region, r.data->region, result.data->region );
+ return result;
+}
+
+/*!
+ Returns a region which is \a r subtracted from this region.
+
+ \img rsubtract.png Region Subtraction
+
+ The figure shows the result when the ellipse on the right is
+ subtracted from the ellipse on the left. (\c left-right )
+*/
+
+TQRegion TQRegion::subtract( const TQRegion &r ) const
+{
+ TQRegion result( FALSE );
+ SubtractRegion( data->region, r.data->region, result.data->region );
+ return result;
+}
+
+/*!
+ Returns a region which is the exclusive or (XOR) of this region
+ and \a r.
+
+ \img rxor.png Region XORed
+
+ The figure shows the exclusive or of two elliptical regions.
+*/
+
+TQRegion TQRegion::eor( const TQRegion &r ) const
+{
+ TQRegion result( FALSE );
+ XorRegion( data->region, r.data->region, result.data->region );
+ return result;
+}
+
+/*!
+ Returns the bounding rectangle of this region. An empty region
+ gives a rectangle that is TQRect::isNull().
+*/
+
+TQRect TQRegion::boundingRect() const
+{
+ return data->region->extents;
+}
+
+
+/*!
+ Returns an array of non-overlapping rectangles that make up the
+ region.
+
+ The union of all the rectangles is equal to the original region.
+*/
+
+TQMemArray<TQRect> TQRegion::rects() const
+{
+ TQMemArray<TQRect> rects;
+ rects.duplicate( data->region->rects, data->region->numRects );
+ return rects;
+}
+
+/*!
+ Sets the region to be the given set of rectangles. The rectangles
+ \e must be optimal Y-X sorted bands as follows:
+ <ul>
+ <li> The rectangles must not intersect
+ <li> All rectangles with a given top coordinate must have the same height.
+ <li> No two rectangles may abut horizontally (they should be combined
+ into a single wider rectangle in that case).
+ <li> The rectangles must be sorted ascendingly by Y as the major sort key
+ and X as the minor sort key.
+ </ul>
+ \internal
+ Only some platforms have that restriction (TQWS and X11).
+*/
+void TQRegion::setRects( const TQRect *rects, int num )
+{
+ *this = TQRegion( FALSE );
+ if ( !rects || (num == 1 && rects->isEmpty()) )
+ num = 0;
+
+ data->region->rects.duplicate( rects, num );
+ data->region->numRects = num;
+ if ( num == 0 ) {
+ data->region->extents = TQRect();
+ } else {
+ int left = INT_MAX, right = INT_MIN, top = INT_MAX, bottom = INT_MIN;
+ int i;
+ for ( i = 0; i < num; i++ ) {
+ left = TQMIN( rects[i].left(), left );
+ right = TQMAX( rects[i].right(), right );
+ top = TQMIN( rects[i].top(), top );
+ bottom = TQMAX( rects[i].bottom(), bottom );
+ }
+ data->region->extents = TQRect( TQPoint(left, top), TQPoint(right, bottom) );
+ }
+}
+
+/*!
+ Returns TRUE if the region is equal to \a r; otherwise returns
+ FALSE.
+*/
+
+bool TQRegion::operator==( const TQRegion &r ) const
+{
+ return data == r.data ?
+ TRUE : EqualRegion( data->region, r.data->region );
+}
+
+/*!
+ \fn bool TQRegion::operator!=( const TQRegion &r ) const
+
+ Returns TRUE if the region is different from \a r; otherwise
+ returns FALSE.
+*/
+
+/*
+ This is how X represents regions internally.
+*/
+
+struct BOX {
+ short x1, x2, y1, y2;
+};
+
+struct _XRegion {
+ long size;
+ long numRects;
+ BOX *rects;
+ BOX extents;
+};
+
+
+void TQRegion::updateX11Region() const
+{
+ data->rgn = XCreateRegion();
+
+ for( int i = 0; i < data->region->numRects; i++ ) {
+ XRectangle r;
+ const TQRect &rect = data->region->rects[i];
+ r.x = TQMAX( SHRT_MIN, rect.x() );
+ r.y = TQMAX( SHRT_MIN, rect.y() );
+ r.width = TQMIN( USHRT_MAX, rect.width() );
+ r.height = TQMIN( USHRT_MAX, rect.height() );
+ XUnionRectWithRegion( &r, data->rgn, data->rgn );
+ }
+}
+
+
+void *TQRegion::clipRectangles( int &num ) const
+{
+ if ( !data->xrectangles ) {
+ XRectangle *r = (XRectangle *) malloc( data->region->numRects * sizeof( XRectangle ) );
+ data->xrectangles = r;
+ for( int i = 0; i < data->region->numRects; i++ ) {
+ const TQRect &rect = data->region->rects[i];
+ r->x = TQMAX( SHRT_MIN, rect.x() );
+ r->y = TQMAX( SHRT_MIN, rect.y() );
+ r->width = TQMIN( USHRT_MAX, rect.width() );
+ r->height = TQMIN( USHRT_MAX, rect.height() );
+ r++;
+ }
+ }
+ num = data->region->numRects;
+ return data->xrectangles;
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqrichtext.cpp b/tqtinterface/qt4/src/kernel/tqrichtext.cpp
new file mode 100644
index 0000000..8b614d6
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqrichtext.cpp
@@ -0,0 +1,16615 @@
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+// #if 0
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqrichtext_p.h"
+
+#ifndef QT_NO_RICHTEXT
+
+#include "Qt/qbitmap.h"
+#include "Qt/qapplication.h"
+#include "tqcleanuphandler.h"
+#include "Qt/qcursor.h"
+#include "Qt/qdatastream.h"
+#include "tqdragobject.h"
+#include "Qt/qdrawutil.h"
+#include "Qt/qfile.h"
+#include "Qt/qfileinfo.h"
+#include "Qt/qfont.h"
+#include "Qt/qimage.h"
+#include "Qt/qmap.h"
+#include "Qt/qmime.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqpainter.h"
+#include "tqstringlist.h"
+#include "Qt/qstyle.h"
+#include "Qt/qstyleoption.h"
+#include "tqstylesheet.h"
+#include "Qt/qtextstream.h"
+#include "private/qt4_qtextengine_p.h"
+// #include <private/qunicodetables_p.h>
+
+#include <stdlib.h>
+
+#if defined(Q_WS_X11)
+// #include "qx11info_x11.h"
+#endif
+
+QT_BEGIN_NAMESPACE
+
+static TQTextCursor* richTextExportStart = 0;
+static TQTextCursor* richTextExportEnd = 0;
+
+class TQTextFormatCollection;
+
+const int border_tolerance = 2;
+
+#ifdef Q_WS_WIN
+QT_BEGIN_INCLUDE_NAMESPACE
+#include "qt_windows.h"
+QT_END_INCLUDE_NAMESPACE
+#endif
+
+static inline bool is_printer(TQPainter *p)
+{
+ if (!p || !p->device())
+ return false;
+ return p->device()->devType() == QInternal::Printer;
+}
+
+static inline int scale(int value, TQPainter *painter)
+{
+ if (is_printer(painter)) {
+ TQPaintDeviceMetrics metrics(painter->device());
+#if defined(Q_WS_X11)
+ value = value * metrics.logicalDpiY() /
+ QX11Info::appDpiY(painter->tqdevice()->x11Screen());
+#elif defined (Q_WS_WIN)
+ HDC hdc = GetDC(0);
+ int gdc = GetDeviceCaps(hdc, LOGPIXELSY);
+ if (gdc)
+ value = value * metrics.logicalDpiY() / gdc;
+ ReleaseDC(0, hdc);
+#elif defined (Q_WS_MAC)
+ value = value * metrics.logicalDpiY() / 75; // ##### FIXME
+#elif defined (Q_WS_QWS)
+ value = value * metrics.logicalDpiY() / 75;
+#endif
+ }
+ return value;
+}
+
+
+static inline bool isBreakable(TQTextString *string, int pos)
+{
+ if (string->at(pos).nobreak)
+ return false;
+ return (pos < string->length()-1 && string->at(pos+1).softBreak);
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+void TQTextCommandHistory::addCommand(TQTextCommand *cmd)
+{
+ if (current < history.count() - 1) {
+ QList<TQTextCommand *> commands;
+
+ for (int i = 0; i <= current; ++i)
+ commands.insert(i, history.takeFirst());
+
+ commands.append(cmd);
+ while (!history.isEmpty())
+ delete history.takeFirst();
+ history = commands;
+ } else {
+ history.append(cmd);
+ }
+
+ if (history.count() > steps)
+ delete history.takeFirst();
+ else
+ ++current;
+}
+
+TQTextCursor *TQTextCommandHistory::undo(TQTextCursor *c)
+{
+ if (current > -1) {
+ TQTextCursor *c2 = history.at(current)->unexecute(c);
+ --current;
+ return c2;
+ }
+ return 0;
+}
+
+TQTextCursor *TQTextCommandHistory::redo(TQTextCursor *c)
+{
+ if (current > -1) {
+ if (current < history.count() - 1) {
+ ++current;
+ return history.at(current)->execute(c);
+ }
+ } else {
+ if (history.count() > 0) {
+ ++current;
+ return history.at(current)->execute(c);
+ }
+ }
+ return 0;
+}
+
+bool TQTextCommandHistory::isUndoAvailable()
+{
+ return current > -1;
+}
+
+bool TQTextCommandHistory::isRedoAvailable()
+{
+ return (current > -1 && current < history.count() - 1) || (current == -1 && history.count() > 0);
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextDeleteCommand::TQTextDeleteCommand(TQTextDocument *dc, int i, int idx, const QVector<TQTextStringChar> &str,
+ const QByteArray& oldStyleInfo)
+ : TQTextCommand(dc), id(i), index(idx), parag(0), text(str), styleInformation(oldStyleInfo)
+{
+ for (int j = 0; j < (int)text.size(); ++j) {
+ if (text[j].format())
+ text[j].format()->addRef();
+ }
+}
+
+TQTextDeleteCommand::TQTextDeleteCommand(TQTextParagraph *p, int idx, const QVector<TQTextStringChar> &str)
+ : TQTextCommand(0), id(-1), index(idx), parag(p), text(str)
+{
+ for (int i = 0; i < (int)text.size(); ++i) {
+ if (text[i].format())
+ text[i].format()->addRef();
+ }
+}
+
+TQTextDeleteCommand::~TQTextDeleteCommand()
+{
+ for (int i = 0; i < (int)text.size(); ++i) {
+ if (text[i].format())
+ text[i].format()->removeRef();
+ }
+ text.resize(0);
+}
+
+TQTextCursor *TQTextDeleteCommand::execute(TQTextCursor *c)
+{
+ TQTextParagraph *s = doc ? doc->paragAt(id) : parag;
+ if (!s) {
+ qWarning("can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId());
+ return 0;
+ }
+
+ cursor.setParagraph(s);
+ cursor.setIndex(index);
+ int len = text.size();
+ if (c)
+ *c = cursor;
+ if (doc) {
+ doc->setSelectionStart(TQTextDocument::Temp, cursor);
+ for (int i = 0; i < len; ++i)
+ cursor.gotoNextLetter();
+ doc->setSelectionEnd(TQTextDocument::Temp, cursor);
+ doc->removeSelectedText(TQTextDocument::Temp, &cursor);
+ if (c)
+ *c = cursor;
+ } else {
+ s->remove(index, len);
+ }
+
+ return c;
+}
+
+TQTextCursor *TQTextDeleteCommand::unexecute(TQTextCursor *c)
+{
+ TQTextParagraph *s = doc ? doc->paragAt(id) : parag;
+ if (!s) {
+ qWarning("can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId());
+ return 0;
+ }
+
+ cursor.setParagraph(s);
+ cursor.setIndex(index);
+ TQString str = TQTextString::toString(text);
+ cursor.insert(str, true, &text);
+ if (c)
+ *c = cursor;
+ cursor.setParagraph(s);
+ cursor.setIndex(index);
+
+#ifndef QT_NO_DATASTREAM
+ if (!styleInformation.isEmpty()) {
+ QDataStream styleStream(&styleInformation, IO_ReadOnly);
+ int num;
+ styleStream >> num;
+ TQTextParagraph *p = s;
+ while (num-- && p) {
+ p->readStyleInformation(styleStream);
+ p = p->next();
+ }
+ }
+#endif
+ s = cursor.paragraph();
+ while (s) {
+ s->format();
+ s->setChanged(true);
+ if (s == c->paragraph())
+ break;
+ s = s->next();
+ }
+
+ return &cursor;
+}
+
+TQTextFormatCommand::TQTextFormatCommand(TQTextDocument *dc, int sid, int sidx, int eid, int eidx,
+ const QVector<TQTextStringChar> &old, TQTextFormat *f, int fl)
+ : TQTextCommand(dc), startId(sid), startIndex(sidx), endId(eid), endIndex(eidx), format(f), oldFormats(old), flags(fl)
+{
+ format = dc->formatCollection()->format(f);
+ for (int j = 0; j < (int)oldFormats.size(); ++j) {
+ if (oldFormats[j].format())
+ oldFormats[j].format()->addRef();
+ }
+}
+
+TQTextFormatCommand::~TQTextFormatCommand()
+{
+ format->removeRef();
+ for (int j = 0; j < (int)oldFormats.size(); ++j) {
+ if (oldFormats[j].format())
+ oldFormats[j].format()->removeRef();
+ }
+}
+
+TQTextCursor *TQTextFormatCommand::execute(TQTextCursor *c)
+{
+ TQTextParagraph *sp = doc->paragAt(startId);
+ TQTextParagraph *ep = doc->paragAt(endId);
+ if (!sp || !ep)
+ return c;
+
+ TQTextCursor start(doc);
+ start.setParagraph(sp);
+ start.setIndex(startIndex);
+ TQTextCursor end(doc);
+ end.setParagraph(ep);
+ end.setIndex(endIndex);
+
+ doc->setSelectionStart(TQTextDocument::Temp, start);
+ doc->setSelectionEnd(TQTextDocument::Temp, end);
+ doc->setFormat(TQTextDocument::Temp, format, flags);
+ doc->removeSelection(TQTextDocument::Temp);
+ if (endIndex == ep->length())
+ end.gotoLeft();
+ *c = end;
+ return c;
+}
+
+TQTextCursor *TQTextFormatCommand::unexecute(TQTextCursor *c)
+{
+ TQTextParagraph *sp = doc->paragAt(startId);
+ TQTextParagraph *ep = doc->paragAt(endId);
+ if (!sp || !ep)
+ return 0;
+
+ int idx = startIndex;
+ int fIndex = 0;
+ while ( fIndex < int(oldFormats.size()) ) {
+ if (oldFormats.at(fIndex).c == TQLatin1Char('\n')) {
+ if (idx > 0) {
+ if (idx < sp->length() && fIndex > 0)
+ sp->setFormat(idx, 1, oldFormats.at(fIndex - 1).format());
+ if (sp == ep)
+ break;
+ sp = sp->next();
+ idx = 0;
+ }
+ fIndex++;
+ }
+ if (oldFormats.at(fIndex).format())
+ sp->setFormat(idx, 1, oldFormats.at(fIndex).format());
+ idx++;
+ fIndex++;
+ if (fIndex >= (int)oldFormats.size())
+ break;
+ if (idx >= sp->length()) {
+ if (sp == ep)
+ break;
+ sp = sp->next();
+ idx = 0;
+ }
+ }
+
+ TQTextCursor end(doc);
+ end.setParagraph(ep);
+ end.setIndex(endIndex);
+ if (endIndex == ep->length())
+ end.gotoLeft();
+ *c = end;
+ return c;
+}
+
+TQTextStyleCommand::TQTextStyleCommand(TQTextDocument *dc, int fParag, int lParag, const QByteArray& beforeChange)
+ : TQTextCommand(dc), firstParag(fParag), lastParag(lParag), before(beforeChange)
+{
+ after = readStyleInformation( dc, fParag, lParag);
+}
+
+
+QByteArray TQTextStyleCommand::readStyleInformation( TQTextDocument* doc, int fParag, int lParag)
+{
+ QByteArray style;
+#ifndef QT_NO_DATASTREAM
+ TQTextParagraph *p = doc->paragAt(fParag);
+ if (!p)
+ return style;
+ QDataStream styleStream(&style, IO_WriteOnly);
+ int num = lParag - fParag + 1;
+ styleStream << num;
+ while (num -- && p) {
+ p->writeStyleInformation(styleStream);
+ p = p->next();
+ }
+#endif
+ return style;
+}
+
+void TQTextStyleCommand::writeStyleInformation( TQTextDocument* doc, int fParag, const QByteArray& style)
+{
+#ifndef QT_NO_DATASTREAM
+ TQTextParagraph *p = doc->paragAt(fParag);
+ if (!p)
+ return;
+ QByteArray copy = style;
+ QDataStream styleStream(&copy, IO_ReadOnly);
+ int num;
+ styleStream >> num;
+ while (num-- && p) {
+ p->readStyleInformation(styleStream);
+ p = p->next();
+ }
+#endif
+}
+
+TQTextCursor *TQTextStyleCommand::execute(TQTextCursor *c)
+{
+ writeStyleInformation(doc, firstParag, after);
+ return c;
+}
+
+TQTextCursor *TQTextStyleCommand::unexecute(TQTextCursor *c)
+{
+ writeStyleInformation(doc, firstParag, before);
+ return c;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextCursor::TQTextCursor(TQTextDocument *dc)
+ : idx(0), tmpX(-1), ox(0), oy(0),
+ valid(true)
+{
+ para = dc ? dc->firstParagraph() : 0;
+}
+
+TQTextCursor::TQTextCursor(const TQTextCursor &c)
+{
+ ox = c.ox;
+ oy = c.oy;
+ idx = c.idx;
+ para = c.para;
+ tmpX = c.tmpX;
+ indices = c.indices;
+ paras = c.paras;
+ xOffsets = c.xOffsets;
+ yOffsets = c.yOffsets;
+ valid = c.valid;
+}
+
+TQTextCursor::~TQTextCursor()
+{
+}
+
+TQTextCursor &TQTextCursor::operator=(const TQTextCursor &c)
+{
+ ox = c.ox;
+ oy = c.oy;
+ idx = c.idx;
+ para = c.para;
+ tmpX = c.tmpX;
+ indices = c.indices;
+ paras = c.paras;
+ xOffsets = c.xOffsets;
+ yOffsets = c.yOffsets;
+ valid = c.valid;
+
+ return *this;
+}
+
+bool TQTextCursor::operator==(const TQTextCursor &c) const
+{
+ return para == c.para && idx == c.idx;
+}
+
+int TQTextCursor::totalOffsetX() const
+{
+ int xoff = ox;
+ for (QStack<int>::ConstIterator xit = xOffsets.begin(); xit != xOffsets.end(); ++xit)
+ xoff += *xit;
+ return xoff;
+}
+
+int TQTextCursor::totalOffsetY() const
+{
+ int yoff = oy;
+ for (QStack<int>::ConstIterator yit = yOffsets.begin(); yit != yOffsets.end(); ++yit)
+ yoff += *yit;
+ return yoff;
+}
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+void TQTextCursor::gotoIntoNested(const QPoint &globalPos)
+{
+ if (!para)
+ return;
+ Q_ASSERT(para->at(idx)->isCustom());
+ push();
+ ox = 0;
+ int bl, y;
+ para->lineHeightOfChar(idx, &bl, &y);
+ oy = y + para->rect().y();
+ ox = para->at(idx)->x;
+ TQTextDocument* doc = document();
+ para->at(idx)->customItem()->enterAt(this, doc, para, idx, ox, oy, globalPos-QPoint(ox,oy));
+}
+#endif
+
+void TQTextCursor::invalidateNested()
+{
+ if (nestedDepth()) {
+ QStack<TQTextParagraph*>::Iterator it = paras.begin();
+ QStack<int>::Iterator it2 = indices.begin();
+ for (; it != paras.end(); ++it, ++it2) {
+ if (*it == para)
+ continue;
+ (*it)->invalidate(0);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if ((*it)->at(*it2)->isCustom())
+ (*it)->at(*it2)->customItem()->invalidate();
+#endif
+ }
+ }
+}
+
+void TQTextCursor::insert(const QString &str, bool checkNewLine, QVector<TQTextStringChar> *formatting)
+{
+ tmpX = -1;
+ bool justInsert = true;
+ TQString s(str);
+#if defined(Q_WS_WIN)
+ if (checkNewLine) {
+ int i = 0;
+ while ((i = s.indexOf(TQLatin1Char('\r'), i)) != -1)
+ s.remove(i ,1);
+ }
+#endif
+ if (checkNewLine)
+ justInsert = s.indexOf(TQLatin1Char('\n')) == -1;
+ if (justInsert) { // we ignore new lines and insert all in the current para at the current index
+ para->insert(idx, s.unicode(), s.length());
+ if (formatting) {
+ for (int i = 0; i < (int)s.length(); ++i) {
+ if (formatting->at(i).format()) {
+ formatting->at(i).format()->addRef();
+ para->string()->setFormat(idx + i, formatting->at(i).format(), true);
+ }
+ }
+ }
+ idx += s.length();
+ } else { // we split at new lines
+ int start = -1;
+ int end;
+ int y = para->rect().y() + para->rect().height();
+ int lastIndex = 0;
+ do {
+ end = s.indexOf(TQLatin1Char('\n'), start + 1); // find line break
+ if (end == -1) // didn't find one, so end of line is end of string
+ end = s.length();
+ int len = (start == -1 ? end : end - start - 1);
+ if (len > 0) // insert the line
+ para->insert(idx, s.unicode() + start + 1, len);
+ else
+ para->invalidate(0);
+ if (formatting) { // set formats to the chars of the line
+ for (int i = 0; i < len; ++i) {
+ if (formatting->at(i + lastIndex).format()) {
+ formatting->at(i + lastIndex).format()->addRef();
+ para->string()->setFormat(i + idx, formatting->at(i + lastIndex).format(), true);
+ }
+ }
+ lastIndex += len;
+ }
+ start = end; // next start is at the end of this line
+ idx += len; // increase the index of the cursor to the end of the inserted text
+ if (s[end] == TQLatin1Char('\n')) { // if at the end was a line break, break the line
+ splitAndInsertEmptyParagraph(false, true);
+ para->setEndState(-1);
+ para->prev()->format(-1, false);
+ lastIndex++;
+ }
+
+ } while (end < (int)s.length());
+
+ para->format(-1, false);
+ int dy = para->rect().y() + para->rect().height() - y;
+ TQTextParagraph *p = para;
+ p->setParagId(p->prev() ? p->prev()->paragId() + 1 : 0);
+ p = p->next();
+ while (p) {
+ p->setParagId(p->prev()->paragId() + 1);
+ p->move(dy);
+ p->invalidate(0);
+ p->setEndState(-1);
+ p = p->next();
+ }
+ }
+
+ int h = para->rect().height();
+ para->format(-1, true);
+ if (h != para->rect().height())
+ invalidateNested();
+ else if (para->document() && para->document()->parent())
+ para->document()->nextDoubleBuffered = true;
+
+ fixCursorPosition();
+}
+
+void TQTextCursor::gotoLeft()
+{
+ if (para->string()->isRightToLeft())
+ gotoNextLetter();
+ else
+ gotoPreviousLetter();
+}
+
+void TQTextCursor::gotoPreviousLetter()
+{
+ tmpX = -1;
+
+ if (idx > 0) {
+ idx = para->string()->previousCursorPosition(idx);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ const TQTextStringChar *tsc = para->at(idx);
+ if (tsc && tsc->isCustom() && tsc->customItem()->isNested())
+ processNesting(EnterEnd);
+#endif
+ } else if (para->prev()) {
+ para = para->prev();
+ while (!para->isVisible() && para->prev())
+ para = para->prev();
+ idx = para->length() - 1;
+ } else if (nestedDepth()) {
+ pop();
+ processNesting(Prev);
+ if (idx == -1) {
+ pop();
+ if (idx > 0) {
+ idx = para->string()->previousCursorPosition(idx);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ const TQTextStringChar *tsc = para->at(idx);
+ if (tsc && tsc->isCustom() && tsc->customItem()->isNested())
+ processNesting(EnterEnd);
+#endif
+ } else if (para->prev()) {
+ para = para->prev();
+ idx = para->length() - 1;
+ }
+ }
+ }
+}
+
+void TQTextCursor::push()
+{
+ indices.push(idx);
+ paras.push(para);
+ xOffsets.push(ox);
+ yOffsets.push(oy);
+}
+
+void TQTextCursor::pop()
+{
+ if (indices.isEmpty())
+ return;
+ idx = indices.pop();
+ para = paras.pop();
+ ox = xOffsets.pop();
+ oy = yOffsets.pop();
+}
+
+void TQTextCursor::restoreState()
+{
+ while (!indices.isEmpty())
+ pop();
+}
+
+bool TQTextCursor::place(const QPoint &p, TQTextParagraph *s, bool link)
+{
+ QPoint pos(p);
+ TQRect r;
+ TQTextParagraph *str = s;
+ if (pos.y() < s->rect().y()) {
+ pos.setY(s->rect().y());
+#ifdef Q_WS_MAC
+ pos.setX(s->rect().x());
+#endif
+ }
+ while (s) {
+ r = s->rect();
+ r.setWidth(document() ? document()->width() : QWIDGETSIZE_MAX);
+ if (s->isVisible())
+ str = s;
+ if (pos.y() >= r.y() && pos.y() <= r.y() + r.height())
+ break;
+ if (!s->next()) {
+#ifdef Q_WS_MAC
+ pos.setX(s->rect().x() + s->rect().width());
+#endif
+ break;
+ }
+ s = s->next();
+ }
+
+ if (!s || !str)
+ return false;
+
+ s = str;
+
+ setParagraph(s);
+ int y = s->rect().y();
+ int lines = s->lines();
+ TQTextStringChar *chr = 0;
+ int index = 0;
+ int i = 0;
+ int cy = 0;
+ int ch = 0;
+ for (; i < lines; ++i) {
+ chr = s->lineStartOfLine(i, &index);
+ cy = s->lineY(i);
+ ch = s->lineHeight(i);
+ if (!chr)
+ return false;
+ if (pos.y() <= y + cy + ch)
+ break;
+ }
+ int nextLine;
+ if (i < lines - 1)
+ s->lineStartOfLine(i+1, &nextLine);
+ else
+ nextLine = s->length();
+ i = index;
+ int x = s->rect().x();
+ if (pos.x() < x)
+ pos.setX(x + 1);
+ int cw;
+ int curpos = s->length()-1;
+ int dist = 10000000;
+ bool inCustom = false;
+ while (i < nextLine) {
+ chr = s->at(i);
+ int cpos = x + chr->x;
+ cw = s->string()->width(i);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (chr->isCustom() && chr->customItem()->isNested()) {
+ if (pos.x() >= cpos && pos.x() <= cpos + cw &&
+ pos.y() >= y + cy && pos.y() <= y + cy + chr->height()) {
+ inCustom = true;
+ curpos = i;
+ break;
+ }
+ } else
+#endif
+ {
+ if(chr->rightToLeft)
+ cpos += cw;
+ int diff = cpos - pos.x();
+ bool dm = diff < 0 ? !chr->rightToLeft : chr->rightToLeft;
+ if ((QABS(diff) < dist || (dist == diff && dm == true)) && para->string()->validCursorPosition(i)) {
+ dist = QABS(diff);
+ if (!link || pos.x() >= x + chr->x)
+ curpos = i;
+ }
+ }
+ i++;
+ }
+ setIndex(curpos);
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (inCustom && para->document() && para->at(curpos)->isCustom() && para->at(curpos)->customItem()->isNested()) {
+ TQTextDocument *oldDoc = para->document();
+ gotoIntoNested(pos);
+ if (oldDoc == para->document())
+ return true;
+ QPoint p(pos.x() - offsetX(), pos.y() - offsetY());
+ if (!place(p, document()->firstParagraph(), link))
+ pop();
+ }
+#endif
+ return true;
+}
+
+bool TQTextCursor::processNesting(Operation op)
+{
+ if (!para->document())
+ return false;
+ TQTextDocument* doc = para->document();
+ push();
+ ox = para->at(idx)->x;
+ int bl, y;
+ para->lineHeightOfChar(idx, &bl, &y);
+ oy = y + para->rect().y();
+ bool ok = false;
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ switch (op) {
+ case EnterBegin:
+ ok = para->at(idx)->customItem()->enter(this, doc, para, idx, ox, oy);
+ break;
+ case EnterEnd:
+ ok = para->at(idx)->customItem()->enter(this, doc, para, idx, ox, oy, true);
+ break;
+ case Next:
+ ok = para->at(idx)->customItem()->next(this, doc, para, idx, ox, oy);
+ break;
+ case Prev:
+ ok = para->at(idx)->customItem()->prev(this, doc, para, idx, ox, oy);
+ break;
+ case Down:
+ ok = para->at(idx)->customItem()->down(this, doc, para, idx, ox, oy);
+ break;
+ case Up:
+ ok = para->at(idx)->customItem()->up(this, doc, para, idx, ox, oy);
+ break;
+ }
+ if (!ok)
+#endif
+ pop();
+ return ok;
+}
+
+void TQTextCursor::gotoRight()
+{
+ if (para->string()->isRightToLeft())
+ gotoPreviousLetter();
+ else
+ gotoNextLetter();
+}
+
+void TQTextCursor::gotoNextLetter()
+{
+ tmpX = -1;
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ const TQTextStringChar *tsc = para->at(idx);
+ if (tsc && tsc->isCustom() && tsc->customItem()->isNested()) {
+ if (processNesting(EnterBegin))
+ return;
+ }
+#endif
+
+ if (idx < para->length() - 1) {
+ idx = para->string()->nextCursorPosition(idx);
+ } else if (para->next()) {
+ para = para->next();
+ while (!para->isVisible() && para->next())
+ para = para->next();
+ idx = 0;
+ } else if (nestedDepth()) {
+ pop();
+ processNesting(Next);
+ if (idx == -1) {
+ pop();
+ if (idx < para->length() - 1) {
+ idx = para->string()->nextCursorPosition(idx);
+ } else if (para->next()) {
+ para = para->next();
+ idx = 0;
+ }
+ }
+ }
+}
+
+void TQTextCursor::gotoUp()
+{
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar(idx, &indexOfLineStart, &line);
+ if (!c)
+ return;
+
+ if (tmpX < 0)
+ tmpX = x();
+
+ if (indexOfLineStart == 0) {
+ if (!para->prev()) {
+ if (!nestedDepth())
+ return;
+ pop();
+ processNesting(Up);
+ if (idx == -1) {
+ pop();
+ if (!para->prev())
+ return;
+ idx = tmpX = 0;
+ } else {
+ tmpX = -1;
+ return;
+ }
+ }
+ TQTextParagraph *p = para->prev();
+ while (p && !p->isVisible())
+ p = p->prev();
+ if (p)
+ para = p;
+ int lastLine = para->lines() - 1;
+ if (!para->lineStartOfLine(lastLine, &indexOfLineStart))
+ return;
+ idx = indexOfLineStart;
+ while (idx < para->length()-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ } else {
+ --line;
+ int oldIndexOfLineStart = indexOfLineStart;
+ if (!para->lineStartOfLine(line, &indexOfLineStart))
+ return;
+ idx = indexOfLineStart;
+ while (idx < oldIndexOfLineStart-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ }
+ fixCursorPosition();
+}
+
+void TQTextCursor::gotoDown()
+{
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar(idx, &indexOfLineStart, &line);
+ if (!c)
+ return;
+
+ if (tmpX < 0)
+ tmpX = x();
+
+ if (line == para->lines() - 1) {
+ if (!para->next()) {
+ if (!nestedDepth())
+ return;
+ pop();
+ processNesting(Down);
+ if (idx == -1) {
+ pop();
+ if (!para->next())
+ return;
+ idx = tmpX = 0;
+ } else {
+ tmpX = -1;
+ return;
+ }
+ }
+ TQTextParagraph *s = para->next();
+ while (s && !s->isVisible())
+ s = s->next();
+ if (s)
+ para = s;
+ if (!para->lineStartOfLine(0, &indexOfLineStart))
+ return;
+ int end;
+ if (para->lines() == 1)
+ end = para->length();
+ else
+ para->lineStartOfLine(1, &end);
+
+ idx = indexOfLineStart;
+ while (idx < end-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ } else {
+ ++line;
+ int end;
+ if (line == para->lines() - 1)
+ end = para->length();
+ else
+ para->lineStartOfLine(line + 1, &end);
+ if (!para->lineStartOfLine(line, &indexOfLineStart))
+ return;
+ idx = indexOfLineStart;
+ while (idx < end-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ }
+ fixCursorPosition();
+}
+
+void TQTextCursor::gotoLineEnd()
+{
+ tmpX = -1;
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar(idx, &indexOfLineStart, &line);
+ if (!c)
+ return;
+
+ if (line == para->lines() - 1) {
+ idx = para->length() - 1;
+ } else {
+ c = para->lineStartOfLine(++line, &indexOfLineStart);
+ indexOfLineStart--;
+ idx = indexOfLineStart;
+ }
+}
+
+void TQTextCursor::gotoLineStart()
+{
+ tmpX = -1;
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar(idx, &indexOfLineStart, &line);
+ if (!c)
+ return;
+
+ idx = indexOfLineStart;
+}
+
+void TQTextCursor::gotoHome()
+{
+ if (topParagraph()->document())
+ gotoPosition(topParagraph()->document()->firstParagraph());
+ else
+ gotoLineStart();
+}
+
+void TQTextCursor::gotoEnd()
+{
+ if (topParagraph()->document() && topParagraph()->document()->lastParagraph()->isValid())
+ gotoPosition(topParagraph()->document()->lastParagraph(),
+ topParagraph()->document()->lastParagraph()->length() - 1);
+ else
+ gotoLineEnd();
+}
+
+void TQTextCursor::gotoPageUp(int visibleHeight)
+{
+ int targetY = globalY() - visibleHeight;
+ TQTextParagraph* old; int index;
+ do {
+ old = para; index = idx;
+ gotoUp();
+ } while ((old != para || index != idx) && globalY() > targetY);
+}
+
+void TQTextCursor::gotoPageDown(int visibleHeight)
+{
+ int targetY = globalY() + visibleHeight;
+ TQTextParagraph* old; int index;
+ do {
+ old = para; index = idx;
+ gotoDown();
+ } while ((old != para || index != idx) && globalY() < targetY);
+}
+
+void TQTextCursor::gotoWordRight()
+{
+ if (para->string()->isRightToLeft())
+ gotoPreviousWord();
+ else
+ gotoNextWord();
+}
+
+void TQTextCursor::gotoWordLeft()
+{
+ if (para->string()->isRightToLeft())
+ gotoNextWord();
+ else
+ gotoPreviousWord();
+}
+
+static bool is_seperator(const TQChar &c, bool onlySpace)
+{
+ if (onlySpace)
+ return c.isSpace();
+ return c.isSpace() ||
+ c == TQLatin1Char('\t') ||
+ c == TQLatin1Char('.') ||
+ c == TQLatin1Char(',') ||
+ c == TQLatin1Char(':') ||
+ c == TQLatin1Char(';') ||
+ c == TQLatin1Char('-') ||
+ c == TQLatin1Char('<') ||
+ c == TQLatin1Char('>') ||
+ c == TQLatin1Char('[') ||
+ c == TQLatin1Char(']') ||
+ c == TQLatin1Char('(') ||
+ c == TQLatin1Char(')') ||
+ c == TQLatin1Char('{') ||
+ c == TQLatin1Char('}');
+}
+
+void TQTextCursor::gotoPreviousWord(bool onlySpace)
+{
+ gotoPreviousLetter();
+ tmpX = -1;
+ TQTextString *s = para->string();
+ bool allowSame = false;
+ if (idx == ((int)s->length()-1))
+ return;
+ for (int i = idx; i >= 0; --i) {
+ if (is_seperator(s->at(i).c, onlySpace)) {
+ if (!allowSame)
+ continue;
+ idx = i + 1;
+ return;
+ }
+ if (!allowSame && !is_seperator(s->at(i).c, onlySpace))
+ allowSame = true;
+ }
+ idx = 0;
+}
+
+void TQTextCursor::gotoNextWord(bool onlySpace)
+{
+ tmpX = -1;
+ TQTextString *s = para->string();
+ bool allowSame = false;
+ for (int i = idx; i < (int)s->length(); ++i) {
+ if (!is_seperator(s->at(i).c, onlySpace)) {
+ if (!allowSame)
+ continue;
+ idx = i;
+ return;
+ }
+ if (!allowSame && is_seperator(s->at(i).c, onlySpace))
+ allowSame = true;
+
+ }
+
+ if (idx < ((int)s->length()-1)) {
+ gotoLineEnd();
+ } else if (para->next()) {
+ TQTextParagraph *p = para->next();
+ while (p && !p->isVisible())
+ p = p->next();
+ if (s) {
+ para = p;
+ idx = 0;
+ }
+ } else {
+ gotoLineEnd();
+ }
+}
+
+bool TQTextCursor::atParagStart()
+{
+ return idx == 0;
+}
+
+bool TQTextCursor::atParagEnd()
+{
+ return idx == para->length() - 1;
+}
+
+void TQTextCursor::splitAndInsertEmptyParagraph(bool ind, bool updateIds)
+{
+ if (!para->document())
+ return;
+ tmpX = -1;
+ TQTextFormat *f = 0;
+ if (para->document()->useFormatCollection()) {
+ f = para->at(idx)->format();
+ if (idx == para->length() - 1 && idx > 0)
+ f = para->at(idx - 1)->format();
+ if (f->isMisspelled()) {
+ f->removeRef();
+ f = para->document()->formatCollection()->format(f->font(), f->color());
+ }
+ }
+
+ if (atParagEnd()) {
+ TQTextParagraph *n = para->next();
+ TQTextParagraph *s = para->document()->createParagraph(para->document(), para, n, updateIds);
+ if (f)
+ s->setFormat(0, 1, f, true);
+ s->copyParagData(para);
+ if (ind) {
+ int oi, ni;
+ s->indent(&oi, &ni);
+ para = s;
+ idx = ni;
+ } else {
+ para = s;
+ idx = 0;
+ }
+ } else if (atParagStart()) {
+ TQTextParagraph *p = para->prev();
+ TQTextParagraph *s = para->document()->createParagraph(para->document(), p, para, updateIds);
+ if (f)
+ s->setFormat(0, 1, f, true);
+ s->copyParagData(para);
+ if (ind) {
+ s->indent();
+ s->format();
+ indent();
+ para->format();
+ }
+ } else {
+ TQString str = para->string()->toString().mid(idx, 0xFFFFFF);
+ TQTextParagraph *n = para->next();
+ TQTextParagraph *s = para->document()->createParagraph(para->document(), para, n, updateIds);
+ s->copyParagData(para);
+ s->remove(0, 1);
+ s->append(str, true);
+ for (int i = 0; i < str.length(); ++i) {
+ TQTextStringChar* tsc = para->at(idx + i);
+ s->setFormat(i, 1, tsc->format(), true);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (tsc->isCustom()) {
+ TQTextCustomItem * item = tsc->customItem();
+ s->at(i)->setCustomItem(item);
+ tsc->loseCustomItem();
+ }
+#endif
+ if (tsc->isAnchor())
+ s->at(i)->setAnchor(tsc->anchorName(),
+ tsc->anchorHref());
+ }
+ para->truncate(idx);
+ if (ind) {
+ int oi, ni;
+ s->indent(&oi, &ni);
+ para = s;
+ idx = ni;
+ } else {
+ para = s;
+ idx = 0;
+ }
+ }
+
+ invalidateNested();
+}
+
+bool TQTextCursor::remove()
+{
+ tmpX = -1;
+ if (!atParagEnd()) {
+ int next = para->string()->nextCursorPosition(idx);
+ para->remove(idx, next-idx);
+ int h = para->rect().height();
+ para->format(-1, true);
+ if (h != para->rect().height())
+ invalidateNested();
+ else if (para->document() && para->document()->parent())
+ para->document()->nextDoubleBuffered = true;
+ return false;
+ } else if (para->next()) {
+ para->join(para->next());
+ invalidateNested();
+ return true;
+ }
+ return false;
+}
+
+/* needed to implement backspace the correct way */
+bool TQTextCursor::removePreviousChar()
+{
+ tmpX = -1;
+ if (!atParagStart()) {
+ para->remove(idx-1, 1);
+ int h = para->rect().height();
+ idx--;
+ // shouldn't be needed, just to make sure.
+ fixCursorPosition();
+ para->format(-1, true);
+ if (h != para->rect().height())
+ invalidateNested();
+ else if (para->document() && para->document()->parent())
+ para->document()->nextDoubleBuffered = true;
+ return false;
+ } else if (para->prev()) {
+ para = para->prev();
+ para->join(para->next());
+ invalidateNested();
+ return true;
+ }
+ return false;
+}
+
+void TQTextCursor::indent()
+{
+ int oi = 0, ni = 0;
+ para->indent(&oi, &ni);
+ if (oi == ni)
+ return;
+
+ if (idx >= oi)
+ idx += ni - oi;
+ else
+ idx = ni;
+}
+
+void TQTextCursor::fixCursorPosition()
+{
+ // searches for the closest valid cursor position
+ if (para->string()->validCursorPosition(idx))
+ return;
+
+ int lineIdx;
+ TQTextStringChar *start = para->lineStartOfChar(idx, &lineIdx, 0);
+ int x = para->string()->at(idx).x;
+ int diff = QABS(start->x - x);
+ int best = lineIdx;
+
+ TQTextStringChar *c = start;
+ ++c;
+
+ TQTextStringChar *end = &para->string()->at(para->length()-1);
+ while (c <= end && !c->lineStart) {
+ int xp = c->x;
+ if (c->rightToLeft)
+ xp += para->string()->width(lineIdx + (c-start));
+ int ndiff = QABS(xp - x);
+ if (ndiff < diff && para->string()->validCursorPosition(lineIdx + (c-start))) {
+ diff = ndiff;
+ best = lineIdx + (c-start);
+ }
+ ++c;
+ }
+ idx = best;
+}
+
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextDocument::TQTextDocument(TQTextDocument *p)
+ : par(p), parentPar(0)
+#ifndef QT_NO_TEXTCUSTOMITEM
+ , tc(0)
+#endif
+ , tArray(0), tStopWidth(0)
+{
+ fCollection = par ? par->fCollection : new TQTextFormatCollection;
+ init();
+}
+
+void TQTextDocument::init()
+{
+ oTextValid = true;
+ mightHaveCustomItems = false;
+ if (par)
+ par->insertChild(this);
+ pProcessor = 0;
+ useFC = true;
+ pFormatter = 0;
+ indenter = 0;
+ fParag = 0;
+ txtFormat = TQt::AutoText;
+ preferRichText = false;
+ pages = false;
+ focusIndicator.parag = 0;
+ minw = 0;
+ wused = 0;
+ minwParag = curParag = 0;
+ align = TQt::AlignAuto;
+ nSelections = 1;
+
+ setStyleSheet(TQStyleSheet::defaultSheet());
+#ifndef QT_NO_MIME
+ factory_ = TQMimeSourceFactory::defaultFactory();
+#endif
+ contxt.clear();
+
+ underlLinks = par ? par->underlLinks : true;
+ backBrush = 0;
+ buf_pixmap = 0;
+ nextDoubleBuffered = false;
+
+ if (par)
+ withoutDoubleBuffer = par->withoutDoubleBuffer;
+ else
+ withoutDoubleBuffer = false;
+
+ lParag = fParag = createParagraph(this, 0, 0);
+
+ cx = 0;
+ cy = 2;
+ if (par)
+ cx = cy = 0;
+ cw = 600;
+ vw = 0;
+ flow_ = new TQTextFlow;
+ flow_->setWidth(cw);
+
+ leftmargin = rightmargin = 4;
+ scaleFontsFactor = 1;
+
+ commandHistory = new TQTextCommandHistory(100);
+ tStopWidth = formatCollection()->defaultFormat()->width(TQLatin1Char('x')) * 8;
+}
+
+TQTextDocument::~TQTextDocument()
+{
+ delete commandHistory;
+ if (par)
+ par->removeChild(this);
+ clear();
+ delete flow_;
+ if (!par) {
+ delete pFormatter;
+ delete fCollection;
+ }
+ delete pProcessor;
+ delete buf_pixmap;
+ delete indenter;
+ delete backBrush;
+ delete [] tArray;
+}
+
+void TQTextDocument::clear(bool createEmptyParag)
+{
+ while (fParag) {
+ TQTextParagraph *p = fParag->next();
+ delete fParag;
+ fParag = p;
+ }
+ if (flow_)
+ flow_->clear();
+ fParag = lParag = 0;
+ if (createEmptyParag)
+ fParag = lParag = createParagraph(this);
+ selections.clear();
+ oText.clear();
+ oTextValid = false;
+}
+
+int TQTextDocument::widthUsed() const
+{
+ return wused + 2*border_tolerance;
+}
+
+int TQTextDocument::height() const
+{
+ int h = 0;
+ if (lParag)
+ h = lParag->rect().top() + lParag->rect().height() + 1;
+ int fh = flow_->boundingRect().bottom();
+ return qMax(h, fh);
+}
+
+
+
+TQTextParagraph *TQTextDocument::createParagraph(TQTextDocument *dc, TQTextParagraph *pr, TQTextParagraph *nx, bool updateIds)
+{
+ return new TQTextParagraph(dc, pr, nx, updateIds);
+}
+
+bool TQTextDocument::setMinimumWidth(int needed, int used, TQTextParagraph *p)
+{
+ if (needed == -1) {
+ minw = 0;
+ wused = 0;
+ p = 0;
+ }
+ if (p == minwParag) {
+ if (minw > needed) {
+ TQTextParagraph *tp = fParag;
+ while (tp) {
+ if (tp != p && tp->minwidth > needed) {
+ needed = tp->minwidth;
+ minwParag = tp;
+ }
+ tp = tp->n;
+ }
+ }
+ minw = needed;
+ emit minimumWidthChanged(minw);
+ } else if (needed > minw) {
+ minw = needed;
+ minwParag = p;
+ emit minimumWidthChanged(minw);
+ }
+ wused = qMax(wused, used);
+ wused = qMax(wused, minw);
+ cw = qMax(minw, cw);
+ return true;
+}
+
+void TQTextDocument::setPlainText(const TQString &text)
+{
+ preferRichText = false;
+ clear();
+ oTextValid = true;
+ oText = text;
+
+ int lastNl = 0;
+ int nl = text.indexOf(TQLatin1Char('\n'));
+ if (nl == -1) {
+ lParag = createParagraph(this, lParag, 0);
+ if (!fParag)
+ fParag = lParag;
+ TQString s = text;
+ if (!s.isEmpty()) {
+ if (s[(int)s.length() - 1] == TQLatin1Char('\r'))
+ s.remove(s.length() - 1, 1);
+ lParag->append(s);
+ }
+ } else {
+ for (;;) {
+ lParag = createParagraph(this, lParag, 0);
+ if (!fParag)
+ fParag = lParag;
+ int l = nl - lastNl;
+ if (l > 0) {
+ if (text.unicode()[nl-1] == TQLatin1Char('\r'))
+ l--;
+ TQString cs = TQString::fromRawData(text.unicode()+lastNl, l);
+ lParag->append(cs);
+ }
+ if (nl == (int)text.length())
+ break;
+ lastNl = nl + 1;
+ nl = text.indexOf(TQLatin1Char('\n'), nl + 1);
+ if (nl == -1)
+ nl = text.length();
+ }
+ }
+ if (!lParag)
+ lParag = fParag = createParagraph(this, 0, 0);
+}
+
+struct TQTextDocumentTag {
+ TQTextDocumentTag(){}
+ TQTextDocumentTag(const TQString&n, const TQStyleSheetItem* s, const TQTextFormat& f)
+ :name(n),style(s), format(f), alignment(TQt::AlignAuto), direction(TQChar::DirON),liststyle(TQStyleSheetItem::ListDisc) {
+ wsm = TQStyleSheetItem::WhiteSpaceNormal;
+ }
+ TQString name;
+ const TQStyleSheetItem* style;
+ TQString anchorHref;
+ TQStyleSheetItem::WhiteSpaceMode wsm;
+ TQTextFormat format;
+ signed int alignment : 16;
+ signed int direction : 5;
+ TQStyleSheetItem::ListStyle liststyle;
+
+ TQTextDocumentTag( const TQTextDocumentTag& t) {
+ name = t.name;
+ style = t.style;
+ anchorHref = t.anchorHref;
+ wsm = t.wsm;
+ format = t.format;
+ alignment = t.alignment;
+ direction = t.direction;
+ liststyle = t.liststyle;
+ }
+ TQTextDocumentTag& operator=(const TQTextDocumentTag& t) {
+ name = t.name;
+ style = t.style;
+ anchorHref = t.anchorHref;
+ wsm = t.wsm;
+ format = t.format;
+ alignment = t.alignment;
+ direction = t.direction;
+ liststyle = t.liststyle;
+ return *this;
+ }
+
+ Q_DUMMY_COMPARISON_OPERATOR(TQTextDocumentTag)
+};
+
+
+#define NEWPAR \
+ do{ \
+ if (!hasNewPar) { \
+ if (!textEditMode && curpar && curpar->length()>1 \
+ && curpar->at(curpar->length()-2)->c == TQChar::LineSeparator) \
+ curpar->remove(curpar->length()-2, 1); \
+ curpar = createParagraph(this, curpar, curpar->next()); \
+ styles.append(vec); \
+ vec = 0; \
+ } \
+ hasNewPar = true; \
+ curpar->rtext = true; \
+ curpar->align = curtag.alignment; \
+ curpar->lstyle = curtag.liststyle; \
+ curpar->litem = (curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem); \
+ curpar->str->setDirection((TQChar::Direction)curtag.direction); \
+ space = true; \
+ tabExpansionColumn = 0; \
+ delete vec; \
+ vec = new QVector<TQStyleSheetItem *>(); \
+ for (QStack<TQTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it) \
+ vec->append(const_cast<TQStyleSheetItem *>((*it).style)); \
+ vec->append(const_cast<TQStyleSheetItem *>(curtag.style)); \
+ } while(false);
+
+
+void TQTextDocument::setRichText(const TQString &text, const TQString &context, const TQTextFormat *initialFormat)
+{
+ preferRichText = true;
+ if (!context.isEmpty())
+ setContext(context);
+ clear();
+ fParag = lParag = createParagraph(this);
+ oTextValid = true;
+ oText = text;
+ setRichTextInternal(text, 0, initialFormat);
+ fParag->rtext = true;
+}
+
+void TQTextDocument::setRichTextInternal(const TQString &text, TQTextCursor* cursor, const TQTextFormat *initialFormat)
+{
+ TQTextParagraph* curpar = lParag;
+ int pos = 0;
+ QStack<TQTextDocumentTag> tags;
+ if (!initialFormat)
+ initialFormat = formatCollection()->defaultFormat();
+ TQTextDocumentTag initag(TQLatin1String(""), sheet_->item(TQLatin1String("")), *initialFormat);
+ if (bodyText.isValid())
+ initag.format.setColor(bodyText);
+ TQTextDocumentTag curtag = initag;
+ bool space = true;
+ bool canMergeLi = false;
+
+ bool textEditMode = false;
+ int tabExpansionColumn = 0;
+
+ const TQChar* doc = static_cast<const TQChar*>(text.unicode());
+ int length = text.length();
+ bool hasNewPar = curpar->length() <= 1;
+ TQString anchorName;
+
+ // style sheet handling for margin and line spacing calculation below
+ TQTextParagraph* stylesPar = curpar;
+ QVector<TQStyleSheetItem *>* vec = 0;
+ QList< QVector<TQStyleSheetItem *> *> styles;
+
+ if (cursor) {
+ cursor->splitAndInsertEmptyParagraph();
+ TQTextCursor tmp = *cursor;
+ tmp.gotoPreviousLetter();
+ stylesPar = curpar = tmp.paragraph();
+ hasNewPar = true;
+ textEditMode = true;
+ } else {
+ NEWPAR;
+ }
+
+ // set rtext spacing to false for the initial paragraph.
+ curpar->rtext = false;
+
+ TQString wellKnownTags = TQLatin1String("br hr wsp table qt body meta title");
+
+ while (pos < length) {
+ if (hasPrefix(doc, length, pos, TQLatin1Char('<'))){
+ if (!hasPrefix(doc, length, pos+1, TQLatin1Char('/'))) {
+ // open tag
+ QMap<TQString, TQString> attr;
+ QMap<TQString, TQString>::Iterator it, end = attr.end();
+ bool emptyTag = false;
+ TQString tagname = parseOpenTag(doc, length, pos, attr, emptyTag);
+ if (tagname.isEmpty())
+ continue; // nothing we could do with this, probably parse error
+
+ const TQStyleSheetItem* nstyle = sheet_->item(tagname);
+
+ if (nstyle) {
+ // we might have to close some 'forgotten' tags
+ while (!nstyle->allowedInContext(curtag.style)) {
+ TQString msg;
+ msg.sprintf("QText Warning: Document not valid ('%s' not allowed in '%s' #%d)",
+ tagname.ascii(), curtag.style->name().ascii(), pos);
+ sheet_->error(msg);
+ if (tags.isEmpty())
+ break;
+ curtag = tags.pop();
+ }
+
+ /* special handling for p and li for HTML
+ compatibility. We do not want to embed blocks in
+ p, and we do not want new blocks inside non-empty
+ lis. Plus we want to merge empty lis sometimes. */
+ if(nstyle->displayMode() == TQStyleSheetItem::DisplayListItem) {
+ canMergeLi = true;
+ } else if (nstyle->displayMode() == TQStyleSheetItem::DisplayBlock) {
+ while (curtag.style->name() == TQLatin1String("p")) {
+ if (tags.isEmpty())
+ break;
+ curtag = tags.pop();
+ }
+
+ if (curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem) {
+ // we are in a li and a new block comes along
+ if (nstyle->name() == TQLatin1String("ul") || nstyle->name() == TQLatin1String("ol"))
+ hasNewPar = false; // we want an empty li (like most browsers)
+ if (!hasNewPar) {
+ /* do not add new blocks inside
+ non-empty lis */
+ while (curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem) {
+ if (tags.isEmpty())
+ break;
+ curtag = tags.pop();
+ }
+ } else if (canMergeLi) {
+ /* we have an empty li and a block
+ comes along, merge them */
+ nstyle = curtag.style;
+ }
+ canMergeLi = false;
+ }
+ }
+ }
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem* custom = 0;
+#else
+ bool custom = false;
+#endif
+
+ // some well-known tags, some have a nstyle, some not
+ if (wellKnownTags.contains(tagname)) {
+ if (tagname == TQLatin1String("br")) {
+ emptyTag = space = true;
+ int index = qMax(curpar->length(),1) - 1;
+ TQTextFormat format = curtag.format.makeTextFormat(nstyle, attr, scaleFontsFactor);
+ curpar->append(TQString(TQChar(TQChar::LineSeparator)));
+ curpar->setFormat(index, 1, &format);
+ hasNewPar = false;
+ } else if (tagname == TQLatin1String("hr")) {
+ emptyTag = space = true;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ custom = tag(sheet_, tagname, attr, contxt, *factory_ , emptyTag, this);
+#endif
+ } else if (tagname == TQLatin1String("table")) {
+ emptyTag = space = true;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor);
+ curpar->setAlignment(curtag.alignment);
+ custom = parseTable(attr, format, doc, length, pos, curpar);
+#endif
+ } else if (tagname == TQLatin1String("qt") || tagname == TQLatin1String("body")) {
+ it = attr.find(TQLatin1String("bgcolor"));
+ if (it != end) {
+ TQBrush *b = new TQBrush(QColor(*it));
+ setPaper(b);
+ }
+ it = attr.find(TQLatin1String("background"));
+ if (it != end) {
+#ifndef QT_NO_MIME
+ TQImage img;
+ TQString bg = *it;
+ const QMimeSource* m = factory_->data(bg, contxt);
+ if (!m) {
+ qCritical("QRichText: no mimesource for %s",
+ QFile::encodeName(bg).data());
+ } else {
+ if (!TQImageDrag::decode(TQT_TQMIMESOURCE_CONST(m), img)) {
+ qCritical("TQTextImage: cannot decode %s",
+ QFile::encodeName(bg).data());
+ }
+ }
+ if (!img.isNull()) {
+ TQBrush *b = new TQBrush(QColor(), TQPixmap(img));
+ setPaper(b);
+ }
+#endif
+ }
+ it = attr.find(TQLatin1String("text"));
+ if (it != end) {
+ QColor c(*it);
+ initag.format.setColor(c);
+ curtag.format.setColor(c);
+ bodyText = c;
+ }
+ it = attr.find(TQLatin1String("link"));
+ if (it != end)
+ linkColor = QColor(*it);
+ it = attr.find(TQLatin1String("title"));
+ if (it != end)
+ attribs.insert(TQLatin1String("title"), *it);
+
+ if (textEditMode) {
+ it = attr.find(TQLatin1String("style"));
+ if (it != end) {
+ TQString a = *it;
+ int count = a.count(TQLatin1Char(';')) + 1;
+ for (int s = 0; s < count; s++) {
+ TQString style = a.section(TQLatin1Char(';'), s, s);
+ if (style.startsWith(TQLatin1String("font-size:")) && style.endsWith(TQLatin1String("pt"))) {
+ scaleFontsFactor = double(formatCollection()->defaultFormat()->fn.pointSize()) /
+ style.mid(10, style.length() - 12).toInt();
+ }
+ }
+ }
+ nstyle = 0; // ignore body in textEditMode
+ }
+ // end qt- and body-tag handling
+ } else if (tagname == TQLatin1String("meta")) {
+ if (attr[TQLatin1String("name")] == TQLatin1String("qrichtext") && attr[TQLatin1String("content")] == TQLatin1String("1"))
+ textEditMode = true;
+ } else if (tagname == TQLatin1String("title")) {
+ TQString title;
+ while (pos < length) {
+ if (hasPrefix(doc, length, pos, TQLatin1Char('<')) && hasPrefix(doc, length, pos+1, TQLatin1Char('/')) &&
+ parseCloseTag(doc, length, pos) == TQLatin1String("title"))
+ break;
+ title += doc[pos];
+ ++pos;
+ }
+ attribs.insert(TQLatin1String("title"), title);
+ }
+ } // end of well-known tag handling
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (!custom) // try generic custom item
+ custom = tag(sheet_, tagname, attr, contxt, *factory_ , emptyTag, this);
+#endif
+ if (!nstyle && !custom) // we have no clue what this tag could be, ignore it
+ continue;
+
+ if (custom) {
+#ifndef QT_NO_TEXTCUSTOMITEM
+ int index = qMax(curpar->length(),1) - 1;
+ TQTextFormat format = curtag.format.makeTextFormat(nstyle, attr, scaleFontsFactor);
+ curpar->append(TQString(TQLatin1Char('*')));
+ TQTextFormat* f = formatCollection()->format(&format);
+ curpar->setFormat(index, 1, f);
+ curpar->at(index)->setCustomItem(custom);
+ if (!curtag.anchorHref.isEmpty())
+ curpar->at(index)->setAnchor(TQString(), curtag.anchorHref);
+ if (!anchorName.isEmpty() ) {
+ curpar->at(index)->setAnchor(anchorName, curpar->at(index)->anchorHref());
+ anchorName.clear();
+ }
+ registerCustomItem(custom, curpar);
+ hasNewPar = false;
+#endif
+ } else if (!emptyTag) {
+ /* if we do nesting, push curtag on the stack,
+ otherwise reinint curag. */
+ if (curtag.style->name() != tagname || nstyle->selfNesting()) {
+ tags.push(curtag);
+ } else {
+ if (!tags.isEmpty())
+ curtag = tags.top();
+ else
+ curtag = initag;
+ }
+
+ curtag.name = tagname;
+ curtag.style = nstyle;
+ curtag.name = tagname;
+ curtag.style = nstyle;
+ if (nstyle->whiteSpaceMode() != TQStyleSheetItem::WhiteSpaceModeUndefined)
+ curtag.wsm = nstyle->whiteSpaceMode();
+
+ /* netscape compatibility: eat a newline and only a newline if a pre block starts */
+ if (curtag.wsm == TQStyleSheetItem::WhiteSpacePre &&
+ nstyle->displayMode() == TQStyleSheetItem::DisplayBlock)
+ eat(doc, length, pos, TQLatin1Char('\n'));
+
+ /* ignore whitespace for inline elements if there
+ was already one*/
+ if (!textEditMode &&
+ (curtag.wsm == TQStyleSheetItem::WhiteSpaceNormal
+ || curtag.wsm == TQStyleSheetItem::WhiteSpaceNoWrap)
+ && (space || nstyle->displayMode() != TQStyleSheetItem::DisplayInline))
+ eatSpace(doc, length, pos);
+
+ curtag.format = curtag.format.makeTextFormat(nstyle, attr, scaleFontsFactor);
+ if (nstyle->isAnchor()) {
+ if (!anchorName.isEmpty())
+ anchorName += TQLatin1Char('#') + attr[TQLatin1String("name")];
+ else
+ anchorName = attr[TQLatin1String("name")];
+ curtag.anchorHref = attr[TQLatin1String("href")];
+ }
+
+ if (nstyle->alignment() != TQStyleSheetItem::Undefined)
+ curtag.alignment = nstyle->alignment();
+
+ if (nstyle->listStyle() != TQStyleSheetItem::ListStyleUndefined)
+ curtag.liststyle = nstyle->listStyle();
+
+ if (nstyle->displayMode() == TQStyleSheetItem::DisplayBlock
+ || nstyle->displayMode() == TQStyleSheetItem::DisplayListItem) {
+
+ if (nstyle->name() == TQLatin1String("ol") ||
+ nstyle->name() == TQLatin1String("ul") ||
+ nstyle->name() == TQLatin1String("li")) {
+ TQString type = attr[TQLatin1String("type")];
+ if (!type.isEmpty()) {
+ if (type == TQLatin1String("1")) {
+ curtag.liststyle = TQStyleSheetItem::ListDecimal;
+ } else if (type == TQLatin1String("a")) {
+ curtag.liststyle = TQStyleSheetItem::ListLowerAlpha;
+ } else if (type == TQLatin1String("A")) {
+ curtag.liststyle = TQStyleSheetItem::ListUpperAlpha;
+ } else {
+ type = type.toLower();
+ if (type == TQLatin1String("square"))
+ curtag.liststyle = TQStyleSheetItem::ListSquare;
+ else if (type == TQLatin1String("disc"))
+ curtag.liststyle = TQStyleSheetItem::ListDisc;
+ else if (type == TQLatin1String("circle"))
+ curtag.liststyle = TQStyleSheetItem::ListCircle;
+ }
+ }
+ }
+
+
+ /* Internally we treat ordered and bullet
+ lists the same for margin calculations. In
+ order to have fast pointer compares in the
+ xMargin() functions we restrict ourselves to
+ <ol>. Once we calculate the margins in the
+ parser rathern than later, the unelegance of
+ this approach goes awy
+ */
+ if (nstyle->name() == TQLatin1String("ul"))
+ curtag.style = sheet_->item(TQLatin1String("ol"));
+
+ it = attr.find(TQLatin1String("align"));
+ if (it != end) {
+ TQString align = (*it).toLower();
+ if (align == TQLatin1String("center"))
+ curtag.alignment = Qt::AlignCenter;
+ else if (align == TQLatin1String("right"))
+ curtag.alignment = Qt::AlignRight;
+ else if (align == TQLatin1String("justify"))
+ curtag.alignment = Qt::AlignJustify;
+ }
+ it = attr.find(TQLatin1String("dir"));
+ if (it != end) {
+ TQString dir = (*it).toLower();
+ if (dir == TQLatin1String("rtl"))
+ curtag.direction = TQChar::DirR;
+ else if (dir == TQLatin1String("ltr"))
+ curtag.direction = TQChar::DirL;
+ }
+
+ NEWPAR;
+
+ if (curtag.style && curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem) {
+ it = attr.find(TQLatin1String("value"));
+ if (it != end)
+ curpar->setListValue((*it).toInt());
+ }
+
+ it = attr.find(TQLatin1String("style"));
+ if (it != end) {
+ TQString a = *it;
+ bool ok = true;
+ int count = a.count(TQLatin1Char(';'))+1;
+ for (int s = 0; ok && s < count; s++) {
+ TQString style = a.section(TQLatin1Char(';'), s, s);
+ if (style.startsWith(TQLatin1String("margin-top:")) && style.endsWith(TQLatin1String("px")))
+ curpar->utm = 1+style.mid(11, style.length() - 13).toInt(&ok);
+ else if (style.startsWith(TQLatin1String("margin-bottom:")) && style.endsWith(TQLatin1String("px")))
+ curpar->ubm = 1+style.mid(14, style.length() - 16).toInt(&ok);
+ else if (style.startsWith(TQLatin1String("margin-left:")) && style.endsWith(TQLatin1String("px")))
+ curpar->ulm = 1+style.mid(12, style.length() - 14).toInt(&ok);
+ else if (style.startsWith(TQLatin1String("margin-right:")) && style.endsWith(TQLatin1String("px")))
+ curpar->urm = 1+style.mid(13, style.length() - 15).toInt(&ok);
+ else if (style.startsWith(TQLatin1String("text-indent:")) && style.endsWith(TQLatin1String("px")))
+ curpar->uflm = 1+style.mid(12, style.length() - 14).toInt(&ok);
+ }
+ if (!ok) // be pressmistic
+ curpar->utm = curpar->ubm = curpar->urm = curpar->ulm = 0;
+ }
+ } else if (nstyle->name() == TQLatin1String("html")) {
+ it = attr.find(TQLatin1String("dir"));
+ if (it != end) {
+ TQString dir = (*it).toLower();
+ if (dir == TQLatin1String("rtl"))
+ curtag.direction = TQChar::DirR;
+ else if (dir == TQLatin1String("ltr"))
+ curtag.direction = TQChar::DirL;
+ }
+ }
+ }
+ } else {
+ TQString tagname = parseCloseTag(doc, length, pos);
+ if (tagname.isEmpty())
+ continue; // nothing we could do with this, probably parse error
+ if (!sheet_->item(tagname)) // ignore unknown tags
+ continue;
+ if (tagname == TQLatin1String("li"))
+ continue;
+
+ // we close a block item. Since the text may continue, we need to have a new paragraph
+ bool needNewPar = curtag.style->displayMode() == TQStyleSheetItem::DisplayBlock
+ || curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem;
+
+
+ // html slopiness: handle unbalanched tag closing
+ while (curtag.name != tagname) {
+ TQString msg;
+ msg.sprintf("QText Warning: Document not valid ('%s' not closed before '%s' #%d)",
+ curtag.name.ascii(), tagname.ascii(), pos);
+ sheet_->error(msg);
+ if (tags.isEmpty())
+ break;
+ curtag = tags.pop();
+ }
+
+
+ // close the tag
+ if (!tags.isEmpty())
+ curtag = tags.pop();
+ else
+ curtag = initag;
+
+ if (needNewPar) {
+ if (textEditMode && (tagname == TQLatin1String("p") || tagname == TQLatin1String("div"))) // preserve empty paragraphs
+ hasNewPar = false;
+ NEWPAR;
+ }
+ }
+ } else {
+ // normal contents
+ TQString s;
+ TQChar c;
+ while (pos < length && !hasPrefix(doc, length, pos, TQLatin1Char('<'))){
+ if (textEditMode) {
+ // text edit mode: we handle all white space but ignore newlines
+ c = parseChar(doc, length, pos, TQStyleSheetItem::WhiteSpacePre);
+ if (c == TQChar::LineSeparator)
+ break;
+ } else {
+ int l = pos;
+ c = parseChar(doc, length, pos, curtag.wsm);
+
+ // in white space pre mode: treat any space as non breakable
+ // and expand tabs to eight character wide columns.
+ if (curtag.wsm == TQStyleSheetItem::WhiteSpacePre) {
+ if (c == TQLatin1Char('\t')) {
+ c = TQLatin1Char(' ');
+ while((++tabExpansionColumn)%8)
+ s += c;
+ }
+ if (c == TQChar::LineSeparator)
+ tabExpansionColumn = 0;
+ else
+ tabExpansionColumn++;
+
+ }
+ if (c == TQLatin1Char(' ') || c == TQChar::LineSeparator) {
+ /* avoid overlong paragraphs by forcing a new
+ paragraph after 4096 characters. This case can
+ occur when loading undiscovered plain text
+ documents in rich text mode. Instead of hanging
+ forever, we do the trick.
+ */
+ if (curtag.wsm == TQStyleSheetItem::WhiteSpaceNormal && s.length() > 4096) do {
+ if (doc[l] == TQLatin1Char('\n')) {
+ hasNewPar = false; // for a new paragraph ...
+ NEWPAR;
+ hasNewPar = false; // ... and make it non-reusable
+ c = TQLatin1Char('\n'); // make sure we break below
+ break;
+ }
+ } while (++l < pos);
+ }
+ }
+
+ if (c == TQLatin1Char('\n'))
+ break; // break on newlines, pre delievers a TQChar::LineSeparator
+
+ bool c_isSpace = c.isSpace() && c.unicode() != 0x00a0U && !textEditMode;
+
+ if (curtag.wsm == TQStyleSheetItem::WhiteSpaceNormal && c_isSpace && space)
+ continue;
+ if (c == TQLatin1Char('\r'))
+ continue;
+ space = c_isSpace;
+ s += c;
+ }
+ if (!s.isEmpty() && curtag.style->displayMode() != TQStyleSheetItem::DisplayNone) {
+ hasNewPar = false;
+ int index = qMax(curpar->length(),1) - 1;
+ curpar->append(s);
+ if (curtag.wsm != TQStyleSheetItem::WhiteSpaceNormal) {
+ TQTextString *str = curpar->string();
+ for (int i = index; i < index + s.length(); ++i)
+ str->at(i).nobreak = true;
+ }
+
+ TQTextFormat* f = formatCollection()->format(&curtag.format);
+ curpar->setFormat(index, s.length(), f, false); // do not use collection because we have done that already
+ f->ref += s.length() -1; // that what friends are for...
+ if (!curtag.anchorHref.isEmpty()) {
+ for (int i = 0; i < int(s.length()); i++)
+ curpar->at(index + i)->setAnchor(TQString(), curtag.anchorHref);
+ }
+ if (!anchorName.isEmpty() ) {
+ for (int i = 0; i < int(s.length()); i++)
+ curpar->at(index + i)->setAnchor(anchorName, curpar->at(index + i)->anchorHref());
+ anchorName.clear();
+ }
+ }
+ }
+ }
+
+ if (hasNewPar && curpar != fParag && !cursor && stylesPar != curpar) {
+ // cleanup unused last paragraphs
+ curpar = curpar->p;
+ delete curpar->n;
+ }
+
+ if (!anchorName.isEmpty() ) {
+ curpar->at(curpar->length() - 1)->setAnchor(anchorName, curpar->at(curpar->length() - 1)->anchorHref());
+ anchorName.clear();
+ }
+
+ setRichTextMarginsInternal(styles, stylesPar);
+
+ if (cursor) {
+ cursor->gotoPreviousLetter();
+ cursor->remove();
+ }
+ while (!styles.isEmpty())
+ delete styles.takeFirst();
+ delete vec;
+}
+
+void TQTextDocument::setRichTextMarginsInternal(QList< QVector<TQStyleSheetItem *> *>& styles, TQTextParagraph* stylesPar)
+{
+ // margin and line spacing calculation
+ // qDebug("setRichTextMarginsInternal: styles.size() = %d", styles.size());
+ QVector<TQStyleSheetItem *>* prevStyle = 0;
+ int stylesIndex = 0;
+ QVector<TQStyleSheetItem *>* curStyle = styles.size() ? styles.first() : 0;
+ QVector<TQStyleSheetItem *>* nextStyle =
+ (++stylesIndex) < styles.size() ? styles.at(stylesIndex) : 0;
+ while (stylesPar) {
+ if (!curStyle) {
+ stylesPar = stylesPar->next();
+ prevStyle = curStyle;
+ curStyle = nextStyle;
+ nextStyle = (++stylesIndex) < styles.size() ? styles.at(stylesIndex) : 0;
+ continue;
+ }
+
+ int i, mar;
+ TQStyleSheetItem* mainStyle = curStyle->size() ? (*curStyle)[curStyle->size()-1] : 0;
+ if (mainStyle && mainStyle->displayMode() == TQStyleSheetItem::DisplayListItem)
+ stylesPar->setListItem(true);
+ int numLists = 0;
+ for (i = 0; i < (int)curStyle->size(); ++i) {
+ if ((*curStyle)[i]->displayMode() == TQStyleSheetItem::DisplayBlock
+ && (*curStyle)[i]->listStyle() != TQStyleSheetItem::ListStyleUndefined)
+ numLists++;
+ }
+ stylesPar->ldepth = numLists;
+ if (stylesPar->next() && nextStyle) {
+ // also set the depth of the next paragraph, required for the margin calculation
+ numLists = 0;
+ for (i = 0; i < (int)nextStyle->size(); ++i) {
+ if ((*nextStyle)[i]->displayMode() == TQStyleSheetItem::DisplayBlock
+ && (*nextStyle)[i]->listStyle() != TQStyleSheetItem::ListStyleUndefined)
+ numLists++;
+ }
+ stylesPar->next()->ldepth = numLists;
+ }
+
+ // do the top margin
+ TQStyleSheetItem* item = mainStyle;
+ int m;
+ if (stylesPar->utm > 0) {
+ m = stylesPar->utm-1;
+ stylesPar->utm = 0;
+ } else {
+ m = qMax(0, item->margin(TQStyleSheetItem::MarginTop));
+ if (stylesPar->ldepth) {
+ if (item->displayMode() == TQStyleSheetItem::DisplayListItem)
+ m /= stylesPar->ldepth * stylesPar->ldepth;
+ else
+ m = 0;
+ }
+ }
+ for (i = (int)curStyle->size() - 2 ; i >= 0; --i) {
+ item = (*curStyle)[i];
+ if (prevStyle && i < (int) prevStyle->size() &&
+ ( item->displayMode() == TQStyleSheetItem::DisplayBlock &&
+ (*prevStyle)[i] == item))
+ break;
+ // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags
+ if (item->listStyle() != TQStyleSheetItem::ListStyleUndefined &&
+ (( i> 0 && (*curStyle)[i-1] == item) || (*curStyle)[i+1] == item))
+ continue;
+ mar = qMax(0, item->margin(TQStyleSheetItem::MarginTop));
+ m = qMax(m, mar);
+ }
+ stylesPar->utm = m - stylesPar->topMargin();
+
+ // do the bottom margin
+ item = mainStyle;
+ if (stylesPar->ubm > 0) {
+ m = stylesPar->ubm-1;
+ stylesPar->ubm = 0;
+ } else {
+ m = qMax(0, item->margin(TQStyleSheetItem::MarginBottom));
+ if (stylesPar->ldepth) {
+ if (item->displayMode() == TQStyleSheetItem::DisplayListItem)
+ m /= stylesPar->ldepth * stylesPar->ldepth;
+ else
+ m = 0;
+ }
+ }
+ for (i = (int)curStyle->size() - 2 ; i >= 0; --i) {
+ item = (*curStyle)[i];
+ if (nextStyle && i < (int) nextStyle->size() &&
+ ( item->displayMode() == TQStyleSheetItem::DisplayBlock &&
+ (*nextStyle)[i] == item))
+ break;
+ // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags
+ if (item->listStyle() != TQStyleSheetItem::ListStyleUndefined &&
+ (( i> 0 && (*curStyle)[i-1] == item) || (*curStyle)[i+1] == item))
+ continue;
+ mar = qMax(0, item->margin(TQStyleSheetItem::MarginBottom));
+ m = qMax(m, mar);
+ }
+ stylesPar->ubm = m - stylesPar->bottomMargin();
+
+ // do the left margin, simplyfied
+ item = mainStyle;
+ if (stylesPar->ulm > 0) {
+ m = stylesPar->ulm-1;
+ stylesPar->ulm = 0;
+ } else {
+ m = qMax(0, item->margin(TQStyleSheetItem::MarginLeft));
+ }
+ for (i = (int)curStyle->size() - 2 ; i >= 0; --i) {
+ item = (*curStyle)[i];
+ m += qMax(0, item->margin(TQStyleSheetItem::MarginLeft));
+ }
+ stylesPar->ulm = m - stylesPar->leftMargin();
+
+ // do the right margin, simplyfied
+ item = mainStyle;
+ if (stylesPar->urm > 0) {
+ m = stylesPar->urm-1;
+ stylesPar->urm = 0;
+ } else {
+ m = qMax(0, item->margin(TQStyleSheetItem::MarginRight));
+ }
+ for (i = (int)curStyle->size() - 2 ; i >= 0; --i) {
+ item = (*curStyle)[i];
+ m += qMax(0, item->margin(TQStyleSheetItem::MarginRight));
+ }
+ stylesPar->urm = m - stylesPar->rightMargin();
+
+ // do the first line margin, which really should be called text-indent
+ item = mainStyle;
+ if (stylesPar->uflm > 0) {
+ m = stylesPar->uflm-1;
+ stylesPar->uflm = 0;
+ } else {
+ m = qMax(0, item->margin(TQStyleSheetItem::MarginFirstLine));
+ }
+ for (i = (int)curStyle->size() - 2 ; i >= 0; --i) {
+ item = (*curStyle)[i];
+ mar = qMax(0, item->margin(TQStyleSheetItem::MarginFirstLine));
+ m = qMax(m, mar);
+ }
+ stylesPar->uflm =m - stylesPar->firstLineMargin();
+
+ // do the bogus line "spacing", which really is just an extra margin
+ item = mainStyle;
+ for (i = (int)curStyle->size() - 1 ; i >= 0; --i) {
+ item = (*curStyle)[i];
+ if (item->lineSpacing() != TQStyleSheetItem::Undefined) {
+ stylesPar->ulinespacing = item->lineSpacing();
+ if (formatCollection() &&
+ stylesPar->ulinespacing < formatCollection()->defaultFormat()->height())
+ stylesPar->ulinespacing += formatCollection()->defaultFormat()->height();
+ break;
+ }
+ }
+
+ stylesPar = stylesPar->next();
+ prevStyle = curStyle;
+ curStyle = nextStyle;
+ nextStyle = (++stylesIndex) < styles.size() ? styles.at(stylesIndex) : 0;
+ }
+}
+
+void TQTextDocument::setText(const TQString &text, const TQString &context)
+{
+ focusIndicator.parag = 0;
+ selections.clear();
+ if ((txtFormat == TQt::AutoText && TQStyleSheet::mightBeRichText(text))
+ || txtFormat == TQt::RichText)
+ setRichText(text, context);
+ else
+ setPlainText(text);
+}
+
+TQString TQTextDocument::plainText() const
+{
+ TQString buffer;
+ TQString s;
+ TQTextParagraph *p = fParag;
+ while (p) {
+ if (!p->mightHaveCustomItems) {
+ const TQTextString *ts = p->string(); // workaround VC++ and Borland
+ s = ts->toString(); // with false we don't fix spaces (nbsp)
+ } else {
+ for (int i = 0; i < p->length() - 1; ++i) {
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (p->at(i)->isCustom()) {
+ if (p->at(i)->customItem()->isNested()) {
+ s += TQLatin1String("\n");
+ TQTextTable *t = (TQTextTable*)p->at(i)->customItem();
+ QList<TQTextTableCell *> cells = t->tableCells();
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *c = cells.at(idx);
+ s += c->richText()->plainText() + TQLatin1String("\n");
+ }
+ s += TQLatin1String("\n");
+ }
+ } else
+#endif
+ {
+ s += p->at(i)->c;
+ }
+ }
+ }
+ s.remove(s.length() - 1, 1);
+ if (p->next())
+ s += TQLatin1String("\n");
+ buffer += s;
+ p = p->next();
+ }
+ return buffer;
+}
+
+static TQString align_to_string(int a)
+{
+ if (a & Qt::AlignRight)
+ return TQLatin1String(" align=\"right\"");
+ if (a & Qt::AlignHCenter)
+ return TQLatin1String(" align=\"center\"");
+ if (a & Qt::AlignJustify)
+ return TQLatin1String(" align=\"justify\"");
+ return TQString();
+}
+
+static TQString direction_to_string(int dir)
+{
+ if (dir != TQChar::DirON)
+ return (dir == TQChar::DirL? TQLatin1String(" dir=\"ltr\"") : TQLatin1String(" dir=\"rtl\""));
+ return TQString();
+}
+
+static TQString list_value_to_string(int v)
+{
+ if (v != -1)
+ return TQLatin1String(" listvalue=\"") + TQString::number(v) + TQLatin1Char('"');
+ return TQString();
+}
+
+static TQString list_style_to_string(int v)
+{
+ switch(v) {
+ case TQStyleSheetItem::ListDecimal: return TQLatin1String("\"1\"");
+ case TQStyleSheetItem::ListLowerAlpha: return TQLatin1String("\"a\"");
+ case TQStyleSheetItem::ListUpperAlpha: return TQLatin1String("\"A\"");
+ case TQStyleSheetItem::ListDisc: return TQLatin1String("\"disc\"");
+ case TQStyleSheetItem::ListSquare: return TQLatin1String("\"square\"");
+ case TQStyleSheetItem::ListCircle: return TQLatin1String("\"circle\"");
+ default:
+ return TQString();
+ }
+}
+
+static inline bool list_is_ordered(int v)
+{
+ return v == TQStyleSheetItem::ListDecimal ||
+ v == TQStyleSheetItem::ListLowerAlpha ||
+ v == TQStyleSheetItem::ListUpperAlpha;
+}
+
+
+static TQString margin_to_string(TQStyleSheetItem* style, int t, int b, int l, int r, int fl)
+{
+ TQString s;
+ if (l > 0)
+ s += TQString(s.size() ? TQLatin1String(";") : TQLatin1String("")) + TQLatin1String("margin-left:") +
+ TQString::number(l+qMax(0,style->margin(TQStyleSheetItem::MarginLeft))) + TQLatin1String("px");
+ if (r > 0)
+ s += TQString(s.size() ? TQLatin1String(";") : TQLatin1String("")) + TQLatin1String("margin-right:") +
+ TQString::number(r+qMax(0,style->margin(TQStyleSheetItem::MarginRight))) + TQLatin1String("px");
+ if (t > 0)
+ s += TQString(s.size() ? TQLatin1String(";") : TQLatin1String("")) + TQLatin1String("margin-top:") +
+ TQString::number(t+qMax(0,style->margin(TQStyleSheetItem::MarginTop))) + TQLatin1String("px");
+ if (b > 0)
+ s += TQString(s.size() ? TQLatin1String(";") : TQLatin1String("")) + TQLatin1String("margin-bottom:") +
+ TQString::number(b+qMax(0,style->margin(TQStyleSheetItem::MarginBottom))) + TQLatin1String("px");
+ if (fl > 0)
+ s += TQString(s.size() ? TQLatin1String(";") : TQLatin1String("")) + TQLatin1String("text-indent:") +
+ TQString::number(fl+qMax(0,style->margin(TQStyleSheetItem::MarginFirstLine))) + TQLatin1String("px");
+ if (s.size())
+ return TQLatin1String(" style=\"") + s + TQLatin1String("\"");
+ return TQString();
+}
+
+TQString TQTextDocument::richText() const
+{
+ TQString s = TQLatin1String("");
+ if (!par) {
+ s += TQLatin1String("<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:");
+ s += TQString::number(formatCollection()->defaultFormat()->font().pointSize());
+ s += TQLatin1String("pt;font-family:");
+ s += formatCollection()->defaultFormat()->font().family();
+ s += TQLatin1String("\">");
+ }
+ TQTextParagraph* p = fParag;
+
+ TQStyleSheetItem* item_p = styleSheet()->item(TQLatin1String("p"));
+ TQStyleSheetItem* item_div = styleSheet()->item(TQLatin1String("div"));
+ TQStyleSheetItem* item_ul = styleSheet()->item(TQLatin1String("ul"));
+ TQStyleSheetItem* item_ol = styleSheet()->item(TQLatin1String("ol"));
+ TQStyleSheetItem* item_li = styleSheet()->item(TQLatin1String("li"));
+ if (!item_p || !item_div || !item_ul || !item_ol || !item_li) {
+ qWarning("QTextEdit: cannot export HTML due to insufficient stylesheet (lack of p, div, ul, ol, or li)");
+ return TQString();
+ }
+ int pastListDepth = 0;
+ int listDepth = 0;
+#if 0
+ int futureListDepth = 0;
+#endif
+ QVector<int> listStyles(10);
+
+ while (p) {
+ listDepth = p->listDepth();
+ if (listDepth < pastListDepth) {
+ for (int i = pastListDepth; i > listDepth; i--)
+ s += list_is_ordered(listStyles[i]) ? TQLatin1String("</ol>") : TQLatin1String("</ul>");
+ s += TQLatin1Char('\n');
+ } else if (listDepth > pastListDepth) {
+ s += TQLatin1Char('\n');
+ listStyles.resize(qMax((int)listStyles.size(), listDepth+1));
+ TQString list_type;
+ listStyles[listDepth] = p->listStyle();
+ if (!list_is_ordered(p->listStyle()) || item_ol->listStyle() != p->listStyle())
+ list_type = TQLatin1String(" type=") + list_style_to_string(p->listStyle());
+ for (int i = pastListDepth; i < listDepth; i++) {
+ s += list_is_ordered(p->listStyle()) ? TQLatin1String("<ol") : TQLatin1String("<ul");
+ s += list_type + TQLatin1Char('>');
+ }
+ } else {
+ s += TQLatin1Char('\n');
+ }
+
+ TQString ps = p->richText();
+
+#if 0
+ // for the bottom margin we need to know whether we are at the end of a list
+ futureListDepth = 0;
+ if (listDepth > 0 && p->next())
+ futureListDepth = p->next()->listDepth();
+#endif
+
+ if (richTextExportStart && richTextExportStart->paragraph() ==p &&
+ richTextExportStart->index() == 0)
+ s += TQLatin1String("<!--StartFragment-->");
+
+ if (p->isListItem()) {
+ s += TQLatin1String("<li");
+ if (p->listStyle() != listStyles[listDepth])
+ s += TQLatin1String(" type=") + list_style_to_string(p->listStyle());
+ s += align_to_string(p->alignment());
+ s += margin_to_string(item_li, p->utm, p->ubm, p->ulm, p->urm, p->uflm);
+ s += list_value_to_string(p->listValue());
+ s += direction_to_string(p->direction());
+ s += TQLatin1Char('>');
+ s += ps;
+ s += TQLatin1String("</li>");
+ } else if (p->listDepth()) {
+ s += TQLatin1String("<div");
+ s += align_to_string(p->alignment());
+ s += margin_to_string(item_div, p->utm, p->ubm, p->ulm, p->urm, p->uflm);
+ s += direction_to_string(p->direction());
+ s += TQLatin1Char('>');
+ s += ps;
+ s += TQLatin1String("</div>");
+ } else {
+ // normal paragraph item
+ s += TQLatin1String("<p");
+ s += align_to_string(p->alignment());
+ s += margin_to_string(item_p, p->utm, p->ubm, p->ulm, p->urm, p->uflm);
+ s += direction_to_string(p->direction());
+ s += TQLatin1Char('>');
+ s += ps;
+ s += TQLatin1String("</p>");
+ }
+ pastListDepth = listDepth;
+ p = p->next();
+ }
+ while (listDepth > 0) {
+ s += list_is_ordered(listStyles[listDepth]) ? TQLatin1String("</ol>") : TQLatin1String("</ul>");
+ listDepth--;
+ }
+
+ if (!par)
+ s += TQLatin1String("\n</body></html>\n");
+
+ return s;
+}
+
+TQString TQTextDocument::text() const
+{
+ if ((txtFormat == TQt::AutoText && preferRichText) || txtFormat == TQt::RichText)
+ return richText();
+ return plainText();
+}
+
+TQString TQTextDocument::text(int parag) const
+{
+ TQTextParagraph *p = paragAt(parag);
+ if (!p)
+ return TQString();
+
+ if ((txtFormat == TQt::AutoText && preferRichText) || txtFormat == TQt::RichText)
+ return p->richText();
+ else
+ return p->string()->toString();
+}
+
+void TQTextDocument::invalidate()
+{
+ TQTextParagraph *s = fParag;
+ while (s) {
+ s->invalidate(0);
+ s = s->next();
+ }
+}
+
+void TQTextDocument::selectionStart(int id, int &paragId, int &index)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.find(id);
+ if (it == selections.end())
+ return;
+ TQTextDocumentSelection &sel = *it;
+ paragId = !sel.swapped ? sel.startCursor.paragraph()->paragId() : sel.endCursor.paragraph()->paragId();
+ index = !sel.swapped ? sel.startCursor.index() : sel.endCursor.index();
+}
+
+TQTextCursor TQTextDocument::selectionStartCursor(int id)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.find(id);
+ if (it == selections.end())
+ return TQTextCursor(this);
+ TQTextDocumentSelection &sel = *it;
+ if (sel.swapped)
+ return sel.endCursor;
+ return sel.startCursor;
+}
+
+TQTextCursor TQTextDocument::selectionEndCursor(int id)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.find(id);
+ if (it == selections.end())
+ return TQTextCursor(this);
+ TQTextDocumentSelection &sel = *it;
+ if (!sel.swapped)
+ return sel.endCursor;
+ return sel.startCursor;
+}
+
+void TQTextDocument::selectionEnd(int id, int &paragId, int &index)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.find(id);
+ if (it == selections.end())
+ return;
+ TQTextDocumentSelection &sel = *it;
+ paragId = sel.swapped ? sel.startCursor.paragraph()->paragId() : sel.endCursor.paragraph()->paragId();
+ index = sel.swapped ? sel.startCursor.index() : sel.endCursor.index();
+}
+
+void TQTextDocument::addSelection(int id)
+{
+ nSelections = qMax(nSelections, id + 1);
+}
+
+static void setSelectionEndHelper(int id, TQTextDocumentSelection &sel, TQTextCursor &start, TQTextCursor &end)
+{
+ TQTextCursor c1 = start;
+ TQTextCursor c2 = end;
+ if (sel.swapped) {
+ c1 = end;
+ c2 = start;
+ }
+
+ c1.paragraph()->removeSelection(id);
+ c2.paragraph()->removeSelection(id);
+ if (c1.paragraph() != c2.paragraph()) {
+ c1.paragraph()->setSelection(id, c1.index(), c1.paragraph()->length() - 1);
+ c2.paragraph()->setSelection(id, 0, c2.index());
+ } else {
+ c1.paragraph()->setSelection(id, qMin(c1.index(), c2.index()), qMax(c1.index(), c2.index()));
+ }
+
+ sel.startCursor = start;
+ sel.endCursor = end;
+ if (sel.startCursor.paragraph() == sel.endCursor.paragraph())
+ sel.swapped = sel.startCursor.index() > sel.endCursor.index();
+}
+
+bool TQTextDocument::setSelectionEnd(int id, const TQTextCursor &cursor)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.find(id);
+ if (it == selections.end())
+ return false;
+ TQTextDocumentSelection &sel = *it;
+
+ TQTextCursor start = sel.startCursor;
+ TQTextCursor end = cursor;
+
+ if (start == end) {
+ removeSelection(id);
+ setSelectionStart(id, cursor);
+ return true;
+ }
+
+ if (sel.endCursor.paragraph() == end.paragraph()) {
+ setSelectionEndHelper(id, sel, start, end);
+ return true;
+ }
+
+ bool inSelection = false;
+ TQTextCursor c(this);
+ TQTextCursor tmp = sel.startCursor;
+ if (sel.swapped)
+ tmp = sel.endCursor;
+ tmp.restoreState();
+ TQTextCursor tmp2 = cursor;
+ tmp2.restoreState();
+ c.setParagraph(tmp.paragraph()->paragId() < tmp2.paragraph()->paragId() ? tmp.paragraph() : tmp2.paragraph());
+ bool hadStart = false;
+ bool hadEnd = false;
+ bool hadStartParag = false;
+ bool hadEndParag = false;
+ bool hadOldStart = false;
+ bool hadOldEnd = false;
+ bool leftSelection = false;
+ sel.swapped = false;
+ for (;;) {
+ if (c == start)
+ hadStart = true;
+ if (c == end)
+ hadEnd = true;
+ if (c.paragraph() == start.paragraph())
+ hadStartParag = true;
+ if (c.paragraph() == end.paragraph())
+ hadEndParag = true;
+ if (c == sel.startCursor)
+ hadOldStart = true;
+ if (c == sel.endCursor)
+ hadOldEnd = true;
+
+ if (!sel.swapped &&
+ ((hadEnd && !hadStart)
+ || (hadEnd && hadStart && start.paragraph() == end.paragraph() && start.index() > end.index())))
+ sel.swapped = true;
+
+ if ((c == end && hadStartParag) || (c == start && hadEndParag)) {
+ TQTextCursor tmp = c;
+ tmp.restoreState();
+ if (tmp.paragraph() != c.paragraph()) {
+ int sstart = tmp.paragraph()->selectionStart(id);
+ tmp.paragraph()->removeSelection(id);
+ tmp.paragraph()->setSelection(id, sstart, tmp.index());
+ }
+ }
+
+ if (inSelection &&
+ ((c == end && hadStart) || (c == start && hadEnd)))
+ leftSelection = true;
+ else if (!leftSelection && !inSelection && (hadStart || hadEnd))
+ inSelection = true;
+
+ bool noSelectionAnymore = hadOldStart && hadOldEnd && leftSelection && !inSelection && !c.paragraph()->hasSelection(id) && c.atParagEnd();
+ c.paragraph()->removeSelection(id);
+ if (inSelection) {
+ if (c.paragraph() == start.paragraph() && start.paragraph() == end.paragraph()) {
+ c.paragraph()->setSelection(id, qMin(start.index(), end.index()), qMax(start.index(), end.index()));
+ } else if (c.paragraph() == start.paragraph() && !hadEndParag) {
+ c.paragraph()->setSelection(id, start.index(), c.paragraph()->length() - 1);
+ } else if (c.paragraph() == end.paragraph() && !hadStartParag) {
+ c.paragraph()->setSelection(id, end.index(), c.paragraph()->length() - 1);
+ } else if (c.paragraph() == end.paragraph() && hadEndParag) {
+ c.paragraph()->setSelection(id, 0, end.index());
+ } else if (c.paragraph() == start.paragraph() && hadStartParag) {
+ c.paragraph()->setSelection(id, 0, start.index());
+ } else {
+ c.paragraph()->setSelection(id, 0, c.paragraph()->length() - 1);
+ }
+ }
+
+ if (leftSelection)
+ inSelection = false;
+
+ if (noSelectionAnymore)
+ break;
+ // *ugle*hack optimization
+ TQTextParagraph *p = c.paragraph();
+ if ( p->mightHaveCustomItems || p == start.paragraph() || p == end.paragraph() || p == lastParagraph()) {
+ c.gotoNextLetter();
+ if (p == lastParagraph() && c.atParagEnd())
+ break;
+ } else {
+ if (p->document()->parent())
+ do {
+ c.gotoNextLetter();
+ } while (c.paragraph() == p);
+ else
+ c.setParagraph(p->next());
+ }
+ }
+
+ if (!sel.swapped)
+ sel.startCursor.paragraph()->setSelection(id, sel.startCursor.index(), sel.startCursor.paragraph()->length() - 1);
+
+ sel.startCursor = start;
+ sel.endCursor = end;
+ if (sel.startCursor.paragraph() == sel.endCursor.paragraph())
+ sel.swapped = sel.startCursor.index() > sel.endCursor.index();
+
+ setSelectionEndHelper(id, sel, start, end);
+
+ return true;
+}
+
+void TQTextDocument::selectAll(int id)
+{
+ removeSelection(id);
+
+ TQTextDocumentSelection sel;
+ sel.swapped = false;
+ TQTextCursor c(this);
+
+ c.setParagraph(fParag);
+ c.setIndex(0);
+ sel.startCursor = c;
+
+ c.setParagraph(lParag);
+ c.setIndex(lParag->length() - 1);
+ sel.endCursor = c;
+
+ selections.insert(id, sel);
+
+ TQTextParagraph *p = fParag;
+ while (p) {
+ p->setSelection(id, 0, p->length() - 1);
+ p = p->next();
+ }
+
+ for (int idx = 0; idx < childList.size(); ++idx) {
+ TQTextDocument *dc = childList.at(idx);
+ dc->selectAll(id);
+ }
+}
+
+bool TQTextDocument::removeSelection(int id)
+{
+ if (!selections.contains(id))
+ return false;
+
+ TQTextDocumentSelection &sel = selections[id];
+
+ TQTextCursor start = sel.swapped ? sel.endCursor : sel.startCursor;
+ TQTextCursor end = sel.swapped ? sel.startCursor : sel.endCursor;
+ TQTextParagraph* p = 0;
+ while (start != end) {
+ if (p != start.paragraph()) {
+ p = start.paragraph();
+ p->removeSelection(id);
+ //### avoid endless loop by all means necessary, did somebody mention refactoring?
+ if (!parent() && p == lParag)
+ break;
+ }
+ start.gotoNextLetter();
+ }
+ p = start.paragraph();
+ p->removeSelection(id);
+ selections.remove(id);
+ return true;
+}
+
+TQString TQTextDocument::selectedText(int id, bool asRichText) const
+{
+ QMap<int, TQTextDocumentSelection>::ConstIterator it = selections.find(id);
+ if (it == selections.end())
+ return TQString();
+
+ TQTextDocumentSelection sel = *it;
+
+
+ TQTextCursor c1 = sel.startCursor;
+ TQTextCursor c2 = sel.endCursor;
+ if (sel.swapped) {
+ c2 = sel.startCursor;
+ c1 = sel.endCursor;
+ }
+
+ /* 3.0.3 improvement: Make it possible to get a reasonable
+ selection inside a table. This approach is very conservative:
+ make sure that both cursors have the same depth level and point
+ to paragraphs within the same text document.
+
+ Meaning if you select text in two table cells, you will get the
+ entire table. This is still far better than the 3.0.2, where
+ you always got the entire table.
+
+ ### Fix this properly when refactoring
+ */
+ while (c2.nestedDepth() > c1.nestedDepth())
+ c2.oneUp();
+ while (c1.nestedDepth() > c2.nestedDepth())
+ c1.oneUp();
+ while (c1.nestedDepth() && c2.nestedDepth() &&
+ c1.paragraph()->document() != c2.paragraph()->document()) {
+ c1.oneUp();
+ c2.oneUp();
+ }
+ // do not trust sel_swapped with tables. Fix this properly when refactoring as well
+ if (c1.paragraph()->paragId() > c2.paragraph()->paragId() ||
+ (c1.paragraph() == c2.paragraph() && c1.index() > c2.index())) {
+ TQTextCursor tmp = c1;
+ c2 = c1;
+ c1 = tmp;
+ }
+
+ // end selection 3.0.3 improvement
+
+ if (asRichText && !parent()) {
+ richTextExportStart = &c1;
+ richTextExportEnd = &c2;
+
+ TQString sel = richText();
+ int from = sel.indexOf(TQLatin1String("<!--StartFragment-->"));
+ if (from >= 0) {
+ from += 20;
+ // find the previous span and move it into the start fragment before we clip it
+ TQString prevspan;
+ int pspan = sel.lastIndexOf(TQLatin1String("<span"), from-21);
+ if (pspan > sel.lastIndexOf(TQLatin1String("</span"), from-21)) {
+ int spanend = sel.indexOf(TQLatin1Char('>'), pspan);
+ prevspan = sel.mid(pspan, spanend - pspan + 1);
+ }
+ int to = sel.lastIndexOf(TQLatin1String("<!--EndFragment-->"));
+ if (from <= to)
+ sel = TQLatin1String("<!--StartFragment-->") + prevspan + sel.mid(from, to - from);
+ }
+ richTextExportStart = richTextExportEnd = 0;
+ return sel;
+ }
+
+ TQString s;
+ if (c1.paragraph() == c2.paragraph()) {
+ TQTextParagraph *p = c1.paragraph();
+ int end = c2.index();
+ if (p->at(qMax(0, end - 1))->isCustom())
+ ++end;
+ if (!p->mightHaveCustomItems) {
+ s += p->string()->toString().mid(c1.index(), end - c1.index());
+ } else {
+ for (int i = c1.index(); i < end; ++i) {
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (p->at(i)->isCustom()) {
+ if (p->at(i)->customItem()->isNested()) {
+ s += TQLatin1String("\n");
+ TQTextTable *t = (TQTextTable*)p->at(i)->customItem();
+ QList<TQTextTableCell *> cells = t->tableCells();
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *c = cells.at(idx);
+ s += c->richText()->plainText() + TQLatin1String("\n");
+ }
+ s += TQLatin1String("\n");
+ }
+ } else
+#endif
+ {
+ s += p->at(i)->c;
+ }
+ }
+ }
+ } else {
+ TQTextParagraph *p = c1.paragraph();
+ int start = c1.index();
+ while (p) {
+ int end = p == c2.paragraph() ? c2.index() : p->length() - 1;
+ if (p == c2.paragraph() && p->at(qMax(0, end - 1))->isCustom())
+ ++end;
+ if (!p->mightHaveCustomItems) {
+ s += p->string()->toString().mid(start, end - start);
+ if (p != c2.paragraph())
+ s += TQLatin1String("\n");
+ } else {
+ for (int i = start; i < end; ++i) {
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (p->at(i)->isCustom()) {
+ if (p->at(i)->customItem()->isNested()) {
+ s += TQLatin1String(TQLatin1String("\n"));
+ TQTextTable *t = (TQTextTable*)p->at(i)->customItem();
+ QList<TQTextTableCell *> cells = t->tableCells();
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *c = cells.at(idx);
+ s += c->richText()->plainText() + TQLatin1String("\n");
+ }
+ s += TQLatin1String("\n");
+ }
+ } else
+#endif
+ {
+ s += p->at(i)->c;
+ }
+ }
+ }
+ start = 0;
+ if (p == c2.paragraph())
+ break;
+ p = p->next();
+ }
+ }
+ // ### workaround for plain text export until we get proper
+ // mime types: turn unicode line seperators into the more
+ // widely understood \n. Makes copy and pasting code snipplets
+ // from within Assistent possible
+ TQChar* uc = (TQChar*) s.unicode();
+ for (int ii = 0; ii < s.length(); ii++) {
+ if (uc[(int)ii] == TQChar::LineSeparator)
+ uc[(int)ii] = TQLatin1Char('\n');
+ else if ( uc[(int)ii] == TQChar::Nbsp )
+ uc[(int)ii] = TQLatin1Char(' ');
+ }
+ return s;
+}
+
+void TQTextDocument::setFormat(int id, TQTextFormat *f, int flags)
+{
+ QMap<int, TQTextDocumentSelection>::ConstIterator it = selections.constFind(id);
+ if (it == selections.constEnd())
+ return;
+
+ TQTextDocumentSelection sel = *it;
+
+ TQTextCursor c1 = sel.startCursor;
+ TQTextCursor c2 = sel.endCursor;
+ if (sel.swapped) {
+ c2 = sel.startCursor;
+ c1 = sel.endCursor;
+ }
+
+ c2.restoreState();
+ c1.restoreState();
+
+ if (c1.paragraph() == c2.paragraph()) {
+ c1.paragraph()->setFormat(c1.index(), c2.index() - c1.index(), f, true, flags);
+ return;
+ }
+
+ c1.paragraph()->setFormat(c1.index(), c1.paragraph()->length() - c1.index(), f, true, flags);
+ TQTextParagraph *p = c1.paragraph()->next();
+ while (p && p != c2.paragraph()) {
+ p->setFormat(0, p->length(), f, true, flags);
+ p = p->next();
+ }
+ c2.paragraph()->setFormat(0, c2.index(), f, true, flags);
+}
+
+void TQTextDocument::removeSelectedText(int id, TQTextCursor *cursor)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.find(id);
+ if (it == selections.end())
+ return;
+
+ TQTextDocumentSelection sel = *it;
+ TQTextCursor c1 = sel.startCursor;
+ TQTextCursor c2 = sel.endCursor;
+ if (sel.swapped) {
+ c2 = sel.startCursor;
+ c1 = sel.endCursor;
+ }
+
+ // ### no support for editing tables yet
+ if (c1.nestedDepth() || c2.nestedDepth())
+ return;
+
+ c2.restoreState();
+ c1.restoreState();
+
+ *cursor = c1;
+ removeSelection(id);
+
+ if (c1.paragraph() == c2.paragraph()) {
+ c1.paragraph()->remove(c1.index(), c2.index() - c1.index());
+ return;
+ }
+
+ if (c1.paragraph() == fParag && c1.index() == 0 &&
+ c2.paragraph() == lParag && c2.index() == lParag->length() - 1)
+ cursor->setValid(false);
+
+ bool didGoLeft = false;
+ if ( c1.index() == 0 && c1.paragraph() != fParag) {
+ cursor->gotoPreviousLetter();
+ didGoLeft = cursor->isValid();
+ }
+
+ c1.paragraph()->remove(c1.index(), c1.paragraph()->length() - 1 - c1.index());
+ TQTextParagraph *p = c1.paragraph()->next();
+ int dy = 0;
+ TQTextParagraph *tmp;
+ while (p && p != c2.paragraph()) {
+ tmp = p->next();
+ dy -= p->rect().height();
+ delete p;
+ p = tmp;
+ }
+ c2.paragraph()->remove(0, c2.index());
+ while (p) {
+ p->move(dy);
+ p->invalidate(0);
+ p->setEndState(-1);
+ p = p->next();
+ }
+
+
+ c1.paragraph()->join(c2.paragraph());
+
+ if (didGoLeft)
+ cursor->gotoNextLetter();
+}
+
+void TQTextDocument::indentSelection(int id)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.find(id);
+ if (it == selections.end())
+ return;
+
+ TQTextDocumentSelection sel = *it;
+ TQTextParagraph *startParag = sel.startCursor.paragraph();
+ TQTextParagraph *endParag = sel.endCursor.paragraph();
+ if (sel.endCursor.paragraph()->paragId() < sel.startCursor.paragraph()->paragId()) {
+ endParag = sel.startCursor.paragraph();
+ startParag = sel.endCursor.paragraph();
+ }
+
+ TQTextParagraph *p = startParag;
+ while (p && p != endParag) {
+ p->indent();
+ p = p->next();
+ }
+}
+
+void TQTextCommandHistory::clear()
+{
+ while (!history.isEmpty())
+ delete history.takeFirst();
+ current = -1;
+}
+
+void TQTextDocument::addCommand(TQTextCommand *cmd)
+{
+ commandHistory->addCommand(cmd);
+}
+
+TQTextCursor *TQTextDocument::undo(TQTextCursor *c)
+{
+ return commandHistory->undo(c);
+}
+
+TQTextCursor *TQTextDocument::redo(TQTextCursor *c)
+{
+ return commandHistory->redo(c);
+}
+
+bool TQTextDocument::find(TQTextCursor& cursor, const TQString &expr, bool cs, bool wo, bool forward)
+{
+ Qt::CaseSensitivity caseSensitive = cs ? Qt::CaseSensitive : Qt::CaseInsensitive;
+ removeSelection(Standard);
+ if (expr.isEmpty())
+ return false;
+ for (;;) {
+ TQString s = cursor.paragraph()->string()->toString();
+ int start = cursor.index();
+ for (;;) {
+ int res = forward
+ ? s.indexOf(expr, start, caseSensitive)
+ : s.lastIndexOf(expr, start, caseSensitive);
+ int end = res + expr.length();
+ if (res == -1 || (!forward && start <= res))
+ break;
+ if (!wo || ((res == 0 || !s[res-1].isLetterOrNumber())
+ && (end == (int)s.length() || !s[end].isLetterOrNumber()))) {
+ removeSelection(Standard);
+ cursor.setIndex(forward ? end : res);
+ setSelectionStart(Standard, cursor);
+ cursor.setIndex(forward ? res : end);
+ setSelectionEnd(Standard, cursor);
+ if (!forward)
+ cursor.setIndex(res);
+ return true;
+ }
+ start = res + (forward ? 1 : -1);
+ }
+ if (forward) {
+ if (cursor.paragraph() == lastParagraph() && cursor.atParagEnd())
+ break;
+ cursor.gotoNextLetter();
+ } else {
+ if (cursor.paragraph() == firstParagraph() && cursor.atParagStart())
+ break;
+ cursor.gotoPreviousLetter();
+ }
+ }
+ return false;
+}
+
+void TQTextDocument::setTextFormat(TQt::TextFormat f)
+{
+ txtFormat = f;
+ if (fParag == lParag && fParag->length() <= 1)
+ fParag->rtext = (f == TQt::RichText);
+}
+
+TQt::TextFormat TQTextDocument::textFormat() const
+{
+ return txtFormat;
+}
+
+bool TQTextDocument::inSelection(int selId, const QPoint &pos) const
+{
+ QMap<int, TQTextDocumentSelection>::ConstIterator it = selections.find(selId);
+ if (it == selections.end())
+ return false;
+
+ TQTextDocumentSelection sel = *it;
+ TQTextParagraph *startParag = sel.startCursor.paragraph();
+ TQTextParagraph *endParag = sel.endCursor.paragraph();
+ if (sel.startCursor.paragraph() == sel.endCursor.paragraph() &&
+ sel.startCursor.paragraph()->selectionStart(selId) == sel.endCursor.paragraph()->selectionEnd(selId))
+ return false;
+ if (sel.endCursor.paragraph()->paragId() < sel.startCursor.paragraph()->paragId()) {
+ endParag = sel.startCursor.paragraph();
+ startParag = sel.endCursor.paragraph();
+ }
+
+ TQTextParagraph *p = startParag;
+ while (p) {
+ if (p->rect().contains(pos)) {
+ bool inSel = false;
+ int selStart = p->selectionStart(selId);
+ int selEnd = p->selectionEnd(selId);
+ int y = 0;
+ int h = 0;
+ for (int i = 0; i < p->length(); ++i) {
+ if (i == selStart)
+ inSel = true;
+ if (i == selEnd)
+ break;
+ if (p->at(i)->lineStart) {
+ y = (*p->lineStarts.find(i))->y;
+ h = (*p->lineStarts.find(i))->h;
+ }
+ if (pos.y() - p->rect().y() >= y && pos.y() - p->rect().y() <= y + h) {
+ if (inSel && pos.x() >= p->at(i)->x &&
+ pos.x() <= p->at(i)->x + p->at(i)->format()->width(p->at(i)->c))
+ return true;
+ }
+ }
+ }
+ if (pos.y() < p->rect().y())
+ break;
+ if (p == endParag)
+ break;
+ p = p->next();
+ }
+
+ return false;
+}
+
+void TQTextDocument::doLayout(TQPainter *p, int w)
+{
+ minw = wused = 0;
+ if (!is_printer(p))
+ p = 0;
+ withoutDoubleBuffer = (p != 0);
+ TQPainter * oldPainter = TQTextFormat::painter();
+ TQTextFormat::setPainter(p);
+ tStopWidth = formatCollection()->defaultFormat()->width( TQLatin1Char('x') ) * 8;
+ flow_->setWidth(w);
+ cw = w;
+ vw = w;
+ TQTextParagraph *parag = fParag;
+ while (parag) {
+ parag->invalidate(0);
+ if (p)
+ parag->adjustToPainter(p);
+ parag->format();
+ parag = parag->next();
+ }
+ TQTextFormat::setPainter(oldPainter);
+}
+
+TQPixmap *TQTextDocument::bufferPixmap(const QSize &s)
+{
+ if (!buf_pixmap)
+ buf_pixmap = new TQPixmap(s.expandedTo(QSize(1,1)));
+ else if (buf_pixmap->size() != s)
+ buf_pixmap->resize(s.expandedTo(buf_pixmap->size()));
+ return buf_pixmap;
+}
+
+void TQTextDocument::draw(TQPainter *p, const TQRect &rect, const QPalette &pal,
+ const TQBrush *paper)
+{
+ if (!firstParagraph())
+ return;
+
+ if (paper) {
+ p->setBrushOrigin(-qIntCast(p->translationX()),
+ -qIntCast(p->translationY()));
+
+ p->fillRect(rect, *paper);
+ }
+
+ TQPainter * oldPainter = TQTextFormat::painter();
+ TQTextFormat::setPainter(p);
+
+ if (formatCollection()->defaultFormat()->color() != pal.text().color())
+ setDefaultFormat(formatCollection()->defaultFormat()->font(), pal.text().color());
+
+ TQTextParagraph *parag = firstParagraph();
+ while (parag) {
+ if (!parag->isValid())
+ parag->format();
+ int y = parag->rect().y();
+ TQRect pr(parag->rect());
+ pr.setX(0);
+ pr.setWidth(QWIDGETSIZE_MAX);
+ if (!rect.isNull() && !rect.intersects(pr)) {
+ parag = parag->next();
+ continue;
+ }
+ p->translate(0, y);
+ if (rect.isValid())
+ parag->paint(*p, pal, 0, false, rect.x(), rect.y(), rect.width(), rect.height());
+ else
+ parag->paint(*p, pal, 0, false);
+ p->translate(0, -y);
+ parag = parag->next();
+ if (!flow()->isEmpty())
+ flow()->drawFloatingItems(p, rect.x(), rect.y(), rect.width(), rect.height(), pal, false);
+ }
+ TQTextFormat::setPainter(oldPainter);
+}
+
+void TQTextDocument::drawParagraph(TQPainter *painter, TQTextParagraph *parag, int cx, int cy,
+ int cw, int ch,
+ TQPixmap *&/*doubleBuffer*/, const QPalette &pal,
+ bool drawCursor, TQTextCursor *cursor, bool resetChanged)
+{
+ if (resetChanged)
+ parag->setChanged(false);
+ TQRect ir(parag->rect());
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (!parag->tableCell())
+#endif
+ ir.setWidth(width());
+
+ painter->translate(ir.x(), ir.y());
+
+ if (!parag->document()->parent()) {
+ const QPoint oldOrigin = painter->brushOrigin();
+ painter->setBrushOrigin(-ir.topLeft());
+ painter->fillRect(TQRect(0, 0, ir.width(), ir.height()), parag->backgroundBrush(pal));
+ painter->setBrushOrigin(oldOrigin);
+ }
+
+ painter->translate(-(ir.x() - parag->rect().x()),
+ -(ir.y() - parag->rect().y()));
+ parag->paint(*painter, pal, drawCursor ? cursor : 0, true, cx, cy, cw, ch);
+
+ painter->translate(-ir.x(), -ir.y());
+
+ parag->document()->nextDoubleBuffered = false;
+}
+
+TQTextParagraph *TQTextDocument::draw(TQPainter *p, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool onlyChanged, bool drawCursor,
+ TQTextCursor *cursor, bool resetChanged)
+{
+ if (withoutDoubleBuffer || (par && par->withoutDoubleBuffer)) {
+ withoutDoubleBuffer = true;
+ TQRect r;
+ draw(p, r, pal);
+ return 0;
+ }
+ withoutDoubleBuffer = false;
+
+ if (!firstParagraph())
+ return 0;
+
+ TQPainter * oldPainter = TQTextFormat::painter();
+ TQTextFormat::setPainter(p);
+ if (formatCollection()->defaultFormat()->color() != pal.text().color())
+ setDefaultFormat(formatCollection()->defaultFormat()->font(), pal.text().color());
+
+ if (cx < 0 && cy < 0) {
+ cx = 0;
+ cy = 0;
+ cw = width();
+ ch = height();
+ }
+
+ TQTextParagraph *lastFormatted = 0;
+ TQTextParagraph *parag = firstParagraph();
+
+ TQPixmap *doubleBuffer = 0;
+
+ while (parag) {
+ lastFormatted = parag;
+ if (!parag->isValid())
+ parag->format();
+
+ TQRect pr = parag->rect();
+ pr.setWidth(parag->document()->width());
+ if (pr.y() > cy + ch)
+ goto floating;
+ TQRect clipr(cx, cy, cw, ch);
+ if (!pr.intersects(clipr) || (onlyChanged && !parag->hasChanged())) {
+ pr.setWidth(parag->document()->width());
+ parag = parag->next();
+ continue;
+ }
+
+ drawParagraph(p, parag, cx, cy, cw, ch, doubleBuffer, pal, drawCursor,
+ cursor, resetChanged);
+ parag = parag->next();
+ }
+
+ parag = lastParagraph();
+
+ floating:
+ if (parag->rect().y() + parag->rect().height() < parag->document()->height()) {
+ if (!parag->document()->parent()) {
+ TQRect fillRect = TQRect(0, parag->rect().y() + parag->rect().height(), parag->document()->width(),
+ parag->document()->height() - (parag->rect().y() + parag->rect().height()));
+ if (TQRect(cx, cy, cw, ch).intersects(fillRect))
+ p->fillRect(fillRect, pal.brush(QPalette::Base));
+ }
+ if (!flow()->isEmpty()) {
+ TQRect cr(cx, cy, cw, ch);
+ flow()->drawFloatingItems(p, cr.x(), cr.y(), cr.width(), cr.height(), pal, false);
+ }
+ }
+
+ if (buf_pixmap && buf_pixmap->height() > 300) {
+ delete buf_pixmap;
+ buf_pixmap = 0;
+ }
+
+ TQTextFormat::setPainter(oldPainter);
+ return lastFormatted;
+}
+
+/*
+ #### this function only sets the default font size in the format collection
+ */
+void TQTextDocument::setDefaultFormat(const QFont &font, const QColor &color)
+{
+ bool reformat = font != fCollection->defaultFormat()->font();
+ for (int idx = 0; idx < childList.size(); ++idx) {
+ TQTextDocument *dc = childList.at(idx);
+ dc->setDefaultFormat(font, color);
+ }
+ fCollection->updateDefaultFormat(font, color, sheet_);
+
+ if (!reformat)
+ return;
+ tStopWidth = formatCollection()->defaultFormat()->width(TQLatin1Char('x')) * 8;
+
+ // invalidate paragraphs and custom items
+ TQTextParagraph *p = fParag;
+ while (p) {
+ p->invalidate(0);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ for (int i = 0; i < p->length() - 1; ++i)
+ if (p->at(i)->isCustom())
+ p->at(i)->customItem()->invalidate();
+#endif
+ p = p->next();
+ }
+}
+
+
+/*!
+ \preliminary
+
+ Generates an internal object for the tag called \a name, given the
+ attributes \a attr, and using additional information provided by
+ the mime source factory \a factory.
+
+ \a context is the optional context of the document, i.e. the path
+ to look for relative links. This becomes important if the text
+ contains relative references, for example within image tags.
+ QSimpleRichText always uses the default mime source factory (see
+ \l{TQMimeSourceFactory::defaultFactory()}) to resolve these
+ references. The context will then be used to calculate the
+ absolute path. See TQMimeSourceFactory::makeAbsolute() for details.
+
+ \a emptyTag and \a doc are for internal use only.
+
+ This function should not be used in application code.
+*/
+#ifndef QT_NO_TEXTCUSTOMITEM
+TQTextCustomItem* TQTextDocument::tag(TQStyleSheet *sheet, const TQString& name,
+ const QMap<TQString, TQString> &attr,
+ const TQString& context,
+ const TQMimeSourceFactory& factory,
+ bool /*emptyTag */, TQTextDocument *doc)
+{
+ const TQStyleSheetItem* style = sheet->item(name);
+ // first some known tags
+ if (!style)
+ return 0;
+ if (style->name() == TQLatin1String("img"))
+ return new TQTextImage(doc, attr, context, (TQMimeSourceFactory&)factory);
+ if (style->name() == TQLatin1String("hr"))
+ return new TQTextHorizontalLine(doc, attr, context, (TQMimeSourceFactory&)factory );
+ return 0;
+}
+#endif
+
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+void TQTextDocument::registerCustomItem(TQTextCustomItem *i, TQTextParagraph *p)
+{
+ if (i && i->placement() != TQTextCustomItem::PlaceInline) {
+ flow_->registerFloatingItem(i);
+ p->registerFloatingItem(i);
+ i->setParagraph(p);
+ }
+ p->mightHaveCustomItems = mightHaveCustomItems = true;
+}
+
+void TQTextDocument::unregisterCustomItem(TQTextCustomItem *i, TQTextParagraph *p)
+{
+ p->unregisterFloatingItem(i);
+ i->setParagraph(0);
+ flow_->unregisterFloatingItem(i);
+}
+#endif
+
+bool TQTextDocument::hasFocusParagraph() const
+{
+ return !!focusIndicator.parag;
+}
+
+TQString TQTextDocument::focusHref() const
+{
+ return focusIndicator.href;
+}
+
+TQString TQTextDocument::focusName() const
+{
+ return focusIndicator.name;
+}
+
+bool TQTextDocument::focusNextPrevChild(bool next)
+{
+ if (!focusIndicator.parag) {
+ if (next) {
+ focusIndicator.parag = fParag;
+ focusIndicator.start = 0;
+ focusIndicator.len = 0;
+ } else {
+ focusIndicator.parag = lParag;
+ focusIndicator.start = lParag->length();
+ focusIndicator.len = 0;
+ }
+ } else {
+ focusIndicator.parag->setChanged(true);
+ }
+ focusIndicator.href.clear();
+ focusIndicator.name.clear();
+
+ if (next) {
+ TQTextParagraph *p = focusIndicator.parag;
+ int index = focusIndicator.start + focusIndicator.len;
+ while (p) {
+ for (int i = index; i < p->length(); ++i) {
+ if (p->at(i)->isAnchor()) {
+ p->setChanged(true);
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = p->at(i)->anchorHref();
+ focusIndicator.name = p->at(i)->anchorName();
+ while (i < p->length()) {
+ if (!p->at(i)->isAnchor())
+ return true;
+ focusIndicator.len++;
+ i++;
+ }
+#ifndef QT_NO_TEXTCUSTOMITEM
+ } else if (p->at(i)->isCustom()) {
+ if (p->at(i)->customItem()->isNested()) {
+ TQTextTable *t = (TQTextTable*)p->at(i)->customItem();
+ QList<TQTextTableCell *> cells = t->tableCells();
+ // first try to continue
+ int idx;
+ bool resetCells = true;
+ for (idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *c = cells.at(idx);
+ if (c->richText()->hasFocusParagraph()) {
+ if (c->richText()->focusNextPrevChild(next)) {
+ p->setChanged(true);
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return true;
+ } else {
+ resetCells = false;
+ ++idx;
+ break;
+ }
+ }
+ }
+ // now really try
+ if (resetCells)
+ idx = 0;
+ for (; idx < cells.size(); ++idx) {
+ TQTextTableCell *c = cells.at(idx);
+ if (c->richText()->focusNextPrevChild(next)) {
+ p->setChanged(true);
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return true;
+ }
+ }
+ }
+#endif
+ }
+ }
+ index = 0;
+ p = p->next();
+ }
+ } else {
+ TQTextParagraph *p = focusIndicator.parag;
+ int index = focusIndicator.start - 1;
+ if (focusIndicator.len == 0 && index < focusIndicator.parag->length() - 1)
+ index++;
+ while (p) {
+ for (int i = index; i >= 0; --i) {
+ if (p->at(i)->isAnchor()) {
+ p->setChanged(true);
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = p->at(i)->anchorHref();
+ focusIndicator.name = p->at(i)->anchorName();
+ while (i >= -1) {
+ if (i < 0 || !p->at(i)->isAnchor()) {
+ focusIndicator.start++;
+ return true;
+ }
+ if (i < 0)
+ break;
+ focusIndicator.len++;
+ focusIndicator.start--;
+ i--;
+ }
+#ifndef QT_NO_TEXTCUSTOMITEM
+ } else if (p->at(i)->isCustom()) {
+ if (p->at(i)->customItem()->isNested()) {
+ TQTextTable *t = (TQTextTable*)p->at(i)->customItem();
+ QList<TQTextTableCell *> cells = t->tableCells();
+ // first try to continue
+ int idx;
+ bool resetCells = true;
+ for (idx = cells.size()-1; idx >= 0; --idx) {
+ TQTextTableCell *c = cells.at(idx);
+ if (c->richText()->hasFocusParagraph()) {
+ if (c->richText()->focusNextPrevChild(next)) {
+ p->setChanged(true);
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return true;
+ } else {
+ resetCells = false;
+ --idx;
+ break;
+ }
+ }
+ }
+ // now really try
+ if (resetCells)
+ idx = cells.size()-1;
+ for (; idx >= 0; --idx) {
+ TQTextTableCell *c = cells.at(idx);
+ if (c->richText()->focusNextPrevChild(next)) {
+ p->setChanged(true);
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return true;
+ }
+ }
+ }
+#endif
+ }
+ }
+ p = p->prev();
+ if (p)
+ index = p->length() - 1;
+ }
+ }
+
+ focusIndicator.parag = 0;
+
+ return false;
+}
+
+int TQTextDocument::length() const
+{
+ int l = -1;
+ TQTextParagraph *p = fParag;
+ while (p) {
+ l += p->length();
+ p = p->next();
+ }
+ return qMax(0,l);
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+int TQTextFormat::width(const TQChar &c) const
+{
+ if (c.unicode() == 0xad) // soft hyphen
+ return 0;
+ if (!pntr || !pntr->isActive()) {
+ if (c == TQLatin1Char('\t'))
+ return fm.width(TQLatin1Char(' '));
+ if (ha == AlignNormal) {
+ int w;
+ if (c.row())
+ w = fm.width(c);
+ else
+ w = widths[c.unicode()];
+ if (w == 0 && !c.row()) {
+ w = fm.width(c);
+ ((TQTextFormat*)this)->widths[c.unicode()] = w;
+ }
+ return w;
+ } else {
+ QFont f(fn);
+ if (usePixelSizes)
+ f.setPixelSize((f.pixelSize() * 2) / 3);
+ else
+ f.setPointSize((f.pointSize() * 2) / 3);
+ QFontMetrics fm_(f);
+ return fm_.width(c);
+ }
+ }
+
+ QFont f(fn);
+ if (ha != AlignNormal) {
+ if (usePixelSizes)
+ f.setPixelSize((f.pixelSize() * 2) / 3);
+ else
+ f.setPointSize((f.pointSize() * 2) / 3);
+ }
+ applyFont(f);
+
+ return pntr_fm->width(c);
+}
+
+int TQTextFormat::width(const TQString &str, int pos) const
+{
+ int w = 0;
+ if (str.unicode()[pos].unicode() == 0xad)
+ return w;
+ if (!pntr || !pntr->isActive()) {
+ if (ha == AlignNormal) {
+ w = fm.charWidth(str, pos);
+ } else {
+ QFont f(fn);
+ if (usePixelSizes)
+ f.setPixelSize((f.pixelSize() * 2) / 3);
+ else
+ f.setPointSize((f.pointSize() * 2) / 3);
+ QFontMetrics fm_(f);
+ w = fm_.charWidth(str, pos);
+ }
+ } else {
+ QFont f(fn);
+ if (ha != AlignNormal) {
+ if (usePixelSizes)
+ f.setPixelSize((f.pixelSize() * 2) / 3);
+ else
+ f.setPointSize((f.pointSize() * 2) / 3);
+ }
+ applyFont(f);
+ w = pntr_fm->charWidth(str, pos);
+ }
+ return w;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextString::TQTextString()
+{
+ bidiDirty = true;
+ bidi = false;
+ rightToLeft = false;
+ dir = TQChar::DirON;
+}
+
+TQTextString::TQTextString(const TQTextString &s)
+{
+ bidiDirty = true;
+ bidi = s.bidi;
+ rightToLeft = s.rightToLeft;
+ dir = s.dir;
+ data = s.data;
+ data.detach();
+ for (int i = 0; i < (int)data.size(); ++i) {
+ TQTextFormat *f = data[i].format();
+ if (f)
+ f->addRef();
+ }
+}
+
+void TQTextString::insert(int index, const QString &s, TQTextFormat *f)
+{
+ insert(index, s.unicode(), s.length(), f);
+}
+
+void TQTextString::insert(int index, const QChar *unicode, int len, TQTextFormat *f)
+{
+ int os = data.size();
+ data.resize(data.size() + len);
+ if (index < os) {
+ memmove(data.data() + index + len, data.data() + index,
+ sizeof(TQTextStringChar) * (os - index));
+ }
+ TQTextStringChar *ch = data.data() + index;
+ for (int i = 0; i < len; ++i) {
+ ch->x = 0;
+ ch->lineStart = 0;
+ ch->nobreak = false;
+ ch->type = TQTextStringChar::Regular;
+ ch->p.format = f;
+ ch->rightToLeft = 0;
+ ch->c = unicode[i];
+ ++ch;
+ }
+ bidiDirty = true;
+}
+
+TQTextString::~TQTextString()
+{
+ clear();
+}
+
+void TQTextString::insert(int index, TQTextStringChar *c, bool doAddRefFormat )
+{
+ int os = data.size();
+ data.resize(data.size() + 1);
+ if (index < os) {
+ memmove(data.data() + index + 1, data.data() + index,
+ sizeof(TQTextStringChar) * (os - index));
+ }
+ TQTextStringChar &ch = data[(int)index];
+ ch.c = c->c;
+ ch.x = 0;
+ ch.lineStart = 0;
+ ch.rightToLeft = 0;
+ ch.p.format = 0;
+ ch.type = TQTextStringChar::Regular;
+ ch.nobreak = false;
+ if (doAddRefFormat && c->format())
+ c->format()->addRef();
+ ch.setFormat(c->format());
+ bidiDirty = true;
+}
+
+int TQTextString::appendParagraphs( TQTextParagraph *start, TQTextParagraph *end )
+{
+ int paragCount = 0;
+ int newLength = data.size();
+ for (TQTextParagraph *p = start; p != end; p = p->next()) {
+ newLength += p->length();
+ ++paragCount;
+ }
+
+ const int oldLength = data.size();
+ data.resize(newLength);
+
+ TQTextStringChar *d = &data[oldLength];
+ for (TQTextParagraph *p = start; p != end; p = p->next()) {
+ const TQTextStringChar * const src = p->at(0);
+ int i = 0;
+ for (; i < p->length() - 1; ++i) {
+ d[i].c = src[i].c;
+ d[i].x = 0;
+ d[i].lineStart = 0;
+ d[i].rightToLeft = 0;
+ d[i].type = TQTextStringChar::Regular;
+ d[i].nobreak = false;
+ d[i].p.format = src[i].format();
+ if (d[i].p.format)
+ d[i].p.format->addRef();
+ }
+ d[i].x = 0;
+ d[i].lineStart = 0;
+ d[i].nobreak = false;
+ d[i].type = TQTextStringChar::Regular;
+ d[i].p.format = 0;
+ d[i].rightToLeft = 0;
+ d[i].c = TQLatin1Char('\n');
+ d += p->length();
+ }
+
+ bidiDirty = true;
+ return paragCount;
+}
+
+void TQTextString::truncate(int index)
+{
+ index = qMax(index, 0);
+ index = qMin(index, (int)data.size() - 1);
+ if (index < (int)data.size()) {
+ for (int i = index + 1; i < (int)data.size(); ++i) {
+ TQTextStringChar &ch = data[i];
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (!(ch.type == TQTextStringChar::Regular)) {
+ delete ch.customItem();
+ if (ch.p.custom->format)
+ ch.p.custom->format->removeRef();
+ delete ch.p.custom;
+ ch.p.custom = 0;
+ } else
+#endif
+ if (ch.format()) {
+ ch.format()->removeRef();
+ }
+ }
+ }
+ data.resize(index);
+ bidiDirty = true;
+}
+
+void TQTextString::remove(int index, int len)
+{
+ for (int i = index; i < (int)data.size() && i - index < len; ++i) {
+ TQTextStringChar &ch = data[i];
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (!(ch.type == TQTextStringChar::Regular)) {
+ delete ch.customItem();
+ if (ch.p.custom->format)
+ ch.p.custom->format->removeRef();
+ delete ch.p.custom;
+ ch.p.custom = 0;
+ } else
+#endif
+ if (ch.format()) {
+ ch.format()->removeRef();
+ }
+ }
+ memmove(data.data() + index, data.data() + index + len,
+ sizeof(TQTextStringChar) * (data.size() - index - len));
+ data.resize(data.size() - len);
+ bidiDirty = true;
+}
+
+void TQTextString::clear()
+{
+ for (int i = 0; i < (int)data.count(); ++i) {
+ TQTextStringChar &ch = data[i];
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (!(ch.type == TQTextStringChar::Regular)) {
+ if (ch.customItem() && ch.customItem()->placement() == TQTextCustomItem::PlaceInline)
+ delete ch.customItem();
+ if (ch.p.custom->format)
+ ch.p.custom->format->removeRef();
+ delete ch.p.custom;
+ ch.p.custom = 0;
+ } else
+#endif
+ if (ch.format()) {
+ ch.format()->removeRef();
+ }
+ }
+ data.resize(0);
+ bidiDirty = true;
+}
+
+void TQTextString::setFormat(int index, TQTextFormat *f, bool useCollection)
+{
+ TQTextStringChar &ch = data[index];
+ if (useCollection && ch.format())
+ ch.format()->removeRef();
+ ch.setFormat(f);
+}
+
+void TQTextString::checkBidi() const
+{
+ // ############ fix BIDI handling
+ TQTextString *that = (TQTextString *)this;
+ that->bidiDirty = false;
+ int length = data.size();
+ if (!length) {
+ that->bidi = rightToLeft;
+ that->rightToLeft = (dir == TQChar::DirR);
+ return;
+ }
+
+ if (dir == TQChar::DirR) {
+ that->rightToLeft = true;
+ } else if (dir == TQChar::DirL) {
+ that->rightToLeft = false;
+ } else {
+ that->rightToLeft = (QApplication::layoutDirection() == Qt::RightToLeft);
+ }
+
+ const TQTextStringChar *start = data.data();
+ const TQTextStringChar *end = start + length;
+
+ ((TQTextString *)this)->stringCache = toString(data);
+
+ // determines the properties we need for layouting
+ QTextEngine textEngine;
+ textEngine.text = toString();
+ textEngine.option.setTextDirection(rightToLeft ? Qt::RightToLeft : Qt::LeftToRight);
+ textEngine.itemize();
+ const HB_CharAttributes *ca = textEngine.attributes() + length-1;
+ TQTextStringChar *ch = (TQTextStringChar *)end - 1;
+ QScriptItem *item = &textEngine.layoutData->items[textEngine.layoutData->items.size()-1];
+ unsigned char bidiLevel = item->analysis.bidiLevel;
+ that->bidi = (bidiLevel || rightToLeft);
+ int pos = length-1;
+ while (ch >= start) {
+ if (item->position > pos) {
+ --item;
+ Q_ASSERT(item >= &textEngine.layoutData->items[0]);
+ bidiLevel = item->analysis.bidiLevel;
+ if (bidiLevel)
+ that->bidi = true;
+ }
+ ch->softBreak = ca->lineBreakType >= HB_Break;
+ ch->whiteSpace = ca->whiteSpace;
+ ch->charStop = ca->charStop;
+ ch->bidiLevel = bidiLevel;
+ ch->rightToLeft = (bidiLevel%2);
+ --ch;
+ --ca;
+ --pos;
+ }
+}
+
+void TQTextDocument::setStyleSheet(TQStyleSheet *s)
+{
+ if (!s)
+ return;
+ sheet_ = s;
+ list_tm = list_bm = par_tm = par_bm = 12;
+ list_lm = 40;
+ li_tm = li_bm = 0;
+ TQStyleSheetItem* item = s->item(TQLatin1String("ol"));
+ if (item) {
+ list_tm = qMax(0,item->margin(TQStyleSheetItem::MarginTop));
+ list_bm = qMax(0,item->margin(TQStyleSheetItem::MarginBottom));
+ list_lm = qMax(0,item->margin(TQStyleSheetItem::MarginLeft));
+ }
+ if ((item = s->item(TQLatin1String("li")))) {
+ li_tm = qMax(0,item->margin(TQStyleSheetItem::MarginTop));
+ li_bm = qMax(0,item->margin(TQStyleSheetItem::MarginBottom));
+ }
+ if ((item = s->item(TQLatin1String("p")))) {
+ par_tm = qMax(0,item->margin(TQStyleSheetItem::MarginTop));
+ par_bm = qMax(0,item->margin(TQStyleSheetItem::MarginBottom));
+ }
+}
+
+void TQTextDocument::setUnderlineLinks(bool b) {
+ underlLinks = b;
+ for (int idx = 0; idx < childList.size(); ++idx) {
+ TQTextDocument *dc = childList.at(idx);
+ dc->setUnderlineLinks(b);
+ }
+}
+
+void TQTextStringChar::setFormat(TQTextFormat *f)
+{
+ if (type == Regular) {
+ p.format = f;
+ } else {
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (!p.custom) {
+ p.custom = new CustomData;
+ p.custom->custom = 0;
+ }
+ p.custom->format = f;
+#endif
+ }
+}
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+void TQTextStringChar::setCustomItem(TQTextCustomItem *i)
+{
+ if (type == Regular) {
+ TQTextFormat *f = format();
+ p.custom = new CustomData;
+ p.custom->format = f;
+ } else {
+ delete p.custom->custom;
+ }
+ p.custom->custom = i;
+ type = (type == Anchor ? CustomAnchor : Custom);
+}
+
+void TQTextStringChar::loseCustomItem()
+{
+ if (type == Custom) {
+ TQTextFormat *f = p.custom->format;
+ p.custom->custom = 0;
+ delete p.custom;
+ type = Regular;
+ p.format = f;
+ } else if (type == CustomAnchor) {
+ p.custom->custom = 0;
+ type = Anchor;
+ }
+}
+
+#endif
+
+TQString TQTextStringChar::anchorName() const
+{
+ if (type == Regular)
+ return TQString();
+ else
+ return p.custom->anchorName;
+}
+
+TQString TQTextStringChar::anchorHref() const
+{
+ if (type == Regular)
+ return TQString();
+ else
+ return p.custom->anchorHref;
+}
+
+void TQTextStringChar::setAnchor(const TQString& name, const TQString& href)
+{
+ if (type == Regular) {
+ TQTextFormat *f = format();
+ p.custom = new CustomData;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ p.custom->custom = 0;
+#endif
+ p.custom->format = f;
+ type = Anchor;
+ } else if (type == Custom) {
+ type = CustomAnchor;
+ }
+ p.custom->anchorName = name;
+ p.custom->anchorHref = href;
+}
+
+
+int TQTextString::width(int idx) const
+{
+ int w = 0;
+ TQTextStringChar *c = &at(idx);
+ if (!c->charStop || c->c.unicode() == 0xad || c->c.unicode() == 0x2028)
+ return 0;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if(c->isCustom()) {
+ if(c->customItem()->placement() == TQTextCustomItem::PlaceInline)
+ w = c->customItem()->width;
+ } else
+#endif
+ {
+ int r = c->c.row();
+ if(r < 0x06
+#ifndef Q_WS_WIN
+ // Uniscribe's handling of Asian makes the condition below fail.
+ || (r > 0x1f && !(r > 0xd7 && r < 0xe0))
+#endif
+ ) {
+ w = c->format()->width(c->c);
+ } else {
+ // complex text. We need some hacks to get the right metric here
+ w = c->format()->width(toString(), idx);
+ }
+ }
+ return w;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextParagraph::TQTextParagraph(TQTextDocument *dc, TQTextParagraph *pr, TQTextParagraph *nx, bool updateIds)
+ : p(pr), n(nx), docOrPseudo(dc),
+ changed(false), firstFormat(true), firstPProcess(true), needPreProcess(false), fullWidth(true),
+ lastInFrame(false), visible(true), breakable(true), movedDown(false),
+ mightHaveCustomItems(false), hasdoc(dc != 0), litem(false), rtext(false),
+ align(0), lstyle(TQStyleSheetItem::ListDisc), invalid(0), mSelections(0),
+#ifndef QT_NO_TEXTCUSTOMITEM
+ mFloatingItems(0),
+#endif
+ utm(0), ubm(0), ulm(0), urm(0), uflm(0), ulinespacing(0),
+ tabStopWidth(0), minwidth(0), tArray(0), eData(0), ldepth(0)
+{
+ lstyle = TQStyleSheetItem::ListDisc;
+ if (!hasdoc)
+ docOrPseudo = new TQTextParagraphPseudoDocument;
+ bgcol = 0;
+ list_val = -1;
+ paintdevice = 0;
+ TQTextFormat* defFormat = formatCollection()->defaultFormat();
+ if (!hasdoc) {
+ tabStopWidth = defFormat->width(TQLatin1Char('x')) * 8;
+ pseudoDocument()->commandHistory = new TQTextCommandHistory(100);
+ }
+
+ if (p)
+ p->n = this;
+ if (n)
+ n->p = this;
+
+ if (!p && hasdoc)
+ document()->setFirstParagraph(this);
+ if (!n && hasdoc)
+ document()->setLastParagraph(this);
+
+ state = -1;
+
+ if (p)
+ id = p->id + 1;
+ else
+ id = 0;
+ if (n && updateIds) {
+ TQTextParagraph *s = n;
+ while (s) {
+ s->id = s->p->id + 1;
+ s->invalidateStyleCache();
+ s = s->n;
+ }
+ }
+
+ str = new TQTextString();
+ const TQChar ch(TQLatin1Char(' '));
+ str->insert(0, &ch, 1, formatCollection()->defaultFormat());
+}
+
+TQTextParagraph::~TQTextParagraph()
+{
+ delete str;
+ if (hasdoc) {
+ register TQTextDocument *doc = document();
+ if (this == doc->minwParag) {
+ doc->minwParag = 0;
+ doc->minw = 0;
+ }
+ if (this == doc->curParag)
+ doc->curParag = 0;
+ } else {
+ delete pseudoDocument();
+ }
+ delete [] tArray;
+ delete eData;
+ QMap<int, QTextLineStart*>::Iterator it = lineStarts.begin();
+ for (; it != lineStarts.end(); ++it)
+ delete *it;
+ if (mSelections)
+ delete mSelections;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (mFloatingItems)
+ delete mFloatingItems;
+#endif
+ if (p)
+ p->setNext(n);
+ if (n)
+ n->setPrev(p);
+ delete bgcol;
+}
+
+void TQTextParagraph::setNext(TQTextParagraph *s)
+{
+ n = s;
+ if (!n && hasdoc)
+ document()->setLastParagraph(this);
+}
+
+void TQTextParagraph::setPrev(TQTextParagraph *s)
+{
+ p = s;
+ if (!p && hasdoc)
+ document()->setFirstParagraph(this);
+}
+
+void TQTextParagraph::invalidate(int chr)
+{
+ if (invalid < 0)
+ invalid = chr;
+ else
+ invalid = qMin(invalid, chr);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (mFloatingItems) {
+ for (int idx = 0; idx < mFloatingItems->size(); ++idx) {
+ TQTextCustomItem *i = mFloatingItems->at(idx);
+ i->ypos = -1;
+ }
+ }
+#endif
+ invalidateStyleCache();
+}
+
+void TQTextParagraph::invalidateStyleCache()
+{
+ if (list_val < 0)
+ list_val = -1;
+}
+
+
+void TQTextParagraph::insert(int index, const QString &s)
+{
+ insert(index, s.unicode(), s.length());
+}
+
+void TQTextParagraph::insert(int index, const QChar *unicode, int len)
+{
+ if (hasdoc && !document()->useFormatCollection() && document()->preProcessor())
+ str->insert(index, unicode, len,
+ document()->preProcessor()->format(TQTextPreProcessor::Standard));
+ else
+ str->insert(index, unicode, len, formatCollection()->defaultFormat());
+ invalidate(index);
+ needPreProcess = true;
+}
+
+void TQTextParagraph::truncate(int index)
+{
+ str->truncate(index);
+ insert(length(), TQLatin1String(" "));
+ needPreProcess = true;
+}
+
+void TQTextParagraph::remove(int index, int len)
+{
+ if (index + len - str->length() > 0)
+ return;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ for (int i = index; i < index + len; ++i) {
+ TQTextStringChar *c = at(i);
+ if (hasdoc && c->isCustom()) {
+ document()->unregisterCustomItem(c->customItem(), this);
+ }
+ }
+#endif
+ str->remove(index, len);
+ invalidate(0);
+ needPreProcess = true;
+}
+
+void TQTextParagraph::join(TQTextParagraph *s)
+{
+ int oh = r.height() + s->r.height();
+ n = s->n;
+ if (n)
+ n->p = this;
+ else if (hasdoc)
+ document()->setLastParagraph(this);
+
+ int start = str->length();
+ if (length() > 0 && at(length() - 1)->c == TQLatin1Char(' ')) {
+ remove(length() - 1, 1);
+ --start;
+ }
+ append(s->str->toString(), true);
+
+ for (int i = 0; i < s->length(); ++i) {
+ if (!hasdoc || document()->useFormatCollection()) {
+ s->str->at(i).format()->addRef();
+ str->setFormat(i + start, s->str->at(i).format(), true);
+ }
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (s->str->at(i).isCustom()) {
+ TQTextCustomItem * item = s->str->at(i).customItem();
+ str->at(i + start).setCustomItem(item);
+ s->str->at(i).loseCustomItem();
+ if (hasdoc) {
+ document()->unregisterCustomItem(item, s);
+ document()->registerCustomItem(item, this);
+ }
+ }
+ if (s->str->at(i).isAnchor()) {
+ str->at(i + start).setAnchor(s->str->at(i).anchorName(),
+ s->str->at(i).anchorHref());
+ }
+#endif
+ }
+
+ if (!extraData() && s->extraData()) {
+ setExtraData(s->extraData());
+ s->setExtraData(0);
+ } else if (extraData() && s->extraData()) {
+ extraData()->join(s->extraData());
+ }
+ delete s;
+ invalidate(0);
+ r.setHeight(oh);
+ needPreProcess = true;
+ if (n) {
+ TQTextParagraph *s = n;
+ s->invalidate(0);
+ while (s) {
+ s->id = s->p->id + 1;
+ s->state = -1;
+ s->needPreProcess = true;
+ s->changed = true;
+ s->invalidateStyleCache();
+ s = s->n;
+ }
+ }
+ format();
+ state = -1;
+}
+
+void TQTextParagraph::move(int &dy)
+{
+ if (dy == 0)
+ return;
+ changed = true;
+ r.moveBy(0, dy);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (mFloatingItems) {
+ for (int idx = 0; idx < mFloatingItems->size(); ++idx) {
+ TQTextCustomItem *i = mFloatingItems->at(idx);
+ i->ypos += dy;
+ }
+ }
+#endif
+ if (p)
+ p->lastInFrame = true;
+
+ // do page breaks if required
+ if (hasdoc && document()->isPageBreakEnabled()) {
+ int shift;
+ if ((shift = document()->formatter()->formatVertically( document(), this))) {
+ if (p)
+ p->setChanged(true);
+ dy += shift;
+ }
+ }
+}
+
+void TQTextParagraph::format(int start, bool doMove)
+{
+ if (!str || str->length() == 0 || !formatter())
+ return;
+
+ if (hasdoc &&
+ document()->preProcessor() &&
+ (needPreProcess || state == -1))
+ document()->preProcessor()->process(document(), this, invalid <= 0 ? 0 : invalid);
+ needPreProcess = false;
+
+ if (invalid == -1)
+ return;
+
+ r.moveTopLeft(QPoint(documentX(), p ? p->r.y() + p->r.height() : documentY()));
+ if (p)
+ p->lastInFrame = false;
+
+ movedDown = false;
+ bool formattedAgain = false;
+
+ formatAgain:
+
+ r.setWidth(documentWidth());
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (hasdoc && mFloatingItems) {
+ for (int idx = 0; idx < mFloatingItems->size(); ++idx) {
+ TQTextCustomItem *i = mFloatingItems->at(idx);
+ i->ypos = r.y();
+ if (i->placement() == TQTextCustomItem::PlaceRight) {
+ i->xpos = r.x() + r.width() - i->width;
+ }
+ }
+ }
+#endif
+ QMap<int, QTextLineStart*> oldLineStarts = lineStarts;
+ lineStarts.clear();
+ int y = formatter()->format(document(), this, start, oldLineStarts);
+
+
+ r.setWidth(qMax(r.width(), formatter()->minimumWidth()));
+
+
+ QMap<int, QTextLineStart*>::Iterator it = oldLineStarts.begin();
+
+ for (; it != oldLineStarts.end(); ++it)
+ delete *it;
+
+ if (!hasdoc) { // qt_format_text bounding rect handling
+ it = lineStarts.begin();
+ int usedw = 0;
+ for (; it != lineStarts.end(); ++it)
+ usedw = qMax(usedw, (*it)->w);
+ if (r.width() <= 0) {
+ // if the user specifies an invalid rect, this means that the
+ // bounding box should grow to the width that the text actually
+ // needs
+ r.setWidth(usedw);
+ } else {
+ r.setWidth(qMin(usedw, r.width()));
+ }
+ }
+
+ if (y != r.height())
+ r.setHeight(y);
+
+ if (!visible) {
+ r.setHeight(0);
+ } else {
+ int minw = minwidth = formatter()->minimumWidth();
+ int wused = formatter()->widthUsed();
+ wused = qMax(minw, wused);
+ if (hasdoc) {
+ document()->setMinimumWidth(minw, wused, this);
+ } else {
+ pseudoDocument()->minw = qMax(pseudoDocument()->minw, minw);
+ pseudoDocument()->wused = qMax(pseudoDocument()->wused, wused);
+ }
+ }
+
+ // do page breaks if required
+ if (hasdoc && document()->isPageBreakEnabled()) {
+ int shift = document()->formatter()->formatVertically(document(), this);
+ if (shift && !formattedAgain) {
+ formattedAgain = true;
+ goto formatAgain;
+ }
+ }
+
+ if (n && doMove && n->invalid == -1 && r.y() + r.height() != n->r.y()) {
+ int dy = (r.y() + r.height()) - n->r.y();
+ TQTextParagraph *s = n;
+ bool makeInvalid = p && p->lastInFrame;
+ while (s && dy) {
+ if (!s->isFullWidth())
+ makeInvalid = true;
+ if (makeInvalid)
+ s->invalidate(0);
+ s->move(dy);
+ if (s->lastInFrame)
+ makeInvalid = true;
+ s = s->n;
+ }
+ }
+
+ firstFormat = false;
+ changed = true;
+ invalid = -1;
+ //##### string()->setTextChanged(false);
+}
+
+int TQTextParagraph::lineHeightOfChar(int i, int *bl, int *y) const
+{
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.end();
+ --it;
+ for (;;) {
+ if (i >= it.key()) {
+ if (bl)
+ *bl = (*it)->baseLine;
+ if (y)
+ *y = (*it)->y;
+ return (*it)->h;
+ }
+ if (it == lineStarts.begin())
+ break;
+ --it;
+ }
+
+ qWarning("TQTextParagraph::lineHeightOfChar: couldn't find lh for %d", i);
+ return 15;
+}
+
+TQTextStringChar *TQTextParagraph::lineStartOfChar(int i, int *index, int *line) const
+{
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ int l = (int)lineStarts.count() - 1;
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.end();
+ --it;
+ for (;;) {
+ if (i >= it.key()) {
+ if (index)
+ *index = it.key();
+ if (line)
+ *line = l;
+ return &str->at(it.key());
+ }
+ if (it == lineStarts.begin())
+ break;
+ --it;
+ --l;
+ }
+
+ qWarning("TQTextParagraph::lineStartOfChar: couldn't find %d", i);
+ return 0;
+}
+
+int TQTextParagraph::lines() const
+{
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ return (int)lineStarts.count();
+}
+
+TQTextStringChar *TQTextParagraph::lineStartOfLine(int line, int *index) const
+{
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ if (line >= 0 && line < (int)lineStarts.count()) {
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while (line-- > 0)
+ ++it;
+ int i = it.key();
+ if (index)
+ *index = i;
+ return &str->at(i);
+ }
+
+ qWarning("TQTextParagraph::lineStartOfLine: couldn't find %d", line);
+ return 0;
+}
+
+int TQTextParagraph::leftGap() const
+{
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ if (str->length() == 0)
+ return 0;
+
+ int line = 0;
+ int x = str->length() ? str->at(0).x : 0; /* set x to x of first char */
+ if (str->isBidi()) {
+ for (int i = 1; i < str->length()-1; ++i)
+ x = qMin(x, str->at(i).x);
+ return x;
+ }
+
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while (line < (int)lineStarts.count()) {
+ int i = it.key(); /* char index */
+ x = qMin(x, str->at(i).x);
+ ++it;
+ ++line;
+ }
+ return x;
+}
+
+void TQTextParagraph::setFormat(int index, int len, TQTextFormat *f, bool useCollection, int flags)
+{
+ if (!f)
+ return;
+ if (index < 0)
+ index = 0;
+ if (index > str->length() - 1)
+ index = str->length() - 1;
+ if (index + len >= str->length())
+ len = str->length() - index;
+
+ TQTextFormatCollection *fc = 0;
+ if (useCollection)
+ fc = formatCollection();
+ TQTextFormat *of;
+ for (int i = 0; i < len; ++i) {
+ of = str->at(i + index).format();
+ if (!changed && (!of || f->key() != of->key()))
+ changed = true;
+ if (invalid == -1 &&
+ (f->font().family() != of->font().family() ||
+ f->font().pointSize() != of->font().pointSize() ||
+ f->font().weight() != of->font().weight() ||
+ f->font().italic() != of->font().italic() ||
+ f->vAlign() != of->vAlign())) {
+ invalidate(0);
+ }
+ if (flags == -1 || flags == TQTextFormat::Format || !fc) {
+ if (fc)
+ f = fc->format(f);
+ str->setFormat(i + index, f, useCollection);
+ } else {
+ TQTextFormat *fm = fc->format(of, f, flags);
+ str->setFormat(i + index, fm, useCollection);
+ }
+ }
+}
+
+void TQTextParagraph::indent(int *oldIndent, int *newIndent)
+{
+ if (!hasdoc || !document()->indent() || isListItem()) {
+ if (oldIndent)
+ *oldIndent = 0;
+ if (newIndent)
+ *newIndent = 0;
+ if (oldIndent && newIndent)
+ *newIndent = *oldIndent;
+ return;
+ }
+ document()->indent()->indent(document(), this, oldIndent, newIndent);
+}
+
+void TQTextParagraph::paint(TQPainter &painter, const QPalette &pal, TQTextCursor *cursor,
+ bool drawSelections, int clipx, int clipy, int clipw, int cliph)
+{
+ if (!visible)
+ return;
+ int i, y, h, baseLine, xstart, xend = 0;
+ i = y =h = baseLine = 0;
+ TQRect cursorRect;
+ drawSelections &= (mSelections != 0);
+ // macintosh full-width selection style
+ bool fullWidthStyle = QApplication::style()->styleHint(QStyle::SH_RichText_FullWidthSelection);
+ int fullSelectionWidth = 0;
+ if (drawSelections && fullWidthStyle)
+ fullSelectionWidth = (hasdoc ? document()->width() : r.width());
+
+ TQString qstr = str->toString();
+ qstr.detach();
+ // ### workaround so that \n are not drawn, actually this should
+ // be fixed in QFont somewhere (under Windows you get ugly boxes
+ // otherwise)
+ TQChar* uc = (TQChar*) qstr.unicode();
+ for (int ii = 0; ii < qstr.length(); ii++)
+ if (uc[(int)ii]== TQLatin1Char(TQLatin1Char('\n')) || uc[(int)ii] == TQLatin1Char('\t'))
+ uc[(int)ii] = 0x20;
+
+ int line = -1;
+ int paintStart = 0;
+ TQTextStringChar *chr = 0;
+ TQTextStringChar *nextchr = at(0);
+ for (i = 0; i < length(); i++) {
+ chr = nextchr;
+ if (i < length()-1)
+ nextchr = at(i+1);
+
+ // we flush at end of document
+ bool flush = (i == length()-1);
+ bool ignoreSoftHyphen = false;
+ if (!flush) {
+ // we flush at end of line
+ flush |= nextchr->lineStart;
+ // we flush on format changes
+ flush |= (nextchr->format() != chr->format());
+ // we flush on link changes
+ flush |= (nextchr->isLink() != chr->isLink());
+ // we flush on start of run
+ flush |= (nextchr->bidiLevel != chr->bidiLevel);
+ // we flush on bidi changes
+ flush |= (nextchr->rightToLeft != chr->rightToLeft);
+ // we flush before and after tabs
+ flush |= (chr->c == TQLatin1Char('\t') || nextchr->c == TQLatin1Char('\t'));
+ // we flush on soft hyphens
+ if (chr->c.unicode() == 0xad) {
+ flush = true;
+ if (!nextchr->lineStart)
+ ignoreSoftHyphen = true;
+ }
+ // we flush on custom items
+ flush |= chr->isCustom();
+ // we flush before custom items
+ flush |= nextchr->isCustom();
+ // when painting justified, we flush on spaces
+ if ((alignment() & Qt::AlignJustify) == Qt::AlignJustify)
+ flush |= chr->whiteSpace;
+ }
+
+ // init a new line
+ if (chr->lineStart) {
+ ++line;
+ paintStart = i;
+ lineInfo(line, y, h, baseLine);
+ if (clipy != -1 && cliph != 0 && y + r.y() - h > clipy + cliph) { // outside clip area, leave
+ break;
+ }
+
+ // if this is the first line and we are a list item, draw the the bullet label
+ if (line == 0 && isListItem()) {
+ int x = chr->x;
+ if (str->isBidi()) {
+ if (str->isRightToLeft()) {
+ x = chr->x + str->width(0);
+ for (int k = 1; k < length(); ++k) {
+ if (str->at(k).lineStart)
+ break;
+ x = qMax(x, str->at(k).x + str->width(k));
+ }
+ } else {
+ x = chr->x;
+ for (int k = 1; k < length(); ++k) {
+ if (str->at(k).lineStart)
+ break;
+ x = qMin(x, str->at(k).x);
+ }
+ }
+ }
+ drawLabel(&painter, x, y, 0, 0, baseLine, pal);
+ }
+ }
+
+ // check for cursor mark
+ if (cursor && this == cursor->paragraph() && i == cursor->index()) {
+ TQTextStringChar *c = i == 0 ? chr : chr - 1;
+ cursorRect.setRect(cursor->x() , y + baseLine - c->format()->ascent(),
+ 1, c->format()->height());
+ }
+
+ if (flush) { // something changed, draw what we have so far
+ if (chr->rightToLeft) {
+ xstart = chr->x;
+ xend = at(paintStart)->x + str->width(paintStart);
+ } else {
+ xstart = at(paintStart)->x;
+ xend = chr->x;
+ if (i < length() - 1) {
+ if (!str->at(i + 1).lineStart &&
+ str->at(i + 1).rightToLeft == chr->rightToLeft)
+ xend = str->at(i + 1).x;
+ else
+ xend += str->width(i);
+ }
+ }
+
+ if ((clipx == -1 || clipw <= 0 || (xend >= clipx && xstart <= clipx + clipw)) &&
+ (clipy == -1 || clipy < y+r.y()+h)) {
+ if (!chr->isCustom())
+ drawString(painter, qstr, paintStart, i - paintStart + (ignoreSoftHyphen ? 0 : 1), xstart, y,
+ baseLine, xend-xstart, h, drawSelections, fullSelectionWidth,
+ chr, pal, chr->rightToLeft);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ else if (chr->customItem()->placement() == TQTextCustomItem::PlaceInline) {
+ bool inSelection = false;
+ if (drawSelections) {
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->constFind(TQTextDocument::Standard);
+ inSelection = (it != mSelections->constEnd() && (*it).start <= i && (*it).end > i);
+ }
+ chr->customItem()->draw(&painter, chr->x, y,
+ clipx == -1 ? clipx : (clipx - r.x()),
+ clipy == -1 ? clipy : (clipy - r.y()),
+ clipw, cliph, pal, inSelection);
+ }
+#endif
+ }
+ paintStart = i+1;
+ }
+
+ }
+
+ // time to draw the cursor
+ const int cursor_extent = 4;
+ if (!cursorRect.isNull() && cursor &&
+ ((clipx == -1 || clipw == -1) || (cursorRect.right()+cursor_extent >= clipx && cursorRect.left()-cursor_extent <= clipx + clipw))) {
+ painter.fillRect(cursorRect, pal.color(QPalette::Text));
+ painter.save();
+ if (string()->isBidi()) {
+ if (at(cursor->index())->rightToLeft) {
+ painter.setPen(Qt::black);
+ painter.drawLine(cursorRect.x(), cursorRect.y(), cursorRect.x() - cursor_extent / 2, cursorRect.y() + cursor_extent / 2);
+ painter.drawLine(cursorRect.x(), cursorRect.y() + cursor_extent, cursorRect.x() - cursor_extent / 2, cursorRect.y() + cursor_extent / 2);
+ } else {
+ painter.setPen(Qt::black);
+ painter.drawLine(cursorRect.x(), cursorRect.y(), cursorRect.x() + cursor_extent / 2, cursorRect.y() + cursor_extent / 2);
+ painter.drawLine(cursorRect.x(), cursorRect.y() + cursor_extent, cursorRect.x() + cursor_extent / 2, cursorRect.y() + cursor_extent / 2);
+ }
+ }
+ painter.restore();
+ }
+}
+
+//#define BIDI_DEBUG
+
+void TQTextParagraph::setColorForSelection(QColor &color, TQPainter &painter,
+ const QPalette &pal, int selection)
+{
+ if (selection < 0)
+ return;
+ color = (hasdoc && selection != TQTextDocument::Standard) ?
+ document()->selectionColor(selection) :
+ pal.color(QPalette::Highlight);
+ QColor text = (hasdoc && document()->hasSelectionTextColor(selection)) ? document()->selectionTextColor(selection) : pal.color(QPalette::HighlightedText);
+ if (text.isValid())
+ painter.setPen(text);
+}
+
+void TQTextParagraph::drawString(TQPainter &painter, const TQString &str, int start, int len,
+ int xstart, int y, int baseLine, int w, int h,
+ bool drawSelections, int fullSelectionWidth,
+ TQTextStringChar *formatChar, const QPalette& pal,
+ bool rightToLeft)
+{
+ bool plainText = hasdoc ? document()->textFormat() == TQt::PlainText : false;
+ TQTextFormat* format = formatChar->format();
+
+ int textFlags = int(rightToLeft ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight);
+
+ if (!plainText || (hasdoc && format->color() != document()->formatCollection()->defaultFormat()->color()))
+ painter.setPen(QPen(format->color()));
+ else
+ painter.setPen(pal.text().color());
+ painter.setFont(format->font());
+
+ if (hasdoc && formatChar->isAnchor() && !formatChar->anchorHref().isEmpty()) {
+ if (format->useLinkColor())
+ painter.setPen(document()->linkColor.isValid() ? document()->linkColor :
+ pal.link().color());
+ if (document()->underlineLinks()) {
+ QFont fn = format->font();
+ fn.setUnderline(true);
+ painter.setFont(fn);
+ }
+ }
+
+ int real_length = len;
+ if (len && !rightToLeft && start + len == length()) // don't draw the last character (trailing space)
+ len--;
+ if (len && str.unicode()[start+len-1] == TQChar::LineSeparator)
+ len--;
+
+
+ TQTextFormat::VerticalAlignment vAlign = format->vAlign();
+ if (vAlign != TQTextFormat::AlignNormal) {
+ // sub or superscript
+ QFont f(painter.font());
+ if (format->fontSizesInPixels())
+ f.setPixelSize((f.pixelSize() * 2) / 3);
+ else
+ f.setPointSize((f.pointSize() * 2) / 3);
+ painter.setFont(f);
+ int h = painter.fontMetrics().height();
+ baseLine += (vAlign == TQTextFormat::AlignSubScript) ? h/6 : -h/2;
+ }
+
+ bool allSelected = false;
+ if (drawSelections) {
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->constFind(TQTextDocument::Standard);
+ allSelected = (it != mSelections->constEnd() && (*it).start <= start && (*it).end >= start+len);
+ }
+ if (!allSelected)
+ painter.drawText(QPointF(xstart, y + baseLine), str.mid(start, len), textFlags, /*justificationPadding*/0);
+
+#ifdef BIDI_DEBUG
+ painter.save();
+ painter.setPen (Qt::red);
+ painter.drawLine(xstart, y, xstart, y + baseLine);
+ painter.drawLine(xstart, y + baseLine/2, xstart + 10, y + baseLine/2);
+ int w = 0;
+ int i = 0;
+ while(i < len)
+ w += painter.fontMetrics().charWidth(str, start + i++);
+ painter.setPen (Qt::blue);
+ painter.drawLine(xstart + w - 1, y, xstart + w - 1, y + baseLine);
+ painter.drawLine(xstart + w - 1, y + baseLine/2, xstart + w - 1 - 10, y + baseLine/2);
+ painter.restore();
+#endif
+
+ // check if we are in a selection and draw it
+ if (drawSelections) {
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->constEnd();
+ while (it != mSelections->constBegin()) {
+ --it;
+ int selStart = (*it).start;
+ int selEnd = (*it).end;
+ int tmpw = w;
+
+ selStart = qMax(selStart, start);
+ int real_selEnd = qMin(selEnd, start+real_length);
+ selEnd = qMin(selEnd, start+len);
+ bool extendRight = false;
+ bool extendLeft = false;
+ bool selWrap = (real_selEnd == length()-1 && n && n->hasSelection(it.key()));
+ if (selWrap
+ || ((real_selEnd < this->str->length()) && this->str->at(real_selEnd).lineStart)) {
+ extendRight = (fullSelectionWidth != 0);
+ if (!extendRight && !rightToLeft)
+ tmpw += painter.fontMetrics().width(TQLatin1Char(' '));
+ }
+ if (fullSelectionWidth && (selStart == 0 || this->str->at(selStart).lineStart)) {
+ extendLeft = true;
+ }
+ if (this->str->isRightToLeft() != rightToLeft)
+ extendLeft = extendRight = false;
+
+ if (this->str->isRightToLeft()) {
+ bool tmp = extendLeft;
+ extendLeft = extendRight;
+ extendRight = tmp;
+ }
+
+ if (selStart < real_selEnd ||
+ (selWrap && fullSelectionWidth && extendRight &&
+ // don't draw the standard selection on a printer=
+ (it.key() != TQTextDocument::Standard || !is_printer(&painter)))) {
+ int selection = it.key();
+ QColor color;
+ setColorForSelection(color, painter, pal, selection);
+ if (selStart != start || selEnd != start + len || selWrap) {
+ // have to clip
+ painter.save();
+ int cs, ce;
+ if (rightToLeft) {
+ cs = (selEnd != start + len) ?
+ this->str->at(this->str->previousCursorPosition(selEnd)).x : xstart;
+ ce = (selStart != start) ?
+ this->str->at(this->str->previousCursorPosition(selStart)).x : xstart+tmpw;
+ } else {
+ cs = (selStart != start) ? this->str->at(selStart).x : xstart;
+ ce = (selEnd != start + len) ? this->str->at(selEnd).x : xstart+tmpw;
+ }
+ TQRect r(cs, y, ce-cs, h);
+ if (extendLeft)
+ r.setLeft(0);
+ if (extendRight)
+ r.setRight(fullSelectionWidth);
+ QRegion reg(r);
+ if (painter.hasClipping())
+ reg &= painter.clipRegion();
+ painter.setClipRegion(reg);
+ }
+ int xleft = xstart;
+ if (extendLeft) {
+ tmpw += xstart;
+ xleft = 0;
+ }
+ if (extendRight)
+ tmpw = fullSelectionWidth - xleft;
+ if(color.isValid())
+ painter.fillRect(xleft, y, tmpw, h, color);
+ painter.drawText(QPointF(xstart, y + baseLine), str.mid(start, len), textFlags, /*justificationPadding*/0);
+ if (selStart != start || selEnd != start + len || selWrap)
+ painter.restore();
+ }
+ }
+ }
+
+ if (format->isMisspelled()) {
+ painter.save();
+ painter.setPen(QPen(Qt::red, 1, Qt::DotLine));
+ painter.drawLine(xstart, y + baseLine + 1, xstart + w, y + baseLine + 1);
+ painter.restore();
+ }
+
+ if (hasdoc && formatChar->isAnchor() && !formatChar->anchorHref().isEmpty() &&
+ document()->focusIndicator.parag == this &&
+ ((document()->focusIndicator.start >= start &&
+ document()->focusIndicator.start + document()->focusIndicator.len <= start + len)
+ || (document()->focusIndicator.start <= start &&
+ document()->focusIndicator.start + document()->focusIndicator.len >= start + len))) {
+ QStyleOptionFocusRect opt;
+ opt.rect.setRect(xstart, y, w, h);
+#ifndef Q_WS_WIN
+ opt.state = QStyle::State_None;
+#else
+ // force drawing a focus rect but only on windows because it's
+ // configurable by the user in windows settings (see
+ // SH_UnderlineShortcut style hint) and we want to override
+ // this settings.
+ opt.state = QStyle::State_KeyboardFocusChange;
+#endif
+ opt.palette = pal;
+ QApplication::style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &painter);
+ }
+}
+
+void TQTextParagraph::drawLabel(TQPainter* p, int x, int y, int w, int h, int base,
+ const QPalette& pal)
+{
+ TQRect r (x, y, w, h);
+ TQStyleSheetItem::ListStyle s = listStyle();
+
+ p->save();
+ TQTextFormat *format = at(0)->format();
+ if (format) {
+ p->setPen(format->color());
+ p->setFont(format->font());
+ }
+ QFontMetrics fm(p->fontMetrics());
+ int size = fm.lineSpacing() / 3;
+
+ bool rtl = str->isRightToLeft();
+
+ switch (s) {
+ case TQStyleSheetItem::ListDecimal:
+ case TQStyleSheetItem::ListLowerAlpha:
+ case TQStyleSheetItem::ListUpperAlpha:
+ {
+ if (list_val == -1) { // uninitialised list value, calcluate the right one
+ int depth = listDepth();
+ list_val--;
+ // ### evil, square and expensive. This needs to be done when formatting, not when painting
+ TQTextParagraph* s = prev();
+ int depth_s;
+ while (s && (depth_s = s->listDepth()) >= depth) {
+ if (depth_s == depth && s->isListItem())
+ list_val--;
+ s = s->prev();
+ }
+ }
+
+ int n = list_val;
+ if (n < -1)
+ n = -n - 1;
+ TQString l;
+ switch (s) {
+ case TQStyleSheetItem::ListLowerAlpha:
+ if (n < 27) {
+ l = TQLatin1Char(('a' + (char) (n-1)));
+ break;
+ }
+ case TQStyleSheetItem::ListUpperAlpha:
+ if (n < 27) {
+ l = TQLatin1Char(('A' + (char) (n-1)));
+ break;
+ }
+ break;
+ default: //TQStyleSheetItem::ListDecimal:
+ l.setNum(n);
+ break;
+ }
+ if (rtl)
+ l.prepend(TQLatin1String(" ."));
+ else
+ l += TQString::fromLatin1(". ");
+ int x = (rtl ? r.left() : r.right() - fm.width(l));
+ p->drawText(x, r.top() + base, l);
+ }
+ break;
+ case TQStyleSheetItem::ListSquare:
+ {
+ int x = rtl ? r.left() + size : r.right() - size*2;
+ TQRect er(x, r.top() + fm.height() / 2 - size / 2, size, size);
+ p->fillRect(er , pal.brush(QPalette::Text));
+ }
+ break;
+ case TQStyleSheetItem::ListCircle:
+ {
+ int x = rtl ? r.left() + size : r.right() - size*2;
+ TQRect er(x, r.top() + fm.height() / 2 - size / 2, size, size);
+ p->drawEllipse(er);
+ }
+ break;
+ case TQStyleSheetItem::ListDisc:
+ default:
+ {
+ p->setBrush(pal.brush(QPalette::Text));
+ int x = rtl ? r.left() + size : r.right() - size*2;
+ TQRect er(x, r.top() + fm.height() / 2 - size / 2, size, size);
+ p->drawEllipse(er);
+ p->setBrush(Qt::NoBrush);
+ }
+ break;
+ }
+
+ p->restore();
+}
+
+#ifndef QT_NO_DATASTREAM
+void TQTextParagraph::readStyleInformation(QDataStream &stream)
+{
+ int int_align, int_lstyle;
+ uchar uchar_litem, uchar_rtext, uchar_dir;
+ stream >> int_align >> int_lstyle >> utm >> ubm >> ulm >> urm >> uflm
+ >> ulinespacing >> ldepth >> uchar_litem >> uchar_rtext >> uchar_dir;
+ align = int_align; lstyle = (TQStyleSheetItem::ListStyle) int_lstyle;
+ litem = uchar_litem; rtext = uchar_rtext; str->setDirection((TQChar::Direction)uchar_dir);
+ TQTextParagraph* s = prev() ? prev() : this;
+ while (s) {
+ s->invalidate(0);
+ s = s->next();
+ }
+}
+
+void TQTextParagraph::writeStyleInformation(QDataStream& stream) const
+{
+ stream << (int) align << (int) lstyle << utm << ubm << ulm << urm << uflm << ulinespacing << ldepth << (uchar)litem << (uchar)rtext << (uchar)str->direction();
+}
+#endif
+
+
+void TQTextParagraph::setListItem(bool li)
+{
+ if ((bool)litem == li)
+ return;
+ litem = li;
+ changed = true;
+ TQTextParagraph* s = prev() ? prev() : this;
+ while (s) {
+ s->invalidate(0);
+ s = s->next();
+ }
+}
+
+void TQTextParagraph::setListDepth(int depth) {
+ if (!hasdoc || depth == ldepth)
+ return;
+ ldepth = depth;
+ TQTextParagraph* s = prev() ? prev() : this;
+ while (s) {
+ s->invalidate(0);
+ s = s->next();
+ }
+}
+
+int *TQTextParagraph::tabArray() const
+{
+ int *ta = tArray;
+ if (!ta && hasdoc)
+ ta = document()->tabArray();
+ return ta;
+}
+
+int TQTextParagraph::nextTab(int, int x)
+{
+ int *ta = tArray;
+ if (hasdoc) {
+ if (!ta)
+ ta = document()->tabArray();
+ tabStopWidth = document()->tabStopWidth();
+ }
+ if (ta) {
+ int i = 0;
+ while (ta[i]) {
+ if (ta[i] >= x)
+ return tArray[i];
+ ++i;
+ }
+ return tArray[0];
+ } else {
+ int n;
+ if (tabStopWidth != 0)
+ n = x / tabStopWidth;
+ else
+ return x;
+ return tabStopWidth * (n + 1);
+ }
+}
+
+void TQTextParagraph::adjustToPainter(TQPainter *p)
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ for (int i = 0; i < length(); ++i) {
+ if (at(i)->isCustom())
+ at(i)->customItem()->adjustToPainter(p);
+ }
+#endif
+}
+
+TQTextFormatCollection *TQTextParagraph::formatCollection() const
+{
+ if (hasdoc)
+ return document()->formatCollection();
+ TQTextFormatCollection* fc = &pseudoDocument()->collection;
+ if (paintdevice != fc->paintDevice())
+ fc->setPaintDevice(paintdevice);
+ return fc;
+}
+
+TQString TQTextParagraph::richText() const
+{
+ TQString s;
+ TQTextStringChar *formatChar = 0;
+ TQString spaces;
+ bool doStart = richTextExportStart && richTextExportStart->paragraph() == this;
+ bool doEnd = richTextExportEnd && richTextExportEnd->paragraph() == this;
+ int i;
+ TQString lastAnchorName;
+ for (i = 0; i < length()-1; ++i) {
+ if (doStart && i && richTextExportStart->index() == i)
+ s += TQLatin1String("<!--StartFragment-->");
+ if (doEnd && richTextExportEnd->index() == i)
+ s += TQLatin1String("<!--EndFragment-->");
+ TQTextStringChar *c = &str->at(i);
+ if (c->isAnchor() && !c->anchorName().isEmpty() && c->anchorName() != lastAnchorName) {
+ lastAnchorName = c->anchorName();
+ if (c->anchorName().contains(TQLatin1Char('#'))) {
+// TQStringList l = c->anchorName().split(TQLatin1Char('#'));
+ TQStringList l = TQStringList::split(TQLatin1Char('#'), c->anchorName());
+ for (TQStringList::ConstIterator it = l.constBegin(); it != l.constEnd(); ++it)
+ s += TQLatin1String("<a name=\"") + *it + TQLatin1String("\"></a>");
+ } else {
+ s += TQLatin1String("<a name=\"") + c->anchorName() + TQLatin1String("\"></a>");
+ }
+ }
+ if (!formatChar) {
+ s += c->format()->makeFormatChangeTags(formatCollection()->defaultFormat(),
+ 0, TQString(), c->anchorHref());
+ formatChar = c;
+ } else if ((formatChar->format()->key() != c->format()->key()) ||
+ (c->anchorHref() != formatChar->anchorHref())) {
+ s += c->format()->makeFormatChangeTags(formatCollection()->defaultFormat(),
+ formatChar->format() , formatChar->anchorHref(), c->anchorHref());
+ formatChar = c;
+ }
+ if (c->c == TQLatin1Char('<'))
+ s += TQLatin1String("&lt;");
+ else if (c->c == TQLatin1Char('>'))
+ s += TQLatin1String("&gt;");
+ else if (c->c == TQLatin1Char('&'))
+ s += TQLatin1String("&amp;");
+ else if (c->c == TQLatin1Char('\"'))
+ s += TQLatin1String("&quot;");
+#ifndef QT_NO_TEXTCUSTOMITEM
+ else if (c->isCustom())
+ s += c->customItem()->richText();
+#endif
+ else if (c->c == TQLatin1Char('\n') || c->c == TQChar::LineSeparator)
+ s += TQLatin1String("<br />"); // space on purpose for compatibility with Netscape, Lynx & Co.
+ else
+ s += c->c;
+ }
+ if (doEnd && richTextExportEnd->index() == i)
+ s += TQLatin1String("<!--EndFragment-->");
+ if (formatChar)
+ s += formatChar->format()->makeFormatEndTags(formatCollection()->defaultFormat(), formatChar->anchorHref());
+ return s;
+}
+
+void TQTextParagraph::addCommand(TQTextCommand *cmd)
+{
+ if (!hasdoc)
+ pseudoDocument()->commandHistory->addCommand(cmd);
+ else
+ document()->commands()->addCommand(cmd);
+}
+
+TQTextCursor *TQTextParagraph::undo(TQTextCursor *c)
+{
+ if (!hasdoc)
+ return pseudoDocument()->commandHistory->undo(c);
+ return document()->commands()->undo(c);
+}
+
+TQTextCursor *TQTextParagraph::redo(TQTextCursor *c)
+{
+ if (!hasdoc)
+ return pseudoDocument()->commandHistory->redo(c);
+ return document()->commands()->redo(c);
+}
+
+int TQTextParagraph::topMargin() const
+{
+ int m = 0;
+ if (rtext) {
+ m = isListItem() ? (document()->li_tm/qMax(1,listDepth()*listDepth())) :
+ (listDepth() ? 0 : document()->par_tm);
+ if (listDepth() == 1 &&( !prev() || prev()->listDepth() < listDepth()))
+ m = qMax<int>(m, document()->list_tm);
+ }
+ m += utm;
+ return scale(m, TQTextFormat::painter());
+}
+
+int TQTextParagraph::bottomMargin() const
+{
+ int m = 0;
+ if (rtext) {
+ m = isListItem() ? (document()->li_bm/qMax(1,listDepth()*listDepth())) :
+ (listDepth() ? 0 : document()->par_bm);
+ if (listDepth() == 1 &&( !next() || next()->listDepth() < listDepth()))
+ m = qMax<int>(m, document()->list_bm);
+ }
+ m += ubm;
+ return scale(m, TQTextFormat::painter());
+}
+
+int TQTextParagraph::leftMargin() const
+{
+ int m = ulm;
+ if (listDepth() && !string()->isRightToLeft())
+ m += listDepth() * document()->list_lm;
+ return scale(m, TQTextFormat::painter());
+}
+
+int TQTextParagraph::firstLineMargin() const
+{
+ int m = uflm;
+ return scale(m, TQTextFormat::painter());
+}
+
+int TQTextParagraph::rightMargin() const
+{
+ int m = urm;
+ if (listDepth() && string()->isRightToLeft())
+ m += listDepth() * document()->list_lm;
+ return scale(m, TQTextFormat::painter());
+}
+
+int TQTextParagraph::lineSpacing() const
+{
+ int l = ulinespacing;
+ l = scale(l, TQTextFormat::painter());
+ return l;
+}
+
+void TQTextParagraph::copyParagData(TQTextParagraph *parag)
+{
+ rtext = parag->rtext;
+ lstyle = parag->lstyle;
+ ldepth = parag->ldepth;
+ litem = parag->litem;
+ align = parag->align;
+ utm = parag->utm;
+ ubm = parag->ubm;
+ urm = parag->urm;
+ ulm = parag->ulm;
+ uflm = parag->uflm;
+ ulinespacing = parag->ulinespacing;
+ QColor *c = parag->backgroundColor();
+ if (c)
+ setBackgroundColor(*c);
+ str->setDirection(parag->str->direction());
+}
+
+void TQTextParagraph::show()
+{
+ if (visible || !hasdoc)
+ return;
+ visible = true;
+}
+
+void TQTextParagraph::hide()
+{
+ if (!visible || !hasdoc)
+ return;
+ visible = false;
+}
+
+void TQTextParagraph::setDirection(TQChar::Direction dir)
+{
+ if (str && str->direction() != dir) {
+ str->setDirection(dir);
+ invalidate(0);
+ }
+}
+
+TQChar::Direction TQTextParagraph::direction() const
+{
+ return (str ? str->direction() : TQChar::DirON);
+}
+
+void TQTextParagraph::setChanged(bool b, bool recursive)
+{
+ changed = b;
+ if (recursive) {
+ if (document() && document()->parentParagraph())
+ document()->parentParagraph()->setChanged(b, recursive);
+ }
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+TQTextPreProcessor::TQTextPreProcessor()
+{
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatter::TQTextFormatter()
+ : thisminw(0), thiswused(0), wrapEnabled(true), wrapColumn(-1), biw(false)
+{
+}
+
+QTextLineStart *TQTextFormatter::formatLine(TQTextParagraph *parag, TQTextString *string, QTextLineStart *line,
+ TQTextStringChar *startChar, TQTextStringChar *lastChar, int align, int space)
+{
+ if (lastChar < startChar)
+ return new QTextLineStart;
+#ifndef QT_NO_COMPLEXTEXT
+ if(string->isBidi())
+ return bidiReorderLine(parag, string, line, startChar, lastChar, align, space);
+#endif
+ int start = (startChar - &string->at(0));
+ int last = (lastChar - &string->at(0));
+
+ // ignore white space at the end of the line.
+ TQTextStringChar *ch = lastChar;
+ while (ch > startChar && ch->whiteSpace) {
+ space += ch->format()->width(TQLatin1Char(' '));
+ --ch;
+ }
+
+ if (space < 0)
+ space = 0;
+
+ // do alignment Auto == Left in this case
+ if (align & Qt::AlignHCenter || align & Qt::AlignRight) {
+ if (align & Qt::AlignHCenter)
+ space /= 2;
+ for (int j = start; j <= last; ++j)
+ string->at(j).x += space;
+ } else if (align & Qt::AlignJustify) {
+ int numSpaces = 0;
+ // End at "last-1", the last space ends up with a width of 0
+ for (int j = last-1; j >= start; --j) {
+ // Start at last tab, if any.
+ TQTextStringChar &ch = string->at(j);
+ if (ch.c == TQLatin1Char('\t')) {
+ start = j+1;
+ break;
+ }
+ if(ch.whiteSpace)
+ numSpaces++;
+ }
+ int toAdd = 0;
+ for (int k = start + 1; k <= last; ++k) {
+ TQTextStringChar &ch = string->at(k);
+ if(numSpaces && ch.whiteSpace) {
+ int s = space / numSpaces;
+ toAdd += s;
+ space -= s;
+ numSpaces--;
+ }
+ string->at(k).x += toAdd;
+ }
+ }
+
+ if (last >= 0 && last < string->length())
+ line->w = string->at(last).x + string->width(last);
+ else
+ line->w = 0;
+
+ return new QTextLineStart;
+}
+
+#ifndef QT_NO_COMPLEXTEXT
+
+#ifdef BIDI_DEBUG
+QT_BEGIN_INCLUDE_NAMESPACE
+#include <iostream>
+QT_END_INCLUDE_NAMESPACE
+#endif
+
+// collects one line of the paragraph and transforms it to visual order
+QTextLineStart *TQTextFormatter::bidiReorderLine(TQTextParagraph * /*parag*/, TQTextString *text, QTextLineStart *line,
+ TQTextStringChar *startChar, TQTextStringChar *lastChar, int align, int space)
+{
+ // ignore white space at the end of the line.
+ int endSpaces = 0;
+ while (lastChar > startChar && lastChar->whiteSpace) {
+ space += lastChar->format()->width(TQLatin1Char(' '));
+ --lastChar;
+ ++endSpaces;
+ }
+
+ int start = (startChar - &text->at(0));
+ int last = (lastChar - &text->at(0));
+
+ int length = lastChar - startChar + 1;
+
+
+ int x = startChar->x;
+
+ unsigned char _levels[256];
+ int _visual[256];
+
+ unsigned char *levels = _levels;
+ int *visual = _visual;
+
+ if (length > 255) {
+ levels = (unsigned char *)malloc(length*sizeof(unsigned char));
+ visual = (int *)malloc(length*sizeof(int));
+ }
+
+ //qDebug("bidiReorderLine: length=%d (%d-%d)", length, start, last);
+
+ TQTextStringChar *ch = startChar;
+ unsigned char *l = levels;
+ while (ch <= lastChar) {
+ //qDebug(" level: %d", ch->bidiLevel);
+ *(l++) = (ch++)->bidiLevel;
+ }
+
+ QTextEngine::bidiReorder(length, levels, visual);
+
+ // now construct the reordered string out of the runs...
+
+ int numSpaces = 0;
+ align = QStyle::visualAlignment(text->isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight, QFlag(align));
+
+ // This is not really correct, but as we can't make the scroll bar move to the left of the origin,
+ // this ensures all text can be scrolled to and read.
+ if (space < 0)
+ space = 0;
+
+ if (align & Qt::AlignHCenter)
+ x += space/2;
+ else if (align & Qt::AlignRight)
+ x += space;
+ else if (align & Qt::AlignJustify) {
+ // End at "last-1", the last space ends up with a width of 0
+ for (int j = last-1; j >= start; --j) {
+ // Start at last tab, if any.
+ TQTextStringChar &ch = text->at(j);
+ if (ch.c == TQLatin1Char('\t')) {
+ start = j+1;
+ break;
+ }
+ if(ch.whiteSpace)
+ numSpaces++;
+ }
+ }
+
+ int toAdd = 0;
+ int xorig = x;
+ TQTextStringChar *lc = startChar + visual[0];
+ for (int i = 0; i < length; i++) {
+ TQTextStringChar *ch = startChar + visual[i];
+ if (numSpaces && ch->whiteSpace) {
+ int s = space / numSpaces;
+ toAdd += s;
+ space -= s;
+ numSpaces--;
+ }
+
+ if (lc->format() != ch->format() && !ch->c.isSpace()
+ && lc->format()->font().italic() && !ch->format()->font().italic()) {
+ int rb = lc->format()->fontMetrics().rightBearing(lc->c);
+ if (rb < 0)
+ x -= rb;
+ }
+
+ ch->x = x + toAdd;
+ ch->rightToLeft = ch->bidiLevel % 2;
+ //qDebug("visual: %d (%p) placed at %d rightToLeft=%d", visual[i], ch, x +toAdd, ch->rightToLeft );
+ int ww = 0;
+ if (ch->c.unicode() >= 32 || ch->c == TQLatin1Char(TQLatin1Char('\t')) || ch->c == TQLatin1Char('\n') || ch->isCustom()) {
+ ww = text->width(start+visual[i]);
+ } else {
+ ww = ch->format()->width(TQLatin1Char(' '));
+ }
+ x += ww;
+ lc = ch;
+ }
+ x += toAdd;
+
+ while (endSpaces--) {
+ ++lastChar;
+ int sw = lastChar->format()->width(TQLatin1Char(' '));
+ if (text->isRightToLeft()) {
+ xorig -= sw;
+ lastChar->x = xorig;
+ ch->rightToLeft = true;
+ } else {
+ lastChar->x = x;
+ x += sw;
+ ch->rightToLeft = false;
+ }
+ }
+
+ line->w = x;
+
+ if (length > 255) {
+ free(levels);
+ free(visual);
+ }
+
+ return new QTextLineStart;
+}
+#endif
+
+
+void TQTextFormatter::insertLineStart(TQTextParagraph *parag, int index, QTextLineStart *ls)
+{
+ QMap<int, QTextLineStart*>::Iterator it;
+ if ((it = parag->lineStartList().find(index)) == parag->lineStartList().end()) {
+ parag->lineStartList().insert(index, ls);
+ } else {
+ delete *it;
+ parag->lineStartList().erase(it);
+ parag->lineStartList().insert(index, ls);
+ }
+}
+
+
+/* Standard pagebreak algorithm using TQTextFlow::adjustFlow. Returns
+ the shift of the paragraphs bottom line.
+ */
+int TQTextFormatter::formatVertically(TQTextDocument* doc, TQTextParagraph* parag)
+{
+ int oldHeight = parag->rect().height();
+ QMap<int, QTextLineStart*>& lineStarts = parag->lineStartList();
+ QMap<int, QTextLineStart*>::Iterator it = lineStarts.begin();
+ int h = parag->prev() ? qMax(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
+ for (; it != lineStarts.end() ; ++it ) {
+ QTextLineStart * ls = it.value();
+ ls->y = h;
+ TQTextStringChar *c = &parag->string()->at(it.key());
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (c && c->customItem() && c->customItem()->ownLine()) {
+ int h = c->customItem()->height;
+ c->customItem()->pageBreak(parag->rect().y() + ls->y + ls->baseLine - h, doc->flow());
+ int delta = c->customItem()->height - h;
+ ls->h += delta;
+ if (delta)
+ parag->setMovedDown(true);
+ } else
+#endif
+ {
+
+ int shift = doc->flow()->adjustFlow(parag->rect().y() + ls->y, ls->w, ls->h);
+ ls->y += shift;
+ if (shift)
+ parag->setMovedDown(true);
+ }
+ h = ls->y + ls->h;
+ }
+ int m = parag->bottomMargin();
+ if (!parag->next())
+ m = 0;
+ else
+ m = qMax(m, parag->next()->topMargin()) / 2;
+ h += m;
+ parag->setHeight(h);
+ return h - oldHeight;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatterBreakInWords::TQTextFormatterBreakInWords()
+{
+}
+
+#define SPACE(s) s
+
+int TQTextFormatterBreakInWords::format(TQTextDocument *doc,TQTextParagraph *parag,
+ int start, const QMap<int, QTextLineStart*> &)
+{
+ // make sure bidi information is correct.
+ (void)parag->string()->isBidi();
+
+ TQTextStringChar *c = 0;
+ TQTextStringChar *firstChar = 0;
+ int left = doc ? parag->leftMargin() + doc->leftMargin() : 0;
+ int x = left + (doc ? parag->firstLineMargin() : 0);
+ int dw = parag->documentVisibleWidth() - (doc ? doc->rightMargin() : 0);
+ int y = parag->prev() ? qMax(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
+ int h = y;
+ int len = parag->length();
+ if (doc)
+ x = doc->flow()->adjustLMargin(y + parag->rect().y(), parag->rect().height(), x, 4);
+ int rm = parag->rightMargin();
+ int w = dw - (doc ? doc->flow()->adjustRMargin(y + parag->rect().y(), parag->rect().height(), rm, 4) : 0);
+ bool fullWidth = true;
+ int minw = 0;
+ int wused = 0;
+ bool wrapEnabled = isWrapEnabled(parag);
+
+ start = 0; //######### what is the point with start?! (Matthias)
+ if (start == 0)
+ c = &parag->string()->at(0);
+
+ int i = start;
+ QTextLineStart *lineStart = new QTextLineStart(y, y, 0);
+ insertLineStart(parag, 0, lineStart);
+
+ TQPainter *painter = TQTextFormat::painter();
+
+ int col = 0;
+ int ww = 0;
+ TQChar lastChr;
+ int tabBase = left < x ? left : x;
+ for (; i < len; ++i, ++col) {
+ if (c)
+ lastChr = c->c;
+ c = &parag->string()->at(i);
+ // ### the lines below should not be needed
+ if (painter)
+ c->format()->setPainter(painter);
+ if (i > 0) {
+ c->lineStart = 0;
+ } else {
+ c->lineStart = 1;
+ firstChar = c;
+ }
+ if (c->c.unicode() >= 32 || c->isCustom()) {
+ ww = parag->string()->width(i);
+ } else if (c->c == TQLatin1Char('\t')) {
+ int nx = parag->nextTab(i, x - tabBase) + tabBase;
+ if (nx < x)
+ ww = w - x;
+ else
+ ww = nx - x;
+ } else {
+ ww = c->format()->width(TQLatin1Char(' '));
+ }
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ if (c->isCustom() && c->customItem()->ownLine()) {
+ x = doc ? doc->flow()->adjustLMargin(y + parag->rect().y(), parag->rect().height(), left, 4) : left;
+ w = dw - (doc ? doc->flow()->adjustRMargin(y + parag->rect().y(), parag->rect().height(), rm, 4) : 0);
+ c->customItem()->resize(w - x);
+ w = dw;
+ y += h;
+ h = c->height();
+ lineStart = new QTextLineStart(y, h, h);
+ insertLineStart(parag, i, lineStart);
+ c->lineStart = 1;
+ firstChar = c;
+ x = 0xffffff;
+ continue;
+ }
+#endif
+
+ if (wrapEnabled &&
+ ((wrapAtColumn() == -1 && x + ww > w) ||
+ (wrapAtColumn() != -1 && col >= wrapAtColumn()))) {
+ x = doc ? parag->document()->flow()->adjustLMargin(y + parag->rect().y(), parag->rect().height(), left, 4) : left;
+ w = dw;
+ y += h;
+ h = c->height();
+ lineStart = formatLine(parag, parag->string(), lineStart, firstChar, c-1);
+ lineStart->y = y;
+ insertLineStart(parag, i, lineStart);
+ lineStart->baseLine = c->ascent();
+ lineStart->h = c->height();
+ c->lineStart = 1;
+ firstChar = c;
+ col = 0;
+ if (wrapAtColumn() != -1)
+ minw = qMax(minw, w);
+ } else if (lineStart) {
+ lineStart->baseLine = qMax(lineStart->baseLine, c->ascent());
+ h = qMax(h, c->height());
+ lineStart->h = h;
+ }
+
+ c->x = x;
+ x += ww;
+ wused = qMax(wused, x);
+ }
+
+ int m = parag->bottomMargin();
+ if (!parag->next())
+ m = 0;
+ else
+ m = qMax(m, parag->next()->topMargin()) / 2;
+ parag->setFullWidth(fullWidth);
+ y += h + m;
+ if (doc)
+ minw += doc->rightMargin();
+ if (!wrapEnabled)
+ minw = qMax(minw, wused);
+
+ thisminw = minw;
+ thiswused = wused;
+ return y;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatterBreakWords::TQTextFormatterBreakWords()
+{
+}
+
+#define DO_FLOW(lineStart) do{ if (doc && doc->isPageBreakEnabled()) { \
+ int yflow = lineStart->y + parag->rect().y();\
+ int shift = doc->flow()->adjustFlow(yflow, dw, lineStart->h); \
+ lineStart->y += shift;\
+ y += shift;\
+ }}while(false)
+
+int TQTextFormatterBreakWords::format(TQTextDocument *doc, TQTextParagraph *parag,
+ int start, const QMap<int, QTextLineStart*> &)
+{
+ // make sure bidi information is correct.
+ (void)parag->string()->isBidi();
+
+ TQTextStringChar *c = 0;
+ TQTextStringChar *firstChar = 0;
+ TQTextString *string = parag->string();
+ int left = doc ? parag->leftMargin() + doc->leftMargin() : 0;
+ int x = left + (doc ? parag->firstLineMargin() : 0);
+ int y = parag->prev() ? qMax(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
+ int h = y;
+ int len = parag->length();
+ if (doc)
+ x = doc->flow()->adjustLMargin(y + parag->rect().y(), parag->rect().height(), x, 0);
+ int dw = parag->documentVisibleWidth() - (doc ? (left != x ? 0 : doc->rightMargin()) : 0);
+
+ int curLeft = x;
+ int rm = parag->rightMargin();
+ int rdiff = doc ? doc->flow()->adjustRMargin(y + parag->rect().y(), parag->rect().height(), rm, 0) : 0;
+ int w = dw - rdiff;
+ bool fullWidth = true;
+ int marg = left + rdiff;
+ int minw = 0;
+ int wused = 0;
+ int tminw = marg;
+ int linespacing = doc ? parag->lineSpacing() : 0;
+ bool wrapEnabled = isWrapEnabled(parag);
+
+ start = 0;
+
+ int i = start;
+ QTextLineStart *lineStart = new QTextLineStart(y, y, 0);
+ insertLineStart(parag, 0, lineStart);
+ int lastBreak = -1;
+ int tmpBaseLine = 0, tmph = 0;
+ bool lastWasNonInlineCustom = false;
+
+ int align = parag->alignment();
+ if (align == TQt::AlignAuto && doc && doc->alignment() != TQt::AlignAuto)
+ align = doc->alignment();
+
+ align &= Qt::AlignHorizontal_Mask;
+
+ // ### hack. The last char in the paragraph is always invisible,
+ // ### and somehow sometimes has a wrong format. It changes
+ // ### between // layouting and printing. This corrects some
+ // ### layouting errors in BiDi mode due to this.
+ if (len > 1) {
+ c = &parag->string()->at(len - 1);
+ if (!c->isAnchor()) {
+ if (c->format())
+ c->format()->removeRef();
+ c->setFormat(string->at(len - 2).format());
+ if (c->format())
+ c->format()->addRef();
+ }
+ }
+
+ c = &parag->string()->at(0);
+
+ TQPainter *painter = TQTextFormat::painter();
+ int col = 0;
+ int ww = 0;
+ TQChar lastChr = c->c;
+ TQTextFormat *lastFormat = c->format();
+ int tabBase = left < x ? left : x;
+ for (; i < len; ++i, ++col) {
+ if (i) {
+ c = &parag->string()->at(i-1);
+ lastChr = c->c;
+ lastFormat = c->format();
+ }
+ bool lastWasOwnLineCustomItem = lastBreak == -2;
+ bool hadBreakableChar = lastBreak != -1;
+ bool lastWasHardBreak = lastChr == TQChar::LineSeparator;
+
+ // ### next line should not be needed
+ if (painter)
+ c->format()->setPainter(painter);
+ c = &string->at(i);
+
+ if (lastFormat != c->format() && !c->c.isSpace()
+ && lastFormat->font().italic() && !c->format()->font().italic()) {
+ int rb = lastFormat->fontMetrics().rightBearing(lastChr);
+ if (rb < 0)
+ x -= rb;
+ }
+
+ if ((i > 0 && (x > curLeft || ww == 0)) || lastWasNonInlineCustom) {
+ c->lineStart = 0;
+ } else {
+ c->lineStart = 1;
+ firstChar = c;
+ }
+
+ // ignore non spacing marks for column count.
+ if (col != 0 && TQChar::category(c->c.unicode()) == TQChar::Mark_NonSpacing)
+ --col;
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ lastWasNonInlineCustom = (c->isCustom() && c->customItem()->placement() != TQTextCustomItem::PlaceInline);
+#endif
+
+ if (c->c.unicode() >= 32 || c->isCustom()) {
+ ww = string->width(i);
+ } else if (c->c == TQLatin1Char('\t')) {
+ if (align == Qt::AlignRight || align == Qt::AlignCenter) {
+ // we can not (yet) do tabs
+ ww = c->format()->width(TQLatin1Char(' '));
+ } else {
+ int tabx = lastWasHardBreak ? (left + (doc ? parag->firstLineMargin() : 0)) : x;
+ int nx = parag->nextTab(i, tabx - tabBase) + tabBase;
+ if (nx < tabx) // strrrange...
+ ww = 0;
+ else
+ ww = nx - tabx;
+ }
+ } else {
+ ww = c->format()->width(TQLatin1Char(' '));
+ }
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem* ci = c->customItem();
+ if (c->isCustom() && ci->ownLine()) {
+ QTextLineStart *lineStart2 = formatLine(parag, string, lineStart, firstChar, c-1, align, SPACE(w - x - ww));
+ x = doc ? doc->flow()->adjustLMargin(y + parag->rect().y(), parag->rect().height(), left, 4) : left;
+ w = dw - (doc ? doc->flow()->adjustRMargin(y + parag->rect().y(), parag->rect().height(), rm, 4) : 0);
+ ci->resize(w - x);
+ if (ci->width < w - x) {
+ if (align & Qt::AlignHCenter)
+ x = (w - ci->width) / 2;
+ else if (align & Qt::AlignRight) {
+ x = w - ci->width;
+ }
+ }
+ c->x = x;
+ curLeft = x;
+ if (i == 0 || !isBreakable(string, i-1) ||
+ string->at(i - 1).lineStart == 0) {
+ y += qMax(h, qMax(tmph, linespacing));
+ tmph = c->height();
+ h = tmph;
+ lineStart = lineStart2;
+ lineStart->y = y;
+ insertLineStart(parag, i, lineStart);
+ c->lineStart = 1;
+ firstChar = c;
+ } else {
+ tmph = c->height();
+ h = tmph;
+ delete lineStart2;
+ }
+ lineStart->h = h;
+ lineStart->baseLine = h;
+ tmpBaseLine = lineStart->baseLine;
+ lastBreak = -2;
+ x = w;
+ minw = qMax(minw, tminw);
+
+ int tw = ci->minimumWidth() + (doc ? doc->leftMargin() : 0);
+ if (tw < QWIDGETSIZE_MAX)
+ tminw = tw;
+ else
+ tminw = marg;
+ wused = qMax(wused, ci->width);
+ continue;
+ } else if (c->isCustom() && ci->placement() != TQTextCustomItem::PlaceInline) {
+ int tw = ci->minimumWidth();
+ if (tw < QWIDGETSIZE_MAX)
+ minw = qMax(minw, tw);
+ }
+#endif
+ // we break if
+ // 1. the last character was a hard break (TQChar::LineSeparator) or
+ // 2. the last character was a own-line custom item (eg. table or ruler) or
+ // 3. wrapping was enabled, it was not a space and following
+ // condition is true: We either had a breakable character
+ // previously or we ar allowed to break in words and - either
+ // we break at w pixels and the current char would exceed that
+ // or - we break at a column and the current character would
+ // exceed that.
+ if (lastWasHardBreak || lastWasOwnLineCustomItem ||
+ (wrapEnabled &&
+ ((!c->c.isSpace() && (hadBreakableChar || allowBreakInWords()) &&
+ ((wrapAtColumn() == -1 && x + ww > w) ||
+ (wrapAtColumn() != -1 && col >= wrapAtColumn()))))
+ )
+ ) {
+ if (wrapAtColumn() != -1)
+ minw = qMax(minw, x + ww);
+ // if a break was forced (no breakable char, hard break or own line custom item), break immediately....
+ if (!hadBreakableChar || lastWasHardBreak || lastWasOwnLineCustomItem) {
+ if (lineStart) {
+ lineStart->baseLine = qMax(lineStart->baseLine, tmpBaseLine);
+ h = qMax(h, tmph);
+ lineStart->h = h;
+ DO_FLOW(lineStart);
+ }
+ lineStart = formatLine(parag, string, lineStart, firstChar, c-1, align, SPACE(w - x));
+ x = doc ? doc->flow()->adjustLMargin(y + parag->rect().y(), parag->rect().height(), left, 4) : left;
+ w = dw - (doc ? doc->flow()->adjustRMargin(y + parag->rect().y(), parag->rect().height(), rm, 4) : 0);
+ if (!doc && c->c == TQLatin1Char('\t')) { // qt_format_text tab handling
+ int nx = parag->nextTab(i, x - tabBase) + tabBase;
+ if (nx < x)
+ ww = w - x;
+ else
+ ww = nx - x;
+ }
+ curLeft = x;
+ y += qMax(h, linespacing);
+ tmph = c->height();
+ h = 0;
+ lineStart->y = y;
+ insertLineStart(parag, i, lineStart);
+ lineStart->baseLine = c->ascent();
+ lineStart->h = c->height();
+ c->lineStart = 1;
+ firstChar = c;
+ tmpBaseLine = lineStart->baseLine;
+ lastBreak = -1;
+ col = 0;
+ if (allowBreakInWords() || lastWasHardBreak) {
+ minw = qMax(minw, tminw);
+ tminw = marg + ww;
+ }
+ } else { // ... otherwise if we had a breakable char, break there
+ DO_FLOW(lineStart);
+ c->x = x;
+ i = lastBreak;
+ lineStart = formatLine(parag, string, lineStart, firstChar, parag->at(lastBreak),align, SPACE(w - string->at(i+1).x));
+ x = doc ? doc->flow()->adjustLMargin(y + parag->rect().y(), parag->rect().height(), left, 4) : left;
+ w = dw - (doc ? doc->flow()->adjustRMargin(y + parag->rect().y(), parag->rect().height(), rm, 4) : 0);
+ if (!doc && c->c == TQLatin1Char('\t')) { // qt_format_text tab handling
+ int nx = parag->nextTab(i, x - tabBase) + tabBase;
+ if (nx < x)
+ ww = w - x;
+ else
+ ww = nx - x;
+ }
+ curLeft = x;
+ y += qMax(h, linespacing);
+ tmph = c->height();
+ h = tmph;
+ lineStart->y = y;
+ insertLineStart(parag, i + 1, lineStart);
+ lineStart->baseLine = c->ascent();
+ lineStart->h = c->height();
+ c->lineStart = 1;
+ firstChar = c;
+ tmpBaseLine = lineStart->baseLine;
+ lastBreak = -1;
+ col = 0;
+ minw = qMax(minw, tminw);
+ tminw = marg;
+ continue;
+ }
+ } else if (lineStart && isBreakable(string, i)) {
+ if (len <= 2 || i < len - 1) {
+ tmpBaseLine = qMax(tmpBaseLine, c->ascent());
+ tmph = qMax(tmph, c->height());
+ }
+ minw = qMax(minw, tminw);
+
+ tminw = marg + ww;
+ lineStart->baseLine = qMax(lineStart->baseLine, tmpBaseLine);
+ h = qMax(h, tmph);
+ lineStart->h = h;
+ if (i < len - 2 || c->c != TQLatin1Char(' '))
+ lastBreak = i;
+ } else {
+ tminw += ww;
+ int cascent = c->ascent();
+ int cheight = c->height();
+ int belowBaseLine = qMax(tmph - tmpBaseLine, cheight-cascent);
+ tmpBaseLine = qMax(tmpBaseLine, cascent);
+ tmph = tmpBaseLine + belowBaseLine;
+ }
+
+ c->x = x;
+ x += ww;
+ wused = qMax(wused, x);
+ }
+
+ if (lineStart) {
+ lineStart->baseLine = qMax(lineStart->baseLine, tmpBaseLine);
+ h = qMax(h, tmph);
+ lineStart->h = h;
+ // last line in a paragraph is not justified
+ if (align & Qt::AlignJustify) {
+ align |= Qt::AlignLeft;
+ align &= ~(Qt::AlignJustify|Qt::AlignAbsolute);
+ }
+ DO_FLOW(lineStart);
+ lineStart = formatLine(parag, string, lineStart, firstChar, c, align, SPACE(w - x));
+ delete lineStart;
+ }
+
+ minw = qMax(minw, tminw);
+ if (doc)
+ minw += doc->rightMargin();
+
+ int m = parag->bottomMargin();
+ if (!parag->next())
+ m = 0;
+ else
+ m = qMax(m, parag->next()->topMargin()) / 2;
+ parag->setFullWidth(fullWidth);
+ y += qMax(h, linespacing) + m;
+
+ wused += rm;
+ if (!wrapEnabled || wrapAtColumn() != -1)
+ minw = qMax(minw, wused);
+
+ // This is the case where we are breaking wherever we darn well please
+ // in cases like that, the minw should not be the length of the entire
+ // word, because we necessarily want to show the word on the whole line.
+ // example: word wrap in iconview
+ if (allowBreakInWords() && minw > wused)
+ minw = wused;
+
+ thisminw = minw;
+ thiswused = wused;
+ return y;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextIndent::TQTextIndent()
+{
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatCollection::TQTextFormatCollection()
+ : paintdevice(0)
+{
+ defFormat = new TQTextFormat(QApplication::font(),
+ QApplication::palette().color(QPalette::Active, QPalette::Text));
+ lastFormat = cres = 0;
+ cflags = -1;
+ cachedFormat = 0;
+}
+
+TQTextFormatCollection::~TQTextFormatCollection()
+{
+ QHash<TQString, TQTextFormat *>::ConstIterator it = cKey.constBegin();
+ while (it != cKey.constEnd()) {
+ delete it.value();
+ ++it;
+ }
+ delete defFormat;
+}
+
+void TQTextFormatCollection::setPaintDevice(QPaintDevice *pd)
+{
+ paintdevice = TQT_TQPAINTDEVICE(pd);
+
+#if defined(Q_WS_X11)
+ int scr = (paintdevice) ? paintdevice->x11Screen() : QX11Info::appScreen();
+
+ defFormat->fn.tqt_x11SetScreen(scr);
+ defFormat->update();
+
+ QHash<TQString, TQTextFormat *>::Iterator it = cKey.begin();
+ for (; it != cKey.end(); ++it) {
+ TQTextFormat *format = *it;
+ format->fn.tqt_x11SetScreen(scr);
+ format->update();
+ }
+#endif // Q_WS_X11
+}
+
+TQTextFormat *TQTextFormatCollection::format(TQTextFormat *f)
+{
+ if (f->parent() == this || f == defFormat) {
+ lastFormat = f;
+ lastFormat->addRef();
+ return lastFormat;
+ }
+
+ if (f == lastFormat || (lastFormat && f->key() == lastFormat->key())) {
+ lastFormat->addRef();
+ return lastFormat;
+ }
+
+ TQTextFormat *fm = cKey.value(f->key());
+ if (fm) {
+ lastFormat = fm;
+ lastFormat->addRef();
+ return lastFormat;
+ }
+
+ if (f->key() == defFormat->key())
+ return defFormat;
+
+ lastFormat = createFormat(*f);
+ lastFormat->collection = this;
+ cKey.insert(lastFormat->key(), lastFormat);
+ return lastFormat;
+}
+
+TQTextFormat *TQTextFormatCollection::format(TQTextFormat *of, TQTextFormat *nf, int flags)
+{
+ if (cres && kof == of->key() && knf == nf->key() && cflags == flags) {
+ cres->addRef();
+ return cres;
+ }
+
+ cres = createFormat(*of);
+ kof = of->key();
+ knf = nf->key();
+ cflags = flags;
+ if (flags & TQTextFormat::Bold)
+ cres->fn.setBold(nf->fn.bold());
+ if (flags & TQTextFormat::Italic)
+ cres->fn.setItalic(nf->fn.italic());
+ if (flags & TQTextFormat::Underline)
+ cres->fn.setUnderline(nf->fn.underline());
+ if (flags & TQTextFormat::StrikeOut)
+ cres->fn.setStrikeOut(nf->fn.strikeOut());
+ if (flags & TQTextFormat::Family)
+ cres->fn.setFamily(nf->fn.family());
+ if (flags & TQTextFormat::Size) {
+ if (of->usePixelSizes)
+ cres->fn.setPixelSize(nf->fn.pixelSize());
+ else
+ cres->fn.setPointSize(nf->fn.pointSize());
+ }
+ if (flags & TQTextFormat::Color)
+ cres->col = nf->col;
+ if (flags & TQTextFormat::Misspelled)
+ cres->missp = nf->missp;
+ if (flags & TQTextFormat::VAlign)
+ cres->ha = nf->ha;
+ cres->update();
+
+ TQTextFormat *fm = cKey.value(cres->key());
+ if (!fm) {
+ cres->collection = this;
+ cKey.insert(cres->key(), cres);
+ } else {
+ delete cres;
+ cres = fm;
+ cres->addRef();
+ }
+
+ return cres;
+}
+
+TQTextFormat *TQTextFormatCollection::format(const QFont &f, const QColor &c)
+{
+ if (cachedFormat && cfont == f && ccol == c) {
+ cachedFormat->addRef();
+ return cachedFormat;
+ }
+
+ TQString key = TQTextFormat::getKey(f, c, false, TQTextFormat::AlignNormal);
+ cachedFormat = cKey.value(key);
+ cfont = f;
+ ccol = c;
+
+ if (cachedFormat) {
+ cachedFormat->addRef();
+ return cachedFormat;
+ }
+
+ if (key == defFormat->key())
+ return defFormat;
+
+ cachedFormat = createFormat(f, c);
+ cachedFormat->collection = this;
+ cKey.insert(cachedFormat->key(), cachedFormat);
+ if (cachedFormat->key() != key)
+ qWarning("ASSERT: keys for format not identical: '%s '%s'", cachedFormat->key().latin1(), key.latin1());
+ return cachedFormat;
+}
+
+void TQTextFormatCollection::remove(TQTextFormat *f)
+{
+ if (lastFormat == f)
+ lastFormat = 0;
+ if (cres == f)
+ cres = 0;
+ if (cachedFormat == f)
+ cachedFormat = 0;
+ if (cKey.value(f->key()) == f)
+ delete cKey.take(f->key());
+}
+
+#define UPDATE(up, lo, rest) \
+ if (font.lo##rest() != defFormat->fn.lo##rest() && fm->fn.lo##rest() == defFormat->fn.lo##rest()) \
+ fm->fn.set##up##rest(font.lo##rest())
+
+void TQTextFormatCollection::updateDefaultFormat(const QFont &font, const QColor &color, TQStyleSheet *sheet)
+{
+ bool usePixels = font.pointSize() == -1;
+ bool changeSize = usePixels ? font.pixelSize() != defFormat->fn.pixelSize() :
+ font.pointSize() != defFormat->fn.pointSize();
+ int base = usePixels ? font.pixelSize() : font.pointSize();
+ QHash<TQString, TQTextFormat *>::Iterator it = cKey.begin();
+ for (; it != cKey.end(); ++it) {
+ TQTextFormat *fm = *it;
+ UPDATE(F, f, amily);
+ UPDATE(W, w, eight);
+ UPDATE(B, b, old);
+ UPDATE(I, i, talic);
+ UPDATE(U, u, nderline);
+ if (changeSize) {
+ fm->stdSize = base;
+ fm->usePixelSizes = usePixels;
+ if (usePixels)
+ fm->fn.setPixelSize(fm->stdSize);
+ else
+ fm->fn.setPointSize(fm->stdSize);
+ sheet->scaleFont(fm->fn, fm->logicalFontSize);
+ }
+ if (color.isValid() && color != defFormat->col && fm->col == defFormat->col)
+ fm->col = color;
+ fm->update();
+ }
+
+ defFormat->fn = font;
+ defFormat->col = color;
+ defFormat->update();
+ defFormat->stdSize = base;
+ defFormat->usePixelSizes = usePixels;
+
+ updateKeys();
+}
+
+// the keys in cKey have changed, rebuild the hashtable
+void TQTextFormatCollection::updateKeys()
+{
+ if (cKey.isEmpty())
+ return;
+ TQTextFormat** formats = new TQTextFormat *[cKey.count() + 1];
+ TQTextFormat **f = formats;
+ for (QHash<TQString, TQTextFormat *>::Iterator it = cKey.begin(); it != cKey.end(); ++it, ++f)
+ *f = *it;
+ *f = 0;
+ cKey.clear();
+ for (f = formats; *f; f++)
+ cKey.insert((*f)->key(), *f);
+ delete [] formats;
+}
+
+
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+void TQTextFormat::setBold(bool b)
+{
+ if (b == fn.bold())
+ return;
+ fn.setBold(b);
+ update();
+}
+
+void TQTextFormat::setMisspelled(bool b)
+{
+ if (b == (bool)missp)
+ return;
+ missp = b;
+ update();
+}
+
+void TQTextFormat::setVAlign(VerticalAlignment a)
+{
+ if (a == ha)
+ return;
+ ha = a;
+ update();
+}
+
+void TQTextFormat::setItalic(bool b)
+{
+ if (b == fn.italic())
+ return;
+ fn.setItalic(b);
+ update();
+}
+
+void TQTextFormat::setUnderline(bool b)
+{
+ if (b == fn.underline())
+ return;
+ fn.setUnderline(b);
+ update();
+}
+
+void TQTextFormat::setStrikeOut(bool b)
+{
+ if (b == fn.strikeOut())
+ return;
+ fn.setStrikeOut(b);
+ update();
+}
+
+void TQTextFormat::setFamily(const TQString &f)
+{
+ if (f == fn.family())
+ return;
+ fn.setFamily(f);
+ update();
+}
+
+void TQTextFormat::setPointSize(int s)
+{
+ if (s == fn.pointSize())
+ return;
+ fn.setPointSize(s);
+ usePixelSizes = false;
+ update();
+}
+
+void TQTextFormat::setFont(const QFont &f)
+{
+ if (f == fn && !k.isEmpty())
+ return;
+ fn = f;
+ update();
+}
+
+void TQTextFormat::setColor(const QColor &c)
+{
+ if (c == col)
+ return;
+ col = c;
+ update();
+}
+
+TQString TQTextFormat::makeFormatChangeTags(TQTextFormat* defaultFormat, TQTextFormat *f,
+ const TQString& oldAnchorHref, const TQString& anchorHref ) const
+{
+ TQString tag;
+ if (f)
+ tag += f->makeFormatEndTags(defaultFormat, oldAnchorHref);
+
+ if (!anchorHref.isEmpty())
+ tag += TQLatin1String("<a href=\"") + anchorHref + TQLatin1String("\">");
+
+ if (font() != defaultFormat->font()
+ || vAlign() != defaultFormat->vAlign()
+ || color().rgb() != defaultFormat->color().rgb()) {
+ TQString s;
+ if (font().family() != defaultFormat->font().family())
+ s += TQString(s.size()?TQLatin1String(";"):TQLatin1String("")) + TQLatin1String("font-family:") + fn.family();
+ if (font().italic() && font().italic() != defaultFormat->font().italic())
+ s += TQString(s.size()?TQLatin1String(";"):TQLatin1String("")) + TQLatin1String("font-style:") + (font().italic() ? TQLatin1String("italic") : TQLatin1String("normal"));
+ if (font().pointSize() != defaultFormat->font().pointSize())
+ s += TQString(s.size()?TQLatin1String(";"):TQLatin1String("")) + TQLatin1String("font-size:") + TQString::number(fn.pointSize()) + TQLatin1String("pt");
+ if (font().weight() != defaultFormat->font().weight())
+ s += TQString(s.size()?TQLatin1String(";"):TQLatin1String("")) + TQLatin1String("font-weight:") + TQString::number(fn.weight() * 8);
+ TQString textDecoration;
+ bool none = false;
+ if ( font().underline() != defaultFormat->font().underline() ) {
+ if (font().underline())
+ textDecoration = TQLatin1String("underline");
+ else
+ none = true;
+ }
+ if ( font().overline() != defaultFormat->font().overline() ) {
+ if (font().overline())
+ textDecoration += TQLatin1String(" overline");
+ else
+ none = true;
+ }
+ if ( font().strikeOut() != defaultFormat->font().strikeOut() ) {
+ if (font().strikeOut())
+ textDecoration += TQLatin1String(" line-through");
+ else
+ none = true;
+ }
+ if (none && textDecoration.isEmpty())
+ textDecoration = TQLatin1String("none");
+ if (!textDecoration.isEmpty())
+ s += TQString(s.size()?TQLatin1String(";"):TQLatin1String("")) + TQLatin1String("text-decoration:") + textDecoration;
+ if (vAlign() != defaultFormat->vAlign()) {
+ s += TQString(s.size()?TQLatin1String(";"):TQLatin1String("")) + TQLatin1String("vertical-align:");
+ if (vAlign() == TQTextFormat::AlignSuperScript)
+ s += TQLatin1String("super");
+ else if (vAlign() == TQTextFormat::AlignSubScript)
+ s += TQLatin1String("sub");
+ else
+ s += TQLatin1String("normal");
+ }
+ if (color().rgb() != defaultFormat->color().rgb())
+ s += TQString(s.size()?TQLatin1String(";"):TQLatin1String("")) + TQLatin1String("color:") + col.name();
+ if (!s.isEmpty())
+ tag += TQLatin1String("<span style=\"") + s + TQLatin1String("\">");
+ }
+
+ return tag;
+}
+
+TQString TQTextFormat::makeFormatEndTags(TQTextFormat* defaultFormat, const TQString& anchorHref) const
+{
+ TQString tag;
+ if (font().family() != defaultFormat->font().family()
+ || font().pointSize() != defaultFormat->font().pointSize()
+ || font().weight() != defaultFormat->font().weight()
+ || font().italic() != defaultFormat->font().italic()
+ || font().underline() != defaultFormat->font().underline()
+ || font().strikeOut() != defaultFormat->font().strikeOut()
+ || vAlign() != defaultFormat->vAlign()
+ || color().rgb() != defaultFormat->color().rgb())
+ tag += TQLatin1String("</span>");
+ if (!anchorHref.isEmpty())
+ tag += TQLatin1String("</a>");
+ return tag;
+}
+
+TQTextFormat TQTextFormat::makeTextFormat(const TQStyleSheetItem *style, const QMap<TQString,TQString>& attr, double scaleFontsFactor) const
+{
+ TQTextFormat format(*this);
+ if (!style)
+ return format;
+
+ if (!style->isAnchor() && style->color().isValid()) {
+ // the style is not an anchor and defines a color.
+ // It might be used inside an anchor and it should
+ // override the link color.
+ format.linkColor = false;
+ }
+ switch (style->verticalAlignment()) {
+ case TQStyleSheetItem::VAlignBaseline:
+ format.setVAlign(TQTextFormat::AlignNormal);
+ break;
+ case TQStyleSheetItem::VAlignSuper:
+ format.setVAlign(TQTextFormat::AlignSuperScript);
+ break;
+ case TQStyleSheetItem::VAlignSub:
+ format.setVAlign(TQTextFormat::AlignSubScript);
+ break;
+ }
+
+ if (style->fontWeight() != TQStyleSheetItem::Undefined)
+ format.fn.setWeight(style->fontWeight());
+ if (style->fontSize() != TQStyleSheetItem::Undefined) {
+ format.fn.setPointSize(style->fontSize());
+ } else if (style->logicalFontSize() != TQStyleSheetItem::Undefined) {
+ format.logicalFontSize = style->logicalFontSize();
+ if (format.usePixelSizes)
+ format.fn.setPixelSize(format.stdSize);
+ else
+ format.fn.setPointSize(format.stdSize);
+ style->styleSheet()->scaleFont(format.fn, format.logicalFontSize);
+ } else if (style->logicalFontSizeStep()) {
+ format.logicalFontSize += style->logicalFontSizeStep();
+ if (format.usePixelSizes)
+ format.fn.setPixelSize(format.stdSize);
+ else
+ format.fn.setPointSize(format.stdSize);
+ style->styleSheet()->scaleFont(format.fn, format.logicalFontSize);
+ }
+ if (!style->fontFamily().isEmpty())
+ format.fn.setFamily(style->fontFamily());
+ if (style->color().isValid())
+ format.col = style->color();
+ if (style->definesFontItalic())
+ format.fn.setItalic(style->fontItalic());
+ if (style->definesFontUnderline())
+ format.fn.setUnderline(style->fontUnderline());
+ if (style->definesFontStrikeOut())
+ format.fn.setStrikeOut(style->fontStrikeOut());
+
+ QMap<TQString, TQString>::ConstIterator it, end = attr.end();
+
+ if (style->name() == TQLatin1String("font")) {
+ it = attr.find(TQLatin1String("color"));
+ if (it != end && ! (*it).isEmpty()){
+ format.col.setNamedColor(*it);
+ format.linkColor = false;
+ }
+ it = attr.find(TQLatin1String("face"));
+ if (it != end) {
+ TQString family = (*it).section(TQLatin1Char(','), 0, 0);
+ if (family.size())
+ format.fn.setFamily(family);
+ }
+ it = attr.find(TQLatin1String("size"));
+ if (it != end) {
+ TQString a = *it;
+ int n = a.toInt();
+ if (a[0] == TQLatin1Char('+') || a[0] == TQLatin1Char('-'))
+ n += 3;
+ format.logicalFontSize = n;
+ if (format.usePixelSizes)
+ format.fn.setPixelSize(format.stdSize);
+ else
+ format.fn.setPointSize(format.stdSize);
+ style->styleSheet()->scaleFont(format.fn, format.logicalFontSize);
+ }
+ }
+
+ it = attr.find(TQLatin1String("style"));
+ if (it != end) {
+ TQString a = *it;
+ int count = a.count(TQLatin1Char(';'))+1;
+ for (int s = 0; s < count; s++) {
+ TQString style = a.section(TQLatin1Char(';'), s, s);
+ if (style.startsWith(TQLatin1String("font-size:")) && style.endsWith(TQLatin1String("pt"))) {
+ format.logicalFontSize = 0;
+ int size = int(scaleFontsFactor * style.mid(10, style.length() - 12).toDouble());
+ format.setPointSize(size);
+ } else if (style.startsWith(TQLatin1String("font-style:"))) {
+ TQString s = style.mid(11).trimmed();
+ if (s == TQLatin1String("normal"))
+ format.fn.setItalic(false);
+ else if (s == TQLatin1String("italic") || s == TQLatin1String("oblique"))
+ format.fn.setItalic(true);
+ } else if (style.startsWith(TQLatin1String("font-weight:"))) {
+ TQString s = style.mid(12);
+ bool ok = true;
+ int n = s.toInt(&ok);
+ if (ok)
+ format.fn.setWeight(n/8);
+ } else if (style.startsWith(TQLatin1String("font-family:"))) {
+ TQString family = style.mid(12).section(TQLatin1Char(','),0,0);
+ family.replace(TQLatin1Char('\"'), TQLatin1Char(' '));
+ family.replace(TQLatin1Char('\''), TQLatin1Char(' '));
+ family = family.trimmed();
+ format.fn.setFamily(family);
+ } else if (style.startsWith(TQLatin1String("text-decoration:"))) {
+ TQString s = style.mid( 16 );
+ format.fn.setOverline(s.contains(TQLatin1String("overline")));
+ format.fn.setStrikeOut(s.contains(TQLatin1String("line-through")));
+ format.fn.setUnderline(s.contains(TQLatin1String("underline")));
+ } else if (style.startsWith(TQLatin1String("vertical-align:"))) {
+ TQString s = style.mid(15).trimmed();
+ if (s == TQLatin1String("sub"))
+ format.setVAlign(TQTextFormat::AlignSubScript);
+ else if (s == TQLatin1String("super"))
+ format.setVAlign(TQTextFormat::AlignSuperScript);
+ else
+ format.setVAlign(TQTextFormat::AlignNormal);
+ } else if (style.startsWith(TQLatin1String("color:"))) {
+ format.col.setNamedColor(style.mid(6));
+ format.linkColor = false;
+ }
+ }
+ }
+
+ format.update();
+ return format;
+}
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+
+struct TQPixmapInt
+{
+ TQPixmapInt() : ref(0) {}
+ TQPixmap pm;
+ int ref;
+ Q_DUMMY_COMPARISON_OPERATOR(TQPixmapInt)
+};
+
+static QMap<TQString, TQPixmapInt> *pixmap_map = 0;
+
+TQTextImage::TQTextImage(TQTextDocument *p, const QMap<TQString, TQString> &attr, const TQString& context,
+ TQMimeSourceFactory &factory)
+ : TQTextCustomItem(p)
+{
+ width = height = 0;
+
+ QMap<TQString, TQString>::ConstIterator it, end = attr.end();
+ it = attr.find(TQLatin1String("width"));
+ if (it != end)
+ width = (*it).toInt();
+ it = attr.find(TQLatin1String("height"));
+ if (it != end)
+ height = (*it).toInt();
+
+ reg = 0;
+ TQString imageName = attr[TQLatin1String("src")];
+
+ if (imageName.size() == 0)
+ imageName = attr[TQLatin1String("source")];
+
+ if (!imageName.isEmpty()) {
+ imgId = TQString::fromLatin1("%1,%2,%3,%4").arg(imageName).arg(width).arg(height).arg((quintptr)&factory);
+ if (!pixmap_map)
+ pixmap_map = new QMap<TQString, TQPixmapInt>;
+ if (pixmap_map->contains(imgId)) {
+ TQPixmapInt& pmi = pixmap_map->operator[](imgId);
+ pm = pmi.pm;
+ pmi.ref++;
+ width = pm.width();
+ height = pm.height();
+ } else {
+ TQImage img;
+ const QMimeSource* m =
+ factory.data(imageName, context);
+ if (!m) {
+ qCritical("TQTextImage: no mimesource for %s", imageName.latin1());
+ }
+ else {
+ if (!TQImageDrag::decode(TQT_TQMIMESOURCE_CONST(m), img)) {
+ qCritical("TQTextImage: cannot decode %s", imageName.latin1());
+ }
+ }
+
+ if (!img.isNull()) {
+ if (width == 0) {
+ width = img.width();
+ if (height != 0) {
+ width = img.width() * height / img.height();
+ }
+ }
+ if (height == 0) {
+ height = img.height();
+ if (width != img.width()) {
+ height = img.height() * width / img.width();
+ }
+ }
+ if (img.width() != width || img.height() != height){
+#ifndef QT_NO_IMAGE_SMOOTHSCALE
+ img = img.smoothScale(width, height);
+#endif
+ width = img.width();
+ height = img.height();
+ }
+ pm.convertFromImage(img);
+ }
+ if (!pm.isNull()) {
+ TQPixmapInt& pmi = pixmap_map->operator[](imgId);
+ pmi.pm = pm;
+ pmi.ref++;
+ }
+ }
+ if (pm.hasAlphaChannel()) {
+ QRegion mask(pm.mask());
+ QRegion all(0, 0, pm.width(), pm.height());
+ reg = new QRegion(all.subtracted(mask));
+ }
+ }
+
+ if (pm.isNull() && (width*height)==0)
+ width = height = 50;
+
+ place = PlaceInline;
+ if (attr[TQLatin1String("align")] == TQLatin1String("left"))
+ place = PlaceLeft;
+ else if (attr[TQLatin1String("align")] == TQLatin1String("right"))
+ place = PlaceRight;
+
+ tmpwidth = width;
+ tmpheight = height;
+
+ attributes = attr;
+}
+
+TQTextImage::~TQTextImage()
+{
+ if (pixmap_map && pixmap_map->contains(imgId)) {
+ TQPixmapInt& pmi = pixmap_map->operator[](imgId);
+ pmi.ref--;
+ if (!pmi.ref) {
+ pixmap_map->remove(imgId);
+ if (pixmap_map->isEmpty()) {
+ delete pixmap_map;
+ pixmap_map = 0;
+ }
+ }
+ }
+ delete reg;
+}
+
+TQString TQTextImage::richText() const
+{
+ TQString s;
+ s += TQLatin1String("<img ");
+ QMap<TQString, TQString>::ConstIterator it = attributes.begin();
+ for (; it != attributes.end(); ++it) {
+ s += it.key() + TQLatin1Char('=');
+ if ((*it).contains(TQLatin1Char(' ')))
+ s += TQLatin1Char('\"') + *it + TQLatin1String("\" ");
+ else
+ s += *it + TQLatin1Char(' ');
+ }
+ s += TQLatin1Char('>');
+ return s;
+}
+
+void TQTextImage::adjustToPainter(TQPainter* p)
+{
+ width = scale(tmpwidth, p);
+ height = scale(tmpheight, p);
+}
+
+#if !defined(Q_WS_X11)
+static TQPixmap *qrt_selection = 0;
+static TQSingleCleanupHandler<TQPixmap> qrt_cleanup_pixmap;
+static void qrt_createSelectionPixmap(const QPalette &pal)
+{
+ qrt_selection = new TQPixmap(2, 2);
+ qrt_cleanup_pixmap.set(&qrt_selection);
+ qrt_selection->fill(Qt::color0);
+ QBitmap m(2, 2);
+ m.fill(Qt::color1);
+ TQPainter p(&m);
+ p.setPen(Qt::color0);
+ for (int j = 0; j < 2; ++j) {
+ p.drawPoint(j % 2, j);
+ }
+ p.end();
+ qrt_selection->setMask(m);
+ qrt_selection->fill(pal.highlight().color());
+}
+#endif
+
+void TQTextImage::draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected)
+{
+ if (placement() != PlaceInline) {
+ x = xpos;
+ y = ypos;
+ }
+
+ if (pm.isNull()) {
+ p->fillRect(x , y, width, height, pal.dark());
+ return;
+ }
+
+ if (is_printer(p)) {
+ p->drawPixmap(TQRect(x, y, width, height), pm);
+ return;
+ }
+
+ if (placement() != PlaceInline && !TQRect(xpos, ypos, width, height).intersects(TQRect(cx, cy, cw, ch)))
+ return;
+
+ if (placement() == PlaceInline)
+ p->drawPixmap(x , y, pm);
+ else
+ p->drawPixmap(cx , cy, pm, cx - x, cy - y, cw, ch);
+
+ if (selected && placement() == PlaceInline && is_printer(p)) {
+#if defined(Q_WS_X11)
+ p->fillRect(TQRect(QPoint(x, y), pm.size()), TQBrush(pal.Highlight,
+ Qt::Dense4Pattern));
+#else // in WIN32 Qt::Dense4Pattern doesn't work correctly (transparency problem), so work around it
+ if (!qrt_selection)
+ qrt_createSelectionPixmap(pal);
+ p->drawTiledPixmap(x, y, pm.width(), pm.height(), *qrt_selection);
+#endif
+ }
+}
+
+void TQTextHorizontalLine::adjustToPainter(TQPainter* p)
+{
+ height = scale(tmpheight, p);
+}
+
+
+TQTextHorizontalLine::TQTextHorizontalLine(TQTextDocument *p, const QMap<TQString, TQString> &attr,
+ const TQString &,
+ TQMimeSourceFactory &)
+ : TQTextCustomItem(p)
+{
+ height = tmpheight = 8;
+ QMap<TQString, TQString>::ConstIterator it, end = attr.end();
+ it = attr.find(TQLatin1String("color"));
+ if (it != end)
+ color = QColor(*it);
+ shade = attr.find(TQLatin1String("noshade")) == end;
+}
+
+TQTextHorizontalLine::~TQTextHorizontalLine()
+{
+}
+
+TQString TQTextHorizontalLine::richText() const
+{
+ return TQLatin1String("<hr>");
+}
+
+void TQTextHorizontalLine::draw(TQPainter* p, int x, int y, int , int , int , int ,
+ const QPalette& pal, bool selected)
+{
+ TQRect r(x, y, width, height);
+ if (is_printer(p) || !shade) {
+ QPen oldPen = p->pen();
+ if (!color.isValid())
+ p->setPen(QPen(pal.text().color(), is_printer(p) ? height/8 : qMax(2, height/4)));
+ else
+ p->setPen(QPen(color, is_printer(p) ? height/8 : qMax(2, height/4)));
+ p->drawLine(r.left()-1, y + height / 2, r.right() + 1, y + height / 2);
+ p->setPen(oldPen);
+ } else {
+ if (selected)
+ p->fillRect(r, pal.highlight());
+ QPalette pal2(pal);
+ if (color.isValid())
+ pal2.setColor(pal2.currentColorGroup(), QPalette::Dark, color);
+ qDrawShadeLine(p, r.left() - 1, y + height / 2, r.right() + 1, y + height / 2, pal2,
+ true, height / 8);
+ }
+}
+#endif //QT_NO_TEXTCUSTOMITEM
+
+/*****************************************************************/
+// Small set of utility functions to make the parser a bit simpler
+//
+
+bool TQTextDocument::hasPrefix(const TQChar* doc, int length, int pos, TQChar c)
+{
+ if (pos + 1 > length)
+ return false;
+ return doc[pos].toLower() == c.toLower();
+}
+
+bool TQTextDocument::hasPrefix(const TQChar* doc, int length, int pos, const TQString& s)
+{
+ if (pos + (int) s.length() > length)
+ return false;
+ for (int i = 0; i < (int)s.length(); i++) {
+ if (doc[pos + i].toLower() != s[i].toLower())
+ return false;
+ }
+ return true;
+}
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+static bool qt_is_cell_in_use(QList<TQTextTableCell *>& cells, int row, int col)
+{
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *c = cells.at(idx);
+ if (row >= c->row() && row < c->row() + c->rowspan()
+ && col >= c->column() && col < c->column() + c->colspan())
+ return true;
+ }
+ return false;
+}
+
+TQTextCustomItem* TQTextDocument::parseTable(const QMap<TQString, TQString> &attr, const TQTextFormat &fmt,
+ const TQChar* doc, int length, int& pos, TQTextParagraph *curpar)
+{
+
+ TQTextTable* table = new TQTextTable(this, attr);
+ int row = -1;
+ int col = -1;
+
+ TQString rowbgcolor;
+ TQString rowalign;
+ TQString tablebgcolor = attr[TQLatin1String("bgcolor")];
+
+ QList<TQTextTableCell *> multicells;
+
+ TQString tagname;
+ (void) eatSpace(doc, length, pos);
+ while (pos < length) {
+ if (hasPrefix(doc, length, pos, TQLatin1Char('<'))){
+ if (hasPrefix(doc, length, pos+1, TQLatin1Char('/'))) {
+ tagname = parseCloseTag(doc, length, pos);
+ if (tagname == TQLatin1String("table")) {
+ return table;
+ }
+ } else {
+ QMap<TQString, TQString> attr2;
+ bool emptyTag = false;
+ tagname = parseOpenTag(doc, length, pos, attr2, emptyTag);
+ if (tagname == TQLatin1String("tr")) {
+ rowbgcolor = attr2[TQLatin1String("bgcolor")];
+ rowalign = attr2[TQLatin1String("align")];
+ row++;
+ col = -1;
+ }
+ else if (tagname == TQLatin1String("td") || tagname == TQLatin1String("th")) {
+ col++;
+ while (qt_is_cell_in_use(multicells, row, col)) {
+ col++;
+ }
+
+ if (row >= 0 && col >= 0) {
+ const TQStyleSheetItem* s = sheet_->item(tagname);
+ if (!attr2.contains(TQLatin1String("bgcolor"))) {
+ if (!rowbgcolor.isEmpty())
+ attr2[TQLatin1String("bgcolor")] = rowbgcolor;
+ else if (!tablebgcolor.isEmpty())
+ attr2[TQLatin1String("bgcolor")] = tablebgcolor;
+ }
+ if (!attr2.contains(TQLatin1String("align"))) {
+ if (!rowalign.isEmpty())
+ attr2[TQLatin1String("align")] = rowalign;
+ }
+
+ // extract the cell contents
+ int end = pos;
+ while (end < length
+ && !hasPrefix(doc, length, end, TQLatin1String("</td"))
+ && !hasPrefix(doc, length, end, TQLatin1String("<td"))
+ && !hasPrefix(doc, length, end, TQLatin1String("</th"))
+ && !hasPrefix(doc, length, end, TQLatin1String("<th"))
+ && !hasPrefix(doc, length, end, TQLatin1String("<td"))
+ && !hasPrefix(doc, length, end, TQLatin1String("</tr"))
+ && !hasPrefix(doc, length, end, TQLatin1String("<tr"))
+ && !hasPrefix(doc, length, end, TQLatin1String("</table"))) {
+ if (hasPrefix(doc, length, end, TQLatin1String("<table"))) { // nested table
+ int nested = 1;
+ ++end;
+ while (end < length && nested != 0) {
+ if (hasPrefix(doc, length, end, TQLatin1String("</table")))
+ nested--;
+ if (hasPrefix(doc, length, end, TQLatin1String("<table")))
+ nested++;
+ end++;
+ }
+ }
+ end++;
+ }
+ TQTextTableCell* cell = new TQTextTableCell(table, row, col,
+ attr2, s, fmt.makeTextFormat(s, attr2, scaleFontsFactor),
+ contxt, *factory_, sheet_,
+ TQString::fromRawData(doc + pos, end - pos));
+ cell->richText()->parentPar = curpar;
+ if (cell->colspan() > 1 || cell->rowspan() > 1)
+ multicells.append(cell);
+ col += cell->colspan()-1;
+ pos = end;
+ }
+ }
+ }
+
+ } else {
+ ++pos;
+ }
+ }
+ return table;
+}
+#endif // QT_NO_TEXTCUSTOMITEM
+
+bool TQTextDocument::eatSpace(const TQChar* doc, int length, int& pos, bool includeNbsp)
+{
+ int old_pos = pos;
+ while (pos < length && doc[pos].isSpace() && (includeNbsp || (doc[pos] != TQChar(TQChar::nbsp))))
+ pos++;
+ return old_pos < pos;
+}
+
+bool TQTextDocument::eat(const TQChar* doc, int length, int& pos, TQChar c)
+{
+ bool ok = pos < length && doc[pos] == c;
+ if (ok)
+ pos++;
+ return ok;
+}
+/*****************************************************************/
+
+struct Entity {
+ const char * name;
+ Q_UINT16 code;
+};
+
+static const Entity entitylist [] = {
+ { "AElig", 0x00c6 },
+ { "Aacute", 0x00c1 },
+ { "Acirc", 0x00c2 },
+ { "Agrave", 0x00c0 },
+ { "Alpha", 0x0391 },
+ { "AMP", 38 },
+ { "Aring", 0x00c5 },
+ { "Atilde", 0x00c3 },
+ { "Auml", 0x00c4 },
+ { "Beta", 0x0392 },
+ { "Ccedil", 0x00c7 },
+ { "Chi", 0x03a7 },
+ { "Dagger", 0x2021 },
+ { "Delta", 0x0394 },
+ { "ETH", 0x00d0 },
+ { "Eacute", 0x00c9 },
+ { "Ecirc", 0x00ca },
+ { "Egrave", 0x00c8 },
+ { "Epsilon", 0x0395 },
+ { "Eta", 0x0397 },
+ { "Euml", 0x00cb },
+ { "Gamma", 0x0393 },
+ { "GT", 62 },
+ { "Iacute", 0x00cd },
+ { "Icirc", 0x00ce },
+ { "Igrave", 0x00cc },
+ { "Iota", 0x0399 },
+ { "Iuml", 0x00cf },
+ { "Kappa", 0x039a },
+ { "Lambda", 0x039b },
+ { "LT", 60 },
+ { "Mu", 0x039c },
+ { "Ntilde", 0x00d1 },
+ { "Nu", 0x039d },
+ { "OElig", 0x0152 },
+ { "Oacute", 0x00d3 },
+ { "Ocirc", 0x00d4 },
+ { "Ograve", 0x00d2 },
+ { "Omega", 0x03a9 },
+ { "Omicron", 0x039f },
+ { "Oslash", 0x00d8 },
+ { "Otilde", 0x00d5 },
+ { "Ouml", 0x00d6 },
+ { "Phi", 0x03a6 },
+ { "Pi", 0x03a0 },
+ { "Prime", 0x2033 },
+ { "Psi", 0x03a8 },
+ { "QUOT", 34 },
+ { "Rho", 0x03a1 },
+ { "Scaron", 0x0160 },
+ { "Sigma", 0x03a3 },
+ { "THORN", 0x00de },
+ { "Tau", 0x03a4 },
+ { "Theta", 0x0398 },
+ { "Uacute", 0x00da },
+ { "Ucirc", 0x00db },
+ { "Ugrave", 0x00d9 },
+ { "Upsilon", 0x03a5 },
+ { "Uuml", 0x00dc },
+ { "Xi", 0x039e },
+ { "Yacute", 0x00dd },
+ { "Yuml", 0x0178 },
+ { "Zeta", 0x0396 },
+ { "aacute", 0x00e1 },
+ { "acirc", 0x00e2 },
+ { "acute", 0x00b4 },
+ { "aelig", 0x00e6 },
+ { "agrave", 0x00e0 },
+ { "alefsym", 0x2135 },
+ { "alpha", 0x03b1 },
+ { "amp", 38 },
+ { "and", 0x22a5 },
+ { "ang", 0x2220 },
+ { "apos", 0x0027 },
+ { "aring", 0x00e5 },
+ { "asymp", 0x2248 },
+ { "atilde", 0x00e3 },
+ { "auml", 0x00e4 },
+ { "bdquo", 0x201e },
+ { "beta", 0x03b2 },
+ { "brvbar", 0x00a6 },
+ { "bull", 0x2022 },
+ { "cap", 0x2229 },
+ { "ccedil", 0x00e7 },
+ { "cedil", 0x00b8 },
+ { "cent", 0x00a2 },
+ { "chi", 0x03c7 },
+ { "circ", 0x02c6 },
+ { "clubs", 0x2663 },
+ { "cong", 0x2245 },
+ { "copy", 0x00a9 },
+ { "crarr", 0x21b5 },
+ { "cup", 0x222a },
+ { "cur" "ren", 0x00a4 },
+ { "dArr", 0x21d3 },
+ { "dagger", 0x2020 },
+ { "darr", 0x2193 },
+ { "deg", 0x00b0 },
+ { "delta", 0x03b4 },
+ { "diams", 0x2666 },
+ { "divide", 0x00f7 },
+ { "eacute", 0x00e9 },
+ { "ecirc", 0x00ea },
+ { "egrave", 0x00e8 },
+ { "empty", 0x2205 },
+ { "emsp", 0x2003 },
+ { "ensp", 0x2002 },
+ { "epsilon", 0x03b5 },
+ { "equiv", 0x2261 },
+ { "eta", 0x03b7 },
+ { "eth", 0x00f0 },
+ { "euml", 0x00eb },
+ { "euro", 0x20ac },
+ { "exist", 0x2203 },
+ { "fnof", 0x0192 },
+ { "forall", 0x2200 },
+ { "frac12", 0x00bd },
+ { "frac14", 0x00bc },
+ { "frac34", 0x00be },
+ { "frasl", 0x2044 },
+ { "gamma", 0x03b3 },
+ { "ge", 0x2265 },
+ { "gt", 62 },
+ { "hArr", 0x21d4 },
+ { "harr", 0x2194 },
+ { "hearts", 0x2665 },
+ { "hellip", 0x2026 },
+ { "iacute", 0x00ed },
+ { "icirc", 0x00ee },
+ { "iexcl", 0x00a1 },
+ { "igrave", 0x00ec },
+ { "image", 0x2111 },
+ { "infin", 0x221e },
+ { "int", 0x222b },
+ { "iota", 0x03b9 },
+ { "iquest", 0x00bf },
+ { "isin", 0x2208 },
+ { "iuml", 0x00ef },
+ { "kappa", 0x03ba },
+ { "lArr", 0x21d0 },
+ { "lambda", 0x03bb },
+ { "lang", 0x2329 },
+ { "laquo", 0x00ab },
+ { "larr", 0x2190 },
+ { "lceil", 0x2308 },
+ { "ldquo", 0x201c },
+ { "le", 0x2264 },
+ { "lfloor", 0x230a },
+ { "lowast", 0x2217 },
+ { "loz", 0x25ca },
+ { "lrm", 0x200e },
+ { "lsaquo", 0x2039 },
+ { "lsquo", 0x2018 },
+ { "lt", 60 },
+ { "macr", 0x00af },
+ { "mdash", 0x2014 },
+ { "micro", 0x00b5 },
+ { "middot", 0x00b7 },
+ { "minus", 0x2212 },
+ { "mu", 0x03bc },
+ { "nabla", 0x2207 },
+ { "nbsp", 0x00a0 },
+ { "ndash", 0x2013 },
+ { "ne", 0x2260 },
+ { "ni", 0x220b },
+ { "not", 0x00ac },
+ { "notin", 0x2209 },
+ { "nsub", 0x2284 },
+ { "ntilde", 0x00f1 },
+ { "nu", 0x03bd },
+ { "oacute", 0x00f3 },
+ { "ocirc", 0x00f4 },
+ { "oelig", 0x0153 },
+ { "ograve", 0x00f2 },
+ { "oline", 0x203e },
+ { "omega", 0x03c9 },
+ { "omicron", 0x03bf },
+ { "oplus", 0x2295 },
+ { "or", 0x22a6 },
+ { "ordf", 0x00aa },
+ { "ordm", 0x00ba },
+ { "oslash", 0x00f8 },
+ { "otilde", 0x00f5 },
+ { "otimes", 0x2297 },
+ { "ouml", 0x00f6 },
+ { "para", 0x00b6 },
+ { "part", 0x2202 },
+ { "percnt", 0x0025 },
+ { "permil", 0x2030 },
+ { "perp", 0x22a5 },
+ { "phi", 0x03c6 },
+ { "pi", 0x03c0 },
+ { "piv", 0x03d6 },
+ { "plusmn", 0x00b1 },
+ { "pound", 0x00a3 },
+ { "prime", 0x2032 },
+ { "prod", 0x220f },
+ { "prop", 0x221d },
+ { "psi", 0x03c8 },
+ { "quot", 34 },
+ { "rArr", 0x21d2 },
+ { "radic", 0x221a },
+ { "rang", 0x232a },
+ { "raquo", 0x00bb },
+ { "rarr", 0x2192 },
+ { "rceil", 0x2309 },
+ { "rdquo", 0x201d },
+ { "real", 0x211c },
+ { "reg", 0x00ae },
+ { "rfloor", 0x230b },
+ { "rho", 0x03c1 },
+ { "rlm", 0x200f },
+ { "rsaquo", 0x203a },
+ { "rsquo", 0x2019 },
+ { "sbquo", 0x201a },
+ { "scaron", 0x0161 },
+ { "sdot", 0x22c5 },
+ { "sect", 0x00a7 },
+ { "shy", 0x00ad },
+ { "sigma", 0x03c3 },
+ { "sigmaf", 0x03c2 },
+ { "sim", 0x223c },
+ { "spades", 0x2660 },
+ { "sub", 0x2282 },
+ { "sube", 0x2286 },
+ { "sum", 0x2211 },
+ { "sup1", 0x00b9 },
+ { "sup2", 0x00b2 },
+ { "sup3", 0x00b3 },
+ { "sup", 0x2283 },
+ { "supe", 0x2287 },
+ { "szlig", 0x00df },
+ { "tau", 0x03c4 },
+ { "there4", 0x2234 },
+ { "theta", 0x03b8 },
+ { "thetasym", 0x03d1 },
+ { "thinsp", 0x2009 },
+ { "thorn", 0x00fe },
+ { "tilde", 0x02dc },
+ { "times", 0x00d7 },
+ { "trade", 0x2122 },
+ { "uArr", 0x21d1 },
+ { "uacute", 0x00fa },
+ { "uarr", 0x2191 },
+ { "ucirc", 0x00fb },
+ { "ugrave", 0x00f9 },
+ { "uml", 0x00a8 },
+ { "upsih", 0x03d2 },
+ { "upsilon", 0x03c5 },
+ { "uuml", 0x00fc },
+ { "weierp", 0x2118 },
+ { "xi", 0x03be },
+ { "yacute", 0x00fd },
+ { "yen", 0x00a5 },
+ { "yuml", 0x00ff },
+ { "zeta", 0x03b6 },
+ { "zwj", 0x200d },
+ { "zwnj", 0x200c },
+ { "", 0x0000 }
+};
+
+
+
+
+
+static QMap<QByteArray, TQChar> *html_map = 0;
+static void qt_cleanup_html_map()
+{
+ delete html_map;
+ html_map = 0;
+}
+
+static QMap<QByteArray, TQChar> *htmlMap()
+{
+ if (!html_map) {
+ html_map = new QMap<QByteArray, TQChar>;
+ qAddPostRoutine(qt_cleanup_html_map);
+
+ const Entity *ent = entitylist;
+ while(ent->code) {
+ html_map->insert(QByteArray(ent->name), TQChar(ent->code));
+ ent++;
+ }
+ }
+ return html_map;
+}
+
+TQChar TQTextDocument::parseHTMLSpecialChar(const TQChar* doc, int length, int& pos)
+{
+ TQString s;
+ pos++;
+ int recoverpos = pos;
+ while (pos < length && doc[pos] != TQLatin1Char(';') && !doc[pos].isSpace() && pos < recoverpos + 8) {
+ s += doc[pos];
+ pos++;
+ }
+ if (doc[pos] != TQLatin1Char(';') && !doc[pos].isSpace()) {
+ pos = recoverpos;
+ return TQLatin1Char('&');
+ }
+ pos++;
+
+ if (s.length() > 1 && s[0] == TQLatin1Char('#')) {
+ int off = 1;
+ int base = 10;
+ if (s[1] == TQLatin1Char('x')) {
+ off = 2;
+ base = 16;
+ }
+ bool ok;
+ int num = s.mid(off).toInt(&ok, base);
+ if (num == 151) // ### hack for designer manual
+ return TQLatin1Char('-');
+ return num;
+ }
+
+ QMap<QByteArray, TQChar>::Iterator it = htmlMap()->find(s.toLatin1());
+ if (it != htmlMap()->end()) {
+ return *it;
+ }
+
+ pos = recoverpos;
+ return TQLatin1Char('&');
+}
+
+TQString TQTextDocument::parseWord(const TQChar* doc, int length, int& pos, bool lower)
+{
+ TQString s;
+
+ if (doc[pos] == TQLatin1Char('"')) {
+ pos++;
+ while (pos < length && doc[pos] != TQLatin1Char('"')) {
+ if (doc[pos] == TQLatin1Char('&')) {
+ s += parseHTMLSpecialChar(doc, length, pos);
+ } else {
+ s += doc[pos];
+ pos++;
+ }
+ }
+ eat(doc, length, pos, TQLatin1Char('"'));
+ } else if (doc[pos] == TQLatin1Char('\'')) {
+ pos++;
+ while (pos < length && doc[pos] != TQLatin1Char('\'')) {
+ s += doc[pos];
+ pos++;
+ }
+ eat(doc, length, pos, TQLatin1Char('\''));
+ } else {
+ static TQString term = TQString::fromLatin1("/>");
+ while (pos < length
+ && doc[pos] != TQLatin1Char('>')
+ && !hasPrefix(doc, length, pos, term)
+ && doc[pos] != TQLatin1Char('<')
+ && doc[pos] != TQLatin1Char('=')
+ && !doc[pos].isSpace())
+ {
+ if (doc[pos] == TQLatin1Char('&')) {
+ s += parseHTMLSpecialChar(doc, length, pos);
+ } else {
+ s += doc[pos];
+ pos++;
+ }
+ }
+ if (lower)
+ s = s.toLower();
+ }
+ return s;
+}
+
+TQChar TQTextDocument::parseChar(const TQChar* doc, int length, int& pos, TQStyleSheetItem::WhiteSpaceMode wsm)
+{
+ if (pos >= length)
+ return TQChar::null;
+
+ TQChar c = doc[pos++];
+
+ if (c == TQLatin1Char('<'))
+ return TQChar::null;
+
+ if (c.isSpace() && c != TQChar(TQChar::nbsp)) {
+ if (wsm == TQStyleSheetItem::WhiteSpacePre) {
+ if (c == TQLatin1Char('\n'))
+ return TQChar::LineSeparator;
+ else
+ return c;
+ } else { // non-pre mode: collapse whitespace except nbsp
+ while (pos< length &&
+ doc[pos].isSpace() && doc[pos] != TQChar(TQChar::nbsp))
+ pos++;
+ return TQLatin1Char(' ');
+ }
+ }
+ else if (c == TQLatin1Char('&'))
+ return parseHTMLSpecialChar(doc, length, --pos);
+ else
+ return c;
+}
+
+TQString TQTextDocument::parseOpenTag(const TQChar* doc, int length, int& pos,
+ QMap<TQString, TQString> &attr, bool& emptyTag)
+{
+ emptyTag = false;
+ pos++;
+ if (hasPrefix(doc, length, pos, TQLatin1Char('!'))) {
+ if (hasPrefix(doc, length, pos+1, TQLatin1String("--"))) {
+ pos += 3;
+ // eat comments
+ TQString pref = TQString::fromLatin1("-->");
+ while (!hasPrefix(doc, length, pos, pref) && pos < length)
+ pos++;
+ if (hasPrefix(doc, length, pos, pref)) {
+ pos += 3;
+ eatSpace(doc, length, pos, true);
+ }
+ emptyTag = true;
+ return TQString();
+ }
+ else {
+ // eat strange internal tags
+ while (!hasPrefix(doc, length, pos, TQLatin1Char('>')) && pos < length)
+ pos++;
+ if (hasPrefix(doc, length, pos, TQLatin1Char('>'))) {
+ pos++;
+ eatSpace(doc, length, pos, true);
+ }
+ return TQString();
+ }
+ }
+
+ TQString tag = parseWord(doc, length, pos);
+ eatSpace(doc, length, pos, true);
+ static TQString term = TQString::fromLatin1("/>");
+ static TQString s_TRUE = TQString::fromLatin1("TRUE");
+
+ while (doc[pos] != TQLatin1Char('>') && ! (emptyTag = hasPrefix(doc, length, pos, term))) {
+ TQString key = parseWord(doc, length, pos);
+ eatSpace(doc, length, pos, true);
+ if (key.isEmpty()) {
+ // error recovery
+ while (pos < length && doc[pos] != TQLatin1Char('>'))
+ pos++;
+ break;
+ }
+ TQString value;
+ if (hasPrefix(doc, length, pos, TQLatin1Char('='))){
+ pos++;
+ eatSpace(doc, length, pos);
+ value = parseWord(doc, length, pos, false);
+ }
+ else
+ value = s_TRUE;
+ attr.insert(key.toLower(), value);
+ eatSpace(doc, length, pos, true);
+ }
+
+ if (emptyTag) {
+ eat(doc, length, pos, TQLatin1Char('/'));
+ eat(doc, length, pos, TQLatin1Char('>'));
+ }
+ else
+ eat(doc, length, pos, TQLatin1Char('>'));
+
+ return tag;
+}
+
+TQString TQTextDocument::parseCloseTag(const TQChar* doc, int length, int& pos)
+{
+ pos++;
+ pos++;
+ TQString tag = parseWord(doc, length, pos);
+ eatSpace(doc, length, pos, true);
+ eat(doc, length, pos, TQLatin1Char('>'));
+ return tag;
+}
+
+TQTextFlow::TQTextFlow()
+{
+ w = pagesize = 0;
+}
+
+TQTextFlow::~TQTextFlow()
+{
+ clear();
+}
+
+void TQTextFlow::clear()
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ while (!leftItems.isEmpty())
+ delete leftItems.takeFirst();
+ while (!rightItems.isEmpty())
+ delete rightItems.takeFirst();
+#endif
+}
+
+void TQTextFlow::setWidth(int width)
+{
+ w = width;
+}
+
+int TQTextFlow::adjustLMargin(int yp, int, int margin, int space)
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ for (int idx = 0; idx < leftItems.size(); ++idx) {
+ TQTextCustomItem* item = leftItems.at(idx);
+ if (item->ypos == -1)
+ continue;
+ if (yp >= item->ypos && yp < item->ypos + item->height)
+ margin = qMax(margin, item->xpos + item->width + space);
+ }
+#endif
+ return margin;
+}
+
+int TQTextFlow::adjustRMargin(int yp, int, int margin, int space)
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ for (int idx = 0; idx < rightItems.size(); ++idx) {
+ TQTextCustomItem* item = rightItems.at(idx);
+ if (item->ypos == -1)
+ continue;
+ if (yp >= item->ypos && yp < item->ypos + item->height)
+ margin = qMax(margin, w - item->xpos - space);
+ }
+#endif
+ return margin;
+}
+
+
+int TQTextFlow::adjustFlow(int y, int /*w*/, int h)
+{
+ if (pagesize > 0) { // check pages
+ int yinpage = y % pagesize;
+ if (yinpage <= border_tolerance)
+ return border_tolerance - yinpage;
+ else
+ if (yinpage + h > pagesize - border_tolerance)
+ return (pagesize - yinpage) + border_tolerance;
+ }
+ return 0;
+}
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+void TQTextFlow::unregisterFloatingItem(TQTextCustomItem* item)
+{
+ leftItems.removeAll(item);
+ rightItems.removeAll(item);
+}
+
+void TQTextFlow::registerFloatingItem(TQTextCustomItem* item)
+{
+ if (item->placement() == TQTextCustomItem::PlaceRight) {
+ if (!rightItems.contains(item))
+ rightItems.append(item);
+ } else if (item->placement() == TQTextCustomItem::PlaceLeft &&
+ !leftItems.contains(item)) {
+ leftItems.append(item);
+ }
+}
+#endif // QT_NO_TEXTCUSTOMITEM
+
+TQRect TQTextFlow::boundingRect() const
+{
+ TQRect br;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ for (int idx = 0; idx < leftItems.size(); ++idx) {
+ TQTextCustomItem* item = leftItems.at(idx);
+ br = br.united(item->geometry());
+ }
+ for (int idx = 0; idx < rightItems.size(); ++idx) {
+ TQTextCustomItem* item = rightItems.at(idx);
+ br = br.united(item->geometry());
+ }
+#endif
+ return br;
+}
+
+
+void TQTextFlow::drawFloatingItems(TQPainter* p, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected)
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ for (int idx = 0; idx < leftItems.size(); ++idx) {
+ TQTextCustomItem* item = leftItems.at(idx);
+ if (item->xpos == -1 || item->ypos == -1)
+ continue;
+ item->draw(p, item->xpos, item->ypos, cx, cy, cw, ch, pal, selected);
+ }
+
+ for (int idx = 0; idx < rightItems.size(); ++idx) {
+ TQTextCustomItem* item = rightItems.at(idx);
+ if (item->xpos == -1 || item->ypos == -1)
+ continue;
+ item->draw(p, item->xpos, item->ypos, cx, cy, cw, ch, pal, selected);
+ }
+#endif
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+void TQTextCustomItem::pageBreak(int /*y*/ , TQTextFlow* /*flow*/)
+{
+}
+#endif
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+TQTextTable::TQTextTable(TQTextDocument *p, const QMap<TQString, TQString> & attr )
+ : TQTextCustomItem(p)
+{
+ cellspacing = 2;
+ cellpadding = 1;
+ border = innerborder = 0;
+
+ QMap<TQString, TQString>::ConstIterator it, end = attr.end();
+ it = attr.find(TQLatin1String("cellspacing"));
+ if (it != end)
+ cellspacing = (*it).toInt();
+ it = attr.find(TQLatin1String("cellpadding"));
+ if (it != end)
+ cellpadding = (*it).toInt();
+ it = attr.find(TQLatin1String("border"));
+ if (it != end) {
+ if (*it == TQLatin1String("TRUE"))
+ border = 1;
+ else
+ border = (*it).toInt();
+ }
+ us_b = border;
+
+ innerborder = us_ib = border ? 1 : 0;
+
+ if (border)
+ cellspacing += 2;
+
+ us_ib = innerborder;
+ us_cs = cellspacing;
+ us_cp = cellpadding;
+ outerborder = cellspacing + border;
+ us_ob = outerborder;
+ layout = new TQGridLayout(1, 1, cellspacing);
+
+ fixwidth = 0;
+ stretch = 0;
+ it = attr.find(TQLatin1String("width"));
+ if (it != end) {
+ bool b;
+ TQString s(*it);
+ int w = s.toInt(&b);
+ if (b) {
+ fixwidth = w;
+ } else {
+ s = s.trimmed();
+ if (s.length() > 1 && s[(int)s.length()-1] == TQLatin1Char('%'))
+ stretch = s.left(s.length()-1).toInt();
+ }
+ }
+ us_fixwidth = fixwidth;
+
+ place = PlaceInline;
+ if (attr[TQLatin1String("align")] == TQLatin1String("left"))
+ place = PlaceLeft;
+ else if (attr[TQLatin1String("align")] == TQLatin1String("right"))
+ place = PlaceRight;
+ cachewidth = 0;
+ attributes = attr;
+ pageBreakFor = -1;
+}
+
+TQTextTable::~TQTextTable()
+{
+ delete layout;
+}
+
+TQString TQTextTable::richText() const
+{
+ TQString s;
+ s = TQLatin1String("<table ");
+ QMap<TQString, TQString>::ConstIterator it = attributes.begin();
+ for (; it != attributes.end(); ++it)
+ s += it.key() + TQLatin1Char('=') + *it + TQLatin1Char(' ');
+ s += TQLatin1String(">\n");
+
+ int lastRow = -1;
+ bool needEnd = false;
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *cell = cells.at(idx);
+ if (lastRow != cell->row()) {
+ if (lastRow != -1)
+ s += TQLatin1String("</tr>\n");
+ s += TQLatin1String("<tr>");
+ lastRow = cell->row();
+ needEnd = true;
+ }
+ s += TQLatin1String("<td");
+ it = cell->attributes.constBegin();
+ for (; it != cell->attributes.constEnd(); ++it)
+ s += TQLatin1Char(' ') + it.key() + TQLatin1Char('=') + *it;
+ s += TQLatin1Char('>');
+ s += cell->richText()->richText();
+ s += TQLatin1String("</td>");
+ }
+ if (needEnd)
+ s += TQLatin1String("</tr>\n");
+ s += TQLatin1String("</table>\n");
+ return s;
+}
+
+void TQTextTable::adjustToPainter(TQPainter* p)
+{
+ cellspacing = scale(us_cs, p);
+ cellpadding = scale(us_cp, p);
+ border = scale(us_b , p);
+ innerborder = scale(us_ib, p);
+ outerborder = scale(us_ob ,p);
+ fixwidth = scale( us_fixwidth, p);
+ width = 0;
+ cachewidth = 0;
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *cell = cells.at(idx);
+ cell->adjustToPainter(p);
+ }
+}
+
+void TQTextTable::adjustCells(int y , int shift)
+{
+ bool enlarge = false;
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *cell = cells.at(idx);
+ TQRect r = cell->geometry();
+ if (y <= r.top()) {
+ r.moveBy(0, shift);
+ cell->setGeometry(r);
+ enlarge = true;
+ } else if (y <= r.bottom()) {
+ r.rBottom() += shift;
+ cell->setGeometry(r);
+ enlarge = true;
+ }
+ }
+ if (enlarge)
+ height += shift;
+}
+
+void TQTextTable::pageBreak(int yt, TQTextFlow* flow)
+{
+ if (flow->pageSize() <= 0)
+ return;
+ if (layout && pageBreakFor > 0 && pageBreakFor != yt) {
+ layout->invalidate();
+ int h = layout->heightForWidth(width-2*outerborder);
+ layout->setGeometry(TQRect(0, 0, width-2*outerborder, h) );
+ height = layout->geometry().height()+2*outerborder;
+ }
+ pageBreakFor = yt;
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *cell = cells.at(idx);
+ int y = yt + outerborder + cell->geometry().y();
+ int shift = flow->adjustFlow(y - cellspacing, width, cell->richText()->height() + 2*cellspacing);
+ adjustCells(y - outerborder - yt, shift);
+ }
+}
+
+
+void TQTextTable::draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected)
+{
+ if (placement() != PlaceInline) {
+ x = xpos;
+ y = ypos;
+ }
+
+ for (int idx = 0; idx < cells.size(); ++idx) {
+ TQTextTableCell *cell = cells.at(idx);
+ if ((cx < 0 && cy < 0) ||
+ TQRect(cx, cy, cw, ch).intersects(TQRect(x + outerborder + cell->geometry().x(),
+ y + outerborder + cell->geometry().y(),
+ cell->geometry().width(),
+ cell->geometry().height()))) {
+ cell->draw(p, x+outerborder, y+outerborder, cx, cy, cw, ch, pal, selected);
+ if (border) {
+ TQRect r(x+outerborder+cell->geometry().x() - innerborder,
+ y+outerborder+cell->geometry().y() - innerborder,
+ cell->geometry().width() + 2 * innerborder,
+ cell->geometry().height() + 2 * innerborder);
+ if (is_printer(p)) {
+ QPen oldPen = p->pen();
+ TQRect r2 = r;
+ r2.adjust(innerborder/2, innerborder/2, -innerborder/2, -innerborder/2);
+ p->setPen(QPen(pal.text().color(), innerborder));
+ p->drawRect(r2);
+ p->setPen(oldPen);
+ } else {
+ int s = qMax(cellspacing-2*innerborder, 0);
+ if (s) {
+ p->fillRect(r.left()-s, r.top(), s+1, r.height(), pal.button());
+ p->fillRect(r.right(), r.top(), s+1, r.height(), pal.button());
+ p->fillRect(r.left()-s, r.top()-s, r.width()+2*s, s, pal.button());
+ p->fillRect(r.left()-s, r.bottom(), r.width()+2*s, s, pal.button());
+ }
+ qDrawShadePanel(p, r, pal, true, innerborder);
+ }
+ }
+ }
+ }
+ if (border) {
+ TQRect r (x, y, width, height);
+ if (is_printer(p)) {
+ TQRect r2 = r;
+ r2.adjust(border/2, border/2, -border/2, -border/2);
+ QPen oldPen = p->pen();
+ p->setPen(QPen(pal.text().color(), border));
+ p->drawRect(r2);
+ p->setPen(oldPen);
+ } else {
+ int s = border+qMax(cellspacing-2*innerborder, 0);
+ if (s) {
+ p->fillRect(r.left(), r.top(), s, r.height(), pal.button());
+ p->fillRect(r.right()-s, r.top(), s, r.height(), pal.button());
+ p->fillRect(r.left(), r.top(), r.width(), s, pal.button());
+ p->fillRect(r.left(), r.bottom()-s, r.width(), s, pal.button());
+ }
+ qDrawShadePanel(p, r, pal, false, border);
+ }
+ }
+
+}
+
+int TQTextTable::minimumWidth() const
+{
+ return qMax(fixwidth, ((layout ? layout->minimumSize().width() : 0) + 2 * outerborder));
+}
+
+void TQTextTable::resize(int nwidth)
+{
+ if (fixwidth && cachewidth != 0)
+ return;
+ if (nwidth == cachewidth)
+ return;
+
+
+ cachewidth = nwidth;
+ int w = nwidth;
+
+ format(w);
+
+ if (stretch)
+ nwidth = nwidth * stretch / 100;
+
+ width = nwidth;
+ layout->invalidate();
+ int shw = layout->sizeHint().width() + 2*outerborder;
+ int mw = layout->minimumSize().width() + 2*outerborder;
+ if (stretch)
+ width = qMax(mw, nwidth);
+ else
+ width = qMax(mw, qMin(nwidth, shw));
+
+ if (fixwidth)
+ width = fixwidth;
+
+ layout->invalidate();
+ mw = layout->minimumSize().width() + 2*outerborder;
+ width = qMax(width, mw);
+
+ int h = layout->heightForWidth(width-2*outerborder);
+ layout->setGeometry(TQRect(0, 0, width-2*outerborder, h) );
+ height = layout->geometry().height()+2*outerborder;
+}
+
+void TQTextTable::format(int w)
+{
+ for (int i = 0; i < (int)cells.count(); ++i) {
+ TQTextTableCell *cell = cells.at(i);
+ TQRect r = cell->geometry();
+ r.setWidth(w - 2*outerborder);
+ cell->setGeometry(r);
+ }
+}
+
+void TQTextTable::addCell(TQTextTableCell* cell)
+{
+ cells.append(cell);
+ layout->addMultiCell(cell, cell->row(), cell->row() + cell->rowspan()-1,
+ cell->column(), cell->column() + cell->colspan()-1);
+}
+
+bool TQTextTable::enter(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd)
+{
+ currCell.remove(c);
+ if (!atEnd)
+ return next(c, doc, parag, idx, ox, oy);
+ currCell.insert(c, cells.count());
+ return prev(c, doc, parag, idx, ox, oy);
+}
+
+bool TQTextTable::enterAt(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, const QPoint &pos)
+{
+ currCell.remove(c);
+ int lastCell = -1;
+ int lastY = -1;
+ int i;
+ for (i = 0; i < (int)cells.count(); ++i) {
+ TQTextTableCell *cell = cells.at(i);
+ if (!cell)
+ continue;
+ TQRect r(cell->geometry().x(),
+ cell->geometry().y(),
+ cell->geometry().width() + 2 * innerborder + 2 * outerborder,
+ cell->geometry().height() + 2 * innerborder + 2 * outerborder);
+
+ if (r.left() <= pos.x() && r.right() >= pos.x()) {
+ if (cell->geometry().y() > lastY) {
+ lastCell = i;
+ lastY = cell->geometry().y();
+ }
+ if (r.top() <= pos.y() && r.bottom() >= pos.y()) {
+ currCell.insert(c, i);
+ break;
+ }
+ }
+ }
+ if (i == (int) cells.count())
+ return false; // no cell found
+
+ if (currCell.find(c) == currCell.end()) {
+ if (lastY != -1)
+ currCell.insert(c, lastCell);
+ else
+ return false;
+ }
+
+ TQTextTableCell *cell = cells.at(*currCell.find(c));
+ if (!cell)
+ return false;
+ doc = cell->richText();
+ parag = doc->firstParagraph();
+ idx = 0;
+ ox += cell->geometry().x() + cell->horizontalAlignmentOffset() + outerborder + parent->x();
+ oy += cell->geometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return true;
+}
+
+bool TQTextTable::next(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy)
+{
+ int cc = -1;
+ if (currCell.find(c) != currCell.end())
+ cc = *currCell.find(c);
+ if (cc > (int)cells.count() - 1 || cc < 0)
+ cc = -1;
+ currCell.remove(c);
+ currCell.insert(c, ++cc);
+ if (cc >= (int)cells.count()) {
+ currCell.insert(c, 0);
+ TQTextCustomItem::next(c, doc, parag, idx, ox, oy);
+ TQTextTableCell *cell = cells.first();
+ if (!cell)
+ return false;
+ doc = cell->richText();
+ idx = -1;
+ return true;
+ }
+
+ if (currCell.find(c) == currCell.end())
+ return false;
+ TQTextTableCell *cell = cells.at(*currCell.find(c));
+ if (!cell)
+ return false;
+ doc = cell->richText();
+ parag = doc->firstParagraph();
+ idx = 0;
+ ox += cell->geometry().x() + cell->horizontalAlignmentOffset() + outerborder + parent->x();
+ oy += cell->geometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return true;
+}
+
+bool TQTextTable::prev(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy)
+{
+ int cc = -1;
+ if (currCell.find(c) != currCell.end())
+ cc = *currCell.find(c);
+ if (cc > (int)cells.count() - 1 || cc < 0)
+ cc = cells.count();
+ currCell.remove(c);
+ currCell.insert(c, --cc);
+ if (cc < 0) {
+ currCell.insert(c, 0);
+ TQTextCustomItem::prev(c, doc, parag, idx, ox, oy);
+ TQTextTableCell *cell = cells.first();
+ if (!cell)
+ return false;
+ doc = cell->richText();
+ idx = -1;
+ return true;
+ }
+
+ if (currCell.find(c) == currCell.end())
+ return false;
+ TQTextTableCell *cell = cells.at(*currCell.find(c));
+ if (!cell)
+ return false;
+ doc = cell->richText();
+ parag = doc->lastParagraph();
+ idx = parag->length() - 1;
+ ox += cell->geometry().x() + cell->horizontalAlignmentOffset() + outerborder + parent->x();
+ oy += cell->geometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return true;
+}
+
+bool TQTextTable::down(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy)
+{
+ if (currCell.find(c) == currCell.end())
+ return false;
+ TQTextTableCell *cell = cells.at(*currCell.find(c));
+ if (cell->row_ == layout->numRows() - 1) {
+ currCell.insert(c, 0);
+ TQTextCustomItem::down(c, doc, parag, idx, ox, oy);
+ TQTextTableCell *cell = cells.first();
+ if (!cell)
+ return false;
+ doc = cell->richText();
+ idx = -1;
+ return true;
+ }
+
+ int oldRow = cell->row_;
+ int oldCol = cell->col_;
+ if (currCell.find(c) == currCell.end())
+ return false;
+ int cc = *currCell.find(c);
+ for (int i = cc; i < (int)cells.count(); ++i) {
+ cell = cells.at(i);
+ if (cell->row_ > oldRow && cell->col_ == oldCol) {
+ currCell.insert(c, i);
+ break;
+ }
+ }
+ doc = cell->richText();
+ if (!cell)
+ return false;
+ parag = doc->firstParagraph();
+ idx = 0;
+ ox += cell->geometry().x() + cell->horizontalAlignmentOffset() + outerborder + parent->x();
+ oy += cell->geometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return true;
+}
+
+bool TQTextTable::up(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy)
+{
+ if (currCell.find(c) == currCell.end())
+ return false;
+ TQTextTableCell *cell = cells.at(*currCell.find(c));
+ if (cell->row_ == 0) {
+ currCell.insert(c, 0);
+ TQTextCustomItem::up(c, doc, parag, idx, ox, oy);
+ TQTextTableCell *cell = cells.first();
+ if (!cell)
+ return false;
+ doc = cell->richText();
+ idx = -1;
+ return true;
+ }
+
+ int oldRow = cell->row_;
+ int oldCol = cell->col_;
+ if (currCell.find(c) == currCell.end())
+ return false;
+ int cc = *currCell.find(c);
+ for (int i = cc; i >= 0; --i) {
+ cell = cells.at(i);
+ if (cell->row_ < oldRow && cell->col_ == oldCol) {
+ currCell.insert(c, i);
+ break;
+ }
+ }
+ doc = cell->richText();
+ if (!cell)
+ return false;
+ parag = doc->lastParagraph();
+ idx = parag->length() - 1;
+ ox += cell->geometry().x() + cell->horizontalAlignmentOffset() + outerborder + parent->x();
+ oy += cell->geometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return true;
+}
+
+TQTextTableCell::TQTextTableCell(TQTextTable* table,
+ int row, int column,
+ const QMap<TQString, TQString> &attr,
+ const TQStyleSheetItem* style,
+ const TQTextFormat& fmt, const TQString& context,
+ TQMimeSourceFactory &factory, TQStyleSheet *sheet,
+ const TQString& doc)
+{
+ cached_width = -1;
+ cached_sizehint = -1;
+
+ maxw = QWIDGETSIZE_MAX;
+ minw = 0;
+
+ parent = table;
+ row_ = row;
+ col_ = column;
+ stretch_ = 0;
+ richtext = new TQTextDocument(table->parent);
+ richtext->formatCollection()->setPaintDevice(table->parent->formatCollection()->paintDevice());
+ richtext->bodyText = fmt.color();
+ richtext->setTableCell(this);
+
+ QMap<TQString,TQString>::ConstIterator it, end = attr.end();
+ int halign = style->alignment();
+ if (halign != TQStyleSheetItem::Undefined)
+ richtext->setAlignment(halign);
+ it = attr.find(TQLatin1String("align"));
+ if (it != end && ! (*it).isEmpty()) {
+ TQString a = (*it).toLower();
+ if (a == TQLatin1String("left"))
+ richtext->setAlignment(Qt::AlignLeft);
+ else if (a == TQLatin1String("center"))
+ richtext->setAlignment(Qt::AlignHCenter);
+ else if (a == TQLatin1String("right"))
+ richtext->setAlignment(Qt::AlignRight);
+ }
+ align = 0;
+ it = attr.find(TQLatin1String("valign"));
+ if (it != end && ! (*it).isEmpty()) {
+ TQString va = (*it).toLower();
+ if ( va == TQLatin1String("top") )
+ align |= Qt::AlignTop;
+ else if ( va == TQLatin1String("center") || va == TQLatin1String("middle") )
+ align |= Qt::AlignVCenter;
+ else if (va == TQLatin1String("bottom"))
+ align |= Qt::AlignBottom;
+ }
+ richtext->setFormatter(table->parent->formatter());
+ richtext->setUseFormatCollection(table->parent->useFormatCollection());
+ richtext->setMimeSourceFactory(&factory);
+ richtext->setStyleSheet(sheet);
+ richtext->setRichText(doc, context, &fmt);
+ rowspan_ = 1;
+ colspan_ = 1;
+
+ it = attr.find(TQLatin1String("colspan"));
+ if (it != end)
+ colspan_ = (*it).toInt();
+ it = attr.find(TQLatin1String("rowspan"));
+ if (it != end)
+ rowspan_ = (*it).toInt();
+
+ background = 0;
+ it = attr.find(TQLatin1String("bgcolor"));
+ if (it != end) {
+ background = new TQBrush(QColor(*it));
+ }
+
+ hasFixedWidth = false;
+ it = attr.find(TQLatin1String("width"));
+ if (it != end) {
+ bool b;
+ TQString s(*it);
+ int w = s.toInt(&b);
+ if (b) {
+ maxw = w;
+ minw = maxw;
+ hasFixedWidth = true;
+ } else {
+ s = s.trimmed();
+ if (s.length() > 1 && s[(int)s.length()-1] == TQLatin1Char('%'))
+ stretch_ = s.left(s.length()-1).toInt();
+ }
+ }
+
+ attributes = attr;
+
+ parent->addCell(this);
+}
+
+TQTextTableCell::~TQTextTableCell()
+{
+ delete background;
+ background = 0;
+ delete richtext;
+ richtext = 0;
+}
+
+TQSize TQTextTableCell::tqsizeHint() const
+{
+ int extra = 2 * (parent->innerborder + parent->cellpadding + border_tolerance);
+ int used = richtext->widthUsed() + extra;
+
+ if (stretch_) {
+ int w = parent->width * stretch_ / 100 - 2*parent->cellspacing - 2*parent->cellpadding;
+ return QSize(qMin(w, maxw), 0).expandedTo(minimumSize());
+ }
+
+ return QSize(used, 0).expandedTo(minimumSize());
+}
+
+TQSize TQTextTableCell::tqminimumSize() const
+{
+ int extra = 2 * (parent->innerborder + parent->cellpadding + border_tolerance);
+ return QSize(qMax(richtext->minimumWidth() + extra, minw), 0);
+}
+
+TQSize TQTextTableCell::tqmaximumSize() const
+{
+ return QSize(maxw, QWIDGETSIZE_MAX);
+}
+
+Qt::Orientations TQTextTableCell::expandingDirections() const
+{
+ return Qt::Horizontal | Qt::Vertical;
+}
+
+bool TQTextTableCell::isEmpty() const
+{
+ return false;
+}
+void TQTextTableCell::setGeometry(const TQRect& r)
+{
+ int extra = 2 * (parent->innerborder + parent->cellpadding);
+ if (r.width() != cached_width)
+ richtext->doLayout(TQTextFormat::painter(), r.width() - extra);
+ cached_width = r.width();
+ geom = r;
+}
+
+TQRect TQTextTableCell::tqgeometry() const
+{
+ return geom;
+}
+
+bool TQTextTableCell::hasHeightForWidth() const
+{
+ return true;
+}
+
+int TQTextTableCell::heightForWidth(int w) const
+{
+ int extra = 2 * (parent->innerborder + parent->cellpadding);
+ w = qMax(minw, w);
+
+ if (cached_width != w) {
+ TQTextTableCell* that = (TQTextTableCell*) this;
+ that->richtext->doLayout(TQTextFormat::painter(), w - extra);
+ that->cached_width = w;
+ }
+ return richtext->height() + extra;
+}
+
+void TQTextTableCell::adjustToPainter(TQPainter* p)
+{
+ TQTextParagraph *parag = richtext->firstParagraph();
+ while (parag) {
+ parag->adjustToPainter(p);
+ parag = parag->next();
+ }
+}
+
+int TQTextTableCell::horizontalAlignmentOffset() const
+{
+ return parent->cellpadding;
+}
+
+int TQTextTableCell::verticalAlignmentOffset() const
+{
+ if ((align & Qt::AlignVCenter) == Qt::AlignVCenter)
+ return (geom.height() - richtext->height()) / 2;
+ else if ((align & Qt::AlignBottom) == Qt::AlignBottom)
+ return geom.height() - parent->cellpadding - richtext->height() ;
+ return parent->cellpadding;
+}
+
+void TQTextTableCell::draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool)
+{
+ if (cached_width != geom.width()) {
+ int extra = 2 * (parent->innerborder + parent->cellpadding);
+ richtext->doLayout(p, geom.width() - extra);
+ cached_width = geom.width();
+ }
+ QPalette pal2(pal);
+ if (background)
+ pal2.setBrush(QPalette::Base, *background);
+ else if (richtext->paper())
+ pal2.setBrush(QPalette::Base, *richtext->paper());
+
+ p->save();
+ p->translate(x + geom.x(), y + geom.y());
+ if (background)
+ p->fillRect(0, 0, geom.width(), geom.height(), *background);
+ else if (richtext->paper())
+ p->fillRect(0, 0, geom.width(), geom.height(), *richtext->paper());
+
+ p->translate(horizontalAlignmentOffset(), verticalAlignmentOffset());
+
+ QRegion r;
+ if (cx >= 0 && cy >= 0)
+ richtext->draw(p, cx - (x + horizontalAlignmentOffset() + geom.x()),
+ cy - (y + geom.y() + verticalAlignmentOffset()),
+ cw, ch, pal2, false, false, 0);
+ else
+ richtext->draw(p, -1, -1, -1, -1, pal2, false, false, 0);
+
+ p->restore();
+}
+#endif
+
+QT_END_NAMESPACE
+
+#endif //QT_NO_RICHTEXT
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of the internal TQt classes dealing with rich text
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqrichtext_p.h"
+
+#ifndef TQT_NO_RICHTEXT
+
+
+#include "tqstringlist.h"
+#include "tqfont.h"
+#include "tqtextstream.h"
+#include "tqfile.h"
+#include "tqapplication.h"
+#include "tqmap.h"
+#include "tqfileinfo.h"
+#include "tqstylesheet.h"
+#include "tqmime.h"
+#include "tqimage.h"
+#include "tqdragobject.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqpainter.h"
+#include "tqdrawutil.h"
+#include "tqcursor.h"
+#include "tqptrstack.h"
+#include "tqptrdict.h"
+#include "tqstyle.h"
+#include "tqcleanuphandler.h"
+#include "tqtextengine_p.h"
+#include <private/tqunicodetables_p.h>
+
+#include <stdlib.h>
+
+static TQTextCursor* richTextExportStart = 0;
+static TQTextCursor* richTextExportEnd = 0;
+
+class TQTextFormatCollection;
+
+const int border_tolerance = 2;
+
+#ifdef TQ_WS_WIN
+#include "tqt_windows.h"
+#endif
+
+#define TQChar_linesep TQChar(0x2028U)
+
+static inline bool is_printer( TQPainter *p )
+{
+ if ( !p || !p->tqdevice() )
+ return FALSE;
+ return p->tqdevice()->devType() == TQInternal::Printer;
+}
+
+static inline int scale( int value, TQPainter *painter )
+{
+ if ( is_printer( painter ) ) {
+ TQPaintDeviceMetrics metrics( painter->tqdevice() );
+#if defined(TQ_WS_X11)
+ value = value * metrics.logicalDpiY() /
+ TQPaintDevice::x11AppDpiY( painter->tqdevice()->x11Screen() );
+#elif defined (TQ_WS_WIN)
+ HDC hdc = GetDC( 0 );
+ int gdc = GetDeviceCaps( hdc, LOGPIXELSY );
+ if ( gdc )
+ value = value * metrics.logicalDpiY() / gdc;
+ ReleaseDC( 0, hdc );
+#elif defined (TQ_WS_MAC)
+ value = value * metrics.logicalDpiY() / 75; // ##### FIXME
+#elif defined (TQ_WS_TQWS)
+ value = value * metrics.logicalDpiY() / 75;
+#endif
+ }
+ return value;
+}
+
+
+inline bool isBreakable( TQTextString *string, int pos )
+{
+ if (string->at(pos).nobreak)
+ return FALSE;
+ return (pos < string->length()-1 && string->at(pos+1).softBreak);
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+void TQTextCommandHistory::addCommand( TQTextCommand *cmd )
+{
+ if ( current < (int)history.count() - 1 ) {
+ TQPtrList<TQTextCommand> commands;
+ commands.setAutoDelete( FALSE );
+
+ for( int i = 0; i <= current; ++i ) {
+ commands.insert( i, history.at( 0 ) );
+ history.take( 0 );
+ }
+
+ commands.append( cmd );
+ history.clear();
+ history = commands;
+ history.setAutoDelete( TRUE );
+ } else {
+ history.append( cmd );
+ }
+
+ if ( (int)history.count() > steps )
+ history.removeFirst();
+ else
+ ++current;
+}
+
+TQTextCursor *TQTextCommandHistory::undo( TQTextCursor *c )
+{
+ if ( current > -1 ) {
+ TQTextCursor *c2 = history.at( current )->unexecute( c );
+ --current;
+ return c2;
+ }
+ return 0;
+}
+
+TQTextCursor *TQTextCommandHistory::redo( TQTextCursor *c )
+{
+ if ( current > -1 ) {
+ if ( current < (int)history.count() - 1 ) {
+ ++current;
+ return history.at( current )->execute( c );
+ }
+ } else {
+ if ( history.count() > 0 ) {
+ ++current;
+ return history.at( current )->execute( c );
+ }
+ }
+ return 0;
+}
+
+bool TQTextCommandHistory::isUndoAvailable()
+{
+ return current > -1;
+}
+
+bool TQTextCommandHistory::isRedoAvailable()
+{
+ return ((current > -1) && current < ((int)history.count() - 1)) || ((current == -1) && (history.count()) > 0);
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextDeleteCommand::TQTextDeleteCommand( TQTextDocument *d, int i, int idx, const TQMemArray<TQTextStringChar> &str,
+ const TQByteArray& oldStyleInfo )
+ : TQTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo )
+{
+ for ( int j = 0; j < (int)text.size(); ++j ) {
+ if ( text[ j ].format() )
+ text[ j ].format()->addRef();
+ }
+}
+
+TQTextDeleteCommand::TQTextDeleteCommand( TQTextParagraph *p, int idx, const TQMemArray<TQTextStringChar> &str )
+ : TQTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str )
+{
+ for ( int i = 0; i < (int)text.size(); ++i ) {
+ if ( text[ i ].format() )
+ text[ i ].format()->addRef();
+ }
+}
+
+TQTextDeleteCommand::~TQTextDeleteCommand()
+{
+ for ( int i = 0; i < (int)text.size(); ++i ) {
+ if ( text[ i ].format() )
+ text[ i ].format()->removeRef();
+ }
+ text.resize( 0 );
+}
+
+TQTextCursor *TQTextDeleteCommand::execute( TQTextCursor *c )
+{
+ TQTextParagraph *s = doc ? doc->paragAt( id ) : parag;
+ if ( !s ) {
+ qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() );
+ return 0;
+ }
+
+ cursor.setParagraph( s );
+ cursor.setIndex( index );
+ int len = text.size();
+ if ( c )
+ *c = cursor;
+ if ( doc ) {
+ doc->setSelectionStart( TQTextDocument::Temp, cursor );
+ for ( int i = 0; i < len; ++i )
+ cursor.gotoNextLetter();
+ doc->setSelectionEnd( TQTextDocument::Temp, cursor );
+ doc->removeSelectedText( TQTextDocument::Temp, &cursor );
+ if ( c )
+ *c = cursor;
+ } else {
+ s->remove( index, len );
+ }
+
+ return c;
+}
+
+TQTextCursor *TQTextDeleteCommand::unexecute( TQTextCursor *c )
+{
+ TQTextParagraph *s = doc ? doc->paragAt( id ) : parag;
+ if ( !s ) {
+ qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() );
+ return 0;
+ }
+
+ cursor.setParagraph( s );
+ cursor.setIndex( index );
+ TQString str = TQTextString::toString( text );
+ cursor.insert( str, TRUE, &text );
+ if ( c )
+ *c = cursor;
+ cursor.setParagraph( s );
+ cursor.setIndex( index );
+
+#ifndef TQT_NO_DATASTREAM
+ if ( !styleInformation.isEmpty() ) {
+ TQDataStream styleStream( styleInformation, IO_ReadOnly );
+ int num;
+ styleStream >> num;
+ TQTextParagraph *p = s;
+ while ( num-- && p ) {
+ p->readStyleInformation( styleStream );
+ p = p->next();
+ }
+ }
+#endif
+ s = cursor.paragraph();
+ while ( s ) {
+ s->format();
+ s->setChanged( TRUE );
+ if ( s == c->paragraph() )
+ break;
+ s = s->next();
+ }
+
+ return &cursor;
+}
+
+TQTextFormatCommand::TQTextFormatCommand( TQTextDocument *d, int sid, int sidx, int eid, int eidx,
+ const TQMemArray<TQTextStringChar> &old, TQTextFormat *f, int fl )
+ : TQTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl )
+{
+ format = d->formatCollection()->format( f );
+ for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
+ if ( oldFormats[ j ].format() )
+ oldFormats[ j ].format()->addRef();
+ }
+}
+
+TQTextFormatCommand::~TQTextFormatCommand()
+{
+ format->removeRef();
+ for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
+ if ( oldFormats[ j ].format() )
+ oldFormats[ j ].format()->removeRef();
+ }
+}
+
+TQTextCursor *TQTextFormatCommand::execute( TQTextCursor *c )
+{
+ TQTextParagraph *sp = doc->paragAt( startId );
+ TQTextParagraph *ep = doc->paragAt( endId );
+ if ( !sp || !ep )
+ return c;
+
+ TQTextCursor start( doc );
+ start.setParagraph( sp );
+ start.setIndex( startIndex );
+ TQTextCursor end( doc );
+ end.setParagraph( ep );
+ end.setIndex( endIndex );
+
+ doc->setSelectionStart( TQTextDocument::Temp, start );
+ doc->setSelectionEnd( TQTextDocument::Temp, end );
+ doc->setFormat( TQTextDocument::Temp, format, flags );
+ doc->removeSelection( TQTextDocument::Temp );
+ if ( endIndex == ep->length() )
+ end.gotoLeft();
+ *c = end;
+ return c;
+}
+
+TQTextCursor *TQTextFormatCommand::unexecute( TQTextCursor *c )
+{
+ TQTextParagraph *sp = doc->paragAt( startId );
+ TQTextParagraph *ep = doc->paragAt( endId );
+ if ( !sp || !ep )
+ return 0;
+
+ int idx = startIndex;
+ int fIndex = 0;
+ while ( fIndex < int(oldFormats.size()) ) {
+ if ( oldFormats.at( fIndex ).c == '\n' ) {
+ if ( idx > 0 ) {
+ if ( idx < sp->length() && fIndex > 0 )
+ sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() );
+ if ( sp == ep )
+ break;
+ sp = sp->next();
+ idx = 0;
+ }
+ fIndex++;
+ }
+ if ( oldFormats.at( fIndex ).format() )
+ sp->setFormat( idx, 1, oldFormats.at( fIndex ).format() );
+ idx++;
+ fIndex++;
+ if ( fIndex >= (int)oldFormats.size() )
+ break;
+ if ( idx >= sp->length() ) {
+ if ( sp == ep )
+ break;
+ sp = sp->next();
+ idx = 0;
+ }
+ }
+
+ TQTextCursor end( doc );
+ end.setParagraph( ep );
+ end.setIndex( endIndex );
+ if ( endIndex == ep->length() )
+ end.gotoLeft();
+ *c = end;
+ return c;
+}
+
+TQTextStyleCommand::TQTextStyleCommand( TQTextDocument *d, int fParag, int lParag, const TQByteArray& beforeChange )
+ : TQTextCommand( d ), firstParag( fParag ), lastParag( lParag ), before( beforeChange )
+{
+ after = readStyleInformation( d, fParag, lParag );
+}
+
+
+TQByteArray TQTextStyleCommand::readStyleInformation( TQTextDocument* doc, int fParag, int lParag )
+{
+ TQByteArray style;
+#ifndef TQT_NO_DATASTREAM
+ TQTextParagraph *p = doc->paragAt( fParag );
+ if ( !p )
+ return style;
+ TQDataStream styleStream( style, IO_WriteOnly );
+ int num = lParag - fParag + 1;
+ styleStream << num;
+ while ( num -- && p ) {
+ p->writeStyleInformation( styleStream );
+ p = p->next();
+ }
+#endif
+ return style;
+}
+
+void TQTextStyleCommand::writeStyleInformation( TQTextDocument* doc, int fParag, const TQByteArray& style )
+{
+#ifndef TQT_NO_DATASTREAM
+ TQTextParagraph *p = doc->paragAt( fParag );
+ if ( !p )
+ return;
+ TQDataStream styleStream( style, IO_ReadOnly );
+ int num;
+ styleStream >> num;
+ while ( num-- && p ) {
+ p->readStyleInformation( styleStream );
+ p = p->next();
+ }
+#endif
+}
+
+TQTextCursor *TQTextStyleCommand::execute( TQTextCursor *c )
+{
+ writeStyleInformation( doc, firstParag, after );
+ return c;
+}
+
+TQTextCursor *TQTextStyleCommand::unexecute( TQTextCursor *c )
+{
+ writeStyleInformation( doc, firstParag, before );
+ return c;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextCursor::TQTextCursor( TQTextDocument *d )
+ : idx( 0 ), tmpX( -1 ), ox( 0 ), oy( 0 ),
+ valid( TRUE )
+{
+ para = d ? d->firstParagraph() : 0;
+}
+
+TQTextCursor::TQTextCursor( const TQTextCursor &c )
+{
+ ox = c.ox;
+ oy = c.oy;
+ idx = c.idx;
+ para = c.para;
+ tmpX = c.tmpX;
+ indices = c.indices;
+ paras = c.paras;
+ xOffsets = c.xOffsets;
+ yOffsets = c.yOffsets;
+ valid = c.valid;
+}
+
+TQTextCursor &TQTextCursor::operator=( const TQTextCursor &c )
+{
+ ox = c.ox;
+ oy = c.oy;
+ idx = c.idx;
+ para = c.para;
+ tmpX = c.tmpX;
+ indices = c.indices;
+ paras = c.paras;
+ xOffsets = c.xOffsets;
+ yOffsets = c.yOffsets;
+ valid = c.valid;
+
+ return *this;
+}
+
+bool TQTextCursor::operator==( const TQTextCursor &c ) const
+{
+ return para == c.para && idx == c.idx;
+}
+
+int TQTextCursor::totalOffsetX() const
+{
+ int xoff = ox;
+ for ( TQValueStack<int>::ConstIterator xit = xOffsets.begin(); xit != xOffsets.end(); ++xit )
+ xoff += *xit;
+ return xoff;
+}
+
+int TQTextCursor::totalOffsetY() const
+{
+ int yoff = oy;
+ for ( TQValueStack<int>::ConstIterator yit = yOffsets.begin(); yit != yOffsets.end(); ++yit )
+ yoff += *yit;
+ return yoff;
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+void TQTextCursor::gotoIntoNested( const TQPoint &globalPos )
+{
+ if ( !para )
+ return;
+ TQ_ASSERT( para->at( idx )->isCustom() );
+ push();
+ ox = 0;
+ int bl, y;
+ para->lineHeightOfChar( idx, &bl, &y );
+ oy = y + para->rect().y();
+ ox = para->at( idx )->x;
+ TQTextDocument* doc = document();
+ para->at( idx )->customItem()->enterAt( this, doc, para, idx, ox, oy, globalPos-TQPoint(ox,oy) );
+}
+#endif
+
+void TQTextCursor::invalidateNested()
+{
+ if ( nestedDepth() ) {
+ TQValueStack<TQTextParagraph*>::Iterator it = paras.begin();
+ TQValueStack<int>::Iterator it2 = indices.begin();
+ for ( ; it != paras.end(); ++it, ++it2 ) {
+ if ( *it == para )
+ continue;
+ (*it)->tqinvalidate( 0 );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( (*it)->at( *it2 )->isCustom() )
+ (*it)->at( *it2 )->customItem()->tqinvalidate();
+#endif
+ }
+ }
+}
+
+void TQTextCursor::insert( const QString &str, bool checkNewLine, TQMemArray<TQTextStringChar> *formatting )
+{
+ tmpX = -1;
+ bool justInsert = TRUE;
+ TQString s( str );
+#if defined(TQ_WS_WIN)
+ if ( checkNewLine ) {
+ int i = 0;
+ while ( ( i = s.tqfind( '\r', i ) ) != -1 )
+ s.remove( i ,1 );
+ }
+#endif
+ if ( checkNewLine )
+ justInsert = s.tqfind( '\n' ) == -1;
+ if ( justInsert ) { // we ignore new lines and insert all in the current para at the current index
+ para->insert( idx, s.tqunicode(), s.length() );
+ if ( formatting ) {
+ for ( int i = 0; i < (int)s.length(); ++i ) {
+ if ( formatting->at( i ).format() ) {
+ formatting->at( i ).format()->addRef();
+ para->string()->setFormat( idx + i, formatting->at( i ).format(), TRUE );
+ }
+ }
+ }
+ idx += s.length();
+ } else { // we split at new lines
+ int start = -1;
+ int end;
+ int y = para->rect().y() + para->rect().height();
+ int lastIndex = 0;
+ do {
+ end = s.tqfind( '\n', start + 1 ); // tqfind line break
+ if ( end == -1 ) // didn't tqfind one, so end of line is end of string
+ end = s.length();
+ int len = (start == -1 ? end : end - start - 1);
+ if ( len > 0 ) // insert the line
+ para->insert( idx, s.tqunicode() + start + 1, len );
+ else
+ para->tqinvalidate( 0 );
+ if ( formatting ) { // set formats to the chars of the line
+ for ( int i = 0; i < len; ++i ) {
+ if ( formatting->at( i + lastIndex ).format() ) {
+ formatting->at( i + lastIndex ).format()->addRef();
+ para->string()->setFormat( i + idx, formatting->at( i + lastIndex ).format(), TRUE );
+ }
+ }
+ lastIndex += len;
+ }
+ start = end; // next start is at the end of this line
+ idx += len; // increase the index of the cursor to the end of the inserted text
+ if ( s[end] == '\n' ) { // if at the end was a line break, break the line
+ splitAndInsertEmptyParagraph( FALSE, TRUE );
+ para->setEndState( -1 );
+ para->prev()->format( -1, FALSE );
+ lastIndex++;
+ }
+
+ } while ( end < (int)s.length() );
+
+ para->format( -1, FALSE );
+ int dy = para->rect().y() + para->rect().height() - y;
+ TQTextParagraph *p = para;
+ p->setParagId( p->prev() ? p->prev()->paragId() + 1 : 0 );
+ p = p->next();
+ while ( p ) {
+ p->setParagId( p->prev()->paragId() + 1 );
+ p->move( dy );
+ p->tqinvalidate( 0 );
+ p->setEndState( -1 );
+ p = p->next();
+ }
+ }
+
+ int h = para->rect().height();
+ para->format( -1, TRUE );
+ if ( h != para->rect().height() )
+ invalidateNested();
+ else if ( para->document() && para->document()->tqparent() )
+ para->document()->nextDoubleBuffered = TRUE;
+
+ fixCursorPosition();
+}
+
+void TQTextCursor::gotoLeft()
+{
+ if ( para->string()->isRightToLeft() )
+ gotoNextLetter();
+ else
+ gotoPreviousLetter();
+}
+
+void TQTextCursor::gotoPreviousLetter()
+{
+ tmpX = -1;
+
+ if ( idx > 0 ) {
+ idx = para->string()->previousCursorPosition( idx );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ const TQTextStringChar *tsc = para->at( idx );
+ if ( tsc && tsc->isCustom() && tsc->customItem()->isNested() )
+ processNesting( EnterEnd );
+#endif
+ } else if ( para->prev() ) {
+ para = para->prev();
+ while ( !para->isVisible() && para->prev() )
+ para = para->prev();
+ idx = para->length() - 1;
+ } else if ( nestedDepth() ) {
+ pop();
+ processNesting( Prev );
+ if ( idx == -1 ) {
+ pop();
+ if ( idx > 0 ) {
+ idx = para->string()->previousCursorPosition( idx );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ const TQTextStringChar *tsc = para->at( idx );
+ if ( tsc && tsc->isCustom() && tsc->customItem()->isNested() )
+ processNesting( EnterEnd );
+#endif
+ } else if ( para->prev() ) {
+ para = para->prev();
+ idx = para->length() - 1;
+ }
+ }
+ }
+}
+
+void TQTextCursor::push()
+{
+ indices.push( idx );
+ paras.push( para );
+ xOffsets.push( ox );
+ yOffsets.push( oy );
+}
+
+void TQTextCursor::pop()
+{
+ if ( indices.isEmpty() )
+ return;
+ idx = indices.pop();
+ para = paras.pop();
+ ox = xOffsets.pop();
+ oy = yOffsets.pop();
+}
+
+void TQTextCursor::restoreState()
+{
+ while ( !indices.isEmpty() )
+ pop();
+}
+
+bool TQTextCursor::place( const TQPoint &p, TQTextParagraph *s, bool link )
+{
+ TQPoint pos( p );
+ TQRect r;
+ TQTextParagraph *str = s;
+ if ( pos.y() < s->rect().y() ) {
+ pos.setY( s->rect().y() );
+#ifdef TQ_WS_MACX
+ pos.setX( s->rect().x() );
+#endif
+ }
+ while ( s ) {
+ r = s->rect();
+ r.setWidth( document() ? document()->width() : TQWIDGETSIZE_MAX );
+ if ( s->isVisible() )
+ str = s;
+ if ( pos.y() >= r.y() && pos.y() <= r.y() + r.height() )
+ break;
+ if ( !s->next() ) {
+#ifdef TQ_WS_MACX
+ pos.setX( s->rect().x() + s->rect().width() );
+#endif
+ break;
+ }
+ s = s->next();
+ }
+
+ if ( !s || !str )
+ return FALSE;
+
+ s = str;
+
+ setParagraph( s );
+ int y = s->rect().y();
+ int lines = s->lines();
+ TQTextStringChar *chr = 0;
+ int index = 0;
+ int i = 0;
+ int cy = 0;
+ int ch = 0;
+ for ( ; i < lines; ++i ) {
+ chr = s->lineStartOfLine( i, &index );
+ cy = s->lineY( i );
+ ch = s->lineHeight( i );
+ if ( !chr )
+ return FALSE;
+ if ( pos.y() <= y + cy + ch )
+ break;
+ }
+ int nextLine;
+ if ( i < lines - 1 )
+ s->lineStartOfLine( i+1, &nextLine );
+ else
+ nextLine = s->length();
+ i = index;
+ int x = s->rect().x();
+ if ( pos.x() < x )
+ pos.setX( x + 1 );
+ int cw;
+ int curpos = s->length()-1;
+ int dist = 10000000;
+ bool inCustom = FALSE;
+ while ( i < nextLine ) {
+ chr = s->at(i);
+ int cpos = x + chr->x;
+ cw = s->string()->width( i );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( chr->isCustom() && chr->customItem()->isNested() ) {
+ if ( pos.x() >= cpos && pos.x() <= cpos + cw &&
+ pos.y() >= y + cy && pos.y() <= y + cy + chr->height() ) {
+ inCustom = TRUE;
+ curpos = i;
+ break;
+ }
+ } else
+#endif
+ {
+ if( chr->rightToLeft )
+ cpos += cw;
+ int d = cpos - pos.x();
+ bool dm = d < 0 ? !chr->rightToLeft : chr->rightToLeft;
+ if ( (TQABS( d ) < dist || (dist == d && dm == TRUE )) && para->string()->validCursorPosition( i ) ) {
+ dist = TQABS( d );
+ if ( !link || pos.x() >= x + chr->x )
+ curpos = i;
+ }
+ }
+ i++;
+ }
+ setIndex( curpos );
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( inCustom && para->document() && para->at( curpos )->isCustom() && para->at( curpos )->customItem()->isNested() ) {
+ TQTextDocument *oldDoc = para->document();
+ gotoIntoNested( pos );
+ if ( oldDoc == para->document() )
+ return TRUE;
+ TQPoint p( pos.x() - offsetX(), pos.y() - offsetY() );
+ if ( !place( p, document()->firstParagraph(), link ) )
+ pop();
+ }
+#endif
+ return TRUE;
+}
+
+bool TQTextCursor::processNesting( Operation op )
+{
+ if ( !para->document() )
+ return FALSE;
+ TQTextDocument* doc = para->document();
+ push();
+ ox = para->at( idx )->x;
+ int bl, y;
+ para->lineHeightOfChar( idx, &bl, &y );
+ oy = y + para->rect().y();
+ bool ok = FALSE;
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ switch ( op ) {
+ case EnterBegin:
+ ok = para->at( idx )->customItem()->enter( this, doc, para, idx, ox, oy );
+ break;
+ case EnterEnd:
+ ok = para->at( idx )->customItem()->enter( this, doc, para, idx, ox, oy, TRUE );
+ break;
+ case Next:
+ ok = para->at( idx )->customItem()->next( this, doc, para, idx, ox, oy );
+ break;
+ case Prev:
+ ok = para->at( idx )->customItem()->prev( this, doc, para, idx, ox, oy );
+ break;
+ case Down:
+ ok = para->at( idx )->customItem()->down( this, doc, para, idx, ox, oy );
+ break;
+ case Up:
+ ok = para->at( idx )->customItem()->up( this, doc, para, idx, ox, oy );
+ break;
+ }
+ if ( !ok )
+#endif
+ pop();
+ return ok;
+}
+
+void TQTextCursor::gotoRight()
+{
+ if ( para->string()->isRightToLeft() )
+ gotoPreviousLetter();
+ else
+ gotoNextLetter();
+}
+
+void TQTextCursor::gotoNextLetter()
+{
+ tmpX = -1;
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ const TQTextStringChar *tsc = para->at( idx );
+ if ( tsc && tsc->isCustom() && tsc->customItem()->isNested() ) {
+ if ( processNesting( EnterBegin ) )
+ return;
+ }
+#endif
+
+ if ( idx < para->length() - 1 ) {
+ idx = para->string()->nextCursorPosition( idx );
+ } else if ( para->next() ) {
+ para = para->next();
+ while ( !para->isVisible() && para->next() )
+ para = para->next();
+ idx = 0;
+ } else if ( nestedDepth() ) {
+ pop();
+ processNesting( Next );
+ if ( idx == -1 ) {
+ pop();
+ if ( idx < para->length() - 1 ) {
+ idx = para->string()->nextCursorPosition( idx );
+ } else if ( para->next() ) {
+ para = para->next();
+ idx = 0;
+ }
+ }
+ }
+}
+
+void TQTextCursor::gotoUp()
+{
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar( idx, &indexOfLineStart, &line );
+ if ( !c )
+ return;
+
+ if (tmpX < 0)
+ tmpX = x();
+
+ if ( indexOfLineStart == 0 ) {
+ if ( !para->prev() ) {
+ if ( !nestedDepth() )
+ return;
+ pop();
+ processNesting( Up );
+ if ( idx == -1 ) {
+ pop();
+ if ( !para->prev() )
+ return;
+ idx = tmpX = 0;
+ } else {
+ tmpX = -1;
+ return;
+ }
+ }
+ TQTextParagraph *p = para->prev();
+ while ( p && !p->isVisible() )
+ p = p->prev();
+ if ( p )
+ para = p;
+ int lastLine = para->lines() - 1;
+ if ( !para->lineStartOfLine( lastLine, &indexOfLineStart ) )
+ return;
+ idx = indexOfLineStart;
+ while (idx < para->length()-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ } else {
+ --line;
+ int oldIndexOfLineStart = indexOfLineStart;
+ if ( !para->lineStartOfLine( line, &indexOfLineStart ) )
+ return;
+ idx = indexOfLineStart;
+ while (idx < oldIndexOfLineStart-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ }
+ fixCursorPosition();
+}
+
+void TQTextCursor::gotoDown()
+{
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar( idx, &indexOfLineStart, &line );
+ if ( !c )
+ return;
+
+ if (tmpX < 0)
+ tmpX = x();
+ if ( line == para->lines() - 1 ) {
+ if ( !para->next() ) {
+ if ( !nestedDepth() )
+ return;
+ pop();
+ processNesting( Down );
+ if ( idx == -1 ) {
+ pop();
+ if ( !para->next() )
+ return;
+ idx = tmpX = 0;
+ } else {
+ tmpX = -1;
+ return;
+ }
+ }
+ TQTextParagraph *s = para->next();
+ while ( s && !s->isVisible() )
+ s = s->next();
+ if ( s )
+ para = s;
+ if ( !para->lineStartOfLine( 0, &indexOfLineStart ) )
+ return;
+ int end;
+ if ( para->lines() == 1 )
+ end = para->length();
+ else
+ para->lineStartOfLine( 1, &end );
+
+ idx = indexOfLineStart;
+ while (idx < end-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ } else {
+ ++line;
+ int end;
+ if ( line == para->lines() - 1 )
+ end = para->length();
+ else
+ para->lineStartOfLine( line + 1, &end );
+ if ( !para->lineStartOfLine( line, &indexOfLineStart ) )
+ return;
+ idx = indexOfLineStart;
+ while (idx < end-1 && para->at(idx)->x < tmpX)
+ ++idx;
+ if (idx > indexOfLineStart &&
+ para->at(idx)->x - tmpX > tmpX - para->at(idx-1)->x)
+ --idx;
+ }
+ fixCursorPosition();
+}
+
+void TQTextCursor::gotoLineEnd()
+{
+ tmpX = -1;
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar( idx, &indexOfLineStart, &line );
+ if ( !c )
+ return;
+
+ if ( line == para->lines() - 1 ) {
+ idx = para->length() - 1;
+ } else {
+ c = para->lineStartOfLine( ++line, &indexOfLineStart );
+ indexOfLineStart--;
+ idx = indexOfLineStart;
+ }
+}
+
+void TQTextCursor::gotoLineStart()
+{
+ tmpX = -1;
+ int indexOfLineStart;
+ int line;
+ TQTextStringChar *c = para->lineStartOfChar( idx, &indexOfLineStart, &line );
+ if ( !c )
+ return;
+
+ idx = indexOfLineStart;
+}
+
+void TQTextCursor::gotoHome()
+{
+ if ( topParagraph()->document() )
+ gotoPosition( topParagraph()->document()->firstParagraph() );
+ else
+ gotoLineStart();
+}
+
+void TQTextCursor::gotoEnd()
+{
+ if ( topParagraph()->document() && topParagraph()->document()->lastParagraph()->isValid() )
+ gotoPosition( topParagraph()->document()->lastParagraph(),
+ topParagraph()->document()->lastParagraph()->length() - 1);
+ else
+ gotoLineEnd();
+}
+
+void TQTextCursor::gotoPageUp( int visibleHeight )
+{
+ int targetY = globalY() - visibleHeight;
+ TQTextParagraph* old; int index;
+ do {
+ old = para; index = idx;
+ gotoUp();
+ } while ( (old != para || index != idx) && globalY() > targetY );
+}
+
+void TQTextCursor::gotoPageDown( int visibleHeight )
+{
+ int targetY = globalY() + visibleHeight;
+ TQTextParagraph* old; int index;
+ do {
+ old = para; index = idx;
+ gotoDown();
+ } while ( (old != para || index != idx) && globalY() < targetY );
+}
+
+void TQTextCursor::gotoWordRight()
+{
+ if ( para->string()->isRightToLeft() )
+ gotoPreviousWord();
+ else
+ gotoNextWord();
+}
+
+void TQTextCursor::gotoWordLeft()
+{
+ if ( para->string()->isRightToLeft() )
+ gotoNextWord();
+ else
+ gotoPreviousWord();
+}
+
+static bool is_seperator( const TQChar &c, bool onlySpace )
+{
+ if ( onlySpace )
+ return c.isSpace();
+ return c.isSpace() ||
+ c == '\t' ||
+ c == '.' ||
+ c == ',' ||
+ c == ':' ||
+ c == ';' ||
+ c == '-' ||
+ c == '<' ||
+ c == '>' ||
+ c == '[' ||
+ c == ']' ||
+ c == '(' ||
+ c == ')' ||
+ c == '{' ||
+ c == '}';
+}
+
+void TQTextCursor::gotoPreviousWord( bool onlySpace )
+{
+ gotoPreviousLetter();
+ tmpX = -1;
+ TQTextString *s = para->string();
+ bool allowSame = FALSE;
+ if ( idx == ((int)s->length()-1) )
+ return;
+ for ( int i = idx; i >= 0; --i ) {
+ if ( is_seperator( s->at( i ).c, onlySpace ) ) {
+ if ( !allowSame )
+ continue;
+ idx = i + 1;
+ return;
+ }
+ if ( !allowSame && !is_seperator( s->at( i ).c, onlySpace ) )
+ allowSame = TRUE;
+ }
+ idx = 0;
+}
+
+void TQTextCursor::gotoNextWord( bool onlySpace )
+{
+ tmpX = -1;
+ TQTextString *s = para->string();
+ bool allowSame = FALSE;
+ for ( int i = idx; i < (int)s->length(); ++i ) {
+ if ( !is_seperator( s->at( i ).c, onlySpace ) ) {
+ if ( !allowSame )
+ continue;
+ idx = i;
+ return;
+ }
+ if ( !allowSame && is_seperator( s->at( i ).c, onlySpace ) )
+ allowSame = TRUE;
+
+ }
+
+ if ( idx < ((int)s->length()-1) ) {
+ gotoLineEnd();
+ } else if ( para->next() ) {
+ TQTextParagraph *p = para->next();
+ while ( p && !p->isVisible() )
+ p = p->next();
+ if ( s ) {
+ para = p;
+ idx = 0;
+ }
+ } else {
+ gotoLineEnd();
+ }
+}
+
+bool TQTextCursor::atParagStart()
+{
+ return idx == 0;
+}
+
+bool TQTextCursor::atParagEnd()
+{
+ return idx == para->length() - 1;
+}
+
+void TQTextCursor::splitAndInsertEmptyParagraph( bool ind, bool updateIds )
+{
+ if ( !para->document() )
+ return;
+ tmpX = -1;
+ TQTextFormat *f = 0;
+ if ( para->document()->useFormatCollection() ) {
+ f = para->at( idx )->format();
+ if ( idx == para->length() - 1 && idx > 0 )
+ f = para->at( idx - 1 )->format();
+ if ( f->isMisspelled() ) {
+ f->removeRef();
+ f = para->document()->formatCollection()->format( f->font(), f->color() );
+ }
+ }
+
+ if ( atParagEnd() ) {
+ TQTextParagraph *n = para->next();
+ TQTextParagraph *s = para->document()->createParagraph( para->document(), para, n, updateIds );
+ if ( f )
+ s->setFormat( 0, 1, f, TRUE );
+ s->copyParagData( para );
+ if ( ind ) {
+ int oi, ni;
+ s->indent( &oi, &ni );
+ para = s;
+ idx = ni;
+ } else {
+ para = s;
+ idx = 0;
+ }
+ } else if ( atParagStart() ) {
+ TQTextParagraph *p = para->prev();
+ TQTextParagraph *s = para->document()->createParagraph( para->document(), p, para, updateIds );
+ if ( f )
+ s->setFormat( 0, 1, f, TRUE );
+ s->copyParagData( para );
+ if ( ind ) {
+ s->indent();
+ s->format();
+ indent();
+ para->format();
+ }
+ } else {
+ TQString str = para->string()->toString().mid( idx, 0xFFFFFF );
+ TQTextParagraph *n = para->next();
+ TQTextParagraph *s = para->document()->createParagraph( para->document(), para, n, updateIds );
+ s->copyParagData( para );
+ s->remove( 0, 1 );
+ s->append( str, TRUE );
+ for ( int i = 0; i < str.length(); ++i ) {
+ TQTextStringChar* tsc = para->at( idx + i );
+ s->setFormat( i, 1, tsc->format(), TRUE );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( tsc->isCustom() ) {
+ TQTextCustomItem * item = tsc->customItem();
+ s->at( i )->setCustomItem( item );
+ tsc->loseCustomItem();
+ }
+#endif
+ if ( tsc->isAnchor() )
+ s->at( i )->setAnchor( tsc->anchorName(),
+ tsc->anchorHref() );
+ }
+ para->truncate( idx );
+ if ( ind ) {
+ int oi, ni;
+ s->indent( &oi, &ni );
+ para = s;
+ idx = ni;
+ } else {
+ para = s;
+ idx = 0;
+ }
+ }
+
+ invalidateNested();
+}
+
+bool TQTextCursor::remove()
+{
+ tmpX = -1;
+ if ( !atParagEnd() ) {
+ int next = para->string()->nextCursorPosition( idx );
+ para->remove( idx, next-idx );
+ int h = para->rect().height();
+ para->format( -1, TRUE );
+ if ( h != para->rect().height() )
+ invalidateNested();
+ else if ( para->document() && para->document()->tqparent() )
+ para->document()->nextDoubleBuffered = TRUE;
+ return FALSE;
+ } else if ( para->next() ) {
+ para->join( para->next() );
+ invalidateNested();
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/* needed to implement backspace the correct way */
+bool TQTextCursor::removePreviousChar()
+{
+ tmpX = -1;
+ if ( !atParagStart() ) {
+ para->remove( idx-1, 1 );
+ int h = para->rect().height();
+ idx--;
+ // shouldn't be needed, just to make sure.
+ fixCursorPosition();
+ para->format( -1, TRUE );
+ if ( h != para->rect().height() )
+ invalidateNested();
+ else if ( para->document() && para->document()->tqparent() )
+ para->document()->nextDoubleBuffered = TRUE;
+ return FALSE;
+ } else if ( para->prev() ) {
+ para = para->prev();
+ para->join( para->next() );
+ invalidateNested();
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void TQTextCursor::indent()
+{
+ int oi = 0, ni = 0;
+ para->indent( &oi, &ni );
+ if ( oi == ni )
+ return;
+
+ if ( idx >= oi )
+ idx += ni - oi;
+ else
+ idx = ni;
+}
+
+void TQTextCursor::fixCursorPosition()
+{
+ // searches for the closest valid cursor position
+ if ( para->string()->validCursorPosition( idx ) )
+ return;
+
+ int lineIdx;
+ TQTextStringChar *start = para->lineStartOfChar( idx, &lineIdx, 0 );
+ int x = para->string()->at( idx ).x;
+ int diff = TQABS(start->x - x);
+ int best = lineIdx;
+
+ TQTextStringChar *c = start;
+ ++c;
+
+ TQTextStringChar *end = &para->string()->at( para->length()-1 );
+ while ( c <= end && !c->lineStart ) {
+ int xp = c->x;
+ if ( c->rightToLeft )
+ xp += para->string()->width( lineIdx + (c-start) );
+ int ndiff = TQABS(xp - x);
+ if ( ndiff < diff && para->string()->validCursorPosition(lineIdx + (c-start)) ) {
+ diff = ndiff;
+ best = lineIdx + (c-start);
+ }
+ ++c;
+ }
+ idx = best;
+}
+
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextDocument::TQTextDocument( TQTextDocument *p )
+ : par( p ), parentPar( 0 )
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ , tc( 0 )
+#endif
+ , tArray( 0 ), tStopWidth( 0 )
+{
+ fCollection = par ? par->fCollection : new TQTextFormatCollection;
+ init();
+}
+
+void TQTextDocument::init()
+{
+ oTextValid = TRUE;
+ mightHaveCustomItems = FALSE;
+ if ( par )
+ par->insertChild( this );
+ pProcessor = 0;
+ useFC = TRUE;
+ pFormatter = 0;
+ indenter = 0;
+ fParag = 0;
+ txtFormat = TQt::AutoText;
+ preferRichText = FALSE;
+ pages = FALSE;
+ focusIndicator.parag = 0;
+ minw = 0;
+ wused = 0;
+ minwParag = curParag = 0;
+ align = TQt::AlignAuto;
+ nSelections = 1;
+
+ setStyleSheet( TQStyleSheet::defaultSheet() );
+#ifndef TQT_NO_MIME
+ factory_ = TQMimeSourceFactory::defaultFactory();
+#endif
+ contxt = TQString::null;
+
+ underlLinks = par ? par->underlLinks : TRUE;
+ backBrush = 0;
+ buf_pixmap = 0;
+ nextDoubleBuffered = FALSE;
+
+ if ( par )
+ withoutDoubleBuffer = par->withoutDoubleBuffer;
+ else
+ withoutDoubleBuffer = FALSE;
+
+ lParag = fParag = createParagraph( this, 0, 0 );
+
+ cx = 0;
+ cy = 2;
+ if ( par )
+ cx = cy = 0;
+ cw = 600;
+ vw = 0;
+ flow_ = new TQTextFlow;
+ flow_->setWidth( cw );
+
+ leftmargin = rightmargin = 4;
+ scaleFontsFactor = 1;
+
+
+ selectionColors[ Standard ] = TQApplication::palette().color( TQPalette::Active, TQColorGroup::Highlight );
+ selectionText[ Standard ] = TRUE;
+ selectionText[ IMSelectionText ] = TRUE;
+ selectionText[ IMCompositionText ] = FALSE;
+ commandHistory = new TQTextCommandHistory( 100 );
+ tStopWidth = formatCollection()->defaultFormat()->width( 'x' ) * 8;
+}
+
+TQTextDocument::~TQTextDocument()
+{
+ delete commandHistory;
+ if ( par )
+ par->removeChild( this );
+ clear();
+ delete flow_;
+ if ( !par ) {
+ delete pFormatter;
+ delete fCollection;
+ }
+ delete pProcessor;
+ delete buf_pixmap;
+ delete indenter;
+ delete backBrush;
+ delete [] tArray;
+}
+
+void TQTextDocument::clear( bool createEmptyParag )
+{
+ while ( fParag ) {
+ TQTextParagraph *p = fParag->next();
+ delete fParag;
+ fParag = p;
+ }
+ if ( flow_ )
+ flow_->clear();
+ fParag = lParag = 0;
+ if ( createEmptyParag )
+ fParag = lParag = createParagraph( this );
+ focusIndicator.parag = 0;
+ selections.clear();
+ oText = TQString::null;
+ oTextValid = FALSE;
+}
+
+int TQTextDocument::widthUsed() const
+{
+ return wused + 2*border_tolerance;
+}
+
+int TQTextDocument::height() const
+{
+ int h = 0;
+ if ( lParag )
+ h = lParag->rect().top() + lParag->rect().height() + 1;
+ int fh = flow_->boundingRect().bottom();
+ return TQMAX( h, fh );
+}
+
+
+
+TQTextParagraph *TQTextDocument::createParagraph( TQTextDocument *d, TQTextParagraph *pr, TQTextParagraph *nx, bool updateIds )
+{
+ return new TQTextParagraph( d, pr, nx, updateIds );
+}
+
+bool TQTextDocument::setMinimumWidth( int needed, int used, TQTextParagraph *p )
+{
+ if ( needed == -1 ) {
+ minw = 0;
+ wused = 0;
+ p = 0;
+ }
+ if ( p == minwParag ) {
+ if (minw > needed) {
+ TQTextParagraph *tp = fParag;
+ while (tp) {
+ if (tp != p && tp->minwidth > needed) {
+ needed = tp->minwidth;
+ minwParag = tp;
+ }
+ tp = tp->n;
+ }
+ }
+ minw = needed;
+ emit minimumWidthChanged( minw );
+ } else if ( needed > minw ) {
+ minw = needed;
+ minwParag = p;
+ emit minimumWidthChanged( minw );
+ }
+ wused = TQMAX( wused, used );
+ wused = TQMAX( wused, minw );
+ cw = TQMAX( minw, cw );
+ return TRUE;
+}
+
+void TQTextDocument::setPlainText( const TQString &text )
+{
+ preferRichText = FALSE;
+ clear();
+ oTextValid = TRUE;
+ oText = text;
+
+ int lastNl = 0;
+ int nl = text.tqfind( '\n' );
+ if ( nl == -1 ) {
+ lParag = createParagraph( this, lParag, 0 );
+ if ( !fParag )
+ fParag = lParag;
+ TQString s = text;
+ if ( !s.isEmpty() ) {
+ if ( s[ (int)s.length() - 1 ] == '\r' )
+ s.remove( s.length() - 1, 1 );
+ lParag->append( s );
+ }
+ } else {
+ for (;;) {
+ lParag = createParagraph( this, lParag, 0 );
+ if ( !fParag )
+ fParag = lParag;
+ int l = nl - lastNl;
+ if ( l > 0 ) {
+ if (text.tqunicode()[nl-1] == '\r')
+ l--;
+ TQConstString cs(text.tqunicode()+lastNl, l);
+ lParag->append( cs.string() );
+ }
+ if ( nl == (int)text.length() )
+ break;
+ lastNl = nl + 1;
+ nl = text.tqfind( '\n', nl + 1 );
+ if ( nl == -1 )
+ nl = text.length();
+ }
+ }
+ if ( !lParag )
+ lParag = fParag = createParagraph( this, 0, 0 );
+}
+
+struct TQ_EXPORT TQTextDocumentTag {
+ TQTextDocumentTag(){}
+ TQTextDocumentTag( const TQString&n, const TQStyleSheetItem* s, const TQTextFormat& f )
+ :name(n),style(s), format(f), tqalignment(TQt::AlignAuto), direction(TQChar::DirON),liststyle(TQStyleSheetItem::ListDisc) {
+ wsm = TQStyleSheetItem::WhiteSpaceNormal;
+ }
+ TQString name;
+ const TQStyleSheetItem* style;
+ TQString anchorHref;
+ TQStyleSheetItem::WhiteSpaceMode wsm;
+ TQTextFormat format;
+ int tqalignment : 16;
+ int direction : 5;
+ TQStyleSheetItem::ListStyle liststyle;
+
+ TQTextDocumentTag( const TQTextDocumentTag& t ) {
+ name = t.name;
+ style = t.style;
+ anchorHref = t.anchorHref;
+ wsm = t.wsm;
+ format = t.format;
+ tqalignment = t.tqalignment;
+ direction = t.direction;
+ liststyle = t.liststyle;
+ }
+ TQTextDocumentTag& operator=(const TQTextDocumentTag& t) {
+ name = t.name;
+ style = t.style;
+ anchorHref = t.anchorHref;
+ wsm = t.wsm;
+ format = t.format;
+ tqalignment = t.tqalignment;
+ direction = t.direction;
+ liststyle = t.liststyle;
+ return *this;
+ }
+
+ TQ_DUMMY_COMPARISON_OPERATOR(TQTextDocumentTag)
+};
+
+
+#define NEWPAR do{ if ( !hasNewPar) { \
+ if ( !textEditMode && curpar && curpar->length()>1 && curpar->at( curpar->length()-2)->c == TQChar_linesep ) \
+ curpar->remove( curpar->length()-2, 1 ); \
+ curpar = createParagraph( this, curpar, curpar->next() ); styles.append( vec ); vec = 0;} \
+ hasNewPar = TRUE; \
+ curpar->rtext = TRUE; \
+ curpar->align = curtag.tqalignment; \
+ curpar->lstyle = curtag.liststyle; \
+ curpar->litem = ( curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem ); \
+ curpar->str->setDirection( (TQChar::Direction)curtag.direction ); \
+ space = TRUE; \
+ tabExpansionColumn = 0; \
+ delete vec; vec = new TQPtrVector<TQStyleSheetItem>( (uint)tags.count() + 1); \
+ int i = 0; \
+ for ( TQValueStack<TQTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it ) \
+ vec->insert( i++, (*it).style ); \
+ vec->insert( i, curtag.style ); \
+ }while(FALSE);
+
+
+void TQTextDocument::setRichText( const TQString &text, const TQString &context, const TQTextFormat *initialFormat )
+{
+ preferRichText = TRUE;
+ if ( !context.isEmpty() )
+ setContext( context );
+ clear();
+ fParag = lParag = createParagraph( this );
+ oTextValid = TRUE;
+ oText = text;
+ setRichTextInternal( text, 0, initialFormat );
+ fParag->rtext = TRUE;
+}
+
+void TQTextDocument::setRichTextInternal( const TQString &text, TQTextCursor* cursor, const TQTextFormat *initialFormat )
+{
+ TQTextParagraph* curpar = lParag;
+ int pos = 0;
+ TQValueStack<TQTextDocumentTag> tags;
+ if ( !initialFormat )
+ initialFormat = formatCollection()->defaultFormat();
+ TQTextDocumentTag initag( "", sheet_->item(""), *initialFormat );
+ if ( bodyText.isValid() )
+ initag.format.setColor( bodyText );
+ TQTextDocumentTag curtag = initag;
+ bool space = TRUE;
+ bool canMergeLi = FALSE;
+
+ bool textEditMode = FALSE;
+ int tabExpansionColumn = 0;
+
+ const TQChar* doc = text.tqunicode();
+ int length = text.length();
+ bool hasNewPar = curpar->length() <= 1;
+ TQString anchorName;
+
+ // style sheet handling for margin and line spacing calculation below
+ TQTextParagraph* stylesPar = curpar;
+ TQPtrVector<TQStyleSheetItem>* vec = 0;
+ TQPtrList< TQPtrVector<TQStyleSheetItem> > styles;
+ styles.setAutoDelete( TRUE );
+
+ if ( cursor ) {
+ cursor->splitAndInsertEmptyParagraph();
+ TQTextCursor tmp = *cursor;
+ tmp.gotoPreviousLetter();
+ stylesPar = curpar = tmp.paragraph();
+ hasNewPar = TRUE;
+ textEditMode = TRUE;
+ } else {
+ NEWPAR;
+ }
+
+ // set rtext spacing to FALSE for the initial paragraph.
+ curpar->rtext = FALSE;
+
+ TQString wellKnownTags = "br hr wsp table qt body meta title";
+
+ while ( pos < length ) {
+ if ( hasPrefix(doc, length, pos, '<' ) ){
+ if ( !hasPrefix( doc, length, pos+1, TQChar('/') ) ) {
+ // open tag
+ QMap<TQString, TQString> attr;
+ bool emptyTag = FALSE;
+ TQString tagname = parseOpenTag(doc, length, pos, attr, emptyTag);
+ if ( tagname.isEmpty() )
+ continue; // nothing we could do with this, probably parse error
+
+ const TQStyleSheetItem* nstyle = sheet_->item(tagname);
+
+ if ( nstyle ) {
+ // we might have to close some 'forgotten' tags
+ while ( !nstyle->allowedInContext( curtag.style ) ) {
+ TQString msg;
+ msg.sprintf( "TQText Warning: Document not valid ( '%s' not allowed in '%s' #%d)",
+ tagname.ascii(), curtag.style->name().ascii(), pos);
+ sheet_->error( msg );
+ if ( tags.isEmpty() )
+ break;
+ curtag = tags.pop();
+ }
+
+ /* special handling for p and li for HTML
+ compatibility. We do not want to embed blocks in
+ p, and we do not want new blocks inside non-empty
+ lis. Plus we want to merge empty lis sometimes. */
+ if( nstyle->displayMode() == TQStyleSheetItem::DisplayListItem ) {
+ canMergeLi = TRUE;
+ } else if ( nstyle->displayMode() == TQStyleSheetItem::DisplayBlock ) {
+ while ( curtag.style->name() == "p" ) {
+ if ( tags.isEmpty() )
+ break;
+ curtag = tags.pop();
+ }
+
+ if ( curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem ) {
+ // we are in a li and a new block comes along
+ if ( nstyle->name() == "ul" || nstyle->name() == "ol" )
+ hasNewPar = FALSE; // we want an empty li (like most browsers)
+ if ( !hasNewPar ) {
+ /* do not add new blocks inside
+ non-empty lis */
+ while ( curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem ) {
+ if ( tags.isEmpty() )
+ break;
+ curtag = tags.pop();
+ }
+ } else if ( canMergeLi ) {
+ /* we have an empty li and a block
+ comes along, merge them */
+ nstyle = curtag.style;
+ }
+ canMergeLi = FALSE;
+ }
+ }
+ }
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem* custom = 0;
+#else
+ bool custom = FALSE;
+#endif
+
+ // some well-known tags, some have a nstyle, some not
+ if ( wellKnownTags.tqfind( tagname ) != -1 ) {
+ if ( tagname == "br" ) {
+ emptyTag = space = TRUE;
+ int index = TQMAX( curpar->length(),1) - 1;
+ TQTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor );
+ curpar->append( TQChar_linesep );
+ curpar->setFormat( index, 1, &format );
+ hasNewPar = false;
+ } else if ( tagname == "hr" ) {
+ emptyTag = space = TRUE;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this );
+#endif
+ } else if ( tagname == "table" ) {
+ emptyTag = space = TRUE;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor );
+ curpar->tqsetAlignment( curtag.tqalignment );
+ custom = parseTable( attr, format, doc, length, pos, curpar );
+#endif
+ } else if ( tagname == "qt" || tagname == "body" ) {
+ if ( attr.tqcontains( "bgcolor" ) ) {
+ TQBrush *b = new TQBrush( TQColor( attr["bgcolor"] ) );
+ setPaper( b );
+ }
+ if ( attr.tqcontains( "background" ) ) {
+#ifndef TQT_NO_MIME
+ TQImage img;
+ TQString bg = attr["background"];
+ const TQMimeSource* m = factory_->data( bg, contxt );
+ if ( !m ) {
+ qWarning("TQRichText: no mimesource for %s", bg.latin1() );
+ } else {
+ if ( !TQImageDrag::decode( m, img ) ) {
+ qWarning("TQTextImage: cannot decode %s", bg.latin1() );
+ }
+ }
+ if ( !img.isNull() ) {
+ TQBrush *b = new TQBrush( TQColor(), TQPixmap( img ) );
+ setPaper( b );
+ }
+#endif
+ }
+ if ( attr.tqcontains( "text" ) ) {
+ TQColor c( attr["text"] );
+ initag.format.setColor( c );
+ curtag.format.setColor( c );
+ bodyText = c;
+ }
+ if ( attr.tqcontains( "link" ) )
+ linkColor = TQColor( attr["link"] );
+ if ( attr.tqcontains( "title" ) )
+ attribs.tqreplace( "title", attr["title"] );
+
+ if ( textEditMode ) {
+ if ( attr.tqcontains("style" ) ) {
+ TQString a = attr["style"];
+ for ( int s = 0; s < a.tqcontains(';')+1; s++ ) {
+ TQString style = a.section( ';', s, s );
+ if ( style.startsWith("font-size:" ) && style.endsWith("pt") ) {
+ scaleFontsFactor = double( formatCollection()->defaultFormat()->fn.pointSize() ) /
+ style.mid( 10, style.length() - 12 ).toInt();
+ }
+ }
+ }
+ nstyle = 0; // ignore body in textEditMode
+ }
+ // end qt- and body-tag handling
+ } else if ( tagname == "meta" ) {
+ if ( attr["name"] == "qrichtext" && attr["content"] == "1" )
+ textEditMode = TRUE;
+ } else if ( tagname == "title" ) {
+ TQString title;
+ while ( pos < length ) {
+ if ( hasPrefix( doc, length, pos, TQChar('<') ) && hasPrefix( doc, length, pos+1, TQChar('/') ) &&
+ parseCloseTag( doc, length, pos ) == "title" )
+ break;
+ title += doc[ pos ];
+ ++pos;
+ }
+ attribs.tqreplace( "title", title );
+ }
+ } // end of well-known tag handling
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( !custom ) // try generic custom item
+ custom = sheet_->tag( tagname, attr, contxt, *factory_ , emptyTag, this );
+#endif
+ if ( !nstyle && !custom ) // we have no clue what this tag could be, ignore it
+ continue;
+
+ if ( custom ) {
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ int index = TQMAX( curpar->length(),1) - 1;
+ TQTextFormat format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor );
+ curpar->append( TQChar('*') );
+ TQTextFormat* f = formatCollection()->format( &format );
+ curpar->setFormat( index, 1, f );
+ curpar->at( index )->setCustomItem( custom );
+ if ( !curtag.anchorHref.isEmpty() )
+ curpar->at(index)->setAnchor( TQString::null, curtag.anchorHref );
+ if ( !anchorName.isEmpty() ) {
+ curpar->at(index)->setAnchor( anchorName, curpar->at(index)->anchorHref() );
+ anchorName = TQString::null;
+ }
+ registerCustomItem( custom, curpar );
+ hasNewPar = FALSE;
+#endif
+ } else if ( !emptyTag ) {
+ /* if we do nesting, push curtag on the stack,
+ otherwise reinint curag. */
+ if ( curtag.style->name() != tagname || nstyle->selfNesting() ) {
+ tags.push( curtag );
+ } else {
+ if ( !tags.isEmpty() )
+ curtag = tags.top();
+ else
+ curtag = initag;
+ }
+
+ curtag.name = tagname;
+ curtag.style = nstyle;
+ curtag.name = tagname;
+ curtag.style = nstyle;
+ if ( nstyle->whiteSpaceMode() != TQStyleSheetItem::WhiteSpaceModeUndefined )
+ curtag.wsm = nstyle->whiteSpaceMode();
+
+ /* netscape compatibility: eat a newline and only a newline if a pre block starts */
+ if ( curtag.wsm == TQStyleSheetItem::WhiteSpacePre &&
+ nstyle->displayMode() == TQStyleSheetItem::DisplayBlock )
+ eat( doc, length, pos, '\n' );
+
+ /* ignore whitespace for inline elements if there
+ was already one*/
+ if ( !textEditMode &&
+ (curtag.wsm == TQStyleSheetItem::WhiteSpaceNormal
+ || curtag.wsm == TQStyleSheetItem::WhiteSpaceNoWrap)
+ && ( space || nstyle->displayMode() != TQStyleSheetItem::DisplayInline ) )
+ eatSpace( doc, length, pos );
+
+ curtag.format = curtag.format.makeTextFormat( nstyle, attr, scaleFontsFactor );
+ if ( nstyle->isAnchor() ) {
+ if ( !anchorName.isEmpty() )
+ anchorName += "#" + attr["name"];
+ else
+ anchorName = attr["name"];
+ curtag.anchorHref = attr["href"];
+ }
+
+ if ( nstyle->tqalignment() != TQStyleSheetItem::Undefined )
+ curtag.tqalignment = nstyle->tqalignment();
+
+ if ( nstyle->listStyle() != TQStyleSheetItem::ListStyleUndefined )
+ curtag.liststyle = nstyle->listStyle();
+
+ if ( nstyle->displayMode() == TQStyleSheetItem::DisplayBlock
+ || nstyle->displayMode() == TQStyleSheetItem::DisplayListItem ) {
+
+ if ( nstyle->name() == "ol" || nstyle->name() == "ul" || nstyle->name() == "li") {
+ TQString type = attr["type"];
+ if ( !type.isEmpty() ) {
+ if ( type == "1" ) {
+ curtag.liststyle = TQStyleSheetItem::ListDecimal;
+ } else if ( type == "a" ) {
+ curtag.liststyle = TQStyleSheetItem::ListLowerAlpha;
+ } else if ( type == "A" ) {
+ curtag.liststyle = TQStyleSheetItem::ListUpperAlpha;
+ } else {
+ type = type.lower();
+ if ( type == "square" )
+ curtag.liststyle = TQStyleSheetItem::ListSquare;
+ else if ( type == "disc" )
+ curtag.liststyle = TQStyleSheetItem::ListDisc;
+ else if ( type == "circle" )
+ curtag.liststyle = TQStyleSheetItem::ListCircle;
+ }
+ }
+ }
+
+
+ /* Internally we treat ordered and bullet
+ lists the same for margin calculations. In
+ order to have fast pointer compares in the
+ xMargin() functions we restrict ourselves to
+ <ol>. Once we calculate the margins in the
+ parser rathern than later, the unelegance of
+ this approach goes awy
+ */
+ if ( nstyle->name() == "ul" )
+ curtag.style = sheet_->item( "ol" );
+
+ if ( attr.tqcontains( "align" ) ) {
+ TQString align = attr["align"].lower();
+ if ( align == "center" )
+ curtag.tqalignment = TQt::AlignCenter;
+ else if ( align == "right" )
+ curtag.tqalignment = TQt::AlignRight;
+ else if ( align == "justify" )
+ curtag.tqalignment = TQt::AlignJustify;
+ }
+ if ( attr.tqcontains( "dir" ) ) {
+ TQString dir = attr["dir"];
+ if ( dir == "rtl" )
+ curtag.direction = TQChar::DirR;
+ else if ( dir == "ltr" )
+ curtag.direction = TQChar::DirL;
+ }
+
+ NEWPAR;
+
+ if ( curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem ) {
+ if ( attr.tqcontains( "value " ) )
+ curpar->setListValue( attr["value"].toInt() );
+ }
+
+ if ( attr.tqcontains( "style" ) ) {
+ TQString a = attr["style"];
+ bool ok = TRUE;
+ for ( int s = 0; ok && s < a.tqcontains(';')+1; s++ ) {
+ TQString style = a.section( ';', s, s );
+ if ( style.startsWith("margin-top:" ) && style.endsWith("px") )
+ curpar->utm = 1+style.mid(11, style.length() - 13).toInt(&ok);
+ else if ( style.startsWith("margin-bottom:" ) && style.endsWith("px") )
+ curpar->ubm = 1+style.mid(14, style.length() - 16).toInt(&ok);
+ else if ( style.startsWith("margin-left:" ) && style.endsWith("px") )
+ curpar->ulm = 1+style.mid(12, style.length() - 14).toInt(&ok);
+ else if ( style.startsWith("margin-right:" ) && style.endsWith("px") )
+ curpar->urm = 1+style.mid(13, style.length() - 15).toInt(&ok);
+ else if ( style.startsWith("text-indent:" ) && style.endsWith("px") )
+ curpar->uflm = 1+style.mid(12, style.length() - 14).toInt(&ok);
+ }
+ if ( !ok ) // be pressmistic
+ curpar->utm = curpar->ubm = curpar->urm = curpar->ulm = 0;
+ }
+ }
+ }
+ } else {
+ TQString tagname = parseCloseTag( doc, length, pos );
+ if ( tagname.isEmpty() )
+ continue; // nothing we could do with this, probably parse error
+ if ( !sheet_->item( tagname ) ) // ignore unknown tags
+ continue;
+ if ( tagname == "li" )
+ continue;
+
+ // we close a block item. Since the text may continue, we need to have a new paragraph
+ bool needNewPar = curtag.style->displayMode() == TQStyleSheetItem::DisplayBlock
+ || curtag.style->displayMode() == TQStyleSheetItem::DisplayListItem;
+
+
+ // html slopiness: handle unbalanched tag closing
+ while ( curtag.name != tagname ) {
+ TQString msg;
+ msg.sprintf( "TQText Warning: Document not valid ( '%s' not closed before '%s' #%d)",
+ curtag.name.ascii(), tagname.ascii(), pos);
+ sheet_->error( msg );
+ if ( tags.isEmpty() )
+ break;
+ curtag = tags.pop();
+ }
+
+
+ // close the tag
+ if ( !tags.isEmpty() )
+ curtag = tags.pop();
+ else
+ curtag = initag;
+
+ if ( needNewPar ) {
+ if ( textEditMode && (tagname == "p" || tagname == "div" ) ) // preserve empty paragraphs
+ hasNewPar = FALSE;
+ NEWPAR;
+ }
+ }
+ } else {
+ // normal contents
+ TQString s;
+ TQChar c;
+ while ( pos < length && !hasPrefix(doc, length, pos, TQChar('<') ) ){
+ if ( textEditMode ) {
+ // text edit mode: we handle all white space but ignore newlines
+ c = parseChar( doc, length, pos, TQStyleSheetItem::WhiteSpacePre );
+ if ( c == TQChar_linesep )
+ break;
+ } else {
+ int l = pos;
+ c = parseChar( doc, length, pos, curtag.wsm );
+
+ // in white space pre mode: treat any space as non breakable
+ // and expand tabs to eight character wide columns.
+ if ( curtag.wsm == TQStyleSheetItem::WhiteSpacePre ) {
+ if ( c == '\t' ) {
+ c = ' ';
+ while( (++tabExpansionColumn)%8 )
+ s += c;
+ }
+ if ( c == TQChar_linesep )
+ tabExpansionColumn = 0;
+ else
+ tabExpansionColumn++;
+
+ }
+ if ( c == ' ' || c == TQChar_linesep ) {
+ /* avoid overlong paragraphs by forcing a new
+ paragraph after 4096 characters. This case can
+ occur when loading undiscovered plain text
+ documents in rich text mode. Instead of hanging
+ forever, we do the trick.
+ */
+ if ( curtag.wsm == TQStyleSheetItem::WhiteSpaceNormal && s.length() > 4096 ) do {
+ if ( doc[l] == '\n' ) {
+ hasNewPar = FALSE; // for a new paragraph ...
+ NEWPAR;
+ hasNewPar = FALSE; // ... and make it non-reusable
+ c = '\n'; // make sure we break below
+ break;
+ }
+ } while ( ++l < pos );
+ }
+ }
+
+ if ( c == '\n' )
+ break; // break on newlines, pre delievers a TQChar_linesep
+
+ bool c_isSpace = c.isSpace() && c.tqunicode() != 0x00a0U && !textEditMode;
+
+ if ( curtag.wsm == TQStyleSheetItem::WhiteSpaceNormal && c_isSpace && space )
+ continue;
+ if ( c == '\r' )
+ continue;
+ space = c_isSpace;
+ s += c;
+ }
+ if ( !s.isEmpty() && curtag.style->displayMode() != TQStyleSheetItem::DisplayNone ) {
+ hasNewPar = FALSE;
+ int index = TQMAX( curpar->length(),1) - 1;
+ curpar->append( s );
+ if (curtag.wsm != TQStyleSheetItem::WhiteSpaceNormal) {
+ TQTextString *str = curpar->string();
+ for (int i = index; i < index + s.length(); ++i)
+ str->at(i).nobreak = TRUE;
+ }
+
+ TQTextFormat* f = formatCollection()->format( &curtag.format );
+ curpar->setFormat( index, s.length(), f, FALSE ); // do not use collection because we have done that already
+ f->ref += s.length() -1; // that what friends are for...
+ if ( !curtag.anchorHref.isEmpty() ) {
+ for ( int i = 0; i < int(s.length()); i++ )
+ curpar->at(index + i)->setAnchor( TQString::null, curtag.anchorHref );
+ }
+ if ( !anchorName.isEmpty() ) {
+ for ( int i = 0; i < int(s.length()); i++ )
+ curpar->at(index + i)->setAnchor( anchorName, curpar->at(index + i)->anchorHref() );
+ anchorName = TQString::null;
+ }
+ }
+ }
+ }
+
+ if ( hasNewPar && curpar != fParag && !cursor && stylesPar != curpar ) {
+ // cleanup unused last paragraphs
+ curpar = curpar->p;
+ delete curpar->n;
+ }
+
+ if ( !anchorName.isEmpty() ) {
+ curpar->at(curpar->length() - 1)->setAnchor( anchorName, curpar->at( curpar->length() - 1 )->anchorHref() );
+ anchorName = TQString::null;
+ }
+
+
+ setRichTextMarginsInternal( styles, stylesPar );
+
+ if ( cursor ) {
+ cursor->gotoPreviousLetter();
+ cursor->remove();
+ }
+ delete vec;
+}
+
+void TQTextDocument::setRichTextMarginsInternal( TQPtrList< TQPtrVector<TQStyleSheetItem> >& styles, TQTextParagraph* stylesPar )
+{
+ // margin and line spacing calculation
+ TQPtrVector<TQStyleSheetItem>* prevStyle = 0;
+ TQPtrVector<TQStyleSheetItem>* curStyle = styles.first();
+ TQPtrVector<TQStyleSheetItem>* nextStyle = styles.next();
+ while ( stylesPar ) {
+ if ( !curStyle ) {
+ stylesPar = stylesPar->next();
+ prevStyle = curStyle;
+ curStyle = nextStyle;
+ nextStyle = styles.next();
+ continue;
+ }
+
+ int i, mar;
+ TQStyleSheetItem* mainStyle = curStyle->size() ? (*curStyle)[curStyle->size()-1] : 0;
+ if ( mainStyle && mainStyle->displayMode() == TQStyleSheetItem::DisplayListItem )
+ stylesPar->setListItem( TRUE );
+ int numLists = 0;
+ for ( i = 0; i < (int)curStyle->size(); ++i ) {
+ if ( (*curStyle)[ i ]->displayMode() == TQStyleSheetItem::DisplayBlock
+ && (*curStyle)[ i ]->listStyle() != TQStyleSheetItem::ListStyleUndefined )
+ numLists++;
+ }
+ stylesPar->ldepth = numLists;
+ if ( stylesPar->next() && nextStyle ) {
+ // also set the depth of the next paragraph, required for the margin calculation
+ numLists = 0;
+ for ( i = 0; i < (int)nextStyle->size(); ++i ) {
+ if ( (*nextStyle)[ i ]->displayMode() == TQStyleSheetItem::DisplayBlock
+ && (*nextStyle)[ i ]->listStyle() != TQStyleSheetItem::ListStyleUndefined )
+ numLists++;
+ }
+ stylesPar->next()->ldepth = numLists;
+ }
+
+ // do the top margin
+ TQStyleSheetItem* item = mainStyle;
+ int m;
+ if (stylesPar->utm > 0 ) {
+ m = stylesPar->utm-1;
+ stylesPar->utm = 0;
+ } else {
+ m = TQMAX(0, item->margin( TQStyleSheetItem::MarginTop ) );
+ if ( stylesPar->ldepth ) {
+ if ( item->displayMode() == TQStyleSheetItem::DisplayListItem )
+ m /= stylesPar->ldepth * stylesPar->ldepth;
+ else
+ m = 0;
+ }
+ }
+ for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
+ item = (*curStyle)[ i ];
+ if ( prevStyle && i < (int) prevStyle->size() &&
+ ( item->displayMode() == TQStyleSheetItem::DisplayBlock &&
+ (*prevStyle)[ i ] == item ) )
+ break;
+ // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags
+ if ( item->listStyle() != TQStyleSheetItem::ListStyleUndefined &&
+ ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) )
+ continue;
+ mar = TQMAX( 0, item->margin( TQStyleSheetItem::MarginTop ) );
+ m = TQMAX( m, mar );
+ }
+ stylesPar->utm = m - stylesPar->topMargin();
+
+ // do the bottom margin
+ item = mainStyle;
+ if (stylesPar->ubm > 0 ) {
+ m = stylesPar->ubm-1;
+ stylesPar->ubm = 0;
+ } else {
+ m = TQMAX(0, item->margin( TQStyleSheetItem::MarginBottom ) );
+ if ( stylesPar->ldepth ) {
+ if ( item->displayMode() == TQStyleSheetItem::DisplayListItem )
+ m /= stylesPar->ldepth * stylesPar->ldepth;
+ else
+ m = 0;
+ }
+ }
+ for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
+ item = (*curStyle)[ i ];
+ if ( nextStyle && i < (int) nextStyle->size() &&
+ ( item->displayMode() == TQStyleSheetItem::DisplayBlock &&
+ (*nextStyle)[ i ] == item ) )
+ break;
+ // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags
+ if ( item->listStyle() != TQStyleSheetItem::ListStyleUndefined &&
+ ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) )
+ continue;
+ mar = TQMAX(0, item->margin( TQStyleSheetItem::MarginBottom ) );
+ m = TQMAX( m, mar );
+ }
+ stylesPar->ubm = m - stylesPar->bottomMargin();
+
+ // do the left margin, simplyfied
+ item = mainStyle;
+ if (stylesPar->ulm > 0 ) {
+ m = stylesPar->ulm-1;
+ stylesPar->ulm = 0;
+ } else {
+ m = TQMAX( 0, item->margin( TQStyleSheetItem::MarginLeft ) );
+ }
+ for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
+ item = (*curStyle)[ i ];
+ m += TQMAX( 0, item->margin( TQStyleSheetItem::MarginLeft ) );
+ }
+ stylesPar->ulm = m - stylesPar->leftMargin();
+
+ // do the right margin, simplyfied
+ item = mainStyle;
+ if (stylesPar->urm > 0 ) {
+ m = stylesPar->urm-1;
+ stylesPar->urm = 0;
+ } else {
+ m = TQMAX( 0, item->margin( TQStyleSheetItem::MarginRight ) );
+ }
+ for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
+ item = (*curStyle)[ i ];
+ m += TQMAX( 0, item->margin( TQStyleSheetItem::MarginRight ) );
+ }
+ stylesPar->urm = m - stylesPar->rightMargin();
+
+ // do the first line margin, which really should be called text-indent
+ item = mainStyle;
+ if (stylesPar->uflm > 0 ) {
+ m = stylesPar->uflm-1;
+ stylesPar->uflm = 0;
+ } else {
+ m = TQMAX( 0, item->margin( TQStyleSheetItem::MarginFirstLine ) );
+ }
+ for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
+ item = (*curStyle)[ i ];
+ mar = TQMAX( 0, item->margin( TQStyleSheetItem::MarginFirstLine ) );
+ m = TQMAX( m, mar );
+ }
+ stylesPar->uflm =m - stylesPar->firstLineMargin();
+
+ // do the bogus line "spacing", which really is just an extra margin
+ item = mainStyle;
+ for ( i = (int)curStyle->size() - 1 ; i >= 0; --i ) {
+ item = (*curStyle)[ i ];
+ if ( item->lineSpacing() != TQStyleSheetItem::Undefined ) {
+ stylesPar->ulinespacing = item->lineSpacing();
+ if ( formatCollection() &&
+ stylesPar->ulinespacing < formatCollection()->defaultFormat()->height() )
+ stylesPar->ulinespacing += formatCollection()->defaultFormat()->height();
+ break;
+ }
+ }
+
+ stylesPar = stylesPar->next();
+ prevStyle = curStyle;
+ curStyle = nextStyle;
+ nextStyle = styles.next();
+ }
+}
+
+void TQTextDocument::setText( const TQString &text, const TQString &context )
+{
+ focusIndicator.parag = 0;
+ selections.clear();
+ if ( ((txtFormat == TQt::AutoText) && (TQStyleSheet::mightBeRichText( text ))) ||
+ (txtFormat == TQt::RichText) )
+ setRichText( text, context );
+ else
+ setPlainText( text );
+}
+
+TQString TQTextDocument::plainText() const
+{
+ TQString buffer;
+ TQString s;
+ TQTextParagraph *p = fParag;
+ while ( p ) {
+ if ( !p->mightHaveCustomItems ) {
+ const TQTextString *ts = p->string(); // workaround VC++ and Borland
+ s = ts->toString(); // with FALSE we don't fix spaces (nbsp)
+ } else {
+ for ( int i = 0; i < p->length() - 1; ++i ) {
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( p->at( i )->isCustom() ) {
+ if ( p->at( i )->customItem()->isNested() ) {
+ s += "\n";
+ TQTextTable *t = (TQTextTable*)p->at( i )->customItem();
+ TQPtrList<TQTextTableCell> cells = t->tableCells();
+ for ( TQTextTableCell *c = cells.first(); c; c = cells.next() )
+ s += c->richText()->plainText() + "\n";
+ s += "\n";
+ }
+ } else
+#endif
+ {
+ s += p->at( i )->c;
+ }
+ }
+ }
+ s.remove( s.length() - 1, 1 );
+ if ( p->next() )
+ s += "\n";
+ buffer += s;
+ p = p->next();
+ }
+ return buffer;
+}
+
+static TQString align_to_string( int a )
+{
+ if ( a & TQt::AlignRight )
+ return " align=\"right\"";
+ if ( a & TQt::AlignHCenter )
+ return " align=\"center\"";
+ if ( a & TQt::AlignJustify )
+ return " align=\"justify\"";
+ return TQString::null;
+}
+
+static TQString direction_to_string( int d )
+{
+ if ( d != TQChar::DirON )
+ return ( d == TQChar::DirL? " dir=\"ltr\"" : " dir=\"rtl\"" );
+ return TQString::null;
+}
+
+static TQString list_value_to_string( int v )
+{
+ if ( v != -1 )
+ return " listvalue=\"" + TQString::number( v ) + "\"";
+ return TQString::null;
+}
+
+static TQString list_style_to_string( int v )
+{
+ switch( v ) {
+ case TQStyleSheetItem::ListDecimal: return "\"1\"";
+ case TQStyleSheetItem::ListLowerAlpha: return "\"a\"";
+ case TQStyleSheetItem::ListUpperAlpha: return "\"A\"";
+ case TQStyleSheetItem::ListDisc: return "\"disc\"";
+ case TQStyleSheetItem::ListSquare: return "\"square\"";
+ case TQStyleSheetItem::ListCircle: return "\"circle\"";
+ default:
+ return TQString::null;
+ }
+}
+
+static inline bool list_is_ordered( int v )
+{
+ return v == TQStyleSheetItem::ListDecimal ||
+ v == TQStyleSheetItem::ListLowerAlpha ||
+ v == TQStyleSheetItem::ListUpperAlpha;
+}
+
+
+static TQString margin_to_string( TQStyleSheetItem* style, int t, int b, int l, int r, int fl )
+{
+ TQString s;
+ if ( l > 0 )
+ s += TQString(!!s?";":"") + "margin-left:" + TQString::number(l+TQMAX(0,style->margin(TQStyleSheetItem::MarginLeft))) + "px";
+ if ( r > 0 )
+ s += TQString(!!s?";":"") + "margin-right:" + TQString::number(r+TQMAX(0,style->margin(TQStyleSheetItem::MarginRight))) + "px";
+ if ( t > 0 )
+ s += TQString(!!s?";":"") + "margin-top:" + TQString::number(t+TQMAX(0,style->margin(TQStyleSheetItem::MarginTop))) + "px";
+ if ( b > 0 )
+ s += TQString(!!s?";":"") + "margin-bottom:" + TQString::number(b+TQMAX(0,style->margin(TQStyleSheetItem::MarginBottom))) + "px";
+ if ( fl > 0 )
+ s += TQString(!!s?";":"") + "text-indent:" + TQString::number(fl+TQMAX(0,style->margin(TQStyleSheetItem::MarginFirstLine))) + "px";
+ if ( !!s )
+ return " style=\"" + s + "\"";
+ return TQString::null;
+}
+
+TQString TQTextDocument::richText() const
+{
+ TQString s = "";
+ if ( !par ) {
+ s += "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:" ;
+ s += TQString::number( formatCollection()->defaultFormat()->font().pointSize() );
+ s += "pt;font-family:";
+ s += formatCollection()->defaultFormat()->font().family();
+ s +="\">";
+ }
+ TQTextParagraph* p = fParag;
+
+ TQStyleSheetItem* item_p = styleSheet()->item("p");
+ TQStyleSheetItem* item_div = styleSheet()->item("div");
+ TQStyleSheetItem* item_ul = styleSheet()->item("ul");
+ TQStyleSheetItem* item_ol = styleSheet()->item("ol");
+ TQStyleSheetItem* item_li = styleSheet()->item("li");
+ if ( !item_p || !item_div || !item_ul || !item_ol || !item_li ) {
+ qWarning( "TQTextEdit: cannot export HTML due to insufficient stylesheet (lack of p, div, ul, ol, or li)" );
+ return TQString::null;
+ }
+ int pastListDepth = 0;
+ int listDepth = 0;
+#if 0
+ int futureListDepth = 0;
+#endif
+ TQMemArray<int> listStyles(10);
+
+ while ( p ) {
+ listDepth = p->listDepth();
+ if ( listDepth < pastListDepth ) {
+ for ( int i = pastListDepth; i > listDepth; i-- )
+ s += list_is_ordered( listStyles[i] ) ? "</ol>" : "</ul>";
+ s += '\n';
+ } else if ( listDepth > pastListDepth ) {
+ s += '\n';
+ listStyles.resize( TQMAX( (int)listStyles.size(), listDepth+1 ) );
+ TQString list_type;
+ listStyles[listDepth] = p->listStyle();
+ if ( !list_is_ordered( p->listStyle() ) || item_ol->listStyle() != p->listStyle() )
+ list_type = " type=" + list_style_to_string( p->listStyle() );
+ for ( int i = pastListDepth; i < listDepth; i++ ) {
+ s += list_is_ordered( p->listStyle() ) ? "<ol" : "<ul" ;
+ s += list_type + ">";
+ }
+ } else {
+ s += '\n';
+ }
+
+ TQString ps = p->richText();
+
+#if 0
+ // for the bottom margin we need to know whether we are at the end of a list
+ futureListDepth = 0;
+ if ( listDepth > 0 && p->next() )
+ futureListDepth = p->next()->listDepth();
+#endif
+
+ if ( richTextExportStart && richTextExportStart->paragraph() ==p &&
+ richTextExportStart->index() == 0 )
+ s += "<!--StartFragment-->";
+
+ if ( p->isListItem() ) {
+ s += "<li";
+ if ( p->listStyle() != listStyles[listDepth] )
+ s += " type=" + list_style_to_string( p->listStyle() );
+ s +=align_to_string( p->tqalignment() );
+ s += margin_to_string( item_li, p->utm, p->ubm, p->ulm, p->urm, p->uflm );
+ s += list_value_to_string( p->listValue() );
+ s += direction_to_string( p->direction() );
+ s +=">";
+ s += ps;
+ s += "</li>";
+ } else if ( p->listDepth() ) {
+ s += "<div";
+ s += align_to_string( p->tqalignment() );
+ s += margin_to_string( item_div, p->utm, p->ubm, p->ulm, p->urm, p->uflm );
+ s +=direction_to_string( p->direction() );
+ s += ">";
+ s += ps;
+ s += "</div>";
+ } else {
+ // normal paragraph item
+ s += "<p";
+ s += align_to_string( p->tqalignment() );
+ s += margin_to_string( item_p, p->utm, p->ubm, p->ulm, p->urm, p->uflm );
+ s +=direction_to_string( p->direction() );
+ s += ">";
+ s += ps;
+ s += "</p>";
+ }
+ pastListDepth = listDepth;
+ p = p->next();
+ }
+ while ( listDepth > 0 ) {
+ s += list_is_ordered( listStyles[listDepth] ) ? "</ol>" : "</ul>";
+ listDepth--;
+ }
+
+ if ( !par )
+ s += "\n</body></html>\n";
+
+ return s;
+}
+
+TQString TQTextDocument::text() const
+{
+ if ( ((txtFormat == TQt::AutoText) && preferRichText) || (txtFormat == TQt::RichText) )
+ return richText();
+ return plainText();
+}
+
+TQString TQTextDocument::text( int parag ) const
+{
+ TQTextParagraph *p = paragAt( parag );
+ if ( !p )
+ return TQString::null;
+
+ if ( ((txtFormat == TQt::AutoText) && preferRichText) || (txtFormat == TQt::RichText) )
+ return p->richText();
+ else
+ return p->string()->toString();
+}
+
+void TQTextDocument::tqinvalidate()
+{
+ TQTextParagraph *s = fParag;
+ while ( s ) {
+ s->tqinvalidate( 0 );
+ s = s->next();
+ }
+}
+
+void TQTextDocument::selectionStart( int id, int &paragId, int &index )
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return;
+ TQTextDocumentSelection &sel = *it;
+ paragId = !sel.swapped ? sel.startCursor.paragraph()->paragId() : sel.endCursor.paragraph()->paragId();
+ index = !sel.swapped ? sel.startCursor.index() : sel.endCursor.index();
+}
+
+TQTextCursor TQTextDocument::selectionStartCursor( int id)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return TQTextCursor( this );
+ TQTextDocumentSelection &sel = *it;
+ if ( sel.swapped )
+ return sel.endCursor;
+ return sel.startCursor;
+}
+
+TQTextCursor TQTextDocument::selectionEndCursor( int id)
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return TQTextCursor( this );
+ TQTextDocumentSelection &sel = *it;
+ if ( !sel.swapped )
+ return sel.endCursor;
+ return sel.startCursor;
+}
+
+void TQTextDocument::selectionEnd( int id, int &paragId, int &index )
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return;
+ TQTextDocumentSelection &sel = *it;
+ paragId = sel.swapped ? sel.startCursor.paragraph()->paragId() : sel.endCursor.paragraph()->paragId();
+ index = sel.swapped ? sel.startCursor.index() : sel.endCursor.index();
+}
+
+void TQTextDocument::addSelection( int id )
+{
+ nSelections = TQMAX( nSelections, id + 1 );
+}
+
+static void setSelectionEndHelper( int id, TQTextDocumentSelection &sel, TQTextCursor &start, TQTextCursor &end )
+{
+ TQTextCursor c1 = start;
+ TQTextCursor c2 = end;
+ if ( sel.swapped ) {
+ c1 = end;
+ c2 = start;
+ }
+
+ c1.paragraph()->removeSelection( id );
+ c2.paragraph()->removeSelection( id );
+ if ( c1.paragraph() != c2.paragraph() ) {
+ c1.paragraph()->setSelection( id, c1.index(), c1.paragraph()->length() - 1 );
+ c2.paragraph()->setSelection( id, 0, c2.index() );
+ } else {
+ c1.paragraph()->setSelection( id, TQMIN( c1.index(), c2.index() ), TQMAX( c1.index(), c2.index() ) );
+ }
+
+ sel.startCursor = start;
+ sel.endCursor = end;
+ if ( sel.startCursor.paragraph() == sel.endCursor.paragraph() )
+ sel.swapped = sel.startCursor.index() > sel.endCursor.index();
+}
+
+bool TQTextDocument::setSelectionEnd( int id, const TQTextCursor &cursor )
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return FALSE;
+ TQTextDocumentSelection &sel = *it;
+
+ TQTextCursor start = sel.startCursor;
+ TQTextCursor end = cursor;
+
+ if ( start == end ) {
+ removeSelection( id );
+ setSelectionStart( id, cursor );
+ return TRUE;
+ }
+
+ if ( sel.endCursor.paragraph() == end.paragraph() ) {
+ setSelectionEndHelper( id, sel, start, end );
+ return TRUE;
+ }
+
+ bool inSelection = FALSE;
+ TQTextCursor c( this );
+ TQTextCursor tmp = sel.startCursor;
+ if ( sel.swapped )
+ tmp = sel.endCursor;
+ tmp.restoreState();
+ TQTextCursor tmp2 = cursor;
+ tmp2.restoreState();
+ c.setParagraph( tmp.paragraph()->paragId() < tmp2.paragraph()->paragId() ? tmp.paragraph() : tmp2.paragraph() );
+ bool hadStart = FALSE;
+ bool hadEnd = FALSE;
+ bool hadStartParag = FALSE;
+ bool hadEndParag = FALSE;
+ bool hadOldStart = FALSE;
+ bool hadOldEnd = FALSE;
+ bool leftSelection = FALSE;
+ sel.swapped = FALSE;
+ for ( ;; ) {
+ if ( c == start )
+ hadStart = TRUE;
+ if ( c == end )
+ hadEnd = TRUE;
+ if ( c.paragraph() == start.paragraph() )
+ hadStartParag = TRUE;
+ if ( c.paragraph() == end.paragraph() )
+ hadEndParag = TRUE;
+ if ( c == sel.startCursor )
+ hadOldStart = TRUE;
+ if ( c == sel.endCursor )
+ hadOldEnd = TRUE;
+
+ if ( !sel.swapped &&
+ ( (hadEnd && !hadStart) ||
+ (hadEnd && hadStart && (start.paragraph() == end.paragraph()) && start.index() > end.index()) ) )
+ sel.swapped = TRUE;
+
+ if ( ((c == end) && hadStartParag) ||
+ ((c == start) && hadEndParag )) {
+ TQTextCursor tmp = c;
+ tmp.restoreState();
+ if ( tmp.paragraph() != c.paragraph() ) {
+ int sstart = tmp.paragraph()->selectionStart( id );
+ tmp.paragraph()->removeSelection( id );
+ tmp.paragraph()->setSelection( id, sstart, tmp.index() );
+ }
+ }
+
+ if ( inSelection &&
+ ( ((c == end) && hadStart) || ((c == start) && hadEnd) ) )
+ leftSelection = TRUE;
+ else if ( !leftSelection && !inSelection && ( hadStart || hadEnd ) )
+ inSelection = TRUE;
+
+ bool noSelectionAnymore = hadOldStart && hadOldEnd && leftSelection && !inSelection && !c.paragraph()->hasSelection( id ) && c.atParagEnd();
+ c.paragraph()->removeSelection( id );
+ if ( inSelection ) {
+ if ( c.paragraph() == start.paragraph() && start.paragraph() == end.paragraph() ) {
+ c.paragraph()->setSelection( id, TQMIN( start.index(), end.index() ), TQMAX( start.index(), end.index() ) );
+ } else if ( c.paragraph() == start.paragraph() && !hadEndParag ) {
+ c.paragraph()->setSelection( id, start.index(), c.paragraph()->length() - 1 );
+ } else if ( c.paragraph() == end.paragraph() && !hadStartParag ) {
+ c.paragraph()->setSelection( id, end.index(), c.paragraph()->length() - 1 );
+ } else if ( c.paragraph() == end.paragraph() && hadEndParag ) {
+ c.paragraph()->setSelection( id, 0, end.index() );
+ } else if ( c.paragraph() == start.paragraph() && hadStartParag ) {
+ c.paragraph()->setSelection( id, 0, start.index() );
+ } else {
+ c.paragraph()->setSelection( id, 0, c.paragraph()->length() - 1 );
+ }
+ }
+
+ if ( leftSelection )
+ inSelection = FALSE;
+
+ if ( noSelectionAnymore )
+ break;
+ // *ugle*hack optimization
+ TQTextParagraph *p = c.paragraph();
+ if ( p->mightHaveCustomItems || p == start.paragraph() || p == end.paragraph() || p == lastParagraph() ) {
+ c.gotoNextLetter();
+ if ( p == lastParagraph() && c.atParagEnd() )
+ break;
+ } else {
+ if ( p->document()->tqparent() )
+ do {
+ c.gotoNextLetter();
+ } while ( c.paragraph() == p );
+ else
+ c.setParagraph( p->next() );
+ }
+ }
+
+ if ( !sel.swapped )
+ sel.startCursor.paragraph()->setSelection( id, sel.startCursor.index(), sel.startCursor.paragraph()->length() - 1 );
+
+ sel.startCursor = start;
+ sel.endCursor = end;
+ if ( sel.startCursor.paragraph() == sel.endCursor.paragraph() )
+ sel.swapped = sel.startCursor.index() > sel.endCursor.index();
+
+ setSelectionEndHelper( id, sel, start, end );
+
+ return TRUE;
+}
+
+void TQTextDocument::selectAll( int id )
+{
+ removeSelection( id );
+
+ TQTextDocumentSelection sel;
+ sel.swapped = FALSE;
+ TQTextCursor c( this );
+
+ c.setParagraph( fParag );
+ c.setIndex( 0 );
+ sel.startCursor = c;
+
+ c.setParagraph( lParag );
+ c.setIndex( lParag->length() - 1 );
+ sel.endCursor = c;
+
+ selections.insert( id, sel );
+
+ TQTextParagraph *p = fParag;
+ while ( p ) {
+ p->setSelection( id, 0, p->length() - 1 );
+ p = p->next();
+ }
+
+ for ( TQTextDocument *d = childList.first(); d; d = childList.next() )
+ d->selectAll( id );
+}
+
+bool TQTextDocument::removeSelection( int id )
+{
+ if ( !selections.tqcontains( id ) )
+ return FALSE;
+
+ TQTextDocumentSelection &sel = selections[ id ];
+
+ TQTextCursor start = sel.swapped ? sel.endCursor : sel.startCursor;
+ TQTextCursor end = sel.swapped ? sel.startCursor : sel.endCursor;
+ TQTextParagraph* p = 0;
+ while ( start != end ) {
+ if ( p != start.paragraph() ) {
+ p = start.paragraph();
+ p->removeSelection( id );
+ //### avoid endless loop by all means necessary, did somebody mention refactoring?
+ if ( !tqparent() && p == lParag )
+ break;
+ }
+ start.gotoNextLetter();
+ }
+ p = start.paragraph();
+ p->removeSelection( id );
+ selections.remove( id );
+ return TRUE;
+}
+
+TQString TQTextDocument::selectedText( int id, bool asRichText ) const
+{
+ QMap<int, TQTextDocumentSelection>::ConstIterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return TQString::null;
+
+ TQTextDocumentSelection sel = *it;
+
+
+ TQTextCursor c1 = sel.startCursor;
+ TQTextCursor c2 = sel.endCursor;
+ if ( sel.swapped ) {
+ c2 = sel.startCursor;
+ c1 = sel.endCursor;
+ }
+
+ /* 3.0.3 improvement: Make it possible to get a reasonable
+ selection inside a table. This approach is very conservative:
+ make sure that both cursors have the same depth level and point
+ to paragraphs within the same text document.
+
+ Meaning if you select text in two table cells, you will get the
+ entire table. This is still far better than the 3.0.2, where
+ you always got the entire table.
+
+ ### Fix this properly when refactoring
+ */
+ while ( c2.nestedDepth() > c1.nestedDepth() )
+ c2.oneUp();
+ while ( c1.nestedDepth() > c2.nestedDepth() )
+ c1.oneUp();
+ while ( c1.nestedDepth() && c2.nestedDepth() &&
+ c1.paragraph()->document() != c2.paragraph()->document() ) {
+ c1.oneUp();
+ c2.oneUp();
+ }
+ // do not trust sel_swapped with tables. Fix this properly when refactoring as well
+ if ( c1.paragraph()->paragId() > c2.paragraph()->paragId() ||
+ (c1.paragraph() == c2.paragraph() && c1.index() > c2.index() ) ) {
+ TQTextCursor tmp = c1;
+ c2 = c1;
+ c1 = tmp;
+ }
+
+ // end selection 3.0.3 improvement
+
+ if ( asRichText && !tqparent() ) {
+ richTextExportStart = &c1;
+ richTextExportEnd = &c2;
+
+ TQString sel = richText();
+ int from = sel.tqfind( "<!--StartFragment-->" );
+ if ( from >= 0 ) {
+ from += 20;
+ // tqfind the previous span and move it into the start fragment before we clip it
+ TQString prevspan;
+ int pspan = sel.tqfindRev( "<span", from-21 );
+ if ( pspan > sel.tqfindRev( "</span", from-21 ) ) {
+ int spanend = sel.tqfind( '>', pspan );
+ prevspan = sel.mid( pspan, spanend - pspan + 1 );
+ }
+ int to = sel.tqfindRev( "<!--EndFragment-->" );
+ if ( from <= to )
+ sel = "<!--StartFragment-->" + prevspan + sel.mid( from, to - from );
+ }
+ richTextExportStart = richTextExportEnd = 0;
+ return sel;
+ }
+
+ TQString s;
+ if ( c1.paragraph() == c2.paragraph() ) {
+ TQTextParagraph *p = c1.paragraph();
+ int end = c2.index();
+ if ( p->at( TQMAX( 0, end - 1 ) )->isCustom() )
+ ++end;
+ if ( !p->mightHaveCustomItems ) {
+ s += p->string()->toString().mid( c1.index(), end - c1.index() );
+ } else {
+ for ( int i = c1.index(); i < end; ++i ) {
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( p->at( i )->isCustom() ) {
+ if ( p->at( i )->customItem()->isNested() ) {
+ s += "\n";
+ TQTextTable *t = (TQTextTable*)p->at( i )->customItem();
+ TQPtrList<TQTextTableCell> cells = t->tableCells();
+ for ( TQTextTableCell *c = cells.first(); c; c = cells.next() )
+ s += c->richText()->plainText() + "\n";
+ s += "\n";
+ }
+ } else
+#endif
+ {
+ s += p->at( i )->c;
+ }
+ }
+ }
+ } else {
+ TQTextParagraph *p = c1.paragraph();
+ int start = c1.index();
+ while ( p ) {
+ int end = p == c2.paragraph() ? c2.index() : p->length() - 1;
+ if ( p == c2.paragraph() && p->at( TQMAX( 0, end - 1 ) )->isCustom() )
+ ++end;
+ if ( !p->mightHaveCustomItems ) {
+ s += p->string()->toString().mid( start, end - start );
+ if ( p != c2.paragraph() )
+ s += "\n";
+ } else {
+ for ( int i = start; i < end; ++i ) {
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( p->at( i )->isCustom() ) {
+ if ( p->at( i )->customItem()->isNested() ) {
+ s += "\n";
+ TQTextTable *t = (TQTextTable*)p->at( i )->customItem();
+ TQPtrList<TQTextTableCell> cells = t->tableCells();
+ for ( TQTextTableCell *c = cells.first(); c; c = cells.next() )
+ s += c->richText()->plainText() + "\n";
+ s += "\n";
+ }
+ } else
+#endif
+ {
+ s += p->at( i )->c;
+ }
+ }
+ }
+ start = 0;
+ if ( p == c2.paragraph() )
+ break;
+ p = p->next();
+ }
+ }
+ // ### workaround for plain text export until we get proper
+ // mime types: turn tqunicode line seperators into the more
+ // widely understood \n. Makes copy and pasting code snipplets
+ // from within Assistent possible
+ TQChar* uc = (TQChar*) s.tqunicode();
+ for ( int ii = 0; ii < s.length(); ii++ ) {
+ if ( uc[(int)ii] == TQChar_linesep )
+ uc[(int)ii] = TQChar('\n');
+ else if ( uc[(int)ii] == TQChar::nbsp )
+ uc[(int)ii] = TQChar(' ');
+ }
+ return s;
+}
+
+void TQTextDocument::setFormat( int id, TQTextFormat *f, int flags )
+{
+ QMap<int, TQTextDocumentSelection>::ConstIterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return;
+
+ TQTextDocumentSelection sel = *it;
+
+ TQTextCursor c1 = sel.startCursor;
+ TQTextCursor c2 = sel.endCursor;
+ if ( sel.swapped ) {
+ c2 = sel.startCursor;
+ c1 = sel.endCursor;
+ }
+
+ c2.restoreState();
+ c1.restoreState();
+
+ if ( c1.paragraph() == c2.paragraph() ) {
+ c1.paragraph()->setFormat( c1.index(), c2.index() - c1.index(), f, TRUE, flags );
+ return;
+ }
+
+ c1.paragraph()->setFormat( c1.index(), c1.paragraph()->length() - c1.index(), f, TRUE, flags );
+ TQTextParagraph *p = c1.paragraph()->next();
+ while ( p && p != c2.paragraph() ) {
+ p->setFormat( 0, p->length(), f, TRUE, flags );
+ p = p->next();
+ }
+ c2.paragraph()->setFormat( 0, c2.index(), f, TRUE, flags );
+}
+
+void TQTextDocument::removeSelectedText( int id, TQTextCursor *cursor )
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return;
+
+ TQTextDocumentSelection sel = *it;
+ TQTextCursor c1 = sel.startCursor;
+ TQTextCursor c2 = sel.endCursor;
+ if ( sel.swapped ) {
+ c2 = sel.startCursor;
+ c1 = sel.endCursor;
+ }
+
+ // ### no support for editing tables yet
+ if ( c1.nestedDepth() || c2.nestedDepth() )
+ return;
+
+ c2.restoreState();
+ c1.restoreState();
+
+ *cursor = c1;
+ removeSelection( id );
+
+ if ( c1.paragraph() == c2.paragraph() ) {
+ c1.paragraph()->remove( c1.index(), c2.index() - c1.index() );
+ return;
+ }
+
+ if ( c1.paragraph() == fParag && c1.index() == 0 &&
+ c2.paragraph() == lParag && c2.index() == lParag->length() - 1 )
+ cursor->setValid( FALSE );
+
+ bool didGoLeft = FALSE;
+ if ( c1.index() == 0 && c1.paragraph() != fParag ) {
+ cursor->gotoPreviousLetter();
+ didGoLeft = cursor->isValid();
+ }
+
+ c1.paragraph()->remove( c1.index(), c1.paragraph()->length() - 1 - c1.index() );
+ TQTextParagraph *p = c1.paragraph()->next();
+ int dy = 0;
+ TQTextParagraph *tmp;
+ while ( p && p != c2.paragraph() ) {
+ tmp = p->next();
+ dy -= p->rect().height();
+ delete p;
+ p = tmp;
+ }
+ c2.paragraph()->remove( 0, c2.index() );
+ while ( p ) {
+ p->move( dy );
+ p->tqinvalidate( 0 );
+ p->setEndState( -1 );
+ p = p->next();
+ }
+
+
+ c1.paragraph()->join( c2.paragraph() );
+
+ if ( didGoLeft )
+ cursor->gotoNextLetter();
+}
+
+void TQTextDocument::indentSelection( int id )
+{
+ QMap<int, TQTextDocumentSelection>::Iterator it = selections.tqfind( id );
+ if ( it == selections.end() )
+ return;
+
+ TQTextDocumentSelection sel = *it;
+ TQTextParagraph *startParag = sel.startCursor.paragraph();
+ TQTextParagraph *endParag = sel.endCursor.paragraph();
+ if ( sel.endCursor.paragraph()->paragId() < sel.startCursor.paragraph()->paragId() ) {
+ endParag = sel.startCursor.paragraph();
+ startParag = sel.endCursor.paragraph();
+ }
+
+ TQTextParagraph *p = startParag;
+ while ( p && p != endParag ) {
+ p->indent();
+ p = p->next();
+ }
+}
+
+void TQTextDocument::addCommand( TQTextCommand *cmd )
+{
+ commandHistory->addCommand( cmd );
+}
+
+TQTextCursor *TQTextDocument::undo( TQTextCursor *c )
+{
+ return commandHistory->undo( c );
+}
+
+TQTextCursor *TQTextDocument::redo( TQTextCursor *c )
+{
+ return commandHistory->redo( c );
+}
+
+bool TQTextDocument::tqfind( TQTextCursor& cursor, const TQString &expr, bool cs, bool wo, bool forward )
+{
+ removeSelection( Standard );
+ TQTextParagraph *p = 0;
+ if ( expr.isEmpty() )
+ return FALSE;
+ for (;;) {
+ if ( p != cursor.paragraph() ) {
+ p = cursor.paragraph();
+ TQString s = cursor.paragraph()->string()->toString();
+ int start = cursor.index();
+ for ( ;; ) {
+ int res = forward ? s.tqfind( expr, start, cs ) : s.tqfindRev( expr, start, cs );
+ int end = res + expr.length();
+ if ( res == -1 || ( !forward && start <= res ) )
+ break;
+ if ( !wo || ( ( res == 0 || s[ res - 1 ].isSpace() || s[ res - 1 ].isPunct() ) &&
+ ( end == (int)s.length() || s[ end ].isSpace() || s[ end ].isPunct() ) ) ) {
+ removeSelection( Standard );
+ cursor.setIndex( forward ? end : res );
+ setSelectionStart( Standard, cursor );
+ cursor.setIndex( forward ? res : end );
+ setSelectionEnd( Standard, cursor );
+ if ( !forward )
+ cursor.setIndex( res );
+ return TRUE;
+ }
+ start = res + (forward ? 1 : -1);
+ }
+ }
+ if ( forward ) {
+ if ( cursor.paragraph() == lastParagraph() && cursor.atParagEnd() )
+ break;
+ cursor.gotoNextLetter();
+ } else {
+ if ( cursor.paragraph() == firstParagraph() && cursor.atParagStart() )
+ break;
+ cursor.gotoPreviousLetter();
+ }
+ }
+ return FALSE;
+}
+
+void TQTextDocument::setTextFormat( TQt::TextFormat f )
+{
+ txtFormat = f;
+ if ( fParag == lParag && fParag->length() <= 1 )
+ fParag->rtext = ( f == TQt::RichText );
+}
+
+TQt::TextFormat TQTextDocument::textFormat() const
+{
+ return txtFormat;
+}
+
+bool TQTextDocument::inSelection( int selId, const TQPoint &pos ) const
+{
+ QMap<int, TQTextDocumentSelection>::ConstIterator it = selections.tqfind( selId );
+ if ( it == selections.end() )
+ return FALSE;
+
+ TQTextDocumentSelection sel = *it;
+ TQTextParagraph *startParag = sel.startCursor.paragraph();
+ TQTextParagraph *endParag = sel.endCursor.paragraph();
+ if ( sel.startCursor.paragraph() == sel.endCursor.paragraph() &&
+ sel.startCursor.paragraph()->selectionStart( selId ) == sel.endCursor.paragraph()->selectionEnd( selId ) )
+ return FALSE;
+ if ( sel.endCursor.paragraph()->paragId() < sel.startCursor.paragraph()->paragId() ) {
+ endParag = sel.startCursor.paragraph();
+ startParag = sel.endCursor.paragraph();
+ }
+
+ TQTextParagraph *p = startParag;
+ while ( p ) {
+ if ( p->rect().tqcontains( pos ) ) {
+ bool inSel = FALSE;
+ int selStart = p->selectionStart( selId );
+ int selEnd = p->selectionEnd( selId );
+ int y = 0;
+ int h = 0;
+ for ( int i = 0; i < p->length(); ++i ) {
+ if ( i == selStart )
+ inSel = TRUE;
+ if ( i == selEnd )
+ break;
+ if ( p->at( i )->lineStart ) {
+ y = (*p->lineStarts.tqfind( i ))->y;
+ h = (*p->lineStarts.tqfind( i ))->h;
+ }
+ if ( pos.y() - p->rect().y() >= y && pos.y() - p->rect().y() <= y + h ) {
+ if ( inSel && pos.x() >= p->at( i )->x &&
+ pos.x() <= p->at( i )->x + p->at( i )->format()->width( p->at( i )->c ) )
+ return TRUE;
+ }
+ }
+ }
+ if ( pos.y() < p->rect().y() )
+ break;
+ if ( p == endParag )
+ break;
+ p = p->next();
+ }
+
+ return FALSE;
+}
+
+void TQTextDocument::doLayout( TQPainter *p, int w )
+{
+ minw = wused = 0;
+ if ( !is_printer( p ) )
+ p = 0;
+ withoutDoubleBuffer = ( p != 0 );
+ TQPainter * oldPainter = TQTextFormat::painter();
+ TQTextFormat::setPainter( p );
+ tStopWidth = formatCollection()->defaultFormat()->width( 'x' ) * 8;
+ flow_->setWidth( w );
+ cw = w;
+ vw = w;
+ TQTextParagraph *parag = fParag;
+ while ( parag ) {
+ parag->tqinvalidate( 0 );
+ if ( p )
+ parag->adjustToPainter( p );
+ parag->format();
+ parag = parag->next();
+ }
+ TQTextFormat::setPainter( oldPainter );
+}
+
+TQPixmap *TQTextDocument::bufferPixmap( const TQSize &s )
+{
+ if ( !buf_pixmap )
+ buf_pixmap = new TQPixmap( s.expandedTo( TQSize(1,1) ) );
+ else if ( buf_pixmap->size() != s )
+ buf_pixmap->resize( s.expandedTo( buf_pixmap->size() ) );
+ return buf_pixmap;
+}
+
+void TQTextDocument::draw( TQPainter *p, const TQRect &rect, const TQColorGroup &cg, const TQBrush *paper )
+{
+ if ( !firstParagraph() )
+ return;
+
+ if ( paper ) {
+ p->setBrushOrigin( -int( p->translationX() ),
+ -int( p->translationY() ) );
+
+ p->fillRect( rect, *paper );
+ }
+
+ TQPainter * oldPainter = TQTextFormat::painter();
+ TQTextFormat::setPainter( p );
+
+ if ( formatCollection()->defaultFormat()->color() != cg.text() )
+ setDefaultFormat( formatCollection()->defaultFormat()->font(), cg.text() );
+
+ TQTextParagraph *parag = firstParagraph();
+ while ( parag ) {
+ if ( !parag->isValid() )
+ parag->format();
+ int y = parag->rect().y();
+ TQRect pr( parag->rect() );
+ pr.setX( 0 );
+ pr.setWidth( TQWIDGETSIZE_MAX );
+ if ( !rect.isNull() && !rect.intersects( pr ) ) {
+ parag = parag->next();
+ continue;
+ }
+ p->translate( 0, y );
+ if ( rect.isValid() )
+ parag->paint( *p, cg, 0, FALSE, rect.x(), rect.y(), rect.width(), rect.height() );
+ else
+ parag->paint( *p, cg, 0, FALSE );
+ p->translate( 0, -y );
+ parag = parag->next();
+ if ( !flow()->isEmpty() )
+ flow()->drawFloatingItems( p, rect.x(), rect.y(), rect.width(), rect.height(), cg, FALSE );
+ }
+ TQTextFormat::setPainter(oldPainter);
+}
+
+void TQTextDocument::drawParagraph( TQPainter *p, TQTextParagraph *parag, int cx, int cy, int cw, int ch,
+ TQPixmap *&doubleBuffer, const TQColorGroup &cg,
+ bool drawCursor, TQTextCursor *cursor, bool resetChanged )
+{
+ TQPainter *painter = 0;
+ if ( resetChanged )
+ parag->setChanged( FALSE );
+ TQRect ir( parag->rect() );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if (!parag->tableCell())
+#endif
+ ir.setWidth(width());
+
+ bool uDoubleBuffer = useDoubleBuffer( parag, p );
+
+ if ( uDoubleBuffer ) {
+ painter = new TQPainter;
+ if ( cx >= 0 && cy >= 0 )
+ ir = ir.intersect( TQRect( cx, cy, cw, ch ) );
+ if ( !doubleBuffer ||
+ ir.width() > doubleBuffer->width() ||
+ ir.height() > doubleBuffer->height() ) {
+ doubleBuffer = bufferPixmap( ir.size() );
+ painter->begin( doubleBuffer );
+ } else {
+ painter->begin( doubleBuffer );
+ }
+ } else {
+ painter = p;
+ painter->translate( ir.x(), ir.y() );
+ }
+
+ painter->setBrushOrigin( -ir.x(), -ir.y() );
+
+ if ( uDoubleBuffer || is_printer( painter ) )
+ painter->fillRect( TQRect( 0, 0, ir.width(), ir.height() ), parag->backgroundBrush( cg ) );
+ else if ( cursor && cursor->paragraph() == parag )
+ painter->fillRect( TQRect( parag->at( cursor->index() )->x, 0, 2, ir.height() ),
+ parag->backgroundBrush( cg ) );
+
+ painter->translate( -( ir.x() - parag->rect().x() ),
+ -( ir.y() - parag->rect().y() ) );
+ parag->paint( *painter, cg, drawCursor ? cursor : 0, TRUE, cx, cy, cw, ch );
+
+ if ( uDoubleBuffer ) {
+ delete painter;
+ painter = 0;
+ p->drawPixmap( ir.topLeft(), *doubleBuffer, TQRect( TQPoint( 0, 0 ), ir.size() ) );
+ } else {
+ painter->translate( -ir.x(), -ir.y() );
+ }
+
+ parag->document()->nextDoubleBuffered = FALSE;
+}
+
+TQTextParagraph *TQTextDocument::draw( TQPainter *p, int cx, int cy, int cw, int ch, const TQColorGroup &cg,
+ bool onlyChanged, bool drawCursor, TQTextCursor *cursor, bool resetChanged )
+{
+ if ( withoutDoubleBuffer || (par && par->withoutDoubleBuffer) ) {
+ withoutDoubleBuffer = TRUE;
+ TQRect r;
+ draw( p, r, cg );
+ return 0;
+ }
+ withoutDoubleBuffer = FALSE;
+
+ if ( !firstParagraph() )
+ return 0;
+
+ TQPainter * oldPainter = TQTextFormat::painter();
+ TQTextFormat::setPainter( p );
+ if ( formatCollection()->defaultFormat()->color() != cg.text() )
+ setDefaultFormat( formatCollection()->defaultFormat()->font(), cg.text() );
+
+ if ( cx < 0 && cy < 0 ) {
+ cx = 0;
+ cy = 0;
+ cw = width();
+ ch = height();
+ }
+
+ TQTextParagraph *lastFormatted = 0;
+ TQTextParagraph *parag = firstParagraph();
+
+ TQPixmap *doubleBuffer = 0;
+
+ while ( parag ) {
+ lastFormatted = parag;
+ if ( !parag->isValid() )
+ parag->format();
+
+ TQRect pr = parag->rect();
+ pr.setWidth( parag->document()->width() );
+ if ( pr.y() > cy + ch )
+ goto floating;
+ TQRect clipr( cx, cy, cw, ch );
+ if ( !pr.intersects( clipr ) || ( onlyChanged && !parag->hasChanged() ) ) {
+ pr.setWidth( parag->document()->width() );
+ parag = parag->next();
+ continue;
+ }
+
+ drawParagraph( p, parag, cx, cy, cw, ch, doubleBuffer, cg, drawCursor, cursor, resetChanged );
+ parag = parag->next();
+ }
+
+ parag = lastParagraph();
+
+ floating:
+ if ( parag->rect().y() + parag->rect().height() < parag->document()->height() ) {
+ if ( !parag->document()->tqparent() ) {
+ TQRect fillRect = TQRect( 0, parag->rect().y() + parag->rect().height(), parag->document()->width(),
+ parag->document()->height() - ( parag->rect().y() + parag->rect().height() ) );
+ if ( TQRect( cx, cy, cw, ch ).intersects( fillRect ) )
+ p->fillRect( fillRect, cg.brush( TQColorGroup::Base ) );
+ }
+ if ( !flow()->isEmpty() ) {
+ TQRect cr( cx, cy, cw, ch );
+ flow()->drawFloatingItems( p, cr.x(), cr.y(), cr.width(), cr.height(), cg, FALSE );
+ }
+ }
+
+ if ( buf_pixmap && buf_pixmap->height() > 300 ) {
+ delete buf_pixmap;
+ buf_pixmap = 0;
+ }
+
+ TQTextFormat::setPainter(oldPainter);
+ return lastFormatted;
+}
+
+/*
+ #### this function only sets the default font size in the format collection
+ */
+void TQTextDocument::setDefaultFormat( const TQFont &font, const TQColor &color )
+{
+ bool reformat = font != fCollection->defaultFormat()->font();
+ for ( TQTextDocument *d = childList.first(); d; d = childList.next() )
+ d->setDefaultFormat( font, color );
+ fCollection->updateDefaultFormat( font, color, sheet_ );
+
+ if ( !reformat )
+ return;
+ tStopWidth = formatCollection()->defaultFormat()->width( 'x' ) * 8;
+
+ // tqinvalidate paragraphs and custom items
+ TQTextParagraph *p = fParag;
+ while ( p ) {
+ p->tqinvalidate( 0 );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ for ( int i = 0; i < p->length() - 1; ++i )
+ if ( p->at( i )->isCustom() )
+ p->at( i )->customItem()->tqinvalidate();
+#endif
+ p = p->next();
+ }
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+void TQTextDocument::registerCustomItem( TQTextCustomItem *i, TQTextParagraph *p )
+{
+ if ( i && i->placement() != TQTextCustomItem::PlaceInline ) {
+ flow_->registerFloatingItem( i );
+ p->registerFloatingItem( i );
+ }
+ if (i) i->setParagraph( p );
+ p->mightHaveCustomItems = mightHaveCustomItems = TRUE;
+}
+
+void TQTextDocument::unregisterCustomItem( TQTextCustomItem *i, TQTextParagraph *p )
+{
+ p->unregisterFloatingItem( i );
+ i->setParagraph( 0 );
+ flow_->unregisterFloatingItem( i );
+}
+#endif
+
+bool TQTextDocument::hasFocusParagraph() const
+{
+ return !!focusIndicator.parag;
+}
+
+TQString TQTextDocument::focusHref() const
+{
+ return focusIndicator.href;
+}
+
+TQString TQTextDocument::focusName() const
+{
+ return focusIndicator.name;
+}
+
+bool TQTextDocument::focusNextPrevChild( bool next )
+{
+ if ( !focusIndicator.parag ) {
+ if ( next ) {
+ focusIndicator.parag = fParag;
+ focusIndicator.start = 0;
+ focusIndicator.len = 0;
+ } else {
+ focusIndicator.parag = lParag;
+ focusIndicator.start = lParag->length();
+ focusIndicator.len = 0;
+ }
+ } else {
+ focusIndicator.parag->setChanged( TRUE );
+ }
+ focusIndicator.href = TQString::null;
+ focusIndicator.name = TQString::null;
+
+ if ( next ) {
+ TQTextParagraph *p = focusIndicator.parag;
+ int index = focusIndicator.start + focusIndicator.len;
+ while ( p ) {
+ for ( int i = index; i < p->length(); ++i ) {
+ if ( p->at( i )->isAnchor() ) {
+ p->setChanged( TRUE );
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = p->at( i )->anchorHref();
+ focusIndicator.name = p->at( i )->anchorName();
+ while ( i < p->length() ) {
+ if ( !p->at( i )->isAnchor() )
+ return TRUE;
+ focusIndicator.len++;
+ i++;
+ }
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ } else if ( p->at( i )->isCustom() ) {
+ if ( p->at( i )->customItem()->isNested() ) {
+ TQTextTable *t = (TQTextTable*)p->at( i )->customItem();
+ TQPtrList<TQTextTableCell> cells = t->tableCells();
+ // first try to continue
+ TQTextTableCell *c;
+ bool resetCells = TRUE;
+ for ( c = cells.first(); c; c = cells.next() ) {
+ if ( c->richText()->hasFocusParagraph() ) {
+ if ( c->richText()->focusNextPrevChild( next ) ) {
+ p->setChanged( TRUE );
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return TRUE;
+ } else {
+ resetCells = FALSE;
+ c = cells.next();
+ break;
+ }
+ }
+ }
+ // now really try
+ if ( resetCells )
+ c = cells.first();
+ for ( ; c; c = cells.next() ) {
+ if ( c->richText()->focusNextPrevChild( next ) ) {
+ p->setChanged( TRUE );
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return TRUE;
+ }
+ }
+ }
+#endif
+ }
+ }
+ index = 0;
+ p = p->next();
+ }
+ } else {
+ TQTextParagraph *p = focusIndicator.parag;
+ int index = focusIndicator.start - 1;
+ if ( focusIndicator.len == 0 && index < focusIndicator.parag->length() - 1 )
+ index++;
+ while ( p ) {
+ for ( int i = index; i >= 0; --i ) {
+ if ( p->at( i )->isAnchor() ) {
+ p->setChanged( TRUE );
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = p->at( i )->anchorHref();
+ focusIndicator.name = p->at( i )->anchorName();
+ while ( i >= -1 ) {
+ if ( i < 0 || !p->at( i )->isAnchor() ) {
+ focusIndicator.start++;
+ return TRUE;
+ }
+ if ( i < 0 )
+ break;
+ focusIndicator.len++;
+ focusIndicator.start--;
+ i--;
+ }
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ } else if ( p->at( i )->isCustom() ) {
+ if ( p->at( i )->customItem()->isNested() ) {
+ TQTextTable *t = (TQTextTable*)p->at( i )->customItem();
+ TQPtrList<TQTextTableCell> cells = t->tableCells();
+ // first try to continue
+ TQTextTableCell *c;
+ bool resetCells = TRUE;
+ for ( c = cells.last(); c; c = cells.prev() ) {
+ if ( c->richText()->hasFocusParagraph() ) {
+ if ( c->richText()->focusNextPrevChild( next ) ) {
+ p->setChanged( TRUE );
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return TRUE;
+ } else {
+ resetCells = FALSE;
+ c = cells.prev();
+ break;
+ }
+ }
+ if ( cells.at() == 0 )
+ break;
+ }
+ // now really try
+ if ( resetCells )
+ c = cells.last();
+ for ( ; c; c = cells.prev() ) {
+ if ( c->richText()->focusNextPrevChild( next ) ) {
+ p->setChanged( TRUE );
+ focusIndicator.parag = p;
+ focusIndicator.start = i;
+ focusIndicator.len = 0;
+ focusIndicator.href = c->richText()->focusHref();
+ focusIndicator.name = c->richText()->focusName();
+ return TRUE;
+ }
+ if ( cells.at() == 0 )
+ break;
+ }
+ }
+#endif
+ }
+ }
+ p = p->prev();
+ if ( p )
+ index = p->length() - 1;
+ }
+ }
+
+ focusIndicator.parag = 0;
+
+ return FALSE;
+}
+
+int TQTextDocument::length() const
+{
+ int l = -1;
+ TQTextParagraph *p = fParag;
+ while ( p ) {
+ l += p->length();
+ p = p->next();
+ }
+ return TQMAX(0,l);
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+int TQTextFormat::width( const TQChar &c ) const
+{
+ if ( c.tqunicode() == 0xad ) // soft hyphen
+ return 0;
+ if ( !pntr || !pntr->isActive() ) {
+ if ( c == '\t' )
+ return fm.width( ' ' );
+ if ( ha == AlignNormal ) {
+ int w;
+ if ( c.row() )
+ w = fm.width( c );
+ else
+ w = widths[ c.tqunicode() ];
+ if ( w == 0 && !c.row() ) {
+ w = fm.width( c );
+ ( (TQTextFormat*)this )->widths[ c.tqunicode() ] = w;
+ }
+ return w;
+ } else {
+ TQFont f( fn );
+ if ( usePixelSizes )
+ f.setPixelSize( ( f.pixelSize() * 2 ) / 3 );
+ else
+ f.setPointSize( ( f.pointSize() * 2 ) / 3 );
+ TQFontMetrics fm_( f );
+ return fm_.width( c );
+ }
+ }
+
+ TQFont f( fn );
+ if ( ha != AlignNormal ) {
+ if ( usePixelSizes )
+ f.setPixelSize( ( f.pixelSize() * 2 ) / 3 );
+ else
+ f.setPointSize( ( f.pointSize() * 2 ) / 3 );
+ }
+ applyFont( f );
+
+ return pntr_fm->width( c );
+}
+
+int TQTextFormat::width( const TQString &str, int pos ) const
+{
+ int w = 0;
+ if ( str.tqunicode()[ pos ].tqunicode() == 0xad )
+ return w;
+ if ( !pntr || !pntr->isActive() ) {
+ if ( ha == AlignNormal ) {
+ w = fm.charWidth( str, pos );
+ } else {
+ TQFont f( fn );
+ if ( usePixelSizes )
+ f.setPixelSize( ( f.pixelSize() * 2 ) / 3 );
+ else
+ f.setPointSize( ( f.pointSize() * 2 ) / 3 );
+ TQFontMetrics fm_( f );
+ w = fm_.charWidth( str, pos );
+ }
+ } else {
+ TQFont f( fn );
+ if ( ha != AlignNormal ) {
+ if ( usePixelSizes )
+ f.setPixelSize( ( f.pixelSize() * 2 ) / 3 );
+ else
+ f.setPointSize( ( f.pointSize() * 2 ) / 3 );
+ }
+ applyFont( f );
+ w = pntr_fm->charWidth( str, pos );
+ }
+ return w;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextString::TQTextString()
+{
+ bidiDirty = TRUE;
+ bidi = FALSE;
+ rightToLeft = FALSE;
+ dir = TQChar::DirON;
+}
+
+TQTextString::TQTextString( const TQTextString &s )
+{
+ bidiDirty = TRUE;
+ bidi = s.bidi;
+ rightToLeft = s.rightToLeft;
+ dir = s.dir;
+ data = s.data;
+ data.detach();
+ for ( int i = 0; i < (int)data.size(); ++i ) {
+ TQTextFormat *f = data[i].format();
+ if ( f )
+ f->addRef();
+ }
+}
+
+void TQTextString::insert( int index, const QString &s, TQTextFormat *f )
+{
+ insert( index, s.tqunicode(), s.length(), f );
+}
+
+void TQTextString::insert( int index, const QChar *tqunicode, int len, TQTextFormat *f )
+{
+ int os = data.size();
+ data.resize( data.size() + len, TQGArray::SpeedOptim );
+ if ( index < os ) {
+ memmove( data.data() + index + len, data.data() + index,
+ sizeof( TQTextStringChar ) * ( os - index ) );
+ }
+ TQTextStringChar *ch = data.data() + index;
+ for ( int i = 0; i < len; ++i ) {
+ ch->x = 0;
+ ch->lineStart = 0;
+ ch->d.format = 0;
+ ch->nobreak = FALSE;
+ ch->type = TQTextStringChar::Regular;
+ ch->d.format = f;
+ ch->rightToLeft = 0;
+ ch->c = tqunicode[i];
+ ++ch;
+ }
+ bidiDirty = TRUE;
+}
+
+TQTextString::~TQTextString()
+{
+ clear();
+}
+
+void TQTextString::insert( int index, TQTextStringChar *c, bool doAddRefFormat )
+{
+ int os = data.size();
+ data.resize( data.size() + 1, TQGArray::SpeedOptim );
+ if ( index < os ) {
+ memmove( data.data() + index + 1, data.data() + index,
+ sizeof( TQTextStringChar ) * ( os - index ) );
+ }
+ TQTextStringChar &ch = data[ (int)index ];
+ ch.c = c->c;
+ ch.x = 0;
+ ch.lineStart = 0;
+ ch.rightToLeft = 0;
+ ch.d.format = 0;
+ ch.type = TQTextStringChar::Regular;
+ ch.nobreak = FALSE;
+ if ( doAddRefFormat && c->format() )
+ c->format()->addRef();
+ ch.setFormat( c->format() );
+ bidiDirty = TRUE;
+}
+
+int TQTextString::appendParagraphs( TQTextParagraph *start, TQTextParagraph *end )
+{
+ int paragCount = 0;
+ int newLength = data.size();
+ TQTextParagraph *p = start;
+ for (; p != end; p = p->next()) {
+ newLength += p->length();
+ ++paragCount;
+ }
+
+ const int oldLength = data.size();
+ data.resize(newLength, TQGArray::SpeedOptim);
+
+ TQTextStringChar *d = &data[oldLength];
+ for (p = start; p != end; p = p->next()) {
+ const TQTextStringChar * const src = p->at(0);
+ int i = 0;
+ for (; i < p->length() - 1; ++i) {
+ d[i].c = src[i].c;
+ d[i].x = 0;
+ d[i].lineStart = 0;
+ d[i].rightToLeft = 0;
+ d[i].type = TQTextStringChar::Regular;
+ d[i].nobreak = FALSE;
+ d[i].d.format = src[i].format();
+ if (d[i].d.format)
+ d[i].d.format->addRef();
+ }
+ d[i].x = 0;
+ d[i].lineStart = 0;
+ d[i].nobreak = FALSE;
+ d[i].type = TQTextStringChar::Regular;
+ d[i].d.format = 0;
+ d[i].rightToLeft = 0;
+ d[i].c = '\n';
+ d += p->length();
+ }
+
+ bidiDirty = TRUE;
+ return paragCount;
+}
+
+void TQTextString::truncate( int index )
+{
+ index = TQMAX( index, 0 );
+ index = TQMIN( index, (int)data.size() - 1 );
+ if ( index < (int)data.size() ) {
+ for ( int i = index + 1; i < (int)data.size(); ++i ) {
+ TQTextStringChar &ch = data[ i ];
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( !(ch.type == TQTextStringChar::Regular) ) {
+ delete ch.customItem();
+ if ( ch.d.custom->format )
+ ch.d.custom->format->removeRef();
+ delete ch.d.custom;
+ ch.d.custom = 0;
+ } else
+#endif
+ if ( ch.format() ) {
+ ch.format()->removeRef();
+ }
+ }
+ }
+ data.truncate( index );
+ bidiDirty = TRUE;
+}
+
+void TQTextString::remove( int index, int len )
+{
+ for ( int i = index; i < (int)data.size() && i - index < len; ++i ) {
+ TQTextStringChar &ch = data[ i ];
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( !(ch.type == TQTextStringChar::Regular) ) {
+ delete ch.customItem();
+ if ( ch.d.custom->format )
+ ch.d.custom->format->removeRef();
+ delete ch.d.custom;
+ ch.d.custom = 0;
+ } else
+#endif
+ if ( ch.format() ) {
+ ch.format()->removeRef();
+ }
+ }
+ memmove( data.data() + index, data.data() + index + len,
+ sizeof( TQTextStringChar ) * ( data.size() - index - len ) );
+ data.resize( data.size() - len, TQGArray::SpeedOptim );
+ bidiDirty = TRUE;
+}
+
+void TQTextString::clear()
+{
+ for ( int i = 0; i < (int)data.count(); ++i ) {
+ TQTextStringChar &ch = data[ i ];
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( !(ch.type == TQTextStringChar::Regular) ) {
+ if ( ch.customItem() && ch.customItem()->placement() == TQTextCustomItem::PlaceInline )
+ delete ch.customItem();
+ if ( ch.d.custom->format )
+ ch.d.custom->format->removeRef();
+ delete ch.d.custom;
+ ch.d.custom = 0;
+ } else
+#endif
+ if ( ch.format() ) {
+ ch.format()->removeRef();
+ }
+ }
+ data.resize( 0 );
+ bidiDirty = TRUE;
+}
+
+void TQTextString::setFormat( int index, TQTextFormat *f, bool useCollection )
+{
+ TQTextStringChar &ch = data[ index ];
+ if ( useCollection && ch.format() )
+ ch.format()->removeRef();
+ ch.setFormat( f );
+}
+
+void TQTextString::checkBidi() const
+{
+ TQTextString *that = (TQTextString *)this;
+ that->bidiDirty = FALSE;
+ int length = data.size();
+ if ( !length ) {
+ that->bidi = FALSE;
+ that->rightToLeft = dir == TQChar::DirR;
+ return;
+ }
+ const TQTextStringChar *start = data.data();
+ const TQTextStringChar *end = start + length;
+
+ ((TQTextString *)this)->stringCache = toString(data);
+
+
+ // determines the properties we need for layouting
+ TQTextEngine textEngine( toString(), 0 );
+ textEngine.direction = (TQChar::Direction) dir;
+ textEngine.itemize(TQTextEngine::SingleLine);
+ const TQCharAttributes *ca = textEngine.attributes() + length-1;
+ TQTextStringChar *ch = (TQTextStringChar *)end - 1;
+ TQScriptItem *item = &textEngine.items[textEngine.items.size()-1];
+ unsigned char bidiLevel = item->analysis.bidiLevel;
+ if ( bidiLevel )
+ that->bidi = TRUE;
+ int pos = length-1;
+ while ( ch >= start ) {
+ if ( item->position > pos ) {
+ --item;
+ TQ_ASSERT( item >= &textEngine.items[0] );
+ TQ_ASSERT( item < &textEngine.items[textEngine.items.size()] );
+ bidiLevel = item->analysis.bidiLevel;
+ if ( bidiLevel )
+ that->bidi = TRUE;
+ }
+ ch->softBreak = ca->softBreak;
+ ch->whiteSpace = ca->whiteSpace;
+ ch->charStop = ca->charStop;
+ ch->wordStop = ca->wordStop;
+ ch->bidiLevel = bidiLevel;
+ ch->rightToLeft = (bidiLevel%2);
+ --ch;
+ --ca;
+ --pos;
+ }
+
+ if ( dir == TQChar::DirR ) {
+ that->bidi = TRUE;
+ that->rightToLeft = TRUE;
+ } else if ( dir == TQChar::DirL ) {
+ that->rightToLeft = FALSE;
+ } else {
+ that->rightToLeft = (textEngine.direction == TQChar::DirR);
+ }
+}
+
+void TQTextDocument::setStyleSheet( TQStyleSheet *s )
+{
+ if ( !s )
+ return;
+ sheet_ = s;
+ list_tm = list_bm = par_tm = par_bm = 12;
+ list_lm = 40;
+ li_tm = li_bm = 0;
+ TQStyleSheetItem* item = s->item( "ol" );
+ if ( item ) {
+ list_tm = TQMAX(0,item->margin( TQStyleSheetItem::MarginTop ));
+ list_bm = TQMAX(0,item->margin( TQStyleSheetItem::MarginBottom ));
+ list_lm = TQMAX(0,item->margin( TQStyleSheetItem::MarginLeft ));
+ }
+ if ( (item = s->item( "li" ) ) ) {
+ li_tm = TQMAX(0,item->margin( TQStyleSheetItem::MarginTop ));
+ li_bm = TQMAX(0,item->margin( TQStyleSheetItem::MarginBottom ));
+ }
+ if ( (item = s->item( "p" ) ) ) {
+ par_tm = TQMAX(0,item->margin( TQStyleSheetItem::MarginTop ));
+ par_bm = TQMAX(0,item->margin( TQStyleSheetItem::MarginBottom ));
+ }
+}
+
+void TQTextDocument::setUnderlineLinks( bool b ) {
+ underlLinks = b;
+ for ( TQTextDocument *d = childList.first(); d; d = childList.next() )
+ d->setUnderlineLinks( b );
+}
+
+void TQTextStringChar::setFormat( TQTextFormat *f )
+{
+ if ( type == Regular ) {
+ d.format = f;
+ } else {
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( !d.custom ) {
+ d.custom = new CustomData;
+ d.custom->custom = 0;
+ }
+ d.custom->format = f;
+#endif
+ }
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+void TQTextStringChar::setCustomItem( TQTextCustomItem *i )
+{
+ if ( type == Regular ) {
+ TQTextFormat *f = format();
+ d.custom = new CustomData;
+ d.custom->format = f;
+ } else {
+ delete d.custom->custom;
+ }
+ d.custom->custom = i;
+ type = (type == Anchor ? CustomAnchor : Custom);
+}
+
+void TQTextStringChar::loseCustomItem()
+{
+ if ( type == Custom ) {
+ TQTextFormat *f = d.custom->format;
+ d.custom->custom = 0;
+ delete d.custom;
+ type = Regular;
+ d.format = f;
+ } else if ( type == CustomAnchor ) {
+ d.custom->custom = 0;
+ type = Anchor;
+ }
+}
+
+#endif
+
+TQString TQTextStringChar::anchorName() const
+{
+ if ( type == Regular )
+ return TQString::null;
+ else
+ return d.custom->anchorName;
+}
+
+TQString TQTextStringChar::anchorHref() const
+{
+ if ( type == Regular )
+ return TQString::null;
+ else
+ return d.custom->anchorHref;
+}
+
+void TQTextStringChar::setAnchor( const TQString& name, const TQString& href )
+{
+ if ( type == Regular ) {
+ TQTextFormat *f = format();
+ d.custom = new CustomData;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ d.custom->custom = 0;
+#endif
+ d.custom->format = f;
+ type = Anchor;
+ } else if ( type == Custom ) {
+ type = CustomAnchor;
+ }
+ d.custom->anchorName = name;
+ d.custom->anchorHref = href;
+}
+
+
+int TQTextString::width( int idx ) const
+{
+ int w = 0;
+ TQTextStringChar *c = &at( idx );
+ if ( !c->charStop || c->c.tqunicode() == 0xad || c->c.tqunicode() == 0x2028 )
+ return 0;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if( c->isCustom() ) {
+ if( c->customItem()->placement() == TQTextCustomItem::PlaceInline )
+ w = c->customItem()->width;
+ } else
+#endif
+ {
+ int r = c->c.row();
+ if(r < 0x06
+#ifndef TQ_WS_WIN
+ // Uniscribe's handling of Asian makes the condition below fail.
+ || (r > 0x1f && !(r > 0xd7 && r < 0xe0))
+#endif
+ ) {
+ w = c->format()->width( c->c );
+ } else {
+ w = c->format()->width(toString(), idx);
+ }
+ }
+ return w;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextParagraph::TQTextParagraph( TQTextDocument *d, TQTextParagraph *pr, TQTextParagraph *nx, bool updateIds )
+ : p( pr ), n( nx ), docOrPseudo( d ),
+ changed(FALSE), firstFormat(TRUE), firstPProcess(TRUE), needPreProcess(FALSE), fullWidth(TRUE),
+ lastInFrame(FALSE), visible(TRUE), breakable(TRUE), movedDown(FALSE),
+ mightHaveCustomItems(FALSE), hasdoc( d != 0 ), litem(FALSE), rtext(FALSE),
+ align( 0 ), lstyle( TQStyleSheetItem::ListDisc ), invalid( 0 ), mSelections( 0 ),
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ mFloatingItems( 0 ),
+#endif
+ utm( 0 ), ubm( 0 ), ulm( 0 ), urm( 0 ), uflm( 0 ), ulinespacing( 0 ),
+ tabStopWidth(0), minwidth(0), tArray(0), eData( 0 ), ldepth( 0 )
+{
+ lstyle = TQStyleSheetItem::ListDisc;
+ if ( !hasdoc )
+ docOrPseudo = new TQTextParagraphPseudoDocument;
+ bgcol = 0;
+ list_val = -1;
+ painttqdevice = 0;
+ TQTextFormat* defFormat = formatCollection()->defaultFormat();
+ if ( !hasdoc ) {
+ tabStopWidth = defFormat->width( 'x' ) * 8;
+ pseudoDocument()->commandHistory = new TQTextCommandHistory( 100 );
+ }
+
+ if ( p )
+ p->n = this;
+ if ( n )
+ n->p = this;
+
+ if ( !p && hasdoc )
+ document()->setFirstParagraph( this );
+ if ( !n && hasdoc )
+ document()->setLastParagraph( this );
+
+ state = -1;
+
+ if ( p )
+ id = p->id + 1;
+ else
+ id = 0;
+ if ( n && updateIds ) {
+ TQTextParagraph *s = n;
+ while ( s ) {
+ s->id = s->p->id + 1;
+ s->invalidateStyleCache();
+ s = s->n;
+ }
+ }
+
+ str = new TQTextString();
+ TQChar ch(' ');
+ str->insert( 0, &ch, 1, formatCollection()->defaultFormat() );
+}
+
+TQTextParagraph::~TQTextParagraph()
+{
+ delete str;
+ if ( hasdoc ) {
+ register TQTextDocument *doc = document();
+ if ( this == doc->minwParag ) {
+ doc->minwParag = 0;
+ doc->minw = 0;
+ }
+ if ( this == doc->curParag )
+ doc->curParag = 0;
+ } else {
+ delete pseudoDocument();
+ }
+ delete [] tArray;
+ delete eData;
+ QMap<int, TQTextLineStart*>::Iterator it = lineStarts.begin();
+ for ( ; it != lineStarts.end(); ++it )
+ delete *it;
+ if ( mSelections )
+ delete mSelections;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( mFloatingItems )
+ delete mFloatingItems;
+#endif
+ if ( p )
+ p->setNext( n );
+ if ( n )
+ n->setPrev( p );
+ delete bgcol;
+}
+
+void TQTextParagraph::setNext( TQTextParagraph *s )
+{
+ n = s;
+ if ( !n && hasdoc )
+ document()->setLastParagraph( this );
+}
+
+void TQTextParagraph::setPrev( TQTextParagraph *s )
+{
+ p = s;
+ if ( !p && hasdoc )
+ document()->setFirstParagraph( this );
+}
+
+void TQTextParagraph::tqinvalidate( int chr )
+{
+ if ( invalid < 0 )
+ invalid = chr;
+ else
+ invalid = TQMIN( invalid, chr );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( mFloatingItems ) {
+ for ( TQTextCustomItem *i = mFloatingItems->first(); i; i = mFloatingItems->next() )
+ i->ypos = -1;
+ }
+#endif
+ invalidateStyleCache();
+}
+
+void TQTextParagraph::invalidateStyleCache()
+{
+ if ( list_val < 0 )
+ list_val = -1;
+}
+
+
+void TQTextParagraph::insert( int index, const QString &s )
+{
+ insert( index, s.tqunicode(), s.length() );
+}
+
+void TQTextParagraph::insert( int index, const QChar *tqunicode, int len )
+{
+ if ( hasdoc && !document()->useFormatCollection() && document()->preProcessor() )
+ str->insert( index, tqunicode, len,
+ document()->preProcessor()->format( TQTextPreProcessor::Standard ) );
+ else
+ str->insert( index, tqunicode, len, formatCollection()->defaultFormat() );
+ tqinvalidate( index );
+ needPreProcess = TRUE;
+}
+
+void TQTextParagraph::truncate( int index )
+{
+ str->truncate( index );
+ insert( length(), " " );
+ needPreProcess = TRUE;
+}
+
+void TQTextParagraph::remove( int index, int len )
+{
+ if ( index + len - str->length() > 0 )
+ return;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ for ( int i = index; i < index + len; ++i ) {
+ TQTextStringChar *c = at( i );
+ if ( hasdoc && c->isCustom() ) {
+ document()->unregisterCustomItem( c->customItem(), this );
+ }
+ }
+#endif
+ str->remove( index, len );
+ tqinvalidate( 0 );
+ needPreProcess = TRUE;
+}
+
+void TQTextParagraph::join( TQTextParagraph *s )
+{
+ int oh = r.height() + s->r.height();
+ n = s->n;
+ if ( n )
+ n->p = this;
+ else if ( hasdoc )
+ document()->setLastParagraph( this );
+
+ int start = str->length();
+ if ( length() > 0 && at( length() - 1 )->c == ' ' ) {
+ remove( length() - 1, 1 );
+ --start;
+ }
+ append( s->str->toString(), TRUE );
+
+ for ( int i = 0; i < s->length(); ++i ) {
+ if ( !hasdoc || document()->useFormatCollection() ) {
+ s->str->at( i ).format()->addRef();
+ str->setFormat( i + start, s->str->at( i ).format(), TRUE );
+ }
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( s->str->at( i ).isCustom() ) {
+ TQTextCustomItem * item = s->str->at( i ).customItem();
+ str->at( i + start ).setCustomItem( item );
+ s->str->at( i ).loseCustomItem();
+ if ( hasdoc ) {
+ document()->unregisterCustomItem( item, s );
+ document()->registerCustomItem( item, this );
+ }
+ }
+ if ( s->str->at( i ).isAnchor() ) {
+ str->at( i + start ).setAnchor( s->str->at( i ).anchorName(),
+ s->str->at( i ).anchorHref() );
+ }
+#endif
+ }
+
+ if ( !extraData() && s->extraData() ) {
+ setExtraData( s->extraData() );
+ s->setExtraData( 0 );
+ } else if ( extraData() && s->extraData() ) {
+ extraData()->join( s->extraData() );
+ }
+ delete s;
+ tqinvalidate( 0 );
+ r.setHeight( oh );
+ needPreProcess = TRUE;
+ if ( n ) {
+ TQTextParagraph *s = n;
+ s->tqinvalidate( 0 );
+ while ( s ) {
+ s->id = s->p->id + 1;
+ s->state = -1;
+ s->needPreProcess = TRUE;
+ s->changed = TRUE;
+ s->invalidateStyleCache();
+ s = s->n;
+ }
+ }
+ format();
+ state = -1;
+}
+
+void TQTextParagraph::move( int &dy )
+{
+ if ( dy == 0 )
+ return;
+ changed = TRUE;
+ r.moveBy( 0, dy );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( mFloatingItems ) {
+ for ( TQTextCustomItem *i = mFloatingItems->first(); i; i = mFloatingItems->next() )
+ i->ypos += dy;
+ }
+#endif
+ if ( p )
+ p->lastInFrame = TRUE;
+
+ // do page breaks if required
+ if ( hasdoc && document()->isPageBreakEnabled() ) {
+ int shift;
+ if ( ( shift = document()->formatter()->formatVertically( document(), this ) ) ) {
+ if ( p )
+ p->setChanged( TRUE );
+ dy += shift;
+ }
+ }
+}
+
+void TQTextParagraph::format( int start, bool doMove )
+{
+ if ( !str || str->length() == 0 || !formatter() )
+ return;
+
+ if ( hasdoc &&
+ document()->preProcessor() &&
+ ( needPreProcess || state == -1 ) )
+ document()->preProcessor()->process( document(), this, invalid <= 0 ? 0 : invalid );
+ needPreProcess = FALSE;
+
+ if ( invalid == -1 )
+ return;
+
+ r.moveTopLeft( TQPoint( documentX(), p ? p->r.y() + p->r.height() : documentY() ) );
+ if ( p )
+ p->lastInFrame = FALSE;
+
+ movedDown = FALSE;
+ bool formattedAgain = FALSE;
+
+ formatAgain:
+
+ r.setWidth( documentWidth() );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( hasdoc && mFloatingItems ) {
+ for ( TQTextCustomItem *i = mFloatingItems->first(); i; i = mFloatingItems->next() ) {
+ i->ypos = r.y();
+ if ( i->placement() == TQTextCustomItem::PlaceRight ) {
+ i->xpos = r.x() + r.width() - i->width;
+ }
+ }
+ }
+#endif
+ QMap<int, TQTextLineStart*> oldLineStarts = lineStarts;
+ lineStarts.clear();
+ int y = formatter()->format( document(), this, start, oldLineStarts );
+
+
+ r.setWidth( TQMAX( r.width(), formatter()->minimumWidth() ) );
+
+
+ QMap<int, TQTextLineStart*>::Iterator it = oldLineStarts.begin();
+
+ for ( ; it != oldLineStarts.end(); ++it )
+ delete *it;
+
+ if ( !hasdoc ) { // qt_format_text bounding rect handling
+ it = lineStarts.begin();
+ int usedw = 0;
+ for ( ; it != lineStarts.end(); ++it )
+ usedw = TQMAX( usedw, (*it)->w );
+ if ( r.width() <= 0 ) {
+ // if the user specifies an invalid rect, this means that the
+ // bounding box should grow to the width that the text actually
+ // needs
+ r.setWidth( usedw );
+ } else {
+ r.setWidth( TQMIN( usedw, r.width() ) );
+ }
+ }
+
+ if ( y != r.height() )
+ r.setHeight( y );
+
+ if ( !visible ) {
+ r.setHeight( 0 );
+ } else {
+ int minw = minwidth = formatter()->minimumWidth();
+ int wused = formatter()->widthUsed();
+ wused = TQMAX( minw, wused );
+ if ( hasdoc ) {
+ document()->setMinimumWidth( minw, wused, this );
+ } else {
+ pseudoDocument()->minw = TQMAX( pseudoDocument()->minw, minw );
+ pseudoDocument()->wused = TQMAX( pseudoDocument()->wused, wused );
+ }
+ }
+
+ // do page breaks if required
+ if ( hasdoc && document()->isPageBreakEnabled() ) {
+ int shift = document()->formatter()->formatVertically( document(), this );
+ if ( shift && !formattedAgain ) {
+ formattedAgain = TRUE;
+ goto formatAgain;
+ }
+ }
+
+ if ( n && doMove && n->invalid == -1 && r.y() + r.height() != n->r.y() ) {
+ int dy = ( r.y() + r.height() ) - n->r.y();
+ TQTextParagraph *s = n;
+ bool makeInvalid = p && p->lastInFrame;
+ while ( s && dy ) {
+ if ( !s->isFullWidth() )
+ makeInvalid = TRUE;
+ if ( makeInvalid )
+ s->tqinvalidate( 0 );
+ s->move( dy );
+ if ( s->lastInFrame )
+ makeInvalid = TRUE;
+ s = s->n;
+ }
+ }
+
+ firstFormat = FALSE;
+ changed = TRUE;
+ invalid = -1;
+ //##### string()->setTextChanged( FALSE );
+}
+
+int TQTextParagraph::lineHeightOfChar( int i, int *bl, int *y ) const
+{
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ QMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.end();
+ --it;
+ for ( ;; ) {
+ if ( i >= it.key() ) {
+ if ( bl )
+ *bl = ( *it )->baseLine;
+ if ( y )
+ *y = ( *it )->y;
+ return ( *it )->h;
+ }
+ if ( it == lineStarts.begin() )
+ break;
+ --it;
+ }
+
+ qWarning( "TQTextParagraph::lineHeightOfChar: couldn't tqfind lh for %d", i );
+ return 15;
+}
+
+TQTextStringChar *TQTextParagraph::lineStartOfChar( int i, int *index, int *line ) const
+{
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ int l = (int)lineStarts.count() - 1;
+ QMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.end();
+ --it;
+ for ( ;; ) {
+ if ( i >= it.key() ) {
+ if ( index )
+ *index = it.key();
+ if ( line )
+ *line = l;
+ return &str->at( it.key() );
+ }
+ if ( it == lineStarts.begin() )
+ break;
+ --it;
+ --l;
+ }
+
+ qWarning( "TQTextParagraph::lineStartOfChar: couldn't tqfind %d", i );
+ return 0;
+}
+
+int TQTextParagraph::lines() const
+{
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ return (int)lineStarts.count();
+}
+
+TQTextStringChar *TQTextParagraph::lineStartOfLine( int line, int *index ) const
+{
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ if ( line >= 0 && line < (int)lineStarts.count() ) {
+ QMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while ( line-- > 0 )
+ ++it;
+ int i = it.key();
+ if ( index )
+ *index = i;
+ return &str->at( i );
+ }
+
+ qWarning( "TQTextParagraph::lineStartOfLine: couldn't tqfind %d", line );
+ return 0;
+}
+
+int TQTextParagraph::leftGap() const
+{
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ if ( str->length() == 0)
+ return 0;
+
+ int line = 0;
+ int x = str->length() ? str->at(0).x : 0; /* set x to x of first char */
+ if ( str->isBidi() ) {
+ for ( int i = 1; i < str->length()-1; ++i )
+ x = TQMIN(x, str->at(i).x);
+ return x;
+ }
+
+ QMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while (line < (int)lineStarts.count()) {
+ int i = it.key(); /* char index */
+ x = TQMIN(x, str->at(i).x);
+ ++it;
+ ++line;
+ }
+ return x;
+}
+
+void TQTextParagraph::setFormat( int index, int len, TQTextFormat *f, bool useCollection, int flags )
+{
+ if ( !f )
+ return;
+ if ( index < 0 )
+ index = 0;
+ if ( index > str->length() - 1 )
+ index = str->length() - 1;
+ if ( index + len >= str->length() )
+ len = str->length() - index;
+
+ TQTextFormatCollection *fc = 0;
+ if ( useCollection )
+ fc = formatCollection();
+ TQTextFormat *of;
+ for ( int i = 0; i < len; ++i ) {
+ of = str->at( i + index ).format();
+ if ( !changed && ( !of || f->key() != of->key() ) )
+ changed = TRUE;
+ if ( invalid == -1 &&
+ ( f->font().family() != of->font().family() ||
+ f->font().pointSize() != of->font().pointSize() ||
+ f->font().weight() != of->font().weight() ||
+ f->font().italic() != of->font().italic() ||
+ f->vAlign() != of->vAlign() ) ) {
+ tqinvalidate( 0 );
+ }
+ if ( flags == -1 || flags == TQTextFormat::Format || !fc ) {
+ if ( fc )
+ f = fc->format( f );
+ str->setFormat( i + index, f, useCollection );
+ } else {
+ TQTextFormat *fm = fc->format( of, f, flags );
+ str->setFormat( i + index, fm, useCollection );
+ }
+ }
+}
+
+void TQTextParagraph::indent( int *oldIndent, int *newIndent )
+{
+ if ( !hasdoc || !document()->indent() || isListItem() ) {
+ if ( oldIndent )
+ *oldIndent = 0;
+ if ( newIndent )
+ *newIndent = 0;
+ if ( oldIndent && newIndent )
+ *newIndent = *oldIndent;
+ return;
+ }
+ document()->indent()->indent( document(), this, oldIndent, newIndent );
+}
+
+void TQTextParagraph::paint( TQPainter &painter, const TQColorGroup &cg, TQTextCursor *cursor, bool drawSelections,
+ int clipx, int clipy, int clipw, int cliph )
+{
+ if ( !visible )
+ return;
+ int i, y, h, baseLine, xstart, xend = 0;
+ i = y =h = baseLine = 0;
+ TQRect cursorRect;
+ drawSelections &= ( mSelections != 0 );
+ // macintosh full-width selection style
+ bool fullWidthStyle = TQApplication::tqstyle().tqstyleHint(TQStyle::SH_RichText_FullWidthSelection);
+ int fullSelectionWidth = 0;
+ if ( drawSelections && fullWidthStyle )
+ fullSelectionWidth = (hasdoc ? document()->width() : r.width());
+
+ TQString qstr = str->toString();
+ // detach string
+ qstr.setLength(qstr.length());
+ // ### workaround so that \n are not drawn, actually this should
+ // be fixed in TQFont somewhere (under Windows you get ugly boxes
+ // otherwise)
+ TQChar* uc = (TQChar*) qstr.tqunicode();
+ for ( int ii = 0; ii < qstr.length(); ii++ )
+ if ( uc[(int)ii]== '\n' || uc[(int)ii] == '\t' )
+ uc[(int)ii] = 0x20;
+
+ int line = -1;
+ int paintStart = 0;
+ TQTextStringChar *chr = 0;
+ TQTextStringChar *nextchr = at( 0 );
+ for ( i = 0; i < length(); i++ ) {
+ chr = nextchr;
+ if ( i < length()-1 )
+ nextchr = at( i+1 );
+
+ // we flush at end of document
+ bool flush = (i == length()-1);
+ bool ignoreSoftHyphen = FALSE;
+ if ( !flush ) {
+ // we flush at end of line
+ flush |= nextchr->lineStart;
+ // we flush on format changes
+ flush |= ( nextchr->format() != chr->format() );
+ // we flush on link changes
+ flush |= ( nextchr->isLink() != chr->isLink() );
+ // we flush on start of run
+ flush |= ( nextchr->bidiLevel != chr->bidiLevel );
+ // we flush on bidi changes
+ flush |= ( nextchr->rightToLeft != chr->rightToLeft );
+ // we flush before and after tabs
+ flush |= ( chr->c == '\t' || nextchr->c == '\t' );
+ // we flush on soft hypens
+ if (chr->c.tqunicode() == 0xad) {
+ flush = TRUE;
+ if (!nextchr->lineStart)
+ ignoreSoftHyphen = TRUE;
+ }
+ // we flush on custom items
+ flush |= chr->isCustom();
+ // we flush before custom items
+ flush |= nextchr->isCustom();
+ // when painting justified, we flush on spaces
+ if ((tqalignment() & TQt::AlignJustify) == TQt::AlignJustify )
+ flush |= chr->whiteSpace;
+ }
+
+ // init a new line
+ if ( chr->lineStart ) {
+ ++line;
+ paintStart = i;
+ lineInfo( line, y, h, baseLine );
+ if ( clipy != -1 && cliph != 0 && y + r.y() - h > clipy + cliph ) { // outside clip area, leave
+ break;
+ }
+
+ // if this is the first line and we are a list item, draw the the bullet label
+ if ( line == 0 && isListItem() ) {
+ int x = chr->x;
+ if (str->isBidi()) {
+ if (str->isRightToLeft()) {
+ x = chr->x + str->width(0);
+ for (int k = 1; k < length(); ++k) {
+ if (str->at(k).lineStart)
+ break;
+ x = TQMAX(x, str->at(k).x + str->width(k));
+ }
+ } else {
+ x = chr->x;
+ for (int k = 1; k < length(); ++k) {
+ if (str->at(k).lineStart)
+ break;
+ x = TQMIN(x, str->at(k).x);
+ }
+ }
+ }
+ drawLabel( &painter, x, y, 0, 0, baseLine, cg );
+ }
+ }
+
+ // check for cursor mark
+ if ( cursor && this == cursor->paragraph() && i == cursor->index() ) {
+ TQTextStringChar *c = i == 0 ? chr : chr - 1;
+ cursorRect.setRect( cursor->x() , y + baseLine - c->format()->ascent(),
+ 1, c->format()->height() );
+ }
+
+ if ( flush ) { // something changed, draw what we have so far
+ if ( chr->rightToLeft ) {
+ xstart = chr->x;
+ xend = at( paintStart )->x + str->width( paintStart );
+ } else {
+ xstart = at( paintStart )->x;
+ xend = chr->x;
+ if ( i < length() - 1 ) {
+ if ( !str->at( i + 1 ).lineStart &&
+ str->at( i + 1 ).rightToLeft == chr->rightToLeft )
+ xend = str->at( i + 1 ).x;
+ else
+ xend += str->width( i );
+ }
+ }
+
+ if ( (clipx == -1 || clipw <= 0 || (xend >= clipx && xstart <= clipx + clipw)) &&
+ ( clipy == -1 || clipy < y+r.y()+h ) ) {
+ if ( !chr->isCustom() )
+ drawString( painter, qstr, paintStart, i - paintStart + (ignoreSoftHyphen ? 0 : 1), xstart, y,
+ baseLine, xend-xstart, h, drawSelections, fullSelectionWidth,
+ chr, cg, chr->rightToLeft );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ else if ( chr->customItem()->placement() == TQTextCustomItem::PlaceInline ) {
+ bool inSelection = FALSE;
+ if (drawSelections) {
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->tqfind( TQTextDocument::Standard );
+ inSelection = (it != mSelections->end() && (*it).start <= i && (*it).end > i);
+ }
+ chr->customItem()->draw( &painter, chr->x, y,
+ clipx == -1 ? clipx : (clipx - r.x()),
+ clipy == -1 ? clipy : (clipy - r.y()),
+ clipw, cliph, cg, inSelection );
+ }
+#endif
+ }
+ paintStart = i+1;
+ }
+
+ }
+
+ // time to draw the cursor
+ const int cursor_extent = 4;
+ if ( !cursorRect.isNull() && cursor &&
+ ((clipx == -1 || clipw == -1) || (cursorRect.right()+cursor_extent >= clipx && cursorRect.left()-cursor_extent <= clipx + clipw)) ) {
+ painter.fillRect( cursorRect, cg.color( TQColorGroup::Text ) );
+ painter.save();
+ if ( string()->isBidi() ) {
+ if ( at( cursor->index() )->rightToLeft ) {
+ painter.setPen( TQt::black );
+ painter.drawLine( cursorRect.x(), cursorRect.y(), cursorRect.x() - cursor_extent / 2, cursorRect.y() + cursor_extent / 2 );
+ painter.drawLine( cursorRect.x(), cursorRect.y() + cursor_extent, cursorRect.x() - cursor_extent / 2, cursorRect.y() + cursor_extent / 2 );
+ } else {
+ painter.setPen( TQt::black );
+ painter.drawLine( cursorRect.x(), cursorRect.y(), cursorRect.x() + cursor_extent / 2, cursorRect.y() + cursor_extent / 2 );
+ painter.drawLine( cursorRect.x(), cursorRect.y() + cursor_extent, cursorRect.x() + cursor_extent / 2, cursorRect.y() + cursor_extent / 2 );
+ }
+ }
+ painter.restore();
+ }
+}
+
+//#define BIDI_DEBUG
+
+void TQTextParagraph::setColorForSelection( TQColor &color, TQPainter &painter,
+ const TQColorGroup& cg, int selection )
+{
+ if (selection < 0)
+ return;
+ color = ( hasdoc && selection != TQTextDocument::Standard ) ?
+ document()->selectionColor( selection ) :
+ cg.color( TQColorGroup::Highlight );
+ if ( selection == TQTextDocument::IMCompositionText ) {
+#ifndef TQ_WS_MACX
+ int h1, s1, v1, h2, s2, v2;
+ TQT_TQCOLOR_OBJECT(cg.color( TQColorGroup::Base )).hsv( &h1, &s1, &v1 );
+ TQT_TQCOLOR_OBJECT(cg.color( TQColorGroup::Background )).hsv( &h2, &s2, &v2 );
+ color.setHsv( h1, s1, ( v1 + v2 ) / 2 );
+#else
+ color = TQt::lightGray;
+#endif
+ painter.setPen( cg.color( TQColorGroup::Text ) );
+ } else if ( selection == TQTextDocument::IMSelectionText ) {
+ color = cg.color( TQColorGroup::Dark );
+ painter.setPen( cg.color( TQColorGroup::BrightText ) );
+ } else if ( !hasdoc || document()->invertSelectionText( selection ) ) {
+ painter.setPen( cg.color( TQColorGroup::HighlightedText ) );
+ }
+}
+
+void TQTextParagraph::drawString( TQPainter &painter, const TQString &str, int start, int len, int xstart,
+ int y, int baseLine, int w, int h, bool drawSelections, int fullSelectionWidth,
+ TQTextStringChar *formatChar, const TQColorGroup& cg,
+ bool rightToLeft )
+{
+ bool plainText = hasdoc ? document()->textFormat() == TQt::PlainText : FALSE;
+ TQTextFormat* format = formatChar->format();
+
+ if ( !plainText || (hasdoc && (format->color() != document()->formatCollection()->defaultFormat()->color())) )
+ painter.setPen( TQPen( format->color() ) );
+ else
+ painter.setPen( cg.text() );
+ painter.setFont( format->font() );
+
+ if ( hasdoc && formatChar->isAnchor() && !formatChar->anchorHref().isEmpty() ) {
+ if ( format->useLinkColor() )
+ painter.setPen(document()->linkColor.isValid() ? document()->linkColor : cg.link());
+ if ( document()->underlineLinks() ) {
+ TQFont fn = format->font();
+ fn.setUnderline( TRUE );
+ painter.setFont( fn );
+ }
+ }
+
+ TQPainter::TextDirection dir = rightToLeft ? TQPainter::RTL : TQPainter::LTR;
+
+ int real_length = len;
+ if (len && dir != TQPainter::RTL && start + len == length() ) // don't draw the last character (trailing space)
+ len--;
+ if (len && str.tqunicode()[start+len-1] == TQChar_linesep)
+ len--;
+
+
+ TQTextFormat::VerticalAlignment vAlign = format->vAlign();
+ if ( vAlign != TQTextFormat::AlignNormal ) {
+ // sub or superscript
+ TQFont f( painter.font() );
+ if ( format->fontSizesInPixels() )
+ f.setPixelSize( ( f.pixelSize() * 2 ) / 3 );
+ else
+ f.setPointSize( ( f.pointSize() * 2 ) / 3 );
+ painter.setFont( f );
+ int h = painter.fontMetrics().height();
+ baseLine += (vAlign == TQTextFormat::AlignSubScript) ? h/6 : -h/2;
+ }
+
+ bool allSelected = FALSE;
+ if (drawSelections) {
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->tqfind( TQTextDocument::Standard );
+ allSelected = (it != mSelections->end() && (*it).start <= start && (*it).end >= start+len);
+ }
+ if (!allSelected)
+ painter.drawText(xstart, y + baseLine, str, start, len, dir);
+
+#ifdef BIDI_DEBUG
+ painter.save();
+ painter.setPen ( TQt::red );
+ painter.drawLine( xstart, y, xstart, y + baseLine );
+ painter.drawLine( xstart, y + baseLine/2, xstart + 10, y + baseLine/2 );
+ int w = 0;
+ int i = 0;
+ while( i < len )
+ w += painter.fontMetrics().charWidth( str, start + i++ );
+ painter.setPen ( TQt::blue );
+ painter.drawLine( xstart + w - 1, y, xstart + w - 1, y + baseLine );
+ painter.drawLine( xstart + w - 1, y + baseLine/2, xstart + w - 1 - 10, y + baseLine/2 );
+ painter.restore();
+#endif
+
+ // check if we are in a selection and draw it
+ if (drawSelections) {
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->end();
+ while ( it != mSelections->begin() ) {
+ --it;
+ int selStart = (*it).start;
+ int selEnd = (*it).end;
+ int tmpw = w;
+
+ selStart = TQMAX(selStart, start);
+ int real_selEnd = TQMIN(selEnd, start+real_length);
+ selEnd = TQMIN(selEnd, start+len);
+ bool extendRight = FALSE;
+ bool extendLeft = FALSE;
+ bool selWrap = (real_selEnd == length()-1 && n && n->hasSelection(it.key()));
+ if (selWrap || this->str->at(real_selEnd).lineStart) {
+ extendRight = (fullSelectionWidth != 0);
+ if (!extendRight && !rightToLeft)
+ tmpw += painter.fontMetrics().width(' ');
+ }
+ if (fullSelectionWidth && (selStart == 0 || this->str->at(selStart).lineStart)) {
+ extendLeft = TRUE;
+ }
+ if (this->str->isRightToLeft() != rightToLeft)
+ extendLeft = extendRight = FALSE;
+
+ if (this->str->isRightToLeft()) {
+ bool tmp = extendLeft;
+ extendLeft = extendRight;
+ extendRight = tmp;
+ }
+
+ if ((selStart < real_selEnd) ||
+ (selWrap && fullSelectionWidth && extendRight &&
+ // don't draw the standard selection on a printer=
+ ((it.key() != TQTextDocument::Standard) || (!is_printer( &painter))))) {
+ int selection = it.key();
+ TQColor color;
+ setColorForSelection( color, painter, cg, selection );
+ if (selStart != start || selEnd != start + len || selWrap) {
+ // have to clip
+ painter.save();
+ int cs, ce;
+ if (rightToLeft) {
+ cs = (selEnd != start + len) ?
+ this->str->at(this->str->previousCursorPosition(selEnd)).x : xstart;
+ ce = (selStart != start) ?
+ this->str->at(this->str->previousCursorPosition(selStart)).x : xstart+tmpw;
+ } else {
+ cs = (selStart != start) ? this->str->at(selStart).x : xstart;
+ ce = (selEnd != start + len) ? this->str->at(selEnd).x : xstart+tmpw;
+ }
+ TQRect r(cs, y, ce-cs, h);
+ if (extendLeft)
+ r.setLeft(0);
+ if (extendRight)
+ r.setRight(fullSelectionWidth);
+ TQRegion reg(r);
+ if ( painter.hasClipping() )
+ reg &= painter.clipRegion(TQPainter::CoordPainter);
+ painter.setClipRegion(reg, TQPainter::CoordPainter);
+ }
+ int xleft = xstart;
+ if ( extendLeft ) {
+ tmpw += xstart;
+ xleft = 0;
+ }
+ if ( extendRight )
+ tmpw = fullSelectionWidth - xleft;
+ painter.fillRect( xleft, y, tmpw, h, color );
+ painter.drawText( xstart, y + baseLine, str, start, len, dir );
+ if (selStart != start || selEnd != start + len || selWrap)
+ painter.restore();
+ }
+ }
+ }
+
+ if ( format->isMisspelled() ) {
+ painter.save();
+ painter.setPen( TQPen( TQt::red, 1, TQt::DotLine ) );
+ painter.drawLine( xstart, y + baseLine + 1, xstart + w, y + baseLine + 1 );
+ painter.restore();
+ }
+
+ if ( hasdoc && formatChar->isAnchor() && !formatChar->anchorHref().isEmpty() &&
+ document()->focusIndicator.parag == this &&
+ ( (document()->focusIndicator.start >= start &&
+ document()->focusIndicator.start + document()->focusIndicator.len <= start + len) ||
+ (document()->focusIndicator.start <= start &&
+ document()->focusIndicator.start + document()->focusIndicator.len >= start + len )) )
+ painter.drawWinFocusRect( TQRect( xstart, y, w, h ) );
+}
+
+void TQTextParagraph::drawLabel( TQPainter* p, int x, int y, int w, int h, int base, const TQColorGroup& cg )
+{
+ TQRect r ( x, y, w, h );
+ TQStyleSheetItem::ListStyle s = listStyle();
+
+ p->save();
+ TQTextFormat *format = at( 0 )->format();
+ if ( format ) {
+ p->setPen( format->color() );
+ p->setFont( format->font() );
+ }
+ TQFontMetrics fm( p->fontMetrics() );
+ int size = fm.lineSpacing() / 3;
+
+ bool rtl = str->isRightToLeft();
+
+ switch ( s ) {
+ case TQStyleSheetItem::ListDecimal:
+ case TQStyleSheetItem::ListLowerAlpha:
+ case TQStyleSheetItem::ListUpperAlpha:
+ {
+ if ( list_val == -1 ) { // uninitialised list value, calcluate the right one
+ int depth = listDepth();
+ list_val--;
+ // ### evil, square and expensive. This needs to be done when formatting, not when painting
+ TQTextParagraph* s = prev();
+ int depth_s;
+ while ( s && (depth_s = s->listDepth()) >= depth ) {
+ if ( depth_s == depth && s->isListItem() )
+ list_val--;
+ s = s->prev();
+ }
+ }
+
+ int n = list_val;
+ if ( n < -1 )
+ n = -n - 1;
+ TQString l;
+ switch ( s ) {
+ case TQStyleSheetItem::ListLowerAlpha:
+ if ( n < 27 ) {
+ l = TQChar( ('a' + (char) (n-1)));
+ break;
+ }
+ case TQStyleSheetItem::ListUpperAlpha:
+ if ( n < 27 ) {
+ l = TQChar( ('A' + (char) (n-1)));
+ break;
+ }
+ break;
+ default: //TQStyleSheetItem::ListDecimal:
+ l.setNum( n );
+ break;
+ }
+ if (rtl)
+ l.prepend(" .");
+ else
+ l += TQString::tqfromLatin1(". ");
+ int x = ( rtl ? r.left() : r.right() - fm.width(l));
+ p->drawText( x, r.top() + base, l );
+ }
+ break;
+ case TQStyleSheetItem::ListSquare:
+ {
+ int x = rtl ? r.left() + size : r.right() - size*2;
+ TQRect er( x, r.top() + fm.height() / 2 - size / 2, size, size );
+ p->fillRect( er , cg.brush( TQColorGroup::Text ) );
+ }
+ break;
+ case TQStyleSheetItem::ListCircle:
+ {
+ int x = rtl ? r.left() + size : r.right() - size*2;
+ TQRect er( x, r.top() + fm.height() / 2 - size / 2, size, size);
+ p->drawEllipse( er );
+ }
+ break;
+ case TQStyleSheetItem::ListDisc:
+ default:
+ {
+ p->setBrush( cg.brush( TQColorGroup::Text ));
+ int x = rtl ? r.left() + size : r.right() - size*2;
+ TQRect er( x, r.top() + fm.height() / 2 - size / 2, size, size);
+ p->drawEllipse( er );
+ p->setBrush( TQt::NoBrush );
+ }
+ break;
+ }
+
+ p->restore();
+}
+
+#ifndef TQT_NO_DATASTREAM
+void TQTextParagraph::readStyleInformation( TQDataStream& stream )
+{
+ int int_align, int_lstyle;
+ uchar uchar_litem, uchar_rtext, uchar_dir;
+ stream >> int_align >> int_lstyle >> utm >> ubm >> ulm >> urm >> uflm
+ >> ulinespacing >> ldepth >> uchar_litem >> uchar_rtext >> uchar_dir;
+ align = int_align; lstyle = (TQStyleSheetItem::ListStyle) int_lstyle;
+ litem = uchar_litem; rtext = uchar_rtext; str->setDirection( (TQChar::Direction)uchar_dir );
+ TQTextParagraph* s = prev() ? prev() : this;
+ while ( s ) {
+ s->tqinvalidate( 0 );
+ s = s->next();
+ }
+}
+
+void TQTextParagraph::writeStyleInformation( TQDataStream& stream ) const
+{
+ stream << (int) align << (int) lstyle << utm << ubm << ulm << urm << uflm << ulinespacing << ldepth << (uchar)litem << (uchar)rtext << (uchar)str->direction();
+}
+#endif
+
+
+void TQTextParagraph::setListItem( bool li )
+{
+ if ( (bool)litem == li )
+ return;
+ litem = li;
+ changed = TRUE;
+ TQTextParagraph* s = prev() ? prev() : this;
+ while ( s ) {
+ s->tqinvalidate( 0 );
+ s = s->next();
+ }
+}
+
+void TQTextParagraph::setListDepth( int depth ) {
+ if ( !hasdoc || depth == ldepth )
+ return;
+ ldepth = depth;
+ TQTextParagraph* s = prev() ? prev() : this;
+ while ( s ) {
+ s->tqinvalidate( 0 );
+ s = s->next();
+ }
+}
+
+int *TQTextParagraph::tabArray() const
+{
+ int *ta = tArray;
+ if ( !ta && hasdoc )
+ ta = document()->tabArray();
+ return ta;
+}
+
+int TQTextParagraph::nextTab( int, int x )
+{
+ int *ta = tArray;
+ if ( hasdoc ) {
+ if ( !ta )
+ ta = document()->tabArray();
+ tabStopWidth = document()->tabStopWidth();
+ }
+ if ( ta ) {
+ int i = 0;
+ while ( ta[ i ] ) {
+ if ( ta[ i ] >= x )
+ return tArray[ i ];
+ ++i;
+ }
+ return tArray[ 0 ];
+ } else {
+ int d;
+ if ( tabStopWidth != 0 )
+ d = x / tabStopWidth;
+ else
+ return x;
+ return tabStopWidth * ( d + 1 );
+ }
+}
+
+void TQTextParagraph::adjustToPainter( TQPainter *p )
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ for ( int i = 0; i < length(); ++i ) {
+ if ( at( i )->isCustom() )
+ at( i )->customItem()->adjustToPainter( p );
+ }
+#endif
+}
+
+TQTextFormatCollection *TQTextParagraph::formatCollection() const
+{
+ if ( hasdoc )
+ return document()->formatCollection();
+ TQTextFormatCollection* fc = &pseudoDocument()->collection;
+ if ( painttqdevice != fc->paintDevice() )
+ fc->setPaintDevice( painttqdevice );
+ return fc;
+}
+
+TQString TQTextParagraph::richText() const
+{
+ TQString s;
+ TQTextStringChar *formatChar = 0;
+ TQString spaces;
+ bool doStart = richTextExportStart && richTextExportStart->paragraph() == this;
+ bool doEnd = richTextExportEnd && richTextExportEnd->paragraph() == this;
+ int i;
+ TQString lastAnchorName;
+ for ( i = 0; i < length()-1; ++i ) {
+ if ( doStart && i && richTextExportStart->index() == i )
+ s += "<!--StartFragment-->";
+ if ( doEnd && richTextExportEnd->index() == i )
+ s += "<!--EndFragment-->";
+ TQTextStringChar *c = &str->at( i );
+ if ( c->isAnchor() && !c->anchorName().isEmpty() && c->anchorName() != lastAnchorName ) {
+ lastAnchorName = c->anchorName();
+ if ( c->anchorName().tqcontains( '#' ) ) {
+ TQStringList l = TQStringList::split( '#', c->anchorName() );
+ for ( TQStringList::ConstIterator it = l.begin(); it != l.end(); ++it )
+ s += "<a name=\"" + *it + "\"></a>";
+ } else {
+ s += "<a name=\"" + c->anchorName() + "\"></a>";
+ }
+ }
+ if ( !formatChar ) {
+ s += c->format()->makeFormatChangeTags( formatCollection()->defaultFormat(),
+ 0, TQString::null, c->anchorHref() );
+ formatChar = c;
+ } else if ( ( formatChar->format()->key() != c->format()->key() ) ||
+ (c->anchorHref() != formatChar->anchorHref() ) ) {
+ s += c->format()->makeFormatChangeTags( formatCollection()->defaultFormat(),
+ formatChar->format() , formatChar->anchorHref(), c->anchorHref() );
+ formatChar = c;
+ }
+ if ( c->c == '<' )
+ s += "&lt;";
+ else if ( c->c == '>' )
+ s += "&gt;";
+ else if ( c->c =='&' )
+ s += "&amp;";
+ else if ( c->c =='\"' )
+ s += "&quot;";
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ else if ( c->isCustom() )
+ s += c->customItem()->richText();
+#endif
+ else if ( c->c == '\n' || c->c == TQChar_linesep )
+ s += "<br />"; // space on purpose for compatibility with Netscape, Lynx & Co.
+ else
+ s += c->c;
+ }
+ if ( doEnd && richTextExportEnd->index() == i )
+ s += "<!--EndFragment-->";
+ if ( formatChar )
+ s += formatChar->format()->makeFormatEndTags( formatCollection()->defaultFormat(), formatChar->anchorHref() );
+ return s;
+}
+
+void TQTextParagraph::addCommand( TQTextCommand *cmd )
+{
+ if ( !hasdoc )
+ pseudoDocument()->commandHistory->addCommand( cmd );
+ else
+ document()->commands()->addCommand( cmd );
+}
+
+TQTextCursor *TQTextParagraph::undo( TQTextCursor *c )
+{
+ if ( !hasdoc )
+ return pseudoDocument()->commandHistory->undo( c );
+ return document()->commands()->undo( c );
+}
+
+TQTextCursor *TQTextParagraph::redo( TQTextCursor *c )
+{
+ if ( !hasdoc )
+ return pseudoDocument()->commandHistory->redo( c );
+ return document()->commands()->redo( c );
+}
+
+int TQTextParagraph::topMargin() const
+{
+ int m = 0;
+ if ( rtext ) {
+ m = isListItem() ? (document()->li_tm/TQMAX(1,listDepth()*listDepth())) :
+ ( listDepth() ? 0 : document()->par_tm );
+ if ( listDepth() == 1 &&( !prev() || prev()->listDepth() < listDepth() ) )
+ m = TQMAX( m, document()->list_tm );
+ }
+ m += utm;
+ return scale( m, TQTextFormat::painter() );
+}
+
+int TQTextParagraph::bottomMargin() const
+{
+ int m = 0;
+ if ( rtext ) {
+ m = isListItem() ? (document()->li_bm/TQMAX(1,listDepth()*listDepth())) :
+ ( listDepth() ? 0 : document()->par_bm );
+ if ( listDepth() == 1 &&( !next() || next()->listDepth() < listDepth() ) )
+ m = TQMAX( m, document()->list_bm );
+ }
+ m += ubm;
+ return scale( m, TQTextFormat::painter() );
+}
+
+int TQTextParagraph::leftMargin() const
+{
+ int m = ulm;
+ if ( listDepth() && !string()->isRightToLeft() )
+ m += listDepth() * document()->list_lm;
+ return scale( m, TQTextFormat::painter() );
+}
+
+int TQTextParagraph::firstLineMargin() const
+{
+ int m = uflm;
+ return scale( m, TQTextFormat::painter() );
+}
+
+int TQTextParagraph::rightMargin() const
+{
+ int m = urm;
+ if ( listDepth() && string()->isRightToLeft() )
+ m += listDepth() * document()->list_lm;
+ return scale( m, TQTextFormat::painter() );
+}
+
+int TQTextParagraph::lineSpacing() const
+{
+ int l = ulinespacing;
+ l = scale( l, TQTextFormat::painter() );
+ return l;
+}
+
+void TQTextParagraph::copyParagData( TQTextParagraph *parag )
+{
+ rtext = parag->rtext;
+ lstyle = parag->lstyle;
+ ldepth = parag->ldepth;
+ litem = parag->litem;
+ align = parag->align;
+ utm = parag->utm;
+ ubm = parag->ubm;
+ urm = parag->urm;
+ ulm = parag->ulm;
+ uflm = parag->uflm;
+ ulinespacing = parag->ulinespacing;
+ TQColor *c = parag->backgroundColor();
+ if ( c )
+ setBackgroundColor( *c );
+ str->setDirection( parag->str->direction() );
+}
+
+void TQTextParagraph::show()
+{
+ if ( visible || !hasdoc )
+ return;
+ visible = TRUE;
+}
+
+void TQTextParagraph::hide()
+{
+ if ( !visible || !hasdoc )
+ return;
+ visible = FALSE;
+}
+
+void TQTextParagraph::setDirection( TQChar::Direction d )
+{
+ if ( str && str->direction() != d ) {
+ str->setDirection( d );
+ tqinvalidate( 0 );
+ }
+}
+
+TQChar::Direction TQTextParagraph::direction() const
+{
+ return (str ? str->direction() : TQChar::DirON );
+}
+
+void TQTextParagraph::setChanged( bool b, bool recursive )
+{
+ changed = b;
+ if ( recursive ) {
+ if ( document() && document()->parentParagraph() )
+ document()->parentParagraph()->setChanged( b, recursive );
+ }
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+TQTextPreProcessor::TQTextPreProcessor()
+{
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatter::TQTextFormatter()
+ : thisminw(0), thiswused(0), wrapEnabled( TRUE ), wrapColumn( -1 ), biw( FALSE )
+{
+}
+
+TQTextLineStart *TQTextFormatter::formatLine( TQTextParagraph *parag, TQTextString *string, TQTextLineStart *line,
+ TQTextStringChar *startChar, TQTextStringChar *lastChar, int align, int space )
+{
+ if ( lastChar < startChar )
+ return new TQTextLineStart;
+#ifndef TQT_NO_COMPLEXTEXT
+ if( string->isBidi() )
+ return bidiReorderLine( parag, string, line, startChar, lastChar, align, space );
+#endif
+ int start = (startChar - &string->at(0));
+ int last = (lastChar - &string->at(0) );
+
+ // ignore white space at the end of the line.
+ TQTextStringChar *ch = lastChar;
+ while ( ch > startChar && ch->whiteSpace ) {
+ space += ch->format()->width( ' ' );
+ --ch;
+ }
+
+ if (space < 0)
+ space = 0;
+
+ // do tqalignment Auto == Left in this case
+ if ( align & TQt::AlignHCenter || align & TQt::AlignRight ) {
+ if ( align & TQt::AlignHCenter )
+ space /= 2;
+ for ( int j = start; j <= last; ++j )
+ string->at( j ).x += space;
+ } else if ( align & TQt::AlignJustify ) {
+ int numSpaces = 0;
+ // End at "last-1", the last space ends up with a width of 0
+ for ( int j = last-1; j >= start; --j ) {
+ // Start at last tab, if any.
+ TQTextStringChar &ch = string->at( j );
+ if ( ch.c == '\t' ) {
+ start = j+1;
+ break;
+ }
+ if(ch.whiteSpace)
+ numSpaces++;
+ }
+ int toAdd = 0;
+ for ( int k = start + 1; k <= last; ++k ) {
+ TQTextStringChar &ch = string->at( k );
+ if( numSpaces && ch.whiteSpace ) {
+ int s = space / numSpaces;
+ toAdd += s;
+ space -= s;
+ numSpaces--;
+ }
+ string->at( k ).x += toAdd;
+ }
+ }
+
+ if ( last >= 0 && last < string->length() )
+ line->w = string->at( last ).x + string->width( last );
+ else
+ line->w = 0;
+
+ return new TQTextLineStart;
+}
+
+#ifndef TQT_NO_COMPLEXTEXT
+
+#ifdef BIDI_DEBUG
+#include <iostream>
+#endif
+
+// collects one line of the paragraph and transforms it to visual order
+TQTextLineStart *TQTextFormatter::bidiReorderLine( TQTextParagraph * /*parag*/, TQTextString *text, TQTextLineStart *line,
+ TQTextStringChar *startChar, TQTextStringChar *lastChar, int align, int space )
+{
+ // ignore white space at the end of the line.
+ int endSpaces = 0;
+ while ( lastChar > startChar && lastChar->whiteSpace ) {
+ space += lastChar->format()->width( ' ' );
+ --lastChar;
+ ++endSpaces;
+ }
+
+ int start = (startChar - &text->at(0));
+ int last = (lastChar - &text->at(0) );
+
+ int length = lastChar - startChar + 1;
+
+
+ int x = startChar->x;
+
+ unsigned char _levels[256];
+ int _visual[256];
+
+ unsigned char *levels = _levels;
+ int *visual = _visual;
+
+ if ( length > 255 ) {
+ levels = (unsigned char *)malloc( length*sizeof( unsigned char ) );
+ visual = (int *)malloc( length*sizeof( int ) );
+ }
+
+ //qDebug("bidiReorderLine: length=%d (%d-%d)", length, start, last );
+
+ TQTextStringChar *ch = startChar;
+ unsigned char *l = levels;
+ while ( ch <= lastChar ) {
+ //qDebug( " level: %d", ch->bidiLevel );
+ *(l++) = (ch++)->bidiLevel;
+ }
+
+ TQTextEngine::bidiReorder( length, levels, visual );
+
+ // now construct the reordered string out of the runs...
+
+ int numSpaces = 0;
+ // set the correct tqalignment. This is a bit messy....
+ if( align == TQt::AlignAuto ) {
+ // align according to directionality of the paragraph...
+ if ( text->isRightToLeft() )
+ align = TQt::AlignRight;
+ }
+
+ // This is not really correct, but as we can't make the scrollbar move to the left of the origin,
+ // this ensures all text can be scrolled to and read.
+ if (space < 0)
+ space = 0;
+
+ if ( align & TQt::AlignHCenter )
+ x += space/2;
+ else if ( align & TQt::AlignRight )
+ x += space;
+ else if ( align & TQt::AlignJustify ) {
+ // End at "last-1", the last space ends up with a width of 0
+ for ( int j = last-1; j >= start; --j ) {
+ // Start at last tab, if any.
+ TQTextStringChar &ch = text->at( j );
+ if ( ch.c == '\t' ) {
+ start = j+1;
+ break;
+ }
+ if(ch.whiteSpace)
+ numSpaces++;
+ }
+ }
+
+ int toAdd = 0;
+ int xorig = x;
+ TQTextStringChar *lc = startChar + visual[0];
+ for ( int i = 0; i < length; i++ ) {
+ TQTextStringChar *ch = startChar + visual[i];
+ if (numSpaces && ch->whiteSpace) {
+ int s = space / numSpaces;
+ toAdd += s;
+ space -= s;
+ numSpaces--;
+ }
+
+ if (lc->format() != ch->format() && !ch->c.isSpace()
+ && lc->format()->font().italic() && !ch->format()->font().italic()) {
+ int rb = lc->format()->fontMetrics().rightBearing(lc->c);
+ if (rb < 0)
+ x -= rb;
+ }
+
+ ch->x = x + toAdd;
+ ch->rightToLeft = ch->bidiLevel % 2;
+ //qDebug("visual: %d (%x) placed at %d rightToLeft=%d", visual[i], ch->c.tqunicode(), x +toAdd, ch->rightToLeft );
+ int ww = 0;
+ if ( ch->c.tqunicode() >= 32 || ch->c == '\t' || ch->c == '\n' || ch->isCustom() ) {
+ ww = text->width( start+visual[i] );
+ } else {
+ ww = ch->format()->width( ' ' );
+ }
+ x += ww;
+ lc = ch;
+ }
+ x += toAdd;
+
+ while ( endSpaces-- ) {
+ ++lastChar;
+ int sw = lastChar->format()->width( ' ' );
+ if ( text->isRightToLeft() ) {
+ xorig -= sw;
+ lastChar->x = xorig;
+ ch->rightToLeft = TRUE;
+ } else {
+ lastChar->x = x;
+ x += sw;
+ ch->rightToLeft = FALSE;
+ }
+ }
+
+ line->w = x;
+
+ if ( length > 255 ) {
+ free( levels );
+ free( visual );
+ }
+
+ return new TQTextLineStart;
+}
+#endif
+
+
+void TQTextFormatter::insertLineStart( TQTextParagraph *parag, int index, TQTextLineStart *ls )
+{
+ QMap<int, TQTextLineStart*>::Iterator it;
+ if ( ( it = parag->lineStartList().tqfind( index ) ) == parag->lineStartList().end() ) {
+ parag->lineStartList().insert( index, ls );
+ } else {
+ delete *it;
+ parag->lineStartList().remove( it );
+ parag->lineStartList().insert( index, ls );
+ }
+}
+
+
+/* Standard pagebreak algorithm using TQTextFlow::adjustFlow. Returns
+ the shift of the paragraphs bottom line.
+ */
+int TQTextFormatter::formatVertically( TQTextDocument* doc, TQTextParagraph* parag )
+{
+ int oldHeight = parag->rect().height();
+ QMap<int, TQTextLineStart*>& lineStarts = parag->lineStartList();
+ QMap<int, TQTextLineStart*>::Iterator it = lineStarts.begin();
+ int h = parag->prev() ? TQMAX(parag->prev()->bottomMargin(),parag->topMargin() ) / 2: 0;
+ for ( ; it != lineStarts.end() ; ++it ) {
+ TQTextLineStart * ls = it.data();
+ ls->y = h;
+ TQTextStringChar *c = &parag->string()->at(it.key());
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( c && c->customItem() && c->customItem()->ownLine() ) {
+ int h = c->customItem()->height;
+ c->customItem()->pageBreak( parag->rect().y() + ls->y + ls->baseLine - h, doc->flow() );
+ int delta = c->customItem()->height - h;
+ ls->h += delta;
+ if ( delta )
+ parag->setMovedDown( TRUE );
+ } else
+#endif
+ {
+
+ int shift = doc->flow()->adjustFlow( parag->rect().y() + ls->y, ls->w, ls->h );
+ ls->y += shift;
+ if ( shift )
+ parag->setMovedDown( TRUE );
+ }
+ h = ls->y + ls->h;
+ }
+ int m = parag->bottomMargin();
+ if ( !parag->next() )
+ m = 0;
+ else
+ m = TQMAX(m, parag->next()->topMargin() ) / 2;
+ h += m;
+ parag->setHeight( h );
+ return h - oldHeight;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatterBreakInWords::TQTextFormatterBreakInWords()
+{
+}
+
+#define SPACE(s) s
+
+int TQTextFormatterBreakInWords::format( TQTextDocument *doc,TQTextParagraph *parag,
+ int start, const QMap<int, TQTextLineStart*> & )
+{
+ // make sure bidi information is correct.
+ (void )parag->string()->isBidi();
+
+ TQTextStringChar *c = 0;
+ TQTextStringChar *firstChar = 0;
+ int left = doc ? parag->leftMargin() + doc->leftMargin() : 0;
+ int x = left + ( doc ? parag->firstLineMargin() : 0 );
+ int dw = parag->documentVisibleWidth() - ( doc ? doc->rightMargin() : 0 );
+ int y = parag->prev() ? TQMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
+ int h = y;
+ int len = parag->length();
+ if ( doc )
+ x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 4 );
+ int rm = parag->rightMargin();
+ int w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
+ bool fullWidth = TRUE;
+ int minw = 0;
+ int wused = 0;
+ bool wrapEnabled = isWrapEnabled( parag );
+
+ start = 0; //######### what is the point with start?! (Matthias)
+ if ( start == 0 )
+ c = &parag->string()->at( 0 );
+
+ int i = start;
+ TQTextLineStart *lineStart = new TQTextLineStart( y, y, 0 );
+ insertLineStart( parag, 0, lineStart );
+
+ TQPainter *painter = TQTextFormat::painter();
+
+ int col = 0;
+ int ww = 0;
+ TQChar lastChr;
+ for ( ; i < len; ++i, ++col ) {
+ if ( c )
+ lastChr = c->c;
+ c = &parag->string()->at( i );
+ // ### the lines below should not be needed
+ if ( painter )
+ c->format()->setPainter( painter );
+ if ( i > 0 ) {
+ c->lineStart = 0;
+ } else {
+ c->lineStart = 1;
+ firstChar = c;
+ }
+ if ( c->c.tqunicode() >= 32 || c->isCustom() ) {
+ ww = parag->string()->width( i );
+ } else if ( c->c == '\t' ) {
+ int nx = parag->nextTab( i, x - left ) + left;
+ if ( nx < x )
+ ww = w - x;
+ else
+ ww = nx - x;
+ } else {
+ ww = c->format()->width( ' ' );
+ }
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ if ( c->isCustom() && c->customItem()->ownLine() ) {
+ x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
+ w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
+ c->customItem()->resize( w - x );
+ w = dw;
+ y += h;
+ h = c->height();
+ lineStart = new TQTextLineStart( y, h, h );
+ insertLineStart( parag, i, lineStart );
+ c->lineStart = 1;
+ firstChar = c;
+ x = 0xffffff;
+ continue;
+ }
+#endif
+
+ if ( wrapEnabled &&
+ ( ((wrapAtColumn() == -1) && (x + ww > w)) ||
+ ((wrapAtColumn() != -1) && (col >= wrapAtColumn())) ) ) {
+ x = doc ? parag->document()->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
+ w = dw;
+ y += h;
+ h = c->height();
+ lineStart = formatLine( parag, parag->string(), lineStart, firstChar, c-1 );
+ lineStart->y = y;
+ insertLineStart( parag, i, lineStart );
+ lineStart->baseLine = c->ascent();
+ lineStart->h = c->height();
+ c->lineStart = 1;
+ firstChar = c;
+ col = 0;
+ if ( wrapAtColumn() != -1 )
+ minw = TQMAX( minw, w );
+ } else if ( lineStart ) {
+ lineStart->baseLine = TQMAX( lineStart->baseLine, c->ascent() );
+ h = TQMAX( h, c->height() );
+ lineStart->h = h;
+ }
+
+ c->x = x;
+ x += ww;
+ wused = TQMAX( wused, x );
+ }
+
+ int m = parag->bottomMargin();
+ if ( !parag->next() )
+ m = 0;
+ else
+ m = TQMAX(m, parag->next()->topMargin() ) / 2;
+ parag->setFullWidth( fullWidth );
+ y += h + m;
+ if ( doc )
+ minw += doc->rightMargin();
+ if ( !wrapEnabled )
+ minw = TQMAX(minw, wused);
+
+ thisminw = minw;
+ thiswused = wused;
+ return y;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatterBreakWords::TQTextFormatterBreakWords()
+{
+}
+
+#define DO_FLOW( lineStart ) do{ if ( doc && doc->isPageBreakEnabled() ) { \
+ int yflow = lineStart->y + parag->rect().y();\
+ int shift = doc->flow()->adjustFlow( yflow, dw, lineStart->h ); \
+ lineStart->y += shift;\
+ y += shift;\
+ }}while(FALSE)
+
+int TQTextFormatterBreakWords::format( TQTextDocument *doc, TQTextParagraph *parag,
+ int start, const QMap<int, TQTextLineStart*> & )
+{
+ // make sure bidi information is correct.
+ (void )parag->string()->isBidi();
+
+ TQTextStringChar *c = 0;
+ TQTextStringChar *firstChar = 0;
+ TQTextString *string = parag->string();
+ int left = doc ? parag->leftMargin() + doc->leftMargin() : 0;
+ int x = left + ( doc ? parag->firstLineMargin() : 0 );
+ int y = parag->prev() ? TQMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
+ int h = y;
+ int len = parag->length();
+ if ( doc )
+ x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 0 );
+ int dw = parag->documentVisibleWidth() - ( doc ? ( left != x ? 0 : doc->rightMargin() ) : 0 );
+
+ int curLeft = x;
+ int rm = parag->rightMargin();
+ int rdiff = doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 0 ) : 0;
+ int w = dw - rdiff;
+ bool fullWidth = TRUE;
+ int marg = left + rdiff;
+ int minw = 0;
+ int wused = 0;
+ int tminw = marg;
+ int linespacing = doc ? parag->lineSpacing() : 0;
+ bool wrapEnabled = isWrapEnabled( parag );
+
+ start = 0;
+
+ int i = start;
+ TQTextLineStart *lineStart = new TQTextLineStart( y, y, 0 );
+ insertLineStart( parag, 0, lineStart );
+ int lastBreak = -1;
+ int tmpBaseLine = 0, tmph = 0;
+ bool lastWasNonInlineCustom = FALSE;
+
+ int align = parag->tqalignment();
+ if ( align == TQt::AlignAuto && doc && doc->tqalignment() != TQt::AlignAuto )
+ align = doc->tqalignment();
+
+ align &= TQt::AlignHorizontal_Mask;
+
+ // ### hack. The last char in the paragraph is always invisible,
+ // ### and somehow sometimes has a wrong format. It changes
+ // ### between // layouting and printing. This corrects some
+ // ### layouting errors in BiDi mode due to this.
+ if ( len > 1 ) {
+ c = &parag->string()->at(len - 1);
+ if (!c->isAnchor()) {
+ if (c->format())
+ c->format()->removeRef();
+ c->setFormat( string->at( len - 2 ).format() );
+ if (c->format())
+ c->format()->addRef();
+ }
+ }
+
+ c = &parag->string()->at( 0 );
+
+ TQPainter *painter = TQTextFormat::painter();
+ int col = 0;
+ int ww = 0;
+ TQChar lastChr = c->c;
+ TQTextFormat *lastFormat = c->format();
+ for ( ; i < len; ++i, ++col ) {
+ if ( i ) {
+ c = &parag->string()->at(i-1);
+ lastChr = c->c;
+ lastFormat = c->format();
+ }
+ bool lastWasOwnLineCustomItem = lastBreak == -2;
+ bool hadBreakableChar = lastBreak != -1;
+ bool lastWasHardBreak = lastChr == TQChar_linesep;
+
+ // ### next line should not be needed
+ if ( painter )
+ c->format()->setPainter( painter );
+ c = &string->at( i );
+
+ if (lastFormat != c->format() && !c->c.isSpace()
+ && lastFormat->font().italic() && !c->format()->font().italic()) {
+ int rb = lastFormat->fontMetrics().rightBearing(lastChr);
+ if (rb < 0)
+ x -= rb;
+ }
+
+ if ( ((i > 0) && (x > curLeft || ww == 0)) || lastWasNonInlineCustom ) {
+ c->lineStart = 0;
+ } else {
+ c->lineStart = 1;
+ firstChar = c;
+ }
+
+ // ignore non spacing marks for column count.
+ if (col != 0 && ::category(c->c) == TQChar::Mark_NonSpacing)
+ --col;
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ lastWasNonInlineCustom = ( c->isCustom() && c->customItem()->placement() != TQTextCustomItem::PlaceInline );
+#endif
+
+ if ( c->c.tqunicode() >= 32 || c->isCustom() ) {
+ ww = string->width( i );
+ } else if ( c->c == '\t' ) {
+ if ( align == TQt::AlignRight || align == TQt::AlignCenter ) {
+ // we can not (yet) do tabs
+ ww = c->format()->width(' ' );
+ } else {
+ int tabx = lastWasHardBreak ? (left + ( doc ? parag->firstLineMargin() : 0 )) : x;
+ int nx = parag->nextTab( i, tabx - left ) + left;
+ if ( nx < tabx ) // strrrange...
+ ww = 0;
+ else
+ ww = nx - tabx;
+ }
+ } else {
+ ww = c->format()->width( ' ' );
+ }
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem* ci = c->customItem();
+ if ( c->isCustom() && ci->ownLine() ) {
+ TQTextLineStart *lineStart2 = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x - ww) );
+ x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
+ w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
+ ci->resize(w - x);
+ if ( ci->width < w - x ) {
+ if ( align & TQt::AlignHCenter )
+ x = ( w - ci->width ) / 2;
+ else if ( align & TQt::AlignRight ) {
+ x = w - ci->width;
+ }
+ }
+ c->x = x;
+ curLeft = x;
+ if ( i == 0 || !isBreakable(string, i-1) ||
+ string->at( i - 1 ).lineStart == 0 ) {
+ y += TQMAX( h, TQMAX( tmph, linespacing ) );
+ tmph = c->height();
+ h = tmph;
+ lineStart = lineStart2;
+ lineStart->y = y;
+ insertLineStart( parag, i, lineStart );
+ c->lineStart = 1;
+ firstChar = c;
+ } else {
+ tmph = c->height();
+ h = tmph;
+ delete lineStart2;
+ }
+ lineStart->h = h;
+ lineStart->baseLine = h;
+ tmpBaseLine = lineStart->baseLine;
+ lastBreak = -2;
+ x = w;
+ minw = TQMAX( minw, tminw );
+
+ int tw = ci->minimumWidth() + ( doc ? doc->leftMargin() : 0 );
+ if ( tw < TQWIDGETSIZE_MAX )
+ tminw = tw;
+ else
+ tminw = marg;
+ wused = TQMAX( wused, ci->width );
+ continue;
+ } else if ( c->isCustom() && ci->placement() != TQTextCustomItem::PlaceInline ) {
+ int tw = ci->minimumWidth();
+ if ( tw < TQWIDGETSIZE_MAX )
+ minw = TQMAX( minw, tw );
+ }
+#endif
+ // we break if
+ // 1. the last character was a hard break (TQChar_linesep) or
+ // 2. the last charater was a own-line custom item (eg. table or ruler) or
+ // 3. wrapping was enabled, it was not a space and following
+ // condition is true: We either had a breakable character
+ // previously or we ar allowed to break in words and - either
+ // we break at w pixels and the current char would exceed that
+ // or - we break at a column and the current character would
+ // exceed that.
+ if ( lastWasHardBreak || lastWasOwnLineCustomItem ||
+ ( wrapEnabled &&
+ ( (!c->c.isSpace() && (hadBreakableChar || allowBreakInWords()) &&
+ ( (wrapAtColumn() == -1 && x + ww > w) ||
+ (wrapAtColumn() != -1 && col >= wrapAtColumn()) ) ) )
+ )
+ ) {
+ if ( wrapAtColumn() != -1 )
+ minw = TQMAX( minw, x + ww );
+ // if a break was forced (no breakable char, hard break or own line custom item), break immediately....
+ if ( !hadBreakableChar || lastWasHardBreak || lastWasOwnLineCustomItem ) {
+ if ( lineStart ) {
+ lineStart->baseLine = TQMAX( lineStart->baseLine, tmpBaseLine );
+ h = TQMAX( h, tmph );
+ lineStart->h = h;
+ DO_FLOW( lineStart );
+ }
+ lineStart = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x) );
+ x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
+ w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
+ if ( !doc && c->c == '\t' ) { // qt_format_text tab handling
+ int nx = parag->nextTab( i, x - left ) + left;
+ if ( nx < x )
+ ww = w - x;
+ else
+ ww = nx - x;
+ }
+ curLeft = x;
+ y += TQMAX( h, linespacing );
+ tmph = c->height();
+ h = 0;
+ lineStart->y = y;
+ insertLineStart( parag, i, lineStart );
+ lineStart->baseLine = c->ascent();
+ lineStart->h = c->height();
+ c->lineStart = 1;
+ firstChar = c;
+ tmpBaseLine = lineStart->baseLine;
+ lastBreak = -1;
+ col = 0;
+ if ( allowBreakInWords() || lastWasHardBreak ) {
+ minw = TQMAX(minw, tminw);
+ tminw = marg + ww;
+ }
+ } else { // ... otherwise if we had a breakable char, break there
+ DO_FLOW( lineStart );
+ c->x = x;
+ i = lastBreak;
+ lineStart = formatLine( parag, string, lineStart, firstChar, parag->at( lastBreak ),align, SPACE(w - string->at( i+1 ).x) );
+ x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
+ w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
+ if ( !doc && c->c == '\t' ) { // qt_format_text tab handling
+ int nx = parag->nextTab( i, x - left ) + left;
+ if ( nx < x )
+ ww = w - x;
+ else
+ ww = nx - x;
+ }
+ curLeft = x;
+ y += TQMAX( h, linespacing );
+ tmph = c->height();
+ h = tmph;
+ lineStart->y = y;
+ insertLineStart( parag, i + 1, lineStart );
+ lineStart->baseLine = c->ascent();
+ lineStart->h = c->height();
+ c->lineStart = 1;
+ firstChar = c;
+ tmpBaseLine = lineStart->baseLine;
+ lastBreak = -1;
+ col = 0;
+ minw = TQMAX(minw, tminw);
+ tminw = marg;
+ continue;
+ }
+ } else if (lineStart && isBreakable(string, i)) {
+ if ( len <= 2 || i < len - 1 ) {
+ tmpBaseLine = TQMAX( tmpBaseLine, c->ascent() );
+ tmph = TQMAX( tmph, c->height() );
+ }
+ minw = TQMAX( minw, tminw );
+
+ tminw = marg + ww;
+ lineStart->baseLine = TQMAX( lineStart->baseLine, tmpBaseLine );
+ h = TQMAX( h, tmph );
+ lineStart->h = h;
+ if ( i < len - 2 || c->c != ' ' )
+ lastBreak = i;
+ } else {
+ tminw += ww;
+ int cascent = c->ascent();
+ int cheight = c->height();
+ int belowBaseLine = TQMAX( tmph - tmpBaseLine, cheight-cascent );
+ tmpBaseLine = TQMAX( tmpBaseLine, cascent );
+ tmph = tmpBaseLine + belowBaseLine;
+ }
+
+ c->x = x;
+ x += ww;
+ wused = TQMAX( wused, x );
+ }
+
+ if ( lineStart ) {
+ lineStart->baseLine = TQMAX( lineStart->baseLine, tmpBaseLine );
+ h = TQMAX( h, tmph );
+ lineStart->h = h;
+ // last line in a paragraph is not justified
+ if ( align == TQt::AlignJustify )
+ align = TQt::AlignAuto;
+ DO_FLOW( lineStart );
+ lineStart = formatLine( parag, string, lineStart, firstChar, c, align, SPACE(w - x) );
+ delete lineStart;
+ }
+
+ minw = TQMAX( minw, tminw );
+ if ( doc )
+ minw += doc->rightMargin();
+
+ int m = parag->bottomMargin();
+ if ( !parag->next() )
+ m = 0;
+ else
+ m = TQMAX(m, parag->next()->topMargin() ) / 2;
+ parag->setFullWidth( fullWidth );
+ y += TQMAX( h, linespacing ) + m;
+
+ wused += rm;
+ if ( !wrapEnabled || wrapAtColumn() != -1 )
+ minw = TQMAX(minw, wused);
+
+ // This is the case where we are breaking wherever we darn well please
+ // in cases like that, the minw should not be the length of the entire
+ // word, because we necessarily want to show the word on the whole line.
+ // example: word wrap in iconview
+ if ( allowBreakInWords() && minw > wused )
+ minw = wused;
+
+ thisminw = minw;
+ thiswused = wused;
+ return y;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextIndent::TQTextIndent()
+{
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+TQTextFormatCollection::TQTextFormatCollection()
+ : cKey( 307 ), painttqdevice( 0 )
+{
+ defFormat = new TQTextFormat( TQApplication::font(),
+ TQApplication::palette().color( TQPalette::Active, TQColorGroup::Text ) );
+ lastFormat = cres = 0;
+ cflags = -1;
+ cKey.setAutoDelete( TRUE );
+ cachedFormat = 0;
+}
+
+TQTextFormatCollection::~TQTextFormatCollection()
+{
+ delete defFormat;
+}
+
+void TQTextFormatCollection::setPaintDevice( TQPaintDevice *pd )
+{
+ painttqdevice = pd;
+
+#if defined(TQ_WS_X11)
+ int scr = ( painttqdevice ) ? painttqdevice->x11Screen() : TQPaintDevice::x11AppScreen();
+
+ defFormat->fn.tqt_x11SetScreen( scr );
+ defFormat->update();
+
+ TQDictIterator<TQTextFormat> it( cKey );
+ TQTextFormat *format;
+ while ( ( format = it.current() ) != 0 ) {
+ ++it;
+ format->fn.tqt_x11SetScreen( scr );
+ format->update();
+ }
+#endif // TQ_WS_X11
+}
+
+TQTextFormat *TQTextFormatCollection::format( TQTextFormat *f )
+{
+ if ( f->tqparent() == this || f == defFormat ) {
+ lastFormat = f;
+ lastFormat->addRef();
+ return lastFormat;
+ }
+
+ if ( f == lastFormat || ( lastFormat && f->key() == lastFormat->key() ) ) {
+ lastFormat->addRef();
+ return lastFormat;
+ }
+
+ TQTextFormat *fm = cKey.tqfind( f->key() );
+ if ( fm ) {
+ lastFormat = fm;
+ lastFormat->addRef();
+ return lastFormat;
+ }
+
+ if ( f->key() == defFormat->key() )
+ return defFormat;
+
+ lastFormat = createFormat( *f );
+ lastFormat->collection = this;
+ cKey.insert( lastFormat->key(), lastFormat );
+ return lastFormat;
+}
+
+TQTextFormat *TQTextFormatCollection::format( TQTextFormat *of, TQTextFormat *nf, int flags )
+{
+ if ( cres && kof == of->key() && knf == nf->key() && cflags == flags ) {
+ cres->addRef();
+ return cres;
+ }
+
+ cres = createFormat( *of );
+ kof = of->key();
+ knf = nf->key();
+ cflags = flags;
+ if ( flags & TQTextFormat::Bold )
+ cres->fn.setBold( nf->fn.bold() );
+ if ( flags & TQTextFormat::Italic )
+ cres->fn.setItalic( nf->fn.italic() );
+ if ( flags & TQTextFormat::Underline )
+ cres->fn.setUnderline( nf->fn.underline() );
+ if ( flags & TQTextFormat::StrikeOut )
+ cres->fn.setStrikeOut( nf->fn.strikeOut() );
+ if ( flags & TQTextFormat::Family )
+ cres->fn.setFamily( nf->fn.family() );
+ if ( flags & TQTextFormat::Size ) {
+ if ( of->usePixelSizes )
+ cres->fn.setPixelSize( nf->fn.pixelSize() );
+ else
+ cres->fn.setPointSize( nf->fn.pointSize() );
+ }
+ if ( flags & TQTextFormat::Color )
+ cres->col = nf->col;
+ if ( flags & TQTextFormat::Misspelled )
+ cres->missp = nf->missp;
+ if ( flags & TQTextFormat::VAlign )
+ cres->ha = nf->ha;
+ cres->update();
+
+ TQTextFormat *fm = cKey.tqfind( cres->key() );
+ if ( !fm ) {
+ cres->collection = this;
+ cKey.insert( cres->key(), cres );
+ } else {
+ delete cres;
+ cres = fm;
+ cres->addRef();
+ }
+
+ return cres;
+}
+
+TQTextFormat *TQTextFormatCollection::format( const TQFont &f, const TQColor &c )
+{
+ if ( cachedFormat && cfont == f && ccol == c ) {
+ cachedFormat->addRef();
+ return cachedFormat;
+ }
+
+ TQString key = TQTextFormat::getKey( f, c, FALSE, TQTextFormat::AlignNormal );
+ cachedFormat = cKey.tqfind( key );
+ cfont = f;
+ ccol = c;
+
+ if ( cachedFormat ) {
+ cachedFormat->addRef();
+ return cachedFormat;
+ }
+
+ if ( key == defFormat->key() )
+ return defFormat;
+
+ cachedFormat = createFormat( f, c );
+ cachedFormat->collection = this;
+ cKey.insert( cachedFormat->key(), cachedFormat );
+ if ( cachedFormat->key() != key )
+ qWarning("ASSERT: keys for format not identical: '%s '%s'", cachedFormat->key().latin1(), key.latin1() );
+ return cachedFormat;
+}
+
+void TQTextFormatCollection::remove( TQTextFormat *f )
+{
+ if ( lastFormat == f )
+ lastFormat = 0;
+ if ( cres == f )
+ cres = 0;
+ if ( cachedFormat == f )
+ cachedFormat = 0;
+ if (cKey.tqfind(f->key()) == f)
+ cKey.remove( f->key() );
+}
+
+#define UPDATE( up, lo, rest ) \
+ if ( font.lo##rest() != defFormat->fn.lo##rest() && fm->fn.lo##rest() == defFormat->fn.lo##rest() ) \
+ fm->fn.set##up##rest( font.lo##rest() )
+
+void TQTextFormatCollection::updateDefaultFormat( const TQFont &font, const TQColor &color, TQStyleSheet *sheet )
+{
+ TQDictIterator<TQTextFormat> it( cKey );
+ TQTextFormat *fm;
+ bool usePixels = font.pointSize() == -1;
+ bool changeSize = usePixels ? font.pixelSize() != defFormat->fn.pixelSize() :
+ font.pointSize() != defFormat->fn.pointSize();
+ int base = usePixels ? font.pixelSize() : font.pointSize();
+ while ( ( fm = it.current() ) ) {
+ ++it;
+ UPDATE( F, f, amily );
+ UPDATE( W, w, eight );
+ UPDATE( B, b, old );
+ UPDATE( I, i, talic );
+ UPDATE( U, u, nderline );
+ if ( changeSize ) {
+ fm->stdSize = base;
+ fm->usePixelSizes = usePixels;
+ if ( usePixels )
+ fm->fn.setPixelSize( fm->stdSize );
+ else
+ fm->fn.setPointSize( fm->stdSize );
+ sheet->scaleFont( fm->fn, fm->logicalFontSize );
+ }
+ if ( color.isValid() && color != defFormat->col && fm->col == defFormat->col )
+ fm->col = color;
+ fm->update();
+ }
+
+ defFormat->fn = font;
+ defFormat->col = color;
+ defFormat->update();
+ defFormat->stdSize = base;
+ defFormat->usePixelSizes = usePixels;
+
+ updateKeys();
+}
+
+// the keys in cKey have changed, rebuild the hashtable
+void TQTextFormatCollection::updateKeys()
+{
+ if ( cKey.isEmpty() )
+ return;
+ cKey.setAutoDelete( FALSE );
+ TQTextFormat** formats = new TQTextFormat*[ cKey.count() + 1 ];
+ TQTextFormat **f = formats;
+ TQDictIterator<TQTextFormat> it( cKey );
+ while ( ( *f = it.current() ) ) {
+ ++it;
+ ++f;
+ }
+ cKey.clear();
+ for ( f = formats; *f; f++ )
+ cKey.insert( (*f)->key(), *f );
+ cKey.setAutoDelete( TRUE );
+ delete [] formats;
+}
+
+
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+void TQTextFormat::setBold( bool b )
+{
+ if ( b == fn.bold() )
+ return;
+ fn.setBold( b );
+ update();
+}
+
+void TQTextFormat::setMisspelled( bool b )
+{
+ if ( b == (bool)missp )
+ return;
+ missp = b;
+ update();
+}
+
+void TQTextFormat::setVAlign( VerticalAlignment a )
+{
+ if ( a == ha )
+ return;
+ ha = a;
+ update();
+}
+
+void TQTextFormat::setItalic( bool b )
+{
+ if ( b == fn.italic() )
+ return;
+ fn.setItalic( b );
+ update();
+}
+
+void TQTextFormat::setUnderline( bool b )
+{
+ if ( b == fn.underline() )
+ return;
+ fn.setUnderline( b );
+ update();
+}
+
+void TQTextFormat::setStrikeOut( bool b )
+{
+ if ( b == fn.strikeOut() )
+ return;
+ fn.setStrikeOut( b );
+ update();
+}
+
+void TQTextFormat::setFamily( const TQString &f )
+{
+ if ( f == fn.family() )
+ return;
+ fn.setFamily( f );
+ update();
+}
+
+void TQTextFormat::setPointSize( int s )
+{
+ if ( s == fn.pointSize() )
+ return;
+ fn.setPointSize( s );
+ usePixelSizes = FALSE;
+ update();
+}
+
+void TQTextFormat::setFont( const TQFont &f )
+{
+ if ( f == fn && !k.isEmpty() )
+ return;
+ fn = f;
+ update();
+}
+
+void TQTextFormat::setColor( const TQColor &c )
+{
+ if ( c == col )
+ return;
+ col = c;
+ update();
+}
+
+TQString TQTextFormat::makeFormatChangeTags( TQTextFormat* defaultFormat, TQTextFormat *f,
+ const TQString& oldAnchorHref, const TQString& anchorHref ) const
+{
+ TQString tag;
+ if ( f )
+ tag += f->makeFormatEndTags( defaultFormat, oldAnchorHref );
+
+ if ( !anchorHref.isEmpty() )
+ tag += "<a href=\"" + anchorHref + "\">";
+
+ if ( font() != defaultFormat->font()
+ || vAlign() != defaultFormat->vAlign()
+ || color().rgb() != defaultFormat->color().rgb() ) {
+ TQString s;
+ if ( font().family() != defaultFormat->font().family() )
+ s += TQString(!!s?";":"") + "font-family:" + fn.family();
+ if ( font().italic() && font().italic() != defaultFormat->font().italic() )
+ s += TQString(!!s?";":"") + "font-style:" + (font().italic() ? "italic" : "normal");
+ if ( font().pointSize() != defaultFormat->font().pointSize() )
+ s += TQString(!!s?";":"") + "font-size:" + TQString::number( fn.pointSize() ) + "pt";
+ if ( font().weight() != defaultFormat->font().weight() )
+ s += TQString(!!s?";":"") + "font-weight:" + TQString::number( fn.weight() * 8 );
+ TQString textDecoration;
+ bool none = FALSE;
+ if ( font().underline() != defaultFormat->font().underline() ) {
+ if (font().underline())
+ textDecoration = "underline";
+ else
+ none = TRUE;
+ }
+ if ( font().overline() != defaultFormat->font().overline() ) {
+ if (font().overline())
+ textDecoration += " overline";
+ else
+ none = TRUE;
+ }
+ if ( font().strikeOut() != defaultFormat->font().strikeOut() ) {
+ if (font().strikeOut())
+ textDecoration += " line-through";
+ else
+ none = TRUE;
+ }
+ if (none && textDecoration.isEmpty())
+ textDecoration = "none";
+ if (!textDecoration.isEmpty())
+ s += TQString(!!s?";":"") + "text-decoration:" + textDecoration;
+ if ( vAlign() != defaultFormat->vAlign() ) {
+ s += TQString(!!s?";":"") + "vertical-align:";
+ if ( vAlign() == TQTextFormat::AlignSuperScript )
+ s += "super";
+ else if ( vAlign() == TQTextFormat::AlignSubScript )
+ s += "sub";
+ else
+ s += "normal";
+ }
+ if ( color().rgb() != defaultFormat->color().rgb() )
+ s += TQString(!!s?";":"") + "color:" + col.name();
+ if ( !s.isEmpty() )
+ tag += "<span style=\"" + s + "\">";
+ }
+
+ return tag;
+}
+
+TQString TQTextFormat::makeFormatEndTags( TQTextFormat* defaultFormat, const TQString& anchorHref ) const
+{
+ TQString tag;
+ if ( font().family() != defaultFormat->font().family()
+ || font().pointSize() != defaultFormat->font().pointSize()
+ || font().weight() != defaultFormat->font().weight()
+ || font().italic() != defaultFormat->font().italic()
+ || font().underline() != defaultFormat->font().underline()
+ || font().strikeOut() != defaultFormat->font().strikeOut()
+ || vAlign() != defaultFormat->vAlign()
+ || color().rgb() != defaultFormat->color().rgb() )
+ tag += "</span>";
+ if ( !anchorHref.isEmpty() )
+ tag += "</a>";
+ return tag;
+}
+
+TQTextFormat TQTextFormat::makeTextFormat( const TQStyleSheetItem *style, const QMap<TQString,TQString>& attr, double scaleFontsFactor ) const
+{
+ TQTextFormat format(*this);
+ if (!style )
+ return format;
+
+ if ( !style->isAnchor() && style->color().isValid() ) {
+ // the style is not an anchor and defines a color.
+ // It might be used inside an anchor and it should
+ // override the link color.
+ format.linkColor = FALSE;
+ }
+ switch ( style->verticalAlignment() ) {
+ case TQStyleSheetItem::VAlignBaseline:
+ format.setVAlign( TQTextFormat::AlignNormal );
+ break;
+ case TQStyleSheetItem::VAlignSuper:
+ format.setVAlign( TQTextFormat::AlignSuperScript );
+ break;
+ case TQStyleSheetItem::VAlignSub:
+ format.setVAlign( TQTextFormat::AlignSubScript );
+ break;
+ }
+
+ if ( style->fontWeight() != TQStyleSheetItem::Undefined )
+ format.fn.setWeight( style->fontWeight() );
+ if ( style->fontSize() != TQStyleSheetItem::Undefined ) {
+ format.fn.setPointSize( style->fontSize() );
+ } else if ( style->logicalFontSize() != TQStyleSheetItem::Undefined ) {
+ format.logicalFontSize = style->logicalFontSize();
+ if ( format.usePixelSizes )
+ format.fn.setPixelSize( format.stdSize );
+ else
+ format.fn.setPointSize( format.stdSize );
+ style->styleSheet()->scaleFont( format.fn, format.logicalFontSize );
+ } else if ( style->logicalFontSizeStep() ) {
+ format.logicalFontSize += style->logicalFontSizeStep();
+ if ( format.usePixelSizes )
+ format.fn.setPixelSize( format.stdSize );
+ else
+ format.fn.setPointSize( format.stdSize );
+ style->styleSheet()->scaleFont( format.fn, format.logicalFontSize );
+ }
+ if ( !style->fontFamily().isEmpty() )
+ format.fn.setFamily( style->fontFamily() );
+ if ( style->color().isValid() )
+ format.col = style->color();
+ if ( style->definesFontItalic() )
+ format.fn.setItalic( style->fontItalic() );
+ if ( style->definesFontUnderline() )
+ format.fn.setUnderline( style->fontUnderline() );
+ if ( style->definesFontStrikeOut() )
+ format.fn.setStrikeOut( style->fontStrikeOut() );
+
+
+ if ( style->name() == "font") {
+ if ( attr.tqcontains("color") ) {
+ TQString s = attr["color"];
+ if ( !s.isEmpty() ) {
+ format.col.setNamedColor( s );
+ format.linkColor = FALSE;
+ }
+ }
+ if ( attr.tqcontains("face") ) {
+ TQString a = attr["face"];
+ TQString family = a.section( ',', 0, 0 );
+ if ( !!family )
+ format.fn.setFamily( family );
+ }
+ if ( attr.tqcontains("size") ) {
+ TQString a = attr["size"];
+ int n = a.toInt();
+ if ( a[0] == '+' || a[0] == '-' )
+ n += 3;
+ format.logicalFontSize = n;
+ if ( format.usePixelSizes )
+ format.fn.setPixelSize( format.stdSize );
+ else
+ format.fn.setPointSize( format.stdSize );
+ style->styleSheet()->scaleFont( format.fn, format.logicalFontSize );
+ }
+ }
+ if ( attr.tqcontains("style" ) ) {
+ TQString a = attr["style"];
+ for ( int s = 0; s < a.tqcontains(';')+1; s++ ) {
+ TQString style = a.section( ';', s, s );
+ if ( style.startsWith("font-size:" ) && style.endsWith("pt") ) {
+ format.logicalFontSize = 0;
+ int size = int( scaleFontsFactor * style.mid( 10, style.length() - 12 ).toDouble() );
+ format.setPointSize( size );
+ } else if ( style.startsWith("font-style:" ) ) {
+ TQString s = TQT_TQSTRING(style.mid( 11 )).stripWhiteSpace();
+ if ( s == "normal" )
+ format.fn.setItalic( FALSE );
+ else if ( s == "italic" || s == "oblique" )
+ format.fn.setItalic( TRUE );
+ } else if ( style.startsWith("font-weight:" ) ) {
+ TQString s = style.mid( 12 );
+ bool ok = TRUE;
+ int n = s.toInt( &ok );
+ if ( ok )
+ format.fn.setWeight( n/8 );
+ } else if ( style.startsWith("font-family:" ) ) {
+ TQString family = style.mid(12).section(',',0,0);
+ family.tqreplace( '\"', ' ' );
+ family.tqreplace( '\'', ' ' );
+ family = family.stripWhiteSpace();
+ format.fn.setFamily( family );
+ } else if ( style.startsWith("text-decoration:" ) ) {
+ TQString s = style.mid( 16 );
+ format.fn.setOverline( s.tqfind("overline") != -1 );
+ format.fn.setStrikeOut( s.tqfind("line-through") != -1 );
+ format.fn.setUnderline( s.tqfind("underline") != -1 );
+ } else if ( style.startsWith("vertical-align:" ) ) {
+ TQString s = TQT_TQSTRING(style.mid( 15 )).stripWhiteSpace();
+ if ( s == "sub" )
+ format.setVAlign( TQTextFormat::AlignSubScript );
+ else if ( s == "super" )
+ format.setVAlign( TQTextFormat::AlignSuperScript );
+ else
+ format.setVAlign( TQTextFormat::AlignNormal );
+ } else if ( style.startsWith("color:" ) ) {
+ format.col.setNamedColor( style.mid(6) );
+ format.linkColor = FALSE;
+ }
+ }
+ }
+
+ format.update();
+ return format;
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+
+struct TQPixmapInt
+{
+ TQPixmapInt() : ref( 0 ) {}
+ TQPixmap pm;
+ int ref;
+ TQ_DUMMY_COMPARISON_OPERATOR(TQPixmapInt)
+};
+
+static QMap<TQString, TQPixmapInt> *pixmap_map = 0;
+
+TQTextImage::TQTextImage( TQTextDocument *p, const QMap<TQString, TQString> &attr, const TQString& context,
+ TQMimeSourceFactory &factory )
+ : TQTextCustomItem( p )
+{
+ width = height = 0;
+ if ( attr.tqcontains("width") )
+ width = attr["width"].toInt();
+ if ( attr.tqcontains("height") )
+ height = attr["height"].toInt();
+
+ reg = 0;
+ TQString imageName = attr["src"];
+
+ if (!imageName)
+ imageName = attr["source"];
+
+ if ( !imageName.isEmpty() ) {
+ imgId = TQString( "%1,%2,%3,%4" ).arg( imageName ).arg( width ).arg( height ).arg( (ulong)&factory );
+ if ( !pixmap_map )
+ pixmap_map = new QMap<TQString, TQPixmapInt>;
+ if ( pixmap_map->tqcontains( imgId ) ) {
+ TQPixmapInt& pmi = pixmap_map->operator[](imgId);
+ pm = pmi.pm;
+ pmi.ref++;
+ width = pm.width();
+ height = pm.height();
+ } else {
+ TQImage img;
+ const TQMimeSource* m =
+ factory.data( imageName, context );
+ if ( !m ) {
+ qWarning("TQTextImage: no mimesource for %s", imageName.latin1() );
+ }
+ else {
+ if ( !TQImageDrag::decode( m, img ) ) {
+ qWarning("TQTextImage: cannot decode %s", imageName.latin1() );
+ }
+ }
+
+ if ( !img.isNull() ) {
+ if ( width == 0 ) {
+ width = img.width();
+ if ( height != 0 ) {
+ width = img.width() * height / img.height();
+ }
+ }
+ if ( height == 0 ) {
+ height = img.height();
+ if ( width != img.width() ) {
+ height = img.height() * width / img.width();
+ }
+ }
+ if ( img.width() != width || img.height() != height ){
+#ifndef TQT_NO_IMAGE_SMOOTHSCALE
+ img = img.smoothScale(width, height);
+#endif
+ width = img.width();
+ height = img.height();
+ }
+ pm.convertFromImage( img );
+ }
+ if ( !pm.isNull() ) {
+ TQPixmapInt& pmi = pixmap_map->operator[](imgId);
+ pmi.pm = pm;
+ pmi.ref++;
+ }
+ }
+ if ( pm.tqmask() ) {
+ TQRegion tqmask( *pm.tqmask() );
+ TQRegion all( 0, 0, pm.width(), pm.height() );
+ reg = new TQRegion( all.subtract( tqmask ) );
+ }
+ }
+
+ if ( pm.isNull() && (width*height)==0 )
+ width = height = 50;
+
+ place = PlaceInline;
+ if ( attr["align"] == "left" )
+ place = PlaceLeft;
+ else if ( attr["align"] == "right" )
+ place = PlaceRight;
+
+ tmpwidth = width;
+ tmpheight = height;
+
+ attributes = attr;
+}
+
+TQTextImage::~TQTextImage()
+{
+ if ( pixmap_map && pixmap_map->tqcontains( imgId ) ) {
+ TQPixmapInt& pmi = pixmap_map->operator[](imgId);
+ pmi.ref--;
+ if ( !pmi.ref ) {
+ pixmap_map->remove( imgId );
+ if ( pixmap_map->isEmpty() ) {
+ delete pixmap_map;
+ pixmap_map = 0;
+ }
+ }
+ }
+ delete reg;
+}
+
+TQString TQTextImage::richText() const
+{
+ TQString s;
+ s += "<img ";
+ QMap<TQString, TQString>::ConstIterator it = attributes.begin();
+ for ( ; it != attributes.end(); ++it ) {
+ s += it.key() + "=";
+ if ( (*it).tqfind( ' ' ) != -1 )
+ s += "\"" + *it + "\"" + " ";
+ else
+ s += *it + " ";
+ }
+ s += ">";
+ return s;
+}
+
+void TQTextImage::adjustToPainter( TQPainter* p )
+{
+ width = scale( tmpwidth, p );
+ height = scale( tmpheight, p );
+}
+
+#if !defined(TQ_WS_X11)
+#include <tqbitmap.h>
+#include <tqcleanuphandler.h>
+static TQPixmap *qrt_selection = 0;
+static TQSingleCleanupHandler<TQPixmap> qrt_cleanup_pixmap;
+static void qrt_createSelectionPixmap( const TQColorGroup &cg )
+{
+ qrt_selection = new TQPixmap( 2, 2 );
+ qrt_cleanup_pixmap.set( &qrt_selection );
+ qrt_selection->fill( TQt::color0 );
+ TQBitmap m( 2, 2 );
+ m.fill( TQt::color1 );
+ TQPainter p( &m );
+ p.setPen( TQt::color0 );
+ for ( int j = 0; j < 2; ++j ) {
+ p.drawPoint( j % 2, j );
+ }
+ p.end();
+ qrt_selection->setMask( m );
+ qrt_selection->fill( cg.highlight() );
+}
+#endif
+
+void TQTextImage::draw( TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected )
+{
+ if ( placement() != PlaceInline ) {
+ x = xpos;
+ y = ypos;
+ }
+
+ if ( pm.isNull() ) {
+ p->fillRect( x , y, width, height, cg.dark() );
+ return;
+ }
+
+ if ( is_printer( p ) ) {
+ p->drawPixmap( TQRect( x, y, width, height ), pm );
+ return;
+ }
+
+ if ( placement() != PlaceInline && !TQRect( xpos, ypos, width, height ).intersects( TQRect( cx, cy, cw, ch ) ) )
+ return;
+
+ if ( placement() == PlaceInline )
+ p->drawPixmap( x , y, pm );
+ else
+ p->drawPixmap( cx , cy, pm, cx - x, cy - y, cw, ch );
+
+ if ( selected && placement() == PlaceInline && is_printer( p ) ) {
+#if defined(TQ_WS_X11)
+ p->fillRect( TQRect( TQPoint( x, y ), pm.size() ), TQBrush( cg.highlight(), Qt::Dense4Pattern) );
+#else // in WIN32 Dense4Pattern doesn't work correctly (transparency problem), so work around it
+ if ( !qrt_selection )
+ qrt_createSelectionPixmap( cg );
+ p->drawTiledPixmap( x, y, pm.width(), pm.height(), *qrt_selection );
+#endif
+ }
+}
+
+void TQTextHorizontalLine::adjustToPainter( TQPainter* p )
+{
+ height = scale( tmpheight, p );
+}
+
+
+TQTextHorizontalLine::TQTextHorizontalLine( TQTextDocument *p, const QMap<TQString, TQString> &attr,
+ const TQString &,
+ TQMimeSourceFactory & )
+ : TQTextCustomItem( p )
+{
+ height = tmpheight = 8;
+ if ( attr.tqfind( "color" ) != attr.end() )
+ color = TQColor( *attr.tqfind( "color" ) );
+ shade = attr.tqfind( "noshade" ) == attr.end();
+}
+
+TQTextHorizontalLine::~TQTextHorizontalLine()
+{
+}
+
+TQString TQTextHorizontalLine::richText() const
+{
+ return "<hr>";
+}
+
+void TQTextHorizontalLine::draw( TQPainter* p, int x, int y, int , int , int , int , const TQColorGroup& cg, bool selected )
+{
+ TQRect r( x, y, width, height);
+ if ( is_printer( p ) || !shade ) {
+ TQPen oldPen = p->pen();
+ if ( !color.isValid() )
+ p->setPen( TQPen( cg.text(), is_printer( p ) ? height/8 : TQMAX( 2, height/4 ) ) );
+ else
+ p->setPen( TQPen( color, is_printer( p ) ? height/8 : TQMAX( 2, height/4 ) ) );
+ p->drawLine( r.left()-1, y + height / 2, r.right() + 1, y + height / 2 );
+ p->setPen( oldPen );
+ } else {
+ TQColorGroup g( cg );
+ if ( color.isValid() )
+ g.setColor( TQColorGroup::Dark, color );
+ if ( selected )
+ p->fillRect( r, g.highlight() );
+ qDrawShadeLine( p, r.left() - 1, y + height / 2, r.right() + 1, y + height / 2, g, TRUE, height / 8 );
+ }
+}
+#endif //TQT_NO_TEXTCUSTOMITEM
+
+/*****************************************************************/
+// Small set of utility functions to make the parser a bit simpler
+//
+
+bool TQTextDocument::hasPrefix(const TQChar* doc, int length, int pos, TQChar c)
+{
+ if ( pos + 1 > length )
+ return FALSE;
+ return doc[ pos ].lower() == c.lower();
+}
+
+bool TQTextDocument::hasPrefix( const TQChar* doc, int length, int pos, const TQString& s )
+{
+ if ( pos + (int) s.length() > length )
+ return FALSE;
+ for ( int i = 0; i < (int)s.length(); i++ ) {
+ if ( doc[ pos + i ].lower() != s[ i ].lower() )
+ return FALSE;
+ }
+ return TRUE;
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+static bool qt_is_cell_in_use( TQPtrList<TQTextTableCell>& cells, int row, int col )
+{
+ for ( TQTextTableCell* c = cells.first(); c; c = cells.next() ) {
+ if ( row >= c->row() && row < c->row() + c->rowspan()
+ && col >= c->column() && col < c->column() + c->colspan() )
+ return TRUE;
+ }
+ return FALSE;
+}
+
+TQTextCustomItem* TQTextDocument::parseTable( const QMap<TQString, TQString> &attr, const TQTextFormat &fmt,
+ const TQChar* doc, int length, int& pos, TQTextParagraph *curpar )
+{
+
+ TQTextTable* table = new TQTextTable( this, attr );
+ int row = -1;
+ int col = -1;
+
+ TQString rowbgcolor;
+ TQString rowalign;
+ TQString tablebgcolor = attr["bgcolor"];
+
+ TQPtrList<TQTextTableCell> multicells;
+
+ TQString tagname;
+ (void) eatSpace(doc, length, pos);
+ while ( pos < length) {
+ if (hasPrefix(doc, length, pos, TQChar('<')) ){
+ if (hasPrefix(doc, length, pos+1, TQChar('/'))) {
+ tagname = parseCloseTag( doc, length, pos );
+ if ( tagname == "table" ) {
+ return table;
+ }
+ } else {
+ QMap<TQString, TQString> attr2;
+ bool emptyTag = FALSE;
+ tagname = parseOpenTag( doc, length, pos, attr2, emptyTag );
+ if ( tagname == "tr" ) {
+ rowbgcolor = attr2["bgcolor"];
+ rowalign = attr2["align"];
+ row++;
+ col = -1;
+ }
+ else if ( tagname == "td" || tagname == "th" ) {
+ col++;
+ while ( qt_is_cell_in_use( multicells, row, col ) ) {
+ col++;
+ }
+
+ if ( row >= 0 && col >= 0 ) {
+ const TQStyleSheetItem* s = sheet_->item(tagname);
+ if ( !attr2.tqcontains("bgcolor") ) {
+ if (!rowbgcolor.isEmpty() )
+ attr2["bgcolor"] = rowbgcolor;
+ else if (!tablebgcolor.isEmpty() )
+ attr2["bgcolor"] = tablebgcolor;
+ }
+ if ( !attr2.tqcontains("align") ) {
+ if (!rowalign.isEmpty() )
+ attr2["align"] = rowalign;
+ }
+
+ // extract the cell contents
+ int end = pos;
+ while ( end < length
+ && !hasPrefix( doc, length, end, "</td")
+ && !hasPrefix( doc, length, end, "<td")
+ && !hasPrefix( doc, length, end, "</th")
+ && !hasPrefix( doc, length, end, "<th")
+ && !hasPrefix( doc, length, end, "<td")
+ && !hasPrefix( doc, length, end, "</tr")
+ && !hasPrefix( doc, length, end, "<tr")
+ && !hasPrefix( doc, length, end, "</table") ) {
+ if ( hasPrefix( doc, length, end, "<table" ) ) { // nested table
+ int nested = 1;
+ ++end;
+ while ( end < length && nested != 0 ) {
+ if ( hasPrefix( doc, length, end, "</table" ) )
+ nested--;
+ if ( hasPrefix( doc, length, end, "<table" ) )
+ nested++;
+ end++;
+ }
+ }
+ end++;
+ }
+ TQTextTableCell* cell = new TQTextTableCell( table, row, col,
+ attr2, s, fmt.makeTextFormat( s, attr2, scaleFontsFactor ),
+ contxt, *factory_, sheet_,
+ TQConstString( doc + pos, end - pos ).string() );
+ cell->richText()->parentPar = curpar;
+ if ( cell->colspan() > 1 || cell->rowspan() > 1 )
+ multicells.append( cell );
+ col += cell->colspan()-1;
+ pos = end;
+ }
+ }
+ }
+
+ } else {
+ ++pos;
+ }
+ }
+ return table;
+}
+#endif // TQT_NO_TEXTCUSTOMITEM
+
+bool TQTextDocument::eatSpace(const TQChar* doc, int length, int& pos, bool includeNbsp )
+{
+ int old_pos = pos;
+ while (pos < length && doc[pos].isSpace() && ( includeNbsp || (doc[pos] != TQChar::nbsp ) ) )
+ pos++;
+ return old_pos < pos;
+}
+
+bool TQTextDocument::eat(const TQChar* doc, int length, int& pos, TQChar c)
+{
+ bool ok = pos < length && doc[pos] == c;
+ if ( ok )
+ pos++;
+ return ok;
+}
+/*****************************************************************/
+
+struct Entity {
+ const char * name;
+ TQ_UINT16 code;
+};
+
+static const Entity entitylist [] = {
+ { "AElig", 0x00c6 },
+ { "Aacute", 0x00c1 },
+ { "Acirc", 0x00c2 },
+ { "Agrave", 0x00c0 },
+ { "Alpha", 0x0391 },
+ { "AMP", 38 },
+ { "Aring", 0x00c5 },
+ { "Atilde", 0x00c3 },
+ { "Auml", 0x00c4 },
+ { "Beta", 0x0392 },
+ { "Ccedil", 0x00c7 },
+ { "Chi", 0x03a7 },
+ { "Dagger", 0x2021 },
+ { "Delta", 0x0394 },
+ { "ETH", 0x00d0 },
+ { "Eacute", 0x00c9 },
+ { "Ecirc", 0x00ca },
+ { "Egrave", 0x00c8 },
+ { "Epsilon", 0x0395 },
+ { "Eta", 0x0397 },
+ { "Euml", 0x00cb },
+ { "Gamma", 0x0393 },
+ { "GT", 62 },
+ { "Iacute", 0x00cd },
+ { "Icirc", 0x00ce },
+ { "Igrave", 0x00cc },
+ { "Iota", 0x0399 },
+ { "Iuml", 0x00cf },
+ { "Kappa", 0x039a },
+ { "Lambda", 0x039b },
+ { "LT", 60 },
+ { "Mu", 0x039c },
+ { "Ntilde", 0x00d1 },
+ { "Nu", 0x039d },
+ { "OElig", 0x0152 },
+ { "Oacute", 0x00d3 },
+ { "Ocirc", 0x00d4 },
+ { "Ograve", 0x00d2 },
+ { "Omega", 0x03a9 },
+ { "Omicron", 0x039f },
+ { "Oslash", 0x00d8 },
+ { "Otilde", 0x00d5 },
+ { "Ouml", 0x00d6 },
+ { "Phi", 0x03a6 },
+ { "Pi", 0x03a0 },
+ { "Prime", 0x2033 },
+ { "Psi", 0x03a8 },
+ { "TQUOT", 34 },
+ { "Rho", 0x03a1 },
+ { "Scaron", 0x0160 },
+ { "Sigma", 0x03a3 },
+ { "THORN", 0x00de },
+ { "Tau", 0x03a4 },
+ { "Theta", 0x0398 },
+ { "Uacute", 0x00da },
+ { "Ucirc", 0x00db },
+ { "Ugrave", 0x00d9 },
+ { "Upsilon", 0x03a5 },
+ { "Uuml", 0x00dc },
+ { "Xi", 0x039e },
+ { "Yacute", 0x00dd },
+ { "Yuml", 0x0178 },
+ { "Zeta", 0x0396 },
+ { "aacute", 0x00e1 },
+ { "acirc", 0x00e2 },
+ { "acute", 0x00b4 },
+ { "aelig", 0x00e6 },
+ { "agrave", 0x00e0 },
+ { "alefsym", 0x2135 },
+ { "alpha", 0x03b1 },
+ { "amp", 38 },
+ { "and", 0x22a5 },
+ { "ang", 0x2220 },
+ { "apos", 0x0027 },
+ { "aring", 0x00e5 },
+ { "asymp", 0x2248 },
+ { "atilde", 0x00e3 },
+ { "auml", 0x00e4 },
+ { "bdquo", 0x201e },
+ { "beta", 0x03b2 },
+ { "brvbar", 0x00a6 },
+ { "bull", 0x2022 },
+ { "cap", 0x2229 },
+ { "ccedil", 0x00e7 },
+ { "cedil", 0x00b8 },
+ { "cent", 0x00a2 },
+ { "chi", 0x03c7 },
+ { "circ", 0x02c6 },
+ { "clubs", 0x2663 },
+ { "cong", 0x2245 },
+ { "copy", 0x00a9 },
+ { "crarr", 0x21b5 },
+ { "cup", 0x222a },
+ { "curren", 0x00a4 },
+ { "dArr", 0x21d3 },
+ { "dagger", 0x2020 },
+ { "darr", 0x2193 },
+ { "deg", 0x00b0 },
+ { "delta", 0x03b4 },
+ { "diams", 0x2666 },
+ { "divide", 0x00f7 },
+ { "eacute", 0x00e9 },
+ { "ecirc", 0x00ea },
+ { "egrave", 0x00e8 },
+ { "empty", 0x2205 },
+ { "emsp", 0x2003 },
+ { "ensp", 0x2002 },
+ { "epsilon", 0x03b5 },
+ { "equiv", 0x2261 },
+ { "eta", 0x03b7 },
+ { "eth", 0x00f0 },
+ { "euml", 0x00eb },
+ { "euro", 0x20ac },
+ { "exist", 0x2203 },
+ { "fnof", 0x0192 },
+ { "forall", 0x2200 },
+ { "frac12", 0x00bd },
+ { "frac14", 0x00bc },
+ { "frac34", 0x00be },
+ { "frasl", 0x2044 },
+ { "gamma", 0x03b3 },
+ { "ge", 0x2265 },
+ { "gt", 62 },
+ { "hArr", 0x21d4 },
+ { "harr", 0x2194 },
+ { "hearts", 0x2665 },
+ { "hellip", 0x2026 },
+ { "iacute", 0x00ed },
+ { "icirc", 0x00ee },
+ { "iexcl", 0x00a1 },
+ { "igrave", 0x00ec },
+ { "image", 0x2111 },
+ { "infin", 0x221e },
+ { "int", 0x222b },
+ { "iota", 0x03b9 },
+ { "iquest", 0x00bf },
+ { "isin", 0x2208 },
+ { "iuml", 0x00ef },
+ { "kappa", 0x03ba },
+ { "lArr", 0x21d0 },
+ { "lambda", 0x03bb },
+ { "lang", 0x2329 },
+ { "laquo", 0x00ab },
+ { "larr", 0x2190 },
+ { "lceil", 0x2308 },
+ { "ldquo", 0x201c },
+ { "le", 0x2264 },
+ { "lfloor", 0x230a },
+ { "lowast", 0x2217 },
+ { "loz", 0x25ca },
+ { "lrm", 0x200e },
+ { "lsaquo", 0x2039 },
+ { "lsquo", 0x2018 },
+ { "lt", 60 },
+ { "macr", 0x00af },
+ { "mdash", 0x2014 },
+ { "micro", 0x00b5 },
+ { "middot", 0x00b7 },
+ { "minus", 0x2212 },
+ { "mu", 0x03bc },
+ { "nabla", 0x2207 },
+ { "nbsp", 0x00a0 },
+ { "ndash", 0x2013 },
+ { "ne", 0x2260 },
+ { "ni", 0x220b },
+ { "not", 0x00ac },
+ { "notin", 0x2209 },
+ { "nsub", 0x2284 },
+ { "ntilde", 0x00f1 },
+ { "nu", 0x03bd },
+ { "oacute", 0x00f3 },
+ { "ocirc", 0x00f4 },
+ { "oelig", 0x0153 },
+ { "ograve", 0x00f2 },
+ { "oline", 0x203e },
+ { "omega", 0x03c9 },
+ { "omicron", 0x03bf },
+ { "oplus", 0x2295 },
+ { "or", 0x22a6 },
+ { "ordf", 0x00aa },
+ { "ordm", 0x00ba },
+ { "oslash", 0x00f8 },
+ { "otilde", 0x00f5 },
+ { "otimes", 0x2297 },
+ { "ouml", 0x00f6 },
+ { "para", 0x00b6 },
+ { "part", 0x2202 },
+ { "percnt", 0x0025 },
+ { "permil", 0x2030 },
+ { "perp", 0x22a5 },
+ { "phi", 0x03c6 },
+ { "pi", 0x03c0 },
+ { "piv", 0x03d6 },
+ { "plusmn", 0x00b1 },
+ { "pound", 0x00a3 },
+ { "prime", 0x2032 },
+ { "prod", 0x220f },
+ { "prop", 0x221d },
+ { "psi", 0x03c8 },
+ { "quot", 34 },
+ { "rArr", 0x21d2 },
+ { "radic", 0x221a },
+ { "rang", 0x232a },
+ { "raquo", 0x00bb },
+ { "rarr", 0x2192 },
+ { "rceil", 0x2309 },
+ { "rdquo", 0x201d },
+ { "real", 0x211c },
+ { "reg", 0x00ae },
+ { "rfloor", 0x230b },
+ { "rho", 0x03c1 },
+ { "rlm", 0x200f },
+ { "rsaquo", 0x203a },
+ { "rsquo", 0x2019 },
+ { "sbquo", 0x201a },
+ { "scaron", 0x0161 },
+ { "sdot", 0x22c5 },
+ { "sect", 0x00a7 },
+ { "shy", 0x00ad },
+ { "sigma", 0x03c3 },
+ { "sigmaf", 0x03c2 },
+ { "sim", 0x223c },
+ { "spades", 0x2660 },
+ { "sub", 0x2282 },
+ { "sube", 0x2286 },
+ { "sum", 0x2211 },
+ { "sup1", 0x00b9 },
+ { "sup2", 0x00b2 },
+ { "sup3", 0x00b3 },
+ { "sup", 0x2283 },
+ { "supe", 0x2287 },
+ { "szlig", 0x00df },
+ { "tau", 0x03c4 },
+ { "there4", 0x2234 },
+ { "theta", 0x03b8 },
+ { "thetasym", 0x03d1 },
+ { "thinsp", 0x2009 },
+ { "thorn", 0x00fe },
+ { "tilde", 0x02dc },
+ { "times", 0x00d7 },
+ { "trade", 0x2122 },
+ { "uArr", 0x21d1 },
+ { "uacute", 0x00fa },
+ { "uarr", 0x2191 },
+ { "ucirc", 0x00fb },
+ { "ugrave", 0x00f9 },
+ { "uml", 0x00a8 },
+ { "upsih", 0x03d2 },
+ { "upsilon", 0x03c5 },
+ { "uuml", 0x00fc },
+ { "weierp", 0x2118 },
+ { "xi", 0x03be },
+ { "yacute", 0x00fd },
+ { "yen", 0x00a5 },
+ { "yuml", 0x00ff },
+ { "zeta", 0x03b6 },
+ { "zwj", 0x200d },
+ { "zwnj", 0x200c },
+ { "", 0x0000 }
+};
+
+
+
+
+
+static QMap<TQString, TQChar> *html_map = 0;
+static void qt_cleanup_html_map()
+{
+ delete html_map;
+ html_map = 0;
+}
+
+static QMap<TQString, TQChar> *htmlMap()
+{
+ if ( !html_map ) {
+ html_map = new QMap<TQString, TQChar>;
+ qAddPostRoutine( qt_cleanup_html_map );
+
+ const Entity *ent = entitylist;
+ while( ent->code ) {
+ html_map->insert( ent->name, TQChar(ent->code) );
+ ent++;
+ }
+ }
+ return html_map;
+}
+
+TQChar TQTextDocument::parseHTMLSpecialChar(const TQChar* doc, int length, int& pos)
+{
+ TQString s;
+ pos++;
+ int recoverpos = pos;
+ while ( pos < length && doc[pos] != ';' && !doc[pos].isSpace() && pos < recoverpos + 8 ) {
+ s += doc[pos];
+ pos++;
+ }
+ if (doc[pos] != ';' && !doc[pos].isSpace() ) {
+ pos = recoverpos;
+ return '&';
+ }
+ pos++;
+
+ if ( s.length() > 1 && s[0] == '#') {
+ int off = 1;
+ int base = 10;
+ if (s[1] == 'x') {
+ off = 2;
+ base = 16;
+ }
+ bool ok;
+ int num = s.mid(off).toInt(&ok, base);
+ if ( num == 151 ) // ### hack for designer manual
+ return '-';
+ if (ok)
+ return num;
+ } else {
+ QMap<TQString, TQChar>::Iterator it = htmlMap()->tqfind(s);
+ if ( it != htmlMap()->end() ) {
+ return *it;
+ }
+ }
+
+ pos = recoverpos;
+ return '&';
+}
+
+TQString TQTextDocument::parseWord(const TQChar* doc, int length, int& pos, bool lower)
+{
+ TQString s;
+
+ if (doc[pos] == '"') {
+ pos++;
+ while ( pos < length && doc[pos] != '"' ) {
+ if ( doc[pos] == '&' ) {
+ s += parseHTMLSpecialChar( doc, length, pos );
+ } else {
+ s += doc[pos];
+ pos++;
+ }
+ }
+ eat(doc, length, pos, '"');
+ } else if (doc[pos] == '\'') {
+ pos++;
+ while ( pos < length && doc[pos] != '\'' ) {
+ s += doc[pos];
+ pos++;
+ }
+ eat(doc, length, pos, '\'');
+ } else {
+ static TQString term = TQString::tqfromLatin1("/>");
+ while ( pos < length
+ && doc[pos] != '>'
+ && !hasPrefix(doc, length, pos, term)
+ && doc[pos] != '<'
+ && doc[pos] != '='
+ && !doc[pos].isSpace() )
+ {
+ if ( doc[pos] == '&' ) {
+ s += parseHTMLSpecialChar( doc, length, pos );
+ } else {
+ s += doc[pos];
+ pos++;
+ }
+ }
+ if (lower)
+ s = s.lower();
+ }
+ return s;
+}
+
+TQChar TQTextDocument::parseChar(const TQChar* doc, int length, int& pos, TQStyleSheetItem::WhiteSpaceMode wsm )
+{
+ if ( pos >= length )
+ return TQChar::null;
+
+ TQChar c = doc[pos++];
+
+ if (c == '<' )
+ return TQChar::null;
+
+ if ( c.isSpace() && c != TQChar::nbsp ) {
+ if ( wsm == TQStyleSheetItem::WhiteSpacePre ) {
+ if ( c == '\n' )
+ return TQChar_linesep;
+ else
+ return c;
+ } else { // non-pre mode: collapse whitespace except nbsp
+ while ( pos< length &&
+ doc[pos].isSpace() && doc[pos] != TQChar::nbsp )
+ pos++;
+ return ' ';
+ }
+ }
+ else if ( c == '&' )
+ return parseHTMLSpecialChar( doc, length, --pos );
+ else
+ return c;
+}
+
+TQString TQTextDocument::parseOpenTag(const TQChar* doc, int length, int& pos,
+ QMap<TQString, TQString> &attr, bool& emptyTag)
+{
+ emptyTag = FALSE;
+ pos++;
+ if ( hasPrefix(doc, length, pos, '!') ) {
+ if ( hasPrefix( doc, length, pos+1, "--")) {
+ pos += 3;
+ // eat comments
+ TQString pref = TQString::tqfromLatin1("-->");
+ while ( !hasPrefix(doc, length, pos, pref ) && pos < length )
+ pos++;
+ if ( hasPrefix(doc, length, pos, pref ) ) {
+ pos += 3;
+ eatSpace(doc, length, pos, TRUE);
+ }
+ emptyTag = TRUE;
+ return TQString::null;
+ }
+ else {
+ // eat strange internal tags
+ while ( !hasPrefix(doc, length, pos, '>') && pos < length )
+ pos++;
+ if ( hasPrefix(doc, length, pos, '>') ) {
+ pos++;
+ eatSpace(doc, length, pos, TRUE);
+ }
+ return TQString::null;
+ }
+ }
+
+ TQString tag = parseWord(doc, length, pos );
+ eatSpace(doc, length, pos, TRUE);
+ static TQString term = TQString::tqfromLatin1("/>");
+ static TQString s_TRUE = TQString::tqfromLatin1("TRUE");
+
+ while (doc[pos] != '>' && ! (emptyTag = hasPrefix(doc, length, pos, term) )) {
+ TQString key = parseWord(doc, length, pos );
+ eatSpace(doc, length, pos, TRUE);
+ if ( key.isEmpty()) {
+ // error recovery
+ while ( pos < length && doc[pos] != '>' )
+ pos++;
+ break;
+ }
+ TQString value;
+ if (hasPrefix(doc, length, pos, '=') ){
+ pos++;
+ eatSpace(doc, length, pos);
+ value = parseWord(doc, length, pos, FALSE);
+ }
+ else
+ value = s_TRUE;
+ attr.insert(key.lower(), value );
+ eatSpace(doc, length, pos, TRUE);
+ }
+
+ if (emptyTag) {
+ eat(doc, length, pos, '/');
+ eat(doc, length, pos, '>');
+ }
+ else
+ eat(doc, length, pos, '>');
+
+ return tag;
+}
+
+TQString TQTextDocument::parseCloseTag( const TQChar* doc, int length, int& pos )
+{
+ pos++;
+ pos++;
+ TQString tag = parseWord(doc, length, pos );
+ eatSpace(doc, length, pos, TRUE);
+ eat(doc, length, pos, '>');
+ return tag;
+}
+
+TQTextFlow::TQTextFlow()
+{
+ w = pagesize = 0;
+}
+
+TQTextFlow::~TQTextFlow()
+{
+ clear();
+}
+
+void TQTextFlow::clear()
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ leftItems.setAutoDelete( TRUE );
+ rightItems.setAutoDelete( TRUE );
+ leftItems.clear();
+ rightItems.clear();
+ leftItems.setAutoDelete( FALSE );
+ rightItems.setAutoDelete( FALSE );
+#endif
+}
+
+void TQTextFlow::setWidth( int width )
+{
+ w = width;
+}
+
+int TQTextFlow::adjustLMargin( int yp, int, int margin, int space )
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ for ( TQTextCustomItem* item = leftItems.first(); item; item = leftItems.next() ) {
+ if ( item->ypos == -1 )
+ continue;
+ if ( yp >= item->ypos && yp < item->ypos + item->height )
+ margin = TQMAX( margin, item->xpos + item->width + space );
+ }
+#endif
+ return margin;
+}
+
+int TQTextFlow::adjustRMargin( int yp, int, int margin, int space )
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ for ( TQTextCustomItem* item = rightItems.first(); item; item = rightItems.next() ) {
+ if ( item->ypos == -1 )
+ continue;
+ if ( yp >= item->ypos && yp < item->ypos + item->height )
+ margin = TQMAX( margin, w - item->xpos - space );
+ }
+#endif
+ return margin;
+}
+
+
+int TQTextFlow::adjustFlow( int y, int /*w*/, int h )
+{
+ if ( pagesize > 0 ) { // check pages
+ int yinpage = y % pagesize;
+ if ( yinpage <= border_tolerance )
+ return border_tolerance - yinpage;
+ else
+ if ( yinpage + h > pagesize - border_tolerance )
+ return ( pagesize - yinpage ) + border_tolerance;
+ }
+ return 0;
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+void TQTextFlow::unregisterFloatingItem( TQTextCustomItem* item )
+{
+ leftItems.removeRef( item );
+ rightItems.removeRef( item );
+}
+
+void TQTextFlow::registerFloatingItem( TQTextCustomItem* item )
+{
+ if ( item->placement() == TQTextCustomItem::PlaceRight ) {
+ if ( !rightItems.tqcontains( item ) )
+ rightItems.append( item );
+ } else if ( item->placement() == TQTextCustomItem::PlaceLeft &&
+ !leftItems.tqcontains( item ) ) {
+ leftItems.append( item );
+ }
+}
+#endif // TQT_NO_TEXTCUSTOMITEM
+
+TQRect TQTextFlow::boundingRect() const
+{
+ TQRect br;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQPtrListIterator<TQTextCustomItem> l( leftItems );
+ while( l.current() ) {
+ br = br.unite( l.current()->tqgeometry() );
+ ++l;
+ }
+ TQPtrListIterator<TQTextCustomItem> r( rightItems );
+ while( r.current() ) {
+ br = br.unite( r.current()->tqgeometry() );
+ ++r;
+ }
+#endif
+ return br;
+}
+
+
+void TQTextFlow::drawFloatingItems( TQPainter* p, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected )
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem *item;
+ for ( item = leftItems.first(); item; item = leftItems.next() ) {
+ if ( item->xpos == -1 || item->ypos == -1 )
+ continue;
+ item->draw( p, item->xpos, item->ypos, cx, cy, cw, ch, cg, selected );
+ }
+
+ for ( item = rightItems.first(); item; item = rightItems.next() ) {
+ if ( item->xpos == -1 || item->ypos == -1 )
+ continue;
+ item->draw( p, item->xpos, item->ypos, cx, cy, cw, ch, cg, selected );
+ }
+#endif
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+void TQTextCustomItem::pageBreak( int /*y*/ , TQTextFlow* /*flow*/ )
+{
+}
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+TQTextTable::TQTextTable( TQTextDocument *p, const QMap<TQString, TQString> & attr )
+ : TQTextCustomItem( p )
+{
+ cells.setAutoDelete( FALSE );
+ cellspacing = 2;
+ if ( attr.tqcontains("cellspacing") )
+ cellspacing = attr["cellspacing"].toInt();
+ cellpadding = 1;
+ if ( attr.tqcontains("cellpadding") )
+ cellpadding = attr["cellpadding"].toInt();
+ border = innerborder = 0;
+ if ( attr.tqcontains("border" ) ) {
+ TQString s( attr["border"] );
+ if ( s == "TRUE" )
+ border = 1;
+ else
+ border = attr["border"].toInt();
+ }
+ us_b = border;
+
+ innerborder = us_ib = border ? 1 : 0;
+
+ if ( border )
+ cellspacing += 2;
+
+ us_ib = innerborder;
+ us_cs = cellspacing;
+ us_cp = cellpadding;
+ outerborder = cellspacing + border;
+ us_ob = outerborder;
+ tqlayout = new TQGridLayout( 1, 1, cellspacing );
+
+ fixwidth = 0;
+ stretch = 0;
+ if ( attr.tqcontains("width") ) {
+ bool b;
+ TQString s( attr["width"] );
+ int w = s.toInt( &b );
+ if ( b ) {
+ fixwidth = w;
+ } else {
+ s = s.stripWhiteSpace();
+ if ( s.length() > 1 && s[ (int)s.length()-1 ] == '%' )
+ stretch = s.left( s.length()-1).toInt();
+ }
+ }
+ us_fixwidth = fixwidth;
+
+ place = PlaceInline;
+ if ( attr["align"] == "left" )
+ place = PlaceLeft;
+ else if ( attr["align"] == "right" )
+ place = PlaceRight;
+ cachewidth = 0;
+ attributes = attr;
+ pageBreakFor = -1;
+}
+
+TQTextTable::~TQTextTable()
+{
+ delete tqlayout;
+}
+
+TQString TQTextTable::richText() const
+{
+ TQString s;
+ s = "<table ";
+ QMap<TQString, TQString>::ConstIterator it = attributes.begin();
+ for ( ; it != attributes.end(); ++it )
+ s += it.key() + "=" + *it + " ";
+ s += ">\n";
+
+ int lastRow = -1;
+ bool needEnd = FALSE;
+ TQPtrListIterator<TQTextTableCell> it2( cells );
+ while ( it2.current() ) {
+ TQTextTableCell *cell = it2.current();
+ ++it2;
+ if ( lastRow != cell->row() ) {
+ if ( lastRow != -1 )
+ s += "</tr>\n";
+ s += "<tr>";
+ lastRow = cell->row();
+ needEnd = TRUE;
+ }
+ s += "<td";
+ it = cell->attributes.begin();
+ for ( ; it != cell->attributes.end(); ++it )
+ s += " " + it.key() + "=" + *it;
+ s += ">";
+ s += cell->richText()->richText();
+ s += "</td>";
+ }
+ if ( needEnd )
+ s += "</tr>\n";
+ s += "</table>\n";
+ return s;
+}
+
+void TQTextTable::setParagraph(TQTextParagraph *p)
+{
+ for ( TQTextTableCell* cell = cells.first(); cell; cell = cells.next() )
+ cell->richText()->parentPar = p;
+ TQTextCustomItem::setParagraph(p);
+}
+
+void TQTextTable::adjustToPainter( TQPainter* p )
+{
+ cellspacing = scale( us_cs, p );
+ cellpadding = scale( us_cp, p );
+ border = scale( us_b , p );
+ innerborder = scale( us_ib, p );
+ outerborder = scale( us_ob ,p );
+ fixwidth = scale( us_fixwidth, p);
+ width = 0;
+ cachewidth = 0;
+ for ( TQTextTableCell* cell = cells.first(); cell; cell = cells.next() )
+ cell->adjustToPainter( p );
+}
+
+void TQTextTable::adjustCells( int y , int shift )
+{
+ TQPtrListIterator<TQTextTableCell> it( cells );
+ TQTextTableCell* cell;
+ bool enlarge = FALSE;
+ while ( ( cell = it.current() ) ) {
+ ++it;
+ TQRect r = cell->tqgeometry();
+ if ( y <= r.top() ) {
+ r.moveBy(0, shift );
+ cell->setGeometry( r );
+ enlarge = TRUE;
+ } else if ( y <= r.bottom() ) {
+ r.rBottom() += shift;
+ cell->setGeometry( r );
+ enlarge = TRUE;
+ }
+ }
+ if ( enlarge )
+ height += shift;
+}
+
+void TQTextTable::pageBreak( int yt, TQTextFlow* flow )
+{
+ if ( flow->pageSize() <= 0 )
+ return;
+ if ( tqlayout && pageBreakFor > 0 && pageBreakFor != yt ) {
+ tqlayout->tqinvalidate();
+ int h = tqlayout->heightForWidth( width-2*outerborder );
+ tqlayout->setGeometry( TQRect(0, 0, width-2*outerborder, h) );
+ height = tqlayout->tqgeometry().height()+2*outerborder;
+ }
+ pageBreakFor = yt;
+ TQPtrListIterator<TQTextTableCell> it( cells );
+ TQTextTableCell* cell;
+ while ( ( cell = it.current() ) ) {
+ ++it;
+ int y = yt + outerborder + cell->tqgeometry().y();
+ int shift = flow->adjustFlow( y - cellspacing, width, cell->richText()->height() + 2*cellspacing );
+ adjustCells( y - outerborder - yt, shift );
+ }
+}
+
+
+void TQTextTable::draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected )
+{
+ if ( placement() != PlaceInline ) {
+ x = xpos;
+ y = ypos;
+ }
+
+ for (TQTextTableCell* cell = cells.first(); cell; cell = cells.next() ) {
+ if ( (cx < 0 && cy) < 0 ||
+ TQRect( cx, cy, cw, ch ).intersects( TQRect( x + outerborder + cell->tqgeometry().x(),
+ y + outerborder + cell->tqgeometry().y(),
+ cell->tqgeometry().width(), cell->tqgeometry().height() ) ) ) {
+ cell->draw( p, x+outerborder, y+outerborder, cx, cy, cw, ch, cg, selected );
+ if ( border ) {
+ TQRect r( x+outerborder+cell->tqgeometry().x() - innerborder,
+ y+outerborder+cell->tqgeometry().y() - innerborder,
+ cell->tqgeometry().width() + 2 * innerborder,
+ cell->tqgeometry().height() + 2 * innerborder );
+ if ( is_printer( p ) ) {
+ TQPen oldPen = p->pen();
+ TQRect r2 = r;
+ r2.addCoords( innerborder/2, innerborder/2, -innerborder/2, -innerborder/2 );
+ p->setPen( TQPen( cg.text(), innerborder ) );
+ p->drawRect( r2 );
+ p->setPen( oldPen );
+ } else {
+ int s = TQMAX( cellspacing-2*innerborder, 0);
+ if ( s ) {
+ p->fillRect( r.left()-s, r.top(), s+1, r.height(), cg.button() );
+ p->fillRect( r.right(), r.top(), s+1, r.height(), cg.button() );
+ p->fillRect( r.left()-s, r.top()-s, r.width()+2*s, s, cg.button() );
+ p->fillRect( r.left()-s, r.bottom(), r.width()+2*s, s, cg.button() );
+ }
+ qDrawShadePanel( p, r, cg, TRUE, innerborder );
+ }
+ }
+ }
+ }
+ if ( border ) {
+ TQRect r ( x, y, width, height );
+ if ( is_printer( p ) ) {
+ TQRect r2 = r;
+ r2.addCoords( border/2, border/2, -border/2, -border/2 );
+ TQPen oldPen = p->pen();
+ p->setPen( TQPen( cg.text(), border ) );
+ p->drawRect( r2 );
+ p->setPen( oldPen );
+ } else {
+ int s = border+TQMAX( cellspacing-2*innerborder, 0);
+ if ( s ) {
+ p->fillRect( r.left(), r.top(), s, r.height(), cg.button() );
+ p->fillRect( r.right()-s, r.top(), s, r.height(), cg.button() );
+ p->fillRect( r.left(), r.top(), r.width(), s, cg.button() );
+ p->fillRect( r.left(), r.bottom()-s, r.width(), s, cg.button() );
+ }
+ qDrawShadePanel( p, r, cg, FALSE, border );
+ }
+ }
+
+}
+
+int TQTextTable::minimumWidth() const
+{
+ return fixwidth ? fixwidth : ((tqlayout ? tqlayout->tqminimumSize().width() : 0) + 2 * outerborder);
+}
+
+void TQTextTable::resize( int nwidth )
+{
+ if ( fixwidth && cachewidth != 0 )
+ return;
+ if ( nwidth == cachewidth )
+ return;
+
+
+ cachewidth = nwidth;
+ int w = nwidth;
+
+ format( w );
+
+ if ( stretch )
+ nwidth = nwidth * stretch / 100;
+
+ width = nwidth;
+ tqlayout->tqinvalidate();
+ int shw = tqlayout->tqsizeHint().width() + 2*outerborder;
+ int mw = tqlayout->tqminimumSize().width() + 2*outerborder;
+ if ( stretch )
+ width = TQMAX( mw, nwidth );
+ else
+ width = TQMAX( mw, TQMIN( nwidth, shw ) );
+
+ if ( fixwidth )
+ width = fixwidth;
+
+ tqlayout->tqinvalidate();
+ mw = tqlayout->tqminimumSize().width() + 2*outerborder;
+ width = TQMAX( width, mw );
+
+ int h = tqlayout->heightForWidth( width-2*outerborder );
+ tqlayout->setGeometry( TQRect(0, 0, width-2*outerborder, h) );
+ height = tqlayout->tqgeometry().height()+2*outerborder;
+}
+
+void TQTextTable::format( int w )
+{
+ for ( int i = 0; i < (int)cells.count(); ++i ) {
+ TQTextTableCell *cell = cells.at( i );
+ TQRect r = cell->tqgeometry();
+ r.setWidth( w - 2*outerborder );
+ cell->setGeometry( r );
+ }
+}
+
+void TQTextTable::addCell( TQTextTableCell* cell )
+{
+ cells.append( cell );
+ tqlayout->addMultiCell( cell, cell->row(), cell->row() + cell->rowspan()-1,
+ cell->column(), cell->column() + cell->colspan()-1 );
+}
+
+bool TQTextTable::enter( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd )
+{
+ currCell.remove( c );
+ if ( !atEnd )
+ return next( c, doc, parag, idx, ox, oy );
+ currCell.insert( c, cells.count() );
+ return prev( c, doc, parag, idx, ox, oy );
+}
+
+bool TQTextTable::enterAt( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, const TQPoint &pos )
+{
+ currCell.remove( c );
+ int lastCell = -1;
+ int lastY = -1;
+ int i;
+ for ( i = 0; i < (int)cells.count(); ++i ) {
+ TQTextTableCell *cell = cells.at( i );
+ if ( !cell )
+ continue;
+ TQRect r( cell->tqgeometry().x(),
+ cell->tqgeometry().y(),
+ cell->tqgeometry().width() + 2 * innerborder + 2 * outerborder,
+ cell->tqgeometry().height() + 2 * innerborder + 2 * outerborder );
+
+ if ( r.left() <= pos.x() && r.right() >= pos.x() ) {
+ if ( cell->tqgeometry().y() > lastY ) {
+ lastCell = i;
+ lastY = cell->tqgeometry().y();
+ }
+ if ( r.top() <= pos.y() && r.bottom() >= pos.y() ) {
+ currCell.insert( c, i );
+ break;
+ }
+ }
+ }
+ if ( i == (int) cells.count() )
+ return FALSE; // no cell found
+
+ if ( currCell.tqfind( c ) == currCell.end() ) {
+ if ( lastY != -1 )
+ currCell.insert( c, lastCell );
+ else
+ return FALSE;
+ }
+
+ TQTextTableCell *cell = cells.at( *currCell.tqfind( c ) );
+ if ( !cell )
+ return FALSE;
+ doc = cell->richText();
+ parag = doc->firstParagraph();
+ idx = 0;
+ ox += cell->tqgeometry().x() + cell->horizontalAlignmentOffset() + outerborder + tqparent->x();
+ oy += cell->tqgeometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return TRUE;
+}
+
+bool TQTextTable::next( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy )
+{
+ int cc = -1;
+ if ( currCell.tqfind( c ) != currCell.end() )
+ cc = *currCell.tqfind( c );
+ if ( cc > (int)cells.count() - 1 || cc < 0 )
+ cc = -1;
+ currCell.remove( c );
+ currCell.insert( c, ++cc );
+ if ( cc >= (int)cells.count() ) {
+ currCell.insert( c, 0 );
+ TQTextCustomItem::next( c, doc, parag, idx, ox, oy );
+ TQTextTableCell *cell = cells.first();
+ if ( !cell )
+ return FALSE;
+ doc = cell->richText();
+ idx = -1;
+ return TRUE;
+ }
+
+ if ( currCell.tqfind( c ) == currCell.end() )
+ return FALSE;
+ TQTextTableCell *cell = cells.at( *currCell.tqfind( c ) );
+ if ( !cell )
+ return FALSE;
+ doc = cell->richText();
+ parag = doc->firstParagraph();
+ idx = 0;
+ ox += cell->tqgeometry().x() + cell->horizontalAlignmentOffset() + outerborder + tqparent->x();
+ oy += cell->tqgeometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return TRUE;
+}
+
+bool TQTextTable::prev( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy )
+{
+ int cc = -1;
+ if ( currCell.tqfind( c ) != currCell.end() )
+ cc = *currCell.tqfind( c );
+ if ( cc > (int)cells.count() - 1 || cc < 0 )
+ cc = cells.count();
+ currCell.remove( c );
+ currCell.insert( c, --cc );
+ if ( cc < 0 ) {
+ currCell.insert( c, 0 );
+ TQTextCustomItem::prev( c, doc, parag, idx, ox, oy );
+ TQTextTableCell *cell = cells.first();
+ if ( !cell )
+ return FALSE;
+ doc = cell->richText();
+ idx = -1;
+ return TRUE;
+ }
+
+ if ( currCell.tqfind( c ) == currCell.end() )
+ return FALSE;
+ TQTextTableCell *cell = cells.at( *currCell.tqfind( c ) );
+ if ( !cell )
+ return FALSE;
+ doc = cell->richText();
+ parag = doc->lastParagraph();
+ idx = parag->length() - 1;
+ ox += cell->tqgeometry().x() + cell->horizontalAlignmentOffset() + outerborder + tqparent->x();
+ oy += cell->tqgeometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return TRUE;
+}
+
+bool TQTextTable::down( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy )
+{
+ if ( currCell.tqfind( c ) == currCell.end() )
+ return FALSE;
+ TQTextTableCell *cell = cells.at( *currCell.tqfind( c ) );
+ if ( cell->row_ == tqlayout->numRows() - 1 ) {
+ currCell.insert( c, 0 );
+ TQTextCustomItem::down( c, doc, parag, idx, ox, oy );
+ TQTextTableCell *cell = cells.first();
+ if ( !cell )
+ return FALSE;
+ doc = cell->richText();
+ idx = -1;
+ return TRUE;
+ }
+
+ int oldRow = cell->row_;
+ int oldCol = cell->col_;
+ if ( currCell.tqfind( c ) == currCell.end() )
+ return FALSE;
+ int cc = *currCell.tqfind( c );
+ for ( int i = cc; i < (int)cells.count(); ++i ) {
+ cell = cells.at( i );
+ if ( cell->row_ > oldRow && cell->col_ == oldCol ) {
+ currCell.insert( c, i );
+ break;
+ }
+ }
+ doc = cell->richText();
+ if ( !cell )
+ return FALSE;
+ parag = doc->firstParagraph();
+ idx = 0;
+ ox += cell->tqgeometry().x() + cell->horizontalAlignmentOffset() + outerborder + tqparent->x();
+ oy += cell->tqgeometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return TRUE;
+}
+
+bool TQTextTable::up( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy )
+{
+ if ( currCell.tqfind( c ) == currCell.end() )
+ return FALSE;
+ TQTextTableCell *cell = cells.at( *currCell.tqfind( c ) );
+ if ( cell->row_ == 0 ) {
+ currCell.insert( c, 0 );
+ TQTextCustomItem::up( c, doc, parag, idx, ox, oy );
+ TQTextTableCell *cell = cells.first();
+ if ( !cell )
+ return FALSE;
+ doc = cell->richText();
+ idx = -1;
+ return TRUE;
+ }
+
+ int oldRow = cell->row_;
+ int oldCol = cell->col_;
+ if ( currCell.tqfind( c ) == currCell.end() )
+ return FALSE;
+ int cc = *currCell.tqfind( c );
+ for ( int i = cc; i >= 0; --i ) {
+ cell = cells.at( i );
+ if ( cell->row_ < oldRow && cell->col_ == oldCol ) {
+ currCell.insert( c, i );
+ break;
+ }
+ }
+ doc = cell->richText();
+ if ( !cell )
+ return FALSE;
+ parag = doc->lastParagraph();
+ idx = parag->length() - 1;
+ ox += cell->tqgeometry().x() + cell->horizontalAlignmentOffset() + outerborder + tqparent->x();
+ oy += cell->tqgeometry().y() + cell->verticalAlignmentOffset() + outerborder;
+ return TRUE;
+}
+
+TQTextTableCell::TQTextTableCell( TQTextTable* table,
+ int row, int column,
+ const QMap<TQString, TQString> &attr,
+ const TQStyleSheetItem* /*style*/, // ### use them
+ const TQTextFormat& fmt, const TQString& context,
+ TQMimeSourceFactory &factory, TQStyleSheet *sheet,
+ const TQString& doc)
+{
+ cached_width = -1;
+ cached_sizehint = -1;
+
+ maxw = TQWIDGETSIZE_MAX;
+ minw = 0;
+
+ tqparent = table;
+ row_ = row;
+ col_ = column;
+ stretch_ = 0;
+ richtext = new TQTextDocument( table->tqparent );
+ richtext->formatCollection()->setPaintDevice( table->tqparent->formatCollection()->paintDevice() );
+ richtext->bodyText = fmt.color();
+ richtext->setTableCell( this );
+ TQString a = *attr.tqfind( "align" );
+ if ( !a.isEmpty() ) {
+ a = a.lower();
+ if ( a == "left" )
+ richtext->tqsetAlignment( TQt::AlignLeft );
+ else if ( a == "center" )
+ richtext->tqsetAlignment( TQt::AlignHCenter );
+ else if ( a == "right" )
+ richtext->tqsetAlignment( TQt::AlignRight );
+ }
+ align = 0;
+ TQString va = *attr.tqfind( "valign" );
+ if ( !va.isEmpty() ) {
+ va = va.lower();
+ if ( va == "top" )
+ align |= TQt::AlignTop;
+ else if ( va == "center" || va == "middle" )
+ align |= TQt::AlignVCenter;
+ else if ( va == "bottom" )
+ align |= TQt::AlignBottom;
+ }
+ richtext->setFormatter( table->tqparent->formatter() );
+ richtext->setUseFormatCollection( table->tqparent->useFormatCollection() );
+ richtext->setMimeSourceFactory( &factory );
+ richtext->setStyleSheet( sheet );
+ richtext->setRichText( doc, context, &fmt );
+ rowspan_ = 1;
+ colspan_ = 1;
+ if ( attr.tqcontains("colspan") )
+ colspan_ = attr["colspan"].toInt();
+ if ( attr.tqcontains("rowspan") )
+ rowspan_ = attr["rowspan"].toInt();
+
+ background = 0;
+ if ( attr.tqcontains("bgcolor") ) {
+ background = new TQBrush(TQColor( attr["bgcolor"] ));
+ }
+
+
+ hasFixedWidth = FALSE;
+ if ( attr.tqcontains("width") ) {
+ bool b;
+ TQString s( attr["width"] );
+ int w = s.toInt( &b );
+ if ( b ) {
+ maxw = w;
+ minw = maxw;
+ hasFixedWidth = TRUE;
+ } else {
+ s = s.stripWhiteSpace();
+ if ( s.length() > 1 && s[ (int)s.length()-1 ] == '%' )
+ stretch_ = s.left( s.length()-1).toInt();
+ }
+ }
+
+ attributes = attr;
+
+ tqparent->addCell( this );
+}
+
+TQTextTableCell::~TQTextTableCell()
+{
+ delete background;
+ background = 0;
+ delete richtext;
+ richtext = 0;
+}
+
+TQSize TQTextTableCell::tqsizeHint() const
+{
+ int extra = 2 * ( tqparent->innerborder + tqparent->cellpadding + border_tolerance);
+ int used = richtext->widthUsed() + extra;
+
+ if (stretch_ ) {
+ int w = tqparent->width * stretch_ / 100 - 2*tqparent->cellspacing - 2*tqparent->cellpadding;
+ return TQSize( TQMIN( w, maxw ), 0 ).expandedTo( tqminimumSize() );
+ }
+
+ return TQSize( used, 0 ).expandedTo( tqminimumSize() );
+}
+
+TQSize TQTextTableCell::tqminimumSize() const
+{
+ int extra = 2 * ( tqparent->innerborder + tqparent->cellpadding + border_tolerance);
+ return TQSize( TQMAX( richtext->minimumWidth() + extra, minw), 0 );
+}
+
+TQSize TQTextTableCell::tqmaximumSize() const
+{
+ return TQSize( maxw, TQWIDGETSIZE_MAX );
+}
+
+TQ_SPExpandData TQTextTableCell::expandingDirections() const
+{
+ return (TQ_SPExpandData)TQSizePolicy::BothDirections;
+}
+
+bool TQTextTableCell::isEmpty() const
+{
+ return FALSE;
+}
+void TQTextTableCell::setGeometry( const TQRect& r )
+{
+ int extra = 2 * ( tqparent->innerborder + tqparent->cellpadding );
+ if ( r.width() != cached_width )
+ richtext->doLayout( TQTextFormat::painter(), r.width() - extra );
+ cached_width = r.width();
+ geom = r;
+}
+
+TQRect TQTextTableCell::tqgeometry() const
+{
+ return geom;
+}
+
+bool TQTextTableCell::hasHeightForWidth() const
+{
+ return TRUE;
+}
+
+int TQTextTableCell::heightForWidth( int w ) const
+{
+ int extra = 2 * ( tqparent->innerborder + tqparent->cellpadding );
+ w = TQMAX( minw, w );
+
+ if ( cached_width != w ) {
+ TQTextTableCell* that = (TQTextTableCell*) this;
+ that->richtext->doLayout( TQTextFormat::painter(), w - extra );
+ that->cached_width = w;
+ }
+ return richtext->height() + extra;
+}
+
+void TQTextTableCell::adjustToPainter( TQPainter* p )
+{
+ TQTextParagraph *parag = richtext->firstParagraph();
+ while ( parag ) {
+ parag->adjustToPainter( p );
+ parag = parag->next();
+ }
+}
+
+int TQTextTableCell::horizontalAlignmentOffset() const
+{
+ return tqparent->cellpadding;
+}
+
+int TQTextTableCell::verticalAlignmentOffset() const
+{
+ if ( (align & TQt::AlignVCenter ) == TQt::AlignVCenter )
+ return ( geom.height() - richtext->height() ) / 2;
+ else if ( ( align & TQt::AlignBottom ) == TQt::AlignBottom )
+ return geom.height() - tqparent->cellpadding - richtext->height() ;
+ return tqparent->cellpadding;
+}
+
+void TQTextTableCell::draw( TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool )
+{
+ if ( cached_width != geom.width() ) {
+ int extra = 2 * ( tqparent->innerborder + tqparent->cellpadding );
+ richtext->doLayout( p, geom.width() - extra );
+ cached_width = geom.width();
+ }
+ TQColorGroup g( cg );
+ if ( background )
+ g.setBrush( TQColorGroup::Base, *background );
+ else if ( richtext->paper() )
+ g.setBrush( TQColorGroup::Base, *richtext->paper() );
+
+ p->save();
+ p->translate( x + geom.x(), y + geom.y() );
+ if ( background )
+ p->fillRect( 0, 0, geom.width(), geom.height(), *background );
+ else if ( richtext->paper() )
+ p->fillRect( 0, 0, geom.width(), geom.height(), *richtext->paper() );
+
+ p->translate( horizontalAlignmentOffset(), verticalAlignmentOffset() );
+
+ TQRegion r;
+ if ( cx >= 0 && cy >= 0 )
+ richtext->draw( p, cx - ( x + horizontalAlignmentOffset() + geom.x() ),
+ cy - ( y + geom.y() + verticalAlignmentOffset() ),
+ cw, ch, g, FALSE, FALSE, 0 );
+ else
+ richtext->draw( p, -1, -1, -1, -1, g, FALSE, FALSE, 0 );
+
+ p->restore();
+}
+#endif
+
+#endif //TQT_NO_RICHTEXT
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqrichtext_p.cpp b/tqtinterface/qt4/src/kernel/tqrichtext_p.cpp
new file mode 100644
index 0000000..d8504df
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqrichtext_p.cpp
@@ -0,0 +1,1283 @@
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+// #if 0
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqrichtext_p.h"
+#include "tqpainter.h"
+
+#ifndef QT_NO_RICHTEXT
+
+QT_BEGIN_NAMESPACE
+
+TQTextCommand::~TQTextCommand() {}
+TQTextCommand::Commands TQTextCommand::type() const { return Invalid; }
+
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+TQTextCustomItem::~TQTextCustomItem() {}
+void TQTextCustomItem::adjustToPainter(TQPainter* p){ if (p) width = 0; }
+TQTextCustomItem::Placement TQTextCustomItem::placement() const { return PlaceInline; }
+
+bool TQTextCustomItem::ownLine() const { return false; }
+void TQTextCustomItem::resize(int nwidth){ width = nwidth; }
+void TQTextCustomItem::invalidate() {}
+
+bool TQTextCustomItem::isNested() const { return false; }
+int TQTextCustomItem::minimumWidth() const { return 0; }
+
+TQString TQTextCustomItem::richText() const { return TQString(); }
+
+bool TQTextCustomItem::enter(TQTextCursor *, TQTextDocument*&, TQTextParagraph *&, int &, int &, int &, bool)
+{
+ return true;
+}
+bool TQTextCustomItem::enterAt(TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int &, const QPoint &)
+{
+ return true;
+}
+bool TQTextCustomItem::next(TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int &)
+{
+ return true;
+}
+bool TQTextCustomItem::prev(TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int &)
+{
+ return true;
+}
+bool TQTextCustomItem::down(TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int &)
+{
+ return true;
+}
+bool TQTextCustomItem::up(TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int &)
+{
+ return true;
+}
+#endif // QT_NO_TEXTCUSTOMITEM
+
+void TQTextFlow::setPageSize(int ps) { pagesize = ps; }
+#ifndef QT_NO_TEXTCUSTOMITEM
+bool TQTextFlow::isEmpty() { return leftItems.isEmpty() && rightItems.isEmpty(); }
+#else
+bool TQTextFlow::isEmpty() { return true; }
+#endif
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+void TQTextTableCell::invalidate() { cached_width = -1; cached_sizehint = -1; }
+
+void TQTextTable::invalidate() { cachewidth = -1; }
+#endif
+
+TQTextParagraphData::~TQTextParagraphData() {}
+void TQTextParagraphData::join(TQTextParagraphData *) {}
+
+TQTextFormatter::~TQTextFormatter() {}
+void TQTextFormatter::setWrapEnabled(bool b) { wrapEnabled = b; }
+void TQTextFormatter::setWrapAtColumn(int c) { wrapColumn = c; }
+
+
+
+int TQTextCursor::x() const
+{
+ if (idx >= para->length())
+ return 0;
+ TQTextStringChar *c = para->at(idx);
+ int curx = c->x;
+ if (!c->rightToLeft &&
+ c->c.isSpace() &&
+ idx > 0 &&
+ para->at(idx - 1)->c != QLatin1Char('\t') &&
+ !c->lineStart &&
+ (para->alignment() & Qt::AlignJustify) == Qt::AlignJustify)
+ curx = para->at(idx - 1)->x + para->string()->width(idx - 1);
+ if (c->rightToLeft)
+ curx += para->string()->width(idx);
+ return curx;
+}
+
+int TQTextCursor::y() const
+{
+ int dummy, line;
+ para->lineStartOfChar(idx, &dummy, &line);
+ return para->lineY(line);
+}
+
+int TQTextCursor::globalX() const { return totalOffsetX() + para->rect().x() + x(); }
+int TQTextCursor::globalY() const { return totalOffsetY() + para->rect().y() + y(); }
+
+TQTextDocument *TQTextCursor::document() const
+{
+ return para ? para->document() : 0;
+}
+
+void TQTextCursor::gotoPosition(TQTextParagraph* p, int index)
+{
+ if (para && p != para) {
+ while (!indices.isEmpty() && para->document() != p->document())
+ pop();
+ Q_ASSERT(indices.isEmpty() || para->document() == p->document());
+ }
+ para = p;
+ if (index < 0 || index >= para->length()) {
+ qWarning("TQTextCursor::gotoParagraph Index: %d out of range", index);
+ if (index < 0 || para->length() == 0)
+ index = 0;
+ else
+ index = para->length() - 1;
+ }
+
+ tmpX = -1;
+ idx = index;
+ fixCursorPosition();
+}
+
+bool TQTextDocument::hasSelection(int id, bool visible) const
+{
+ return (selections.find(id) != selections.end() &&
+ (!visible ||
+ ((TQTextDocument*)this)->selectionStartCursor(id) !=
+ ((TQTextDocument*)this)->selectionEndCursor(id)));
+}
+
+void TQTextDocument::setSelectionStart(int id, const TQTextCursor &cursor)
+{
+ TQTextDocumentSelection sel;
+ sel.startCursor = cursor;
+ sel.endCursor = cursor;
+ sel.swapped = false;
+ selections[id] = sel;
+}
+
+TQTextParagraph *TQTextDocument::paragAt(int i) const
+{
+ TQTextParagraph* p = curParag;
+ if (!p || p->paragId() > i)
+ p = fParag;
+ while (p && p->paragId() != i)
+ p = p->next();
+ ((TQTextDocument*)this)->curParag = p;
+ return p;
+}
+
+
+TQTextFormat::~TQTextFormat()
+{
+}
+
+TQTextFormat::TQTextFormat()
+ : fm(QFontMetrics(fn)), linkColor(true), logicalFontSize(3), stdSize(qApp->font().pointSize())
+{
+ ref = 0;
+
+ usePixelSizes = false;
+ if (stdSize == -1) {
+ stdSize = qApp->font().pixelSize();
+ usePixelSizes = true;
+ }
+
+ missp = false;
+ ha = AlignNormal;
+ collection = 0;
+}
+
+TQTextFormat::TQTextFormat(const TQStyleSheetItem *style)
+ : fm(QFontMetrics(fn)), linkColor(true), logicalFontSize(3), stdSize(qApp->font().pointSize())
+{
+ ref = 0;
+
+ usePixelSizes = false;
+ if (stdSize == -1) {
+ stdSize = qApp->font().pixelSize();
+ usePixelSizes = true;
+ }
+
+ missp = false;
+ ha = AlignNormal;
+ collection = 0;
+ fn = QFont(style->fontFamily(),
+ style->fontSize(),
+ style->fontWeight(),
+ style->fontItalic());
+ fn.setUnderline(style->fontUnderline());
+ fn.setStrikeOut(style->fontStrikeOut());
+ col = style->color();
+ fm = QFontMetrics(fn);
+ leftBearing = fm.minLeftBearing();
+ rightBearing = fm.minRightBearing();
+ hei = fm.lineSpacing();
+ asc = fm.ascent() + (fm.leading()+1)/2;
+ dsc = fm.descent();
+ missp = false;
+ ha = AlignNormal;
+ memset(widths, 0, 256);
+ generateKey();
+ addRef();
+}
+
+TQTextFormat::TQTextFormat(const QFont &f, const QColor &c, TQTextFormatCollection *parent)
+ : fn(f), col(c), fm(QFontMetrics(f)), linkColor(true),
+ logicalFontSize(3), stdSize(f.pointSize())
+{
+ ref = 0;
+ usePixelSizes = false;
+ if (stdSize == -1) {
+ stdSize = f.pixelSize();
+ usePixelSizes = true;
+ }
+ collection = parent;
+ leftBearing = fm.minLeftBearing();
+ rightBearing = fm.minRightBearing();
+ hei = fm.lineSpacing();
+ asc = fm.ascent() + (fm.leading()+1)/2;
+ dsc = fm.descent();
+ missp = false;
+ ha = AlignNormal;
+ memset(widths, 0, 256);
+ generateKey();
+ addRef();
+}
+
+TQTextFormat::TQTextFormat(const TQTextFormat &f)
+ : fm(f.fm)
+{
+ ref = 0;
+ collection = 0;
+ fn = f.fn;
+ col = f.col;
+ leftBearing = f.leftBearing;
+ rightBearing = f.rightBearing;
+ memset(widths, 0, 256);
+ hei = f.hei;
+ asc = f.asc;
+ dsc = f.dsc;
+ stdSize = f.stdSize;
+ usePixelSizes = f.usePixelSizes;
+ logicalFontSize = f.logicalFontSize;
+ missp = f.missp;
+ ha = f.ha;
+ k = f.k;
+ linkColor = f.linkColor;
+ addRef();
+}
+
+TQTextFormat& TQTextFormat::operator=(const TQTextFormat &f)
+{
+ ref = 0;
+ collection = f.collection;
+ fn = f.fn;
+ col = f.col;
+ fm = f.fm;
+ leftBearing = f.leftBearing;
+ rightBearing = f.rightBearing;
+ memset(widths, 0, 256);
+ hei = f.hei;
+ asc = f.asc;
+ dsc = f.dsc;
+ stdSize = f.stdSize;
+ usePixelSizes = f.usePixelSizes;
+ logicalFontSize = f.logicalFontSize;
+ missp = f.missp;
+ ha = f.ha;
+ k = f.k;
+ linkColor = f.linkColor;
+ addRef();
+ return *this;
+}
+
+void TQTextFormat::update()
+{
+ fm = QFontMetrics(fn);
+ leftBearing = fm.minLeftBearing();
+ rightBearing = fm.minRightBearing();
+ hei = fm.lineSpacing();
+ asc = fm.ascent() + (fm.leading()+1)/2;
+ dsc = fm.descent();
+ memset(widths, 0, 256);
+ generateKey();
+}
+
+
+TQPainter* TQTextFormat::pntr = 0;
+QFontMetrics* TQTextFormat::pntr_fm = 0;
+int TQTextFormat::pntr_ldg=-1;
+int TQTextFormat::pntr_asc=-1;
+int TQTextFormat::pntr_hei=-1;
+int TQTextFormat::pntr_dsc=-1;
+
+void TQTextFormat::setPainter(TQPainter *p)
+{
+ pntr = p;
+}
+
+TQPainter* TQTextFormat::painter()
+{
+ return pntr;
+}
+
+void TQTextFormat::applyFont(const QFont &f)
+{
+ QFontMetrics fm(pntr->fontMetrics());
+ if (!pntr_fm || pntr->font() != f) {
+ pntr->setFont(f);
+ delete pntr_fm;
+ pntr_fm = new QFontMetrics(pntr->fontMetrics());
+ pntr_ldg = pntr_fm->leading();
+ pntr_asc = pntr_fm->ascent()+(pntr_ldg+1)/2;
+ pntr_hei = pntr_fm->lineSpacing();
+ pntr_dsc = -1;
+ }
+}
+
+int TQTextFormat::minLeftBearing() const
+{
+ if (!pntr || !pntr->isActive())
+ return leftBearing;
+ applyFont(fn);
+ return pntr_fm->minLeftBearing();
+}
+
+int TQTextFormat::minRightBearing() const
+{
+ if (!pntr || !pntr->isActive())
+ return rightBearing;
+ applyFont(fn);
+ return pntr_fm->minRightBearing();
+}
+
+int TQTextFormat::height() const
+{
+ if (!pntr || !pntr->isActive())
+ return hei;
+ applyFont(fn);
+ return pntr_hei;
+}
+
+int TQTextFormat::ascent() const
+{
+ if (!pntr || !pntr->isActive())
+ return asc;
+ applyFont(fn);
+ return pntr_asc;
+}
+
+int TQTextFormat::descent() const
+{
+ if (!pntr || !pntr->isActive())
+ return dsc;
+ applyFont(fn);
+ if (pntr_dsc < 0)
+ pntr_dsc = pntr_fm->descent();
+ return pntr_dsc;
+}
+
+int TQTextFormat::leading() const
+{
+ if (!pntr || !pntr->isActive())
+ return fm.leading();
+ applyFont(fn);
+ return pntr_ldg;
+}
+
+void TQTextFormat::generateKey()
+{
+ k = getKey(fn, col, isMisspelled(), vAlign());
+}
+
+TQString TQTextFormat::getKey(const QFont &fn, const QColor &col, bool misspelled, VerticalAlignment a)
+{
+ TQString k = fn.key();
+ k += QLatin1Char('/');
+ k += TQString::number((uint)col.rgb());
+ k += QLatin1Char('/');
+ k += TQString::number((int)misspelled);
+ k += QLatin1Char('/');
+ k += TQString::number((int)a);
+ return k;
+}
+
+TQString TQTextString::toString(const QVector<TQTextStringChar> &data)
+{
+ TQString s;
+ int l = data.size();
+ s.setUnicode(0, l);
+ const TQTextStringChar *c = data.data();
+ QChar *uc = (QChar *)s.unicode();
+ while (l--)
+ *(uc++) = (c++)->c;
+
+ return s;
+}
+
+void TQTextParagraph::setSelection(int id, int start, int end)
+{
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = selections().constFind(id);
+ if (it != mSelections->constEnd()) {
+ if (start == (*it).start && end == (*it).end)
+ return;
+ }
+
+ TQTextParagraphSelection sel;
+ sel.start = start;
+ sel.end = end;
+ (*mSelections)[id] = sel;
+ setChanged(true, true);
+}
+
+void TQTextParagraph::removeSelection(int id)
+{
+ if (!hasSelection(id))
+ return;
+ if (mSelections)
+ mSelections->remove(id);
+ setChanged(true, true);
+}
+
+int TQTextParagraph::selectionStart(int id) const
+{
+ if (!mSelections)
+ return -1;
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->constFind(id);
+ if (it == mSelections->constEnd())
+ return -1;
+ return (*it).start;
+}
+
+int TQTextParagraph::selectionEnd(int id) const
+{
+ if (!mSelections)
+ return -1;
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->constFind(id);
+ if (it == mSelections->constEnd())
+ return -1;
+ return (*it).end;
+}
+
+bool TQTextParagraph::hasSelection(int id) const
+{
+ return mSelections ? mSelections->contains(id) : false;
+}
+
+bool TQTextParagraph::fullSelected(int id) const
+{
+ if (!mSelections)
+ return false;
+ QMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->constFind(id);
+ if (it == mSelections->constEnd())
+ return false;
+ return (*it).start == 0 && (*it).end == str->length() - 1;
+}
+
+int TQTextParagraph::lineY(int l) const
+{
+ if (l > (int)lineStarts.count() - 1) {
+ qWarning("TQTextParagraph::lineY: line %d out of range!", l);
+ return 0;
+ }
+
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while (l-- > 0)
+ ++it;
+ return (*it)->y;
+}
+
+int TQTextParagraph::lineBaseLine(int l) const
+{
+ if (l > (int)lineStarts.count() - 1) {
+ qWarning("TQTextParagraph::lineBaseLine: line %d out of range!", l);
+ return 10;
+ }
+
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while (l-- > 0)
+ ++it;
+ return (*it)->baseLine;
+}
+
+int TQTextParagraph::lineHeight(int l) const
+{
+ if (l > (int)lineStarts.count() - 1) {
+ qWarning("TQTextParagraph::lineHeight: line %d out of range!", l);
+ return 15;
+ }
+
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while (l-- > 0)
+ ++it;
+ return (*it)->h;
+}
+
+void TQTextParagraph::lineInfo(int l, int &y, int &h, int &bl) const
+{
+ if (l > (int)lineStarts.count() - 1) {
+ qWarning("TQTextParagraph::lineInfo: line %d out of range!", l);
+ qDebug("%d %d", (int)lineStarts.count() - 1, l);
+ y = 0;
+ h = 15;
+ bl = 10;
+ return;
+ }
+
+ if (!isValid())
+ ((TQTextParagraph*)this)->format();
+
+ QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while (l-- > 0)
+ ++it;
+ y = (*it)->y;
+ h = (*it)->h;
+ bl = (*it)->baseLine;
+}
+
+
+void TQTextParagraph::setAlignment(int a)
+{
+ if (a == (int)align)
+ return;
+ align = a;
+ invalidate(0);
+}
+
+TQTextFormatter *TQTextParagraph::formatter() const
+{
+ if (hasdoc)
+ return document()->formatter();
+ if (pseudoDocument()->pFormatter)
+ return pseudoDocument()->pFormatter;
+ return (((TQTextParagraph*)this)->pseudoDocument()->pFormatter = new TQTextFormatterBreakWords);
+}
+
+void TQTextParagraph::setTabArray(int *a)
+{
+ delete [] tArray;
+ tArray = a;
+}
+
+void TQTextParagraph::setTabStops(int tw)
+{
+ if (hasdoc)
+ document()->setTabStops(tw);
+ else
+ tabStopWidth = tw;
+}
+
+QMap<int, TQTextParagraphSelection> &TQTextParagraph::selections() const
+{
+ if (!mSelections)
+ ((TQTextParagraph *)this)->mSelections = new QMap<int, TQTextParagraphSelection>;
+ return *mSelections;
+}
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+QList<TQTextCustomItem *> &TQTextParagraph::floatingItems() const
+{
+ if (!mFloatingItems)
+ ((TQTextParagraph *)this)->mFloatingItems = new QList<TQTextCustomItem *>;
+ return *mFloatingItems;
+}
+#endif
+
+TQTextStringChar::~TQTextStringChar()
+{
+ if (format())
+ format()->removeRef();
+ if (type) // not Regular
+ delete p.custom;
+}
+
+TQTextParagraphPseudoDocument::TQTextParagraphPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0),collection(){}
+TQTextParagraphPseudoDocument::~TQTextParagraphPseudoDocument(){ delete pFormatter; delete commandHistory; }
+
+
+QT_END_NAMESPACE
+
+#endif //QT_NO_RICHTEXT
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of the internal TQt classes dealing with rich text
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqrichtext_p.h"
+
+#ifndef TQT_NO_RICHTEXT
+
+TQTextCommand::~TQTextCommand() {}
+TQTextCommand::Commands TQTextCommand::type() const { return Invalid; }
+
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+TQTextCustomItem::~TQTextCustomItem() {}
+void TQTextCustomItem::adjustToPainter( TQPainter* p){ if ( p ) width = 0; }
+TQTextCustomItem::Placement TQTextCustomItem::placement() const { return PlaceInline; }
+
+bool TQTextCustomItem::ownLine() const { return FALSE; }
+void TQTextCustomItem::resize( int nwidth ){ width = nwidth; }
+void TQTextCustomItem::tqinvalidate() {}
+
+bool TQTextCustomItem::isNested() const { return FALSE; }
+int TQTextCustomItem::minimumWidth() const { return 0; }
+
+TQString TQTextCustomItem::richText() const { return TQString::null; }
+
+bool TQTextCustomItem::enter( TQTextCursor *, TQTextDocument*&, TQTextParagraph *&, int &, int &, int &, bool )
+{
+ return TRUE;
+}
+bool TQTextCustomItem::enterAt( TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int &, const TQPoint & )
+{
+ return TRUE;
+}
+bool TQTextCustomItem::next( TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int & )
+{
+ return TRUE;
+}
+bool TQTextCustomItem::prev( TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int & )
+{
+ return TRUE;
+}
+bool TQTextCustomItem::down( TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int & )
+{
+ return TRUE;
+}
+bool TQTextCustomItem::up( TQTextCursor *, TQTextDocument *&, TQTextParagraph *&, int &, int &, int & )
+{
+ return TRUE;
+}
+#endif // TQT_NO_TEXTCUSTOMITEM
+
+void TQTextFlow::setPageSize( int ps ) { pagesize = ps; }
+#ifndef TQT_NO_TEXTCUSTOMITEM
+bool TQTextFlow::isEmpty() { return leftItems.isEmpty() && rightItems.isEmpty(); }
+#else
+bool TQTextFlow::isEmpty() { return TRUE; }
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+void TQTextTableCell::tqinvalidate() { cached_width = -1; cached_sizehint = -1; }
+
+void TQTextTable::tqinvalidate() { cachewidth = -1; }
+#endif
+
+TQTextParagraphData::~TQTextParagraphData() {}
+void TQTextParagraphData::join( TQTextParagraphData * ) {}
+
+TQTextFormatter::~TQTextFormatter() {}
+void TQTextFormatter::setWrapEnabled( bool b ) { wrapEnabled = b; }
+void TQTextFormatter::setWrapAtColumn( int c ) { wrapColumn = c; }
+
+
+
+int TQTextCursor::x() const
+{
+ if ( idx >= para->length() )
+ return 0;
+ TQTextStringChar *c = para->at( idx );
+ int curx = c->x;
+ if ( !c->rightToLeft &&
+ c->c.isSpace() &&
+ idx > 0 &&
+ para->at( idx - 1 )->c != '\t' &&
+ !c->lineStart &&
+ ( para->tqalignment() & TQt::AlignJustify ) == TQt::AlignJustify )
+ curx = para->at( idx - 1 )->x + para->string()->width( idx - 1 );
+ if ( c->rightToLeft )
+ curx += para->string()->width( idx );
+ return curx;
+}
+
+int TQTextCursor::y() const
+{
+ int dummy, line;
+ para->lineStartOfChar( idx, &dummy, &line );
+ return para->lineY( line );
+}
+
+int TQTextCursor::globalX() const { return totalOffsetX() + para->rect().x() + x(); }
+int TQTextCursor::globalY() const { return totalOffsetY() + para->rect().y() + y(); }
+
+TQTextDocument *TQTextCursor::document() const
+{
+ return para ? para->document() : 0;
+}
+
+void TQTextCursor::gotoPosition( TQTextParagraph* p, int index )
+{
+ if ( para && p != para ) {
+ while ( !indices.isEmpty() && para->document() != p->document() )
+ pop();
+ TQ_ASSERT( indices.isEmpty() || para->document() == p->document() );
+ }
+ para = p;
+ if ( index < 0 || index >= para->length() ) {
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQTextCursor::gotoParagraph Index: %d out of range", index );
+#endif
+ if ( index < 0 || para->length() == 0 )
+ index = 0;
+ else
+ index = para->length() - 1;
+ }
+
+ tmpX = -1;
+ idx = index;
+ fixCursorPosition();
+}
+
+bool TQTextDocument::hasSelection( int id, bool visible ) const
+{
+ return ( selections.tqfind( id ) != selections.end() &&
+ ( !visible ||
+ ( (TQTextDocument*)this )->selectionStartCursor( id ) !=
+ ( (TQTextDocument*)this )->selectionEndCursor( id ) ) );
+}
+
+void TQTextDocument::setSelectionStart( int id, const TQTextCursor &cursor )
+{
+ TQTextDocumentSelection sel;
+ sel.startCursor = cursor;
+ sel.endCursor = cursor;
+ sel.swapped = FALSE;
+ selections[ id ] = sel;
+}
+
+TQTextParagraph *TQTextDocument::paragAt( int i ) const
+{
+ TQTextParagraph* p = curParag;
+ if ( !p || p->paragId() > i )
+ p = fParag;
+ while ( p && p->paragId() != i )
+ p = p->next();
+ ((TQTextDocument*)this)->curParag = p;
+ return p;
+}
+
+
+TQTextFormat::~TQTextFormat()
+{
+}
+
+TQTextFormat::TQTextFormat()
+ : fm( TQFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( tqApp->font().pointSize() )
+{
+ ref = 0;
+
+ usePixelSizes = FALSE;
+ if ( stdSize == -1 ) {
+ stdSize = tqApp->font().pixelSize();
+ usePixelSizes = TRUE;
+ }
+
+ missp = FALSE;
+ ha = AlignNormal;
+ collection = 0;
+}
+
+TQTextFormat::TQTextFormat( const TQStyleSheetItem *style )
+ : fm( TQFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( tqApp->font().pointSize() )
+{
+ ref = 0;
+
+ usePixelSizes = FALSE;
+ if ( stdSize == -1 ) {
+ stdSize = tqApp->font().pixelSize();
+ usePixelSizes = TRUE;
+ }
+
+ missp = FALSE;
+ ha = AlignNormal;
+ collection = 0;
+ fn = TQFont( style->fontFamily(),
+ style->fontSize(),
+ style->fontWeight(),
+ style->fontItalic() );
+ fn.setUnderline( style->fontUnderline() );
+ fn.setStrikeOut( style->fontStrikeOut() );
+ col = style->color();
+ fm = TQFontMetrics( fn );
+ leftBearing = fm.minLeftBearing();
+ rightBearing = fm.minRightBearing();
+ hei = fm.lineSpacing();
+ asc = fm.ascent() + (fm.leading()+1)/2;
+ dsc = fm.descent();
+ missp = FALSE;
+ ha = AlignNormal;
+ memset( widths, 0, 256 );
+ generateKey();
+ addRef();
+}
+
+TQTextFormat::TQTextFormat( const TQFont &f, const TQColor &c, TQTextFormatCollection *tqparent )
+ : fn( f ), col( c ), fm( TQFontMetrics( f ) ), linkColor( TRUE ),
+ logicalFontSize( 3 ), stdSize( f.pointSize() )
+{
+ ref = 0;
+ usePixelSizes = FALSE;
+ if ( stdSize == -1 ) {
+ stdSize = f.pixelSize();
+ usePixelSizes = TRUE;
+ }
+ collection = tqparent;
+ leftBearing = fm.minLeftBearing();
+ rightBearing = fm.minRightBearing();
+ hei = fm.lineSpacing();
+ asc = fm.ascent() + (fm.leading()+1)/2;
+ dsc = fm.descent();
+ missp = FALSE;
+ ha = AlignNormal;
+ memset( widths, 0, 256 );
+ generateKey();
+ addRef();
+}
+
+TQTextFormat::TQTextFormat( const TQTextFormat &f )
+ : fm( f.fm )
+{
+ ref = 0;
+ collection = 0;
+ fn = f.fn;
+ col = f.col;
+ leftBearing = f.leftBearing;
+ rightBearing = f.rightBearing;
+ memset( widths, 0, 256 );
+ hei = f.hei;
+ asc = f.asc;
+ dsc = f.dsc;
+ stdSize = f.stdSize;
+ usePixelSizes = f.usePixelSizes;
+ logicalFontSize = f.logicalFontSize;
+ missp = f.missp;
+ ha = f.ha;
+ k = f.k;
+ linkColor = f.linkColor;
+ addRef();
+}
+
+TQTextFormat& TQTextFormat::operator=( const TQTextFormat &f )
+{
+ ref = 0;
+ collection = f.collection;
+ fn = f.fn;
+ col = f.col;
+ fm = f.fm;
+ leftBearing = f.leftBearing;
+ rightBearing = f.rightBearing;
+ memset( widths, 0, 256 );
+ hei = f.hei;
+ asc = f.asc;
+ dsc = f.dsc;
+ stdSize = f.stdSize;
+ usePixelSizes = f.usePixelSizes;
+ logicalFontSize = f.logicalFontSize;
+ missp = f.missp;
+ ha = f.ha;
+ k = f.k;
+ linkColor = f.linkColor;
+ addRef();
+ return *this;
+}
+
+void TQTextFormat::update()
+{
+ fm = TQFontMetrics( fn );
+ leftBearing = fm.minLeftBearing();
+ rightBearing = fm.minRightBearing();
+ hei = fm.lineSpacing();
+ asc = fm.ascent() + (fm.leading()+1)/2;
+ dsc = fm.descent();
+ memset( widths, 0, 256 );
+ generateKey();
+}
+
+
+TQPainter* TQTextFormat::pntr = 0;
+TQFontMetrics* TQTextFormat::pntr_fm = 0;
+int TQTextFormat::pntr_ldg=-1;
+int TQTextFormat::pntr_asc=-1;
+int TQTextFormat::pntr_hei=-1;
+int TQTextFormat::pntr_dsc=-1;
+
+void TQTextFormat::setPainter( TQPainter *p )
+{
+ pntr = p;
+}
+
+TQPainter* TQTextFormat::painter()
+{
+ return pntr;
+}
+
+void TQTextFormat::applyFont( const TQFont &f )
+{
+ TQFontMetrics fm( pntr->fontMetrics() );
+ if ( !pntr_fm
+// || pntr_fm->painter != pntr
+// || pntr_fm->d != fm.d
+ || !pntr->font().isCopyOf( f ) ) {
+ pntr->setFont( f );
+ delete pntr_fm;
+ pntr_fm = new TQFontMetrics( pntr->fontMetrics() );
+ pntr_ldg = pntr_fm->leading();
+ pntr_asc = pntr_fm->ascent()+(pntr_ldg+1)/2;
+ pntr_hei = pntr_fm->lineSpacing();
+ pntr_dsc = -1;
+ }
+}
+
+int TQTextFormat::minLeftBearing() const
+{
+ if ( !pntr || !pntr->isActive() )
+ return leftBearing;
+ applyFont( fn );
+ return pntr_fm->minLeftBearing();
+}
+
+int TQTextFormat::minRightBearing() const
+{
+ if ( !pntr || !pntr->isActive() )
+ return rightBearing;
+ applyFont( fn );
+ return pntr_fm->minRightBearing();
+}
+
+int TQTextFormat::height() const
+{
+ if ( !pntr || !pntr->isActive() )
+ return hei;
+ applyFont( fn );
+ return pntr_hei;
+}
+
+int TQTextFormat::ascent() const
+{
+ if ( !pntr || !pntr->isActive() )
+ return asc;
+ applyFont( fn );
+ return pntr_asc;
+}
+
+int TQTextFormat::descent() const
+{
+ if ( !pntr || !pntr->isActive() )
+ return dsc;
+ applyFont( fn );
+ if ( pntr_dsc < 0 )
+ pntr_dsc = pntr_fm->descent();
+ return pntr_dsc;
+}
+
+int TQTextFormat::leading() const
+{
+ if ( !pntr || !pntr->isActive() )
+ return fm.leading();
+ applyFont( fn );
+ return pntr_ldg;
+}
+
+void TQTextFormat::generateKey()
+{
+ k = getKey( fn, col, isMisspelled(), vAlign() );
+}
+
+TQString TQTextFormat::getKey( const TQFont &fn, const TQColor &col, bool misspelled, VerticalAlignment a )
+{
+ TQString k = fn.key();
+ k += '/';
+ k += TQString::number( (uint)col.rgb() );
+ k += '/';
+ k += TQString::number( (int)misspelled );
+ k += '/';
+ k += TQString::number( (int)a );
+ return k;
+}
+
+TQString TQTextString::toString( const TQMemArray<TQTextStringChar> &data )
+{
+ TQString s;
+ int l = data.size();
+ s.setUnicode( 0, l );
+ TQTextStringChar *c = data.data();
+ TQChar *uc = (TQChar *)s.tqunicode();
+ while ( l-- )
+ *(uc++) = (c++)->c;
+
+ return s;
+}
+
+void TQTextParagraph::setSelection( int id, int start, int end )
+{
+ TQMap<int, TQTextParagraphSelection>::ConstIterator it = selections().tqfind( id );
+ if ( it != mSelections->end() ) {
+ if ( start == ( *it ).start && end == ( *it ).end )
+ return;
+ }
+
+ TQTextParagraphSelection sel;
+ sel.start = start;
+ sel.end = end;
+ (*mSelections)[ id ] = sel;
+ setChanged( TRUE, TRUE );
+}
+
+void TQTextParagraph::removeSelection( int id )
+{
+ if ( !hasSelection( id ) )
+ return;
+ if ( mSelections )
+ mSelections->remove( id );
+ setChanged( TRUE, TRUE );
+}
+
+int TQTextParagraph::selectionStart( int id ) const
+{
+ if ( !mSelections )
+ return -1;
+ TQMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->tqfind( id );
+ if ( it == mSelections->end() )
+ return -1;
+ return ( *it ).start;
+}
+
+int TQTextParagraph::selectionEnd( int id ) const
+{
+ if ( !mSelections )
+ return -1;
+ TQMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->tqfind( id );
+ if ( it == mSelections->end() )
+ return -1;
+ return ( *it ).end;
+}
+
+bool TQTextParagraph::hasSelection( int id ) const
+{
+ return mSelections ? mSelections->tqcontains( id ) : FALSE;
+}
+
+bool TQTextParagraph::fullSelected( int id ) const
+{
+ if ( !mSelections )
+ return FALSE;
+ TQMap<int, TQTextParagraphSelection>::ConstIterator it = mSelections->tqfind( id );
+ if ( it == mSelections->end() )
+ return FALSE;
+ return ( *it ).start == 0 && ( *it ).end == str->length() - 1;
+}
+
+int TQTextParagraph::lineY( int l ) const
+{
+ if ( l > (int)lineStarts.count() - 1 ) {
+ qWarning( "TQTextParagraph::lineY: line %d out of range!", l );
+ return 0;
+ }
+
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ TQMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while ( l-- > 0 )
+ ++it;
+ return ( *it )->y;
+}
+
+int TQTextParagraph::lineBaseLine( int l ) const
+{
+ if ( l > (int)lineStarts.count() - 1 ) {
+ qWarning( "TQTextParagraph::lineBaseLine: line %d out of range!", l );
+ return 10;
+ }
+
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ TQMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while ( l-- > 0 )
+ ++it;
+ return ( *it )->baseLine;
+}
+
+int TQTextParagraph::lineHeight( int l ) const
+{
+ if ( l > (int)lineStarts.count() - 1 ) {
+ qWarning( "TQTextParagraph::lineHeight: line %d out of range!", l );
+ return 15;
+ }
+
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ TQMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while ( l-- > 0 )
+ ++it;
+ return ( *it )->h;
+}
+
+void TQTextParagraph::lineInfo( int l, int &y, int &h, int &bl ) const
+{
+ if ( l > (int)lineStarts.count() - 1 ) {
+ qWarning( "TQTextParagraph::lineInfo: line %d out of range!", l );
+ qDebug( "%d %d", (int)lineStarts.count() - 1, l );
+ y = 0;
+ h = 15;
+ bl = 10;
+ return;
+ }
+
+ if ( !isValid() )
+ ( (TQTextParagraph*)this )->format();
+
+ TQMap<int, TQTextLineStart*>::ConstIterator it = lineStarts.begin();
+ while ( l-- > 0 )
+ ++it;
+ y = ( *it )->y;
+ h = ( *it )->h;
+ bl = ( *it )->baseLine;
+}
+
+
+void TQTextParagraph::tqsetAlignment( int a )
+{
+ if ( a == (int)align )
+ return;
+ align = a;
+ tqinvalidate( 0 );
+}
+
+TQTextFormatter *TQTextParagraph::formatter() const
+{
+ if ( hasdoc )
+ return document()->formatter();
+ if ( pseudoDocument()->pFormatter )
+ return pseudoDocument()->pFormatter;
+ return ( ( (TQTextParagraph*)this )->pseudoDocument()->pFormatter = new TQTextFormatterBreakWords );
+}
+
+void TQTextParagraph::setTabArray( int *a )
+{
+ delete [] tArray;
+ tArray = a;
+}
+
+void TQTextParagraph::setTabStops( int tw )
+{
+ if ( hasdoc )
+ document()->setTabStops( tw );
+ else
+ tabStopWidth = tw;
+}
+
+TQMap<int, TQTextParagraphSelection> &TQTextParagraph::selections() const
+{
+ if ( !mSelections )
+ ((TQTextParagraph *)this)->mSelections = new TQMap<int, TQTextParagraphSelection>;
+ return *mSelections;
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+TQPtrList<TQTextCustomItem> &TQTextParagraph::floatingItems() const
+{
+ if ( !mFloatingItems )
+ ((TQTextParagraph *)this)->mFloatingItems = new TQPtrList<TQTextCustomItem>;
+ return *mFloatingItems;
+}
+#endif
+
+TQTextStringChar::~TQTextStringChar()
+{
+ if ( format() )
+ format()->removeRef();
+ if ( type ) // not Regular
+ delete d.custom;
+}
+
+TQTextParagraphPseudoDocument::TQTextParagraphPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0),collection(){}
+TQTextParagraphPseudoDocument::~TQTextParagraphPseudoDocument(){ delete pFormatter; delete commandHistory; }
+
+
+#endif //TQT_NO_RICHTEXT
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqrichtext_p.h b/tqtinterface/qt4/src/kernel/tqrichtext_p.h
new file mode 100644
index 0000000..b9cbd98
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqrichtext_p.h
@@ -0,0 +1,4300 @@
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+// #if 0
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TQRICHTEXT_P_H
+#define TQRICHTEXT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of a number of Qt sources files. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtGui/qapplication.h"
+#include "QtGui/qcolor.h"
+#include "QtCore/qhash.h"
+#include "QtGui/qfont.h"
+#include "QtGui/qfontmetrics.h"
+#include "QtGui/qlayout.h"
+#include "QtCore/qmap.h"
+#include "QtCore/qvector.h"
+#include "QtCore/qstack.h"
+#include "QtCore/qlist.h"
+#include "QtCore/qobject.h"
+#include "QtGui/qpainter.h"
+#include "QtGui/qpixmap.h"
+#include "QtCore/qrect.h"
+#include "QtCore/qsize.h"
+#include "QtCore/qstring.h"
+#include "QtCore/qstringlist.h"
+#include "tqstylesheet.h"
+#include "tqmime.h"
+#include "tqpalette.h"
+#include "tqpixmap.h"
+#include "tqbrush.h"
+#include "tqlayout.h"
+
+#define TQLatin1String TQString
+#define TQLatin1Char TQChar
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_RICHTEXT
+
+class TQTextDocument;
+class TQTextString;
+class TQTextPreProcessor;
+class TQTextFormat;
+class TQTextCursor;
+class TQTextParagraph;
+class TQTextFormatter;
+class TQTextIndent;
+class TQTextFormatCollection;
+class TQStyleSheetItem;
+#ifndef QT_NO_TEXTCUSTOMITEM
+class TQTextCustomItem;
+#endif
+class TQTextFlow;
+struct QBidiContext;
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextStringChar
+{
+ friend class TQTextString;
+
+public:
+ // this is never called, initialize variables in TQTextString::insert()!!!
+ TQTextStringChar() : nobreak(false), lineStart(0), type(Regular) {p.format=0;}
+ ~TQTextStringChar();
+
+ struct CustomData
+ {
+ TQTextFormat *format;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem *custom;
+#endif
+ TQString anchorName;
+ TQString anchorHref;
+ };
+ enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 };
+
+ TQChar c;
+ // this is the same struct as in qtextengine_p.h. Don't change!
+ uchar softBreak :1; // Potential linebreak point
+ uchar whiteSpace :1; // A unicode whitespace character, except NBSP, ZWNBSP
+ uchar charStop :1; // Valid cursor position (for left/right arrow)
+ uchar nobreak :1;
+
+ uchar lineStart : 1;
+ uchar /*Type*/ type : 2;
+ uchar bidiLevel :7;
+ uchar rightToLeft : 1;
+
+ int x;
+ union {
+ TQTextFormat* format;
+ CustomData* custom;
+ } p;
+
+
+ int height() const;
+ int ascent() const;
+ int descent() const;
+ bool isCustom() const { return (type & Custom) != 0; }
+ TQTextFormat *format() const;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem *customItem() const;
+#endif
+ void setFormat(TQTextFormat *f);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ void setCustomItem(TQTextCustomItem *i);
+#endif
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ void loseCustomItem();
+#endif
+
+
+ bool isAnchor() const { return (type & Anchor) != 0; }
+ bool isLink() const { return isAnchor() && p.custom->anchorHref.count(); }
+ TQString anchorName() const;
+ TQString anchorHref() const;
+ void setAnchor(const TQString& name, const TQString& href);
+
+ TQTextStringChar(const TQTextStringChar &) {
+ Q_ASSERT(false);
+ }
+private:
+ TQTextStringChar &operator=(const TQTextStringChar &) {
+ //abort();
+ return *this;
+ }
+ friend class TQTextParagraph;
+};
+
+Q_DECLARE_TYPEINFO(TQTextStringChar, Q_PRIMITIVE_TYPE);
+
+class Q_COMPAT_EXPORT TQTextString
+{
+public:
+
+ TQTextString();
+ TQTextString(const TQTextString &s);
+ virtual ~TQTextString();
+
+ static TQString toString(const QVector<TQTextStringChar> &data);
+ TQString toString() const;
+
+ inline TQTextStringChar &at(int i) const {
+ return const_cast<TQTextString *>(this)->data[i];
+ }
+ inline int length() const { return data.size(); }
+
+ int width(int idx) const;
+
+ void insert(int index, const QString &s, TQTextFormat *f);
+ void insert(int index, const QChar *unicode, int len, TQTextFormat *f);
+ void insert(int index, TQTextStringChar *c, bool doAddRefFormat = false);
+ void truncate(int index);
+ void remove(int index, int len);
+ void clear();
+
+ void setFormat(int index, TQTextFormat *f, bool useCollection);
+
+ void setBidi(bool b) { bidi = b; }
+ bool isBidi() const;
+ bool isRightToLeft() const;
+ TQChar::Direction direction() const;
+ void setDirection(TQChar::Direction dr) { dir = dr; bidiDirty = true; }
+
+ QVector<TQTextStringChar> rawData() const { return data; }
+
+ void operator=(const TQString &s) { clear(); insert(0, s, 0); }
+ void operator+=(const TQString &s) { insert(length(), s, 0); }
+ void prepend(const TQString &s) { insert(0, s, 0); }
+ int appendParagraphs( TQTextParagraph *start, TQTextParagraph *end );
+
+ // return next and previous valid cursor positions.
+ bool validCursorPosition(int idx);
+ int nextCursorPosition(int idx);
+ int previousCursorPosition(int idx);
+
+private:
+ void checkBidi() const;
+
+private:
+ QVector<TQTextStringChar> data;
+ TQString stringCache;
+ uint bidiDirty : 1;
+ uint bidi : 1; // true when the paragraph has right to left characters
+ uint rightToLeft : 1;
+ uint dir : 5;
+};
+
+inline bool TQTextString::isBidi() const
+{
+ if (bidiDirty)
+ checkBidi();
+ return bidi;
+}
+
+inline bool TQTextString::isRightToLeft() const
+{
+ if (bidiDirty)
+ checkBidi();
+ return rightToLeft;
+}
+
+inline TQString TQTextString::toString() const
+{
+ if (bidiDirty)
+ checkBidi();
+ return stringCache;
+}
+
+inline TQChar::Direction TQTextString::direction() const
+{
+ return rightToLeft ? TQChar::DirR : TQChar::DirL;
+}
+
+inline int TQTextString::nextCursorPosition(int next)
+{
+ if (bidiDirty)
+ checkBidi();
+
+ const TQTextStringChar *c = data.data();
+ int len = length();
+
+ if (next < len - 1) {
+ next++;
+ while (next < len - 1 && !c[next].charStop)
+ next++;
+ }
+ return next;
+}
+
+inline int TQTextString::previousCursorPosition(int prev)
+{
+ if (bidiDirty)
+ checkBidi();
+
+ const TQTextStringChar *c = data.data();
+
+ if (prev) {
+ prev--;
+ while (prev && !c[prev].charStop)
+ prev--;
+ }
+ return prev;
+}
+
+inline bool TQTextString::validCursorPosition(int idx)
+{
+ if (bidiDirty)
+ checkBidi();
+
+ return (at(idx).charStop);
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextCursor
+{
+public:
+ TQTextCursor(TQTextDocument * = 0);
+ TQTextCursor(const TQTextCursor &c);
+ TQTextCursor &operator=(const TQTextCursor &c);
+ virtual ~TQTextCursor();
+
+ bool operator==(const TQTextCursor &c) const;
+ bool operator!=(const TQTextCursor &c) const { return !(*this == c); }
+
+ inline TQTextParagraph *paragraph() const { return para; }
+
+ TQTextDocument *document() const;
+ int index() const;
+
+ void gotoPosition(TQTextParagraph* p, int index = 0);
+ void setIndex(int index) { gotoPosition(paragraph(), index); }
+ void setParagraph(TQTextParagraph*p) { gotoPosition(p, 0); }
+
+ void gotoLeft();
+ void gotoRight();
+ void gotoNextLetter();
+ void gotoPreviousLetter();
+ void gotoUp();
+ void gotoDown();
+ void gotoLineEnd();
+ void gotoLineStart();
+ void gotoHome();
+ void gotoEnd();
+ void gotoPageUp(int visibleHeight);
+ void gotoPageDown(int visibleHeight);
+ void gotoNextWord(bool onlySpace = false);
+ void gotoPreviousWord(bool onlySpace = false);
+ void gotoWordLeft();
+ void gotoWordRight();
+
+ void insert(const QString &s, bool checkNewLine, QVector<TQTextStringChar> *formatting = 0);
+ void splitAndInsertEmptyParagraph(bool ind = true, bool updateIds = true);
+ bool remove();
+ bool removePreviousChar();
+ void indent();
+
+ bool atParagStart();
+ bool atParagEnd();
+
+ int x() const; // x in current paragraph
+ int y() const; // y in current paragraph
+
+ int globalX() const;
+ int globalY() const;
+
+ TQTextParagraph *topParagraph() const { return paras.isEmpty() ? para : paras.first(); }
+ int offsetX() const { return ox; } // inner document offset
+ int offsetY() const { return oy; } // inner document offset
+ int totalOffsetX() const; // total document offset
+ int totalOffsetY() const; // total document offset
+
+ bool place(const QPoint &pos, TQTextParagraph *s) { return place(pos, s, false); }
+ bool place(const QPoint &pos, TQTextParagraph *s, bool link);
+ void restoreState();
+
+
+ int nestedDepth() const { return (int)indices.count(); } //### size_t/int cast
+ void oneUp() { if (!indices.isEmpty()) pop(); }
+ void setValid(bool b) { valid = b; }
+ bool isValid() const { return valid; }
+
+ void fixCursorPosition();
+private:
+ enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
+
+ void push();
+ void pop();
+ bool processNesting(Operation op);
+ void invalidateNested();
+ void gotoIntoNested(const QPoint &globalPos);
+
+ TQTextParagraph *para;
+ int idx, tmpX;
+ int ox, oy;
+ QStack<int> indices;
+ QStack<TQTextParagraph*> paras;
+ QStack<int> xOffsets;
+ QStack<int> yOffsets;
+ uint valid : 1;
+
+};
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextCommand
+{
+public:
+ enum Commands { Invalid, Insert, Delete, Format, Style };
+
+ TQTextCommand(TQTextDocument *dc) : doc(dc), cursor(dc) {}
+ virtual ~TQTextCommand();
+
+ virtual Commands type() const;
+
+ virtual TQTextCursor *execute(TQTextCursor *c) = 0;
+ virtual TQTextCursor *unexecute(TQTextCursor *c) = 0;
+
+protected:
+ TQTextDocument *doc;
+ TQTextCursor cursor;
+
+};
+
+class Q_COMPAT_EXPORT TQTextCommandHistory
+{
+public:
+ TQTextCommandHistory(int s) : current(-1), steps(s) { }
+ virtual ~TQTextCommandHistory(); // ### why is it virtual?
+
+ void clear();
+
+ void addCommand(TQTextCommand *cmd);
+ TQTextCursor *undo(TQTextCursor *c);
+ TQTextCursor *redo(TQTextCursor *c);
+
+ bool isUndoAvailable();
+ bool isRedoAvailable();
+
+ void setUndoDepth(int depth) { steps = depth; }
+ int undoDepth() const { return steps; }
+
+ int historySize() const { return history.count(); }
+ int currentPosition() const { return current; }
+
+private:
+ QList<TQTextCommand *> history;
+ int current, steps;
+};
+
+inline TQTextCommandHistory::~TQTextCommandHistory()
+{
+ clear();
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+class Q_COMPAT_EXPORT TQTextCustomItem
+{
+public:
+ TQTextCustomItem(TQTextDocument *p)
+ : xpos(0), ypos(-1), width(-1), height(0), parent(p)
+ {}
+ virtual ~TQTextCustomItem();
+ virtual void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected) = 0;
+
+ virtual void adjustToPainter(TQPainter*);
+
+ enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
+ virtual Placement placement() const;
+ bool placeInline() { return placement() == PlaceInline; }
+
+ virtual bool ownLine() const;
+ virtual void resize(int nwidth);
+ virtual void invalidate();
+ virtual int ascent() const { return height; }
+
+ virtual bool isNested() const;
+ virtual int minimumWidth() const;
+
+ virtual TQString richText() const;
+
+ int xpos; // used for floating items
+ int ypos; // used for floating items
+ int width;
+ int height;
+
+ TQRect geometry() const { return TQRect(xpos, ypos, width, height); }
+
+ virtual bool enter(TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = false);
+ virtual bool enterAt(TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, const QPoint &);
+ virtual bool next(TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+ virtual bool prev(TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+ virtual bool down(TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+ virtual bool up(TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+
+ void setParagraph(TQTextParagraph *p) { parag = p; }
+ TQTextParagraph *paragraph() const { return parag; }
+
+ TQTextDocument *parent;
+ TQTextParagraph *parag;
+
+ virtual void pageBreak(int y, TQTextFlow* flow);
+};
+#endif
+
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+class Q_COMPAT_EXPORT TQTextImage : public TQTextCustomItem
+{
+public:
+ TQTextImage(TQTextDocument *p, const QMap<TQString, TQString> &attr, const TQString& context,
+ TQMimeSourceFactory &factory);
+ virtual ~TQTextImage();
+
+ Placement placement() const { return place; }
+ void adjustToPainter(TQPainter*);
+ int minimumWidth() const { return width; }
+
+ TQString richText() const;
+
+ void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected);
+
+private:
+ QRegion* reg;
+ TQPixmap pm;
+ Placement place;
+ int tmpwidth, tmpheight;
+ QMap<TQString, TQString> attributes;
+ TQString imgId;
+
+};
+#endif
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+class Q_COMPAT_EXPORT TQTextHorizontalLine : public TQTextCustomItem
+{
+public:
+ TQTextHorizontalLine(TQTextDocument *p, const QMap<TQString, TQString> &attr, const TQString& context,
+ TQMimeSourceFactory &factory);
+ virtual ~TQTextHorizontalLine();
+
+ void adjustToPainter(TQPainter*);
+ void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected);
+ TQString richText() const;
+
+ bool ownLine() const { return true; }
+
+private:
+ int tmpheight;
+ QColor color;
+ bool shade;
+
+};
+#endif
+
+class Q_COMPAT_EXPORT TQTextFlow
+{
+ friend class TQTextDocument;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ friend class TQTextTableCell;
+#endif
+
+public:
+ TQTextFlow();
+ virtual ~TQTextFlow();
+
+ virtual void setWidth(int width);
+ int width() const;
+
+ virtual void setPageSize(int ps);
+ int pageSize() const { return pagesize; }
+
+ virtual int adjustLMargin(int yp, int h, int margin, int space);
+ virtual int adjustRMargin(int yp, int h, int margin, int space);
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ virtual void registerFloatingItem(TQTextCustomItem* item);
+ virtual void unregisterFloatingItem(TQTextCustomItem* item);
+#endif
+ virtual TQRect boundingRect() const;
+ virtual void drawFloatingItems(TQPainter* p, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected);
+
+ virtual int adjustFlow(int y, int w, int h); // adjusts y according to the defined pagesize. Returns the shift.
+
+ virtual bool isEmpty();
+
+ void clear();
+
+private:
+ int w;
+ int pagesize;
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ QList<TQTextCustomItem *> leftItems;
+ QList<TQTextCustomItem *> rightItems;
+#endif
+};
+
+inline int TQTextFlow::width() const { return w; }
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+class TQTextTable;
+
+class Q_COMPAT_EXPORT TQTextTableCell : public TQLayoutItem
+{
+ friend class TQTextTable;
+
+public:
+ TQTextTableCell(TQTextTable* table,
+ int row, int column,
+ const QMap<TQString, TQString> &attr,
+ const TQStyleSheetItem* style,
+ const TQTextFormat& fmt, const TQString& context,
+ TQMimeSourceFactory &factory, TQStyleSheet *sheet, const TQString& doc);
+ virtual ~TQTextTableCell();
+
+ TQSize tqsizeHint() const ;
+ TQSize tqminimumSize() const ;
+ TQSize tqmaximumSize() const ;
+ Qt::Orientations expandingDirections() const;
+ bool isEmpty() const;
+ void setGeometry(const TQRect&) ;
+ TQRect tqgeometry() const;
+
+ bool hasHeightForWidth() const;
+ int heightForWidth(int) const;
+
+ void adjustToPainter(TQPainter*);
+
+ int row() const { return row_; }
+ int column() const { return col_; }
+ int rowspan() const { return rowspan_; }
+ int colspan() const { return colspan_; }
+ int stretch() const { return stretch_; }
+
+ TQTextDocument* richText() const { return richtext; }
+ TQTextTable* table() const { return parent; }
+
+ void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &cg, bool selected);
+
+ TQBrush *backGround() const { return background; }
+ virtual void invalidate();
+
+ int verticalAlignmentOffset() const;
+ int horizontalAlignmentOffset() const;
+
+ QLAYOUTITEM_REQUIRED_FUNCTIONS
+
+private:
+ TQRect geom;
+ TQTextTable* parent;
+ TQTextDocument* richtext;
+ int row_;
+ int col_;
+ int rowspan_;
+ int colspan_;
+ int stretch_;
+ int maxw;
+ int minw;
+ bool hasFixedWidth;
+ TQBrush *background;
+ int cached_width;
+ int cached_sizehint;
+ QMap<TQString, TQString> attributes;
+ int align;
+};
+#endif
+
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+class Q_COMPAT_EXPORT TQTextTable: public TQTextCustomItem
+{
+ friend class TQTextTableCell;
+
+public:
+ TQTextTable(TQTextDocument *p, const QMap<TQString, TQString> &attr);
+ virtual ~TQTextTable();
+
+ void adjustToPainter(TQPainter *p);
+ void pageBreak(int y, TQTextFlow* flow);
+ void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const QPalette &pal, bool selected);
+
+ bool noErase() const { return true; }
+ bool ownLine() const { return true; }
+ Placement placement() const { return place; }
+ bool isNested() const { return true; }
+ void resize(int nwidth);
+ virtual void invalidate();
+
+ virtual bool enter(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = false);
+ virtual bool enterAt(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, const QPoint &pos);
+ virtual bool next(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+ virtual bool prev(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+ virtual bool down(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+ virtual bool up(TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy);
+
+ TQString richText() const;
+
+ int minimumWidth() const;
+
+ QList<TQTextTableCell *> tableCells() const { return cells; }
+
+ TQPtrList<TQTextTableCell> tqtableCells() const {
+ TQPtrList<TQTextTableCell> tc;
+ tc.clear();
+ for (int i = 0; i < cells.size(); ++i) tc.append(cells.at(i));
+ return tc;
+ }
+
+ bool isStretching() const { return stretch; }
+
+private:
+ void format(int w);
+ void addCell(TQTextTableCell* cell);
+
+private:
+ TQGridLayout* layout;
+ QList<TQTextTableCell *> cells;
+ int cachewidth;
+ int fixwidth;
+ int cellpadding;
+ int cellspacing;
+ int border;
+ int outerborder;
+ int stretch;
+ int innerborder;
+ int us_cp, us_ib, us_b, us_ob, us_cs;
+ int us_fixwidth;
+ QMap<TQString, TQString> attributes;
+ QMap<TQTextCursor*, int> currCell;
+ Placement place;
+ void adjustCells(int y , int shift);
+ int pageBreakFor;
+};
+#endif
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+class TQTextTableCell;
+class TQTextParagraph;
+#endif
+
+struct Q_COMPAT_EXPORT TQTextDocumentSelection
+{
+ TQTextCursor startCursor, endCursor;
+ bool swapped;
+ Q_DUMMY_COMPARISON_OPERATOR(TQTextDocumentSelection)
+};
+
+class Q_COMPAT_EXPORT TQTextDocument : public TQT_BASE_OBJECT_NAME
+{
+ Q_OBJECT
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ friend class TQTextTableCell;
+#endif
+ friend class TQTextCursor;
+ friend class TQTextEdit;
+ friend class TQTextParagraph;
+
+public:
+
+ enum SelectionIds {
+ Standard = 0,
+ IMSelectionText = 31998,
+ IMCompositionText = 31999, // this must be higher!
+ Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to
+ // remove multiple lines with removeSelectedText()
+ };
+
+ TQTextDocument(TQTextDocument *p);
+ virtual ~TQTextDocument();
+
+ TQTextDocument *parent() const { return par; }
+ TQTextParagraph *parentParagraph() const { return parentPar; }
+
+ void setText(const TQString &text, const TQString &context);
+ QMap<TQString, TQString> attributes() const { return attribs; }
+ void setAttributes(const QMap<TQString, TQString> &attr) { attribs = attr; }
+
+ TQString text() const;
+ TQString text(int parag) const;
+ TQString originalText() const;
+
+ void setInvertSelectionText( int id, bool b );
+ bool invertSelectionText( int id ) const;
+
+ int x() const;
+ int y() const;
+ int width() const;
+ int widthUsed() const;
+ int visibleWidth() const;
+ int height() const;
+ void setWidth(int w);
+ int minimumWidth() const;
+ bool setMinimumWidth(int needed, int used = -1, TQTextParagraph *parag = 0);
+
+ void setY(int y);
+ int leftMargin() const;
+ void setLeftMargin(int lm);
+ int rightMargin() const;
+ void setRightMargin(int rm);
+
+ TQTextParagraph *firstParagraph() const;
+ TQTextParagraph *lastParagraph() const;
+ void setFirstParagraph(TQTextParagraph *p);
+ void setLastParagraph(TQTextParagraph *p);
+
+ void invalidate();
+ inline void tqinvalidate() { invalidate(); }
+
+ void setPreProcessor(TQTextPreProcessor *sh);
+ TQTextPreProcessor *preProcessor() const;
+
+ void setFormatter(TQTextFormatter *f);
+ TQTextFormatter *formatter() const;
+
+ void setIndent(TQTextIndent *i);
+ TQTextIndent *indent() const;
+
+ QColor selectionColor(int id) const;
+ QColor selectionTextColor(int id) const;
+ bool hasSelectionTextColor(int id) const;
+ void setSelectionColor(int id, const QColor &c);
+ void setSelectionTextColor(int id, const QColor &b);
+ bool hasSelection(int id, bool visible = false) const;
+ void setSelectionStart(int id, const TQTextCursor &cursor);
+ bool setSelectionEnd(int id, const TQTextCursor &cursor);
+ void selectAll(int id);
+ bool removeSelection(int id);
+ void selectionStart(int id, int &paragId, int &index);
+ TQTextCursor selectionStartCursor(int id);
+ TQTextCursor selectionEndCursor(int id);
+ void selectionEnd(int id, int &paragId, int &index);
+ void setFormat(int id, TQTextFormat *f, int flags);
+ int numSelections() const { return nSelections; }
+ void addSelection(int id);
+
+ TQString selectedText(int id, bool asRichText = false) const;
+ void removeSelectedText(int id, TQTextCursor *cursor);
+ void indentSelection(int id);
+
+ TQTextParagraph *paragAt(int i) const;
+
+ void addCommand(TQTextCommand *cmd);
+ TQTextCursor *undo(TQTextCursor *c = 0);
+ TQTextCursor *redo(TQTextCursor *c = 0);
+ TQTextCommandHistory *commands() const { return commandHistory; }
+
+ TQTextFormatCollection *formatCollection() const;
+
+ bool find(TQTextCursor &cursor, const TQString &expr, bool cs, bool wo, bool forward);
+ inline bool tqfind(TQTextCursor &cursor, const TQString &expr, bool cs, bool wo, bool forward) { return find(cursor, expr, cs, wo, forward); }
+
+ void setTextFormat(TQt::TextFormat f);
+ TQt::TextFormat textFormat() const;
+
+ bool inSelection(int selId, const QPoint &pos) const;
+
+ TQStyleSheet *styleSheet() const { return sheet_; }
+#ifndef QT_NO_MIME
+ TQMimeSourceFactory *mimeSourceFactory() const { return factory_; }
+#endif
+ TQString context() const { return contxt; }
+
+ void setStyleSheet(TQStyleSheet *s);
+ void setDefaultFormat(const QFont &font, const QColor &color);
+#ifndef QT_NO_MIME
+ void setMimeSourceFactory(TQMimeSourceFactory *f) { if (f) factory_ = f; }
+#endif
+ void setContext(const TQString &c) { if (!c.isEmpty()) contxt = c; }
+
+ void setUnderlineLinks(bool b);
+ bool underlineLinks() const { return underlLinks; }
+
+ void setPaper(TQBrush *brush) { if (backBrush) delete backBrush; backBrush = brush; }
+ TQBrush *paper() const { return backBrush; }
+
+ void doLayout(TQPainter *p, int w);
+ void draw(TQPainter *p, const TQRect& rect, const QPalette &pal, const TQBrush *paper = 0);
+
+ void drawParagraph(TQPainter *p, TQTextParagraph *parag, int cx, int cy, int cw, int ch,
+ TQPixmap *&doubleBuffer, const QPalette &pal,
+ bool drawCursor, TQTextCursor *cursor, bool resetChanged = true);
+ TQTextParagraph *draw(TQPainter *p, int cx, int cy, int cw, int ch, const QPalette &pal,
+ bool onlyChanged = false, bool drawCursor = false, TQTextCursor *cursor = 0,
+ bool resetChanged = true);
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ static TQTextCustomItem* tag(TQStyleSheet *sheet, const TQString& name,
+ const QMap<TQString, TQString> &attr,
+ const TQString& context,
+ const TQMimeSourceFactory& factory,
+ bool emptyTag, TQTextDocument *doc);
+#endif
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ void registerCustomItem(TQTextCustomItem *i, TQTextParagraph *p);
+ void unregisterCustomItem(TQTextCustomItem *i, TQTextParagraph *p);
+#endif
+
+ void setFlow(TQTextFlow *f);
+ void takeFlow();
+ TQTextFlow *flow() const { return flow_; }
+ bool isPageBreakEnabled() const { return pages; }
+ void setPageBreakEnabled(bool b) { pages = b; }
+
+ void setUseFormatCollection(bool b) { useFC = b; }
+ bool useFormatCollection() const { return useFC; }
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextTableCell *tableCell() const { return tc; }
+ void setTableCell(TQTextTableCell *c) { tc = c; }
+#endif
+
+ void setPlainText(const TQString &text);
+ void setRichText(const TQString &text, const TQString &context, const TQTextFormat *initialFormat = 0);
+ TQString richText() const;
+ TQString plainText() const;
+
+ bool focusNextPrevChild(bool next);
+
+ int alignment() const;
+ void setAlignment(int a);
+
+ int *tabArray() const;
+ int tabStopWidth() const;
+ void setTabArray(int *a);
+ void setTabStops(int tw);
+
+ void setUndoDepth(int depth) { commandHistory->setUndoDepth(depth); }
+ int undoDepth() const { return commandHistory->undoDepth(); }
+
+ int length() const;
+ void clear(bool createEmptyParag = false);
+
+ virtual TQTextParagraph *createParagraph(TQTextDocument *, TQTextParagraph *pr = 0, TQTextParagraph *nx = 0, bool updateIds = true);
+ void insertChild(TQTextDocument *dc) { childList.append(dc); }
+ void removeChild(TQTextDocument *dc) { childList.removeAll(dc); }
+ QList<TQTextDocument *> children() const { return childList; }
+
+ bool hasFocusParagraph() const;
+ TQString focusHref() const;
+ TQString focusName() const;
+
+ void invalidateOriginalText() { oTextValid = false; oText = TQLatin1String(""); }
+
+Q_SIGNALS:
+ void minimumWidthChanged(int);
+
+private:
+ Q_DISABLE_COPY(TQTextDocument)
+
+ void init();
+ TQPixmap *bufferPixmap(const QSize &s);
+ // HTML parser
+ bool hasPrefix(const TQChar* doc, int length, int pos, TQChar c);
+ bool hasPrefix(const TQChar* doc, int length, int pos, const TQString& s);
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem* parseTable(const QMap<TQString, TQString> &attr, const TQTextFormat &fmt,
+ const TQChar* doc, int length, int& pos, TQTextParagraph *curpar);
+#endif
+ bool eatSpace(const TQChar* doc, int length, int& pos, bool includeNbsp = false);
+ bool eat(const TQChar* doc, int length, int& pos, TQChar c);
+ TQString parseOpenTag(const TQChar* doc, int length, int& pos, QMap<TQString, TQString> &attr, bool& emptyTag);
+ TQString parseCloseTag(const TQChar* doc, int length, int& pos);
+ TQChar parseHTMLSpecialChar(const TQChar* doc, int length, int& pos);
+ TQString parseWord(const TQChar* doc, int length, int& pos, bool lower = true);
+ TQChar parseChar(const TQChar* doc, int length, int& pos, TQStyleSheetItem::WhiteSpaceMode wsm);
+ void setRichTextInternal(const TQString &text, TQTextCursor* cursor = 0, const TQTextFormat *initialFormat = 0);
+ void setRichTextMarginsInternal(QList< QVector<TQStyleSheetItem *> *>& styles, TQTextParagraph* stylesPar);
+
+ struct Q_COMPAT_EXPORT Focus {
+ TQTextParagraph *parag;
+ int start, len;
+ TQString href;
+ TQString name;
+ };
+
+ int cx, cy, cw, vw;
+ TQTextParagraph *fParag, *lParag;
+ TQTextPreProcessor *pProcessor;
+ struct SelectionColor {
+ QColor background;
+ QColor text;
+ };
+ QMap<int, SelectionColor> selectionColors;
+ QMap<int, TQTextDocumentSelection> selections;
+ TQTextCommandHistory *commandHistory;
+ TQTextFormatter *pFormatter;
+ TQTextIndent *indenter;
+ TQTextFormatCollection *fCollection;
+ TQt::TextFormat txtFormat;
+ uint preferRichText : 1;
+ uint pages : 1;
+ uint useFC : 1;
+ uint withoutDoubleBuffer : 1;
+ uint underlLinks : 1;
+ uint nextDoubleBuffered : 1;
+ uint oTextValid : 1;
+ uint mightHaveCustomItems : 1;
+ int align;
+ int nSelections;
+ TQTextFlow *flow_;
+ TQTextDocument *par;
+ TQTextParagraph *parentPar;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextTableCell *tc;
+#endif
+ TQBrush *backBrush;
+ TQPixmap *buf_pixmap;
+ Focus focusIndicator;
+ int minw;
+ int wused;
+ int leftmargin;
+ int rightmargin;
+ TQTextParagraph *minwParag, *curParag;
+ TQStyleSheet* sheet_;
+#ifndef QT_NO_MIME
+ TQMimeSourceFactory* factory_;
+#endif
+ TQString contxt;
+ QMap<TQString, TQString> attribs;
+ int *tArray;
+ int tStopWidth;
+ int uDepth;
+ TQString oText;
+ QList<TQTextDocument *> childList;
+ QColor linkColor, bodyText;
+ double scaleFontsFactor;
+
+ // TQt specific
+ TQMap<int, bool> selectionText;
+
+ short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm;
+};
+
+inline void TQTextDocument::setInvertSelectionText( int id, bool b )
+{
+// TQTextDocument *p = this;
+// while (p->par)
+// p = p->par;
+ selectionText[ id ] = b;
+}
+
+inline bool TQTextDocument::invertSelectionText( int id ) const
+{
+// TQTextDocument *p = this;
+// while (p->par)
+// p = p->par;
+ return selectionText[ id ];
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+class Q_COMPAT_EXPORT TQTextDeleteCommand : public TQTextCommand
+{
+public:
+ TQTextDeleteCommand(TQTextDocument *dc, int i, int idx, const QVector<TQTextStringChar> &str,
+ const QByteArray& oldStyle);
+ TQTextDeleteCommand(TQTextParagraph *p, int idx, const QVector<TQTextStringChar> &str);
+ virtual ~TQTextDeleteCommand();
+
+ Commands type() const { return Delete; }
+ TQTextCursor *execute(TQTextCursor *c);
+ TQTextCursor *unexecute(TQTextCursor *c);
+
+protected:
+ int id, index;
+ TQTextParagraph *parag;
+ QVector<TQTextStringChar> text;
+ QByteArray styleInformation;
+
+};
+
+class Q_COMPAT_EXPORT TQTextInsertCommand : public TQTextDeleteCommand
+{
+public:
+ TQTextInsertCommand(TQTextDocument *dc, int i, int idx, const QVector<TQTextStringChar> &str,
+ const QByteArray& oldStyleInfo)
+ : TQTextDeleteCommand(dc, i, idx, str, oldStyleInfo) {}
+ TQTextInsertCommand(TQTextParagraph *p, int idx, const QVector<TQTextStringChar> &str)
+ : TQTextDeleteCommand(p, idx, str) {}
+ virtual ~TQTextInsertCommand() {}
+
+ Commands type() const { return Insert; }
+ TQTextCursor *execute(TQTextCursor *c) { return TQTextDeleteCommand::unexecute(c); }
+ TQTextCursor *unexecute(TQTextCursor *c) { return TQTextDeleteCommand::execute(c); }
+
+};
+
+class Q_COMPAT_EXPORT TQTextFormatCommand : public TQTextCommand
+{
+public:
+ TQTextFormatCommand(TQTextDocument *dc, int sid, int sidx, int eid, int eidx, const QVector<TQTextStringChar> &old, TQTextFormat *f, int fl);
+ virtual ~TQTextFormatCommand();
+
+ Commands type() const { return Format; }
+ TQTextCursor *execute(TQTextCursor *c);
+ TQTextCursor *unexecute(TQTextCursor *c);
+
+protected:
+ int startId, startIndex, endId, endIndex;
+ TQTextFormat *format;
+ QVector<TQTextStringChar> oldFormats;
+ int flags;
+
+};
+
+class Q_COMPAT_EXPORT TQTextStyleCommand : public TQTextCommand
+{
+public:
+ TQTextStyleCommand(TQTextDocument *dc, int fParag, int lParag, const QByteArray& beforeChange );
+ virtual ~TQTextStyleCommand() {}
+
+ Commands type() const { return Style; }
+ TQTextCursor *execute(TQTextCursor *c);
+ TQTextCursor *unexecute(TQTextCursor *c);
+
+ static QByteArray readStyleInformation( TQTextDocument* dc, int fParag, int lParag);
+ static void writeStyleInformation( TQTextDocument* dc, int fParag, const QByteArray& style);
+
+private:
+ int firstParag, lastParag;
+ QByteArray before;
+ QByteArray after;
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+struct Q_COMPAT_EXPORT TQTextParagraphSelection
+{
+ int start, end;
+ Q_DUMMY_COMPARISON_OPERATOR(TQTextParagraphSelection)
+};
+
+struct Q_COMPAT_EXPORT QTextLineStart
+{
+ QTextLineStart() : y(0), baseLine(0), h(0)
+ { }
+ QTextLineStart(int y_, int bl, int h_) : y(y_), baseLine(bl), h(h_),
+ w(0)
+ { }
+
+public:
+ int y, baseLine, h;
+ int w;
+};
+
+class Q_COMPAT_EXPORT TQTextParagraphData
+{
+public:
+ TQTextParagraphData() {}
+ virtual ~TQTextParagraphData();
+ virtual void join(TQTextParagraphData *);
+};
+
+class TQTextParagraphPseudoDocument;
+
+class TQSyntaxHighlighter;
+
+class Q_COMPAT_EXPORT TQTextParagraph
+{
+ friend class TQTextDocument;
+ friend class TQTextCursor;
+ friend class TQSyntaxHighlighter;
+
+public:
+ TQTextParagraph(TQTextDocument *dc, TQTextParagraph *pr = 0, TQTextParagraph *nx = 0, bool updateIds = true);
+ ~TQTextParagraph();
+
+ TQTextString *string() const;
+ TQTextStringChar *at(int i) const; // maybe remove later
+ int leftGap() const;
+ int length() const; // maybe remove later
+
+ void setListStyle(TQStyleSheetItem::ListStyle ls) { lstyle = ls; changed = true; }
+ TQStyleSheetItem::ListStyle listStyle() const { return (TQStyleSheetItem::ListStyle)lstyle; }
+ void setListItem(bool li);
+ bool isListItem() const { return litem; }
+ void setListValue(int v) { list_val = v; }
+ int listValue() const { return list_val > 0 ? list_val : -1; }
+
+ void setListDepth(int depth);
+ int listDepth() const { return ldepth; }
+
+// void setFormat(TQTextFormat *fm);
+// TQTextFormat *paragFormat() const;
+
+ inline TQTextDocument *document() const {
+ if (hasdoc) return (TQTextDocument*) docOrPseudo;
+ return 0;
+ }
+ TQTextParagraphPseudoDocument *pseudoDocument() const;
+
+ TQRect rect() const;
+ void setHeight(int h) { r.setHeight(h); }
+ void show();
+ void hide();
+ bool isVisible() const { return visible; }
+
+ TQTextParagraph *prev() const;
+ TQTextParagraph *next() const;
+ void setPrev(TQTextParagraph *s);
+ void setNext(TQTextParagraph *s);
+
+ void insert(int index, const QString &s);
+ void insert(int index, const QChar *unicode, int len);
+ void append(const TQString &s, bool reallyAtEnd = false);
+ void truncate(int index);
+ void remove(int index, int len);
+ void join(TQTextParagraph *s);
+
+ void invalidate(int chr);
+ inline void tqinvalidate(int chr) { invalidate(chr); }
+
+ void move(int &dy);
+ void format(int start = -1, bool doMove = true);
+
+ bool isValid() const;
+ bool hasChanged() const;
+ void setChanged(bool b, bool recursive = false);
+
+ int lineHeightOfChar(int i, int *bl = 0, int *y = 0) const;
+ TQTextStringChar *lineStartOfChar(int i, int *index = 0, int *line = 0) const;
+ int lines() const;
+ TQTextStringChar *lineStartOfLine(int line, int *index = 0) const;
+ int lineY(int l) const;
+ int lineBaseLine(int l) const;
+ int lineHeight(int l) const;
+ void lineInfo(int l, int &y, int &h, int &bl) const;
+
+ void setSelection(int id, int start, int end);
+ void removeSelection(int id);
+ int selectionStart(int id) const;
+ int selectionEnd(int id) const;
+ bool hasSelection(int id) const;
+ bool hasAnySelection() const;
+ bool fullSelected(int id) const;
+
+ void setEndState(int s);
+ int endState() const;
+
+ void setParagId(int i);
+ int paragId() const;
+
+ bool firstPreProcess() const;
+ void setFirstPreProcess(bool b);
+
+ void indent(int *oldIndent = 0, int *newIndent = 0);
+
+ void setExtraData(TQTextParagraphData *data);
+ TQTextParagraphData *extraData() const;
+
+ QMap<int, QTextLineStart*> &lineStartList();
+
+ void setFormat(int index, int len, TQTextFormat *f, bool useCollection = true, int flags = -1);
+
+ void setAlignment(int a);
+ inline void tqsetAlignment(int a) { setAlignment(a); }
+
+ int alignment() const;
+ inline int tqalignment() const { return alignment(); }
+
+ void paint(TQPainter &painter, const QPalette &pal, TQTextCursor *cursor = 0,
+ bool drawSelections = false, int clipx = -1, int clipy = -1,
+ int clipw = -1, int cliph = -1);
+
+ int topMargin() const;
+ int bottomMargin() const;
+ int leftMargin() const;
+ int firstLineMargin() const;
+ int rightMargin() const;
+ int lineSpacing() const;
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ void registerFloatingItem(TQTextCustomItem *i);
+ void unregisterFloatingItem(TQTextCustomItem *i);
+#endif
+
+ void setFullWidth(bool b) { fullWidth = b; }
+ bool isFullWidth() const { return fullWidth; }
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+ TQTextTableCell *tableCell() const;
+#endif
+
+ TQBrush *background() const;
+
+ int documentWidth() const;
+ int documentVisibleWidth() const;
+ int documentX() const;
+ int documentY() const;
+ TQTextFormatCollection *formatCollection() const;
+ TQTextFormatter *formatter() const;
+
+ int nextTab(int i, int x);
+ int *tabArray() const;
+ void setTabArray(int *a);
+ void setTabStops(int tw);
+
+ void adjustToPainter(TQPainter *p);
+
+ void setNewLinesAllowed(bool b);
+ bool isNewLinesAllowed() const;
+
+ TQString richText() const;
+
+ void addCommand(TQTextCommand *cmd);
+ TQTextCursor *undo(TQTextCursor *c = 0);
+ TQTextCursor *redo(TQTextCursor *c = 0);
+ TQTextCommandHistory *commands() const;
+ void copyParagData(TQTextParagraph *parag);
+
+ void setBreakable(bool b) { breakable = b; }
+ bool isBreakable() const { return breakable; }
+
+ void setBackgroundColor(const QColor &c);
+ QColor *backgroundColor() const { return bgcol; }
+ void clearBackgroundColor();
+
+ void setMovedDown(bool b) { movedDown = b; }
+ bool wasMovedDown() const { return movedDown; }
+
+ void setDirection(TQChar::Direction);
+ TQChar::Direction direction() const;
+ void setPaintDevice(TQPaintDevice *pd) { paintdevice = pd; }
+
+ void readStyleInformation(QDataStream& stream);
+ void writeStyleInformation(QDataStream& stream) const;
+
+protected:
+ void setColorForSelection(QColor &c, TQPainter &p, const QPalette &pal, int selection);
+ void drawLabel(TQPainter* p, int x, int y, int w, int h, int base, const QPalette &pal);
+ void drawString(TQPainter &painter, const TQString &str, int start, int len, int xstart,
+ int y, int baseLine, int w, int h, bool drawSelections, int fullSelectionWidth,
+ TQTextStringChar *formatChar, const QPalette &pal,
+ bool rightToLeft);
+
+private:
+ QMap<int, TQTextParagraphSelection> &selections() const;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ QList<TQTextCustomItem *> &floatingItems() const;
+#endif
+ inline TQBrush backgroundBrush(const QPalette &pal) {
+ if (bgcol)
+ return *bgcol;
+ return pal.brush(QPalette::Base);
+ }
+ void invalidateStyleCache();
+
+ QMap<int, QTextLineStart*> lineStarts;
+ TQRect r;
+ TQTextParagraph *p, *n;
+ void *docOrPseudo;
+ uint changed : 1;
+ uint firstFormat : 1;
+ uint firstPProcess : 1;
+ uint needPreProcess : 1;
+ uint fullWidth : 1;
+ uint lastInFrame : 1;
+ uint visible : 1;
+ uint breakable : 1;
+ uint movedDown : 1;
+ uint mightHaveCustomItems : 1;
+ uint hasdoc : 1;
+ uint litem : 1; // whether the paragraph is a list item
+ uint rtext : 1; // whether the paragraph needs rich text margin
+ signed int align : 5;
+ uint /*TQStyleSheetItem::ListStyle*/ lstyle : 4;
+ int invalid;
+ int state, id;
+ TQTextString *str;
+ QMap<int, TQTextParagraphSelection> *mSelections;
+#ifndef QT_NO_TEXTCUSTOMITEM
+ QList<TQTextCustomItem *> *mFloatingItems;
+#endif
+ short utm, ubm, ulm, urm, uflm, ulinespacing;
+ short tabStopWidth, minwidth;
+ int *tArray;
+ TQTextParagraphData *eData;
+ short list_val;
+ ushort ldepth;
+ QColor *bgcol;
+ TQPaintDevice *paintdevice;
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextFormatter
+{
+public:
+ TQTextFormatter();
+ virtual ~TQTextFormatter();
+
+ virtual int format(TQTextDocument *doc, TQTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts) = 0;
+ virtual int formatVertically(TQTextDocument* doc, TQTextParagraph* parag);
+
+ bool isWrapEnabled(TQTextParagraph *p) const { if (!wrapEnabled) return false; if (p && !p->isBreakable()) return false; return true;}
+ int wrapAtColumn() const { return wrapColumn;}
+ virtual void setWrapEnabled(bool b);
+ virtual void setWrapAtColumn(int c);
+ virtual void setAllowBreakInWords(bool b) { biw = b; }
+ bool allowBreakInWords() const { return biw; }
+
+ int minimumWidth() const { return thisminw; }
+ int widthUsed() const { return thiswused; }
+
+protected:
+ virtual QTextLineStart *formatLine(TQTextParagraph *parag, TQTextString *string, QTextLineStart *line, TQTextStringChar *start,
+ TQTextStringChar *last, int align = TQt::AlignAuto, int space = 0);
+#ifndef QT_NO_COMPLEXTEXT
+ virtual QTextLineStart *bidiReorderLine(TQTextParagraph *parag, TQTextString *string, QTextLineStart *line, TQTextStringChar *start,
+ TQTextStringChar *last, int align, int space);
+#endif
+ void insertLineStart(TQTextParagraph *parag, int index, QTextLineStart *ls);
+
+ int thisminw;
+ int thiswused;
+
+private:
+ bool wrapEnabled;
+ int wrapColumn;
+ bool biw;
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextFormatterBreakInWords : public TQTextFormatter
+{
+public:
+ TQTextFormatterBreakInWords();
+ virtual ~TQTextFormatterBreakInWords() {}
+
+ int format(TQTextDocument *doc, TQTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextFormatterBreakWords : public TQTextFormatter
+{
+public:
+ TQTextFormatterBreakWords();
+ virtual ~TQTextFormatterBreakWords() {}
+
+ int format(TQTextDocument *doc, TQTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextIndent
+{
+public:
+ TQTextIndent();
+ virtual ~TQTextIndent() {}
+
+ virtual void indent(TQTextDocument *doc, TQTextParagraph *parag, int *oldIndent = 0, int *newIndent = 0) = 0;
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextPreProcessor
+{
+public:
+ enum Ids {
+ Standard = 0
+ };
+
+ TQTextPreProcessor();
+ virtual ~TQTextPreProcessor() {}
+
+ virtual void process(TQTextDocument *doc, TQTextParagraph *, int, bool = true) = 0;
+ virtual TQTextFormat *format(int id) = 0;
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextFormat
+{
+ friend class TQTextFormatCollection;
+ friend class TQTextDocument;
+
+public:
+ enum Flags {
+ NoFlags,
+ Bold = 1,
+ Italic = 2,
+ Underline = 4,
+ Family = 8,
+ Size = 16,
+ Color = 32,
+ Misspelled = 64,
+ VAlign = 128,
+ StrikeOut= 256,
+ Font = Bold | Italic | Underline | Family | Size | StrikeOut,
+ Format = Font | Color | Misspelled | VAlign
+ };
+
+ enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript };
+
+ TQTextFormat();
+ virtual ~TQTextFormat();
+
+ TQTextFormat(const TQStyleSheetItem *s);
+ TQTextFormat(const QFont &f, const QColor &c, TQTextFormatCollection *parent = 0);
+ TQTextFormat(const TQTextFormat &fm);
+ TQTextFormat makeTextFormat(const TQStyleSheetItem *style, const QMap<TQString,TQString>& attr, double scaleFontsFactor) const;
+ TQTextFormat& operator=(const TQTextFormat &fm);
+ QColor color() const;
+ QFont font() const;
+ QFontMetrics fontMetrics() const { return fm; }
+ bool isMisspelled() const;
+ VerticalAlignment vAlign() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+ int width(const TQChar &c) const;
+ int width(const TQString &str, int pos) const;
+ int height() const;
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ bool useLinkColor() const;
+
+ void setBold(bool b);
+ void setItalic(bool b);
+ void setUnderline(bool b);
+ void setStrikeOut(bool b);
+ void setFamily(const TQString &f);
+ void setPointSize(int s);
+ void setFont(const QFont &f);
+ void setColor(const QColor &c);
+ void setMisspelled(bool b);
+ void setVAlign(VerticalAlignment a);
+
+ bool operator==(const TQTextFormat &f) const;
+ TQTextFormatCollection *parent() const;
+ const TQString &key() const;
+
+ static TQString getKey(const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign);
+
+ void addRef();
+ void removeRef();
+
+ TQString makeFormatChangeTags(TQTextFormat* defaultFormat, TQTextFormat *f, const TQString& oldAnchorHref, const TQString& anchorHref) const;
+ TQString makeFormatEndTags(TQTextFormat* defaultFormat, const TQString& anchorHref) const;
+
+ static void setPainter(TQPainter *p);
+ static TQPainter* painter();
+
+ bool fontSizesInPixels() { return usePixelSizes; }
+
+protected:
+ virtual void generateKey();
+
+private:
+ void update();
+ static void applyFont(const QFont &f);
+
+private:
+ TQFont fn;
+ QColor col;
+ QFontMetrics fm;
+ uint missp : 1;
+ uint linkColor : 1;
+ uint usePixelSizes : 1;
+ int leftBearing, rightBearing;
+ VerticalAlignment ha;
+ uchar widths[256];
+ int hei, asc, dsc;
+ TQTextFormatCollection *collection;
+ int ref;
+ TQString k;
+ int logicalFontSize;
+ int stdSize;
+ static TQPainter *pntr;
+ static QFontMetrics *pntr_fm;
+ static int pntr_asc;
+ static int pntr_hei;
+ static int pntr_ldg;
+ static int pntr_dsc;
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class Q_COMPAT_EXPORT TQTextFormatCollection
+{
+ friend class TQTextDocument;
+ friend class TQTextFormat;
+
+public:
+ TQTextFormatCollection();
+ virtual ~TQTextFormatCollection();
+
+ void setDefaultFormat(TQTextFormat *f);
+ TQTextFormat *defaultFormat() const;
+ virtual TQTextFormat *format(TQTextFormat *f);
+ virtual TQTextFormat *format(TQTextFormat *of, TQTextFormat *nf, int flags);
+ virtual TQTextFormat *format(const QFont &f, const QColor &c);
+ virtual void remove(TQTextFormat *f);
+ virtual TQTextFormat *createFormat(const TQTextFormat &f) { return new TQTextFormat(f); }
+ virtual TQTextFormat *createFormat(const QFont &f, const QColor &c) { return new TQTextFormat(f, c, this); }
+
+ void updateDefaultFormat(const QFont &font, const QColor &c, TQStyleSheet *sheet);
+
+ TQPaintDevice *paintDevice() const { return paintdevice; }
+ void setPaintDevice(QPaintDevice *);
+
+private:
+ void updateKeys();
+
+private:
+ TQTextFormat *defFormat, *lastFormat, *cachedFormat;
+ QHash<TQString, TQTextFormat *> cKey;
+ TQTextFormat *cres;
+ QFont cfont;
+ QColor ccol;
+ TQString kof, knf;
+ int cflags;
+
+ TQPaintDevice *paintdevice;
+};
+
+class Q_COMPAT_EXPORT TQTextParagraphPseudoDocument
+{
+public:
+ TQTextParagraphPseudoDocument();
+ ~TQTextParagraphPseudoDocument();
+ TQRect docRect;
+ TQTextFormatter *pFormatter;
+ TQTextCommandHistory *commandHistory;
+ int minw;
+ int wused;
+ TQTextFormatCollection collection;
+};
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline int TQTextParagraph::length() const
+{
+ return str->length();
+}
+
+inline TQRect TQTextParagraph::rect() const
+{
+ return r;
+}
+
+inline int TQTextCursor::index() const
+{
+ return idx;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline int TQTextDocument::x() const
+{
+ return cx;
+}
+
+inline int TQTextDocument::y() const
+{
+ return cy;
+}
+
+inline int TQTextDocument::width() const
+{
+ return qMax(cw, flow_->width());
+}
+
+inline int TQTextDocument::visibleWidth() const
+{
+ return vw;
+}
+
+inline TQTextParagraph *TQTextDocument::firstParagraph() const
+{
+ return fParag;
+}
+
+inline TQTextParagraph *TQTextDocument::lastParagraph() const
+{
+ return lParag;
+}
+
+inline void TQTextDocument::setFirstParagraph(TQTextParagraph *p)
+{
+ fParag = p;
+}
+
+inline void TQTextDocument::setLastParagraph(TQTextParagraph *p)
+{
+ lParag = p;
+}
+
+inline void TQTextDocument::setWidth(int w)
+{
+ cw = qMax(w, minw);
+ flow_->setWidth(cw);
+ vw = w;
+}
+
+inline int TQTextDocument::minimumWidth() const
+{
+ return minw;
+}
+
+inline void TQTextDocument::setY(int y)
+{
+ cy = y;
+}
+
+inline int TQTextDocument::leftMargin() const
+{
+ return leftmargin;
+}
+
+inline void TQTextDocument::setLeftMargin(int lm)
+{
+ leftmargin = lm;
+}
+
+inline int TQTextDocument::rightMargin() const
+{
+ return rightmargin;
+}
+
+inline void TQTextDocument::setRightMargin(int rm)
+{
+ rightmargin = rm;
+}
+
+inline TQTextPreProcessor *TQTextDocument::preProcessor() const
+{
+ return pProcessor;
+}
+
+inline void TQTextDocument::setPreProcessor(TQTextPreProcessor * sh)
+{
+ pProcessor = sh;
+}
+
+inline void TQTextDocument::setFormatter(TQTextFormatter *f)
+{
+ delete pFormatter;
+ pFormatter = f;
+}
+
+inline TQTextFormatter *TQTextDocument::formatter() const
+{
+ return pFormatter;
+}
+
+inline void TQTextDocument::setIndent(TQTextIndent *i)
+{
+ indenter = i;
+}
+
+inline TQTextIndent *TQTextDocument::indent() const
+{
+ return indenter;
+}
+
+inline QColor TQTextDocument::selectionColor(int id) const
+{
+ const TQTextDocument *p = this;
+ while (p->par)
+ p = p->par;
+ return p->selectionColors[id].background;
+}
+
+inline QColor TQTextDocument::selectionTextColor(int id) const
+{
+ const TQTextDocument *p = this;
+ while (p->par)
+ p = p->par;
+ return p->selectionColors[id].text;
+}
+
+inline bool TQTextDocument::hasSelectionTextColor(int id) const
+{
+ const TQTextDocument *p = this;
+ while (p->par)
+ p = p->par;
+ return p->selectionColors.contains(id);
+}
+
+inline void TQTextDocument::setSelectionColor(int id, const QColor &c)
+{
+ TQTextDocument *p = this;
+ while (p->par)
+ p = p->par;
+ p->selectionColors[id].background = c;
+}
+
+inline void TQTextDocument::setSelectionTextColor(int id, const QColor &c)
+{
+ TQTextDocument *p = this;
+ while (p->par)
+ p = p->par;
+ p->selectionColors[id].text = c;
+}
+
+inline TQTextFormatCollection *TQTextDocument::formatCollection() const
+{
+ return fCollection;
+}
+
+inline int TQTextDocument::alignment() const
+{
+ return align;
+}
+
+inline void TQTextDocument::setAlignment(int a)
+{
+ align = a;
+}
+
+inline int *TQTextDocument::tabArray() const
+{
+ return tArray;
+}
+
+inline int TQTextDocument::tabStopWidth() const
+{
+ return tStopWidth;
+}
+
+inline void TQTextDocument::setTabArray(int *a)
+{
+ tArray = a;
+}
+
+inline void TQTextDocument::setTabStops(int tw)
+{
+ tStopWidth = tw;
+}
+
+inline TQString TQTextDocument::originalText() const
+{
+ if (oTextValid)
+ return oText;
+ return text();
+}
+
+inline void TQTextDocument::setFlow(TQTextFlow *f)
+{
+ if (flow_)
+ delete flow_;
+ flow_ = f;
+}
+
+inline void TQTextDocument::takeFlow()
+{
+ flow_ = 0;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline QColor TQTextFormat::color() const
+{
+ return col;
+}
+
+inline QFont TQTextFormat::font() const
+{
+ return fn;
+}
+
+inline bool TQTextFormat::isMisspelled() const
+{
+ return missp;
+}
+
+inline TQTextFormat::VerticalAlignment TQTextFormat::vAlign() const
+{
+ return ha;
+}
+
+inline bool TQTextFormat::operator==(const TQTextFormat &f) const
+{
+ return k == f.k;
+}
+
+inline TQTextFormatCollection *TQTextFormat::parent() const
+{
+ return collection;
+}
+
+inline void TQTextFormat::addRef()
+{
+ ref++;
+}
+
+inline void TQTextFormat::removeRef()
+{
+ ref--;
+ if (!collection)
+ return;
+ if (this == collection->defFormat)
+ return;
+ if (ref == 0)
+ collection->remove(this);
+}
+
+inline const TQString &TQTextFormat::key() const
+{
+ return k;
+}
+
+inline bool TQTextFormat::useLinkColor() const
+{
+ return linkColor;
+}
+
+inline TQTextStringChar *TQTextParagraph::at(int i) const
+{
+ return &str->at(i);
+}
+
+inline bool TQTextParagraph::isValid() const
+{
+ return invalid == -1;
+}
+
+inline bool TQTextParagraph::hasChanged() const
+{
+ return changed;
+}
+
+inline void TQTextParagraph::setBackgroundColor(const QColor & c)
+{
+ delete bgcol;
+ bgcol = new QColor(c);
+ setChanged(true);
+}
+
+inline void TQTextParagraph::clearBackgroundColor()
+{
+ delete bgcol; bgcol = 0; setChanged(true);
+}
+
+inline void TQTextParagraph::append(const TQString &s, bool reallyAtEnd)
+{
+ if (reallyAtEnd) {
+ insert(str->length(), s);
+ } else {
+ int str_end = str->length() - 1;
+ insert(str_end > 0 ? str_end : 0, s);
+ }
+}
+
+inline TQTextParagraph *TQTextParagraph::prev() const
+{
+ return p;
+}
+
+inline TQTextParagraph *TQTextParagraph::next() const
+{
+ return n;
+}
+
+inline bool TQTextParagraph::hasAnySelection() const
+{
+ return mSelections ? !selections().isEmpty() : false;
+}
+
+inline void TQTextParagraph::setEndState(int s)
+{
+ if (s == state)
+ return;
+ state = s;
+}
+
+inline int TQTextParagraph::endState() const
+{
+ return state;
+}
+
+inline void TQTextParagraph::setParagId(int i)
+{
+ id = i;
+}
+
+inline int TQTextParagraph::paragId() const
+{
+ if (id == -1)
+ qWarning("invalid parag id!!!!!!!! (%p)", (void*)this);
+ return id;
+}
+
+inline bool TQTextParagraph::firstPreProcess() const
+{
+ return firstPProcess;
+}
+
+inline void TQTextParagraph::setFirstPreProcess(bool b)
+{
+ firstPProcess = b;
+}
+
+inline QMap<int, QTextLineStart*> &TQTextParagraph::lineStartList()
+{
+ return lineStarts;
+}
+
+inline TQTextString *TQTextParagraph::string() const
+{
+ return str;
+}
+
+inline TQTextParagraphPseudoDocument *TQTextParagraph::pseudoDocument() const
+{
+ if (hasdoc)
+ return 0;
+ return (TQTextParagraphPseudoDocument*) docOrPseudo;
+}
+
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+inline TQTextTableCell *TQTextParagraph::tableCell() const
+{
+ return hasdoc ? document()->tableCell () : 0;
+}
+#endif
+
+inline TQTextCommandHistory *TQTextParagraph::commands() const
+{
+ return hasdoc ? document()->commands() : pseudoDocument()->commandHistory;
+}
+
+
+inline int TQTextParagraph::alignment() const
+{
+ return align;
+}
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+inline void TQTextParagraph::registerFloatingItem(TQTextCustomItem *i)
+{
+ floatingItems().append(i);
+}
+
+inline void TQTextParagraph::unregisterFloatingItem(TQTextCustomItem *i)
+{
+ floatingItems().removeAll(i);
+}
+#endif
+
+inline TQBrush *TQTextParagraph::background() const
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ return tableCell() ? tableCell()->backGround() : 0;
+#else
+ return 0;
+#endif
+}
+
+inline int TQTextParagraph::documentWidth() const
+{
+ return hasdoc ? document()->width() : pseudoDocument()->docRect.width();
+}
+
+inline int TQTextParagraph::documentVisibleWidth() const
+{
+ return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width();
+}
+
+inline int TQTextParagraph::documentX() const
+{
+ return hasdoc ? document()->x() : pseudoDocument()->docRect.x();
+}
+
+inline int TQTextParagraph::documentY() const
+{
+ return hasdoc ? document()->y() : pseudoDocument()->docRect.y();
+}
+
+inline void TQTextParagraph::setExtraData(TQTextParagraphData *data)
+{
+ eData = data;
+}
+
+inline TQTextParagraphData *TQTextParagraph::extraData() const
+{
+ return eData;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline void TQTextFormatCollection::setDefaultFormat(TQTextFormat *f)
+{
+ defFormat = f;
+}
+
+inline TQTextFormat *TQTextFormatCollection::defaultFormat() const
+{
+ return defFormat;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline TQTextFormat *TQTextStringChar::format() const
+{
+ return (type == Regular) ? p.format : p.custom->format;
+}
+
+
+#ifndef QT_NO_TEXTCUSTOMITEM
+inline TQTextCustomItem *TQTextStringChar::customItem() const
+{
+ return isCustom() ? p.custom->custom : 0;
+}
+#endif
+
+inline int TQTextStringChar::height() const
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ return !isCustom() ? format()->height() : (customItem()->placement() == TQTextCustomItem::PlaceInline ? customItem()->height : 0);
+#else
+ return format()->height();
+#endif
+}
+
+inline int TQTextStringChar::ascent() const
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ return !isCustom() ? format()->ascent() : (customItem()->placement() == TQTextCustomItem::PlaceInline ? customItem()->ascent() : 0);
+#else
+ return format()->ascent();
+#endif
+}
+
+inline int TQTextStringChar::descent() const
+{
+#ifndef QT_NO_TEXTCUSTOMITEM
+ return !isCustom() ? format()->descent() : 0;
+#else
+ return format()->descent();
+#endif
+}
+
+#endif // QT_NO_RICHTEXT
+
+QT_END_NAMESPACE
+
+#endif // TQRICHTEXT_P_H
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Definition of internal rich text classes
+**
+** Created : 990124
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQRICHTEXT_P_H
+#define TQRICHTEXT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of a number of TQt sources files. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#include "tqstring.h"
+#include "tqptrlist.h"
+#include "tqrect.h"
+#include "tqfontmetrics.h"
+#include "tqintdict.h"
+#include "tqmap.h"
+#include "tqstringlist.h"
+#include "tqfont.h"
+#include "tqcolor.h"
+#include "tqsize.h"
+#include "tqvaluelist.h"
+#include "tqvaluestack.h"
+#include "tqobject.h"
+#include "tqdict.h"
+#include "tqpixmap.h"
+#include "tqstylesheet.h"
+#include "tqptrvector.h"
+#include "tqpainter.h"
+#include "tqlayout.h"
+#include "tqobject.h"
+#include "tqapplication.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_RICHTEXT
+
+class TQTextDocument;
+class TQTextString;
+class TQTextPreProcessor;
+class TQTextFormat;
+class TQTextCursor;
+class TQTextParagraph;
+class TQTextFormatter;
+class TQTextIndent;
+class TQTextFormatCollection;
+class TQStyleSheetItem;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQTextCustomItem;
+#endif
+class TQTextFlow;
+struct TQBidiContext;
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextStringChar
+{
+ friend class TQTextString;
+
+public:
+ // this is never called, initialize variables in TQTextString::insert()!!!
+ TQTextStringChar() : nobreak(FALSE), lineStart( 0 ), type( Regular ) {d.format=0;}
+ ~TQTextStringChar();
+
+ struct CustomData
+ {
+ TQTextFormat *format;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem *custom;
+#endif
+ TQString anchorName;
+ TQString anchorHref;
+ };
+ enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 };
+
+ TQChar c;
+ // this is the same struct as in qtextengine_p.h. Don't change!
+ uchar softBreak :1; // Potential linebreak point
+ uchar whiteSpace :1; // A tqunicode whitespace character, except NBSP, ZWNBSP
+ uchar charStop :1; // Valid cursor position (for left/right arrow)
+ uchar wordStop :1; // Valid cursor position (for ctrl + left/right arrow)
+ uchar nobreak :1;
+
+ uchar lineStart : 1;
+ uchar /*Type*/ type : 2;
+ uchar bidiLevel :7;
+ uchar rightToLeft : 1;
+
+ int x;
+ union {
+ TQTextFormat* format;
+ CustomData* custom;
+ } d;
+
+
+ int height() const;
+ int ascent() const;
+ int descent() const;
+ bool isCustom() const { return (type & Custom) != 0; }
+ TQTextFormat *format() const;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem *customItem() const;
+#endif
+ void setFormat( TQTextFormat *f );
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ void setCustomItem( TQTextCustomItem *i );
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ void loseCustomItem();
+#endif
+
+
+ bool isAnchor() const { return ( type & Anchor) != 0; }
+ bool isLink() const { return isAnchor() && !!d.custom->anchorHref; }
+ TQString anchorName() const;
+ TQString anchorHref() const;
+ void setAnchor( const TQString& name, const TQString& href );
+
+private:
+ TQTextStringChar &operator=( const TQTextStringChar & ) {
+ //abort();
+ return *this;
+ }
+ TQTextStringChar( const TQTextStringChar & ) {
+ }
+ friend class TQTextParagraph;
+};
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMemArray<TQTextStringChar>;
+// TQMOC_SKIP_END
+#endif
+
+class TQ_EXPORT TQTextString
+{
+public:
+
+ TQTextString();
+ TQTextString( const TQTextString &s );
+ virtual ~TQTextString();
+
+ static TQString toString( const TQMemArray<TQTextStringChar> &data );
+ TQString toString() const;
+
+ inline TQTextStringChar &at( int i ) const { return data[ i ]; }
+ inline int length() const { return data.size(); }
+
+ int width( int idx ) const;
+
+ void insert( int index, const QString &s, TQTextFormat *f );
+ void insert( int index, const QChar *tqunicode, int len, TQTextFormat *f );
+ void insert( int index, TQTextStringChar *c, bool doAddRefFormat = FALSE );
+ void truncate( int index );
+ void remove( int index, int len );
+ void clear();
+
+ void setFormat( int index, TQTextFormat *f, bool useCollection );
+
+ void setBidi( bool b ) { bidi = b; }
+ bool isBidi() const;
+ bool isRightToLeft() const;
+ TQChar::Direction direction() const;
+ void setDirection( TQChar::Direction d ) { dir = d; bidiDirty = TRUE; }
+
+ TQMemArray<TQTextStringChar> rawData() const { return data.copy(); }
+
+ void operator=( const TQString &s ) { clear(); insert( 0, s, 0 ); }
+ void operator+=( const TQString &s ) { insert( length(), s, 0 ); }
+ void prepend( const TQString &s ) { insert( 0, s, 0 ); }
+ int appendParagraphs( TQTextParagraph *start, TQTextParagraph *end );
+
+ // return next and previous valid cursor positions.
+ bool validCursorPosition( int idx );
+ int nextCursorPosition( int idx );
+ int previousCursorPosition( int idx );
+
+private:
+ void checkBidi() const;
+
+ TQMemArray<TQTextStringChar> data;
+ TQString stringCache;
+ uint bidiDirty : 1;
+ uint bidi : 1; // true when the paragraph has right to left characters
+ uint rightToLeft : 1;
+ uint dir : 5;
+};
+
+inline bool TQTextString::isBidi() const
+{
+ if ( bidiDirty )
+ checkBidi();
+ return bidi;
+}
+
+inline bool TQTextString::isRightToLeft() const
+{
+ if ( bidiDirty )
+ checkBidi();
+ return rightToLeft;
+}
+
+inline TQString TQTextString::toString() const
+{
+ if(bidiDirty)
+ checkBidi();
+ return stringCache;
+}
+
+inline TQChar::Direction TQTextString::direction() const
+{
+ return (TQChar::Direction) dir;
+}
+
+inline int TQTextString::nextCursorPosition( int next )
+{
+ if ( bidiDirty )
+ checkBidi();
+
+ const TQTextStringChar *c = data.data();
+ int len = length();
+
+ if ( next < len - 1 ) {
+ next++;
+ while ( next < len - 1 && !c[next].charStop )
+ next++;
+ }
+ return next;
+}
+
+inline int TQTextString::previousCursorPosition( int prev )
+{
+ if ( bidiDirty )
+ checkBidi();
+
+ const TQTextStringChar *c = data.data();
+
+ if ( prev ) {
+ prev--;
+ while ( prev && !c[prev].charStop )
+ prev--;
+ }
+ return prev;
+}
+
+inline bool TQTextString::validCursorPosition( int idx )
+{
+ if ( bidiDirty )
+ checkBidi();
+
+ return (at( idx ).charStop);
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQValueStack<int>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQValueStack<TQTextParagraph*>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQValueStack<bool>;
+// TQMOC_SKIP_END
+#endif
+
+class TQ_EXPORT TQTextCursor
+{
+public:
+ TQTextCursor( TQTextDocument *d = 0 );
+ TQTextCursor( const TQTextCursor &c );
+ TQTextCursor &operator=( const TQTextCursor &c );
+ virtual ~TQTextCursor() {}
+
+ bool operator==( const TQTextCursor &c ) const;
+ bool operator!=( const TQTextCursor &c ) const { return !(*this == c); }
+
+ inline TQTextParagraph *paragraph() const { return para; }
+
+ TQTextDocument *document() const;
+ int index() const;
+
+ void gotoPosition( TQTextParagraph* p, int index = 0);
+ void setIndex( int index ) { gotoPosition(paragraph(), index ); }
+ void setParagraph( TQTextParagraph*p ) { gotoPosition(p, 0 ); }
+
+ void gotoLeft();
+ void gotoRight();
+ void gotoNextLetter();
+ void gotoPreviousLetter();
+ void gotoUp();
+ void gotoDown();
+ void gotoLineEnd();
+ void gotoLineStart();
+ void gotoHome();
+ void gotoEnd();
+ void gotoPageUp( int visibleHeight );
+ void gotoPageDown( int visibleHeight );
+ void gotoNextWord( bool onlySpace = FALSE );
+ void gotoPreviousWord( bool onlySpace = FALSE );
+ void gotoWordLeft();
+ void gotoWordRight();
+
+ void insert( const QString &s, bool checkNewLine, TQMemArray<TQTextStringChar> *formatting = 0 );
+ void splitAndInsertEmptyParagraph( bool ind = TRUE, bool updateIds = TRUE );
+ bool remove();
+ bool removePreviousChar();
+ void indent();
+
+ bool atParagStart();
+ bool atParagEnd();
+
+ int x() const; // x in current paragraph
+ int y() const; // y in current paragraph
+
+ int globalX() const;
+ int globalY() const;
+
+ TQTextParagraph *topParagraph() const { return paras.isEmpty() ? para : paras.first(); }
+ int offsetX() const { return ox; } // inner document offset
+ int offsetY() const { return oy; } // inner document offset
+ int totalOffsetX() const; // total document offset
+ int totalOffsetY() const; // total document offset
+
+ bool place( const TQPoint &pos, TQTextParagraph *s ) { return place( pos, s, FALSE ); }
+ bool place( const TQPoint &pos, TQTextParagraph *s, bool link );
+ void restoreState();
+
+
+ int nestedDepth() const { return (int)indices.count(); } //### size_t/int cast
+ void oneUp() { if ( !indices.isEmpty() ) pop(); }
+ void setValid( bool b ) { valid = b; }
+ bool isValid() const { return valid; }
+
+ void fixCursorPosition();
+private:
+ enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
+
+ void push();
+ void pop();
+ bool processNesting( Operation op );
+ void invalidateNested();
+ void gotoIntoNested( const TQPoint &globalPos );
+
+ TQTextParagraph *para;
+ int idx, tmpX;
+ int ox, oy;
+ TQValueStack<int> indices;
+ TQValueStack<TQTextParagraph*> paras;
+ TQValueStack<int> xOffsets;
+ TQValueStack<int> yOffsets;
+ uint valid : 1;
+
+};
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextCommand
+{
+public:
+ enum Commands { Invalid, Insert, Delete, Format, Style };
+
+ TQTextCommand( TQTextDocument *d ) : doc( d ), cursor( d ) {}
+ virtual ~TQTextCommand();
+
+ virtual Commands type() const;
+
+ virtual TQTextCursor *execute( TQTextCursor *c ) = 0;
+ virtual TQTextCursor *unexecute( TQTextCursor *c ) = 0;
+
+protected:
+ TQTextDocument *doc;
+ TQTextCursor cursor;
+
+};
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrList<TQTextCommand>;
+// TQMOC_SKIP_END
+#endif
+
+class TQ_EXPORT TQTextCommandHistory
+{
+public:
+ TQTextCommandHistory( int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); }
+ virtual ~TQTextCommandHistory();
+
+ void clear() { history.clear(); current = -1; }
+
+ void addCommand( TQTextCommand *cmd );
+ TQTextCursor *undo( TQTextCursor *c );
+ TQTextCursor *redo( TQTextCursor *c );
+
+ bool isUndoAvailable();
+ bool isRedoAvailable();
+
+ void setUndoDepth( int d ) { steps = d; }
+ int undoDepth() const { return steps; }
+
+ int historySize() const { return history.count(); }
+ int currentPosition() const { return current; }
+
+private:
+ TQPtrList<TQTextCommand> history;
+ int current, steps;
+
+};
+
+inline TQTextCommandHistory::~TQTextCommandHistory()
+{
+ clear();
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQ_EXPORT TQTextCustomItem
+{
+public:
+ TQTextCustomItem( TQTextDocument *p )
+ : xpos(0), ypos(-1), width(-1), height(0), tqparent( p )
+ {}
+ virtual ~TQTextCustomItem();
+ virtual void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected ) = 0;
+
+ virtual void adjustToPainter( TQPainter* );
+
+ enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
+ virtual Placement placement() const;
+ bool placeInline() { return placement() == PlaceInline; }
+
+ virtual bool ownLine() const;
+ virtual void resize( int nwidth );
+ virtual void tqinvalidate();
+ virtual int ascent() const { return height; }
+
+ virtual bool isNested() const;
+ virtual int minimumWidth() const;
+
+ virtual TQString richText() const;
+
+ int xpos; // used for floating items
+ int ypos; // used for floating items
+ int width;
+ int height;
+
+ TQRect tqgeometry() const { return TQRect( xpos, ypos, width, height ); }
+
+ virtual bool enter( TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = FALSE );
+ virtual bool enterAt( TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, const TQPoint & );
+ virtual bool next( TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+ virtual bool prev( TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+ virtual bool down( TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+ virtual bool up( TQTextCursor *, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+
+ virtual void setParagraph( TQTextParagraph *p ) { parag = p; }
+ TQTextParagraph *paragraph() const { return parag; }
+
+ TQTextDocument *tqparent;
+ TQTextParagraph *parag;
+
+ virtual void pageBreak( int y, TQTextFlow* flow );
+};
+#endif
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+//TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMap<TQString, TQString>;
+// TQMOC_SKIP_END
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQ_EXPORT TQTextImage : public TQTextCustomItem
+{
+public:
+ TQTextImage( TQTextDocument *p, const QMap<TQString, TQString> &attr, const TQString& context,
+ TQMimeSourceFactory &factory );
+ virtual ~TQTextImage();
+
+ Placement placement() const { return place; }
+ void adjustToPainter( TQPainter* );
+ int minimumWidth() const { return width; }
+
+ TQString richText() const;
+
+ void draw( TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected );
+
+private:
+ TQRegion* reg;
+ TQPixmap pm;
+ Placement place;
+ int tmpwidth, tmpheight;
+ TQMap<TQString, TQString> attributes;
+ TQString imgId;
+
+};
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQ_EXPORT TQTextHorizontalLine : public TQTextCustomItem
+{
+public:
+ TQTextHorizontalLine( TQTextDocument *p, const TQMap<TQString, TQString> &attr, const TQString& context,
+ TQMimeSourceFactory &factory );
+ virtual ~TQTextHorizontalLine();
+
+ void adjustToPainter( TQPainter* );
+ void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected );
+ TQString richText() const;
+
+ bool ownLine() const { return TRUE; }
+
+private:
+ int tmpheight;
+ TQColor color;
+ bool shade;
+
+};
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrList<TQTextCustomItem>;
+// TQMOC_SKIP_END
+#endif
+#endif
+
+class TQ_EXPORT TQTextFlow
+{
+ friend class TQTextDocument;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ friend class TQTextTableCell;
+#endif
+
+public:
+ TQTextFlow();
+ virtual ~TQTextFlow();
+
+ virtual void setWidth( int width );
+ int width() const;
+
+ virtual void setPageSize( int ps );
+ int pageSize() const { return pagesize; }
+
+ virtual int adjustLMargin( int yp, int h, int margin, int space );
+ virtual int adjustRMargin( int yp, int h, int margin, int space );
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ virtual void registerFloatingItem( TQTextCustomItem* item );
+ virtual void unregisterFloatingItem( TQTextCustomItem* item );
+#endif
+ virtual TQRect boundingRect() const;
+ virtual void drawFloatingItems(TQPainter* p, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected );
+
+ virtual int adjustFlow( int y, int w, int h ); // adjusts y according to the defined pagesize. Returns the shift.
+
+ virtual bool isEmpty();
+
+ void clear();
+
+private:
+ int w;
+ int pagesize;
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQPtrList<TQTextCustomItem> leftItems;
+ TQPtrList<TQTextCustomItem> rightItems;
+#endif
+};
+
+inline int TQTextFlow::width() const { return w; }
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQTextTable;
+
+class TQ_EXPORT TQTextTableCell : public TQLayoutItem
+{
+ friend class TQTextTable;
+
+public:
+ TQTextTableCell( TQTextTable* table,
+ int row, int column,
+ const TQMap<TQString, TQString> &attr,
+ const TQStyleSheetItem* style,
+ const TQTextFormat& fmt, const TQString& context,
+ TQMimeSourceFactory &factory, TQStyleSheet *sheet, const TQString& doc );
+ virtual ~TQTextTableCell();
+
+ TQSize tqsizeHint() const ;
+ TQSize tqminimumSize() const ;
+ TQSize tqmaximumSize() const ;
+ TQ_SPExpandData expandingDirections() const;
+ bool isEmpty() const;
+ void setGeometry( const TQRect& ) ;
+ TQRect tqgeometry() const;
+
+ bool hasHeightForWidth() const;
+ int heightForWidth( int ) const;
+
+ void adjustToPainter( TQPainter* );
+
+ int row() const { return row_; }
+ int column() const { return col_; }
+ int rowspan() const { return rowspan_; }
+ int colspan() const { return colspan_; }
+ int stretch() const { return stretch_; }
+
+ TQTextDocument* richText() const { return richtext; }
+ TQTextTable* table() const { return tqparent; }
+
+ void draw( TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected );
+
+ TQBrush *backGround() const { return background; }
+ virtual void tqinvalidate();
+
+ int verticalAlignmentOffset() const;
+ int horizontalAlignmentOffset() const;
+
+private:
+ TQRect geom;
+ TQTextTable* tqparent;
+ TQTextDocument* richtext;
+ int row_;
+ int col_;
+ int rowspan_;
+ int colspan_;
+ int stretch_;
+ int maxw;
+ int minw;
+ bool hasFixedWidth;
+ TQBrush *background;
+ int cached_width;
+ int cached_sizehint;
+ TQMap<TQString, TQString> attributes;
+ int align;
+};
+#endif
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrList<TQTextTableCell>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMap<TQTextCursor*, int>;
+// TQMOC_SKIP_END
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQ_EXPORT TQTextTable: public TQTextCustomItem
+{
+ friend class TQTextTableCell;
+
+public:
+ TQTextTable( TQTextDocument *p, const TQMap<TQString, TQString> &attr );
+ virtual ~TQTextTable();
+
+ void adjustToPainter( TQPainter *p );
+ void pageBreak( int y, TQTextFlow* flow );
+ void draw( TQPainter* p, int x, int y, int cx, int cy, int cw, int ch,
+ const TQColorGroup& cg, bool selected );
+
+ bool noErase() const { return TRUE; }
+ bool ownLine() const { return TRUE; }
+ Placement placement() const { return place; }
+ bool isNested() const { return TRUE; }
+ void resize( int nwidth );
+ virtual void tqinvalidate();
+
+ virtual bool enter( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = FALSE );
+ virtual bool enterAt( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy, const TQPoint &pos );
+ virtual bool next( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+ virtual bool prev( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+ virtual bool down( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+ virtual bool up( TQTextCursor *c, TQTextDocument *&doc, TQTextParagraph *&parag, int &idx, int &ox, int &oy );
+
+ TQString richText() const;
+
+ int minimumWidth() const;
+
+ TQPtrList<TQTextTableCell> tableCells() const { return cells; }
+
+ bool isStretching() const { return stretch; }
+ void setParagraph(TQTextParagraph *p);
+
+private:
+ void format( int w );
+ void addCell( TQTextTableCell* cell );
+
+private:
+ TQGridLayout* tqlayout;
+ TQPtrList<TQTextTableCell> cells;
+ int cachewidth;
+ int fixwidth;
+ int cellpadding;
+ int cellspacing;
+ int border;
+ int outerborder;
+ int stretch;
+ int innerborder;
+ int us_cp, us_ib, us_b, us_ob, us_cs;
+ int us_fixwidth;
+ TQMap<TQString, TQString> attributes;
+ TQMap<TQTextCursor*, int> currCell;
+ Placement place;
+ void adjustCells( int y , int shift );
+ int pageBreakFor;
+};
+#endif
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQTextTableCell;
+class TQTextParagraph;
+#endif
+
+struct TQ_EXPORT TQTextDocumentSelection
+{
+ TQTextCursor startCursor, endCursor;
+ bool swapped;
+ TQ_DUMMY_COMPARISON_OPERATOR(TQTextDocumentSelection)
+};
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMap<int, TQColor>;
+//TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMap<int, bool>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMap<int, TQTextDocumentSelection>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrList<TQTextDocument>;
+// TQMOC_SKIP_END
+#endif
+
+class TQ_EXPORT TQTextDocument : public TQObject
+{
+ TQ_OBJECT
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ friend class TQTextTableCell;
+#endif
+ friend class TQTextCursor;
+ friend class TQTextEdit;
+ friend class TQTextParagraph;
+ friend class TQTextTable;
+
+public:
+ enum SelectionIds {
+ Standard = 0,
+ IMSelectionText = 31998,
+ IMCompositionText = 31999, // this must be higher!
+ Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to
+ // remove multiple lines with removeSelectedText()
+ };
+
+ TQTextDocument( TQTextDocument *p );
+ virtual ~TQTextDocument();
+
+ TQTextDocument *tqparent() const { return par; }
+ TQTextParagraph *parentParagraph() const { return parentPar; }
+
+ void setText( const TQString &text, const TQString &context );
+ TQMap<TQString, TQString> attributes() const { return attribs; }
+ void setAttributes( const TQMap<TQString, TQString> &attr ) { attribs = attr; }
+
+ TQString text() const;
+ TQString text( int parag ) const;
+ TQString originalText() const;
+
+ int x() const;
+ int y() const;
+ int width() const;
+ int widthUsed() const;
+ int visibleWidth() const;
+ int height() const;
+ void setWidth( int w );
+ int minimumWidth() const;
+ bool setMinimumWidth( int needed, int used = -1, TQTextParagraph *parag = 0 );
+
+ void setY( int y );
+ int leftMargin() const;
+ void setLeftMargin( int lm );
+ int rightMargin() const;
+ void setRightMargin( int rm );
+
+ TQTextParagraph *firstParagraph() const;
+ TQTextParagraph *lastParagraph() const;
+ void setFirstParagraph( TQTextParagraph *p );
+ void setLastParagraph( TQTextParagraph *p );
+
+ void tqinvalidate();
+
+ void setPreProcessor( TQTextPreProcessor *sh );
+ TQTextPreProcessor *preProcessor() const;
+
+ void setFormatter( TQTextFormatter *f );
+ TQTextFormatter *formatter() const;
+
+ void setIndent( TQTextIndent *i );
+ TQTextIndent *indent() const;
+
+ TQColor selectionColor( int id ) const;
+ bool invertSelectionText( int id ) const;
+ void setSelectionColor( int id, const TQColor &c );
+ void setInvertSelectionText( int id, bool b );
+ bool hasSelection( int id, bool visible = FALSE ) const;
+ void setSelectionStart( int id, const TQTextCursor &cursor );
+ bool setSelectionEnd( int id, const TQTextCursor &cursor );
+ void selectAll( int id );
+ bool removeSelection( int id );
+ void selectionStart( int id, int &paragId, int &index );
+ TQTextCursor selectionStartCursor( int id );
+ TQTextCursor selectionEndCursor( int id );
+ void selectionEnd( int id, int &paragId, int &index );
+ void setFormat( int id, TQTextFormat *f, int flags );
+ int numSelections() const { return nSelections; }
+ void addSelection( int id );
+
+ TQString selectedText( int id, bool asRichText = FALSE ) const;
+ void removeSelectedText( int id, TQTextCursor *cursor );
+ void indentSelection( int id );
+
+ TQTextParagraph *paragAt( int i ) const;
+
+ void addCommand( TQTextCommand *cmd );
+ TQTextCursor *undo( TQTextCursor *c = 0 );
+ TQTextCursor *redo( TQTextCursor *c = 0 );
+ TQTextCommandHistory *commands() const { return commandHistory; }
+
+ TQTextFormatCollection *formatCollection() const;
+
+ bool tqfind( TQTextCursor &cursor, const TQString &expr, bool cs, bool wo, bool forward);
+
+ void setTextFormat( TQt::TextFormat f );
+ TQt::TextFormat textFormat() const;
+
+ bool inSelection( int selId, const TQPoint &pos ) const;
+
+ TQStyleSheet *styleSheet() const { return sheet_; }
+#ifndef TQT_NO_MIME
+ TQMimeSourceFactory *mimeSourceFactory() const { return factory_; }
+#endif
+ TQString context() const { return contxt; }
+
+ void setStyleSheet( TQStyleSheet *s );
+ void setDefaultFormat( const TQFont &font, const TQColor &color );
+#ifndef TQT_NO_MIME
+ void setMimeSourceFactory( TQMimeSourceFactory *f ) { if ( f ) factory_ = f; }
+#endif
+ void setContext( const TQString &c ) { if ( !c.isEmpty() ) contxt = c; }
+
+ void setUnderlineLinks( bool b );
+ bool underlineLinks() const { return underlLinks; }
+
+ void setPaper( TQBrush *brush ) { if ( backBrush ) delete backBrush; backBrush = brush; }
+ TQBrush *paper() const { return backBrush; }
+
+ void doLayout( TQPainter *p, int w );
+ void draw( TQPainter *p, const TQRect& rect, const TQColorGroup &cg, const TQBrush *paper = 0 );
+ bool useDoubleBuffer( TQTextParagraph *parag, TQPainter *p );
+
+ void drawParagraph( TQPainter *p, TQTextParagraph *parag, int cx, int cy, int cw, int ch,
+ TQPixmap *&doubleBuffer, const TQColorGroup &cg,
+ bool drawCursor, TQTextCursor *cursor, bool resetChanged = TRUE );
+ TQTextParagraph *draw( TQPainter *p, int cx, int cy, int cw, int ch, const TQColorGroup &cg,
+ bool onlyChanged = FALSE, bool drawCursor = FALSE, TQTextCursor *cursor = 0,
+ bool resetChanged = TRUE );
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ void registerCustomItem( TQTextCustomItem *i, TQTextParagraph *p );
+ void unregisterCustomItem( TQTextCustomItem *i, TQTextParagraph *p );
+#endif
+
+ void setFlow( TQTextFlow *f );
+ void takeFlow();
+ TQTextFlow *flow() const { return flow_; }
+ bool isPageBreakEnabled() const { return pages; }
+ void setPageBreakEnabled( bool b ) { pages = b; }
+
+ void setUseFormatCollection( bool b ) { useFC = b; }
+ bool useFormatCollection() const { return useFC; }
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextTableCell *tableCell() const { return tc; }
+ void setTableCell( TQTextTableCell *c ) { tc = c; }
+#endif
+
+ void setPlainText( const TQString &text );
+ void setRichText( const TQString &text, const TQString &context, const TQTextFormat *initialFormat = 0 );
+ TQString richText() const;
+ TQString plainText() const;
+
+ bool focusNextPrevChild( bool next );
+
+ int tqalignment() const;
+ void tqsetAlignment( int a );
+
+ int *tabArray() const;
+ int tabStopWidth() const;
+ void setTabArray( int *a );
+ void setTabStops( int tw );
+
+ void setUndoDepth( int d ) { commandHistory->setUndoDepth( d ); }
+ int undoDepth() const { return commandHistory->undoDepth(); }
+
+ int length() const;
+ void clear( bool createEmptyParag = FALSE );
+
+ virtual TQTextParagraph *createParagraph( TQTextDocument *d, TQTextParagraph *pr = 0, TQTextParagraph *nx = 0, bool updateIds = TRUE );
+ void insertChild( TQObject *o ) { TQObject::insertChild( o ); }
+ void removeChild( TQObject *o ) { TQObject::removeChild( o ); }
+ void insertChild( TQTextDocument *d ) { childList.append( d ); }
+ void removeChild( TQTextDocument *d ) { childList.removeRef( d ); }
+ TQPtrList<TQTextDocument> childrenListObject() const { return childList; }
+
+ bool hasFocusParagraph() const;
+ TQString focusHref() const;
+ TQString focusName() const;
+
+ void invalidateOriginalText() { oTextValid = FALSE; oText = ""; }
+
+Q_SIGNALS:
+ void minimumWidthChanged( int );
+
+private:
+ void init();
+ TQPixmap *bufferPixmap( const TQSize &s );
+ // HTML parser
+ bool hasPrefix(const TQChar* doc, int length, int pos, TQChar c);
+ bool hasPrefix(const TQChar* doc, int length, int pos, const TQString& s);
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextCustomItem* parseTable( const TQMap<TQString, TQString> &attr, const TQTextFormat &fmt,
+ const TQChar* doc, int length, int& pos, TQTextParagraph *curpar );
+#endif
+ bool eatSpace(const TQChar* doc, int length, int& pos, bool includeNbsp = FALSE );
+ bool eat(const TQChar* doc, int length, int& pos, TQChar c);
+ TQString parseOpenTag(const TQChar* doc, int length, int& pos, TQMap<TQString, TQString> &attr, bool& emptyTag);
+ TQString parseCloseTag( const TQChar* doc, int length, int& pos );
+ TQChar parseHTMLSpecialChar(const TQChar* doc, int length, int& pos);
+ TQString parseWord(const TQChar* doc, int length, int& pos, bool lower = TRUE);
+ TQChar parseChar(const TQChar* doc, int length, int& pos, TQStyleSheetItem::WhiteSpaceMode wsm );
+ void setRichTextInternal( const TQString &text, TQTextCursor* cursor = 0, const TQTextFormat *initialFormat = 0 );
+ void setRichTextMarginsInternal( TQPtrList< TQPtrVector<TQStyleSheetItem> >& styles, TQTextParagraph* stylesPar );
+
+private:
+ struct TQ_EXPORT Focus {
+ TQTextParagraph *parag;
+ int start, len;
+ TQString href;
+ TQString name;
+ };
+
+ int cx, cy, cw, vw;
+ TQTextParagraph *fParag, *lParag;
+ TQTextPreProcessor *pProcessor;
+ TQMap<int, TQColor> selectionColors;
+ TQMap<int, TQTextDocumentSelection> selections;
+ TQMap<int, bool> selectionText;
+ TQTextCommandHistory *commandHistory;
+ TQTextFormatter *pFormatter;
+ TQTextIndent *indenter;
+ TQTextFormatCollection *fCollection;
+ TQt::TextFormat txtFormat;
+ uint preferRichText : 1;
+ uint pages : 1;
+ uint useFC : 1;
+ uint withoutDoubleBuffer : 1;
+ uint underlLinks : 1;
+ uint nextDoubleBuffered : 1;
+ uint oTextValid : 1;
+ uint mightHaveCustomItems : 1;
+ int align;
+ int nSelections;
+ TQTextFlow *flow_;
+ TQTextDocument *par;
+ TQTextParagraph *parentPar;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextTableCell *tc;
+#endif
+ TQBrush *backBrush;
+ TQPixmap *buf_pixmap;
+ Focus focusIndicator;
+ int minw;
+ int wused;
+ int leftmargin;
+ int rightmargin;
+ TQTextParagraph *minwParag, *curParag;
+ TQStyleSheet* sheet_;
+#ifndef TQT_NO_MIME
+ TQMimeSourceFactory* factory_;
+#endif
+ TQString contxt;
+ TQMap<TQString, TQString> attribs;
+ int *tArray;
+ int tStopWidth;
+ int uDepth;
+ TQString oText;
+ TQPtrList<TQTextDocument> childList;
+ TQColor linkColor, bodyText;
+ double scaleFontsFactor;
+
+ short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm;
+#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator=
+ TQTextDocument( const TQTextDocument & );
+ TQTextDocument &operator=( const TQTextDocument & );
+#endif
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+class TQ_EXPORT TQTextDeleteCommand : public TQTextCommand
+{
+public:
+ TQTextDeleteCommand( TQTextDocument *d, int i, int idx, const TQMemArray<TQTextStringChar> &str,
+ const TQByteArray& oldStyle );
+ TQTextDeleteCommand( TQTextParagraph *p, int idx, const TQMemArray<TQTextStringChar> &str );
+ virtual ~TQTextDeleteCommand();
+
+ Commands type() const { return Delete; }
+ TQTextCursor *execute( TQTextCursor *c );
+ TQTextCursor *unexecute( TQTextCursor *c );
+
+protected:
+ int id, index;
+ TQTextParagraph *parag;
+ TQMemArray<TQTextStringChar> text;
+ TQByteArray styleInformation;
+
+};
+
+class TQ_EXPORT TQTextInsertCommand : public TQTextDeleteCommand
+{
+public:
+ TQTextInsertCommand( TQTextDocument *d, int i, int idx, const TQMemArray<TQTextStringChar> &str,
+ const TQByteArray& oldStyleInfo )
+ : TQTextDeleteCommand( d, i, idx, str, oldStyleInfo ) {}
+ TQTextInsertCommand( TQTextParagraph *p, int idx, const TQMemArray<TQTextStringChar> &str )
+ : TQTextDeleteCommand( p, idx, str ) {}
+ virtual ~TQTextInsertCommand() {}
+
+ Commands type() const { return Insert; }
+ TQTextCursor *execute( TQTextCursor *c ) { return TQTextDeleteCommand::unexecute( c ); }
+ TQTextCursor *unexecute( TQTextCursor *c ) { return TQTextDeleteCommand::execute( c ); }
+
+};
+
+class TQ_EXPORT TQTextFormatCommand : public TQTextCommand
+{
+public:
+ TQTextFormatCommand( TQTextDocument *d, int sid, int sidx, int eid, int eidx, const TQMemArray<TQTextStringChar> &old, TQTextFormat *f, int fl );
+ virtual ~TQTextFormatCommand();
+
+ Commands type() const { return Format; }
+ TQTextCursor *execute( TQTextCursor *c );
+ TQTextCursor *unexecute( TQTextCursor *c );
+
+protected:
+ int startId, startIndex, endId, endIndex;
+ TQTextFormat *format;
+ TQMemArray<TQTextStringChar> oldFormats;
+ int flags;
+
+};
+
+class TQ_EXPORT TQTextStyleCommand : public TQTextCommand
+{
+public:
+ TQTextStyleCommand( TQTextDocument *d, int fParag, int lParag, const TQByteArray& beforeChange );
+ virtual ~TQTextStyleCommand() {}
+
+ Commands type() const { return Style; }
+ TQTextCursor *execute( TQTextCursor *c );
+ TQTextCursor *unexecute( TQTextCursor *c );
+
+ static TQByteArray readStyleInformation( TQTextDocument* d, int fParag, int lParag );
+ static void writeStyleInformation( TQTextDocument* d, int fParag, const TQByteArray& style );
+
+private:
+ int firstParag, lastParag;
+ TQByteArray before;
+ TQByteArray after;
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+struct TQ_EXPORT TQTextParagraphSelection
+{
+ TQTextParagraphSelection() : start(0), end(0) { }
+ int start, end;
+ TQ_DUMMY_COMPARISON_OPERATOR(TQTextParagraphSelection)
+};
+
+struct TQ_EXPORT TQTextLineStart
+{
+ TQTextLineStart() : y( 0 ), baseLine( 0 ), h( 0 )
+ { }
+ TQTextLineStart( int y_, int bl, int h_ ) : y( y_ ), baseLine( bl ), h( h_ ),
+ w( 0 )
+ { }
+
+public:
+ int y, baseLine, h;
+ int w;
+};
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMap<int, TQTextParagraphSelection>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQMap<int, TQTextLineStart*>;
+// TQMOC_SKIP_END
+#endif
+
+class TQ_EXPORT TQTextParagraphData
+{
+public:
+ TQTextParagraphData() {}
+ virtual ~TQTextParagraphData();
+ virtual void join( TQTextParagraphData * );
+};
+
+class TQTextParagraphPseudoDocument;
+
+class TQSyntaxHighlighter;
+
+class TQ_EXPORT TQTextParagraph
+{
+ friend class TQTextDocument;
+ friend class TQTextCursor;
+ friend class TQSyntaxHighlighter;
+
+public:
+ TQTextParagraph( TQTextDocument *d, TQTextParagraph *pr = 0, TQTextParagraph *nx = 0, bool updateIds = TRUE );
+ ~TQTextParagraph();
+
+ TQTextString *string() const;
+ TQTextStringChar *at( int i ) const; // maybe remove later
+ int leftGap() const;
+ int length() const; // maybe remove later
+
+ void setListStyle( TQStyleSheetItem::ListStyle ls ) { lstyle = ls; changed = TRUE; }
+ TQStyleSheetItem::ListStyle listStyle() const { return (TQStyleSheetItem::ListStyle)lstyle; }
+ void setListItem( bool li );
+ bool isListItem() const { return litem; }
+ void setListValue( int v ) { list_val = v; }
+ int listValue() const { return list_val > 0 ? list_val : -1; }
+
+ void setListDepth( int depth );
+ int listDepth() const { return ldepth; }
+
+// void setFormat( TQTextFormat *fm );
+// TQTextFormat *paragFormat() const;
+
+ inline TQTextDocument *document() const {
+ if (hasdoc) return (TQTextDocument*) docOrPseudo;
+ return 0;
+ }
+ TQTextParagraphPseudoDocument *pseudoDocument() const;
+
+ TQRect rect() const;
+ void setHeight( int h ) { r.setHeight( h ); }
+ void show();
+ void hide();
+ bool isVisible() const { return visible; }
+
+ TQTextParagraph *prev() const;
+ TQTextParagraph *next() const;
+ void setPrev( TQTextParagraph *s );
+ void setNext( TQTextParagraph *s );
+
+ void insert( int index, const QString &s );
+ void insert( int index, const QChar *tqunicode, int len );
+ void append( const TQString &s, bool reallyAtEnd = FALSE );
+ void truncate( int index );
+ void remove( int index, int len );
+ void join( TQTextParagraph *s );
+
+ void tqinvalidate( int chr );
+
+ void move( int &dy );
+ void format( int start = -1, bool doMove = TRUE );
+
+ bool isValid() const;
+ bool hasChanged() const;
+ void setChanged( bool b, bool recursive = FALSE );
+
+ int lineHeightOfChar( int i, int *bl = 0, int *y = 0 ) const;
+ TQTextStringChar *lineStartOfChar( int i, int *index = 0, int *line = 0 ) const;
+ int lines() const;
+ TQTextStringChar *lineStartOfLine( int line, int *index = 0 ) const;
+ int lineY( int l ) const;
+ int lineBaseLine( int l ) const;
+ int lineHeight( int l ) const;
+ void lineInfo( int l, int &y, int &h, int &bl ) const;
+
+ void setSelection( int id, int start, int end );
+ void removeSelection( int id );
+ int selectionStart( int id ) const;
+ int selectionEnd( int id ) const;
+ bool hasSelection( int id ) const;
+ bool hasAnySelection() const;
+ bool fullSelected( int id ) const;
+
+ void setEndState( int s );
+ int endState() const;
+
+ void setParagId( int i );
+ int paragId() const;
+
+ bool firstPreProcess() const;
+ void setFirstPreProcess( bool b );
+
+ void indent( int *oldIndent = 0, int *newIndent = 0 );
+
+ void setExtraData( TQTextParagraphData *data );
+ TQTextParagraphData *extraData() const;
+
+ TQMap<int, TQTextLineStart*> &lineStartList();
+
+ void setFormat( int index, int len, TQTextFormat *f, bool useCollection = TRUE, int flags = -1 );
+
+ void tqsetAlignment( int a );
+ int tqalignment() const;
+
+ void paint( TQPainter &painter, const TQColorGroup &cg, TQTextCursor *cursor = 0, bool drawSelections = FALSE,
+ int clipx = -1, int clipy = -1, int clipw = -1, int cliph = -1 );
+
+ int topMargin() const;
+ int bottomMargin() const;
+ int leftMargin() const;
+ int firstLineMargin() const;
+ int rightMargin() const;
+ int lineSpacing() const;
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ void registerFloatingItem( TQTextCustomItem *i );
+ void unregisterFloatingItem( TQTextCustomItem *i );
+#endif
+
+ void setFullWidth( bool b ) { fullWidth = b; }
+ bool isFullWidth() const { return fullWidth; }
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQTextTableCell *tableCell() const;
+#endif
+
+ TQBrush *background() const;
+
+ int documentWidth() const;
+ int documentVisibleWidth() const;
+ int documentX() const;
+ int documentY() const;
+ TQTextFormatCollection *formatCollection() const;
+ TQTextFormatter *formatter() const;
+
+ int nextTab( int i, int x );
+ int *tabArray() const;
+ void setTabArray( int *a );
+ void setTabStops( int tw );
+
+ void adjustToPainter( TQPainter *p );
+
+ void setNewLinesAllowed( bool b );
+ bool isNewLinesAllowed() const;
+
+ TQString richText() const;
+
+ void addCommand( TQTextCommand *cmd );
+ TQTextCursor *undo( TQTextCursor *c = 0 );
+ TQTextCursor *redo( TQTextCursor *c = 0 );
+ TQTextCommandHistory *commands() const;
+ void copyParagData( TQTextParagraph *parag );
+
+ void setBreakable( bool b ) { breakable = b; }
+ bool isBreakable() const { return breakable; }
+
+ void setBackgroundColor( const TQColor &c );
+ TQColor *backgroundColor() const { return bgcol; }
+ void clearBackgroundColor();
+
+ void setMovedDown( bool b ) { movedDown = b; }
+ bool wasMovedDown() const { return movedDown; }
+
+ void setDirection( TQChar::Direction d );
+ TQChar::Direction direction() const;
+ void setPaintDevice( TQPaintDevice *pd ) { painttqdevice = pd; }
+
+ void readStyleInformation( TQDataStream& stream );
+ void writeStyleInformation( TQDataStream& stream ) const;
+
+protected:
+ void setColorForSelection( TQColor &c, TQPainter &p, const TQColorGroup& cg, int selection );
+ void drawLabel( TQPainter* p, int x, int y, int w, int h, int base, const TQColorGroup& cg );
+ void drawString( TQPainter &painter, const TQString &str, int start, int len, int xstart,
+ int y, int baseLine, int w, int h, bool drawSelections, int fullSelectionWidth,
+ TQTextStringChar *formatChar, const TQColorGroup& cg,
+ bool rightToLeft );
+
+private:
+ TQMap<int, TQTextParagraphSelection> &selections() const;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQPtrList<TQTextCustomItem> &floatingItems() const;
+#endif
+ TQBrush backgroundBrush( const TQColorGroup&cg ) { if ( bgcol ) return *bgcol; return cg.brush( TQColorGroup::Base ); }
+ void invalidateStyleCache();
+
+ TQMap<int, TQTextLineStart*> lineStarts;
+ TQRect r;
+ TQTextParagraph *p, *n;
+ void *docOrPseudo;
+ uint changed : 1;
+ uint firstFormat : 1;
+ uint firstPProcess : 1;
+ uint needPreProcess : 1;
+ uint fullWidth : 1;
+ uint lastInFrame : 1;
+ uint visible : 1;
+ uint breakable : 1;
+ uint movedDown : 1;
+ uint mightHaveCustomItems : 1;
+ uint hasdoc : 1;
+ uint litem : 1; // whether the paragraph is a list item
+ uint rtext : 1; // whether the paragraph needs rich text margin
+ int align : 4;
+ uint /*TQStyleSheetItem::ListStyle*/ lstyle : 4;
+ int invalid;
+ int state, id;
+ TQTextString *str;
+ TQMap<int, TQTextParagraphSelection> *mSelections;
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ TQPtrList<TQTextCustomItem> *mFloatingItems;
+#endif
+ short utm, ubm, ulm, urm, uflm, ulinespacing;
+ short tabStopWidth;
+ int minwidth;
+ int *tArray;
+ TQTextParagraphData *eData;
+ short list_val;
+ ushort ldepth;
+ TQColor *bgcol;
+ TQPaintDevice *painttqdevice;
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextFormatter
+{
+public:
+ TQTextFormatter();
+ virtual ~TQTextFormatter();
+
+ virtual int format( TQTextDocument *doc, TQTextParagraph *parag, int start, const TQMap<int, TQTextLineStart*> &oldLineStarts ) = 0;
+ virtual int formatVertically( TQTextDocument* doc, TQTextParagraph* parag );
+
+ bool isWrapEnabled( TQTextParagraph *p ) const { if ( !wrapEnabled ) return FALSE; if ( p && !p->isBreakable() ) return FALSE; return TRUE;}
+ int wrapAtColumn() const { return wrapColumn;}
+ virtual void setWrapEnabled( bool b );
+ virtual void setWrapAtColumn( int c );
+ virtual void setAllowBreakInWords( bool b ) { biw = b; }
+ bool allowBreakInWords() const { return biw; }
+
+ int minimumWidth() const { return thisminw; }
+ int widthUsed() const { return thiswused; }
+
+protected:
+ virtual TQTextLineStart *formatLine( TQTextParagraph *parag, TQTextString *string, TQTextLineStart *line, TQTextStringChar *start,
+ TQTextStringChar *last, int align = TQt::AlignAuto, int space = 0 );
+#ifndef TQT_NO_COMPLEXTEXT
+ virtual TQTextLineStart *bidiReorderLine( TQTextParagraph *parag, TQTextString *string, TQTextLineStart *line, TQTextStringChar *start,
+ TQTextStringChar *last, int align, int space );
+#endif
+ void insertLineStart( TQTextParagraph *parag, int index, TQTextLineStart *ls );
+
+ int thisminw;
+ int thiswused;
+
+private:
+ bool wrapEnabled;
+ int wrapColumn;
+ bool biw;
+
+#ifdef HAVE_THAI_BREAKS
+ static TQCString *thaiCache;
+ static TQTextString *cachedString;
+ static ThBreakIterator *thaiIt;
+#endif
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextFormatterBreakInWords : public TQTextFormatter
+{
+public:
+ TQTextFormatterBreakInWords();
+ virtual ~TQTextFormatterBreakInWords() {}
+
+ int format( TQTextDocument *doc, TQTextParagraph *parag, int start, const TQMap<int, TQTextLineStart*> &oldLineStarts );
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextFormatterBreakWords : public TQTextFormatter
+{
+public:
+ TQTextFormatterBreakWords();
+ virtual ~TQTextFormatterBreakWords() {}
+
+ int format( TQTextDocument *doc, TQTextParagraph *parag, int start, const TQMap<int, TQTextLineStart*> &oldLineStarts );
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextIndent
+{
+public:
+ TQTextIndent();
+ virtual ~TQTextIndent() {}
+
+ virtual void indent( TQTextDocument *doc, TQTextParagraph *parag, int *oldIndent = 0, int *newIndent = 0 ) = 0;
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextPreProcessor
+{
+public:
+ enum Ids {
+ Standard = 0
+ };
+
+ TQTextPreProcessor();
+ virtual ~TQTextPreProcessor() {}
+
+ virtual void process( TQTextDocument *doc, TQTextParagraph *, int, bool = TRUE ) = 0;
+ virtual TQTextFormat *format( int id ) = 0;
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+class TQ_EXPORT TQTextFormat
+{
+ friend class TQTextFormatCollection;
+ friend class TQTextDocument;
+
+public:
+ enum Flags {
+ NoFlags,
+ Bold = 1,
+ Italic = 2,
+ Underline = 4,
+ Family = 8,
+ Size = 16,
+ Color = 32,
+ Misspelled = 64,
+ VAlign = 128,
+ StrikeOut= 256,
+ Font = Bold | Italic | Underline | Family | Size | StrikeOut,
+ Format = Font | Color | Misspelled | VAlign
+ };
+
+ enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript };
+
+ TQTextFormat();
+ virtual ~TQTextFormat();
+
+ TQTextFormat( const TQStyleSheetItem *s );
+ TQTextFormat( const TQFont &f, const TQColor &c, TQTextFormatCollection *tqparent = 0 );
+ TQTextFormat( const TQTextFormat &fm );
+ TQTextFormat makeTextFormat( const TQStyleSheetItem *style, const TQMap<TQString,TQString>& attr, double scaleFontsFactor ) const;
+ TQTextFormat& operator=( const TQTextFormat &fm );
+ TQColor color() const;
+ TQFont font() const;
+ TQFontMetrics fontMetrics() const { return fm; }
+ bool isMisspelled() const;
+ VerticalAlignment vAlign() const;
+ int minLeftBearing() const;
+ int minRightBearing() const;
+ int width( const TQChar &c ) const;
+ int width( const TQString &str, int pos ) const;
+ int height() const;
+ int ascent() const;
+ int descent() const;
+ int leading() const;
+ bool useLinkColor() const;
+
+ void setBold( bool b );
+ void setItalic( bool b );
+ void setUnderline( bool b );
+ void setStrikeOut( bool b );
+ void setFamily( const TQString &f );
+ void setPointSize( int s );
+ void setFont( const TQFont &f );
+ void setColor( const TQColor &c );
+ void setMisspelled( bool b );
+ void setVAlign( VerticalAlignment a );
+
+ bool operator==( const TQTextFormat &f ) const;
+ TQTextFormatCollection *tqparent() const;
+ const TQString &key() const;
+
+ static TQString getKey( const TQFont &f, const TQColor &c, bool misspelled, VerticalAlignment vAlign );
+
+ void addRef();
+ void removeRef();
+
+ TQString makeFormatChangeTags( TQTextFormat* defaultFormat, TQTextFormat *f, const TQString& oldAnchorHref, const TQString& anchorHref ) const;
+ TQString makeFormatEndTags( TQTextFormat* defaultFormat, const TQString& anchorHref ) const;
+
+ static void setPainter( TQPainter *p );
+ static TQPainter* painter();
+
+ bool fontSizesInPixels() { return usePixelSizes; }
+
+protected:
+ virtual void generateKey();
+
+private:
+ void update();
+ static void applyFont( const TQFont &f );
+
+private:
+ TQFont fn;
+ TQColor col;
+ TQFontMetrics fm;
+ uint missp : 1;
+ uint linkColor : 1;
+ uint usePixelSizes : 1;
+ int leftBearing, rightBearing;
+ VerticalAlignment ha;
+ uchar widths[ 256 ];
+ int hei, asc, dsc;
+ TQTextFormatCollection *collection;
+ int ref;
+ TQString k;
+ int logicalFontSize;
+ int stdSize;
+ static TQPainter *pntr;
+ static TQFontMetrics *pntr_fm;
+ static int pntr_asc;
+ static int pntr_hei;
+ static int pntr_ldg;
+ static int pntr_dsc;
+
+};
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQDict<TQTextFormat>;
+// TQMOC_SKIP_END
+#endif
+
+class TQ_EXPORT TQTextFormatCollection
+{
+ friend class TQTextDocument;
+ friend class TQTextFormat;
+
+public:
+ TQTextFormatCollection();
+ virtual ~TQTextFormatCollection();
+
+ void setDefaultFormat( TQTextFormat *f );
+ TQTextFormat *defaultFormat() const;
+ virtual TQTextFormat *format( TQTextFormat *f );
+ virtual TQTextFormat *format( TQTextFormat *of, TQTextFormat *nf, int flags );
+ virtual TQTextFormat *format( const TQFont &f, const TQColor &c );
+ virtual void remove( TQTextFormat *f );
+ virtual TQTextFormat *createFormat( const TQTextFormat &f ) { return new TQTextFormat( f ); }
+ virtual TQTextFormat *createFormat( const TQFont &f, const TQColor &c ) { return new TQTextFormat( f, c, this ); }
+
+ void updateDefaultFormat( const TQFont &font, const TQColor &c, TQStyleSheet *sheet );
+
+ TQPaintDevice *paintDevice() const { return painttqdevice; }
+ void setPaintDevice( TQPaintDevice * );
+
+private:
+ void updateKeys();
+
+private:
+ TQTextFormat *defFormat, *lastFormat, *cachedFormat;
+ TQDict<TQTextFormat> cKey;
+ TQTextFormat *cres;
+ TQFont cfont;
+ TQColor ccol;
+ TQString kof, knf;
+ int cflags;
+
+ TQPaintDevice *painttqdevice;
+};
+
+class TQ_EXPORT TQTextParagraphPseudoDocument
+{
+public:
+ TQTextParagraphPseudoDocument();
+ ~TQTextParagraphPseudoDocument();
+ TQRect docRect;
+ TQTextFormatter *pFormatter;
+ TQTextCommandHistory *commandHistory;
+ int minw;
+ int wused;
+ TQTextFormatCollection collection;
+};
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline int TQTextParagraph::length() const
+{
+ return str->length();
+}
+
+inline TQRect TQTextParagraph::rect() const
+{
+ return r;
+}
+
+inline int TQTextCursor::index() const
+{
+ return idx;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline int TQTextDocument::x() const
+{
+ return cx;
+}
+
+inline int TQTextDocument::y() const
+{
+ return cy;
+}
+
+inline int TQTextDocument::width() const
+{
+ return TQMAX( cw, flow_->width() );
+}
+
+inline int TQTextDocument::visibleWidth() const
+{
+ return vw;
+}
+
+inline TQTextParagraph *TQTextDocument::firstParagraph() const
+{
+ return fParag;
+}
+
+inline TQTextParagraph *TQTextDocument::lastParagraph() const
+{
+ return lParag;
+}
+
+inline void TQTextDocument::setFirstParagraph( TQTextParagraph *p )
+{
+ fParag = p;
+}
+
+inline void TQTextDocument::setLastParagraph( TQTextParagraph *p )
+{
+ lParag = p;
+}
+
+inline void TQTextDocument::setWidth( int w )
+{
+ cw = TQMAX( w, minw );
+ flow_->setWidth( cw );
+ vw = w;
+}
+
+inline int TQTextDocument::minimumWidth() const
+{
+ return minw;
+}
+
+inline void TQTextDocument::setY( int y )
+{
+ cy = y;
+}
+
+inline int TQTextDocument::leftMargin() const
+{
+ return leftmargin;
+}
+
+inline void TQTextDocument::setLeftMargin( int lm )
+{
+ leftmargin = lm;
+}
+
+inline int TQTextDocument::rightMargin() const
+{
+ return rightmargin;
+}
+
+inline void TQTextDocument::setRightMargin( int rm )
+{
+ rightmargin = rm;
+}
+
+inline TQTextPreProcessor *TQTextDocument::preProcessor() const
+{
+ return pProcessor;
+}
+
+inline void TQTextDocument::setPreProcessor( TQTextPreProcessor * sh )
+{
+ pProcessor = sh;
+}
+
+inline void TQTextDocument::setFormatter( TQTextFormatter *f )
+{
+ delete pFormatter;
+ pFormatter = f;
+}
+
+inline TQTextFormatter *TQTextDocument::formatter() const
+{
+ return pFormatter;
+}
+
+inline void TQTextDocument::setIndent( TQTextIndent *i )
+{
+ indenter = i;
+}
+
+inline TQTextIndent *TQTextDocument::indent() const
+{
+ return indenter;
+}
+
+inline TQColor TQTextDocument::selectionColor( int id ) const
+{
+ return selectionColors[ id ];
+}
+
+inline bool TQTextDocument::invertSelectionText( int id ) const
+{
+ return selectionText[ id ];
+}
+
+inline void TQTextDocument::setSelectionColor( int id, const TQColor &c )
+{
+ selectionColors[ id ] = c;
+}
+
+inline void TQTextDocument::setInvertSelectionText( int id, bool b )
+{
+ selectionText[ id ] = b;
+}
+
+inline TQTextFormatCollection *TQTextDocument::formatCollection() const
+{
+ return fCollection;
+}
+
+inline int TQTextDocument::tqalignment() const
+{
+ return align;
+}
+
+inline void TQTextDocument::tqsetAlignment( int a )
+{
+ align = a;
+}
+
+inline int *TQTextDocument::tabArray() const
+{
+ return tArray;
+}
+
+inline int TQTextDocument::tabStopWidth() const
+{
+ return tStopWidth;
+}
+
+inline void TQTextDocument::setTabArray( int *a )
+{
+ tArray = a;
+}
+
+inline void TQTextDocument::setTabStops( int tw )
+{
+ tStopWidth = tw;
+}
+
+inline TQString TQTextDocument::originalText() const
+{
+ if ( oTextValid )
+ return oText;
+ return text();
+}
+
+inline void TQTextDocument::setFlow( TQTextFlow *f )
+{
+ if ( flow_ )
+ delete flow_;
+ flow_ = f;
+}
+
+inline void TQTextDocument::takeFlow()
+{
+ flow_ = 0;
+}
+
+inline bool TQTextDocument::useDoubleBuffer( TQTextParagraph *parag, TQPainter *p )
+{
+ return ( !parag->document()->tqparent() || parag->document()->nextDoubleBuffered ) &&
+ ( !p || !p->tqdevice() || p->tqdevice()->devType() != TQInternal::Printer );
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline TQColor TQTextFormat::color() const
+{
+ return col;
+}
+
+inline TQFont TQTextFormat::font() const
+{
+ return fn;
+}
+
+inline bool TQTextFormat::isMisspelled() const
+{
+ return missp;
+}
+
+inline TQTextFormat::VerticalAlignment TQTextFormat::vAlign() const
+{
+ return ha;
+}
+
+inline bool TQTextFormat::operator==( const TQTextFormat &f ) const
+{
+ return k == f.k;
+}
+
+inline TQTextFormatCollection *TQTextFormat::tqparent() const
+{
+ return collection;
+}
+
+inline void TQTextFormat::addRef()
+{
+ ref++;
+}
+
+inline void TQTextFormat::removeRef()
+{
+ ref--;
+ if ( !collection )
+ return;
+ if ( this == collection->defFormat )
+ return;
+ if ( ref == 0 )
+ collection->remove( this );
+}
+
+inline const TQString &TQTextFormat::key() const
+{
+ return k;
+}
+
+inline bool TQTextFormat::useLinkColor() const
+{
+ return linkColor;
+}
+
+inline TQTextStringChar *TQTextParagraph::at( int i ) const
+{
+ return &str->at( i );
+}
+
+inline bool TQTextParagraph::isValid() const
+{
+ return invalid == -1;
+}
+
+inline bool TQTextParagraph::hasChanged() const
+{
+ return changed;
+}
+
+inline void TQTextParagraph::setBackgroundColor( const TQColor & c )
+{
+ delete bgcol;
+ bgcol = new TQColor( c );
+ setChanged( TRUE );
+}
+
+inline void TQTextParagraph::clearBackgroundColor()
+{
+ delete bgcol; bgcol = 0; setChanged( TRUE );
+}
+
+inline void TQTextParagraph::append( const TQString &s, bool reallyAtEnd )
+{
+ if ( reallyAtEnd )
+ insert( str->length(), s );
+ else
+ insert( TQMAX( str->length() - 1, 0 ), s );
+}
+
+inline TQTextParagraph *TQTextParagraph::prev() const
+{
+ return p;
+}
+
+inline TQTextParagraph *TQTextParagraph::next() const
+{
+ return n;
+}
+
+inline bool TQTextParagraph::hasAnySelection() const
+{
+ return mSelections ? !selections().isEmpty() : FALSE;
+}
+
+inline void TQTextParagraph::setEndState( int s )
+{
+ if ( s == state )
+ return;
+ state = s;
+}
+
+inline int TQTextParagraph::endState() const
+{
+ return state;
+}
+
+inline void TQTextParagraph::setParagId( int i )
+{
+ id = i;
+}
+
+inline int TQTextParagraph::paragId() const
+{
+ if ( id == -1 )
+ qWarning( "invalid parag id!!!!!!!! (%p)", (void*)this );
+ return id;
+}
+
+inline bool TQTextParagraph::firstPreProcess() const
+{
+ return firstPProcess;
+}
+
+inline void TQTextParagraph::setFirstPreProcess( bool b )
+{
+ firstPProcess = b;
+}
+
+inline TQMap<int, TQTextLineStart*> &TQTextParagraph::lineStartList()
+{
+ return lineStarts;
+}
+
+inline TQTextString *TQTextParagraph::string() const
+{
+ return str;
+}
+
+inline TQTextParagraphPseudoDocument *TQTextParagraph::pseudoDocument() const
+{
+ if ( hasdoc )
+ return 0;
+ return (TQTextParagraphPseudoDocument*) docOrPseudo;
+}
+
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+inline TQTextTableCell *TQTextParagraph::tableCell() const
+{
+ return hasdoc ? document()->tableCell () : 0;
+}
+#endif
+
+inline TQTextCommandHistory *TQTextParagraph::commands() const
+{
+ return hasdoc ? document()->commands() : pseudoDocument()->commandHistory;
+}
+
+
+inline int TQTextParagraph::tqalignment() const
+{
+ return align;
+}
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+inline void TQTextParagraph::registerFloatingItem( TQTextCustomItem *i )
+{
+ floatingItems().append( i );
+}
+
+inline void TQTextParagraph::unregisterFloatingItem( TQTextCustomItem *i )
+{
+ floatingItems().removeRef( i );
+}
+#endif
+
+inline TQBrush *TQTextParagraph::background() const
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ return tableCell() ? tableCell()->backGround() : 0;
+#else
+ return 0;
+#endif
+}
+
+inline int TQTextParagraph::documentWidth() const
+{
+ return hasdoc ? document()->width() : pseudoDocument()->docRect.width();
+}
+
+inline int TQTextParagraph::documentVisibleWidth() const
+{
+ return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width();
+}
+
+inline int TQTextParagraph::documentX() const
+{
+ return hasdoc ? document()->x() : pseudoDocument()->docRect.x();
+}
+
+inline int TQTextParagraph::documentY() const
+{
+ return hasdoc ? document()->y() : pseudoDocument()->docRect.y();
+}
+
+inline void TQTextParagraph::setExtraData( TQTextParagraphData *data )
+{
+ eData = data;
+}
+
+inline TQTextParagraphData *TQTextParagraph::extraData() const
+{
+ return eData;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline void TQTextFormatCollection::setDefaultFormat( TQTextFormat *f )
+{
+ defFormat = f;
+}
+
+inline TQTextFormat *TQTextFormatCollection::defaultFormat() const
+{
+ return defFormat;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+inline TQTextFormat *TQTextStringChar::format() const
+{
+ return (type == Regular) ? d.format : d.custom->format;
+}
+
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+inline TQTextCustomItem *TQTextStringChar::customItem() const
+{
+ return isCustom() ? d.custom->custom : 0;
+}
+#endif
+
+inline int TQTextStringChar::height() const
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ return !isCustom() ? format()->height() : ( customItem()->placement() == TQTextCustomItem::PlaceInline ? customItem()->height : 0 );
+#else
+ return format()->height();
+#endif
+}
+
+inline int TQTextStringChar::ascent() const
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ return !isCustom() ? format()->ascent() : ( customItem()->placement() == TQTextCustomItem::PlaceInline ? customItem()->ascent() : 0 );
+#else
+ return format()->ascent();
+#endif
+}
+
+inline int TQTextStringChar::descent() const
+{
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ return !isCustom() ? format()->descent() : 0;
+#else
+ return format()->descent();
+#endif
+}
+
+#endif //TQT_NO_RICHTEXT
+
+#endif
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqscriptengine.cpp b/tqtinterface/qt4/src/kernel/tqscriptengine.cpp
new file mode 100644
index 0000000..a45237f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqscriptengine.cpp
@@ -0,0 +1,1630 @@
+/****************************************************************************
+**
+** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqscriptengine_p.h"
+
+#include "tqstring.h"
+#include "tqrect.h"
+#include "tqfont.h"
+#include <private/tqunicodetables_p.h>
+#include "tqtextengine_p.h"
+#include "tqfontengine_p.h"
+#include <stdlib.h>
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+#undef None
+#undef Pre
+#undef Above
+#undef Below
+
+const int Prealloc = 256;
+template<class T>
+class TQVarLengthArray
+{
+public:
+ inline explicit TQVarLengthArray(int size = 0);
+ inline ~TQVarLengthArray() {
+ if (ptr != reinterpret_cast<T *>(array))
+ free(ptr);
+ }
+
+ inline int size() const { return s; }
+ inline int count() const { return s; }
+ inline bool isEmpty() const { return (s == 0); }
+ inline void resize(int size);
+ inline void clear() { resize(0); }
+
+ inline int capacity() const { return a; }
+ inline void reserve(int size);
+
+ inline T &operator[](int idx) {
+ TQ_ASSERT(idx >= 0 && idx < s);
+ return ptr[idx];
+ }
+ inline const T &operator[](int idx) const {
+ TQ_ASSERT(idx >= 0 && idx < s);
+ return ptr[idx];
+ }
+
+ inline void append(const T &t) {
+ const int idx = s;
+ resize(idx + 1);
+ ptr[idx] = t;
+ }
+
+ inline T *data() { return ptr; }
+ inline const T *data() const { return ptr; }
+ inline const T * constData() const { return ptr; }
+
+private:
+ void realloc(int size, int alloc);
+
+ int a;
+ int s;
+ T *ptr;
+ TQ_UINT64 array[((Prealloc * sizeof(T)) / sizeof(TQ_UINT64)) + 1];
+};
+
+template <class T>
+TQ_INLINE_TEMPLATES TQVarLengthArray<T>::TQVarLengthArray(int asize)
+ : s(asize) {
+ if (s > Prealloc) {
+ ptr = reinterpret_cast<T *>(malloc(s * sizeof(T)));
+ a = s;
+ } else {
+ ptr = reinterpret_cast<T *>(array);
+ a = Prealloc;
+ }
+}
+
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Basic processing
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+static inline void positionCluster(TQShaperItem *item, int gfrom, int glast)
+{
+ int nmarks = glast - gfrom;
+ if (nmarks <= 0) {
+ qWarning("positionCluster: no marks to position!");
+ return;
+ }
+
+ TQFontEngine *f = item->font;
+
+ glyph_metrics_t baseInfo = f->boundingBox(item->glyphs[gfrom]);
+
+ if (item->script == TQFont::Hebrew)
+ // we need to attach below the baseline, because of the hebrew iud.
+ baseInfo.height = TQMAX(baseInfo.height, -baseInfo.y);
+
+ TQRect baseRect(baseInfo.x, baseInfo.y, baseInfo.width, baseInfo.height);
+
+// qDebug("---> positionCluster: cluster from %d to %d", gfrom, glast);
+// qDebug("baseInfo: %f/%f (%f/%f) off=%f/%f", baseInfo.x, baseInfo.y, baseInfo.width, baseInfo.height, baseInfo.xoff, baseInfo.yoff);
+
+ int size = (f->ascent()/10);
+ int offsetBase = (size - 4) / 4 + TQMIN(size, 4) + 1;
+// qDebug("offset = %f", offsetBase);
+
+ bool rightToLeft = item->flags & TQTextEngine::RightToLeft;
+
+ int i;
+ unsigned char lastCmb = 0;
+ TQRect attachmentRect;
+
+ for(i = 1; i <= nmarks; i++) {
+ glyph_t mark = item->glyphs[gfrom+i];
+ TQPoint p;
+ glyph_metrics_t markInfo = f->boundingBox(mark);
+ TQRect markRect(markInfo.x, markInfo.y, markInfo.width, markInfo.height);
+// qDebug("markInfo: %f/%f (%f/%f) off=%f/%f", markInfo.x, markInfo.y, markInfo.width, markInfo.height, markInfo.xoff, markInfo.yoff);
+
+ int offset = offsetBase;
+ unsigned char cmb = item->attributes[gfrom+i].combiningClass;
+
+ // ### maybe the whole position determination should move down to heuristicSetGlyphAttributes. Would save some
+ // bits in the glyphAttributes structure.
+ if (cmb < 200) {
+ // fixed position classes. We approximate by mapping to one of the others.
+ // currently I added only the ones for arabic, hebrew, lao and thai.
+
+ // for Lao and Thai marks with class 0, see below (heuristicSetGlyphAttributes)
+
+ // add a bit more offset to arabic, a bit hacky
+ if (cmb >= 27 && cmb <= 36 && offset < 3)
+ offset +=1;
+ // below
+ if ((cmb >= 10 && cmb <= 18) ||
+ cmb == 20 || cmb == 22 ||
+ cmb == 29 || cmb == 32)
+ cmb = TQChar::Combining_Below;
+ // above
+ else if (cmb == 23 || cmb == 27 || cmb == 28 ||
+ cmb == 30 || cmb == 31 || (cmb >= 33 && cmb <= 36))
+ cmb = TQChar::Combining_Above;
+ //below-right
+ else if (cmb == 9 || cmb == 103 || cmb == 118)
+ cmb = TQChar::Combining_BelowRight;
+ // above-right
+ else if (cmb == 24 || cmb == 107 || cmb == 122)
+ cmb = TQChar::Combining_AboveRight;
+ else if (cmb == 25)
+ cmb = TQChar::Combining_AboveLeft;
+ // fixed:
+ // 19 21
+
+ }
+
+ // combining marks of different class don't interact. Reset the rectangle.
+ if (cmb != lastCmb) {
+ //qDebug("resetting rect");
+ attachmentRect = baseRect;
+ }
+
+ switch(cmb) {
+ case TQChar::Combining_DoubleBelow:
+ // ### wrong in rtl context!
+ case TQChar::Combining_BelowLeft:
+ p += TQPoint(0, offset);
+ case TQChar::Combining_BelowLeftAttached:
+ p += attachmentRect.bottomLeft() - markRect.topLeft();
+ break;
+ case TQChar::Combining_Below:
+ p += TQPoint(0, offset);
+ case TQChar::Combining_BelowAttached:
+ p += attachmentRect.bottomLeft() - markRect.topLeft();
+ p += TQPoint((attachmentRect.width() - markRect.width())/2 , 0);
+ break;
+ case TQChar::Combining_BelowRight:
+ p += TQPoint(0, offset);
+ case TQChar::Combining_BelowRightAttached:
+ p += attachmentRect.bottomRight() - markRect.topRight();
+ break;
+ case TQChar::Combining_Left:
+ p += TQPoint(-offset, 0);
+ case TQChar::Combining_LeftAttached:
+ break;
+ case TQChar::Combining_Right:
+ p += TQPoint(offset, 0);
+ case TQChar::Combining_RightAttached:
+ break;
+ case TQChar::Combining_DoubleAbove:
+ // ### wrong in RTL context!
+ case TQChar::Combining_AboveLeft:
+ p += TQPoint(0, -offset);
+ case TQChar::Combining_AboveLeftAttached:
+ p += attachmentRect.topLeft() - markRect.bottomLeft();
+ break;
+ case TQChar::Combining_Above:
+ p += TQPoint(0, -offset);
+ case TQChar::Combining_AboveAttached:
+ p += attachmentRect.topLeft() - markRect.bottomLeft();
+ p += TQPoint((attachmentRect.width() - markRect.width())/2 , 0);
+ break;
+ case TQChar::Combining_AboveRight:
+ p += TQPoint(0, -offset);
+ case TQChar::Combining_AboveRightAttached:
+ p += attachmentRect.topRight() - markRect.bottomRight();
+ break;
+
+ case TQChar::Combining_IotaSubscript:
+ default:
+ break;
+ }
+// qDebug("char=%x combiningClass = %d offset=%d/%d", mark, cmb, p.x(), p.y());
+ markRect.moveBy(p.x(), p.y());
+ attachmentRect |= markRect;
+ lastCmb = cmb;
+ if (rightToLeft) {
+ item->offsets[gfrom+i].x = p.x();
+ item->offsets[gfrom+i].y = p.y();
+ } else {
+ item->offsets[gfrom+i].x = p.x() - baseInfo.xoff;
+ item->offsets[gfrom+i].y = p.y() - baseInfo.yoff;
+ }
+ item->advances[gfrom+i] = 0;
+ }
+ item->has_positioning = TRUE;
+}
+
+
+void qt_heuristicPosition(TQShaperItem *item)
+{
+ int cEnd = -1;
+ int i = item->num_glyphs;
+ while (i--) {
+ if (cEnd == -1 && item->attributes[i].mark) {
+ cEnd = i;
+ } else if (cEnd != -1 && !item->attributes[i].mark) {
+ positionCluster(item, i, cEnd);
+ cEnd = -1;
+ }
+ }
+}
+
+
+
+// set the glyph attributes heuristically. Assumes a 1 to 1 relationship between chars and glyphs
+// and no reordering.
+// also computes logClusters heuristically
+static void heuristicSetGlyphAttributes(TQShaperItem *item, const TQChar *uc, int length)
+{
+ // justification is missing here!!!!!
+
+ if ( item->num_glyphs != length )
+ qWarning("TQScriptEngine::heuristicSetGlyphAttributes: char length and num glyphs disagree" );
+
+ unsigned short *logClusters = item->log_clusters;
+
+ int i;
+ for (i = 0; i < length; ++i)
+ logClusters[i] = i;
+
+ // first char in a run is never (treated as) a mark
+ int cStart = 0;
+ item->attributes[0].mark = FALSE;
+ item->attributes[0].clusterStart = TRUE;
+ item->attributes[0].combiningClass = 0;
+ if (qIsZeroWidthChar(uc[0].tqunicode())) {
+ item->attributes[0].zeroWidth = TRUE;
+ item->advances[0] = 0;
+ item->has_positioning = TRUE;
+ } else {
+ item->attributes[0].zeroWidth = FALSE;
+ }
+
+ int lastCat = ::category(uc[0]);
+ for (i = 1; i < length; ++i) {
+ int cat = ::category(uc[i]);
+ if (qIsZeroWidthChar(uc[i].tqunicode())) {
+ item->attributes[i].mark = FALSE;
+ item->attributes[i].clusterStart = TRUE;
+ item->attributes[i].zeroWidth = TRUE;
+ item->attributes[i].combiningClass = 0;
+ cStart = i;
+ item->advances[i] = 0;
+ item->has_positioning = TRUE;
+ } else if (cat != TQChar::Mark_NonSpacing) {
+ item->attributes[i].mark = FALSE;
+ item->attributes[i].clusterStart = TRUE;
+ item->attributes[i].combiningClass = 0;
+ cStart = i;
+ } else {
+ int cmb = ::combiningClass(uc[i]);
+
+ if (cmb == 0) {
+ // Fix 0 combining classes
+ if ((uc[i].tqunicode() & 0xff00) == 0x0e00) {
+ // thai or lao
+ unsigned char col = uc[i].cell();
+ if (col == 0x31 ||
+ col == 0x34 ||
+ col == 0x35 ||
+ col == 0x36 ||
+ col == 0x37 ||
+ col == 0x47 ||
+ col == 0x4c ||
+ col == 0x4d ||
+ col == 0x4e) {
+ cmb = TQChar::Combining_AboveRight;
+ } else if (col == 0xb1 ||
+ col == 0xb4 ||
+ col == 0xb5 ||
+ col == 0xb6 ||
+ col == 0xb7 ||
+ col == 0xbb ||
+ col == 0xcc ||
+ col == 0xcd) {
+ cmb = TQChar::Combining_Above;
+ } else if (col == 0xbc) {
+ cmb = TQChar::Combining_Below;
+ }
+ }
+ }
+
+ item->attributes[i].mark = TRUE;
+ item->attributes[i].clusterStart = FALSE;
+ item->attributes[i].combiningClass = cmb;
+ logClusters[i] = cStart;
+ item->advances[i] = 0;
+ item->has_positioning = TRUE;
+ }
+
+ if (lastCat == TQChar::Separator_Space)
+ item->attributes[i-1].justification = GlyphAttributes::Space;
+ else if (cat != TQChar::Mark_NonSpacing)
+ item->attributes[i-1].justification = GlyphAttributes::Character;
+ else
+ item->attributes[i-1].justification = GlyphAttributes::NoJustification;
+
+ lastCat = cat;
+ }
+}
+
+static void heuristicSetGlyphAttributes(TQShaperItem *item)
+{
+ heuristicSetGlyphAttributes(item, item->string->tqunicode() + item->from, item->length);
+}
+
+
+static bool basic_tqshape(TQShaperItem *item)
+{
+ if (item->font->stringToCMap(item->string->tqunicode()+item->from, item->length, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+
+ heuristicSetGlyphAttributes(item);
+ qt_heuristicPosition(item);
+ return TRUE;
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Middle eastern languages
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+// Uniscribe also defines dlig for Hebrew, but we leave this out for now, as it's mostly
+// ligatures one does not want in modern Hebrew (as lam-alef ligatures).
+enum {
+ CcmpProperty = 0x1
+};
+#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+static const TQOpenType::Features hebrew_features[] = {
+ { FT_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty },
+ {0, 0}
+};
+#endif
+/* Hebrew shaping. In the non opentype case we try to use the
+ presentation forms specified for Hebrew. Especially for the
+ ligatures with Dagesh this gives much better results than we could
+ achieve manually.
+*/
+static bool hebrew_tqshape(TQShaperItem *item)
+{
+ TQ_ASSERT(item->script == TQFont::Hebrew);
+
+#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+ TQOpenType *openType = item->font->openType();
+
+ if (openType && openType->supportsScript(item->script)) {
+ openType->selectScript(item->script, hebrew_features);
+
+ if (item->font->stringToCMap(item->string->tqunicode()+item->from, item->length, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+
+ heuristicSetGlyphAttributes(item);
+ openType->tqshape(item);
+ return openType->positionAndAdd(item);
+ }
+#endif
+
+ enum {
+ Dagesh = 0x5bc,
+ ShinDot = 0x5c1,
+ SinDot = 0x5c2,
+ Patah = 0x5b7,
+ Qamats = 0x5b8,
+ Holam = 0x5b9,
+ Rafe = 0x5bf
+ };
+ unsigned short chars[512];
+ TQChar *tqshapedChars = item->length > 256 ? (TQChar *)::malloc(2*item->length * sizeof(TQChar)) : (TQChar *)chars;
+
+ const TQChar *uc = item->string->tqunicode() + item->from;
+ unsigned short *logClusters = item->log_clusters;
+
+ *tqshapedChars = *uc;
+ logClusters[0] = 0;
+ int slen = 1;
+ int cluster_start = 0;
+ int i;
+ for (i = 1; i < item->length; ++i) {
+ ushort base = tqshapedChars[slen-1].tqunicode();
+ ushort tqshaped = 0;
+ bool invalid = FALSE;
+ if (uc[i].tqunicode() == Dagesh) {
+ if (base >= 0x5d0
+ && base <= 0x5ea
+ && base != 0x5d7
+ && base != 0x5dd
+ && base != 0x5df
+ && base != 0x5e2
+ && base != 0x5e5) {
+ tqshaped = base - 0x5d0 + 0xfb30;
+ } else if (base == 0xfb2a || base == 0xfb2b /* Shin with Shin or Sin dot */) {
+ tqshaped = base + 2;
+ } else {
+ invalid = TRUE;
+ }
+ } else if (uc[i].tqunicode() == ShinDot) {
+ if (base == 0x05e9)
+ tqshaped = 0xfb2a;
+ else if (base == 0xfb49)
+ tqshaped = 0xfb2c;
+ else
+ invalid = TRUE;
+ } else if (uc[i].tqunicode() == SinDot) {
+ if (base == 0x05e9)
+ tqshaped = 0xfb2b;
+ else if (base == 0xfb49)
+ tqshaped = 0xfb2d;
+ else
+ invalid = TRUE;
+ } else if (uc[i].tqunicode() == Patah) {
+ if (base == 0x5d0)
+ tqshaped = 0xfb2e;
+ } else if (uc[i].tqunicode() == Qamats) {
+ if (base == 0x5d0)
+ tqshaped = 0xfb2f;
+ } else if (uc[i].tqunicode() == Holam) {
+ if (base == 0x5d5)
+ tqshaped = 0xfb4b;
+ } else if (uc[i].tqunicode() == Rafe) {
+ if (base == 0x5d1)
+ tqshaped = 0xfb4c;
+ else if (base == 0x5db)
+ tqshaped = 0xfb4d;
+ else if (base == 0x5e4)
+ tqshaped = 0xfb4e;
+ }
+
+ if (invalid) {
+ tqshapedChars[slen] = 0x25cc;
+ item->attributes[slen].clusterStart = TRUE;
+ item->attributes[slen].mark = FALSE;
+ item->attributes[slen].combiningClass = 0;
+ cluster_start = slen;
+ ++slen;
+ }
+ if (tqshaped) {
+ if (item->font->canRender((TQChar *)&tqshaped, 1)) {
+ tqshapedChars[slen-1] = TQChar(tqshaped);
+ } else
+ tqshaped = 0;
+ }
+ if (!tqshaped) {
+ tqshapedChars[slen] = uc[i];
+ if (::category(uc[i]) != TQChar::Mark_NonSpacing) {
+ item->attributes[slen].clusterStart = TRUE;
+ item->attributes[slen].mark = FALSE;
+ item->attributes[slen].combiningClass = 0;
+ cluster_start = slen;
+ } else {
+ item->attributes[slen].clusterStart = FALSE;
+ item->attributes[slen].mark = TRUE;
+ item->attributes[slen].combiningClass = ::combiningClass(uc[i]);
+ }
+ ++slen;
+ }
+ logClusters[i] = cluster_start;
+ }
+
+ if (item->font->stringToCMap(tqshapedChars, slen, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+ for (i = 0; i < item->num_glyphs; ++i) {
+ if (item->attributes[i].mark)
+ item->advances[i] = 0;
+ }
+ qt_heuristicPosition(item);
+
+ if (item->length > 256)
+ ::free(tqshapedChars);
+ return TRUE;
+}
+
+// these groups correspond to the groups defined in the Unicode standard.
+// Some of these groups are equal whith regards to both joining and line breaking behaviour,
+// and thus have the same enum value
+//
+// I'm not sure the mapping of syriac to arabic enums is correct with regards to justification, but as
+// I couldn't tqfind any better document I'll hope for the best.
+enum ArabicGroup {
+ // NonJoining
+ ArabicNone,
+ ArabicSpace,
+ // Transtqparent
+ Transtqparent,
+ // Causing
+ Center,
+ Kashida,
+
+ // Arabic
+ // Dual
+ Beh,
+ Noon,
+ Meem = Noon,
+ Heh = Noon,
+ KnottedHeh = Noon,
+ HehGoal = Noon,
+ SwashKaf = Noon,
+ Yeh,
+ Hah,
+ Seen,
+ Sad = Seen,
+ Tah,
+ Kaf = Tah,
+ Gaf = Tah,
+ Lam = Tah,
+ Ain,
+ Feh = Ain,
+ Qaf = Ain,
+ // Right
+ Alef,
+ Waw,
+ Dal,
+ TehMarbuta = Dal,
+ Reh,
+ HamzaOnHehGoal,
+ YehWithTail = HamzaOnHehGoal,
+ YehBarre = HamzaOnHehGoal,
+
+ // Syriac
+ // Dual
+ Beth = Beh,
+ Gamal = Ain,
+ Heth = Noon,
+ Teth = Hah,
+ Yudh = Noon,
+ Kaph = Noon,
+ Lamadh = Lam,
+ Mim = Noon,
+ Nun = Noon,
+ Semakh = Noon,
+ FinalSemakh = Noon,
+ SyriacE = Ain,
+ Pe = Ain,
+ ReversedPe = Hah,
+ Qaph = Noon,
+ Shin = Noon,
+ Fe = Ain,
+
+ // Right
+ Alaph = Alef,
+ Dalath = Dal,
+ He = Dal,
+ SyriacWaw = Waw,
+ Zain = Alef,
+ YudhHe = Waw,
+ Sadhe = HamzaOnHehGoal,
+ Taw = Dal,
+
+ // Compiler bug? Otherwise ArabicGroupsEnd would be equal to Dal + 1.
+ Dummy = HamzaOnHehGoal,
+ ArabicGroupsEnd
+};
+
+static const unsigned char arabic_group[0x150] = {
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+
+ ArabicNone, ArabicNone, Alef, Alef,
+ Waw, Alef, Yeh, Alef,
+ Beh, TehMarbuta, Beh, Beh,
+ Hah, Hah, Hah, Dal,
+
+ Dal, Reh, Reh, Seen,
+ Seen, Sad, Sad, Tah,
+ Tah, Ain, Ain, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+
+ // 0x640
+ Kashida, Feh, Qaf, Kaf,
+ Lam, Meem, Noon, Heh,
+ Waw, Yeh, Yeh, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, Beh, Qaf,
+
+ Transtqparent, Alef, Alef, Alef,
+ ArabicNone, Alef, Waw, Waw,
+ Yeh, Beh, Beh, Beh,
+ Beh, Beh, Beh, Beh,
+
+ // 0x680
+ Beh, Hah, Hah, Hah,
+ Hah, Hah, Hah, Hah,
+ Dal, Dal, Dal, Dal,
+ Dal, Dal, Dal, Dal,
+
+ Dal, Reh, Reh, Reh,
+ Reh, Reh, Reh, Reh,
+ Reh, Reh, Seen, Seen,
+ Seen, Sad, Sad, Tah,
+
+ Ain, Feh, Feh, Feh,
+ Feh, Feh, Feh, Qaf,
+ Qaf, Gaf, SwashKaf, Gaf,
+ Kaf, Kaf, Kaf, Gaf,
+
+ Gaf, Gaf, Gaf, Gaf,
+ Gaf, Lam, Lam, Lam,
+ Lam, Noon, Noon, Noon,
+ Noon, Noon, KnottedHeh, Hah,
+
+ // 0x6c0
+ TehMarbuta, HehGoal, HamzaOnHehGoal, HamzaOnHehGoal,
+ Waw, Waw, Waw, Waw,
+ Waw, Waw, Waw, Waw,
+ Yeh, YehWithTail, Yeh, Waw,
+
+ Yeh, Yeh, YehBarre, YehBarre,
+ ArabicNone, TehMarbuta, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, ArabicNone, ArabicNone, Transtqparent,
+
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, ArabicNone, ArabicNone, Transtqparent,
+ Transtqparent, ArabicNone, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Dal, Reh,
+
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, Seen, Sad,
+ Ain, ArabicNone, ArabicNone, KnottedHeh,
+
+ // 0x700
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+ ArabicNone, ArabicNone, ArabicNone, ArabicNone,
+
+ Alaph, Transtqparent, Beth, Gamal,
+ Gamal, Dalath, Dalath, He,
+ SyriacWaw, Zain, Heth, Teth,
+ Teth, Yudh, YudhHe, Kaph,
+
+ Lamadh, Mim, Nun, Semakh,
+ FinalSemakh, SyriacE, Pe, ReversedPe,
+ Sadhe, Qaph, Dalath, Shin,
+ Taw, Beth, Gamal, Dalath,
+
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, Transtqparent,
+ Transtqparent, Transtqparent, Transtqparent, ArabicNone,
+ ArabicNone, Zain, Kaph, Fe,
+};
+
+static inline ArabicGroup arabicGroup(unsigned short uc)
+{
+ if (uc >= 0x0600 && uc < 0x750)
+ return (ArabicGroup) arabic_group[uc-0x600];
+ else if (uc == 0x200d)
+ return Center;
+ else if (::category(uc) == TQChar::Separator_Space)
+ return ArabicSpace;
+ else
+ return ArabicNone;
+}
+
+
+/*
+ Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on
+ arabic).
+
+ Each tqunicode char has a joining class (right, dual (left&right), center (joincausing) or transtqparent).
+ transtqparent joining is not encoded in TQChar::joining(), but applies to all combining marks and format marks.
+
+ Right join-causing: dual + center
+ Left join-causing: dual + right + center
+
+ Rules are as follows (for a string already in visual order, as we have it here):
+
+ R1 Transtqparent characters do not affect joining behaviour.
+ R2 A right joining character, that has a right join-causing char on the right will get form XRight
+ (R3 A left joining character, that has a left join-causing char on the left will get form XLeft)
+ Note: the above rule is meaningless, as there are no pure left joining characters defined in Unicode
+ R4 A dual joining character, that has a left join-causing char on the left and a right join-causing char on
+ the right will get form XMedial
+ R5 A dual joining character, that has a right join causing char on the right, and no left join causing char on the left
+ will get form XRight
+ R6 A dual joining character, that has a left join causing char on the left, and no right join causing char on the right
+ will get form XLeft
+ R7 Otherwise the character will get form XIsolated
+
+ Additionally we have to do the minimal ligature support for lam-alef ligatures:
+
+ L1 Transtqparent characters do not affect ligature behaviour.
+ L2 Any sequence of Alef(XRight) + Lam(XMedial) will form the ligature Alef.Lam(XLeft)
+ L3 Any sequence of Alef(XRight) + Lam(XLeft) will form the ligature Alef.Lam(XIsolated)
+
+ The state table below handles rules R1-R7.
+*/
+
+enum Shape {
+ XIsolated,
+ XFinal,
+ XInitial,
+ XMedial,
+ // intermediate state
+ XCausing
+};
+
+
+enum Joining {
+ JNone,
+ JCausing,
+ JDual,
+ JRight,
+ JTranstqparent
+};
+
+
+static const Joining joining_for_group[ArabicGroupsEnd] = {
+ // NonJoining
+ JNone, // ArabicNone
+ JNone, // ArabicSpace
+ // Transtqparent
+ JTranstqparent, // Transtqparent
+ // Causing
+ JCausing, // Center
+ JCausing, // Kashida
+ // Dual
+ JDual, // Beh
+ JDual, // Noon
+ JDual, // Yeh
+ JDual, // Hah
+ JDual, // Seen
+ JDual, // Tah
+ JDual, // Ain
+ // Right
+ JRight, // Alef
+ JRight, // Waw
+ JRight, // Dal
+ JRight, // Reh
+ JRight // HamzaOnHehGoal
+};
+
+
+struct JoiningPair {
+ Shape form1;
+ Shape form2;
+};
+
+static const JoiningPair joining_table[5][4] =
+// None, Causing, Dual, Right
+{
+ { { XIsolated, XIsolated }, { XIsolated, XCausing }, { XIsolated, XInitial }, { XIsolated, XIsolated } }, // XIsolated
+ { { XFinal, XIsolated }, { XFinal, XCausing }, { XFinal, XInitial }, { XFinal, XIsolated } }, // XFinal
+ { { XIsolated, XIsolated }, { XInitial, XCausing }, { XInitial, XMedial }, { XInitial, XFinal } }, // XInitial
+ { { XFinal, XIsolated }, { XMedial, XCausing }, { XMedial, XMedial }, { XMedial, XFinal } }, // XMedial
+ { { XIsolated, XIsolated }, { XIsolated, XCausing }, { XIsolated, XMedial }, { XIsolated, XFinal } }, // XCausing
+};
+
+
+/*
+According to http://www.microsoft.com/middleeast/Arabicdev/IE6/KBase.asp
+
+1. Find the priority of the connecting opportunities in each word
+2. Add expansion at the highest priority connection opportunity
+3. If more than one connection opportunity have the same highest value,
+ use the opportunity closest to the end of the word.
+
+Following is a chart that provides the priority for connection
+opportunities and where expansion occurs. The character group names
+are those in table 6.6 of the UNICODE 2.0 book.
+
+
+PrioritY Glyph Condition Kashida Location
+
+Arabic_Kashida User inserted Kashida The user entered a Kashida in a position. After the user
+ (Shift+j or Shift+[E with hat]) Thus, it is the highest priority to insert an inserted kashida
+ automatic kashida.
+
+Arabic_Seen Seen, Sad Connecting to the next character. After the character.
+ (Initial or medial form).
+
+Arabic_HaaDal Teh Marbutah, Haa, Dal Connecting to previous character. Before the final form
+ of these characters.
+
+Arabic_Alef Alef, Tah, Lam, Connecting to previous character. Before the final form
+ Kaf and Gaf of these characters.
+
+Arabic_BaRa Reh, Yeh Connected to medial Beh Before preceding medial Baa
+
+Arabic_Waw Waw, Ain, Qaf, Feh Connecting to previous character. Before the final form of
+ these characters.
+
+Arabic_Normal Other connecting Connecting to previous character. Before the final form
+ characters of these characters.
+
+
+
+This seems to imply that we have at most one kashida point per arabic word.
+
+*/
+
+struct TQArabicProperties {
+ unsigned char tqshape;
+ unsigned char justification;
+};
+
+
+static void getArabicProperties(const unsigned short *chars, int len, TQArabicProperties *properties)
+{
+// qDebug("arabicSyriacOpenTypeShape: properties:");
+ int lastPos = 0;
+ int lastGroup = ArabicNone;
+
+ ArabicGroup group = arabicGroup(chars[0]);
+ Joining j = joining_for_group[group];
+ Shape tqshape = joining_table[XIsolated][j].form2;
+ properties[0].justification = GlyphAttributes::NoJustification;
+
+ for (int i = 1; i < len; ++i) {
+ // #### fix handling for spaces and punktuation
+ properties[i].justification = GlyphAttributes::NoJustification;
+
+ group = arabicGroup(chars[i]);
+ j = joining_for_group[group];
+
+ if (j == JTranstqparent) {
+ properties[i].tqshape = XIsolated;
+ continue;
+ }
+
+ properties[lastPos].tqshape = joining_table[tqshape][j].form1;
+ tqshape = joining_table[tqshape][j].form2;
+
+ switch(lastGroup) {
+ case Seen:
+ if (properties[lastPos].tqshape == XInitial || properties[lastPos].tqshape == XMedial)
+ properties[i-1].justification = GlyphAttributes::Arabic_Seen;
+ break;
+ case Hah:
+ if (properties[lastPos].tqshape == XFinal)
+ properties[lastPos-1].justification = GlyphAttributes::Arabic_HaaDal;
+ break;
+ case Alef:
+ if (properties[lastPos].tqshape == XFinal)
+ properties[lastPos-1].justification = GlyphAttributes::Arabic_Alef;
+ break;
+ case Ain:
+ if (properties[lastPos].tqshape == XFinal)
+ properties[lastPos-1].justification = GlyphAttributes::Arabic_Waw;
+ break;
+ case Noon:
+ if (properties[lastPos].tqshape == XFinal)
+ properties[lastPos-1].justification = GlyphAttributes::Arabic_Normal;
+ break;
+ case ArabicNone:
+ break;
+
+ default:
+ TQ_ASSERT(FALSE);
+ }
+
+ lastGroup = ArabicNone;
+
+ switch(group) {
+ case ArabicNone:
+ case Transtqparent:
+ // ### Center should probably be treated as transtqparent when it comes to justification.
+ case Center:
+ break;
+ case ArabicSpace:
+ properties[i].justification = GlyphAttributes::Arabic_Space;
+ break;
+ case Kashida:
+ properties[i].justification = GlyphAttributes::Arabic_Kashida;
+ break;
+ case Seen:
+ lastGroup = Seen;
+ break;
+
+ case Hah:
+ case Dal:
+ lastGroup = Hah;
+ break;
+
+ case Alef:
+ case Tah:
+ lastGroup = Alef;
+ break;
+
+ case Yeh:
+ case Reh:
+ if (properties[lastPos].tqshape == XMedial && arabicGroup(chars[lastPos]) == Beh)
+ properties[lastPos-1].justification = GlyphAttributes::Arabic_BaRa;
+ break;
+
+ case Ain:
+ case Waw:
+ lastGroup = Ain;
+ break;
+
+ case Noon:
+ case Beh:
+ case HamzaOnHehGoal:
+ lastGroup = Noon;
+ break;
+ case ArabicGroupsEnd:
+ TQ_ASSERT(FALSE);
+ }
+
+ lastPos = i;
+ }
+ properties[lastPos].tqshape = joining_table[tqshape][JNone].form1;
+
+
+// for (int i = 0; i < len; ++i)
+// qDebug("arabic properties(%d): uc=%x tqshape=%d, justification=%d", i, chars[i], properties[i].tqshape, properties[i].justification);
+}
+
+
+
+
+
+
+// The tqunicode to tqunicode shaping codec.
+// does only presentation forms B at the moment, but that should be enough for
+// simple display
+static const ushort arabicUnicodeMapping[256][2] = {
+ // base of tqshaped forms, and number-1 of them (0 for non shaping,
+ // 1 for right binding and 3 for dual binding
+
+ // These are just the glyphs available in Unicode,
+ // some characters are in R class, but have no glyphs in Unicode.
+
+ { 0x0600, 0 }, // 0x0600
+ { 0x0601, 0 }, // 0x0601
+ { 0x0602, 0 }, // 0x0602
+ { 0x0603, 0 }, // 0x0603
+ { 0x0604, 0 }, // 0x0604
+ { 0x0605, 0 }, // 0x0605
+ { 0x0606, 0 }, // 0x0606
+ { 0x0607, 0 }, // 0x0607
+ { 0x0608, 0 }, // 0x0608
+ { 0x0609, 0 }, // 0x0609
+ { 0x060A, 0 }, // 0x060A
+ { 0x060B, 0 }, // 0x060B
+ { 0x060C, 0 }, // 0x060C
+ { 0x060D, 0 }, // 0x060D
+ { 0x060E, 0 }, // 0x060E
+ { 0x060F, 0 }, // 0x060F
+
+ { 0x0610, 0 }, // 0x0610
+ { 0x0611, 0 }, // 0x0611
+ { 0x0612, 0 }, // 0x0612
+ { 0x0613, 0 }, // 0x0613
+ { 0x0614, 0 }, // 0x0614
+ { 0x0615, 0 }, // 0x0615
+ { 0x0616, 0 }, // 0x0616
+ { 0x0617, 0 }, // 0x0617
+ { 0x0618, 0 }, // 0x0618
+ { 0x0619, 0 }, // 0x0619
+ { 0x061A, 0 }, // 0x061A
+ { 0x061B, 0 }, // 0x061B
+ { 0x061C, 0 }, // 0x061C
+ { 0x061D, 0 }, // 0x061D
+ { 0x061E, 0 }, // 0x061E
+ { 0x061F, 0 }, // 0x061F
+
+ { 0x0620, 0 }, // 0x0620
+ { 0xFE80, 0 }, // 0x0621 HAMZA
+ { 0xFE81, 1 }, // 0x0622 R ALEF WITH MADDA ABOVE
+ { 0xFE83, 1 }, // 0x0623 R ALEF WITH HAMZA ABOVE
+ { 0xFE85, 1 }, // 0x0624 R WAW WITH HAMZA ABOVE
+ { 0xFE87, 1 }, // 0x0625 R ALEF WITH HAMZA BELOW
+ { 0xFE89, 3 }, // 0x0626 D YEH WITH HAMZA ABOVE
+ { 0xFE8D, 1 }, // 0x0627 R ALEF
+ { 0xFE8F, 3 }, // 0x0628 D BEH
+ { 0xFE93, 1 }, // 0x0629 R TEH MARBUTA
+ { 0xFE95, 3 }, // 0x062A D TEH
+ { 0xFE99, 3 }, // 0x062B D THEH
+ { 0xFE9D, 3 }, // 0x062C D JEEM
+ { 0xFEA1, 3 }, // 0x062D D HAH
+ { 0xFEA5, 3 }, // 0x062E D KHAH
+ { 0xFEA9, 1 }, // 0x062F R DAL
+
+ { 0xFEAB, 1 }, // 0x0630 R THAL
+ { 0xFEAD, 1 }, // 0x0631 R REH
+ { 0xFEAF, 1 }, // 0x0632 R ZAIN
+ { 0xFEB1, 3 }, // 0x0633 D SEEN
+ { 0xFEB5, 3 }, // 0x0634 D SHEEN
+ { 0xFEB9, 3 }, // 0x0635 D SAD
+ { 0xFEBD, 3 }, // 0x0636 D DAD
+ { 0xFEC1, 3 }, // 0x0637 D TAH
+ { 0xFEC5, 3 }, // 0x0638 D ZAH
+ { 0xFEC9, 3 }, // 0x0639 D AIN
+ { 0xFECD, 3 }, // 0x063A D GHAIN
+ { 0x063B, 0 }, // 0x063B
+ { 0x063C, 0 }, // 0x063C
+ { 0x063D, 0 }, // 0x063D
+ { 0x063E, 0 }, // 0x063E
+ { 0x063F, 0 }, // 0x063F
+
+ { 0x0640, 0 }, // 0x0640 C TATWEEL // ### Join Causing, only one glyph
+ { 0xFED1, 3 }, // 0x0641 D FEH
+ { 0xFED5, 3 }, // 0x0642 D TQAF
+ { 0xFED9, 3 }, // 0x0643 D KAF
+ { 0xFEDD, 3 }, // 0x0644 D LAM
+ { 0xFEE1, 3 }, // 0x0645 D MEEM
+ { 0xFEE5, 3 }, // 0x0646 D NOON
+ { 0xFEE9, 3 }, // 0x0647 D HEH
+ { 0xFEED, 1 }, // 0x0648 R WAW
+ { 0x0649, 3 }, // 0x0649 ALEF MAKSURA // ### Dual, glyphs not consecutive, handle in code.
+ { 0xFEF1, 3 }, // 0x064A D YEH
+ { 0x064B, 0 }, // 0x064B
+ { 0x064C, 0 }, // 0x064C
+ { 0x064D, 0 }, // 0x064D
+ { 0x064E, 0 }, // 0x064E
+ { 0x064F, 0 }, // 0x064F
+
+ { 0x0650, 0 }, // 0x0650
+ { 0x0651, 0 }, // 0x0651
+ { 0x0652, 0 }, // 0x0652
+ { 0x0653, 0 }, // 0x0653
+ { 0x0654, 0 }, // 0x0654
+ { 0x0655, 0 }, // 0x0655
+ { 0x0656, 0 }, // 0x0656
+ { 0x0657, 0 }, // 0x0657
+ { 0x0658, 0 }, // 0x0658
+ { 0x0659, 0 }, // 0x0659
+ { 0x065A, 0 }, // 0x065A
+ { 0x065B, 0 }, // 0x065B
+ { 0x065C, 0 }, // 0x065C
+ { 0x065D, 0 }, // 0x065D
+ { 0x065E, 0 }, // 0x065E
+ { 0x065F, 0 }, // 0x065F
+
+ { 0x0660, 0 }, // 0x0660
+ { 0x0661, 0 }, // 0x0661
+ { 0x0662, 0 }, // 0x0662
+ { 0x0663, 0 }, // 0x0663
+ { 0x0664, 0 }, // 0x0664
+ { 0x0665, 0 }, // 0x0665
+ { 0x0666, 0 }, // 0x0666
+ { 0x0667, 0 }, // 0x0667
+ { 0x0668, 0 }, // 0x0668
+ { 0x0669, 0 }, // 0x0669
+ { 0x066A, 0 }, // 0x066A
+ { 0x066B, 0 }, // 0x066B
+ { 0x066C, 0 }, // 0x066C
+ { 0x066D, 0 }, // 0x066D
+ { 0x066E, 0 }, // 0x066E
+ { 0x066F, 0 }, // 0x066F
+
+ { 0x0670, 0 }, // 0x0670
+ { 0xFB50, 1 }, // 0x0671 R ALEF WASLA
+ { 0x0672, 0 }, // 0x0672
+ { 0x0673, 0 }, // 0x0673
+ { 0x0674, 0 }, // 0x0674
+ { 0x0675, 0 }, // 0x0675
+ { 0x0676, 0 }, // 0x0676
+ { 0x0677, 0 }, // 0x0677
+ { 0x0678, 0 }, // 0x0678
+ { 0xFB66, 3 }, // 0x0679 D TTEH
+ { 0xFB5E, 3 }, // 0x067A D TTEHEH
+ { 0xFB52, 3 }, // 0x067B D BEEH
+ { 0x067C, 0 }, // 0x067C
+ { 0x067D, 0 }, // 0x067D
+ { 0xFB56, 3 }, // 0x067E D PEH
+ { 0xFB62, 3 }, // 0x067F D TEHEH
+
+ { 0xFB5A, 3 }, // 0x0680 D BEHEH
+ { 0x0681, 0 }, // 0x0681
+ { 0x0682, 0 }, // 0x0682
+ { 0xFB76, 3 }, // 0x0683 D NYEH
+ { 0xFB72, 3 }, // 0x0684 D DYEH
+ { 0x0685, 0 }, // 0x0685
+ { 0xFB7A, 3 }, // 0x0686 D TCHEH
+ { 0xFB7E, 3 }, // 0x0687 D TCHEHEH
+ { 0xFB88, 1 }, // 0x0688 R DDAL
+ { 0x0689, 0 }, // 0x0689
+ { 0x068A, 0 }, // 0x068A
+ { 0x068B, 0 }, // 0x068B
+ { 0xFB84, 1 }, // 0x068C R DAHAL
+ { 0xFB82, 1 }, // 0x068D R DDAHAL
+ { 0xFB86, 1 }, // 0x068E R DUL
+ { 0x068F, 0 }, // 0x068F
+
+ { 0x0690, 0 }, // 0x0690
+ { 0xFB8C, 1 }, // 0x0691 R RREH
+ { 0x0692, 0 }, // 0x0692
+ { 0x0693, 0 }, // 0x0693
+ { 0x0694, 0 }, // 0x0694
+ { 0x0695, 0 }, // 0x0695
+ { 0x0696, 0 }, // 0x0696
+ { 0x0697, 0 }, // 0x0697
+ { 0xFB8A, 1 }, // 0x0698 R JEH
+ { 0x0699, 0 }, // 0x0699
+ { 0x069A, 0 }, // 0x069A
+ { 0x069B, 0 }, // 0x069B
+ { 0x069C, 0 }, // 0x069C
+ { 0x069D, 0 }, // 0x069D
+ { 0x069E, 0 }, // 0x069E
+ { 0x069F, 0 }, // 0x069F
+
+ { 0x06A0, 0 }, // 0x06A0
+ { 0x06A1, 0 }, // 0x06A1
+ { 0x06A2, 0 }, // 0x06A2
+ { 0x06A3, 0 }, // 0x06A3
+ { 0xFB6A, 3 }, // 0x06A4 D VEH
+ { 0x06A5, 0 }, // 0x06A5
+ { 0xFB6E, 3 }, // 0x06A6 D PEHEH
+ { 0x06A7, 0 }, // 0x06A7
+ { 0x06A8, 0 }, // 0x06A8
+ { 0xFB8E, 3 }, // 0x06A9 D KEHEH
+ { 0x06AA, 0 }, // 0x06AA
+ { 0x06AB, 0 }, // 0x06AB
+ { 0x06AC, 0 }, // 0x06AC
+ { 0xFBD3, 3 }, // 0x06AD D NG
+ { 0x06AE, 0 }, // 0x06AE
+ { 0xFB92, 3 }, // 0x06AF D GAF
+
+ { 0x06B0, 0 }, // 0x06B0
+ { 0xFB9A, 3 }, // 0x06B1 D NGOEH
+ { 0x06B2, 0 }, // 0x06B2
+ { 0xFB96, 3 }, // 0x06B3 D GUEH
+ { 0x06B4, 0 }, // 0x06B4
+ { 0x06B5, 0 }, // 0x06B5
+ { 0x06B6, 0 }, // 0x06B6
+ { 0x06B7, 0 }, // 0x06B7
+ { 0x06B8, 0 }, // 0x06B8
+ { 0x06B9, 0 }, // 0x06B9
+ { 0xFB9E, 1 }, // 0x06BA R NOON GHUNNA
+ { 0xFBA0, 3 }, // 0x06BB D RNOON
+ { 0x06BC, 0 }, // 0x06BC
+ { 0x06BD, 0 }, // 0x06BD
+ { 0xFBAA, 3 }, // 0x06BE D HEH DOACHASHMEE
+ { 0x06BF, 0 }, // 0x06BF
+
+ { 0xFBA4, 1 }, // 0x06C0 R HEH WITH YEH ABOVE
+ { 0xFBA6, 3 }, // 0x06C1 D HEH GOAL
+ { 0x06C2, 0 }, // 0x06C2
+ { 0x06C3, 0 }, // 0x06C3
+ { 0x06C4, 0 }, // 0x06C4
+ { 0xFBE0, 1 }, // 0x06C5 R KIRGHIZ OE
+ { 0xFBD9, 1 }, // 0x06C6 R OE
+ { 0xFBD7, 1 }, // 0x06C7 R U
+ { 0xFBDB, 1 }, // 0x06C8 R YU
+ { 0xFBE2, 1 }, // 0x06C9 R KIRGHIZ YU
+ { 0x06CA, 0 }, // 0x06CA
+ { 0xFBDE, 1 }, // 0x06CB R VE
+ { 0xFBFC, 3 }, // 0x06CC D FARSI YEH
+ { 0x06CD, 0 }, // 0x06CD
+ { 0x06CE, 0 }, // 0x06CE
+ { 0x06CF, 0 }, // 0x06CF
+
+ { 0xFBE4, 3 }, // 0x06D0 D E
+ { 0x06D1, 0 }, // 0x06D1
+ { 0xFBAE, 1 }, // 0x06D2 R YEH BARREE
+ { 0xFBB0, 1 }, // 0x06D3 R YEH BARREE WITH HAMZA ABOVE
+ { 0x06D4, 0 }, // 0x06D4
+ { 0x06D5, 0 }, // 0x06D5
+ { 0x06D6, 0 }, // 0x06D6
+ { 0x06D7, 0 }, // 0x06D7
+ { 0x06D8, 0 }, // 0x06D8
+ { 0x06D9, 0 }, // 0x06D9
+ { 0x06DA, 0 }, // 0x06DA
+ { 0x06DB, 0 }, // 0x06DB
+ { 0x06DC, 0 }, // 0x06DC
+ { 0x06DD, 0 }, // 0x06DD
+ { 0x06DE, 0 }, // 0x06DE
+ { 0x06DF, 0 }, // 0x06DF
+
+ { 0x06E0, 0 }, // 0x06E0
+ { 0x06E1, 0 }, // 0x06E1
+ { 0x06E2, 0 }, // 0x06E2
+ { 0x06E3, 0 }, // 0x06E3
+ { 0x06E4, 0 }, // 0x06E4
+ { 0x06E5, 0 }, // 0x06E5
+ { 0x06E6, 0 }, // 0x06E6
+ { 0x06E7, 0 }, // 0x06E7
+ { 0x06E8, 0 }, // 0x06E8
+ { 0x06E9, 0 }, // 0x06E9
+ { 0x06EA, 0 }, // 0x06EA
+ { 0x06EB, 0 }, // 0x06EB
+ { 0x06EC, 0 }, // 0x06EC
+ { 0x06ED, 0 }, // 0x06ED
+ { 0x06EE, 0 }, // 0x06EE
+ { 0x06EF, 0 }, // 0x06EF
+
+ { 0x06F0, 0 }, // 0x06F0
+ { 0x06F1, 0 }, // 0x06F1
+ { 0x06F2, 0 }, // 0x06F2
+ { 0x06F3, 0 }, // 0x06F3
+ { 0x06F4, 0 }, // 0x06F4
+ { 0x06F5, 0 }, // 0x06F5
+ { 0x06F6, 0 }, // 0x06F6
+ { 0x06F7, 0 }, // 0x06F7
+ { 0x06F8, 0 }, // 0x06F8
+ { 0x06F9, 0 }, // 0x06F9
+ { 0x06FA, 0 }, // 0x06FA
+ { 0x06FB, 0 }, // 0x06FB
+ { 0x06FC, 0 }, // 0x06FC
+ { 0x06FD, 0 }, // 0x06FD
+ { 0x06FE, 0 }, // 0x06FE
+ { 0x06FF, 0 } // 0x06FF
+};
+
+// the arabicUnicodeMapping does not work for U+0649 ALEF MAKSURA, this table does
+static const ushort alefMaksura[4] = {0xFEEF, 0xFEF0, 0xFBE8, 0xFBE9};
+
+// this is a bit tricky. Alef always binds to the right, so the second parameter descibing the tqshape
+// of the lam can be either initial of medial. So initial maps to the isolated form of the ligature,
+// medial to the final form
+static const ushort arabicUnicodeLamAlefMapping[6][4] = {
+ { 0xfffd, 0xfffd, 0xfef5, 0xfef6 }, // 0x622 R Alef with Madda above
+ { 0xfffd, 0xfffd, 0xfef7, 0xfef8 }, // 0x623 R Alef with Hamza above
+ { 0xfffd, 0xfffd, 0xfffd, 0xfffd }, // 0x624 // Just to fill the table ;-)
+ { 0xfffd, 0xfffd, 0xfef9, 0xfefa }, // 0x625 R Alef with Hamza below
+ { 0xfffd, 0xfffd, 0xfffd, 0xfffd }, // 0x626 // Just to fill the table ;-)
+ { 0xfffd, 0xfffd, 0xfefb, 0xfefc } // 0x627 R Alef
+};
+
+static inline int getShape(uchar cell, int tqshape)
+{
+ // the arabicUnicodeMapping does not work for U+0649 ALEF MAKSURA, handle this here
+ uint ch = (cell != 0x49)
+ ? (tqshape ? arabicUnicodeMapping[cell][0] + tqshape : 0x600+cell)
+ : alefMaksura[tqshape] ;
+ return ch;
+}
+
+
+/*
+ Two small helper functions for arabic shaping.
+*/
+static inline const TQChar prevChar(const TQString *str, int pos)
+{
+ //qDebug("leftChar: pos=%d", pos);
+ pos--;
+ const TQChar *ch = str->tqunicode() + pos;
+ while(pos > -1) {
+ if(::category(*ch) != TQChar::Mark_NonSpacing)
+ return *ch;
+ pos--;
+ ch--;
+ }
+ return TQChar::tqreplacement;
+}
+
+static inline const TQChar nextChar(const TQString *str, int pos)
+{
+ pos++;
+ int len = str->length();
+ const TQChar *ch = str->tqunicode() + pos;
+ while(pos < len) {
+ //qDebug("rightChar: %d isLetter=%d, joining=%d", pos, ch.isLetter(), ch.joining());
+ if(::category(*ch) != TQChar::Mark_NonSpacing)
+ return *ch;
+ // assume it's a transtqparent char, this might not be 100% correct
+ pos++;
+ ch++;
+ }
+ return TQChar::tqreplacement;
+}
+
+
+static void tqshapedString(const TQString *uc, int from, int len, TQChar *tqshapeBuffer, int *tqshapedLength,
+ bool reverse, GlyphAttributes *attributes, unsigned short *logClusters)
+{
+ TQ_ASSERT((int)uc->length() >= from + len);
+
+ if(len == 0) {
+ *tqshapedLength = 0;
+ return;
+ }
+
+ TQVarLengthArray<TQArabicProperties> props(len + 2);
+ TQArabicProperties *properties = props.data();
+ int f = from;
+ int l = len;
+ if (from > 0) {
+ --f;
+ ++l;
+ ++properties;
+ }
+ if (f + l < (int)uc->length()) {
+ ++l;
+ }
+ getArabicProperties((const unsigned short *)(uc->tqunicode()+f), l, props.data());
+
+ const TQChar *ch = uc->tqunicode() + from;
+ TQChar *data = tqshapeBuffer;
+ int clusterStart = 0;
+
+ for (int i = 0; i < len; i++) {
+ uchar r = ch->row();
+ int gpos = data - tqshapeBuffer;
+
+ if (r != 0x06) {
+ if (r == 0x20) {
+ uchar c = ch->cell();
+ if (c == 0x0c || c == 0x0d)
+ // remove ZWJ and ZWNJ
+ goto skip;
+ }
+ if (reverse)
+ *data = mirroredChar(*ch);
+ else
+ *data = *ch;
+ } else {
+ uchar c = ch->cell();
+ int pos = i + from;
+ int tqshape = properties[i].tqshape;
+// qDebug("mapping U+%x to tqshape %d glyph=0x%x", ch->tqunicode(), tqshape, getShape(c, tqshape));
+ // take care of lam-alef ligatures (lam right of alef)
+ ushort map;
+ switch (c) {
+ case 0x44: { // lam
+ const TQChar pch = nextChar(uc, pos);
+ if (pch.row() == 0x06) {
+ switch (pch.cell()) {
+ case 0x22:
+ case 0x23:
+ case 0x25:
+ case 0x27:
+// qDebug(" lam of lam-alef ligature");
+ map = arabicUnicodeLamAlefMapping[pch.cell() - 0x22][tqshape];
+ goto next;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+ case 0x22: // alef with madda
+ case 0x23: // alef with hamza above
+ case 0x25: // alef with hamza below
+ case 0x27: // alef
+ if (prevChar(uc, pos).tqunicode() == 0x0644) {
+ // have a lam alef ligature
+ //qDebug(" alef of lam-alef ligature");
+ goto skip;
+ }
+ default:
+ break;
+ }
+ map = getShape(c, tqshape);
+ next:
+ *data = map;
+ }
+ // ##### Fixme
+ //attributes[gpos].zeroWidth = zeroWidth;
+ if (::category(*ch) == TQChar::Mark_NonSpacing) {
+ attributes[gpos].mark = TRUE;
+// qDebug("glyph %d (char %d) is mark!", gpos, i);
+ } else {
+ attributes[gpos].mark = FALSE;
+ clusterStart = data - tqshapeBuffer;
+ }
+ attributes[gpos].clusterStart = !attributes[gpos].mark;
+ attributes[gpos].combiningClass = combiningClass(*ch);
+ attributes[gpos].justification = properties[i].justification;
+// qDebug("data[%d] = %x (from %x)", gpos, (uint)data->tqunicode(), ch->tqunicode());
+ data++;
+ skip:
+ ch++;
+ logClusters[i] = clusterStart;
+ }
+ *tqshapedLength = data - tqshapeBuffer;
+}
+
+#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+
+enum {
+ InitProperty = 0x2,
+ IsolProperty = 0x4,
+ FinaProperty = 0x8,
+ MediProperty = 0x10,
+ RligProperty = 0x20,
+ CaltProperty = 0x40,
+ LigaProperty = 0x80,
+ DligProperty = 0x100,
+ CswhProperty = 0x200,
+ MsetProperty = 0x400
+};
+
+static const TQOpenType::Features arabic_features[] = {
+ { FT_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty },
+ { FT_MAKE_TAG('i', 's', 'o', 'l'), IsolProperty },
+ { FT_MAKE_TAG('f', 'i', 'n', 'a'), FinaProperty },
+ { FT_MAKE_TAG('m', 'e', 'd', 'i'), MediProperty },
+ { FT_MAKE_TAG('i', 'n', 'i', 't'), InitProperty },
+ { FT_MAKE_TAG('r', 'l', 'i', 'g'), RligProperty },
+ { FT_MAKE_TAG('c', 'a', 'l', 't'), CaltProperty },
+ { FT_MAKE_TAG('l', 'i', 'g', 'a'), LigaProperty },
+ { FT_MAKE_TAG('d', 'l', 'i', 'g'), DligProperty },
+ { FT_MAKE_TAG('c', 's', 'w', 'h'), CswhProperty },
+ // mset is used in old Win95 fonts that don't have a 'mark' positioning table.
+ { FT_MAKE_TAG('m', 's', 'e', 't'), MsetProperty },
+ {0, 0}
+};
+
+static const TQOpenType::Features syriac_features[] = {
+ { FT_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty },
+ { FT_MAKE_TAG('i', 's', 'o', 'l'), IsolProperty },
+ { FT_MAKE_TAG('f', 'i', 'n', 'a'), FinaProperty },
+ { FT_MAKE_TAG('f', 'i', 'n', '2'), FinaProperty },
+ { FT_MAKE_TAG('f', 'i', 'n', '3'), FinaProperty },
+ { FT_MAKE_TAG('m', 'e', 'd', 'i'), MediProperty },
+ { FT_MAKE_TAG('m', 'e', 'd', '2'), MediProperty },
+ { FT_MAKE_TAG('i', 'n', 'i', 't'), InitProperty },
+ { FT_MAKE_TAG('r', 'l', 'i', 'g'), RligProperty },
+ { FT_MAKE_TAG('c', 'a', 'l', 't'), CaltProperty },
+ { FT_MAKE_TAG('l', 'i', 'g', 'a'), LigaProperty },
+ { FT_MAKE_TAG('d', 'l', 'i', 'g'), DligProperty },
+ {0, 0}
+};
+
+static bool arabicSyriacOpenTypeShape(TQOpenType *openType, TQShaperItem *item, bool *ot_ok)
+{
+ *ot_ok = true;
+
+ openType->selectScript(item->script, item->script == TQFont::Arabic ? arabic_features : syriac_features);
+ int nglyphs = item->num_glyphs;
+ if (item->font->stringToCMap(item->string->tqunicode()+item->from, item->length, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+ heuristicSetGlyphAttributes(item);
+
+ unsigned short *logClusters = item->log_clusters;
+ const unsigned short *uc = (const unsigned short *)item->string->tqunicode() + item->from;
+
+ TQVarLengthArray<TQArabicProperties> props(item->length+2);
+ TQArabicProperties *properties = props.data();
+ int f = 0;
+ int l = item->length;
+ if (item->from > 0) {
+ --f;
+ ++l;
+ ++properties;
+ }
+ if (f + l < (int)item->string->length()) {
+ ++l;
+ }
+ getArabicProperties((const unsigned short *)(uc+f), l, props.data());
+
+ TQVarLengthArray<uint> apply(item->num_glyphs);
+
+
+ // Hack to remove ZWJ and ZWNJ from rendered output.
+ int j = 0;
+ for (int i = 0; i < item->num_glyphs; i++) {
+ if (uc[i] == 0x200c || uc[i] == 0x200d)
+ continue;
+ item->glyphs[j] = item->glyphs[i];
+ item->attributes[j] = item->attributes[i];
+ item->advances[j] = item->advances[i];
+ item->offsets[j] = item->offsets[i];
+ properties[j] = properties[i];
+ item->attributes[j].justification = properties[i].justification;
+ logClusters[i] = logClusters[j];
+ ++j;
+ }
+ item->num_glyphs = j;
+
+ for (int i = 0; i < item->num_glyphs; i++) {
+ apply[i] = 0;
+
+ if (properties[i].tqshape == XIsolated)
+ apply[i] |= MediProperty|FinaProperty|InitProperty;
+ else if (properties[i].tqshape == XMedial)
+ apply[i] |= IsolProperty|FinaProperty|InitProperty;
+ else if (properties[i].tqshape == XFinal)
+ apply[i] |= IsolProperty|MediProperty|InitProperty;
+ else if (properties[i].tqshape == XInitial)
+ apply[i] |= IsolProperty|MediProperty|FinaProperty;
+ }
+
+ if (!openType->tqshape(item, apply.data())) {
+ *ot_ok = false;
+ return false;
+ }
+ item->num_glyphs = nglyphs;
+ return openType->positionAndAdd(item);
+}
+
+#endif
+
+// #### stil missing: identify invalid character combinations
+static bool arabic_tqshape(TQShaperItem *item)
+{
+ TQ_ASSERT(item->script == TQFont::Arabic);
+
+#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE)
+ TQOpenType *openType = item->font->openType();
+
+ if (openType && openType->supportsScript(TQFont::Arabic)) {
+ bool ot_ok;
+ if (arabicSyriacOpenTypeShape(openType, item, &ot_ok))
+ return true;
+ if (ot_ok)
+ return false;
+ // fall through to the non OT code
+ }
+#endif
+
+ TQVarLengthArray<ushort> tqshapedChars(item->length);
+
+ int slen;
+ tqshapedString(item->string, item->from, item->length, (TQChar *)tqshapedChars.data(), &slen,
+ item->flags & TQTextEngine::RightToLeft,
+ item->attributes, item->log_clusters);
+
+ if (item->font->stringToCMap((TQChar *)tqshapedChars.data(), slen, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+
+ for (int i = 0; i < slen; ++i)
+ if (item->attributes[i].mark)
+ item->advances[i] = 0;
+ qt_heuristicPosition(item);
+ return TRUE;
+}
+
+#if defined(TQ_WS_X11)
+# include "tqscriptengine_x11.cpp"
+#elif defined(TQ_WS_WIN)
+# include "tqscriptengine_win.cpp"
+#elif defined(TQ_WS_MAC)
+# include "tqscriptengine_mac.cpp"
+#elif defined(TQ_WS_TQWS)
+# include "tqscriptengine_qws.cpp"
+#endif
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqscriptengine_p.h b/tqtinterface/qt4/src/kernel/tqscriptengine_p.h
new file mode 100644
index 0000000..42698e9
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqscriptengine_p.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the $MODULE$ of the TQt Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+****************************************************************************/
+
+#ifndef TQSCRIPTENGINE_P_H
+#define TQSCRIPTENGINE_P_H
+
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "tqtextengine_p.h"
+
+class TQString;
+struct TQCharAttributes;
+
+struct TQShaperItem {
+ int script;
+ const TQString *string;
+ int from;
+ int length;
+ TQFontEngine *font;
+ glyph_t *glyphs;
+ advance_t *advances;
+ qoffset_t *offsets;
+ GlyphAttributes *attributes;
+ int num_glyphs; // in: available glyphs out: glyphs used/needed
+ unsigned short *log_clusters;
+ int flags;
+ bool has_positioning;
+};
+
+// return true if ok.
+typedef bool (*ShapeFunction)(TQShaperItem *item);
+typedef void (*AttributeFunction)(int script, const TQString &, int, int, TQCharAttributes *);
+
+struct q_scriptEngine {
+ ShapeFunction tqshape;
+ AttributeFunction charAttributes;
+};
+
+extern const q_scriptEngine scriptEngines[];
+
+#endif // USE_QT4
+
+#endif // TQSCRIPTENGINE_P_H
diff --git a/tqtinterface/qt4/src/kernel/tqscriptengine_x11.cpp b/tqtinterface/qt4/src/kernel/tqscriptengine_x11.cpp
new file mode 100644
index 0000000..3cd84d7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqscriptengine_x11.cpp
@@ -0,0 +1,3752 @@
+/****************************************************************************
+**
+** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+// ------------------------------------------------------------------------------------------------------------------
+//
+// Continuation of middle eastern languages
+//
+// ------------------------------------------------------------------------------------------------------------------
+
+// #### stil missing: identify invalid character combinations
+static bool syriac_tqshape(TQShaperItem *item)
+{
+ TQ_ASSERT(item->script == TQFont::Syriac);
+
+#ifndef TQT_NO_XFTFREETYPE
+ TQOpenType *openType = item->font->openType();
+ if (openType && openType->supportsScript(TQFont::Syriac)) {
+ bool ot_ok;
+ if (arabicSyriacOpenTypeShape(openType, item, &ot_ok))
+ return true;
+ if (ot_ok)
+ return false;
+ // fall through to the non OT code
+ }
+#endif
+ return basic_tqshape(item);
+}
+
+
+static bool thaana_tqshape(TQShaperItem *item)
+{
+ TQ_ASSERT(item->script == TQFont::Thaana);
+
+#ifndef TQT_NO_XFTFREETYPE
+ TQOpenType *openType = item->font->openType();
+
+ if (openType && openType->supportsScript(item->script)) {
+ openType->selectScript(TQFont::Thaana);
+ if (item->font->stringToCMap(item->string->tqunicode()+item->from, item->length, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+ heuristicSetGlyphAttributes(item);
+ openType->tqshape(item);
+ return openType->positionAndAdd(item);
+ }
+#endif
+ return basic_tqshape(item);
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Indic languages
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+enum Form {
+ Invalid = 0x0,
+ Unknown = Invalid,
+ Consonant,
+ Nukta,
+ Halant,
+ Matra,
+ VowelMark,
+ StressMark,
+ IndependentVowel,
+ LengthMark,
+ Control,
+ Other
+};
+
+static const unsigned char indicForms[0xe00-0x900] = {
+ // Devangari
+ Invalid, VowelMark, VowelMark, VowelMark,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Nukta, Other, Matra, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Matra, Matra, Matra, Matra,
+ Matra, Matra, Matra, Matra,
+ Matra, Halant, Unknown, Unknown,
+
+ Other, StressMark, StressMark, StressMark,
+ StressMark, Unknown, Unknown, Unknown,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ IndependentVowel, IndependentVowel, VowelMark, VowelMark,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Consonant,
+ Consonant, Consonant /* ??? */, Consonant, Consonant,
+
+ // Bengali
+ Invalid, VowelMark, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, Invalid, Invalid, IndependentVowel,
+
+ IndependentVowel, Invalid, Invalid, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Invalid, Consonant, Invalid,
+ Invalid, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Nukta, Other, Matra, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Matra, Invalid, Invalid, Matra,
+ Matra, Invalid, Invalid, Matra,
+ Matra, Halant, Consonant, Unknown,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, VowelMark,
+ Invalid, Invalid, Invalid, Invalid,
+ Consonant, Consonant, Invalid, Consonant,
+
+ IndependentVowel, IndependentVowel, VowelMark, VowelMark,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Consonant, Consonant, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ // Gurmukhi
+ Invalid, VowelMark, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, Invalid,
+ Invalid, Invalid, Invalid, IndependentVowel,
+
+ IndependentVowel, Invalid, Invalid, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Invalid, Consonant, Consonant,
+ Invalid, Consonant, Consonant, Invalid,
+ Consonant, Consonant, Unknown, Unknown,
+ Nukta, Other, Matra, Matra,
+
+ Matra, Matra, Matra, Invalid,
+ Invalid, Invalid, Invalid, Matra,
+ Matra, Invalid, Invalid, Matra,
+ Matra, Halant, Unknown, Unknown,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Unknown, Unknown, Unknown,
+ Invalid, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Invalid,
+
+ Other, Other, Invalid, Invalid,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ StressMark, StressMark, Consonant, Consonant,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ // Gujarati
+ Invalid, VowelMark, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, Invalid, IndependentVowel,
+
+ IndependentVowel, IndependentVowel, Invalid, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Invalid, Consonant, Consonant,
+ Invalid, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Nukta, Other, Matra, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Matra, Matra, Invalid, Matra,
+ Matra, Matra, Invalid, Matra,
+ Matra, Halant, Unknown, Unknown,
+
+ Other, Unknown, Unknown, Unknown,
+ Unknown, Unknown, Unknown, Unknown,
+ Unknown, Unknown, Unknown, Unknown,
+ Unknown, Unknown, Unknown, Unknown,
+
+ IndependentVowel, IndependentVowel, VowelMark, VowelMark,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ // Oriya
+ Invalid, VowelMark, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, Invalid, Invalid, IndependentVowel,
+
+ IndependentVowel, Invalid, Invalid, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Invalid, Consonant, Consonant,
+ Invalid, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Nukta, Other, Matra, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Invalid, Invalid, Invalid, Matra,
+ Matra, Invalid, Invalid, Matra,
+ Matra, Halant, Unknown, Unknown,
+
+ Other, Invalid, Invalid, Invalid,
+ Invalid, Unknown, LengthMark, LengthMark,
+ Invalid, Invalid, Invalid, Invalid,
+ Consonant, Consonant, Invalid, Consonant,
+
+ IndependentVowel, IndependentVowel, Invalid, Invalid,
+ Invalid, Invalid, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Other, Consonant, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ //Tamil
+ Invalid, Invalid, VowelMark, Other,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, Invalid,
+ Invalid, Invalid, IndependentVowel, IndependentVowel,
+
+ IndependentVowel, Invalid, IndependentVowel, IndependentVowel,
+ IndependentVowel, Consonant, Invalid, Invalid,
+ Invalid, Consonant, Consonant, Invalid,
+ Consonant, Invalid, Consonant, Consonant,
+
+ Invalid, Invalid, Invalid, Consonant,
+ Consonant, Invalid, Invalid, Invalid,
+ Consonant, Consonant, Consonant, Invalid,
+ Invalid, Invalid, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Invalid, Invalid, Matra, Matra,
+
+ Matra, Matra, Matra, Invalid,
+ Invalid, Invalid, Matra, Matra,
+ Matra, Invalid, Matra, Matra,
+ Matra, Halant, Invalid, Invalid,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, LengthMark,
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ // Telugu
+ Invalid, VowelMark, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, Invalid, IndependentVowel, IndependentVowel,
+
+ IndependentVowel, Invalid, IndependentVowel, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Invalid, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Invalid, Invalid, Matra, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Matra, Invalid, Matra, Matra,
+ Matra, Invalid, Matra, Matra,
+ Matra, Halant, Invalid, Invalid,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, LengthMark, Matra, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+
+ IndependentVowel, IndependentVowel, Invalid, Invalid,
+ Invalid, Invalid, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ // Kannada
+ Invalid, Invalid, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, Invalid, IndependentVowel, IndependentVowel,
+
+ IndependentVowel, Invalid, IndependentVowel, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Invalid, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Nukta, Other, Matra, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Matra, Invalid, Matra, Matra,
+ Matra, Invalid, Matra, Matra,
+ Matra, Halant, Invalid, Invalid,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, LengthMark, LengthMark, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Consonant, Invalid,
+
+ IndependentVowel, IndependentVowel, VowelMark, VowelMark,
+ Invalid, Invalid, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ // Malayalam
+ Invalid, Invalid, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, Invalid, IndependentVowel, IndependentVowel,
+
+ IndependentVowel, Invalid, IndependentVowel, IndependentVowel,
+ IndependentVowel, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Unknown, Unknown,
+ Invalid, Invalid, Matra, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Invalid, Invalid, Matra, Matra,
+ Matra, Invalid, Matra, Matra,
+ Matra, Halant, Invalid, Invalid,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, LengthMark,
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+
+ IndependentVowel, IndependentVowel, Invalid, Invalid,
+ Invalid, Invalid, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+
+ // Sinhala
+ Invalid, Invalid, VowelMark, VowelMark,
+ Invalid, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+
+ IndependentVowel, IndependentVowel, IndependentVowel, IndependentVowel,
+ IndependentVowel, IndependentVowel, IndependentVowel, Invalid,
+ Invalid, Invalid, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+
+ Consonant, Consonant, Invalid, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Consonant,
+ Invalid, Consonant, Invalid, Invalid,
+
+ Consonant, Consonant, Consonant, Consonant,
+ Consonant, Consonant, Consonant, Invalid,
+ Invalid, Invalid, Halant, Invalid,
+ Invalid, Invalid, Invalid, Matra,
+
+ Matra, Matra, Matra, Matra,
+ Matra, Invalid, Matra, Invalid,
+ Matra, Matra, Matra, Matra,
+ Matra, Matra, Matra, Matra,
+
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+ Invalid, Invalid, Invalid, Invalid,
+
+ Invalid, Invalid, Matra, Matra,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+ Other, Other, Other, Other,
+};
+
+enum Position {
+ None,
+ Pre,
+ Above,
+ Below,
+ Post,
+ Split,
+ Base,
+ Reph,
+ Vattu,
+ Inherit
+};
+
+static const unsigned char indicPosition[0xe00-0x900] = {
+ // Devanagari
+ None, Above, Above, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ Below, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, Post, Pre,
+
+ Post, Below, Below, Below,
+ Below, Above, Above, Above,
+ Above, Post, Post, Post,
+ Post, None, None, None,
+
+ None, Above, Below, Above,
+ Above, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, Below, Below,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Bengali
+ None, Above, Post, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ Below, None, None, Post,
+
+ Below, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ Below, None, Post, Pre,
+
+ Post, Below, Below, Below,
+ Below, None, None, Pre,
+ Pre, None, None, Split,
+ Split, Below, None, None,
+
+ None, None, None, None,
+ None, None, None, Post,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, Below, Below,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Gurmukhi
+ None, Above, Above, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, Post,
+
+ Below, None, None, None,
+ None, Below, None, None,
+ None, Below, None, None,
+ Below, None, Post, Pre,
+
+ Post, Below, Below, None,
+ None, None, None, Above,
+ Above, None, None, Above,
+ Above, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ Above, Above, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Gujarati
+ None, Above, Above, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ Below, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, Post, Pre,
+
+ Post, Below, Below, Below,
+ Below, Above, None, Above,
+ Above, Post, None, Post,
+ Post, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, Below, Below,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Oriya
+ None, Above, Post, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ Below, None, None, None,
+ Below, None, None, None,
+ Below, Below, Below, Post,
+
+ Below, None, Below, Below,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, Post, Above,
+
+ Post, Below, Below, Below,
+ None, None, None, Pre,
+ Split, None, None, Split,
+ Split, None, None, None,
+
+ None, None, None, None,
+ None, None, Above, Post,
+ None, None, None, None,
+ None, None, None, Post,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, Below, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Tamil
+ None, None, Above, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, Post, Post,
+
+ Above, Below, Below, None,
+ None, None, Pre, Pre,
+ Pre, None, Split, Split,
+ Split, Halant, None, None,
+
+ None, None, None, None,
+ None, None, None, Post,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Telugu
+ None, Post, Post, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, Below, Below, Below,
+ Below, Below, Below, Below,
+ Below, Below, Below, Below,
+
+ Below, Below, Below, Below,
+ Below, Below, Below, Below,
+ Below, None, Below, Below,
+ Below, Below, Below, Below,
+
+ Below, None, Below, Below,
+ None, Below, Below, Below,
+ Below, Below, None, None,
+ None, None, Post, Above,
+
+ Above, Post, Post, Post,
+ Post, None, Above, Above,
+ Split, None, Post, Above,
+ Above, Halant, None, None,
+
+ None, None, None, None,
+ None, Above, Below, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Kannada
+ None, None, Post, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, Below, Below, Below,
+ Below, Below, Below, Below,
+ Below, Below, Below, Below,
+
+ Below, Below, Below, Below,
+ Below, Below, Below, Below,
+ Below, Below, Below, Below,
+ Below, Below, Below, Below,
+
+ Below, None, Below, Below,
+ None, Below, Below, Below,
+ Below, Below, None, None,
+ None, None, Post, Above,
+
+ Split, Post, Post, Post,
+ Post, None, Above, Split,
+ Split, None, Split, Split,
+ Above, Halant, None, None,
+
+ None, None, None, None,
+ None, Post, Post, None,
+ None, None, None, None,
+ None, None, Below, None,
+
+ None, None, Below, Below,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Malayalam
+ None, None, Post, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, Post,
+
+ Post, None, Below, None,
+ None, Post, None, None,
+ None, None, None, None,
+ None, None, Post, Post,
+
+ Post, Post, Post, Post,
+ None, None, Pre, Pre,
+ Pre, None, Split, Split,
+ Split, Halant, None, None,
+
+ None, None, None, None,
+ None, None, None, Post,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ // Sinhala
+ None, None, Post, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, Post,
+
+ Post, Post, Above, Above,
+ Below, None, Below, None,
+ Post, Pre, Split, Pre,
+ Split, Split, Split, Post,
+
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None,
+
+ None, None, Post, Post,
+ None, None, None, None,
+ None, None, None, None,
+ None, None, None, None
+};
+
+static inline Form form(unsigned short uc) {
+ if (uc < 0x900 || uc > 0xdff) {
+ if (uc == 0x25cc)
+ return Consonant;
+ if (uc == 0x200c || uc == 0x200d)
+ return Control;
+ return Other;
+ }
+ return (Form)indicForms[uc-0x900];
+}
+
+static inline Position indic_position(unsigned short uc) {
+ if (uc < 0x900 || uc > 0xdff)
+ return None;
+ return (Position) indicPosition[uc-0x900];
+}
+
+
+enum IndicScriptProperties {
+ HasReph = 0x01,
+ HasSplit = 0x02
+};
+
+const uchar scriptProperties[10] = {
+ // Devanagari,
+ HasReph,
+ // Bengali,
+ HasReph|HasSplit,
+ // Gurmukhi,
+ 0,
+ // Gujarati,
+ HasReph,
+ // Oriya,
+ HasReph|HasSplit,
+ // Tamil,
+ HasSplit,
+ // Telugu,
+ HasSplit,
+ // Kannada,
+ HasSplit|HasReph,
+ // Malayalam,
+ HasSplit,
+ // Sinhala,
+ HasSplit
+};
+
+struct IndicOrdering {
+ Form form;
+ Position position;
+};
+
+static const IndicOrdering devanagari_order [] = {
+ { Consonant, Below },
+ { Matra, Below },
+ { VowelMark, Below },
+ { StressMark, Below },
+ { Matra, Above },
+ { Matra, Post },
+ { Consonant, Reph },
+ { VowelMark, Above },
+ { StressMark, Above },
+ { VowelMark, Post },
+ { (Form)0, None }
+};
+
+static const IndicOrdering bengali_order [] = {
+ { Consonant, Below },
+ { Matra, Below },
+ { Matra, Above },
+ { Consonant, Reph },
+ { VowelMark, Above },
+ { Consonant, Post },
+ { Matra, Post },
+ { VowelMark, Post },
+ { (Form)0, None }
+};
+
+static const IndicOrdering gurmukhi_order [] = {
+ { Consonant, Below },
+ { Matra, Below },
+ { Matra, Above },
+ { Consonant, Post },
+ { Matra, Post },
+ { VowelMark, Above },
+ { (Form)0, None }
+};
+
+static const IndicOrdering tamil_order [] = {
+ { Matra, Above },
+ { Matra, Post },
+ { VowelMark, Post },
+ { (Form)0, None }
+};
+
+static const IndicOrdering telugu_order [] = {
+ { Matra, Above },
+ { Matra, Below },
+ { Matra, Post },
+ { Consonant, Below },
+ { Consonant, Post },
+ { VowelMark, Post },
+ { (Form)0, None }
+};
+
+static const IndicOrdering kannada_order [] = {
+ { Matra, Above },
+ { Matra, Post },
+ { Consonant, Below },
+ { Consonant, Post },
+ { LengthMark, Post },
+ { Consonant, Reph },
+ { VowelMark, Post },
+ { (Form)0, None }
+};
+
+static const IndicOrdering malayalam_order [] = {
+ { Consonant, Below },
+ { Matra, Below },
+ { Consonant, Reph },
+ { Consonant, Post },
+ { Matra, Post },
+ { VowelMark, Post },
+ { (Form)0, None }
+};
+
+static const IndicOrdering sinhala_order [] = {
+ { Matra, Below },
+ { Matra, Above },
+ { Matra, Post },
+ { VowelMark, Post },
+ { (Form)0, None }
+};
+
+static const IndicOrdering * const indic_order[] = {
+ devanagari_order, // Devanagari
+ bengali_order, // Bengali
+ gurmukhi_order, // Gurmukhi
+ devanagari_order, // Gujarati
+ bengali_order, // Oriya
+ tamil_order, // Tamil
+ telugu_order, // Telugu
+ kannada_order, // Kannada
+ malayalam_order, // Malayalam
+ sinhala_order // Sinhala
+};
+
+
+
+// vowel matras that have to be split into two parts.
+static const unsigned short split_matras[] = {
+ // matra, split1, split2
+
+ // bengalis
+ 0x9cb, 0x9c7, 0x9be,
+ 0x9cc, 0x9c7, 0x9d7,
+ // oriya
+ 0xb48, 0xb47, 0xb56,
+ 0xb4b, 0xb47, 0xb3e,
+ 0xb4c, 0xb47, 0xb57,
+ // tamil
+ 0xbca, 0xbc6, 0xbbe,
+ 0xbcb, 0xbc7, 0xbbe,
+ 0xbcc, 0xbc6, 0xbd7,
+ // telugu
+ 0xc48, 0xc46, 0xc56,
+ // kannada
+ 0xcc0, 0xcbf, 0xcd5,
+ 0xcc7, 0xcc6, 0xcd5,
+ 0xcc8, 0xcc6, 0xcd6,
+ 0xcca, 0xcc6, 0xcc2,
+ 0xccb, 0xcca, 0xcd5,
+ // malayalam
+ 0xd4a, 0xd46, 0xd3e,
+ 0xd4b, 0xd47, 0xd3e,
+ 0xd4c, 0xd46, 0xd57,
+ // sinhala
+ 0xdda, 0xdd9, 0xdca,
+ 0xddc, 0xdd9, 0xdcf,
+ 0xddd, 0xddc, 0xdca,
+ 0xdde, 0xdd9, 0xddf,
+ 0xffff
+};
+
+static inline void splitMatra(unsigned short *reordered, int matra, int &len, int &base)
+{
+ unsigned short matra_uc = reordered[matra];
+ //qDebug("matra=%d, reordered[matra]=%x", matra, reordered[matra]);
+
+ const unsigned short *split = split_matras;
+ while (split[0] < matra_uc)
+ split += 3;
+
+ assert(*split == matra_uc);
+ ++split;
+
+ if (indic_position(*split) == Pre) {
+ reordered[matra] = split[1];
+ memmove(reordered + 1, reordered, len*sizeof(unsigned short));
+ reordered[0] = split[0];
+ base++;
+ } else {
+ memmove(reordered + matra + 1, reordered + matra, (len-matra)*sizeof(unsigned short));
+ reordered[matra] = split[0];
+ reordered[matra+1] = split[1];
+ }
+ len++;
+}
+
+enum IndicProperties {
+ // these two are already defined
+// CcmpProperty = 0x1,
+// InitProperty = 0x2,
+ NuktaProperty = 0x4,
+ AkhantProperty = 0x8,
+ RephProperty = 0x10,
+ PreFormProperty = 0x20,
+ BelowFormProperty = 0x40,
+ AboveFormProperty = 0x80,
+ HalfFormProperty = 0x100,
+ PostFormProperty = 0x200,
+ VattuProperty = 0x400,
+ PreSubstProperty = 0x800,
+ BelowSubstProperty = 0x1000,
+ AboveSubstProperty = 0x2000,
+ PostSubstProperty = 0x4000,
+ HalantProperty = 0x8000,
+ CligProperty = 0x10000
+};
+
+#ifndef TQT_NO_XFTFREETYPE
+static const TQOpenType::Features indic_features[] = {
+ { FT_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty },
+ { FT_MAKE_TAG('i', 'n', 'i', 't'), InitProperty },
+ { FT_MAKE_TAG('n', 'u', 'k', 't'), NuktaProperty },
+ { FT_MAKE_TAG('a', 'k', 'h', 'n'), AkhantProperty },
+ { FT_MAKE_TAG('r', 'p', 'h', 'f'), RephProperty },
+ { FT_MAKE_TAG('b', 'l', 'w', 'f'), BelowFormProperty },
+ { FT_MAKE_TAG('h', 'a', 'l', 'f'), HalfFormProperty },
+ { FT_MAKE_TAG('p', 's', 't', 'f'), PostFormProperty },
+ { FT_MAKE_TAG('v', 'a', 't', 'u'), VattuProperty },
+ { FT_MAKE_TAG('p', 'r', 'e', 's'), PreSubstProperty },
+ { FT_MAKE_TAG('b', 'l', 'w', 's'), BelowSubstProperty },
+ { FT_MAKE_TAG('a', 'b', 'v', 's'), AboveSubstProperty },
+ { FT_MAKE_TAG('p', 's', 't', 's'), PostSubstProperty },
+ { FT_MAKE_TAG('h', 'a', 'l', 'n'), HalantProperty },
+ { 0, 0 }
+};
+#endif
+
+// #define INDIC_DEBUG
+#ifdef INDIC_DEBUG
+#define IDEBUG qDebug
+#else
+#define IDEBUG if(0) qDebug
+#endif
+
+#ifdef INDIC_DEBUG
+static TQString propertiesToString(int properties)
+{
+ TQString res;
+ properties = ~properties;
+ if (properties & CcmpProperty)
+ res += "Ccmp ";
+ if (properties & InitProperty)
+ res += "Init ";
+ if (properties & NuktaProperty)
+ res += "Nukta ";
+ if (properties & AkhantProperty)
+ res += "Akhant ";
+ if (properties & RephProperty)
+ res += "Reph ";
+ if (properties & PreFormProperty)
+ res += "PreForm ";
+ if (properties & BelowFormProperty)
+ res += "BelowForm ";
+ if (properties & AboveFormProperty)
+ res += "AboveForm ";
+ if (properties & HalfFormProperty)
+ res += "HalfForm ";
+ if (properties & PostFormProperty)
+ res += "PostForm ";
+ if (properties & VattuProperty)
+ res += "Vattu ";
+ if (properties & PreSubstProperty)
+ res += "PreSubst ";
+ if (properties & BelowSubstProperty)
+ res += "BelowSubst ";
+ if (properties & AboveSubstProperty)
+ res += "AboveSubst ";
+ if (properties & PostSubstProperty)
+ res += "PostSubst ";
+ if (properties & HalantProperty)
+ res += "Halant ";
+ if (properties & CligProperty)
+ res += "Clig ";
+ return res;
+}
+#endif
+
+static bool indic_tqshape_syllable(TQOpenType *openType, TQShaperItem *item, bool invalid)
+{
+ TQ_UNUSED(openType)
+ int script = item->script;
+ TQ_ASSERT(script >= TQFont::Devanagari && script <= TQFont::Sinhala);
+ const unsigned short script_base = 0x0900 + 0x80*(script-TQFont::Devanagari);
+ const unsigned short ra = script_base + 0x30;
+ const unsigned short halant = script_base + 0x4d;
+ const unsigned short nukta = script_base + 0x3c;
+
+ int len = item->length;
+ IDEBUG(">>>>> indic tqshape: from=%d, len=%d invalid=%d", item->from, item->length, invalid);
+
+ if (item->num_glyphs < len+4) {
+ item->num_glyphs = len+4;
+ return FALSE;
+ }
+
+ TQVarLengthArray<unsigned short> reordered(len+4);
+ TQVarLengthArray<unsigned char> position(len+4);
+
+ unsigned char properties = scriptProperties[script-TQFont::Devanagari];
+
+ if (invalid) {
+ *reordered.data() = 0x25cc;
+ memcpy(reordered.data()+1, item->string->tqunicode() + item->from, len*sizeof(TQChar));
+ len++;
+ } else {
+ memcpy(reordered.data(), item->string->tqunicode() + item->from, len*sizeof(TQChar));
+ }
+ if (reordered[len-1] == 0x200c) // zero width non joiner
+ len--;
+
+ int i;
+ int base = 0;
+ int reph = -1;
+
+#ifdef INDIC_DEBUG
+ IDEBUG("original:");
+ for (i = 0; i < len; i++) {
+ IDEBUG(" %d: %4x", i, reordered[i]);
+ }
+#endif
+
+ if (len != 1) {
+ unsigned short *uc = reordered.data();
+ bool beginsWithRa = FALSE;
+
+ // Rule 1: tqfind base consonant
+ //
+ // The shaping engine tqfinds the base consonant of the
+ // syllable, using the following algorithm: starting from the
+ // end of the syllable, move backwards until a consonant is
+ // found that does not have a below-base or post-base form
+ // (post-base forms have to follow below-base forms), or
+ // arrive at the first consonant. The consonant stopped at
+ // will be the base.
+ //
+ // * If the syllable starts with Ra + H (in a script that has
+ // 'Reph'), Ra is excluded from candidates for base
+ // consonants.
+ //
+ // * In Kannada and Telugu, the base consonant cannot be
+ // farther than 3 consonants from the end of the syllable.
+ // #### tqreplace the HasReph property by testing if the feature exists in the font!
+ if (form(*uc) == Consonant || (script == TQFont::Bengali && form(*uc) == IndependentVowel)) {
+ beginsWithRa = (properties & HasReph) && ((len > 2) && *uc == ra && *(uc+1) == halant);
+
+ if (beginsWithRa && form(*(uc+2)) == Control)
+ beginsWithRa = FALSE;
+
+ base = (beginsWithRa ? 2 : 0);
+ IDEBUG(" length = %d, beginsWithRa = %d, base=%d", len, beginsWithRa, base);
+
+ int lastConsonant = 0;
+ int matra = -1;
+ // we remember:
+ // * the last consonant since we need it for rule 2
+ // * the matras position for rule 3 and 4
+
+ // figure out possible base glyphs
+ memset(position.data(), 0, len);
+ if (script == TQFont::Devanagari || script == TQFont::Gujarati) {
+ bool vattu = FALSE;
+ for (i = base; i < len; ++i) {
+ position[i] = form(uc[i]);
+ if (position[i] == Consonant) {
+ lastConsonant = i;
+ vattu = (!vattu && uc[i] == ra);
+ if (vattu) {
+ IDEBUG("excluding vattu glyph at %d from base candidates", i);
+ position[i] = Vattu;
+ }
+ } else if (position[i] == Matra) {
+ matra = i;
+ }
+ }
+ } else {
+ for (i = base; i < len; ++i) {
+ position[i] = form(uc[i]);
+ if (position[i] == Consonant)
+ lastConsonant = i;
+ else if (matra < 0 && position[i] == Matra)
+ matra = i;
+ }
+ }
+ int skipped = 0;
+ Position pos = Post;
+ for (i = len-1; i > base; i--) {
+ if (position[i] != Consonant && (position[i] != Control || script == TQFont::Kannada))
+ continue;
+
+ Position charPosition = indic_position(uc[i]);
+ if (pos == Post && charPosition == Post) {
+ pos = Post;
+ } else if ((pos == Post || pos == Below) && charPosition == Below) {
+ if (script == TQFont::Devanagari || script == TQFont::Gujarati)
+ base = i;
+ pos = Below;
+ } else {
+ base = i;
+ break;
+ }
+ if (skipped == 2 && (script == TQFont::Kannada || script == TQFont::Telugu)) {
+ base = i;
+ break;
+ }
+ ++skipped;
+ }
+
+ IDEBUG(" base consonant at %d skipped=%d, lastConsonant=%d", base, skipped, lastConsonant);
+
+ // Rule 2:
+ //
+ // If the base consonant is not the last one, Uniscribe
+ // moves the halant from the base consonant to the last
+ // one.
+ if (lastConsonant > base) {
+ int halantPos = 0;
+ if (uc[base+1] == halant)
+ halantPos = base + 1;
+ else if (uc[base+1] == nukta && uc[base+2] == halant)
+ halantPos = base + 2;
+ if (halantPos > 0) {
+ IDEBUG(" moving halant from %d to %d!", base+1, lastConsonant);
+ for (i = halantPos; i < lastConsonant; i++)
+ uc[i] = uc[i+1];
+ uc[lastConsonant] = halant;
+ }
+ }
+
+ // Rule 3:
+ //
+ // If the syllable starts with Ra + H, Uniscribe moves
+ // this combination so that it follows either:
+
+ // * the post-base 'matra' (if any) or the base consonant
+ // (in scripts that show similarity to Devanagari, i.e.,
+ // Devanagari, Gujarati, Bengali)
+ // * the base consonant (other scripts)
+ // * the end of the syllable (Kannada)
+
+ Position matra_position = None;
+ if (matra > 0)
+ matra_position = indic_position(uc[matra]);
+ IDEBUG(" matra at %d with form %d, base=%d", matra, matra_position, base);
+
+ if (beginsWithRa && base != 0) {
+ int toPos = base+1;
+ if (toPos < len && uc[toPos] == nukta)
+ toPos++;
+ if (toPos < len && uc[toPos] == halant)
+ toPos++;
+ if (toPos < len && uc[toPos] == 0x200d)
+ toPos++;
+ if (toPos < len-1 && uc[toPos] == ra && uc[toPos+1] == halant)
+ toPos += 2;
+ if (script == TQFont::Devanagari || script == TQFont::Gujarati || script == TQFont::Bengali) {
+ if (matra_position == Post || matra_position == Split) {
+ toPos = matra+1;
+ matra -= 2;
+ }
+ } else if (script == TQFont::Kannada) {
+ toPos = len;
+ matra -= 2;
+ }
+
+ IDEBUG("moving leading ra+halant to position %d", toPos);
+ for (i = 2; i < toPos; i++)
+ uc[i-2] = uc[i];
+ uc[toPos-2] = ra;
+ uc[toPos-1] = halant;
+ base -= 2;
+ if (properties & HasReph)
+ reph = toPos-2;
+ }
+
+ // Rule 4:
+
+ // Uniscribe splits two- or three-part matras into their
+ // parts. This splitting is a character-to-character
+ // operation).
+ //
+ // Uniscribe describes some moving operations for these
+ // matras here. For shaping however all pre matras need
+ // to be at the begining of the syllable, so we just move
+ // them there now.
+ if (matra_position == Split) {
+ splitMatra(uc, matra, len, base);
+ // Handle three-part matras (0xccb in Kannada)
+ matra_position = indic_position(uc[matra]);
+ if (matra_position == Split)
+ splitMatra(uc, matra, len, base);
+ } else if (matra_position == Pre) {
+ unsigned short m = uc[matra];
+ while (matra--)
+ uc[matra+1] = uc[matra];
+ uc[0] = m;
+ base++;
+ }
+ }
+
+ // Rule 5:
+ //
+ // Uniscribe classifies consonants and 'matra' parts as
+ // pre-base, above-base (Reph), below-base or post-base. This
+ // classification exists on the character code level and is
+ // language-dependent, not font-dependent.
+ for (i = 0; i < base; ++i)
+ position[i] = Pre;
+ position[base] = Base;
+ for (i = base+1; i < len; ++i) {
+ position[i] = indic_position(uc[i]);
+ // #### tqreplace by adjusting table
+ if (uc[i] == nukta || uc[i] == halant)
+ position[i] = Inherit;
+ }
+ if (reph > 0) {
+ // recalculate reph, it might have changed.
+ for (i = base+1; i < len; ++i)
+ if (uc[i] == ra)
+ reph = i;
+ position[reph] = Reph;
+ position[reph+1] = Inherit;
+ }
+
+ // all reordering happens now to the chars after the base
+ int fixed = base+1;
+ if (fixed < len && uc[fixed] == nukta)
+ fixed++;
+ if (fixed < len && uc[fixed] == halant)
+ fixed++;
+ if (fixed < len && uc[fixed] == 0x200d)
+ fixed++;
+
+#ifdef INDIC_DEBUG
+ for (i = fixed; i < len; ++i)
+ IDEBUG("position[%d] = %d, form=%d", i, position[i], form(uc[i]));
+#endif
+ // we continuosly position the matras and vowel marks and increase the fixed
+ // until we reached the end.
+ const IndicOrdering *finalOrder = indic_order[script-TQFont::Devanagari];
+
+ IDEBUG(" reordering pass:");
+ //IDEBUG(" base=%d fixed=%d", base, fixed);
+ int toMove = 0;
+ while (finalOrder[toMove].form && fixed < len-1) {
+ //IDEBUG(" fixed = %d, moving form %d with pos %d", fixed, finalOrder[toMove].form, finalOrder[toMove].position);
+ for (i = fixed; i < len; i++) {
+ if (form(uc[i]) == finalOrder[toMove].form &&
+ position[i] == finalOrder[toMove].position) {
+ // need to move this glyph
+ int to = fixed;
+ if (i < len-1 && position[i+1] == Inherit) {
+ IDEBUG(" moving two chars from %d to %d", i, to);
+ unsigned short ch = uc[i];
+ unsigned short ch2 = uc[i+1];
+ unsigned char pos = position[i];
+ for (int j = i+1; j > to+1; j--) {
+ uc[j] = uc[j-2];
+ position[j] = position[j-2];
+ }
+ uc[to] = ch;
+ uc[to+1] = ch2;
+ position[to] = pos;
+ position[to+1] = pos;
+ fixed += 2;
+ } else {
+ IDEBUG(" moving one char from %d to %d", i, to);
+ unsigned short ch = uc[i];
+ unsigned char pos = position[i];
+ for (int j = i; j > to; j--) {
+ uc[j] = uc[j-1];
+ position[j] = position[j-1];
+ }
+ uc[to] = ch;
+ position[to] = pos;
+ fixed++;
+ }
+ }
+ }
+ toMove++;
+ }
+
+ }
+
+ if (reph > 0) {
+ // recalculate reph, it might have changed.
+ for (i = base+1; i < len; ++i)
+ if (reordered[i] == ra)
+ reph = i;
+ }
+
+ if (item->font->stringToCMap((const TQChar *)reordered.data(), len, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+
+
+ IDEBUG(" base=%d, reph=%d", base, reph);
+ IDEBUG("reordered:");
+ for (i = 0; i < len; i++) {
+ item->attributes[i].mark = FALSE;
+ item->attributes[i].clusterStart = FALSE;
+ item->attributes[i].justification = 0;
+ item->attributes[i].zeroWidth = FALSE;
+ IDEBUG(" %d: %4x", i, reordered[i]);
+ }
+
+ // now we have the syllable in the right order, and can start running it through open type.
+
+ bool control = FALSE;
+ for (i = 0; i < len; ++i)
+ control |= (form(reordered[i]) == Control);
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (openType) {
+
+ // we need to keep track of where the base glyph is for some
+ // scripts and use the cluster feature for this. This
+ // also means we have to correct the logCluster output from
+ // the open type engine manually afterwards. for indic this
+ // is rather simple, as all chars just point to the first
+ // glyph in the syllable.
+ TQVarLengthArray<unsigned short> clusters(len);
+ TQVarLengthArray<unsigned int> properties(len);
+
+ for (i = 0; i < len; ++i)
+ clusters[i] = i;
+
+ // features we should always apply
+ for (i = 0; i < len; ++i)
+ properties[i] = ~(CcmpProperty
+ | NuktaProperty
+ | VattuProperty
+ | PreSubstProperty
+ | BelowSubstProperty
+ | AboveSubstProperty
+ | HalantProperty
+ | PositioningProperties);
+
+ // Ccmp always applies
+ // Init
+ if (item->from == 0
+ || !(item->string->tqunicode()[item->from-1].isLetter() || item->string->tqunicode()[item->from-1].isMark()))
+ properties[0] &= ~InitProperty;
+
+ // Nukta always applies
+ // Akhant
+ for (i = 0; i <= base; ++i)
+ properties[i] &= ~AkhantProperty;
+ // Reph
+ if (reph >= 0) {
+ properties[reph] &= ~RephProperty;
+ properties[reph+1] &= ~RephProperty;
+ }
+ // BelowForm
+ for (i = base+1; i < len; ++i)
+ properties[i] &= ~BelowFormProperty;
+
+ if (script == TQFont::Devanagari || script == TQFont::Gujarati) {
+ // vattu glyphs need this aswell
+ bool vattu = FALSE;
+ for (i = base-2; i > 1; --i) {
+ if (form(reordered[i]) == Consonant) {
+ vattu = (!vattu && reordered[i] == ra);
+ if (vattu) {
+ IDEBUG("forming vattu ligature at %d", i);
+ properties[i] &= ~BelowFormProperty;
+ properties[i+1] &= ~BelowFormProperty;
+ }
+ }
+ }
+ }
+ // HalfFormProperty
+ for (i = 0; i < base; ++i)
+ properties[i] &= ~HalfFormProperty;
+ if (control) {
+ for (i = 2; i < len; ++i) {
+ if (reordered[i] == 0x200d /* ZWJ */) {
+ properties[i-1] &= ~HalfFormProperty;
+ properties[i-2] &= ~HalfFormProperty;
+ } else if (reordered[i] == 0x200c /* ZWNJ */) {
+ properties[i-1] &= ~HalfFormProperty;
+ properties[i-2] &= ~HalfFormProperty;
+ }
+ }
+ }
+ // PostFormProperty
+ for (i = base+1; i < len; ++i)
+ properties[i] &= ~PostFormProperty;
+ // vattu always applies
+ // pres always applies
+ // blws always applies
+ // abvs always applies
+
+ // psts
+ // ### this looks slightly different from before, but I believe it's correct
+ if (reordered[len-1] != halant || base != len-2)
+ properties[base] &= ~PostSubstProperty;
+ for (i = base+1; i < len; ++i)
+ properties[i] &= ~PostSubstProperty;
+
+ // halant always applies
+
+#ifdef INDIC_DEBUG
+ {
+ IDEBUG("OT properties:");
+ for (int i = 0; i < len; ++i)
+ qDebug(" i: %s", ::propertiesToString(properties[i]).toLatin1().data());
+ }
+#endif
+
+ // initialize
+ item->log_clusters = clusters.data();
+ openType->tqshape(item, properties.data());
+
+ int newLen = openType->len();
+ OTL_GlyphItem otl_glyphs = openType->glyphs();
+
+ // move the left matra back to it's correct position in malayalam and tamil
+ if ((script == TQFont::Malayalam || script == TQFont::Tamil) && (form(reordered[0]) == Matra)) {
+// qDebug("reordering matra, len=%d", newLen);
+ // need to tqfind the base in the tqshaped string and move the matra there
+ int basePos = 0;
+ while (basePos < newLen && (int)otl_glyphs[basePos].cluster <= base)
+ basePos++;
+ --basePos;
+ if (basePos < newLen && basePos > 1) {
+// qDebug("moving prebase matra to position %d in syllable newlen=%d", basePos, newLen);
+ OTL_GlyphItemRec m = otl_glyphs[0];
+ --basePos;
+ for (i = 0; i < basePos; ++i)
+ otl_glyphs[i] = otl_glyphs[i+1];
+ otl_glyphs[basePos] = m;
+ }
+ }
+
+ if (!openType->positionAndAdd(item, FALSE))
+ return FALSE;
+
+ if (control) {
+ IDEBUG("found a control char in the syllable");
+ int i = 0, j = 0;
+ while (i < item->num_glyphs) {
+ if (form(reordered[otl_glyphs[i].cluster]) == Control) {
+ ++i;
+ if (i >= item->num_glyphs)
+ break;
+ }
+ item->glyphs[j] = item->glyphs[i];
+ ++i;
+ ++j;
+ }
+ item->num_glyphs = j;
+ }
+
+ }
+#endif
+
+ item->attributes[0].clusterStart = TRUE;
+ IDEBUG("<<<<<<");
+ return TRUE;
+}
+
+
+/* syllables are of the form:
+
+ (Consonant Nukta? Halant)* Consonant Matra? VowelMark? StressMark?
+ (Consonant Nukta? Halant)* Consonant Halant
+ IndependentVowel VowelMark? StressMark?
+
+ We return syllable boundaries on invalid combinations aswell
+*/
+static int indic_nextSyllableBoundary(int script, const TQString &s, int start, int end, bool *invalid)
+{
+ *invalid = FALSE;
+ IDEBUG("indic_nextSyllableBoundary: start=%d, end=%d", start, end);
+ const TQChar *uc = s.tqunicode()+start;
+
+ int pos = 0;
+ Form state = form(uc[pos].tqunicode());
+ IDEBUG("state[%d]=%d (uc=%4x)", pos, state, uc[pos].tqunicode());
+ pos++;
+
+ if (state != Consonant && state != IndependentVowel) {
+ if (state != Other)
+ *invalid = TRUE;
+ goto finish;
+ }
+
+ while (pos < end - start) {
+ Form newState = form(uc[pos].tqunicode());
+ IDEBUG("state[%d]=%d (uc=%4x)", pos, newState, uc[pos].tqunicode());
+ switch(newState) {
+ case Control:
+ newState = state;
+ if (state == Halant && uc[pos].tqunicode() == 0x200d /* ZWJ */)
+ break;
+ // the control character should be the last char in the item
+ ++pos;
+ goto finish;
+ case Consonant:
+ if (state == Halant && (script != TQFont::Sinhala || uc[pos-1].tqunicode() == 0x200d /* ZWJ */))
+ break;
+ goto finish;
+ case Halant:
+ if (state == Nukta || state == Consonant)
+ break;
+ // Bengali has a special exception allowing the combination Vowel_A/E + Halant + Ya
+ if (script == TQFont::Bengali && pos == 1 &&
+ (uc[0].tqunicode() == 0x0985 || uc[0].tqunicode() == 0x098f))
+ break;
+ goto finish;
+ case Nukta:
+ if (state == Consonant)
+ break;
+ goto finish;
+ case StressMark:
+ if (state == VowelMark)
+ break;
+ // fall through
+ case VowelMark:
+ if (state == Matra || state == IndependentVowel)
+ break;
+ // fall through
+ case Matra:
+ if (state == Consonant || state == Nukta)
+ break;
+ // ### not sure if this is correct. If it is, does it apply only to Bengali or should
+ // it work for all Indic languages?
+ // the combination Independent_A + Vowel Sign AA is allowed.
+ if (script == TQFont::Bengali && uc[pos].tqunicode() == 0x9be && uc[pos-1].tqunicode() == 0x985)
+ break;
+ if (script == TQFont::Tamil && state == Matra) {
+ if (uc[pos-1].tqunicode() == 0x0bc6 &&
+ (uc[pos].tqunicode() == 0xbbe || uc[pos].tqunicode() == 0xbd7))
+ break;
+ if (uc[pos-1].tqunicode() == 0x0bc7 && uc[pos].tqunicode() == 0xbbe)
+ break;
+ }
+ goto finish;
+
+ case LengthMark:
+ case IndependentVowel:
+ case Invalid:
+ case Other:
+ goto finish;
+ }
+ state = newState;
+ pos++;
+ }
+ finish:
+ return pos+start;
+}
+
+static bool indic_tqshape(TQShaperItem *item)
+{
+ TQ_ASSERT(item->script >= TQFont::Devanagari && item->script <= TQFont::Sinhala);
+
+#ifndef TQT_NO_XFTFREETYPE
+ TQOpenType *openType = item->font->openType();
+ if (openType)
+ openType->selectScript(item->script, indic_features);
+#else
+ TQOpenType *openType = 0;
+#endif
+ unsigned short *logClusters = item->log_clusters;
+
+ TQShaperItem syllable = *item;
+ int first_glyph = 0;
+
+ int sstart = item->from;
+ int end = sstart + item->length;
+ IDEBUG("indic_tqshape: from %d length %d", item->from, item->length);
+ while (sstart < end) {
+ bool invalid;
+ int send = indic_nextSyllableBoundary(item->script, *item->string, sstart, end, &invalid);
+ IDEBUG("syllable from %d, length %d, invalid=%s", sstart, send-sstart,
+ invalid ? "TRUE" : "FALSE");
+ syllable.from = sstart;
+ syllable.length = send-sstart;
+ syllable.glyphs = item->glyphs + first_glyph;
+ syllable.offsets = item->offsets + first_glyph;
+ syllable.advances = item->advances + first_glyph;
+ syllable.attributes = item->attributes + first_glyph;
+ syllable.num_glyphs = item->num_glyphs - first_glyph;
+ if (!indic_tqshape_syllable(openType, &syllable, invalid)) {
+ IDEBUG("syllable shaping failed, syllable requests %d glyphs", syllable.num_glyphs);
+ item->num_glyphs += syllable.num_glyphs;
+ return FALSE;
+ }
+ item->has_positioning |= syllable.has_positioning;
+
+ // fix logcluster array
+ IDEBUG("syllable:");
+ int i;
+ for (i = first_glyph; i < first_glyph + syllable.num_glyphs; ++i)
+ IDEBUG(" %d -> glyph %x", i, item->glyphs[i]);
+ IDEBUG(" logclusters:");
+ for (i = sstart; i < send; ++i) {
+ IDEBUG(" %d -> glyph %d", i, first_glyph);
+ logClusters[i-item->from] = first_glyph;
+ }
+ sstart = send;
+ first_glyph += syllable.num_glyphs;
+ }
+ item->num_glyphs = first_glyph;
+ return TRUE;
+}
+
+
+static void indic_attributes(int script, const TQString &text, int from, int len, TQCharAttributes *attributes)
+{
+ int end = from + len;
+ const TQChar *uc = text.tqunicode() + from;
+ attributes += from;
+ int i = 0;
+ while (i < len) {
+ bool invalid;
+ int boundary = indic_nextSyllableBoundary(script, text, from+i, end, &invalid) - from;
+ attributes[i].charStop = TRUE;
+
+ if (boundary > len-1) boundary = len;
+ i++;
+ while (i < boundary) {
+ attributes[i].charStop = FALSE;
+ ++uc;
+ ++i;
+ }
+ assert(i == boundary);
+ }
+
+
+}
+
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Thai and Lao
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+#include <tqtextcodec.h>
+#include <tqlibrary.h>
+
+
+static void thaiWordBreaks(const TQChar *string, const int len, TQCharAttributes *attributes)
+{
+#ifndef TQT_NO_TEXTCODEC
+ typedef int (*th_brk_def)(const char*, int[], int);
+ static TQTextCodec *thaiCodec = TQTextCodec::codecForMib(2259);
+ static th_brk_def th_brk = 0;
+
+#ifndef TQT_NO_LIBRARY
+ /* load libthai dynamically */
+ if (!th_brk && thaiCodec) {
+ th_brk = (th_brk_def)TQLibrary::resolve("thai", "th_brk");
+ if (!th_brk)
+ thaiCodec = 0;
+ }
+#endif
+
+ if (!th_brk)
+ return;
+
+ TQCString cstr = thaiCodec->fromUnicode(TQConstString(string, len).string());
+
+ int brp[128];
+ int *break_positions = brp;
+ int numbreaks = th_brk(cstr.data(), break_positions, 128);
+ if (numbreaks > 128) {
+ break_positions = new int[numbreaks];
+ numbreaks = th_brk(cstr.data(),break_positions, numbreaks);
+ }
+
+ attributes[0].softBreak = TRUE;
+ int i;
+ for (i = 1; i < len; ++i)
+ attributes[i].softBreak = FALSE;
+
+ for (i = 0; i < numbreaks; ++i)
+ attributes[break_positions[i]].softBreak = TRUE;
+
+ if (break_positions != brp)
+ delete [] break_positions;
+#endif
+}
+
+
+static void thai_attributes( int script, const TQString &text, int from, int len, TQCharAttributes *attributes )
+{
+ TQ_UNUSED(script);
+ TQ_ASSERT(script == TQFont::Thai);
+ thaiWordBreaks(text.tqunicode() + from, len, attributes);
+}
+
+
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Tibetan
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+// tibetan syllables are of the form:
+// head position consonant
+// first sub-joined consonant
+// ....intermediate sub-joined consonants (if any)
+// last sub-joined consonant
+// sub-joined vowel (a-chung U+0F71)
+// standard or compound vowel sign (or 'virama' for devanagari transliteration)
+
+enum TibetanForm {
+ TibetanOther,
+ TibetanHeadConsonant,
+ TibetanSubjoinedConsonant,
+ TibetanSubjoinedVowel,
+ TibetanVowel
+};
+
+// this table starts at U+0f40
+static const unsigned char tibetanForm[0x80] = {
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant, TibetanHeadConsonant,
+ TibetanOther, TibetanOther, TibetanOther, TibetanOther,
+
+ TibetanOther, TibetanVowel, TibetanVowel, TibetanVowel,
+ TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel,
+ TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel,
+ TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel,
+
+ TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel,
+ TibetanVowel, TibetanVowel, TibetanVowel, TibetanVowel,
+ TibetanOther, TibetanOther, TibetanOther, TibetanOther,
+ TibetanOther, TibetanOther, TibetanOther, TibetanOther,
+
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant, TibetanSubjoinedConsonant,
+ TibetanSubjoinedConsonant, TibetanOther, TibetanOther, TibetanOther
+};
+
+
+static inline TibetanForm tibetan_form(const TQChar &c)
+{
+ return (TibetanForm)tibetanForm[c.tqunicode() - 0x0f40];
+}
+
+#ifndef TQT_NO_XFTFREETYPE
+static const TQOpenType::Features tibetan_features[] = {
+ { FT_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty },
+ { FT_MAKE_TAG('a', 'b', 'v', 's'), AboveSubstProperty },
+ { FT_MAKE_TAG('b', 'l', 'w', 's'), BelowSubstProperty },
+ {0, 0}
+};
+#endif
+
+static bool tibetan_tqshape_syllable(TQOpenType *openType, TQShaperItem *item, bool invalid)
+{
+ TQ_UNUSED(openType)
+ int len = item->length;
+
+ if (item->num_glyphs < item->length + 4) {
+ item->num_glyphs = item->length + 4;
+ return FALSE;
+ }
+
+ int i;
+ TQVarLengthArray<unsigned short> reordered(len+4);
+
+ const TQChar *str = item->string->tqunicode() + item->from;
+ if (invalid) {
+ *reordered.data() = 0x25cc;
+ memcpy(reordered.data()+1, str, len*sizeof(TQChar));
+ len++;
+ str = (TQChar *)reordered.data();
+ }
+
+ if (item->font->stringToCMap(str, len, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+
+ for (i = 0; i < item->length; i++) {
+ item->attributes[i].mark = FALSE;
+ item->attributes[i].clusterStart = FALSE;
+ item->attributes[i].justification = 0;
+ item->attributes[i].zeroWidth = FALSE;
+ IDEBUG(" %d: %4x", i, str[i].tqunicode());
+ }
+
+ // now we have the syllable in the right order, and can start running it through open type.
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (openType && openType->supportsScript(TQFont::Tibetan)) {
+ openType->selectScript(TQFont::Tibetan, tibetan_features);
+
+ openType->tqshape(item);
+ if (!openType->positionAndAdd(item, FALSE))
+ return FALSE;
+ }
+#endif
+
+ item->attributes[0].clusterStart = TRUE;
+ return TRUE;
+}
+
+
+static int tibetan_nextSyllableBoundary(const TQString &s, int start, int end, bool *invalid)
+{
+ const TQChar *uc = s.tqunicode() + start;
+
+ int pos = 0;
+ TibetanForm state = tibetan_form(*uc);
+
+// qDebug("state[%d]=%d (uc=%4x)", pos, state, uc[pos].tqunicode());
+ pos++;
+
+ if (state != TibetanHeadConsonant) {
+ if (state != TibetanOther)
+ *invalid = TRUE;
+ goto finish;
+ }
+
+ while (pos < end - start) {
+ TibetanForm newState = tibetan_form(uc[pos]);
+ switch(newState) {
+ case TibetanSubjoinedConsonant:
+ case TibetanSubjoinedVowel:
+ if (state != TibetanHeadConsonant &&
+ state != TibetanSubjoinedConsonant)
+ goto finish;
+ state = newState;
+ break;
+ case TibetanVowel:
+ if (state != TibetanHeadConsonant &&
+ state != TibetanSubjoinedConsonant &&
+ state != TibetanSubjoinedVowel)
+ goto finish;
+ break;
+ case TibetanOther:
+ case TibetanHeadConsonant:
+ goto finish;
+ }
+ pos++;
+ }
+
+finish:
+ *invalid = FALSE;
+ return start+pos;
+}
+
+static bool tibetan_tqshape(TQShaperItem *item)
+{
+ TQ_ASSERT(item->script == TQFont::Tibetan);
+
+#ifndef TQT_NO_XFTFREETYPE
+ TQOpenType *openType = item->font->openType();
+ if (openType && !openType->supportsScript(item->script))
+ openType = 0;
+#else
+ TQOpenType *openType = 0;
+#endif
+ unsigned short *logClusters = item->log_clusters;
+
+ TQShaperItem syllable = *item;
+ int first_glyph = 0;
+
+ int sstart = item->from;
+ int end = sstart + item->length;
+ while (sstart < end) {
+ bool invalid;
+ int send = tibetan_nextSyllableBoundary(*(item->string), sstart, end, &invalid);
+ IDEBUG("syllable from %d, length %d, invalid=%s", sstart, send-sstart,
+ invalid ? "TRUE" : "FALSE");
+ syllable.from = sstart;
+ syllable.length = send-sstart;
+ syllable.glyphs = item->glyphs + first_glyph;
+ syllable.offsets = item->offsets + first_glyph;
+ syllable.advances = item->advances + first_glyph;
+ syllable.attributes = item->attributes + first_glyph;
+ syllable.num_glyphs = item->num_glyphs - first_glyph;
+ if (!tibetan_tqshape_syllable(openType, &syllable, invalid)) {
+ item->num_glyphs += syllable.num_glyphs;
+ return FALSE;
+ }
+ item->has_positioning |= syllable.has_positioning;
+
+ // fix logcluster array
+ for (int i = sstart; i < send; ++i)
+ logClusters[i-item->from] = first_glyph;
+ sstart = send;
+ first_glyph += syllable.num_glyphs;
+ }
+ item->num_glyphs = first_glyph;
+ return TRUE;
+}
+
+static void tibetan_attributes(int script, const TQString &text, int from, int len, TQCharAttributes *attributes)
+{
+ TQ_UNUSED(script);
+
+ int end = from + len;
+ const TQChar *uc = text.tqunicode() + from;
+ attributes += from;
+ int i = 0;
+ while (i < len) {
+ bool invalid;
+ int boundary = tibetan_nextSyllableBoundary(text, from+i, end, &invalid) - from;
+
+ attributes[i].charStop = TRUE;
+
+ if (boundary > len-1) boundary = len;
+ i++;
+ while (i < boundary) {
+ attributes[i].charStop = FALSE;
+ ++uc;
+ ++i;
+ }
+ assert(i == boundary);
+ }
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Khmer
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+
+// Vocabulary
+// Base -> A consonant or an independent vowel in its full (not subscript) form. It is the
+// center of the syllable, it can be surrounded by coeng (subscript) consonants, vowels,
+// split vowels, signs... but there is only one base in a syllable, it has to be coded as
+// the first character of the syllable.
+// split vowel --> vowel that has two parts placed separately (e.g. Before and after the consonant).
+// Khmer language has five of them. Khmer split vowels either have one part before the
+// base and one after the base or they have a part before the base and a part above the base.
+// The first part of all Khmer split vowels is the same character, identical to
+// the glyph of Khmer dependent vowel SRA EI
+// coeng --> modifier used in Khmer to construct coeng (subscript) consonants
+// Differently than indian languages, the coeng modifies the consonant that follows it,
+// not the one preceding it Each consonant has two forms, the base form and the subscript form
+// the base form is the normal one (using the consonants code-point), the subscript form is
+// displayed when the combination coeng + consonant is encountered.
+// Consonant of type 1 -> A consonant which has subscript for that only occupies space under a base consonant
+// Consonant of type 2.-> Its subscript form occupies space under and before the base (only one, RO)
+// Consonant of Type 3 -> Its subscript form occupies space under and after the base (KHO, CHHO, THHO, BA, YO, SA)
+// Consonant shifter -> Khmer has to series of consonants. The same dependent vowel has different sounds
+// if it is attached to a consonant of the first series or a consonant of the second series
+// Most consonants have an equivalent in the other series, but some of theme exist only in
+// one series (for example SA). If we want to use the consonant SA with a vowel sound that
+// can only be done with a vowel sound that corresponds to a vowel accompanying a consonant
+// of the other series, then we need to use a consonant shifter: TRIISAP or MUSIKATOAN
+// x17C9 y x17CA. TRIISAP changes a first series consonant to second series sound and
+// MUSIKATOAN a second series consonant to have a first series vowel sound.
+// Consonant shifter are both normally supercript marks, but, when they are followed by a
+// superscript, they change tqshape and take the form of subscript dependent vowel SRA U.
+// If they are in the same syllable as a coeng consonant, Unicode 3.0 says that they
+// should be typed before the coeng. Unicode 4.0 breaks the standard and says that it should
+// be placed after the coeng consonant.
+// Dependent vowel -> In khmer dependent vowels can be placed above, below, before or after the base
+// Each vowel has its own position. Only one vowel per syllable is allowed.
+// Signs -> Khmer has above signs and post signs. Only one above sign and/or one post sign are
+// Allowed in a syllable.
+//
+//
+// order is important here! This order must be the same that is found in each horizontal
+// line in the statetable for Khmer (see khmerStateTable) .
+//
+enum KhmerCharClassValues {
+ CC_RESERVED = 0,
+ CC_CONSONANT = 1, // Consonant of type 1 or independent vowel
+ CC_CONSONANT2 = 2, // Consonant of type 2
+ CC_CONSONANT3 = 3, // Consonant of type 3
+ CC_ZERO_WIDTH_NJ_MARK = 4, // Zero Width non joiner character (0x200C)
+ CC_CONSONANT_SHIFTER = 5,
+ CC_ROBAT = 6, // Khmer special diacritic accent -treated differently in state table
+ CC_COENG = 7, // Subscript consonant combining character
+ CC_DEPENDENT_VOWEL = 8,
+ CC_SIGN_ABOVE = 9,
+ CC_SIGN_AFTER = 10,
+ CC_ZERO_WIDTH_J_MARK = 11, // Zero width joiner character
+ CC_COUNT = 12 // This is the number of character classes
+};
+
+
+enum KhmerCharClassFlags {
+ CF_CLASS_MASK = 0x0000FFFF,
+
+ CF_CONSONANT = 0x01000000, // flag to speed up comparing
+ CF_SPLIT_VOWEL = 0x02000000, // flag for a split vowel -> the first part is added in front of the syllable
+ CF_DOTTED_CIRCLE = 0x04000000, // add a dotted circle if a character with this flag is the first in a syllable
+ CF_COENG = 0x08000000, // flag to speed up comparing
+ CF_SHIFTER = 0x10000000, // flag to speed up comparing
+ CF_ABOVE_VOWEL = 0x20000000, // flag to speed up comparing
+
+ // position flags
+ CF_POS_BEFORE = 0x00080000,
+ CF_POS_BELOW = 0x00040000,
+ CF_POS_ABOVE = 0x00020000,
+ CF_POS_AFTER = 0x00010000,
+ CF_POS_MASK = 0x000f0000
+};
+
+
+// Characters that get refered to by name
+enum KhmerChar {
+ C_SIGN_ZWNJ = 0x200C,
+ C_SIGN_ZWJ = 0x200D,
+ C_DOTTED_CIRCLE = 0x25CC,
+ C_RO = 0x179A,
+ C_VOWEL_AA = 0x17B6,
+ C_SIGN_NIKAHIT = 0x17C6,
+ C_VOWEL_E = 0x17C1,
+ C_COENG = 0x17D2
+};
+
+
+// simple classes, they are used in the statetable (in this file) to control the length of a syllable
+// they are also used to know where a character should be placed (location in reference to the base character)
+// and also to know if a character, when independently displayed, should be displayed with a dotted-circle to
+// indicate error in syllable construction
+//
+enum {
+ _xx = CC_RESERVED,
+ _sa = CC_SIGN_ABOVE | CF_DOTTED_CIRCLE | CF_POS_ABOVE,
+ _sp = CC_SIGN_AFTER | CF_DOTTED_CIRCLE| CF_POS_AFTER,
+ _c1 = CC_CONSONANT | CF_CONSONANT,
+ _c2 = CC_CONSONANT2 | CF_CONSONANT,
+ _c3 = CC_CONSONANT3 | CF_CONSONANT,
+ _rb = CC_ROBAT | CF_POS_ABOVE | CF_DOTTED_CIRCLE,
+ _cs = CC_CONSONANT_SHIFTER | CF_DOTTED_CIRCLE | CF_SHIFTER,
+ _dl = CC_DEPENDENT_VOWEL | CF_POS_BEFORE | CF_DOTTED_CIRCLE,
+ _db = CC_DEPENDENT_VOWEL | CF_POS_BELOW | CF_DOTTED_CIRCLE,
+ _da = CC_DEPENDENT_VOWEL | CF_POS_ABOVE | CF_DOTTED_CIRCLE | CF_ABOVE_VOWEL,
+ _dr = CC_DEPENDENT_VOWEL | CF_POS_AFTER | CF_DOTTED_CIRCLE,
+ _co = CC_COENG | CF_COENG | CF_DOTTED_CIRCLE,
+
+ // split vowel
+ _va = _da | CF_SPLIT_VOWEL,
+ _vr = _dr | CF_SPLIT_VOWEL
+};
+
+
+// Character class: a character class value
+// ORed with character class flags.
+//
+typedef unsigned long KhmerCharClass;
+
+
+// Character class tables
+// _xx character does not combine into syllable, such as numbers, puntuation marks, non-Khmer signs...
+// _sa Sign placed above the base
+// _sp Sign placed after the base
+// _c1 Consonant of type 1 or independent vowel (independent vowels behave as type 1 consonants)
+// _c2 Consonant of type 2 (only RO)
+// _c3 Consonant of type 3
+// _rb Khmer sign robat u17CC. combining mark for subscript consonants
+// _cd Consonant-shifter
+// _dl Dependent vowel placed before the base (left of the base)
+// _db Dependent vowel placed below the base
+// _da Dependent vowel placed above the base
+// _dr Dependent vowel placed behind the base (right of the base)
+// _co Khmer combining mark COENG u17D2, combines with the consonant or independent vowel following
+// it to create a subscript consonant or independent vowel
+// _va Khmer split vowel in wich the first part is before the base and the second one above the base
+// _vr Khmer split vowel in wich the first part is before the base and the second one behind (right of) the base
+//
+static const KhmerCharClass khmerCharClasses[] = {
+ _c1, _c1, _c1, _c3, _c1, _c1, _c1, _c1, _c3, _c1, _c1, _c1, _c1, _c3, _c1, _c1, // 1780 - 178F
+ _c1, _c1, _c1, _c1, _c3, _c1, _c1, _c1, _c1, _c3, _c2, _c1, _c1, _c1, _c3, _c3, // 1790 - 179F
+ _c1, _c3, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, _c1, // 17A0 - 17AF
+ _c1, _c1, _c1, _c1, _dr, _dr, _dr, _da, _da, _da, _da, _db, _db, _db, _va, _vr, // 17B0 - 17BF
+ _vr, _dl, _dl, _dl, _vr, _vr, _sa, _sp, _sp, _cs, _cs, _sa, _rb, _sa, _sa, _sa, // 17C0 - 17CF
+ _sa, _sa, _co, _sa, _xx, _xx, _xx, _xx, _xx, _xx, _xx, _xx, _xx, _sa, _xx, _xx // 17D0 - 17DF
+};
+
+// this enum must reflect the range of khmerCharClasses
+enum KhmerCharClassesRange {
+ KhmerFirstChar = 0x1780,
+ KhmerLastChar = 0x17df
+};
+
+// Below we define how a character in the input string is either in the khmerCharClasses table
+// (in which case we get its type back), a ZWJ or ZWNJ (two characters that may appear
+// within the syllable, but are not in the table) we also get their type back, or an unknown object
+// in which case we get _xx (CC_RESERVED) back
+//
+static inline KhmerCharClass getKhmerCharClass(const TQChar &uc)
+{
+ if (uc.tqunicode() == C_SIGN_ZWJ) {
+ return CC_ZERO_WIDTH_J_MARK;
+ }
+
+ if (uc.tqunicode() == C_SIGN_ZWNJ) {
+ return CC_ZERO_WIDTH_NJ_MARK;
+ }
+
+ if (uc.tqunicode() < KhmerFirstChar || uc.tqunicode() > KhmerLastChar) {
+ return CC_RESERVED;
+ }
+
+ return khmerCharClasses[uc.tqunicode() - KhmerFirstChar];
+}
+
+
+// The stateTable is used to calculate the end (the length) of a well
+// formed Khmer Syllable.
+//
+// Each horizontal line is ordered exactly the same way as the values in KhmerClassTable
+// CharClassValues. This coincidence of values allows the follow up of the table.
+//
+// Each line corresponds to a state, which does not necessarily need to be a type
+// of component... for example, state 2 is a base, with is always a first character
+// in the syllable, but the state could be produced a consonant of any type when
+// it is the first character that is analysed (in ground state).
+//
+// Differentiating 3 types of consonants is necessary in order to
+// forbid the use of certain combinations, such as having a second
+// coeng after a coeng RO,
+// The inexistent possibility of having a type 3 after another type 3 is permitted,
+// eliminating it would very much complicate the table, and it does not create typing
+// problems, as the case above.
+//
+// The table is quite complex, in order to limit the number of coeng consonants
+// to 2 (by means of the table).
+//
+// There a peculiarity, as far as Unicode is concerned:
+// - The consonant-shifter is considered in two possible different
+// locations, the one considered in Unicode 3.0 and the one considered in
+// Unicode 4.0. (there is a backwards compatibility problem in this standard).
+//
+//
+// xx independent character, such as a number, punctuation sign or non-khmer char
+//
+// c1 Khmer consonant of type 1 or an independent vowel
+// that is, a letter in which the subscript for is only under the
+// base, not taking any space to the right or to the left
+//
+// c2 Khmer consonant of type 2, the coeng form takes space under
+// and to the left of the base (only RO is of this type)
+//
+// c3 Khmer consonant of type 3. Its subscript form takes space under
+// and to the right of the base.
+//
+// cs Khmer consonant shifter
+//
+// rb Khmer robat
+//
+// co coeng character (u17D2)
+//
+// dv dependent vowel (including split vowels, they are treated in the same way).
+// even if dv is not defined above, the component that is really tested for is
+// KhmerClassTable::CC_DEPENDENT_VOWEL, which is common to all dependent vowels
+//
+// zwj Zero Width joiner
+//
+// zwnj Zero width non joiner
+//
+// sa above sign
+//
+// sp post sign
+//
+// there are lines with equal content but for an easier understanding
+// (and maybe change in the future) we did not join them
+//
+static const signed char khmerStateTable[][CC_COUNT] =
+{
+ // xx c1 c2 c3 zwnj cs rb co dv sa sp zwj
+ { 1, 2, 2, 2, 1, 1, 1, 6, 1, 1, 1, 2}, // 0 - ground state
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 1 - exit state (or sign to the right of the syllable)
+ {-1, -1, -1, -1, 3, 4, 5, 6, 16, 17, 1, -1}, // 2 - Base consonant
+ {-1, -1, -1, -1, -1, 4, -1, -1, 16, -1, -1, -1}, // 3 - First ZWNJ before a register shifter It can only be followed by a shifter or a vowel
+ {-1, -1, -1, -1, 15, -1, -1, 6, 16, 17, 1, 14}, // 4 - First register shifter
+ {-1, -1, -1, -1, -1, -1, -1, -1, 20, -1, 1, -1}, // 5 - Robat
+ {-1, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1}, // 6 - First Coeng
+ {-1, -1, -1, -1, 12, 13, -1, 10, 16, 17, 1, 14}, // 7 - First consonant of type 1 after coeng
+ {-1, -1, -1, -1, 12, 13, -1, -1, 16, 17, 1, 14}, // 8 - First consonant of type 2 after coeng
+ {-1, -1, -1, -1, 12, 13, -1, 10, 16, 17, 1, 14}, // 9 - First consonant or type 3 after ceong
+ {-1, 11, 11, 11, -1, -1, -1, -1, -1, -1, -1, -1}, // 10 - Second Coeng (no register shifter before)
+ {-1, -1, -1, -1, 15, -1, -1, -1, 16, 17, 1, 14}, // 11 - Second coeng consonant (or ind. vowel) no register shifter before
+ {-1, -1, -1, -1, -1, 13, -1, -1, 16, -1, -1, -1}, // 12 - Second ZWNJ before a register shifter
+ {-1, -1, -1, -1, 15, -1, -1, -1, 16, 17, 1, 14}, // 13 - Second register shifter
+ {-1, -1, -1, -1, -1, -1, -1, -1, 16, -1, -1, -1}, // 14 - ZWJ before vowel
+ {-1, -1, -1, -1, -1, -1, -1, -1, 16, -1, -1, -1}, // 15 - ZWNJ before vowel
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 1, 18}, // 16 - dependent vowel
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 18}, // 17 - sign above
+ {-1, -1, -1, -1, -1, -1, -1, 19, -1, -1, -1, -1}, // 18 - ZWJ after vowel
+ {-1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1}, // 19 - Third coeng
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1}, // 20 - dependent vowel after a Robat
+};
+
+
+// #define KHMER_DEBUG
+#ifdef KHMER_DEBUG
+#define KHDEBUG qDebug
+#else
+#define KHDEBUG if(0) qDebug
+#endif
+
+// Given an input string of characters and a location in which to start looking
+// calculate, using the state table, which one is the last character of the syllable
+// that starts in the starting position.
+//
+static inline int khmer_nextSyllableBoundary(const TQString &s, int start, int end, bool *invalid)
+{
+ *invalid = FALSE;
+ const TQChar *uc = s.tqunicode() + start;
+ int state = 0;
+ int pos = start;
+
+ while (pos < end) {
+ KhmerCharClass charClass = getKhmerCharClass(*uc);
+ if (pos == start) {
+ *invalid = (charClass > 0) && ! (charClass & CF_CONSONANT);
+ }
+ state = khmerStateTable[state][charClass & CF_CLASS_MASK];
+
+ KHDEBUG("state[%d]=%d class=%8lx (uc=%4x)", pos - start, state,
+ charClass, uc->tqunicode() );
+
+ if (state < 0) {
+ break;
+ }
+ ++uc;
+ ++pos;
+ }
+ return pos;
+}
+
+
+#ifndef TQT_NO_XFTFREETYPE
+static const TQOpenType::Features khmer_features[] = {
+ { FT_MAKE_TAG( 'p', 'r', 'e', 'f' ), PreFormProperty },
+ { FT_MAKE_TAG( 'b', 'l', 'w', 'f' ), BelowFormProperty },
+ { FT_MAKE_TAG( 'a', 'b', 'v', 'f' ), AboveFormProperty },
+ { FT_MAKE_TAG( 'p', 's', 't', 'f' ), PostFormProperty },
+ { FT_MAKE_TAG( 'p', 'r', 'e', 's' ), PreSubstProperty },
+ { FT_MAKE_TAG( 'b', 'l', 'w', 's' ), BelowSubstProperty },
+ { FT_MAKE_TAG( 'a', 'b', 'v', 's' ), AboveSubstProperty },
+ { FT_MAKE_TAG( 'p', 's', 't', 's' ), PostSubstProperty },
+ { FT_MAKE_TAG( 'c', 'l', 'i', 'g' ), CligProperty },
+ { 0, 0 }
+};
+#endif
+
+
+static bool khmer_tqshape_syllable(TQOpenType *openType, TQShaperItem *item)
+{
+#ifndef TQT_NO_XFTFREETYPE
+ if (openType)
+ openType->selectScript(TQFont::Khmer, khmer_features);
+#endif
+ // according to the specs this is the max length one can get
+ // ### the real value should be smaller
+ assert(item->length < 13);
+
+ KHDEBUG("syllable from %d len %d, str='%s'", item->from, item->length,
+ item->string->mid(item->from, item->length).utf8().data());
+
+ int len = 0;
+ int syllableEnd = item->from + item->length;
+ unsigned short reordered[16];
+ unsigned char properties[16];
+ enum {
+ AboveForm = 0x01,
+ PreForm = 0x02,
+ PostForm = 0x04,
+ BelowForm = 0x08
+ };
+ memset(properties, 0, 16*sizeof(unsigned char));
+
+#ifdef KHMER_DEBUG
+ qDebug("original:");
+ for (int i = from; i < syllableEnd; i++) {
+ qDebug(" %d: %4x", i, string[i].tqunicode());
+ }
+#endif
+
+ // write a pre vowel or the pre part of a split vowel first
+ // and look out for coeng + ro. RO is the only vowel of type 2, and
+ // therefore the only one that requires saving space before the base.
+ //
+ int coengRo = -1; // There is no Coeng Ro, if found this value will change
+ int i;
+ for (i = item->from; i < syllableEnd; i += 1) {
+ KhmerCharClass charClass = getKhmerCharClass(item->string->at(i));
+
+ // if a split vowel, write the pre part. In Khmer the pre part
+ // is the same for all split vowels, same glyph as pre vowel C_VOWEL_E
+ if (charClass & CF_SPLIT_VOWEL) {
+ reordered[len] = C_VOWEL_E;
+ properties[len] = PreForm;
+ ++len;
+ break; // there can be only one vowel
+ }
+ // if a vowel with pos before write it out
+ if (charClass & CF_POS_BEFORE) {
+ reordered[len] = item->string->at(i).tqunicode();
+ properties[len] = PreForm;
+ ++len;
+ break; // there can be only one vowel
+ }
+ // look for coeng + ro and remember position
+ // works because coeng + ro is always in front of a vowel (if there is a vowel)
+ // and because CC_CONSONANT2 is enough to identify it, as it is the only consonant
+ // with this flag
+ if ( (charClass & CF_COENG) && (i + 1 < syllableEnd) &&
+ ( (getKhmerCharClass(item->string->at(i+1)) & CF_CLASS_MASK) == CC_CONSONANT2) ) {
+ coengRo = i;
+ }
+ }
+
+ // write coeng + ro if found
+ if (coengRo > -1) {
+ reordered[len] = C_COENG;
+ properties[len] = PreForm;
+ ++len;
+ reordered[len] = C_RO;
+ properties[len] = PreForm;
+ ++len;
+ }
+
+ // shall we add a dotted circle?
+ // If in the position in which the base should be (first char in the string) there is
+ // a character that has the Dotted circle flag (a character that cannot be a base)
+ // then write a dotted circle
+ if (getKhmerCharClass(item->string->at(item->from)) & CF_DOTTED_CIRCLE) {
+ reordered[len] = C_DOTTED_CIRCLE;
+ ++len;
+ }
+
+ // copy what is left to the output, skipping before vowels and
+ // coeng Ro if they are present
+ for (i = item->from; i < syllableEnd; i += 1) {
+ TQChar uc = item->string->at(i);
+ KhmerCharClass charClass = getKhmerCharClass(uc);
+
+ // skip a before vowel, it was already processed
+ if (charClass & CF_POS_BEFORE) {
+ continue;
+ }
+
+ // skip coeng + ro, it was already processed
+ if (i == coengRo) {
+ i += 1;
+ continue;
+ }
+
+ switch (charClass & CF_POS_MASK)
+ {
+ case CF_POS_ABOVE :
+ reordered[len] = uc.tqunicode();
+ properties[len] = AboveForm;
+ ++len;
+ break;
+
+ case CF_POS_AFTER :
+ reordered[len] = uc.tqunicode();
+ properties[len] = PostForm;
+ ++len;
+ break;
+
+ case CF_POS_BELOW :
+ reordered[len] = uc.tqunicode();
+ properties[len] = BelowForm;
+ ++len;
+ break;
+
+ default:
+ // assign the correct flags to a coeng consonant
+ // Consonants of type 3 are taged as Post forms and those type 1 as below forms
+ if ( (charClass & CF_COENG) && i + 1 < syllableEnd ) {
+ unsigned char property = (getKhmerCharClass(item->string->at(i+1)) & CF_CLASS_MASK) == CC_CONSONANT3 ?
+ PostForm : BelowForm;
+ reordered[len] = uc.tqunicode();
+ properties[len] = property;
+ ++len;
+ i += 1;
+ reordered[len] = item->string->at(i).tqunicode();
+ properties[len] = property;
+ ++len;
+ break;
+ }
+
+ // if a shifter is followed by an above vowel change the shifter to below form,
+ // an above vowel can have two possible positions i + 1 or i + 3
+ // (position i+1 corresponds to tqunicode 3, position i+3 to Unicode 4)
+ // and there is an extra rule for C_VOWEL_AA + C_SIGN_NIKAHIT also for two
+ // different positions, right after the shifter or after a vowel (Unicode 4)
+ if ( (charClass & CF_SHIFTER) && (i + 1 < syllableEnd) ) {
+ if (getKhmerCharClass(item->string->at(i+1)) & CF_ABOVE_VOWEL ) {
+ reordered[len] = uc.tqunicode();
+ properties[len] = BelowForm;
+ ++len;
+ break;
+ }
+ if (i + 2 < syllableEnd &&
+ (item->string->at(i+1).tqunicode() == C_VOWEL_AA) &&
+ (item->string->at(i+2).tqunicode() == C_SIGN_NIKAHIT) )
+ {
+ reordered[len] = uc.tqunicode();
+ properties[len] = BelowForm;
+ ++len;
+ break;
+ }
+ if (i + 3 < syllableEnd && (getKhmerCharClass(item->string->at(i+3)) & CF_ABOVE_VOWEL) ) {
+ reordered[len] = uc.tqunicode();
+ properties[len] = BelowForm;
+ ++len;
+ break;
+ }
+ if (i + 4 < syllableEnd &&
+ (item->string->at(i+3).tqunicode() == C_VOWEL_AA) &&
+ (item->string->at(i+4).tqunicode() == C_SIGN_NIKAHIT) )
+ {
+ reordered[len] = uc.tqunicode();
+ properties[len] = BelowForm;
+ ++len;
+ break;
+ }
+ }
+
+ // default - any other characters
+ reordered[len] = uc.tqunicode();
+ ++len;
+ break;
+ } // switch
+ } // for
+
+ if (item->font->stringToCMap((const TQChar *)reordered, len, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+
+ KHDEBUG("after shaping: len=%d", len);
+ for (i = 0; i < len; i++) {
+ item->attributes[i].mark = FALSE;
+ item->attributes[i].clusterStart = FALSE;
+ item->attributes[i].justification = 0;
+ item->attributes[i].zeroWidth = FALSE;
+ KHDEBUG(" %d: %4x property=%x", i, reordered[i], properties[i]);
+ }
+
+ // now we have the syllable in the right order, and can start running it through open type.
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (openType) {
+ unsigned short logClusters[16];
+ for (int i = 0; i < len; ++i)
+ logClusters[i] = i;
+
+ uint where[16];
+
+ for (int i = 0; i < len; ++i) {
+ where[i] = ~(PreSubstProperty
+ | BelowSubstProperty
+ | AboveSubstProperty
+ | PostSubstProperty
+ | CligProperty
+ | PositioningProperties);
+ if (properties[i] == PreForm)
+ where[i] &= ~PreFormProperty;
+ else if (properties[i] == BelowForm)
+ where[i] &= ~BelowFormProperty;
+ else if (properties[i] == AboveForm)
+ where[i] &= ~AboveFormProperty;
+ else if (properties[i] == PostForm)
+ where[i] &= ~PostFormProperty;
+ }
+
+ openType->tqshape(item, where);
+ if (!openType->positionAndAdd(item, FALSE))
+ return FALSE;
+ } else
+#endif
+ {
+ KHDEBUG("Not using openType");
+ TQ_UNUSED(openType);
+ }
+
+ item->attributes[0].clusterStart = TRUE;
+ return TRUE;
+}
+
+static bool khmer_tqshape(TQShaperItem *item)
+{
+ assert(item->script == TQFont::Khmer);
+
+#ifndef TQT_NO_XFTFREETYPE
+ TQOpenType *openType = item->font->openType();
+ if (openType && !openType->supportsScript(item->script))
+ openType = 0;
+#else
+ TQOpenType *openType = 0;
+#endif
+ unsigned short *logClusters = item->log_clusters;
+
+ TQShaperItem syllable = *item;
+ int first_glyph = 0;
+
+ int sstart = item->from;
+ int end = sstart + item->length;
+ KHDEBUG("khmer_tqshape: from %d length %d", item->from, item->length);
+ while (sstart < end) {
+ bool invalid;
+ int send = khmer_nextSyllableBoundary(*item->string, sstart, end, &invalid);
+ KHDEBUG("syllable from %d, length %d, invalid=%s", sstart, send-sstart,
+ invalid ? "TRUE" : "FALSE");
+ syllable.from = sstart;
+ syllable.length = send-sstart;
+ syllable.glyphs = item->glyphs + first_glyph;
+ syllable.offsets = item->offsets + first_glyph;
+ syllable.advances = item->advances + first_glyph;
+ syllable.attributes = item->attributes + first_glyph;
+ syllable.num_glyphs = item->num_glyphs - first_glyph;
+ if (!khmer_tqshape_syllable(openType, &syllable)) {
+ KHDEBUG("syllable shaping failed, syllable requests %d glyphs", syllable.num_glyphs);
+ item->num_glyphs += syllable.num_glyphs;
+ return FALSE;
+ }
+ item->has_positioning |= syllable.has_positioning;
+
+ // fix logcluster array
+ KHDEBUG("syllable:");
+ int i;
+ for (i = first_glyph; i < first_glyph + syllable.num_glyphs; ++i)
+ KHDEBUG(" %d -> glyph %x", i, item->glyphs[i]);
+ KHDEBUG(" logclusters:");
+ for (i = sstart; i < send; ++i) {
+ KHDEBUG(" %d -> glyph %d", i, first_glyph);
+ logClusters[i-item->from] = first_glyph;
+ }
+ sstart = send;
+ first_glyph += syllable.num_glyphs;
+ }
+ item->num_glyphs = first_glyph;
+ return TRUE;
+}
+
+static void khmer_attributes( int script, const TQString &text, int from, int len, TQCharAttributes *attributes )
+{
+ TQ_UNUSED(script);
+
+ int end = from + len;
+ const TQChar *uc = text.tqunicode() + from;
+ attributes += from;
+ int i = 0;
+ while ( i < len ) {
+ bool invalid;
+ int boundary = khmer_nextSyllableBoundary( text, from+i, end, &invalid ) - from;
+
+ attributes[i].charStop = TRUE;
+
+ if ( boundary > len-1 ) boundary = len;
+ i++;
+ while ( i < boundary ) {
+ attributes[i].charStop = FALSE;
+ ++uc;
+ ++i;
+ }
+ assert( i == boundary );
+ }
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Myanmar
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+enum MymrCharClassValues
+{
+ Mymr_CC_RESERVED = 0,
+ Mymr_CC_CONSONANT = 1, /* Consonant of type 1, that has subscript form */
+ Mymr_CC_CONSONANT2 = 2, /* Consonant of type 2, that has no subscript form */
+ Mymr_CC_NGA = 3, /* Consonant NGA */
+ Mymr_CC_YA = 4, /* Consonant YA */
+ Mymr_CC_RA = 5, /* Consonant RA */
+ Mymr_CC_WA = 6, /* Consonant WA */
+ Mymr_CC_HA = 7, /* Consonant HA */
+ Mymr_CC_IND_VOWEL = 8, /* Independent vowel */
+ Mymr_CC_ZERO_WIDTH_NJ_MARK = 9, /* Zero Width non joiner character (0x200C) */
+ Mymr_CC_VIRAMA = 10, /* Subscript consonant combining character */
+ Mymr_CC_PRE_VOWEL = 11, /* Dependent vowel, prebase (Vowel e) */
+ Mymr_CC_BELOW_VOWEL = 12, /* Dependent vowel, prebase (Vowel u, uu) */
+ Mymr_CC_ABOVE_VOWEL = 13, /* Dependent vowel, prebase (Vowel i, ii, ai) */
+ Mymr_CC_POST_VOWEL = 14, /* Dependent vowel, prebase (Vowel aa) */
+ Mymr_CC_SIGN_ABOVE = 15,
+ Mymr_CC_SIGN_BELOW = 16,
+ Mymr_CC_SIGN_AFTER = 17,
+ Mymr_CC_ZERO_WIDTH_J_MARK = 18, /* Zero width joiner character */
+ Mymr_CC_COUNT = 19 /* This is the number of character classes */
+};
+
+enum MymrCharClassFlags
+{
+ Mymr_CF_CLASS_MASK = 0x0000FFFF,
+
+ Mymr_CF_CONSONANT = 0x01000000, /* flag to speed up comparing */
+ Mymr_CF_MEDIAL = 0x02000000, /* flag to speed up comparing */
+ Mymr_CF_IND_VOWEL = 0x04000000, /* flag to speed up comparing */
+ Mymr_CF_DEP_VOWEL = 0x08000000, /* flag to speed up comparing */
+ Mymr_CF_DOTTED_CIRCLE = 0x10000000, /* add a dotted circle if a character with this flag is the first in a syllable */
+ Mymr_CF_VIRAMA = 0x20000000, /* flag to speed up comparing */
+
+ /* position flags */
+ Mymr_CF_POS_BEFORE = 0x00080000,
+ Mymr_CF_POS_BELOW = 0x00040000,
+ Mymr_CF_POS_ABOVE = 0x00020000,
+ Mymr_CF_POS_AFTER = 0x00010000,
+ Mymr_CF_POS_MASK = 0x000f0000,
+
+ Mymr_CF_AFTER_KINZI = 0x00100000
+};
+
+/* Characters that get refrered to by name */
+enum MymrChar
+{
+ Mymr_C_SIGN_ZWNJ = 0x200C,
+ Mymr_C_SIGN_ZWJ = 0x200D,
+ Mymr_C_DOTTED_CIRCLE = 0x25CC,
+ Mymr_C_RA = 0x101B,
+ Mymr_C_YA = 0x101A,
+ Mymr_C_NGA = 0x1004,
+ Mymr_C_VOWEL_E = 0x1031,
+ Mymr_C_VIRAMA = 0x1039
+};
+
+enum
+{
+ Mymr_xx = Mymr_CC_RESERVED,
+ Mymr_c1 = Mymr_CC_CONSONANT | Mymr_CF_CONSONANT | Mymr_CF_POS_BELOW,
+ Mymr_c2 = Mymr_CC_CONSONANT2 | Mymr_CF_CONSONANT,
+ Mymr_ng = Mymr_CC_NGA | Mymr_CF_CONSONANT | Mymr_CF_POS_ABOVE,
+ Mymr_ya = Mymr_CC_YA | Mymr_CF_CONSONANT | Mymr_CF_MEDIAL | Mymr_CF_POS_AFTER | Mymr_CF_AFTER_KINZI,
+ Mymr_ra = Mymr_CC_RA | Mymr_CF_CONSONANT | Mymr_CF_MEDIAL | Mymr_CF_POS_BEFORE,
+ Mymr_wa = Mymr_CC_WA | Mymr_CF_CONSONANT | Mymr_CF_MEDIAL | Mymr_CF_POS_BELOW,
+ Mymr_ha = Mymr_CC_HA | Mymr_CF_CONSONANT | Mymr_CF_MEDIAL | Mymr_CF_POS_BELOW,
+ Mymr_id = Mymr_CC_IND_VOWEL | Mymr_CF_IND_VOWEL,
+ Mymr_vi = Mymr_CC_VIRAMA | Mymr_CF_VIRAMA | Mymr_CF_POS_ABOVE | Mymr_CF_DOTTED_CIRCLE,
+ Mymr_dl = Mymr_CC_PRE_VOWEL | Mymr_CF_DEP_VOWEL | Mymr_CF_POS_BEFORE | Mymr_CF_DOTTED_CIRCLE | Mymr_CF_AFTER_KINZI,
+ Mymr_db = Mymr_CC_BELOW_VOWEL | Mymr_CF_DEP_VOWEL | Mymr_CF_POS_BELOW | Mymr_CF_DOTTED_CIRCLE | Mymr_CF_AFTER_KINZI,
+ Mymr_da = Mymr_CC_ABOVE_VOWEL | Mymr_CF_DEP_VOWEL | Mymr_CF_POS_ABOVE | Mymr_CF_DOTTED_CIRCLE | Mymr_CF_AFTER_KINZI,
+ Mymr_dr = Mymr_CC_POST_VOWEL | Mymr_CF_DEP_VOWEL | Mymr_CF_POS_AFTER | Mymr_CF_DOTTED_CIRCLE | Mymr_CF_AFTER_KINZI,
+ Mymr_sa = Mymr_CC_SIGN_ABOVE | Mymr_CF_DOTTED_CIRCLE | Mymr_CF_POS_ABOVE | Mymr_CF_AFTER_KINZI,
+ Mymr_sb = Mymr_CC_SIGN_BELOW | Mymr_CF_DOTTED_CIRCLE | Mymr_CF_POS_BELOW | Mymr_CF_AFTER_KINZI,
+ Mymr_sp = Mymr_CC_SIGN_AFTER | Mymr_CF_DOTTED_CIRCLE | Mymr_CF_AFTER_KINZI
+};
+
+
+typedef int MymrCharClass;
+
+
+static const MymrCharClass mymrCharClasses[] =
+{
+ Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1, Mymr_ng, Mymr_c1, Mymr_c1, Mymr_c1,
+ Mymr_c1, Mymr_c1, Mymr_c2, Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1, /* 1000 - 100F */
+ Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1, Mymr_c1,
+ Mymr_c1, Mymr_c1, Mymr_ya, Mymr_ra, Mymr_c1, Mymr_wa, Mymr_c1, Mymr_ha, /* 1010 - 101F */
+ Mymr_c2, Mymr_c2, Mymr_xx, Mymr_id, Mymr_id, Mymr_id, Mymr_id, Mymr_id,
+ Mymr_xx, Mymr_id, Mymr_id, Mymr_xx, Mymr_dr, Mymr_da, Mymr_da, Mymr_db, /* 1020 - 102F */
+ Mymr_db, Mymr_dl, Mymr_da, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_sa, Mymr_sb,
+ Mymr_sp, Mymr_vi, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, /* 1030 - 103F */
+ Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx,
+ Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, /* 1040 - 104F */
+ Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx,
+ Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, Mymr_xx, /* 1050 - 105F */
+};
+
+static MymrCharClass
+getMyanmarCharClass (const TQChar &ch)
+{
+ if (ch.tqunicode() == Mymr_C_SIGN_ZWJ)
+ return Mymr_CC_ZERO_WIDTH_J_MARK;
+
+ if (ch.tqunicode() == Mymr_C_SIGN_ZWNJ)
+ return Mymr_CC_ZERO_WIDTH_NJ_MARK;
+
+ if (ch.tqunicode() < 0x1000 || ch.tqunicode() > 0x105f)
+ return Mymr_CC_RESERVED;
+
+ return mymrCharClasses[ch.tqunicode() - 0x1000];
+}
+
+static const signed char mymrStateTable[][Mymr_CC_COUNT] =
+{
+// xx c1, c2 ng ya ra wa ha id zwnj vi dl db da dr sa sb sp zwj
+ { 1, 4, 4, 2, 4, 4, 4, 4, 24, 1, 27, 17, 18, 19, 20, 21, 1, 1, 4}, // 0 - ground state
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 1 - exit state (or sp to the right of the syllable)
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 17, 18, 19, 20, 21, -1, -1, 4}, // 2 - NGA
+ {-1, 4, 4, 4, 4, 4, 4, 4, -1, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 3 - Virama after NGA
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 5, 17, 18, 19, 20, 21, 1, 1, -1}, // 4 - Base consonant
+ {-2, 6, -2, -2, 7, 8, 9, 10, -2, 23, -2, -2, -2, -2, -2, -2, -2, -2, -2}, // 5 - First virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 25, 17, 18, 19, 20, 21, -1, -1, -1}, // 6 - c1 after virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 17, 18, 19, 20, 21, -1, -1, -1}, // 7 - ya after virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 17, 18, 19, 20, 21, -1, -1, -1}, // 8 - ra after virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 17, 18, 19, 20, 21, -1, -1, -1}, // 9 - wa after virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 18, 19, 20, 21, -1, -1, -1}, // 10 - ha after virama
+ {-1, -1, -1, -1, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 11 - Virama after NGA+zwj
+ {-2, -2, -2, -2, -2, -2, 13, 14, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2}, // 12 - Second virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, 17, 18, 19, 20, 21, -1, -1, -1}, // 13 - wa after virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 18, 19, 20, 21, -1, -1, -1}, // 14 - ha after virama
+ {-2, -2, -2, -2, -2, -2, -2, 16, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2}, // 15 - Third virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 18, 19, 20, 21, -1, -1, -1}, // 16 - ha after virama
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 20, 21, 1, 1, -1}, // 17 - dl, Dependent vowel e
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 19, -1, 21, 1, 1, -1}, // 18 - db, Dependent vowel u,uu
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1}, // 19 - da, Dependent vowel i,ii,ai
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, -1, -1, -1, -1, -1, 1, 1, -1}, // 20 - dr, Dependent vowel aa
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1}, // 21 - sa, Sign anusvara
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 22 - atha
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1}, // 23 - zwnj for atha
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1}, // 24 - Independent vowel
+ {-2, -2, -2, -2, 26, 26, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2}, // 25 - Virama after subscript consonant
+ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 17, 18, 19, 20, 21, -1, 1, -1}, // 26 - ra/ya after subscript consonant + virama
+ {-1, 6, -1, -1, 7, 8, 9, 10, -1, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 27 - Virama after ground state
+// exit state -2 is for invalid order of medials and combination of invalids
+// with virama where virama should treat as start of next syllable
+};
+
+
+
+// #define MYANMAR_DEBUG
+#ifdef MYANMAR_DEBUG
+#define MMDEBUG qDebug
+#else
+#define MMDEBUG if(0) qDebug
+#endif
+
+// Given an input string of characters and a location in which to start looking
+// calculate, using the state table, which one is the last character of the syllable
+// that starts in the starting position.
+//
+static inline int myanmar_nextSyllableBoundary(const TQString &s, int start, int end, bool *invalid)
+{
+ *invalid = FALSE;
+ const TQChar *uc = s.tqunicode() + start;
+ int state = 0;
+ int pos = start;
+
+ while (pos < end) {
+ MymrCharClass charClass = getMyanmarCharClass(*uc);
+ state = mymrStateTable[state][charClass & Mymr_CF_CLASS_MASK];
+ if (pos == start)
+ *invalid = charClass & Mymr_CF_DOTTED_CIRCLE;
+
+ MMDEBUG("state[%d]=%d class=%8x (uc=%4x)", pos - start, state, charClass, uc->tqunicode() );
+
+ if (state < 0) {
+ if (state < -1)
+ --pos;
+ break;
+ }
+ ++uc;
+ ++pos;
+ }
+ return pos;
+}
+
+
+#ifndef TQT_NO_XFTFREETYPE
+// ###### might have to change order of above and below forms and substitutions,
+// but according to Unicode below comes before above
+static const TQOpenType::Features myanmar_features[] = {
+ { FT_MAKE_TAG( 'p', 'r', 'e', 'f' ), PreFormProperty },
+ { FT_MAKE_TAG( 'b', 'l', 'w', 'f' ), BelowFormProperty },
+ { FT_MAKE_TAG( 'a', 'b', 'v', 'f' ), AboveFormProperty },
+ { FT_MAKE_TAG( 'p', 's', 't', 'f' ), PostFormProperty },
+ { FT_MAKE_TAG( 'p', 'r', 'e', 's' ), PreSubstProperty },
+ { FT_MAKE_TAG( 'b', 'l', 'w', 's' ), BelowSubstProperty },
+ { FT_MAKE_TAG( 'a', 'b', 'v', 's' ), AboveSubstProperty },
+ { FT_MAKE_TAG( 'p', 's', 't', 's' ), PostSubstProperty },
+ { FT_MAKE_TAG( 'r', 'l', 'i', 'g' ), CligProperty }, // Myanmar1 uses this instead of the other features
+ { 0, 0 }
+};
+#endif
+
+
+// Visual order before shaping should be:
+//
+// [Vowel Mark E]
+// [Virama + Medial Ra]
+// [Base]
+// [Virama + Consonant]
+// [Nga + Virama] (Kinzi) ### should probably come before post forms (medial ya)
+// [Vowels]
+// [Marks]
+//
+// This means that we can keep the logical order apart from having to
+// move the pre vowel, medial ra and kinzi
+
+static bool myanmar_tqshape_syllable(TQOpenType *openType, TQShaperItem *item, bool invalid)
+{
+#ifndef TQT_NO_XFTFREETYPE
+ if (openType)
+ openType->selectScript(TQFont::Myanmar, myanmar_features);
+#endif
+ // according to the table the max length of a syllable should be around 14 chars
+ assert(item->length < 32);
+
+ MMDEBUG("\nsyllable from %d len %d, str='%s'", item->from, item->length,
+ item->string->mid(item->from, item->length).utf8().data());
+
+ const TQChar *uc = item->string->tqunicode() + item->from;
+#ifdef MYANMAR_DEBUG
+ qDebug("original:");
+ for (int i = 0; i < item->length; i++) {
+ qDebug(" %d: %4x", i, uc[i].tqunicode());
+ }
+#endif
+ int vowel_e = -1;
+ int kinzi = -1;
+ int medial_ra = -1;
+ int base = -1;
+ int i;
+ for (i = 0; i < item->length; ++i) {
+ ushort chr = uc[i].tqunicode();
+
+ if (chr == Mymr_C_VOWEL_E) {
+ vowel_e = i;
+ continue;
+ }
+ if (i == 0
+ && chr == Mymr_C_NGA
+ && i + 2 < item->length
+ && uc[i+1].tqunicode() == Mymr_C_VIRAMA) {
+ int mc = getMyanmarCharClass(uc[i+2]);
+ //MMDEBUG("maybe kinzi: mc=%x", mc);
+ if ((mc & Mymr_CF_CONSONANT) == Mymr_CF_CONSONANT) {
+ kinzi = i;
+ continue;
+ }
+ }
+ if (base >= 0
+ && chr == Mymr_C_VIRAMA
+ && i + 1 < item->length
+ && uc[i+1].tqunicode() == Mymr_C_RA) {
+ medial_ra = i;
+ continue;
+ }
+ if (base < 0)
+ base = i;
+ }
+
+ MMDEBUG("\n base=%d, vowel_e=%d, kinzi=%d, medial_ra=%d", base, vowel_e, kinzi, medial_ra);
+ int len = 0;
+ unsigned short reordered[32];
+ unsigned char properties[32];
+ enum {
+ AboveForm = 0x01,
+ PreForm = 0x02,
+ PostForm = 0x04,
+ BelowForm = 0x08
+ };
+ memset(properties, 0, 32*sizeof(unsigned char));
+
+ // write vowel_e if found
+ if (vowel_e >= 0) {
+ reordered[0] = Mymr_C_VOWEL_E;
+ len = 1;
+ }
+ // write medial_ra
+ if (medial_ra >= 0) {
+ reordered[len] = Mymr_C_VIRAMA;
+ reordered[len+1] = Mymr_C_RA;
+ properties[len] = PreForm;
+ properties[len+1] = PreForm;
+ len += 2;
+ }
+
+ // shall we add a dotted circle?
+ // If in the position in which the base should be (first char in the string) there is
+ // a character that has the Dotted circle flag (a character that cannot be a base)
+ // then write a dotted circle
+ if (invalid) {
+ reordered[len] = C_DOTTED_CIRCLE;
+ ++len;
+ }
+
+ bool lastWasVirama = FALSE;
+ int basePos = -1;
+ // copy the rest of the syllable to the output, inserting the kinzi
+ // at the correct place
+ for (i = 0; i < item->length; ++i) {
+ if (i == vowel_e)
+ continue;
+ if (i == medial_ra || i == kinzi) {
+ ++i;
+ continue;
+ }
+
+ ushort chr = uc[i].tqunicode();
+ MymrCharClass cc = getMyanmarCharClass(uc[i]);
+ if (kinzi >= 0 && i > base && (cc & Mymr_CF_AFTER_KINZI)) {
+ reordered[len] = Mymr_C_NGA;
+ reordered[len+1] = Mymr_C_VIRAMA;
+ properties[len-1] = AboveForm;
+ properties[len] = AboveForm;
+ len += 2;
+ kinzi = -1;
+ }
+
+ if (lastWasVirama) {
+ int prop = 0;
+ switch(cc & Mymr_CF_POS_MASK) {
+ case Mymr_CF_POS_BEFORE:
+ prop = PreForm;
+ break;
+ case Mymr_CF_POS_BELOW:
+ prop = BelowForm;
+ break;
+ case Mymr_CF_POS_ABOVE:
+ prop = AboveForm;
+ break;
+ case Mymr_CF_POS_AFTER:
+ prop = PostForm;
+ break;
+ default:
+ break;
+ }
+ properties[len-1] = prop;
+ properties[len] = prop;
+ if(basePos >= 0 && basePos == len-2)
+ properties[len-2] = prop;
+ }
+ lastWasVirama = (chr == Mymr_C_VIRAMA);
+ if(i == base)
+ basePos = len;
+
+ if ((chr != Mymr_C_SIGN_ZWNJ && chr != Mymr_C_SIGN_ZWJ) || !len) {
+ reordered[len] = chr;
+ ++len;
+ }
+ }
+ if (kinzi >= 0) {
+ reordered[len] = Mymr_C_NGA;
+ reordered[len+1] = Mymr_C_VIRAMA;
+ properties[len] = AboveForm;
+ properties[len+1] = AboveForm;
+ len += 2;
+ }
+
+ if (item->font->stringToCMap((const TQChar *)reordered, len, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+
+ MMDEBUG("after shaping: len=%d", len);
+ for (i = 0; i < len; i++) {
+ item->attributes[i].mark = FALSE;
+ item->attributes[i].clusterStart = FALSE;
+ item->attributes[i].justification = 0;
+ item->attributes[i].zeroWidth = FALSE;
+ MMDEBUG(" %d: %4x property=%x", i, reordered[i], properties[i]);
+ }
+
+ // now we have the syllable in the right order, and can start running it through open type.
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (openType) {
+ unsigned short logClusters[32];
+ for (int i = 0; i < len; ++i)
+ logClusters[i] = i;
+
+ uint where[32];
+
+ for (int i = 0; i < len; ++i) {
+ where[i] = ~(PreSubstProperty
+ | BelowSubstProperty
+ | AboveSubstProperty
+ | PostSubstProperty
+ | CligProperty
+ | PositioningProperties);
+ if (properties[i] == PreForm)
+ where[i] &= ~PreFormProperty;
+ else if (properties[i] == BelowForm)
+ where[i] &= ~BelowFormProperty;
+ else if (properties[i] == AboveForm)
+ where[i] &= ~AboveFormProperty;
+ else if (properties[i] == PostForm)
+ where[i] &= ~PostFormProperty;
+ }
+
+ openType->tqshape(item, where);
+ if (!openType->positionAndAdd(item, FALSE))
+ return FALSE;
+ } else
+#endif
+ {
+ MMDEBUG("Not using openType");
+ TQ_UNUSED(openType);
+ }
+
+ item->attributes[0].clusterStart = TRUE;
+ return TRUE;
+}
+
+static bool myanmar_tqshape(TQShaperItem *item)
+{
+ assert(item->script == TQFont::Myanmar);
+
+#ifndef TQT_NO_XFTFREETYPE
+ TQOpenType *openType = item->font->openType();
+ if (openType && !openType->supportsScript(item->script))
+ openType = 0;
+#else
+ TQOpenType *openType = 0;
+#endif
+ unsigned short *logClusters = item->log_clusters;
+
+ TQShaperItem syllable = *item;
+ int first_glyph = 0;
+
+ int sstart = item->from;
+ int end = sstart + item->length;
+ MMDEBUG("myanmar_tqshape: from %d length %d", item->from, item->length);
+ while (sstart < end) {
+ bool invalid;
+ int send = myanmar_nextSyllableBoundary(*item->string, sstart, end, &invalid);
+ MMDEBUG("syllable from %d, length %d, invalid=%s", sstart, send-sstart,
+ invalid ? "TRUE" : "FALSE");
+ syllable.from = sstart;
+ syllable.length = send-sstart;
+ syllable.glyphs = item->glyphs + first_glyph;
+ syllable.offsets = item->offsets + first_glyph;
+ syllable.advances = item->advances + first_glyph;
+ syllable.attributes = item->attributes + first_glyph;
+ syllable.num_glyphs = item->num_glyphs - first_glyph;
+ if (!myanmar_tqshape_syllable(openType, &syllable, invalid)) {
+ MMDEBUG("syllable shaping failed, syllable requests %d glyphs", syllable.num_glyphs);
+ item->num_glyphs += syllable.num_glyphs;
+ return FALSE;
+ }
+ item->has_positioning |= syllable.has_positioning;
+
+ // fix logcluster array
+ MMDEBUG("syllable:");
+ int i;
+ for (i = first_glyph; i < first_glyph + syllable.num_glyphs; ++i)
+ MMDEBUG(" %d -> glyph %x", i, item->glyphs[i]);
+ MMDEBUG(" logclusters:");
+ for (i = sstart; i < send; ++i) {
+ MMDEBUG(" %d -> glyph %d", i, first_glyph);
+ logClusters[i-item->from] = first_glyph;
+ }
+ sstart = send;
+ first_glyph += syllable.num_glyphs;
+ }
+ item->num_glyphs = first_glyph;
+ return TRUE;
+}
+
+static void myanmar_attributes( int script, const TQString &text, int from, int len, TQCharAttributes *attributes )
+{
+ TQ_UNUSED(script);
+
+ int end = from + len;
+ const TQChar *uc = text.tqunicode() + from;
+ attributes += from;
+ int i = 0;
+ while ( i < len ) {
+ bool invalid;
+ int boundary = myanmar_nextSyllableBoundary( text, from+i, end, &invalid ) - from;
+
+ attributes[i].charStop = TRUE;
+ attributes[i].softBreak = TRUE;
+
+ if ( boundary > len-1 ) boundary = len;
+ i++;
+ while ( i < boundary ) {
+ attributes[i].charStop = FALSE;
+ attributes[i].softBreak = FALSE;
+ ++uc;
+ ++i;
+ }
+ assert( i == boundary );
+ }
+}
+
+// --------------------------------------------------------------------------------------------------------------------------------------------
+//
+// Hangul
+//
+// --------------------------------------------------------------------------------------------------------------------------------------------
+
+// Hangul is a syllable based script. Unicode reserves a large range
+// for precomposed hangul, where syllables are already precomposed to
+// their final glyph tqshape. In addition, a so called jamo range is
+// defined, that can be used to express old Hangul. Modern hangul
+// syllables can also be expressed as jamo, and should be composed
+// into syllables. The operation is rather simple and mathematical.
+
+// Every hangul jamo is classified as being either a Leading consonant
+// (L), and intermediat Vowel (V) or a trailing consonant (T). Modern
+// hangul syllables (the ones in the precomposed area can be of type
+// LV or LVT.
+//
+// Syllable breaks do _not_ occur between:
+//
+// L L, V or precomposed
+// V, LV V, T
+// LVT, T T
+//
+// A standard syllable is of the form L+V+T*. The above rules allow
+// nonstandard syllables L*V*T*. To transform them into standard
+// syllables fill characers L_f and V_f can be inserted.
+
+enum {
+ Hangul_SBase = 0xac00,
+ Hangul_LBase = 0x1100,
+ Hangul_VBase = 0x1161,
+ Hangul_TBase = 0x11a7,
+ Hangul_SCount = 11172,
+ Hangul_LCount = 19,
+ Hangul_VCount = 21,
+ Hangul_TCount = 28,
+ Hangul_NCount = 21*28
+};
+
+static inline bool hangul_isPrecomposed(unsigned short uc) {
+ return (uc >= Hangul_SBase && uc < Hangul_SBase + Hangul_SCount);
+}
+
+static inline bool hangul_isLV(unsigned short uc) {
+ return ((uc - Hangul_SBase) % Hangul_TCount == 0);
+}
+
+enum HangulType {
+ L,
+ V,
+ T,
+ LV,
+ LVT,
+ X
+};
+
+static inline HangulType hangul_type(unsigned short uc) {
+ if (uc > Hangul_SBase && uc < Hangul_SBase + Hangul_SCount)
+ return hangul_isLV(uc) ? LV : LVT;
+ if (uc < Hangul_LBase || uc > 0x11ff)
+ return X;
+ if (uc < Hangul_VBase)
+ return L;
+ if (uc < Hangul_TBase)
+ return V;
+ return T;
+}
+
+static int hangul_nextSyllableBoundary(const TQString &s, int start, int end)
+{
+ const TQChar *uc = s.tqunicode() + start;
+
+ HangulType state = hangul_type(uc->tqunicode());
+ int pos = 1;
+
+ while (pos < end - start) {
+ HangulType newState = hangul_type(uc[pos].tqunicode());
+ switch(newState) {
+ case X:
+ goto finish;
+ case L:
+ case V:
+ case T:
+ if (state > newState)
+ goto finish;
+ state = newState;
+ break;
+ case LV:
+ if (state > L)
+ goto finish;
+ state = V;
+ break;
+ case LVT:
+ if (state > L)
+ goto finish;
+ state = T;
+ }
+ ++pos;
+ }
+
+ finish:
+ return start+pos;
+}
+
+#ifndef TQT_NO_XFTFREETYPE
+static const TQOpenType::Features hangul_features [] = {
+ { FT_MAKE_TAG('c', 'c', 'm', 'p'), CcmpProperty },
+ { FT_MAKE_TAG('l', 'j', 'm', 'o'), CcmpProperty },
+ { FT_MAKE_TAG('j', 'j', 'm', 'o'), CcmpProperty },
+ { FT_MAKE_TAG('t', 'j', 'm', 'o'), CcmpProperty },
+ { 0, 0 }
+};
+#endif
+
+static bool hangul_tqshape_syllable(TQOpenType *openType, TQShaperItem *item)
+{
+ TQ_UNUSED(openType)
+ const TQChar *ch = item->string->tqunicode() + item->from;
+
+ int i;
+ unsigned short composed = 0;
+ // see if we can compose the syllable into a modern hangul
+ if (item->length == 2) {
+ int LIndex = ch[0].tqunicode() - Hangul_LBase;
+ int VIndex = ch[1].tqunicode() - Hangul_VBase;
+ if (LIndex >= 0 && LIndex < Hangul_LCount &&
+ VIndex >= 0 && VIndex < Hangul_VCount)
+ composed = (LIndex * Hangul_VCount + VIndex) * Hangul_TCount + Hangul_SBase;
+ } else if (item->length == 3) {
+ int LIndex = ch[0].tqunicode() - Hangul_LBase;
+ int VIndex = ch[1].tqunicode() - Hangul_VBase;
+ int TIndex = ch[2].tqunicode() - Hangul_TBase;
+ if (LIndex >= 0 && LIndex < Hangul_LCount &&
+ VIndex >= 0 && VIndex < Hangul_VCount &&
+ TIndex >= 0 && TIndex < Hangul_TCount)
+ composed = (LIndex * Hangul_VCount + VIndex) * Hangul_TCount + TIndex + Hangul_SBase;
+ }
+
+
+ int len = item->length;
+ TQChar c(composed);
+
+ // ### icc says 'chars' is unused
+ // const TQChar *chars = ch;
+
+ // if we have a modern hangul use the composed form
+ if (composed) {
+ // chars = &c;
+ len = 1;
+ }
+
+ if (item->font->stringToCMap(ch, len, item->glyphs, item->advances,
+ &item->num_glyphs, item->flags & TQTextEngine::RightToLeft) != TQFontEngine::NoError)
+ return FALSE;
+ for (i = 0; i < len; i++) {
+ item->attributes[i].mark = FALSE;
+ item->attributes[i].clusterStart = FALSE;
+ item->attributes[i].justification = 0;
+ item->attributes[i].zeroWidth = FALSE;
+ IDEBUG(" %d: %4x", i, ch[i].tqunicode());
+ }
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (openType && !composed) {
+
+ TQVarLengthArray<unsigned short> logClusters(len);
+ for (i = 0; i < len; ++i)
+ logClusters[i] = i;
+ item->log_clusters = logClusters.data();
+
+ openType->tqshape(item);
+ if (!openType->positionAndAdd(item, FALSE))
+ return FALSE;
+
+ }
+#endif
+
+ item->attributes[0].clusterStart = TRUE;
+ return TRUE;
+}
+
+static bool hangul_tqshape(TQShaperItem *item)
+{
+ TQ_ASSERT(item->script == TQFont::Hangul);
+
+ const TQChar *uc = item->string->tqunicode() + item->from;
+
+ bool allPrecomposed = TRUE;
+ for (int i = 0; i < item->length; ++i) {
+ if (!hangul_isPrecomposed(uc[i].tqunicode())) {
+ allPrecomposed = FALSE;
+ break;
+ }
+ }
+
+ if (!allPrecomposed) {
+#ifndef TQT_NO_XFTFREETYPE
+ TQOpenType *openType = item->font->openType();
+ if (openType && !openType->supportsScript(item->script))
+ openType = 0;
+ if (openType)
+ openType->selectScript(TQFont::Hangul, hangul_features);
+#else
+ TQOpenType *openType = 0;
+#endif
+
+ unsigned short *logClusters = item->log_clusters;
+
+ TQShaperItem syllable = *item;
+ int first_glyph = 0;
+
+ int sstart = item->from;
+ int end = sstart + item->length;
+ while (sstart < end) {
+ int send = hangul_nextSyllableBoundary(*(item->string), sstart, end);
+
+ syllable.from = sstart;
+ syllable.length = send-sstart;
+ syllable.glyphs = item->glyphs + first_glyph;
+ syllable.offsets = item->offsets + first_glyph;
+ syllable.advances = item->advances + first_glyph;
+ syllable.attributes = item->attributes + first_glyph;
+ syllable.num_glyphs = item->num_glyphs - first_glyph;
+ if (!hangul_tqshape_syllable(openType, &syllable)) {
+ item->num_glyphs += syllable.num_glyphs;
+ return FALSE;
+ }
+ item->has_positioning |= syllable.has_positioning;
+ // fix logcluster array
+ for (int i = sstart; i < send; ++i)
+ logClusters[i-item->from] = first_glyph;
+ sstart = send;
+ first_glyph += syllable.num_glyphs;
+ }
+ item->num_glyphs = first_glyph;
+ return TRUE;
+ }
+
+ return basic_tqshape(item);
+}
+
+static void hangul_attributes(int script, const TQString &text, int from, int len, TQCharAttributes *attributes)
+{
+ TQ_UNUSED(script);
+
+ int end = from + len;
+ const TQChar *uc = text.tqunicode() + from;
+ attributes += from;
+ int i = 0;
+ while (i < len) {
+ int boundary = hangul_nextSyllableBoundary(text, from+i, end) - from;
+
+ attributes[i].charStop = TRUE;
+
+ if (boundary > len-1) boundary = len;
+ i++;
+ while (i < boundary) {
+ attributes[i].charStop = FALSE;
+ ++uc;
+ ++i;
+ }
+ assert(i == boundary);
+ }
+}
+
+// -----------------------------------------------------------------------------------------------
+//
+// The script engine jump table
+//
+// -----------------------------------------------------------------------------------------------
+
+const q_scriptEngine scriptEngines[] = {
+ // Latin,
+ { basic_tqshape, 0 },
+ // Greek,
+ { basic_tqshape, 0 },
+ // Cyrillic,
+ { basic_tqshape, 0 },
+ // Armenian,
+ { basic_tqshape, 0 },
+ // Georgian,
+ { basic_tqshape, 0 },
+ // Runic,
+ { basic_tqshape, 0 },
+ // Ogham,
+ { basic_tqshape, 0 },
+ // SpacingModifiers,
+ { basic_tqshape, 0 },
+ // CombiningMarks,
+ { basic_tqshape, 0 },
+
+ // // Middle Eastern Scripts
+ // Hebrew,
+ { hebrew_tqshape, 0 },
+ // Arabic,
+ { arabic_tqshape, 0 },
+ // Syriac,
+ { syriac_tqshape, 0 },
+ // Thaana,
+ { thaana_tqshape, 0 },
+
+ // // South and Southeast Asian Scripts
+ // Devanagari,
+ { indic_tqshape, indic_attributes },
+ // Bengali,
+ { indic_tqshape, indic_attributes },
+ // Gurmukhi,
+ { indic_tqshape, indic_attributes },
+ // Gujarati,
+ { indic_tqshape, indic_attributes },
+ // Oriya,
+ { indic_tqshape, indic_attributes },
+ // Tamil,
+ { indic_tqshape, indic_attributes },
+ // Telugu,
+ { indic_tqshape, indic_attributes },
+ // Kannada,
+ { indic_tqshape, indic_attributes },
+ // Malayalam,
+ { indic_tqshape, indic_attributes },
+ // Sinhala,
+ { indic_tqshape, indic_attributes },
+ // Thai,
+ { basic_tqshape, thai_attributes },
+ // Lao,
+ { basic_tqshape, thai_attributes },
+ // Tibetan,
+ { tibetan_tqshape, tibetan_attributes },
+ // Myanmar,
+ { myanmar_tqshape, myanmar_attributes },
+ // Khmer,
+ { khmer_tqshape, khmer_attributes },
+
+ // // East Asian Scripts
+ // Han,
+ { basic_tqshape, 0 },
+ // Hiragana,
+ { basic_tqshape, 0 },
+ // Katakana,
+ { basic_tqshape, 0 },
+ // Hangul,
+ { hangul_tqshape, hangul_attributes },
+ // Bopomofo,
+ { basic_tqshape, 0 },
+ // Yi,
+ { basic_tqshape, 0 },
+
+ // // Additional Scripts
+ // Ethiopic,
+ { basic_tqshape, 0 },
+ // Cherokee,
+ { basic_tqshape, 0 },
+ // CanadianAboriginal,
+ { basic_tqshape, 0 },
+ // Mongolian,
+ { basic_tqshape, 0 },
+
+ // // Symbols
+ // CurrencySymbols,
+ { basic_tqshape, 0 },
+ // LetterlikeSymbols,
+ { basic_tqshape, 0 },
+ // NumberForms,
+ { basic_tqshape, 0 },
+ // MathematicalOperators,
+ { basic_tqshape, 0 },
+ // TechnicalSymbols,
+ { basic_tqshape, 0 },
+ // GeometricSymbols,
+ { basic_tqshape, 0 },
+ // MiscellaneousSymbols,
+ { basic_tqshape, 0 },
+ // EnclosedAndSquare,
+ { basic_tqshape, 0 },
+ // Braille,
+ { basic_tqshape, 0 },
+
+ // Unicode,
+ { basic_tqshape, 0 },
+ //Tagalog,
+ { basic_tqshape, 0 },
+ //Hanunoo,
+ { basic_tqshape, 0 },
+ //Buhid,
+ { basic_tqshape, 0 },
+ //Tagbanwa,
+ { basic_tqshape, 0 },
+ // KatakanaHalfWidth
+ { basic_tqshape, 0 },
+ // Limbu
+ { basic_tqshape, 0 },
+ // TaiLe
+ { basic_tqshape, 0 }
+};
diff --git a/tqtinterface/qt4/src/kernel/tqsession.h b/tqtinterface/qt4/src/kernel/tqsession.h
new file mode 100644
index 0000000..6c7a800
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsession.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Definition of TQSession class
+**
+** Created : 990510
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSESSION_H
+#define TQSESSION_H
+
+#ifndef TQT_H
+#endif // TQT_H
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqsessionmanager.h b/tqtinterface/qt4/src/kernel/tqsessionmanager.h
new file mode 100644
index 0000000..d537270
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsessionmanager.h
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Definition of TQSessionManager class
+**
+** Created : 990510
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSESSIONMANAGER_H
+#define TQSESSIONMANAGER_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqwindowdefs.h"
+#include "tqstring.h"
+#include "tqstringlist.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+#include "tqapplication.h"
+// Nasty, nasty horrid HACK to get access to QSessionManager's private members
+// This is TERRIBLE and I wish there was a way around it
+// This is a good example of the new, broken & irritating Qt4 API,
+// and the corresponding loss in functionality versus Qt3.
+// See also tqrect.cpp
+#define private protected
+#include <Qt/qsessionmanager.h>
+#undef private
+#endif // USE_QT4
+
+#ifndef TQT_NO_SESSIONMANAGER
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQSessionManager : public QSessionManager, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+ TQSessionManager( QApplication *app, QString id, QString key ) : QSessionManager( app, id, key ) {}
+
+ inline TQStringList restartCommand() const {
+ QStringList ql = QSessionManager::restartCommand();
+ TQStringList tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+
+ inline TQStringList discardCommand() const {
+ QStringList ql = QSessionManager::discardCommand();
+ TQStringList tqsl;
+ tqsl.clear();
+ for (int i = 0; i < ql.size(); ++i) tqsl.append(ql.at(i));
+ return tqsl;
+ }
+
+ inline void setRestartCommand( const TQStringList& tqsl ) {
+ QStringList ql;
+ ql.clear();
+ for ( TQStringList::ConstIterator it = tqsl.begin(); it != tqsl.end(); ++it ) ql.append(*it);
+ QSessionManager::setRestartCommand(ql);
+ }
+
+ inline void setDiscardCommand( const TQStringList& tqsl ) {
+ QStringList ql;
+ ql.clear();
+ for ( TQStringList::ConstIterator it = tqsl.begin(); it != tqsl.end(); ++it ) ql.append(*it);
+ QSessionManager::setDiscardCommand(ql);
+ }
+
+ // Interoperability
+ static TQSessionManager& convertFromQSessionManager( QSessionManager& qsm );
+ static const TQSessionManager& convertFromQSessionManager( const QSessionManager& qsm );
+};
+
+// Interoperability
+inline static TQSessionManager& convertFromQSessionManager( QSessionManager& qsm ) {
+ return (*static_cast<TQSessionManager*>(&qsm));
+}
+inline static const TQSessionManager& convertFromQSessionManager( const QSessionManager& qsm ) {
+ return (*static_cast<const TQSessionManager*>(&qsm));
+}
+
+#else // USE_QT4
+
+class TQSessionManagerData;
+
+class TQ_EXPORT TQSessionManager : public TQObject
+{
+ TQ_OBJECT
+ TQSessionManager( TQApplication *app, TQString &id, TQString &key );
+ ~TQSessionManager();
+public:
+ TQString sessionId() const;
+ TQString sessionKey() const;
+#if defined(TQ_WS_X11) || defined(TQ_WS_MAC)
+ void* handle() const;
+#endif
+
+ bool allowsInteraction();
+ bool allowsErrorInteraction();
+ void release();
+
+ void cancel();
+
+ enum RestartHint {
+ RestartIfRunning,
+ RestartAnyway,
+ RestartImmediately,
+ RestartNever
+ };
+ void setRestartHint( RestartHint );
+ RestartHint restartHint() const;
+
+ void setRestartCommand( const TQStringList& );
+ TQStringList restartCommand() const;
+ void setDiscardCommand( const TQStringList& );
+ TQStringList discardCommand() const;
+
+ void setManagerProperty( const TQString& name, const TQString& value );
+ void setManagerProperty( const TQString& name, const TQStringList& value );
+
+ bool isPhase2() const;
+ void requestPhase2();
+
+private:
+ friend class TQApplication;
+ friend class TQBaseApplication;
+ TQSessionManagerData* d;
+};
+
+#endif // USE_QT4
+#endif // TQT_NO_SESSIONMANAGER
+#endif // TQSESSIONMANAGER_H
diff --git a/tqtinterface/qt4/src/kernel/tqsharedmemory_p.cpp b/tqtinterface/qt4/src/kernel/tqsharedmemory_p.cpp
new file mode 100644
index 0000000..20aa70b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsharedmemory_p.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Provides a standardised interface to shared memory
+**
+** Created : 020124
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsharedmemory_p.h"
+
+#if !defined(TQT_TQWS_NO_SHM)
+
+#if defined(TQT_POSIX_TQSHM)
+#include <fcntl.h>
+#include <sys/mman.h>
+
+TQSharedMemory::TQSharedMemory (int size, TQString filename, char c )
+{
+ shmSize = size;
+ shmFile = filename;
+ character = c;
+ shmFile.append(c);
+}
+
+bool TQSharedMemory::create ()
+{
+ shmFD = shm_open (shmFile.latin1 (), O_RDWR | O_EXCL | O_CREAT, 0666);
+ if (shmFD == -1)
+ return FALSE;
+ else if (ftruncate (shmFD, shmSize) == -1)
+ {
+ close (shmFD);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void TQSharedMemory::destroy ()
+{
+ shm_unlink (shmFile.latin1 ());
+}
+
+bool TQSharedMemory::attach ()
+{
+ shmBase = mmap (0, shmSize, PROT_READ | PROT_WRITE, MAP_SHARED, shmFD, 0);
+
+ if (shmBase == MAP_FAILED)
+ return FALSE;
+
+ close (shmFD);
+ return TRUE;
+}
+
+void TQSharedMemory::detach ()
+{
+ munmap (shmBase, shmSize);
+}
+
+void TQSharedMemory::setPermissions (mode_t mode)
+{
+ mprotect (shmBase, shmSize, mode); // Provide defines to make prot work properly
+}
+
+int TQSharedMemory::size()
+{
+ struct stat buf;
+ int rc = fstat (shmFD, &buf);
+ if (rc != -1)
+ return buf.st_size;
+ else
+ return rc;
+}
+
+#else // Assume SysV for backwards compat
+#include <sys/shm.h>
+
+TQSharedMemory::TQSharedMemory (int size, TQString filename, char c )
+{
+ shmSize = size;
+ shmFile = filename;
+ character = c;
+ key = ftok (shmFile.latin1 (), c);
+ idInitted = FALSE;
+ shmId = -1;
+}
+
+bool TQSharedMemory::create ()
+{
+ shmId = shmget (key, shmSize, IPC_CREAT | 0666);
+ if (shmId == -1)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+void TQSharedMemory::destroy ()
+{
+ if (shmId != -1) {
+ struct shmid_ds shm;
+ shmctl (shmId, IPC_RMID, &shm);
+ }
+}
+
+bool TQSharedMemory::attach ()
+{
+ if (shmId == -1)
+ shmId = shmget (key, shmSize, 0);
+
+ shmBase = shmat (shmId, 0, 0);
+ if ((int) shmBase == -1 || shmBase == 0)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+void TQSharedMemory::detach ()
+{
+ shmdt (shmBase);
+}
+
+void TQSharedMemory::setPermissions (mode_t mode)
+{
+ struct shmid_ds shm;
+ shmctl (shmId, IPC_STAT, &shm);
+ shm.shm_perm.mode = mode;
+ shmctl (shmId, IPC_SET, &shm);
+}
+
+int TQSharedMemory::size ()
+{
+ struct shmid_ds shm;
+ shmctl (shmId, IPC_STAT, &shm);
+ return shm.shm_segsz;
+}
+
+#endif
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqsharedmemory_p.h b/tqtinterface/qt4/src/kernel/tqsharedmemory_p.h
new file mode 100644
index 0000000..55526b0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsharedmemory_p.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Includes system files for shared memory
+**
+** Created : 020124
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSHAREDMEMORY_P_H
+#define TQSHAREDMEMORY_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of qapplication_qws.cpp and qgfxvnc_qws.cpp. This header file may
+// change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#include "tqstring.h"
+#endif // TQT_H
+
+#if !defined (TQT_TQWS_NO_SHM)
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+
+class TQSharedMemory {
+public:
+ TQSharedMemory(){};
+ TQSharedMemory(int, TQString, char c = 'Q');
+ ~TQSharedMemory(){};
+
+ bool create();
+ void destroy();
+
+ bool attach();
+ void detach();
+
+ void setPermissions(mode_t mode);
+ int size();
+ void * base() { return shmBase; };
+
+private:
+ void *shmBase;
+ int shmSize;
+ TQString shmFile;
+ char character;
+#if defined(TQT_POSIX_TQSHM)
+ int shmFD;
+#else
+ int shmId;
+ key_t key;
+ int idInitted;
+#endif
+};
+
+#endif
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqsignal.cpp b/tqtinterface/qt4/src/kernel/tqsignal.cpp
new file mode 100644
index 0000000..262164a
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsignal.cpp
@@ -0,0 +1,493 @@
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqsignal.h"
+#include "Qt/qmetaobject.h"
+#include "Qt/qpointer.h"
+#include "tqcstring.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class TQSignal
+ \brief The TQSignal class can be used to send signals for classes
+ that don't inherit TQT_BASE_OBJECT_NAME.
+
+ \compat
+
+ If you want to send signals from a class that does not inherit
+ TQT_BASE_OBJECT_NAME, you can create an internal TQSignal object to emit the
+ signal. You must also provide a function that connects the signal
+ to an outside object slot. This is how we used to implement
+ signals in Qt 3's QMenuData class, which was not a TQT_BASE_OBJECT_NAME. In Qt
+ 4, menus contain actions, which are TQT_BASE_OBJECT_NAMEs.
+
+ In general, we recommend inheriting TQT_BASE_OBJECT_NAME instead. TQT_BASE_OBJECT_NAME
+ provides much more functionality.
+
+ You can set a single QVariant parameter for the signal with
+ setValue().
+
+ Note that TQT_BASE_OBJECT_NAME is a \e private base class of TQSignal, i.e. you
+ cannot call any TQT_BASE_OBJECT_NAME member functions from a TQSignal object.
+
+ Example:
+ \snippet doc/src/snippets/code/src_qt3support_tools_q3signal.cpp 0
+*/
+
+/*!
+ Constructs a signal object called \a name, with the parent object
+ \a parent. These arguments are passed directly to TQT_BASE_OBJECT_NAME.
+*/
+
+TQSignal::TQSignal(TQT_BASE_OBJECT_NAME *parent, const char *name)
+ : TQT_BASE_OBJECT_NAME(parent)
+{
+ setObjectName(QString::fromAscii(name));
+#ifndef QT_NO_VARIANT
+ val = 0;
+#endif
+}
+
+/*!
+ Destroys the signal. All connections are removed, as is the case
+ with all TQT_BASE_OBJECT_NAMEs.
+*/
+TQSignal::~TQSignal()
+{
+}
+#ifndef QT_NO_VARIANT
+// Returns true if it matches ".+(.*int.*"
+static inline bool intSignature(const char *member)
+{
+ TQCString s(member);
+ int p = s.tqfind('(');
+ return p > 0 && p < s.tqfindRev("int");
+}
+#endif
+/*!
+ Connects the signal to \a member in object \a receiver.
+ Returns true if the connection is successful.
+
+ \sa disconnect(), TQT_BASE_OBJECT_NAME::connect()
+*/
+
+bool TQSignal::connect(const TQT_BASE_OBJECT_NAME *receiver, const char *member)
+{
+#ifndef QT_NO_VARIANT
+ if (intSignature(member))
+#endif
+ return TQT_BASE_OBJECT_NAME::connect((TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(intSignal(int)), receiver, member);
+#ifndef QT_NO_VARIANT
+ return TQT_BASE_OBJECT_NAME::connect((TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(signal(QVariant)),
+ receiver, member);
+#endif
+}
+
+/*!
+ Disonnects the signal from \a member in object \a receiver.
+ Returns true if the connection existed and the disconnect
+ was successful.
+
+ \sa connect(), TQT_BASE_OBJECT_NAME::disconnect()
+*/
+
+bool TQSignal::disconnect(const TQT_BASE_OBJECT_NAME *receiver, const char *member)
+{
+ if (!member)
+ return TQT_BASE_OBJECT_NAME::disconnect((TQT_BASE_OBJECT_NAME *)this, 0, receiver, member);
+#ifndef QT_NO_VARIANT
+ if (intSignature(member))
+#endif
+ return TQT_BASE_OBJECT_NAME::disconnect((TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(intSignal(int)), receiver, member);
+#ifndef QT_NO_VARIANT
+ return TQT_BASE_OBJECT_NAME::disconnect((TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(signal(QVariant)),
+ receiver, member);
+#endif
+}
+
+
+/*!
+ \fn bool TQSignal::isBlocked() const
+ \obsolete
+ Returns true if the signal is blocked, or false if it is not blocked.
+
+ The signal is not blocked by default.
+
+ \sa block(), TQT_BASE_OBJECT_NAME::signalsBlocked()
+*/
+
+/*!
+ \fn void TQSignal::block(bool b)
+ \obsolete
+ Blocks the signal if \a b is true, or unblocks the signal if \a b is false.
+
+ An activated signal disappears into hyperspace if it is blocked.
+
+ \sa isBlocked(), activate(), TQT_BASE_OBJECT_NAME::blockSignals()
+*/
+
+
+/*!
+ \fn void TQSignal::activate()
+
+ Emits the signal. If the platform supports QVariant and a
+ parameter has been set with setValue(), this value is passed in
+ the signal.
+*/
+void TQSignal::activate()
+{
+#ifndef QT_NO_VARIANT
+ /* Create this TQGuardedPtr on this, if we get destroyed after the intSignal (but before the variant signal)
+ we cannot just emit the signal (because val has been destroyed already) */
+ QPointer<TQSignal> me = this;
+ if(me)
+ emit intSignal(val.toInt());
+ if(me)
+ emit signal(val);
+#else
+ emit intSignal(0);
+#endif
+}
+
+#ifndef QT_NO_VARIANT
+/*!
+ Sets the signal's parameter to \a value
+*/
+void TQSignal::setValue(const QVariant &value)
+{
+ val = value;
+}
+
+/*!
+ Returns the signal's parameter
+*/
+QVariant TQSignal::value() const
+{
+ return val;
+}
+/*! \fn void TQSignal::signal(const QVariant &)
+ \internal
+*/
+/*! \fn void TQSignal::intSignal(int)
+ \internal
+*/
+
+/*! \obsolete */
+void TQSignal::setParameter(int value)
+{
+ val = value;
+}
+
+/*! \obsolete */
+int TQSignal::parameter() const
+{
+ return val.toInt();
+}
+#endif //QT_NO_VARIANT
+
+QT_END_NAMESPACE
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of TQSignal class
+**
+** Created : 941201
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsignal.h"
+#include "tqmetaobject.h"
+#include "tqguardedptr.h"
+
+/*!
+ \class TQSignal tqsignal.h
+ \brief The TQSignal class can be used to send Q_SIGNALS for classes
+ that don't inherit TQObject.
+
+ \ingroup io
+ \ingroup misc
+
+ If you want to send Q_SIGNALS from a class that does not inherit
+ TQObject, you can create an internal TQSignal object to emit the
+ signal. You must also provide a function that connects the signal
+ to an outside object slot. This is how we have implemented
+ Q_SIGNALS in the TQMenuData class, which is not a TQObject.
+
+ In general, we recommend inheriting TQObject instead. TQObject
+ provides much more functionality.
+
+ You can set a single TQVariant parameter for the signal with
+ setValue().
+
+ Note that TQObject is a \e private base class of TQSignal, i.e. you
+ cannot call any TQObject member functions from a TQSignal object.
+
+ Example:
+ \code
+ #include <tqsignal.h>
+
+ class MyClass
+ {
+ public:
+ MyClass();
+ ~MyClass();
+
+ void doSomething();
+
+ void connect( TQObject *receiver, const char *member );
+
+ private:
+ TQSignal *sig;
+ };
+
+ MyClass::MyClass()
+ {
+ sig = new TQSignal;
+ }
+
+ MyClass::~MyClass()
+ {
+ delete sig;
+ }
+
+ void MyClass::doSomething()
+ {
+ // ... does something
+ sig->activate(); // emits the signal
+ }
+
+ void MyClass::connect( TQObject *receiver, const char *member )
+ {
+ sig->connect( receiver, member );
+ }
+ \endcode
+*/
+
+/*!
+ Constructs a signal object called \a name, with the tqparent object
+ \a tqparent. These arguments are passed directly to TQObject.
+*/
+
+TQSignal::TQSignal( TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name )
+{
+ isSignal = TRUE;
+#ifndef TQT_NO_VARIANT
+ val = 0;
+#endif
+}
+
+/*!
+ Destroys the signal. All connections are removed, as is the case
+ with all TQObjects.
+*/
+TQSignal::~TQSignal()
+{
+}
+#ifndef TQT_NO_VARIANT
+// Returns TRUE if it matches ".+(.*int.*"
+static inline bool intSignature( const char *member )
+{
+ TQCString s( member );
+ int p = s.tqfind( '(' );
+ return p > 0 && p < s.tqfindRev( "int" );
+}
+#endif
+/*!
+ Connects the signal to \a member in object \a receiver.
+
+ \sa disconnect(), TQObject::connect()
+*/
+
+bool TQSignal::connect( const TQT_BASE_OBJECT_NAME *receiver, const char *member )
+{
+#ifndef TQT_NO_VARIANT
+ if ( intSignature( member ) )
+#endif
+ return TQObject::connect( (TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(intSignal(int)), receiver, member );
+#ifndef TQT_NO_VARIANT
+ return TQObject::connect( (TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(signal(const TQVariant&)),
+ receiver, member );
+#endif
+}
+
+/*!
+ Disonnects the signal from \a member in object \a receiver.
+
+ \sa connect(), TQObject::disconnect()
+*/
+
+bool TQSignal::disconnect( const TQT_BASE_OBJECT_NAME *receiver, const char *member )
+{
+ if (!member)
+ return TQObject::disconnect( (TQT_BASE_OBJECT_NAME *)this, 0, receiver, member);
+#ifndef TQT_NO_VARIANT
+ if ( intSignature( member ) )
+#endif
+ return TQObject::disconnect( (TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(intSignal(int)), receiver, member );
+#ifndef TQT_NO_VARIANT
+ return TQObject::disconnect( (TQT_BASE_OBJECT_NAME *)this, TQT_SIGNAL(signal(const TQVariant&)),
+ receiver, member );
+#endif
+}
+
+
+/*!
+ \fn bool TQSignal::isBlocked() const
+ \obsolete
+ Returns TRUE if the signal is blocked, or FALSE if it is not blocked.
+
+ The signal is not blocked by default.
+
+ \sa block(), TQObject::tqsignalsBlocked()
+*/
+
+/*!
+ \fn void TQSignal::block( bool b )
+ \obsolete
+ Blocks the signal if \a b is TRUE, or unblocks the signal if \a b is FALSE.
+
+ An activated signal disappears into hyperspace if it is blocked.
+
+ \sa isBlocked(), activate(), TQObject::blockSignals()
+*/
+
+
+/*!
+ \fn void TQSignal::activate()
+
+ Emits the signal. If the platform supports TQVariant and a
+ parameter has been set with setValue(), this value is passed in
+ the signal.
+*/
+void TQSignal::activate()
+{
+#ifndef TQT_NO_VARIANT
+ /* Create this TQGuardedPtr on this, if we get destroyed after the intSignal (but before the variant signal)
+ we cannot just emit the signal (because val has been destroyed already) */
+ TQGuardedPtr<TQSignal> me = this;
+ if( me )
+ emit intSignal( val.toInt() );
+ if( me )
+ emit signal( val );
+#else
+ emit intSignal(0);
+#endif
+}
+
+#ifndef TQT_NO_VARIANT
+/*!
+ Sets the signal's parameter to \a value
+*/
+void TQSignal::setValue( const TQVariant &value )
+{
+ val = value;
+}
+
+/*!
+ Returns the signal's parameter
+*/
+TQVariant TQSignal::value() const
+{
+ return val;
+}
+/*! \fn void TQSignal::signal( const TQVariant & )
+ \internal
+*/
+/*! \fn void TQSignal::intSignal( int )
+ \internal
+*/
+
+#ifndef TQT_NO_COMPAT
+/*! \obsolete */
+void TQSignal::setParameter( int value )
+{
+ val = value;
+}
+
+/*! \obsolete */
+int TQSignal::parameter() const
+{
+ return val.toInt();
+}
+#endif
+#endif //TQT_NO_VARIANT
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqsignal.h b/tqtinterface/qt4/src/kernel/tqsignal.h
new file mode 100644
index 0000000..72fd880
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsignal.h
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Definition of TQSignal class
+**
+** Created : 941201
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSIGNAL_H
+#define TQSIGNAL_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqvariant.h"
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <QtCore/qvariant.h>
+#include <QtCore/qobject.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Qt3SupportLight)
+
+class Q_COMPAT_EXPORT TQSignal : public TQT_BASE_OBJECT_NAME, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ TQSignal(TQT_BASE_OBJECT_NAME *parent=0, const char *name=0);
+ ~TQSignal();
+
+ bool connect(const TQT_BASE_OBJECT_NAME *receiver, const char *member);
+ bool disconnect(const TQT_BASE_OBJECT_NAME *receiver, const char *member=0);
+
+ void activate();
+
+ bool isBlocked() const { return TQT_BASE_OBJECT_NAME::signalsBlocked(); }
+ void block(bool b) { TQT_BASE_OBJECT_NAME::blockSignals(b); }
+#ifndef QT_NO_VARIANT
+ void setParameter(int value);
+ int parameter() const;
+#endif
+
+#ifndef QT_NO_VARIANT
+ void setValue(const QVariant &value);
+ QVariant value() const;
+#endif
+Q_SIGNALS:
+#ifndef QT_NO_VARIANT
+ void signal(const QVariant&);
+#endif
+ void intSignal(int);
+
+private:
+ Q_DISABLE_COPY(TQSignal)
+
+#ifndef QT_NO_VARIANT
+ QVariant val;
+#endif
+
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#else // USE_QT4
+
+class TQ_EXPORT TQSignal : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ TQSignal( TQObject *tqparent=0, const char *name=0 );
+ ~TQSignal();
+
+ bool connect( const TQT_BASE_OBJECT_NAME *receiver, const char *member );
+ bool disconnect( const TQT_BASE_OBJECT_NAME *receiver, const char *member=0 );
+
+ void activate();
+
+#ifndef TQT_NO_COMPAT
+ bool isBlocked() const { return TQObject::tqsignalsBlocked(); }
+ void block( bool b ) { TQObject::blockSignals( b ); }
+#ifndef TQT_NO_VARIANT
+ void setParameter( int value );
+ int parameter() const;
+#endif
+#endif
+
+#ifndef TQT_NO_VARIANT
+ void setValue( const TQVariant &value );
+ TQVariant value() const;
+#endif
+Q_SIGNALS:
+#ifndef TQT_NO_VARIANT
+ void signal( const TQVariant& );
+#endif
+ void intSignal( int );
+
+private:
+#ifndef TQT_NO_VARIANT
+ TQVariant val;
+#endif
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQSignal( const TQSignal & );
+ TQSignal &operator=( const TQSignal & );
+#endif
+};
+
+#endif // USE_QT4
+
+#endif // TQSIGNAL_H
diff --git a/tqtinterface/qt4/src/kernel/tqsignalmapper.cpp b/tqtinterface/qt4/src/kernel/tqsignalmapper.cpp
new file mode 100644
index 0000000..8a99c54
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsignalmapper.cpp
@@ -0,0 +1,183 @@
+/****************************************************************************
+**
+** Implementation of TQSignalMapper class
+**
+** Created : 980503
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsignalmapper.h"
+#ifndef TQT_NO_SIGNALMAPPER
+#include "tqptrdict.h"
+
+struct TQSignalMapperRec {
+ TQSignalMapperRec()
+ {
+ has_int = 0;
+ str_id = TQString::null;
+ }
+
+ uint has_int:1;
+
+ int int_id;
+ TQString str_id;
+ // extendable to other types of identification
+};
+
+class TQSignalMapperData {
+public:
+ TQSignalMapperData()
+ {
+ dict.setAutoDelete( TRUE );
+ }
+
+ TQPtrDict<TQSignalMapperRec> dict;
+};
+
+/*!
+ \class TQSignalMapper tqsignalmapper.h
+ \brief The TQSignalMapper class bundles Q_SIGNALS from identifiable senders.
+
+ \ingroup io
+
+ This class collects a set of parameterless Q_SIGNALS, and re-emits
+ them with integer or string parameters corresponding to the object
+ that sent the signal.
+*/
+
+/*!
+ Constructs a TQSignalMapper called \a name, with tqparent \a tqparent.
+ Like all TQObjects, it will be deleted when the tqparent is deleted.
+*/
+TQSignalMapper::TQSignalMapper( TQObject* tqparent, const char* name ) :
+ TQObject( tqparent, name )
+{
+ d = new TQSignalMapperData;
+}
+
+/*!
+ Destroys the TQSignalMapper.
+*/
+TQSignalMapper::~TQSignalMapper()
+{
+ delete d;
+}
+
+/*!
+ Adds a mapping so that when map() is signaled from the given \a
+ sender, the signal mapped(\a identifier) is emitted.
+
+ There may be at most one integer identifier for each object.
+*/
+void TQSignalMapper::setMapping( const TQObject* sender, int identifier )
+{
+ TQSignalMapperRec* rec = getRec(sender);
+ rec->int_id = identifier;
+ rec->has_int = 1;
+}
+
+/*!
+ \overload
+
+ Adds a mapping so that when map() is signaled from the given \a
+ sender, the signal mapper(\a identifier) is emitted.
+
+ There may be at most one string identifier for each object, and it
+ may not be empty.
+*/
+void TQSignalMapper::setMapping( const TQObject* sender, const TQString &identifier )
+{
+ TQSignalMapperRec* rec = getRec(sender);
+ rec->str_id = identifier;
+}
+
+/*!
+ Removes all mappings for \a sender. This is done automatically
+ when mapped objects are destroyed.
+*/
+void TQSignalMapper::removeMappings( const TQObject* sender )
+{
+ d->dict.remove((void*)sender);
+}
+
+void TQSignalMapper::removeMapping()
+{
+ removeMappings(const_cast<const TQObject*>(static_cast<TQObject*>(sender())));
+}
+
+/*!
+ This slot emits Q_SIGNALS based on which object sends Q_SIGNALS to it.
+*/
+void TQSignalMapper::map()
+{
+ const TQObject* s = const_cast<const TQObject*>(static_cast<TQObject*>(sender()));
+ TQSignalMapperRec* rec = d->dict.tqfind( (void*)s );
+ if ( rec ) {
+ if ( rec->has_int )
+ emit mapped( rec->int_id );
+ if ( !rec->str_id.isEmpty() )
+ emit mapped( rec->str_id );
+ }
+}
+
+TQSignalMapperRec* TQSignalMapper::getRec( const TQObject* sender )
+{
+ TQSignalMapperRec* rec = d->dict.tqfind( (void*)sender );
+ if (!rec) {
+ rec = new TQSignalMapperRec;
+ d->dict.insert( (void*)sender, rec );
+ connect( sender, TQT_SIGNAL(destroyed()), this, TQT_SLOT(removeMapping()) );
+ }
+ return rec;
+}
+
+/*!
+ \fn void TQSignalMapper::mapped(int)
+
+ This signal is emitted when map() is signaled from an object that
+ has an integer mapping set.
+
+ \sa setMapping()
+*/
+
+/*!
+ \overload void TQSignalMapper::mapped(const TQString&)
+
+ This signal is emitted when map() is signaled from an object that
+ has a string mapping set.
+
+ \sa setMapping()
+*/
+#endif //TQT_NO_SIGNALMAPPER
diff --git a/tqtinterface/qt4/src/kernel/tqsignalmapper.h b/tqtinterface/qt4/src/kernel/tqsignalmapper.h
new file mode 100644
index 0000000..903dad2
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsignalmapper.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Definition of TQSignalMapper class
+**
+** Created : 980503
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSIGNALMAPPER_H
+#define TQSIGNALMAPPER_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+#ifndef TQT_NO_SIGNALMAPPER
+class TQSignalMapperData;
+struct TQSignalMapperRec;
+
+
+class TQ_EXPORT TQSignalMapper : public TQObject {
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQSignalMapper( TQObject* tqparent, const char* name=0 );
+ ~TQSignalMapper();
+
+ virtual void setMapping( const TQObject* sender, int identifier );
+ virtual void setMapping( const TQObject* sender, const TQString &identifier );
+ void removeMappings( const TQObject* sender );
+
+Q_SIGNALS:
+ void mapped(int);
+ void mapped(const TQString &);
+
+public Q_SLOTS:
+ void map();
+
+private:
+ TQSignalMapperData* d;
+ TQSignalMapperRec* getRec( const TQObject* );
+
+private Q_SLOTS:
+ void removeMapping();
+};
+
+#endif // TQT_NO_SIGNALMAPPER
+#endif // TQSIGNALMAPPER_H
diff --git a/tqtinterface/qt4/src/kernel/tqsignalslotimp.h b/tqtinterface/qt4/src/kernel/tqsignalslotimp.h
new file mode 100644
index 0000000..b16d453
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsignalslotimp.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Definition of signal/slot collections etc.
+**
+** Created : 980821
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSIGNALSLOTIMP_H
+#define TQSIGNALSLOTIMP_H
+
+#ifndef TQT_H
+#include "tqconnection.h"
+#include "tqptrlist.h"
+#include "tqptrvector.h"
+#endif // TQT_H
+
+class TQ_EXPORT TQConnectionList : public TQPtrList<TQConnection>
+{
+public:
+ TQConnectionList() : TQPtrList<TQConnection>() {}
+ TQConnectionList( const TQConnectionList &list ) : TQPtrList<TQConnection>(list) {}
+ ~TQConnectionList() { clear(); }
+ TQConnectionList &operator=(const TQConnectionList &list)
+ { return (TQConnectionList&)TQPtrList<TQConnection>::operator=(list); }
+};
+
+class TQ_EXPORT TQConnectionListIt : public TQPtrListIterator<TQConnection>
+{
+public:
+ TQConnectionListIt( const TQConnectionList &l ) : TQPtrListIterator<TQConnection>(l) {}
+ TQConnectionListIt &operator=(const TQConnectionListIt &i)
+ { return (TQConnectionListIt&)TQPtrListIterator<TQConnection>::operator=(i); }
+};
+
+#if defined(TQ_TEMPLATEDLL) && defined(TQ_CC_INTEL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrVector<TQConnectionList>;
+#define TQ_EXPORTED_TQPTRVECTORCONNECTTIONLIST_TEMPLATES
+// TQMOC_SKIP_END
+#endif
+
+class TQ_EXPORT TQSignalVec : public TQPtrVector<TQConnectionList>
+{
+public:
+ TQSignalVec(int size=17 )
+ : TQPtrVector<TQConnectionList>(size) {}
+ TQSignalVec( const TQSignalVec &dict )
+ : TQPtrVector<TQConnectionList>(dict) {}
+ ~TQSignalVec() { clear(); }
+ TQSignalVec &operator=(const TQSignalVec &dict)
+ { return (TQSignalVec&)TQPtrVector<TQConnectionList>::operator=(dict); }
+ TQConnectionList* at( uint index ) const {
+ return index >= size()? 0 : TQPtrVector<TQConnectionList>::at(index);
+ }
+ bool insert( uint index, const TQConnectionList* d ) {
+ if (index >= size() )
+ resize( 2*index + 1);
+ return TQPtrVector<TQConnectionList>::insert(index, d);
+ }
+};
+
+#define TQ_DEFINED_TQCONNECTION_LIST
+#include "tqwinexport.h"
+#endif // TQSIGNALSLOTIMP_H
diff --git a/tqtinterface/qt4/src/kernel/tqsimplerichtext.cpp b/tqtinterface/qt4/src/kernel/tqsimplerichtext.cpp
new file mode 100644
index 0000000..4721fd8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsimplerichtext.cpp
@@ -0,0 +1,851 @@
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tqsimplerichtext.h"
+
+#ifndef QT_NO_RICHTEXT
+#include "tqrichtext_p.h"
+#include "tqapplication.h"
+
+QT_BEGIN_NAMESPACE
+
+class TQSimpleRichTextData
+{
+public:
+ TQTextDocument *doc;
+ QFont font;
+ int cachedWidth;
+ bool cachedWidthWithPainter;
+ void adjustSize();
+};
+
+// Pull this private function in from qglobal.cpp
+Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n);
+
+void TQSimpleRichTextData::adjustSize() {
+ QFontMetrics fm(font);
+ int mw = fm.width(QString(QLatin1Char('x'))) * 80;
+ int w = mw;
+ doc->doLayout(0,w);
+ if (doc->widthUsed() != 0) {
+ w = qt_int_sqrt(5 * doc->height() * doc->widthUsed() / 3);
+ doc->doLayout(0, qMin(w, mw));
+
+ if (w*3 < 5*doc->height()) {
+ w = qt_int_sqrt(2 * doc->height() * doc->widthUsed());
+ doc->doLayout(0,qMin(w, mw));
+ }
+ }
+ cachedWidth = doc->width();
+ cachedWidthWithPainter = false;
+}
+
+/*!
+ \class TQSimpleRichText
+ \brief The TQSimpleRichText class provides a small displayable piece of rich text.
+
+ \compat
+
+ This class encapsulates simple rich text usage in which a string
+ is interpreted as rich text and can be drawn. This is particularly
+ useful if you want to display some rich text in a custom widget. A
+ TQStyleSheet is needed to interpret the tags and format the rich
+ text. Qt provides a default HTML-like style sheet, but you may
+ define custom style sheets.
+
+ Once created, the rich text object can be queried for its width(),
+ height(), and the actual width used (see widthUsed()). Most
+ importantly, it can be drawn on any given QPainter with draw().
+ TQSimpleRichText can also be used to implement hypertext or active
+ text facilities by using anchorAt(). A hit test through inText()
+ makes it possible to use simple rich text for text objects in
+ editable drawing canvases.
+
+ Once constructed from a string the contents cannot be changed,
+ only resized. If the contents change, just throw the rich text
+ object away and make a new one with the new contents.
+
+ For large documents use QTextEdit or QTextBrowser. For very small
+ items of rich text you can use a QLabel.
+
+ If you are using TQSimpleRichText to print in high resolution you
+ should call setWidth(QPainter, int) so that the content will be
+ laid out properly on the page.
+*/
+
+/*!
+ Constructs a TQSimpleRichText from the rich text string \a text and
+ the font \a fnt.
+
+ The font is used as a basis for the text rendering. When using
+ rich text rendering on a widget \e w, you would normally specify
+ the widget's font, for example:
+
+ \snippet doc/src/snippets/code/src_qt3support_text_q3simplerichtext.cpp 0
+
+ \a context is the optional context of the rich text object. This
+ becomes important if \a text contains relative references, for
+ example within image tags. TQSimpleRichText always uses the default
+ mime source factory (see \l{TQMimeSourceFactory::defaultFactory()})
+ to resolve those references. The context will then be used to
+ calculate the absolute path. See
+ TQMimeSourceFactory::makeAbsolute() for details.
+
+ The \a sheet is an optional style sheet. If it is 0, the default
+ style sheet will be used (see \l{TQStyleSheet::defaultSheet()}).
+*/
+
+TQSimpleRichText::TQSimpleRichText(const QString& text, const QFont& fnt,
+ const QString& context, const TQStyleSheet* sheet)
+{
+ d = new TQSimpleRichTextData;
+ d->cachedWidth = -1;
+ d->cachedWidthWithPainter = false;
+ d->font = fnt;
+ d->doc = new TQTextDocument(0);
+ d->doc->setTextFormat(TQt::RichText);
+ d->doc->setLeftMargin(0);
+ d->doc->setRightMargin(0);
+ d->doc->setFormatter(new TQTextFormatterBreakWords);
+ d->doc->setStyleSheet((TQStyleSheet*)sheet);
+ d->doc->setDefaultFormat(fnt, QColor());
+ d->doc->setText(text, context);
+}
+
+
+/*!
+ Constructs a TQSimpleRichText from the rich text string \a text and
+ the font \a fnt.
+
+ This is a slightly more complex constructor for TQSimpleRichText
+ that takes an additional mime source factory \a factory, a page
+ break parameter \a pageBreak and a bool \a linkUnderline. \a
+ linkColor is only provided for compatibility, but has no effect,
+ as QPalette::link() color is used now.
+
+ \a context is the optional context of the rich text object. This
+ becomes important if \a text contains relative references, for
+ example within image tags. TQSimpleRichText always uses the default
+ mime source factory (see \l{TQMimeSourceFactory::defaultFactory()})
+ to resolve those references. The context will then be used to
+ calculate the absolute path. See
+ TQMimeSourceFactory::makeAbsolute() for details.
+
+ The \a sheet is an optional style sheet. If it is 0, the default
+ style sheet will be used (see \l{TQStyleSheet::defaultSheet()}).
+
+ This constructor is useful for creating a TQSimpleRichText object
+ suitable for printing. Set \a pageBreak to be the height of the
+ contents area of the pages.
+*/
+
+TQSimpleRichText::TQSimpleRichText(const QString& text, const QFont& fnt,
+ const QString& context, const TQStyleSheet* sheet,
+ const TQMimeSourceFactory* factory, int pageBreak,
+ const QColor& /*linkColor*/, bool linkUnderline)
+{
+ d = new TQSimpleRichTextData;
+ d->cachedWidth = -1;
+ d->cachedWidthWithPainter = false;
+ d->font = fnt;
+ d->doc = new TQTextDocument(0);
+ d->doc->setTextFormat(TQt::RichText);
+ d->doc->setFormatter(new TQTextFormatterBreakWords);
+ d->doc->setStyleSheet((TQStyleSheet*)sheet);
+ d->doc->setDefaultFormat(fnt, QColor());
+ d->doc->flow()->setPageSize(pageBreak);
+ d->doc->setPageBreakEnabled(true);
+#ifndef QT_NO_MIME
+ d->doc->setMimeSourceFactory((TQMimeSourceFactory*)factory);
+#endif
+ d->doc->setUnderlineLinks(linkUnderline);
+ d->doc->setText(text, context);
+}
+
+/*!
+ Destroys the rich text object, freeing memory.
+*/
+
+TQSimpleRichText::~TQSimpleRichText()
+{
+ delete d->doc;
+ delete d;
+}
+
+/*!
+ \overload
+
+ Sets the width of the rich text object to \a w pixels.
+
+ \sa height(), adjustSize()
+*/
+
+void TQSimpleRichText::setWidth(int w)
+{
+ if (w == d->cachedWidth && !d->cachedWidthWithPainter)
+ return;
+ d->doc->formatter()->setAllowBreakInWords(d->doc->isPageBreakEnabled());
+ d->cachedWidth = w;
+ d->cachedWidthWithPainter = false;
+ d->doc->doLayout(0, w);
+}
+
+/*!
+ Sets the width of the rich text object to \a w pixels,
+ recalculating the layout as if it were to be drawn with painter \a
+ p.
+
+ Passing a painter is useful when you intend drawing on devices
+ other than the screen, for example a QPrinter.
+
+ \sa height(), adjustSize()
+*/
+
+void TQSimpleRichText::setWidth(QPainter *p, int w)
+{
+ if (w == d->cachedWidth && d->cachedWidthWithPainter)
+ return;
+ d->doc->formatter()->setAllowBreakInWords(d->doc->isPageBreakEnabled() ||
+ (p && p->device() &&
+ p->device()->devType() == QInternal::Printer));
+ p->save();
+ d->cachedWidth = w;
+ d->cachedWidthWithPainter = true;
+ d->doc->doLayout(TQT_TQPAINTER(p), w);
+ p->restore();
+}
+
+/*!
+ Returns the set width of the rich text object in pixels.
+
+ \sa widthUsed()
+*/
+
+int TQSimpleRichText::width() const
+{
+ if (d->cachedWidth < 0)
+ d->adjustSize();
+ return d->doc->width();
+}
+
+/*!
+ Returns the width in pixels that is actually used by the rich text
+ object. This can be smaller or wider than the set width.
+
+ It may be wider, for example, if the text contains images or
+ non-breakable words that are already wider than the available
+ space. It's smaller when the object only consists of lines that do
+ not fill the width completely.
+
+ \sa width()
+*/
+
+int TQSimpleRichText::widthUsed() const
+{
+ if (d->cachedWidth < 0)
+ d->adjustSize();
+ return d->doc->widthUsed();
+}
+
+/*!
+ Returns the height of the rich text object in pixels.
+
+ \sa setWidth()
+*/
+
+int TQSimpleRichText::height() const
+{
+ if (d->cachedWidth < 0)
+ d->adjustSize();
+ return d->doc->height();
+}
+
+/*!
+ Adjusts the rich text object to a reasonable size.
+
+ \sa setWidth()
+*/
+
+void TQSimpleRichText::adjustSize()
+{
+ d->adjustSize();
+}
+
+/*!
+ Draws the formatted text with painter \a p, at position (\a x, \a
+ y), clipped to \a clipRect. The clipping rectangle is given in the
+ rich text object's coordinates translated by (\a x, \a y). Passing
+ an null rectangle results in no clipping. Colors from the color
+ group \a cg are used as needed, and if not 0, *\a{paper} is
+ used as the background brush.
+
+ Note that the display code is highly optimized to reduce flicker,
+ so passing a brush for \a paper is preferable to simply clearing
+ the area to be painted and then calling this without a brush.
+*/
+
+void TQSimpleRichText::draw(QPainter *p, int x, int y, const QRect& clipRect,
+ const TQColorGroup &cg, const QBrush* paper) const
+{
+ p->save();
+ if (d->cachedWidth < 0)
+ d->adjustSize();
+ TQRect r = clipRect;
+ if (!r.isNull())
+ r.moveBy(-x, -y);
+
+ if (paper)
+ d->doc->setPaper(new TQBrush(*paper));
+ QPalette pal2 = cg;
+ if (d->doc->paper())
+ pal2.setBrush(QPalette::Base, *d->doc->paper());
+
+ if (!clipRect.isNull())
+ p->setClipRect(clipRect);
+ p->translate(x, y);
+ d->doc->draw(TQT_TQPAINTER(p), r, pal2, TQT_TQBRUSH_CONST(paper));
+ p->translate(-x, -y);
+ p->restore();
+}
+
+
+/*! \fn void TQSimpleRichText::draw(QPainter *p, int x, int y, const QRegion& clipRegion,
+ const QColorGroup &cg, const QBrush* paper) const
+
+ Use the version with clipRect instead of this \a clipRegion version,
+ since this region version has problems with larger documents on some
+ platforms (on X11 regions internally are represented with 16-bit
+ coordinates).
+*/
+
+
+
+/*!
+ Returns the context of the rich text object. If no context has
+ been specified in the constructor, an empty string is returned. The
+ context is the path to use to look up relative links, such as
+ image tags and anchor references.
+*/
+
+TQString TQSimpleRichText::context() const
+{
+ return d->doc->context();
+}
+
+/*!
+ Returns the anchor at the requested position, \a pos. An empty
+ string is returned if no anchor is specified for this position.
+*/
+
+TQString TQSimpleRichText::anchorAt(const QPoint& pos) const
+{
+ if (d->cachedWidth < 0)
+ d->adjustSize();
+ TQTextCursor c(d->doc);
+ c.place(pos, d->doc->firstParagraph(), true);
+ return c.paragraph()->at(c.index())->anchorHref();
+}
+
+/*!
+ Returns true if \a pos is within a text line of the rich text
+ object; otherwise returns false.
+*/
+
+bool TQSimpleRichText::inText(const QPoint& pos) const
+{
+ if (d->cachedWidth < 0)
+ d->adjustSize();
+ if (pos.y() > d->doc->height())
+ return false;
+ TQTextCursor c(d->doc);
+ c.place(pos, d->doc->firstParagraph());
+ return c.totalOffsetX() + c.paragraph()->at(c.index())->x +
+ c.paragraph()->at(c.index())->format()->width(c.paragraph()->at(c.index())->c) > pos.x();
+}
+
+/*!
+ Sets the default font for the rich text object to \a f
+*/
+
+void TQSimpleRichText::setDefaultFont(const QFont &f)
+{
+ if (d->font == f)
+ return;
+ d->font = f;
+ d->cachedWidth = -1;
+ d->cachedWidthWithPainter = false;
+ d->doc->setDefaultFormat(f, QColor());
+ d->doc->setText(d->doc->originalText(), d->doc->context());
+}
+
+QT_END_NAMESPACE
+
+#endif //QT_NO_RICHTEXT
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Implementation of the TQSimpleRichText class
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsimplerichtext.h"
+
+#ifndef TQT_NO_RICHTEXT
+#include "tqrichtext_p.h"
+#include "tqapplication.h"
+
+class TQSimpleRichTextData
+{
+public:
+ TQTextDocument *doc;
+ TQFont font;
+ int cachedWidth;
+ bool cachedWidthWithPainter;
+ void adjustSize(TQPainter *p = 0);
+};
+
+// Pull this private function in from qglobal.cpp
+extern unsigned int qt_int_sqrt( unsigned int n );
+
+void TQSimpleRichTextData::adjustSize(TQPainter *p) {
+ TQFontMetrics fm( font );
+ int mw = fm.width( 'x' ) * 80;
+ int w = mw;
+ doc->doLayout(p, w);
+ if ( doc->widthUsed() != 0 ) {
+ w = qt_int_sqrt( 5 * doc->height() * doc->widthUsed() / 3 );
+ doc->doLayout(p, TQMIN(w, mw));
+
+ if ( w*3 < 5*doc->height() ) {
+ w = qt_int_sqrt( 2 * doc->height() * doc->widthUsed() );
+ doc->doLayout(p, TQMIN(w, mw));
+ }
+ }
+ cachedWidth = doc->width();
+ cachedWidthWithPainter = FALSE;
+}
+
+/*!
+ \class TQSimpleRichText tqsimplerichtext.h
+ \brief The TQSimpleRichText class provides a small displayable piece of rich text.
+
+ \ingroup text
+ \mainclass
+
+ This class encapsulates simple rich text usage in which a string
+ is interpreted as rich text and can be drawn. This is particularly
+ useful if you want to display some rich text in a custom widget. A
+ TQStyleSheet is needed to interpret the tags and format the rich
+ text. TQt provides a default HTML-like style sheet, but you may
+ define custom style sheets.
+
+ Once created, the rich text object can be queried for its width(),
+ height(), and the actual width used (see widthUsed()). Most
+ importantly, it can be drawn on any given TQPainter with draw().
+ TQSimpleRichText can also be used to implement hypertext or active
+ text facilities by using anchorAt(). A hit test through inText()
+ makes it possible to use simple rich text for text objects in
+ editable drawing canvases.
+
+ Once constructed from a string the contents cannot be changed,
+ only resized. If the contents change, just throw the rich text
+ object away and make a new one with the new contents.
+
+ For large documents use TQTextEdit or TQTextBrowser. For very small
+ items of rich text you can use a TQLabel.
+
+ If you are using TQSimpleRichText to print in high resolution you
+ should call setWidth(TQPainter, int) so that the content will be
+ laid out properly on the page.
+*/
+
+/*!
+ Constructs a TQSimpleRichText from the rich text string \a text and
+ the font \a fnt.
+
+ The font is used as a basis for the text rendering. When using
+ rich text rendering on a widget \e w, you would normally specify
+ the widget's font, for example:
+
+ \code
+ TQSimpleRichText myrichtext( contents, mywidget->font() );
+ \endcode
+
+ \a context is the optional context of the rich text object. This
+ becomes important if \a text tqcontains relative references, for
+ example within image tags. TQSimpleRichText always uses the default
+ mime source factory (see \l{TQMimeSourceFactory::defaultFactory()})
+ to resolve those references. The context will then be used to
+ calculate the absolute path. See
+ TQMimeSourceFactory::makeAbsolute() for details.
+
+ The \a sheet is an optional style sheet. If it is 0, the default
+ style sheet will be used (see \l{TQStyleSheet::defaultSheet()}).
+*/
+
+TQSimpleRichText::TQSimpleRichText( const TQString& text, const TQFont& fnt,
+ const TQString& context, const TQStyleSheet* sheet )
+{
+ d = new TQSimpleRichTextData;
+ d->cachedWidth = -1;
+ d->cachedWidthWithPainter = FALSE;
+ d->font = fnt;
+ d->doc = new TQTextDocument( 0 );
+ d->doc->setTextFormat( TQt::RichText );
+ d->doc->setLeftMargin( 0 );
+ d->doc->setRightMargin( 0 );
+ d->doc->setFormatter( new TQTextFormatterBreakWords );
+ d->doc->setStyleSheet( (TQStyleSheet*)sheet );
+ d->doc->setDefaultFormat( fnt, TQColor() );
+ d->doc->setText( text, context );
+}
+
+
+/*!
+ Constructs a TQSimpleRichText from the rich text string \a text and
+ the font \a fnt.
+
+ This is a slightly more complex constructor for TQSimpleRichText
+ that takes an additional mime source factory \a factory, a page
+ break parameter \a pageBreak and a bool \a linkUnderline. \a
+ linkColor is only provided for compatibility, but has no effect,
+ as TQColorGroup's TQColorGroup::link() color is used now.
+
+ \a context is the optional context of the rich text object. This
+ becomes important if \a text tqcontains relative references, for
+ example within image tags. TQSimpleRichText always uses the default
+ mime source factory (see \l{TQMimeSourceFactory::defaultFactory()})
+ to resolve those references. The context will then be used to
+ calculate the absolute path. See
+ TQMimeSourceFactory::makeAbsolute() for details.
+
+ The \a sheet is an optional style sheet. If it is 0, the default
+ style sheet will be used (see \l{TQStyleSheet::defaultSheet()}).
+
+ This constructor is useful for creating a TQSimpleRichText object
+ suitable for printing. Set \a pageBreak to be the height of the
+ contents area of the pages.
+*/
+
+TQSimpleRichText::TQSimpleRichText( const TQString& text, const TQFont& fnt,
+ const TQString& context, const TQStyleSheet* sheet,
+ const TQMimeSourceFactory* factory, int pageBreak,
+ const TQColor& /*linkColor*/, bool linkUnderline )
+{
+ d = new TQSimpleRichTextData;
+ d->cachedWidth = -1;
+ d->cachedWidthWithPainter = FALSE;
+ d->font = fnt;
+ d->doc = new TQTextDocument( 0 );
+ d->doc->setTextFormat( TQt::RichText );
+ d->doc->setFormatter( new TQTextFormatterBreakWords );
+ d->doc->setStyleSheet( (TQStyleSheet*)sheet );
+ d->doc->setDefaultFormat( fnt, TQColor() );
+ d->doc->flow()->setPageSize( pageBreak );
+ d->doc->setPageBreakEnabled( TRUE );
+#ifndef TQT_NO_MIME
+ d->doc->setMimeSourceFactory( (TQMimeSourceFactory*)factory );
+#endif
+ d->doc->setUnderlineLinks( linkUnderline );
+ d->doc->setText( text, context );
+}
+
+/*!
+ Destroys the rich text object, freeing memory.
+*/
+
+TQSimpleRichText::~TQSimpleRichText()
+{
+ delete d->doc;
+ delete d;
+}
+
+/*!
+ \overload
+
+ Sets the width of the rich text object to \a w pixels.
+
+ \sa height(), adjustSize()
+*/
+
+void TQSimpleRichText::setWidth( int w )
+{
+ if ( w == d->cachedWidth && !d->cachedWidthWithPainter )
+ return;
+ d->doc->formatter()->setAllowBreakInWords( d->doc->isPageBreakEnabled() );
+ d->cachedWidth = w;
+ d->cachedWidthWithPainter = FALSE;
+ d->doc->doLayout( 0, w );
+}
+
+/*!
+ Sets the width of the rich text object to \a w pixels,
+ recalculating the tqlayout as if it were to be drawn with painter \a
+ p.
+
+ Passing a painter is useful when you intend drawing on tqdevices
+ other than the screen, for example a TQPrinter.
+
+ \sa height(), adjustSize()
+*/
+
+void TQSimpleRichText::setWidth( TQPainter *p, int w )
+{
+ if ( w == d->cachedWidth && d->cachedWidthWithPainter )
+ return;
+ d->doc->formatter()->setAllowBreakInWords( d->doc->isPageBreakEnabled() ||
+ (p && p->tqdevice() &&
+ (p->tqdevice()->devType() == TQInternal::Printer)) );
+ p->save();
+ d->cachedWidth = w;
+ d->cachedWidthWithPainter = TRUE;
+ d->doc->doLayout( p, w );
+ p->restore();
+}
+
+/*!
+ Returns the set width of the rich text object in pixels.
+
+ \sa widthUsed()
+*/
+
+int TQSimpleRichText::width() const
+{
+ if ( d->cachedWidth < 0 )
+ d->adjustSize();
+ return d->doc->width();
+}
+
+/*!
+ Returns the width in pixels that is actually used by the rich text
+ object. This can be smaller or wider than the set width.
+
+ It may be wider, for example, if the text tqcontains images or
+ non-breakable words that are already wider than the available
+ space. It's smaller when the object only consists of lines that do
+ not fill the width completely.
+
+ \sa width()
+*/
+
+int TQSimpleRichText::widthUsed() const
+{
+ if ( d->cachedWidth < 0 )
+ d->adjustSize();
+ return d->doc->widthUsed();
+}
+
+/*!
+ Returns the height of the rich text object in pixels.
+
+ \sa setWidth()
+*/
+
+int TQSimpleRichText::height() const
+{
+ if ( d->cachedWidth < 0 )
+ d->adjustSize();
+ return d->doc->height();
+}
+
+/*!
+ Adjusts the richt text object to a reasonable size.
+
+ \sa setWidth()
+*/
+
+void TQSimpleRichText::adjustSize()
+{
+ d->adjustSize();
+}
+
+/*!
+ Draws the formatted text with painter \a p, at position (\a x, \a
+ y), clipped to \a clipRect. The clipping rectangle is given in the
+ rich text object's coordinates translated by (\a x, \a y). Passing
+ an null rectangle results in no clipping. Colors from the color
+ group \a cg are used as needed, and if not 0, \a *paper is used as
+ the background brush.
+
+ Note that the display code is highly optimized to reduce flicker,
+ so passing a brush for \a paper is preferable to simply clearing
+ the area to be painted and then calling this without a brush.
+*/
+
+void TQSimpleRichText::draw( TQPainter *p, int x, int y, const QRect& clipRect,
+ const TQColorGroup& cg, const TQBrush* paper ) const
+{
+ p->save();
+ if ( d->cachedWidth < 0 )
+ d->adjustSize(p);
+
+ TQRect r = clipRect;
+ if ( !r.isNull() )
+ r.moveBy( -x, -y );
+
+ if ( paper )
+ d->doc->setPaper( new TQBrush( *paper ) );
+ TQColorGroup g = cg;
+ if ( d->doc->paper() )
+ g.setBrush( TQColorGroup::Base, *d->doc->paper() );
+
+ if ( !clipRect.isNull() )
+ p->setClipRect( clipRect, TQPainter::CoordPainter );
+ p->translate( x, y );
+ d->doc->draw( p, r, g, paper );
+ p->translate( -x, -y );
+ p->restore();
+}
+
+
+/*! \fn void TQSimpleRichText::draw( TQPainter *p, int x, int y, const TQRegion& clipRegion,
+ const TQColorGroup& cg, const TQBrush* paper ) const
+
+ \obsolete
+
+ Use the version with clipRect instead. The region version has
+ problems with larger documents on some platforms (on X11 regions
+ internally are represented with 16bit coordinates).
+*/
+
+
+
+/*!
+ Returns the context of the rich text object. If no context has
+ been specified in the constructor, a null string is returned. The
+ context is the path to use to look up relative links, such as
+ image tags and anchor references.
+*/
+
+TQString TQSimpleRichText::context() const
+{
+ return d->doc->context();
+}
+
+/*!
+ Returns the anchor at the requested position, \a pos. An empty
+ string is returned if no anchor is specified for this position.
+*/
+
+TQString TQSimpleRichText::anchorAt( const TQPoint& pos ) const
+{
+ if ( d->cachedWidth < 0 )
+ d->adjustSize();
+ TQTextCursor c( d->doc );
+ c.place( pos, d->doc->firstParagraph(), TRUE );
+ return c.paragraph()->at( c.index() )->anchorHref();
+}
+
+/*!
+ Returns TRUE if \a pos is within a text line of the rich text
+ object; otherwise returns FALSE.
+*/
+
+bool TQSimpleRichText::inText( const TQPoint& pos ) const
+{
+ if ( d->cachedWidth < 0 )
+ d->adjustSize();
+ if ( pos.y() > d->doc->height() )
+ return FALSE;
+ TQTextCursor c( d->doc );
+ c.place( pos, d->doc->firstParagraph() );
+ return c.totalOffsetX() + c.paragraph()->at( c.index() )->x +
+ c.paragraph()->at( c.index() )->format()->width( c.paragraph()->at( c.index() )->c ) > pos.x();
+}
+
+/*!
+ Sets the default font for the rich text object to \a f
+*/
+
+void TQSimpleRichText::setDefaultFont( const TQFont &f )
+{
+ if ( d->font == f )
+ return;
+ d->font = f;
+ d->cachedWidth = -1;
+ d->cachedWidthWithPainter = FALSE;
+ d->doc->setDefaultFormat( f, TQColor() );
+ d->doc->setText( d->doc->originalText(), d->doc->context() );
+}
+
+#endif //TQT_NO_RICHTEXT
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqsimplerichtext.h b/tqtinterface/qt4/src/kernel/tqsimplerichtext.h
new file mode 100644
index 0000000..2b29c53
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsimplerichtext.h
@@ -0,0 +1,234 @@
+#include "tqtglobaldefines.h"
+
+#ifdef USE_QT4
+
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt3Support module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TQSIMPLERICHTEXT_H
+#define TQSIMPLERICHTEXT_H
+
+#include <QtCore/qnamespace.h>
+#include <QtCore/qstring.h>
+#include <QtGui/qregion.h>
+#include <QtGui/qcolor.h>
+
+#include "tqpalette.h"
+#include "tqpainter.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Qt3SupportLight)
+
+#ifndef QT_NO_RICHTEXT
+
+class QPainter;
+class QWidget;
+class TQStyleSheet;
+class QBrush;
+class TQMimeSourceFactory;
+class TQSimpleRichTextData;
+
+class Q_COMPAT_EXPORT TQSimpleRichText
+{
+public:
+ TQSimpleRichText(const QString& text, const QFont& fnt,
+ const QString& context = QString(), const TQStyleSheet* sheet = 0);
+ TQSimpleRichText(const QString& text, const QFont& fnt,
+ const QString& context, const TQStyleSheet *sheet,
+ const TQMimeSourceFactory* factory, int pageBreak = -1,
+ const QColor& linkColor = Qt::blue, bool linkUnderline = true);
+ ~TQSimpleRichText();
+
+ void setWidth(int);
+ void setWidth(QPainter*, int);
+ void setDefaultFont(const QFont &f);
+ int width() const;
+ int widthUsed() const;
+ int height() const;
+ void adjustSize();
+
+ void draw(QPainter* p, int x, int y, const QRect& clipRect,
+ const TQColorGroup& cg, const QBrush* paper = 0) const;
+
+ void draw(QPainter* p, int x, int y, const QRegion& clipRegion,
+ const TQColorGroup& cg, const QBrush* paper = 0) const {
+ draw(p, x, y, clipRegion.boundingRect(), cg, paper);
+ }
+
+ TQString context() const;
+ TQString anchorAt(const QPoint& pos) const;
+
+ bool inText(const QPoint& pos) const;
+
+private:
+ Q_DISABLE_COPY(TQSimpleRichText)
+
+ TQSimpleRichTextData* d;
+};
+
+#endif // QT_NO_RICHTEXT
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // TQSIMPLERICHTEXT_H
+
+#else // USE_QT4
+
+/****************************************************************************
+**
+** Definition of the TQSimpleRichText class
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSIMPLERICHTEXT_H
+#define TQSIMPLERICHTEXT_H
+
+#ifndef TQT_H
+#include "tqnamespace.h"
+#include "tqstring.h"
+#include "tqregion.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_RICHTEXT
+
+class TQ_EXPORT TQSimpleRichText : public QSimpleRichText
+{
+public:
+ TQSimpleRichText( const QString& text, const QFont& fnt, const QString& context = TQString::null, const QStyleSheet* sheet = 0) : QSimpleRichText( text, fnt, context, sheet ) {}
+ TQSimpleRichText( const TQString& text, const TQFont& fnt, const TQString& context, const TQStyleSheet* sheet, const TQMimeSourceFactory* factory, int pageBreak = -1, const TQColor& linkColor = TQt::blue, bool linkUnderline = TRUE ) : QSimpleRichText( text, fnt, context, sheet, factory, pageBreak, linkColor, linkUnderline ) {}
+};
+
+#else // USE_QT4
+
+class TQPainter;
+class TQWidget;
+class TQStyleSheet;
+class TQBrush;
+class TQMimeSourceFactory;
+class TQSimpleRichTextData;
+
+class TQ_EXPORT TQSimpleRichText
+{
+public:
+ TQSimpleRichText( const TQString& text, const TQFont& fnt,
+ const TQString& context = TQString::null, const TQStyleSheet* sheet = 0);
+ TQSimpleRichText( const TQString& text, const TQFont& fnt,
+ const TQString& context, const TQStyleSheet* sheet,
+ const TQMimeSourceFactory* factory, int pageBreak = -1,
+ const TQColor& linkColor = TQt::blue, bool linkUnderline = TRUE );
+ ~TQSimpleRichText();
+
+ void setWidth( int );
+ void setWidth( TQPainter*, int );
+ void setDefaultFont( const TQFont &f );
+ int width() const;
+ int widthUsed() const;
+ int height() const;
+ void adjustSize();
+
+ void draw( TQPainter* p, int x, int y, const QRect& clipRect,
+ const TQColorGroup& cg, const TQBrush* paper = 0) const;
+
+ // obsolete
+ void draw( TQPainter* p, int x, int y, const TQRegion& clipRegion,
+ const TQColorGroup& cg, const TQBrush* paper = 0) const {
+ draw( p, x, y, clipRegion.boundingRect(), cg, paper );
+ }
+
+ TQString context() const;
+ TQString anchorAt( const TQPoint& pos ) const;
+
+ bool inText( const TQPoint& pos ) const;
+
+private:
+ TQSimpleRichTextData* d;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQSimpleRichText( const TQSimpleRichText & );
+ TQSimpleRichText &operator=( const TQSimpleRichText & );
+#endif
+};
+
+#endif // TQT_NO_RICHTEXT
+
+#endif // TQSIMPLERICHTEXT_H
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqsize.cpp b/tqtinterface/qt4/src/kernel/tqsize.cpp
new file mode 100644
index 0000000..e308f3c
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsize.cpp
@@ -0,0 +1,437 @@
+/****************************************************************************
+**
+** Implementation of TQSize class
+**
+** Created : 931028
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsize.h"
+#include "tqdatastream.h"
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ \class TQSize
+ \brief The TQSize class defines the size of a two-dimensional object.
+
+ \ingroup images
+ \ingroup graphics
+
+ A size is specified by a width and a height.
+
+ The coordinate type is TQCOORD (defined in \c <tqwindowdefs.h> as \c int).
+ The minimum value of TQCOORD is TQCOORD_MIN (-2147483648) and the maximum
+ value is TQCOORD_MAX (2147483647).
+
+ The size can be set in the constructor and changed with setWidth()
+ and setHeight(), or using operator+=(), operator-=(), operator*=()
+ and operator/=(), etc. You can swap the width and height with
+ transpose(). You can get a size which holds the maximum height and
+ width of two sizes using expandedTo(), and the minimum height and
+ width of two sizes using boundedTo().
+
+
+ \sa TQPoint, TQRect
+*/
+
+
+/*****************************************************************************
+ TQSize member functions
+ *****************************************************************************/
+
+/*!
+ \fn TQSize::TQSize()
+ Constructs a size with invalid (negative) width and height.
+*/
+
+/*!
+ \fn TQSize::TQSize( int w, int h )
+ Constructs a size with width \a w and height \a h.
+*/
+
+/*!
+ \fn bool TQSize::isNull() const
+ Returns TRUE if the width is 0 and the height is 0; otherwise
+ returns FALSE.
+*/
+
+/*!
+ \fn bool TQSize::isEmpty() const
+ Returns TRUE if the width is less than or equal to 0, or the height is
+ less than or equal to 0; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQSize::isValid() const
+ Returns TRUE if the width is equal to or greater than 0 and the height is
+ equal to or greater than 0; otherwise returns FALSE.
+*/
+
+/*!
+ \fn int TQSize::width() const
+ Returns the width.
+ \sa height()
+*/
+
+/*!
+ \fn int TQSize::height() const
+ Returns the height.
+ \sa width()
+*/
+
+/*!
+ \fn void TQSize::setWidth( int w )
+ Sets the width to \a w.
+ \sa width(), setHeight()
+*/
+
+/*!
+ \fn void TQSize::setHeight( int h )
+ Sets the height to \a h.
+ \sa height(), setWidth()
+*/
+
+/*!
+ Swaps the values of width and height.
+*/
+
+void TQSize::transpose()
+{
+ TQCOORD tmp = wd;
+ wd = ht;
+ ht = tmp;
+}
+
+/*! \enum TQSize::ScaleMode
+
+ This enum type defines the different ways of scaling a size.
+
+ \img scaling.png
+
+ \value ScaleFree The size is scaled freely. The ratio is not preserved.
+ \value ScaleMin The size is scaled to a rectangle as large as possible
+ inside a given rectangle, preserving the aspect ratio.
+ \value ScaleMax The size is scaled to a rectangle as small as possible
+ outside a given rectangle, preserving the aspect ratio.
+
+ \sa TQSize::scale(), TQImage::scale(), TQImage::smoothScale()
+*/
+
+/*!
+ Scales the size to a rectangle of width \a w and height \a h according
+ to the ScaleMode \a mode.
+
+ \list
+ \i If \a mode is \c ScaleFree, the size is set to (\a w, \a h).
+ \i If \a mode is \c ScaleMin, the current size is scaled to a rectangle
+ as large as possible inside (\a w, \a h), preserving the aspect ratio.
+ \i If \a mode is \c ScaleMax, the current size is scaled to a rectangle
+ as small as possible outside (\a w, \a h), preserving the aspect ratio.
+ \endlist
+
+ Example:
+ \code
+ TQSize t1( 10, 12 );
+ t1.scale( 60, 60, TQSize::ScaleFree );
+ // t1 is (60, 60)
+
+ TQSize t2( 10, 12 );
+ t2.scale( 60, 60, TQSize::ScaleMin );
+ // t2 is (50, 60)
+
+ TQSize t3( 10, 12 );
+ t3.scale( 60, 60, TQSize::ScaleMax );
+ // t3 is (60, 72)
+ \endcode
+*/
+void TQSize::scale( int w, int h, ScaleMode mode )
+{
+ if ( mode == ScaleFree ) {
+ wd = (TQCOORD)w;
+ ht = (TQCOORD)h;
+ } else {
+ bool useHeight = TRUE;
+ int w0 = width();
+ int h0 = height();
+ int rw = h * w0 / h0;
+
+ if ( mode == ScaleMin ) {
+ useHeight = ( rw <= w );
+ } else { // mode == ScaleMax
+ useHeight = ( rw >= w );
+ }
+
+ if ( useHeight ) {
+ wd = (TQCOORD)rw;
+ ht = (TQCOORD)h;
+ } else {
+ wd = (TQCOORD)w;
+ ht = (TQCOORD)( w * h0 / w0 );
+ }
+ }
+}
+
+/*!
+ \overload
+
+ Equivalent to scale(\a{s}.width(), \a{s}.height(), \a mode).
+*/
+void TQSize::scale( const TQSize &s, ScaleMode mode )
+{
+ scale( s.width(), s.height(), mode );
+}
+
+/*!
+ \fn TQCOORD &TQSize::rwidth()
+ Returns a reference to the width.
+
+ Using a reference makes it possible to directly manipulate the width.
+
+ Example:
+ \code
+ TQSize s( 100, 10 );
+ s.rwidth() += 20; // s becomes (120,10)
+ \endcode
+
+ \sa rheight()
+*/
+
+/*!
+ \fn TQCOORD &TQSize::rheight()
+ Returns a reference to the height.
+
+ Using a reference makes it possible to directly manipulate the height.
+
+ Example:
+ \code
+ TQSize s( 100, 10 );
+ s.rheight() += 5; // s becomes (100,15)
+ \endcode
+
+ \sa rwidth()
+*/
+
+/*!
+ \fn TQSize &TQSize::operator+=( const TQSize &s )
+
+ Adds \a s to the size and returns a reference to this size.
+
+ Example:
+ \code
+ TQSize s( 3, 7 );
+ TQSize r( -1, 4 );
+ s += r; // s becomes (2,11)
+\endcode
+*/
+
+/*!
+ \fn TQSize &TQSize::operator-=( const TQSize &s )
+
+ Subtracts \a s from the size and returns a reference to this size.
+
+ Example:
+ \code
+ TQSize s( 3, 7 );
+ TQSize r( -1, 4 );
+ s -= r; // s becomes (4,3)
+ \endcode
+*/
+
+/*!
+ \fn TQSize &TQSize::operator*=( int c )
+ Multiplies both the width and height by \a c and returns a reference to
+ the size.
+*/
+
+/*!
+ \overload TQSize &TQSize::operator*=( double c )
+
+ Multiplies both the width and height by \a c and returns a reference to
+ the size.
+
+ Note that the result is truncated.
+*/
+
+/*!
+ \fn bool operator==( const TQSize &s1, const TQSize &s2 )
+ \relates TQSize
+ Returns TRUE if \a s1 and \a s2 are equal; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool operator!=( const TQSize &s1, const TQSize &s2 )
+ \relates TQSize
+ Returns TRUE if \a s1 and \a s2 are different; otherwise returns FALSE.
+*/
+
+/*!
+ \fn const TQSize operator+( const TQSize &s1, const TQSize &s2 )
+ \relates TQSize
+ Returns the sum of \a s1 and \a s2; each component is added separately.
+*/
+
+/*!
+ \fn const TQSize operator-( const TQSize &s1, const TQSize &s2 )
+ \relates TQSize
+ Returns \a s2 subtracted from \a s1; each component is
+ subtracted separately.
+*/
+
+/*!
+ \fn const TQSize operator*( const TQSize &s, int c )
+ \relates TQSize
+ Multiplies \a s by \a c and returns the result.
+*/
+
+/*!
+ \overload const TQSize operator*( int c, const TQSize &s )
+ \relates TQSize
+ Multiplies \a s by \a c and returns the result.
+*/
+
+/*!
+ \overload const TQSize operator*( const TQSize &s, double c )
+ \relates TQSize
+ Multiplies \a s by \a c and returns the result.
+*/
+
+/*!
+ \overload const TQSize operator*( double c, const TQSize &s )
+ \relates TQSize
+ Multiplies \a s by \a c and returns the result.
+*/
+
+/*!
+ \fn TQSize &TQSize::operator/=( int c )
+ Divides both the width and height by \a c and returns a reference to the
+ size.
+*/
+
+/*!
+ \fn TQSize &TQSize::operator/=( double c )
+ \overload
+ Divides both the width and height by \a c and returns a reference to the
+ size.
+
+ Note that the result is truncated.
+*/
+
+/*!
+ \fn const TQSize operator/( const TQSize &s, int c )
+ \relates TQSize
+ Divides \a s by \a c and returns the result.
+*/
+
+/*!
+ \fn const TQSize operator/( const TQSize &s, double c )
+ \relates TQSize
+ \overload
+ Divides \a s by \a c and returns the result.
+
+ Note that the result is truncated.
+*/
+
+/*!
+ \fn TQSize TQSize::expandedTo( const TQSize & otherSize ) const
+
+ Returns a size with the maximum width and height of this size and
+ \a otherSize.
+*/
+
+/*!
+ \fn TQSize TQSize::boundedTo( const TQSize & otherSize ) const
+
+ Returns a size with the minimum width and height of this size and
+ \a otherSize.
+*/
+
+
+void TQSize::warningDivByZero()
+{
+#if defined(TQT_CHECK_MATH)
+ qWarning( "TQSize: Division by zero error" );
+#endif
+}
+
+
+/*****************************************************************************
+ TQSize stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQSize
+ Writes the size \a sz to the stream \a s and returns a reference to
+ the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQSize &sz )
+{
+ if ( s.version() == 1 )
+ s << (TQ_INT16)sz.width() << (TQ_INT16)sz.height();
+ else
+ s << (TQ_INT32)sz.width() << (TQ_INT32)sz.height();
+ return s;
+}
+
+/*!
+ \relates TQSize
+ Reads the size from the stream \a s into size \a sz and returns a
+ reference to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQSize &sz )
+{
+ if ( s.version() == 1 ) {
+ TQ_INT16 w, h;
+ s >> w; sz.rwidth() = w;
+ s >> h; sz.rheight() = h;
+ }
+ else {
+ TQ_INT32 w, h;
+ s >> w; sz.rwidth() = w;
+ s >> h; sz.rheight() = h;
+ }
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqsize.h b/tqtinterface/qt4/src/kernel/tqsize.h
new file mode 100644
index 0000000..c74610b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsize.h
@@ -0,0 +1,318 @@
+/****************************************************************************
+**
+** Definition of TQSize class
+**
+** Created : 931028
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSIZE_H
+#define TQSIZE_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqpoint.h" // ### change to tqwindowdefs.h?
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qsize.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQSize : public QSize, virtual public TQt
+{
+public:
+ // ### Move this enum to tqnamespace.h in TQt 4.0
+ enum ScaleMode {
+ ScaleFree,
+ ScaleMin,
+ ScaleMax
+ };
+
+ TQSize() : QSize() {}
+ TQSize( int w, int h ) : QSize(w, h) {}
+
+ // Interoperability
+ TQSize(QSize a) {
+ setWidth(a.width());
+ setHeight(a.height());
+ }
+
+ void tqscale( int w, int h, ScaleMode mode ) { scale(w, h, (Qt::AspectRatioMode)mode); }
+ void tqscale( const TQSize &s, ScaleMode mode ) { scale(s, (Qt::AspectRatioMode)mode); }
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQSize
+// ### Make TQSize inherit TQt in TQt 4.0
+{
+public:
+ // ### Move this enum to tqnamespace.h in TQt 4.0
+ enum ScaleMode {
+ ScaleFree,
+ ScaleMin,
+ ScaleMax
+ };
+
+ TQSize();
+ TQSize( int w, int h );
+
+// #ifdef USE_QT4
+//
+// // // Interoperability
+// // TQPtrList(const QList<type*>& l)
+// // {
+// // for (int i = 0; i < l.size(); ++i) append(l.at(i));
+// // }
+// //
+// // TQPtrList<type>& operator= (const QList<type*>& l)
+// // {
+// // this->clear();
+// // for (int i = 0; i < l.size(); ++i) append(l.at(i));
+// // return *this;
+// // }
+// //
+// // operator QList<type*>() const {
+// // QList<type*> list;
+// // for (typename TQPtrList<type>::const_iterator it = TQPtrList<type>::constBegin();
+// // it != TQPtrList<type>::constEnd(); ++it)
+// // list.append(*it);
+// // return list;
+// // }
+//
+// // Interoperability
+// TQSize(const QSize& a)
+// {
+// setWidth(a.width());
+// setHeight(a.height());
+// }
+//
+// // TQSize& operator= (const QSize& a)
+// // {
+// // this->setWidth(a.width());
+// // this->setHeight(a.height());
+// // return *this;
+// // }
+//
+// operator QSize() const {
+// QSize a;
+// a.setWidth(width());
+// a.setHeight(height());
+// return a;
+// }
+//
+// #endif // USE_QT4
+
+ bool isNull() const;
+ bool isEmpty() const;
+ bool isValid() const;
+
+ int width() const;
+ int height() const;
+ void setWidth( int w );
+ void setHeight( int h );
+ void transpose();
+
+ void scale( int w, int h, ScaleMode mode );
+ void scale( const TQSize &s, ScaleMode mode );
+
+ TQSize expandedTo( const TQSize & ) const;
+ TQSize boundedTo( const TQSize & ) const;
+
+ TQCOORD &rwidth();
+ TQCOORD &rheight();
+
+ TQSize &operator+=( const TQSize & );
+ TQSize &operator-=( const TQSize & );
+ TQSize &operator*=( int c );
+ TQSize &operator*=( double c );
+ TQSize &operator/=( int c );
+ TQSize &operator/=( double c );
+
+ friend inline bool operator==( const TQSize &, const TQSize & );
+ friend inline bool operator!=( const TQSize &, const TQSize & );
+ friend inline const TQSize operator+( const TQSize &, const TQSize & );
+ friend inline const TQSize operator-( const TQSize &, const TQSize & );
+ friend inline const TQSize operator*( const TQSize &, int );
+ friend inline const TQSize operator*( int, const TQSize & );
+ friend inline const TQSize operator*( const TQSize &, double );
+ friend inline const TQSize operator*( double, const TQSize & );
+ friend inline const TQSize operator/( const TQSize &, int );
+ friend inline const TQSize operator/( const TQSize &, double );
+
+private:
+ static void warningDivByZero();
+
+ TQCOORD wd;
+ TQCOORD ht;
+};
+
+/*****************************************************************************
+ TQSize stream functions
+ *****************************************************************************/
+
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQSize & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQSize & );
+
+
+/*****************************************************************************
+ TQSize inline functions
+ *****************************************************************************/
+
+inline TQSize::TQSize()
+{ wd = ht = -1; }
+
+inline TQSize::TQSize( int w, int h )
+{ wd=(TQCOORD)w; ht=(TQCOORD)h; }
+
+inline bool TQSize::isNull() const
+{ return wd==0 && ht==0; }
+
+inline bool TQSize::isEmpty() const
+{ return wd<1 || ht<1; }
+
+inline bool TQSize::isValid() const
+{ return wd>=0 && ht>=0; }
+
+inline int TQSize::width() const
+{ return wd; }
+
+inline int TQSize::height() const
+{ return ht; }
+
+inline void TQSize::setWidth( int w )
+{ wd=(TQCOORD)w; }
+
+inline void TQSize::setHeight( int h )
+{ ht=(TQCOORD)h; }
+
+inline TQCOORD &TQSize::rwidth()
+{ return wd; }
+
+inline TQCOORD &TQSize::rheight()
+{ return ht; }
+
+inline TQSize &TQSize::operator+=( const TQSize &s )
+{ wd+=s.wd; ht+=s.ht; return *this; }
+
+inline TQSize &TQSize::operator-=( const TQSize &s )
+{ wd-=s.wd; ht-=s.ht; return *this; }
+
+inline TQSize &TQSize::operator*=( int c )
+{ wd*=(TQCOORD)c; ht*=(TQCOORD)c; return *this; }
+
+inline TQSize &TQSize::operator*=( double c )
+{ wd=(TQCOORD)(wd*c); ht=(TQCOORD)(ht*c); return *this; }
+
+inline bool operator==( const TQSize &s1, const TQSize &s2 )
+{ return s1.wd == s2.wd && s1.ht == s2.ht; }
+
+inline bool operator!=( const TQSize &s1, const TQSize &s2 )
+{ return s1.wd != s2.wd || s1.ht != s2.ht; }
+
+inline const TQSize operator+( const TQSize & s1, const TQSize & s2 )
+{ return TQSize(s1.wd+s2.wd, s1.ht+s2.ht); }
+
+inline const TQSize operator-( const TQSize &s1, const TQSize &s2 )
+{ return TQSize(s1.wd-s2.wd, s1.ht-s2.ht); }
+
+inline const TQSize operator*( const TQSize &s, int c )
+{ return TQSize(s.wd*c, s.ht*c); }
+
+inline const TQSize operator*( int c, const TQSize &s )
+{ return TQSize(s.wd*c, s.ht*c); }
+
+inline const TQSize operator*( const TQSize &s, double c )
+{ return TQSize((TQCOORD)(s.wd*c), (TQCOORD)(s.ht*c)); }
+
+inline const TQSize operator*( double c, const TQSize &s )
+{ return TQSize((TQCOORD)(s.wd*c), (TQCOORD)(s.ht*c)); }
+
+inline TQSize &TQSize::operator/=( int c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0 )
+ warningDivByZero();
+#endif
+ wd/=(TQCOORD)c; ht/=(TQCOORD)c;
+ return *this;
+}
+
+inline TQSize &TQSize::operator/=( double c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0.0 )
+ warningDivByZero();
+#endif
+ wd=(TQCOORD)(wd/c); ht=(TQCOORD)(ht/c);
+ return *this;
+}
+
+inline const TQSize operator/( const TQSize &s, int c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0 )
+ TQSize::warningDivByZero();
+#endif
+ return TQSize(s.wd/c, s.ht/c);
+}
+
+inline const TQSize operator/( const TQSize &s, double c )
+{
+#if defined(TQT_CHECK_MATH)
+ if ( c == 0.0 )
+ TQSize::warningDivByZero();
+#endif
+ return TQSize((TQCOORD)(s.wd/c), (TQCOORD)(s.ht/c));
+}
+
+inline TQSize TQSize::expandedTo( const TQSize & otherSize ) const
+{
+ return TQSize( TQMAX(wd,otherSize.wd), TQMAX(ht,otherSize.ht) );
+}
+
+inline TQSize TQSize::boundedTo( const TQSize & otherSize ) const
+{
+ return TQSize( TQMIN(wd,otherSize.wd), TQMIN(ht,otherSize.ht) );
+}
+
+#endif // USE_QT4
+
+#endif // TQSIZE_H
diff --git a/tqtinterface/qt4/src/kernel/tqsizegrip.cpp b/tqtinterface/qt4/src/kernel/tqsizegrip.cpp
new file mode 100644
index 0000000..bcea2db
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsizegrip.cpp
@@ -0,0 +1,286 @@
+/****************************************************************************
+**
+** Implementation of TQSizeGrip class
+**
+** Created : 980119
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsizegrip.h"
+
+#ifndef TQT_NO_SIZEGRIP
+
+#include "tqpainter.h"
+#include "tqapplication.h"
+#include "tqstyle.h"
+
+#if defined(TQ_WS_X11)
+#include "tqt_x11_p.h"
+extern Atom qt_sizegrip; // defined in qapplication_x11.cpp
+#elif defined (TQ_WS_WIN )
+#include "tqobjectlist.h"
+#include "tqt_windows.h"
+#elif defined(TQ_WS_MAC)
+bool qt_mac_update_sizer(TQWidget *, int); //qwidget_mac.cpp
+#endif
+
+
+static TQWidget *qt_sizegrip_tqtopLevelWidget( TQWidget* w)
+{
+ TQWidget *p = w->parentWidget();
+ while ( !w->isTopLevel() && p && !p->inherits("TQWorkspace") ) {
+ w = p;
+ p = p->parentWidget();
+ }
+ return w;
+}
+
+static TQWidget* qt_sizegrip_workspace( TQWidget* w )
+{
+ while ( w && !w->inherits("TQWorkspace" ) ) {
+ if ( w->isTopLevel() )
+ return 0;
+ w = w->parentWidget();
+ }
+ return w;
+}
+
+
+/*!
+ \class TQSizeGrip tqsizegrip.h
+
+ \brief The TQSizeGrip class provides a corner-grip for resizing a top-level window.
+
+ \ingroup application
+ \ingroup basic
+ \ingroup appearance
+
+ This widget works like the standard Windows resize handle. In the
+ X11 version this resize handle generally works differently from
+ the one provided by the system; we hope to reduce this difference
+ in the future.
+
+ Put this widget anywhere in a widget tree and the user can use it
+ to resize the top-level window. Generally, this should be in the
+ lower right-hand corner. Note that TQStatusBar already uses this
+ widget, so if you have a status bar (e.g. you are using
+ TQMainWindow), then you don't need to use this widget explicitly.
+
+ <img src=qsizegrip-m.png> <img src=qsizegrip-w.png>
+
+ \sa TQStatusBar
+*/
+
+
+/*!
+ Constructs a resize corner called \a name, as a child widget of \a
+ tqparent.
+*/
+TQSizeGrip::TQSizeGrip( TQWidget * tqparent, const char* name )
+ : TQWidget( tqparent, name )
+{
+#ifndef TQT_NO_CURSOR
+#ifndef TQ_WS_MAC
+ if ( TQApplication::reverseLayout() )
+ setCursor( Qt::SizeBDiagCursor );
+ else
+ setCursor( Qt::SizeFDiagCursor );
+#endif
+#endif
+ tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) );
+#if defined(TQ_WS_X11)
+ if ( !qt_sizegrip_workspace( this ) ) {
+ WId id = winId();
+ XChangeProperty(qt_xdisplay(), tqtopLevelWidget()->winId(),
+ qt_sizegrip, XA_WINDOW, 32, PropModeReplace,
+ (unsigned char *)&id, 1);
+ }
+#endif
+ tlw = qt_sizegrip_tqtopLevelWidget( this );
+ if ( tlw )
+ tlw->installEventFilter( this );
+ installEventFilter( this ); //for binary compatibility fix in 4.0 with an event() ###
+}
+
+
+/*!
+ Destroys the size grip.
+*/
+TQSizeGrip::~TQSizeGrip()
+{
+#if defined(TQ_WS_X11)
+ if ( !TQApplication::closingDown() && parentWidget() ) {
+ WId id = None;
+ XChangeProperty(qt_xdisplay(), tqtopLevelWidget()->winId(),
+ qt_sizegrip, XA_WINDOW, 32, PropModeReplace,
+ (unsigned char *)&id, 1);
+ }
+#endif
+}
+
+/*!
+ Returns the size grip's size hint; this is a small size.
+*/
+TQSize TQSizeGrip::tqsizeHint() const
+{
+ return (tqstyle().tqsizeFromContents(TQStyle::CT_SizeGrip, this, TQSize(13, 13)).
+ expandedTo(TQApplication::globalStrut()));
+}
+
+/*!
+ Paints the resize grip. Resize grips are usually rendered as small
+ diagonal textured lines in the lower-right corner. The event is in
+ \a e.
+*/
+void TQSizeGrip::paintEvent( TQPaintEvent *e )
+{
+ TQPainter painter( this );
+ painter.setClipRegion(e->region());
+ tqstyle().tqdrawPrimitive(TQStyle::PE_SizeGrip, &painter, rect(), tqcolorGroup());
+}
+
+/*!
+ Primes the resize operation. The event is in \a e.
+*/
+void TQSizeGrip::mousePressEvent( TQMouseEvent * e )
+{
+ p = e->globalPos();
+ s = qt_sizegrip_tqtopLevelWidget(this)->size();
+}
+
+
+/*!
+ Resizes the top-level widget containing this widget. The event is
+ in \a e.
+*/
+void TQSizeGrip::mouseMoveEvent( TQMouseEvent * e )
+{
+ if ( e->state() != Qt::LeftButton )
+ return;
+
+ TQWidget* tlw = qt_sizegrip_tqtopLevelWidget(this);
+ if ( tlw->testWState((WState)TQt::WState_ConfigPending) )
+ return;
+
+ TQPoint np( e->globalPos() );
+
+ TQWidget* ws = qt_sizegrip_workspace( this );
+ if ( ws ) {
+ TQPoint tmp( ws->mapFromGlobal( np ) );
+ if ( tmp.x() > ws->width() )
+ tmp.setX( ws->width() );
+ if ( tmp.y() > ws->height() )
+ tmp.setY( ws->height() );
+ np = ws->mapToGlobal( tmp );
+ }
+
+ int w;
+ int h = np.y() - p.y() + s.height();
+
+ if ( TQApplication::reverseLayout() )
+ w = s.width() - ( np.x() - p.x() );
+ else
+ w = np.x() - p.x() + s.width();
+
+ if ( w < 1 )
+ w = 1;
+ if ( h < 1 )
+ h = 1;
+ TQSize ms( tlw->tqminimumSizeHint() );
+ ms = ms.expandedTo( tqminimumSize() );
+ if ( w < ms.width() )
+ w = ms.width();
+ if ( h < ms.height() )
+ h = ms.height();
+
+ if (TQApplication::reverseLayout()) {
+ tlw->resize( w, h );
+ if (tlw->size() == TQSize(w,h))
+ tlw->move( tlw->x() + ( np.x()-p.x() ), tlw->y() );
+ } else {
+ tlw->resize( w, h );
+ }
+#ifdef TQ_WS_WIN
+ MSG msg;
+ while( PeekMessage( &msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE ) )
+ ;
+#endif
+ TQApplication::syncX();
+
+ if ( TQApplication::reverseLayout() && tlw->size() == TQSize(w,h) ) {
+ s.rwidth() = tlw->size().width();
+ p.rx() = np.x();
+ }
+}
+
+/*! \reimp */
+bool TQSizeGrip::eventFilter( TQObject *o, TQEvent *e )
+{
+ if ( static_cast<TQT_BASE_OBJECT_NAME*>(o) == tlw ) {
+ switch ( e->type() ) {
+#ifndef TQ_WS_MAC
+ /* The size grip goes no where on Mac OS X when you maximize! --Sam */
+ case TQEvent::ShowMaximized:
+#endif
+ case TQEvent::ShowFullScreen:
+ hide();
+ break;
+ case TQEvent::ShowNormal:
+ show();
+ break;
+ default:
+ break;
+ }
+ } else if(static_cast<TQT_BASE_OBJECT_NAME*>(o) == this) {
+#if defined(TQ_WS_MAC)
+ switch(e->type()) {
+ case TQEvent::Hide:
+ case TQEvent::Show:
+ if(!TQApplication::closingDown() && parentWidget() && !qt_sizegrip_workspace(this)) {
+ if(TQWidget *w = qt_sizegrip_tqtopLevelWidget(this)) {
+ if(w->isTopLevel())
+ qt_mac_update_sizer(w, e->type() == TQEvent::Hide ? -1 : 1);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ #endif
+ }
+ return FALSE;
+}
+
+#endif //TQT_NO_SIZEGRIP
diff --git a/tqtinterface/qt4/src/kernel/tqsizegrip.h b/tqtinterface/qt4/src/kernel/tqsizegrip.h
new file mode 100644
index 0000000..fa893a2
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsizegrip.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Definition of TQSizeGrip class
+**
+** Created : 980316
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSIZEGRIP_H
+#define TQSIZEGRIP_H
+
+#ifndef TQT_H
+#include "tqwidget.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_SIZEGRIP
+
+class TQ_EXPORT TQSizeGrip: public TQWidget
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQSizeGrip( TQWidget* tqparent, const char* name=0 );
+ ~TQSizeGrip();
+
+ TQSize tqsizeHint() const;
+
+protected:
+ void paintEvent( TQPaintEvent * );
+ void mousePressEvent( TQMouseEvent * );
+ void mouseMoveEvent( TQMouseEvent * );
+
+ bool eventFilter( TQObject *, TQEvent * );
+
+private:
+ TQPoint p;
+ TQSize s;
+ int d;
+ TQWidget *tlw;
+};
+
+#endif //TQT_NO_SIZEGRIP
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqsizepolicy.h b/tqtinterface/qt4/src/kernel/tqsizepolicy.h
new file mode 100644
index 0000000..29236a0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsizepolicy.h
@@ -0,0 +1,194 @@
+/****************************************************************************
+**
+** Definition of the TQSizePolicy class
+**
+** Created : 980929
+**
+** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSIZEPOLICY_H
+#define TQSIZEPOLICY_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqglobal.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qsizepolicy.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQSizePolicy : public QSizePolicy
+{
+public:
+ typedef Policy SizeType;
+ typedef Qt::Orientations ExpandData;
+ enum {
+ NoDirection = 0,
+ Horizontally = 1,
+ Vertically = 2,
+ BothDirections = Horizontally | Vertically
+ };
+
+ TQSizePolicy() : QSizePolicy() {}
+ TQSizePolicy( SizeType hor, SizeType ver, bool hfw = FALSE ) : QSizePolicy( hor, ver ) {
+ setHorizontalPolicy(hor);
+ setVerticalPolicy(ver);
+ setHeightForWidth(hfw);
+ }
+ TQSizePolicy( SizeType hor, SizeType ver, uchar hors, uchar vers, bool hfw = FALSE ) : QSizePolicy( hor, ver )
+ {
+ setHorizontalPolicy(hor);
+ setVerticalPolicy(ver);
+ setHorizontalStretch(hors);
+ setVerticalStretch(vers);
+ setHeightForWidth(hfw);
+ }
+
+ inline ExpandData expanding() const { return expandingDirections(); }
+ inline bool mayShrinkHorizontally() const { return horizontalPolicy() & QSizePolicy::ShrinkFlag; }
+ inline bool mayShrinkVertically() const { return verticalPolicy() & QSizePolicy::ShrinkFlag; }
+ inline bool mayGrowHorizontally() const { return QSizePolicy::horizontalPolicy() & QSizePolicy::GrowFlag; }
+ inline bool mayGrowVertically() const { return verticalPolicy() & QSizePolicy::GrowFlag; }
+
+ inline SizeType horData() const { return horizontalPolicy(); }
+ inline SizeType verData() const { return verticalPolicy(); }
+ inline void setHorData(Policy d) { setHorizontalPolicy(d); }
+ inline void setVerData(Policy d) { setVerticalPolicy(d); }
+
+ inline uint horStretch() const { return horizontalStretch(); }
+ inline uint verStretch() const { return verticalStretch(); }
+ inline void setHorStretch(uchar sf) { setHorizontalStretch(sf); }
+ inline void setVerStretch(uchar sf) { setVerticalStretch(sf); }
+
+ // Interoperability
+ static const TQSizePolicy& convertFromQSizePolicy( QSizePolicy& qs );
+};
+
+// Interoperability
+inline static const TQSizePolicy& convertFromQSizePolicy( const QSizePolicy& qs ) {
+ return (*static_cast<const TQSizePolicy*>(&qs));
+}
+
+#else // USE_QT4
+
+// Documentation is in qabstracttqlayout.cpp.
+
+class TQ_EXPORT TQSizePolicy
+{
+private:
+ enum SizePolicy_Internal { HSize = 6, HMask = 0x3f, VMask = HMask << HSize,
+ MayGrow = 1, ExpMask = 2, MayShrink = 4 };
+public:
+ enum SizeType { Fixed = 0,
+ Minimum = MayGrow,
+ Maximum = MayShrink,
+ Preferred = MayGrow | MayShrink,
+ MinimumExpanding = MayGrow | ExpMask,
+ Expanding = MayGrow | MayShrink | ExpMask,
+ Ignored = ExpMask /* magic value */ };
+
+ enum ExpandData { NoDirection = 0,
+ Horizontally = 1,
+ Vertically = 2,
+#ifndef TQT_NO_COMPAT
+ Horizontal = Horizontally,
+ Vertical = Vertically,
+#endif
+ BothDirections = Horizontally | Vertically };
+
+ TQSizePolicy() : data( 0 ) { }
+
+ TQSizePolicy( SizeType hor, SizeType ver, bool hfw = FALSE )
+ : data( hor | (ver<<HSize) | (hfw ? (TQ_UINT32)(1<<2*HSize) : 0) ) { }
+ TQSizePolicy( SizeType hor, SizeType ver, uchar hors, uchar vers, bool hfw = FALSE );
+
+ SizeType horData() const { return (SizeType)( data & HMask ); }
+ SizeType verData() const { return (SizeType)( (data & VMask) >> HSize ); }
+
+ bool mayShrinkHorizontally() const { return horData() & MayShrink || horData() == Ignored; }
+ bool mayShrinkVertically() const { return verData() & MayShrink || verData() == Ignored; }
+ bool mayGrowHorizontally() const { return horData() & MayGrow || horData() == Ignored; }
+ bool mayGrowVertically() const { return verData() & MayGrow || verData() == Ignored; }
+
+ ExpandData expanding() const
+ {
+ return (ExpandData)( (int)(verData() & ExpMask ? Vertically : 0) |
+ (int)(horData() & ExpMask ? Horizontally : 0) );
+ }
+
+ void setHorData( SizeType d ) { data = (TQ_UINT32)(data & ~HMask) | d; }
+ void setVerData( SizeType d ) { data = (TQ_UINT32)(data & ~(HMask << HSize)) |
+ (d << HSize); }
+
+ void setHeightForWidth( bool b ) { data = b ? (TQ_UINT32)( data | ( 1 << 2*HSize ) )
+ : (TQ_UINT32)( data & ~( 1 << 2*HSize ) ); }
+ bool hasHeightForWidth() const { return data & ( 1 << 2*HSize ); }
+
+ bool operator==( const TQSizePolicy& s ) const { return data == s.data; }
+ bool operator!=( const TQSizePolicy& s ) const { return data != s.data; }
+
+
+ uint horStretch() const { return data >> 24; }
+ uint verStretch() const { return (data >> 16) & 0xff; }
+ void setHorStretch( uchar sf ) { data = (data&0x00ffffff) | (uint(sf)<<24); }
+ void setVerStretch( uchar sf ) { data = (data&0xff00ffff) | (uint(sf)<<16); }
+ inline void transpose();
+
+private:
+ TQSizePolicy( int i ) : data( (TQ_UINT32)i ) { }
+
+ TQ_UINT32 data;
+};
+
+inline TQSizePolicy::TQSizePolicy( SizeType hor, SizeType ver, uchar hors, uchar vers, bool hfw )
+ : data( hor | (ver<<HSize) | (hfw ? (TQ_UINT32)(1<<2*HSize) : 0) ) {
+ setHorStretch( hors );
+ setVerStretch( vers );
+}
+
+inline void TQSizePolicy::transpose() {
+ *this = TQSizePolicy( verData(), horData(), verStretch(), horStretch(),
+ hasHeightForWidth() );
+}
+
+#endif // USE_QT4
+
+#endif // TQSIZEPOLICY_H
diff --git a/tqtinterface/qt4/src/kernel/tqsocketnotifier.cpp b/tqtinterface/qt4/src/kernel/tqsocketnotifier.cpp
new file mode 100644
index 0000000..9275de3
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsocketnotifier.cpp
@@ -0,0 +1,270 @@
+/****************************************************************************
+**
+** Implementation of TQSocketNotifier class
+**
+** Created : 951114
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsocketnotifier.h"
+#include "tqapplication.h"
+#include "tqevent.h"
+#include "tqeventloop.h"
+#include "tqplatformdefs.h"
+
+#if defined(TQ_OS_UNIX)
+#include <sys/types.h>
+#endif
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+/*!
+ \class TQSocketNotifier tqsocketnotifier.h
+ \brief The TQSocketNotifier class provides support for socket callbacks.
+
+ \ingroup io
+
+ This class makes it possible to write asynchronous socket-based
+ code in TQt. Using synchronous socket operations blocks the
+ program, which is clearly not acceptable for an event-driven GUI
+ program.
+
+ Once you have opened a non-blocking socket (whether for TCP, UDP,
+ a UNIX-domain socket, or any other protocol family your operating
+ system supports), you can create a socket notifier to monitor the
+ socket. Then you connect the activated() signal to the slot you
+ want to be called when a socket event occurs.
+
+ Note for Windows users: the socket passed to TQSocketNotifier will
+ become non-blocking, even if it was created as a blocking socket.
+
+ There are three types of socket notifiers (read, write and
+ exception); you must specify one of these in the constructor.
+
+ The type specifies when the activated() signal is to be emitted:
+ \list 1
+ \i TQSocketNotifier::Read - There is data to be read (socket read event).
+ \i TQSocketNotifier::Write - Data can be written (socket write event).
+ \i TQSocketNofifier::Exception - An exception has occurred (socket
+ exception event). We recommend against using this.
+ \endlist
+
+ For example, if you need to monitor both reads and writes for the
+ same socket you must create two socket notifiers.
+
+ For read notifiers it makes little sense to connect the
+ activated() signal to more than one slot because the data can be
+ read from the socket only once.
+
+ Also observe that if you do not read all the available data when
+ the read notifier fires, it fires again and again.
+
+ For write notifiers, immediately disable the notifier after the
+ activated() signal has been received and you have sent the data to
+ be written on the socket. When you have more data to be written,
+ enable it again to get a new activated() signal. The exception is
+ if the socket data writing operation (send() or equivalent) fails
+ with a "would block" error, which means that some buffer is full
+ and you must wait before sending more data. In that case you do
+ not need to disable and re-enable the write notifier; it will fire
+ again as soon as the system allows more data to be sent.
+
+ The behavior of a write notifier that is left in enabled state
+ after having emitting the first activated() signal (and no "would
+ block" error has occurred) is undefined. Depending on the
+ operating system, it may fire on every pass of the event loop or
+ not at all.
+
+ If you need a time-out for your sockets you can use either \link
+ TQObject::startTimer() timer events\endlink or the TQTimer class.
+
+ Socket action is detected in the \link TQApplication::exec() main
+ event loop\endlink of TQt. The X11 version of TQt has a single UNIX
+ select() call that incorporates all socket notifiers and the X
+ socket.
+
+ Note that on XFree86 for OS/2, select() works only in the thread
+ in which main() is running; you should therefore use that thread
+ for GUI operations.
+
+ \sa TQSocket, TQServerSocket, TQSocketDevice, TQFile::handle()
+*/
+
+/*!
+ \enum TQSocketNotifier::Type
+
+ \value Read
+ \value Write
+ \value Exception
+*/
+
+
+/*!
+ Constructs a socket notifier called \a name, with the tqparent, \a
+ tqparent. It watches \a socket for \a type events, and enables it.
+
+ It is generally advisable to explicitly enable or disable the
+ socket notifier, especially for write notifiers.
+
+ \sa setEnabled(), isEnabled()
+*/
+
+TQSocketNotifier::TQSocketNotifier( int socket, Type type, TQObject *tqparent,
+ const char *name )
+ : TQObject( tqparent, name )
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( socket < 0 )
+ qWarning( "TQSocketNotifier: Invalid socket specified" );
+# if defined(TQ_OS_UNIX)
+ if ( socket >= FD_SETSIZE )
+ qWarning( "TQSocketNotifier: Socket descriptor too large for select()" );
+# endif
+#endif
+ sockfd = socket;
+ sntype = type;
+ snenabled = TRUE;
+ TQApplication::eventLoop()->registerSocketNotifier( this );
+}
+
+/*!
+ Destroys the socket notifier.
+*/
+
+TQSocketNotifier::~TQSocketNotifier()
+{
+ setEnabled( FALSE );
+}
+
+
+/*!
+ \fn void TQSocketNotifier::activated( int socket )
+
+ This signal is emitted under certain conditions specified by the
+ notifier type():
+ \list 1
+ \i TQSocketNotifier::Read - There is data to be read (socket read event).
+ \i TQSocketNotifier::Write - Data can be written (socket write event).
+ \i TQSocketNofifier::Exception - An exception has occurred (socket
+ exception event).
+ \endlist
+
+ The \a socket argument is the \link socket() socket\endlink identifier.
+
+ \sa type(), socket()
+*/
+
+
+/*!
+ \fn int TQSocketNotifier::socket() const
+
+ Returns the socket identifier specified to the constructor.
+
+ \sa type()
+*/
+
+/*!
+ \fn Type TQSocketNotifier::type() const
+
+ Returns the socket event type specified to the constructor: \c
+ TQSocketNotifier::Read, \c TQSocketNotifier::Write, or \c
+ TQSocketNotifier::Exception.
+
+ \sa socket()
+*/
+
+
+/*!
+ \fn bool TQSocketNotifier::isEnabled() const
+
+ Returns TRUE if the notifier is enabled; otherwise returns FALSE.
+
+ \sa setEnabled()
+*/
+
+/*!
+ Enables the notifier if \a enable is TRUE or disables it if \a
+ enable is FALSE.
+
+ The notifier is enabled by default.
+
+ If the notifier is enabled, it emits the activated() signal
+ whenever a socket event corresponding to its \link type()
+ type\endlink occurs. If it is disabled, it ignores socket events
+ (the same effect as not creating the socket notifier).
+
+ Write notifiers should normally be disabled immediately after the
+ activated() signal has been emitted; see discussion of write
+ notifiers in the \link #details class description\endlink above.
+
+ \sa isEnabled(), activated()
+*/
+
+void TQSocketNotifier::setEnabled( bool enable )
+{
+ if ( sockfd < 0 )
+ return;
+ if ( snenabled == enable ) // no change
+ return;
+ snenabled = enable;
+
+ TQEventLoop *eventloop = TQApplication::eventLoop();
+ if ( ! eventloop ) // perhaps application is shutting down
+ return;
+
+ if ( snenabled )
+ eventloop->registerSocketNotifier( this );
+ else
+ eventloop->unregisterSocketNotifier( this );
+}
+
+
+/*!\reimp
+*/
+bool TQSocketNotifier::event( TQEvent *e )
+{
+ // Emits the activated() signal when a \c TQEvent::SockAct is
+ // received.
+ TQObject::event( e ); // will activate filters
+ if ( e->type() == TQEvent::SockAct ) {
+ emit activated( sockfd );
+ return TRUE;
+ }
+ return FALSE;
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqsocketnotifier.h b/tqtinterface/qt4/src/kernel/tqsocketnotifier.h
new file mode 100644
index 0000000..404e9f7
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsocketnotifier.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Definition of TQSocketNotifier class
+**
+** Created : 951114
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSOCKETNOTIFIER_H
+#define TQSOCKETNOTIFIER_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include <Qt/qsocketnotifier.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQSocketNotifier : public QSocketNotifier
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQSocketNotifier( int socket, Type type, TQObject *tqparent=0, const char *name=0 ) : QSocketNotifier(socket, type, tqparent) { setObjectName(name); }
+};
+
+#else // USE_QT4
+
+class TQ_EXPORT TQSocketNotifier : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ enum Type { Read, Write, Exception };
+
+ TQSocketNotifier( int socket, Type, TQObject *tqparent=0, const char *name=0 );
+ ~TQSocketNotifier();
+
+ int socket() const;
+ Type type() const;
+
+ bool isEnabled() const;
+ virtual void setEnabled( bool );
+
+Q_SIGNALS:
+ void activated( int socket );
+
+protected:
+ bool event( TQEvent * );
+
+private:
+ int sockfd;
+ Type sntype;
+ bool snenabled;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQSocketNotifier( const TQSocketNotifier & );
+ TQSocketNotifier &operator=( const TQSocketNotifier & );
+#endif
+};
+
+
+inline int TQSocketNotifier::socket() const
+{ return sockfd; }
+
+inline TQSocketNotifier::Type TQSocketNotifier::type() const
+{ return sntype; }
+
+inline bool TQSocketNotifier::isEnabled() const
+{ return snenabled; }
+
+#endif // USE_QT4
+
+#endif // TQSOCKETNOTIFIER_H
diff --git a/tqtinterface/qt4/src/kernel/tqsound.cpp b/tqtinterface/qt4/src/kernel/tqsound.cpp
new file mode 100644
index 0000000..afb3871
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsound.cpp
@@ -0,0 +1,316 @@
+/****************************************************************************
+**
+** Implementation of TQSound class and TQAuServer internal class
+**
+** Created : 000117
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqsound.h"
+
+#ifndef TQT_NO_SOUND
+
+#include "tqptrlist.h"
+
+static TQPtrList<TQAuServer> *servers=0;
+
+TQAuServer::TQAuServer(TQObject* tqparent, const char* name) :
+ TQObject(tqparent,name)
+{
+ if ( !servers ) {
+ servers = new TQPtrList<TQAuServer>;
+ // ### add cleanup
+ }
+ servers->prepend(this);
+}
+
+TQAuServer::~TQAuServer()
+{
+ servers->remove(this);
+ if ( servers->count() == 0 ) {
+ delete servers;
+ servers = 0;
+ }
+}
+
+void TQAuServer::play(const TQString& filename)
+{
+ TQSound s(filename);
+ play(&s);
+}
+
+extern TQAuServer* qt_new_audio_server();
+
+static TQAuServer& server()
+{
+ if (!servers) qt_new_audio_server();
+ return *servers->first();
+}
+
+class TQSoundData {
+public:
+ TQSoundData(const TQString& fname) :
+ filename(fname), bucket(0), looprem(0), looptotal(1)
+ {
+ }
+
+ ~TQSoundData()
+ {
+ delete bucket;
+ }
+
+ TQString filename;
+ TQAuBucket* bucket;
+ int looprem;
+ int looptotal;
+};
+
+/*!
+ \class TQSound tqsound.h
+ \brief The TQSound class provides access to the platform audio facilities.
+
+ \ingroup multimedia
+ \mainclass
+
+ TQt provides the most commonly required audio operation in GUI
+ applications: asynchronously playing a sound file. This is most
+ easily accomplished with a single call:
+ \code
+ TQSound::play("mysounds/bells.wav");
+ \endcode
+
+ A second API is provided in which a TQSound object is created from
+ a sound file and is played later:
+ \code
+ TQSound bells("mysounds/bells.wav");
+
+ bells.play();
+ \endcode
+
+ Sounds played using the second model may use more memory but play
+ more immediately than sounds played using the first model,
+ depending on the underlying platform audio facilities.
+
+ On Microsoft Windows the underlying multimedia system is used;
+ only WAVE format sound files are supported.
+
+ On X11 the \link ftp://ftp.x.org/contrib/audio/nas/ Network Audio
+ System\endlink is used if available, otherwise all operations work
+ silently. NAS supports WAVE and AU files.
+
+ On Macintosh, ironically, we use QT (\link
+ http://quicktime.apple.com QuickTime\endlink) for sound, this
+ means all QuickTime formats are supported by TQt/Mac.
+
+ On TQt/Embedded, a built-in mixing sound server is used, which
+ accesses \c /dev/dsp directly. Only the WAVE format is supported.
+
+ The availability of sound can be tested with
+ TQSound::isAvailable().
+*/
+
+/*!
+ \fn static bool TQSound::available()
+
+ Returns TRUE if sound support is available; otherwise returns FALSE.
+*/
+
+/*!
+ Plays the sound in a file called \a filename.
+*/
+void TQSound::play(const TQString& filename)
+{
+ server().play(filename);
+}
+
+/*!
+ Constructs a TQSound that can quickly play the sound in a file
+ named \a filename.
+
+ This may use more memory than the static \c play function.
+
+ The \a tqparent and \a name arguments (default 0) are passed on to
+ the TQObject constructor.
+*/
+TQSound::TQSound(const TQString& filename, TQObject* tqparent, const char* name) :
+ TQObject(tqparent,name),
+ d(new TQSoundData(filename))
+{
+ server().init(this);
+}
+
+/*!
+ Destroys the sound object. If the sound is not finished playing stop() is called on it.
+
+ \sa stop() isFinished()
+*/
+TQSound::~TQSound()
+{
+ if ( !isFinished() )
+ stop();
+ delete d;
+}
+
+/*!
+ Returns TRUE if the sound has finished playing; otherwise returns FALSE.
+
+ \warning On Windows this function always returns TRUE for unlooped sounds.
+*/
+bool TQSound::isFinished() const
+{
+ return d->looprem == 0;
+}
+
+/*!
+ \overload
+
+ Starts the sound playing. The function returns immediately.
+ Depending on the platform audio facilities, other sounds may stop
+ or may be mixed with the new sound.
+
+ The sound can be played again at any time, possibly mixing or
+ replacing previous plays of the sound.
+*/
+void TQSound::play()
+{
+ d->looprem = d->looptotal;
+ server().play(this);
+}
+
+/*!
+ Returns the number of times the sound will play.
+*/
+int TQSound::loops() const
+{
+ return d->looptotal;
+}
+
+/*!
+ Returns the number of times the sound will loop. This value
+ decreases each time the sound loops.
+*/
+int TQSound::loopsRemaining() const
+{
+ return d->looprem;
+}
+
+/*!
+ Sets the sound to repeat \a l times when it is played. Passing the
+ value -1 will cause the sound to loop indefinitely.
+
+ \sa loops()
+*/
+void TQSound::setLoops(int l)
+{
+ d->looptotal = l;
+}
+
+/*!
+ Returns the filename associated with the sound.
+*/
+TQString TQSound::fileName() const
+{
+ return d->filename;
+}
+
+/*!
+ Stops the sound playing.
+
+ On Windows the current loop will finish if a sound is played
+ in a loop.
+
+ \sa play()
+*/
+void TQSound::stop()
+{
+ server().stop(this);
+}
+
+
+/*!
+ Returns TRUE if sound facilities exist on the platform; otherwise
+ returns FALSE. An application may choose either to notify the user
+ if sound is crucial to the application or to operate silently
+ without bothering the user.
+
+ If no sound is available, all TQSound operations work silently and
+ quickly.
+*/
+bool TQSound::isAvailable()
+{
+ return server().okay();
+}
+
+/*!
+ Sets the internal bucket record of sound \a s to \a b, deleting
+ any previous setting.
+*/
+void TQAuServer::setBucket(TQSound* s, TQAuBucket* b)
+{
+ delete s->d->bucket;
+ s->d->bucket = b;
+}
+
+/*!
+ Returns the internal bucket record of sound \a s.
+*/
+TQAuBucket* TQAuServer::bucket(TQSound* s)
+{
+ return s->d->bucket;
+}
+
+/*!
+ Decrements the TQSound::loopRemaining() value for sound \a s,
+ returning the result.
+*/
+int TQAuServer::decLoop(TQSound* s)
+{
+ if ( s->d->looprem > 0 )
+ --s->d->looprem;
+ return s->d->looprem;
+}
+
+/*!
+ Initializes the sound. The default implementation does nothing.
+*/
+void TQAuServer::init(TQSound*)
+{
+}
+
+TQAuBucket::~TQAuBucket()
+{
+}
+
+#endif // TQT_NO_SOUND
diff --git a/tqtinterface/qt4/src/kernel/tqsound.h b/tqtinterface/qt4/src/kernel/tqsound.h
new file mode 100644
index 0000000..a24a63f
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsound.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Definition of TQSound class and TQAuServer internal class
+**
+** Created : 000117
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+#ifndef TQSOUND_H
+#define TQSOUND_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_SOUND
+
+class TQSoundData;
+
+class TQ_EXPORT TQSound : public TQObject {
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ static bool isAvailable();
+ static void play(const TQString& filename);
+
+ TQSound(const TQString& filename, TQObject* tqparent=0, const char* name=0);
+ ~TQSound();
+
+ /* Coming soon...
+ ?
+ TQSound(int hertz, Type type=Mono);
+ int play(const ushort* data, int samples);
+ bool full();
+ signal void notFull();
+ ?
+ */
+
+#ifndef TQT_NO_COMPAT
+ static bool available() { return isAvailable(); }
+#endif
+
+ int loops() const;
+ int loopsRemaining() const;
+ void setLoops(int);
+ TQString fileName() const;
+
+ bool isFinished() const;
+
+public Q_SLOTS:
+ void play();
+ void stop();
+
+private:
+ TQSoundData* d;
+ friend class TQAuServer;
+};
+
+
+/*
+ TQAuServer is an INTERNAL class. If you wish to provide support for
+ additional audio servers, you can make a subclass of TQAuServer to do
+ so, HOWEVER, your class may need to be re-engineered to some degree
+ with each new TQt release, including minor releases.
+
+ TQAuBucket is whatever you want.
+*/
+
+class TQAuBucket {
+public:
+ virtual ~TQAuBucket();
+};
+
+class TQAuServer : public TQObject {
+ TQ_OBJECT
+
+public:
+ TQAuServer(TQObject* tqparent, const char* name);
+ ~TQAuServer();
+
+ virtual void init(TQSound*);
+ virtual void play(const TQString& filename);
+ virtual void play(TQSound*)=0;
+ virtual void stop(TQSound*)=0;
+ virtual bool okay()=0;
+
+protected:
+ void setBucket(TQSound*, TQAuBucket*);
+ TQAuBucket* bucket(TQSound*);
+ int decLoop(TQSound*);
+};
+
+#endif // TQT_NO_SOUND
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqsound_x11.cpp b/tqtinterface/qt4/src/kernel/tqsound_x11.cpp
new file mode 100644
index 0000000..6ffe6e8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqsound_x11.cpp
@@ -0,0 +1,284 @@
+/****************************************************************************
+**
+** Implementation of TQSound class and TQAuServer internal class
+**
+** Created : 000117
+**
+** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#define TQT_CLEAN_NAMESPACE
+
+#include "tqsound.h"
+
+#ifndef TQT_NO_SOUND
+
+#include "tqptrdict.h"
+#include "tqsocketnotifier.h"
+#include "tqapplication.h"
+
+
+#ifdef TQT_NAS_SUPPORT
+
+#include <audio/audiolib.h>
+#include <audio/soundlib.h>
+
+static AuServer *nas=0;
+
+static AuBool eventPred(AuServer *, AuEvent *e, AuPointer p)
+{
+ if (e && (e->type == AuEventTypeElementNotify)) {
+ if (e->auelementnotify.flow == *((AuFlowID *)p))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+class TQAuBucketNAS : public TQAuBucket {
+public:
+ TQAuBucketNAS(AuBucketID b, AuFlowID f = 0) : id(b), flow(f), stopped(TRUE), numplaying(0) { }
+ ~TQAuBucketNAS()
+ {
+ if ( nas ) {
+ AuSync(nas, FALSE);
+ AuDestroyBucket(nas, id, NULL);
+
+ AuEvent ev;
+ while (AuScanEvents(nas, AuEventsQueuedAfterFlush, TRUE, eventPred, &flow, &ev))
+ ;
+ }
+ }
+
+ AuBucketID id;
+ AuFlowID flow;
+ bool stopped;
+ int numplaying;
+};
+
+class TQAuServerNAS : public TQAuServer {
+ Q_OBJECT
+ TQ_OBJECT
+
+ TQSocketNotifier* sn;
+
+public:
+ TQAuServerNAS(TQObject* tqparent);
+ ~TQAuServerNAS();
+
+ void init(TQSound*);
+ void play(const TQString& filename);
+ void play(TQSound*);
+ void stop(TQSound*);
+ bool okay();
+ void setDone(TQSound*);
+
+public Q_SLOTS:
+ void dataReceived();
+ void soundDestroyed(TQObject *o);
+
+private:
+ TQAuBucketNAS* bucket(TQSound* s)
+ {
+ return (TQAuBucketNAS*)TQAuServer::bucket(s);
+ }
+};
+
+TQAuServerNAS::TQAuServerNAS(TQObject* tqparent) :
+ TQAuServer(tqparent,"Network Audio System")
+{
+ nas = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL);
+ if (nas) {
+ AuSetCloseDownMode(nas, AuCloseDownDestroy, NULL);
+ // Ask TQt for async messages...
+ sn=new TQSocketNotifier(AuServerConnectionNumber(nas),
+ TQSocketNotifier::Read);
+ TQObject::connect(sn, TQT_SIGNAL(activated(int)),
+ this, TQT_SLOT(dataReceived()));
+ } else {
+ sn = 0;
+ }
+}
+
+TQAuServerNAS::~TQAuServerNAS()
+{
+ if ( nas )
+ AuCloseServer( nas );
+ delete sn;
+ nas = 0;
+}
+
+static TQPtrDict<void> *inprogress=0;
+
+void TQAuServerNAS::soundDestroyed(TQObject *o)
+{
+ if (inprogress) {
+ TQSound *so = static_cast<TQSound *>(o);
+ while (inprogress->remove(so))
+ ; // Loop while remove returns TRUE
+ }
+}
+
+void TQAuServerNAS::play(const TQString& filename)
+{
+ if (nas) {
+ int iv=100;
+ AuFixedPoint volume=AuFixedPointFromFraction(iv,100);
+ AuSoundPlayFromFile(nas, filename, AuNone, volume, NULL, NULL, NULL, NULL, NULL, NULL);
+ AuFlush(nas);
+ dataReceived();
+ AuFlush(nas);
+ tqApp->flushX();
+ }
+}
+
+static void callback( AuServer*, AuEventHandlerRec*, AuEvent* e, AuPointer p)
+{
+ if ( inprogress->tqfind(p) && e ) {
+ if (e->type==AuEventTypeElementNotify &&
+ e->auelementnotify.kind==AuElementNotifyKindState) {
+ if ( e->auelementnotify.cur_state == AuStateStop )
+ ((TQAuServerNAS*)inprogress->tqfind(p))->setDone((TQSound*)p);
+ }
+ }
+}
+
+void TQAuServerNAS::setDone(TQSound* s)
+{
+ if (nas) {
+ decLoop(s);
+ if (s->loopsRemaining() && !bucket(s)->stopped) {
+ bucket(s)->stopped = TRUE;
+ play(s);
+ } else {
+ if (--(bucket(s)->numplaying) == 0)
+ bucket(s)->stopped = TRUE;
+ inprogress->remove(s);
+ }
+ }
+}
+
+void TQAuServerNAS::play(TQSound* s)
+{
+ if (nas) {
+ ++(bucket(s)->numplaying);
+ if (!bucket(s)->stopped) {
+ stop(s);
+ }
+
+ bucket(s)->stopped = FALSE;
+ if ( !inprogress )
+ inprogress = new TQPtrDict<void>;
+ inprogress->insert(s,(void*)this);
+ int iv=100;
+ AuFixedPoint volume=AuFixedPointFromFraction(iv,100);
+ TQAuBucketNAS *b = bucket(s);
+ AuSoundPlayFromBucket(nas, b->id, AuNone, volume,
+ callback, s, 0, &b->flow, NULL, NULL, NULL);
+ AuFlush(nas);
+ dataReceived();
+ AuFlush(nas);
+ tqApp->flushX();
+ }
+}
+
+void TQAuServerNAS::stop(TQSound* s)
+{
+ if (nas && !bucket(s)->stopped) {
+ bucket(s)->stopped = TRUE;
+ AuStopFlow(nas, bucket(s)->flow, NULL);
+ AuFlush(nas);
+ dataReceived();
+ AuFlush(nas);
+ tqApp->flushX();
+ }
+}
+
+void TQAuServerNAS::init(TQSound* s)
+{
+ connect(s, TQT_SIGNAL(destroyed(TQObject *)),
+ this, TQT_SLOT(soundDestroyed(TQObject *)));
+
+ if ( nas ) {
+ AuBucketID b_id =
+ AuSoundCreateBucketFromFile(nas, s->fileName(),
+ 0 /*AuAccessAllMasks*/, NULL, NULL);
+ setBucket(s, new TQAuBucketNAS(b_id));
+ }
+}
+
+bool TQAuServerNAS::okay()
+{
+ return !!nas;
+}
+
+void TQAuServerNAS::dataReceived()
+{
+ AuHandleEvents(nas);
+}
+
+#include "tqsound_x11.tqmoc"
+
+#endif
+
+
+class TQAuServerNull : public TQAuServer {
+public:
+ TQAuServerNull(TQObject* tqparent);
+
+ void play(const TQString&) { }
+ void play(TQSound*s) { while(decLoop(s) > 0) /* nothing */ ; }
+ void stop(TQSound*) { }
+ bool okay() { return FALSE; }
+};
+
+TQAuServerNull::TQAuServerNull(TQObject* tqparent) :
+ TQAuServer(tqparent,"Null Audio Server")
+{
+}
+
+
+TQAuServer* qt_new_audio_server()
+{
+#ifdef TQT_NAS_SUPPORT
+ TQAuServer* s=new TQAuServerNAS(TQT_TQOBJECT(tqApp));
+ if (s->okay()) {
+ return s;
+ } else {
+ delete s;
+ }
+#endif
+ return new TQAuServerNull(TQT_TQOBJECT(tqApp));
+}
+
+#endif // TQT_NO_SOUND
diff --git a/tqtinterface/qt4/src/kernel/tqstyle.cpp b/tqtinterface/qt4/src/kernel/tqstyle.cpp
new file mode 100644
index 0000000..ac14dcb
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqstyle.cpp
@@ -0,0 +1,2186 @@
+/****************************************************************************
+**
+** Implementation of TQStyle class
+**
+** Created : 981231
+**
+** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqstyle.h"
+#ifndef TQT_NO_STYLE
+#include "tqapplication.h"
+#include "tqpainter.h"
+#include "tqbitmap.h"
+#include "tqpixmapcache.h"
+
+#include <limits.h>
+
+#ifdef USE_QT4
+
+// // Default implementations in case Qt4 style objects are being used
+// int TQStyle::tqpixelMetric( QStyle::PixelMetric metric, const TQWidget *widget ) const {
+// // return QStyle::pixelMetric(metric, 0, widget);
+// printf("[WARNING] TQStyle::tqpixelMetric( QStyle::PixelMetric metric, const TQWidget *widget ) const unimplemented\n\r");
+// return 0;
+// }
+//
+// // End default implementations
+
+bool TQStyle::isA( const char *classname ) const
+{
+ if (tqstrcmp(classname, metaObject()->className()) == 0) return true;
+ else {
+ TQString cn = metaObject()->className();
+ if (cn[0] == 'T')
+ cn = cn.remove(0,1);
+ return (tqstrcmp(classname, cn.ascii()) == 0);
+ }
+}
+
+bool TQStyle::inherits( const char *classname ) const {
+ if (QStyle::inherits(classname)) return true;
+ else {
+ TQString cn = classname;
+ if (cn[0] != 'T')
+ cn = cn.prepend('T');
+ return QStyle::inherits(cn.ascii());
+ }
+}
+
+//const char *TQStyle::name(const char *defaultName) const {
+// TQString s = objectName();
+// return s.isEmpty()?defaultName:s.latin1_helper();
+//}
+
+const char *TQStyle::tqname() const {
+ if (dynamic_cast<const TQStyle*>(static_cast<const QStyle*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQStyle::tqname() on an object without a constructed TQStyle object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+const char *TQStyle::name() const {
+ if (dynamic_cast<const TQStyle*>(static_cast<const QStyle*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQStyle::name() on an object without a constructed TQStyle object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+TQMetaObject *TQStyle::tqmetaObject() const {
+ return TQT_TQOBJECT_CONST(this)->tqmetaObject();
+}
+
+/*!
+ Returns the appropriate area (see below) within rectangle \a r in
+ which to draw the \a text or \a pixmap using painter \a p. If \a
+ len is -1 (the default) all the \a text is drawn; otherwise only
+ the first \a len characters of \a text are drawn. The text is
+ aligned in accordance with the tqalignment \a flags (see
+ \l{TQt::AlignmentFlags}). The \a enabled bool indicates whether or
+ not the item is enabled.
+
+ If \a r is larger than the area needed to render the \a text the
+ rectangle that is returned will be offset within \a r in
+ accordance with the tqalignment \a flags. For example if \a flags is
+ \c AlignCenter the returned rectangle will be centered within \a
+ r. If \a r is smaller than the area needed the rectangle that is
+ returned will be \e larger than \a r (the smallest rectangle large
+ enough to render the \a text or \a pixmap).
+
+ By default, if both the text and the pixmap are not null, the
+ pixmap is drawn and the text is ignored.
+*/
+TQRect TQStyle::tqitemRect( QPainter *p, const QRect &r,
+ int flags, bool enabled, const QPixmap *pixmap,
+ const QString& text, int len ) const
+{
+ TQRect result;
+ int x = r.x();
+ int y = r.y();
+ int w = r.width();
+ int h = r.height();
+ TQt::GUIStyle gs = (TQt::GUIStyle)tqstyleHint( SH_GUIStyle );
+
+ if ( pixmap ) {
+ if ( (flags & TQt::AlignVCenter) == TQt::AlignVCenter )
+ y += h/2 - pixmap->height()/2;
+ else if ( (flags & TQt::AlignBottom) == TQt::AlignBottom)
+ y += h - pixmap->height();
+ if ( (flags & TQt::AlignRight) == TQt::AlignRight )
+ x += w - pixmap->width();
+ else if ( (flags & TQt::AlignHCenter) == TQt::AlignHCenter )
+ x += w/2 - pixmap->width()/2;
+ else if ( (flags & TQt::AlignLeft) != TQt::AlignLeft && TQApplication::reverseLayout() )
+ x += w - pixmap->width();
+ result = TQRect(x, y, pixmap->width(), pixmap->height());
+ } else if ( !text.isNull() && p ) {
+ result = TQT_TQPAINTER(p)->boundingRect( x, y, w, h, flags, text, len );
+ if ( gs == TQt::WindowsStyle && !enabled ) {
+ result.setWidth(result.width()+1);
+ result.setHeight(result.height()+1);
+ }
+ } else {
+ result = TQRect(x, y, w, h);
+ }
+
+ return result;
+}
+
+/*!
+ Draws the \a text or \a pixmap in rectangle \a r using painter \a
+ p and color group \a g. The pen color is specified with \a
+ penColor. The \a enabled bool indicates whether or not the item is
+ enabled; when reimplementing this bool should influence how the
+ item is drawn. If \a len is -1 (the default) all the \a text is
+ drawn; otherwise only the first \a len characters of \a text are
+ drawn. The text is aligned and wrapped according to the tqalignment
+ \a flags (see \l{TQt::AlignmentFlags}).
+
+ By default, if both the text and the pixmap are not null, the
+ pixmap is drawn and the text is ignored.
+*/
+void TQStyle::drawItem( TQPainter *p, const TQRect &r,
+ int flags, const TQColorGroup &g, bool enabled,
+ const TQPixmap *pixmap, const TQString& text, int len,
+ const TQColor* penColor ) const
+{
+ int x = r.x();
+ int y = r.y();
+ int w = r.width();
+ int h = r.height();
+ TQt::GUIStyle gs = (TQt::GUIStyle)tqstyleHint( SH_GUIStyle );
+
+ p->setPen( penColor?*penColor:g.foreground() );
+ if ( pixmap ) {
+ TQPixmap pm( *pixmap );
+ bool clip = (flags & TQt::DontClip) == 0;
+ if ( clip ) {
+ if ( pm.width() < w && pm.height() < h ) {
+ clip = FALSE;
+ } else {
+ p->save();
+ TQRegion cr = TQRect(x, y, w, h);
+ if (p->hasClipping())
+ cr &= p->clipRegion(TQPainter::CoordPainter);
+ p->setClipRegion(cr);
+ }
+ }
+ if ( (flags & TQt::AlignVCenter) == TQt::AlignVCenter )
+ y += h/2 - pm.height()/2;
+ else if ( (flags & TQt::AlignBottom) == TQt::AlignBottom)
+ y += h - pm.height();
+ if ( (flags & TQt::AlignRight) == TQt::AlignRight )
+ x += w - pm.width();
+ else if ( (flags & TQt::AlignHCenter) == TQt::AlignHCenter )
+ x += w/2 - pm.width()/2;
+ else if ( ((flags & TQt::AlignLeft) != TQt::AlignLeft) && TQApplication::reverseLayout() ) // AlignAuto && rightToLeft
+ x += w - pm.width();
+
+ if ( !enabled ) {
+ if ( pm.tqmask() ) { // pixmap with a tqmask
+ if ( !pm.selfMask() ) { // tqmask is not pixmap itself
+ TQPixmap pmm( *pm.tqmask() );
+ pmm.setMask( *((TQBitmap *)&pmm) );
+ pm = pmm;
+ }
+ } else if ( pm.depth() == 1 ) { // monochrome pixmap, no tqmask
+ pm.setMask( *((TQBitmap *)&pm) );
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+ } else { // color pixmap, no tqmask
+ TQString k;
+ k.sprintf( "$qt-drawitem-%x", pm.serialNumber() );
+ TQPixmap *tqmask = TQPixmapCache::tqfind(k);
+ bool del=FALSE;
+ if ( !tqmask ) {
+ tqmask = new TQPixmap( pm.createHeuristicMask() );
+ tqmask->setMask( *((TQBitmap*)tqmask) );
+ del = !TQPixmapCache::insert( k, tqmask );
+ }
+ pm = *tqmask;
+ if (del) delete tqmask;
+#endif
+ }
+ if ( gs == TQt::WindowsStyle ) {
+ p->setPen( g.light() );
+ p->drawPixmap( x+1, y+1, pm );
+ p->setPen( g.text() );
+ }
+ }
+ p->drawPixmap( x, y, pm );
+ if ( clip )
+ p->restore();
+ } else if ( !text.isNull() ) {
+ if ( gs == TQt::WindowsStyle && !enabled ) {
+ p->setPen( g.light() );
+ p->drawText( x+1, y+1, w, h, flags, text, len );
+ p->setPen( g.text() );
+ }
+ p->drawText( x, y, w, h, flags, text, len );
+ }
+}
+
+/*!
+ Initializes the appearance of a widget.
+
+ This function is called for every widget at some point after it
+ has been fully created but just \e before it is shown the very
+ first time.
+
+ Reasonable actions in this function might be to call
+ TQWidget::setBackgroundMode() for the widget. An example of highly
+ unreasonable use would be setting the tqgeometry! Reimplementing
+ this function gives you a back-door through which you can change
+ the appearance of a widget. With TQt 3.0's style engine you will
+ rarely need to write your own polish(); instead reimplement
+ drawItem(), drawPrimitive(), etc.
+
+ The TQWidget::inherits() function may provide enough information to
+ allow class-specific customizations. But be careful not to
+ hard-code things too much because new TQStyle subclasses are
+ expected to work reasonably with all current and \e future
+ widgets.
+
+ \sa unPolish()
+*/
+void TQStyle::polish( TQWidget*)
+{
+}
+
+/*!
+ Undoes the initialization of a widget's appearance.
+
+ This function is the counterpart to polish. It is called for every
+ polished widget when the style is dynamically changed. The former
+ style has to unpolish its settings before the new style can polish
+ them again.
+
+ \sa polish()
+*/
+void TQStyle::unPolish( TQWidget*)
+{
+}
+
+/*!
+ \overload
+ Late initialization of the TQApplication object.
+
+ \sa unPolish()
+*/
+void TQStyle::polish( TQApplication*)
+{
+}
+
+/*!
+ \overload
+
+ Undoes the application polish.
+
+ \sa polish()
+*/
+void TQStyle::unPolish( TQApplication*)
+{
+}
+
+/*!
+ \overload
+
+ The style may have certain requirements for color palettes. In
+ this function it has the chance to change the palette according to
+ these requirements.
+
+ \sa TQPalette, TQApplication::setPalette()
+*/
+void TQStyle::polish( TQPalette&)
+{
+}
+
+#else // USE_QT4
+
+class TQStylePrivate
+{
+public:
+ TQStylePrivate()
+ {
+ }
+};
+
+/*!
+ \class TQStyleOption tqstyle.h
+ \brief The TQStyleOption class specifies optional parameters for TQStyle functions.
+ \ingroup appearance
+
+ Some TQStyle functions take an optional argument specifying extra
+ information that is required for a paritical primitive or control.
+ So that the TQStyle class can be extended, TQStyleOption is used to
+ provide a variable-argument for these options.
+
+ The TQStyleOption class has constructors for each type of optional
+ argument, and this set of constructors may be extended in future
+ TQt releases. There are also corresponding access functions that
+ return the optional arguments: these too may be extended.
+
+ For each constructor, you should refer to the documentation of the
+ TQStyle functions to see the meaning of the arguments.
+
+ When calling TQStyle functions from your own widgets, you must only
+ pass the default TQStyleOption or the argument that TQStyle is
+ documented to accept. For example, if the function expects
+ TQStyleOption(TQMenuItem *, int), passing TQStyleOption(TQMenuItem *)
+ leaves the optional integer argument uninitialized.
+
+ When subclassing TQStyle, you must similarly only expect the
+ default or documented arguments. The other arguments will have
+ uninitialized values.
+
+ If you make your own TQStyle subclasses and your own widgets, you
+ can make a subclass of TQStyleOption to pass additional arguments
+ to your TQStyle subclass. You will need to cast the "const
+ TQStyleOption&" argument to your subclass, so be sure your style
+ has been called from your widget.
+*/
+
+/*!
+ \enum TQStyleOption::StyleOptionDefault
+
+ This enum value can be passed as the optional argument to any
+ TQStyle function.
+
+ \value Default
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(StyleOptionDefault)
+
+ The default option. This can always be passed as the optional
+ argument to TQStyle functions.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(int)
+
+ Pass one integer, \a in1. For example, headerSection.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(int, int)
+
+ Pass two integers, \a in1 and \a in2. For example, linewidth and
+ midlinewidth.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(int, int, int, int)
+
+ Pass four integers, \a in1, \a in2, \a in3 and \a in4.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(TQMenuItem*)
+
+ Pass a menu item, \a m.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(TQMenuItem*, int)
+
+ Pass a menu item and an integer, \a m and \a in1.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(TQMenuItem*, int, int)
+
+ Pass a menu item and two integers, \a m, \a in1 and \a in2.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(const TQColor&)
+
+ Pass a color, \a c.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(TQTab*)
+
+ Pass a TQTab, \a t.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(TQListViewItem*)
+
+ Pass a TQListViewItem, \a i.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(TQt::ArrowType)
+
+ Pass an TQt::ArrowType, \a a.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption(TQCheckListItem* i)
+
+ Pass a TQCheckListItem, \a i.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption( const TQRect &r )
+
+ Pass a TQRect, \a r.
+*/
+
+/*!
+ \fn TQStyleOption::TQStyleOption( TQWidget *w )
+
+ Pass a TQWidget, \a w.
+*/
+
+/*!
+ \fn bool TQStyleOption::isDefault() const
+
+ Returns TRUE if the option was constructed with the default
+ constructor; otherwise returns FALSE.
+*/
+
+/*!
+ \fn int TQStyleOption::day() const
+
+ Returns the index of the day in the month if the appropriate
+ constructor was called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn int TQStyleOption::lineWidth() const
+
+ Returns the line width if the appropriate constructor was called;
+ otherwise the return value is undefined.
+*/
+
+/*!
+ \fn int TQStyleOption::midLineWidth() const
+
+ Returns the mid-line width if the appropriate constructor was
+ called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn int TQStyleOption::frameShape() const
+
+ Returns a TQFrame::Shape value if the appropriate constructor was
+ called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn int TQStyleOption::frameShadow() const
+
+ Returns a TQFrame::Shadow value if the appropriate constructor was
+ called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn TQMenuItem* TQStyleOption::menuItem() const
+
+ Returns a menu item if the appropriate constructor was called;
+ otherwise the return value is undefined.
+*/
+
+/*!
+ \fn int TQStyleOption::maxIconWidth() const
+
+ Returns the maximum width of the menu item check area if the
+ appropriate constructor was called; otherwise the return value is
+ undefined.
+*/
+
+/*!
+ \fn int TQStyleOption::tabWidth() const
+
+ Returns the tab indent width if the appropriate constructor was
+ called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn int TQStyleOption::headerSection() const
+
+ Returns the header section if the appropriate constructor was
+ called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn const TQColor& TQStyleOption::color() const
+
+ Returns a color if the appropriate constructor was called;
+ otherwise the return value is undefined.
+*/
+
+/*!
+ \fn TQTab* TQStyleOption::tab() const
+
+ Returns a TQTabBar tab if the appropriate constructor was called;
+ otherwise the return value is undefined.
+*/
+
+/*!
+ \fn TQListViewItem* TQStyleOption::listViewItem() const
+
+ Returns a TQListView item if the appropriate constructor was
+ called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn TQt::ArrowType TQStyleOption::arrowType() const
+
+ Returns an arrow type if the appropriate constructor was called;
+ otherwise the return value is undefined.
+*/
+
+/*!
+ \fn TQCheckListItem* TQStyleOption::checkListItem() const
+
+ Returns a check list item if the appropriate constructor was
+ called; otherwise the return value is undefined.
+*/
+
+/*!
+ \fn TQRect TQStyleOption::rect() const
+
+ Returns a rectangle if the appropriate constructor was called;
+ otherwise the return value is undefined.
+*/
+
+/*!
+ \fn TQWidget* TQStyleOption::widget() const
+
+ Returns a pointer to a widget if the appropriate constructor was called;
+ otherwise the return value is undefined.
+*/
+
+/*!
+ \class TQStyle tqstyle.h
+ \brief The TQStyle class specifies the look and feel of a GUI.
+ \ingroup appearance
+
+ A large number of GUI elements are common to many widgets. The
+ TQStyle class allows the look of these elements to be modified
+ across all widgets that use the TQStyle functions. It also
+ provides two feel options: Motif and Windows.
+
+ Although it is not possible to fully enumerate the look of
+ graphical elements and the feel of widgets in a GUI, TQStyle
+ provides a considerable amount of control and customisability.
+
+ In TQt 1.x the look and feel option for widgets was specified by a
+ single value: the GUIStyle. Starting with TQt 2.0, this notion was
+ expanded to allow the look to be specified by virtual drawing
+ functions.
+
+ Derived classes may reimplement some or all of the drawing
+ functions to modify the look of all widgets that use those
+ functions.
+
+ Languages written from right to left (such as Arabic and Hebrew)
+ usually also mirror the whole tqlayout of widgets. If you design a
+ style, you should take special care when drawing asymmetric
+ elements to make sure that they also look correct in a mirrored
+ tqlayout. You can start your application with \c -reverse to check
+ the mirrored tqlayout. Also notice, that for a reversed tqlayout, the
+ light usually comes from top right instead of top left.
+
+ The actual reverse tqlayout is performed automatically when
+ possible. However, for the sake of flexibility, the translation
+ cannot be performed everywhere. The documentation for each
+ function in the TQStyle API states whether the function
+ expects/returns logical or screen coordinates. Using logical
+ coordinates (in ComplexControls, for example) provides great
+ flexibility in controlling the look of a widget. Use tqvisualRect()
+ when necessary to translate logical coordinates into screen
+ coordinates for drawing.
+
+ In TQt versions prior to 3.0, if you wanted a low level route into
+ changing the appearance of a widget, you would reimplement
+ polish(). With the new 3.0 style engine the recommended approach
+ is to reimplement the draw functions, for example drawItem(),
+ drawPrimitive(), tqdrawControl(), tqdrawControlMask(),
+ tqdrawComplexControl() and tqdrawComplexControlMask(). Each of these
+ functions is called with a range of parameters that provide
+ information that you can use to determine how to draw them, e.g.
+ style flags, rectangle, color group, etc.
+
+ For information on changing elements of an existing style or
+ creating your own style see the \link customstyles.html Style
+ overview\endlink.
+
+ Styles can also be created as \link plugins-howto.html
+ plugins\endlink.
+*/
+
+/*!
+ \enum TQt::GUIStyle
+
+ \obsolete
+
+ \value WindowsStyle
+ \value MotifStyle
+ \value MacStyle
+ \value Win3Style
+ \value PMStyle
+*/
+
+/*!
+ \enum TQt::UIEffect
+
+ \value UI_General
+ \value UI_AnimateMenu
+ \value UI_FadeMenu
+ \value UI_AnimateCombo
+ \value UI_AnimateTooltip
+ \value UI_FadeTooltip
+ \value UI_AnimateToolBox Reserved
+*/
+
+/*!
+ Constructs a TQStyle.
+*/
+TQStyle::TQStyle()
+{
+ d = new TQStylePrivate;
+}
+
+/*!
+ Destroys the style and frees all allocated resources.
+*/
+TQStyle::~TQStyle()
+{
+ delete d;
+ d = 0;
+}
+
+/*
+ \fn GUIStyle TQStyle::guiStyle() const
+ \obsolete
+
+ Returns an indicator to the additional "feel" component of a
+ style. Current supported values are TQt::WindowsStyle and TQt::MotifStyle.
+*/
+
+
+
+/*!
+ Initializes the appearance of a widget.
+
+ This function is called for every widget at some point after it
+ has been fully created but just \e before it is shown the very
+ first time.
+
+ Reasonable actions in this function might be to call
+ TQWidget::setBackgroundMode() for the widget. An example of highly
+ unreasonable use would be setting the tqgeometry! Reimplementing
+ this function gives you a back-door through which you can change
+ the appearance of a widget. With TQt 3.0's style engine you will
+ rarely need to write your own polish(); instead reimplement
+ drawItem(), drawPrimitive(), etc.
+
+ The TQWidget::inherits() function may provide enough information to
+ allow class-specific customizations. But be careful not to
+ hard-code things too much because new TQStyle subclasses are
+ expected to work reasonably with all current and \e future
+ widgets.
+
+ \sa unPolish()
+*/
+void TQStyle::polish( TQWidget*)
+{
+}
+
+/*!
+ Undoes the initialization of a widget's appearance.
+
+ This function is the counterpart to polish. It is called for every
+ polished widget when the style is dynamically changed. The former
+ style has to unpolish its settings before the new style can polish
+ them again.
+
+ \sa polish()
+*/
+void TQStyle::unPolish( TQWidget*)
+{
+}
+
+
+/*!
+ \overload
+ Late initialization of the TQApplication object.
+
+ \sa unPolish()
+*/
+void TQStyle::polish( TQApplication*)
+{
+}
+
+/*!
+ \overload
+
+ Undoes the application polish.
+
+ \sa polish()
+*/
+void TQStyle::unPolish( TQApplication*)
+{
+}
+
+/*!
+ \overload
+
+ The style may have certain requirements for color palettes. In
+ this function it has the chance to change the palette according to
+ these requirements.
+
+ \sa TQPalette, TQApplication::setPalette()
+*/
+void TQStyle::polish( TQPalette&)
+{
+}
+
+/*!
+ Polishes the popup menu according to the GUI style. This usually
+ means setting the mouse tracking
+ (\l{TQPopupMenu::setMouseTracking()}) and whether the menu is
+ checkable by default (\l{TQPopupMenu::setCheckable()}).
+*/
+void TQStyle::polishPopupMenu( TQPopupMenu *)
+{
+}
+
+/*!
+ Returns the appropriate area (see below) within rectangle \a r in
+ which to draw the \a text or \a pixmap using painter \a p. If \a
+ len is -1 (the default) all the \a text is drawn; otherwise only
+ the first \a len characters of \a text are drawn. The text is
+ aligned in accordance with the tqalignment \a flags (see
+ \l{TQt::AlignmentFlags}). The \a enabled bool indicates whether or
+ not the item is enabled.
+
+ If \a r is larger than the area needed to render the \a text the
+ rectangle that is returned will be offset within \a r in
+ accordance with the tqalignment \a flags. For example if \a flags is
+ \c AlignCenter the returned rectangle will be centered within \a
+ r. If \a r is smaller than the area needed the rectangle that is
+ returned will be \e larger than \a r (the smallest rectangle large
+ enough to render the \a text or \a pixmap).
+
+ By default, if both the text and the pixmap are not null, the
+ pixmap is drawn and the text is ignored.
+*/
+TQRect TQStyle::tqitemRect( TQPainter *p, const TQRect &r,
+ int flags, bool enabled, const TQPixmap *pixmap,
+ const TQString& text, int len ) const
+{
+ TQRect result;
+ int x = r.x();
+ int y = r.y();
+ int w = r.width();
+ int h = r.height();
+ GUIStyle gs = (GUIStyle)tqstyleHint( SH_GUIStyle );
+
+ if ( pixmap ) {
+ if ( (flags & TQt::AlignVCenter) == TQt::AlignVCenter )
+ y += h/2 - pixmap->height()/2;
+ else if ( (flags & TQt::AlignBottom) == TQt::AlignBottom)
+ y += h - pixmap->height();
+ if ( (flags & TQt::AlignRight) == TQt::AlignRight )
+ x += w - pixmap->width();
+ else if ( (flags & TQt::AlignHCenter) == TQt::AlignHCenter )
+ x += w/2 - pixmap->width()/2;
+ else if ( (flags & TQt::AlignLeft) != TQt::AlignLeft && TQApplication::reverseLayout() )
+ x += w - pixmap->width();
+ result = TQRect(x, y, pixmap->width(), pixmap->height());
+ } else if ( !text.isNull() && p ) {
+ result = p->boundingRect( x, y, w, h, flags, text, len );
+ if ( gs == TQt::WindowsStyle && !enabled ) {
+ result.setWidth(result.width()+1);
+ result.setHeight(result.height()+1);
+ }
+ } else {
+ result = TQRect(x, y, w, h);
+ }
+
+ return result;
+}
+
+
+/*!
+ Draws the \a text or \a pixmap in rectangle \a r using painter \a
+ p and color group \a g. The pen color is specified with \a
+ penColor. The \a enabled bool indicates whether or not the item is
+ enabled; when reimplementing this bool should influence how the
+ item is drawn. If \a len is -1 (the default) all the \a text is
+ drawn; otherwise only the first \a len characters of \a text are
+ drawn. The text is aligned and wrapped according to the tqalignment
+ \a flags (see \l{TQt::AlignmentFlags}).
+
+ By default, if both the text and the pixmap are not null, the
+ pixmap is drawn and the text is ignored.
+*/
+void TQStyle::drawItem( TQPainter *p, const TQRect &r,
+ int flags, const TQColorGroup &g, bool enabled,
+ const TQPixmap *pixmap, const TQString& text, int len,
+ const TQColor* penColor ) const
+{
+ int x = r.x();
+ int y = r.y();
+ int w = r.width();
+ int h = r.height();
+ GUIStyle gs = (GUIStyle)tqstyleHint( SH_GUIStyle );
+
+ p->setPen( penColor?*penColor:g.foreground() );
+ if ( pixmap ) {
+ TQPixmap pm( *pixmap );
+ bool clip = (flags & TQt::DontClip) == 0;
+ if ( clip ) {
+ if ( pm.width() < w && pm.height() < h ) {
+ clip = FALSE;
+ } else {
+ p->save();
+ TQRegion cr = TQRect(x, y, w, h);
+ if (p->hasClipping())
+ cr &= p->clipRegion(TQPainter::CoordPainter);
+ p->setClipRegion(cr);
+ }
+ }
+ if ( (flags & TQt::AlignVCenter) == TQt::AlignVCenter )
+ y += h/2 - pm.height()/2;
+ else if ( (flags & TQt::AlignBottom) == TQt::AlignBottom)
+ y += h - pm.height();
+ if ( (flags & TQt::AlignRight) == TQt::AlignRight )
+ x += w - pm.width();
+ else if ( (flags & TQt::AlignHCenter) == TQt::AlignHCenter )
+ x += w/2 - pm.width()/2;
+ else if ( ((flags & TQt::AlignLeft) != TQt::AlignLeft) && TQApplication::reverseLayout() ) // AlignAuto && rightToLeft
+ x += w - pm.width();
+
+ if ( !enabled ) {
+ if ( pm.tqmask() ) { // pixmap with a tqmask
+ if ( !pm.selfMask() ) { // tqmask is not pixmap itself
+ TQPixmap pmm( *pm.tqmask() );
+ pmm.setMask( *((TQBitmap *)&pmm) );
+ pm = pmm;
+ }
+ } else if ( pm.depth() == 1 ) { // monochrome pixmap, no tqmask
+ pm.setMask( *((TQBitmap *)&pm) );
+#ifndef TQT_NO_IMAGE_HEURISTIC_MASK
+ } else { // color pixmap, no tqmask
+ TQString k;
+ k.sprintf( "$qt-drawitem-%x", pm.serialNumber() );
+ TQPixmap *tqmask = TQPixmapCache::tqfind(k);
+ bool del=FALSE;
+ if ( !tqmask ) {
+ tqmask = new TQPixmap( pm.createHeuristicMask() );
+ tqmask->setMask( *((TQBitmap*)tqmask) );
+ del = !TQPixmapCache::insert( k, tqmask );
+ }
+ pm = *tqmask;
+ if (del) delete tqmask;
+#endif
+ }
+ if ( gs == TQt::WindowsStyle ) {
+ p->setPen( g.light() );
+ p->drawPixmap( x+1, y+1, pm );
+ p->setPen( g.text() );
+ }
+ }
+ p->drawPixmap( x, y, pm );
+ if ( clip )
+ p->restore();
+ } else if ( !text.isNull() ) {
+ if ( gs == TQt::WindowsStyle && !enabled ) {
+ p->setPen( g.light() );
+ p->drawText( x+1, y+1, w, h, flags, text, len );
+ p->setPen( g.text() );
+ }
+ p->drawText( x, y, w, h, flags, text, len );
+ }
+}
+
+/*!
+ \enum TQStyle::PrimitiveElement
+
+ This enum represents the PrimitiveElements of a style. A
+ PrimitiveElement is a common GUI element, such as a checkbox
+ indicator or pushbutton bevel.
+
+ \value PE_ButtonCommand button used to initiate an action, for
+ example, a TQPushButton.
+ \value PE_ButtonDefault this button is the default button, e.g.
+ in a dialog.
+ \value PE_ButtonBevel generic button bevel.
+ \value PE_ButtonTool tool button, for example, a TQToolButton.
+ \value PE_ButtonDropDown drop down button, for example, a tool
+ button that displays a popup menu, for example, TQPopupMenu.
+
+
+ \value PE_FocusRect generic focus indicator.
+
+
+ \value PE_ArrowUp up arrow.
+ \value PE_ArrowDown down arrow.
+ \value PE_ArrowRight right arrow.
+ \value PE_ArrowLeft left arrow.
+
+
+ \value PE_SpinWidgetUp up symbol for a spin widget, for example a
+ TQSpinBox.
+ \value PE_SpinWidgetDown down symbol for a spin widget.
+ \value PE_SpinWidgetPlus increase symbol for a spin widget.
+ \value PE_SpinWidgetMinus decrease symbol for a spin widget.
+
+
+ \value PE_Indicator on/off indicator, for example, a TQCheckBox.
+ \value PE_IndicatorMask bitmap tqmask for an indicator.
+ \value PE_ExclusiveIndicator exclusive on/off indicator, for
+ example, a TQRadioButton.
+ \value PE_ExclusiveIndicatorMask bitmap tqmask for an exclusive indicator.
+
+
+ \value PE_DockWindowHandle tear off handle for dock windows and
+ toolbars, for example \l{TQDockWindow}s and \l{TQToolBar}s.
+ \value PE_DockWindowSeparator item separator for dock window and
+ toolbar contents.
+ \value PE_DockWindowResizeHandle resize handle for dock windows.
+
+ \value PE_Splitter splitter handle; see also TQSplitter.
+
+
+ \value PE_Panel generic panel frame; see also TQFrame.
+ \value PE_PanelPopup panel frame for popup windows/menus; see also
+ TQPopupMenu.
+ \value PE_PanelMenuBar panel frame for menu bars.
+ \value PE_PanelDockWindow panel frame for dock windows and toolbars.
+ \value PE_PanelTabWidget panel frame for tab widgets.
+ \value PE_PanelLineEdit panel frame for line edits.
+ \value PE_PanelGroupBox panel frame for group boxes.
+
+ \value PE_TabBarBase area below tabs in a tab widget, for example,
+ TQTab.
+
+
+ \value PE_HeaderSection section of a list or table header; see also
+ TQHeader.
+ \value PE_HeaderArrow arrow used to indicate sorting on a list or table
+ header
+ \value PE_tqStatusBarSection section of a status bar; see also
+ TQStatusBar.
+
+
+ \value PE_GroupBoxFrame frame around a group box; see also
+ TQGroupBox.
+ \value PE_WindowFrame frame around a MDI window or a docking window
+
+
+ \value PE_Separator generic separator.
+
+
+ \value PE_SizeGrip window resize handle; see also TQSizeGrip.
+
+
+ \value PE_CheckMark generic check mark; see also TQCheckBox.
+
+
+ \value PE_ScrollBarAddLine scrollbar line increase indicator
+ (i.e. scroll down); see also TQScrollBar.
+ \value PE_ScrollBarSubLine scrollbar line decrease indicator (i.e. scroll up).
+ \value PE_ScrollBarAddPage scolllbar page increase indicator (i.e. page down).
+ \value PE_ScrollBarSubPage scrollbar page decrease indicator (i.e. page up).
+ \value PE_ScrollBarSlider scrollbar slider
+ \value PE_ScrollBarFirst scrollbar first line indicator (i.e. home).
+ \value PE_ScrollBarLast scrollbar last line indicator (i.e. end).
+
+
+ \value PE_ProgressBarChunk section of a progress bar indicator; see
+ also TQProgressBar.
+
+ \value PE_CheckListController controller part of a listview item
+ \value PE_CheckListIndicator checkbox part of a listview item
+ \value PE_CheckListExclusiveIndicator radiobutton part of a listview item
+ \value PE_RubberBand rubber band used in such things as iconview
+
+ \value PE_CustomBase base value for custom PrimitiveElements.
+ All values above this are reserved for custom use. Custom
+ values must be greater than this value.
+
+ \sa drawPrimitive()
+*/
+/*! \enum TQStyle::SFlags
+ \internal
+*/
+/*! \enum TQStyle::SCFlags
+ \internal
+*/
+
+/*!
+ \enum TQStyle::StyleFlags
+
+ This enum represents flags for drawing PrimitiveElements. Not all
+ primitives use all of these flags. Note that these flags may mean
+ different things to different primitives. For an explanation of
+ the relationship between primitives and their flags, as well as
+ the different meanings of the flags, see the \link
+ customstyles.html Style overview\endlink.
+
+ \value Style_Default
+ \value Style_Enabled
+ \value Style_Raised
+ \value Style_Sunken
+ \value Style_Off
+ \value Style_NoChange
+ \value Style_On
+ \value Style_Down
+ \value Style_Horizontal
+ \value Style_HasFocus
+ \value Style_Top
+ \value Style_Bottom
+ \value Style_FocusAtBorder
+ \value Style_AutoRaise
+ \value Style_MouseOver
+ \value Style_Up
+ \value Style_Selected
+ \value Style_HasFocus
+ \value Style_Active
+ \value Style_ButtonDefault
+
+ \sa drawPrimitive()
+*/
+
+/*!
+ \fn void TQStyle::drawPrimitive( PrimitiveElement pe, TQPainter *p, const TQRect &r, const TQColorGroup &cg, SFlags flags, const TQStyleOption& opt) const
+
+ Draws the style PrimitiveElement \a pe using the painter \a p in
+ the area \a r. Colors are used from the color group \a cg.
+
+ The rect \a r should be in screen coordinates.
+
+ The \a flags argument is used to control how the PrimitiveElement
+ is drawn. Multiple flags can be OR'ed together.
+
+ For example, a pressed button would be drawn with the flags \c
+ Style_Enabled and \c Style_Down.
+
+ The \a opt argument can be used to control how various
+ PrimitiveElements are drawn. Note that \a opt may be the default
+ value even for PrimitiveElements that make use of extra options.
+ When \a opt is non-default, it is used as follows:
+
+ \table
+ \header \i PrimitiveElement \i Options \i Notes
+ \row \i \l PE_FocusRect
+ \i \l TQStyleOption ( const \l TQColor & bg )
+ \list
+ \i opt.\link TQStyleOption::color() color\endlink()
+ \endlist
+ \i \e bg is the background color on which the focus rect is being drawn.
+ \row \i12 \l PE_Panel
+ \i12 \l TQStyleOption ( int linewidth, int midlinewidth )
+ \list
+ \i opt.\link TQStyleOption::lineWidth() lineWidth\endlink()
+ \i opt.\link TQStyleOption::midLineWidth() midLineWidth\endlink()
+ \endlist
+ \i \e linewidth is the line width for drawing the panel.
+ \row \i \e midlinewidth is the mid-line width for drawing the panel.
+ \row \i12 \l PE_PanelPopup
+ \i12 \l TQStyleOption ( int linewidth, int midlinewidth )
+ \list
+ \i opt.\link TQStyleOption::lineWidth() lineWidth\endlink()
+ \i opt.\link TQStyleOption::midLineWidth() midLineWidth\endlink()
+ \endlist
+ \i \e linewidth is the line width for drawing the panel.
+ \row \i \e midlinewidth is the mid-line width for drawing the panel.
+ \row \i12 \l PE_PanelMenuBar
+ \i12 \l TQStyleOption ( int linewidth, int midlinewidth )
+ \list
+ \i opt.\link TQStyleOption::lineWidth() lineWidth\endlink()
+ \i opt.\link TQStyleOption::midLineWidth() midLineWidth\endlink()
+ \endlist
+ \i \e linewidth is the line width for drawing the panel.
+ \row \i \e midlinewidth is the mid-line width for drawing the panel.
+ \row \i12 \l PE_PanelDockWindow
+ \i12 \l TQStyleOption ( int linewidth, int midlinewidth )
+ \list
+ \i opt.\link TQStyleOption::lineWidth() lineWidth\endlink()
+ \i opt.\link TQStyleOption::midLineWidth() midLineWidth\endlink()
+ \endlist
+ \i \e linewidth is the line width for drawing the panel.
+ \row \i \e midlinewidth is the mid-line width for drawing the panel.
+ \row \i14 \l PE_GroupBoxFrame
+ \i14 \l TQStyleOption ( int linewidth, int midlinewidth, int tqshape, int shadow )
+ \list
+ \i opt.\link TQStyleOption::lineWidth() lineWidth\endlink()
+ \i opt.\link TQStyleOption::midLineWidth() midLineWidth\endlink()
+ \i opt.\link TQStyleOption::frameShape() frameShape\endlink()
+ \i opt.\link TQStyleOption::frameShadow() frameShadow\endlink()
+ \endlist
+ \i \e linewidth is the line width for the group box.
+ \row \i \e midlinewidth is the mid-line width for the group box.
+ \row \i \e tqshape is the \link TQFrame::frameShape frame tqshape \endlink
+ for the group box.
+ \row \i \e shadow is the \link TQFrame::frameShadow frame shadow \endlink
+ for the group box.
+ \endtable
+
+
+ For all other \link TQStyle::PrimitiveElement
+ PrimitiveElements\endlink, \a opt is unused.
+
+ \sa StyleFlags
+*/
+
+/*!
+ \enum TQStyle::ControlElement
+
+ This enum represents a ControlElement. A ControlElement is part of
+ a widget that performs some action or displays information to the
+ user.
+
+ \value CE_PushButton the bevel and default indicator of a TQPushButton.
+ \value CE_PushButtonLabel the label (iconset with text or pixmap)
+ of a TQPushButton.
+
+ \value CE_CheckBox the indicator of a TQCheckBox.
+ \value CE_CheckBoxLabel the label (text or pixmap) of a TQCheckBox.
+
+ \value CE_RadioButton the indicator of a TQRadioButton.
+ \value CE_RadioButtonLabel the label (text or pixmap) of a TQRadioButton.
+
+ \value CE_TabBarTab the tab within a TQTabBar (a TQTab).
+ \value CE_TabBarLabel the label within a TQTab.
+
+ \value CE_ProgressBarGroove the groove where the progress
+ indicator is drawn in a TQProgressBar.
+ \value CE_ProgressBarContents the progress indicator of a TQProgressBar.
+ \value CE_ProgressBarLabel the text label of a TQProgressBar.
+
+ \value CE_PopupMenuItem a menu item in a TQPopupMenu.
+ \value CE_PopupMenuScroller scrolling areas in a popumenu when the
+ style supports scrolling.
+ \value CE_PopupMenuHorizontalExtra extra frame area set aside with PM_PopupMenuFrameHorizontalExtra
+ \value CE_PopupMenuVerticalExtra extra frame area set aside with PM_PopupMenuFrameVerticalExtra
+
+ \value CE_MenuBarItem a menu item in a TQMenuBar.
+
+ \value CE_ToolButtonLabel a tool button's label.
+
+ \value CE_MenuBarEmptyArea the empty area of a TQMenuBar.
+ \value CE_DockWindowEmptyArea the empty area of a TQDockWindow.
+
+ \value CE_ToolBoxTab the toolbox's tab area
+ \value CE_HeaderLabel the header's label
+
+ \value CE_CustomBase base value for custom ControlElements. All values above
+ this are reserved for custom use. Therefore, custom values must be
+ greater than this value.
+
+ \sa tqdrawControl()
+*/
+
+/*!
+ \fn void TQStyle::tqdrawControl( ControlElement element, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQColorGroup &cg, SFlags how, const TQStyleOption& opt) const
+
+ Draws the ControlElement \a element using the painter \a p in the
+ area \a r. Colors are used from the color group \a cg.
+
+ The rect \a r should be in screen coordinates.
+
+ The \a how argument is used to control how the ControlElement is
+ drawn. Multiple flags can be OR'ed together. See the table below
+ for an explanation of which flags are used with the various
+ ControlElements.
+
+ The \a widget argument is a pointer to a TQWidget or one of its
+ subclasses. The widget can be cast to the appropriate type based
+ on the value of \a element. The \a opt argument can be used to
+ pass extra information required when drawing the ControlElement.
+ Note that \a opt may be the default value even for ControlElements
+ that can make use of the extra options. See the table below for
+ the appropriate \a widget and \a opt usage:
+
+ \table
+ \header \i ControlElement<br>\& Widget Cast
+ \i Style Flags
+ \i Notes
+ \i Options
+ \i Notes
+
+ \row \i16 \l{CE_PushButton}(const \l TQPushButton *)
+
+ and
+
+ \l{CE_PushButtonLabel}(const \l TQPushButton *)
+ \i \l Style_Enabled \i Set if the button is enabled.
+ \i16 Unused.
+ \i16 &nbsp;
+ \row \i \l Style_HasFocus \i Set if the button has input focus.
+ \row \i \l Style_Raised \i Set if the button is not down, not on and not flat.
+ \row \i \l Style_On \i Set if the button is a toggle button and toggled on.
+ \row \i \l Style_Down \i Set if the button is down (i.e., the mouse button or
+ space bar is pressed on the button).
+ \row \i \l Style_ButtonDefault \i Set if the button is a default button.
+
+ \row \i16 \l{CE_CheckBox}(const \l TQCheckBox *)
+
+ and
+
+ \l{CE_CheckBoxLabel}(const \l TQCheckBox *)
+
+ \i \l Style_Enabled \i Set if the checkbox is enabled.
+ \i16 Unused.
+ \i16 &nbsp;
+ \row \i \l Style_HasFocus \i Set if the checkbox has input focus.
+ \row \i \l Style_On \i Set if the checkbox is checked.
+ \row \i \l Style_Off \i Set if the checkbox is not checked.
+ \row \i \l Style_NoChange \i Set if the checkbox is in the NoChange state.
+ \row \i \l Style_Down \i Set if the checkbox is down (i.e., the mouse button or
+ space bar is pressed on the button).
+
+ \row \i15 \l{CE_RadioButton}(const TQRadioButton *)
+
+ and
+
+ \l{CE_RadioButtonLabel}(const TQRadioButton *)
+ \i \l Style_Enabled \i Set if the radiobutton is enabled.
+ \i15 Unused.
+ \i15 &nbsp;
+ \row \i \l Style_HasFocus \i Set if the radiobutton has input focus.
+ \row \i \l Style_On \i Set if the radiobutton is checked.
+ \row \i \l Style_Off \i Set if the radiobutton is not checked.
+ \row \i \l Style_Down \i Set if the radiobutton is down (i.e., the mouse
+ button or space bar is pressed on the radiobutton).
+
+ \row \i12 \l{CE_TabBarTab}(const \l TQTabBar *)
+
+ and
+
+ \l{CE_TabBarLabel}(const \l TQTabBar *)
+
+ \i \l Style_Enabled \i Set if the tabbar and tab is enabled.
+ \i12 \l TQStyleOption ( \l TQTab *t )
+ \list
+ \i opt.\link TQStyleOption::tab() tab\endlink()
+ \endlist
+ \i12 \e t is the TQTab being drawn.
+ \row \i \l Style_Selected \i Set if the tab is the current tab.
+
+ \row \i12 \l{CE_ProgressBarGroove}(const TQProgressBar *)
+
+ and
+
+ \l{CE_ProgressBarContents}(const TQProgressBar *)
+
+ and
+
+ \l{CE_ProgressBarLabel}(const TQProgressBar *)
+
+ \i \l Style_Enabled \i Set if the progressbar is enabled.
+ \i12 Unused.
+ \i12 &nbsp;
+ \row \i \l Style_HasFocus \i Set if the progressbar has input focus.
+
+ \row \i13 \l{CE_PopupMenuItem}(const \l TQPopupMenu *)
+ \i \l Style_Enabled \i Set if the menuitem is enabled.
+ \i13 \l TQStyleOption ( TQMenuItem *mi, int tabwidth, int maxpmwidth )
+ \list
+ \i opt.\link TQStyleOption::menuItem() menuItem\endlink()
+ \i opt.\link TQStyleOption::tabWidth() tabWidth\endlink()
+ \i opt.\link TQStyleOption::maxIconWidth() maxIconWidth\endlink()
+ \endlist
+ \i \e mi is the menu item being drawn. TQMenuItem is currently an
+ internal class.
+ \row \i \l Style_Active \i Set if the menuitem is the current item.
+ \i \e tabwidth is the width of the tab column where key accelerators
+ are drawn.
+ \row \i \l Style_Down \i Set if the menuitem is down (i.e., the mouse button
+ or space bar is pressed).
+ \i \e maxpmwidth is the maximum width of the check column where
+ checkmarks and iconsets are drawn.
+
+ \row \i14 \l{CE_MenuBarItem}(const \l TQMenuBar *)
+ \i \l Style_Enabled \i Set if the menuitem is enabled
+ \i14 \l TQStyleOption ( TQMenuItem *mi )
+ \list
+ \i opt.\link TQStyleOption::menuItem() menuItem\endlink()
+ \endlist
+ \i14 \e mi is the menu item being drawn.
+ \row \i \l Style_Active \i Set if the menuitem is the current item.
+ \row \i \l Style_Down \i Set if the menuitem is down (i.e., a mouse button or
+ the space bar is pressed).
+ \row \i \l Style_HasFocus \i Set if the menubar has input focus.
+
+ \row \i17 \l{CE_ToolButtonLabel}(const \l TQToolButton *)
+ \i \l Style_Enabled \i Set if the toolbutton is enabled.
+ \i17 \l TQStyleOption ( \l ArrowType t )
+ \list
+ \i opt.\link TQStyleOption::arrowType() arrowType\endlink()
+ \endlist
+ \i17 When the tool button only tqcontains an arrow, \e t is the
+ arrow's type.
+ \row \i \l Style_HasFocus \i Set if the toolbutton has input focus.
+ \row \i \l Style_Down \i Set if the toolbutton is down (i.e., a
+ mouse button or the space is pressed).
+ \row \i \l Style_On \i Set if the toolbutton is a toggle button
+ and is toggled on.
+ \row \i \l Style_AutoRaise \i Set if the toolbutton has auto-raise enabled.
+ \row \i \l Style_MouseOver \i Set if the mouse pointer is over the toolbutton.
+ \row \i \l Style_Raised \i Set if the button is not down, not on and doesn't
+ contain the mouse when auto-raise is enabled.
+ \endtable
+
+ \sa ControlElement, StyleFlags
+*/
+
+/*!
+ \fn void TQStyle::tqdrawControlMask( ControlElement element, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQStyleOption& opt) const
+
+ Draw a bittqmask for the ControlElement \a element using the painter
+ \a p in the area \a r. See tqdrawControl() for an explanation of the
+ use of the \a widget and \a opt arguments.
+
+ The rect \a r should be in screen coordinates.
+
+ \sa tqdrawControl(), ControlElement
+*/
+
+/*!
+ \enum TQStyle::SubRect
+
+ This enum represents a sub-area of a widget. Style implementations
+ would use these areas to draw the different parts of a widget.
+
+ \value SR_PushButtonContents area containing the label (iconset
+ with text or pixmap).
+ \value SR_PushButtonFocusRect area for the focus rect (usually
+ larger than the contents rect).
+
+ \value SR_CheckBoxIndicator area for the state indicator (e.g. check mark).
+ \value SR_CheckBoxContents area for the label (text or pixmap).
+ \value SR_CheckBoxFocusRect area for the focus indicator.
+
+
+ \value SR_RadioButtonIndicator area for the state indicator.
+ \value SR_RadioButtonContents area for the label.
+ \value SR_RadioButtonFocusRect area for the focus indicator.
+
+
+ \value SR_ComboBoxFocusRect area for the focus indicator.
+
+
+ \value SR_SliderFocusRect area for the focus indicator.
+
+
+ \value SR_DockWindowHandleRect area for the tear-off handle.
+
+
+ \value SR_ProgressBarGroove area for the groove.
+ \value SR_ProgressBarContents area for the progress indicator.
+ \value SR_ProgressBarLabel area for the text label.
+
+
+ \value SR_ToolButtonContents area for the tool button's label.
+
+ \value SR_DialogButtonAccept area for a dialog's accept button.
+ \value SR_DialogButtonReject area for a dialog's reject button.
+ \value SR_DialogButtonApply area for a dialog's apply button.
+ \value SR_DialogButtonHelp area for a dialog's help button.
+ \value SR_DialogButtonAll area for a dialog's all button.
+ \value SR_DialogButtonRetry area for a dialog's retry button.
+ \value SR_DialogButtonAbort area for a dialog's abort button.
+ \value SR_DialogButtonIgnore area for a dialog's ignore button.
+ \value SR_DialogButtonCustom area for a dialog's custom widget area (in button row).
+
+ \value SR_ToolBoxTabContents area for a toolbox tab's icon and label
+
+ \value SR_CustomBase base value for custom ControlElements. All values above
+ this are reserved for custom use. Therefore, custom values must be
+ greater than this value.
+
+ \sa subRect()
+*/
+
+/*!
+ \fn TQRect TQStyle::subRect( SubRect subrect, const TQWidget *widget ) const;
+
+ Returns the sub-area \a subrect for the \a widget in logical
+ coordinates.
+
+ The \a widget argument is a pointer to a TQWidget or one of its
+ subclasses. The widget can be cast to the appropriate type based
+ on the value of \a subrect. See the table below for the
+ appropriate \a widget casts:
+
+ \table
+ \header \i SubRect \i Widget Cast
+ \row \i \l SR_PushButtonContents \i (const \l TQPushButton *)
+ \row \i \l SR_PushButtonFocusRect \i (const \l TQPushButton *)
+ \row \i \l SR_CheckBoxIndicator \i (const \l TQCheckBox *)
+ \row \i \l SR_CheckBoxContents \i (const \l TQCheckBox *)
+ \row \i \l SR_CheckBoxFocusRect \i (const \l TQCheckBox *)
+ \row \i \l SR_RadioButtonIndicator \i (const \l TQRadioButton *)
+ \row \i \l SR_RadioButtonContents \i (const \l TQRadioButton *)
+ \row \i \l SR_RadioButtonFocusRect \i (const \l TQRadioButton *)
+ \row \i \l SR_ComboBoxFocusRect \i (const \l TQComboBox *)
+ \row \i \l SR_DockWindowHandleRect \i (const \l TQWidget *)
+ \row \i \l SR_ProgressBarGroove \i (const \l TQProgressBar *)
+ \row \i \l SR_ProgressBarContents \i (const \l TQProgressBar *)
+ \row \i \l SR_ProgressBarLabel \i (const \l TQProgressBar *)
+ \endtable
+
+ The tear-off handle (SR_DockWindowHandleRect) for TQDockWindow
+ is a private class. Use TQWidget::parentWidget() to access the
+ TQDockWindow:
+
+ \code
+ if ( !widget->parentWidget() )
+ return;
+ const TQDockWindow *dw = (const TQDockWindow *) widget->parentWidget();
+ \endcode
+
+ \sa SubRect
+*/
+
+/*!
+ \enum TQStyle::ComplexControl
+
+ This enum represents a ComplexControl. ComplexControls have
+ different behaviour depending upon where the user clicks on them
+ or which keys are pressed.
+
+ \value CC_SpinWidget
+ \value CC_ComboBox
+ \value CC_ScrollBar
+ \value CC_Slider
+ \value CC_ToolButton
+ \value CC_TitleBar
+ \value CC_ListView
+
+
+ \value CC_CustomBase base value for custom ControlElements. All
+ values above this are reserved for custom use. Therefore,
+ custom values must be greater than this value.
+
+ \sa SubControl tqdrawComplexControl()
+*/
+
+/*!
+ \enum TQStyle::SubControl
+
+ This enum represents a SubControl within a ComplexControl.
+
+ \value SC_None special value that matches no other SubControl.
+
+
+ \value SC_ScrollBarAddLine scrollbar add line (i.e. down/right
+ arrow); see also TQScrollbar.
+ \value SC_ScrollBarSubLine scrollbar sub line (i.e. up/left arrow).
+ \value SC_ScrollBarAddPage scrollbar add page (i.e. page down).
+ \value SC_ScrollBarSubPage scrollbar sub page (i.e. page up).
+ \value SC_ScrollBarFirst scrollbar first line (i.e. home).
+ \value SC_ScrollBarLast scrollbar last line (i.e. end).
+ \value SC_ScrollBarSlider scrollbar slider handle.
+ \value SC_ScrollBarGroove special subcontrol which tqcontains the
+ area in which the slider handle may move.
+
+
+ \value SC_SpinWidgetUp spinwidget up/increase; see also TQSpinBox.
+ \value SC_SpinWidgetDown spinwidget down/decrease.
+ \value SC_SpinWidgetFrame spinwidget frame.
+ \value SC_SpinWidgetEditField spinwidget edit field.
+ \value SC_SpinWidgetButtonField spinwidget button field.
+
+
+ \value SC_ComboBoxEditField combobox edit field; see also TQComboBox.
+ \value SC_ComboBoxArrow combobox arrow
+ \value SC_ComboBoxFrame combobox frame
+ \value SC_ComboBoxListBoxPopup combobox list box
+
+ \value SC_SliderGroove special subcontrol which tqcontains the area
+ in which the slider handle may move.
+ \value SC_SliderHandle slider handle.
+ \value SC_SliderTickmarks slider tickmarks.
+
+
+ \value SC_ToolButton tool button; see also TQToolbutton.
+ \value SC_ToolButtonMenu subcontrol for opening a popup menu in a
+ tool button; see also TQPopupMenu.
+
+
+ \value SC_TitleBarSysMenu system menu button (i.e. restore, close, etc.).
+ \value SC_TitleBarMinButton minimize button.
+ \value SC_TitleBarMaxButton maximize button.
+ \value SC_TitleBarCloseButton close button.
+ \value SC_TitleBarLabel window title label.
+ \value SC_TitleBarNormalButton normal (restore) button.
+ \value SC_TitleBarShadeButton shade button.
+ \value SC_TitleBarUnshadeButton unshade button.
+
+
+ \value SC_ListView the list view area.
+ \value SC_ListViewBranch (internal)
+ \value SC_ListViewExpand expand item (i.e. show/hide child items).
+
+
+ \value SC_All special value that matches all SubControls.
+
+
+ \sa ComplexControl
+*/
+
+/*!
+ \fn void TQStyle::tqdrawComplexControl( ComplexControl control, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQColorGroup &cg, SFlags how, SCFlags sub, SCFlags subActive, const TQStyleOption& opt ) const
+
+ Draws the ComplexControl \a control using the painter \a p in the
+ area \a r. Colors are used from the color group \a cg. The \a sub
+ argument specifies which SubControls to draw. Multiple SubControls
+ can be OR'ed together. The \a subActive argument specifies which
+ SubControl is active.
+
+ The rect \a r should be in logical coordinates. Reimplementations
+ of this function should use tqvisualRect() to change the logical
+ coordinates into screen coordinates when using drawPrimitive() and
+ tqdrawControl().
+
+ The \a how argument is used to control how the ComplexControl is
+ drawn. Multiple flags can OR'ed together. See the table below for
+ an explanation of which flags are used with the various
+ ComplexControls.
+
+ The \a widget argument is a pointer to a TQWidget or one of its
+ subclasses. The widget can be cast to the appropriate type based
+ on the value of \a control. The \a opt argument can be used to
+ pass extra information required when drawing the ComplexControl.
+ Note that \a opt may be the default value even for ComplexControls
+ that can make use of the extra options. See the table below for
+ the appropriate \a widget and \a opt usage:
+
+ \table
+ \header \i ComplexControl<br>\& Widget Cast
+ \i Style Flags
+ \i Notes
+ \i Options
+ \i Notes
+
+ \row \i12 \l{CC_SpinWidget}(const TQSpinWidget *)
+ \i \l Style_Enabled \i Set if the spinwidget is enabled.
+ \i12 Unused.
+ \i12 &nbsp;
+ \row \i \l Style_HasFocus \i Set if the spinwidget has input focus.
+
+ \row \i12 \l{CC_ComboBox}(const \l TQComboBox *)
+ \i \l Style_Enabled \i Set if the combobox is enabled.
+ \i12 Unused.
+ \i12 &nbsp;
+ \row \i \l Style_HasFocus \i Set if the combobox has input focus.
+
+ \row \i12 \l{CC_ScrollBar}(const \l TQScrollBar *)
+ \i \l Style_Enabled \i Set if the scrollbar is enabled.
+ \i12 Unused.
+ \i12 &nbsp;
+ \row \i \l Style_HasFocus \i Set if the scrollbar has input focus.
+
+ \row \i12 \l{CC_Slider}(const \l TQSlider *)
+ \i \l Style_Enabled \i Set if the slider is enabled.
+ \i12 Unused.
+ \i12 &nbsp;
+
+ \row \i \l Style_HasFocus \i Set if the slider has input focus.
+
+ \row \i16 \l{CC_ToolButton}(const \l TQToolButton *)
+ \i \l Style_Enabled \i Set if the toolbutton is enabled.
+ \i16 \l TQStyleOption ( \l ArrowType t )
+ \list
+ \i opt.\link TQStyleOption::arrowType() arrowType\endlink()
+ \endlist
+ \i16 When the tool button only tqcontains an arrow, \e t is the
+ arrow's type.
+ \row \i \l Style_HasFocus \i Set if the toolbutton has input focus.
+ \row \i \l Style_Down \i Set if the toolbutton is down (ie. mouse
+ button or space pressed).
+ \row \i \l Style_On \i Set if the toolbutton is a toggle button
+ and is toggled on.
+ \row \i \l Style_AutoRaise \i Set if the toolbutton has auto-raise enabled.
+ \row \i \l Style_Raised \i Set if the button is not down, not on and doesn't
+ contain the mouse when auto-raise is enabled.
+
+ \row \i \l{CC_TitleBar}(const \l TQWidget *)
+ \i \l Style_Enabled \i Set if the titlebar is enabled.
+ \i Unused.
+ \i &nbsp;
+
+ \row \i \l{CC_ListView}(const \l TQListView *)
+ \i \l Style_Enabled \i Set if the titlebar is enabled.
+ \i \l TQStyleOption ( \l TQListViewItem *item )
+ \list
+ \i opt.\link TQStyleOption::listViewItem() listViewItem\endlink()
+ \endlist
+ \i \e item is the item that needs branches drawn
+ \endtable
+
+ \sa ComplexControl, SubControl
+*/
+
+/*!
+ \fn void TQStyle::tqdrawComplexControlMask( ComplexControl control, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQStyleOption& opt) const
+
+ Draw a bittqmask for the ComplexControl \a control using the painter
+ \a p in the area \a r. See tqdrawComplexControl() for an explanation
+ of the use of the \a widget and \a opt arguments.
+
+ The rect \a r should be in logical coordinates. Reimplementations
+ of this function should use tqvisualRect() to change the logical
+ corrdinates into screen coordinates when using drawPrimitive() and
+ tqdrawControl().
+
+ \sa tqdrawComplexControl() ComplexControl
+*/
+
+/*!
+ \fn TQRect TQStyle::querySubControlMetrics( ComplexControl control, const TQWidget *widget, SubControl subcontrol, const TQStyleOption& opt = TQStyleOption::Default ) const;
+
+ Returns the rect for the SubControl \a subcontrol for \a widget in
+ logical coordinates.
+
+ The \a widget argument is a pointer to a TQWidget or one of its
+ subclasses. The widget can be cast to the appropriate type based
+ on the value of \a control. The \a opt argument can be used to
+ pass extra information required when drawing the ComplexControl.
+ Note that \a opt may be the default value even for ComplexControls
+ that can make use of the extra options. See tqdrawComplexControl()
+ for an explanation of the \a widget and \a opt arguments.
+
+ \sa tqdrawComplexControl(), ComplexControl, SubControl
+*/
+
+/*!
+ \fn SubControl TQStyle::querySubControl( ComplexControl control, const TQWidget *widget, const TQPoint &pos, const TQStyleOption& opt = TQStyleOption::Default ) const;
+
+ Returns the SubControl for \a widget at the point \a pos. The \a
+ widget argument is a pointer to a TQWidget or one of its
+ subclasses. The widget can be cast to the appropriate type based
+ on the value of \a control. The \a opt argument can be used to
+ pass extra information required when drawing the ComplexControl.
+ Note that \a opt may be the default value even for ComplexControls
+ that can make use of the extra options. See tqdrawComplexControl()
+ for an explanation of the \a widget and \a opt arguments.
+
+ Note that \a pos is passed in screen coordinates. When using
+ querySubControlMetrics() to check for hits and misses, use
+ tqvisualRect() to change the logical coordinates into screen
+ coordinates.
+
+ \sa tqdrawComplexControl(), ComplexControl, SubControl, querySubControlMetrics()
+*/
+
+/*!
+ \enum TQStyle::PixelMetric
+
+ This enum represents a PixelMetric. A PixelMetric is a style
+ dependent size represented as a single pixel value.
+
+ \value PM_ButtonMargin amount of whitespace between pushbutton
+ labels and the frame.
+ \value PM_ButtonDefaultIndicator width of the default-button indicator frame.
+ \value PM_MenuButtonIndicator width of the menu button indicator
+ proportional to the widget height.
+ \value PM_ButtonShiftHorizontal horizontal contents shift of a
+ button when the button is down.
+ \value PM_ButtonShiftVertical vertical contents shift of a button when the
+ button is down.
+
+ \value PM_DefaultFrameWidth default frame width, usually 2.
+ \value PM_SpinBoxFrameWidth frame width of a spin box.
+ \value PM_MDIFrameWidth frame width of an MDI window.
+ \value PM_MDIMinimizedWidth width of a minimized MSI window.
+
+ \value PM_MaximumDragDistance Some feels require the scrollbar or
+ other sliders to jump back to the original position when the
+ mouse pointer is too far away while dragging. A value of -1
+ disables this behavior.
+
+ \value PM_ScrollBarExtent width of a vertical scrollbar and the
+ height of a horizontal scrollbar.
+ \value PM_ScrollBarSliderMin the minimum height of a vertical
+ scrollbar's slider and the minimum width of a horiztonal
+ scrollbar slider.
+
+ \value PM_SliderThickness total slider thickness.
+ \value PM_SliderControlThickness thickness of the slider handle.
+ \value PM_SliderLength length of the slider.
+ \value PM_SliderTickmarkOffset the offset between the tickmarks
+ and the slider.
+ \value PM_SliderSpaceAvailable the available space for the slider to move.
+
+ \value PM_DockWindowSeparatorExtent width of a separator in a
+ horiztonal dock window and the height of a separator in a
+ vertical dock window.
+ \value PM_DockWindowHandleExtent width of the handle in a
+ horizontal dock window and the height of the handle in a
+ vertical dock window.
+ \value PM_DockWindowFrameWidth frame width of a dock window.
+
+ \value PM_MenuBarFrameWidth frame width of a menubar.
+
+ \value PM_MenuBarItemSpacing spacing between menubar items.
+ \value PM_ToolBarItemSpacing spacing between toolbar items.
+
+ \value PM_TabBarTabOverlap number of pixels the tabs should overlap.
+ \value PM_TabBarTabHSpace extra space added to the tab width.
+ \value PM_TabBarTabVSpace extra space added to the tab height.
+ \value PM_TabBarBaseHeight height of the area between the tab bar
+ and the tab pages.
+ \value PM_TabBarBaseOverlap number of pixels the tab bar overlaps
+ the tab bar base.
+ \value PM_TabBarScrollButtonWidth
+ \value PM_TabBarTabShiftHorizontal horizontal pixel shift when a
+ tab is selected.
+ \value PM_TabBarTabShiftVertical vertical pixel shift when a
+ tab is selected.
+
+ \value PM_ProgressBarChunkWidth width of a chunk in a progress bar indicator.
+
+ \value PM_SplitterWidth width of a splitter.
+
+ \value PM_TitleBarHeight height of the title bar.
+ \value PM_PopupMenuFrameHorizontalExtra additional border, e.g. for panels
+ \value PM_PopupMenuFrameVerticalExtra additional border, e.g. for panels
+
+ \value PM_IndicatorWidth width of a check box indicator.
+ \value PM_IndicatorHeight height of a checkbox indicator.
+ \value PM_ExclusiveIndicatorWidth width of a radio button indicator.
+ \value PM_ExclusiveIndicatorHeight height of a radio button indicator.
+
+ \value PM_PopupMenuScrollerHeight height of the scroller area in a popupmenu.
+ \value PM_PopupMenuScrollerHeight height of the scroller area in a popupmenu.
+ \value PM_CheckListButtonSize area (width/height) of the
+ checkbox/radiobutton in a TQCheckListItem
+ \value PM_CheckListControllerSize area (width/height) of the
+ controller in a TQCheckListItem
+
+ \value PM_DialogButtonsSeparator distance between buttons in a dialog buttons widget.
+ \value PM_DialogButtonsButtonWidth minimum width of a button in a dialog buttons widget.
+ \value PM_DialogButtonsButtonHeight minimum height of a button in a dialog buttons widget.
+
+ \value PM_HeaderMarkSize
+ \value PM_HeaderGripMargin
+ \value PM_HeaderMargin
+
+ \value PM_CustomBase base value for custom ControlElements. All
+ values above this are reserved for custom use. Therefore,
+ custom values must be greater than this value.
+
+
+ \sa tqpixelMetric()
+*/
+
+/*!
+ \fn int TQStyle::tqpixelMetric( PixelMetric metric, const TQWidget *widget = 0 ) const;
+
+ Returns the pixel metric for \a metric. The \a widget argument is
+ a pointer to a TQWidget or one of its subclasses. The widget can be
+ cast to the appropriate type based on the value of \a metric. Note
+ that \a widget may be zero even for PixelMetrics that can make use
+ of \a widget. See the table below for the appropriate \a widget
+ casts:
+
+ \table
+ \header \i PixelMetric \i Widget Cast
+ \row \i \l PM_SliderControlThickness \i (const \l TQSlider *)
+ \row \i \l PM_SliderLength \i (const \l TQSlider *)
+ \row \i \l PM_SliderTickmarkOffset \i (const \l TQSlider *)
+ \row \i \l PM_SliderSpaceAvailable \i (const \l TQSlider *)
+ \row \i \l PM_TabBarTabOverlap \i (const \l TQTabBar *)
+ \row \i \l PM_TabBarTabHSpace \i (const \l TQTabBar *)
+ \row \i \l PM_TabBarTabVSpace \i (const \l TQTabBar *)
+ \row \i \l PM_TabBarBaseHeight \i (const \l TQTabBar *)
+ \row \i \l PM_TabBarBaseOverlap \i (const \l TQTabBar *)
+ \endtable
+*/
+
+/*!
+ \enum TQStyle::ContentsType
+
+ This enum represents a ContentsType. It is used to calculate sizes
+ for the contents of various widgets.
+
+ \value CT_PushButton
+ \value CT_CheckBox
+ \value CT_RadioButton
+ \value CT_ToolButton
+ \value CT_ComboBox
+ \value CT_Splitter
+ \value CT_DockWindow
+ \value CT_ProgressBar
+ \value CT_PopupMenuItem
+ \value CT_TabBarTab
+ \value CT_Slider
+ \value CT_Header
+ \value CT_LineEdit
+ \value CT_MenuBar
+ \value CT_SpinBox
+ \value CT_SizeGrip
+ \value CT_TabWidget
+ \value CT_DialogButtons
+
+ \value CT_CustomBase base value for custom ControlElements. All
+ values above this are reserved for custom use. Custom values
+ must be greater than this value.
+
+ \sa sizeFromContents()
+*/
+
+/*!
+ \fn TQSize TQStyle::sizeFromContents( ContentsType contents, const TQWidget *widget, const TQSize &contentsSize, const TQStyleOption& opt = TQStyleOption::Default ) const;
+
+ Returns the size of \a widget based on the contents size \a
+ contentsSize.
+
+ The \a widget argument is a pointer to a TQWidget or one of its
+ subclasses. The widget can be cast to the appropriate type based
+ on the value of \a contents. The \a opt argument can be used to
+ pass extra information required when calculating the size. Note
+ that \a opt may be the default value even for ContentsTypes that
+ can make use of the extra options. See the table below for the
+ appropriate \a widget and \a opt usage:
+
+ \table
+ \header \i ContentsType \i Widget Cast \i Options \i Notes
+ \row \i \l CT_PushButton \i (const \l TQPushButton *) \i Unused. \i &nbsp;
+ \row \i \l CT_CheckBox \i (const \l TQCheckBox *) \i Unused. \i &nbsp;
+ \row \i \l CT_RadioButton \i (const \l TQRadioButton *) \i Unused. \i &nbsp;
+ \row \i \l CT_ToolButton \i (const \l TQToolButton *) \i Unused. \i &nbsp;
+ \row \i \l CT_ComboBox \i (const \l TQComboBox *) \i Unused. \i &nbsp;
+ \row \i \l CT_Splitter \i (const \l TQSplitter *) \i Unused. \i &nbsp;
+ \row \i \l CT_DockWindow \i (const \l TQDockWindow *) \i Unused. \i &nbsp;
+ \row \i \l CT_ProgressBar \i (const \l TQProgressBar *) \i Unused. \i &nbsp;
+ \row \i \l CT_PopupMenuItem \i (const TQPopupMenu *)
+ \i \l TQStyleOption ( TQMenuItem *mi )
+ \list
+ \i opt.\link TQStyleOption::menuItem() menuItem\endlink()
+ \endlist
+ \i \e mi is the menu item to use when calculating the size.
+ TQMenuItem is currently an internal class.
+ \endtable
+*/
+
+/*!
+ \enum TQStyle::StyleHint
+
+ This enum represents a StyleHint. A StyleHint is a general look
+ and/or feel hint.
+
+ \value SH_EtchDisabledText disabled text is "etched" like Windows.
+
+ \value SH_GUIStyle the GUI style to use.
+
+ \value SH_ScrollBar_BackgroundMode the background mode for a
+ TQScrollBar. Possible values are any of those in the \link
+ TQt::BackgroundMode BackgroundMode\endlink enum.
+
+ \value SH_ScrollBar_MiddleClickAbsolutePosition a boolean value.
+ If TRUE, middle clicking on a scrollbar causes the slider to
+ jump to that position. If FALSE, the middle clicking is
+ ignored.
+
+ \value SH_ScrollBar_LeftClickAbsolutePosition a boolean value.
+ If TRUE, left clicking on a scrollbar causes the slider to
+ jump to that position. If FALSE, the left clicking will
+ behave as appropriate for each control.
+
+ \value SH_ScrollBar_ScrollWhenPointerLeavesControl a boolean
+ value. If TRUE, when clicking a scrollbar SubControl, holding
+ the mouse button down and moving the pointer outside the
+ SubControl, the scrollbar continues to scroll. If FALSE, the
+ scollbar stops scrolling when the pointer leaves the
+ SubControl.
+
+ \value SH_TabBar_Alignment the tqalignment for tabs in a
+ TQTabWidget. Possible values are \c TQt::AlignLeft, \c
+ TQt::AlignCenter and \c TQt::AlignRight.
+
+ \value SH_Header_ArrowAlignment the placement of the sorting
+ indicator may appear in list or table headers. Possible values
+ are \c TQt::Left or \c TQt::Right.
+
+ \value SH_Slider_SnapToValue sliders snap to values while moving,
+ like Windows
+
+ \value SH_Slider_SloppyKeyEvents key presses handled in a sloppy
+ manner, i.e. left on a vertical slider subtracts a line.
+
+ \value SH_ProgressDialog_CenterCancelButton center button on
+ progress dialogs, like Motif, otherwise right aligned.
+
+ \value SH_ProgressDialog_TextLabelAlignment TQt::AlignmentFlags --
+ text label tqalignment in progress dialogs; Center on windows,
+ Auto|VCenter otherwise.
+
+ \value SH_PrintDialog_RightAlignButtons right align buttons in
+ the print dialog, like Windows.
+
+ \value SH_MainWindow_SpaceBelowMenuBar 1 or 2 pixel space between
+ the menubar and the dockarea, like Windows.
+
+ \value SH_FontDialog_SelectAssociatedText select the text in the
+ line edit, or when selecting an item from the listbox, or when
+ the line edit receives focus, like Windows.
+
+ \value SH_PopupMenu_AllowActiveAndDisabled allows disabled menu
+ items to be active.
+
+ \value SH_PopupMenu_SpaceActivatesItem pressing Space activates
+ the item, like Motif.
+
+ \value SH_PopupMenu_SubMenuPopupDelay the number of milliseconds
+ to wait before opening a submenu; 256 on windows, 96 on Motif.
+
+ \value SH_PopupMenu_Scrollable whether popupmenu's must support
+ scrolling.
+
+ \value SH_PopupMenu_SloppySubMenus whether popupmenu's must support
+ sloppy submenu; as implemented on Mac OS.
+
+ \value SH_ScrollView_FrameOnlyAroundContents whether scrollviews
+ draw their frame only around contents (like Motif), or around
+ contents, scrollbars and corner widgets (like Windows).
+
+ \value SH_MenuBar_AltKeyNavigation menubars items are navigable
+ by pressing Alt, followed by using the arrow keys to select
+ the desired item.
+
+ \value SH_ComboBox_ListMouseTracking mouse tracking in combobox
+ dropdown lists.
+
+ \value SH_PopupMenu_MouseTracking mouse tracking in popup menus.
+
+ \value SH_MenuBar_MouseTracking mouse tracking in menubars.
+
+ \value SH_ItemView_ChangeHighlightOnFocus gray out selected items
+ when losing focus.
+
+ \value SH_Widget_ShareActivation turn on sharing activation with
+ floating modeless dialogs.
+
+ \value SH_TabBar_SelectMouseType which type of mouse event should
+ cause a tab to be selected.
+
+ \value SH_ListViewExpand_SelectMouseType which type of mouse event should
+ cause a listview expansion to be selected.
+
+ \value SH_TabBar_PreferNoArrows whether a tabbar should suggest a size
+ to prevent scoll arrows.
+
+ \value SH_ComboBox_Popup allows popups as a combobox dropdown
+ menu.
+
+ \value SH_Workspace_FillSpaceOnMaximize the workspace should
+ maximize the client area.
+
+ \value SH_TitleBar_NoBorder the titlebar has no border
+
+ \value SH_ScrollBar_StopMouseOverSlider stops autorepeat when
+ slider reaches mouse
+
+ \value SH_BlinkCursorWhenTextSelected whether cursor should blink
+ when text is selected
+
+ \value SH_RichText_FullWidthSelection whether richtext selections
+ should extend the full width of the document.
+
+ \value SH_GroupBox_TextLabelVerticalAlignment how to vertically align a
+ groupbox's text label.
+
+ \value SH_GroupBox_TextLabelColor how to paint a groupbox's text label.
+
+ \value SH_DialogButtons_DefaultButton which buttons gets the
+ default status in a dialog's button widget.
+
+ \value SH_CustomBase base value for custom ControlElements. All
+ values above this are reserved for custom use. Therefore,
+ custom values must be greater than this value.
+
+ \value SH_ToolButton_Uses3D indicates whether TQToolButtons should
+ use a 3D frame when the mouse is over them
+
+ \value SH_ToolBox_SelectedPageTitleBold Boldness of the selected
+ page title in a TQToolBox.
+
+ \value SH_LineEdit_PasswordCharacter The TQChar Unicode character
+ to be used for passwords.
+
+ \value SH_Table_GridLineColor
+
+ \value SH_UnderlineAccelerator whether accelerators are underlined
+
+ \sa tqstyleHint()
+*/
+
+/*!
+ \fn int TQStyle::tqstyleHint( StyleHint stylehint, const TQWidget *widget = 0, const TQStyleOption &opt = TQStyleOption::Default, TQStyleHintReturn *returnData = 0 ) const;
+
+ Returns the style hint \a stylehint for \a widget. Currently, \a
+ widget, \a opt, and \a returnData are unused; they're included to
+ allow for future enhancements.
+
+ For an explanation of the return value see \l StyleHint.
+*/
+
+/*!
+ \enum TQStyle::StylePixmap
+
+ This enum represents a StylePixmap. A StylePixmap is a pixmap that
+ can follow some existing GUI style or guideline.
+
+
+ \value SP_TitleBarMinButton minimize button on titlebars. For
+ example, in a TQWorkspace.
+ \value SP_TitleBarMaxButton maximize button on titlebars.
+ \value SP_TitleBarCloseButton close button on titlebars.
+ \value SP_TitleBarNormalButton normal (restore) button on titlebars.
+ \value SP_TitleBarShadeButton shade button on titlebars.
+ \value SP_TitleBarUnshadeButton unshade button on titlebars.
+ \value SP_MessageBoxInformation the 'information' icon.
+ \value SP_MessageBoxWarning the 'warning' icon.
+ \value SP_MessageBoxCritical the 'critical' icon.
+ \value SP_MessageBoxQuestion the 'question' icon.
+
+
+ \value SP_DockWindowCloseButton close button on dock windows;
+ see also TQDockWindow.
+
+
+ \value SP_CustomBase base value for custom ControlElements. All
+ values above this are reserved for custom use. Therefore,
+ custom values must be greater than this value.
+
+ \sa stylePixmap()
+*/
+
+/*!
+ \fn TQPixmap TQStyle::stylePixmap( StylePixmap stylepixmap, const TQWidget *widget = 0, const TQStyleOption& opt = TQStyleOption::Default ) const;
+
+ Returns a pixmap for \a stylepixmap.
+
+ The \a opt argument can be used to pass extra information required
+ when drawing the ControlElement. Note that \a opt may be the
+ default value even for StylePixmaps that can make use of the extra
+ options. Currently, the \a opt argument is unused.
+
+ The \a widget argument is a pointer to a TQWidget or one of its
+ subclasses. The widget can be cast to the appropriate type based
+ on the value of \a stylepixmap. See the table below for the
+ appropriate \a widget casts:
+
+ \table
+ \header \i StylePixmap \i Widget Cast
+ \row \i \l SP_TitleBarMinButton \i (const \l TQWidget *)
+ \row \i \l SP_TitleBarMaxButton \i (const \l TQWidget *)
+ \row \i \l SP_TitleBarCloseButton \i (const \l TQWidget *)
+ \row \i \l SP_TitleBarNormalButton \i (const \l TQWidget *)
+ \row \i \l SP_TitleBarShadeButton \i (const \l TQWidget *)
+ \row \i \l SP_TitleBarUnshadeButton \i (const \l TQWidget *)
+ \row \i \l SP_DockWindowCloseButton \i (const \l TQDockWindow *)
+ \endtable
+
+ \sa StylePixmap
+*/
+
+/*!
+ \fn TQRect TQStyle::tqvisualRect( const TQRect &logical, const TQWidget *w );
+
+ Returns the rect \a logical in screen coordinates. The bounding
+ rect for widget \a w is used to perform the translation. This
+ function is provided to aid style implementors in supporting
+ right-to-left mode.
+
+ \sa TQApplication::reverseLayout()
+*/
+TQRect TQStyle::tqvisualRect( const TQRect &logical, const TQWidget *w )
+{
+ TQRect boundingRect = w->rect();
+ TQRect r = logical;
+ if ( TQApplication::reverseLayout() )
+ r.moveBy( 2*(boundingRect.right() - logical.right()) +
+ logical.width() - boundingRect.width(), 0 );
+ return r;
+}
+
+/*!
+ \overload TQRect TQStyle::tqvisualRect( const TQRect &logical, const TQRect &bounding );
+
+ Returns the rect \a logical in screen coordinates. The rect \a
+ bounding is used to perform the translation. This function is
+ provided to aid style implementors in supporting right-to-left
+ mode.
+
+ \sa TQApplication::reverseLayout()
+*/
+TQRect TQStyle::tqvisualRect( const TQRect &logical, const TQRect &boundingRect )
+{
+ TQRect r = logical;
+ if ( TQApplication::reverseLayout() )
+ r.moveBy( 2*(boundingRect.right() - logical.right()) +
+ logical.width() - boundingRect.width(), 0 );
+ return r;
+}
+
+/*!
+ \fn int TQStyle::defaultFrameWidth() const
+ \obsolete
+*/
+
+/*!
+ \fn void TQStyle::tabbarMetrics( const TQWidget *, int &, int &, int & ) const
+ \obsolete
+*/
+
+/*!
+ \fn TQSize TQStyle::scrollBarExtent() const
+ \obsolete
+*/
+
+#endif // USE_QT4
+
+#endif // TQT_NO_STYLE
diff --git a/tqtinterface/qt4/src/kernel/tqstyle.h b/tqtinterface/qt4/src/kernel/tqstyle.h
new file mode 100644
index 0000000..5d657d8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqstyle.h
@@ -0,0 +1,1278 @@
+/****************************************************************************
+**
+** Definition of TQStyle class
+**
+** Created : 980616
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+#ifndef TQSTYLE_H
+#define TQSTYLE_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include "tqpainter.h"
+#include "tqpalette.h"
+#include "tqwidget.h"
+
+#include <Qt/qstyle.h>
+#include <Qt/qstyleoption.h>
+
+#include "tqtenuminheritance.h"
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+// HACK
+#define tqdrawPrimitiveBase tqdrawPrimitive
+
+// Remap changed values
+#define CT_DockWindow CT_Q3DockWindow
+#define CT_Header CT_Q3Header
+#define CT_PopupMenuItem CT_MenuItem
+
+// #define PE_SizeGrip CE_SizeGrip
+// #define PE_Splitter CE_Splitter
+// #define PE_RubberBand CE_RubberBand
+// #define PE_HeaderSection CE_HeaderSection
+#define PE_HeaderArrow PE_IndicatorHeaderArrow
+#define PE_FocusRect PE_FrameFocusRect
+#define PE_DockWindowResizeHandle PE_IndicatorDockWidgetResizeHandle
+#define PE_PanelGroupBox PE_FrameGroupBox
+#define PE_DockWindowHandle PE_IndicatorToolBarHandle
+#define PE_WindowFrame PE_FrameWindow
+#define PE_PanelTabWidget PE_FrameTabWidget
+#define PE_Panel PE_Frame
+#define PE_ButtonTool PE_PanelButtonTool
+#define PE_ButtonDropDown PE_IndicatorButtonDropDown
+#define PE_SpinWidgetPlus PE_IndicatorSpinPlus
+#define PE_SpinWidgetMinus PE_IndicatorSpinMinus
+#define PE_SpinWidgetUp PE_IndicatorSpinUp
+#define PE_SpinWidgetDown PE_IndicatorSpinDown
+#define PE_ButtonBevel PE_PanelButtonBevel
+#define PE_PanelDockWindow PE_FrameDockWindow
+#define PE_PanelPopup PE_FrameMenu
+#define PE_FrameDockWindow PE_FrameDockWidget
+#define PE_CheckMark PE_IndicatorMenuCheckMark
+#define PE_ButtonDefault PE_FrameDefaultButton
+#define PE_ArrowUp PE_IndicatorArrowUp
+#define PE_ArrowDown PE_IndicatorArrowDown
+#define PE_ArrowRight PE_IndicatorArrowRight
+#define PE_ArrowLeft PE_IndicatorArrowLeft
+// #define PE_ScrollBarSubLine CE_ScrollBarSubLine
+// #define PE_ScrollBarAddLine CE_ScrollBarAddLine
+// #define PE_ScrollBarSubPage CE_ScrollBarSubPage
+// #define PE_ScrollBarAddPage CE_ScrollBarAddPage
+// #define PE_ScrollBarFirst CE_ScrollBarFirst
+// #define PE_ScrollBarLast CE_ScrollBarLast
+// #define PE_ScrollBarSlider CE_ScrollBarSlider
+#define PE_Separator PE_Q3Separator
+#define PE_Indicator PE_IndicatorCheckBox
+#define PE_TabBarBase PE_FrameTabBarBase
+#define PE_StatusBarSection PE_FrameStatusBar
+#define PE_ProgressBarChunk PE_IndicatorProgressChunk
+#define PE_ButtonCommand PE_PanelButtonCommand
+#define PE_DockWindowSeparator PE_Q3DockWindowSeparator
+#define PE_CheckListController PE_Q3CheckListController
+#define PE_CheckListIndicator PE_Q3CheckListIndicator
+#define PE_CheckListExclusiveIndicator PE_Q3CheckListExclusiveIndicator
+
+class TQPopupMenu;
+class TQStylePrivate;
+class TQMenuItem;
+class TQTab;
+class TQListViewItem;
+class TQCheckListItem;
+
+// !!! [WARNING] !!!
+// THIS ENTIRE CLASS IS PRETTY MUCH COMPLETELY BROKEN
+// IT IS NOT INTERCHANGABLE WITH QSTYLEOPTION BY ANY STRETCH OF THE IMAGINATION
+// !!! [BEWARE] !!!
+// !!! [FIXME] !!!
+
+class TQStyleOption : public QStyleOption, virtual public TQt {
+public:
+ enum StyleOptionDefault { Default };
+
+ TQStyleOption(StyleOptionDefault=Default) : QStyleOption(), def(TRUE) {}
+ TQStyleOption(const QStyleOption &qso);
+
+// TQStyleOption(int in1) : QStyleOption( in1 ) {}
+// TQStyleOption(int in1, int in2) : QStyleOption( in1, in2 ) {}
+// TQStyleOption(int x, int y, int w, int h) : QStyleOption() { TQ_UNUSED(x); TQ_UNUSED(y); TQ_UNUSED(w); TQ_UNUSED(h);} // [FIXME] What are x, y, w, and h and what do they do? They are likely the visual bounding rectangle for the style element...origin at (x,y) with width w and height h
+
+ TQStyleOption(int in1) : QStyleOption(), def(FALSE), i1(in1) {}
+ TQStyleOption(int in1, int in2) : QStyleOption(), def(FALSE), i1(in1), i2(in2) {}
+ TQStyleOption(int in1, int in2, int in3, int in4) : QStyleOption(), def(FALSE), i1(in1), i2(in2), i3(in3), i4(in4) {}
+
+ TQStyleOption(TQMenuItem* m) : QStyleOption(), def(FALSE), mi(m) {}
+ TQStyleOption(TQMenuItem* m, int in1) : QStyleOption(), def(FALSE), mi(m), i1(in1) {}
+ TQStyleOption(TQMenuItem* m, int in1, int in2) : QStyleOption(), def(FALSE), mi(m), i1(in1), i2(in2) {}
+ TQStyleOption(const TQColor& c) : QStyleOption(), def(FALSE), cl(&c) {}
+ TQStyleOption(TQTab* t) : QStyleOption(), def(FALSE), tb(t) {}
+ TQStyleOption(TQListViewItem* i) : QStyleOption(), def(FALSE), li(i) {}
+ TQStyleOption(TQCheckListItem* i) : QStyleOption(), def(FALSE), cli(i) {}
+// TQStyleOption(TQt::ArrowType a) : QStyleOption( a ) {}
+// TQStyleOption(const TQRect& r) : QStyleOption( r ) {}
+ TQStyleOption(TQWidget *w) : QStyleOption(), def(FALSE), p1((void*)w) {}
+
+ // [FIXME] These are NOT YET PORTED to Qt4!!!
+ bool isDefault() const { return def; }
+ int day() const { return i1; }
+ int lineWidth() const { return i1; }
+ int midLineWidth() const { return i2; }
+ int frameShape() const { return i3; }
+ int frameShadow() const { return i4; }
+ int headerSection() const { return i1; }
+ TQMenuItem* menuItem() const { return mi; }
+ int maxIconWidth() const { return i1; }
+ int tabWidth() const { return i2; }
+ const TQColor& color() const { return *cl; }
+ TQTab* tab() const { return tb; }
+ TQCheckListItem* checkListItem() const { return cli; }
+ TQListViewItem* listViewItem() const { return li; }
+ TQt::ArrowType arrowType() const { return (TQt::ArrowType)i1; }
+ TQRect rect() const { return TQRect( i1, i2, i3, i4 ); }
+ TQWidget* widget() const { return (TQWidget*)p1; }
+
+private:
+ bool def;
+ TQTab* tb;
+ TQMenuItem* mi;
+ const TQColor* cl;
+ TQListViewItem* li;
+ int i1, i2, i3, i4;
+ TQCheckListItem* cli;
+ void *p1, *p2, *p3, *p4; // reserved
+ // (padded to 64 bytes on some architectures)
+};
+
+inline TQStyleOption::TQStyleOption(const QStyleOption& qso) {
+// i1 = qso.rect().x();
+// i2 = qso.rect().y();
+// i3 = qso.rect().width();
+// i4 = qso.rect().height();
+
+// switch (qso.type()) {
+// case QStyleOption::SO_MenuItem:
+//
+// break;
+// }
+
+ printf("[FIXME] TQt does not utilize any QStyleOption parameters during conversion to TQStyleOption\n\r");
+// qFatal("[ABORTING FOR DEBUGGING]");
+ //*this = TQStyleOption(*static_cast<const TQStyleOption*>(&qso));
+}
+
+// #define Style_Default State_None
+// #define Style_Enabled State_Enabled
+// #define Style_HasFocus State_HasFocus
+// #define Style_Up State_Raised
+// #define Style_Down State_Sunken
+// #define Style_On State_On
+// #define Style_Off State_Off
+// #define Style_Top State_Top
+// #define Style_Bottom State_Bottom
+// #define Style_NoChange State_NoChange
+// #define Style_MouseOver State_MouseOver
+// #define Style_Horizontal State_Horizontal
+// #define Style_Vertical State_Vertical
+// #define Style_Active State_Active
+// #define Style_Sunken State_Sunken
+// #define Style_Raised State_Raised
+// #define Style_Selected State_Selected
+// #define Style_AutoRaise State_AutoRaise
+// #define Style_FocusAtBorder State_FocusAtBorder
+// #define Style_ButtonDefault State_None /* [FIXME] Should be QStyleOptionButton::DefaultButton */
+
+#define SP_DockWindowCloseButton SP_DockWidgetCloseButton
+
+#define PM_DockWindowHandleExtent PM_DockWidgetHandleExtent
+#define PM_MenuBarFrameWidth PM_MenuBarPanelWidth
+#define PM_DockWindowFrameWidth PM_DockWidgetFrameWidth
+#define PM_PopupMenuFrameVerticalExtra PM_MenuVMargin
+#define PM_PopupMenuFrameHorizontalExtra PM_MenuHMargin
+#define PM_PopupMenuScrollerHeight PM_MenuScrollerHeight
+#define PM_DockWindowSeparatorExtent PM_DockWidgetSeparatorExtent
+
+#define CE_PopupMenuItem CE_MenuItem
+#define CE_PopupMenuVerticalExtra CE_MenuVMargin
+#define CE_PopupMenuHorizontalExtra CE_MenuHMargin
+#define CE_PopupMenuScroller CE_MenuScroller
+#define CE_TabBarLabel CE_TabBarTabLabel
+
+#define CC_ListView CC_Q3ListView
+
+#define SH_ListViewExpand_SelectMouseType SH_Q3ListViewExpand_SelectMouseType
+#define SH_PopupMenu_MouseTracking SH_Menu_MouseTracking
+#define SH_PopupMenu_Scrollable SH_Menu_Scrollable
+#define SH_PopupMenu_AllowActiveAndDisabled SH_Menu_AllowActiveAndDisabled
+#define SH_PopupMenu_SubMenuPopupDelay SH_Menu_SubMenuPopupDelay
+#define SH_PopupMenu_SpaceActivatesItem SH_Menu_SpaceActivatesItem
+#define SH_PopupMenu_SloppySubMenus SH_Menu_SloppySubMenus
+#define SH_ToolButton_Uses3D SH_ToolButtonStyle /* [FIXME] Verify that this is correct */
+
+// Use the TQt virtual functions, not the built in Qt ones...
+// This requires that the base virtual Qt functions be reimplemented so as to point to the TQt virtual functions instead as shown below.
+// This way, when Trinity overrides a TQt virtual function, the calling Qt code will blithely use the overriden TQt function instead.
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_01 inline void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const { TQ_UNUSED(opt); TQ_UNUSED(w); static_cast<const TQStyle*>(this)->tqdrawPrimitive(pe, static_cast<TQPainter*>(p), TQRect(), TQColorGroup()); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_02 inline QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const { return static_cast<const TQStyle*>(this)->tqsizeFromContents( ct, static_cast<const TQWidget*>(w), contentsSize, TQT_TQSTYLEOPTION_OBJECT(*opt) ); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_03 inline QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const { TQ_UNUSED(fm); return static_cast<const TQStyle*>(this)->tqitemRect(NULL, r, flags, enabled, NULL, text); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_04 inline QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const { return static_cast<const TQStyle*>(this)->tqitemRect(NULL, r, flags, true, &pixmap, NULL); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_05 inline void drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const { static_cast<const TQStyle*>(this)->tqdrawControl( element, static_cast<TQPainter*>(p), static_cast<const TQWidget*>(w), opt->rect, TQColorGroup() ); /* [FIXME] an empty (black) qcolorgroup is WRONG!*/ }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_06 inline int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const { TQ_UNUSED(option); return static_cast<const TQStyle*>(this)->tqpixelMetric( metric, TQT_TQWIDGET_CONST(widget) ); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_07 inline void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const { static_cast<const TQStyle*>(this)->tqdrawComplexControl( cc, static_cast<TQPainter*>(p), static_cast<const TQWidget*>(widget), opt->rect, TQColorGroup()); } /* [FIXME] an empty (black) qcolorgroup is WRONG! */
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_08 inline QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const { return static_cast<const TQStyle*>(this)->stylePixmap( standardPixmap, TQT_TQWIDGET_CONST(widget), TQT_TQSTYLEOPTION_OBJECT(*opt) ); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_09 inline int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn* returnData) const { return static_cast<const TQStyle*>(this)->tqstyleHint( stylehint, TQT_TQWIDGET_CONST(widget), TQT_TQSTYLEOPTION_OBJECT(*opt), returnData ); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_10 inline virtual QRect subElementRect(QStyle::SubElement r, const QStyleOption*, const QWidget *widget) const { return static_cast<const TQStyle*>(this)->subRect( (SubRect)r, static_cast<const TQWidget*>(widget) ); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_11 inline virtual QStyle::SubControl hitTestComplexControl(QStyle::ComplexControl, const QStyleOptionComplex*, const QPoint&, const QWidget*) const { /* [FIXME] */ printf("[WARNING] virtual QStyle::SubControl hitTestComplexControl(QStyle::ComplexControl, const QStyleOptionComplex*, const QPoint&, const QWidget*) unimplemented\n\r"); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_12 inline virtual QRect subControlRect(QStyle::ComplexControl r, const QStyleOptionComplex*, QStyle::SubControl, const QWidget* widget) const { return static_cast<const TQStyle*>(this)->subRect( (SubRect)r, static_cast<const TQWidget*>(widget) ); }
+
+#define TQT_TQSTYLE_QT4_INTERFACE_VFUNC_13 inline virtual QPixmap generatedIconPixmap(QIcon::Mode, const QPixmap&, const QStyleOption*) const { /* [FIXME] */ printf("[WARNING] virtual QPixmap generatedIconPixmap(QIcon::Mode, const QPixmap&, const QStyleOption*) unimplemented\n\r"); }
+
+//class TQStyleHintReturn; // not defined yet
+#define TQStyleHintReturn QStyleHintReturn
+
+class TQ_EXPORT TQStyle: public QStyle, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ typedef uint SFlags;
+
+// typedef State SFlags;
+ typedef StandardPixmap StylePixmap;
+
+ TQStyle() : QStyle() { TQT_TQOBJECT_REQUIRED_INITIALIZATION(tqparent) }
+
+ enum SH_NewTypes {
+ SH_GUIStyle = 0x00000100,
+ SH_ScrollBar_BackgroundMode,
+ SH_UnderlineAccelerator = SH_UnderlineShortcut
+ };
+
+ typedef TQTInheritEnum< SH_NewTypes, QStyle::StyleHint > TQ_StyleHint;
+
+ enum CE_NewTypes {
+ CE_DockWindowEmptyArea = 0xff000000
+ };
+
+ typedef TQTInheritEnum< CE_NewTypes, QStyle::ControlElement > TQ_ControlElement;
+
+ enum CC_NewTypes {
+ CC_SpinWidget = 0xff000000
+ };
+
+ typedef TQTInheritEnum< CC_NewTypes, QStyle::ComplexControl > TQ_ComplexControl;
+
+ enum PE_NewTypes {
+ PE_IndicatorMask = 0xff000000,
+ PE_ExclusiveIndicator = 0xff000001,
+ PE_ExclusiveIndicatorMask = 0xff000002,
+ PE_GroupBoxFrame = 0xff000003,
+
+ // NOTE: These need an interface to Qt4 such that Qt4 calls for CE_ScrollBar<xxx> are translated to the equivalent TQt PE_ScrollBar<xxx> calls
+ PE_ScrollBarAddLine = 0xff000004,
+ PE_ScrollBarSubLine = 0xff000005,
+ PE_ScrollBarAddPage = 0xff000006,
+ PE_ScrollBarSubPage = 0xff000007,
+ PE_ScrollBarSlider = 0xff000008,
+ PE_ScrollBarFirst = 0xff000009,
+ PE_ScrollBarLast = 0xff00000a,
+
+ // NOTE: Same as above...
+ PE_SizeGrip = 0xff00000b,
+ PE_Splitter = 0xff00000c,
+ PE_RubberBand = 0xff00000d,
+ PE_HeaderSection = 0xff00000e
+ };
+
+ typedef TQTInheritEnum< PE_NewTypes, QStyle::PrimitiveElement > TQ_PrimitiveElement;
+
+ // Note that StyleFlags is now StateFlags
+ enum StyleFlags {
+ Style_Default = QStyle::State_None,
+ Style_Enabled = QStyle::State_Enabled,
+ Style_HasFocus = QStyle::State_HasFocus,
+ Style_Up = QStyle::State_Raised,
+ Style_Down = QStyle::State_Sunken,
+ Style_On = QStyle::State_On,
+ Style_Off = QStyle::State_Off,
+ Style_Top = QStyle::State_Top,
+ Style_Bottom = QStyle::State_Bottom,
+ Style_NoChange = QStyle::State_NoChange,
+ Style_MouseOver = QStyle::State_MouseOver,
+ Style_Horizontal = QStyle::State_Horizontal,
+// Style_Vertical = QStyle::State_Vertical,
+ Style_Active = QStyle::State_Active,
+ Style_Sunken = QStyle::State_Sunken,
+ Style_Raised = QStyle::State_Raised,
+ Style_Selected = QStyle::State_Selected,
+ Style_AutoRaise = QStyle::State_AutoRaise,
+ Style_FocusAtBorder = QStyle::State_FocusAtBorder,
+ Style_ButtonDefault = QStyle::State_None /* [FIXME] Should be QStyleOptionButton::DefaultButton */
+ };
+
+ // Note that SubRect may not have an equivalent in Qt4--be careful!
+ enum SubRect {
+ SR_PushButtonContents,
+ SR_PushButtonFocusRect,
+
+ SR_CheckBoxIndicator,
+ SR_CheckBoxContents,
+ SR_CheckBoxFocusRect,
+
+ SR_RadioButtonIndicator,
+ SR_RadioButtonContents,
+ SR_RadioButtonFocusRect,
+
+ SR_ComboBoxFocusRect,
+
+ SR_SliderFocusRect,
+
+ SR_DockWindowHandleRect,
+
+ SR_ProgressBarGroove,
+ SR_ProgressBarContents,
+ SR_ProgressBarLabel,
+
+ SR_ToolButtonContents,
+
+ SR_DialogButtonAccept,
+ SR_DialogButtonReject,
+ SR_DialogButtonApply,
+ SR_DialogButtonHelp,
+ SR_DialogButtonAll,
+ SR_DialogButtonAbort,
+ SR_DialogButtonIgnore,
+ SR_DialogButtonRetry,
+ SR_DialogButtonCustom,
+
+ SR_ToolBoxTabContents,
+
+ // do not add any values below/greater than this
+ SR_CustomBase = 0xf0000000
+ };
+
+ // Note that SubControl may not have an equivalent in Qt4--be careful!
+ enum SubControl {
+ SC_None = 0x00000000,
+
+ SC_ScrollBarAddLine = 0x00000001,
+ SC_ScrollBarSubLine = 0x00000002,
+ SC_ScrollBarAddPage = 0x00000004,
+ SC_ScrollBarSubPage = 0x00000008,
+ SC_ScrollBarFirst = 0x00000010,
+ SC_ScrollBarLast = 0x00000020,
+ SC_ScrollBarSlider = 0x00000040,
+ SC_ScrollBarGroove = 0x00000080,
+
+ SC_SpinWidgetUp = 0x00000001,
+ SC_SpinWidgetDown = 0x00000002,
+ SC_SpinWidgetFrame = 0x00000004,
+ SC_SpinWidgetEditField = 0x00000008,
+ SC_SpinWidgetButtonField = 0x00000010,
+
+ SC_ComboBoxFrame = 0x00000001,
+ SC_ComboBoxEditField = 0x00000002,
+ SC_ComboBoxArrow = 0x00000004,
+ SC_ComboBoxListBoxPopup = 0x00000008,
+
+ SC_SliderGroove = 0x00000001,
+ SC_SliderHandle = 0x00000002,
+ SC_SliderTickmarks = 0x00000004,
+
+ SC_ToolButton = 0x00000001,
+ SC_ToolButtonMenu = 0x00000002,
+
+ SC_TitleBarLabel = 0x00000001,
+ SC_TitleBarSysMenu = 0x00000002,
+ SC_TitleBarMinButton = 0x00000004,
+ SC_TitleBarMaxButton = 0x00000008,
+ SC_TitleBarCloseButton = 0x00000010,
+ SC_TitleBarNormalButton = 0x00000020,
+ SC_TitleBarShadeButton = 0x00000040,
+ SC_TitleBarUnshadeButton = 0x00000080,
+
+ SC_ListView = 0x00000001,
+ SC_ListViewBranch = 0x00000002,
+ SC_ListViewExpand = 0x00000004,
+
+ SC_All = 0xffffffff
+ };
+ typedef uint SCFlags;
+
+ bool isA(const char *classname) const;
+ bool inherits( const char * ) const;
+
+ const char *tqname() const;
+ const char *name() const;
+// const char *name(const char *defaultName) const;
+
+ TQMetaObject *tqmetaObject() const;
+
+ // Compatibility functions
+ // For example, a TQt application may call tqdrawPrimitive with a ControlElement parameter
+ // TQt "knows" that the application should have called tqdrawControl instead, and translates accordingly.
+ inline void tqdrawPrimitive( TQ_ControlElement element, TQPainter *p, const TQRect &r, const TQColorGroup &cg, SFlags flags = Style_Default, const TQStyleOption &opt = TQStyleOption::Default ) const {
+ TQ_UNUSED(r);
+ TQ_UNUSED(cg);
+ TQ_UNUSED(flags);
+ drawControl((QStyle::ControlElement)(int)element, &opt, p, 0); // [FIXME] What should widget really be? I imagine 0 is *wrong*!!!
+ }
+ inline void tqdrawPrimitive( TQ_ComplexControl element, TQPainter *p, const TQRect &r, const TQColorGroup &cg, SFlags flags = Style_Default, const TQStyleOption &opt = TQStyleOption::Default ) const {
+ TQ_UNUSED(r);
+ TQ_UNUSED(cg);
+ TQ_UNUSED(flags);
+ drawComplexControl((QStyle::ComplexControl)(int)element, 0, p, 0); // [FIXME] What should widget and complexcontrol really be? I imagine 0 is *wrong*!!!
+ }
+ inline void tqdrawPrimitive( TQ_ControlElement element, TQPainter *p, const TQRect &r, const TQColorGroup &cg, int flags, const TQStyleOption &opt = TQStyleOption::Default ) const { tqdrawPrimitive( element, p, r, cg, (SFlags)flags, opt); }
+
+// inline void tqdrawPrimitive( TQ_PrimitiveElement pe, TQPainter *p, const TQRect &r, const TQColorGroup &cg, SFlags flags = Style_Default, const TQStyleOption &opt = TQStyleOption::Default ) const { tqdrawPrimitiveBase( pe, p, r, cg, flags, opt); }
+// inline void tqdrawPrimitive( TQ_PrimitiveElement pe, TQPainter *p, const TQRect &r, const TQColorGroup &cg, int flags, const TQStyleOption &opt = TQStyleOption::Default ) const { tqdrawPrimitive( pe, p, r, cg, (SFlags)flags, opt ); }
+ virtual void tqdrawPrimitive( TQ_PrimitiveElement pe, TQPainter *p, const TQRect &r, const TQColorGroup &cg, SFlags flags = Style_Default, const TQStyleOption &opt = TQStyleOption::Default ) const = 0;
+
+ inline static TQRect tqvisualRect( const TQRect &logical, const TQWidget *w ) { return visualRect(QApplication::layoutDirection(), w->rect(), logical); }
+ inline static TQRect tqvisualRect( const QRect &logical, const QRect &bounding ) { return visualRect(QApplication::layoutDirection(), bounding, logical); }
+
+// virtual void tqdrawPrimitiveBase( TQ_PrimitiveElement pe, TQPainter *p, const TQRect &r, const TQColorGroup &cg, SFlags flags = Style_Default, const TQStyleOption &opt = TQStyleOption::Default ) const = 0;
+ virtual TQSize tqsizeFromContents( ContentsType contents, const TQWidget *widget, const TQSize &contentsSize, const TQStyleOption& = TQStyleOption::Default ) const = 0;
+ virtual int tqstyleHint( TQ_StyleHint stylehint, const TQWidget *widget = 0, const TQStyleOption& = TQStyleOption::Default, TQStyleHintReturn* returnData = 0) const = 0;
+ virtual TQRect subRect( SubRect r, const TQWidget *widget ) const = 0; // There doesn't seem to be a Qt4 equivalent for this virtual function; should it just be left as-is here?
+ virtual TQRect tqitemRect( QPainter *p, const QRect &r, int flags, bool enabled, const QPixmap *pixmap, const QString &text, int len = -1 ) const;
+ virtual void tqdrawControlMask( TQ_ControlElement element, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQStyleOption& = TQStyleOption::Default ) const = 0; // There doesn't seem to be a Qt4 equivalent for this virtual function; should it just be left as-is here?
+ virtual void tqdrawControl( TQ_ControlElement element, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQColorGroup &cg, SFlags how = Style_Default, const TQStyleOption& = TQStyleOption::Default ) const = 0;
+ virtual int tqpixelMetric( PixelMetric metric, const TQWidget *widget = 0 ) const = 0;
+ virtual TQRect querySubControlMetrics( TQ_ComplexControl control, const TQWidget *widget, SubControl sc, const TQStyleOption& = TQStyleOption::Default ) const = 0; // There doesn't seem to be a Qt4 equivalent for this virtual function; should it just be left as-is here?
+ virtual void tqdrawComplexControl( TQ_ComplexControl control, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQColorGroup &cg, SFlags how = Style_Default,
+#ifdef TQ_TQDOC
+ SCFlags sub = SC_All,
+#else
+ SCFlags sub = (uint)SC_All,
+#endif
+ SCFlags subActive = SC_None, const TQStyleOption& = TQStyleOption::Default ) const = 0;
+ virtual void tqdrawComplexControlMask( TQ_ComplexControl control, TQPainter *p, const TQWidget *widget, const TQRect &r, const TQStyleOption& = TQStyleOption::Default ) const = 0; // There doesn't seem to be a Qt4 equivalent for this virtual function; should it just be left as-is here?
+ virtual TQPixmap stylePixmap( StylePixmap stylepixmap, const TQWidget *widget = 0, const TQStyleOption& = TQStyleOption::Default ) const = 0;
+ virtual SubControl querySubControl( TQ_ComplexControl control, const TQWidget *widget, const TQPoint &pos, const TQStyleOption& = TQStyleOption::Default ) const = 0; // There doesn't seem to be a Qt4 equivalent for this virtual function; should it just be left as-is here?
+ virtual void polishPopupMenu( TQPopupMenu* ) = 0; // There doesn't seem to be a Qt4 equivalent for this virtual function; should it just be left as-is here?
+
+ // The Qt4 methods need to be here as well, otherwise they will be hidden by the method definitions above...
+// virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = 0) const = 0;
+// virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w = 0) const = 0;
+
+ // These are implemented in the cpp file
+ virtual void drawItem( TQPainter *p, const TQRect &r, int flags, const TQColorGroup &g, bool enabled, const TQPixmap *pixmap, const TQString &text, int len = -1, const TQColor *penColor = 0 ) const;
+
+ // Compatibility
+ virtual void polish( TQWidget * );
+ virtual void unPolish( TQWidget * );
+ virtual void polish( TQApplication * );
+ virtual void unPolish( TQApplication * );
+ virtual void polish( TQPalette & );
+
+ // Feel free to look but please don't touch!
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_01
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_02
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_03
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_04
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_05
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_06
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_07
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_08
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_09
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_10
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_11
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_12
+ TQT_TQSTYLE_QT4_INTERFACE_VFUNC_13
+
+ // Old 2.x TQStyle API
+
+#ifndef TQT_NO_COMPAT
+ int defaultFrameWidth() const {
+ return tqpixelMetric( PM_DefaultFrameWidth );
+ }
+
+ void tabbarMetrics( const TQWidget* t, int& hf, int& vf, int& ov ) const {
+ hf = tqpixelMetric( PM_TabBarTabHSpace, t );
+ vf = tqpixelMetric( PM_TabBarTabVSpace, t );
+ ov = tqpixelMetric( PM_TabBarBaseOverlap, t );
+ }
+
+ TQSize scrollBarExtent() const {
+ return TQSize(tqpixelMetric(PM_ScrollBarExtent), tqpixelMetric(PM_ScrollBarExtent));
+ }
+#endif
+
+public Q_SLOTS:
+ void tqt_handle_qt_destroyed(QObject* obj) { emit destroyed(TQT_TQOBJECT(obj)); }
+
+Q_SIGNALS:
+ void destroyed( TQObject* obj );
+
+private:
+ mutable TQString static_object_name;
+};
+
+#else // USE_QT4
+
+#ifndef TQT_NO_STYLE
+
+class TQPopupMenu;
+class TQStylePrivate;
+class TQMenuItem;
+class TQTab;
+class TQListViewItem;
+class TQCheckListItem;
+
+class TQStyleOption {
+public:
+ enum StyleOptionDefault { Default };
+
+ TQStyleOption(StyleOptionDefault=Default) : def(TRUE) {}
+
+ // Note: we don't use default arguments since that is unnecessary
+ // initialization.
+ TQStyleOption(int in1) :
+ def(FALSE), i1(in1) {}
+ TQStyleOption(int in1, int in2) :
+ def(FALSE), i1(in1), i2(in2) {}
+ TQStyleOption(int in1, int in2, int in3, int in4) :
+ def(FALSE), i1(in1), i2(in2), i3(in3), i4(in4) {}
+ TQStyleOption(TQMenuItem* m) : def(FALSE), mi(m) {}
+ TQStyleOption(TQMenuItem* m, int in1) : def(FALSE), mi(m), i1(in1) {}
+ TQStyleOption(TQMenuItem* m, int in1, int in2) : def(FALSE), mi(m), i1(in1), i2(in2) {}
+ TQStyleOption(const TQColor& c) : def(FALSE), cl(&c) {}
+ TQStyleOption(TQTab* t) : def(FALSE), tb(t) {}
+ TQStyleOption(TQListViewItem* i) : def(FALSE), li(i) {}
+ TQStyleOption(TQCheckListItem* i) : def(FALSE), cli(i) {}
+ TQStyleOption(TQt::ArrowType a) : def(FALSE), i1((int)a) {}
+ TQStyleOption(const TQRect& r) : def(FALSE), i1(r.x()), i2(r.y()), i3(r.width()),i4(r.height()){}
+ TQStyleOption(TQWidget *w) : def(FALSE), p1((void*)w) {}
+
+ bool isDefault() const { return def; }
+
+ int day() const { return i1; }
+
+ int lineWidth() const { return i1; }
+ int midLineWidth() const { return i2; }
+ int frameShape() const { return i3; }
+ int frameShadow() const { return i4; }
+
+ int headerSection() const { return i1; }
+ TQMenuItem* menuItem() const { return mi; }
+ int maxIconWidth() const { return i1; }
+ int tabWidth() const { return i2; }
+
+ const TQColor& color() const { return *cl; }
+
+ TQTab* tab() const { return tb; }
+
+ TQCheckListItem* checkListItem() const { return cli; }
+ TQListViewItem* listViewItem() const { return li; }
+
+ TQt::ArrowType arrowType() const { return (TQt::ArrowType)i1; }
+ TQRect rect() const { return TQRect( i1, i2, i3, i4 ); }
+ TQWidget* widget() const { return (TQWidget*)p1; }
+
+private:
+ // NOTE: none of these components have constructors.
+ bool def;
+ bool b1,b2,b3; // reserved
+ TQMenuItem* mi;
+ TQTab* tb;
+ TQListViewItem* li;
+ const TQColor* cl;
+ int i1, i2, i3, i4;
+ int i5, i6; // reserved
+ TQCheckListItem* cli;
+ void *p1, *p2, *p3, *p4; // reserved
+ // (padded to 64 bytes on some architectures)
+};
+
+class TQStyleHintReturn; // not defined yet
+
+class TQ_EXPORT TQStyle: public TQObject
+{
+ TQ_OBJECT
+
+public:
+ TQStyle();
+ virtual ~TQStyle();
+
+ // New TQStyle API - most of these should probably be pure virtual
+
+ virtual void polish( TQWidget * );
+ virtual void unPolish( TQWidget * );
+
+ virtual void polish( TQApplication * );
+ virtual void unPolish( TQApplication * );
+
+ virtual void polish( TQPalette & );
+
+ virtual void polishPopupMenu( TQPopupMenu* ) = 0;
+
+ virtual TQRect tqitemRect( TQPainter *p, const TQRect &r,
+ int flags, bool enabled,
+ const TQPixmap *pixmap,
+ const TQString &text, int len = -1 ) const;
+
+ virtual void drawItem( TQPainter *p, const TQRect &r,
+ int flags, const TQColorGroup &g, bool enabled,
+ const TQPixmap *pixmap, const TQString &text,
+ int len = -1, const TQColor *penColor = 0 ) const;
+
+
+ enum PrimitiveElement {
+ PE_ButtonCommand,
+ PE_ButtonDefault,
+ PE_ButtonBevel,
+ PE_ButtonTool,
+ PE_ButtonDropDown,
+
+ PE_FocusRect,
+
+ PE_ArrowUp,
+ PE_ArrowDown,
+ PE_ArrowRight,
+ PE_ArrowLeft,
+
+ PE_SpinWidgetUp,
+ PE_SpinWidgetDown,
+ PE_SpinWidgetPlus,
+ PE_SpinWidgetMinus,
+
+ PE_Indicator,
+ PE_IndicatorMask,
+ PE_ExclusiveIndicator,
+ PE_ExclusiveIndicatorMask,
+
+ PE_DockWindowHandle,
+ PE_DockWindowSeparator,
+ PE_DockWindowResizeHandle,
+
+ PE_Splitter,
+
+ PE_Panel,
+ PE_PanelPopup,
+ PE_PanelMenuBar,
+ PE_PanelDockWindow,
+
+ PE_TabBarBase,
+
+ PE_HeaderSection,
+ PE_HeaderArrow,
+ PE_tqStatusBarSection,
+
+ PE_GroupBoxFrame,
+
+ PE_Separator,
+
+ PE_SizeGrip,
+
+ PE_CheckMark,
+
+ PE_ScrollBarAddLine,
+ PE_ScrollBarSubLine,
+ PE_ScrollBarAddPage,
+ PE_ScrollBarSubPage,
+ PE_ScrollBarSlider,
+ PE_ScrollBarFirst,
+ PE_ScrollBarLast,
+
+ PE_ProgressBarChunk,
+
+ PE_PanelLineEdit,
+ PE_PanelTabWidget,
+
+ PE_WindowFrame,
+
+ PE_CheckListController,
+ PE_CheckListIndicator,
+ PE_CheckListExclusiveIndicator,
+
+ PE_PanelGroupBox,
+ PE_RubberBand,
+
+ // do not add any values below/greater this
+ PE_CustomBase = 0xf000000
+ };
+
+ enum StyleFlags {
+ Style_Default = 0x00000000,
+ Style_Enabled = 0x00000001,
+ Style_Raised = 0x00000002,
+ Style_Sunken = 0x00000004,
+ Style_Off = 0x00000008,
+ Style_NoChange = 0x00000010,
+ Style_On = 0x00000020,
+ Style_Down = 0x00000040,
+ Style_Horizontal = 0x00000080,
+ Style_HasFocus = 0x00000100,
+ Style_Top = 0x00000200,
+ Style_Bottom = 0x00000400,
+ Style_FocusAtBorder = 0x00000800,
+ Style_AutoRaise = 0x00001000,
+ Style_MouseOver = 0x00002000,
+ Style_Up = 0x00004000,
+ Style_Selected = 0x00008000,
+ Style_Active = 0x00010000,
+ Style_ButtonDefault = 0x00020000
+ };
+ typedef uint SFlags;
+
+ virtual void drawPrimitive( PrimitiveElement pe,
+ TQPainter *p,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags flags = Style_Default,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+
+
+ enum ControlElement {
+ CE_PushButton,
+ CE_PushButtonLabel,
+
+ CE_CheckBox,
+ CE_CheckBoxLabel,
+
+ CE_RadioButton,
+ CE_RadioButtonLabel,
+
+ CE_TabBarTab,
+ CE_TabBarLabel,
+
+ CE_ProgressBarGroove,
+ CE_ProgressBarContents,
+ CE_ProgressBarLabel,
+
+ CE_PopupMenuItem,
+ CE_MenuBarItem,
+
+ CE_ToolButtonLabel,
+ CE_MenuBarEmptyArea,
+ CE_PopupMenuScroller,
+ CE_DockWindowEmptyArea,
+ CE_PopupMenuVerticalExtra,
+ CE_PopupMenuHorizontalExtra,
+
+ CE_ToolBoxTab,
+ CE_HeaderLabel,
+
+ // do not add any values below/greater than this
+ CE_CustomBase = 0xf0000000
+ };
+
+ virtual void tqdrawControl( ControlElement element,
+ TQPainter *p,
+ const TQWidget *widget,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags how = Style_Default,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+ virtual void tqdrawControlMask( ControlElement element,
+ TQPainter *p,
+ const TQWidget *widget,
+ const TQRect &r,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+
+ enum SubRect {
+ SR_PushButtonContents,
+ SR_PushButtonFocusRect,
+
+ SR_CheckBoxIndicator,
+ SR_CheckBoxContents,
+ SR_CheckBoxFocusRect,
+
+ SR_RadioButtonIndicator,
+ SR_RadioButtonContents,
+ SR_RadioButtonFocusRect,
+
+ SR_ComboBoxFocusRect,
+
+ SR_SliderFocusRect,
+
+ SR_DockWindowHandleRect,
+
+ SR_ProgressBarGroove,
+ SR_ProgressBarContents,
+ SR_ProgressBarLabel,
+
+ SR_ToolButtonContents,
+
+ SR_DialogButtonAccept,
+ SR_DialogButtonReject,
+ SR_DialogButtonApply,
+ SR_DialogButtonHelp,
+ SR_DialogButtonAll,
+ SR_DialogButtonAbort,
+ SR_DialogButtonIgnore,
+ SR_DialogButtonRetry,
+ SR_DialogButtonCustom,
+
+ SR_ToolBoxTabContents,
+
+ // do not add any values below/greater than this
+ SR_CustomBase = 0xf0000000
+ };
+
+ virtual TQRect subRect( SubRect r, const TQWidget *widget ) const = 0;
+
+
+ enum ComplexControl{
+ CC_SpinWidget,
+ CC_ComboBox,
+ CC_ScrollBar,
+ CC_Slider,
+ CC_ToolButton,
+ CC_TitleBar,
+ CC_ListView,
+
+ // do not add any values below/greater than this
+ CC_CustomBase = 0xf0000000
+ };
+
+ enum SubControl {
+ SC_None = 0x00000000,
+
+ SC_ScrollBarAddLine = 0x00000001,
+ SC_ScrollBarSubLine = 0x00000002,
+ SC_ScrollBarAddPage = 0x00000004,
+ SC_ScrollBarSubPage = 0x00000008,
+ SC_ScrollBarFirst = 0x00000010,
+ SC_ScrollBarLast = 0x00000020,
+ SC_ScrollBarSlider = 0x00000040,
+ SC_ScrollBarGroove = 0x00000080,
+
+ SC_SpinWidgetUp = 0x00000001,
+ SC_SpinWidgetDown = 0x00000002,
+ SC_SpinWidgetFrame = 0x00000004,
+ SC_SpinWidgetEditField = 0x00000008,
+ SC_SpinWidgetButtonField = 0x00000010,
+
+ SC_ComboBoxFrame = 0x00000001,
+ SC_ComboBoxEditField = 0x00000002,
+ SC_ComboBoxArrow = 0x00000004,
+ SC_ComboBoxListBoxPopup = 0x00000008,
+
+ SC_SliderGroove = 0x00000001,
+ SC_SliderHandle = 0x00000002,
+ SC_SliderTickmarks = 0x00000004,
+
+ SC_ToolButton = 0x00000001,
+ SC_ToolButtonMenu = 0x00000002,
+
+ SC_TitleBarLabel = 0x00000001,
+ SC_TitleBarSysMenu = 0x00000002,
+ SC_TitleBarMinButton = 0x00000004,
+ SC_TitleBarMaxButton = 0x00000008,
+ SC_TitleBarCloseButton = 0x00000010,
+ SC_TitleBarNormalButton = 0x00000020,
+ SC_TitleBarShadeButton = 0x00000040,
+ SC_TitleBarUnshadeButton = 0x00000080,
+
+ SC_ListView = 0x00000001,
+ SC_ListViewBranch = 0x00000002,
+ SC_ListViewExpand = 0x00000004,
+
+ SC_All = 0xffffffff
+ };
+ typedef uint SCFlags;
+
+
+ virtual void tqdrawComplexControl( ComplexControl control,
+ TQPainter *p,
+ const TQWidget *widget,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags how = Style_Default,
+#ifdef TQ_TQDOC
+ SCFlags sub = SC_All,
+#else
+ SCFlags sub = (uint)SC_All,
+#endif
+ SCFlags subActive = SC_None,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+ virtual void tqdrawComplexControlMask( ComplexControl control,
+ TQPainter *p,
+ const TQWidget *widget,
+ const TQRect &r,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+
+ virtual TQRect querySubControlMetrics( ComplexControl control,
+ const TQWidget *widget,
+ SubControl sc,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+ virtual SubControl querySubControl( ComplexControl control,
+ const TQWidget *widget,
+ const TQPoint &pos,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+
+
+ enum PixelMetric {
+ PM_ButtonMargin,
+ PM_ButtonDefaultIndicator,
+ PM_MenuButtonIndicator,
+ PM_ButtonShiftHorizontal,
+ PM_ButtonShiftVertical,
+
+ PM_DefaultFrameWidth,
+ PM_SpinBoxFrameWidth,
+
+ PM_MaximumDragDistance,
+
+ PM_ScrollBarExtent,
+ PM_ScrollBarSliderMin,
+
+ PM_SliderThickness, // total slider thickness
+ PM_SliderControlThickness, // thickness of the business part
+ PM_SliderLength, // total length of slider
+ PM_SliderTickmarkOffset, //
+ PM_SliderSpaceAvailable, // available space for slider to move
+
+ PM_DockWindowSeparatorExtent,
+ PM_DockWindowHandleExtent,
+ PM_DockWindowFrameWidth,
+
+ PM_MenuBarFrameWidth,
+
+ PM_TabBarTabOverlap,
+ PM_TabBarTabHSpace,
+ PM_TabBarTabVSpace,
+ PM_TabBarBaseHeight,
+ PM_TabBarBaseOverlap,
+
+ PM_ProgressBarChunkWidth,
+
+ PM_SplitterWidth,
+ PM_TitleBarHeight,
+
+ PM_IndicatorWidth,
+ PM_IndicatorHeight,
+ PM_ExclusiveIndicatorWidth,
+ PM_ExclusiveIndicatorHeight,
+ PM_PopupMenuScrollerHeight,
+ PM_CheckListButtonSize,
+ PM_CheckListControllerSize,
+ PM_PopupMenuFrameHorizontalExtra,
+ PM_PopupMenuFrameVerticalExtra,
+
+ PM_DialogButtonsSeparator,
+ PM_DialogButtonsButtonWidth,
+ PM_DialogButtonsButtonHeight,
+
+ PM_MDIFrameWidth,
+ PM_MDIMinimizedWidth,
+ PM_HeaderMargin,
+ PM_HeaderMarkSize,
+ PM_HeaderGripMargin,
+ PM_TabBarTabShiftHorizontal,
+ PM_TabBarTabShiftVertical,
+ PM_TabBarScrollButtonWidth,
+
+ PM_MenuBarItemSpacing,
+ PM_ToolBarItemSpacing,
+
+ // do not add any values below/greater than this
+ PM_CustomBase = 0xf0000000
+ };
+
+ virtual int tqpixelMetric( PixelMetric metric,
+ const TQWidget *widget = 0 ) const = 0;
+
+
+ enum ContentsType {
+ CT_PushButton,
+ CT_CheckBox,
+ CT_RadioButton,
+ CT_ToolButton,
+ CT_ComboBox,
+ CT_Splitter,
+ CT_DockWindow,
+ CT_ProgressBar,
+ CT_PopupMenuItem,
+ CT_TabBarTab,
+ CT_Slider,
+ CT_Header,
+ CT_LineEdit,
+ CT_MenuBar,
+ CT_SpinBox,
+ CT_SizeGrip,
+ CT_TabWidget,
+ CT_DialogButtons,
+
+ // do not add any values below/greater than this
+ CT_CustomBase = 0xf0000000
+ };
+
+ virtual TQSize sizeFromContents( ContentsType contents,
+ const TQWidget *widget,
+ const TQSize &contentsSize,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+
+ enum StyleHint {
+ // ...
+ // the general hints
+ // ...
+ // disabled text should be etched, ala Windows
+ SH_EtchDisabledText,
+
+ // the GUI style enum, argh!
+ SH_GUIStyle,
+
+ // ...
+ // widget specific hints
+ // ...
+ SH_ScrollBar_BackgroundMode,
+ SH_ScrollBar_MiddleClickAbsolutePosition,
+ SH_ScrollBar_ScrollWhenPointerLeavesControl,
+
+ // TQEvent::Type - which mouse event to select a tab
+ SH_TabBar_SelectMouseType,
+
+ SH_TabBar_Alignment,
+
+ SH_Header_ArrowAlignment,
+
+ // bool - sliders snap to values while moving, ala Windows
+ SH_Slider_SnapToValue,
+
+ // bool - key presses handled in a sloppy manner - ie. left on a vertical
+ // slider subtracts a line
+ SH_Slider_SloppyKeyEvents,
+
+ // bool - center button on progress dialogs, ala Motif, else right aligned
+ // perhaps this should be a TQt::Alignment value
+ SH_ProgressDialog_CenterCancelButton,
+
+ // TQt::AlignmentFlags - text label tqalignment in progress dialogs
+ // Center on windows, Auto|VCenter otherwize
+ SH_ProgressDialog_TextLabelAlignment,
+
+ // bool - right align buttons on print dialog, ala Windows
+ SH_PrintDialog_RightAlignButtons,
+
+ // bool - 1 or 2 pixel space between the menubar and the dockarea, ala Windows
+ // this *REALLY* needs a better name
+ SH_MainWindow_SpaceBelowMenuBar,
+
+ // bool - select the text in the line edit about the listbox when selecting
+ // an item from the listbox, or when the line edit receives focus, ala Windows
+ SH_FontDialog_SelectAssociatedText,
+
+ // bool - allows disabled menu items to be active
+ SH_PopupMenu_AllowActiveAndDisabled,
+
+ // bool - pressing space activates item, ala Motif
+ SH_PopupMenu_SpaceActivatesItem,
+
+ // int - number of milliseconds to wait before opening a submenu
+ // 256 on windows, 96 on motif
+ SH_PopupMenu_SubMenuPopupDelay,
+
+ // bool - should scrollviews draw their frame only around contents (ala Motif),
+ // or around contents, scrollbars and corner widgets (ala Windows) ?
+ SH_ScrollView_FrameOnlyAroundContents,
+
+ // bool - menubars items are navigatable by pressing alt, followed by using
+ // the arrow keys to select the desired item
+ SH_MenuBar_AltKeyNavigation,
+
+ // bool - mouse tracking in combobox dropdown lists
+ SH_ComboBox_ListMouseTracking,
+
+ // bool - mouse tracking in popupmenus
+ SH_PopupMenu_MouseTracking,
+
+ // bool - mouse tracking in menubars
+ SH_MenuBar_MouseTracking,
+
+ // bool - gray out selected items when loosing focus
+ SH_ItemView_ChangeHighlightOnFocus,
+
+ // bool - supports shared activation among modeless widgets
+ SH_Widget_ShareActivation,
+
+ // bool - workspace should just maximize the client area
+ SH_Workspace_FillSpaceOnMaximize,
+
+ // bool - supports popup menu comboboxes
+ SH_ComboBox_Popup,
+
+ // bool - titlebar has no border
+ SH_TitleBar_NoBorder,
+
+ // bool - stop scrollbar at mouse
+ SH_ScrollBar_StopMouseOverSlider,
+
+ //bool - blink cursort with selected text
+ SH_BlinkCursorWhenTextSelected,
+
+ //bool - richtext selections extend the full width of the docuemnt
+ SH_RichText_FullWidthSelection,
+
+ //bool - popupmenu supports scrolling instead of multicolumn mode
+ SH_PopupMenu_Scrollable,
+
+ // TQt::AlignmentFlags - text label vertical tqalignment in groupboxes
+ // Center on windows, Auto|VCenter otherwize
+ SH_GroupBox_TextLabelVerticalAlignment,
+
+ // TQt::TQRgb - text label color in groupboxes
+ SH_GroupBox_TextLabelColor,
+
+ // bool - popupmenu supports sloppy submenus
+ SH_PopupMenu_SloppySubMenus,
+
+ // TQt::TQRgb - table grid color
+ SH_Table_GridLineColor,
+
+ // TQChar - Unicode character for password char
+ SH_LineEdit_PasswordCharacter,
+
+ // TQDialogButtons::Button - default button
+ SH_DialogButtons_DefaultButton,
+
+ // TQToolBox - Boldness of the selected page title
+ SH_ToolBox_SelectedPageTitleBold,
+
+ //bool - if a tabbar prefers not to have scroller arrows
+ SH_TabBar_PreferNoArrows,
+
+ //bool - if left button should cause an absolute position
+ SH_ScrollBar_LeftClickAbsolutePosition,
+
+ // TQEvent::Type - which mouse event to select a list view expansion
+ SH_ListViewExpand_SelectMouseType,
+
+ //bool - if underline for accelerators
+ SH_UnderlineAccelerator,
+
+ // bool - TQToolButton - if tool buttons should use a 3D frame
+ // when the mouse is over the button
+ SH_ToolButton_Uses3D,
+
+ // do not add any values below/greater than this
+ SH_CustomBase = 0xf0000000
+ };
+
+ virtual int tqstyleHint( StyleHint stylehint,
+ const TQWidget *widget = 0,
+ const TQStyleOption& = TQStyleOption::Default,
+ TQStyleHintReturn* returnData = 0
+ ) const = 0;
+
+
+ enum StylePixmap {
+ SP_TitleBarMinButton,
+ SP_TitleBarMaxButton,
+ SP_TitleBarCloseButton,
+ SP_TitleBarNormalButton,
+ SP_TitleBarShadeButton,
+ SP_TitleBarUnshadeButton,
+ SP_DockWindowCloseButton,
+ SP_MessageBoxInformation,
+ SP_MessageBoxWarning,
+ SP_MessageBoxCritical,
+ SP_MessageBoxQuestion,
+
+ // do not add any values below/greater than this
+ SP_CustomBase = 0xf0000000
+ };
+
+ virtual TQPixmap stylePixmap( StylePixmap stylepixmap,
+ const TQWidget *widget = 0,
+ const TQStyleOption& = TQStyleOption::Default ) const = 0;
+
+
+ static TQRect tqvisualRect( const TQRect &logical, const TQWidget *w );
+
+ static TQRect tqvisualRect( const TQRect &logical, const TQRect &bounding );
+
+
+
+
+ // Old 2.x TQStyle API
+
+#ifndef TQT_NO_COMPAT
+ int defaultFrameWidth() const
+ {
+ return tqpixelMetric( PM_DefaultFrameWidth );
+ }
+ void tabbarMetrics( const TQWidget* t,
+ int& hf, int& vf, int& ov ) const
+ {
+ hf = tqpixelMetric( PM_TabBarTabHSpace, t );
+ vf = tqpixelMetric( PM_TabBarTabVSpace, t );
+ ov = tqpixelMetric( PM_TabBarBaseOverlap, t );
+ }
+ TQSize scrollBarExtent() const
+ {
+ return TQSize(tqpixelMetric(PM_ScrollBarExtent),
+ tqpixelMetric(PM_ScrollBarExtent));
+ }
+#endif
+
+
+private:
+ TQStylePrivate * d;
+
+#if defined(TQ_DISABLE_COPY)
+ TQStyle( const TQStyle & );
+ TQStyle& operator=( const TQStyle & );
+#endif
+};
+
+#endif // TQT_NO_STYLE
+#endif // TQSTYLE_H
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqstylesheet.cpp b/tqtinterface/qt4/src/kernel/tqstylesheet.cpp
new file mode 100644
index 0000000..25f6c0c
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqstylesheet.cpp
@@ -0,0 +1,1623 @@
+/****************************************************************************
+**
+** Implementation of the TQStyleSheet class
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqstylesheet.h"
+
+#ifndef TQT_NO_RICHTEXT
+
+#include "private/tqrichtext_p.h"
+#include "tqlayout.h"
+#include "tqpainter.h"
+#include "tqcleanuphandler.h"
+
+#include <stdio.h>
+
+class TQStyleSheetItemData
+{
+public:
+ TQStyleSheetItem::DisplayMode disp;
+ int fontitalic;
+ int fontunderline;
+ int fontstrikeout;
+ int fontweight;
+ int fontsize;
+ int fontsizelog;
+ int fontsizestep;
+ int lineSpacing;
+ TQString fontfamily;
+ TQStyleSheetItem *parentstyle;
+ TQString stylename;
+ int ncolumns;
+ TQColor col;
+ bool anchor;
+ int align;
+ TQStyleSheetItem::VerticalAlignment valign;
+ int margin[5];
+ TQStyleSheetItem::ListStyle list;
+ TQStyleSheetItem::WhiteSpaceMode whitespacemode;
+ TQString contxt;
+ bool selfnest;
+ TQStyleSheet* sheet;
+};
+
+/*!
+ \class TQStyleSheetItem tqstylesheet.h
+ \brief The TQStyleSheetItem class provides an encapsulation of a set of text styles.
+
+ \ingroup text
+
+ A style sheet item consists of a name and a set of attributes that
+ specifiy its font, color, etc. When used in a \link TQStyleSheet
+ style sheet\endlink (see styleSheet()), items define the name() of
+ a rich text tag and the display property changes associated with
+ it.
+
+ The \link TQStyleSheetItem::DisplayMode display mode\endlink
+ attribute indicates whether the item is a block, an inline element
+ or a list element; see setDisplayMode(). The treatment of
+ whitespace is controlled by the \link
+ TQStyleSheetItem::WhiteSpaceMode white space mode\endlink; see
+ setWhiteSpaceMode(). An item's margins are set with setMargin(),
+ In the case of list items, the list style is set with
+ setListStyle(). An item may be a hypertext link anchor; see
+ setAnchor(). Other attributes are set with tqsetAlignment(),
+ setVerticalAlignment(), setFontFamily(), setFontSize(),
+ setFontWeight(), setFontItalic(), setFontUnderline(),
+ setFontStrikeOut and setColor().
+*/
+
+/*! \enum TQStyleSheetItem::AdditionalStyleValues
+ \internal
+*/
+
+/*!
+ \enum TQStyleSheetItem::WhiteSpaceMode
+
+ This enum defines the ways in which TQStyleSheet can treat
+ whitespace.
+
+ \value WhiteSpaceNormal any sequence of whitespace (including
+ line-breaks) is equivalent to a single space.
+
+ \value WhiteSpacePre whitespace must be output exactly as given
+ in the input.
+
+ \value WhiteSpaceNoWrap multiple spaces are collapsed as with
+ WhiteSpaceNormal, but no automatic line-breaks occur. To break
+ lines manually, use the \c{<br>} tag.
+
+*/
+
+/*!
+ \enum TQStyleSheetItem::Margin
+
+ \value MarginLeft left margin
+ \value MarginRight right margin
+ \value MarginTop top margin
+ \value MarginBottom bottom margin
+ \value MarginAll all margins (left, right, top and bottom)
+ \value MarginVertical top and bottom margins
+ \value MarginHorizontal left and right margins
+ \value MarginFirstLine margin (indentation) of the first line of
+ a paragarph (in addition to the MarginLeft of the paragraph)
+*/
+
+/*!
+ Constructs a new style called \a name for the stylesheet \a
+ tqparent.
+
+ All properties in TQStyleSheetItem are initially in the "do not
+ change" state, except \link TQStyleSheetItem::DisplayMode display
+ mode\endlink, which defaults to \c DisplayInline.
+*/
+TQStyleSheetItem::TQStyleSheetItem( TQStyleSheet* tqparent, const TQString& name )
+{
+ d = new TQStyleSheetItemData;
+ d->stylename = name.lower();
+ d->sheet = tqparent;
+ init();
+ if (tqparent)
+ tqparent->insert( this );
+}
+
+/*!
+ Copy constructor. Constructs a copy of \a other that is not bound
+ to any style sheet.
+*/
+TQStyleSheetItem::TQStyleSheetItem( const TQStyleSheetItem & other )
+{
+ d = new TQStyleSheetItemData;
+ *d = *other.d;
+}
+
+
+/*!
+ Destroys the style. Note that TQStyleSheetItem objects become
+ owned by TQStyleSheet when they are created.
+*/
+TQStyleSheetItem::~TQStyleSheetItem()
+{
+ delete d;
+}
+
+/*!
+ Assignment. Assings a copy of \a other that is not bound to any style sheet.
+ Unbounds first from previous style sheet.
+ */
+TQStyleSheetItem& TQStyleSheetItem::operator=( const TQStyleSheetItem& other )
+{
+ if ( &other == this )
+ return *this;
+ delete d;
+ d = new TQStyleSheetItemData;
+ *d = *other.d;
+ return *this;
+}
+
+/*!
+ Returns the style sheet this item is in.
+*/
+TQStyleSheet* TQStyleSheetItem::styleSheet()
+{
+ return d->sheet;
+}
+
+/*!
+ \overload
+
+ Returns the style sheet this item is in.
+*/
+const TQStyleSheet* TQStyleSheetItem::styleSheet() const
+{
+ return d->sheet;
+}
+
+/*!
+ \internal
+ Internal initialization
+ */
+void TQStyleSheetItem::init()
+{
+ d->disp = DisplayInline;
+
+ d->fontitalic = Undefined;
+ d->fontunderline = Undefined;
+ d->fontstrikeout = Undefined;
+ d->fontweight = Undefined;
+ d->fontsize = Undefined;
+ d->fontsizelog = Undefined;
+ d->fontsizestep = 0;
+ d->ncolumns = Undefined;
+ d->col = TQColor(); // !isValid()
+ d->anchor = FALSE;
+ d->align = Undefined;
+ d->valign = VAlignBaseline;
+ d->margin[0] = Undefined;
+ d->margin[1] = Undefined;
+ d->margin[2] = Undefined;
+ d->margin[3] = Undefined;
+ d->margin[4] = Undefined;
+ d->list = ListStyleUndefined;
+ d->whitespacemode = WhiteSpaceModeUndefined;
+ d->selfnest = TRUE;
+ d->lineSpacing = Undefined;
+}
+
+/*!
+ Returns the name of the style item.
+*/
+TQString TQStyleSheetItem::name() const
+{
+ return d->stylename;
+}
+
+/*!
+ Returns the \link TQStyleSheetItem::DisplayMode display
+ mode\endlink of the style.
+
+ \sa setDisplayMode()
+*/
+TQStyleSheetItem::DisplayMode TQStyleSheetItem::displayMode() const
+{
+ return d->disp;
+}
+
+/*!
+ \enum TQStyleSheetItem::DisplayMode
+
+ This enum type defines the way adjacent elements are displayed.
+
+ \value DisplayBlock elements are displayed as a rectangular block
+ (e.g. \c{<p>...</p>}).
+
+ \value DisplayInline elements are displayed in a horizontally
+ flowing sequence (e.g. \c{<em>...</em>}).
+
+ \value DisplayListItem elements are displayed in a vertical
+ sequence (e.g. \c{<li>...</li>}).
+
+ \value DisplayNone elements are not displayed at all.
+*/
+
+/*!
+ Sets the display mode of the style to \a m.
+
+ \sa displayMode()
+ */
+void TQStyleSheetItem::setDisplayMode(DisplayMode m)
+{
+ d->disp=m;
+}
+
+
+/*!
+ Returns the tqalignment of this style. Possible values are \c
+ AlignAuto, \c AlignLeft, \c AlignRight, \c AlignCenter or \c
+ AlignJustify.
+
+ \sa tqsetAlignment(), TQt::AlignmentFlags
+*/
+int TQStyleSheetItem::tqalignment() const
+{
+ return d->align;
+}
+
+/*!
+ Sets the tqalignment to \a f. This only makes sense for styles with
+ a \link TQStyleSheetItem::DisplayMode display mode\endlink of
+ DisplayBlock. Possible values are \c AlignAuto, \c AlignLeft,
+ \c AlignRight, \c AlignCenter or \c AlignJustify.
+
+ \sa tqalignment(), displayMode(), TQt::AlignmentFlags
+*/
+void TQStyleSheetItem::tqsetAlignment( int f )
+{
+ d->align = f;
+}
+
+
+/*!
+ Returns the vertical tqalignment of the style. Possible values are
+ \c VAlignBaseline, \c VAlignSub or \c VAlignSuper.
+
+ \sa setVerticalAlignment()
+*/
+TQStyleSheetItem::VerticalAlignment TQStyleSheetItem::verticalAlignment() const
+{
+ return d->valign;
+}
+
+/*!
+ \enum TQStyleSheetItem::VerticalAlignment
+
+ This enum type defines the way elements are aligned vertically.
+ This is only supported for text elements.
+
+ \value VAlignBaseline align the baseline of the element (or the
+ bottom, if the element doesn't have a baseline) with the
+ baseline of the tqparent
+
+ \value VAlignSub subscript the element
+
+ \value VAlignSuper superscript the element
+
+*/
+
+
+/*!
+ Sets the vertical tqalignment to \a valign. Possible values are
+ \c VAlignBaseline, \c VAlignSub or \c VAlignSuper.
+
+ The vertical tqalignment property is not inherited.
+
+ \sa verticalAlignment()
+*/
+void TQStyleSheetItem::setVerticalAlignment( VerticalAlignment valign )
+{
+ d->valign = valign;
+}
+
+
+/*!
+ Returns TRUE if the style sets an italic font; otherwise returns
+ FALSE.
+
+ \sa setFontItalic(), definesFontItalic()
+*/
+bool TQStyleSheetItem::fontItalic() const
+{
+ return d->fontitalic > 0;
+}
+
+/*!
+ If \a italic is TRUE sets italic for the style; otherwise sets
+ upright.
+
+ \sa fontItalic(), definesFontItalic()
+*/
+void TQStyleSheetItem::setFontItalic(bool italic)
+{
+ d->fontitalic = italic?1:0;
+}
+
+/*!
+ Returns TRUE if the style defines a font tqshape; otherwise returns
+ FALSE. A style does not define any tqshape until setFontItalic() is
+ called.
+
+ \sa setFontItalic(), fontItalic()
+*/
+bool TQStyleSheetItem::definesFontItalic() const
+{
+ return d->fontitalic != Undefined;
+}
+
+/*!
+ Returns TRUE if the style sets an underlined font; otherwise
+ returns FALSE.
+
+ \sa setFontUnderline(), definesFontUnderline()
+*/
+bool TQStyleSheetItem::fontUnderline() const
+{
+ return d->fontunderline > 0;
+}
+
+/*!
+ If \a underline is TRUE, sets underline for the style; otherwise
+ sets no underline.
+
+ \sa fontUnderline(), definesFontUnderline()
+*/
+void TQStyleSheetItem::setFontUnderline(bool underline)
+{
+ d->fontunderline = underline?1:0;
+}
+
+/*!
+ Returns TRUE if the style defines a setting for the underline
+ property of the font; otherwise returns FALSE. A style does not
+ define this until setFontUnderline() is called.
+
+ \sa setFontUnderline(), fontUnderline()
+*/
+bool TQStyleSheetItem::definesFontUnderline() const
+{
+ return d->fontunderline != Undefined;
+}
+
+
+/*!
+ Returns TRUE if the style sets a strike out font; otherwise
+ returns FALSE.
+
+ \sa setFontStrikeOut(), definesFontStrikeOut()
+*/
+bool TQStyleSheetItem::fontStrikeOut() const
+{
+ return d->fontstrikeout > 0;
+}
+
+/*!
+ If \a strikeOut is TRUE, sets strike out for the style; otherwise
+ sets no strike out.
+
+ \sa fontStrikeOut(), definesFontStrikeOut()
+*/
+void TQStyleSheetItem::setFontStrikeOut(bool strikeOut)
+{
+ d->fontstrikeout = strikeOut?1:0;
+}
+
+/*!
+ Returns TRUE if the style defines a setting for the strikeOut
+ property of the font; otherwise returns FALSE. A style does not
+ define this until setFontStrikeOut() is called.
+
+ \sa setFontStrikeOut(), fontStrikeOut()
+*/
+bool TQStyleSheetItem::definesFontStrikeOut() const
+{
+ return d->fontstrikeout != Undefined;
+}
+
+
+/*!
+ Returns the font weight setting of the style. This is either a
+ valid \c TQFont::Weight or the value \c TQStyleSheetItem::Undefined.
+
+ \sa setFontWeight(), TQFont
+*/
+int TQStyleSheetItem::fontWeight() const
+{
+ return d->fontweight;
+}
+
+/*!
+ Sets the font weight setting of the style to \a w. Valid values
+ are those defined by \c TQFont::Weight.
+
+ \sa TQFont, fontWeight()
+*/
+void TQStyleSheetItem::setFontWeight(int w)
+{
+ d->fontweight = w;
+}
+
+/*!
+ Returns the logical font size setting of the style. This is either
+ a valid size between 1 and 7 or \c TQStyleSheetItem::Undefined.
+
+ \sa setLogicalFontSize(), setLogicalFontSizeStep(), TQFont::pointSize(), TQFont::setPointSize()
+*/
+int TQStyleSheetItem::logicalFontSize() const
+{
+ return d->fontsizelog;
+}
+
+
+/*!
+ Sets the logical font size setting of the style to \a s. Valid
+ logical sizes are 1 to 7.
+
+ \sa logicalFontSize(), TQFont::pointSize(), TQFont::setPointSize()
+*/
+void TQStyleSheetItem::setLogicalFontSize(int s)
+{
+ d->fontsizelog = s;
+}
+
+/*!
+ Returns the logical font size step of this style.
+
+ The default is 0. Tags such as \c big define \c +1; \c small
+ defines \c -1.
+
+ \sa setLogicalFontSizeStep()
+*/
+int TQStyleSheetItem::logicalFontSizeStep() const
+{
+ return d->fontsizestep;
+}
+
+/*!
+ Sets the logical font size step of this style to \a s.
+
+ \sa logicalFontSizeStep()
+*/
+void TQStyleSheetItem::setLogicalFontSizeStep( int s )
+{
+ d->fontsizestep = s;
+}
+
+
+
+/*!
+ Sets the font size setting of the style to \a s points.
+
+ \sa fontSize(), TQFont::pointSize(), TQFont::setPointSize()
+*/
+void TQStyleSheetItem::setFontSize(int s)
+{
+ d->fontsize = s;
+}
+
+/*!
+ Returns the font size setting of the style. This is either a valid
+ point size or \c TQStyleSheetItem::Undefined.
+
+ \sa setFontSize(), TQFont::pointSize(), TQFont::setPointSize()
+*/
+int TQStyleSheetItem::fontSize() const
+{
+ return d->fontsize;
+}
+
+
+/*!
+ Returns the font family setting of the style. This is either a
+ valid font family or TQString::null if no family has been set.
+
+ \sa setFontFamily(), TQFont::family(), TQFont::setFamily()
+*/
+TQString TQStyleSheetItem::fontFamily() const
+{
+ return d->fontfamily;
+}
+
+/*!
+ Sets the font family setting of the style to \a fam.
+
+ \sa fontFamily(), TQFont::family(), TQFont::setFamily()
+*/
+void TQStyleSheetItem::setFontFamily( const TQString& fam)
+{
+ d->fontfamily = fam;
+}
+
+
+/*!\obsolete
+ Returns the number of columns for this style.
+
+ \sa setNumberOfColumns(), displayMode(), setDisplayMode()
+
+ */
+int TQStyleSheetItem::numberOfColumns() const
+{
+ return d->ncolumns;
+}
+
+
+/*!\obsolete
+ Sets the number of columns for this style. Elements in the style
+ are divided into columns.
+
+ This makes sense only if the style uses a block display mode
+ (see TQStyleSheetItem::DisplayMode).
+
+ \sa numberOfColumns()
+ */
+void TQStyleSheetItem::setNumberOfColumns(int ncols)
+{
+ if (ncols > 0)
+ d->ncolumns = ncols;
+}
+
+
+/*!
+ Returns the text color of this style or an invalid color if no
+ color has been set.
+
+ \sa setColor() TQColor::isValid()
+*/
+TQColor TQStyleSheetItem::color() const
+{
+ return d->col;
+}
+
+/*!
+ Sets the text color of this style to \a c.
+
+ \sa color()
+*/
+void TQStyleSheetItem::setColor( const TQColor &c)
+{
+ d->col = c;
+}
+
+/*!
+ Returns whether this style is an anchor.
+
+ \sa setAnchor()
+*/
+bool TQStyleSheetItem::isAnchor() const
+{
+ return d->anchor;
+}
+
+/*!
+ If \a anc is TRUE, sets this style to be an anchor (hypertext
+ link); otherwise sets it to not be an anchor. Elements in this
+ style link to other documents or anchors.
+
+ \sa isAnchor()
+*/
+void TQStyleSheetItem::setAnchor(bool anc)
+{
+ d->anchor = anc;
+}
+
+
+/*!
+ Returns the whitespace mode.
+
+ \sa setWhiteSpaceMode() WhiteSpaceMode
+*/
+TQStyleSheetItem::WhiteSpaceMode TQStyleSheetItem::whiteSpaceMode() const
+{
+ return d->whitespacemode;
+}
+
+/*!
+ Sets the whitespace mode to \a m.
+
+ \sa WhiteSpaceMode
+*/
+void TQStyleSheetItem::setWhiteSpaceMode(WhiteSpaceMode m)
+{
+ d->whitespacemode = m;
+}
+
+
+/*!
+ Returns the width of margin \a m in pixels.
+
+ The margin, \a m, can be \c MarginLeft, \c MarginRight, \c
+ MarginTop, \c MarginBottom, or \c MarginFirstLine.
+
+ \sa setMargin() Margin
+*/
+int TQStyleSheetItem::margin(Margin m) const
+{
+ if (m == MarginAll ) {
+ return d->margin[MarginLeft];
+ } else if (m == MarginVertical) {
+ return d->margin[MarginTop];
+ } else if (m == MarginHorizontal) {
+ return d->margin[MarginLeft];
+ } else {
+ return d->margin[m];
+ }
+}
+
+
+/*!
+ Sets the width of margin \a m to \a v pixels.
+
+ The margin, \a m, can be \c MarginLeft, \c MarginRight, \c
+ MarginTop, \c MarginBottom, \c MarginFirstLine, \c MarginAll,
+ \c MarginVertical or \c MarginHorizontal. The value \a v must
+ be >= 0.
+
+ \sa margin()
+*/
+void TQStyleSheetItem::setMargin(Margin m, int v)
+{
+ if (m == MarginAll) {
+ d->margin[MarginLeft] = v;
+ d->margin[MarginRight] = v;
+ d->margin[MarginTop] = v;
+ d->margin[MarginBottom] = v;
+ } else if (m == MarginVertical ) {
+ d->margin[MarginTop] = v;
+ d->margin[MarginBottom] = v;
+ } else if (m == MarginHorizontal ) {
+ d->margin[MarginLeft] = v;
+ d->margin[MarginRight] = v;
+ } else {
+ d->margin[m] = v;
+ }
+}
+
+
+/*!
+ Returns the list style of the style.
+
+ \sa setListStyle() ListStyle
+ */
+TQStyleSheetItem::ListStyle TQStyleSheetItem::listStyle() const
+{
+ return d->list;
+}
+
+/*!
+ \enum TQStyleSheetItem::ListStyle
+
+ This enum type defines how the items in a list are prefixed when
+ displayed.
+
+ \value ListDisc a filled circle (i.e. a bullet)
+ \value ListCircle an unfilled circle
+ \value ListSquare a filled square
+ \value ListDecimal an integer in base 10: \e 1, \e 2, \e 3, ...
+ \value ListLowerAlpha a lowercase letter: \e a, \e b, \e c, ...
+ \value ListUpperAlpha an uppercase letter: \e A, \e B, \e C, ...
+*/
+
+/*!
+ Sets the list style of the style to \a s.
+
+ This is used by nested elements that have a display mode of \c
+ DisplayListItem.
+
+ \sa listStyle() DisplayMode ListStyle
+*/
+void TQStyleSheetItem::setListStyle(ListStyle s)
+{
+ d->list=s;
+}
+
+
+/*!
+ Returns a space-separated list of names of styles that may contain
+ elements of this style. If nothing has been set, contexts()
+ returns an empty string, which indicates that this style can be
+ nested everywhere.
+
+ \sa setContexts()
+*/
+TQString TQStyleSheetItem::contexts() const
+{
+ return d->contxt;
+}
+
+/*!
+ Sets a space-separated list of names of styles that may contain
+ elements of this style. If \a c is empty, the style can be nested
+ everywhere.
+
+ \sa contexts()
+*/
+void TQStyleSheetItem::setContexts( const TQString& c)
+{
+ d->contxt = TQChar(' ') + c + TQChar(' ');
+}
+
+/*!
+ Returns TRUE if this style can be nested into an element of style
+ \a s; otherwise returns FALSE.
+
+ \sa contexts(), setContexts()
+*/
+bool TQStyleSheetItem::allowedInContext( const TQStyleSheetItem* s) const
+{
+ if ( d->contxt.isEmpty() )
+ return TRUE;
+ return d->contxt.tqfind( TQChar(' ')+s->name()+TQChar(' ')) != -1;
+}
+
+
+/*!
+ Returns TRUE if this style has self-nesting enabled; otherwise
+ returns FALSE.
+
+ \sa setSelfNesting()
+*/
+bool TQStyleSheetItem::selfNesting() const
+{
+ return d->selfnest;
+}
+
+/*!
+ Sets the self-nesting property for this style to \a nesting.
+
+ In order to support "dirty" HTML, paragraphs \c{<p>} and list
+ items \c{<li>} are not self-nesting. This means that starting a
+ new paragraph or list item automatically closes the previous one.
+
+ \sa selfNesting()
+*/
+void TQStyleSheetItem::setSelfNesting( bool nesting )
+{
+ d->selfnest = nesting;
+}
+
+/*!
+ \internal
+ Sets the linespacing to be at least \a ls pixels.
+
+ For compatibility with previous TQt releases, small values get
+ treated differently: If \a ls is smaller than the default font
+ line spacing in pixels at parse time, the resulting line spacing
+ is the sum of the default line spacing plus \a ls. We recommend
+ not relying on this behavior.
+*/
+
+void TQStyleSheetItem::setLineSpacing( int ls )
+{
+ d->lineSpacing = ls;
+}
+
+/*!
+ \obsolete
+
+ Returns the linespacing
+*/
+
+int TQStyleSheetItem::lineSpacing() const
+{
+ return d->lineSpacing;
+}
+
+//************************************************************************
+
+
+
+
+//************************************************************************
+
+
+/*!
+ \class TQStyleSheet tqstylesheet.h
+ \ingroup text
+ \brief The TQStyleSheet class is a collection of styles for rich text
+ rendering and a generator of tags.
+
+ \ingroup graphics
+ \ingroup helpsystem
+
+ By creating TQStyleSheetItem objects for a style sheet you build a
+ definition of a set of tags. This definition will be used by the
+ internal rich text rendering system to parse and display text
+ documents to which the style sheet applies. Rich text is normally
+ visualized in a TQTextEdit or a TQTextBrowser. However, TQLabel,
+ TQWhatsThis and TQMessageBox also support it, and other classes are
+ likely to follow. With TQSimpleRichText it is possible to use the
+ rich text renderer for custom widgets as well.
+
+ The default TQStyleSheet object has the following style bindings,
+ sorted by structuring bindings, anchors, character style bindings
+ (i.e. inline styles), special elements such as horizontal lines or
+ images, and other tags. In addition, rich text supports simple
+ HTML tables.
+
+ The structuring tags are
+ \table
+ \header \i Structuring tags \i Notes
+ \row \i \c{<qt>}...\c{</qt>}
+ \i A TQt rich text document. It understands the following
+ attributes:
+ \list
+ \i \c title -- The caption of the document. This attribute is
+ easily accessible with TQTextEdit::documentTitle().
+ \i \c type -- The type of the document. The default type is \c
+ page. It indicates that the document is displayed in a
+ page of its own. Another style is \c detail, which can be
+ used to explain certain expressions in more detail in a
+ few sentences. For \c detail, TQTextBrowser will then keep
+ the current page and display the new document in a small
+ popup similar to TQWhatsThis. Note that links will not work
+ in documents with \c{<qt type="detail">...</qt>}.
+ \i \c bgcolor -- The background color, for example \c
+ bgcolor="yellow" or \c bgcolor="#0000FF".
+ \i \c background -- The background pixmap, for example \c
+ background="granite.xpm". The pixmap name will be resolved
+ by a TQMimeSourceFactory().
+ \i \c text -- The default text color, for example \c text="red".
+ \i \c link -- The link color, for example \c link="green".
+ \endlist
+ \row \i \c{<h1>...</h1>}
+ \i A top-level heading.
+ \row \i \c{<h2>...</h2>}
+ \i A sublevel heading.
+ \row \i \c{<h3>...</h3>}
+ \i A sub-sublevel heading.
+ \row \i \c{<h4>...</h4>} \c{<h5>...</h5>}
+ \i Headings of lesser importance.
+ \row \i \c{<p>...</p>}
+ \i A left-aligned paragraph. Adjust the tqalignment with the \c
+ align attribute. Possible values are \c left, \c right and
+ \c center.
+ \row \i \c{<center>...}<br>\c{</center>}
+ \i A centered paragraph.
+ \row \i \c{<blockquote>...}<br>\c{</blockquote>}
+ \i An indented paragraph that is useful for quotes.
+ \row \i \c{<ul>...</ul>}
+ \i An unordered list. You can also pass a type argument to
+ define the bullet style. The default is \c type=disc;
+ other types are \c circle and \c square.
+ \row \i \c{<ol>...</ol>}
+ \i An ordered list. You can also pass a type argument to
+ define the enumeration label style. The default is \c
+ type="1"; other types are \c "a" and \c "A".
+ \row \i \c{<li>...</li>}
+ \i A list item. This tag can be used only within the context
+ of \c{<ol>} or \c{<ul>}.
+ \row \i \c{<dl>...</dl>}
+ \i A list of definitions, consisting of terms and descriptions.
+ \row \i \c{<dt>...</dt>}
+ \i A term in a list of definitions. This tag can be used only
+ in the context of \c{<dl>...</dl>}.
+ \row \i \c{<dd>...</dd>}
+ \i A description in a list of definitions. This tag can be
+ used only in the context of \c{<dl>...</dl>}.
+ \row \i \c{<pre>...</pre>}
+ \i For larger chunks of code. Whitespaces in the contents are
+ preserved. For small bits of code use the inline-style \c
+ code.
+ \row \i \c{<div>...</div>} and \c{<span>...</span>}
+ \i Block grouping elements. These are used to structure the
+ document, and are often used to provide hints about the
+ intended presentation of the document.
+ \endtable
+
+ Anchors and links are done with a single tag:
+ \table
+ \header \i Anchor tags \i Notes
+ \row \i \c{<a>...</a>}
+ \i An anchor or link.
+ \list
+ \i A link is created by using an \c href
+ attribute, for example
+ <br>\c{<a href="target.qml">Link Text</a>}. Links to
+ targets within a document are achieved in the same way
+ as for HTML, e.g.
+ <br>\c{<a href="target.qml#subtitle">Link Text</a>}.
+ \i A target is created by using a \c name
+ attribute, for example
+ <br>\c{<a name="subtitle"><h2>Sub Title</h2></a>}.
+ \endlist
+ \endtable
+
+ The default character style bindings are
+ \table
+ \header \i Style tags \i Notes
+ \row \i \c{<em>...</em>}
+ \i Emphasized. By default this is the same as \c{<i>...</i>}
+ (italic).
+ \row \i \c{<strong>...</strong>}
+ \i Strong. By default this is the same as \c{<b>...</b>}
+ (bold).
+ \row \i \c{<i>...</i>}
+ \i Italic font style.
+ \row \i \c{<b>...</b>}
+ \i Bold font style.
+ \row \i \c{<u>...</u>}
+ \i Underlined font style.
+ \row \i \c{<s>...</s>}
+ \i Strike out font style.
+ \row \i \c{<big>...</big>}
+ \i A larger font size.
+ \row \i \c{<small>...</small>}
+ \i A smaller font size.
+ \row \i \c{<sub>...</sub>}
+ \i Subscripted text
+ \row \i \c{<sup>...</sup>}
+ \i Superscripted text
+ \row \i \c{<code>...</code>}
+ \i Indicates code. By default this is the same as
+ \c{<tt>...</tt>} (typewriter). For larger chunks of code
+ use the block-tag \c{<}\c{pre>}.
+ \row \i \c{<tt>...</tt>}
+ \i Typewriter font style.
+ \row \i \c{<font>...</font>}
+ \i Customizes the font size, family and text color. The tag
+ understands the following attributes:
+ \list
+ \i \c color -- The text color, for example \c color="red" or
+ \c color="#FF0000".
+ \i \c size -- The logical size of the font. Logical sizes 1
+ to 7 are supported. The value may either be absolute
+ (for example, \c size=3) or relative (\c size=-2). In
+ the latter case the sizes are simply added.
+ \i \c face -- The family of the font, for example \c face=times.
+ \endlist
+ \endtable
+
+ Special elements are:
+ \table
+ \header \i Special tags \i Notes
+ \row \i \c{<img>}
+ \i An image. The image name for the mime source factory is
+ given in the source attribute, for example
+ \c{<img src="qt.xpm">} The image tag also understands the
+ attributes \c width and \c height that determine the size
+ of the image. If the pixmap does not fit the specified
+ size it will be scaled automatically (by using
+ TQImage::smoothScale()).
+ <br>
+ The \c align attribute determines where the image is
+ placed. By default, an image is placed inline just like a
+ normal character. Specify \c left or \c right to place the
+ image at the respective side.
+ \row \i \c{<hr>}
+ \i A horizontal line.
+ \row \i \c{<br>}
+ \i A line break.
+ \row \i \c{<nobr>...</nobr>}
+ \i No break. Prevents word wrap.
+ \endtable
+
+ In addition, rich text supports simple HTML tables. A table
+ consists of one or more rows each of which tqcontains one or more
+ cells. Cells are either data cells or header cells, depending on
+ their content. Cells which span rows and columns are supported.
+
+ \table
+ \header \i Table tags \i Notes
+ \row \i \c{<table>...</table>}
+ \i A table. Tables support the following attributes:
+ \list
+ \i \c bgcolor -- The background color.
+ \i \c width -- The table width. This is either an absolute
+ pixel width or a relative percentage of the table's
+ width, for example \c width=80%.
+ \i \c border -- The width of the table border. The default is
+ 0 (= no border).
+ \i \c cellspacing -- Additional space around the table cells.
+ The default is 2.
+ \i \c cellpadding -- Additional space around the contents of
+ table cells. The default is 1.
+ \endlist
+ \row \i \c{<tr>...</tr>}
+ \i A table row. This is only valid within a \c table. Rows
+ support the following attribute:
+ \list
+ \i \c bgcolor -- The background color.
+ \endlist
+ \row \i \c{<th>...</th>}
+ \i A table header cell. Similar to \c td, but defaults to
+ center tqalignment and a bold font.
+ \row \i \c{<td>...</td>}
+ \i A table data cell. This is only valid within a \c tr.
+ Cells support the following attributes:
+ \list
+ \i \c bgcolor -- The background color.
+ \i \c width -- The cell width. This is either an absolute
+ pixel width or a relative percentage of table's width,
+ for example \c width=50%.
+ \i \c colspan -- Specifies how many columns this cell spans.
+ The default is 1.
+ \i \c rowspan -- Specifies how many rows this cell spans. The
+ default is 1.
+ \i \c align -- Alignment; possible values are \c left, \c
+ right, and \c center. The default is \c left.
+ \i \c valign -- Vertical tqalignment; possible values are \c
+ top, \c middle, and \c bottom. The default is \c middle.
+ \endlist
+ \endtable
+*/
+
+/*!
+ Creates a style sheet called \a name, with tqparent \a tqparent. Like
+ any TQObject it will be deleted when its tqparent is destroyed (if
+ the child still exists).
+
+ By default the style sheet has the tag definitions defined above.
+*/
+TQStyleSheet::TQStyleSheet( TQObject *tqparent, const char *name )
+ : TQObject( tqparent, name )
+{
+ init();
+}
+
+/*!
+ Destroys the style sheet. All styles inserted into the style sheet
+ will be deleted.
+*/
+TQStyleSheet::~TQStyleSheet()
+{
+}
+
+/*!
+ \internal
+ Initialized the style sheet to the basic TQt style.
+*/
+void TQStyleSheet::init()
+{
+ styles.setAutoDelete( TRUE );
+
+ nullstyle = new TQStyleSheetItem( this,
+ TQString::tqfromLatin1("") );
+
+ TQStyleSheetItem* style;
+
+ style = new TQStyleSheetItem( this, "qml" ); // compatibility
+ style->setDisplayMode( TQStyleSheetItem::DisplayBlock );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("qt") );
+ style->setDisplayMode( TQStyleSheetItem::DisplayBlock );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("a") );
+ style->setAnchor( TRUE );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("em") );
+ style->setFontItalic( TRUE );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("i") );
+ style->setFontItalic( TRUE );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("big") );
+ style->setLogicalFontSizeStep( 1 );
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("large") ); // compatibility
+ style->setLogicalFontSizeStep( 1 );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("small") );
+ style->setLogicalFontSizeStep( -1 );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("strong") );
+ style->setFontWeight( TQFont::Bold);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("b") );
+ style->setFontWeight( TQFont::Bold);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("h1") );
+ style->setFontWeight( TQFont::Bold);
+ style->setLogicalFontSize(6);
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style-> setMargin(TQStyleSheetItem::MarginTop, 18);
+ style-> setMargin(TQStyleSheetItem::MarginBottom, 12);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("h2") );
+ style->setFontWeight( TQFont::Bold);
+ style->setLogicalFontSize(5);
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style-> setMargin(TQStyleSheetItem::MarginTop, 16);
+ style-> setMargin(TQStyleSheetItem::MarginBottom, 12);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("h3") );
+ style->setFontWeight( TQFont::Bold);
+ style->setLogicalFontSize(4);
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style-> setMargin(TQStyleSheetItem::MarginTop, 14);
+ style-> setMargin(TQStyleSheetItem::MarginBottom, 12);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("h4") );
+ style->setFontWeight( TQFont::Bold);
+ style->setLogicalFontSize(3);
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style-> setMargin(TQStyleSheetItem::MarginVertical, 12);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("h5") );
+ style->setFontWeight( TQFont::Bold);
+ style->setLogicalFontSize(2);
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style-> setMargin(TQStyleSheetItem::MarginTop, 12);
+ style-> setMargin(TQStyleSheetItem::MarginBottom, 4);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("p") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style-> setMargin(TQStyleSheetItem::MarginVertical, 12);
+ style->setSelfNesting( FALSE );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("center") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->tqsetAlignment( Qt::AlignCenter );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("twocolumn") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->setNumberOfColumns( 2 );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("multicol") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ (void) new TQStyleSheetItem( this, TQString::tqfromLatin1("font") );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("ul") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->setListStyle( TQStyleSheetItem::ListDisc );
+ style-> setMargin(TQStyleSheetItem::MarginVertical, 12);
+ style->setMargin( TQStyleSheetItem::MarginLeft, 40 );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("ol") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->setListStyle( TQStyleSheetItem::ListDecimal );
+ style-> setMargin(TQStyleSheetItem::MarginVertical, 12);
+ style->setMargin( TQStyleSheetItem::MarginLeft, 40 );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("li") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayListItem);
+ style->setSelfNesting( FALSE );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("code") );
+ style->setFontFamily( TQString::tqfromLatin1("Courier New,courier") );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("tt") );
+ style->setFontFamily( TQString::tqfromLatin1("Courier New,courier") );
+
+ new TQStyleSheetItem(this, TQString::tqfromLatin1("img"));
+ new TQStyleSheetItem(this, TQString::tqfromLatin1("br"));
+ new TQStyleSheetItem(this, TQString::tqfromLatin1("hr"));
+
+ style = new TQStyleSheetItem(this, TQString::tqfromLatin1("sub"));
+ style->setVerticalAlignment( TQStyleSheetItem::VAlignSub );
+ style = new TQStyleSheetItem(this, TQString::tqfromLatin1("sup"));
+ style->setVerticalAlignment( TQStyleSheetItem::VAlignSuper );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("pre") );
+ style->setFontFamily( TQString::tqfromLatin1("Courier New,courier") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->setWhiteSpaceMode(TQStyleSheetItem::WhiteSpacePre);
+ style-> setMargin(TQStyleSheetItem::MarginVertical, 12);
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("blockquote") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->setMargin(TQStyleSheetItem::MarginHorizontal, 40 );
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("head") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayNone);
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("body") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("div") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock) ;
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("span") );
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("dl") );
+ style-> setMargin(TQStyleSheetItem::MarginVertical, 8);
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("dt") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->setContexts(TQString::tqfromLatin1("dl") );
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("dd") );
+ style->setDisplayMode(TQStyleSheetItem::DisplayBlock);
+ style->setMargin(TQStyleSheetItem::MarginLeft, 30);
+ style->setContexts(TQString::tqfromLatin1("dt dl") );
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("u") );
+ style->setFontUnderline( TRUE);
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("s") );
+ style->setFontStrikeOut( TRUE);
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("nobr") );
+ style->setWhiteSpaceMode( TQStyleSheetItem::WhiteSpaceNoWrap );
+
+ // compatibily with some minor 3.0.x TQt versions that had an
+ // undocumented <wsp> tag. ### Remove 3.1
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("wsp") );
+ style->setWhiteSpaceMode( TQStyleSheetItem::WhiteSpacePre );
+
+ // tables
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("table") );
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("tr") );
+ style->setContexts(TQString::tqfromLatin1("table"));
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("td") );
+ style->setContexts(TQString::tqfromLatin1("tr"));
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("th") );
+ style->setFontWeight( TQFont::Bold );
+ style->tqsetAlignment( TQt::AlignCenter );
+ style->setContexts(TQString::tqfromLatin1("tr"));
+
+ style = new TQStyleSheetItem( this, TQString::tqfromLatin1("html") );
+}
+
+
+
+static TQStyleSheet* defaultsheet = 0;
+static TQSingleCleanupHandler<TQStyleSheet> qt_cleanup_stylesheet;
+
+/*!
+ Returns the application-wide default style sheet. This style sheet
+ is used by rich text rendering classes such as TQSimpleRichText,
+ TQWhatsThis and TQMessageBox to define the rendering style and
+ available tags within rich text documents. It also serves as the
+ initial style sheet for the more complex render widgets, TQTextEdit
+ and TQTextBrowser.
+
+ \sa setDefaultSheet()
+*/
+TQStyleSheet* TQStyleSheet::defaultSheet()
+{
+ if (!defaultsheet) {
+ defaultsheet = new TQStyleSheet();
+ qt_cleanup_stylesheet.set( &defaultsheet );
+ }
+ return defaultsheet;
+}
+
+/*!
+ Sets the application-wide default style sheet to \a sheet,
+ deleting any style sheet previously set. The ownership is
+ transferred to TQStyleSheet.
+
+ \sa defaultSheet()
+*/
+void TQStyleSheet::setDefaultSheet( TQStyleSheet* sheet)
+{
+ if ( defaultsheet != sheet ) {
+ if ( defaultsheet )
+ qt_cleanup_stylesheet.reset();
+ delete defaultsheet;
+ }
+ defaultsheet = sheet;
+ if ( defaultsheet )
+ qt_cleanup_stylesheet.set( &defaultsheet );
+}
+
+/*!\internal
+ Inserts \a style. Any tags generated after this time will be
+ bound to this style. Note that \a style becomes owned by the
+ style sheet and will be deleted when the style sheet is destroyed.
+*/
+void TQStyleSheet::insert( TQStyleSheetItem* style )
+{
+ styles.insert(style->name(), style);
+}
+
+
+/*!
+ Returns the style called \a name or 0 if there is no such style.
+*/
+TQStyleSheetItem* TQStyleSheet::item( const TQString& name)
+{
+ if ( name.isNull() )
+ return 0;
+ return styles[name];
+}
+
+/*!
+ \overload
+
+ Returns the style called \a name or 0 if there is no such style
+ (const version)
+*/
+const TQStyleSheetItem* TQStyleSheet::item( const TQString& name) const
+{
+ if ( name.isNull() )
+ return 0;
+ return styles[name];
+}
+
+
+/*!
+ \preliminary
+
+ Generates an internal object for the tag called \a name, given the
+ attributes \a attr, and using additional information provided by
+ the mime source factory \a factory.
+
+ \a context is the optional context of the document, i.e. the path
+ to look for relative links. This becomes important if the text
+ tqcontains relative references, for example within image tags.
+ TQSimpleRichText always uses the default mime source factory (see
+ \l{TQMimeSourceFactory::defaultFactory()}) to resolve these
+ references. The context will then be used to calculate the
+ absolute path. See TQMimeSourceFactory::makeAbsolute() for details.
+
+ \a emptyTag and \a doc are for internal use only.
+
+ This function should not be used in application code.
+*/
+#ifndef TQT_NO_TEXTCUSTOMITEM
+TQTextCustomItem* TQStyleSheet::tag( const TQString& name,
+ const TQMap<TQString, TQString> &attr,
+ const TQString& context,
+ const TQMimeSourceFactory& factory,
+ bool /*emptyTag */, TQTextDocument *doc ) const
+{
+ const TQStyleSheetItem* style = item( name );
+ // first some known tags
+ if ( !style )
+ return 0;
+ if ( style->name() == "img" )
+ return new TQTextImage( doc, attr, context, (TQMimeSourceFactory&)factory );
+ if ( style->name() == "hr" )
+ return new TQTextHorizontalLine( doc, attr, context, (TQMimeSourceFactory&)factory );
+ return 0;
+}
+#endif
+
+
+/*! Auxiliary function. Converts the plain text string \a plain to a
+ rich text formatted paragraph while preserving most of its look.
+
+ \a mode defines the whitespace mode. Possible values are \c
+ TQStyleSheetItem::WhiteSpacePre (no wrapping, all whitespaces
+ preserved) and \c TQStyleSheetItem::WhiteSpaceNormal (wrapping,
+ simplified whitespaces).
+
+ \sa escape()
+*/
+TQString TQStyleSheet::convertFromPlainText( const TQString& plain, TQStyleSheetItem::WhiteSpaceMode mode )
+{
+ int col = 0;
+ TQString rich;
+ rich += "<p>";
+ for ( int i = 0; i < int(plain.length()); ++i ) {
+ if ( plain[i] == '\n' ){
+ int c = 1;
+ while ( i+1 < int(plain.length()) && plain[i+1] == '\n' ) {
+ i++;
+ c++;
+ }
+ if ( c == 1)
+ rich += "<br>\n";
+ else {
+ rich += "</p>\n";
+ while ( --c > 1 )
+ rich += "<br>\n";
+ rich += "<p>";
+ }
+ col = 0;
+ } else {
+ if ( mode == TQStyleSheetItem::WhiteSpacePre && plain[i] == '\t' ){
+ rich += 0x00a0U;
+ ++col;
+ while ( col % 8 ) {
+ rich += 0x00a0U;
+ ++col;
+ }
+ }
+ else if ( mode == TQStyleSheetItem::WhiteSpacePre && plain[i].isSpace() )
+ rich += 0x00a0U;
+ else if ( plain[i] == '<' )
+ rich +="&lt;";
+ else if ( plain[i] == '>' )
+ rich +="&gt;";
+ else if ( plain[i] == '&' )
+ rich +="&amp;";
+ else
+ rich += plain[i];
+ ++col;
+ }
+ }
+ if ( col != 0 )
+ rich += "</p>";
+ return rich;
+}
+
+/*!
+ Auxiliary function. Converts the plain text string \a plain to a
+ rich text formatted string with any HTML meta-characters escaped.
+
+ \sa convertFromPlainText()
+*/
+TQString TQStyleSheet::escape( const TQString& plain)
+{
+ TQString rich;
+ for ( int i = 0; i < int(plain.length()); ++i ) {
+ if ( plain[i] == '<' )
+ rich +="&lt;";
+ else if ( plain[i] == '>' )
+ rich +="&gt;";
+ else if ( plain[i] == '&' )
+ rich +="&amp;";
+ else
+ rich += plain[i];
+ }
+ return rich;
+}
+
+// Must doc this enum somewhere, and it is logically related to TQStyleSheet
+
+/*!
+ \enum TQt::TextFormat
+
+ This enum is used in widgets that can display both plain text and
+ rich text, e.g. TQLabel. It is used for deciding whether a text
+ string should be interpreted as one or the other. This is normally
+ done by passing one of the enum values to a setTextFormat()
+ function.
+
+ \value PlainText The text string is interpreted as a plain text
+ string.
+
+ \value RichText The text string is interpreted as a rich text
+ string using the current TQStyleSheet::defaultSheet().
+
+ \value AutoText The text string is interpreted as for \c RichText
+ if TQStyleSheet::mightBeRichText() returns TRUE, otherwise as
+ \c PlainText.
+
+ \value LogText A special, limited text format which is only used
+ by TQTextEdit in an optimized mode.
+*/
+
+/*!
+ Returns TRUE if the string \a text is likely to be rich text;
+ otherwise returns FALSE.
+
+ This function uses a fast and therefore simple heuristic. It
+ mainly checks whether there is something that looks like a tag
+ before the first line break. Although the result may be correct
+ for common cases, there is no guarantee.
+*/
+bool TQStyleSheet::mightBeRichText( const TQString& text)
+{
+ if ( text.isEmpty() )
+ return FALSE;
+ int start = 0;
+
+ while ( start < int(text.length()) && text[start].isSpace() )
+ ++start;
+ if ( TQT_TQSTRING(text.mid( start, 5 )).lower() == "<!doc" )
+ return TRUE;
+ int open = start;
+ while ( open < int(text.length()) && text[open] != '<'
+ && text[open] != '\n' ) {
+ if ( text[open] == '&' && text.mid(open+1,3) == "lt;" )
+ return TRUE; // support desperate attempt of user to see <...>
+ ++open;
+ }
+ if ( open < (int)text.length() && text[open] == '<' ) {
+ int close = text.tqfind('>', open);
+ if ( close > -1 ) {
+ TQString tag;
+ for (int i = open+1; i < close; ++i) {
+ if ( text[i].isDigit() || text[i].isLetter() )
+ tag += text[i];
+ else if ( !tag.isEmpty() && text[i].isSpace() )
+ break;
+ else if ( !text[i].isSpace() && (!tag.isEmpty() || text[i] != '!' ) )
+ return FALSE; // that's not a tag
+ }
+ return defaultSheet()->item( tag.lower() ) != 0;
+ }
+ }
+ return FALSE;
+}
+
+
+/*!
+ \fn void TQStyleSheet::error( const TQString& msg) const
+
+ This virtual function is called when an error occurs when
+ processing rich text. Reimplement it if you need to catch error
+ messages.
+
+ Errors might occur if some rich text strings contain tags that are
+ not understood by the stylesheet, if some tags are nested
+ incorrectly, or if tags are not closed properly.
+
+ \a msg is the error message.
+*/
+void TQStyleSheet::error( const TQString& ) const
+{
+}
+
+
+/*!
+ Scales the font \a font to the appropriate physical point size
+ corresponding to the logical font size \a logicalSize.
+
+ When calling this function, \a font has a point size corresponding
+ to the logical font size 3.
+
+ Logical font sizes range from 1 to 7, with 1 being the smallest.
+
+ \sa TQStyleSheetItem::logicalFontSize(), TQStyleSheetItem::logicalFontSizeStep(), TQFont::setPointSize()
+ */
+void TQStyleSheet::scaleFont( QFont& font, int logicalSize ) const
+{
+ if ( logicalSize < 1 )
+ logicalSize = 1;
+ if ( logicalSize > 7 )
+ logicalSize = 7;
+ int baseSize = font.pointSize();
+ bool pixel = FALSE;
+ if ( baseSize == -1 ) {
+ baseSize = font.pixelSize();
+ pixel = TRUE;
+ }
+ int s;
+ switch ( logicalSize ) {
+ case 1:
+ s = 7*baseSize/10;
+ break;
+ case 2:
+ s = (8 * baseSize) / 10;
+ break;
+ case 4:
+ s = (12 * baseSize) / 10;
+ break;
+ case 5:
+ s = (15 * baseSize) / 10;
+ break;
+ case 6:
+ s = 2 * baseSize;
+ break;
+ case 7:
+ s = (24 * baseSize) / 10;
+ break;
+ default:
+ s = baseSize;
+ }
+ if ( pixel )
+ font.setPixelSize( s );
+ else
+ font.setPointSize( s );
+}
+
+#endif // TQT_NO_RICHTEXT
diff --git a/tqtinterface/qt4/src/kernel/tqstylesheet.h b/tqtinterface/qt4/src/kernel/tqstylesheet.h
new file mode 100644
index 0000000..7f650be
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqstylesheet.h
@@ -0,0 +1,256 @@
+/****************************************************************************
+**
+** Definition of the TQStyleSheet class
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQSTYLESHEET_H
+#define TQSTYLESHEET_H
+
+#ifndef TQT_H
+#include "tqstring.h"
+#include "tqvaluelist.h"
+#include "tqptrvector.h"
+#include "tqdict.h"
+#include "tqobject.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_RICHTEXT
+
+class TQStyleSheet;
+class TQTextDocument;
+template<class Key, class T> class TQMap;
+class TQStyleSheetItemData;
+
+class TQ_EXPORT TQStyleSheetItem : public TQt
+{
+public:
+ TQStyleSheetItem( TQStyleSheet* tqparent, const TQString& name );
+ TQStyleSheetItem( const TQStyleSheetItem & );
+ ~TQStyleSheetItem();
+
+ TQStyleSheetItem& operator=( const TQStyleSheetItem& other );
+
+ TQString name() const;
+
+ TQStyleSheet* styleSheet();
+ const TQStyleSheet* styleSheet() const;
+
+ enum AdditionalStyleValues { Undefined = - 1};
+
+ enum DisplayMode {
+ DisplayBlock,
+ DisplayInline,
+ DisplayListItem,
+ DisplayNone
+#ifndef TQ_TQDOC
+ , DisplayModeUndefined = -1
+#endif
+ };
+
+ DisplayMode displayMode() const;
+ void setDisplayMode(DisplayMode m);
+
+ int tqalignment() const;
+ void tqsetAlignment( int f);
+
+ inline int alignment() const { return tqalignment(); }
+ inline void setAlignment( int f) { tqsetAlignment( f ); }
+
+ enum VerticalAlignment {
+ VAlignBaseline,
+ VAlignSub,
+ VAlignSuper
+ };
+
+ VerticalAlignment verticalAlignment() const;
+ void setVerticalAlignment( VerticalAlignment valign );
+
+ int fontWeight() const;
+ void setFontWeight(int w);
+
+ int logicalFontSize() const;
+ void setLogicalFontSize(int s);
+
+ int logicalFontSizeStep() const;
+ void setLogicalFontSizeStep( int s );
+
+ int fontSize() const;
+ void setFontSize(int s);
+
+ TQString fontFamily() const;
+ void setFontFamily( const TQString& );
+
+ int numberOfColumns() const;
+ void setNumberOfColumns(int ncols);
+
+ TQColor color() const;
+ void setColor( const TQColor &);
+
+ bool fontItalic() const;
+ void setFontItalic( bool );
+ bool definesFontItalic() const;
+
+ bool fontUnderline() const;
+ void setFontUnderline( bool );
+ bool definesFontUnderline() const;
+
+ bool fontStrikeOut() const;
+ void setFontStrikeOut( bool );
+ bool definesFontStrikeOut() const;
+
+ bool isAnchor() const;
+ void setAnchor(bool anc);
+
+ enum WhiteSpaceMode {
+ WhiteSpaceNormal,
+ WhiteSpacePre,
+ WhiteSpaceNoWrap
+#ifndef TQ_TQDOC
+ , WhiteSpaceModeUndefined = -1
+#endif
+ };
+ WhiteSpaceMode whiteSpaceMode() const;
+ void setWhiteSpaceMode(WhiteSpaceMode m);
+
+ enum Margin {
+ MarginLeft,
+ MarginRight,
+ MarginTop,
+ MarginBottom,
+ MarginFirstLine,
+ MarginAll,
+ MarginVertical,
+ MarginHorizontal
+#ifndef TQ_TQDOC
+ , MarginUndefined = -1
+#endif
+ };
+
+ int margin( Margin m) const;
+ void setMargin( Margin, int);
+
+ enum ListStyle {
+ ListDisc,
+ ListCircle,
+ ListSquare,
+ ListDecimal,
+ ListLowerAlpha,
+ ListUpperAlpha
+#ifndef TQ_TQDOC
+ , ListStyleUndefined = -1
+#endif
+ };
+
+ ListStyle listStyle() const;
+ void setListStyle( ListStyle );
+
+ TQString contexts() const;
+ void setContexts( const TQString& );
+ bool allowedInContext( const TQStyleSheetItem* ) const;
+
+ bool selfNesting() const;
+ void setSelfNesting( bool );
+
+ void setLineSpacing( int ls );
+ int lineSpacing() const;
+
+private:
+ void init();
+ TQStyleSheetItemData* d;
+};
+
+
+#if defined(TQ_TEMPLATEDLL)
+// TQMOC_SKIP_BEGIN
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQDict<TQStyleSheetItem>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQValueList< TQPtrVector<TQStyleSheetItem> >;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQPtrVector<TQStyleSheetItem>;
+TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQValueList<TQStyleSheetItem::ListStyle>;
+// TQMOC_SKIP_END
+#endif
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+class TQTextCustomItem;
+#endif
+
+class TQ_EXPORT TQStyleSheet : public TQObject
+{
+ TQ_OBJECT
+public:
+ TQStyleSheet( TQObject *tqparent=0, const char *name=0 );
+ virtual ~TQStyleSheet();
+
+ static TQStyleSheet* defaultSheet();
+ static void setDefaultSheet( TQStyleSheet* );
+
+
+ TQStyleSheetItem* item( const TQString& name);
+ const TQStyleSheetItem* item( const TQString& name) const;
+
+ void insert( TQStyleSheetItem* item);
+
+#ifndef TQT_NO_TEXTCUSTOMITEM
+ virtual TQTextCustomItem* tag( const TQString& name,
+ const TQMap<TQString, TQString> &attr,
+ const TQString& context,
+ const TQMimeSourceFactory& factory,
+ bool emptyTag, TQTextDocument *doc ) const;
+#endif
+ static TQString escape( const TQString& );
+ static TQString convertFromPlainText( const TQString&,
+ TQStyleSheetItem::WhiteSpaceMode mode = TQStyleSheetItem::WhiteSpacePre );
+ static bool mightBeRichText( const TQString& );
+
+ virtual void scaleFont( QFont& font, int logicalSize ) const;
+
+ virtual void error( const TQString& ) const;
+
+private:
+ void init();
+ TQDict<TQStyleSheetItem> styles;
+ TQStyleSheetItem* nullstyle;
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQStyleSheet( const TQStyleSheet & );
+ TQStyleSheet &operator=( const TQStyleSheet & );
+#endif
+};
+
+#endif // TQT_NO_RICHTEXT
+
+#endif // TQSTYLESHEET_H
diff --git a/tqtinterface/qt4/src/kernel/tqt.h b/tqtinterface/qt4/src/kernel/tqt.h
new file mode 100644
index 0000000..3e1fefa
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqt.h
@@ -0,0 +1,379 @@
+/****************************************************************************
+**
+** TQt GUI Toolkit
+**
+** This header file efficiently includes all TQt GUI Toolkit functionality.
+**
+** Generated : Mon Oct 13 13:07:29 CEST 2003
+
+**
+** Copyright (C) 1995-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the TQt GUI Toolkit.
+**
+*****************************************************************************/
+
+#define USE_QT4
+
+#ifdef __cplusplus
+
+#ifndef TQT_H
+#define TQT_H
+#undef QT_NO_TRANSLATION
+#undef TQT_NO_TRANSLATION
+#include "tqglobal.h"
+#include "tqfeatures.h"
+#include "tqshared.h"
+#include "tqptrcollection.h"
+#include "tqglist.h"
+#include "tqobjectdefs.h"
+#include "tqnamespace.h"
+#include "tqgarray.h"
+#include "tqmemarray.h"
+#include "tqcstring.h"
+#include "tqstring.h"
+#include "tqptrlist.h"
+#include "tqiodevice.h"
+#include "tqkeysequence.h"
+#include "tqwindowdefs.h"
+#include "tqgdict.h"
+#include "tqfont.h"
+#include "tqdatastream.h"
+#include "tqpair.h"
+#include "tqpoint.h"
+#include <stdio.h>
+#include "tqtextstream.h"
+#include "tqfontinfo.h"
+#include "tqsizepolicy.h"
+#include "tqtl.h"
+#include "tqsize.h"
+#include "tqrect.h"
+#include "tqbitarray.h"
+#include "tqregion.h"
+#include "tqsql.h"
+#include "tqstrlist.h"
+#include "tqvaluelist.h"
+#include "tqmap.h"
+#include "tqdatetime.h"
+#include "tqmime.h"
+#include "tqasciidict.h"
+#include "tqpaintdevice.h"
+#include "tqfontmetrics.h"
+#include "tqdict.h"
+#include "tqevent.h"
+#include "tqhostaddress.h"
+#include "tqstringlist.h"
+#include "tqcolor.h"
+#include <tqdom.h>
+#include "tqobject.h"
+#include <tqdrawutil.h>
+#include "tqbrush.h"
+#include "tqpalette.h"
+#include "tqwidget.h"
+#include "tqjpunicode.h"
+#include "tqtextcodec.h"
+#include "tqstyle.h"
+#include "tqframe.h"
+#include "tqfile.h"
+#include "tqfileinfo.h"
+#include "tqurlinfo.h"
+#include "tqwidgetlist.h"
+#include <tqcombobox.h>
+#include "tqgroupbox.h"
+#include "tqdialog.h"
+#include <tqdataview.h>
+#include "tqdockwindow.h"
+#include "tqcommonstyle.h"
+#include "tqnetworkprotocol.h"
+#include <tqeuckrcodec.h>
+#include <tqgb18030codec.h>
+#include "tqgcache.h"
+#include "tqpixmap.h"
+#include <tqgif.h>
+#include <tqglcolormap.h>
+#include <tqcache.h>
+#include <tqdropsite.h>
+#include "tqgplugin.h"
+#include <tqgrid.h>
+#include "tqrangecontrol.h"
+#include "tqbuttongroup.h"
+#include <tqdatetimeedit.h>
+#include "tqgvector.h"
+#include "tqhbox.h"
+#include <tqhbuttongroup.h>
+#include "tqiconset.h"
+#include <tqhgroupbox.h>
+#include "tqsocketnotifier.h"
+#include <tqeventloop.h>
+#include <tqhttp.h>
+#include <tqaction.h>
+#include "tqbuffer.h"
+#include "tqimage.h"
+#include <tqimageformatplugin.h>
+#include "tqlineedit.h"
+#include <tqintcache.h>
+#include "tqintdict.h"
+#include "tqmotifstyle.h"
+#include "tqpicture.h"
+#include <tqjiscodec.h>
+#include <tqeucjpcodec.h>
+#include <tqkeycode.h>
+#include <tqaccel.h>
+#include "tqlabel.h"
+#include "tqlayout.h"
+#include <tqlcdnumber.h>
+#include <tqlibrary.h>
+#include <tqinputdialog.h>
+#include "tqscrollbar.h"
+#include "tqscrollview.h"
+#include "tqdir.h"
+#include "tqwindowsstyle.h"
+#include "tqconnection.h"
+#include "tqbitmap.h"
+#include "tqvariant.h"
+#include "tqsignal.h"
+#include <tqmessagebox.h>
+#include "tqmetaobject.h"
+#include "tqheader.h"
+#include <tqmotifplusstyle.h>
+#include <tqcdestyle.h>
+#include <tqmovie.h>
+#include "tqptrvector.h"
+#include "tqmutex.h"
+#include "tqbutton.h"
+#include <tqnetwork.h>
+#include <tqftp.h>
+#include "tqguardedptr.h"
+#include <tqobjectcleanuphandler.h>
+#include "tqsqlfield.h"
+#include <tqobjectdict.h>
+#include <tqobjectlist.h>
+#include <tqcolordialog.h>
+#include <tqpaintdevicemetrics.h>
+#include "tqpointarray.h"
+#include "tqmenudata.h"
+#include <tqlistview.h>
+#include "tqpen.h"
+#include "tqdragobject.h"
+#include <tqiconview.h>
+#include <tqpixmapcache.h>
+#include <tqplatinumstyle.h>
+#include <tqpngio.h>
+#include <tqcursor.h>
+#include <tqerrormessage.h>
+#include <tqpolygonscanner.h>
+#include "tqpopupmenu.h"
+#include <tqprintdialog.h>
+#include <tqprinter.h>
+#include <tqprocess.h>
+#include "tqprogressbar.h"
+#include "tqsemimodal.h"
+#include <tqasciicache.h>
+#include "tqptrdict.h"
+#include <tqcleanuphandler.h>
+#include <tqptrqueue.h>
+#include <tqptrstack.h>
+#include "tqstylesheet.h"
+#include <tqpushbutton.h>
+#include <tqradiobutton.h>
+#include <tqdial.h>
+#include <tqdockarea.h>
+#include "tqregexp.h"
+#include <tqclipboard.h>
+#include <tqrtlcodec.h>
+#include <tqlistbox.h>
+#include <tqgridview.h>
+#include "tqsemaphore.h"
+#include <tqprogressdialog.h>
+#include "tqsocketdevice.h"
+#include <tqsessionmanager.h>
+#include <tqsettings.h>
+#include <tqsgistyle.h>
+#include <tqfontdialog.h>
+#include "tqtimer.h"
+#include <tqsignalmapper.h>
+#include <tqsignalslotimp.h>
+#include <tqsimplerichtext.h>
+#include "tqwmatrix.h"
+#include <tqsizegrip.h>
+#include <tqabstractlayout.h>
+#include <tqsjiscodec.h>
+#include <tqslider.h>
+#include <tqsocket.h>
+#include <tqserversocket.h>
+#include <tqdns.h>
+#include <tqsortedlist.h>
+#include <tqsound.h>
+#include <tqspinbox.h>
+#include <tqsplashscreen.h>
+#include <tqsplitter.h>
+#include "tqsqlerror.h"
+#include "tqeditorfactory.h"
+#include "tqsqlquery.h"
+#include "tqsqlrecord.h"
+#include <tqsqldriverplugin.h>
+#include "tqsqlindex.h"
+#include "tqsqlcursor.h"
+#include <tqsqldriver.h>
+#include <tqsqlform.h>
+#include "tqtable.h"
+#include <tqsqlpropertymap.h>
+#include <tqsqldatabase.h>
+#include <tqdatabrowser.h>
+#include <tqsqlresult.h>
+#include <tqsqlselectcursor.h>
+#include <tqstatusbar.h>
+#include <tqmenubar.h>
+#include <tqcanvas.h>
+#include "tqtranslator.h"
+#include <tqstrvec.h>
+#include <tqinterlacestyle.h>
+#include <tqstylefactory.h>
+#include <tqstyleplugin.h>
+#include "tqtextedit.h"
+#include <tqsyntaxhighlighter.h>
+#include <tqtabbar.h>
+#include <tqtabdialog.h>
+#include "tqsqleditorfactory.h"
+#include <tqtabwidget.h>
+#include <tqtextbrowser.h>
+#include <tqbig5codec.h>
+#include <tqtextcodecfactory.h>
+#include <tqtextcodecplugin.h>
+#include <tqmultilineedit.h>
+#include "tqtoolbar.h"
+#include <tqtextview.h>
+#include "tqwaitcondition.h"
+#include <tqasyncio.h>
+#include <tqfontdatabase.h>
+#include <tqmainwindow.h>
+#include <tqtoolbox.h>
+#include <tqtoolbutton.h>
+#include <tqtooltip.h>
+#include "tqdesktopwidget.h"
+#include <tqtsciicodec.h>
+#include "tqurl.h"
+#include "tqurloperator.h"
+#include <tqfiledialog.h>
+#include <tqutfcodec.h>
+#include <tquuid.h>
+#include <tqvalidator.h>
+#include <tqasyncimageio.h>
+#include <tqvaluestack.h>
+#include <tqvaluevector.h>
+#include <tqdatatable.h>
+#include <tqvbox.h>
+#include <tqvbuttongroup.h>
+#include <tqvfbhdr.h>
+#include <tqvgroupbox.h>
+#include <tqthread.h>
+#include <tqwhatsthis.h>
+#include <tqapplication.h>
+#include <tqwidgetintdict.h>
+#include <tqfocusdata.h>
+#include <tqwidgetplugin.h>
+#include <tqwidgetstack.h>
+#include <tqcheckbox.h>
+#include <tqcompactstyle.h>
+#include <tqwizard.h>
+#include <tqpainter.h>
+#include <tqworkspace.h>
+#include <tqlocalfs.h>
+#include <tqxml.h>
+
+#if defined( TQT_TQMOC_CPP ) || defined( TQT_H_CPP ) || defined( TQ_OS_MACX )
+#include <private/tqcom_p.h>
+#include <private/tqucom_p.h>
+#include "private/tqgfxdriverinterface_p.h"
+#include "private/tqcom_p.h"
+#include "private/tqimageformatinterface_p.h"
+#include "private/tqisciicodec_p.h"
+#include "private/tqkbddriverinterface_p.h"
+#include "private/tqlayoutengine_p.h"
+#include "private/tqcomlibrary_p.h"
+#include "private/tqmousedriverinterface_p.h"
+#include "private/tqeffects_p.h"
+#include "private/tqgpluginmanager_p.h"
+#include "private/tqinternal_p.h"
+#include "private/tqsqldriverinterface_p.h"
+#include "private/tqsqlmanager_p.h"
+#include "private/tqlock_p.h"
+#include "private/tqcomponentfactory_p.h"
+#include "private/tqstyleinterface_p.h"
+#include "private/tqrichtext_p.h"
+#include "private/tqsvgdevice_p.h"
+#include "private/tqfontcodecs_p.h"
+#include "private/tqtextcodecinterface_p.h"
+#include "private/tqpsprinter_p.h"
+#include "private/tqtitlebar_p.h"
+#include "private/tqucom_p.h"
+#include "private/tqucomextra_p.h"
+#include "private/tqpluginmanager_p.h"
+#include "private/tqdir_p.h"
+#include "private/tqsettings_p.h"
+#include "private/tqsqlextension_p.h"
+#include "private/tqdialogbuttons_p.h"
+#include "private/tqwidgetinterface_p.h"
+#include "private/tqwidgetresizehandler_p.h"
+#include "private/tqlibrary_p.h"
+#endif // Private headers
+
+
+#ifdef TQ_WS_MAC
+#include <tqaquastyle.h>
+#include <tqmacstyle_mac.h>
+#endif // TQ_WS_MAC
+
+#ifdef TQ_WS_WIN
+#include <tqwindowsxpstyle.h>
+#endif
+
+#ifdef TQ_WS_TQWS
+#include <private/tqtextengine_p.h>
+#include "tqfontmanager_qws.h"
+#include <tqfontfactorybdf_qws.h>
+#include <tqgfxvoodoodefs_qws.h>
+#include <tqgfxmatroxdefs_qws.h>
+#include <tqgfxdriverplugin_qws.h>
+#include <tqkbddriverfactory_qws.h>
+#include <tqkbddriverplugin_qws.h>
+#include <tqmousedriverfactory_qws.h>
+#include <tqmousedriverplugin_qws.h>
+#include <tqcopchannel_qws.h>
+#include <tqdirectpainter_qws.h>
+#include "tqmemorymanager_qws.h"
+#include <tqmouse_qws.h>
+#include <tqfontfactoryttf_qws.h>
+#ifndef TQ_OS_MAC
+# include <tqsoundqss_qws.h>
+#endif
+#include "tqgfx_qws.h"
+#include <tqgfxdriverfactory_qws.h>
+#include "tqwsdisplay_qws.h"
+#include "tqwssocket_qws.h"
+#include "tqwsdecoration_qws.h"
+#include "tqwsutils_qws.h"
+#include <tqwscursor_qws.h>
+#include "tqwsmanager_qws.h"
+#include "tqwsdefaultdecoration_qws.h"
+#include <tqgfxraster_qws.h>
+#include "tqwscommand_qws.h"
+#include <tqwshydrodecoration_qws.h>
+#include <tqwskde2decoration_qws.h>
+#include <tqwskdedecoration_qws.h>
+#include <tqwsbeosdecoration_qws.h>
+#include "tqwsproperty_qws.h"
+#include <tqwsregionmanager_qws.h>
+#include "tqwsevent_qws.h"
+#include <tqwindowsystem_qws.h>
+#include <tqwswindowsdecoration_qws.h>
+#endif // TQ_WS_TQWS
+
+
+#ifdef TQ_WS_WCE
+#include <tqpocketpcstyle_wce.h>
+#endif // TQ_WS_WCE
+
+#endif // TQT_H
+
+#endif // __cplusplus
diff --git a/tqtinterface/qt4/src/kernel/tqt_pch.h b/tqtinterface/qt4/src/kernel/tqt_pch.h
new file mode 100644
index 0000000..6693c8d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqt_pch.h
@@ -0,0 +1,57 @@
+/*
+ * This is a precompiled header file for use in Xcode / Mac GCC /
+ * GCC >= 3.4 / VC to greatly speed the building of TQt. It may also be
+ * of use to people developing their own project, but it is probably
+ * better to define your own header. Use of this header is currently
+ * UNSUPPORTED.
+ */
+
+#if (defined(_WIN32) || defined(__NT__))
+# define TQT_UNDEF_MACROS_IN_PCH
+# define _WINSCARD_H_
+# define _POSIX_ /* Make sure PATH_MAX et al. are defined */
+# include <limits.h>
+# undef _POSIX_ /* Don't polute */
+#endif
+
+#if defined __cplusplus
+# if defined(__GNUC__)
+# ifndef TQT_NO_STL
+# include <ios>
+# undef _GLIBCPP_FULLY_COMPLIANT_HEADERS // Makes qlocale.cpp compile
+# endif
+# endif
+#include <tqmap.h> // I must be first!
+#include <private/tqucomextra_p.h> // All tqmoc genereated code has this include
+#include <tqapplication.h>
+#include <tqbitmap.h>
+#include <tqcursor.h>
+#include <tqdatetime.h>
+#include <tqglobal.h>
+#include <tqimage.h>
+#include <tqmetaobject.h> // All tqmoc genereated code has this include
+#include <tqobject.h>
+#include <tqpainter.h>
+#include <tqpixmap.h>
+#include <tqplatformdefs.h>
+#include <tqptrlist.h>
+#include <tqstring.h>
+#include <tqstringlist.h>
+#include <tqstyle.h>
+#include <tqtimer.h>
+#include <tqwidget.h>
+
+#include <limits.h>
+#include <stdlib.h>
+#if defined(__GNUC__)
+# ifndef TQT_NO_STL
+# define _GLIBCPP_FULLY_COMPLIANT_HEADERS
+# endif
+#endif
+#endif
+
+#if defined(TQT_UNDEF_MACROS_IN_PCH)
+# undef max /* These are defined in windef.h, but */
+# undef min /* we don't want them when building TQt */
+# undef _WINSCARD_H_
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqt_x11_p.h b/tqtinterface/qt4/src/kernel/tqt_x11_p.h
new file mode 100644
index 0000000..e08531d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqt_x11_p.h
@@ -0,0 +1,275 @@
+/****************************************************************************
+**
+** Includes X11 system header files.
+**
+** Created : 981123
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQT_X11_H
+#define TQT_X11_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of q*_x11.cpp. This header file may change from version to version
+// without notice, or even be removed.
+//
+//
+
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#endif // TQT_H
+
+// the following is necessary to work around breakage in many versions
+// of XFree86's Xlib.h still in use
+// ### which versions?
+#if defined(_XLIB_H_) // crude hack, but...
+#error "cannot include <X11/Xlib.h> before this file"
+#endif
+#define XRegisterIMInstantiateCallback qt_XRegisterIMInstantiateCallback
+#define XUnregisterIMInstantiateCallback qt_XUnregisterIMInstantiateCallback
+#define XSetIMValues qt_XSetIMValues
+#include <X11/Xlib.h>
+#undef XRegisterIMInstantiateCallback
+#undef XUnregisterIMInstantiateCallback
+#undef XSetIMValues
+
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+
+
+//#define TQT_NO_SHAPE
+#ifdef TQT_NO_SHAPE
+#define XShapeCombineRegion(a,b,c,d,e,f,g)
+#define XShapeCombineMask(a,b,c,d,e,f,g)
+#else
+#include <X11/extensions/shape.h>
+#endif // TQT_NO_SHAPE
+
+
+// the wacom tablet (currently just the IRIX version)
+#if defined (TQT_TABLET_SUPPORT)
+# include <X11/extensions/XInput.h>
+#if defined (TQ_OS_IRIX)
+# include <wacom.h> // wacom driver defines for IRIX (quite handy)
+#endif
+#endif // TQT_TABLET_SUPPORT
+
+
+// #define TQT_NO_XINERAMA
+#ifndef TQT_NO_XINERAMA
+# if 0 // ### Xsun, but how to detect it?
+// Xinerama is only supported in Solaris 7 with patches 107648/108376 and
+// Solaris 8 or above which introduce the X11R6.4 Xserver.
+// To switch the Xinerama functionality on, you need to add the "+xinerama"
+// argument to the Xsun start line.
+// At least Solaris 7 and 8 are missing Xinerama system headers and function
+// declarations (bug 4284701).
+// The Xinerama API is not documented. In theory it could change but it
+// probably won't because Sun are using it in at least dtlogin (bug 4221829).
+extern "C" Bool XPanoramiXQueryExtension(
+ Display*,
+ int*,
+ int*
+);
+extern "C" tqStatus XPanoramiXQueryVersion(
+ Display*,
+ int*,
+ int*
+);
+extern "C" tqStatus XPanoramiXGetState(
+ Display*,
+ Drawable,
+ XPanoramiXInfo*
+);
+extern "C" tqStatus XPanoramiXGetScreenCount(
+ Display *,
+ Drawable,
+ XPanoramiXInfo*
+);
+extern "C" tqStatus XPanoramiXGetScreenSize(
+ Display*,
+ Drawable,
+ int,
+ XPanoramiXInfo*
+);
+# else // XFree86
+// XFree86 does not C++ify Xinerama (at least up to XFree86 4.0.3).
+extern "C" {
+# include <X11/extensions/Xinerama.h>
+}
+# endif
+#endif // TQT_NO_XINERAMA
+
+// #define TQT_NO_XRANDR
+#ifndef TQT_NO_XRANDR
+# include <X11/extensions/Xrandr.h>
+#endif // TQT_NO_XRANDR
+
+// #define TQT_NO_XRENDER
+#ifndef TQT_NO_XRENDER
+# include <X11/extensions/Xrender.h>
+// #define TQT_NO_XFTFREETYPE
+# ifndef TQT_NO_XFTFREETYPE
+// This hacks around the freetype poeple putting an #error into freetype.h in 2.1.7, making
+// it impossible to use an updated freetype with older Xft header files.
+# include <ft2build.h>
+# ifdef TQT_USE_XFT2_HEADER
+# include <X11/Xft/Xft2.h>
+# else
+# include <X11/Xft/Xft.h>
+# endif // TQT_USE_XFT2_HEADER
+# if defined(XFT_VERSION) && XFT_VERSION >= 20000
+# define TQT_XFT2
+# else
+# include <X11/Xft/XftFreetype.h>
+// Xft1 doesn't have these functions, so we implement them in qtaddons_x11.cpp
+extern "C" {
+ TQt::HANDLE XftDrawPicture( XftDraw * );
+ void XftDrawSetClipRectangles(XftDraw *, int, int, XRectangle *, int);
+ void XftDrawSetSubwindowMode(XftDraw *, int);
+}
+# endif // XFT_VERSION
+# endif // TQT_NO_XFTFREETYPE
+#else
+// make sure TQT_NO_XFTFREETYPE is defined if TQT_NO_XRENDER is defined
+# ifndef TQT_NO_XFTFREETYPE
+# define TQT_NO_XFTFREETYPE
+# endif
+#endif // TQT_NO_XRENDER
+
+
+#ifndef TQT_NO_XKB
+# include <X11/XKBlib.h>
+#endif // TQT_NO_XKB
+
+
+#if !defined(XlibSpecificationRelease)
+# define X11R4
+typedef char *XPointer;
+#else
+# undef X11R4
+#endif
+
+// #define TQT_NO_XIM
+#if defined(X11R4)
+// X11R4 does not have XIM
+#define TQT_NO_XIM
+#elif defined(TQ_OS_OSF) && (XlibSpecificationRelease < 6)
+// broken in Xlib up to OSF/1 3.2
+#define TQT_NO_XIM
+#elif defined(TQ_OS_AIX)
+// broken in Xlib up to what version of AIX?
+#define TQT_NO_XIM
+#elif defined(TQT_NO_DEBUG) && defined(TQ_OS_IRIX)
+// XmbLookupString broken on IRIX
+// XCreateIC broken when compiling -64 on IRIX 6.5.2
+#define TQT_NO_XIM
+#elif defined(TQ_OS_HPUX) && defined(__LP64__)
+// XCreateIC broken when compiling 64-bit ELF on HP-UX 11.0
+#define TQT_NO_XIM
+#elif defined(TQ_OS_SCO)
+// ### suggested by user...
+// ### #define TQT_NO_XIM
+#endif // TQT_NO_XIM
+
+
+/*
+ * Solaris patch 108652-47 and higher fixes crases in
+ * XRegisterIMInstantiateCallback, but the function doesn't seem to
+ * work.
+ *
+ * Instead, we disabled R6 input, and open the input method
+ * immediately at application start.
+ */
+#if !defined(TQT_NO_XIM) && (XlibSpecificationRelease >= 6) && \
+ !defined(TQ_OS_SOLARIS)
+#define USE_X11R6_XIM
+
+//######### XFree86 has wrong declarations for XRegisterIMInstantiateCallback
+//######### and XUnregisterIMInstantiateCallback in at least version 3.3.2.
+//######### Many old X11R6 header files lack XSetIMValues.
+//######### Therefore, we have to declare these functions ourselves.
+
+extern "C" Bool XRegisterIMInstantiateCallback(
+ Display*,
+ struct _XrmHashBucketRec*,
+ char*,
+ char*,
+ XIMProc, //XFree86 has XIDProc, which has to be wrong
+ XPointer
+);
+
+extern "C" Bool XUnregisterIMInstantiateCallback(
+ Display*,
+ struct _XrmHashBucketRec*,
+ char*,
+ char*,
+ XIMProc, //XFree86 has XIDProc, which has to be wrong
+ XPointer
+);
+
+extern "C" char *XSetIMValues( XIM /* im */, ... );
+
+#endif
+
+#ifndef TQT_NO_XIM
+// some platforms (eg. Solaris 2.51) don't have these defines in Xlib.h
+#ifndef XNResetState
+#define XNResetState "resetState"
+#endif
+#ifndef XIMPreserveState
+#define XIMPreserveState (1L<<1)
+#endif
+#endif
+
+
+#ifndef X11R4
+# include <X11/Xlocale.h>
+#endif // X11R4
+
+
+#ifdef TQT_MITSHM
+# include <X11/extensions/XShm.h>
+#endif // TQT_MITSHM
+
+
+#endif // TQT_X11_H
diff --git a/tqtinterface/qt4/src/kernel/tqtaddons_x11.cpp b/tqtinterface/qt4/src/kernel/tqtaddons_x11.cpp
new file mode 100644
index 0000000..4ad2199
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtaddons_x11.cpp
@@ -0,0 +1,144 @@
+/*
+ * $XFree86: xc/lib/Xft/xftname.c,v 1.10 2001/03/30 18:50:18 keithp Exp $
+ *
+ * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Keith Packard makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSETQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "tqt_x11_p.h"
+
+#if !defined(TQT_NO_XFTFREETYPE) && !defined(TQT_XFT2)
+
+#include <X11/Xft/Xft.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+extern bool qt_use_xrender; // defined in qapplication_x11.cpp
+
+extern "C" {
+
+#define XFT_DRAW_N_SRC 2
+
+struct _XftDraw {
+ Display *dpy;
+ Drawable drawable;
+ Visual *visual;
+ Colormap colormap;
+ Region clip;
+ Bool core_set;
+ Bool render_set;
+ Bool render_able;
+ struct {
+ Picture pict;
+ struct {
+ Picture pict;
+ XRenderColor color;
+ } src[XFT_DRAW_N_SRC];
+ } render;
+ struct {
+ GC draw_gc;
+ unsigned long fg;
+ Font font;
+ } core;
+};
+
+Picture XftDrawPicture( XftDraw *draw )
+{
+ if ( ! draw ) return 0;
+ if ( ! draw->render_set ) {
+ // force the RENDER Picture to be created...
+ XftColor color;
+ color.color.red = color.color.green = color.color.blue = color.color.alpha =
+ color.pixel = 0;
+ XftDrawRect( draw, &color, -100, -100, 1, 1 );
+ }
+ return draw->render.pict;
+}
+
+XftDraw *XftDrawCreateAlpha( Display *display,
+ Pixmap pixmap,
+ int depth )
+{
+ // taken from Xft 1 sources, see copyright above
+ XftDraw *draw;
+
+ draw = (XftDraw *) malloc (sizeof (XftDraw));
+ if (!draw)
+ return 0;
+ draw->dpy = display;
+ draw->drawable = pixmap;
+ draw->visual = 0;
+ draw->colormap = 0;
+ draw->core_set = False;
+ draw->clip = 0;
+
+ // TQt addition - go ahead and create the render picture now
+ draw->render_set = True;
+ draw->render_able = False;
+
+ if ( qt_use_xrender ) {
+ draw->render_able = True;
+
+ XRenderPictFormat *format = 0;
+ XRenderPictFormat req;
+ unsigned long tqmask = PictFormatType | PictFormatDepth | PictFormatAlphaMask;
+ req.type = PictTypeDirect;
+ req.depth = depth;
+ req.direct.alphaMask = 0xff;
+ format = XRenderFindFormat(draw->dpy, tqmask, &req, 0);
+ if (format) {
+ draw->render.pict =
+ XRenderCreatePicture(draw->dpy, draw->drawable, format, 0, 0);
+ }
+
+ // to keep Xft from trying to free zero pixmaps/pictures, we need to create
+ // 2 more pictures (that are identical to draw->render.pict) :/
+ draw->render.src[0].pict =
+ XRenderCreatePicture( draw->dpy, draw->drawable, format, 0, 0 );
+ draw->render.src[1].pict =
+ XRenderCreatePicture( draw->dpy, draw->drawable, format, 0, 0 );
+ }
+
+ return draw;
+}
+
+void XftDrawSetClipRectangles(XftDraw *draw, int xoff, int yoff, XRectangle *rects, int count)
+{
+ if (!draw) return;
+
+ Picture pict = XftDrawPicture(draw);
+ XRenderSetPictureClipRectangles(draw->dpy, pict, xoff, yoff, rects, count);
+}
+
+void XftDrawSetSubwindowMode(XftDraw *draw, int mode)
+{
+ if (!draw) return;
+
+ Picture pict = XftDrawPicture(draw);
+ XRenderPictureAttributes pattr;
+ pattr.subwindow_mode = mode;
+ XRenderChangePicture(draw->dpy, pict, CPSubwindowMode, &pattr);
+}
+
+} // extern "C"
+
+#endif // !TQT_NO_XFTFREETYPE && !TQT_XFT2
diff --git a/tqtinterface/qt4/src/kernel/tqtextengine.cpp b/tqtinterface/qt4/src/kernel/tqtextengine.cpp
new file mode 100644
index 0000000..dd5d9d3
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtextengine.cpp
@@ -0,0 +1,1186 @@
+/****************************************************************************
+**
+** Text engine classes
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqtextengine_p.h"
+
+#include "tqscriptengine_p.h"
+#include <tqfont.h>
+#include "tqfontdata_p.h"
+#include "tqfontengine_p.h"
+#include <tqstring.h>
+#include <private/tqunicodetables_p.h>
+#include <stdlib.h>
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+// -----------------------------------------------------------------------------------------------------
+//
+// The BiDi algorithm
+//
+// -----------------------------------------------------------------------------------------------------
+
+
+#define BIDI_DEBUG 0//2
+#if (BIDI_DEBUG >= 1)
+#include <iostream>
+using namespace std;
+
+static const char *directions[] = {
+ "DirL", "DirR", "DirEN", "DirES", "DirET", "DirAN", "DirCS", "DirB", "DirS", "DirWS", "DirON",
+ "DirLRE", "DirLRO", "DirAL", "DirRLE", "DirRLO", "DirPDF", "DirNSM", "DirBN"
+};
+
+#endif
+
+struct BiditqStatus {
+ BiditqStatus() {
+ eor = TQChar::DirON;
+ lastStrong = TQChar::DirON;
+ last = TQChar:: DirON;
+ dir = TQChar::DirON;
+ }
+ TQChar::Direction eor;
+ TQChar::Direction lastStrong;
+ TQChar::Direction last;
+ TQChar::Direction dir;
+};
+
+struct BidiControl {
+ struct Context {
+ unsigned char level : 6;
+ unsigned char override : 1;
+ unsigned char unused : 1;
+ };
+
+ inline BidiControl( bool rtl )
+ : cCtx( 0 ), singleLine( FALSE ) {
+ ctx[0].level = (rtl ? 1 : 0);
+ ctx[0].override = FALSE;
+ }
+
+ inline void embed( int level, bool override = FALSE ) {
+ if ( ctx[cCtx].level < 61 && cCtx < 61 ) {
+ (void) ++cCtx;
+ ctx[cCtx].level = level;
+ ctx[cCtx].override = override;
+ }
+ }
+ inline void pdf() {
+ if ( cCtx ) (void) --cCtx;
+ }
+
+ inline uchar level() const {
+ return ctx[cCtx].level;
+ }
+ inline bool override() const {
+ return ctx[cCtx].override;
+ }
+ inline TQChar::Direction basicDirection() {
+ return (ctx[0].level ? TQChar::DirR : TQChar:: DirL );
+ }
+ inline uchar baseLevel() {
+ return ctx[0].level;
+ }
+ inline TQChar::Direction direction() {
+ return ((ctx[cCtx].level%2) ? TQChar::DirR : TQChar:: DirL );
+ }
+
+ Context ctx[63];
+ unsigned int cCtx : 8;
+ bool singleLine : 8;
+};
+
+static TQChar::Direction basicDirection( const TQString &str )
+{
+ int len = str.length();
+ int pos = 0;
+ const TQChar *uc = str.tqunicode() + pos;
+ while( pos < len ) {
+ switch( direction( *uc ) )
+ {
+ case TQChar::DirL:
+ case TQChar::DirLRO:
+ case TQChar::DirLRE:
+ return TQChar::DirL;
+ case TQChar::DirR:
+ case TQChar::DirAL:
+ case TQChar::DirRLO:
+ case TQChar::DirRLE:
+ return TQChar::DirR;
+ default:
+ break;
+ }
+ ++pos;
+ ++uc;
+ }
+ return TQChar::DirL;
+}
+
+
+static void tqAppendItems(TQTextEngine *engine, int &start, int &stop, BidiControl &control, TQChar::Direction dir )
+{
+ TQScriptItemArray &items = engine->items;
+ const TQChar *text = engine->string.tqunicode();
+
+ if ( start > stop ) {
+ // #### the algorithm is currently not really safe against this. Still needs fixing.
+// qWarning( "Bidi: appendItems() internal error" );
+ return;
+ }
+
+ int level = control.level();
+
+ if(dir != TQChar::DirON && !control.override()) {
+ // add level of run (cases I1 & I2)
+ if( level % 2 ) {
+ if(dir == TQChar::DirL || dir == TQChar::DirAN || dir == TQChar::DirEN )
+ level++;
+ } else {
+ if( dir == TQChar::DirR )
+ level++;
+ else if( dir == TQChar::DirAN || dir == TQChar::DirEN )
+ level += 2;
+ }
+ }
+
+#if (BIDI_DEBUG >= 1)
+ qDebug("new run: dir=%s from %d, to %d level = %d\n", directions[dir], start, stop, level);
+#endif
+ TQFont::Script script = TQFont::NoScript;
+ TQScriptItem item;
+ item.position = start;
+ item.analysis.script = script;
+ item.analysis.bidiLevel = level;
+ item.analysis.override = control.override();
+ item.analysis.reserved = 0;
+
+ if ( control.singleLine ) {
+ for ( int i = start; i <= stop; i++ ) {
+
+ unsigned short uc = text[i].tqunicode();
+ TQFont::Script s = (TQFont::Script)scriptForChar( uc );
+ if (s == TQFont::UnknownScript || s == TQFont::CombiningMarks)
+ s = script;
+
+ if (s != script) {
+ item.analysis.script = s;
+ item.analysis.bidiLevel = level;
+ item.position = i;
+ items.append( item );
+ script = s;
+ }
+ }
+ } else {
+ for ( int i = start; i <= stop; i++ ) {
+
+ unsigned short uc = text[i].tqunicode();
+ TQFont::Script s = (TQFont::Script)scriptForChar( uc );
+ if (s == TQFont::UnknownScript || s == TQFont::CombiningMarks)
+ s = script;
+
+ TQChar::Category category = ::category( uc );
+ if ( uc == 0xfffcU || uc == 0x2028U ) {
+ item.analysis.bidiLevel = level % 2 ? level-1 : level;
+ item.analysis.script = TQFont::Latin;
+ item.isObject = TRUE;
+ s = TQFont::NoScript;
+ } else if ((uc >= 9 && uc <=13) ||
+ (category >= TQChar::Separator_Space && category <= TQChar::Separator_Paragraph)) {
+ item.analysis.script = TQFont::Latin;
+ item.isSpace = TRUE;
+ item.isTab = ( uc == '\t' );
+ item.analysis.bidiLevel = item.isTab ? control.baseLevel() : level;
+ s = TQFont::NoScript;
+ } else if ( s != script && (category != TQChar::Mark_NonSpacing || script == TQFont::NoScript)) {
+ item.analysis.script = s;
+ item.analysis.bidiLevel = level;
+ } else {
+ if (i - start < 32000)
+ continue;
+ start = i;
+ }
+
+ item.position = i;
+ items.append( item );
+ script = s;
+ item.isSpace = item.isTab = item.isObject = FALSE;
+ }
+ }
+ ++stop;
+ start = stop;
+}
+
+typedef void (* fAppendItems)(TQTextEngine *, int &start, int &stop, BidiControl &control, TQChar::Direction dir);
+static fAppendItems appendItems = tqAppendItems;
+
+// creates the next TQScript items.
+static void bidiItemize( TQTextEngine *engine, bool rightToLeft, int mode )
+{
+ BidiControl control( rightToLeft );
+ if ( mode & TQTextEngine::SingleLine )
+ control.singleLine = TRUE;
+
+ int sor = 0;
+ int eor = -1;
+
+ // ### should get rid of this!
+ bool first = TRUE;
+
+ int length = engine->string.length();
+
+ if ( !length )
+ return;
+
+ const TQChar *tqunicode = engine->string.tqunicode();
+ int current = 0;
+
+ TQChar::Direction dir = rightToLeft ? TQChar::DirR : TQChar::DirL;
+ BiditqStatus status;
+ TQChar::Direction sdir = direction( *tqunicode );
+ if ( sdir != TQChar::DirL && sdir != TQChar::DirR && sdir != TQChar::DirAL && sdir != TQChar::DirEN && sdir != TQChar::DirAN )
+ sdir = TQChar::DirON;
+ else
+ dir = TQChar::DirON;
+ status.eor = sdir;
+ status.lastStrong = rightToLeft ? TQChar::DirR : TQChar::DirL;
+ status.last = status.lastStrong;
+ status.dir = sdir;
+#if (BIDI_DEBUG >= 2)
+ qDebug("---- bidiReorder --- '%s'", engine->string.utf8().data());
+ qDebug("rightToLeft = %d", rightToLeft);
+#endif
+
+
+ while ( current <= length ) {
+
+ TQChar::Direction dirCurrent;
+ if ( current == (int)length )
+ dirCurrent = control.basicDirection();
+ else
+ dirCurrent = direction( tqunicode[current] );
+
+#if (BIDI_DEBUG >= 2)
+ cout << "pos=" << current << " dir=" << directions[dir]
+ << " current=" << directions[dirCurrent] << " last=" << directions[status.last]
+ << " eor=" << eor << "/" << directions[status.eor]
+ << " sor=" << sor << " lastStrong="
+ << directions[status.lastStrong]
+ << " level=" << (int)control.level() << endl;
+#endif
+
+ switch(dirCurrent) {
+
+ // embedding and overrides (X1-X9 in the BiDi specs)
+ case TQChar::DirRLE:
+ case TQChar::DirRLO:
+ case TQChar::DirLRE:
+ case TQChar::DirLRO:
+ {
+ bool rtl = (dirCurrent == TQChar::DirRLE || dirCurrent == TQChar::DirRLO );
+ bool override = (dirCurrent == TQChar::DirLRO || dirCurrent == TQChar::DirRLO );
+
+ uchar level = control.level();
+ if( (level%2 != 0) == rtl )
+ level += 2;
+ else
+ level++;
+ if(level < 61) {
+ eor = current-1;
+ appendItems(engine, sor, eor, control, dir);
+ eor = current;
+ control.embed( level, override );
+ TQChar::Direction edir = (rtl ? TQChar::DirR : TQChar::DirL );
+ dir = status.eor = edir;
+ status.lastStrong = edir;
+ }
+ break;
+ }
+ case TQChar::DirPDF:
+ {
+ if (dir != control.direction()) {
+ eor = current-1;
+ appendItems(engine, sor, eor, control, dir);
+ dir = control.direction();
+ }
+ eor = current;
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirON;
+ status.last = control.direction();
+ control.pdf();
+ if ( control.override() )
+ dir = control.direction();
+ else
+ dir = TQChar::DirON;
+ status.lastStrong = control.direction();
+ break;
+ }
+
+ // strong types
+ case TQChar::DirL:
+ if(dir == TQChar::DirON)
+ dir = TQChar::DirL;
+ switch(status.last)
+ {
+ case TQChar::DirL:
+ eor = current; status.eor = TQChar::DirL; break;
+ case TQChar::DirR:
+ case TQChar::DirAL:
+ case TQChar::DirEN:
+ case TQChar::DirAN:
+ if ( !first ) {
+ appendItems(engine, sor, eor, control, dir);
+ dir = eor < length ? direction( tqunicode[eor] ) : control.basicDirection();
+ status.eor = dir;
+ } else {
+ eor = current; status.eor = dir;
+ }
+ break;
+ case TQChar::DirES:
+ case TQChar::DirET:
+ case TQChar::DirCS:
+ case TQChar::DirBN:
+ case TQChar::DirB:
+ case TQChar::DirS:
+ case TQChar::DirWS:
+ case TQChar::DirON:
+ if(dir != TQChar::DirL) {
+ //last stuff takes embedding dir
+ if( control.direction() == TQChar::DirR ) {
+ if(status.eor != TQChar::DirR) {
+ // AN or EN
+ appendItems(engine, sor, eor, control, dir);
+ status.eor = TQChar::DirON;
+ dir = TQChar::DirR;
+ }
+ eor = current - 1;
+ appendItems(engine, sor, eor, control, dir);
+ dir = eor < length ? direction( tqunicode[eor] ) : control.basicDirection();
+ status.eor = dir;
+ } else {
+ if(status.eor != TQChar::DirL) {
+ appendItems(engine, sor, eor, control, dir);
+ status.eor = TQChar::DirON;
+ dir = TQChar::DirL;
+ } else {
+ eor = current; status.eor = TQChar::DirL; break;
+ }
+ }
+ } else {
+ eor = current; status.eor = TQChar::DirL;
+ }
+ default:
+ break;
+ }
+ status.lastStrong = TQChar::DirL;
+ break;
+ case TQChar::DirAL:
+ case TQChar::DirR:
+ if(dir == TQChar::DirON) dir = TQChar::DirR;
+ switch(status.last)
+ {
+ case TQChar::DirL:
+ case TQChar::DirEN:
+ case TQChar::DirAN:
+ if ( !first ) {
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirON;
+ break;
+ }
+ case TQChar::DirR:
+ case TQChar::DirAL:
+ eor = current; status.eor = TQChar::DirR; break;
+ case TQChar::DirES:
+ case TQChar::DirET:
+ case TQChar::DirCS:
+ case TQChar::DirBN:
+ case TQChar::DirB:
+ case TQChar::DirS:
+ case TQChar::DirWS:
+ case TQChar::DirON:
+ if( status.eor != TQChar::DirR && status.eor != TQChar::DirAL ) {
+ //last stuff takes embedding dir
+ if(control.direction() == TQChar::DirR
+ || status.lastStrong == TQChar::DirR || status.lastStrong == TQChar::DirAL) {
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirON;
+ dir = TQChar::DirR;
+ eor = current;
+ } else {
+ eor = current - 1;
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirON;
+ dir = TQChar::DirR;
+ }
+ } else {
+ eor = current; status.eor = TQChar::DirR;
+ }
+ default:
+ break;
+ }
+ status.lastStrong = dirCurrent;
+ break;
+
+ // weak types:
+
+ case TQChar::DirNSM:
+ if (eor == current-1)
+ eor = current;
+ break;
+ case TQChar::DirEN:
+ // if last strong was AL change EN to AN
+ if(status.lastStrong != TQChar::DirAL) {
+ if(dir == TQChar::DirON) {
+ if(status.lastStrong == TQChar::DirL)
+ dir = TQChar::DirL;
+ else
+ dir = TQChar::DirEN;
+ }
+ switch(status.last)
+ {
+ case TQChar::DirET:
+ if ( status.lastStrong == TQChar::DirR || status.lastStrong == TQChar::DirAL ) {
+ appendItems(engine, sor, eor, control, dir);
+ status.eor = TQChar::DirON;
+ dir = TQChar::DirAN;
+ }
+ // fall through
+ case TQChar::DirEN:
+ case TQChar::DirL:
+ eor = current;
+ status.eor = dirCurrent;
+ break;
+ case TQChar::DirR:
+ case TQChar::DirAL:
+ case TQChar::DirAN:
+ if ( !first )
+ appendItems(engine, sor, eor, control, dir);
+ status.eor = TQChar::DirEN;
+ dir = TQChar::DirAN; break;
+ case TQChar::DirES:
+ case TQChar::DirCS:
+ if(status.eor == TQChar::DirEN || dir == TQChar::DirAN) {
+ eor = current; break;
+ }
+ case TQChar::DirBN:
+ case TQChar::DirB:
+ case TQChar::DirS:
+ case TQChar::DirWS:
+ case TQChar::DirON:
+ if(status.eor == TQChar::DirR) {
+ // neutrals go to R
+ eor = current - 1;
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirEN;
+ dir = TQChar::DirAN;
+ }
+ else if( status.eor == TQChar::DirL ||
+ (status.eor == TQChar::DirEN && status.lastStrong == TQChar::DirL)) {
+ eor = current; status.eor = dirCurrent;
+ } else {
+ // numbers on both sides, neutrals get right to left direction
+ if(dir != TQChar::DirL) {
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirON;
+ eor = current - 1;
+ dir = TQChar::DirR;
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirON;
+ dir = TQChar::DirAN;
+ } else {
+ eor = current; status.eor = dirCurrent;
+ }
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case TQChar::DirAN:
+ dirCurrent = TQChar::DirAN;
+ if(dir == TQChar::DirON) dir = TQChar::DirAN;
+ switch(status.last)
+ {
+ case TQChar::DirL:
+ case TQChar::DirAN:
+ eor = current; status.eor = TQChar::DirAN; break;
+ case TQChar::DirR:
+ case TQChar::DirAL:
+ case TQChar::DirEN:
+ if ( !first )
+ appendItems(engine, sor, eor, control, dir);
+ dir = TQChar::DirON; status.eor = TQChar::DirAN;
+ break;
+ case TQChar::DirCS:
+ if(status.eor == TQChar::DirAN) {
+ eor = current; break;
+ }
+ case TQChar::DirES:
+ case TQChar::DirET:
+ case TQChar::DirBN:
+ case TQChar::DirB:
+ case TQChar::DirS:
+ case TQChar::DirWS:
+ case TQChar::DirON:
+ if(status.eor == TQChar::DirR) {
+ // neutrals go to R
+ eor = current - 1;
+ appendItems(engine, sor, eor, control, dir);
+ status.eor = TQChar::DirAN;
+ dir = TQChar::DirAN;
+ } else if( status.eor == TQChar::DirL ||
+ (status.eor == TQChar::DirEN && status.lastStrong == TQChar::DirL)) {
+ eor = current; status.eor = dirCurrent;
+ } else {
+ // numbers on both sides, neutrals get right to left direction
+ if(dir != TQChar::DirL) {
+ appendItems(engine, sor, eor, control, dir);
+ status.eor = TQChar::DirON;
+ eor = current - 1;
+ dir = TQChar::DirR;
+ appendItems(engine, sor, eor, control, dir);
+ status.eor = TQChar::DirAN;
+ dir = TQChar::DirAN;
+ } else {
+ eor = current; status.eor = dirCurrent;
+ }
+ }
+ default:
+ break;
+ }
+ break;
+ case TQChar::DirES:
+ case TQChar::DirCS:
+ break;
+ case TQChar::DirET:
+ if(status.last == TQChar::DirEN) {
+ dirCurrent = TQChar::DirEN;
+ eor = current; status.eor = dirCurrent;
+ }
+ break;
+
+ // boundary neutrals should be ignored
+ case TQChar::DirBN:
+ break;
+ // neutrals
+ case TQChar::DirB:
+ // ### what do we do with newline and paragraph separators that come to here?
+ break;
+ case TQChar::DirS:
+ // ### implement rule L1
+ break;
+ case TQChar::DirWS:
+ case TQChar::DirON:
+ break;
+ default:
+ break;
+ }
+
+ //cout << " after: dir=" << // dir << " current=" << dirCurrent << " last=" << status.last << " eor=" << status.eor << " lastStrong=" << status.lastStrong << " embedding=" << control.direction() << endl;
+
+ if(current >= (int)length) break;
+
+ // set status.last as needed.
+ switch(dirCurrent) {
+ case TQChar::DirET:
+ case TQChar::DirES:
+ case TQChar::DirCS:
+ case TQChar::DirS:
+ case TQChar::DirWS:
+ case TQChar::DirON:
+ switch(status.last)
+ {
+ case TQChar::DirL:
+ case TQChar::DirR:
+ case TQChar::DirAL:
+ case TQChar::DirEN:
+ case TQChar::DirAN:
+ status.last = dirCurrent;
+ break;
+ default:
+ status.last = TQChar::DirON;
+ }
+ break;
+ case TQChar::DirNSM:
+ case TQChar::DirBN:
+ // ignore these
+ break;
+ case TQChar::DirLRO:
+ case TQChar::DirLRE:
+ status.last = TQChar::DirL;
+ break;
+ case TQChar::DirRLO:
+ case TQChar::DirRLE:
+ status.last = TQChar::DirR;
+ break;
+ case TQChar::DirEN:
+ if ( status.last == TQChar::DirL ) {
+ status.last = TQChar::DirL;
+ break;
+ }
+ // fall through
+ default:
+ status.last = dirCurrent;
+ }
+
+ first = FALSE;
+ ++current;
+ }
+
+#if (BIDI_DEBUG >= 1)
+ cout << "reached end of line current=" << current << ", eor=" << eor << endl;
+#endif
+ eor = current - 1; // remove dummy char
+
+ if ( sor <= eor )
+ appendItems(engine, sor, eor, control, dir);
+
+
+}
+
+void TQTextEngine::bidiReorder( int numItems, const TQ_UINT8 *levels, int *visualOrder )
+{
+
+ // first tqfind highest and lowest levels
+ uchar levelLow = 128;
+ uchar levelHigh = 0;
+ int i = 0;
+ while ( i < numItems ) {
+ //printf("level = %d\n", r->level);
+ if ( levels[i] > levelHigh )
+ levelHigh = levels[i];
+ if ( levels[i] < levelLow )
+ levelLow = levels[i];
+ i++;
+ }
+
+ // implements reordering of the line (L2 according to BiDi spec):
+ // L2. From the highest level found in the text to the lowest odd level on each line,
+ // reverse any contiguous sequence of characters that are at that level or higher.
+
+ // reversing is only done up to the lowest odd level
+ if(!(levelLow%2)) levelLow++;
+
+#if (BIDI_DEBUG >= 1)
+ cout << "reorderLine: lineLow = " << (uint)levelLow << ", lineHigh = " << (uint)levelHigh << endl;
+#endif
+
+ int count = numItems - 1;
+ for ( i = 0; i < numItems; i++ )
+ visualOrder[i] = i;
+
+ while(levelHigh >= levelLow) {
+ int i = 0;
+ while ( i < count ) {
+ while(i < count && levels[i] < levelHigh) i++;
+ int start = i;
+ while(i <= count && levels[i] >= levelHigh) i++;
+ int end = i-1;
+
+ if(start != end) {
+ //cout << "reversing from " << start << " to " << end << endl;
+ for(int j = 0; j < (end-start+1)/2; j++) {
+ int tmp = visualOrder[start+j];
+ visualOrder[start+j] = visualOrder[end-j];
+ visualOrder[end-j] = tmp;
+ }
+ }
+ i++;
+ }
+ levelHigh--;
+ }
+
+#if (BIDI_DEBUG >= 1)
+ cout << "visual order is:" << endl;
+ for ( i = 0; i < numItems; i++ )
+ cout << visualOrder[i] << endl;
+#endif
+}
+
+
+// -----------------------------------------------------------------------------------------------------
+//
+// The line break algorithm. See http://www.tqunicode.org/reports/tr14/tr14-13.html
+//
+// -----------------------------------------------------------------------------------------------------
+
+/* The Unicode algorithm does in our opinion allow line breaks at some
+ places they shouldn't be allowed. The following changes were thus
+ made in comparison to the Unicode reference:
+
+ CL->AL from Dbk to Ibk
+ CL->PR from Dbk to Ibk
+ EX->AL from Dbk to Ibk
+ IS->AL from Dbk to Ibk
+ PO->AL from Dbk to Ibk
+ SY->AL from Dbk to Ibk
+ SY->PO from Dbk to Ibk
+ SY->PR from Dbk to Ibk
+ SY->OP from Dbk to Ibk
+ Al->OP from Dbk to Ibk
+ AL->HY from Dbk to Ibk
+ AL->PR from Dbk to Ibk
+ AL->PO from Dbk to Ibk
+ PR->PR from Dbk to Ibk
+ PO->PO from Dbk to Ibk
+ PR->PO from Dbk to Ibk
+ PO->PR from Dbk to Ibk
+ HY->PO from Dbk to Ibk
+ HY->PR from Dbk to Ibk
+ HY->OP from Dbk to Ibk
+ PO->OP from Dbk to Ibk
+ NU->EX from Dbk to Ibk
+ NU->PR from Dbk to Ibk
+ PO->NU from Dbk to Ibk
+ EX->PO from Dbk to Ibk
+*/
+
+enum break_action {
+ Dbk, // Direct break
+ Ibk, // Indirect break; only allowed if space between the two chars
+ Pbk // Prohibited break; no break allowed even if space between chars
+};
+
+// The following line break classes are not treated by the table:
+// SA, BK, CR, LF, SG, CB, SP
+static const TQ_UINT8 breakTable[TQUnicodeTables::LineBreak_CM+1][TQUnicodeTables::LineBreak_CM+1] =
+{
+ // OP, CL, QU, GL, NS, EX, SY, IS, PR, PO, NU, AL, ID, IN, HY, BA, BB, B2, ZW, CM
+ { Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk, Pbk }, // OP
+ { Dbk, Pbk, Ibk, Pbk, Pbk, Pbk, Pbk, Pbk, Ibk, Ibk, Dbk, Ibk, Dbk, Dbk, Ibk, Ibk, Pbk, Pbk, Pbk, Pbk }, // CL
+ { Pbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Pbk, Pbk }, // QU
+ { Ibk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Pbk, Pbk }, // GL
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // NS
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Ibk, Ibk, Ibk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // EX
+ { Ibk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // SY
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // IS
+ { Ibk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Ibk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Pbk }, // PR
+ { Ibk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // PO
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Dbk, Ibk, Ibk, Ibk, Dbk, Dbk, Pbk, Pbk }, // NU
+ { Ibk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Dbk, Ibk, Ibk, Ibk, Dbk, Dbk, Pbk, Pbk }, // AL
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Ibk, Dbk, Dbk, Dbk, Ibk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // ID
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Dbk, Dbk, Dbk, Dbk, Ibk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // IN
+ { Ibk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // HY
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Ibk, Ibk, Dbk, Dbk, Pbk, Ibk }, // BA
+ { Ibk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Ibk, Pbk, Ibk }, // BB
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Ibk, Ibk, Dbk, Pbk, Pbk, Ibk }, // B2
+ { Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Dbk, Pbk, Ibk }, // ZW
+ { Dbk, Pbk, Ibk, Pbk, Ibk, Pbk, Pbk, Pbk, Dbk, Ibk, Dbk, Dbk, Dbk, Ibk, Ibk, Ibk, Dbk, Dbk, Pbk, Pbk } // CM
+};
+
+// set the soft break flag at every possible line breaking point. This needs correct clustering information.
+static void calcLineBreaks(const TQString &str, TQCharAttributes *charAttributes)
+{
+ int len = str.length();
+ if (!len)
+ return;
+
+ const TQChar *uc = str.tqunicode();
+ int cls = lineBreakClass(*uc);
+ if (cls >= TQUnicodeTables::LineBreak_CM)
+ cls = TQUnicodeTables::LineBreak_ID;
+
+ charAttributes[0].softBreak = FALSE;
+ charAttributes[0].whiteSpace = (cls == TQUnicodeTables::LineBreak_SP);
+ charAttributes[0].charStop = TRUE;
+
+ for (int i = 1; i < len; ++i) {
+ int ncls = ::lineBreakClass(uc[i]);
+ int category = ::category(uc[i]);
+ if (category == TQChar::Mark_NonSpacing)
+ goto nsm;
+
+ if (category == TQChar::Other_Surrogate) {
+ // char stop only on first pair
+ if (uc[i].tqunicode() >= 0xd800 && uc[i].tqunicode() < 0xdc00 && i < len-1
+ && uc[i+1].tqunicode() >= 0xdc00 && uc[i+1].tqunicode() < 0xe000)
+ goto nsm;
+ // ### correctly handle second surrogate
+ }
+
+ if (ncls == TQUnicodeTables::LineBreak_SP) {
+ charAttributes[i].softBreak = FALSE;
+ charAttributes[i].whiteSpace = TRUE;
+ charAttributes[i].charStop = TRUE;
+ cls = ncls;
+ continue;
+ }
+
+
+ if (cls == TQUnicodeTables::LineBreak_SA && ncls == TQUnicodeTables::LineBreak_SA) {
+ // two complex chars (thai or lao), thai_attributes might override, but here
+ // we do a best guess
+ charAttributes[i].softBreak = TRUE;
+ charAttributes[i].whiteSpace = FALSE;
+ charAttributes[i].charStop = TRUE;
+ cls = ncls;
+ continue;
+ }
+ {
+ int tcls = ncls;
+ if (tcls >= TQUnicodeTables::LineBreak_SA)
+ tcls = TQUnicodeTables::LineBreak_ID;
+ if (cls >= TQUnicodeTables::LineBreak_SA)
+ cls = TQUnicodeTables::LineBreak_ID;
+
+ bool softBreak;
+ int brk = breakTable[cls][tcls];
+ if (brk == Ibk)
+ softBreak = (cls == TQUnicodeTables::LineBreak_SP);
+ else
+ softBreak = (brk == Dbk);
+// qDebug("char = %c %04x, cls=%d, ncls=%d, brk=%d soft=%d", uc[i].cell(), uc[i].tqunicode(), cls, ncls, brk, charAttributes[i].softBreak);
+ charAttributes[i].softBreak = softBreak;
+ charAttributes[i].whiteSpace = FALSE;
+ charAttributes[i].charStop = TRUE;
+ cls = ncls;
+ }
+ continue;
+ nsm:
+ charAttributes[i].softBreak = FALSE;
+ charAttributes[i].whiteSpace = FALSE;
+ charAttributes[i].charStop = FALSE;
+ }
+}
+
+#if defined( TQ_WS_X11 ) || defined ( TQ_WS_TQWS )
+# include "tqtextengine_unix.cpp"
+#elif defined( TQ_WS_WIN )
+# include "tqtextengine_win.cpp"
+#elif defined( TQ_WS_MAC )
+# include "tqtextengine_mac.cpp"
+#endif
+
+
+
+TQTextEngine::TQTextEngine( const TQString &str, TQFontPrivate *f )
+ : string( str ), fnt( f ), direction( TQChar::DirON ), haveCharAttributes( FALSE ), widthOnly( FALSE )
+{
+#ifdef TQ_WS_WIN
+ if ( !resolvedUsp10 )
+ resolveUsp10();
+#endif
+ if ( fnt ) fnt->ref();
+
+ num_glyphs = TQMAX( 16, str.length()*3/2 );
+ int space_charAttributes = (sizeof(TQCharAttributes)*str.length()+sizeof(void*)-1)/sizeof(void*);
+ int space_logClusters = (sizeof(unsigned short)*str.length()+sizeof(void*)-1)/sizeof(void*);
+ int space_glyphs = (sizeof(glyph_t)*num_glyphs+sizeof(void*)-1)/sizeof(void*);
+ int space_advances = (sizeof(advance_t)*num_glyphs+sizeof(void*)-1)/sizeof(void*);
+ int space_offsets = (sizeof(qoffset_t)*num_glyphs+sizeof(void*)-1)/sizeof(void*);
+ int space_glyphAttributes = (sizeof(GlyphAttributes)*num_glyphs+sizeof(void*)-1)/sizeof(void*);
+
+ allocated = space_charAttributes + space_glyphs + space_advances +
+ space_offsets + space_logClusters + space_glyphAttributes;
+ memory = (void **)::malloc( allocated*sizeof( void * ) );
+ memset( memory, 0, allocated*sizeof( void * ) );
+
+ void **m = memory;
+ m += space_charAttributes;
+ logClustersPtr = (unsigned short *) m;
+ m += space_logClusters;
+ glyphPtr = (glyph_t *) m;
+ m += space_glyphs;
+ advancePtr = (advance_t *) m;
+ m += space_advances;
+ offsetsPtr = (qoffset_t *) m;
+ m += space_offsets;
+ glyphAttributesPtr = (GlyphAttributes *) m;
+
+ used = 0;
+}
+
+TQTextEngine::~TQTextEngine()
+{
+ if ( fnt && fnt->deref())
+ delete fnt;
+ free( memory );
+ allocated = 0;
+}
+
+void TQTextEngine::reallocate( int totalGlyphs )
+{
+ int new_num_glyphs = totalGlyphs;
+ int space_charAttributes = (sizeof(TQCharAttributes)*string.length()+sizeof(void*)-1)/sizeof(void*);
+ int space_logClusters = (sizeof(unsigned short)*string.length()+sizeof(void*)-1)/sizeof(void*);
+ int space_glyphs = (sizeof(glyph_t)*new_num_glyphs+sizeof(void*)-1)/sizeof(void*);
+ int space_advances = (sizeof(advance_t)*new_num_glyphs+sizeof(void*)-1)/sizeof(void*);
+ int space_offsets = (sizeof(qoffset_t)*new_num_glyphs+sizeof(void*)-1)/sizeof(void*);
+ int space_glyphAttributes = (sizeof(GlyphAttributes)*new_num_glyphs+sizeof(void*)-1)/sizeof(void*);
+
+ int newAllocated = space_charAttributes + space_glyphs + space_advances +
+ space_offsets + space_logClusters + space_glyphAttributes;
+ void ** newMemory = (void **)::malloc( newAllocated*sizeof( void * ) );
+
+ void **nm = newMemory;
+ memcpy( nm, memory, string.length()*sizeof(TQCharAttributes) );
+ nm += space_charAttributes;
+ memcpy( nm, logClustersPtr, num_glyphs*sizeof(unsigned short) );
+ logClustersPtr = (unsigned short *) nm;
+ nm += space_logClusters;
+ memcpy( nm, glyphPtr, num_glyphs*sizeof(glyph_t) );
+ glyphPtr = (glyph_t *) nm;
+ nm += space_glyphs;
+ memcpy( nm, advancePtr, num_glyphs*sizeof(advance_t) );
+ advancePtr = (advance_t *) nm;
+ nm += space_advances;
+ memcpy( nm, offsetsPtr, num_glyphs*sizeof(qoffset_t) );
+ offsetsPtr = (qoffset_t *) nm;
+ nm += space_offsets;
+ memcpy( nm, glyphAttributesPtr, num_glyphs*sizeof(GlyphAttributes) );
+ glyphAttributesPtr = (GlyphAttributes *) nm;
+
+ free( memory );
+ memory = newMemory;
+ allocated = newAllocated;
+ num_glyphs = new_num_glyphs;
+}
+
+const TQCharAttributes *TQTextEngine::attributes()
+{
+ TQCharAttributes *charAttributes = (TQCharAttributes *) memory;
+ if ( haveCharAttributes )
+ return charAttributes;
+
+ if ( !items.d )
+ itemize();
+
+ ensureSpace(string.length());
+ charAttributes = (TQCharAttributes *) memory;
+ calcLineBreaks(string, charAttributes);
+
+ for ( int i = 0; i < items.size(); i++ ) {
+ TQScriptItem &si = items[i];
+#ifdef TQ_WS_WIN
+ int script = uspScriptForItem(this, i);
+#else
+ int script = si.analysis.script;
+#endif
+ TQ_ASSERT( script < TQFont::NScripts );
+ AttributeFunction attributes = scriptEngines[script].charAttributes;
+ if (!attributes)
+ continue;
+ int from = si.position;
+ int len = length( i );
+ attributes( script, string, from, len, charAttributes );
+ }
+
+ haveCharAttributes = TRUE;
+ return charAttributes;
+}
+
+void TQTextEngine::splitItem( int item, int pos )
+{
+ if ( pos <= 0 )
+ return;
+
+ // we have to ensure we get correct shaping for arabic and other
+ // complex languages so we have to call tqshape _before_ we split the item.
+ tqshape(item);
+
+ if ( items.d->size == items.d->alloc )
+ items.resize( items.d->size + 1 );
+
+ int numMove = items.d->size - item-1;
+ if ( numMove > 0 )
+ memmove( items.d->items + item+2, items.d->items +item+1, numMove*sizeof( TQScriptItem ) );
+ items.d->size++;
+ TQScriptItem &newItem = items.d->items[item+1];
+ TQScriptItem &oldItem = items.d->items[item];
+ newItem = oldItem;
+ items.d->items[item+1].position += pos;
+ if ( newItem.fontEngine )
+ newItem.fontEngine->ref();
+
+ if (oldItem.num_glyphs) {
+ // already tqshaped, break glyphs aswell
+ int breakGlyph = logClusters(&oldItem)[pos];
+
+ newItem.num_glyphs = oldItem.num_glyphs - breakGlyph;
+ oldItem.num_glyphs = breakGlyph;
+ newItem.glyph_data_offset = oldItem.glyph_data_offset + breakGlyph;
+
+ for (int i = 0; i < newItem.num_glyphs; i++)
+ logClusters(&newItem)[i] -= breakGlyph;
+
+ int w = 0;
+ const advance_t *a = advances(&oldItem);
+ for(int j = 0; j < breakGlyph; ++j)
+ w += *(a++);
+
+ newItem.width = oldItem.width - w;
+ oldItem.width = w;
+ }
+
+// qDebug("split at position %d itempos=%d", pos, item );
+}
+
+
+int TQTextEngine::width( int from, int len ) const
+{
+ int w = 0;
+
+// qDebug("TQTextEngine::width( from = %d, len = %d ), numItems=%d, strleng=%d", from, len, items.size(), string.length() );
+ for ( int i = 0; i < items.size(); i++ ) {
+ TQScriptItem *si = &items[i];
+ int pos = si->position;
+ int ilen = length( i );
+// qDebug("item %d: from %d len %d", i, pos, ilen );
+ if ( pos >= from + len )
+ break;
+ if ( pos + ilen > from ) {
+ if ( !si->num_glyphs )
+ tqshape( i );
+
+ advance_t *advances = this->advances( si );
+ unsigned short *logClusters = this->logClusters( si );
+
+// fprintf( stderr, " logclusters:" );
+// for ( int k = 0; k < ilen; k++ )
+// fprintf( stderr, " %d", logClusters[k] );
+// fprintf( stderr, "\n" );
+ // do the simple thing for now and give the first glyph in a cluster the full width, all other ones 0.
+ int charFrom = from - pos;
+ if ( charFrom < 0 )
+ charFrom = 0;
+ int glyphStart = logClusters[charFrom];
+ if ( charFrom > 0 && logClusters[charFrom-1] == glyphStart )
+ while ( charFrom < ilen && logClusters[charFrom] == glyphStart )
+ charFrom++;
+ if ( charFrom < ilen ) {
+ glyphStart = logClusters[charFrom];
+ int charEnd = from + len - 1 - pos;
+ if ( charEnd >= ilen )
+ charEnd = ilen-1;
+ int glyphEnd = logClusters[charEnd];
+ while ( charEnd < ilen && logClusters[charEnd] == glyphEnd )
+ charEnd++;
+ glyphEnd = (charEnd == ilen) ? si->num_glyphs : logClusters[charEnd];
+
+// qDebug("char: start=%d end=%d / glyph: start = %d, end = %d", charFrom, charEnd, glyphStart, glyphEnd );
+ for ( int i = glyphStart; i < glyphEnd; i++ )
+ w += advances[i];
+ }
+ }
+ }
+// qDebug(" --> w= %d ", w );
+ return w;
+}
+
+void TQTextEngine::itemize( int mode )
+{
+ if ( !items.d ) {
+ int size = 8;
+ items.d = (TQScriptItemArrayPrivate *)malloc( sizeof( TQScriptItemArrayPrivate ) +
+ sizeof( TQScriptItem ) * size );
+ items.d->alloc = size;
+ }
+ items.d->size = 0;
+ if ( string.length() == 0 )
+ return;
+
+ if ( !(mode & NoBidi) ) {
+ if ( direction == TQChar::DirON )
+ direction = basicDirection( string );
+ bidiItemize( this, direction == TQChar::DirR, mode );
+ } else {
+ BidiControl control( FALSE );
+ if ( mode & TQTextEngine::SingleLine )
+ control.singleLine = TRUE;
+ int start = 0;
+ int stop = string.length() - 1;
+ appendItems(this, start, stop, control, TQChar::DirL);
+ }
+ if ( (mode & WidthOnly) == WidthOnly )
+ widthOnly = TRUE;
+}
+
+glyph_metrics_t TQTextEngine::boundingBox( int from, int len ) const
+{
+ glyph_metrics_t gm;
+
+ for ( int i = 0; i < items.size(); i++ ) {
+ TQScriptItem *si = &items[i];
+ int pos = si->position;
+ int ilen = length( i );
+ if ( pos > from + len )
+ break;
+ if ( pos + len > from ) {
+ if ( !si->num_glyphs )
+ tqshape( i );
+ advance_t *advances = this->advances( si );
+ unsigned short *logClusters = this->logClusters( si );
+ glyph_t *glyphs = this->glyphs( si );
+ qoffset_t *offsets = this->offsets( si );
+
+ // do the simple thing for now and give the first glyph in a cluster the full width, all other ones 0.
+ int charFrom = from - pos;
+ if ( charFrom < 0 )
+ charFrom = 0;
+ int glyphStart = logClusters[charFrom];
+ if ( charFrom > 0 && logClusters[charFrom-1] == glyphStart )
+ while ( charFrom < ilen && logClusters[charFrom] == glyphStart )
+ charFrom++;
+ if ( charFrom < ilen ) {
+ glyphStart = logClusters[charFrom];
+ int charEnd = from + len - 1 - pos;
+ if ( charEnd >= ilen )
+ charEnd = ilen-1;
+ int glyphEnd = logClusters[charEnd];
+ while ( charEnd < ilen && logClusters[charEnd] == glyphEnd )
+ charEnd++;
+ glyphEnd = (charEnd == ilen) ? si->num_glyphs : logClusters[charEnd];
+ if ( glyphStart <= glyphEnd ) {
+ TQFontEngine *fe = si->fontEngine;
+ glyph_metrics_t m = fe->boundingBox( glyphs+glyphStart, advances+glyphStart,
+ offsets+glyphStart, glyphEnd-glyphStart );
+ gm.x = TQMIN( gm.x, m.x + gm.xoff );
+ gm.y = TQMIN( gm.y, m.y + gm.yoff );
+ gm.width = TQMAX( gm.width, m.width+gm.xoff );
+ gm.height = TQMAX( gm.height, m.height+gm.yoff );
+ gm.xoff += m.xoff;
+ gm.yoff += m.yoff;
+ }
+ }
+ }
+ }
+ return gm;
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqtextengine_p.h b/tqtinterface/qt4/src/kernel/tqtextengine_p.h
new file mode 100644
index 0000000..dcdbbba
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtextengine_p.h
@@ -0,0 +1,467 @@
+/****************************************************************************
+**
+** ???
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQTEXTENGINE_P_H
+#define TQTEXTENGINE_P_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqglobal.h"
+#include "tqstring.h"
+#include "tqnamespace.h"
+#include <private/tqfontdata_p.h>
+#endif // TQT_H
+
+#include <stdlib.h>
+#ifndef TQ_OS_TEMP
+#include <assert.h>
+#endif // TQ_OS_TEMP
+
+#ifdef USE_QT4
+
+// #include <private/qt4_qtextengine_p.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+// class TQTextEngine : public QTextEngine {
+// public:
+// TQTextEngine( const TQString &str, TQFontPrivate *f ) : QTextEngine(str, convertToQFont(f)) {}
+//
+// enum Mode {
+// Full = 0x00,
+// NoBidi = 0x01,
+// SingleLine = 0x02,
+// WidthOnly = 0x07
+// };
+//
+// enum Edge {
+// Leading,
+// Trailing
+// };
+// enum ShaperFlag {
+// RightToLeft = 0x0001,
+// Mirrored = 0x0001
+// };
+// //
+// // // Interoperability
+// // QFont convertToQFont( TQFontPrivate *f );
+// };
+//
+// // Interoperability
+// inline QFont convertToQFont( TQFontPrivate *f ) {
+// QFont qf;
+// // Copy over every single #!$% parameter from the TQFontPrivate object [FIXME]
+// QFont qft(qf, f->painttqdevice);
+// return qft;
+// }
+//
+// struct TQScriptAnalysis
+// {
+// unsigned short script : 7;
+// unsigned short bidiLevel : 6; // Unicode Bidi algorithm embedding level (0-61)
+// unsigned short override : 1; // Set when in LRO/RLO embedding
+// unsigned short reserved : 2;
+// bool operator == ( const TQScriptAnalysis &other ) {
+// return
+// script == other.script &&
+// bidiLevel == other.bidiLevel;
+// // ###
+// // && override == other.override;
+// }
+//
+// };
+//
+// class TQFontEngine;
+//
+// struct TQScriptItem
+// {
+// inline TQScriptItem() : position( 0 ), isSpace( FALSE ), isTab( FALSE ),
+// isObject( FALSE ), hasPositioning( FALSE ),
+// descent( -1 ), ascent( -1 ), width( -1 ),
+// x( 0 ), y( 0 ), num_glyphs( 0 ), glyph_data_offset( 0 ),
+// fontEngine( 0 ) { }
+// int position;
+// TQScriptAnalysis analysis;
+// unsigned short isSpace : 1;
+// unsigned short isTab : 1;
+// unsigned short isObject : 1;
+// unsigned short hasPositioning : 1;
+// unsigned short complex : 1; // Windows only
+// unsigned short private_use : 1; // Windows only
+// unsigned short reserved : 10;
+// short descent;
+// int ascent;
+// int width;
+// int x;
+// int y;
+// int num_glyphs;
+// int glyph_data_offset;
+// TQFontEngine *fontEngine;
+// };
+
+#else // USE_QT4
+
+class TQFontPrivate;
+class TQString;
+
+class TQOpenType;
+class TQPainter;
+
+// this uses the same coordinate system as TQt, but a different one to freetype and Xft.
+// * y is usually negative, and is equal to the ascent.
+// * negative yoff means the following stuff is drawn higher up.
+// the characters bounding rect is given by TQRect( x,y,width,height), it's advance by
+// xoo and yoff
+struct glyph_metrics_t
+{
+ inline glyph_metrics_t() {
+ x = 100000;
+ y = 100000;
+ width = 0;
+ height = 0;
+ xoff = 0;
+ yoff = 0;
+ }
+ inline glyph_metrics_t( int _x, int _y, int _width, int _height, int _xoff, int _yoff ) {
+ x = _x;
+ y = _y;
+ width = _width;
+ height = _height;
+ xoff = _xoff;
+ yoff = _yoff;
+ }
+ int x;
+ int y;
+ int width;
+ int height;
+ int xoff;
+ int yoff;
+};
+
+#if defined( TQ_WS_X11 ) || defined ( TQ_WS_TQWS )
+typedef unsigned short glyph_t;
+
+struct qoffset_t {
+ short x;
+ short y;
+};
+
+typedef int advance_t;
+
+struct TQScriptAnalysis
+{
+ unsigned short script : 7;
+ unsigned short bidiLevel : 6; // Unicode Bidi algorithm embedding level (0-61)
+ unsigned short override : 1; // Set when in LRO/RLO embedding
+ unsigned short reserved : 2;
+ bool operator == ( const TQScriptAnalysis &other ) {
+ return
+ script == other.script &&
+ bidiLevel == other.bidiLevel;
+ // ###
+// && override == other.override;
+ }
+
+};
+
+#elif defined( TQ_WS_MAC )
+
+typedef unsigned short glyph_t;
+
+struct qoffset_t {
+ short x;
+ short y;
+};
+
+typedef int advance_t;
+
+struct TQScriptAnalysis
+{
+ unsigned short script : 7;
+ unsigned short bidiLevel : 6; // Unicode Bidi algorithm embedding level (0-61)
+ unsigned short override : 1; // Set when in LRO/RLO embedding
+ unsigned short reserved : 2;
+ bool operator == ( const TQScriptAnalysis &other ) {
+ return
+ script == other.script &&
+ bidiLevel == other.bidiLevel;
+ // ###
+// && override == other.override;
+ }
+
+};
+
+#elif defined( TQ_WS_WIN )
+
+// do not change the definitions below unless you know what you are doing!
+// it is designed to be compatible with the types found in uniscribe.
+
+typedef unsigned short glyph_t;
+
+struct qoffset_t {
+ int x;
+ int y;
+};
+
+typedef int advance_t;
+
+struct TQScriptAnalysis {
+ unsigned short script :10;
+ unsigned short rtl :1;
+ unsigned short layoutRTL :1;
+ unsigned short linkBefore :1;
+ unsigned short linkAfter :1;
+ unsigned short logicalOrder :1;
+ unsigned short noGlyphIndex :1;
+ unsigned short bidiLevel :5;
+ unsigned short override :1;
+ unsigned short inhibitSymSwap :1;
+ unsigned short charShape :1;
+ unsigned short digitSubstitute :1;
+ unsigned short inhibitLigate :1;
+ unsigned short fDisplayZWG :1;
+ unsigned short arabicNumContext :1;
+ unsigned short gcpClusters :1;
+ unsigned short reserved :1;
+ unsigned short engineReserved :2;
+};
+
+inline bool operator == ( const TQScriptAnalysis &sa1, const TQScriptAnalysis &sa2 )
+{
+ return
+ sa1.script == sa2.script &&
+ sa1.bidiLevel == sa2.bidiLevel;
+ // ###
+// && override == other.override;
+}
+
+#endif
+
+// enum and struct are made to be compatible with Uniscribe, dont change unless you know what you're doing.
+struct GlyphAttributes {
+ // highest value means highest priority for justification. Justification is done by first inserting kashidas
+ // starting with the highest priority positions, then stretching spaces, afterwards extending inter char
+ // spacing, and last spacing between arabic words.
+ // NoJustification is for example set for arabic where no Kashida can be inserted or for diacritics.
+ enum Justification {
+ NoJustification= 0, // Justification can't be applied after this glyph
+ Arabic_Space = 1, // This glyph represents a space inside arabic text
+ Character = 2, // Inter-character justification point follows this glyph
+ Space = 4, // This glyph represents a blank outside an Arabic run
+ Arabic_Normal = 7, // Normal Middle-Of-Word glyph that connects to the right (begin)
+ Arabic_Waw = 8, // Next character is final form of Waw/Ain/Qaf/Fa
+ Arabic_BaRa = 9, // Next two chars are Ba + Ra/Ya/AlefMaksura
+ Arabic_Alef = 10, // Next character is final form of Alef/Tah/Lam/Kaf/Gaf
+ Arabic_HaaDal = 11, // Next character is final form of Haa/Dal/Taa Marbutah
+ Arabic_Seen = 12, // Initial or Medial form Of Seen/Sad
+ Arabic_Kashida = 13 // Kashida(U+640) in middle of word
+ };
+ unsigned short justification :4; // Justification class
+ unsigned short clusterStart :1; // First glyph of representation of cluster
+ unsigned short mark :1; // needs to be positioned around base char
+ unsigned short zeroWidth :1; // ZWJ, ZWNJ etc, with no width, currently used as "Don't print" for ZWSP
+ unsigned short reserved :1;
+ unsigned short combiningClass :8;
+};
+
+// also this is compatible to uniscribe. Do not change.
+struct TQCharAttributes {
+ uchar softBreak :1; // Potential linebreak point _before_ this character
+ uchar whiteSpace :1; // A tqunicode whitespace character, except NBSP, ZWNBSP
+ uchar charStop :1; // Valid cursor position (for left/right arrow)
+ uchar wordStop :1; // Valid cursor position (for ctrl + left/right arrow)
+ uchar invalid :1;
+ uchar reserved :3;
+};
+
+inline bool qIsZeroWidthChar(ushort uc)
+{
+ return (uc >= 0x200b && uc <= 0x200f /* ZW Space, ZWNJ, ZWJ, LRM and RLM */)
+ || (uc >= 0x2028 && uc <= 0x202f /* LS, PS, LRE, RLE, PDF, LRO, RLO, NNBSP */)
+ || (uc >= 0x206a && uc <= 0x206f /* ISS, ASS, IAFS, AFS, NADS, NODS */);
+}
+
+class TQFontEngine;
+
+struct TQScriptItem
+{
+ inline TQScriptItem() : position( 0 ), isSpace( FALSE ), isTab( FALSE ),
+ isObject( FALSE ), hasPositioning( FALSE ),
+ descent( -1 ), ascent( -1 ), width( -1 ),
+ x( 0 ), y( 0 ), num_glyphs( 0 ), glyph_data_offset( 0 ),
+ fontEngine( 0 ) { }
+ int position;
+ TQScriptAnalysis analysis;
+ unsigned short isSpace : 1;
+ unsigned short isTab : 1;
+ unsigned short isObject : 1;
+ unsigned short hasPositioning : 1;
+ unsigned short complex : 1; // Windows only
+ unsigned short private_use : 1; // Windows only
+ unsigned short reserved : 10;
+ short descent;
+ int ascent;
+ int width;
+ int x;
+ int y;
+ int num_glyphs;
+ int glyph_data_offset;
+ TQFontEngine *fontEngine;
+};
+
+struct TQScriptItemArrayPrivate
+{
+ unsigned int alloc;
+ unsigned int size;
+ TQScriptItem items[1];
+};
+
+class TQScriptItemArray
+{
+public:
+ TQScriptItemArray() : d( 0 ) {}
+ ~TQScriptItemArray();
+
+ inline TQScriptItem &operator[] (int i) const {return d->items[i]; }
+ inline void append( const TQScriptItem &item ) {
+ if ( d->size == d->alloc )
+ resize( d->size + 1 );
+ d->items[d->size] = item;
+ d->size++;
+ }
+ inline int size() const { return d ? d->size : 0; }
+
+ void resize( int s );
+ void clear();
+
+ TQScriptItemArrayPrivate *d;
+private:
+#ifdef TQ_DISABLE_COPY
+ TQScriptItemArray( const TQScriptItemArray & );
+ TQScriptItemArray &operator = ( const TQScriptItemArray & );
+#endif
+};
+
+class TQFontPrivate;
+
+class TQTextEngine {
+public:
+ TQTextEngine( const TQString &str, TQFontPrivate *f );
+ ~TQTextEngine();
+
+ enum Mode {
+ Full = 0x00,
+ NoBidi = 0x01,
+ SingleLine = 0x02,
+ WidthOnly = 0x07
+ };
+
+ void itemize( int mode = Full );
+
+ static void bidiReorder( int numRuns, const TQ_UINT8 *levels, int *visualOrder );
+
+ const TQCharAttributes *attributes();
+ void tqshape( int item ) const;
+
+ // ### we need something for justification
+
+ enum Edge {
+ Leading,
+ Trailing
+ };
+ enum ShaperFlag {
+ RightToLeft = 0x0001,
+ Mirrored = 0x0001
+ };
+
+ int width( int charFrom, int numChars ) const;
+ glyph_metrics_t boundingBox( int from, int len ) const;
+
+ TQScriptItemArray items;
+ TQString string;
+ TQFontPrivate *fnt;
+ int lineWidth;
+ int widthUsed;
+ int firstItemInLine;
+ int currentItem;
+ TQChar::Direction direction : 5;
+ unsigned int haveCharAttributes : 1;
+ unsigned int widthOnly : 1;
+ unsigned int reserved : 25;
+
+ int length( int item ) const {
+ const TQScriptItem &si = items[item];
+ int from = si.position;
+ item++;
+ return ( item < items.size() ? items[item].position : string.length() ) - from;
+ }
+ void splitItem( int item, int pos );
+
+ unsigned short *logClustersPtr;
+ glyph_t *glyphPtr;
+ advance_t *advancePtr;
+ qoffset_t *offsetsPtr;
+ GlyphAttributes *glyphAttributesPtr;
+
+ inline unsigned short *logClusters( const TQScriptItem *si ) const
+ { return logClustersPtr+si->position; }
+ inline glyph_t *glyphs( const TQScriptItem *si ) const
+ { return glyphPtr+si->glyph_data_offset; }
+ inline advance_t *advances( const TQScriptItem *si ) const
+ { return advancePtr+si->glyph_data_offset; }
+ inline qoffset_t *offsets( const TQScriptItem *si ) const
+ { return offsetsPtr+si->glyph_data_offset; }
+ inline GlyphAttributes *glyphAttributes( const TQScriptItem *si ) const
+ { return glyphAttributesPtr+si->glyph_data_offset; }
+
+ void reallocate( int totalGlyphs );
+ inline void ensureSpace( int nGlyphs ) const {
+ if ( num_glyphs - used < nGlyphs )
+ ((TQTextEngine *)this)->reallocate( ( (used + nGlyphs + 16) >> 4 ) << 4 );
+ }
+
+ int allocated;
+ void **memory;
+ int num_glyphs;
+ int used;
+};
+
+#endif
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqtextengine_unix.cpp b/tqtinterface/qt4/src/kernel/tqtextengine_unix.cpp
new file mode 100644
index 0000000..e503897
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtextengine_unix.cpp
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Text engine classes
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <assert.h>
+
+
+TQScriptItemArray::~TQScriptItemArray()
+{
+ clear();
+ free( d );
+}
+
+void TQScriptItemArray::clear()
+{
+ if ( d ) {
+ for ( unsigned int i = 0; i < d->size; i++ ) {
+ TQScriptItem &si = d->items[i];
+ if ( si.fontEngine )
+ si.fontEngine->deref();
+ }
+ d->size = 0;
+ }
+}
+
+void TQScriptItemArray::resize( int s )
+{
+ int alloc = (s + 8) >> 3 << 3;
+ d = (TQScriptItemArrayPrivate *)realloc( d, sizeof( TQScriptItemArrayPrivate ) +
+ sizeof( TQScriptItem ) * alloc );
+ d->alloc = alloc;
+}
+
+void TQTextEngine::tqshape( int item ) const
+{
+ assert( item < items.size() );
+ TQScriptItem &si = items[item];
+
+ if ( si.num_glyphs )
+ return;
+
+ TQFont::Script script = (TQFont::Script)si.analysis.script;
+ si.glyph_data_offset = used;
+
+ if ( !si.fontEngine )
+ si.fontEngine = fnt->engineForScript( script );
+ si.fontEngine->ref();
+
+ si.ascent = si.fontEngine->ascent();
+ si.descent = si.fontEngine->descent();
+ si.num_glyphs = 0;
+
+ if ( si.fontEngine && si.fontEngine != (TQFontEngine*)-1 ) {
+ TQShaperItem tqshaper_item;
+ tqshaper_item.script = si.analysis.script;
+ tqshaper_item.string = &string;
+ tqshaper_item.from = si.position;
+ tqshaper_item.length = length(item);
+ tqshaper_item.font = si.fontEngine;
+ tqshaper_item.num_glyphs = TQMAX(int(num_glyphs - used), tqshaper_item.length);
+ tqshaper_item.flags = si.analysis.bidiLevel % 2 ? RightToLeft : 0;
+ tqshaper_item.has_positioning = FALSE;
+
+ while (1) {
+// qDebug(" . num_glyphs=%d, used=%d, item.num_glyphs=%d", num_glyphs, used, tqshaper_item.num_glyphs);
+ ensureSpace(tqshaper_item.num_glyphs);
+ tqshaper_item.num_glyphs = num_glyphs - used;
+// qDebug(" .. num_glyphs=%d, used=%d, item.num_glyphs=%d", num_glyphs, used, tqshaper_item.num_glyphs);
+ tqshaper_item.glyphs = glyphs(&si);
+ tqshaper_item.advances = advances(&si);
+ tqshaper_item.offsets = offsets(&si);
+ tqshaper_item.attributes = glyphAttributes(&si);
+ tqshaper_item.log_clusters = logClusters(&si);
+ if (scriptEngines[tqshaper_item.script].tqshape(&tqshaper_item))
+ break;
+ }
+
+ si.num_glyphs = tqshaper_item.num_glyphs;
+ si.hasPositioning = tqshaper_item.has_positioning;
+ }
+ ((TQTextEngine *)this)->used += si.num_glyphs;
+
+ si.width = 0;
+ advance_t *advances = this->advances( &si );
+ advance_t *end = advances + si.num_glyphs;
+ while ( advances < end ) {
+// qDebug("advances[%d] = %d", advances - this->advances(&si), *advances);
+ si.width += *(advances++);
+ }
+
+ return;
+}
+
diff --git a/tqtinterface/qt4/src/kernel/tqtextlayout.cpp b/tqtinterface/qt4/src/kernel/tqtextlayout.cpp
new file mode 100644
index 0000000..1a007a8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtextlayout.cpp
@@ -0,0 +1,818 @@
+/****************************************************************************
+**
+** ???
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <tqtglobaldefines.h>
+// Nasty, nasty horrid HACK to get access to QTextLine's private members
+// This is TERRIBLE and I wish there was a way around it
+// This is a good example of the new, broken & irritating Qt4 API,
+// and the corresponding loss in functionality versus Qt3.
+// See also tqrect.cpp
+#define private protected
+#include <Qt/qtextlayout.h>
+#undef private
+
+#include "tqtextlayout_p.h"
+#include "tqtextengine_p.h"
+
+#include <tqfont.h>
+#include <tqapplication.h>
+#include <tqpainter.h>
+
+#ifdef USE_QT4
+#include "private/qt4_qtextengine_p.h"
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+TQTextItem::TQTextItem(int line, QTextEngine *e) : QTextLine(line, e) {}
+
+// TQt internal functions
+// Do not modify unless you know what you are doing!
+QTextEngine* TQTextItem::tqt_textEngine() const {
+ return eng;
+}
+
+TQString TQTextItem::tqt_textString() const {
+ return eng->layoutData->string;
+}
+
+void TQTextItem::tqt_tqdrawTextItem( TQPainter* p, int x, int y, const TQTextItem &ti, int textFlags ) const {
+ // [FIXME] This needs serious help--it ignores the selected font, font size, etc.
+ #warning TQTextItem::tqt_tqdrawTextItem( TQPainter* p, int x, int y, const TQTextItem &ti, int textFlags ) unimplemented
+ printf("[WARNING] TQTextItem::tqt_tqdrawTextItem( TQPainter* p, int x, int y, const TQTextItem &ti, int textFlags ) partially implemented\n\r");
+
+ // Cheat!
+ TQString textToPaint = ti.tqt_textString();
+ p->save();
+ p->setFont(eng->font());
+ p->drawText( x, y, textToPaint, textToPaint.length());
+// p->drawText( x, y, TQString("BAD WOLF"), 8);
+ p->restore();
+}
+
+// End TQt internal functions
+
+// // [FIXME]
+TQTextItem TQTextLayout::nextItem() {
+ tqtl_currentItem++;
+
+ if ( tqtl_currentItem >= numItems() )
+ return TQTextItem();
+
+// d->tqshape( tqtl_currentItem );
+ return TQTextItem( tqtl_currentItem, d );
+}
+
+TQTextItem TQTextLayout::currentItem() {
+ if ( tqtl_currentItem >= numItems() )
+ return TQTextItem();
+
+// d->tqshape( tqtl_currentItem );
+ return TQTextItem( tqtl_currentItem, d );
+}
+
+bool TQTextItem::isRightToLeft() const
+{
+// if (textDirection() == Qt::RightToLeft) {
+// return true;
+// }
+// else {
+// return false;
+// }
+ printf("[WARNING] bool TQTextItem::isRightToLeft() const unimplemented\n\r");
+ return false;
+}
+
+bool TQTextItem::isObject() const
+{
+ printf("[WARNING] bool TQTextItem::isObject() const unimplemented\n\r");
+ return false;
+}
+
+bool TQTextItem::isSpace() const
+{
+ printf("[WARNING] bool TQTextItem::isSpace() const unimplemented\n\r");
+ return false;
+}
+
+bool TQTextItem::isTab() const
+{
+ printf("[WARNING] bool TQTextItem::isTab() const unimplemented\n\r");
+ return false;
+}
+
+int TQTextLayout::availableWidth() const
+{
+ return tqtl_lineWidth - tqtl_widthUsed;
+}
+
+int TQTextItem::from() const
+{
+// return engine->items[item].position;
+ return textStart();
+
+// printf("[WARNING] int TQTextItem::from() const unimplemented\n\r");
+// return 0;
+}
+
+int TQTextItem::length() const
+{
+// return engine->length(item);
+ return textLength();
+
+// printf("[WARNING] int TQTextItem::length() const unimplemented\n\r");
+// return 0;
+}
+
+void TQTextLayout::beginLine( int width ) {
+ tqtl_widthUsed = 0;
+ tqtl_lineWidth = width;
+ QTextLine line = createLine();
+ tqtl_currentItem = numItems() - 1;
+ line.setLineWidth(width);
+}
+
+bool TQTextLayout::atEnd() const
+{
+ return tqtl_currentItem >= numItems();
+}
+
+int TQTextLayout::widthUsed() {
+ return tqtl_widthUsed;
+}
+
+TQTextLayout::Result TQTextLayout::addCurrentItem() {
+ if (currentItem().isValid()) {
+ tqtl_widthUsed = currentItem().naturalTextWidth();
+ }
+ else {
+ tqtl_widthUsed = 0;
+ }
+ tqtl_currentItem++;
+ printf("[WARNING] TextLayout::Result TQTextLayout::addCurrentItem() partially implemented -- some of its functionality has been moved to beginLine()\n\r");
+ return Ok;
+// return (tqtl_widthUsed <= tqtl_lineWidth || (tqtl_currentItem < d->items.size() && d->items[tqtl_currentItem].isSpace)) ? Ok : LineFull;
+}
+
+TQTextLayout::Result TQTextLayout::endLine( int x, int y, int tqalignment, int *ascent, int *descent, int *lineLeft, int *lineRight )
+{
+// [FIXME] This crashes...
+// QTextLine line = itemAt(tqtl_currentItem);
+// line.setPosition(QPointF(x,y));
+// TQ_UNUSED(tqalignment);
+// TQ_UNUSED(ascent);
+// TQ_UNUSED(descent);
+// TQ_UNUSED(lineLeft);
+// TQ_UNUSED(lineRight);
+
+ TQ_UNUSED(x);
+ TQ_UNUSED(y);
+ TQ_UNUSED(tqalignment);
+ TQ_UNUSED(ascent);
+ TQ_UNUSED(descent);
+ TQ_UNUSED(lineLeft);
+ TQ_UNUSED(lineRight);
+ // tqtl_currentItem must be dealt with here as well
+ printf("[WARNING] TQTextLayout::Result TQTextLayout::endLine( int x, int y, int tqalignment, int *ascent, int *descent, int *lineLeft, int *lineRight ) unimplemented\n\r");
+ return Ok;
+}
+
+void TQTextLayout::setDirection(TQChar::Direction dir) {
+ printf("[WARNING] void TQTextLayout::setDirection(TQChar::Direction dir) unimplemented\n\r");
+}
+
+#else // USE_QT4
+
+TQRect TQTextItem::rect() const
+{
+ TQScriptItem& si = engine->items[item];
+ return TQRect( si.x, si.y, si.width, si.ascent+si.descent );
+}
+
+int TQTextItem::x() const
+{
+ return engine->items[item].x;
+}
+
+int TQTextItem::y() const
+{
+ return engine->items[item].y;
+}
+
+int TQTextItem::width() const
+{
+ return engine->items[item].width;
+}
+
+int TQTextItem::ascent() const
+{
+ return engine->items[item].ascent;
+}
+
+int TQTextItem::descent() const
+{
+ return engine->items[item].descent;
+}
+
+void TQTextItem::setWidth( int w )
+{
+ engine->items[item].width = w;
+}
+
+void TQTextItem::setAscent( int a )
+{
+ engine->items[item].ascent = a;
+}
+
+void TQTextItem::setDescent( int d )
+{
+ engine->items[item].descent = d;
+}
+
+int TQTextItem::from() const
+{
+ return engine->items[item].position;
+}
+
+int TQTextItem::length() const
+{
+ return engine->length(item);
+}
+
+
+int TQTextItem::cursorToX( int *cPos, Edge edge ) const
+{
+ int pos = *cPos;
+ TQScriptItem *si = &engine->items[item];
+
+ engine->tqshape( item );
+ advance_t *advances = engine->advances( si );
+ GlyphAttributes *glyphAttributes = engine->glyphAttributes( si );
+ unsigned short *logClusters = engine->logClusters( si );
+
+ int l = engine->length( item );
+ if ( pos > l )
+ pos = l;
+ if ( pos < 0 )
+ pos = 0;
+
+ int glyph_pos = pos == l ? si->num_glyphs : logClusters[pos];
+ if ( edge == Trailing ) {
+ // trailing edge is leading edge of next cluster
+ while ( glyph_pos < si->num_glyphs && !glyphAttributes[glyph_pos].clusterStart )
+ glyph_pos++;
+ }
+
+ int x = 0;
+ bool reverse = engine->items[item].analysis.bidiLevel % 2;
+
+ if ( reverse ) {
+ for ( int i = si->num_glyphs-1; i >= glyph_pos; i-- )
+ x += advances[i];
+ } else {
+ for ( int i = 0; i < glyph_pos; i++ )
+ x += advances[i];
+ }
+// qDebug("cursorToX: pos=%d, gpos=%d x=%d", pos, glyph_pos, x );
+ *cPos = pos;
+ return x;
+}
+
+int TQTextItem::xToCursor( int x, CursorPosition cpos ) const
+{
+ TQScriptItem *si = &engine->items[item];
+ engine->tqshape( item );
+ advance_t *advances = engine->advances( si );
+ unsigned short *logClusters = engine->logClusters( si );
+
+ int l = engine->length( item );
+ bool reverse = si->analysis.bidiLevel % 2;
+ if ( x < 0 )
+ return reverse ? l : 0;
+
+
+ if ( reverse ) {
+ int width = 0;
+ for ( int i = 0; i < si->num_glyphs; i++ ) {
+ width += advances[i];
+ }
+ x = -x + width;
+ }
+ int cp_before = 0;
+ int cp_after = 0;
+ int x_before = 0;
+ int x_after = 0;
+
+ int lastCluster = 0;
+ for ( int i = 1; i <= l; i++ ) {
+ int newCluster = i < l ? logClusters[i] : si->num_glyphs;
+ if ( newCluster != lastCluster ) {
+ // calculate cluster width
+ cp_before = cp_after;
+ x_before = x_after;
+ cp_after = i;
+ for ( int j = lastCluster; j < newCluster; j++ )
+ x_after += advances[j];
+ // qDebug("cluster boundary: lastCluster=%d, newCluster=%d, x_before=%d, x_after=%d",
+ // lastCluster, newCluster, x_before, x_after );
+ if ( x_after > x )
+ break;
+ lastCluster = newCluster;
+ }
+ }
+
+ bool before = ( cpos == OnCharacters || (x - x_before) < (x_after - x) );
+
+// qDebug("got cursor position for %d: %d/%d, x_ba=%d/%d using %d",
+// x, cp_before,cp_after, x_before, x_after, before ? cp_before : cp_after );
+
+ return before ? cp_before : cp_after;
+
+}
+
+
+bool TQTextItem::isRightToLeft() const
+{
+ return (engine->items[item].analysis.bidiLevel % 2);
+}
+
+bool TQTextItem::isObject() const
+{
+ return engine->items[item].isObject;
+}
+
+bool TQTextItem::isSpace() const
+{
+ return engine->items[item].isSpace;
+}
+
+bool TQTextItem::isTab() const
+{
+ return engine->items[item].isTab;
+}
+
+TQTextLayout::TQTextLayout()
+ :d(0) {}
+
+TQTextLayout::TQTextLayout( const TQString& string, TQPainter *p )
+{
+ TQFontPrivate *f = p ? ( p->pfont ? p->pfont->d : p->cfont.d ) : TQApplication::font().d;
+ d = new TQTextEngine( (string.isNull() ? (const TQString&)TQString::tqfromLatin1("") : string), f );
+}
+
+TQTextLayout::TQTextLayout( const TQString& string, const TQFont& fnt )
+{
+ d = new TQTextEngine( (string.isNull() ? (const TQString&)TQString::tqfromLatin1("") : string), fnt.d );
+}
+
+TQTextLayout::~TQTextLayout()
+{
+ delete d;
+}
+
+void TQTextLayout::setText( const TQString& string, const TQFont& fnt )
+{
+ delete d;
+ d = new TQTextEngine( (string.isNull() ? (const TQString&)TQString::tqfromLatin1("") : string), fnt.d );
+}
+
+/* add an additional item boundary eg. for style change */
+void TQTextLayout::setBoundary( int strPos )
+{
+ if ( strPos <= 0 || strPos >= (int)d->string.length() )
+ return;
+
+ int itemToSplit = 0;
+ while ( itemToSplit < d->items.size() && d->items[itemToSplit].position <= strPos )
+ itemToSplit++;
+ itemToSplit--;
+ if ( d->items[itemToSplit].position == strPos ) {
+ // already a split at the requested position
+ return;
+ }
+ d->splitItem( itemToSplit, strPos - d->items[itemToSplit].position );
+}
+
+
+int TQTextLayout::numItems() const
+{
+ return d->items.size();
+}
+
+TQTextItem TQTextLayout::itemAt( int i ) const
+{
+ return TQTextItem( i, d );
+}
+
+
+TQTextItem TQTextLayout::tqfindItem( int strPos ) const
+{
+ if ( strPos == 0 && d->items.size() )
+ return TQTextItem( 0, d );
+ // ## TODO use bsearch
+ for ( int i = d->items.size()-1; i >= 0; --i ) {
+ if ( d->items[i].position < strPos )
+ return TQTextItem( i, d );
+ }
+ return TQTextItem();
+}
+
+
+void TQTextLayout::beginLayout( TQTextLayout::LayoutMode m )
+{
+ d->items.clear();
+ TQTextEngine::Mode mode = TQTextEngine::Full;
+ if (m == NoBidi)
+ mode = TQTextEngine::NoBidi;
+ else if (m == SingleLine)
+ mode = TQTextEngine::SingleLine;
+ d->itemize( mode );
+ d->currentItem = 0;
+ d->firstItemInLine = -1;
+}
+
+void TQTextLayout::beginLine( int width )
+{
+ d->lineWidth = width;
+ d->widthUsed = 0;
+ d->firstItemInLine = -1;
+}
+
+bool TQTextLayout::atEnd() const
+{
+ return d->currentItem >= d->items.size();
+}
+
+TQTextItem TQTextLayout::nextItem()
+{
+ d->currentItem++;
+
+ if ( d->currentItem >= d->items.size() )
+ return TQTextItem();
+
+ d->tqshape( d->currentItem );
+ return TQTextItem( d->currentItem, d );
+}
+
+TQTextItem TQTextLayout::currentItem()
+{
+ if ( d->currentItem >= d->items.size() )
+ return TQTextItem();
+
+ d->tqshape( d->currentItem );
+ return TQTextItem( d->currentItem, d );
+}
+
+/* ## maybe also currentItem() */
+void TQTextLayout::setLineWidth( int newWidth )
+{
+ d->lineWidth = newWidth;
+}
+
+int TQTextLayout::lineWidth() const
+{
+ return d->lineWidth;
+}
+
+int TQTextLayout::widthUsed() const
+{
+ return d->widthUsed;
+}
+
+int TQTextLayout::availableWidth() const
+{
+ return d->lineWidth - d->widthUsed;
+}
+
+
+/* returns true if completely added */
+TQTextLayout::Result TQTextLayout::addCurrentItem()
+{
+ if ( d->firstItemInLine == -1 )
+ d->firstItemInLine = d->currentItem;
+ TQScriptItem &current = d->items[d->currentItem];
+ d->tqshape( d->currentItem );
+ d->widthUsed += current.width;
+// qDebug("trying to add item %d with width %d, remaining %d", d->currentItem, current.width, d->lineWidth-d->widthUsed );
+
+ d->currentItem++;
+
+ return (d->widthUsed <= d->lineWidth
+ || (d->currentItem < d->items.size() && d->items[d->currentItem].isSpace)) ? Ok : LineFull;
+}
+
+TQTextLayout::Result TQTextLayout::endLine( int x, int y, int tqalignment,
+ int *ascent, int *descent, int *lineLeft, int *lineRight )
+{
+ int available = d->lineWidth;
+ int numRuns = 0;
+ int numSpaceItems = 0;
+ TQ_UINT8 _levels[128];
+ int _visual[128];
+ TQ_UINT8 *levels = _levels;
+ int *visual = _visual;
+ int i;
+ TQTextLayout::Result result = LineEmpty;
+
+// qDebug("endLine x=%d, y=%d, first=%d, current=%d lw=%d wu=%d", x, y, d->firstItemInLine, d->currentItem, d->lineWidth, d->widthUsed );
+ int width_nobreak_found = d->widthUsed;
+ if ( d->firstItemInLine == -1 )
+ goto end;
+
+ if ( !(tqalignment & (TQt::SingleLine|TQt::IncludeTrailingSpaces))
+ && d->currentItem > d->firstItemInLine && d->items[d->currentItem-1].isSpace ) {
+ int i = d->currentItem-1;
+ while ( i > d->firstItemInLine && d->items[i].isSpace ) {
+ numSpaceItems++;
+ d->widthUsed -= d->items[i--].width;
+ }
+ }
+
+ if ( (tqalignment & (TQt::WordBreak|TQt::BreakAnywhere)) &&
+ d->widthUsed > d->lineWidth ) {
+ // tqfind linebreak
+
+ // even though we removed trailing spaces the line was too wide. We'll have to break at an earlier
+ // position. To not confuse the layouting below, reset the number of space items
+ numSpaceItems = 0;
+
+
+ bool breakany = tqalignment & TQt::BreakAnywhere;
+
+ const TQCharAttributes *attrs = d->attributes();
+ int w = 0;
+ int itemWidth = 0;
+ int breakItem = d->firstItemInLine;
+ int breakPosition = -1;
+#if 0
+ // we iterate backwards or forward depending on what we guess is closer
+ if ( d->widthUsed - d->lineWidth < d->lineWidth ) {
+ // backwards search should be faster
+
+ } else
+#endif
+ {
+ int tmpWidth = 0;
+ int swidth = 0;
+ // forward search is probably faster
+ for ( int i = d->firstItemInLine; i < d->currentItem; i++ ) {
+ const TQScriptItem *si = &d->items[i];
+ int length = d->length( i );
+ const TQCharAttributes *itemAttrs = attrs + si->position;
+
+ advance_t *advances = d->advances( si );
+ unsigned short *logClusters = d->logClusters( si );
+
+ int lastGlyph = 0;
+ int tmpItemWidth = 0;
+
+// qDebug("looking for break in item %d, isSpace=%d", i, si->isSpace );
+ if(si->isSpace && !(tqalignment & (TQt::SingleLine|TQt::IncludeTrailingSpaces))) {
+ swidth += si->width;
+ } else {
+ tmpWidth += swidth;
+ swidth = 0;
+ for ( int pos = 0; pos < length; pos++ ) {
+// qDebug("advance=%d, w=%d, tmpWidth=%d, softbreak=%d, whitespace=%d",
+// *advances, w, tmpWidth, itemAttrs->softBreak, itemAttrs->whiteSpace );
+ int glyph = logClusters[pos];
+ if ( lastGlyph != glyph ) {
+ while ( lastGlyph < glyph )
+ tmpItemWidth += advances[lastGlyph++];
+ if ( breakPosition != -1 && w + tmpWidth + tmpItemWidth > d->lineWidth ) {
+// qDebug("found break at w=%d, tmpWidth=%d, tmpItemWidth=%d", w, tmpWidth, tmpItemWidth);
+ d->widthUsed = w;
+ goto found;
+ }
+ }
+ if ( (itemAttrs->softBreak ||
+ ( breakany && itemAttrs->charStop ) ) &&
+ (i != d->firstItemInLine || pos != 0) ) {
+ if ( breakItem != i )
+ itemWidth = 0;
+ if (itemAttrs->softBreak)
+ breakany = FALSE;
+ breakItem = i;
+ breakPosition = pos;
+// qDebug("found possible break at item %d, position %d (absolute=%d), w=%d, tmpWidth=%d, tmpItemWidth=%d", breakItem, breakPosition, d->items[breakItem].position+breakPosition, w, tmpWidth, tmpItemWidth);
+ w += tmpWidth + tmpItemWidth;
+ itemWidth += tmpItemWidth;
+ tmpWidth = 0;
+ tmpItemWidth = 0;
+ }
+ itemAttrs++;
+ }
+ while ( lastGlyph < si->num_glyphs )
+ tmpItemWidth += advances[lastGlyph++];
+ tmpWidth += tmpItemWidth;
+ if ( w + tmpWidth > d->lineWidth ) {
+ d->widthUsed = w;
+ goto found;
+ }
+ }
+ }
+ }
+
+ found:
+ // no valid break point found
+ if ( breakPosition == -1 ) {
+ d->widthUsed = width_nobreak_found;
+ goto nobreak;
+ }
+
+// qDebug("linebreak at item %d, position %d, wu=%d", breakItem, breakPosition, d->widthUsed );
+ // split the line
+ if ( breakPosition > 0 ) {
+// int length = d->length( breakItem );
+
+// qDebug("splitting item, itemWidth=%d", itemWidth);
+ // not a full item, need to break
+ d->splitItem( breakItem, breakPosition );
+ d->currentItem = breakItem+1;
+ } else {
+ d->currentItem = breakItem;
+ }
+ }
+
+ result = Ok;
+
+ nobreak:
+ // position the objects in the line
+ available -= d->widthUsed;
+
+ numRuns = d->currentItem - d->firstItemInLine - numSpaceItems;
+ if ( numRuns > 127 ) {
+ levels = new TQ_UINT8[numRuns];
+ visual = new int[numRuns];
+ }
+
+// qDebug("reordering %d runs, numSpaceItems=%d", numRuns, numSpaceItems );
+ for ( i = 0; i < numRuns; i++ ) {
+ levels[i] = d->items[i+d->firstItemInLine].analysis.bidiLevel;
+// qDebug(" level = %d", d->items[i+d->firstItemInLine].analysis.bidiLevel );
+ }
+ d->bidiReorder( numRuns, levels, visual );
+
+ end:
+ // ### FIXME
+ if ( tqalignment & TQt::AlignJustify ) {
+ // #### justify items
+ tqalignment = TQt::AlignAuto;
+ }
+ if ( (tqalignment & TQt::AlignHorizontal_Mask) == TQt::AlignAuto )
+ tqalignment = TQt::AlignLeft;
+ if ( tqalignment & TQt::AlignRight )
+ x += available;
+ else if ( tqalignment & TQt::AlignHCenter )
+ x += available/2;
+
+
+ int asc = ascent ? *ascent : 0;
+ int desc = descent ? *descent : 0;
+
+ for ( i = 0; i < numRuns; i++ ) {
+ TQScriptItem &si = d->items[d->firstItemInLine+visual[i]];
+ asc = TQMAX( asc, si.ascent );
+ desc = TQMAX( desc, si.descent );
+ }
+
+ int left = x;
+ for ( i = 0; i < numRuns; i++ ) {
+ TQScriptItem &si = d->items[d->firstItemInLine+visual[i]];
+// qDebug("positioning item %d with width %d (from=%d/length=%d) at %d", d->firstItemInLine+visual[i], si.width, si.position,
+// d->length(d->firstItemInLine+visual[i]), x );
+ si.x = x;
+ si.y = y + asc;
+ x += si.width;
+ }
+ int right = x;
+
+ if ( numSpaceItems ) {
+ if ( d->items[d->firstItemInLine+numRuns].analysis.bidiLevel % 2 ) {
+ x = left;
+ for ( i = 0; i < numSpaceItems; i++ ) {
+ TQScriptItem &si = d->items[d->firstItemInLine + numRuns + i];
+ x -= si.width;
+ si.x = x;
+ si.y = y + asc;
+ }
+ } else {
+ for ( i = 0; i < numSpaceItems; i++ ) {
+ TQScriptItem &si = d->items[d->firstItemInLine + numRuns + i];
+ si.x = x;
+ si.y = y + asc;
+ x += si.width;
+ }
+ }
+ }
+
+ if ( lineLeft )
+ *lineLeft = left;
+ if ( lineRight )
+ *lineRight = right;
+ if ( ascent )
+ *ascent = asc;
+ if ( descent )
+ *descent = desc;
+
+ if (levels != _levels)
+ delete []levels;
+ if (visual != _visual)
+ delete []visual;
+
+ return result;
+}
+
+void TQTextLayout::endLayout()
+{
+ // nothing to do currently
+}
+
+
+int TQTextLayout::nextCursorPosition( int oldPos, CursorMode mode ) const
+{
+// qDebug("looking for next cursor pos for %d", oldPos );
+ const TQCharAttributes *attributes = d->attributes();
+ int len = d->string.length();
+ if ( oldPos >= len )
+ return oldPos;
+ oldPos++;
+ if ( mode == SkipCharacters ) {
+ while ( oldPos < len && !attributes[oldPos].charStop )
+ oldPos++;
+ } else {
+ while ( oldPos < len && !attributes[oldPos].wordStop && !attributes[oldPos-1].whiteSpace )
+ oldPos++;
+ }
+// qDebug(" -> %d", oldPos );
+ return oldPos;
+}
+
+int TQTextLayout::previousCursorPosition( int oldPos, CursorMode mode ) const
+{
+// qDebug("looking for previous cursor pos for %d", oldPos );
+ const TQCharAttributes *attributes = d->attributes();
+ if ( oldPos <= 0 )
+ return 0;
+ oldPos--;
+ if ( mode == SkipCharacters ) {
+ while ( oldPos && !attributes[oldPos].charStop )
+ oldPos--;
+ } else {
+ while ( oldPos && !attributes[oldPos].wordStop && !attributes[oldPos-1].whiteSpace )
+ oldPos--;
+ }
+// qDebug(" -> %d", oldPos );
+ return oldPos;
+}
+
+
+bool TQTextLayout::validCursorPosition( int pos ) const
+{
+ const TQCharAttributes *attributes = d->attributes();
+ if ( pos < 0 || pos > (int)d->string.length() )
+ return FALSE;
+ return attributes[pos].charStop;
+}
+
+void TQTextLayout::setDirection(TQChar::Direction dir)
+{
+ d->direction = dir;
+}
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqtextlayout_p.h b/tqtinterface/qt4/src/kernel/tqtextlayout_p.h
new file mode 100644
index 0000000..049ede2
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtextlayout_p.h
@@ -0,0 +1,300 @@
+/****************************************************************************
+**
+** ???
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQTEXTLAYOUT_P_H
+#define TQTEXTLAYOUT_P_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqstring.h"
+#include "tqnamespace.h"
+#include "tqrect.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include "tqfont.h"
+#include <Qt/qpaintengine.h>
+#include <Qt/qtextlayout.h>
+
+#endif // USE_QT4
+
+class TQTextEngine;
+class TQFont;
+
+// [FIXME]
+// Due to the absence of a font engine, we MUST inherit something from Qt4, as we therefore cannot directly implement the old QTextItem class!
+// [FIXME]
+
+#ifdef USE_QT4
+
+#define BetweenCharacters CursorBetweenCharacters
+#define OnCharacters CursorOnCharacter
+
+class TQ_EXPORT TQTextItem : public QTextLine, virtual public TQt
+{
+public:
+ TQTextItem() : QTextLine() {}
+
+ bool isRightToLeft() const;
+ bool isObject() const;
+ bool isSpace() const;
+ bool isTab() const;
+
+ int from() const;
+ int length() const;
+
+ inline TQRect tqrect() const { return TQRect(rect().left(), rect().top(), rect().width(), rect().height()); }
+
+private:
+ TQTextItem(int line, QTextEngine *e);
+ QTextEngine* tqt_textEngine() const;
+ TQString tqt_textString() const;
+ void tqt_tqdrawTextItem( TQPainter* p, int x, int y, const TQTextItem &ti, int textFlags ) const;
+ friend class TQTextLayout;
+ friend class TQPainter;
+
+public:
+ // Interoperability
+ static const TQTextItem& convertFromQTextLine( QTextLine& qtl );
+};
+
+// Interoperability
+inline static const TQTextItem& convertFromQTextLine( const QTextLine& qtl ) {
+ return (*static_cast<const TQTextItem*>(&qtl));
+}
+
+#else // USE_QT4
+
+class TQ_EXPORT TQTextItem
+{
+public:
+ inline TQTextItem() : item(0), engine(0) {}
+ inline bool isValid() const { return (bool)engine; }
+
+ TQRect rect() const;
+ int x() const;
+ int y() const;
+ int width() const;
+ int ascent() const;
+ int descent() const;
+
+ enum Edge {
+ Leading,
+ Trailing
+ };
+ enum CursorPosition {
+ BetweenCharacters,
+ OnCharacters
+ };
+
+ /* cPos gets set to the valid position */
+ int cursorToX( int *cPos, Edge edge = Leading ) const;
+ inline int cursorToX( int cPos, Edge edge = Leading ) const { return cursorToX( &cPos, edge ); }
+ int xToCursor( int x, CursorPosition = BetweenCharacters ) const;
+
+ bool isRightToLeft() const;
+ bool isObject() const;
+ bool isSpace() const;
+ bool isTab() const;
+
+ void setWidth( int w );
+ void setAscent( int a );
+ void setDescent( int d );
+
+ int from() const;
+ int length() const;
+
+private:
+ friend class TQTextLayout;
+ friend class TQPainter;
+ friend class TQPSPrinter;
+ TQTextItem( int i, TQTextEngine *e ) : item( i ), engine( e ) {}
+ int item;
+ TQTextEngine *engine;
+};
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQTextLayout : public QTextLayout, virtual public TQt
+{
+public:
+ TQTextLayout() : QTextLayout() {}
+ TQTextLayout( const QString& string, QPainter *p = 0 ) : QTextLayout(string, QFont(), p->device()) {}
+ TQTextLayout( const TQString& string, const TQFont& fnt ) : QTextLayout(string, convertFromQFont(fnt)) {}
+
+ enum LayoutMode {
+ NoBidi,
+ SingleLine,
+ MultiLine
+ };
+
+ enum LineBreakStrategy {
+ AtWordBoundaries,
+ AtCharBoundaries
+ };
+
+ enum Result {
+ Ok,
+ LineFull,
+ LineEmpty,
+ Error
+ };
+ Result addCurrentItem();
+ Result endLine( int x = 0, int y = 0, int tqalignment = TQt::AlignLeft, int *ascent = 0, int *descent = 0, int *left = 0, int *right = 0 );
+
+ int numItems() const { return lineCount(); }
+ TQTextItem itemAt( int i ) const { return convertFromQTextLine(lineAt(i)); }
+ TQTextItem tqfindItem( int strPos ) const { return convertFromQTextLine(lineForTextPosition(strPos)); }
+ bool atEnd() const;
+ TQTextItem nextItem();
+ TQTextItem currentItem();
+
+ inline void setLineWidth( int newWidth ) { tqtl_lineWidth = newWidth; currentItem().setLineWidth(newWidth); }
+ inline int lineWidth() { return tqtl_lineWidth; }
+ int widthUsed();
+ int availableWidth() const;
+
+ void beginLine( int width );
+
+ inline void beginLayout() { tqtl_currentItem = 0; return QTextLayout::beginLayout(); }
+ inline void beginLayout( LayoutMode m ) { TQ_UNUSED(m); tqtl_currentItem = 0; return QTextLayout::beginLayout(); }
+
+ inline void setText( const QString& string ) { QTextLayout::setText(string); }
+ inline void setText( const TQString& string, const TQFont& fnt ) { QTextLayout::setText(string); QTextLayout::setFont(fnt); }
+
+ void setDirection(TQChar::Direction);
+
+private:
+ int tqtl_currentItem;
+ int tqtl_widthUsed;
+ int tqtl_lineWidth;
+};
+
+#else // USE_QT4
+
+class TQPainter;
+
+class TQ_EXPORT TQTextLayout
+{
+public:
+ // does itemization
+ TQTextLayout();
+ TQTextLayout( const TQString& string, TQPainter * = 0 );
+ TQTextLayout( const TQString& string, const TQFont& fnt );
+ ~TQTextLayout();
+
+ void setText( const TQString& string, const TQFont& fnt );
+
+ enum LineBreakStrategy {
+ AtWordBoundaries,
+ AtCharBoundaries
+ };
+
+ /* add an additional item boundary eg. for style change */
+ void setBoundary( int strPos );
+
+ int numItems() const;
+ TQTextItem itemAt( int i ) const;
+ TQTextItem tqfindItem( int strPos ) const;
+
+ enum LayoutMode {
+ NoBidi,
+ SingleLine,
+ MultiLine
+ };
+ void beginLayout( LayoutMode m = MultiLine );
+ void beginLine( int width );
+
+ bool atEnd() const;
+ TQTextItem nextItem();
+ TQTextItem currentItem();
+ /* ## maybe also currentItem() */
+ void setLineWidth( int newWidth );
+ int lineWidth() const;
+ int widthUsed() const;
+ int availableWidth() const;
+
+ enum Result {
+ Ok,
+ LineFull,
+ LineEmpty,
+ Error
+ };
+ /* returns true if completely added */
+ Result addCurrentItem();
+
+ /* Note: if ascent and descent are used they must be initialized to the minimum ascent/descent
+ acceptable for the line. TQFontMetrics::ascent/descent() is usually the right choice */
+ Result endLine( int x = 0, int y = 0, int tqalignment = TQt::AlignLeft,
+ int *ascent = 0, int *descent = 0, int *left = 0, int *right = 0 );
+ void endLayout();
+
+ enum CursorMode {
+ SkipCharacters,
+ SkipWords
+ };
+ bool validCursorPosition( int pos ) const;
+ int nextCursorPosition( int oldPos, CursorMode mode = SkipCharacters ) const;
+ int previousCursorPosition( int oldPos, CursorMode mode = SkipCharacters ) const;
+
+ void setDirection(TQChar::Direction);
+private:
+ TQTextLayout( TQTextEngine *e ) : d( e ) {}
+ /* disable copy and assignment */
+ TQTextLayout( const TQTextLayout & ) {}
+ void operator = ( const TQTextLayout & ) {}
+
+ friend class TQTextItem;
+ friend class TQPainter;
+ friend class TQPSPrinter;
+ TQTextEngine *d;
+};
+
+
+/*
+ class TQPainter {
+ .....
+ void tqdrawTextItem( int x, int y, TQTextItem *item );
+ };
+*/
+
+#endif // USE_QT4
+
+#endif \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqtglobaldefines.h b/tqtinterface/qt4/src/kernel/tqtglobaldefines.h
new file mode 100644
index 0000000..7fc3168
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtglobaldefines.h
@@ -0,0 +1,502 @@
+#ifndef TQTGLOBALDEFINES_H
+#define TQTGLOBALDEFINES_H
+
+#include "tqtglobalsettings.h"
+
+// #ifdef USE_QT4
+// #define QT3_SUPPORT
+// #endif
+//
+#ifdef USE_QT4
+
+#include <Qt/qglobal.h>
+#include <Qt/qnamespace.h>
+#include <Qt/qobjectdefs.h>
+
+#ifdef QT_NO_TRANSLATION
+#define TQT_NO_TRANSLATION
+#endif // QT_NO_TRANSLATION
+
+#ifdef QT_THREAD_SUPPORT
+#define TQT_THREAD_SUPPORT
+#endif // QT_THREAD_SUPPORT
+
+// #define tqqt_cast qobject_cast
+
+// Mark certain Qt3 static variables squarely OFF LIMITS
+#define qt_x_time "Usage of the qt_x_time static variable is strongly deprecated in TQt, and is unavailable in TQt for Qt4. Use GET_QT_X_TIME/SET_QT_X_TIME instead"
+#define qt_x_user_time "Usage of the qt_x_time static variable is strongly deprecated in TQt, and is unavailable in TQt for Qt4. Use GET_QT_X_USER_TIME/SET_QT_X_USER_TIME instead"
+
+// #define TQT_TQOBJECT(x) (static_cast<TQObject*>(static_cast<TQT_BASE_OBJECT_NAME*>(x)))
+#define TQT_TQOBJECT(x) (convertFromTQT_BASE_OBJECT_NAMEPointer(x))
+#define TQT_TQWIDGET(x) TQWidget::tqt_ensure_valid_widget_painting(static_cast<TQWidget*>(static_cast<QWidget*>(static_cast<TQT_BASE_OBJECT_NAME*>(x))))
+#define TQT_TQSIZEPOLICY(x) (static_cast<TQSizePolicy*>(static_cast<QSizePolicy*>(x)))
+#define TQT_TQLAYOUT(x) (static_cast<TQLayout*>(static_cast<QLayout*>(x)))
+#define TQT_TQGRIDLAYOUT(x) (static_cast<TQGridLayout*>(static_cast<QGridLayout*>(x)))
+#define TQT_TQPAINTER(x) (static_cast<TQPainter*>(static_cast<QPainter*>(x)))
+#define TQT_TQPAINTDEVICE(x) (static_cast<TQPaintDevice*>(static_cast<QPaintDevice*>(x)))
+#define TQT_TQLAYOUTITEM(x) (static_cast<TQLayoutItem*>(static_cast<QLayoutItem*>(x)))
+#define TQT_TQIODEVICE(x) (static_cast<TQIODevice*>(static_cast<QIODevice*>(x)))
+#define TQT_TQCOLOR(x) (static_cast<TQColor*>(static_cast<QColor*>(x)))
+#define TQT_TQCHAR(x) TQChar(x)
+#define TQT_TQSTRING(x) TQString(x)
+#define TQT_TQPOINT(x) (static_cast<TQPoint*>(static_cast<QPoint*>(x)))
+#define TQT_TQBUFFER(x) (static_cast<TQBuffer*>(static_cast<QBuffer*>(x)))
+#define TQT_TQWMATRIX(x) (static_cast<TQWMatrix*>(static_cast<QMatrix*>(x)))
+#define TQT_TQFILE(x) (static_cast<TQFile*>(static_cast<QFile*>(x)))
+#define TQT_TQBYTEARRAY(x) (static_cast<TQByteArray*>(static_cast<QByteArray*>(x)))
+#define TQT_TQMIMESOURCE(x) (static_cast<TQMimeSource*>(static_cast<QMimeSource*>(x)))
+#define TQT_TQWEXTRA(x) (static_cast<TQWExtra*>(static_cast<QWExtra*>(x)))
+#define TQT_TQPIXMAP(x) (static_cast<TQPixmap*>(static_cast<QPixmap*>(x)))
+#define TQT_TQCLIPBOARD(x) (static_cast<TQClipboard*>(static_cast<QClipboard*>(x)))
+#define TQT_TQPRINTER(x) (static_cast<TQPrinter*>(static_cast<QPrinter*>(x)))
+#define TQT_TQVARIANT(x) (static_cast<TQVariant*>(static_cast<QVariant*>(x)))
+#define TQT_TQMETAOBJECT(x) (static_cast<TQMetaObject*>(static_cast<QMetaObject*>(x)))
+#define TQT_TQSTYLEOPTION(x) (static_cast<TQStyleOption*>(static_cast<TQStyleOption*>(x)))
+#define TQT_TQEVENT(x) (static_cast<TQEvent*>(static_cast<QEvent*>(x)))
+#define TQT_TQKEYEVENT(x) (static_cast<TQKeyEvent*>(static_cast<QKeyEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQMOVEEVENT(x) (static_cast<TQMoveEvent*>(static_cast<QMoveEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQSHOWEVENT(x) (static_cast<TQShowEvent*>(static_cast<QShowEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQMOUSEEVENT(x) (static_cast<TQMouseEvent*>(static_cast<QMouseEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQWHEELEVENT(x) (static_cast<TQWheelEvent*>(static_cast<QWheelEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQFOCUSEVENT(x) (static_cast<TQFocusEvent*>(static_cast<QFocusEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQPAINTEVENT(x) (static_cast<TQPaintEvent*>(static_cast<QPaintEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQCHILDEVENT(x) (static_cast<TQChildEvent*>(static_cast<QChildEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQCLOSEEVENT(x) (static_cast<TQCloseEvent*>(static_cast<QCloseEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQTIMEREVENT(x) (static_cast<TQTimerEvent*>(static_cast<QTimerEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQRESIZEEVENT(x) (static_cast<TQResizeEvent*>(static_cast<QResizeEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQTABLETEVENT(x) (static_cast<TQTabletEvent*>(static_cast<QTabletEvent*>(static_cast<QEvent*>(x))))
+#define TQT_TQCONTEXTMENUEVENT(x) (static_cast<TQContextMenuEvent*>(static_cast<QContextMenuEvent*>(static_cast<QEvent*>(x))))
+
+#define TQT_TQOBJECT_OBJECT(x) (convertFromTQT_BASE_OBJECT_NAME(x))
+#define TQT_TQSIZEPOLICY_OBJECT(x) (convertFromQSizePolicy(x))
+#define TQT_TQLAYOUT_OBJECT(x) (convertFromQLayout(x))
+#define TQT_TQCOLOR_OBJECT(x) (convertFromQColor(x))
+#define TQT_TQSTRING_OBJECT(x) (convertFromQString(x))
+#define TQT_TQSTRLIST_OBJECT(x) (convertFromQStrList(x))
+#define TQT_TQSTRINGLIST_OBJECT(x) (TQStringList::convertFromQStringList(x))
+#define TQT_TQWMATRIX_OBJECT(x) (convertFromQMatrix(x))
+#define TQT_TQRECT_OBJECT(x) TQRect(x)
+#define TQT_TQBYTEARRAY_OBJECT(x) (convertFromQByteArray(x))
+#define TQT_TQPIXMAP_OBJECT(x) (convertFromQPixmap(x))
+#define TQT_TQTIME_OBJECT(x) (TQTime::convertFromQTime(x))
+#define TQT_TQDATE_OBJECT(x) (TQDate::convertFromQDate(x))
+#define TQT_TQDATETIME_OBJECT(x) (TQDateTime::convertFromQDateTime(x))
+#define TQT_TQBRUSH_OBJECT(x) (convertFromQBrush(x))
+#define TQT_TQPALETTE_OBJECT(x) (convertFromQPalette(x))
+#define TQT_TQPOINT_OBJECT(x) (convertFromQPoint(x))
+#define TQT_TQREGION_OBJECT(x) (convertFromQRegion(x))
+#define TQT_TQIMAGE_OBJECT(x) (convertFromQImage(x))
+#define TQT_TQPAINTDEVICE_OBJECT(x) (convertFromQPaintDevice(x))
+#define TQT_TQVARIANT_OBJECT(x) (convertFromQVariant(x))
+#define TQT_TQIODEVICE_OBJECT(x) (convertFromQIODevice(x))
+#define TQT_TQSESSIONMANAGER_OBJECT(x) (convertFromQSessionManager(x))
+#define TQT_TQSTYLEOPTION_OBJECT(x) (TQStyleOption(x))
+
+// #define TQT_TQOBJECT_CONST(x) (static_cast<const TQObject*>(static_cast<const TQT_BASE_OBJECT_NAME*>(x)))
+#define TQT_TQOBJECT_CONST(x) (convertFromTQT_BASE_OBJECT_NAMEPointerConst(x))
+#define TQT_TQWIDGET_CONST(x) (static_cast<const TQWidget*>(static_cast<const QWidget*>(static_cast<const TQT_BASE_OBJECT_NAME*>(x))))
+#define TQT_TQMIMESOURCE_CONST(x) (static_cast<const TQMimeSource*>(static_cast<const QMimeSource*>(x)))
+#define TQT_TQPOINT_CONST(x) (static_cast<const TQPoint*>(static_cast<const QPoint*>(x)))
+#define TQT_TQBRUSH_CONST(x) (static_cast<const TQBrush*>(static_cast<const QBrush*>(x)))
+#define TQT_TQPIXMAP_CONST(x) (static_cast<const TQPixmap*>(static_cast<const QPixmap*>(x)))
+#define TQT_TQPAINTDEVICE_CONST(x) (static_cast<const TQPaintDevice*>(static_cast<const QPaintDevice*>(x)))
+#define TQT_TQCOLOR_CONST(x) (static_cast<const TQColor*>(static_cast<const QColor*>(x)))
+#define TQT_TQPRINTER_CONST(x) (static_cast<const TQPrinter*>(static_cast<const QPrinter*>(x)))
+#define TQT_TQIODEVICE_CONST(x) (static_cast<const TQIODevice*>(static_cast<const QIODevice*>(x)))
+#define TQT_TQVARIANT_CONST(x) (static_cast<const TQVariant*>(static_cast<const QVariant*>(x)))
+#define TQT_TQMETAOBJECT_CONST(x) (static_cast<const TQMetaObject*>(static_cast<const QMetaObject*>(x)))
+#define TQT_TQSTYLEOPTION_CONST(x) (static_cast<const TQStyleOption*>(static_cast<const TQStyleOption*>(x)))
+
+#define TQPOINT_OBJECT_NAME_STRING "TQPoint"
+#define TQBYTEARRAY_OBJECT_NAME_STRING "TQByteArray"
+#define TQPIXMAP_OBJECT_NAME_STRING "TQPixmap"
+#define TQSTRING_OBJECT_NAME_STRING "TQString"
+#define TQSTRINGLIST_OBJECT_NAME_STRING "TQStringList"
+#define TQLAYOUT_OBJECT_NAME_STRING "TQLayout"
+#define TQBOXLAYOUT_OBJECT_NAME_STRING "TQBoxLayout"
+#define TQHBOXLAYOUT_OBJECT_NAME_STRING "TQHBoxLayout"
+#define TQVBOXLAYOUT_OBJECT_NAME_STRING "TQVBoxLayout"
+#define TQGRIDLAYOUT_OBJECT_NAME_STRING "TQGridLayout"
+#define TQHBOX_OBJECT_NAME_STRING "TQHBox"
+#define TQVBOX_OBJECT_NAME_STRING "TQVBox"
+#define TQGRID_OBJECT_NAME_STRING "TQGrid"
+#define TQTABWIDGET_OBJECT_NAME_STRING "TQTabWidget"
+#define TQCHECKBOX_OBJECT_NAME_STRING "TQCheckBox"
+#define TQLINEEDIT_OBJECT_NAME_STRING "TQLineEdit"
+#define TQTEXTEDIT_OBJECT_NAME_STRING "TQTextEdit"
+#define TQOBJECT_OBJECT_NAME_STRING "TQObject"
+#define TQWIDGET_OBJECT_NAME_STRING "TQWidget"
+#define TQGLWIDGET_OBJECT_NAME_STRING "TQGLWidget"
+#define TQLABEL_OBJECT_NAME_STRING "TQLabel"
+#define TQTIMER_OBJECT_NAME_STRING "TQTimer"
+#define TQFRAME_OBJECT_NAME_STRING "TQFrame"
+#define TQACCEL_OBJECT_NAME_STRING "TQAccel"
+#define TQDIALOG_OBJECT_NAME_STRING "TQDialog"
+#define TQDIAL_OBJECT_NAME_STRING "TQDial"
+#define TQACTION_OBJECT_NAME_STRING "TQAction"
+#define TQACTIONGROUP_OBJECT_NAME_STRING "TQActionGroup"
+#define TQLCDNUMBER_OBJECT_NAME_STRING "TQLCDNumber"
+#define TQPROGRESSBAR_OBJECT_NAME_STRING "TQProgressBar"
+#define TQTABDIALOG_OBJECT_NAME_STRING "TQTabDialog"
+#define TQTABWIDGET_OBJECT_NAME_STRING "TQTabWidget"
+#define TQDOCKWINDOW_OBJECT_NAME_STRING "TQDockWindow"
+#define TQGROUPBOX_OBJECT_NAME_STRING "TQGroupBox"
+#define TQCOMBOBOX_OBJECT_NAME_STRING "TQComboBox"
+#define TQSPINBOX_OBJECT_NAME_STRING "TQSpinBox"
+#define TQSPINWIDGET_OBJECT_NAME_STRING "TQSpinWidget"
+#define TQLISTBOX_OBJECT_NAME_STRING "TQListBox"
+#define TQTOOLBOX_OBJECT_NAME_STRING "TQToolBox"
+#define TQTOOLBOXBUTTON_OBJECT_NAME_STRING "TQToolBoxButton"
+#define TQVGROUPBOX_OBJECT_NAME_STRING "TQVGroupBox"
+#define TQSPLITTER_OBJECT_NAME_STRING "TQSplitter"
+#define TQSPLITTERHANDLE_OBJECT_NAME_STRING "TQSplitterHandle"
+#define TQBUTTON_OBJECT_NAME_STRING "TQButton"
+#define TQGRIDVIEW_OBJECT_NAME_STRING "TQGridView"
+#define TQSLIDER_OBJECT_NAME_STRING "TQSlider"
+#define TQPUSHBUTTON_OBJECT_NAME_STRING "TQPushButton"
+#define TQTOOLBUTTON_OBJECT_NAME_STRING "TQToolButton"
+#define TQRADIOBUTTON_OBJECT_NAME_STRING "TQRadioButton"
+#define TQPOPUPMENU_OBJECT_NAME_STRING "TQPopupMenu"
+#define TQTOOLBAR_OBJECT_NAME_STRING "TQToolBar"
+#define TQMENUBAR_OBJECT_NAME_STRING "TQMenuBar"
+#define TQTABBAR_OBJECT_NAME_STRING "TQTabBar"
+#define TQLISTVIEW_OBJECT_NAME_STRING "TQListView"
+#define TQSCROLLBAR_OBJECT_NAME_STRING "TQScrollBar"
+#define TQSCROLLVIEW_OBJECT_NAME_STRING "TQScrollView"
+#define TQRANGECONTROL_OBJECT_NAME_STRING "TQRangeControl"
+#define TQCANVASITEM_OBJECT_NAME_STRING "TQCanvasItem"
+#define TQICONVIEW_OBJECT_NAME_STRING "TQIconView"
+#define TQMULTILINEEDIT_OBJECT_NAME_STRING "TQMultiLineEdit"
+#define TQINTVALIDATOR_OBJECT_NAME_STRING "TQIntValidator"
+#define TQDATEEDIT_OBJECT_NAME_STRING "TQDateEdit"
+#define TQTIMEEDIT_OBJECT_NAME_STRING "TQTimeEdit"
+#define TQDATETIMEEDIT_OBJECT_NAME_STRING "TQDateTimeEdit"
+#define TQHEADER_OBJECT_NAME_STRING "TQHeader"
+#define TQSIZEGRIP_OBJECT_NAME_STRING "TQSizeGrip"
+#define TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING "TQDockWindowHandle"
+#define TQHIDEDOCK_OBJECT_NAME_STRING "TQHideDock"
+#define TQTABLE_OBJECT_NAME_STRING "TQTable"
+#define TQWIZARD_OBJECT_NAME_STRING "TQWizard"
+#define TQDATATABLE_OBJECT_NAME_STRING "TQDataTable"
+#define TQDATABROWSER_OBJECT_NAME_STRING "TQDataBrowser"
+#define TQDATAVIEW_OBJECT_NAME_STRING "TQDataView"
+#define TQMAINWINDOW_OBJECT_NAME_STRING "TQMainWindow"
+#define TQWIDGETSTACK_OBJECT_NAME_STRING "TQWidgetStack"
+#define TQBUTTONGROUP_OBJECT_NAME_STRING "TQButtonGroup"
+#define TQTEXTVIEW_OBJECT_NAME_STRING "TQTextView"
+#define TQTEXTBROWSER_OBJECT_NAME_STRING "TQTextBrowser"
+#define TQLAYOUTWIDGET_OBJECT_NAME_STRING "TQLayoutWidget"
+
+#define TQMOTIFPLUSSTYLE_OBJECT_NAME_STRING "TQMotifPlusStyle"
+
+// #define tqarrowCursor Qt::ArrowCursor
+// #define tqupArrowCursor Qt::UpArrowCursor
+// #define tqcrossCursor Qt::CrossCursor
+// #define tqwaitCursor Qt::WaitCursor
+// #define tqibeamCursor Qt::IBeamCursor
+// #define tqsizeVerCursor Qt::SizeVerCursor
+// #define tqsizeHorCursor Qt::SizeHorCursor
+// #define tqsizeBDiagCursor Qt::SizeBDiagCursor
+// #define tqsizeFDiagCursor Qt::SizeFDiagCursor
+// #define tqsizeAllCursor Qt::SizeAllCursor
+// #define tqblankCursor Qt::BlankCursor
+// #define tqsplitVCursor Qt::SplitVCursor
+// #define tqsplitHCursor Qt::SplitHCursor
+// #define tqpointingHandCursor Qt::PointingHandCursor
+// #define tqforbiddenCursor Qt::ForbiddenCursor
+// #define tqwhatsThisCursor Qt::WhatsThisCursor
+// #define tqbusyCursor Qt::BusyCursor
+
+#define tqarrowCursor TQt::arrowCursor
+#define tqupArrowCursor TQt::upArrowCursor
+#define tqcrossCursor TQt::crossCursor
+#define tqwaitCursor TQt::waitCursor
+#define tqibeamCursor TQt::ibeamCursor
+#define tqsizeVerCursor TQt::sizeVerCursor
+#define tqsizeHorCursor TQt::sizeHorCursor
+#define tqsizeBDiagCursor TQt::sizeBDiagCursor
+#define tqsizeFDiagCursor TQt::sizeFDiagCursor
+#define tqsizeAllCursor TQt::sizeAllCursor
+#define tqblankCursor TQt::blankCursor
+#define tqsplitVCursor TQt::splitVCursor
+#define tqsplitHCursor TQt::splitHCursor
+#define tqpointingHandCursor TQt::pointingHandCursor
+#define tqforbiddenCursor TQt::forbiddenCursor
+#define tqwhatsThisCursor TQt::whatsThisCursor
+#define tqbusyCursor TQt::busyCursor
+
+#define tqreadBlock readData
+#define tqwriteBlock writeData
+#define TQT_TQIO_LONG qint64
+#define TQT_TQIO_ULONG qint64
+#define TQ_WFlags WFlags
+
+#define SET_QT_X_TIME(x) QX11Info::setAppTime(x)
+#define GET_QT_X_TIME(x) QX11Info::appTime()
+#define SET_QT_X_USER_TIME(x) QX11Info::setAppUserTime(x)
+#define GET_QT_X_USER_TIME(x) QX11Info::appUserTime()
+
+// // [FIXME]
+// // This should try a dynamic cast first before resorting to conversion (which entails a create/copy/delete operation)
+// // Also, is simply overwriting the origin pointer enough to make this work in all cases???
+// template <class T, class U>
+// U* tqt_convert_object(T* orig)
+// {
+// T* orig_ptr = orig;
+// U* temp = new U();
+// *temp = *orig;
+// orig_ptr = temp;
+// delete orig;
+// return temp;
+// }
+//
+// #define TQT_TQPIXMAP(x) (tqt_convert_object<QPixmap, TQPixmap>(x))
+// #define TQT_TQPIXMAP_CONST(x) (tqt_convert_object<const QPixmap, const TQPixmap>(x))
+
+// [NOTE]
+// It is IMPOSSIBLE to downcast an abstract base class [ABC] to a derived type. Period. End of story.
+// Think of it this way...is it ever possible to instantiate an ABC on its own (e.g. with new)? No!
+// Therefore, it is also impossible to copy an ABC.
+// static_cast won't work because an ABC has a completely different structure than a non abstract class.
+// Specifically, you will get segmentation faults in typeinfo for the ABC at runtime.
+// This is probably due to the complete absence of the abstract method implementations in the static_casted object.
+// The only exception that I can think of MIGHT be if NO CHANGES are made to the abstracted methods,
+// including addition, modification, or removal of said methods. Don't bet the farm on this however!
+
+// #define TQT_TQLAYOUTITEM_CONST(x) (static_cast<const TQLayoutItem*>(static_cast<const QLayoutItem*>(x)))
+
+// // [FIXME]
+// // This should try a dynamic cast first before resorting to conversion (which entails a create/copy/delete operation)
+// // There is half a chance that this sort of nasty hackery is only required for abstract base classes, such as QStyle and QLayoutItem
+// // For other class types a simple static_cast *might* suffice. [???]
+// template <class T, class U>
+// U* tqt_convert_object(T* orig)
+// {
+// T* orig_ptr = orig;
+// U* temp = new U();
+// *temp = *orig;
+// orig_ptr = temp;
+// delete orig;
+// return temp;
+// }
+//
+// #define TQT_TQLAYOUTITEM_CONST(x) (tqt_convert_object<const QLayoutItem, const TQLayoutItem>(x))
+
+// TQT_BASE_OBJECT is here for equality operators, as pointers will only be considered equal if the top (base) classes are compared
+// This is because all widget/extension/etc. classes will have one and only one TQT_BASE_OBJECT class instance in memory
+// Thus casting both pointers to TQT_BASE_OBJECT and comparing will reveal if the objects being compared are truly the same
+// For TQT 3 TQObject is the real base class, while in TQt 4 QObject is the real base class
+#define TQT_BASE_OBJECT_NAME QObject
+#define TQT_BASE_OBJECT(x) (static_cast<TQT_BASE_OBJECT_NAME*>(x))
+#define TQT_BASE_OBJECT_CONST(x) (static_cast<const TQT_BASE_OBJECT_NAME*>(x))
+
+// This can be used to change any object name within TQt
+// x is a QString or TQString
+#define TQT_OBJECT_NAME_HANDLER(x) TQString(x)
+
+// Safe casts
+template <class T>
+T tqt_dynamic_cast(TQT_BASE_OBJECT_NAME* a) { return dynamic_cast<T>(a); }
+
+template <class T>
+T tqt_dynamic_cast(const TQT_BASE_OBJECT_NAME* a) { return dynamic_cast<T>(a); }
+
+// Interface defines
+#define QABS(n) qAbs(n)
+#define QMIN(x, y) qMin(x, y)
+#define QMAX(x, y) qMax(x, y)
+
+#define tqt_mo_access access()
+#define tqt_mo_ci_name name()
+#define tqt_mo_ci_value value()
+#define tqt_mo_ci_count count()
+#define tqt_mo_ci_items items()
+#define tqt_mo_ci_method method()
+
+// [FIXME] The underlying problem in uic creating the need for these defines should probably be fixed sometime in the future...
+// See object.cpp e.g. line 571
+#define setTqmaximumSize setMaximumSize
+#define setTqminimumSize setMinimumSize
+#define setTqalignment tqsetAlignment
+#define setTqgeometry setGeometry
+
+#define Q_UINT16 quint16
+
+#define ttqqt_cast( x ) tqqt_cast(TQT_TQOBJECT(x))
+
+// TQT for Qt3 compatibility defines
+#define tqred red
+#define tqgreen green
+#define tqblue blue
+#define tqcyan cyan
+#define tqmagenta magenta
+#define tqyellow yellow
+#define tqdarkRed darkRed
+#define tqdarkGreen darkGreen
+#define tqdarkBlue darkBlue
+#define tqdarkCyan darkCyan
+#define tqdarkMagenta darkMagenta
+#define tqdarkYellow darkYellow
+#define tqwhite white
+#define tqwhiteptr &TQt::white
+#define tqlightGray lightGray
+#define tqgray gray
+#define tqdarkGray darkGray
+#define tqblack black
+#define tqblackptr &TQt::black
+#define tqcolor0 color0
+#define tqcolor1 color1
+
+// #define tqaccess access
+// #define tqcolorTable colorTable
+#define TQSO_Default Default
+// #define tqqt_cast ::qt_cast
+#define TQ_Alignment Qt::Alignment
+#define TQ_Horizontal Horizontal
+#define TQ_Vertical Vertical
+#define TQImage_ScaleFree ScaleFree
+#define TQ_Key_Shift Key_Shift
+#define TQ_Key_Control Key_Control
+#define TQ_Key_Alt Key_Alt
+#define TQ_Key_Meta Key_Meta
+#define TQ_Key_Super_L Key_Super_L
+#define TQ_Key_Super_R Key_Super_R
+#define TQ_Key_Hyper_L Key_Hyper_L
+#define TQ_Key_Hyper_R Key_Hyper_R
+#define TQ_ButtonState TQt::ButtonState
+#define TQ_LeftButton Qt::LeftButton
+#define TQ_MidButton Qt::MidButton
+#define TQ_RightButton Qt::RightButton
+#define TQ_ShiftButton ShiftButton
+#define TQ_ControlButton ControlButton
+#define TQ_AltButton AltButton
+#define TQ_MetaButton MetaButton
+#define TQ_ScaleFree ScaleFree
+#define TQ_ScaleMin ScaleMin
+#define TQ_ScaleMax ScaleMax
+#define TQ_ScaleMode ScaleMode
+#define TQ_StrongFocus Qt::StrongFocus
+#define TQ_NoFocus Qt::NoFocus
+#define TQ_WheelFocus Qt::WheelFocus
+#define TQ_ClickFocus Qt::ClickFocus
+#define TQ_TabFocus Qt::TabFocus
+#define TQ_FocusPolicy Qt::FocusPolicy
+#define TQ_SPExpandData Qt::Orientations
+#define TQIODevice_OpenModeFlag QIODevice::OpenModeFlag
+#define TQ_OpenMode OpenMode
+#define TQ_SPVertically (Qt::Orientations) TQSizePolicy::Vertically
+#define TQ_SPHorizontally (Qt::Orientations) TQSizePolicy::Horizontally
+#define TQ_SPNoDirection (Qt::Orientations) TQSizePolicy::NoDirection
+
+// #define Orientation Qt::Orientation
+
+// #define SubRect SubElement
+// #define SR_PushButtonContents SE_PushButtonContents
+// #define SR_PushButtonFocusRect SE_PushButtonFocusRect
+// #define SR_CheckBoxIndicator SE_CheckBoxIndicator
+// #define SR_CheckBoxContents SE_CheckBoxContents
+// #define SR_CheckBoxFocusRect SE_CheckBoxFocusRect
+// #define SR_RadioButtonIndicator SE_RadioButtonIndicator
+// #define SR_RadioButtonContents SE_RadioButtonContents
+// #define SR_RadioButtonFocusRect SE_RadioButtonFocusRect
+// #define SR_ComboBoxFocusRect SE_ComboBoxFocusRect
+// #define SR_SliderFocusRect SE_SliderFocusRect
+// #define SR_DockWindowHandleRect SE_DockWindowHandleRect
+// #define SR_ProgressBarGroove SE_ProgressBarGroove
+// #define SR_ProgressBarContents SE_ProgressBarContents
+// #define SR_ProgressBarLabel SE_ProgressBarLabel
+// #define SR_ToolButtonContents SE_ToolButtonContents
+// #define SR_DialogButtonAccept SE_DialogButtonAccept
+// #define SR_DialogButtonReject SE_DialogButtonReject
+// #define SR_DialogButtonApply SE_DialogButtonApply
+// #define SR_DialogButtonHelp SE_DialogButtonHelp
+// #define SR_DialogButtonAll SE_DialogButtonAll
+// #define SR_DialogButtonAbort SE_DialogButtonAbort
+// #define SR_DialogButtonIgnore SE_DialogButtonIgnore
+// #define SR_DialogButtonRetry SE_DialogButtonRetry
+// #define SR_DialogButtonCustom SE_DialogButtonCustom
+// #define SR_ToolBoxTabContents SE_ToolBoxTabContents
+// #define SR_CustomBase SE_CustomBase
+//
+// #define StylePixmap StandardPixmap
+// // #define SP_TitleBarMinButton SC_TitleBarMinButton
+// // #define SP_TitleBarMaxButton SC_TitleBarMaxButton
+// // #define SP_TitleBarCloseButton SC_TitleBarCloseButton
+// // #define SP_TitleBarNormalButton SC_TitleBarNormalButton
+// // #define SP_TitleBarShadeButton SC_TitleBarShadeButton
+// // #define SP_TitleBarUnshadeButton SC_TitleBarUnshadeButton
+// #define SP_DockWindowCloseButton SP_DockWidgetCloseButton
+// // #define SP_MessageBoxInformation SC_MessageBoxInformation
+// // #define SP_MessageBoxWarning SC_MessageBoxWarning
+// // #define SP_MessageBoxCritical SC_MessageBoxCritical
+// // #define SP_MessageBoxQuestion SC_MessageBoxQuestion
+// // #define SP_CustomBase SC_CustomBase
+//
+// #define StyleFlags StateFlags
+// #define Style_Default QStyle::State_Default
+// #define Style_Enabled QStyle::State_Enabled
+// #define Style_Raised QStyle::State_Raised
+// #define Style_Sunken QStyle::State_Sunken
+// #define Style_Off QStyle::State_Off
+// #define Style_NoChange QStyle::State_NoChange
+// #define Style_On QStyle::State_On
+// #define Style_Down QStyle::State_DownArrow
+// #define Style_Horizontal QStyle::State_Horizontal
+// #define Style_HasFocus QStyle::State_HasFocus
+// #define Style_To QStyle::State_To
+// #define Style_Bottom QStyle::State_Bottom
+// #define Style_FocusAtBorder QStyle::State_FocusAtBorder
+// #define Style_AutoRaise QStyle::State_AutoRaise
+// #define Style_MouseOver QStyle::State_MouseOver
+// #define Style_Up QStyle::State_UpArrow
+// #define Style_Selected QStyle::State_Selected
+// #define Style_Active QStyle::State_Active
+// #define Style_ButtonDefault QStyle::State_ButtonDefault
+//
+// #define PE_ArrowDown PE_IndicatorArrowDown
+// #define PE_ArrowUp PE_IndicatorArrowUp
+// #define PE_ButtonTool PE_PanelButtonTool
+// #define PE_DockWindowHandle PE_IndicatorToolBarHandle
+// #define PE_DockWindowSeparator PE_Q3DockWindowSeparator
+// // Verify this one -------------v
+// #define PE_FocusRect PE_FrameFocusRect
+// #define PE_Panel PE_Frame
+// #define PE_RubberBand CE_RubberBand
+// #define PE_ScrollBarAddLine CE_ScrollBarAddLine
+// #define PE_ScrollBarAddPage CE_ScrollBarAddPage
+// #define PE_ScrollBarFirst CE_ScrollBarFirst
+// #define PE_ScrollBarLast CE_ScrollBarLast
+// #define PE_ScrollBarSlider CE_ScrollBarSlider
+// #define PE_ScrollBarSubLine CE_ScrollBarSubLine
+// #define PE_ScrollBarSubPage CE_ScrollBarSubPage
+//
+// #define SC_ListView SC_Q3ListView
+// #define SC_ListViewBranch SC_Q3ListViewBranch
+// #define SC_ListViewExpand SC_Q3ListViewExpand
+//
+// #define CC_ListView CC_Q3ListView
+//
+// #define WState Qt::WidgetAttribute
+// #define WState_Polished Qt::WA_WState_Polished
+// //#define WState_ForceHide Qt::WA_WState_ForceHide
+// #define WState_ForceHide Qt::WA_WState_Hidden
+//
+// #define SH_PopupMenu_Scrollable SH_Menu_Scrollable
+// #define SH_PopupMenu_SloppySubMenus SH_Menu_SloppySubMenus
+// #define SH_PopupMenu_SubMenuPopupDelay SH_Menu_SubMenuPopupDelay
+// #define SH_PopupMenu_AllowActiveAndDisabled SH_Menu_AllowActiveAndDisabled
+// #define SH_PopupMenu_MouseTracking SH_Menu_MouseTracking
+//
+// #define CE_PopupMenuScroller CE_MenuScroller
+//
+// #define PM_DockWindowHandleExtent PM_DockWidgetHandleExtent
+// #define PM_MenuBarFrameWidth PM_ToolBarFrameWidth
+// #define PM_DockWindowFrameWidth PM_DockWidgetFrameWidth
+// #define PM_PopupMenuScrollerHeight PM_MenuScrollerHeight
+//
+// // #define WFlags Qt::WindowFlags
+
+#endif // USE_QT4
+
+#endif // TQTGLOBALDEFINES_H
diff --git a/tqtinterface/qt4/src/kernel/tqtglobalsettings.h b/tqtinterface/qt4/src/kernel/tqtglobalsettings.h
new file mode 100644
index 0000000..45cf9ac
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtglobalsettings.h
@@ -0,0 +1,7 @@
+#ifndef TQTGLOBALSETTINGS_H
+#define TQTGLOBALSETTINGS_H
+
+//#define USE_QT3
+#define USE_QT4
+
+#endif // TQTGLOBALSETTINGS_H \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqthread.cpp b/tqtinterface/qt4/src/kernel/tqthread.cpp
new file mode 100644
index 0000000..34667fa
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqthread.cpp
@@ -0,0 +1,241 @@
+/****************************************************************************
+**
+** Cross-platform TQThread implementation.
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifdef TQT_THREAD_SUPPORT
+
+#include "tqplatformdefs.h"
+
+#include "tqthread.h"
+#include <private/tqthreadinstance_p.h>
+
+#ifndef TQT_H
+# include "tqapplication.h"
+#endif // TQT_H
+
+#if TQT_VERSION >= 0x040000
+# error "Remove TQThread::TQThread() and TQThread::start()."
+#endif
+
+
+/*!
+ \class TQThread tqthread.h
+ \threadsafe
+ \brief The TQThread class provides platform-independent threads.
+
+ \ingroup thread
+ \ingroup environment
+
+ A TQThread represents a separate thread of control within the
+ program; it shares data with all the other threads within the
+ process but executes independently in the way that a separate
+ program does on a multitasking operating system. Instead of
+ starting in main(), TQThreads begin executing in run(). You inherit
+ run() to include your code. For example:
+
+ \code
+ class MyThread : public TQThread {
+
+ public:
+
+ virtual void run();
+
+ };
+
+ void MyThread::run()
+ {
+ for( int count = 0; count < 20; count++ ) {
+ sleep( 1 );
+ qDebug( "Ping!" );
+ }
+ }
+
+ int main()
+ {
+ MyThread a;
+ MyThread b;
+ a.start();
+ b.start();
+ a.wait();
+ b.wait();
+ }
+ \endcode
+
+ This will start two threads, each of which writes Ping! 20 times
+ to the screen and exits. The wait() calls at the end of main() are
+ necessary because exiting main() ends the program, unceremoniously
+ killing all other threads. Each MyThread stops executing when it
+ reaches the end of MyThread::run(), just as an application does
+ when it leaves main().
+
+ \sa \link threads.html Thread Support in TQt\endlink.
+*/
+
+/*!
+ \enum TQThread::Priority
+
+ This enum type indicates how the operating system should schedule
+ newly created threads.
+
+ \value IdlePriority scheduled only when no other threads are
+ running.
+
+ \value LowestPriority scheduled less often than LowPriority.
+ \value LowPriority scheduled less often than NormalPriority.
+
+ \value NormalPriority the default priority of the operating
+ system.
+
+ \value HighPriority scheduled more often than NormalPriority.
+ \value HighestPriority scheduled more often then HighPriority.
+
+ \value TimeCriticalPriority scheduled as often as possible.
+
+ \value InheritPriority use the same priority as the creating
+ thread. This is the default.
+*/
+
+TQThread::TQThread()
+{
+ d = new TQThreadInstance;
+ d->init(0);
+}
+
+/*!
+ Constructs a new thread. The thread does not begin executing until
+ start() is called.
+
+ If \a stackSize is greater than zero, the maximum stack size is
+ set to \a stackSize bytes, otherwise the maximum stack size is
+ automatically determined by the operating system.
+
+ \warning Most operating systems place minimum and maximum limits
+ on thread stack sizes. The thread will fail to start if the stack
+ size is outside these limits.
+*/
+TQThread::TQThread( unsigned int stackSize )
+{
+ d = new TQThreadInstance;
+ d->init(stackSize);
+}
+
+/*!
+ TQThread destructor.
+
+ Note that deleting a TQThread object will not stop the execution of
+ the thread it represents. Deleting a running TQThread (i.e.
+ finished() returns FALSE) will probably result in a program crash.
+ You can wait() on a thread to make sure that it has finished.
+*/
+TQThread::~TQThread()
+{
+ TQMutexLocker locker( d->mutex() );
+ if ( d->running && !d->finished ) {
+#ifdef TQT_CHECK_STATE
+ qWarning("TQThread object destroyed while thread is still running.");
+#endif
+
+ d->orphan = TRUE;
+ return;
+ }
+
+ d->deinit();
+ delete d;
+}
+
+/*!
+ This function terminates the execution of the thread. The thread
+ may or may not be terminated immediately, depending on the
+ operating system's scheduling policies. Use TQThread::wait()
+ after terminate() for synchronous termination.
+
+ When the thread is terminated, all threads waiting for the
+ the thread to finish will be woken up.
+
+ \warning This function is dangerous, and its use is discouraged.
+ The thread can be terminated at any point in its code path. Threads
+ can be terminated while modifying data. There is no chance for
+ the thread to cleanup after itself, unlock any held mutexes, etc.
+ In short, use this function only if \e absolutely necessary.
+*/
+void TQThread::terminate()
+{
+ TQMutexLocker locker( d->mutex() );
+ if ( d->finished || !d->running )
+ return;
+ d->terminate();
+}
+
+/*!
+ Returns TRUE if the thread is finished; otherwise returns FALSE.
+*/
+bool TQThread::finished() const
+{
+ TQMutexLocker locker( d->mutex() );
+ return d->finished;
+}
+
+/*!
+ Returns TRUE if the thread is running; otherwise returns FALSE.
+*/
+bool TQThread::running() const
+{
+ TQMutexLocker locker( d->mutex() );
+ return d->running;
+}
+
+/*!
+ \fn void TQThread::run()
+
+ This method is pure virtual, and must be implemented in derived
+ classes in order to do useful work. Returning from this method
+ will end the execution of the thread.
+
+ \sa wait()
+*/
+
+#ifndef TQT_NO_COMPAT
+/*! \obsolete
+ Use TQApplication::postEvent() instead.
+*/
+void TQThread::postEvent( TQObject * receiver, TQEvent * event )
+{
+ TQApplication::postEvent( receiver, event );
+}
+#endif
+
+#endif // TQT_THREAD_SUPPORT
diff --git a/tqtinterface/qt4/src/kernel/tqthread.h b/tqtinterface/qt4/src/kernel/tqthread.h
new file mode 100644
index 0000000..3d5c51e
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqthread.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Definition of TQThread class
+**
+** Created : 931107
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQTHREAD_H
+#define TQTHREAD_H
+
+#if defined(TQT_THREAD_SUPPORT)
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#ifndef TQT_NO_COMPAT
+#include "tqmutex.h"
+#include "tqsemaphore.h"
+#include "tqwaitcondition.h"
+#endif // TQT_NO_COMPAT
+#endif // TQT_H
+
+#include <limits.h>
+
+class TQThreadInstance;
+
+class TQ_EXPORT TQThread : public TQt
+{
+public:
+ static TQt::HANDLE currentThread();
+
+#ifndef TQT_NO_COMPAT
+ static void postEvent( TQObject *,TQEvent * );
+#endif
+
+ static void initialize();
+ static void cleanup();
+
+ static void exit();
+
+#ifdef TQ_TQDOC
+ TQThread( unsigned int stackSize = 0 );
+#else
+ TQThread( unsigned int stackSize );
+ TQThread();
+#endif
+
+ virtual ~TQThread();
+
+ // default argument causes thread to block indefinately
+ bool wait( unsigned long time = ULONG_MAX );
+
+ enum Priority {
+ IdlePriority,
+
+ LowestPriority,
+ LowPriority,
+ NormalPriority,
+ HighPriority,
+ HighestPriority,
+
+ TimeCriticalPriority,
+
+ InheritPriority
+ };
+
+#ifdef TQ_TQDOC
+ void start( Priority = InheritPriority );
+#else
+ void start( Priority );
+ void start();
+#endif
+
+ void terminate();
+
+ bool finished() const;
+ bool running() const;
+
+protected:
+ virtual void run() = 0;
+
+ static void sleep( unsigned long );
+ static void msleep( unsigned long );
+ static void usleep( unsigned long );
+
+private:
+ TQThreadInstance * d;
+ friend class TQThreadInstance;
+
+#if defined(TQ_DISABLE_COPY)
+ TQThread( const TQThread & );
+ TQThread &operator=( const TQThread & );
+#endif // TQ_DISABLE_COPY
+};
+
+#endif // TQT_THREAD_SUPPORT
+
+#endif // TQTHREAD_H
diff --git a/tqtinterface/qt4/src/kernel/tqthread_unix.cpp b/tqtinterface/qt4/src/kernel/tqthread_unix.cpp
new file mode 100644
index 0000000..11a1a90
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqthread_unix.cpp
@@ -0,0 +1,474 @@
+/****************************************************************************
+**
+** TQThread class for Unix
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#if defined(TQT_THREAD_SUPPORT)
+
+#include "tqplatformdefs.h"
+
+typedef pthread_mutex_t TQ_MUTEX_T;
+
+#include "tqthread.h"
+#include <private/tqthreadinstance_p.h>
+#include <private/tqmutex_p.h>
+#include <private/tqmutexpool_p.h>
+#include <tqthreadstorage.h>
+
+#include <errno.h>
+#include <sched.h>
+
+
+static TQThreadInstance main_instance = {
+ 0, { 0, &main_instance }, 0, 0, 1, 0, PTHREAD_COND_INITIALIZER, 0
+};
+
+
+static TQMutexPool *qt_thread_mutexpool = 0;
+
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+typedef void*(*TQtThreadCallback)(void*);
+
+static pthread_once_t storage_key_once = PTHREAD_ONCE_INIT;
+static pthread_key_t storage_key;
+static void create_storage_key()
+{
+ pthread_key_create( &storage_key, NULL );
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+
+/**************************************************************************
+ ** TQThreadInstance
+ *************************************************************************/
+
+TQThreadInstance *TQThreadInstance::current()
+{
+ pthread_once( &storage_key_once, create_storage_key );
+ TQThreadInstance *ret = (TQThreadInstance *) pthread_getspecific( storage_key );
+ return ret;
+}
+
+void TQThreadInstance::init(unsigned int stackSize)
+{
+ stacksize = stackSize;
+ args[0] = args[1] = 0;
+ thread_storage = 0;
+ finished = FALSE;
+ running = FALSE;
+ orphan = FALSE;
+
+ pthread_cond_init(&thread_done, NULL);
+ thread_id = 0;
+
+ // threads have not been initialized yet, do it now
+ if (! qt_thread_mutexpool) TQThread::initialize();
+}
+
+void TQThreadInstance::deinit()
+{
+ pthread_cond_destroy(&thread_done);
+}
+
+void *TQThreadInstance::start( void *_arg )
+{
+ void **arg = (void **) _arg;
+
+ pthread_once( &storage_key_once, create_storage_key );
+ pthread_setspecific( storage_key, arg[1] );
+ pthread_cleanup_push( TQThreadInstance::finish, arg[1] );
+ pthread_testcancel();
+
+ ( (TQThread *) arg[0] )->run();
+
+ pthread_cleanup_pop( TRUE );
+ return 0;
+}
+
+void TQThreadInstance::finish( void * )
+{
+ TQThreadInstance *d = current();
+
+ if ( ! d ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQThread: internal error: zero data for running thread." );
+#endif // TQT_CHECK_STATE
+ return;
+ }
+
+ TQMutexLocker locker( d->mutex() );
+ d->running = FALSE;
+ d->finished = TRUE;
+ d->args[0] = d->args[1] = 0;
+
+
+ TQThreadStorageData::finish( d->thread_storage );
+ d->thread_storage = 0;
+
+ d->thread_id = 0;
+ pthread_cond_broadcast(&d->thread_done);
+
+ if (d->orphan) {
+ d->deinit();
+ delete d;
+ }
+}
+
+TQMutex *TQThreadInstance::mutex() const
+{
+ return qt_thread_mutexpool ? qt_thread_mutexpool->get( (void *) this ) : 0;
+}
+
+void TQThreadInstance::terminate()
+{
+ if ( ! thread_id ) return;
+ pthread_cancel( thread_id );
+}
+
+
+/**************************************************************************
+ ** TQThread
+ *************************************************************************/
+
+/*!
+ This returns the thread handle of the currently executing thread.
+
+ \warning The handle returned by this function is used for internal
+ purposes and should \e not be used in any application code. On
+ Windows, the returned value is a pseudo handle for the current
+ thread, and it cannot be used for numerical comparison.
+*/
+TQt::HANDLE TQThread::currentThread()
+{
+ return (HANDLE) pthread_self();
+}
+
+/*! \internal
+ Initializes the TQThread system.
+*/
+void TQThread::initialize()
+{
+ if ( ! tqt_global_mutexpool )
+ tqt_global_mutexpool = new TQMutexPool( TRUE, 73 );
+ if ( ! qt_thread_mutexpool )
+ qt_thread_mutexpool = new TQMutexPool( FALSE, 127 );
+
+ pthread_once( &storage_key_once, create_storage_key );
+ pthread_setspecific( storage_key, &main_instance );
+}
+
+/*! \internal
+ Cleans up the TQThread system.
+*/
+void TQThread::cleanup()
+{
+ delete tqt_global_mutexpool;
+ delete qt_thread_mutexpool;
+ tqt_global_mutexpool = 0;
+ qt_thread_mutexpool = 0;
+
+ TQThreadInstance::finish(&main_instance);
+
+ pthread_once( &storage_key_once, create_storage_key );
+ pthread_setspecific( storage_key, 0 );
+}
+
+/*!
+ Ends the execution of the calling thread and wakes up any threads
+ waiting for its termination.
+*/
+void TQThread::exit()
+{
+ pthread_exit( 0 );
+}
+
+/* \internal
+ helper function to do thread sleeps, since usleep()/nanosleep()
+ aren't reliable enough (in terms of behavior and availability)
+*/
+static void thread_sleep( struct timespec *ti )
+{
+ pthread_mutex_t mtx;
+ pthread_cond_t cnd;
+
+ pthread_mutex_init(&mtx, 0);
+ pthread_cond_init(&cnd, 0);
+
+ pthread_mutex_lock( &mtx );
+ (void) pthread_cond_timedwait( &cnd, &mtx, ti );
+ pthread_mutex_unlock( &mtx );
+
+ pthread_cond_destroy( &cnd );
+ pthread_mutex_destroy( &mtx );
+}
+
+/*!
+ System independent sleep. This causes the current thread to sleep
+ for \a secs seconds.
+*/
+void TQThread::sleep( unsigned long secs )
+{
+ struct timeval tv;
+ gettimeofday( &tv, 0 );
+ struct timespec ti;
+ ti.tv_sec = tv.tv_sec + secs;
+ ti.tv_nsec = ( tv.tv_usec * 1000 );
+ thread_sleep( &ti );
+}
+
+/*!
+ System independent sleep. This causes the current thread to sleep
+ for \a msecs milliseconds
+*/
+void TQThread::msleep( unsigned long msecs )
+{
+ struct timeval tv;
+ gettimeofday( &tv, 0 );
+ struct timespec ti;
+
+ ti.tv_nsec = ( tv.tv_usec + ( msecs % 1000 ) * 1000 ) * 1000;
+ ti.tv_sec = tv.tv_sec + ( msecs / 1000 ) + ( ti.tv_nsec / 1000000000 );
+ ti.tv_nsec %= 1000000000;
+ thread_sleep( &ti );
+}
+
+/*!
+ System independent sleep. This causes the current thread to sleep
+ for \a usecs microseconds
+*/
+void TQThread::usleep( unsigned long usecs )
+{
+ struct timeval tv;
+ gettimeofday( &tv, 0 );
+ struct timespec ti;
+
+ ti.tv_nsec = ( tv.tv_usec + ( usecs % 1000000 ) ) * 1000;
+ ti.tv_sec = tv.tv_sec + ( usecs / 1000000 ) + ( ti.tv_nsec / 1000000000 );
+ ti.tv_nsec %= 1000000000;
+ thread_sleep( &ti );
+}
+
+/*!
+ Begins execution of the thread by calling run(), which should be
+ reimplemented in a TQThread subclass to contain your code. The
+ operating system will schedule the thread according to the \a
+ priority argument.
+
+ If you try to start a thread that is already running, this
+ function will wait until the the thread has finished and then
+ restart the thread.
+
+ \sa Priority
+*/
+void TQThread::start(Priority priority)
+{
+ TQMutexLocker locker( d->mutex() );
+
+ if ( d->running )
+ pthread_cond_wait(&d->thread_done, &locker.mutex()->d->handle);
+ d->running = TRUE;
+ d->finished = FALSE;
+
+ int ret;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+#if !defined(TQ_OS_OPENBSD) && defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && (_POSIX_THREAD_PRIORITY_SCHEDULING-0 >= 0)
+ switch (priority) {
+ case InheritPriority:
+ {
+ pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
+ break;
+ }
+
+ default:
+ {
+ int sched_policy;
+ if (pthread_attr_getschedpolicy(&attr, &sched_policy) != 0) {
+ // failed to get the scheduling policy, don't bother
+ // setting the priority
+ qWarning("TQThread: cannot determine default scheduler policy");
+ break;
+ }
+
+ int prio_min = sched_get_priority_min(sched_policy);
+ int prio_max = sched_get_priority_max(sched_policy);
+ if (prio_min == -1 || prio_max == -1) {
+ // failed to get the scheduling parameters, don't
+ // bother setting the priority
+ qWarning("TQThread: cannot determine scheduler priority range");
+ break;
+ }
+
+ int prio;
+ switch (priority) {
+ case IdlePriority:
+ prio = prio_min;
+ break;
+
+ case HighestPriority:
+ prio = prio_max;
+ break;
+
+ default:
+ // crudely scale our priority enum values to the prio_min/prio_max
+ prio = (((prio_max - prio_min) / TimeCriticalPriority) *
+ priority) + prio_min;
+ prio = TQMAX(prio_min, TQMIN(prio_max, prio));
+ break;
+ }
+
+ sched_param sp;
+ sp.sched_priority = prio;
+
+ pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+ pthread_attr_setschedparam(&attr, &sp);
+ break;
+ }
+ }
+#endif // _POSIX_THREAD_PRIORITY_SCHEDULING
+
+ if ( d->stacksize > 0 ) {
+#if defined(_POSIX_THREAD_ATTR_STACKSIZE) && (_POSIX_THREAD_ATTR_STACKSIZE-0 > 0)
+ ret = pthread_attr_setstacksize( &attr, d->stacksize );
+#else
+ ret = ENOSYS; // stack size not supported, automatically fail
+#endif // _POSIX_THREAD_ATTR_STACKSIZE
+
+ if ( ret ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQThread::start: thread stack size error: %s", strerror( ret ) ) ;
+#endif // TQT_CHECK_STATE
+
+ // we failed to set the stacksize, and as the documentation states,
+ // the thread will fail to run...
+ d->running = FALSE;
+ d->finished = FALSE;
+ return;
+ }
+ }
+
+ d->args[0] = this;
+ d->args[1] = d;
+ ret = pthread_create( &d->thread_id, &attr, (TQtThreadCallback)TQThreadInstance::start, d->args );
+#if defined (TQ_OS_HPUX)
+ if (ret == EPERM) {
+ pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
+ ret = pthread_create(&d->thread_id, &attr, (TQtThreadCallback)TQThreadInstance::start, d->args);
+ }
+#endif
+ pthread_attr_destroy( &attr );
+
+ if ( ret ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQThread::start: thread creation error: %s", strerror( ret ) );
+#endif // TQT_CHECK_STATE
+
+ d->running = FALSE;
+ d->finished = FALSE;
+ d->args[0] = d->args[1] = 0;
+ }
+}
+
+void TQThread::start()
+{
+ start(InheritPriority);
+}
+
+/*!
+ A thread calling this function will block until either of these
+ conditions is met:
+
+ \list
+ \i The thread associated with this TQThread object has finished
+ execution (i.e. when it returns from \l{run()}). This function
+ will return TRUE if the thread has finished. It also returns
+ TRUE if the thread has not been started yet.
+ \i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the
+ default), then the wait will never timeout (the thread must
+ return from \l{run()}). This function will return FALSE if the
+ wait timed out.
+ \endlist
+
+ This provides similar functionality to the POSIX \c pthread_join() function.
+*/
+bool TQThread::wait( unsigned long time )
+{
+ TQMutexLocker locker( d->mutex() );
+
+ if ( d->thread_id == pthread_self() ) {
+#ifdef TQT_CHECK_STATE
+ qWarning( "TQThread::wait: thread tried to wait on itself" );
+#endif // TQT_CHECK_STATE
+
+ return FALSE;
+ }
+
+ if ( d->finished || ! d->running )
+ return TRUE;
+
+ int ret;
+ if (time != ULONG_MAX) {
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+
+ timespec ti;
+ ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000;
+ ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000);
+ ti.tv_nsec %= 1000000000;
+
+ ret = pthread_cond_timedwait(&d->thread_done, &locker.mutex()->d->handle, &ti);
+ } else
+ ret = pthread_cond_wait(&d->thread_done, &locker.mutex()->d->handle);
+
+#ifdef TQT_CHECK_RANGE
+ if (ret && ret != ETIMEDOUT)
+ qWarning("Wait condition wait failure: %s",strerror(ret));
+#endif
+
+ return (ret == 0);
+}
+
+
+#endif // TQT_THREAD_SUPPORT
diff --git a/tqtinterface/qt4/src/kernel/tqtimer.cpp b/tqtinterface/qt4/src/kernel/tqtimer.cpp
new file mode 100644
index 0000000..d1a98e1
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtimer.cpp
@@ -0,0 +1,350 @@
+/****************************************************************************
+**
+** Implementation of TQTimer class
+**
+** Created : 931111
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqtimer.h"
+#include "tqsignal.h"
+#include "tqobjectlist.h"
+
+#ifdef USE_QT4
+#include <Qt/qtimer.h>
+#endif // USE_QT4
+
+/*!
+ \class TQTimer tqtimer.h
+ \brief The TQTimer class provides timer Q_SIGNALS and single-shot timers.
+
+ \ingroup time
+ \ingroup events
+ \mainclass
+
+ It uses \link TQTimerEvent timer events\endlink internally to
+ provide a more versatile timer. TQTimer is very easy to use:
+ create a TQTimer, call start() to start it and connect its
+ timeout() to the appropriate Q_SLOTS. When the time is up it will
+ emit the timeout() signal.
+
+ Note that a TQTimer object is destroyed automatically when its
+ tqparent object is destroyed.
+
+ Example:
+ \code
+ TQTimer *timer = new TQTimer( myObject );
+ connect( timer, TQT_SIGNAL(timeout()), myObject, TQT_SLOT(timerDone()) );
+ timer->start( 2000, TRUE ); // 2 seconds single-shot timer
+ \endcode
+
+ You can also use the static singleShot() function to create a
+ single shot timer.
+
+ As a special case, a TQTimer with timeout 0 times out as soon as
+ all the events in the window system's event queue have been
+ processed.
+
+ This can be used to do heavy work while providing a snappy
+ user interface:
+ \code
+ TQTimer *t = new TQTimer( myObject );
+ connect( t, TQT_SIGNAL(timeout()), TQT_SLOT(processOneThing()) );
+ t->start( 0, FALSE );
+ \endcode
+
+ myObject->processOneThing() will be called repeatedly and should
+ return quickly (typically after processing one data item) so that
+ TQt can deliver events to widgets and stop the timer as soon as it
+ has done all its work. This is the traditional way of
+ implementing heavy work in GUI applications; multi-threading is
+ now becoming available on more and more platforms, and we expect
+ that null events will eventually be tqreplaced by threading.
+
+ Note that TQTimer's accuracy depends on the underlying operating
+ system and hardware. Most platforms support an accuracy of 20ms;
+ some provide more. If TQt is unable to deliver the requested
+ number of timer clicks, it will silently discard some.
+
+ An alternative to using TQTimer is to call TQObject::startTimer()
+ for your object and reimplement the TQObject::timerEvent() event
+ handler in your class (which must, of course, inherit TQObject).
+ The disadvantage is that timerEvent() does not support such
+ high-level features as single-shot timers or Q_SIGNALS.
+
+ Some operating systems limit the number of timers that may be
+ used; TQt tries to work around these limitations.
+*/
+
+
+static const int INV_TIMER = -1; // invalid timer id
+
+
+/*!
+ Constructs a timer called \a name, with the tqparent \a tqparent.
+
+ Note that the tqparent object's destructor will destroy this timer
+ object.
+*/
+
+TQTimer::TQTimer( TQT_BASE_OBJECT_NAME *tqparent, const char *name )
+ : TQObject( tqparent, name ), id(INV_TIMER), single(0), nulltimer(0)
+{
+}
+
+/*!
+ Destroys the timer.
+*/
+
+TQTimer::~TQTimer()
+{
+ if ( id != INV_TIMER ) // stop running timer
+ stop();
+}
+
+
+/*!
+ \fn void TQTimer::timeout()
+
+ This signal is emitted when the timer is activated.
+*/
+
+/*!
+ \fn bool TQTimer::isActive() const
+
+ Returns TRUE if the timer is running (pending); otherwise returns
+ FALSE.
+*/
+
+/*!
+ \fn int TQTimer::timerId() const
+
+ Returns the ID of the timer if the timer is running; otherwise returns
+ -1.
+*/
+
+
+/*!
+ Starts the timer with a \a msec milliseconds timeout, and returns
+ the ID of the timer, or zero when starting the timer failed.
+
+ If \a sshot is TRUE, the timer will be activated only once;
+ otherwise it will continue until it is stopped.
+
+ Any pending timer will be stopped.
+
+ \sa singleShot() stop(), changeInterval(), isActive()
+*/
+
+int TQTimer::start( int msec, bool sshot )
+{
+ if ( id >=0 && nulltimer && !msec && sshot )
+ return id;
+ if ( id != INV_TIMER ) // stop running timer
+ stop();
+ single = sshot;
+ nulltimer = ( !msec && sshot );
+ return id = startTimer( msec );
+}
+
+
+/*!
+ Changes the timeout interval to \a msec milliseconds.
+
+ If the timer signal is pending, it will be stopped and restarted;
+ otherwise it will be started.
+
+ \sa start(), isActive()
+*/
+
+void TQTimer::changeInterval( int msec )
+{
+ if ( id == INV_TIMER ) { // create new timer
+ start( msec );
+ } else {
+ killTimer( id ); // restart timer
+ id = startTimer( msec );
+ }
+}
+
+/*!
+ Stops the timer.
+
+ \sa start()
+*/
+
+void TQTimer::stop()
+{
+ if ( id != INV_TIMER ) {
+ killTimer( id );
+ id = INV_TIMER;
+ }
+}
+
+
+/*!
+ \reimp
+*/
+bool TQTimer::event( TQEvent *e )
+{
+ if ( e->type() != TQEvent::Timer ) // ignore all other events
+ return FALSE;
+ if ( single ) // stop single shot timer
+ stop();
+ emit timeout(); // emit timeout signal
+ return TRUE;
+}
+
+
+/*
+ The TQSingleShotTimer class is an internal class for implementing
+ TQTimer::singleShot(). It starts a timer and emits the signal
+ and kills itself when it gets the timeout.
+*/
+
+static TQObjectList *sst_list = 0; // list of single shot timers
+
+static void sst_cleanup()
+{
+ if ( sst_list ) {
+ sst_list->setAutoDelete( TRUE );
+ delete sst_list;
+ sst_list = 0;
+ }
+}
+
+static void sst_init()
+{
+ if ( !sst_list ) {
+ sst_list = new TQObjectList;
+ TQ_CHECK_PTR( sst_list );
+ qAddPostRoutine( sst_cleanup );
+ }
+}
+
+
+class TQSingleShotTimer : public TQObject
+{
+public:
+ ~TQSingleShotTimer();
+ bool start( int msec, TQT_BASE_OBJECT_NAME *r, const char * m );
+ bool isActive() const { return timerId > 0; }
+protected:
+ bool event( TQEvent * );
+private:
+ TQSignal signal;
+ int timerId;
+};
+
+extern int qStartTimer( int interval, TQObject *obj ); // implemented in qapp_xxx.cpp
+extern bool qKillTimer( int id );
+
+TQSingleShotTimer::~TQSingleShotTimer()
+{
+ if (timerId != 0) {
+ qKillTimer(timerId);
+ timerId = 0;
+ }
+}
+
+bool TQSingleShotTimer::start( int msec, TQT_BASE_OBJECT_NAME *r, const char *m )
+{
+ timerId = 0;
+ if ( signal.connect(TQT_TQOBJECT(r), m) )
+ timerId = qStartTimer( msec, TQT_TQOBJECT(this) );
+ return timerId != 0;
+}
+
+bool TQSingleShotTimer::event( TQEvent * )
+{
+ qKillTimer( timerId ); // no more timeouts
+ signal.activate(); // emit the signal
+ signal.disconnect( 0, 0 );
+ timerId = 0; // mark as inactive
+ return TRUE;
+}
+
+
+/*!
+ This static function calls a slot after a given time interval.
+
+ It is very convenient to use this function because you do not need
+ to bother with a \link TQObject::timerEvent() timerEvent\endlink or
+ to create a local TQTimer object.
+
+ Example:
+ \code
+ #include <tqapplication.h>
+ #include <tqtimer.h>
+
+ int main( int argc, char **argv )
+ {
+ TQApplication a( argc, argv );
+ TQTimer::singleShot( 10*60*1000, &a, TQT_SLOT(quit()) );
+ ... // create and show your widgets
+ return a.exec();
+ }
+ \endcode
+
+ This sample program automatically terminates after 10 minutes (i.e.
+ 600000 milliseconds).
+
+ The \a receiver is the receiving object and the \a member is the
+ slot. The time interval is \a msec.
+*/
+
+#ifdef USE_QT4
+void TQTimer::singleShot( int msec, TQT_BASE_OBJECT_NAME *receiver, const char *member )
+{
+ // Cheat!
+ QTimer::singleShot(msec, receiver, member);
+}
+#else // USE_QT4
+void TQTimer::singleShot( int msec, TQT_BASE_OBJECT_NAME *receiver, const char *member )
+{
+ if ( !sst_list )
+ sst_init();
+ // search the list for a free ss timer we could reuse
+ TQSingleShotTimer *sst = (TQSingleShotTimer*)sst_list->first();
+ while ( sst && sst->isActive() )
+ sst = (TQSingleShotTimer*)sst_list->next();
+ // create a new one if not successful
+ if ( !sst ) {
+ sst = new TQSingleShotTimer;
+ sst_list->append( sst );
+ }
+ sst->start(msec, receiver, member);
+}
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqtimer.h b/tqtinterface/qt4/src/kernel/tqtimer.h
new file mode 100644
index 0000000..1d2398a
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtimer.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Definition of TQTimer class
+**
+** Created : 931111
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQTIMER_H
+#define TQTIMER_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#endif // TQT_H
+
+
+class TQ_EXPORT TQTimer : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQTimer( TQT_BASE_OBJECT_NAME *tqparent=0, const char *name=0 );
+ ~TQTimer();
+
+ bool isActive() const;
+
+ int start( int msec, bool sshot = FALSE );
+ void changeInterval( int msec );
+ void stop();
+
+ static void singleShot( int msec, TQT_BASE_OBJECT_NAME *receiver, const char *member );
+
+ int timerId() const { return id; }
+
+Q_SIGNALS:
+ void timeout();
+
+protected:
+ bool event( TQEvent * );
+
+private:
+ int id;
+ uint single : 1;
+ uint nulltimer : 1;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQTimer( const TQTimer & );
+ TQTimer &operator=( const TQTimer & );
+#endif
+};
+
+
+inline bool TQTimer::isActive() const
+{
+ return id >= 0;
+}
+
+
+#endif // TQTIMER_H
diff --git a/tqtinterface/qt4/src/kernel/tqtranslator.cpp b/tqtinterface/qt4/src/kernel/tqtranslator.cpp
new file mode 100644
index 0000000..ec0856b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtranslator.cpp
@@ -0,0 +1,2438 @@
+/****************************************************************************
+**
+** Localization database support.
+**
+** Created : 980906
+**
+** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqplatformdefs.h"
+
+// POSIX Large File Support redefines open -> open64
+static inline int qt_open(const char *pathname, int flags, mode_t mode)
+{ return ::open(pathname, flags, mode); }
+#if defined(open)
+# undef open
+#endif
+
+// POSIX Large File Support redefines truncate -> truncate64
+#if defined(truncate)
+# undef truncate
+#endif
+
+#include "tqtranslator.h"
+
+#ifndef TQT_NO_TRANSLATION
+
+#include "tqfileinfo.h"
+#include "tqwidgetlist.h"
+#include "tqintdict.h"
+#include "tqstring.h"
+#include "tqapplication.h"
+#include "tqfile.h"
+#include "tqbuffer.h"
+#include "tqdatastream.h"
+#include "tqmap.h"
+#include "tqtl.h"
+
+#if defined(TQ_OS_UNIX)
+#define TQT_USE_MMAP
+#endif
+
+// most of the headers below are already included in qplatformdefs.h
+// also this lacks Large File support but that's probably irrelevant
+#if defined(TQT_USE_MMAP)
+// for mmap
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+// for htonl
+#include <netinet/in.h>
+#endif
+
+#include <stdlib.h>
+
+#ifdef USE_QT4
+
+// magic number for the file
+static const int MagicLength = 16;
+static const uchar magic[MagicLength] = {
+ 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
+ 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd
+};
+
+static bool match( const char* found, const char* target )
+{
+ // 0 means anything, "" means empty
+ return found == 0 || qstrcmp( found, target ) == 0;
+}
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+/*
+ Yes, unfortunately, we have code here that depends on endianness.
+ The candidate is big endian (it comes from a .qm file) whereas the
+ target endianness depends on the system TQt is running on.
+*/
+#ifdef TQ_OS_TEMP
+static int __cdecl cmp_uint32_little( const void* target, const void* candidate )
+#else
+static int cmp_uint32_little( const void* target, const void* candidate )
+#endif
+{
+ const uchar* t = (const uchar*) target;
+ const uchar* c = (const uchar*) candidate;
+ return t[3] != c[0] ? (int) t[3] - (int) c[0]
+ : t[2] != c[1] ? (int) t[2] - (int) c[1]
+ : t[1] != c[2] ? (int) t[1] - (int) c[2]
+ : (int) t[0] - (int) c[3];
+}
+
+#ifdef TQ_OS_TEMP
+static int __cdecl cmp_uint32_big( const void* target, const void* candidate )
+#else
+static int cmp_uint32_big( const void* target, const void* candidate )
+#endif
+{
+ const uchar* t = (const uchar*) target;
+ const uchar* c = (const uchar*) candidate;
+ return t[0] != c[0] ? (int) t[0] - (int) c[0]
+ : t[1] != c[1] ? (int) t[1] - (int) c[1]
+ : t[2] != c[2] ? (int) t[2] - (int) c[2]
+ : (int) t[3] - (int) c[3];
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+static int systemWordSize = 0;
+static bool systemBigEndian;
+
+static uint elfHash( const char * name )
+{
+ const uchar *k;
+ uint h = 0;
+ uint g;
+
+ if ( name ) {
+ k = (const uchar *) name;
+ while ( *k ) {
+ h = ( h << 4 ) + *k++;
+ if ( (g = (h & 0xf0000000)) != 0 )
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ }
+ if ( !h )
+ h = 1;
+ return h;
+}
+
+extern bool qt_detectRTLLanguage();
+
+class TQTranslatorPrivate {
+public:
+ struct Offset {
+ Offset()
+ : h( 0 ), o( 0 ) { }
+ Offset( const TQTranslatorMessage& m, int offset )
+ : h( m.hash() ), o( offset ) { }
+
+ bool operator<( const Offset&k ) const {
+ return ( h != k.h ) ? h < k.h : o < k.o;
+ }
+ TQ_DUMMY_COMPARISON_OPERATOR(TQTranslatorPrivate::Offset)
+ uint h;
+ uint o;
+ };
+
+ enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69 };
+
+ TQTranslatorPrivate() :
+ unmapPointer( 0 ), unmapLength( 0 ),
+ messageArray( 0 ), offsetArray( 0 ), contextArray( 0 )
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ , messages( 0 )
+#endif
+ { }
+ // TQTranslator must finalize this before deallocating it
+
+ // for mmap'ed files, this is what needs to be unmapped.
+ char * unmapPointer;
+ unsigned int unmapLength;
+
+ // for squeezed but non-file data, this is what needs to be deleted
+ TQByteArray * messageArray;
+ TQByteArray * offsetArray;
+ TQByteArray * contextArray;
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ TQMap<TQTranslatorMessage, void *> * messages;
+#endif
+#ifdef TQ_WS_WIN
+ int oldPermissionLookup;
+#endif
+};
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+
+/*!
+ Returns a list of the messages in the translator. This function is
+ rather slow. Because it is seldom called, it's optimized for
+ simplicity and small size, rather than speed.
+
+ If you want to iterate over the list, you should iterate over a
+ copy, e.g.
+ \code
+ TQValueList<TQTranslatorMessage> list = myTranslator.messages();
+ TQValueList<TQTranslatorMessage>::Iterator it = list.begin();
+ while ( it != list.end() ) {
+ process_message( *it );
+ ++it;
+ }
+ \endcode
+*/
+
+TQValueList<TQTranslatorMessage> TQTranslator::messages() const
+{
+ if ( d->messages )
+ return d->messages->keys();
+
+ ((TQTranslator *) this)->unsqueeze();
+ TQValueList<TQTranslatorMessage> result = d->messages->keys();
+ delete d->messages;
+ d->messages = 0;
+ return result;
+}
+
+/*!
+ Saves this message file to \a filename, overwriting the previous
+ contents of \a filename. If \a mode is \c Everything (the
+ default), all the information is preserved. If \a mode is \c
+ Stripped, any information that is not necessary for tqfindMessage()
+ is stripped away.
+
+ \sa load()
+*/
+
+bool TQTranslator::save( const TQString & filename, SaveMode mode )
+{
+ TQFile f( filename );
+ if ( f.open( IO_WriteOnly ) ) {
+ squeeze( mode );
+
+ TQDataStream s( &f );
+ s.writeRawBytes( (const char *)magic, MagicLength );
+ TQ_UINT8 tag;
+
+ if ( d->offsetArray != 0 ) {
+ tag = (TQ_UINT8) TQTranslatorPrivate::Hashes;
+ TQ_UINT32 oas = (TQ_UINT32) d->offsetArray->size();
+ s << tag << oas;
+ s.writeRawBytes( d->offsetArray->data(), oas );
+ }
+ if ( d->messageArray != 0 ) {
+ tag = (TQ_UINT8) TQTranslatorPrivate::Messages;
+ TQ_UINT32 mas = (TQ_UINT32) d->messageArray->size();
+ s << tag << mas;
+ s.writeRawBytes( d->messageArray->data(), mas );
+ }
+ if ( d->contextArray != 0 ) {
+ tag = (TQ_UINT8) TQTranslatorPrivate::Contexts;
+ TQ_UINT32 cas = (TQ_UINT32) d->contextArray->size();
+ s << tag << cas;
+ s.writeRawBytes( d->contextArray->data(), cas );
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*!
+ Empties this translator of all contents.
+
+ This function works with stripped translator files.
+*/
+
+void TQTranslator::clear()
+{
+ if ( d->unmapPointer && d->unmapLength ) {
+#if defined(TQT_USE_MMAP)
+ munmap( d->unmapPointer, d->unmapLength );
+#else
+ delete [] d->unmapPointer;
+#endif
+ d->unmapPointer = 0;
+ d->unmapLength = 0;
+ }
+
+ if ( d->messageArray ) {
+ d->messageArray->resetRawData( d->messageArray->data(),
+ d->messageArray->size() );
+ delete d->messageArray;
+ d->messageArray = 0;
+ }
+ if ( d->offsetArray ) {
+ d->offsetArray->resetRawData( d->offsetArray->data(),
+ d->offsetArray->size() );
+ delete d->offsetArray;
+ d->offsetArray = 0;
+ }
+ if ( d->contextArray ) {
+ d->contextArray->resetRawData( d->contextArray->data(),
+ d->contextArray->size() );
+ delete d->contextArray;
+ d->contextArray = 0;
+ }
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ delete d->messages;
+ d->messages = 0;
+#endif
+
+ if ( tqApp ) {
+ tqApp->setReverseLayout( qt_detectRTLLanguage() );
+
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ if (!w->isDesktop())
+ tqApp->postEvent( w, new TQEvent( TQEvent::LanguageChange ) );
+ }
+ delete list;
+ }
+}
+
+/*!
+ Converts this message file to the compact format used to store
+ message files on disk.
+
+ You should never need to call this directly; save() and other
+ functions call it as necessary. \a mode is for internal use.
+
+ \sa save() unsqueeze()
+*/
+
+void TQTranslator::squeeze( SaveMode mode )
+{
+ if ( !d->messages ) {
+ if ( mode == Stripped )
+ unsqueeze();
+ else
+ return;
+ }
+
+ TQMap<TQTranslatorMessage, void *> * messages = d->messages;
+
+ d->messages = 0;
+ clear();
+
+ d->messageArray = new TQByteArray;
+ d->offsetArray = new TQByteArray;
+
+ TQMap<TQTranslatorPrivate::Offset, void *> offsets;
+
+ TQDataStream ms( *d->messageArray, IO_WriteOnly );
+ TQMap<TQTranslatorMessage, void *>::Iterator it = messages->begin(), next;
+ int cpPrev = 0, cpNext = 0;
+ for ( it = messages->begin(); it != messages->end(); ++it ) {
+ cpPrev = cpNext;
+ next = it;
+ ++next;
+ if ( next == messages->end() )
+ cpNext = 0;
+ else
+ cpNext = (int) it.key().commonPrefix( next.key() );
+ offsets.tqreplace( TQTranslatorPrivate::Offset(it.key(),
+ ms.tqdevice()->at()), (void*)0 );
+ it.key().write( ms, mode == Stripped,
+ (TQTranslatorMessage::Prefix) TQMAX(cpPrev, cpNext + 1) );
+ }
+
+ d->offsetArray->resize( 0 );
+ TQMap<TQTranslatorPrivate::Offset, void *>::Iterator offset;
+ offset = offsets.begin();
+ TQDataStream ds( *d->offsetArray, IO_WriteOnly );
+ while ( offset != offsets.end() ) {
+ TQTranslatorPrivate::Offset k = offset.key();
+ ++offset;
+ ds << (TQ_UINT32)k.h << (TQ_UINT32)k.o;
+ }
+
+ if ( mode == Stripped ) {
+ TQAsciiDict<int> contextSet( 1511 );
+ int baudelaire;
+
+ for ( it = messages->begin(); it != messages->end(); ++it )
+ contextSet.tqreplace( it.key().context(), &baudelaire );
+
+ TQ_UINT16 hTableSize;
+ if ( contextSet.count() < 200 )
+ hTableSize = ( contextSet.count() < 60 ) ? 151 : 503;
+ else if ( contextSet.count() < 2500 )
+ hTableSize = ( contextSet.count() < 750 ) ? 1511 : 5003;
+ else
+ hTableSize = 15013;
+
+ TQIntDict<char> hDict( hTableSize );
+ TQAsciiDictIterator<int> c = contextSet;
+ while ( c.current() != 0 ) {
+ hDict.insert( (long) (elfHash(c.currentKey()) % hTableSize),
+ c.currentKey() );
+ ++c;
+ }
+
+ /*
+ The contexts found in this translator are stored in a hash
+ table to provide fast lookup. The context array has the
+ following format:
+
+ TQ_UINT16 hTableSize;
+ TQ_UINT16 hTable[hTableSize];
+ TQ_UINT8 contextPool[...];
+
+ The context pool stores the contexts as Pascal strings:
+
+ TQ_UINT8 len;
+ TQ_UINT8 data[len];
+
+ Let's consider the look-up of context "FunnyDialog". A
+ hash value between 0 and hTableSize - 1 is computed, say h.
+ If hTable[h] is 0, "FunnyDialog" is not covered by this
+ translator. Else, we check in the contextPool at offset
+ 2 * hTable[h] to see if "FunnyDialog" is one of the
+ contexts stored there, until we tqfind it or we meet the
+ empty string.
+ */
+ d->contextArray = new TQByteArray;
+ d->contextArray->resize( 2 + (hTableSize << 1) );
+ TQDataStream t( *d->contextArray, IO_WriteOnly );
+ TQ_UINT16 *hTable = new TQ_UINT16[hTableSize];
+ memset( hTable, 0, hTableSize * sizeof(TQ_UINT16) );
+
+ t << hTableSize;
+ t.tqdevice()->at( 2 + (hTableSize << 1) );
+ t << (TQ_UINT16) 0; // the entry at offset 0 cannot be used
+ uint upto = 2;
+
+ for ( int i = 0; i < hTableSize; i++ ) {
+ const char *con = hDict.tqfind( i );
+ if ( con == 0 ) {
+ hTable[i] = 0;
+ } else {
+ hTable[i] = (TQ_UINT16) ( upto >> 1 );
+ do {
+ uint len = (uint) tqstrlen( con );
+ len = TQMIN( len, 255 );
+ t << (TQ_UINT8) len;
+ t.writeRawBytes( con, len );
+ upto += 1 + len;
+ hDict.remove( i );
+ } while ( (con = hDict.tqfind(i)) != 0 );
+ do {
+ t << (TQ_UINT8) 0; // empty string (at least one)
+ upto++;
+ } while ( (upto & 0x1) != 0 ); // offsets have to be even
+ }
+ }
+ t.tqdevice()->at( 2 );
+ for ( int j = 0; j < hTableSize; j++ )
+ t << hTable[j];
+ delete [] hTable;
+
+ if ( upto > 131072 ) {
+ qWarning( "TQTranslator::squeeze: Too many contexts" );
+ delete d->contextArray;
+ d->contextArray = 0;
+ }
+ }
+ delete messages;
+}
+
+
+/*!
+ Converts this message file into an easily modifiable data
+ structure, less compact than the format used in the files.
+
+ You should never need to call this function; it is called by
+ insert() and friends as necessary.
+
+ \sa squeeze()
+*/
+
+void TQTranslator::unsqueeze()
+{
+ if ( d->messages )
+ return;
+
+ d->messages = new TQMap<TQTranslatorMessage, void *>;
+ if ( !d->messageArray )
+ return;
+
+ TQDataStream s( *d->messageArray, IO_ReadOnly );
+ for ( ;; ) {
+ TQTranslatorMessage m( s );
+ if ( m.hash() == 0 )
+ break;
+ d->messages->insert( m, (void *) 0 );
+ }
+}
+
+/*!
+ Returns TRUE if this message file tqcontains a message with the key
+ (\a context, \a sourceText, \a comment); otherwise returns FALSE.
+
+ This function works with stripped translator files.
+
+ (This is is a one-liner that calls tqfindMessage().)
+*/
+
+bool TQTranslator::tqcontains( const char* context, const char* sourceText,
+ const char* comment ) const
+{
+ return !tqfindMessage( context, sourceText, comment ).translation().isNull();
+}
+
+/*!
+ Inserts \a message into this message file.
+
+ This function does \e not work with stripped translator files. It
+ may appear to, but that is not dependable.
+
+ \sa remove()
+*/
+
+void TQTranslator::insert( const TQTranslatorMessage& message )
+{
+ unsqueeze();
+ d->messages->remove( message ); // safer
+ d->messages->insert( message, (void *) 0 );
+}
+
+
+/*!
+ \fn void TQTranslator::insert( const char *, const char *, const TQString & )
+ \overload
+ \obsolete
+*/
+
+/*!
+ Removes \a message from this translator.
+
+ This function works with stripped translator files.
+
+ \sa insert()
+*/
+
+void TQTranslator::remove( const TQTranslatorMessage& message )
+{
+ unsqueeze();
+ d->messages->remove( message );
+}
+
+/*! Returns the TQTranslatorMessage for the key
+ (\a context, \a sourceText, \a comment). If none is found,
+ also tries (\a context, \a sourceText, "").
+*/
+
+#endif
+
+TQTranslatorMessage TQTranslator::tqfindMessage( const char* context,
+ const char* sourceText,
+ const char* comment ) const
+{
+ if ( context == 0 )
+ context = "";
+ if ( sourceText == 0 )
+ sourceText = "";
+ if ( comment == 0 )
+ comment = "";
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ if ( d->messages ) {
+ TQMap<TQTranslatorMessage, void *>::ConstIterator it;
+
+ it = d->messages->tqfind( TQTranslatorMessage(context, sourceText,
+ comment) );
+ if ( it != d->messages->end() )
+ return it.key();
+
+ if ( comment[0] ) {
+ it = d->messages->tqfind( TQTranslatorMessage(context, sourceText,
+ "") );
+ if ( it != d->messages->end() )
+ return it.key();
+ }
+ return TQTranslatorMessage();
+ }
+#endif
+
+ if ( !d->offsetArray )
+ return TQTranslatorMessage();
+
+ /*
+ Check if the context belongs to this TQTranslator. If many translators are
+ installed, this step is necessary.
+ */
+ if ( d->contextArray ) {
+ TQ_UINT16 hTableSize = 0;
+ TQDataStream t( *d->contextArray, IO_ReadOnly );
+ t >> hTableSize;
+ uint g = elfHash( context ) % hTableSize;
+ t.tqdevice()->at( 2 + (g << 1) );
+ TQ_UINT16 off;
+ t >> off;
+ if ( off == 0 )
+ return TQTranslatorMessage();
+ t.tqdevice()->at( 2 + (hTableSize << 1) + (off << 1) );
+
+ TQ_UINT8 len;
+ char con[256];
+ for ( ;; ) {
+ t >> len;
+ if ( len == 0 )
+ return TQTranslatorMessage();
+ t.readRawBytes( con, len );
+ con[len] = '\0';
+ if ( qstrcmp(con, context) == 0 )
+ break;
+ }
+ }
+
+ size_t numItems = d->offsetArray->size() / ( 2 * sizeof(TQ_UINT32) );
+ if ( !numItems )
+ return TQTranslatorMessage();
+
+ if ( systemWordSize == 0 )
+ qSysInfo( &systemWordSize, &systemBigEndian );
+
+ for ( ;; ) {
+ TQ_UINT32 h = elfHash( TQCString(sourceText) + comment );
+
+ char *r = (char *) bsearch( &h, d->offsetArray->data(), numItems,
+ 2 * sizeof(TQ_UINT32),
+ systemBigEndian ? cmp_uint32_big
+ : cmp_uint32_little );
+ if ( r != 0 ) {
+ // go back on equal key
+ while ( r != d->offsetArray->data() &&
+ cmp_uint32_big(r - 8, r) == 0 )
+ r -= 8;
+
+ TQDataStream s( *d->offsetArray, IO_ReadOnly );
+ s.tqdevice()->at( r - d->offsetArray->data() );
+
+ TQ_UINT32 rh, ro;
+ s >> rh >> ro;
+
+ TQDataStream ms( *d->messageArray, IO_ReadOnly );
+ while ( rh == h ) {
+ ms.tqdevice()->at( ro );
+ TQTranslatorMessage m( ms );
+ if ( match(m.context(), context)
+ && match(m.sourceText(), sourceText)
+ && match(m.comment(), comment) )
+ return m;
+ if ( s.atEnd() )
+ break;
+ s >> rh >> ro;
+ }
+ }
+ if ( !comment[0] )
+ break;
+ comment = "";
+ }
+ return TQTranslatorMessage();
+}
+
+// The functions below handle TQTranslatorMessage [USE_QT4]
+
+/*!
+ \class TQTranslatorMessage
+
+ \brief The TQTranslatorMessage class tqcontains a translator message and its
+ properties.
+
+ \ingroup i18n
+ \ingroup environment
+
+ This class is of no interest to most applications. It is useful
+ for translation tools such as \link linguist-manual.book TQt
+ Linguist\endlink. It is provided simply to make the API complete
+ and regular.
+
+ For a TQTranslator object, a lookup key is a triple (\e context, \e
+ {source text}, \e comment) that uniquely identifies a message. An
+ extended key is a quadruple (\e hash, \e context, \e {source
+ text}, \e comment), where \e hash is computed from the source text
+ and the comment. Unless you plan to read and write messages
+ yourself, you need not worry about the hash value.
+
+ TQTranslatorMessage stores this triple or quadruple and the relevant
+ translation if there is any.
+
+ \sa TQTranslator
+*/
+
+/*!
+ Constructs a translator message with the extended key (0, 0, 0, 0)
+ and TQString::null as translation.
+*/
+
+TQTranslatorMessage::TQTranslatorMessage()
+ : h( 0 ), cx( 0 ), st( 0 ), cm( 0 )
+{
+}
+
+
+/*!
+ Constructs an translator message with the extended key (\e h, \a
+ context, \a sourceText, \a comment), where \e h is computed from
+ \a sourceText and \a comment, and possibly with a \a translation.
+*/
+
+TQTranslatorMessage::TQTranslatorMessage( const char * context,
+ const char * sourceText,
+ const char * comment,
+ const TQString& translation )
+ : cx( context ), st( sourceText ), cm( comment ), tn( translation )
+{
+ // 0 means we don't know, "" means empty
+ if ( cx == (const char*)0 )
+ cx = "";
+ if ( st == (const char*)0 )
+ st = "";
+ if ( cm == (const char*)0 )
+ cm = "";
+ h = elfHash( st + cm );
+}
+
+
+/*!
+ Constructs a translator message read from the \a stream. The
+ resulting message may have any combination of content.
+
+ \sa TQTranslator::save()
+*/
+
+TQTranslatorMessage::TQTranslatorMessage( TQDataStream & stream )
+ : cx( 0 ), st( 0 ), cm( 0 )
+{
+ TQString str16;
+ char tag;
+ TQ_UINT8 obs1;
+
+ for ( ;; ) {
+ tag = 0;
+ if ( !stream.atEnd() )
+ stream.readRawBytes( &tag, 1 );
+ switch( (Tag)tag ) {
+ case Tag_End:
+ if ( h == 0 )
+ h = elfHash( st + cm );
+ return;
+ case Tag_SourceText16: // obsolete
+ stream >> str16;
+ st = str16.latin1();
+ break;
+ case Tag_Translation:
+ stream >> tn;
+ break;
+ case Tag_Context16: // obsolete
+ stream >> str16;
+ cx = str16.latin1();
+ break;
+ case Tag_Hash:
+ stream >> h;
+ break;
+ case Tag_SourceText:
+ stream >> st;
+ break;
+ case Tag_Context:
+ stream >> cx;
+ if ( cx == "" ) // for compatibility
+ cx = 0;
+ break;
+ case Tag_Comment:
+ stream >> cm;
+ break;
+ case Tag_Obsolete1: // obsolete
+ stream >> obs1;
+ break;
+ default:
+ h = 0;
+ st = 0;
+ cx = 0;
+ cm = 0;
+ tn = TQString::null;
+ return;
+ }
+ }
+}
+
+
+/*!
+ Constructs a copy of translator message \a m.
+*/
+
+TQTranslatorMessage::TQTranslatorMessage( const TQTranslatorMessage & m )
+ : cx( m.cx ), st( m.st ), cm( m.cm ), tn( m.tn )
+{
+ h = m.h;
+}
+
+
+/*!
+ Assigns message \a m to this translator message and returns a
+ reference to this translator message.
+*/
+
+TQTranslatorMessage & TQTranslatorMessage::operator=(
+ const TQTranslatorMessage & m )
+{
+ h = m.h;
+ cx = m.cx;
+ st = m.st;
+ cm = m.cm;
+ tn = m.tn;
+ return *this;
+}
+
+
+/*!
+ \fn uint TQTranslatorMessage::hash() const
+
+ Returns the hash value used internally to represent the lookup
+ key. This value is zero only if this translator message was
+ constructed from a stream containing invalid data.
+
+ The hashing function is unspecified, but it will remain unchanged
+ in future versions of TQt.
+*/
+
+/*!
+ \fn const char *TQTranslatorMessage::context() const
+
+ Returns the context for this message (e.g. "MyDialog").
+
+ \warning This may return 0 if the TQTranslator object is stripped
+ (compressed).
+*/
+
+/*!
+ \fn const char *TQTranslatorMessage::sourceText() const
+
+ Returns the source text of this message (e.g. "&Save").
+
+ \warning This may return 0 if the TQTranslator object is stripped
+ (compressed).
+*/
+
+/*!
+ \fn const char *TQTranslatorMessage::comment() const
+
+ Returns the comment for this message (e.g. "File|Save").
+
+ \warning This may return 0 if the TQTranslator object is stripped
+ (compressed).
+*/
+
+/*!
+ \fn void TQTranslatorMessage::setTranslation( const TQString & translation )
+
+ Sets the translation of the source text to \a translation.
+
+ \sa translation()
+*/
+
+/*!
+ \fn TQString TQTranslatorMessage::translation() const
+
+ Returns the translation of the source text (e.g., "&Sauvegarder").
+
+ \sa setTranslation()
+*/
+
+/*!
+ \enum TQTranslatorMessage::Prefix
+
+ Let (\e h, \e c, \e s, \e m) be the extended key. The possible
+ prefixes are
+
+ \value NoPrefix no prefix
+ \value Hash only (\e h)
+ \value HashContext only (\e h, \e c)
+ \value HashContextSourceText only (\e h, \e c, \e s)
+ \value HashContextSourceTextComment the whole extended key, (\e
+ h, \e c, \e s, \e m)
+
+ \sa write() commonPrefix()
+*/
+
+/*!
+ Writes this translator message to the \a stream. If \a strip is
+ FALSE (the default), all the information in the message is
+ written. If \a strip is TRUE, only the part of the extended key
+ specified by \a prefix is written with the translation (\c
+ HashContextSourceTextComment by default).
+
+ \sa commonPrefix()
+*/
+
+void TQTranslatorMessage::write( TQDataStream & stream, bool strip,
+ Prefix prefix ) const
+{
+ char tag;
+
+ tag = (char)Tag_Translation;
+ stream.writeRawBytes( &tag, 1 );
+ stream << tn;
+
+ bool mustWriteHash = TRUE;
+ if ( !strip )
+ prefix = HashContextSourceTextComment;
+
+ switch ( prefix ) {
+ case HashContextSourceTextComment:
+ tag = (char)Tag_Comment;
+ stream.writeRawBytes( &tag, 1 );
+ stream << cm;
+ // fall through
+ case HashContextSourceText:
+ tag = (char)Tag_SourceText;
+ stream.writeRawBytes( &tag, 1 );
+ stream << st;
+ // fall through
+ case HashContext:
+ tag = (char)Tag_Context;
+ stream.writeRawBytes( &tag, 1 );
+ stream << cx;
+ // fall through
+ default:
+ if ( mustWriteHash ) {
+ tag = (char)Tag_Hash;
+ stream.writeRawBytes( &tag, 1 );
+ stream << h;
+ }
+ }
+
+ tag = (char)Tag_End;
+ stream.writeRawBytes( &tag, 1 );
+}
+
+
+/*!
+ Returns the widest lookup prefix that is common to this translator
+ message and to message \a m.
+
+ For example, if the extended key is for this message is (71,
+ "PrintDialog", "Yes", "Print?") and that for \a m is (71,
+ "PrintDialog", "No", "Print?"), this function returns \c
+ HashContext.
+
+ \sa write()
+*/
+
+TQTranslatorMessage::Prefix TQTranslatorMessage::commonPrefix(
+ const TQTranslatorMessage& m ) const
+{
+ if ( h != m.h )
+ return NoPrefix;
+ if ( cx != m.cx )
+ return Hash;
+ if ( st != m.st )
+ return HashContext;
+ if ( cm != m.cm )
+ return HashContextSourceText;
+ return HashContextSourceTextComment;
+}
+
+
+/*!
+ Returns TRUE if the extended key of this object is equal to that of
+ \a m; otherwise returns FALSE.
+*/
+
+bool TQTranslatorMessage::operator==( const TQTranslatorMessage& m ) const
+{
+ return h == m.h && cx == m.cx && st == m.st && cm == m.cm;
+}
+
+
+/*!
+ \fn bool TQTranslatorMessage::operator!=( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is different from
+ that of \a m; otherwise returns FALSE.
+*/
+
+
+/*!
+ Returns TRUE if the extended key of this object is
+ lexicographically before than that of \a m; otherwise returns
+ FALSE.
+*/
+
+bool TQTranslatorMessage::operator<( const TQTranslatorMessage& m ) const
+{
+ return h != m.h ? h < m.h
+ : ( cx != m.cx ? cx < m.cx
+ : (st != m.st ? st < m.st : cm < m.cm) );
+}
+
+
+/*!
+ \fn bool TQTranslatorMessage::operator<=( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is
+ lexicographically before that of \a m or if they are equal;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQTranslatorMessage::operator>( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is
+ lexicographically after that of \a m; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQTranslatorMessage::operator>=( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is
+ lexicographically after that of \a m or if they are equal;
+ otherwise returns FALSE.
+*/
+
+#else // USE_QT4
+
+/*
+$ mcookie
+3cb86418caef9c95cd211cbf60a1bddd
+$
+*/
+
+// magic number for the file
+static const int MagicLength = 16;
+static const uchar magic[MagicLength] = {
+ 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
+ 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd
+};
+
+static bool match( const char* found, const char* target )
+{
+ // 0 means anything, "" means empty
+ return found == 0 || qstrcmp( found, target ) == 0;
+}
+
+#if defined(TQ_C_CALLBACKS)
+extern "C" {
+#endif
+
+/*
+ Yes, unfortunately, we have code here that depends on endianness.
+ The candidate is big endian (it comes from a .qm file) whereas the
+ target endianness depends on the system TQt is running on.
+*/
+#ifdef TQ_OS_TEMP
+static int __cdecl cmp_uint32_little( const void* target, const void* candidate )
+#else
+static int cmp_uint32_little( const void* target, const void* candidate )
+#endif
+{
+ const uchar* t = (const uchar*) target;
+ const uchar* c = (const uchar*) candidate;
+ return t[3] != c[0] ? (int) t[3] - (int) c[0]
+ : t[2] != c[1] ? (int) t[2] - (int) c[1]
+ : t[1] != c[2] ? (int) t[1] - (int) c[2]
+ : (int) t[0] - (int) c[3];
+}
+
+#ifdef TQ_OS_TEMP
+static int __cdecl cmp_uint32_big( const void* target, const void* candidate )
+#else
+static int cmp_uint32_big( const void* target, const void* candidate )
+#endif
+{
+ const uchar* t = (const uchar*) target;
+ const uchar* c = (const uchar*) candidate;
+ return t[0] != c[0] ? (int) t[0] - (int) c[0]
+ : t[1] != c[1] ? (int) t[1] - (int) c[1]
+ : t[2] != c[2] ? (int) t[2] - (int) c[2]
+ : (int) t[3] - (int) c[3];
+}
+
+#if defined(TQ_C_CALLBACKS)
+}
+#endif
+
+static int systemWordSize = 0;
+static bool systemBigEndian;
+
+static uint elfHash( const char * name )
+{
+ const uchar *k;
+ uint h = 0;
+ uint g;
+
+ if ( name ) {
+ k = (const uchar *) name;
+ while ( *k ) {
+ h = ( h << 4 ) + *k++;
+ if ( (g = (h & 0xf0000000)) != 0 )
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ }
+ if ( !h )
+ h = 1;
+ return h;
+}
+
+extern bool qt_detectRTLLanguage();
+
+class TQTranslatorPrivate {
+public:
+ struct Offset {
+ Offset()
+ : h( 0 ), o( 0 ) { }
+ Offset( const TQTranslatorMessage& m, int offset )
+ : h( m.hash() ), o( offset ) { }
+
+ bool operator<( const Offset&k ) const {
+ return ( h != k.h ) ? h < k.h : o < k.o;
+ }
+ TQ_DUMMY_COMPARISON_OPERATOR(TQTranslatorPrivate::Offset)
+ uint h;
+ uint o;
+ };
+
+ enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69 };
+
+ TQTranslatorPrivate() :
+ unmapPointer( 0 ), unmapLength( 0 ),
+ messageArray( 0 ), offsetArray( 0 ), contextArray( 0 )
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ , messages( 0 )
+#endif
+ { }
+ // TQTranslator must finalize this before deallocating it
+
+ // for mmap'ed files, this is what needs to be unmapped.
+ char * unmapPointer;
+ unsigned int unmapLength;
+
+ // for squeezed but non-file data, this is what needs to be deleted
+ TQByteArray * messageArray;
+ TQByteArray * offsetArray;
+ TQByteArray * contextArray;
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ TQMap<TQTranslatorMessage, void *> * messages;
+#endif
+#ifdef TQ_WS_WIN
+ int oldPermissionLookup;
+#endif
+};
+
+
+/*!
+ \class TQTranslator
+
+ \brief The TQTranslator class provides internationalization support for text
+ output.
+
+ \ingroup i18n
+ \ingroup environment
+ \mainclass
+
+ An object of this class tqcontains a set of TQTranslatorMessage
+ objects, each of which specifies a translation from a source
+ language to a target language. TQTranslator provides functions to
+ look up translations, add new ones, remove them, load and save
+ them, etc.
+
+ The most common use of TQTranslator is to: load a translator file
+ created with \link linguist-manual.book TQt Linguist\endlink,
+ install it using TQApplication::installTranslator(), and use it via
+ TQObject::tr(). For example:
+
+ \code
+ int main( int argc, char ** argv )
+ {
+ TQApplication app( argc, argv );
+
+ TQTranslator translator( 0 );
+ translator.load( "french.qm", "." );
+ app.installTranslator( &translator );
+
+ MyWidget m;
+ app.setMainWidget( &m );
+ m.show();
+
+ return app.exec();
+ }
+ \endcode
+ Note that the translator must be created \e before the
+ application's main window.
+
+ Most applications will never need to do anything else with this
+ class. The other functions provided by this class are useful for
+ applications that work on translator files.
+
+ We call a translation a "messsage". For this reason, translation
+ files are sometimes referred to as "message files".
+
+ It is possible to lookup a translation using tqfindMessage() (as
+ tr() and TQApplication::translate() do) and tqcontains(), to insert a
+ new translation messsage using insert(), and to remove one using
+ remove().
+
+ Translation tools often need more information than the bare source
+ text and translation, for example, context information to help
+ the translator. But end-user programs that are using translations
+ usually only need lookup. To cater for these different needs,
+ TQTranslator can use stripped translator files that use the minimum
+ of memory and which support little more functionality than
+ tqfindMessage().
+
+ Thus, load() may not load enough information to make anything more
+ than tqfindMessage() work. save() has an argument indicating
+ whether to save just this minimum of information or to save
+ everything.
+
+ "Everything" means that for each translation item the following
+ information is kept:
+
+ \list
+ \i The \e {translated text} - the return value from tr().
+ \i The input key:
+ \list
+ \i The \e {source text} - usually the argument to tr().
+ \i The \e context - usually the class name for the tr() caller.
+ \i The \e comment - a comment that helps disambiguate different uses
+ of the same text in the same context.
+ \endlist
+ \endlist
+
+ The minimum for each item is just the information necessary for
+ tqfindMessage() to return the right text. This may include the
+ source, context and comment, but usually it is just a hash value
+ and the translated text.
+
+ For example, the "Cancel" in a dialog might have "Anuluj" when the
+ program runs in Polish (in this case the source text would be
+ "Cancel"). The context would (normally) be the dialog's class
+ name; there would normally be no comment, and the translated text
+ would be "Anuluj".
+
+ But it's not always so simple. The Spanish version of a printer
+ dialog with settings for two-sided printing and binding would
+ probably require both "Activado" and "Activada" as translations
+ for "Enabled". In this case the source text would be "Enabled" in
+ both cases, and the context would be the dialog's class name, but
+ the two items would have disambiguating comments such as
+ "two-sided printing" for one and "binding" for the other. The
+ comment enables the translator to choose the appropriate gender
+ for the Spanish version, and enables TQt to distinguish between
+ translations.
+
+ Note that when TQTranslator loads a stripped file, most functions
+ do not work. The functions that do work with stripped files are
+ explicitly documented as such.
+
+ \sa TQTranslatorMessage TQApplication::installTranslator()
+ TQApplication::removeTranslator() TQObject::tr() TQApplication::translate()
+*/
+
+/*!
+ \enum TQTranslator::SaveMode
+
+ This enum type defines how TQTranslator writes translation
+ files. There are two modes:
+
+ \value Everything files are saved with all available information
+ \value Stripped files are saved with just enough information for
+ end-user applications
+
+ Note that when TQTranslator loads a stripped file, most functions do
+ not work. The functions that do work with stripped files are
+ explicitly documented as such.
+*/
+
+#if defined(TQ_WS_WIN)
+extern int qt_ntfs_permission_lookup;
+#endif
+
+/*!
+ Constructs an empty message file object that is not connected to
+ any file. The object is called \a name with tqparent \a tqparent.
+*/
+
+TQTranslator::TQTranslator( TQObject * tqparent, const char * name )
+ : TQObject( tqparent, name )
+{
+ d = new TQTranslatorPrivate;
+#if defined(TQ_WS_WIN)
+ d->oldPermissionLookup = qt_ntfs_permission_lookup;
+#endif
+}
+
+
+/*!
+ Destroys the object and frees any allocated resources.
+*/
+
+TQTranslator::~TQTranslator()
+{
+ if ( tqApp )
+ tqApp->removeTranslator( this );
+ clear();
+ delete d;
+}
+
+
+extern bool qt_detectRTLLanguage();
+
+/*!
+ Loads \a filename, which may be an absolute file name or relative
+ to \a directory. The previous contents of this translator object
+ is discarded. Returns TRUE if the file is loaded successfully;
+ otherwise returns FALSE.
+
+ If the full file name does not exist, other file names are tried
+ in the following order:
+
+ \list 1
+ \i File name with \a suffix appended (".qm" if the \a suffix is
+ TQString::null).
+ \i File name with text after a character in \a search_delimiters
+ stripped ("_." is the default for \a search_delimiters if it is
+ TQString::null).
+ \i File name stripped and \a suffix appended.
+ \i File name stripped further, etc.
+ \endlist
+
+ For example, an application running in the fr_CA locale
+ (French-speaking Canada) might call load("foo.fr_ca",
+ "/opt/foolib"). load() would then try to open the first existing
+ readable file from this list:
+
+ \list 1
+ \i /opt/foolib/foo.fr_ca
+ \i /opt/foolib/foo.fr_ca.qm
+ \i /opt/foolib/foo.fr
+ \i /opt/foolib/foo.fr.qm
+ \i /opt/foolib/foo
+ \i /opt/foolib/foo.qm
+ \endlist
+
+ \sa save()
+*/
+
+bool TQTranslator::load( const TQString & filename, const TQString & directory,
+ const TQString & search_delimiters,
+ const TQString & suffix )
+{
+ clear();
+
+ TQString prefix;
+
+ if ( filename[0] == '/'
+#ifdef TQ_WS_WIN
+ || (filename[0] && filename[1] == ':') || filename[0] == '\\'
+#endif
+ )
+ prefix = TQString::tqfromLatin1( "" );
+ else
+ prefix = directory;
+
+ if ( prefix.length() ) {
+ if ( prefix[int(prefix.length()-1)] != '/' )
+ prefix += TQChar( '/' );
+ }
+
+ TQString fname = filename;
+ TQString realname;
+ TQString delims;
+ delims = search_delimiters.isNull() ?
+ TQString::tqfromLatin1( "_." ) : search_delimiters;
+
+#if defined(TQ_WS_WIN)
+ qt_ntfs_permission_lookup--;
+#endif
+ for ( ;; ) {
+ TQFileInfo fi;
+
+ realname = prefix + fname;
+ fi.setFile( realname );
+ if ( fi.isReadable() )
+ break;
+
+ realname += suffix.isNull() ? TQString::tqfromLatin1( ".qm" ) : suffix;
+ fi.setFile( realname );
+ if ( fi.isReadable() )
+ break;
+
+ int rightmost = 0;
+ for ( int i = 0; i < (int)delims.length(); i++ ) {
+ int k = fname.tqfindRev( delims[i] );
+ if ( k > rightmost )
+ rightmost = k;
+ }
+
+ // no truncations? fail
+ if ( rightmost == 0 ) {
+#if defined(TQ_WS_WIN)
+ if (d->oldPermissionLookup != qt_ntfs_permission_lookup)
+ qt_ntfs_permission_lookup++;
+#endif
+ return FALSE;
+ }
+
+ fname.truncate( rightmost );
+ }
+#if defined(TQ_WS_WIN)
+ if (d->oldPermissionLookup != qt_ntfs_permission_lookup)
+ qt_ntfs_permission_lookup++;
+#endif
+
+ // realname is now the fully qualified name of a readable file.
+
+#if defined(TQT_USE_MMAP)
+
+#ifndef MAP_FILE
+#define MAP_FILE 0
+#endif
+#ifndef MAP_FAILED
+#define MAP_FAILED -1
+#endif
+
+ int f;
+
+ f = qt_open( TQFile::encodeName(realname), O_RDONLY, 0666 );
+ if ( f < 0 ) {
+ // qDebug( "can't open %s: %s", realname.ascii(), strerror( errno ) );
+ return FALSE;
+ }
+
+ struct stat st;
+ if ( fstat( f, &st ) ) {
+ // qDebug( "can't stat %s: %s", realname.ascii(), strerror( errno ) );
+ return FALSE;
+ }
+ char * tmp;
+ tmp = (char*)mmap( 0, st.st_size, // any address, whole file
+ PROT_READ, // read-only memory
+ MAP_FILE | MAP_PRIVATE, // swap-backed map from file
+ f, 0 ); // from offset 0 of f
+ if ( !tmp || tmp == (char*)MAP_FAILED ) {
+ // qDebug( "can't mmap %s: %s", filename.ascii(), strerror( errno ) );
+ return FALSE;
+ }
+
+ ::close( f );
+
+ d->unmapPointer = tmp;
+ d->unmapLength = st.st_size;
+#else
+ TQFile f( realname );
+ if ( !f.exists() )
+ return FALSE;
+ d->unmapLength = f.size();
+ d->unmapPointer = new char[d->unmapLength];
+ bool ok = FALSE;
+ if ( f.open(IO_ReadOnly) ) {
+ ok = d->unmapLength ==
+ (uint)f.readBlock( d->unmapPointer, d->unmapLength );
+ f.close();
+ }
+ if ( !ok ) {
+ delete [] d->unmapPointer;
+ d->unmapPointer = 0;
+ return FALSE;
+ }
+#endif
+
+ return do_load( (const uchar *) d->unmapPointer, d->unmapLength );
+}
+
+/*!
+ \overload
+ \fn bool TQTranslator::load( const uchar *data, int len )
+
+ Loads the .qm file data \a data of length \a len into the
+ translator. Returns TRUE if the data is loaded successfully;
+ otherwise returns FALSE.
+
+ The data is not copied. The caller must be able to guarantee that \a data
+ will not be deleted or modified.
+*/
+
+bool TQTranslator::do_load( const uchar *data, int len )
+{
+ if ( len < MagicLength || memcmp( data, magic, MagicLength ) != 0 ) {
+ clear();
+ return FALSE;
+ }
+
+ TQByteArray array;
+ array.setRawData( (const char *) data, len );
+ TQDataStream s( array, IO_ReadOnly );
+ bool ok = TRUE;
+
+ s.tqdevice()->at( MagicLength );
+
+ TQ_UINT8 tag = 0;
+ TQ_UINT32 blockLen = 0;
+ s >> tag >> blockLen;
+ while ( tag && blockLen ) {
+ if ( (TQ_UINT32) s.tqdevice()->at() + blockLen > (TQ_UINT32) len ) {
+ ok = FALSE;
+ break;
+ }
+
+ if ( tag == TQTranslatorPrivate::Contexts && !d->contextArray ) {
+ d->contextArray = new TQByteArray;
+ d->contextArray->setRawData( array.data() + s.tqdevice()->at(),
+ blockLen );
+ } else if ( tag == TQTranslatorPrivate::Hashes && !d->offsetArray ) {
+ d->offsetArray = new TQByteArray;
+ d->offsetArray->setRawData( array.data() + s.tqdevice()->at(),
+ blockLen );
+ } else if ( tag == TQTranslatorPrivate::Messages && !d->messageArray ) {
+ d->messageArray = new TQByteArray;
+ d->messageArray->setRawData( array.data() + s.tqdevice()->at(),
+ blockLen );
+ }
+
+ if ( !s.tqdevice()->at(s.tqdevice()->at() + blockLen) ) {
+ ok = FALSE;
+ break;
+ }
+ tag = 0;
+ blockLen = 0;
+ if ( !s.atEnd() )
+ s >> tag >> blockLen;
+ }
+ array.resetRawData( (const char *) data, len );
+
+ if ( tqApp && tqApp->translators && tqApp->translators->tqcontains(this) )
+ tqApp->setReverseLayout( qt_detectRTLLanguage() );
+ return ok;
+}
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+
+/*!
+ Saves this message file to \a filename, overwriting the previous
+ contents of \a filename. If \a mode is \c Everything (the
+ default), all the information is preserved. If \a mode is \c
+ Stripped, any information that is not necessary for tqfindMessage()
+ is stripped away.
+
+ \sa load()
+*/
+
+bool TQTranslator::save( const TQString & filename, SaveMode mode )
+{
+ TQFile f( filename );
+ if ( f.open( IO_WriteOnly ) ) {
+ squeeze( mode );
+
+ TQDataStream s( &f );
+ s.writeRawBytes( (const char *)magic, MagicLength );
+ TQ_UINT8 tag;
+
+ if ( d->offsetArray != 0 ) {
+ tag = (TQ_UINT8) TQTranslatorPrivate::Hashes;
+ TQ_UINT32 oas = (TQ_UINT32) d->offsetArray->size();
+ s << tag << oas;
+ s.writeRawBytes( d->offsetArray->data(), oas );
+ }
+ if ( d->messageArray != 0 ) {
+ tag = (TQ_UINT8) TQTranslatorPrivate::Messages;
+ TQ_UINT32 mas = (TQ_UINT32) d->messageArray->size();
+ s << tag << mas;
+ s.writeRawBytes( d->messageArray->data(), mas );
+ }
+ if ( d->contextArray != 0 ) {
+ tag = (TQ_UINT8) TQTranslatorPrivate::Contexts;
+ TQ_UINT32 cas = (TQ_UINT32) d->contextArray->size();
+ s << tag << cas;
+ s.writeRawBytes( d->contextArray->data(), cas );
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+#endif
+
+/*!
+ Empties this translator of all contents.
+
+ This function works with stripped translator files.
+*/
+
+void TQTranslator::clear()
+{
+ if ( d->unmapPointer && d->unmapLength ) {
+#if defined(TQT_USE_MMAP)
+ munmap( d->unmapPointer, d->unmapLength );
+#else
+ delete [] d->unmapPointer;
+#endif
+ d->unmapPointer = 0;
+ d->unmapLength = 0;
+ }
+
+ if ( d->messageArray ) {
+ d->messageArray->resetRawData( d->messageArray->data(),
+ d->messageArray->size() );
+ delete d->messageArray;
+ d->messageArray = 0;
+ }
+ if ( d->offsetArray ) {
+ d->offsetArray->resetRawData( d->offsetArray->data(),
+ d->offsetArray->size() );
+ delete d->offsetArray;
+ d->offsetArray = 0;
+ }
+ if ( d->contextArray ) {
+ d->contextArray->resetRawData( d->contextArray->data(),
+ d->contextArray->size() );
+ delete d->contextArray;
+ d->contextArray = 0;
+ }
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ delete d->messages;
+ d->messages = 0;
+#endif
+
+ if ( tqApp ) {
+ tqApp->setReverseLayout( qt_detectRTLLanguage() );
+
+ TQWidgetList *list = TQApplication::tqtopLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget *w;
+ while ( ( w=it.current() ) != 0 ) {
+ ++it;
+ if (!w->isDesktop())
+ tqApp->postEvent( w, new TQEvent( TQEvent::LanguageChange ) );
+ }
+ delete list;
+ }
+}
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+
+/*!
+ Converts this message file to the compact format used to store
+ message files on disk.
+
+ You should never need to call this directly; save() and other
+ functions call it as necessary. \a mode is for internal use.
+
+ \sa save() unsqueeze()
+*/
+
+void TQTranslator::squeeze( SaveMode mode )
+{
+ if ( !d->messages ) {
+ if ( mode == Stripped )
+ unsqueeze();
+ else
+ return;
+ }
+
+ TQMap<TQTranslatorMessage, void *> * messages = d->messages;
+
+ d->messages = 0;
+ clear();
+
+ d->messageArray = new TQByteArray;
+ d->offsetArray = new TQByteArray;
+
+ TQMap<TQTranslatorPrivate::Offset, void *> offsets;
+
+ TQDataStream ms( *d->messageArray, IO_WriteOnly );
+ TQMap<TQTranslatorMessage, void *>::Iterator it = messages->begin(), next;
+ int cpPrev = 0, cpNext = 0;
+ for ( it = messages->begin(); it != messages->end(); ++it ) {
+ cpPrev = cpNext;
+ next = it;
+ ++next;
+ if ( next == messages->end() )
+ cpNext = 0;
+ else
+ cpNext = (int) it.key().commonPrefix( next.key() );
+ offsets.tqreplace( TQTranslatorPrivate::Offset(it.key(),
+ ms.tqdevice()->at()), (void*)0 );
+ it.key().write( ms, mode == Stripped,
+ (TQTranslatorMessage::Prefix) TQMAX(cpPrev, cpNext + 1) );
+ }
+
+ d->offsetArray->resize( 0 );
+ TQMap<TQTranslatorPrivate::Offset, void *>::Iterator offset;
+ offset = offsets.begin();
+ TQDataStream ds( *d->offsetArray, IO_WriteOnly );
+ while ( offset != offsets.end() ) {
+ TQTranslatorPrivate::Offset k = offset.key();
+ ++offset;
+ ds << (TQ_UINT32)k.h << (TQ_UINT32)k.o;
+ }
+
+ if ( mode == Stripped ) {
+ TQAsciiDict<int> contextSet( 1511 );
+ int baudelaire;
+
+ for ( it = messages->begin(); it != messages->end(); ++it )
+ contextSet.tqreplace( it.key().context(), &baudelaire );
+
+ TQ_UINT16 hTableSize;
+ if ( contextSet.count() < 200 )
+ hTableSize = ( contextSet.count() < 60 ) ? 151 : 503;
+ else if ( contextSet.count() < 2500 )
+ hTableSize = ( contextSet.count() < 750 ) ? 1511 : 5003;
+ else
+ hTableSize = 15013;
+
+ TQIntDict<char> hDict( hTableSize );
+ TQAsciiDictIterator<int> c = contextSet;
+ while ( c.current() != 0 ) {
+ hDict.insert( (long) (elfHash(c.currentKey()) % hTableSize),
+ c.currentKey() );
+ ++c;
+ }
+
+ /*
+ The contexts found in this translator are stored in a hash
+ table to provide fast lookup. The context array has the
+ following format:
+
+ TQ_UINT16 hTableSize;
+ TQ_UINT16 hTable[hTableSize];
+ TQ_UINT8 contextPool[...];
+
+ The context pool stores the contexts as Pascal strings:
+
+ TQ_UINT8 len;
+ TQ_UINT8 data[len];
+
+ Let's consider the look-up of context "FunnyDialog". A
+ hash value between 0 and hTableSize - 1 is computed, say h.
+ If hTable[h] is 0, "FunnyDialog" is not covered by this
+ translator. Else, we check in the contextPool at offset
+ 2 * hTable[h] to see if "FunnyDialog" is one of the
+ contexts stored there, until we tqfind it or we meet the
+ empty string.
+ */
+ d->contextArray = new TQByteArray;
+ d->contextArray->resize( 2 + (hTableSize << 1) );
+ TQDataStream t( *d->contextArray, IO_WriteOnly );
+ TQ_UINT16 *hTable = new TQ_UINT16[hTableSize];
+ memset( hTable, 0, hTableSize * sizeof(TQ_UINT16) );
+
+ t << hTableSize;
+ t.tqdevice()->at( 2 + (hTableSize << 1) );
+ t << (TQ_UINT16) 0; // the entry at offset 0 cannot be used
+ uint upto = 2;
+
+ for ( int i = 0; i < hTableSize; i++ ) {
+ const char *con = hDict.tqfind( i );
+ if ( con == 0 ) {
+ hTable[i] = 0;
+ } else {
+ hTable[i] = (TQ_UINT16) ( upto >> 1 );
+ do {
+ uint len = (uint) tqstrlen( con );
+ len = TQMIN( len, 255 );
+ t << (TQ_UINT8) len;
+ t.writeRawBytes( con, len );
+ upto += 1 + len;
+ hDict.remove( i );
+ } while ( (con = hDict.tqfind(i)) != 0 );
+ do {
+ t << (TQ_UINT8) 0; // empty string (at least one)
+ upto++;
+ } while ( (upto & 0x1) != 0 ); // offsets have to be even
+ }
+ }
+ t.tqdevice()->at( 2 );
+ for ( int j = 0; j < hTableSize; j++ )
+ t << hTable[j];
+ delete [] hTable;
+
+ if ( upto > 131072 ) {
+ qWarning( "TQTranslator::squeeze: Too many contexts" );
+ delete d->contextArray;
+ d->contextArray = 0;
+ }
+ }
+ delete messages;
+}
+
+
+/*!
+ Converts this message file into an easily modifiable data
+ structure, less compact than the format used in the files.
+
+ You should never need to call this function; it is called by
+ insert() and friends as necessary.
+
+ \sa squeeze()
+*/
+
+void TQTranslator::unsqueeze()
+{
+ if ( d->messages )
+ return;
+
+ d->messages = new TQMap<TQTranslatorMessage, void *>;
+ if ( !d->messageArray )
+ return;
+
+ TQDataStream s( *d->messageArray, IO_ReadOnly );
+ for ( ;; ) {
+ TQTranslatorMessage m( s );
+ if ( m.hash() == 0 )
+ break;
+ d->messages->insert( m, (void *) 0 );
+ }
+}
+
+
+/*!
+ Returns TRUE if this message file tqcontains a message with the key
+ (\a context, \a sourceText, \a comment); otherwise returns FALSE.
+
+ This function works with stripped translator files.
+
+ (This is is a one-liner that calls tqfindMessage().)
+*/
+
+bool TQTranslator::tqcontains( const char* context, const char* sourceText,
+ const char* comment ) const
+{
+ return !tqfindMessage( context, sourceText, comment ).translation().isNull();
+}
+
+
+/*!
+ Inserts \a message into this message file.
+
+ This function does \e not work with stripped translator files. It
+ may appear to, but that is not dependable.
+
+ \sa remove()
+*/
+
+void TQTranslator::insert( const TQTranslatorMessage& message )
+{
+ unsqueeze();
+ d->messages->remove( message ); // safer
+ d->messages->insert( message, (void *) 0 );
+}
+
+
+/*!
+ \fn void TQTranslator::insert( const char *, const char *, const TQString & )
+ \overload
+ \obsolete
+*/
+
+/*!
+ Removes \a message from this translator.
+
+ This function works with stripped translator files.
+
+ \sa insert()
+*/
+
+void TQTranslator::remove( const TQTranslatorMessage& message )
+{
+ unsqueeze();
+ d->messages->remove( message );
+}
+
+
+/*!
+ \fn void TQTranslator::remove( const char *, const char * )
+ \overload
+ \obsolete
+
+ Removes the translation associated to the key (\a context, \a sourceText,
+ "") from this translator.
+*/
+#endif
+
+/*!
+ \fn TQString TQTranslator::tqfind( const char*, const char*, const char* ) const
+ \obsolete
+
+ Please use tqfindMessage() instead.
+
+ Returns the translation for the key (\a context, \a sourceText,
+ \a comment) or TQString::null if there is none in this translator.
+*/
+
+/*! Returns the TQTranslatorMessage for the key
+ (\a context, \a sourceText, \a comment). If none is found,
+ also tries (\a context, \a sourceText, "").
+*/
+
+TQTranslatorMessage TQTranslator::tqfindMessage( const char* context,
+ const char* sourceText,
+ const char* comment ) const
+{
+ if ( context == 0 )
+ context = "";
+ if ( sourceText == 0 )
+ sourceText = "";
+ if ( comment == 0 )
+ comment = "";
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ if ( d->messages ) {
+ TQMap<TQTranslatorMessage, void *>::ConstIterator it;
+
+ it = d->messages->tqfind( TQTranslatorMessage(context, sourceText,
+ comment) );
+ if ( it != d->messages->end() )
+ return it.key();
+
+ if ( comment[0] ) {
+ it = d->messages->tqfind( TQTranslatorMessage(context, sourceText,
+ "") );
+ if ( it != d->messages->end() )
+ return it.key();
+ }
+ return TQTranslatorMessage();
+ }
+#endif
+
+ if ( !d->offsetArray )
+ return TQTranslatorMessage();
+
+ /*
+ Check if the context belongs to this TQTranslator. If many translators are
+ installed, this step is necessary.
+ */
+ if ( d->contextArray ) {
+ TQ_UINT16 hTableSize = 0;
+ TQDataStream t( *d->contextArray, IO_ReadOnly );
+ t >> hTableSize;
+ uint g = elfHash( context ) % hTableSize;
+ t.tqdevice()->at( 2 + (g << 1) );
+ TQ_UINT16 off;
+ t >> off;
+ if ( off == 0 )
+ return TQTranslatorMessage();
+ t.tqdevice()->at( 2 + (hTableSize << 1) + (off << 1) );
+
+ TQ_UINT8 len;
+ char con[256];
+ for ( ;; ) {
+ t >> len;
+ if ( len == 0 )
+ return TQTranslatorMessage();
+ t.readRawBytes( con, len );
+ con[len] = '\0';
+ if ( qstrcmp(con, context) == 0 )
+ break;
+ }
+ }
+
+ size_t numItems = d->offsetArray->size() / ( 2 * sizeof(TQ_UINT32) );
+ if ( !numItems )
+ return TQTranslatorMessage();
+
+ if ( systemWordSize == 0 )
+ qSysInfo( &systemWordSize, &systemBigEndian );
+
+ for ( ;; ) {
+ TQ_UINT32 h = elfHash( TQCString(sourceText) + comment );
+
+ char *r = (char *) bsearch( &h, d->offsetArray->data(), numItems,
+ 2 * sizeof(TQ_UINT32),
+ systemBigEndian ? cmp_uint32_big
+ : cmp_uint32_little );
+ if ( r != 0 ) {
+ // go back on equal key
+ while ( r != d->offsetArray->data() &&
+ cmp_uint32_big(r - 8, r) == 0 )
+ r -= 8;
+
+ TQDataStream s( *d->offsetArray, IO_ReadOnly );
+ s.tqdevice()->at( r - d->offsetArray->data() );
+
+ TQ_UINT32 rh, ro;
+ s >> rh >> ro;
+
+ TQDataStream ms( *d->messageArray, IO_ReadOnly );
+ while ( rh == h ) {
+ ms.tqdevice()->at( ro );
+ TQTranslatorMessage m( ms );
+ if ( match(m.context(), context)
+ && match(m.sourceText(), sourceText)
+ && match(m.comment(), comment) )
+ return m;
+ if ( s.atEnd() )
+ break;
+ s >> rh >> ro;
+ }
+ }
+ if ( !comment[0] )
+ break;
+ comment = "";
+ }
+ return TQTranslatorMessage();
+}
+
+/*!
+ Returns TRUE if this translator is empty, otherwise returns FALSE.
+ This function works with stripped and unstripped translation files.
+*/
+bool TQTranslator::isEmpty() const
+{
+ return !( d->unmapPointer || d->unmapLength || d->messageArray ||
+ d->offsetArray || d->contextArray
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ || (d->messages && d->messages->count())
+#endif
+ );
+}
+
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+
+/*!
+ Returns a list of the messages in the translator. This function is
+ rather slow. Because it is seldom called, it's optimized for
+ simplicity and small size, rather than speed.
+
+ If you want to iterate over the list, you should iterate over a
+ copy, e.g.
+ \code
+ TQValueList<TQTranslatorMessage> list = myTranslator.messages();
+ TQValueList<TQTranslatorMessage>::Iterator it = list.begin();
+ while ( it != list.end() ) {
+ process_message( *it );
+ ++it;
+ }
+ \endcode
+*/
+
+TQValueList<TQTranslatorMessage> TQTranslator::messages() const
+{
+ if ( d->messages )
+ return d->messages->keys();
+
+ ((TQTranslator *) this)->unsqueeze();
+ TQValueList<TQTranslatorMessage> result = d->messages->keys();
+ delete d->messages;
+ d->messages = 0;
+ return result;
+}
+
+#endif
+
+/*!
+ \class TQTranslatorMessage
+
+ \brief The TQTranslatorMessage class tqcontains a translator message and its
+ properties.
+
+ \ingroup i18n
+ \ingroup environment
+
+ This class is of no interest to most applications. It is useful
+ for translation tools such as \link linguist-manual.book TQt
+ Linguist\endlink. It is provided simply to make the API complete
+ and regular.
+
+ For a TQTranslator object, a lookup key is a triple (\e context, \e
+ {source text}, \e comment) that uniquely identifies a message. An
+ extended key is a quadruple (\e hash, \e context, \e {source
+ text}, \e comment), where \e hash is computed from the source text
+ and the comment. Unless you plan to read and write messages
+ yourself, you need not worry about the hash value.
+
+ TQTranslatorMessage stores this triple or quadruple and the relevant
+ translation if there is any.
+
+ \sa TQTranslator
+*/
+
+/*!
+ Constructs a translator message with the extended key (0, 0, 0, 0)
+ and TQString::null as translation.
+*/
+
+TQTranslatorMessage::TQTranslatorMessage()
+ : h( 0 ), cx( 0 ), st( 0 ), cm( 0 )
+{
+}
+
+
+/*!
+ Constructs an translator message with the extended key (\e h, \a
+ context, \a sourceText, \a comment), where \e h is computed from
+ \a sourceText and \a comment, and possibly with a \a translation.
+*/
+
+TQTranslatorMessage::TQTranslatorMessage( const char * context,
+ const char * sourceText,
+ const char * comment,
+ const TQString& translation )
+ : cx( context ), st( sourceText ), cm( comment ), tn( translation )
+{
+ // 0 means we don't know, "" means empty
+ if ( cx == (const char*)0 )
+ cx = "";
+ if ( st == (const char*)0 )
+ st = "";
+ if ( cm == (const char*)0 )
+ cm = "";
+ h = elfHash( st + cm );
+}
+
+
+/*!
+ Constructs a translator message read from the \a stream. The
+ resulting message may have any combination of content.
+
+ \sa TQTranslator::save()
+*/
+
+TQTranslatorMessage::TQTranslatorMessage( TQDataStream & stream )
+ : cx( 0 ), st( 0 ), cm( 0 )
+{
+ TQString str16;
+ char tag;
+ TQ_UINT8 obs1;
+
+ for ( ;; ) {
+ tag = 0;
+ if ( !stream.atEnd() )
+ stream.readRawBytes( &tag, 1 );
+ switch( (Tag)tag ) {
+ case Tag_End:
+ if ( h == 0 )
+ h = elfHash( st + cm );
+ return;
+ case Tag_SourceText16: // obsolete
+ stream >> str16;
+ st = str16.latin1();
+ break;
+ case Tag_Translation:
+ stream >> tn;
+ break;
+ case Tag_Context16: // obsolete
+ stream >> str16;
+ cx = str16.latin1();
+ break;
+ case Tag_Hash:
+ stream >> h;
+ break;
+ case Tag_SourceText:
+ stream >> st;
+ break;
+ case Tag_Context:
+ stream >> cx;
+ if ( cx == "" ) // for compatibility
+ cx = 0;
+ break;
+ case Tag_Comment:
+ stream >> cm;
+ break;
+ case Tag_Obsolete1: // obsolete
+ stream >> obs1;
+ break;
+ default:
+ h = 0;
+ st = 0;
+ cx = 0;
+ cm = 0;
+ tn = TQString::null;
+ return;
+ }
+ }
+}
+
+
+/*!
+ Constructs a copy of translator message \a m.
+*/
+
+TQTranslatorMessage::TQTranslatorMessage( const TQTranslatorMessage & m )
+ : cx( m.cx ), st( m.st ), cm( m.cm ), tn( m.tn )
+{
+ h = m.h;
+}
+
+
+/*!
+ Assigns message \a m to this translator message and returns a
+ reference to this translator message.
+*/
+
+TQTranslatorMessage & TQTranslatorMessage::operator=(
+ const TQTranslatorMessage & m )
+{
+ h = m.h;
+ cx = m.cx;
+ st = m.st;
+ cm = m.cm;
+ tn = m.tn;
+ return *this;
+}
+
+
+/*!
+ \fn uint TQTranslatorMessage::hash() const
+
+ Returns the hash value used internally to represent the lookup
+ key. This value is zero only if this translator message was
+ constructed from a stream containing invalid data.
+
+ The hashing function is unspecified, but it will remain unchanged
+ in future versions of TQt.
+*/
+
+/*!
+ \fn const char *TQTranslatorMessage::context() const
+
+ Returns the context for this message (e.g. "MyDialog").
+
+ \warning This may return 0 if the TQTranslator object is stripped
+ (compressed).
+*/
+
+/*!
+ \fn const char *TQTranslatorMessage::sourceText() const
+
+ Returns the source text of this message (e.g. "&Save").
+
+ \warning This may return 0 if the TQTranslator object is stripped
+ (compressed).
+*/
+
+/*!
+ \fn const char *TQTranslatorMessage::comment() const
+
+ Returns the comment for this message (e.g. "File|Save").
+
+ \warning This may return 0 if the TQTranslator object is stripped
+ (compressed).
+*/
+
+/*!
+ \fn void TQTranslatorMessage::setTranslation( const TQString & translation )
+
+ Sets the translation of the source text to \a translation.
+
+ \sa translation()
+*/
+
+/*!
+ \fn TQString TQTranslatorMessage::translation() const
+
+ Returns the translation of the source text (e.g., "&Sauvegarder").
+
+ \sa setTranslation()
+*/
+
+/*!
+ \enum TQTranslatorMessage::Prefix
+
+ Let (\e h, \e c, \e s, \e m) be the extended key. The possible
+ prefixes are
+
+ \value NoPrefix no prefix
+ \value Hash only (\e h)
+ \value HashContext only (\e h, \e c)
+ \value HashContextSourceText only (\e h, \e c, \e s)
+ \value HashContextSourceTextComment the whole extended key, (\e
+ h, \e c, \e s, \e m)
+
+ \sa write() commonPrefix()
+*/
+
+/*!
+ Writes this translator message to the \a stream. If \a strip is
+ FALSE (the default), all the information in the message is
+ written. If \a strip is TRUE, only the part of the extended key
+ specified by \a prefix is written with the translation (\c
+ HashContextSourceTextComment by default).
+
+ \sa commonPrefix()
+*/
+
+void TQTranslatorMessage::write( TQDataStream & stream, bool strip,
+ Prefix prefix ) const
+{
+ char tag;
+
+ tag = (char)Tag_Translation;
+ stream.writeRawBytes( &tag, 1 );
+ stream << tn;
+
+ bool mustWriteHash = TRUE;
+ if ( !strip )
+ prefix = HashContextSourceTextComment;
+
+ switch ( prefix ) {
+ case HashContextSourceTextComment:
+ tag = (char)Tag_Comment;
+ stream.writeRawBytes( &tag, 1 );
+ stream << cm;
+ // fall through
+ case HashContextSourceText:
+ tag = (char)Tag_SourceText;
+ stream.writeRawBytes( &tag, 1 );
+ stream << st;
+ // fall through
+ case HashContext:
+ tag = (char)Tag_Context;
+ stream.writeRawBytes( &tag, 1 );
+ stream << cx;
+ // fall through
+ default:
+ if ( mustWriteHash ) {
+ tag = (char)Tag_Hash;
+ stream.writeRawBytes( &tag, 1 );
+ stream << h;
+ }
+ }
+
+ tag = (char)Tag_End;
+ stream.writeRawBytes( &tag, 1 );
+}
+
+
+/*!
+ Returns the widest lookup prefix that is common to this translator
+ message and to message \a m.
+
+ For example, if the extended key is for this message is (71,
+ "PrintDialog", "Yes", "Print?") and that for \a m is (71,
+ "PrintDialog", "No", "Print?"), this function returns \c
+ HashContext.
+
+ \sa write()
+*/
+
+TQTranslatorMessage::Prefix TQTranslatorMessage::commonPrefix(
+ const TQTranslatorMessage& m ) const
+{
+ if ( h != m.h )
+ return NoPrefix;
+ if ( cx != m.cx )
+ return Hash;
+ if ( st != m.st )
+ return HashContext;
+ if ( cm != m.cm )
+ return HashContextSourceText;
+ return HashContextSourceTextComment;
+}
+
+
+/*!
+ Returns TRUE if the extended key of this object is equal to that of
+ \a m; otherwise returns FALSE.
+*/
+
+bool TQTranslatorMessage::operator==( const TQTranslatorMessage& m ) const
+{
+ return h == m.h && cx == m.cx && st == m.st && cm == m.cm;
+}
+
+
+/*!
+ \fn bool TQTranslatorMessage::operator!=( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is different from
+ that of \a m; otherwise returns FALSE.
+*/
+
+
+/*!
+ Returns TRUE if the extended key of this object is
+ lexicographically before than that of \a m; otherwise returns
+ FALSE.
+*/
+
+bool TQTranslatorMessage::operator<( const TQTranslatorMessage& m ) const
+{
+ return h != m.h ? h < m.h
+ : ( cx != m.cx ? cx < m.cx
+ : (st != m.st ? st < m.st : cm < m.cm) );
+}
+
+
+/*!
+ \fn bool TQTranslatorMessage::operator<=( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is
+ lexicographically before that of \a m or if they are equal;
+ otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQTranslatorMessage::operator>( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is
+ lexicographically after that of \a m; otherwise returns FALSE.
+*/
+
+/*!
+ \fn bool TQTranslatorMessage::operator>=( const TQTranslatorMessage& m ) const
+
+ Returns TRUE if the extended key of this object is
+ lexicographically after that of \a m or if they are equal;
+ otherwise returns FALSE.
+*/
+
+#endif // USE_QT4
+
+#endif // TQT_NO_TRANSLATION
diff --git a/tqtinterface/qt4/src/kernel/tqtranslator.h b/tqtinterface/qt4/src/kernel/tqtranslator.h
new file mode 100644
index 0000000..b42c983
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqtranslator.h
@@ -0,0 +1,281 @@
+/****************************************************************************
+**
+** Definition of the translator class
+**
+** Created : 980906
+**
+** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+
+#ifndef TQTRANSLATOR_H
+#define TQTRANSLATOR_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqvaluelist.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_TRANSLATION
+
+#ifdef USE_QT4
+
+#undef QT_NO_TRANSLATION
+#include <Qt/qtranslator.h>
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQTranslatorPrivate;
+
+class TQ_EXPORT TQTranslatorMessage
+{
+public:
+ TQTranslatorMessage();
+ TQTranslatorMessage( const char * context,
+ const char * sourceText,
+ const char * comment,
+ const TQString& translation = TQString::null );
+ TQTranslatorMessage( TQDataStream & );
+ TQTranslatorMessage( const TQTranslatorMessage & m );
+
+ TQTranslatorMessage & operator=( const TQTranslatorMessage & m );
+
+ uint hash() const { return h; }
+ const char *context() const { return cx; }
+ const char *sourceText() const { return st; }
+ const char *comment() const { return cm; }
+
+ void setTranslation( const TQString & translation ) { tn = translation; }
+ TQString translation() const { return tn; }
+
+ enum Prefix { NoPrefix, Hash, HashContext, HashContextSourceText,
+ HashContextSourceTextComment };
+ void write( TQDataStream & s, bool strip = FALSE,
+ Prefix prefix = HashContextSourceTextComment ) const;
+ Prefix commonPrefix( const TQTranslatorMessage& ) const;
+
+ bool operator==( const TQTranslatorMessage& m ) const;
+ bool operator!=( const TQTranslatorMessage& m ) const
+ { return !operator==( m ); }
+ bool operator<( const TQTranslatorMessage& m ) const;
+ bool operator<=( const TQTranslatorMessage& m ) const
+ { return !m.operator<( *this ); }
+ bool operator>( const TQTranslatorMessage& m ) const
+ { return m.operator<( *this ); }
+ bool operator>=( const TQTranslatorMessage& m ) const
+ { return !operator<( m ); }
+
+private:
+ uint h;
+ TQCString cx;
+ TQCString st;
+ TQCString cm;
+ TQString tn;
+
+ enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16,
+ Tag_Hash, Tag_SourceText, Tag_Context, Tag_Comment,
+ Tag_Obsolete1 };
+};
+
+// TQTranslator is now a hybrid class that provides Qt4 compatible functionality for basic translations,
+// but also provides separate advanced level translation functions and methods via an independent TQTranslatorPrivate object.
+// Be aware that only the compatible functions can safely interface with Qt4/QApplication!!!
+//
+// See also tools/linguist/shared/translator.cpp for the inspiration behind this idea
+
+class TQ_EXPORT TQTranslator: public QTranslator, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQTranslator( TQObject * tqparent = 0, const char * name = 0 ) : QTranslator( tqparent ) { setObjectName(QString::fromAscii(name)); }
+
+ inline TQString find(const char *context, const char *sourceText, const char * comment = 0) const { return translate(context, sourceText, comment); }
+
+ // Everything below is part of the old API and is therefore incompatible with Qt4 functions which expect a pure QTranslator object or object pointer
+
+#ifndef TQT_NO_COMPAT
+ inline TQString tqfind( const char *context, const char *sourceText, const char * comment = 0 ) const { return tqfindMessage( context, sourceText, comment ).translation(); }
+#endif
+ virtual TQTranslatorMessage tqfindMessage( const char *, const char *, const char * = 0 ) const;
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ enum SaveMode { Everything, Stripped };
+
+ bool save( const TQString & filename, SaveMode mode = Everything );
+
+ void insert( const TQTranslatorMessage& );
+ inline void insert( const char *context, const char *sourceText, const TQString &translation ) { insert( TQTranslatorMessage(context, sourceText, "", translation) ); }
+ void remove( const TQTranslatorMessage& );
+ inline void remove( const char *context, const char *sourceText ) { remove( TQTranslatorMessage(context, sourceText, "") ); }
+
+ void squeeze( SaveMode = Everything );
+ void unsqueeze();
+
+ bool tqcontains( const char *, const char *, const char * comment = 0 ) const;
+
+ TQValueList<TQTranslatorMessage> messages() const;
+#endif
+
+ void clear();
+
+private:
+ TQTranslatorPrivate * d;
+};
+
+#else // USE_QT4
+
+class TQTranslatorPrivate;
+
+class TQ_EXPORT TQTranslatorMessage
+{
+public:
+ TQTranslatorMessage();
+ TQTranslatorMessage( const char * context,
+ const char * sourceText,
+ const char * comment,
+ const TQString& translation = TQString::null );
+ TQTranslatorMessage( TQDataStream & );
+ TQTranslatorMessage( const TQTranslatorMessage & m );
+
+ TQTranslatorMessage & operator=( const TQTranslatorMessage & m );
+
+ uint hash() const { return h; }
+ const char *context() const { return cx; }
+ const char *sourceText() const { return st; }
+ const char *comment() const { return cm; }
+
+ void setTranslation( const TQString & translation ) { tn = translation; }
+ TQString translation() const { return tn; }
+
+ enum Prefix { NoPrefix, Hash, HashContext, HashContextSourceText,
+ HashContextSourceTextComment };
+ void write( TQDataStream & s, bool strip = FALSE,
+ Prefix prefix = HashContextSourceTextComment ) const;
+ Prefix commonPrefix( const TQTranslatorMessage& ) const;
+
+ bool operator==( const TQTranslatorMessage& m ) const;
+ bool operator!=( const TQTranslatorMessage& m ) const
+ { return !operator==( m ); }
+ bool operator<( const TQTranslatorMessage& m ) const;
+ bool operator<=( const TQTranslatorMessage& m ) const
+ { return !m.operator<( *this ); }
+ bool operator>( const TQTranslatorMessage& m ) const
+ { return m.operator<( *this ); }
+ bool operator>=( const TQTranslatorMessage& m ) const
+ { return !operator<( m ); }
+
+private:
+ uint h;
+ TQCString cx;
+ TQCString st;
+ TQCString cm;
+ TQString tn;
+
+ enum Tag { Tag_End = 1, Tag_SourceText16, Tag_Translation, Tag_Context16,
+ Tag_Hash, Tag_SourceText, Tag_Context, Tag_Comment,
+ Tag_Obsolete1 };
+};
+
+
+class TQ_EXPORT TQTranslator: public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQTranslator( TQObject * tqparent = 0, const char * name = 0 );
+ ~TQTranslator();
+
+#ifndef TQT_NO_COMPAT
+ TQString tqfind( const char *context, const char *sourceText, const char * comment = 0 ) const {
+ return tqfindMessage( context, sourceText, comment ).translation();
+ }
+#endif
+ virtual TQTranslatorMessage tqfindMessage( const char *, const char *,
+ const char * = 0 ) const;
+
+ bool load( const TQString & filename,
+ const TQString & directory = TQString::null,
+ const TQString & search_delimiters = TQString::null,
+ const TQString & suffix = TQString::null );
+ bool load( const uchar *data, int len ) {
+ clear();
+ return do_load( data, len );
+ }
+
+ void clear();
+
+#ifndef TQT_NO_TRANSLATION_BUILDER
+ enum SaveMode { Everything, Stripped };
+
+ bool save( const TQString & filename, SaveMode mode = Everything );
+
+ void insert( const TQTranslatorMessage& );
+ void insert( const char *context, const char *sourceText, const TQString &translation ) {
+ insert( TQTranslatorMessage(context, sourceText, "", translation) );
+ }
+ void remove( const TQTranslatorMessage& );
+ void remove( const char *context, const char *sourceText ) {
+ remove( TQTranslatorMessage(context, sourceText, "") );
+ }
+ bool tqcontains( const char *, const char *, const char * comment = 0 ) const;
+
+ void squeeze( SaveMode = Everything );
+ void unsqueeze();
+
+ TQValueList<TQTranslatorMessage> messages() const;
+#endif
+
+ bool isEmpty() const;
+
+private:
+#if defined(TQ_DISABLE_COPY)
+ TQTranslator( const TQTranslator & );
+ TQTranslator &operator=( const TQTranslator & );
+#endif
+
+ bool do_load( const uchar *data, int len );
+
+ TQTranslatorPrivate * d;
+};
+
+#endif // USE_QT4
+
+#endif // TQT_NO_TRANSLATION
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqucomextra.cpp b/tqtinterface/qt4/src/kernel/tqucomextra.cpp
new file mode 100644
index 0000000..b2f401b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqucomextra.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Implementation of extra TQUcom classes
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqucomextra_p.h"
+#include <tqvariant.h>
+
+
+#ifndef TQT_NO_VARIANT
+// 6dc75d58-a1d9-4417-b591-d45c63a3a4ea
+const TQUuid TID_TQUType_TQVariant( 0x6dc75d58, 0xa1d9, 0x4417, 0xb5, 0x91, 0xd4, 0x5c, 0x63, 0xa3, 0xa4, 0xea );
+TQUType_TQVariant static_TQUType_TQVariant;
+
+const TQUuid *TQUType_TQVariant::uuid() const { return &TID_TQUType_TQVariant; }
+const char *TQUType_TQVariant::desc() const { return "TQVariant"; }
+
+void TQUType_TQVariant::set( TQUObject *o, const TQVariant& v )
+{
+ o->payload.ptr = new TQVariant( v );
+ o->type = this;
+}
+
+TQVariant &TQUType_TQVariant::get( TQUObject * o )
+{
+ return *(TQVariant*)o->payload.ptr;
+}
+
+bool TQUType_TQVariant::canConvertFrom( TQUObject *o, TQUType *t )
+{
+ if ( isEqual( o->type, &static_TQUType_TQString )
+ || isEqual( o->type, &static_TQUType_int )
+ || isEqual( o->type, &static_TQUType_bool )
+ || isEqual( o->type, &static_TQUType_double )
+ || isEqual( o->type, &static_TQUType_charstar ) )
+ return TRUE;
+ return t->canConvertTo( o, this );
+}
+
+bool TQUType_TQVariant::canConvertTo( TQUObject * /*o*/, TQUType * /*t*/ )
+{
+ return FALSE;
+}
+
+bool TQUType_TQVariant::convertFrom( TQUObject *o, TQUType *t )
+{
+ TQVariant *var = 0;
+ if ( isEqual( o->type, &static_TQUType_TQString ) )
+ var = new TQVariant( static_TQUType_TQString.get( o ) );
+ else if ( isEqual( o->type, &static_TQUType_int ) )
+ var = new TQVariant( static_TQUType_int.get( o ) );
+ else if ( isEqual( o->type, &static_TQUType_bool ) )
+ var = new TQVariant( static_TQUType_bool.get( o ), 42 );
+ else if ( isEqual( o->type, &static_TQUType_double ) )
+ var = new TQVariant( static_TQUType_double.get( o ) );
+ else if ( isEqual( o->type, &static_TQUType_charstar ) )
+ var = new TQVariant( static_TQUType_charstar.get( o ) );
+ else
+ return t->convertTo( o, this );
+
+ o->type->clear( o );
+ o->payload.ptr = var;
+ o->type = this;
+ return TRUE;
+}
+
+bool TQUType_TQVariant::convertTo( TQUObject * /*o*/, TQUType * /*t*/ )
+{
+ return FALSE;
+}
+
+void TQUType_TQVariant::clear( TQUObject *o )
+{
+ delete (TQVariant*)o->payload.ptr;
+ o->payload.ptr = 0;
+}
+
+int TQUType_TQVariant::serializeTo( TQUObject *, TQUBuffer * )
+{
+ return 0;
+}
+
+int TQUType_TQVariant::serializeFrom( TQUObject *, TQUBuffer * )
+{
+ return 0;
+}
+
+
+#endif
+
+const TQUuid TID_TQUType_varptr( 0x8d48b3a8, 0xbd7f, 0x11d5, 0x8d, 0x74, 0x00, 0xc0, 0xf0, 0x3b, 0xc0, 0xf3 );
+TQUType_varptr static_TQUType_varptr;
+const TQUuid *TQUType_varptr::uuid() const { return &TID_TQUType_varptr; }
+const char *TQUType_varptr::desc() const { return "varptr"; }
+
+void TQUType_varptr::set( TQUObject *o, const void* v )
+{
+ o->payload.ptr = (void*) v;
+ o->type = this;
+}
+
+bool TQUType_varptr::canConvertFrom( TQUObject *o, TQUType *t )
+{
+ if ( isEqual( t, &static_TQUType_ptr ) )
+ return TRUE;
+ return t->canConvertTo( o, this );
+}
+
+bool TQUType_varptr::canConvertTo( TQUObject *, TQUType * t)
+{
+ return isEqual( t, &static_TQUType_ptr );
+}
+
+bool TQUType_varptr::convertFrom( TQUObject *o, TQUType *t )
+{
+ if ( isEqual( t, &static_TQUType_ptr ) )
+ ;
+ else
+ return t->convertTo( o, this );
+
+ o->type = this;
+ return TRUE;
+}
+
+bool TQUType_varptr::convertTo( TQUObject *o, TQUType * t)
+{
+ if ( isEqual( t, &static_TQUType_ptr ) ) {
+ o->type = &static_TQUType_ptr;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+int TQUType_varptr::serializeTo( TQUObject *, TQUBuffer * )
+{
+ return 0;
+}
+
+int TQUType_varptr::serializeFrom( TQUObject *, TQUBuffer * )
+{
+ return 0;
+}
diff --git a/tqtinterface/qt4/src/kernel/tqucomextra_p.h b/tqtinterface/qt4/src/kernel/tqucomextra_p.h
new file mode 100644
index 0000000..0862465
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqucomextra_p.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Definition of extra TQUcom classes
+**
+** Created : 990101
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQUCOMEXTRA_P_H
+#define TQUCOMEXTRA_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. This header file may
+// change from version to version without notice, or even be
+// removed.
+//
+// We mean it.
+//
+//
+
+#include <private/tqucom_p.h>
+
+#if __GNUC__ - 0 > 3
+#pragma GCC system_header
+#endif
+
+class TQVariant;
+
+#ifndef TQT_NO_VARIANT
+// 6dc75d58-a1d9-4417-b591-d45c63a3a4ea
+extern const TQUuid TID_TQUType_TQVariant;
+
+struct TQ_EXPORT TQUType_TQVariant : public TQUType
+{
+ const TQUuid *uuid() const;
+ const char *desc() const;
+
+ void set( TQUObject *, const TQVariant & );
+ TQVariant &get( TQUObject * o );
+
+ bool canConvertFrom( TQUObject *, TQUType * );
+ bool canConvertTo( TQUObject *, TQUType * );
+ bool convertFrom( TQUObject *, TQUType * );
+ bool convertTo( TQUObject *, TQUType * );
+ void clear( TQUObject * );
+ int serializeTo( TQUObject *, TQUBuffer * );
+ int serializeFrom( TQUObject *, TQUBuffer * );
+};
+extern TQ_EXPORT TQUType_TQVariant static_TQUType_TQVariant;
+#endif //TQT_NO_VARIANT
+
+
+// {0x8d48b3a8, 0xbd7f, 0x11d5, 0x8d, 0x74, 0x00, 0xc0, 0xf0, 0x3b, 0xc0, 0xf3 }
+extern TQ_EXPORT const TQUuid TID_TQUType_varptr;
+struct TQ_EXPORT TQUType_varptr : public TQUType
+{
+ const TQUuid *uuid() const;
+ const char *desc() const;
+
+ void set( TQUObject *, const void* );
+ void* &get( TQUObject * o ) { return o->payload.ptr; }
+ bool canConvertFrom( TQUObject *, TQUType * );
+ bool canConvertTo( TQUObject *, TQUType * );
+ bool convertFrom( TQUObject *, TQUType * );
+ bool convertTo( TQUObject *, TQUType * );
+ void clear( TQUObject * ) {}
+ int serializeTo( TQUObject *, TQUBuffer * );
+ int serializeFrom( TQUObject *, TQUBuffer * );
+};
+extern TQ_EXPORT TQUType_varptr static_TQUType_varptr;
+
+
+#endif // TQUCOMEXTRA_P_H
+
diff --git a/tqtinterface/qt4/src/kernel/tqurl.cpp b/tqtinterface/qt4/src/kernel/tqurl.cpp
new file mode 100644
index 0000000..a355c4a
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqurl.cpp
@@ -0,0 +1,1345 @@
+/****************************************************************************
+**
+** Implementation of TQUrl class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqurl.h"
+
+#ifndef TQT_NO_URL
+
+#include "tqdir.h"
+
+#include <stdlib.h>
+
+class TQUrlPrivate
+{
+public:
+ TQString protocol;
+ TQString user;
+ TQString pass;
+ TQString host;
+ TQString path, cleanPath;
+ TQString refEncoded;
+ TQString queryEncoded;
+ bool isValid;
+ int port;
+ bool cleanPathDirty;
+};
+
+/*!
+ Replaces backslashes with slashes and removes multiple occurrences
+ of slashes or backslashes if \c allowMultiple is FALSE.
+*/
+
+static void slashify( TQString& s, bool allowMultiple = TRUE )
+{
+ bool justHadSlash = FALSE;
+ for ( int i = 0; i < (int)s.length(); i++ ) {
+ if ( !allowMultiple && justHadSlash &&
+ ( s[ i ] == '/' || s[ i ] == '\\' ) ) {
+ s.remove( i, 1 );
+ --i;
+ continue;
+ }
+ if ( s[ i ] == '\\' )
+ s[ i ] = '/';
+#if defined (TQ_WS_MAC9)
+ if ( s[ i ] == ':' && (i == (int)s.length()-1 || s[ i + 1 ] != '/' ) ) //mac colon's go away, unless after a protocol
+ s[ i ] = '/';
+#endif
+ if ( s[ i ] == '/' )
+ justHadSlash = TRUE;
+ else
+ justHadSlash = FALSE;
+ }
+}
+
+
+
+/*!
+ \class TQUrl tqurl.h
+
+ \brief The TQUrl class provides a URL parser and simplifies working with URLs.
+\if defined(commercial)
+ It is part of the <a href="commercialeditions.html">TQt Enterprise Edition</a>.
+\endif
+
+ \ingroup io
+ \ingroup misc
+ \mainclass
+
+ \module network
+
+ The TQUrl class is provided for simple work with URLs. It can
+ parse, decode, encode, etc.
+
+ TQUrl works with the decoded path and encoded query in turn.
+
+ Example:
+
+ <tt>http://www.trolltech.com:80/cgi-bin/test%20me.pl?cmd=Hello%20you</tt>
+
+ \table
+ \header \i Function \i Returns
+ \row \i \l protocol() \i "http"
+ \row \i \l host() \i "www.trolltech.com"
+ \row \i \l port() \i 80
+ \row \i \l path() \i "/cgi-bin/test&nbsp;me.pl"
+ \row \i \l fileName() \i "test&nbsp;me.pl"
+ \row \i \l query() \i "cmd=Hello%20you"
+ \endtable
+
+ Example:
+
+ <tt>http://doc.trolltech.com/tqdockarea.html#lines</tt>
+
+ \table
+ \header \i Function \i Returns
+ \row \i \l protocol() \i "http"
+ \row \i \l host() \i "doc.trolltech.com"
+ \row \i \l fileName() \i "tqdockarea.html"
+ \row \i \l ref() \i "lines"
+ \endtable
+
+ The individual parts of a URL can be set with setProtocol(),
+ setHost(), setPort(), setPath(), setFileName(), setRef() and
+ setQuery(). A URL could contain, for example, an ftp address which
+ requires a user name and password; these can be set with setUser()
+ and setPassword().
+
+ Because path is always encoded internally you must not use "%00"
+ in the path, although this is okay (but not recommended) for the
+ query.
+
+ TQUrl is normally used like this:
+
+ \code
+ TQUrl url( "http://www.trolltech.com" );
+ // or
+ TQUrl url( "file:/home/myself/Mail", "Inbox" );
+ \endcode
+
+ You can then access and manipulate the various parts of the URL.
+
+ To make it easy to work with TQUrls and TQStrings, TQUrl implements
+ the necessary cast and assignment operators so you can do
+ following:
+
+ \code
+ TQUrl url( "http://www.trolltech.com" );
+ TQString s = url;
+ // or
+ TQString s( "http://www.trolltech.com" );
+ TQUrl url( s );
+ \endcode
+
+ Use the static functions, encode() and decode() to encode or
+ decode a URL in a string. (They operate on the string in-place.)
+ The isRelativeUrl() static function returns TRUE if the given
+ string is a relative URL.
+
+ If you want to use a URL to work on a hierarchical structure (e.g.
+ a local or remote filesystem), you might want to use the subclass
+ TQUrlOperator.
+
+ \sa TQUrlOperator
+*/
+
+
+/*!
+ Constructs an empty URL that is invalid.
+*/
+
+TQUrl::TQUrl()
+{
+ d = new TQUrlPrivate;
+ d->isValid = FALSE;
+ d->port = -1;
+ d->cleanPathDirty = TRUE;
+}
+
+/*!
+ Constructs a URL by parsing the string \a url.
+
+ If you pass a string like "/home/qt", the "file" protocol is
+ assumed.
+*/
+
+TQUrl::TQUrl( const TQString& url )
+{
+ d = new TQUrlPrivate;
+ d->protocol = "file";
+ d->port = -1;
+ parse( url );
+}
+
+/*!
+ Copy constructor. Copies the data of \a url.
+*/
+
+TQUrl::TQUrl( const TQUrl& url )
+{
+ d = new TQUrlPrivate;
+ *d = *url.d;
+}
+
+/*!
+ Returns TRUE if \a url is relative; otherwise returns FALSE.
+*/
+
+bool TQUrl::isRelativeUrl( const TQString &url )
+{
+ int colon = url.tqfind( ":" );
+ int slash = url.tqfind( "/" );
+
+ return ( slash != 0 && ( colon == -1 || ( slash != -1 && colon > slash ) ) );
+}
+
+/*!
+ Constructs an URL taking \a url as the base (context) and
+ \a relUrl as a relative URL to \a url. If \a relUrl is not relative,
+ \a relUrl is taken as the new URL.
+
+ For example, the path of
+ \code
+ TQUrl url( "ftp://ftp.trolltech.com/qt/source", "qt-2.1.0.tar.gz" );
+ \endcode
+ will be "/qt/srource/qt-2.1.0.tar.gz".
+
+ On the other hand,
+ \code
+ TQUrl url( "ftp://ftp.trolltech.com/qt/source", "/usr/local" );
+ \endcode
+ will result in a new URL, "ftp://ftp.trolltech.com/usr/local",
+ because "/usr/local" isn't relative.
+
+ Similarly,
+ \code
+ TQUrl url( "ftp://ftp.trolltech.com/qt/source", "file:/usr/local" );
+ \endcode
+ will result in a new URL, with "/usr/local" as the path
+ and "file" as the protocol.
+
+ Normally it is expected that the path of \a url points to a
+ directory, even if the path has no slash at the end. But if you
+ want the constructor to handle the last part of the path as a file
+ name if there is no slash at the end, and to let it be tqreplaced by
+ the file name of \a relUrl (if it tqcontains one), set \a checkSlash
+ to TRUE.
+*/
+
+TQUrl::TQUrl( const TQUrl& url, const TQString& relUrl, bool checkSlash )
+{
+ d = new TQUrlPrivate;
+ TQString rel = relUrl;
+ slashify( rel );
+
+ TQUrl urlTmp( url );
+ if ( !urlTmp.isValid() ) {
+ urlTmp.reset();
+ }
+ if ( isRelativeUrl( rel ) ) {
+ if ( rel[ 0 ] == '#' ) {
+ *this = urlTmp;
+ rel.remove( (uint)0, 1 );
+ decode( rel );
+ setRef( rel );
+ } else if ( rel[ 0 ] == '?' ) {
+ *this = urlTmp;
+ rel.remove( (uint)0, 1 );
+ setQuery( rel );
+ } else {
+ decode( rel );
+ *this = urlTmp;
+ setRef( TQString::null );
+ if ( checkSlash && d->cleanPath[(int)path().length()-1] != '/' ) {
+ if ( isRelativeUrl( path() ) )
+ setEncodedPathAndQuery( rel );
+ else
+ setFileName( rel );
+ } else {
+ TQString p = urlTmp.path();
+ if ( p.isEmpty() ) {
+ // allow URLs like "file:foo"
+ if ( !d->host.isEmpty() && !d->user.isEmpty() && !d->pass.isEmpty() )
+ p = "/";
+ }
+ if ( !p.isEmpty() && p.right(1)!="/" )
+ p += "/";
+ p += rel;
+ d->path = p;
+ d->cleanPathDirty = TRUE;
+ }
+ }
+ } else {
+ if ( rel[ 0 ] == TQChar( '/' ) ) {
+ *this = urlTmp;
+ setEncodedPathAndQuery( rel );
+ } else {
+ *this = rel;
+ }
+ }
+}
+
+/*!
+ Destructor.
+*/
+
+TQUrl::~TQUrl()
+{
+ delete d;
+ d = 0;
+}
+
+/*!
+ Returns the protocol of the URL. Typically, "file", "http", "ftp",
+ etc.
+
+ \sa setProtocol()
+*/
+
+TQString TQUrl::protocol() const
+{
+ return d->protocol;
+}
+
+/*!
+ Sets the protocol of the URL to \a protocol. Typically, "file",
+ "http", "ftp", etc.
+
+ \sa protocol()
+*/
+
+void TQUrl::setProtocol( const TQString& protocol )
+{
+ d->protocol = protocol;
+ if ( hasHost() )
+ d->isValid = TRUE;
+}
+
+/*!
+ Returns the username of the URL.
+
+ \sa setUser() setPassword()
+*/
+
+TQString TQUrl::user() const
+{
+ return d->user;
+}
+
+/*!
+ Sets the username of the URL to \a user.
+
+ \sa user() setPassword()
+*/
+
+void TQUrl::setUser( const TQString& user )
+{
+ d->user = user;
+}
+
+/*!
+ Returns TRUE if the URL tqcontains a username; otherwise returns
+ FALSE.
+
+ \sa setUser() setPassword()
+*/
+
+bool TQUrl::hasUser() const
+{
+ return !d->user.isEmpty();
+}
+
+/*!
+ Returns the password of the URL.
+
+ \warning Passwords passed in URLs are normally \e insecure; this
+ is due to the mechanism, not because of TQt.
+
+ \sa setPassword() setUser()
+*/
+
+TQString TQUrl::password() const
+{
+ return d->pass;
+}
+
+/*!
+ Sets the password of the URL to \a pass.
+
+ \warning Passwords passed in URLs are normally \e insecure; this
+ is due to the mechanism, not because of TQt.
+
+ \sa password() setUser()
+*/
+
+void TQUrl::setPassword( const TQString& pass )
+{
+ d->pass = pass;
+}
+
+/*!
+ Returns TRUE if the URL tqcontains a password; otherwise returns
+ FALSE.
+
+ \warning Passwords passed in URLs are normally \e insecure; this
+ is due to the mechanism, not because of TQt.
+
+ \sa setPassword() setUser()
+*/
+
+bool TQUrl::hasPassword() const
+{
+ return !d->pass.isEmpty();
+}
+
+/*!
+ Returns the hostname of the URL.
+
+ \sa setHost() hasHost()
+*/
+
+TQString TQUrl::host() const
+{
+ return d->host;
+}
+
+/*!
+ Sets the hostname of the URL to \a host.
+
+ \sa host() hasHost()
+*/
+
+void TQUrl::setHost( const TQString& host )
+{
+ d->host = host;
+ if ( !d->protocol.isNull() && d->protocol != "file" )
+ d->isValid = TRUE;
+}
+
+/*!
+ Returns TRUE if the URL tqcontains a hostname; otherwise returns
+ FALSE.
+
+ \sa setHost()
+*/
+
+bool TQUrl::hasHost() const
+{
+ return !d->host.isEmpty();
+}
+
+/*!
+ Returns the port of the URL or -1 if no port has been set.
+
+ \sa setPort()
+*/
+
+int TQUrl::port() const
+{
+ return d->port;
+}
+
+/*!
+ Sets the port of the URL to \a port.
+
+ \sa port()
+*/
+
+void TQUrl::setPort( int port )
+{
+ d->port = port;
+}
+
+/*!
+ Returns TRUE if the URL tqcontains a port; otherwise returns FALSE.
+
+ \sa setPort()
+*/
+
+bool TQUrl::hasPort() const
+{
+ return d->port >= 0;
+}
+
+/*!
+ Sets the path of the URL to \a path.
+
+ \sa path() hasPath()
+*/
+
+void TQUrl::setPath( const TQString& path )
+{
+ d->path = path;
+ slashify( d->path );
+ d->cleanPathDirty = TRUE;
+ d->isValid = TRUE;
+}
+
+/*!
+ Returns TRUE if the URL tqcontains a path; otherwise returns FALSE.
+
+ \sa path() setPath()
+*/
+
+bool TQUrl::hasPath() const
+{
+ return !d->path.isEmpty();
+}
+
+/*!
+ Sets the query of the URL to \a txt. \a txt must be encoded.
+
+ \sa query() encode()
+*/
+
+void TQUrl::setQuery( const TQString& txt )
+{
+ d->queryEncoded = txt;
+}
+
+/*!
+ Returns the (encoded) query of the URL.
+
+ \sa setQuery() decode()
+*/
+
+TQString TQUrl::query() const
+{
+ return d->queryEncoded;
+}
+
+/*!
+ Returns the (encoded) reference of the URL.
+
+ \sa setRef() hasRef() decode()
+*/
+
+TQString TQUrl::ref() const
+{
+ return d->refEncoded;
+}
+
+/*!
+ Sets the reference of the URL to \a txt. \a txt must be encoded.
+
+ \sa ref() hasRef() encode()
+*/
+
+void TQUrl::setRef( const TQString& txt )
+{
+ d->refEncoded = txt;
+}
+
+/*!
+ Returns TRUE if the URL has a reference; otherwise returns FALSE.
+
+ \sa setRef()
+*/
+
+bool TQUrl::hasRef() const
+{
+ return !d->refEncoded.isEmpty();
+}
+
+/*!
+ Returns TRUE if the URL is valid; otherwise returns FALSE. A URL
+ is invalid if it cannot be parsed, for example.
+*/
+
+bool TQUrl::isValid() const
+{
+ return d->isValid;
+}
+
+/*!
+ Resets all parts of the URL to their default values and
+ invalidates it.
+*/
+
+void TQUrl::reset()
+{
+ d->protocol = "file";
+ d->user = "";
+ d->pass = "";
+ d->host = "";
+ d->path = "";
+ d->queryEncoded = "";
+ d->refEncoded = "";
+ d->isValid = TRUE;
+ d->port = -1;
+ d->cleanPathDirty = TRUE;
+}
+
+/*!
+ Parses the \a url.
+*/
+
+bool TQUrl::parse( const TQString& url )
+{
+ TQString url_( url );
+ slashify( url_ );
+
+ if ( url_.isEmpty() ) {
+ d->isValid = FALSE;
+ return FALSE;
+ }
+
+ d->cleanPathDirty = TRUE;
+ d->isValid = TRUE;
+ TQString oldProtocol = d->protocol;
+ d->protocol = TQString::null;
+
+ const int Init = 0;
+ const int Protocol = 1;
+ const int Separator1= 2; // :
+ const int Separator2= 3; // :/
+ const int Separator3= 4; // :// or more slashes
+ const int User = 5;
+ const int Pass = 6;
+ const int Host = 7;
+ const int Path = 8;
+ const int Ref = 9;
+ const int Query = 10;
+ const int Port = 11;
+ const int Done = 12;
+
+ const int InputAlpha= 1;
+ const int InputDigit= 2;
+ const int InputSlash= 3;
+ const int InputColon= 4;
+ const int InputAt = 5;
+ const int InputHash = 6;
+ const int InputQuery= 7;
+
+ static uchar table[ 12 ][ 8 ] = {
+ /* None InputAlpha InputDigit InputSlash InputColon InputAt InputHash InputQuery */
+ { 0, Protocol, 0, Path, 0, 0, 0, 0, }, // Init
+ { 0, Protocol, Protocol, 0, Separator1, 0, 0, 0, }, // Protocol
+ { 0, Path, Path, Separator2, 0, 0, 0, 0, }, // Separator1
+ { 0, Path, Path, Separator3, 0, 0, 0, 0, }, // Separator2
+ { 0, User, User, Separator3, Pass, Host, 0, 0, }, // Separator3
+ { 0, User, User, User, Pass, Host, User, User, }, // User
+ { 0, Pass, Pass, Pass, Pass, Host, Pass, Pass, }, // Pass
+ { 0, Host, Host, Path, Port, Host, Ref, Query, }, // Host
+ { 0, Path, Path, Path, Path, Path, Ref, Query, }, // Path
+ { 0, Ref, Ref, Ref, Ref, Ref, Ref, Query, }, // Ref
+ { 0, Query, Query, Query, Query, Query, Query, Query, }, // Query
+ { 0, 0, Port, Path, 0, 0, 0, 0, } // Port
+ };
+
+ bool relPath = FALSE;
+
+ relPath = FALSE;
+ bool forceRel = FALSE;
+
+ // If ':' is at pos 1, we have only one letter
+ // before that separator => that's a drive letter!
+ if ( url_.length() >= 2 && url_[1] == ':' )
+ relPath = forceRel = TRUE;
+
+ int hasNoHost = -1;
+ int cs = url_.tqfind( ":/" );
+ if ( cs != -1 ) // if a protocol is there, tqfind out if there is a host or directly the path after it
+ hasNoHost = url_.tqfind( "///", cs );
+ table[ 4 ][ 1 ] = User;
+ table[ 4 ][ 2 ] = User;
+ if ( cs == -1 || forceRel ) { // we have a relative file
+ if ( url.tqfind( ':' ) == -1 || forceRel ) {
+ table[ 0 ][ 1 ] = Path;
+ // Filenames may also begin with a digit
+ table[ 0 ][ 2 ] = Path;
+ } else {
+ table[ 0 ][ 1 ] = Protocol;
+ }
+ relPath = TRUE;
+ } else { // some checking
+ table[ 0 ][ 1 ] = Protocol;
+
+ // tqfind the part between the protocol and the path as the meaning
+ // of that part is dependend on some chars
+ ++cs;
+ while ( url_[ cs ] == '/' )
+ ++cs;
+ int slash = url_.tqfind( "/", cs );
+ if ( slash == -1 )
+ slash = url_.length() - 1;
+ TQString tmp = url_.mid( cs, slash - cs + 1 );
+
+ if ( !tmp.isEmpty() ) { // if this part exists
+
+ // look for the @ in this part
+ int at = tmp.tqfind( "@" );
+ if ( at != -1 )
+ at += cs;
+ // we have no @, which means host[:port], so directly
+ // after the protocol the host starts, or if the protocol
+ // is file or there were more than 2 slashes, it�s the
+ // path
+ if ( at == -1 ) {
+ if ( url_.left( 4 ) == "file" || hasNoHost != -1 )
+ table[ 4 ][ 1 ] = Path;
+ else
+ table[ 4 ][ 1 ] = Host;
+ table[ 4 ][ 2 ] = table[ 4 ][ 1 ];
+ }
+ }
+ }
+
+ int state = Init; // parse state
+ int input; // input token
+
+ TQChar c = url_.at( 0 );
+ int i = 0;
+ TQString port;
+
+ for ( ;; ) {
+ switch ( c ) {
+ case '?':
+ input = InputQuery;
+ break;
+ case '#':
+ input = InputHash;
+ break;
+ case '@':
+ input = InputAt;
+ break;
+ case ':':
+ input = InputColon;
+ break;
+ case '/':
+ input = InputSlash;
+ break;
+ case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9': case '0':
+ input = InputDigit;
+ break;
+ default:
+ input = InputAlpha;
+ }
+
+ state = table[ state ][ input ];
+
+ switch ( state ) {
+ case Protocol:
+ d->protocol += c;
+ break;
+ case User:
+ d->user += c;
+ break;
+ case Pass:
+ d->pass += c;
+ break;
+ case Host:
+ d->host += c;
+ break;
+ case Path:
+ d->path += c;
+ break;
+ case Ref:
+ d->refEncoded += c;
+ break;
+ case Query:
+ d->queryEncoded += c;
+ break;
+ case Port:
+ port += c;
+ break;
+ default:
+ break;
+ }
+
+ ++i;
+ if ( i > (int)url_.length() - 1 || state == Done || state == 0 )
+ break;
+ c = url_[ i ];
+
+ }
+
+ if ( !port.isEmpty() ) {
+ port.remove( (uint)0, 1 );
+ d->port = atoi( port.latin1() );
+ }
+
+ // error
+ if ( i < (int)url_.length() - 1 ) {
+ d->isValid = FALSE;
+ return FALSE;
+ }
+
+
+ if ( d->protocol.isEmpty() )
+ d->protocol = oldProtocol;
+
+ if ( d->path.isEmpty() )
+ d->path = "/";
+
+ // hack for windows
+ if ( d->path.length() == 2 && d->path[ 1 ] == ':' )
+ d->path += "/";
+
+ // #### do some corrections, should be done nicer too
+ if ( !d->pass.isEmpty() ) {
+ if ( d->pass[ 0 ] == ':' )
+ d->pass.remove( (uint)0, 1 );
+ decode( d->pass );
+ }
+ if ( !d->user.isEmpty() ) {
+ decode( d->user );
+ }
+ if ( !d->path.isEmpty() ) {
+ if ( d->path[ 0 ] == '@' || d->path[ 0 ] == ':' )
+ d->path.remove( (uint)0, 1 );
+ if ( d->path[ 0 ] != '/' && !relPath && d->path[ 1 ] != ':' )
+ d->path.prepend( "/" );
+ }
+ if ( !d->refEncoded.isEmpty() && d->refEncoded[ 0 ] == '#' )
+ d->refEncoded.remove( (uint)0, 1 );
+ if ( !d->queryEncoded.isEmpty() && d->queryEncoded[ 0 ] == '?' )
+ d->queryEncoded.remove( (uint)0, 1 );
+ if ( !d->host.isEmpty() && d->host[ 0 ] == '@' )
+ d->host.remove( (uint)0, 1 );
+
+#if defined(TQ_OS_WIN32)
+ // hack for windows file://machine/path syntax
+ if ( d->protocol == "file" ) {
+ if ( url.left( 7 ) == "file://" &&
+ d->path.length() > 1 && d->path[ 1 ] != ':' )
+ d->path.prepend( "/" );
+ }
+#endif
+
+ decode( d->path );
+ d->cleanPathDirty = TRUE;
+
+#if 0
+ qDebug( "URL: %s", url.latin1() );
+ qDebug( "protocol: %s", d->protocol.latin1() );
+ qDebug( "user: %s", d->user.latin1() );
+ qDebug( "pass: %s", d->pass.latin1() );
+ qDebug( "host: %s", d->host.latin1() );
+ qDebug( "path: %s", path().latin1() );
+ qDebug( "ref: %s", d->refEncoded.latin1() );
+ qDebug( "query: %s", d->queryEncoded.latin1() );
+ qDebug( "port: %d\n\n----------------------------\n\n", d->port );
+#endif
+
+ return TRUE;
+}
+
+/*!
+ \overload
+
+ Parses \a url and assigns the resulting data to this class.
+
+ If you pass a string like "/home/qt" the "file" protocol will be
+ assumed.
+*/
+
+TQUrl& TQUrl::operator=( const TQString& url )
+{
+ reset();
+ parse( url );
+
+ return *this;
+}
+
+/*!
+ Assigns the data of \a url to this class.
+*/
+
+TQUrl& TQUrl::operator=( const TQUrl& url )
+{
+ *d = *url.d;
+ return *this;
+}
+
+/*!
+ Compares this URL with \a url and returns TRUE if they are equal;
+ otherwise returns FALSE.
+*/
+
+bool TQUrl::operator==( const TQUrl& url ) const
+{
+ if ( !isValid() || !url.isValid() )
+ return FALSE;
+
+ if ( d->protocol == url.d->protocol &&
+ d->user == url.d->user &&
+ d->pass == url.d->pass &&
+ d->host == url.d->host &&
+ d->path == url.d->path &&
+ d->queryEncoded == url.d->queryEncoded &&
+ d->refEncoded == url.d->refEncoded &&
+ d->isValid == url.d->isValid &&
+ d->port == url.d->port )
+ return TRUE;
+
+ return FALSE;
+}
+
+/*!
+ \overload
+
+ Compares this URL with \a url. \a url is parsed first. Returns
+ TRUE if \a url is equal to this url; otherwise returns FALSE.
+*/
+
+bool TQUrl::operator==( const TQString& url ) const
+{
+ TQUrl u( url );
+ return ( *this == u );
+}
+
+/*!
+ Sets the file name of the URL to \a name. If this URL tqcontains a
+ fileName(), the original file name is tqreplaced by \a name.
+
+ See the documentation of fileName() for a more detailed discussion
+ of what is handled as file name and what is handled as a directory
+ path.
+
+ \sa fileName()
+*/
+
+void TQUrl::setFileName( const TQString& name )
+{
+ TQString fn( name );
+ slashify( fn );
+
+ while ( fn[ 0 ] == '/' )
+ fn.remove( (uint)0, 1 );
+
+ TQString p;
+ if ( path().isEmpty() ) {
+ p = "/";
+ } else {
+ p = path();
+ int slash = p.tqfindRev( TQChar( '/' ) );
+ if ( slash == -1 ) {
+ p = "/";
+ } else if ( p[ (int)p.length() - 1 ] != '/' ) {
+ p.truncate( slash + 1 );
+ }
+ }
+
+ p += fn;
+ if ( !d->queryEncoded.isEmpty() )
+ p += "?" + d->queryEncoded;
+ setEncodedPathAndQuery( p );
+}
+
+/*!
+ Returns the encoded path and query.
+
+ \sa decode()
+*/
+
+TQString TQUrl::encodedPathAndQuery()
+{
+ TQString p = path();
+ if ( p.isEmpty() )
+ p = "/";
+
+ encode( p );
+
+ if ( !d->queryEncoded.isEmpty() ) {
+ p += "?";
+ p += d->queryEncoded;
+ }
+
+ return p;
+}
+
+/*!
+ Parses \a pathAndQuery for a path and query and sets those values.
+ The whole string must be encoded.
+
+ \sa encode()
+*/
+
+void TQUrl::setEncodedPathAndQuery( const TQString& pathAndQuery )
+{
+ d->cleanPathDirty = TRUE;
+ int pos = pathAndQuery.tqfind( '?' );
+ if ( pos == -1 ) {
+ d->path = pathAndQuery;
+ d->queryEncoded = "";
+ } else {
+ d->path = pathAndQuery.left( pos );
+ d->queryEncoded = pathAndQuery.mid( pos + 1 );
+ }
+
+ decode( d->path );
+ d->cleanPathDirty = TRUE;
+}
+
+extern bool qt_resolve_symlinks; // defined in qapplication.cpp
+
+/*!
+ Returns the path of the URL. If \a correct is TRUE, the path is
+ cleaned (deals with too many or too few slashes, cleans things
+ like "/../..", etc). Otherwise path() returns exactly the path
+ that was parsed or set.
+
+ \sa setPath() hasPath()
+*/
+TQString TQUrl::path( bool correct ) const
+{
+ if ( !correct )
+ return d->path;
+
+ if ( d->cleanPathDirty ) {
+ bool check = TRUE;
+ if ( TQDir::isRelativePath( d->path ) ) {
+ d->cleanPath = d->path;
+ } else if ( isLocalFile() ) {
+#if defined(TQ_OS_WIN32)
+ // hack for stuff like \\machine\path and //machine/path on windows
+ if ( ( d->path.left( 1 ) == "/" || d->path.left( 1 ) == "\\" ) &&
+ d->path.length() > 1 ) {
+ d->cleanPath = d->path;
+ bool share = (d->cleanPath[0] == '\\' && d->cleanPath[1] == '\\') ||
+ (d->cleanPath[0] == '/' && d->cleanPath[1] == '/');
+ slashify( d->cleanPath, FALSE );
+ d->cleanPath = TQDir::cleanDirPath( d->cleanPath );
+ if ( share ) {
+ check = FALSE;
+ while (d->cleanPath.at(0) != '/' || d->cleanPath.at(1) != '/')
+ d->cleanPath.prepend("/");
+ }
+ }
+#endif
+ if ( check ) {
+ TQFileInfo fi( d->path );
+ if ( !fi.exists() )
+ d->cleanPath = d->path;
+ else if ( fi.isDir() ) {
+ TQString canPath = TQDir( d->path ).canonicalPath();
+ TQString dir;
+ if ( qt_resolve_symlinks && !canPath.isNull() )
+ dir = TQDir::cleanDirPath( canPath );
+ else
+ dir = TQDir::cleanDirPath( TQDir( d->path ).absPath() );
+ dir += "/";
+ if ( dir == "//" )
+ d->cleanPath = "/";
+ else
+ d->cleanPath = dir;
+ } else {
+ TQString p =
+ TQDir::cleanDirPath( (qt_resolve_symlinks ?
+ fi.dir().canonicalPath() :
+ fi.dir().absPath()) );
+ d->cleanPath = p + "/" + fi.fileName();
+ }
+ }
+ } else {
+ if ( d->path != "/" && d->path[ (int)d->path.length() - 1 ] == '/' )
+ d->cleanPath = TQDir::cleanDirPath( d->path ) + "/";
+ else
+ d->cleanPath = TQDir::cleanDirPath( d->path );
+ }
+
+ if ( check )
+ slashify( d->cleanPath, FALSE );
+ d->cleanPathDirty = FALSE;
+ }
+
+ return d->cleanPath;
+}
+
+/*!
+ Returns TRUE if the URL is a local file; otherwise returns FALSE.
+*/
+
+bool TQUrl::isLocalFile() const
+{
+ return d->protocol == "file";
+}
+
+/*!
+ Returns the file name of the URL. If the path of the URL doesn't
+ have a slash at the end, the part between the last slash and the
+ end of the path string is considered to be the file name. If the
+ path has a slash at the end, an empty string is returned here.
+
+ \sa setFileName()
+*/
+
+TQString TQUrl::fileName() const
+{
+ if ( d->path.isEmpty() || d->path.endsWith( "/" )
+#ifdef TQ_WS_WIN
+ || d->path.endsWith( "\\" )
+#endif
+ )
+ return TQString::null;
+
+ return TQFileInfo( d->path ).fileName();
+}
+
+/*!
+ Adds the path \a pa to the path of the URL.
+
+ \sa setPath() hasPath()
+*/
+
+void TQUrl::addPath( const TQString& pa )
+{
+ if ( pa.isEmpty() )
+ return;
+
+ TQString p( pa );
+ slashify( p );
+
+ if ( path().isEmpty() ) {
+ if ( p[ 0 ] != TQChar( '/' ) )
+ d->path = "/" + p;
+ else
+ d->path = p;
+ } else {
+ if ( p[ 0 ] != TQChar( '/' ) && d->path[ (int)d->path.length() - 1 ] != '/' )
+ d->path += "/" + p;
+ else
+ d->path += p;
+ }
+ d->cleanPathDirty = TRUE;
+}
+
+/*!
+ Returns the directory path of the URL. This is the part of the
+ path of the URL without the fileName(). See the documentation of
+ fileName() for a discussion of what is handled as file name and
+ what is handled as directory path.
+
+ \sa setPath() hasPath()
+*/
+
+TQString TQUrl::dirPath() const
+{
+ if ( path().isEmpty() )
+ return TQString::null;
+
+ TQString s = path();
+ int pos = s.tqfindRev( '/' );
+ if ( pos == -1 ) {
+ return TQString::tqfromLatin1(".");
+ } else {
+ if ( pos == 0 )
+ return TQString::tqfromLatin1( "/" );
+ return s.left( pos );
+ }
+}
+
+/*!
+ Encodes the \a url in-place into UTF-8. For example
+
+ \code
+ TQString url = http://www.trolltech.com
+ TQUrl::encode( url );
+ // url is now "http%3A//www%20trolltech%20com"
+ \endcode
+
+ \sa decode()
+*/
+
+void TQUrl::encode( TQString& url )
+{
+ if ( url.isEmpty() )
+ return;
+
+ TQCString curl = url.utf8();
+ int oldlen = curl.length();
+
+ const TQCString special( "+<>#@\"&%$:,;?={}|^~[]\'`\\ \n\t\r" );
+ TQString newUrl;
+ int newlen = 0;
+
+ for ( int i = 0; i < oldlen ;++i ) {
+ uchar inCh = (uchar)curl[ i ];
+
+ if ( inCh >= 128 || special.tqcontains(inCh) ) {
+ newUrl[ newlen++ ] = TQChar( '%' );
+
+ ushort c = inCh / 16;
+ c += c > 9 ? 'A' - 10 : '0';
+ newUrl[ newlen++ ] = c;
+
+ c = inCh % 16;
+ c += c > 9 ? 'A' - 10 : '0';
+ newUrl[ newlen++ ] = c;
+ } else {
+ newUrl[ newlen++ ] = inCh;
+ }
+ }
+
+ url = newUrl;
+}
+
+static uchar hex_to_int( uchar c )
+{
+ if ( c >= 'A' && c <= 'F' )
+ return c - 'A' + 10;
+ if ( c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ if ( c >= '0' && c <= '9')
+ return c - '0';
+ return 0;
+}
+
+/*!
+ Decodes the \a url in-place into UTF-8. For example
+
+ \code
+ TQString url = "http%3A//www%20trolltech%20com"
+ TQUrl::decode( url );
+ // url is now "http://www.trolltech.com"
+ \endcode
+
+ \sa encode()
+*/
+
+void TQUrl::decode( TQString& url )
+{
+ if ( url.isEmpty() )
+ return;
+
+ int newlen = 0;
+ TQCString curl = url.utf8();
+ int oldlen = curl.length();
+
+ TQCString newUrl(oldlen);
+
+ int i = 0;
+ while ( i < oldlen ) {
+ uchar c = (uchar)curl[ i++ ];
+ if ( c == '%' && i <= oldlen - 2 ) {
+ c = hex_to_int( (uchar)curl[ i ] ) * 16 + hex_to_int( (uchar)curl[ i + 1 ] );
+ i += 2;
+ }
+ newUrl [ newlen++ ] = c;
+ }
+ newUrl.truncate( newlen );
+
+ url = TQString::fromUtf8(newUrl.data());
+}
+
+
+/*!
+ Composes a string version of the URL and returns it. If \a
+ encodedPath is TRUE the path in the returned string is encoded. If
+ \a forcePrependProtocol is TRUE and \a encodedPath looks like a
+ local filename, the "file:/" protocol is also prepended.
+
+ \sa encode() decode()
+*/
+
+TQString TQUrl::toString( bool encodedPath, bool forcePrependProtocol ) const
+{
+ TQString res, p = path();
+ if ( encodedPath )
+ encode( p );
+
+ if ( isLocalFile() ) {
+ if ( forcePrependProtocol )
+ res = d->protocol + ":" + p;
+ else
+ res = p;
+ } else if ( d->protocol == "mailto" ) {
+ res = d->protocol + ":" + p;
+ } else {
+ res = d->protocol + "://";
+ if ( !d->user.isEmpty() || !d->pass.isEmpty() ) {
+ TQString tmp;
+ if ( !d->user.isEmpty() ) {
+ tmp = d->user;
+ encode( tmp );
+ res += tmp;
+ }
+ if ( !d->pass.isEmpty() ) {
+ tmp = d->pass;
+ encode( tmp );
+ res += ":" + tmp;
+ }
+ res += "@";
+ }
+ res += d->host;
+ if ( d->port != -1 )
+ res += ":" + TQString( "%1" ).arg( d->port );
+ if ( !p.isEmpty() ) {
+ if ( !d->host.isEmpty() && p[0]!='/' )
+ res += "/";
+ res += p;
+ }
+ }
+
+ if ( !d->refEncoded.isEmpty() )
+ res += "#" + d->refEncoded;
+ if ( !d->queryEncoded.isEmpty() )
+ res += "?" + d->queryEncoded;
+
+ return res;
+}
+
+/*!
+ Composes a string version of the URL and returns it.
+
+ \sa TQUrl::toString()
+*/
+
+TQUrl::operator TQString() const
+{
+ return toString();
+}
+
+/*!
+ Changes the directory to one directory up.
+
+ \sa setPath()
+*/
+
+bool TQUrl::cdUp()
+{
+ d->path += "/..";
+ d->cleanPathDirty = TRUE;
+ return TRUE;
+}
+
+#endif // TQT_NO_URL
diff --git a/tqtinterface/qt4/src/kernel/tqurl.h b/tqtinterface/qt4/src/kernel/tqurl.h
new file mode 100644
index 0000000..532633b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqurl.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Definition of TQUrl class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQURL_H
+#define TQURL_H
+
+#ifndef TQT_H
+#include "tqstring.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_URL
+
+class TQUrlPrivate;
+
+class TQ_EXPORT TQUrl
+{
+public:
+ TQUrl();
+ TQUrl( const TQString& url );
+ TQUrl( const TQUrl& url );
+ TQUrl( const TQUrl& url, const TQString& relUrl, bool checkSlash = FALSE );
+ virtual ~TQUrl();
+
+ TQString protocol() const;
+ virtual void setProtocol( const TQString& protocol );
+
+ TQString user() const;
+ virtual void setUser( const TQString& user );
+ bool hasUser() const;
+
+ TQString password() const;
+ virtual void setPassword( const TQString& pass );
+ bool hasPassword() const;
+
+ TQString host() const;
+ virtual void setHost( const TQString& user );
+ bool hasHost() const;
+
+ int port() const;
+ virtual void setPort( int port );
+ bool hasPort() const;
+
+ TQString path( bool correct = TRUE ) const;
+ virtual void setPath( const TQString& path );
+ bool hasPath() const;
+
+ virtual void setEncodedPathAndQuery( const TQString& enc );
+ TQString encodedPathAndQuery();
+
+ virtual void setQuery( const TQString& txt );
+ TQString query() const;
+
+ TQString ref() const;
+ virtual void setRef( const TQString& txt );
+ bool hasRef() const;
+
+ bool isValid() const;
+ bool isLocalFile() const;
+
+ virtual void addPath( const TQString& path );
+ virtual void setFileName( const TQString& txt );
+
+ TQString fileName() const;
+ TQString dirPath() const;
+
+ TQUrl& operator=( const TQUrl& url );
+ TQUrl& operator=( const TQString& url );
+
+ bool operator==( const TQUrl& url ) const;
+ bool operator==( const TQString& url ) const;
+
+ static void decode( TQString& url );
+ static void encode( TQString& url );
+
+ operator TQString() const;
+ virtual TQString toString( bool encodedPath = FALSE, bool forcePrependProtocol = TRUE ) const;
+
+ virtual bool cdUp();
+
+ static bool isRelativeUrl( const TQString &url );
+
+protected:
+ virtual void reset();
+ virtual bool parse( const TQString& url );
+
+private:
+ TQUrlPrivate *d;
+
+};
+
+#endif //TQT_NO_URL
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqurlinfo.cpp b/tqtinterface/qt4/src/kernel/tqurlinfo.cpp
new file mode 100644
index 0000000..60b9f15
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqurlinfo.cpp
@@ -0,0 +1,761 @@
+/****************************************************************************
+**
+** Implementation of TQUrlInfo class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqurlinfo.h"
+
+#ifndef TQT_NO_NETWORKPROTOCOL
+
+#include "tqurloperator.h"
+#include "tqdir.h"
+#include <limits.h>
+
+class TQUrlInfoPrivate
+{
+public:
+ TQUrlInfoPrivate() :
+ permissions(0),
+ size(0),
+ isDir(FALSE),
+ isFile(TRUE),
+ isSymLink(FALSE),
+ isWritable(TRUE),
+ isReadable(TRUE),
+ isExecutable(FALSE)
+ {}
+
+ TQString name;
+ int permissions;
+ TQString owner;
+ TQString group;
+#if defined(TQT_LARGEFILE_SUPPORT)
+ TQIODevice::Offset size;
+#else
+ uint size;
+#endif
+ TQDateTime lastModified;
+ TQDateTime lastRead;
+ bool isDir;
+ bool isFile;
+ bool isSymLink;
+ bool isWritable;
+ bool isReadable;
+ bool isExecutable;
+};
+
+
+/*!
+ \class TQUrlInfo tqurlinfo.h
+ \brief The TQUrlInfo class stores information about URLs.
+
+ \ingroup io
+ \ingroup misc
+
+ This class is just a container for storing information about URLs,
+ which is why all information must be passed in the constructor.
+
+ Unless you're reimplementing a network protocol you're unlikely to
+ create TQUrlInfo objects yourself, but you may receive TQUrlInfo
+ objects from functions, e.g. TQUrlOperator::info().
+
+ The information that can be retrieved includes name(),
+ permissions(), owner(), group(), size(), lastModified(),
+ lastRead(), isDir(), isFile(), isSymLink(), isWritable(),
+ isReadable() and isExecutable().
+*/
+
+/*!
+ \enum TQUrlInfo::PermissionSpec
+
+ This enum is used by the permissions() function to report the
+ permissions of a file.
+
+ \value ReadOwner The file is readable by the owner of the file.
+ \value WriteOwner The file is writable by the owner of the file.
+ \value ExeOwner The file is executable by the owner of the file.
+ \value ReadGroup The file is readable by the group.
+ \value WriteGroup The file is writable by the group.
+ \value ExeGroup The file is executable by the group.
+ \value ReadOther The file is readable by anyone.
+ \value WriteOther The file is writable by anyone.
+ \value ExeOther The file is executable by anyone.
+*/
+
+/*!
+ Constructs an invalid TQUrlInfo object with default values.
+
+ \sa isValid()
+*/
+
+TQUrlInfo::TQUrlInfo()
+{
+ d = 0;
+}
+
+/*!
+ Constructs a TQUrlInfo object with information about the file \a
+ file in the \a path. It tries to tqfind the information about the \a
+ file in the TQUrlOperator \a path.
+
+ If the information is not found, this constructor creates an
+ invalid TQUrlInfo, i.e. isValid() returns FALSE. You should always
+ check if the URL info is valid before relying on the return values
+ of any getter functions.
+
+ If \a file is empty, it defaults to the TQUrlOperator \a path, i.e.
+ to the directory.
+
+ \sa isValid() TQUrlOperator::info()
+*/
+
+TQUrlInfo::TQUrlInfo( const TQUrlOperator &path, const TQString &file )
+{
+ TQString file_ = file;
+ if ( file_.isEmpty() )
+ file_ = ".";
+
+ TQUrlInfo inf = path.info( file_ );
+ if ( inf.d ) {
+ d = new TQUrlInfoPrivate;
+ *d = *inf.d;
+ } else {
+ d = 0;
+ }
+}
+
+/*!
+ Copy constructor, copies \a ui to this URL info object.
+*/
+
+TQUrlInfo::TQUrlInfo( const TQUrlInfo &ui )
+{
+ if ( ui.d ) {
+ d = new TQUrlInfoPrivate;
+ *d = *ui.d;
+ } else {
+ d = 0;
+ }
+}
+
+/*!
+ Constructs a TQUrlInfo object by specifying all the URL's
+ information.
+
+ The information that is passed is the \a name, file \a
+ permissions, \a owner and \a group and the file's \a size. Also
+ passed is the \a lastModified date/time and the \a lastRead
+ date/time. Flags are also passed, specifically, \a isDir, \a
+ isFile, \a isSymLink, \a isWritable, \a isReadable and \a
+ isExecutable.
+*/
+
+#if defined(TQT_ABI_QT4)
+TQUrlInfo::TQUrlInfo( const TQString &name, int permissions, const TQString &owner,
+ const TQString &group, TQIODevice::Offset size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable )
+#else
+TQUrlInfo::TQUrlInfo( const TQString &name, int permissions, const TQString &owner,
+ const TQString &group, uint size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable )
+#endif
+{
+ d = new TQUrlInfoPrivate;
+ d->name = name;
+ d->permissions = permissions;
+ d->owner = owner;
+ d->group = group;
+ d->size = size;
+ d->lastModified = lastModified;
+ d->lastRead = lastRead;
+ d->isDir = isDir;
+ d->isFile = isFile;
+ d->isSymLink = isSymLink;
+ d->isWritable = isWritable;
+ d->isReadable = isReadable;
+ d->isExecutable = isExecutable;
+}
+
+
+/*!
+ Constructs a TQUrlInfo object by specifying all the URL's
+ information.
+
+ The information that is passed is the \a url, file \a
+ permissions, \a owner and \a group and the file's \a size. Also
+ passed is the \a lastModified date/time and the \a lastRead
+ date/time. Flags are also passed, specifically, \a isDir, \a
+ isFile, \a isSymLink, \a isWritable, \a isReadable and \a
+ isExecutable.
+*/
+
+#if defined(TQT_ABI_QT4)
+TQUrlInfo::TQUrlInfo( const TQUrl &url, int permissions, const TQString &owner,
+ const TQString &group, TQIODevice::Offset size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable )
+#else
+TQUrlInfo::TQUrlInfo( const TQUrl &url, int permissions, const TQString &owner,
+ const TQString &group, uint size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable )
+#endif
+{
+ d = new TQUrlInfoPrivate;
+ d->name = TQFileInfo( url.path() ).fileName();
+ d->permissions = permissions;
+ d->owner = owner;
+ d->group = group;
+ d->size = size;
+ d->lastModified = lastModified;
+ d->lastRead = lastRead;
+ d->isDir = isDir;
+ d->isFile = isFile;
+ d->isSymLink = isSymLink;
+ d->isWritable = isWritable;
+ d->isReadable = isReadable;
+ d->isExecutable = isExecutable;
+}
+
+
+/*!
+ Sets the name of the URL to \a name. The name is the full text,
+ for example, "http://doc.trolltech.com/tqurlinfo.html".
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setName( const TQString &name )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->name = name;
+}
+
+
+/*!
+ If \a b is TRUE then the URL is set to be a directory; if \b is
+ FALSE then the URL is set not to be a directory (which normally
+ means it is a file). (Note that a URL can refer to both a file and
+ a directory even though most file systems do not support this.)
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setDir( bool b )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->isDir = b;
+}
+
+
+/*!
+ If \a b is TRUE then the URL is set to be a file; if \b is FALSE
+ then the URL is set not to be a file (which normally means it is a
+ directory). (Note that a URL can refer to both a file and a
+ directory even though most file systems do not support this.)
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setFile( bool b )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->isFile = b;
+}
+
+
+/*!
+ Specifies that the URL refers to a symbolic link if \a b is TRUE
+ and that it does not if \a b is FALSE.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setSymLink( bool b )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->isSymLink = b;
+}
+
+
+/*!
+ Specifies that the URL is writable if \a b is TRUE and not
+ writable if \a b is FALSE.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setWritable( bool b )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->isWritable = b;
+}
+
+
+/*!
+ Specifies that the URL is readable if \a b is TRUE and not
+ readable if \a b is FALSE.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setReadable( bool b )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->isReadable = b;
+}
+
+/*!
+ Specifies that the owner of the URL is called \a s.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setOwner( const TQString &s )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->owner = s;
+}
+
+/*!
+ Specifies that the owning group of the URL is called \a s.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setGroup( const TQString &s )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->group = s;
+}
+
+/*!
+ Specifies the \a size of the URL.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+#if defined(TQT_ABI_QT4)
+void TQUrlInfo::setSize( TQIODevice::Offset size )
+#else
+void TQUrlInfo::setSize( uint size )
+#endif
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->size = size;
+}
+
+
+// ### reggie - what's the permission type? As in Unix?
+
+/*!
+ Specifies that the URL has access permisions, \a p.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setPermissions( int p )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->permissions = p;
+}
+
+/*!
+ Specifies that the object the URL refers to was last modified at
+ \a dt.
+
+ If you call this function for an invalid URL info, this function
+ turns it into a valid one.
+
+ \sa isValid()
+*/
+
+void TQUrlInfo::setLastModified( const TQDateTime &dt )
+{
+ if ( !d )
+ d = new TQUrlInfoPrivate;
+ d->lastModified = dt;
+}
+
+/*!
+ Destroys the URL info object.
+
+ The TQUrlOperator object to which this URL referred (if any) is not
+ affected.
+*/
+
+TQUrlInfo::~TQUrlInfo()
+{
+ delete d;
+}
+
+/*!
+ Assigns the values of \a ui to this TQUrlInfo object.
+*/
+
+TQUrlInfo &TQUrlInfo::operator=( const TQUrlInfo &ui )
+{
+ if ( ui.d ) {
+ if ( !d )
+ d= new TQUrlInfoPrivate;
+ *d = *ui.d;
+ } else {
+ delete d;
+ d = 0;
+ }
+ return *this;
+}
+
+/*!
+ Returns the file name of the URL.
+
+ \sa isValid()
+*/
+
+TQString TQUrlInfo::name() const
+{
+ if ( !d )
+ return TQString::null;
+ return d->name;
+}
+
+/*!
+ Returns the permissions of the URL. You can use the \c PermissionSpec flags
+ to test for certain permissions.
+
+ \sa isValid()
+*/
+
+int TQUrlInfo::permissions() const
+{
+ if ( !d )
+ return 0;
+ return d->permissions;
+}
+
+/*!
+ Returns the owner of the URL.
+
+ \sa isValid()
+*/
+
+TQString TQUrlInfo::owner() const
+{
+ if ( !d )
+ return TQString::null;
+ return d->owner;
+}
+
+/*!
+ Returns the group of the URL.
+
+ \sa isValid()
+*/
+
+TQString TQUrlInfo::group() const
+{
+ if ( !d )
+ return TQString::null;
+ return d->group;
+}
+
+/*!
+ Returns the size of the URL.
+
+ \sa isValid()
+*/
+
+#if defined(TQT_ABI_QT4)
+TQIODevice::Offset TQUrlInfo::size() const
+#else
+uint TQUrlInfo::size() const
+#endif
+{
+ if ( !d )
+ return 0;
+#if defined(TQT_LARGEFILE_SUPPORT) && !defined(TQT_ABI_QT4)
+ return d->size > UINT_MAX ? UINT_MAX : (uint)d->size;
+#else
+ return d->size;
+#endif
+}
+
+/*!
+ Returns the last modification date of the URL.
+
+ \sa isValid()
+*/
+
+TQDateTime TQUrlInfo::lastModified() const
+{
+ if ( !d )
+ return TQDateTime();
+ return d->lastModified;
+}
+
+/*!
+ Returns the date when the URL was last read.
+
+ \sa isValid()
+*/
+
+TQDateTime TQUrlInfo::lastRead() const
+{
+ if ( !d )
+ return TQDateTime();
+ return d->lastRead;
+}
+
+/*!
+ Returns TRUE if the URL is a directory; otherwise returns FALSE.
+
+ \sa isValid()
+*/
+
+bool TQUrlInfo::isDir() const
+{
+ if ( !d )
+ return FALSE;
+ return d->isDir;
+}
+
+/*!
+ Returns TRUE if the URL is a file; otherwise returns FALSE.
+
+ \sa isValid()
+*/
+
+bool TQUrlInfo::isFile() const
+{
+ if ( !d )
+ return FALSE;
+ return d->isFile;
+}
+
+/*!
+ Returns TRUE if the URL is a symbolic link; otherwise returns FALSE.
+
+ \sa isValid()
+*/
+
+bool TQUrlInfo::isSymLink() const
+{
+ if ( !d )
+ return FALSE;
+ return d->isSymLink;
+}
+
+/*!
+ Returns TRUE if the URL is writable; otherwise returns FALSE.
+
+ \sa isValid()
+*/
+
+bool TQUrlInfo::isWritable() const
+{
+ if ( !d )
+ return FALSE;
+ return d->isWritable;
+}
+
+/*!
+ Returns TRUE if the URL is readable; otherwise returns FALSE.
+
+ \sa isValid()
+*/
+
+bool TQUrlInfo::isReadable() const
+{
+ if ( !d )
+ return FALSE;
+ return d->isReadable;
+}
+
+/*!
+ Returns TRUE if the URL is executable; otherwise returns FALSE.
+
+ \sa isValid()
+*/
+
+bool TQUrlInfo::isExecutable() const
+{
+ if ( !d )
+ return FALSE;
+ return d->isExecutable;
+}
+
+/*!
+ Returns TRUE if \a i1 is greater than \a i2; otherwise returns
+ FALSE. The objects are compared by the value, which is specified
+ by \a sortBy. This must be one of TQDir::Name, TQDir::Time or
+ TQDir::Size.
+*/
+
+bool TQUrlInfo::greaterThan( const TQUrlInfo &i1, const TQUrlInfo &i2,
+ int sortBy )
+{
+ switch ( sortBy ) {
+ case TQDir::Name:
+ return i1.name() > i2.name();
+ case TQDir::Time:
+ return i1.lastModified() > i2.lastModified();
+ case TQDir::Size:
+ return i1.size() > i2.size();
+ default:
+ return FALSE;
+ }
+}
+
+/*!
+ Returns TRUE if \a i1 is less than \a i2; otherwise returns FALSE.
+ The objects are compared by the value, which is specified by \a
+ sortBy. This must be one of TQDir::Name, TQDir::Time or TQDir::Size.
+*/
+
+bool TQUrlInfo::lessThan( const TQUrlInfo &i1, const TQUrlInfo &i2,
+ int sortBy )
+{
+ return !greaterThan( i1, i2, sortBy );
+}
+
+/*!
+ Returns TRUE if \a i1 equals to \a i2; otherwise returns FALSE.
+ The objects are compared by the value, which is specified by \a
+ sortBy. This must be one of TQDir::Name, TQDir::Time or TQDir::Size.
+*/
+
+bool TQUrlInfo::equal( const TQUrlInfo &i1, const TQUrlInfo &i2,
+ int sortBy )
+{
+ switch ( sortBy ) {
+ case TQDir::Name:
+ return i1.name() == i2.name();
+ case TQDir::Time:
+ return i1.lastModified() == i2.lastModified();
+ case TQDir::Size:
+ return i1.size() == i2.size();
+ default:
+ return FALSE;
+ }
+}
+
+/*!
+ Compares this TQUrlInfo with \a i and returns TRUE if they are
+ equal; otherwise returns FALSE.
+*/
+
+bool TQUrlInfo::operator==( const TQUrlInfo &i ) const
+{
+ if ( !d )
+ return i.d == 0;
+ if ( !i.d )
+ return FALSE;
+
+ return ( d->name == i.d->name &&
+ d->permissions == i.d->permissions &&
+ d->owner == i.d->owner &&
+ d->group == i.d->group &&
+ d->size == i.d->size &&
+ d->lastModified == i.d->lastModified &&
+ d->lastRead == i.d->lastRead &&
+ d->isDir == i.d->isDir &&
+ d->isFile == i.d->isFile &&
+ d->isSymLink == i.d->isSymLink &&
+ d->isWritable == i.d->isWritable &&
+ d->isReadable == i.d->isReadable &&
+ d->isExecutable == i.d->isExecutable );
+}
+
+/*!
+ Returns TRUE if the URL info is valid; otherwise returns FALSE.
+ Valid means that the TQUrlInfo tqcontains real information. For
+ example, a call to TQUrlOperator::info() might return a an invalid
+ TQUrlInfo, if no information about the requested entry is
+ available.
+
+ You should always check if the URL info is valid before relying on
+ the values.
+*/
+bool TQUrlInfo::isValid() const
+{
+ return d != 0;
+}
+
+#endif // TQT_NO_NETWORKPROTOCOL
diff --git a/tqtinterface/qt4/src/kernel/tqurlinfo.h b/tqtinterface/qt4/src/kernel/tqurlinfo.h
new file mode 100644
index 0000000..1954367
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqurlinfo.h
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Definition of TQUrlInfo class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQURLINFO_H
+#define TQURLINFO_H
+
+#ifndef TQT_H
+#include "tqdatetime.h"
+#include "tqstring.h"
+#if defined(TQT_ABI_QT4)
+#include "tqiodevice.h"
+#endif
+#endif // TQT_H
+
+class TQUrlOperator;
+class TQUrl;
+class TQUrlInfoPrivate;
+
+class TQ_EXPORT TQUrlInfo
+{
+public:
+ enum PermissionSpec {
+ ReadOwner = 00400, WriteOwner = 00200, ExeOwner = 00100,
+ ReadGroup = 00040, WriteGroup = 00020, ExeGroup = 00010,
+ ReadOther = 00004, WriteOther = 00002, ExeOther = 00001 };
+
+ TQUrlInfo();
+ TQUrlInfo( const TQUrlOperator &path, const TQString &file );
+ TQUrlInfo( const TQUrlInfo &ui );
+#if (TQT_VERSION-0 >= 0x040000)
+#error "TQUrlInfo::TQUrlInfo() should accept TQIODevice::Offset instead of uint"
+#elif defined(TQT_ABI_QT4)
+ TQUrlInfo( const TQString &name, int permissions, const TQString &owner,
+ const TQString &group, TQIODevice::Offset size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable );
+ TQUrlInfo( const TQUrl &url, int permissions, const TQString &owner,
+ const TQString &group, TQIODevice::Offset size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable );
+#else
+ TQUrlInfo( const TQString &name, int permissions, const TQString &owner,
+ const TQString &group, uint size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable );
+ TQUrlInfo( const TQUrl &url, int permissions, const TQString &owner,
+ const TQString &group, uint size, const TQDateTime &lastModified,
+ const TQDateTime &lastRead, bool isDir, bool isFile, bool isSymLink,
+ bool isWritable, bool isReadable, bool isExecutable );
+#endif
+ TQUrlInfo &operator=( const TQUrlInfo &ui );
+ virtual ~TQUrlInfo();
+
+ virtual void setName( const TQString &name );
+ virtual void setDir( bool b );
+ virtual void setFile( bool b );
+ virtual void setSymLink( bool b );
+ virtual void setOwner( const TQString &s );
+ virtual void setGroup( const TQString &s );
+#if (TQT_VERSION-0 >= 0x040000)
+#error "TQUrlInfo::setSize() should accept TQIODevice::Offset instead of uint"
+#elif defined(TQT_ABI_QT4)
+ virtual void setSize( TQIODevice::Offset size );
+#else
+ virtual void setSize( uint size );
+#endif
+ virtual void setWritable( bool b );
+ virtual void setReadable( bool b );
+ virtual void setPermissions( int p );
+ virtual void setLastModified( const TQDateTime &dt );
+
+ bool isValid() const;
+
+ TQString name() const;
+ int permissions() const;
+ TQString owner() const;
+ TQString group() const;
+#if (TQT_VERSION-0 >= 0x040000)
+#error "TQUrlInfo::size() should return TQIODevice::Offset instead of uint"
+#elif defined(TQT_ABI_QT4)
+ TQIODevice::Offset size() const;
+#else
+ uint size() const;
+#endif
+ TQDateTime lastModified() const;
+ TQDateTime lastRead() const;
+ bool isDir() const;
+ bool isFile() const;
+ bool isSymLink() const;
+ bool isWritable() const;
+ bool isReadable() const;
+ bool isExecutable() const;
+
+ static bool greaterThan( const TQUrlInfo &i1, const TQUrlInfo &i2,
+ int sortBy );
+ static bool lessThan( const TQUrlInfo &i1, const TQUrlInfo &i2,
+ int sortBy );
+ static bool equal( const TQUrlInfo &i1, const TQUrlInfo &i2,
+ int sortBy );
+
+ bool operator==( const TQUrlInfo &i ) const;
+private:
+ TQUrlInfoPrivate *d;
+
+};
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqurloperator.cpp b/tqtinterface/qt4/src/kernel/tqurloperator.cpp
new file mode 100644
index 0000000..bae40bc
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqurloperator.cpp
@@ -0,0 +1,1226 @@
+/****************************************************************************
+**
+** Implementation of TQUrlOperator class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqurloperator.h"
+
+#ifndef TQT_NO_NETWORKPROTOCOL
+
+#include "tqurlinfo.h"
+#include "tqnetworkprotocol.h"
+#include "tqmap.h"
+#include "tqdir.h"
+#include "tqptrdict.h"
+#include "tqguardedptr.h"
+
+//#define TQURLOPERATOR_DEBUG
+
+class TQUrlOperatorPrivate
+{
+public:
+ TQUrlOperatorPrivate()
+ {
+ oldOps.setAutoDelete( FALSE );
+ networkProtocol = 0;
+ nameFilter = "*";
+ currPut = 0;
+ }
+
+ ~TQUrlOperatorPrivate()
+ {
+ delete networkProtocol;
+ while ( oldOps.first() ) {
+ oldOps.first()->free();
+ oldOps.removeFirst();
+ }
+ }
+
+ TQMap<TQString, TQUrlInfo> entryMap;
+ TQNetworkProtocol *networkProtocol;
+ TQString nameFilter;
+ TQDir dir;
+
+ // maps needed for copy/move operations
+ TQPtrDict<TQNetworkOperation> getOpPutOpMap;
+ TQPtrDict<TQNetworkProtocol> getOpPutProtMap;
+ TQPtrDict<TQNetworkProtocol> getOpGetProtMap;
+ TQPtrDict<TQNetworkOperation> getOpRemoveOpMap;
+ TQGuardedPtr<TQNetworkProtocol> currPut;
+ TQStringList waitingCopies;
+ TQString waitingCopiesDest;
+ bool waitingCopiesMove;
+ TQPtrList< TQNetworkOperation > oldOps;
+};
+
+/*!
+ \class TQUrlOperator tqurloperator.h
+
+ \brief The TQUrlOperator class provides common operations on URLs.
+\if defined(commercial)
+ It is part of the <a href="commercialeditions.html">TQt Enterprise Edition</a>.
+\endif
+
+ \ingroup io
+ \ingroup misc
+ \mainclass
+
+ \module network
+
+ This class operates on hierarchical structures (such as
+ filesystems) using URLs. Its API facilitates all the common
+ operations:
+ \table
+ \header \i Operation \i Function
+ \row \i List files \i \l listChildren()
+ \row \i Make a directory \i \l mkdir()
+ \row \i Remove a file \i \l remove()
+ \row \i Rename a file \i \l rename()
+ \row \i Get a file \i \l get()
+ \row \i Put a file \i \l put()
+ \row \i Copy a file \i \l copy()
+ \endtable
+
+ You can obtain additional information about the URL with isDir()
+ and info(). If a directory is to be traversed using
+ listChildren(), a name filter can be set with setNameFilter().
+
+ A TQUrlOperator can be used like this, for example to download a
+ file (and assuming that the FTP protocol is \link
+ qInitNetworkProtocols() registered\endlink):
+ \code
+ TQUrlOperator *op = new TQUrlOperator();
+ op->copy( TQString("ftp://ftp.trolltech.com/qt/source/qt-2.1.0.tar.gz"),
+ "file:/tmp" );
+ \endcode
+
+ If you want to be notified about success/failure, progress, etc.,
+ you can connect to TQUrlOperator's Q_SIGNALS, e.g. to start(),
+ newChildren(), createdDirectory(), removed(), data(),
+ dataTransferProgress(), startedNextCopy(),
+ connectionStateChanged(), finished(), etc. A network operation can
+ be stopped with stop().
+
+ The class uses the functionality of registered network protocols
+ to perform these operations. Depending of the protocol of the URL,
+ it uses an appropriate network protocol class for the operations.
+ Each of the operation functions of TQUrlOperator creates a
+ TQNetworkOperation object that describes the operation and puts it
+ into the operation queue for the network protocol used. If no
+ suitable protocol could be found (because no implementation of the
+ necessary network protocol is registered), the URL operator emits
+ errors. Not every protocol supports every operation, but error
+ handling deals with this problem.
+
+ To register the available network protocols, use the
+ qInitNetworkProtocols() function. The protocols currently
+ supported are:
+ \list
+ \i \link TQFtp FTP\endlink,
+ \i \link TQHttp HTTP\endlink,
+ \i \link TQLocalFs local file system\endlink.
+ \endlist
+
+ For more information about the TQt Network Architecture see the
+ \link network.html TQt Network Documentation\endlink.
+
+ \sa TQNetworkProtocol, TQNetworkOperation
+*/
+
+/*!
+ \fn void TQUrlOperator::newChildren( const TQValueList<TQUrlInfo> &i, TQNetworkOperation *op )
+
+ This signal is emitted after listChildren() was called and new
+ tqchildren (i.e. files) have been read from a list of files. \a i
+ holds the information about the new files. \a op is a pointer
+ to the operation object which tqcontains all the information about
+ the operation, including the state.
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+
+/*!
+ \fn void TQUrlOperator::finished( TQNetworkOperation *op )
+
+ This signal is emitted when an operation of some sort finishes,
+ whether with success or failure. \a op is a pointer to the
+ operation object, which tqcontains all the information, including
+ the state, of the operation which has been finished. Check the
+ state and error code of the operation object to see whether or not
+ the operation was successful.
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+/*!
+ \fn void TQUrlOperator::start( TQNetworkOperation *op )
+
+ Some operations (such as listChildren()) emit this signal when
+ they start processing the operation. \a op is a pointer to the
+ operation object which tqcontains all the information about the
+ operation, including the state.
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+/*!
+ \fn void TQUrlOperator::createdDirectory( const TQUrlInfo &i, TQNetworkOperation *op )
+
+ This signal is emitted when mkdir() succeeds and the directory has
+ been created. \a i holds the information about the new directory.
+
+ \a op is a pointer to the operation object, which tqcontains all the
+ information about the operation, including the state.
+ \c op->arg(0) holds the new directory's name.
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+/*!
+ \fn void TQUrlOperator::removed( TQNetworkOperation *op )
+
+ This signal is emitted when remove() has been succesful and the
+ file has been removed.
+
+ \a op is a pointer to the operation object which tqcontains all the
+ information about the operation, including the state.
+ \c op->arg(0) holds the name of the file that was removed.
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+/*!
+ \fn void TQUrlOperator::itemChanged( TQNetworkOperation *op )
+
+ This signal is emitted whenever a file which is a child of the URL
+ has been changed, for example by successfully calling rename().
+ \a op is a pointer to the operation object which tqcontains all the
+ information about the operation, including the state.
+ \c op->arg(0) holds the original file name and \c op->arg(1) holds
+ the new file name (if it was changed).
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+/*!
+ \fn void TQUrlOperator::data( const TQByteArray &data, TQNetworkOperation *op )
+
+ This signal is emitted when new \a data has been received after calling
+ get() or put().
+ \a op is a pointer to the operation object which tqcontains all
+ the information about the operation, including the state.
+ \c op->arg(0) holds the name of the file whose data is retrieved
+ and op->rawArg(1) holds the (raw) data.
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+/*!
+ \fn void TQUrlOperator::dataTransferProgress( int bytesDone, int bytesTotal, TQNetworkOperation *op )
+
+ This signal is emitted during data transfer (using put() or
+ get()). \a bytesDone specifies how many bytes of \a bytesTotal have
+ been transferred. More information about the operation is stored in
+ \a op, a pointer to the network operation that is processed.
+ \a bytesTotal may be -1, which means that the total number of bytes
+ is not known.
+
+ \sa TQNetworkOperation, TQNetworkProtocol
+*/
+
+/*!
+ \fn void TQUrlOperator::startedNextCopy( const TQPtrList<TQNetworkOperation> &lst )
+
+ This signal is emitted if copy() starts a new copy operation. \a
+ lst tqcontains all TQNetworkOperations related to this copy
+ operation.
+
+ \sa copy()
+*/
+
+/*!
+ \fn void TQUrlOperator::connectionStateChanged( int state, const TQString &data )
+
+ This signal is emitted whenever the URL operator's connection
+ state changes. \a state describes the new state, which is a
+ \l{TQNetworkProtocol::ConnectionState} value.
+
+ \a data is a string that describes the change of the connection.
+ This can be used to display a message to the user.
+*/
+
+/*!
+ Constructs a TQUrlOperator with an empty (i.e. invalid) URL.
+*/
+
+TQUrlOperator::TQUrlOperator()
+ : TQUrl()
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: cstr 1" );
+#endif
+ d = new TQUrlOperatorPrivate;
+}
+
+/*!
+ Constructs a TQUrlOperator using \a url and parses this string.
+
+ If you pass strings like "/home/qt" the "file" protocol is
+ assumed.
+*/
+
+TQUrlOperator::TQUrlOperator( const TQString &url )
+ : TQUrl( url )
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: cstr 2" );
+#endif
+ d = new TQUrlOperatorPrivate;
+ getNetworkProtocol();
+}
+
+/*!
+ Constructs a copy of \a url.
+*/
+
+TQUrlOperator::TQUrlOperator( const TQUrlOperator& url )
+ : TQObject(), TQUrl( url )
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: cstr 3" );
+#endif
+ d = new TQUrlOperatorPrivate;
+ *d = *url.d;
+
+ d->networkProtocol = 0;
+ getNetworkProtocol();
+ d->nameFilter = "*";
+ d->currPut = 0;
+}
+
+/*!
+ Constructs a TQUrlOperator. The URL on which this TQUrlOperator
+ operates is constructed out of the arguments \a url, \a relUrl and
+ \a checkSlash: see the corresponding TQUrl constructor for an
+ explanation of these arguments.
+*/
+
+TQUrlOperator::TQUrlOperator( const TQUrlOperator& url, const TQString& relUrl, bool checkSlash )
+ : TQUrl( url, relUrl, checkSlash )
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: cstr 4" );
+#endif
+ d = new TQUrlOperatorPrivate;
+ if ( relUrl == "." )
+ *d = *url.d;
+
+ d->networkProtocol = 0;
+ getNetworkProtocol();
+ d->currPut = 0;
+}
+
+/*!
+ Destructor.
+*/
+
+TQUrlOperator::~TQUrlOperator()
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: dstr" );
+#endif
+ delete d;
+}
+
+/*!
+ This private function is used by the simple operation functions,
+ i.e. listChildren(), mkdir(), remove(), rename(), get() and put(),
+ to really start the operation. \a op is a pointer to the network
+ operation that should be started. Returns \a op on success;
+ otherwise returns 0.
+*/
+const TQNetworkOperation *TQUrlOperator::startOperation( TQNetworkOperation *op )
+{
+ if ( !d->networkProtocol )
+ getNetworkProtocol();
+
+ if ( d->networkProtocol && (d->networkProtocol->supportedOperations()&op->operation()) ) {
+ d->networkProtocol->addOperation( op );
+ if ( op->operation() == TQNetworkProtocol::OpListChildren )
+ clearEntries();
+ return op;
+ }
+
+ // error
+ TQString msg;
+ if ( !d->networkProtocol ) {
+ msg = tr( "The protocol `%1' is not supported" ).arg( protocol() );
+ } else {
+ switch ( op->operation() ) {
+ case TQNetworkProtocol::OpListChildren:
+ msg = tr( "The protocol `%1' does not support listing directories" ).arg( protocol() );
+ break;
+ case TQNetworkProtocol::OpMkDir:
+ msg = tr( "The protocol `%1' does not support creating new directories" ).arg( protocol() );
+ break;
+ case TQNetworkProtocol::OpRemove:
+ msg = tr( "The protocol `%1' does not support removing files or directories" ).arg( protocol() );
+ break;
+ case TQNetworkProtocol::OpRename:
+ msg = tr( "The protocol `%1' does not support renaming files or directories" ).arg( protocol() );
+ break;
+ case TQNetworkProtocol::OpGet:
+ msg = tr( "The protocol `%1' does not support getting files" ).arg( protocol() );
+ break;
+ case TQNetworkProtocol::OpPut:
+ msg = tr( "The protocol `%1' does not support putting files" ).arg( protocol() );
+ break;
+ default:
+ // this should never happen
+ break;
+ }
+ }
+ op->setState( TQNetworkProtocol::StFailed );
+ op->setProtocolDetail( msg );
+ op->setErrorCode( (int)TQNetworkProtocol::ErrUnsupported );
+ emit finished( op );
+ deleteOperation( op );
+ return 0;
+}
+
+/*!
+ Starts listing the tqchildren of this URL (e.g. the files in the
+ directory). The start() signal is emitted before the first entry
+ is listed and finished() is emitted after the last one. The
+ newChildren() signal is emitted for each list of new entries. If
+ an error occurs, the signal finished() is emitted, so be sure to
+ check the state of the network operation pointer.
+
+ Because the operation may not be executed immediately, a pointer
+ to the TQNetworkOperation object created by this function is
+ returned. This object tqcontains all the data about the operation
+ and is used to refer to this operation later (e.g. in the Q_SIGNALS
+ that are emitted by the TQUrlOperator). The return value can also
+ be 0 if the operation object couldn't be created.
+
+ The path of this TQUrlOperator must to point to a directory
+ (because the tqchildren of this directory will be listed), not to a
+ file.
+*/
+
+const TQNetworkOperation *TQUrlOperator::listChildren()
+{
+ if ( !checkValid() )
+ return 0;
+
+ TQNetworkOperation *res = new TQNetworkOperation( TQNetworkProtocol::OpListChildren, TQString::null, TQString::null, TQString::null );
+ return startOperation( res );
+}
+
+/*!
+ Tries to create a directory (child) with the name \a dirname. If
+ it is successful, a newChildren() signal with the new child is
+ emitted, and the createdDirectory() signal with the information
+ about the new child is also emitted. The finished() signal (with
+ success or failure) is emitted after the operation has been
+ processed, so check the state of the network operation object to
+ see whether or not the operation was successful.
+
+ Because the operation will not be executed immediately, a pointer
+ to the TQNetworkOperation object created by this function is
+ returned. This object tqcontains all the data about the operation
+ and is used to refer to this operation later (e.g. in the Q_SIGNALS
+ that are emitted by the TQUrlOperator). The return value can also
+ be 0 if the operation object couldn't be created.
+
+ The path of this TQUrlOperator must to point to a directory (not a
+ file) because the new directory will be created in this path.
+*/
+
+const TQNetworkOperation *TQUrlOperator::mkdir( const TQString &dirname )
+{
+ if ( !checkValid() )
+ return 0;
+
+ TQNetworkOperation *res = new TQNetworkOperation( TQNetworkProtocol::OpMkDir, dirname, TQString::null, TQString::null );
+ return startOperation( res );
+}
+
+/*!
+ Tries to remove the file (child) \a filename. If it succeeds the
+ removed() signal is emitted. finished() (with success or failure)
+ is also emitted after the operation has been processed, so check
+ the state of the network operation object to see whether or not
+ the operation was successful.
+
+ Because the operation will not be executed immediately, a pointer
+ to the TQNetworkOperation object created by this function is
+ returned. This object tqcontains all the data about the operation
+ and is used to refer to this operation later (e.g. in the Q_SIGNALS
+ that are emitted by the TQUrlOperator). The return value can also
+ be 0 if the operation object couldn't be created.
+
+ The path of this TQUrlOperator must point to a directory; because
+ if \a filename is relative, it will try to remove it in this
+ directory.
+*/
+
+const TQNetworkOperation *TQUrlOperator::remove( const TQString &filename )
+{
+ if ( !checkValid() )
+ return 0;
+
+ TQNetworkOperation *res = new TQNetworkOperation( TQNetworkProtocol::OpRemove, filename, TQString::null, TQString::null );
+ return startOperation( res );
+}
+
+/*!
+ Tries to rename the file (child) called \a oldname to \a newname.
+ If it succeeds, the itemChanged() signal is emitted. finished()
+ (with success or failure) is also emitted after the operation has
+ been processed, so check the state of the network operation object
+ to see whether or not the operation was successful.
+
+ Because the operation may not be executed immediately, a pointer
+ to the TQNetworkOperation object created by this function is
+ returned. This object tqcontains all the data about the operation
+ and is used to refer to this operation later (e.g. in the Q_SIGNALS
+ that are emitted by the TQUrlOperator). The return value can also
+ be 0 if the operation object couldn't be created.
+
+ This path of this TQUrlOperator must to point to a directory
+ because \a oldname and \a newname are handled relative to this
+ directory.
+*/
+
+const TQNetworkOperation *TQUrlOperator::rename( const TQString &oldname, const TQString &newname )
+{
+ if ( !checkValid() )
+ return 0;
+
+ TQNetworkOperation *res = new TQNetworkOperation( TQNetworkProtocol::OpRename, oldname, newname, TQString::null );
+ return startOperation( res );
+}
+
+/*!
+ Copies the file \a from to \a to. If \a move is TRUE, the file is
+ moved (copied and removed). \a from must point to a file and \a to
+ must point to a directory (into which \a from is copied) unless \a
+ toPath is set to FALSE. If \a toPath is set to FALSE then the \a
+ to variable is assumed to be the absolute file path (destination
+ file path + file name). The copying is done using the get() and
+ put() operations. If you want to be notified about the progress of
+ the operation, connect to the dataTransferProgress() signal. Bear
+ in mind that the get() and put() operations emit this signal
+ through the TQUrlOperator. The number of transferred bytes and the
+ total bytes that you receive as arguments in this signal do not
+ relate to the the whole copy operation; they relate first to the
+ get() and then to the put() operation. Always check what type of
+ operation the signal comes from; this is given in the signal's
+ last argument.
+
+ At the end, finished() (with success or failure) is emitted, so
+ check the state of the network operation object to see whether or
+ not the operation was successful.
+
+ Because a move or copy operation consists of multiple operations
+ (get(), put() and maybe remove()), this function doesn't return a
+ single TQNetworkOperation, but rather a list of them. They are in
+ the order: get(), put() and (if applicable) remove().
+
+ \sa get(), put()
+*/
+
+TQPtrList<TQNetworkOperation> TQUrlOperator::copy( const TQString &from, const TQString &to, bool move, bool toPath )
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: copy %s %s %d", from.latin1(), to.latin1(), move );
+#endif
+
+ TQPtrList<TQNetworkOperation> ops;
+ ops.setAutoDelete( FALSE );
+
+ TQUrlOperator *uFrom = new TQUrlOperator( *this, from );
+ TQUrlOperator *uTo = new TQUrlOperator( to );
+
+ // prepare some string for later usage
+ TQString frm = *uFrom;
+ TQString file = uFrom->fileName();
+
+ if (frm == to + file)
+ return ops;
+
+ file.prepend( "/" );
+
+ // uFrom and uTo are deleted when the TQNetworkProtocol deletes itself via
+ // autodelete
+ uFrom->getNetworkProtocol();
+ uTo->getNetworkProtocol();
+ TQNetworkProtocol *gProt = uFrom->d->networkProtocol;
+ TQNetworkProtocol *pProt = uTo->d->networkProtocol;
+
+ uFrom->setPath( uFrom->dirPath() );
+
+ if ( gProt && (gProt->supportedOperations()&TQNetworkProtocol::OpGet) &&
+ pProt && (pProt->supportedOperations()&TQNetworkProtocol::OpPut) ) {
+
+ connect( gProt, TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ),
+ this, TQT_SLOT( copyGotData(const TQByteArray&,TQNetworkOperation*) ) );
+ connect( gProt, TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ),
+ this, TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ) );
+ connect( gProt, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ this, TQT_SLOT( continueCopy(TQNetworkOperation*) ) );
+ connect( gProt, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ this, TQT_SIGNAL( finished(TQNetworkOperation*) ) );
+ connect( gProt, TQT_SIGNAL( connectionStateChanged(int,const TQString&) ),
+ this, TQT_SIGNAL( connectionStateChanged(int,const TQString&) ) );
+
+ connect( pProt, TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ),
+ this, TQT_SIGNAL( dataTransferProgress(int,int,TQNetworkOperation*) ) );
+ connect( pProt, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ this, TQT_SIGNAL( finished(TQNetworkOperation*) ) );
+ connect( pProt, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ this, TQT_SLOT( finishedCopy() ) );
+
+ TQNetworkOperation *opGet = new TQNetworkOperation( TQNetworkProtocol::OpGet, frm, TQString::null, TQString::null );
+ ops.append( opGet );
+ gProt->addOperation( opGet );
+
+
+ TQString toFile = to + file;
+ if (!toPath)
+ toFile = to;
+
+ TQNetworkOperation *opPut = new TQNetworkOperation( TQNetworkProtocol::OpPut, toFile, TQString::null, TQString::null );
+ ops.append( opPut );
+
+ d->getOpPutProtMap.insert( (void*)opGet, pProt );
+ d->getOpGetProtMap.insert( (void*)opGet, gProt );
+ d->getOpPutOpMap.insert( (void*)opGet, opPut );
+
+ if ( move && (gProt->supportedOperations()&TQNetworkProtocol::OpRemove) ) {
+ gProt->setAutoDelete( FALSE );
+
+ TQNetworkOperation *opRm = new TQNetworkOperation( TQNetworkProtocol::OpRemove, frm, TQString::null, TQString::null );
+ ops.append( opRm );
+ d->getOpRemoveOpMap.insert( (void*)opGet, opRm );
+ } else {
+ gProt->setAutoDelete( TRUE );
+ }
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: copy operation should start now..." );
+#endif
+ return ops;
+ } else {
+ TQString msg;
+ if ( !gProt ) {
+ msg = tr( "The protocol `%1' is not supported" ).arg( uFrom->protocol() );
+ } else if ( gProt->supportedOperations() & TQNetworkProtocol::OpGet ) {
+ msg = tr( "The protocol `%1' does not support copying or moving files or directories" ).arg( uFrom->protocol() );
+ } else if ( !pProt ) {
+ msg = tr( "The protocol `%1' is not supported" ).arg( uTo->protocol() );
+ } else {
+ msg = tr( "The protocol `%1' does not support copying or moving files or directories" ).arg( uTo->protocol() );
+ }
+ delete uFrom;
+ delete uTo;
+ TQNetworkOperation *res = new TQNetworkOperation( TQNetworkProtocol::OpGet, frm, to, TQString::null );
+ res->setState( TQNetworkProtocol::StFailed );
+ res->setProtocolDetail( msg );
+ res->setErrorCode( (int)TQNetworkProtocol::ErrUnsupported );
+ emit finished( res );
+ deleteOperation( res );
+ }
+
+ return ops;
+}
+
+/*!
+ \overload
+
+ Copies the \a files to the directory \a dest. If \a move is TRUE
+ the files are moved, not copied. \a dest must point to a
+ directory.
+
+ This function calls copy() for each entry in \a files in turn. You
+ don't get a result from this function; each time a new copy
+ begins, startedNextCopy() is emitted, with a list of
+ TQNetworkOperations that describe the new copy operation.
+*/
+
+void TQUrlOperator::copy( const TQStringList &files, const TQString &dest,
+ bool move )
+{
+ d->waitingCopies = files;
+ d->waitingCopiesDest = dest;
+ d->waitingCopiesMove = move;
+
+ finishedCopy();
+}
+
+/*!
+ Returns TRUE if the URL is a directory; otherwise returns FALSE.
+ This may not always work correctly, if the protocol of the URL is
+ something other than file (local filesystem). If you pass a bool
+ pointer as the \a ok argument, \a *ok is set to TRUE if the result
+ of this function is known to be correct, and to FALSE otherwise.
+*/
+
+bool TQUrlOperator::isDir( bool *ok )
+{
+ if ( ok )
+ *ok = TRUE;
+ if ( isLocalFile() ) {
+ if ( TQFileInfo( path() ).isDir() )
+ return TRUE;
+ else
+ return FALSE;
+ }
+
+ if ( d->entryMap.tqcontains( "." ) ) {
+ return d->entryMap[ "." ].isDir();
+ }
+ // #### can assume that we are a directory?
+ if ( ok )
+ *ok = FALSE;
+ return TRUE;
+}
+
+/*!
+ Tells the network protocol to get data from \a location or, if
+ this is TQString::null, to get data from the location to which this
+ URL points (see TQUrl::fileName() and TQUrl::encodedPathAndQuery()).
+ What happens then depends on the network protocol. The data()
+ signal is emitted when data comes in. Because it's unlikely that
+ all data will come in at once, it is common for multiple data()
+ Q_SIGNALS to be emitted. The dataTransferProgress() signal is
+ emitted while processing the operation. At the end, finished()
+ (with success or failure) is emitted, so check the state of the
+ network operation object to see whether or not the operation was
+ successful.
+
+ If \a location is TQString::null, the path of this TQUrlOperator
+ should point to a file when you use this operation. If \a location
+ is not empty, it can be a relative URL (a child of the path to
+ which the TQUrlOperator points) or an absolute URL.
+
+ For example, to get a web page you might do something like this:
+
+ \code
+ TQUrlOperator op( "http://www.whatever.org/cgi-bin/search.pl?cmd=Hello" );
+ op.get();
+ \endcode
+
+ For most other operations, the path of the TQUrlOperator must point
+ to a directory. If you want to download a file you could do the
+ following:
+
+ \code
+ TQUrlOperator op( "ftp://ftp.whatever.org/pub" );
+ // do some other stuff like op.listChildren() or op.mkdir( "new_dir" )
+ op.get( "a_file.txt" );
+ \endcode
+
+ This will get the data of ftp://ftp.whatever.org/pub/a_file.txt.
+
+ \e Never do anything like this:
+ \code
+ TQUrlOperator op( "http://www.whatever.org/cgi-bin" );
+ op.get( "search.pl?cmd=Hello" ); // WRONG!
+ \endcode
+
+ If \a location is not empty and relative it must not contain any
+ queries or references, just the name of a child. So if you need to
+ specify a query or reference, do it as shown in the first example
+ or specify the full URL (such as
+ http://www.whatever.org/cgi-bin/search.pl?cmd=Hello) as \a location.
+
+ \sa copy()
+*/
+
+const TQNetworkOperation *TQUrlOperator::get( const TQString &location )
+{
+ TQUrl u( *this );
+ if ( !location.isEmpty() )
+ u = TQUrl( *this, location );
+
+ if ( !u.isValid() )
+ return 0;
+
+ if ( !d->networkProtocol ) {
+ setProtocol( u.protocol() );
+ getNetworkProtocol();
+ }
+
+ TQNetworkOperation *res = new TQNetworkOperation( TQNetworkProtocol::OpGet, u, TQString::null, TQString::null );
+ return startOperation( res );
+}
+
+/*!
+ This function tells the network protocol to put \a data in \a
+ location. If \a location is empty (TQString::null), it puts the \a
+ data in the location to which the URL points. What happens depends
+ on the network protocol. Depending on the network protocol, some
+ data might come back after putting data, in which case the data()
+ signal is emitted. The dataTransferProgress() signal is emitted
+ during processing of the operation. At the end, finished() (with
+ success or failure) is emitted, so check the state of the network
+ operation object to see whether or not the operation was
+ successful.
+
+ If \a location is TQString::null, the path of this TQUrlOperator
+ should point to a file when you use this operation. If \a location
+ is not empty, it can be a relative (a child of the path to which
+ the TQUrlOperator points) or an absolute URL.
+
+ For putting some data to a file you can do the following:
+
+ \code
+ TQUrlOperator op( "ftp://ftp.whatever.com/home/me/filename.dat" );
+ op.put( data );
+ \endcode
+
+ For most other operations, the path of the TQUrlOperator must point
+ to a directory. If you want to upload data to a file you could do
+ the following:
+
+ \code
+ TQUrlOperator op( "ftp://ftp.whatever.com/home/me" );
+ // do some other stuff like op.listChildren() or op.mkdir( "new_dir" )
+ op.put( data, "filename.dat" );
+ \endcode
+
+ This will upload the data to ftp://ftp.whatever.com/home/me/filename.dat.
+
+ \sa copy()
+*/
+
+const TQNetworkOperation *TQUrlOperator::put( const TQByteArray &data, const TQString &location )
+{
+ TQUrl u( *this );
+ if ( !location.isEmpty() )
+ u = TQUrl( *this, location );
+
+ if ( !u.isValid() )
+ return 0;
+
+ if ( !d->networkProtocol ) {
+ setProtocol( u.protocol() );
+ getNetworkProtocol();
+ }
+
+ TQNetworkOperation *res = new TQNetworkOperation( TQNetworkProtocol::OpPut, u, TQString::null, TQString::null );
+ res->setRawArg( 1, data );
+ return startOperation( res );
+}
+
+/*!
+ Sets the name filter of the URL to \a nameFilter.
+
+ \sa TQDir::setNameFilter()
+*/
+
+void TQUrlOperator::setNameFilter( const TQString &nameFilter )
+{
+ d->nameFilter = nameFilter;
+}
+
+/*!
+ Returns the name filter of the URL.
+
+ \sa TQUrlOperator::setNameFilter() TQDir::nameFilter()
+*/
+
+TQString TQUrlOperator::nameFilter() const
+{
+ return d->nameFilter;
+}
+
+/*!
+ Clears the cache of tqchildren.
+*/
+
+void TQUrlOperator::clearEntries()
+{
+ d->entryMap.clear();
+}
+
+/*!
+ Adds an entry to the cache of tqchildren.
+*/
+
+void TQUrlOperator::addEntry( const TQValueList<TQUrlInfo> &i )
+{
+ TQValueList<TQUrlInfo>::ConstIterator it = i.begin();
+ for ( ; it != i.end(); ++it )
+ d->entryMap[ ( *it ).name().stripWhiteSpace() ] = *it;
+}
+
+/*!
+ Returns the URL information for the child \a entry, or returns an
+ empty TQUrlInfo object if there is no information available about
+ \a entry. Information about \a entry is only available after a successfully
+ finished listChildren() operation.
+*/
+
+TQUrlInfo TQUrlOperator::info( const TQString &entry ) const
+{
+ if ( d->entryMap.tqcontains( entry.stripWhiteSpace() ) ) {
+ return d->entryMap[ entry.stripWhiteSpace() ];
+ } else if ( entry == "." || entry == ".." ) {
+ // return a faked TQUrlInfo
+ TQUrlInfo inf;
+ inf.setName( entry );
+ inf.setDir( TRUE );
+ inf.setFile( FALSE );
+ inf.setSymLink( FALSE );
+ inf.setOwner( tr( "(unknown)" ) );
+ inf.setGroup( tr( "(unknown)" ) );
+ inf.setSize( 0 );
+ inf.setWritable( FALSE );
+ inf.setReadable( TRUE );
+ return inf;
+ }
+ return TQUrlInfo();
+}
+
+/*!
+ Finds a network protocol for the URL and deletes the old network protocol.
+*/
+
+void TQUrlOperator::getNetworkProtocol()
+{
+ delete d->networkProtocol;
+ TQNetworkProtocol *p = TQNetworkProtocol::getNetworkProtocol( protocol() );
+ if ( !p ) {
+ d->networkProtocol = 0;
+ return;
+ }
+
+ d->networkProtocol = (TQNetworkProtocol *)p;
+ d->networkProtocol->setUrl( this );
+ connect( d->networkProtocol, TQT_SIGNAL( itemChanged(TQNetworkOperation*) ),
+ this, TQT_SLOT( slotItemChanged(TQNetworkOperation*) ) );
+}
+
+/*!
+ Deletes the currently used network protocol.
+*/
+
+void TQUrlOperator::deleteNetworkProtocol()
+{
+ if (d->networkProtocol) {
+ d->networkProtocol->deleteLater();
+ d->networkProtocol = 0;
+ }
+}
+
+/*!
+ \reimp
+*/
+
+void TQUrlOperator::setPath( const TQString& path )
+{
+ TQUrl::setPath( path );
+ if ( d->networkProtocol )
+ d->networkProtocol->setUrl( this );
+}
+
+/*!
+ \reimp
+*/
+
+void TQUrlOperator::reset()
+{
+ TQUrl::reset();
+ deleteNetworkProtocol();
+ d->nameFilter = "*";
+}
+
+/*!
+ \reimp
+*/
+
+bool TQUrlOperator::parse( const TQString &url )
+{
+ bool b = TQUrl::parse( url );
+ if ( !b ) {
+ return b;
+ }
+
+ getNetworkProtocol();
+
+ return b;
+}
+
+/*!
+ \reimp
+*/
+
+TQUrlOperator& TQUrlOperator::operator=( const TQUrlOperator &url )
+{
+ deleteNetworkProtocol();
+ TQUrl::operator=( url );
+
+ TQPtrDict<TQNetworkOperation> getOpPutOpMap = d->getOpPutOpMap;
+ TQPtrDict<TQNetworkProtocol> getOpPutProtMap = d->getOpPutProtMap;
+ TQPtrDict<TQNetworkProtocol> getOpGetProtMap = d->getOpGetProtMap;
+ TQPtrDict<TQNetworkOperation> getOpRemoveOpMap = d->getOpRemoveOpMap;
+
+ *d = *url.d;
+
+ d->oldOps.setAutoDelete( FALSE );
+ d->getOpPutOpMap = getOpPutOpMap;
+ d->getOpPutProtMap = getOpPutProtMap;
+ d->getOpGetProtMap = getOpGetProtMap;
+ d->getOpRemoveOpMap = getOpRemoveOpMap;
+
+ d->networkProtocol = 0;
+ getNetworkProtocol();
+ return *this;
+}
+
+/*!
+ \reimp
+*/
+
+TQUrlOperator& TQUrlOperator::operator=( const TQString &url )
+{
+ deleteNetworkProtocol();
+ TQUrl::operator=( url );
+ d->oldOps.setAutoDelete( FALSE );
+ getNetworkProtocol();
+ return *this;
+}
+
+/*!
+ \reimp
+*/
+
+bool TQUrlOperator::cdUp()
+{
+ bool b = TQUrl::cdUp();
+ if ( d->networkProtocol )
+ d->networkProtocol->setUrl( this );
+ return b;
+}
+
+/*!
+ \reimp
+*/
+
+bool TQUrlOperator::checkValid()
+{
+ // ######
+ if ( !isValid() ) {
+ //emit error( ErrValid, tr( "The entered URL is not valid!" ) );
+ return FALSE;
+ } else
+ return TRUE;
+}
+
+
+/*!
+ \internal
+*/
+
+void TQUrlOperator::copyGotData( const TQByteArray &data_, TQNetworkOperation *op )
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: copyGotData: %d new bytes", data_.size() );
+#endif
+ TQNetworkOperation *put = d->getOpPutOpMap[ (void*)op ];
+ if ( put ) {
+ TQByteArray &s = put->raw( 1 );
+ int size = s.size();
+ s.resize( size + data_.size() );
+ memcpy( s.data() + size, data_.data(), data_.size() );
+ }
+ emit data( data_, op );
+}
+
+/*!
+ \internal
+*/
+
+void TQUrlOperator::continueCopy( TQNetworkOperation *op )
+{
+ if ( op->operation() != TQNetworkProtocol::OpGet )
+ return;
+ if ( op->state()!=TQNetworkProtocol::StDone && op->state()!=TQNetworkProtocol::StFailed ) {
+ return;
+ }
+
+#ifdef TQURLOPERATOR_DEBUG
+ if ( op->state() != TQNetworkProtocol::StFailed ) {
+ qDebug( "TQUrlOperator: continue copy (get finished, put will start)" );
+ }
+#endif
+
+ TQNetworkOperation *put = d->getOpPutOpMap[ (void*)op ];
+ TQNetworkProtocol *gProt = d->getOpGetProtMap[ (void*)op ];
+ TQNetworkProtocol *pProt = d->getOpPutProtMap[ (void*)op ];
+ TQNetworkOperation *rm = d->getOpRemoveOpMap[ (void*)op ];
+ d->getOpPutOpMap.take( op );
+ d->getOpGetProtMap.take( op );
+ d->getOpPutProtMap.take( op );
+ d->getOpRemoveOpMap.take( op );
+ if ( pProt )
+ pProt->setAutoDelete( TRUE );
+ if ( put && pProt ) {
+ if ( op->state() != TQNetworkProtocol::StFailed ) {
+ pProt->addOperation( put );
+ d->currPut = pProt;
+ } else {
+ deleteOperation( put );
+ }
+ }
+ if ( gProt ) {
+ gProt->setAutoDelete( TRUE );
+ }
+ if ( rm && gProt ) {
+ if ( op->state() != TQNetworkProtocol::StFailed ) {
+ gProt->addOperation( rm );
+ } else {
+ deleteOperation( rm );
+ }
+ }
+ disconnect( gProt, TQT_SIGNAL( data(const TQByteArray&,TQNetworkOperation*) ),
+ this, TQT_SLOT( copyGotData(const TQByteArray&,TQNetworkOperation*) ) );
+ disconnect( gProt, TQT_SIGNAL( finished(TQNetworkOperation*) ),
+ this, TQT_SLOT( continueCopy(TQNetworkOperation*) ) );
+}
+
+/*!
+ \internal
+*/
+
+void TQUrlOperator::finishedCopy()
+{
+#ifdef TQURLOPERATOR_DEBUG
+ qDebug( "TQUrlOperator: finished copy (finished putting)" );
+#endif
+
+ if ( d->waitingCopies.isEmpty() )
+ return;
+
+ TQString cp = d->waitingCopies.first();
+ d->waitingCopies.remove( cp );
+ TQPtrList<TQNetworkOperation> lst = copy( cp, d->waitingCopiesDest, d->waitingCopiesMove );
+ emit startedNextCopy( lst );
+}
+
+/*!
+ Stops the current network operation and removes all this
+ TQUrlOperator's waiting network operations.
+*/
+
+void TQUrlOperator::stop()
+{
+ d->getOpPutOpMap.clear();
+ d->getOpRemoveOpMap.clear();
+ d->getOpGetProtMap.setAutoDelete( TRUE );
+ d->getOpPutProtMap.setAutoDelete( TRUE );
+ TQPtrDictIterator<TQNetworkProtocol> it( d->getOpPutProtMap );
+ for ( ; it.current(); ++it )
+ it.current()->stop();
+ d->getOpPutProtMap.clear();
+ it = TQPtrDictIterator<TQNetworkProtocol>( d->getOpGetProtMap );
+ for ( ; it.current(); ++it )
+ it.current()->stop();
+ d->getOpGetProtMap.clear();
+ if ( d->currPut ) {
+ d->currPut->stop();
+ delete (TQNetworkProtocol *) d->currPut;
+ d->currPut = 0;
+ }
+ d->waitingCopies.clear();
+ if ( d->networkProtocol )
+ d->networkProtocol->stop();
+ getNetworkProtocol();
+}
+
+/*!
+ \internal
+*/
+
+void TQUrlOperator::deleteOperation( TQNetworkOperation *op )
+{
+ if ( op )
+ d->oldOps.append( op );
+}
+
+/*!
+ \internal
+ updates the entryMap after a network operation finished
+*/
+
+void TQUrlOperator::slotItemChanged( TQNetworkOperation *op )
+{
+ if ( !op )
+ return;
+
+ switch ( op->operation() ) {
+ case TQNetworkProtocol::OpRename :
+ {
+ if ( op->arg( 0 ) == op->arg( 1 ) )
+ return;
+
+ TQMap<TQString, TQUrlInfo>::iterator mi = d->entryMap.tqfind( op->arg( 0 ) );
+ if ( mi != d->entryMap.end() ) {
+ mi.data().setName( op->arg( 1 ) );
+ d->entryMap[ op->arg( 1 ) ] = mi.data();
+ d->entryMap.erase( mi );
+ }
+ break;
+ }
+ case TQNetworkProtocol::OpRemove :
+ {
+ TQMap<TQString, TQUrlInfo>::iterator mi = d->entryMap.tqfind( op->arg( 0 ) );
+ if ( mi != d->entryMap.end() )
+ d->entryMap.erase( mi );
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+
+#endif // TQT_NO_NETWORKPROTOCOL
diff --git a/tqtinterface/qt4/src/kernel/tqurloperator.h b/tqtinterface/qt4/src/kernel/tqurloperator.h
new file mode 100644
index 0000000..822c769
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqurloperator.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Definition of TQUrlOperator class
+**
+** Created : 950429
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQURLOPERATOR_H
+#define TQURLOPERATOR_H
+
+#ifndef TQT_H
+#include "tqobject.h"
+#include "tqurl.h"
+#include "tqptrlist.h"
+#include "tqnetworkprotocol.h"
+#include "tqstringlist.h" // TQString->TQStringList conversion
+#endif // TQT_H
+
+#ifndef TQT_NO_NETWORKPROTOCOL
+
+class TQUrlInfo;
+class TQUrlOperatorPrivate;
+
+class TQ_EXPORT TQUrlOperator : public TQObject, public TQUrl
+{
+ friend class TQNetworkProtocol;
+
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+ TQUrlOperator();
+ TQUrlOperator( const TQString &urL );
+ TQUrlOperator( const TQUrlOperator& url );
+ TQUrlOperator( const TQUrlOperator& url, const TQString& relUrl, bool checkSlash = FALSE );
+ virtual ~TQUrlOperator();
+
+ virtual void setPath( const TQString& path );
+ virtual bool cdUp();
+
+ virtual const TQNetworkOperation *listChildren();
+ virtual const TQNetworkOperation *mkdir( const TQString &dirname );
+ virtual const TQNetworkOperation *remove( const TQString &filename );
+ virtual const TQNetworkOperation *rename( const TQString &oldname, const TQString &newname );
+ virtual const TQNetworkOperation *get( const TQString &location = TQString::null );
+ virtual const TQNetworkOperation *put( const TQByteArray &data, const TQString &location = TQString::null );
+ virtual TQPtrList<TQNetworkOperation> copy( const TQString &from, const TQString &to, bool move = FALSE, bool toPath = TRUE );
+ virtual void copy( const TQStringList &files, const TQString &dest, bool move = FALSE );
+ virtual bool isDir( bool *ok = 0 );
+
+ virtual void setNameFilter( const TQString &nameFilter );
+ TQString nameFilter() const;
+
+ virtual TQUrlInfo info( const TQString &entry ) const;
+
+ TQUrlOperator& operator=( const TQUrlOperator &url );
+ TQUrlOperator& operator=( const TQString &url );
+
+ virtual void stop();
+
+Q_SIGNALS:
+ void newChildren( const TQValueList<TQUrlInfo> &, TQNetworkOperation *res );
+ void finished( TQNetworkOperation *res );
+ void start( TQNetworkOperation *res );
+ void createdDirectory( const TQUrlInfo &, TQNetworkOperation *res );
+ void removed( TQNetworkOperation *res );
+ void itemChanged( TQNetworkOperation *res );
+ void data( const TQByteArray &, TQNetworkOperation *res );
+ void dataTransferProgress( int bytesDone, int bytesTotal, TQNetworkOperation *res );
+ void startedNextCopy( const TQPtrList<TQNetworkOperation> &lst );
+ void connectionStateChanged( int state, const TQString &data );
+
+protected:
+ void reset();
+ bool parse( const TQString& url );
+ virtual bool checkValid();
+ virtual void clearEntries();
+ void getNetworkProtocol();
+ void deleteNetworkProtocol();
+
+private Q_SLOTS:
+ const TQNetworkOperation *startOperation( TQNetworkOperation *op );
+ void copyGotData( const TQByteArray &data, TQNetworkOperation *op );
+ void continueCopy( TQNetworkOperation *op );
+ void finishedCopy();
+ void addEntry( const TQValueList<TQUrlInfo> &i );
+ void slotItemChanged( TQNetworkOperation *op );
+
+private:
+ void deleteOperation( TQNetworkOperation *op );
+
+ TQUrlOperatorPrivate *d;
+};
+
+#endif // TQT_NO_NETWORKPROTOCOL
+
+#endif // TQURLOPERATOR_H
diff --git a/tqtinterface/qt4/src/kernel/tqvariant.cpp b/tqtinterface/qt4/src/kernel/tqvariant.cpp
new file mode 100644
index 0000000..bd022e1
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqvariant.cpp
@@ -0,0 +1,4972 @@
+/****************************************************************************
+**
+** Implementation of TQVariant class
+**
+** Created : 990414
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <float.h>
+
+#include "tqvariant.h"
+#ifndef TQT_NO_VARIANT
+#include "tqstring.h"
+#include "tqcstring.h"
+#include "tqfont.h"
+#include "tqpixmap.h"
+#include "tqimage.h"
+#include "tqbrush.h"
+#include "tqpoint.h"
+#include "tqrect.h"
+#include "tqsize.h"
+#include "tqcolor.h"
+#include "tqpalette.h"
+#include "tqiconset.h"
+#include "tqdatastream.h"
+#include "tqregion.h"
+#include "tqpointarray.h"
+#include "tqbitmap.h"
+#include "tqcursor.h"
+#include "tqdatetime.h"
+#include "tqsizepolicy.h"
+#include "tqshared.h"
+#include "tqbitarray.h"
+#include "tqkeysequence.h"
+#include "tqpen.h"
+
+#ifdef USE_QT4
+
+#define IconSet Icon
+#define CString ByteArray
+#define PointArray Polygon
+#define ColorGroup 63
+
+/*!
+ Constructs a copy of the variant, \a p, passed as the argument to
+ this constructor. Usually this is a deep copy, but a shallow copy
+ is made if the stored data type is explicitly shared, as e.g.
+ TQImage is.
+*/
+TQVariant::TQVariant( const QVariant& p )
+ : QVariant(p)
+{
+// p.d.ref();
+// d = p.d;
+}
+
+#ifndef TQT_NO_DATASTREAM
+/*!
+ Reads the variant from the data stream, \a s.
+*/
+TQVariant::TQVariant( TQDataStream& s )
+{
+ s >> *this;
+}
+#endif //TQT_NO_DATASTREAM
+
+/*!
+ Constructs a new variant with a string value, \a val.
+*/
+TQVariant::TQVariant( const TQString& val )
+ : QVariant(val)
+{
+// d.type = String;
+// d.data.ptr = new TQString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value, \a val.
+
+ If you want to modify the TQCString after you've passed it to this
+ constructor, we recommend passing a deep copy (see
+ TQCString::copy()).
+*/
+TQVariant::TQVariant( const TQCString& val )
+{
+ d.type = CString;
+ d.data.ptr = new TQCString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value of \a val if \a val
+ is non-null. The variant creates a deep copy of \a val.
+
+ If \a val is null, the resulting variant has type Invalid.
+*/
+TQVariant::TQVariant( const char* val )
+{
+ if ( val == 0 )
+ return;
+ d.type = CString;
+ d.data.ptr = new TQCString( val );
+}
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Constructs a new variant with a string list value, \a val.
+*/
+TQVariant::TQVariant( const TQStringList& val )
+{
+ d.type = StringList;
+ d.data.ptr = new TQStringList( val );
+ d.is_null = FALSE;
+}
+#endif // TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a map of TQVariants, \a val.
+*/
+TQVariant::TQVariant( const TQMap<TQString,TQVariant>& val )
+{
+ d.type = Map;
+ d.data.ptr = new TQMap<TQString,TQVariant>( val );
+ d.is_null = FALSE;
+}
+#endif
+/*!
+ Constructs a new variant with a font value, \a val.
+*/
+TQVariant::TQVariant( const TQFont& val )
+{
+ d.type = Font;
+ d.data.ptr = new TQFont( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a pixmap value, \a val.
+*/
+TQVariant::TQVariant( const TQPixmap& val )
+{
+ d.type = Pixmap;
+ d.data.ptr = new TQPixmap( val );
+}
+
+
+/*!
+ Constructs a new variant with an image value, \a val.
+
+ Because TQImage is explicitly shared, you may need to pass a deep
+ copy to the variant using TQImage::copy(), e.g. if you intend
+ changing the image you've passed later on.
+*/
+TQVariant::TQVariant( const TQImage& val )
+{
+ d.type = Image;
+ d.data.ptr = new TQImage( val );
+}
+
+/*!
+ Constructs a new variant with a brush value, \a val.
+*/
+TQVariant::TQVariant( const TQBrush& val )
+{
+ d.type = Brush;
+ d.data.ptr = new TQBrush( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point value, \a val.
+*/
+TQVariant::TQVariant( const TQPoint& val )
+{
+ d.type = Point;
+ d.data.ptr = new TQPoint( val );
+}
+
+/*!
+ Constructs a new variant with a rect value, \a val.
+*/
+TQVariant::TQVariant( const TQRect& val )
+{
+ d.type = Rect;
+ d.data.ptr = new TQRect( val );
+}
+
+/*!
+ Constructs a new variant with a size value, \a val.
+*/
+TQVariant::TQVariant( const TQSize& val )
+{
+ d.type = Size;
+ d.data.ptr = new TQSize( val );
+}
+
+/*!
+ Constructs a new variant with a color value, \a val.
+*/
+TQVariant::TQVariant( const TQColor& val )
+{
+ d.type = Color;
+ d.data.ptr = new TQColor( val );
+ d.is_null = FALSE;
+}
+
+#ifndef TQT_NO_PALETTE
+/*!
+ Constructs a new variant with a color palette value, \a val.
+*/
+TQVariant::TQVariant( const TQPalette& val )
+{
+ d.type = Palette;
+ d.data.ptr = new TQPalette( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a color group value, \a val.
+*/
+TQVariant::TQVariant( const TQColorGroup& val )
+{
+ d.type = ColorGroup;
+ d.data.ptr = new TQColorGroup( val );
+ d.is_null = FALSE;
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Constructs a new variant with an icon set value, \a val.
+*/
+TQVariant::TQVariant( const TQIconSet& val )
+{
+ d.type = IconSet;
+ d.data.ptr = new TQIconSet( val );
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Constructs a new variant with a region value, \a val.
+*/
+TQVariant::TQVariant( const TQRegion& val )
+{
+ d.type = Region;
+ // ## Force a detach
+ d.data.ptr = new TQRegion( val );
+ ((TQRegion*)d.data.ptr)->translate( 0, 0 );
+}
+
+/*!
+ Constructs a new variant with a bitmap value, \a val.
+*/
+TQVariant::TQVariant( const TQBitmap& val )
+{
+ d.type = Bitmap;
+ d.data.ptr = new TQBitmap( val );
+}
+
+/*!
+ Constructs a new variant with a cursor value, \a val.
+*/
+TQVariant::TQVariant( const TQCursor& val )
+{
+ d.type = Cursor;
+ d.data.ptr = new TQCursor( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point array value, \a val.
+
+ Because TQPointArray is explicitly shared, you may need to pass a
+ deep copy to the variant using TQPointArray::copy(), e.g. if you
+ intend changing the point array you've passed later on.
+*/
+TQVariant::TQVariant( const TQPointArray& val )
+{
+ d.type = PointArray;
+ d.data.ptr = new TQPointArray( val );
+}
+
+/*!
+ Constructs a new variant with a date value, \a val.
+*/
+TQVariant::TQVariant( const TQDate& val )
+{
+ d.type = Date;
+ d.data.ptr = new TQDate( val );
+}
+
+/*!
+ Constructs a new variant with a time value, \a val.
+*/
+TQVariant::TQVariant( const TQTime& val )
+{
+ d.type = Time;
+ d.data.ptr = new TQTime( val );
+}
+
+/*!
+ Constructs a new variant with a date/time value, \a val.
+*/
+TQVariant::TQVariant( const TQDateTime& val )
+{
+ d.type = DateTime;
+ d.data.ptr = new TQDateTime( val );
+}
+
+/*!
+ Constructs a new variant with a bytearray value, \a val.
+*/
+TQVariant::TQVariant( const TQByteArray& val )
+{
+ d.type = ByteArray;
+ d.data.ptr = new TQByteArray( val );
+}
+
+/*!
+ Constructs a new variant with a bitarray value, \a val.
+*/
+TQVariant::TQVariant( const TQBitArray& val )
+{
+ d.type = BitArray;
+ d.data.ptr = new TQBitArray( val );
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Constructs a new variant with a key sequence value, \a val.
+*/
+TQVariant::TQVariant( const TQKeySequence& val )
+{
+ d.type = KeySequence;
+ d.data.ptr = new TQKeySequence( val );
+ d.is_null = FALSE;
+}
+
+#endif
+
+/*!
+ Constructs a new variant with a pen value, \a val.
+*/
+TQVariant::TQVariant( const TQPen& val )
+{
+ d.type = Pen;
+ d.data.ptr = new TQPen( val );
+}
+
+#if 0
+
+/*!
+ Constructs a new variant with an integer value, \a val.
+*/
+TQVariant::TQVariant( int val )
+{
+ d = new Private;
+ d->typ = Int;
+ d->value.i = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned integer value, \a val.
+*/
+TQVariant::TQVariant( uint val )
+{
+ d = new Private;
+ d->typ = UInt;
+ d->value.u = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a long long integer value, \a val.
+*/
+TQVariant::TQVariant( TQ_LLONG val )
+{
+ d = new Private;
+ d->typ = LongLong;
+ d->value.ll = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned long long integer value, \a val.
+*/
+
+TQVariant::TQVariant( TQ_ULLONG val )
+{
+ d = new Private;
+ d->typ = ULongLong;
+ d->value.ull = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a boolean value, \a val. The integer
+ argument is a dummy, necessary for compatibility with some
+ compilers.
+*/
+TQVariant::TQVariant( bool val, int )
+{ // this is the comment that does NOT name said compiler.
+ d = new Private;
+ d->typ = Bool;
+ d->value.b = val;
+ d->is_null = FALSE;
+}
+
+
+/*!
+ Constructs a new variant with a floating point value, \a val.
+*/
+TQVariant::TQVariant( double val )
+{
+ d = new Private;
+ d->typ = Double;
+ d->value.d = val;
+ d->is_null = FALSE;
+}
+
+#endif
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a list value, \a val.
+*/
+TQVariant::TQVariant( const TQValueList<TQVariant>& val )
+{
+ d.type = List;
+ d.data.ptr = new TQValueList<TQVariant>( val );
+ d.is_null = FALSE;
+}
+#endif
+
+/*!
+ Constructs a new variant with a size policy value, \a val.
+*/
+TQVariant::TQVariant( TQSizePolicy val )
+{
+// d = new Private;
+ d.type = SizePolicy;
+// d.value.ptr = new TQSizePolicy( val );
+ d.data.ptr = new TQSizePolicy( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Assigns the value of the variant \a variant to this variant.
+
+ This is a deep copy of the variant, but note that if the variant
+ holds an explicitly shared type such as TQImage, a shallow copy is
+ performed.
+
+ Directly taken from Qt4 qvariant.cpp
+*/
+// TQVariant& TQVariant::operator= ( const QVariant& variant )
+// {
+// // if (this == &variant)
+// // return *this;
+// //
+// // clear();
+// // if (variant.d.is_shared) {
+// // variant.d.data.shared->ref.ref();
+// // d = variant.d;
+// // } else if (variant.d.type > Char && variant.d.type < UserType) {
+// // d.type = variant.d.type;
+// // handler->construct(&d, variant.constData());
+// // d.is_null = variant.d.is_null;
+// // } else {
+// // d = variant.d;
+// // }
+// //
+// // return *this;
+//
+// return QVariant::operator=(variant);
+// }
+
+/*!
+ Returns the variant as a TQFont if the variant can be cast to Font;
+ otherwise returns the application's default font.
+
+ \sa asFont(), canCast()
+*/
+const TQFont TQVariant::toFont() const
+{
+ switch ( type() ) {
+// case CString:
+ case ByteArray:
+ case String:
+ {
+ TQFont fnt;
+ fnt.fromString( toString() );
+ return fnt;
+ }
+ case Font:
+ return *((TQFont*)d.data.ptr);
+ default:
+ return TQFont();
+ }
+}
+
+#define TQ_VARIANT_AS( f ) TQ##f& TQVariant::as##f() \
+{ \
+ bool b = isNull(); \
+ if ( d.type != f ) \
+ *this = TQVariant( to##f() ); \
+ else \
+ detach(); \
+ d.is_null = b; \
+ return *((TQ##f*)d.data.ptr); \
+}
+
+TQ_VARIANT_AS(String)
+TQ_VARIANT_AS(CString)
+#ifndef TQT_NO_STRINGLIST
+TQ_VARIANT_AS(StringList)
+#endif
+TQ_VARIANT_AS(Font)
+TQ_VARIANT_AS(Pixmap)
+TQ_VARIANT_AS(Image)
+TQ_VARIANT_AS(Brush)
+TQ_VARIANT_AS(Point)
+TQ_VARIANT_AS(Rect)
+TQ_VARIANT_AS(Size)
+TQ_VARIANT_AS(Color)
+#ifndef TQT_NO_PALETTE
+TQ_VARIANT_AS(Palette)
+TQ_VARIANT_AS(ColorGroup)
+#endif
+#ifndef TQT_NO_ICONSET
+TQ_VARIANT_AS(IconSet)
+#endif
+TQ_VARIANT_AS(PointArray)
+TQ_VARIANT_AS(Bitmap)
+TQ_VARIANT_AS(Region)
+TQ_VARIANT_AS(Cursor)
+TQ_VARIANT_AS(SizePolicy)
+TQ_VARIANT_AS(Date)
+TQ_VARIANT_AS(Time)
+TQ_VARIANT_AS(DateTime)
+TQ_VARIANT_AS(ByteArray)
+TQ_VARIANT_AS(BitArray)
+#ifndef TQT_NO_ACCEL
+TQ_VARIANT_AS(KeySequence)
+#endif
+TQ_VARIANT_AS(Pen)
+
+// #if 0
+
+/*!
+ Returns the variant's value as int reference.
+*/
+int& TQVariant::asInt()
+{
+ detach();
+ if ( d.type != Int ) {
+ int i = toInt();
+ bool b = isNull();
+// d.clear();
+ d.data.i = i;
+ d.type = Int;
+ d.is_null = b;
+ }
+ return d.data.i;
+}
+
+/*!
+ Returns the variant's value as unsigned int reference.
+*/
+uint& TQVariant::asUInt()
+{
+ detach();
+ if ( d.type != UInt ) {
+ uint u = toUInt();
+ bool b = isNull();
+// d.clear();
+ d.data.u = u;
+ d.type = UInt;
+ d.is_null = b;
+ }
+ return d.data.u;
+}
+
+/*!
+ Returns the variant's value as long long reference.
+*/
+TQ_LLONG& TQVariant::asLongLong()
+{
+ detach();
+ if ( d.type != LongLong ) {
+ TQ_LLONG ll = toLongLong();
+ bool b = isNull();
+// d.clear();
+ d.data.ll = ll;
+ d.type = LongLong;
+ d.is_null = b;
+ }
+ return d.data.ll;
+}
+
+/*!
+ Returns the variant's value as unsigned long long reference.
+*/
+TQ_ULLONG& TQVariant::asULongLong()
+{
+ detach();
+ if ( d.type != ULongLong ) {
+ TQ_ULLONG ull = toULongLong();
+ bool b = isNull();
+// d.clear();
+ d.data.ull = ull;
+ d.type = ULongLong;
+ d.is_null = b;
+ }
+ return d.data.ull;
+}
+
+/*!
+ Returns the variant's value as bool reference.
+*/
+bool& TQVariant::asBool()
+{
+ detach();
+ if ( d.type != Bool ) {
+ bool b = toBool();
+ bool nb = isNull();
+// d.clear();
+ d.data.b = b;
+ d.type = Bool;
+ d.is_null = nb;
+ }
+ return d.data.b;
+}
+
+/*!
+ Returns the variant's value as double reference.
+*/
+double& TQVariant::asDouble()
+{
+ detach();
+ if ( d.type != Double ) {
+ double dbl = toDouble();
+ bool b = isNull();
+// d.clear();
+ d.data.d = dbl;
+ d.type = Double;
+ d.is_null = b;
+ }
+ return d.data.d;
+}
+
+// #endif
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant's value as variant list reference.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.asList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQValueList<TQVariant>& TQVariant::asList()
+{
+ bool b = isNull();
+ if ( d.type != List )
+ *this = TQVariant( toList() );
+ else
+ detach();
+ d.is_null = b;
+ return *((TQValueList<TQVariant>*)d.data.ptr);
+}
+
+/*!
+ Returns the variant's value as variant map reference.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.asMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQMap<TQString, TQVariant>& TQVariant::asMap()
+{
+ bool b = isNull();
+ if ( d.type != Map )
+ *this = TQVariant( toMap() );
+ else
+ detach();
+ d.is_null = b;
+ return *((TQMap<TQString,TQVariant>*)d.data.ptr);
+}
+#endif
+
+/*!
+ Returns the variant as a TQString if the variant can be cast to
+ String, otherwise returns TQString::null.
+
+ \sa asString(), canCast()
+*/
+const TQString TQVariant::toString() const
+{
+// switch( d.type ) {
+// // case CString:
+// // return TQString::tqfromLatin1( toCString() );
+// case Int:
+// return TQString::number( toInt() );
+// case UInt:
+// return TQString::number( toUInt() );
+// case LongLong:
+// return TQString::number( toLongLong() );
+// case ULongLong:
+// return TQString::number( toULongLong() );
+// case Double:
+// return TQString::number( toDouble(), 'g', DBL_DIG );
+// #if !defined(TQT_NO_SPRINTF) && !defined(TQT_NO_DATESTRING)
+// case Date:
+// return toDate().toString( Qt::ISODate );
+// case Time:
+// return toTime().toString( Qt::ISODate );
+// case DateTime:
+// return toDateTime().toString( Qt::ISODate );
+// #endif
+// case Bool:
+// return toInt() ? "true" : "false";
+// #ifndef TQT_NO_ACCEL
+// case KeySequence:
+// return (TQString) *( (TQKeySequence*)d.data.ptr );
+// #endif
+// case ByteArray:
+// return TQString( *((TQByteArray*)d.data.ptr) );
+// case Font:
+// return toFont().toString();
+// case Color:
+// return toColor().name();
+// case String:
+// return *(static_cast<TQString*>(d.data.ptr));
+// default:
+// return TQString();
+// }
+
+// const QString& ref = QVariant::toString();
+// return *(static_cast<const TQString*>(&ref));
+ return TQString(QVariant::toString());
+}
+/*!
+ Returns the variant as a TQCString if the variant can be cast to a
+ CString; otherwise returns 0.
+
+ \sa asCString(), canCast()
+*/
+const TQCString TQVariant::toCString() const
+{
+ switch( d.type ) {
+ case CString: return *((TQCString*)d.data.ptr);
+ case String: return ((TQString*)d.data.ptr)->latin1();
+ default: {
+ if (!canCast(String))
+ return 0;
+ TQString c = toString();
+ return TQCString(c.latin1());
+ }
+ }
+}
+
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Returns the variant as a TQStringList if the variant has type()
+ StringList or List of a type that can be converted to TQString;
+ otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myVariant.toStringList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asStringList()
+*/
+const TQStringList TQVariant::toStringList() const
+{
+ switch ( d.type ) {
+ case StringList:
+ return *((TQStringList*)d.data.ptr);
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ {
+ TQStringList lst;
+ TQValueList<TQVariant>::ConstIterator it = listBegin();
+ TQValueList<TQVariant>::ConstIterator end = listEnd();
+ while( it != end ) {
+ TQString tmp = (*it).toString();
+ ++it;
+ lst.append( tmp );
+ }
+ return lst;
+ }
+#endif
+ default:
+ return TQStringList();
+ }
+}
+#endif //TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQMap<TQString,TQVariant> if the variant has
+ type() Map; otherwise returns an empty map.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.toMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asMap()
+*/
+const TQMap<TQString, TQVariant> TQVariant::toMap() const
+{
+ if ( d.type != Map )
+ return TQMap<TQString,TQVariant>();
+
+ return *((TQMap<TQString,TQVariant>*)d.data.ptr);
+}
+#endif
+
+/*!
+ Returns the variant as a TQPixmap if the variant has type() Pixmap;
+ otherwise returns a null pixmap.
+
+ \sa asPixmap()
+*/
+const TQPixmap TQVariant::toPixmap() const
+{
+ if ( d.type != Pixmap )
+ return TQPixmap();
+
+ return *((TQPixmap*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQImage if the variant has type() Image;
+ otherwise returns a null image.
+
+ \sa asImage()
+*/
+const TQImage TQVariant::toImage() const
+{
+ if ( d.type != Image )
+ return TQImage();
+
+ return *((TQImage*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQBrush if the variant has type() Brush;
+ otherwise returns a default brush (with all black colors).
+
+ \sa asBrush()
+*/
+const TQBrush TQVariant::toBrush() const
+{
+ if( d.type != Brush )
+ return TQBrush();
+
+ return *((TQBrush*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQPoint if the variant has type() Point;
+ otherwise returns a point (0, 0).
+
+ \sa asPoint()
+*/
+const TQPoint TQVariant::toPoint() const
+{
+ if ( d.type != Point )
+ return TQPoint();
+
+ return *((TQPoint*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQRect if the variant has type() Rect;
+ otherwise returns an empty rectangle.
+
+ \sa asRect()
+*/
+const TQRect TQVariant::toRect() const
+{
+ if ( d.type != Rect )
+ return TQRect();
+
+ return *((TQRect*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQSize if the variant has type() Size;
+ otherwise returns an invalid size.
+
+ \sa asSize()
+*/
+const TQSize TQVariant::toSize() const
+{
+ if ( d.type != Size )
+ return TQSize();
+
+ return *((TQSize*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQColor if the variant can be cast to Color;
+ otherwise returns an invalid color.
+
+ \sa asColor(), canCast()
+*/
+const TQColor TQVariant::toColor() const
+{
+ switch ( d.type ) {
+ case ByteArray:
+// case CString:
+ case String:
+ {
+ TQColor col;
+ col.setNamedColor( toString() );
+ return col;
+ }
+ case Color:
+ return *((TQColor*)d.data.ptr);
+ default:
+ return TQColor();
+ }
+}
+#ifndef TQT_NO_PALETTE
+/*!
+ Returns the variant as a TQPalette if the variant has type()
+ Palette; otherwise returns a completely black palette.
+
+ \sa asPalette()
+*/
+const TQPalette TQVariant::toPalette() const
+{
+ if ( d.type != Palette )
+ return TQPalette();
+
+ return *((TQPalette*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQColorGroup if the variant has type()
+ ColorGroup; otherwise returns a completely black color group.
+
+ \sa asColorGroup()
+*/
+const TQColorGroup TQVariant::toColorGroup() const
+{
+ if ( d.type != ColorGroup )
+ return TQColorGroup();
+
+ return *((TQColorGroup*)d.data.ptr);
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQIconSet if the variant has type()
+ IconSet; otherwise returns an icon set of null pixmaps.
+
+ \sa asIconSet()
+*/
+const TQIconSet TQVariant::toIconSet() const
+{
+ if ( d.type != IconSet )
+ return TQIconSet();
+
+ return *((TQIconSet*)d.data.ptr);
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQPointArray if the variant has type()
+ PointArray; otherwise returns an empty TQPointArray.
+
+ \sa asPointArray()
+*/
+const TQPointArray TQVariant::toPointArray() const
+{
+ if ( d.type != PointArray )
+ return TQPointArray();
+
+ return *((TQPointArray*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQBitmap if the variant has type() Bitmap;
+ otherwise returns a null TQBitmap.
+
+ \sa asBitmap()
+*/
+const TQBitmap TQVariant::toBitmap() const
+{
+ if ( d.type != Bitmap )
+ return TQBitmap();
+
+ return *((TQBitmap*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQRegion if the variant has type() Region;
+ otherwise returns an empty TQRegion.
+
+ \sa asRegion()
+*/
+const TQRegion TQVariant::toRegion() const
+{
+ if ( d.type != Region )
+ return TQRegion();
+
+ return *((TQRegion*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQCursor if the variant has type() Cursor;
+ otherwise returns the default arrow cursor.
+
+ \sa asCursor()
+*/
+const TQCursor TQVariant::toCursor() const
+{
+#ifndef TQT_NO_CURSOR
+ if ( d.type != Cursor )
+ return TQCursor();
+#endif
+
+ return *((TQCursor*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQDate if the variant can be cast to Date;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ date will be returned if the string cannot be parsed as a
+ Qt::ISODate format date.
+
+ \sa asDate(), canCast()
+*/
+const TQDate TQVariant::toDate() const
+{
+ switch ( d.type ) {
+ case Date:
+ return *((TQDate*)d.data.ptr);
+ case DateTime:
+ return TQT_TQDATE_OBJECT(((TQDateTime*)d.data.ptr)->date());
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQT_TQDATE_OBJECT(TQDate::fromString( *((TQString*)d.data.ptr), Qt::ISODate ));
+// case CString:
+ case ByteArray:
+ return TQT_TQDATE_OBJECT(TQDate::fromString(toString(), Qt::ISODate));
+#endif
+ default:
+ return TQDate();
+ }
+}
+
+/*!
+ Returns the variant as a TQTime if the variant can be cast to Time;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ time will be returned if the string cannot be parsed as a
+ Qt::ISODate format time.
+
+ \sa asTime()
+*/
+const TQTime TQVariant::toTime() const
+{
+ switch ( d.type ) {
+ case Time:
+ return *((TQTime*)d.data.ptr);
+ case DateTime:
+ return TQT_TQTIME_OBJECT(((TQDateTime*)d.data.ptr)->time());
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQT_TQTIME_OBJECT(TQTime::fromString( *((TQString*)d.data.ptr), Qt::ISODate ));
+// case CString:
+ case ByteArray:
+ return TQT_TQTIME_OBJECT(TQTime::fromString(toString(), Qt::ISODate));
+#endif
+ default:
+ return TQTime();
+ }
+}
+
+/*!
+ Returns the variant as a TQDateTime if the variant can be cast to
+ DateTime; otherwise returns an invalid TQDateTime.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ TQDateTime will be returned if the string cannot be parsed as a
+ Qt::ISODate format date/time.
+
+ \sa asDateTime()
+*/
+const TQDateTime TQVariant::toDateTime() const
+{
+ switch ( d.type ) {
+ case DateTime:
+ return *((TQDateTime*)d.data.ptr);
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQT_TQDATETIME_OBJECT(TQDateTime::fromString( *((TQString*)d.data.ptr), Qt::ISODate ));
+// case CString:
+ case ByteArray:
+ return TQT_TQDATETIME_OBJECT(TQDateTime::fromString(toString(), Qt::ISODate));
+#endif
+ case Date:
+ return TQDateTime( *((TQDate*)d.data.ptr) );
+ default:
+ return TQDateTime();
+ }
+}
+
+/*!
+ Returns the variant as a TQByteArray if the variant can be cast to
+ a ByteArray; otherwise returns an empty bytearray.
+
+ \sa asByteArray(), canCast()
+*/
+const TQByteArray TQVariant::toByteArray() const
+{
+ switch(d.type) {
+ case ByteArray: return *((TQByteArray*)d.data.ptr);
+// case CString: return *((TQByteArray*)d.data.ptr);
+ default: {
+ TQByteArray ret;
+ if (canCast(String)) {
+ TQString c = toString();
+ ret.duplicate(c.latin1(), c.length());
+ }
+ return ret;
+ }
+ }
+}
+
+/*!
+ Returns the variant as a TQBitArray if the variant has type()
+ BitArray; otherwise returns an empty bitarray.
+
+ \sa asBitArray()
+*/
+const TQBitArray TQVariant::toBitArray() const
+{
+ if ( d.type == BitArray )
+ return *((TQBitArray*)d.data.ptr);
+ return TQBitArray();
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQKeySequence if the variant can be cast
+ to a KeySequence; otherwise returns an empty key sequence.
+
+ \sa asKeySequence(), canCast()
+*/
+const TQKeySequence TQVariant::toKeySequence() const
+{
+ switch ( d.type ) {
+ case KeySequence:
+ return *((TQKeySequence*)d.data.ptr);
+ case String:
+ case ByteArray:
+// case CString:
+ return TQKeySequence( toString() );
+ case Int:
+ case UInt:
+ case Double:
+ case ULongLong:
+ case LongLong:
+ return TQKeySequence( toInt() );
+ default:
+ return TQKeySequence();
+ }
+}
+
+#endif // TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQPen if the variant has type()
+ Pen; otherwise returns an empty TQPen.
+
+ \sa asPen()
+*/
+const TQPen TQVariant::toPen() const
+{
+ if ( d.type != Pen )
+ return TQPen();
+
+ return *((TQPen*)d.data.ptr);
+}
+
+#if 0
+
+/*!
+ Returns the variant as an int if the variant can be cast to Int;
+ otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asInt(), canCast()
+*/
+int TQVariant::toInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Int );
+
+ switch ( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d.data.ptr)->toInt( ok );
+ case Int:
+ return d.data.i;
+ case UInt:
+ return (int)d.data.u;
+ case LongLong:
+ return (int)d.data.ll;
+ case ULongLong:
+ return (int)d.data.ull;
+ case Double:
+ return (int)d.data.d;
+ case Bool:
+ return (int)d.data.b;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return (int) *( (TQKeySequence*)d.data.ptr );
+#endif
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as an unsigned int if the variant can be cast
+ to UInt; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an unsigned int; otherwise \a *ok is set to FALSE.
+
+ \sa asUInt(), canCast()
+*/
+uint TQVariant::toUInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( UInt );
+
+ switch( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toUInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d.data.ptr)->toUInt( ok );
+ case Int:
+ return (uint)d.data.i;
+ case UInt:
+ return d.data.u;
+ case LongLong:
+ return (uint)d.data.ll;
+ case ULongLong:
+ return (uint)d.data.ull;
+ case Double:
+ return (uint)d.data.d;
+ case Bool:
+ return (uint)d.data.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a long long int if the variant can be cast
+ to LongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asLongLong(), canCast()
+*/
+TQ_LLONG TQVariant::toLongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( LongLong );
+
+ switch ( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toLongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d.data.ptr).toLongLong(ok);
+ case Int:
+ return (TQ_LLONG)d.data.i;
+ case UInt:
+ return (TQ_LLONG)d.data.u;
+ case LongLong:
+ return d.data.ll;
+ case ULongLong:
+ return (TQ_LLONG)d.data.ull;
+ case Double:
+ return (TQ_LLONG)d.data.d;
+ case Bool:
+ return (TQ_LLONG)d.data.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as as an unsigned long long int if the variant
+ can be cast to ULongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asULongLong(), canCast()
+*/
+TQ_ULLONG TQVariant::toULongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( ULongLong );
+
+ switch ( d.type ) {
+ case Int:
+ return (TQ_ULLONG)d.data.i;
+ case UInt:
+ return (TQ_ULLONG)d.data.u;
+ case LongLong:
+ return (TQ_ULLONG)d.data.ll;
+ case ULongLong:
+ return d.data.ull;
+ case Double:
+ return (TQ_ULLONG)d.data.d;
+ case Bool:
+ return (TQ_ULLONG)d.data.b;
+ case String:
+ return ((TQString*)d.data.ptr)->toULongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d.data.ptr).toULongLong(ok);
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a bool if the variant can be cast to Bool;
+ otherWise returns FALSE.
+
+ Returns TRUE if the variant has a numeric type and its value is
+ non-zero, or if the variant has type String, ByteArray or CString
+ and its lower-case content is not empty, "0" or "false"; otherwise
+ returns FALSE.
+
+ \sa asBool(), canCast()
+*/
+bool TQVariant::toBool() const
+{
+ switch( d.type ) {
+ case Bool:
+ return d.data.b;
+ case Double:
+ return d.data.d != 0.0;
+ case Int:
+ return d.data.i != 0;
+ case UInt:
+ return d.data.u != 0;
+ case LongLong:
+ return d.data.ll != 0;
+ case ULongLong:
+ return d.data.ull != 0;
+ case String:
+ case CString:
+ case ByteArray:
+ {
+ TQString str = toString().lower();
+ return !(str == "0" || str == "false" || str.isEmpty() );
+ }
+ default:
+ return FALSE;
+ }
+}
+
+/*!
+ Returns the variant as a double if the variant can be cast to
+ Double; otherwise returns 0.0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to a double; otherwise \a *ok is set to FALSE.
+
+ \sa asDouble(), canCast()
+*/
+double TQVariant::toDouble( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Double );
+
+ switch ( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toDouble( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d.data.ptr)->toDouble( ok );
+ case Double:
+ return d.data.d;
+ case Int:
+ return (double)d.data.i;
+ case Bool:
+ return (double)d.data.b;
+ case UInt:
+ return (double)d.data.u;
+ case LongLong:
+ return (double)d.data.ll;
+ case ULongLong:
+#if defined(TQ_CC_MSVC) && !defined(TQ_CC_MSVC_NET)
+ return (double)(TQ_LLONG)d.data.ull;
+#else
+ return (double)d.data.ull;
+#endif
+ default:
+ return 0.0;
+ }
+}
+
+#endif
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQValueList<TQVariant> if the variant has
+ type() List or StringList; otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.toList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asList()
+*/
+const TQValueList<TQVariant> TQVariant::toList() const
+{
+ if ( d.type == List )
+ return *((TQValueList<TQVariant>*)d.data.ptr);
+#ifndef TQT_NO_STRINGLIST
+ if ( d.type == StringList ) {
+ TQValueList<TQVariant> lst;
+ TQStringList::ConstIterator it = stringListBegin();
+ TQStringList::ConstIterator end = stringListEnd();
+ for( ; it != end; ++it )
+ lst.append( TQVariant( *it ) );
+ return lst;
+ }
+#endif //TQT_NO_STRINGLIST
+ return TQValueList<TQVariant>();
+}
+#endif
+
+/*!
+ Returns the variant as a TQSizePolicy if the variant has type()
+ SizePolicy; otherwise returns an undefined (but legal) size
+ policy.
+*/
+
+TQSizePolicy TQVariant::toSizePolicy() const
+{
+ if ( d.type == SizePolicy )
+ return *((TQSizePolicy*)d.data.ptr);
+
+ return TQSizePolicy();
+}
+
+#else // USE_QT4
+
+#ifndef DBL_DIG
+#define DBL_DIG 10
+#endif //DBL_DIG
+
+// Uncomment to test for memory leaks or to run qt/test/qvariant/main.cpp
+// #define TQVARIANT_DEBUG
+
+
+static bool isNumeric(TQVariant::Type type)
+{
+ return (type == TQVariant::Int || type == TQVariant::UInt
+ || type == TQVariant::Double || type == TQVariant::LongLong
+ || type == TQVariant::ULongLong || type == TQVariant::Bool);
+}
+
+
+#ifdef TQVARIANT_DEBUG
+int qv_count = 0;
+int get_qv_count() { return qv_count; }
+#endif
+
+TQVariant::Private::Private()
+{
+#ifdef TQVARIANT_DEBUG
+ qv_count++;
+#endif
+ typ = TQVariant::Invalid;
+ is_null = TRUE;
+}
+
+TQVariant::Private::Private( Private* d )
+{
+#ifdef TQVARIANT_DEBUG
+ qv_count++;
+#endif
+
+ switch( d->typ )
+ {
+ case TQVariant::Invalid:
+ break;
+ case TQVariant::Bitmap:
+ value.ptr = new TQBitmap( *((TQBitmap*)d->value.ptr) );
+ break;
+ case TQVariant::Region:
+ value.ptr = new TQRegion( *((TQRegion*)d->value.ptr) );
+ // ## Force a detach
+ // ((TQRegion*)value.ptr)->translate( 0, 0 );
+ break;
+ case TQVariant::PointArray:
+ // TQPointArray is explicit shared
+ value.ptr = new TQPointArray( *((TQPointArray*)d->value.ptr) );
+ break;
+ case TQVariant::String:
+ value.ptr = new TQString( *((TQString*)d->value.ptr) );
+ break;
+ case TQVariant::CString:
+ // TQCString is explicit shared
+ value.ptr = new TQCString( *((TQCString*)d->value.ptr) );
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+ value.ptr = new TQStringList( *((TQStringList*)d->value.ptr) );
+ break;
+#endif //TQT_NO_STRINGLIST
+ case TQVariant::Font:
+ value.ptr = new TQFont( *((TQFont*)d->value.ptr) );
+ break;
+ case TQVariant::Pixmap:
+ value.ptr = new TQPixmap( *((TQPixmap*)d->value.ptr) );
+ break;
+ case TQVariant::Image:
+ // TQImage is explicit shared
+ value.ptr = new TQImage( *((TQImage*)d->value.ptr) );
+ break;
+ case TQVariant::Brush:
+ value.ptr = new TQBrush( *((TQBrush*)d->value.ptr) );
+ // ## Force a detach
+ // ((TQBrush*)value.ptr)->setColor( ((TQBrush*)value.ptr)->color() );
+ break;
+ case TQVariant::Point:
+ value.ptr = new TQPoint( *((TQPoint*)d->value.ptr) );
+ break;
+ case TQVariant::Rect:
+ value.ptr = new TQRect( *((TQRect*)d->value.ptr) );
+ break;
+ case TQVariant::Size:
+ value.ptr = new TQSize( *((TQSize*)d->value.ptr) );
+ break;
+ case TQVariant::Color:
+ value.ptr = new TQColor( *((TQColor*)d->value.ptr) );
+ break;
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ value.ptr = new TQPalette( *((TQPalette*)d->value.ptr) );
+ break;
+ case TQVariant::ColorGroup:
+ value.ptr = new TQColorGroup( *((TQColorGroup*)d->value.ptr) );
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ value.ptr = new TQIconSet( *((TQIconSet*)d->value.ptr) );
+ break;
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ value.ptr = new TQMap<TQString,TQVariant>( *((TQMap<TQString,TQVariant>*)d->value.ptr) );
+ break;
+ case TQVariant::List:
+ value.ptr = new TQValueList<TQVariant>( *((TQValueList<TQVariant>*)d->value.ptr) );
+ break;
+#endif
+ case TQVariant::Date:
+ value.ptr = new TQDate( *((TQDate*)d->value.ptr) );
+ break;
+ case TQVariant::Time:
+ value.ptr = new TQTime( *((TQTime*)d->value.ptr) );
+ break;
+ case TQVariant::DateTime:
+ value.ptr = new TQDateTime( *((TQDateTime*)d->value.ptr) );
+ break;
+ case TQVariant::ByteArray:
+ value.ptr = new TQByteArray( *((TQByteArray*)d->value.ptr) );
+ break;
+ case TQVariant::BitArray:
+ value.ptr = new TQBitArray( *((TQBitArray*)d->value.ptr) );
+ break;
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+ value.ptr = new TQKeySequence( *((TQKeySequence*)d->value.ptr) );
+ break;
+#endif
+ case TQVariant::Pen:
+ value.ptr = new TQPen( *((TQPen*)d->value.ptr) );
+ break;
+ case TQVariant::Int:
+ value.i = d->value.i;
+ break;
+ case TQVariant::UInt:
+ value.u = d->value.u;
+ break;
+ case TQVariant::LongLong:
+ value.ll = d->value.ll;
+ break;
+ case TQVariant::ULongLong:
+ value.ull = d->value.ull;
+ break;
+ case TQVariant::Bool:
+ value.b = d->value.b;
+ break;
+ case TQVariant::Double:
+ value.d = d->value.d;
+ break;
+ case TQVariant::SizePolicy:
+ value.ptr = new TQSizePolicy( *((TQSizePolicy*)d->value.ptr) );
+ break;
+ case TQVariant::Cursor:
+ value.ptr = new TQCursor( *((TQCursor*)d->value.ptr) );
+ break;
+ default:
+ TQ_ASSERT( 0 );
+ }
+
+ typ = d->typ;
+ is_null = d->is_null;
+}
+
+TQVariant::Private::~Private()
+{
+#ifdef TQVARIANT_DEBUG
+ qv_count--;
+#endif
+ clear();
+}
+
+void TQVariant::Private::clear()
+{
+ switch( typ )
+ {
+ case TQVariant::Bitmap:
+ delete (TQBitmap*)value.ptr;
+ break;
+ case TQVariant::Cursor:
+ delete (TQCursor*)value.ptr;
+ break;
+ case TQVariant::Region:
+ delete (TQRegion*)value.ptr;
+ break;
+ case TQVariant::PointArray:
+ delete (TQPointArray*)value.ptr;
+ break;
+ case TQVariant::String:
+ delete (TQString*)value.ptr;
+ break;
+ case TQVariant::CString:
+ delete (TQCString*)value.ptr;
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+ delete (TQStringList*)value.ptr;
+ break;
+#endif //TQT_NO_STRINGLIST
+ case TQVariant::Font:
+ delete (TQFont*)value.ptr;
+ break;
+ case TQVariant::Pixmap:
+ delete (TQPixmap*)value.ptr;
+ break;
+ case TQVariant::Image:
+ delete (TQImage*)value.ptr;
+ break;
+ case TQVariant::Brush:
+ delete (TQBrush*)value.ptr;
+ break;
+ case TQVariant::Point:
+ delete (TQPoint*)value.ptr;
+ break;
+ case TQVariant::Rect:
+ delete (TQRect*)value.ptr;
+ break;
+ case TQVariant::Size:
+ delete (TQSize*)value.ptr;
+ break;
+ case TQVariant::Color:
+ delete (TQColor*)value.ptr;
+ break;
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ delete (TQPalette*)value.ptr;
+ break;
+ case TQVariant::ColorGroup:
+ delete (TQColorGroup*)value.ptr;
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ delete (TQIconSet*)value.ptr;
+ break;
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ delete (TQMap<TQString,TQVariant>*)value.ptr;
+ break;
+ case TQVariant::List:
+ delete (TQValueList<TQVariant>*)value.ptr;
+ break;
+#endif
+ case TQVariant::SizePolicy:
+ delete (TQSizePolicy*)value.ptr;
+ break;
+ case TQVariant::Date:
+ delete (TQDate*)value.ptr;
+ break;
+ case TQVariant::Time:
+ delete (TQTime*)value.ptr;
+ break;
+ case TQVariant::DateTime:
+ delete (TQDateTime*)value.ptr;
+ break;
+ case TQVariant::ByteArray:
+ delete (TQByteArray*)value.ptr;
+ break;
+ case TQVariant::BitArray:
+ delete (TQBitArray*)value.ptr;
+ break;
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+ delete (TQKeySequence*)value.ptr;
+ break;
+#endif
+ case TQVariant::Pen:
+ delete (TQPen*)value.ptr;
+ break;
+ case TQVariant::Invalid:
+ case TQVariant::Int:
+ case TQVariant::UInt:
+ case TQVariant::LongLong:
+ case TQVariant::ULongLong:
+ case TQVariant::Bool:
+ case TQVariant::Double:
+ break;
+ }
+
+ typ = TQVariant::Invalid;
+ is_null = TRUE;
+}
+
+/*!
+ \class TQVariant tqvariant.h
+ \brief The TQVariant class acts like a union for the most common TQt data types.
+
+ \ingroup objectmodel
+ \ingroup misc
+ \mainclass
+
+ Because C++ forbids unions from including types that have
+ non-default constructors or destructors, most interesting TQt
+ classes cannot be used in unions. Without TQVariant, this would be
+ a problem for TQObject::property() and for database work, etc.
+
+ A TQVariant object holds a single value of a single type() at a
+ time. (Some type()s are multi-valued, for example a string list.)
+ You can tqfind out what type, T, the variant holds, convert it to a
+ different type using one of the asT() functions, e.g. asSize(),
+ get its value using one of the toT() functions, e.g. toSize(), and
+ check whether the type can be converted to a particular type using
+ canCast().
+
+ The methods named toT() (for any supported T, see the \c Type
+ documentation for a list) are const. If you ask for the stored
+ type, they return a copy of the stored object. If you ask for a
+ type that can be generated from the stored type, toT() copies and
+ converts and leaves the object itself unchanged. If you ask for a
+ type that cannot be generated from the stored type, the result
+ depends on the type (see the function documentation for details).
+
+ Note that three data types supported by TQVariant are explicitly
+ shared, namely TQImage, TQPointArray, and TQCString, and in these
+ cases the toT() methods return a shallow copy. In almost all cases
+ you must make a deep copy of the returned values before modifying
+ them.
+
+ The asT() functions are not const. They do conversion like the
+ toT() methods, set the variant to hold the converted value, and
+ return a reference to the new contents of the variant.
+
+ Here is some example code to demonstrate the use of TQVariant:
+
+ \code
+ TQDataStream out(...);
+ TQVariant v(123); // The variant now tqcontains an int
+ int x = v.toInt(); // x = 123
+ out << v; // Writes a type tag and an int to out
+ v = TQVariant("hello"); // The variant now tqcontains a TQCString
+ v = TQVariant(tr("hello"));// The variant now tqcontains a TQString
+ int y = v.toInt(); // y = 0 since v cannot be converted to an int
+ TQString s = v.toString(); // s = tr("hello") (see TQObject::tr())
+ out << v; // Writes a type tag and a TQString to out
+ ...
+ TQDataStream in(...); // (opening the previously written stream)
+ in >> v; // Reads an Int variant
+ int z = v.toInt(); // z = 123
+ qDebug("Type is %s", // prints "Type is int"
+ v.typeName());
+ v.asInt() += 100; // The variant now hold the value 223.
+ v = TQVariant( TQStringList() );
+ v.asStringList().append( "Hello" );
+ \endcode
+
+ You can even store TQValueList<TQVariant>s and
+ TQMap<TQString,TQVariant>s in a variant, so you can easily construct
+ arbitrarily complex data structures of arbitrary types. This is
+ very powerful and versatile, but may prove less memory and speed
+ efficient than storing specific types in standard data structures.
+
+ TQVariant also supports the notion of NULL values, where you have a
+ defined type with no value set.
+ \code
+ TQVariant x, y( TQString() ), z( TQString("") );
+ x.asInt();
+ // x.isNull() == TRUE, y.isNull() == TRUE, z.isNull() == FALSE
+ \endcode
+
+ See the \link collection.html Collection Classes\endlink.
+*/
+
+/*!
+ \enum TQVariant::Type
+
+ This enum type defines the types of variable that a TQVariant can
+ contain.
+
+ \value Invalid no type
+ \value BitArray a TQBitArray
+ \value ByteArray a TQByteArray
+ \value Bitmap a TQBitmap
+ \value Bool a bool
+ \value Brush a TQBrush
+ \value Color a TQColor
+ \value ColorGroup a TQColorGroup
+ \value Cursor a TQCursor
+ \value Date a TQDate
+ \value DateTime a TQDateTime
+ \value Double a double
+ \value Font a TQFont
+ \value IconSet a TQIconSet
+ \value Image a TQImage
+ \value Int an int
+ \value KeySequence a TQKeySequence
+ \value List a TQValueList<TQVariant>
+ \value LongLong a long long
+ \value ULongLong an unsigned long long
+ \value Map a TQMap<TQString,TQVariant>
+ \value Palette a TQPalette
+ \value Pen a TQPen
+ \value Pixmap a TQPixmap
+ \value Point a TQPoint
+ \value PointArray a TQPointArray
+ \value Rect a TQRect
+ \value Region a TQRegion
+ \value Size a TQSize
+ \value SizePolicy a TQSizePolicy
+ \value String a TQString
+ \value CString a TQCString
+ \value StringList a TQStringList
+ \value Time a TQTime
+ \value UInt an unsigned int
+
+ Note that TQt's definition of bool depends on the compiler.
+ \c tqglobal.h has the system-dependent definition of bool.
+*/
+
+/*!
+ Constructs an invalid variant.
+*/
+TQVariant::TQVariant()
+{
+ d = new Private;
+}
+
+/*!
+ Destroys the TQVariant and the contained object.
+
+ Note that subclasses that reimplement clear() should reimplement
+ the destructor to call clear(). This destructor calls clear(), but
+ because it is the destructor, TQVariant::clear() is called rather
+ than a subclass's clear().
+*/
+TQVariant::~TQVariant()
+{
+ if ( d->deref() )
+ delete d;
+}
+
+/*!
+ Constructs a copy of the variant, \a p, passed as the argument to
+ this constructor. Usually this is a deep copy, but a shallow copy
+ is made if the stored data type is explicitly shared, as e.g.
+ TQImage is.
+*/
+TQVariant::TQVariant( const TQVariant& p )
+{
+ p.d->ref();
+ d = p.d;
+}
+
+#ifndef TQT_NO_DATASTREAM
+/*!
+ Reads the variant from the data stream, \a s.
+*/
+TQVariant::TQVariant( TQDataStream& s )
+{
+ d = new Private;
+ s >> *this;
+}
+#endif //TQT_NO_DATASTREAM
+
+/*!
+ Constructs a new variant with a string value, \a val.
+*/
+TQVariant::TQVariant( const TQString& val )
+{
+ d = new Private;
+ d->typ = String;
+ d->value.ptr = new TQString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value, \a val.
+
+ If you want to modify the TQCString after you've passed it to this
+ constructor, we recommend passing a deep copy (see
+ TQCString::copy()).
+*/
+TQVariant::TQVariant( const TQCString& val )
+{
+ d = new Private;
+ d->typ = CString;
+ d->value.ptr = new TQCString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value of \a val if \a val
+ is non-null. The variant creates a deep copy of \a val.
+
+ If \a val is null, the resulting variant has type Invalid.
+*/
+TQVariant::TQVariant( const char* val )
+{
+ d = new Private;
+ if ( val == 0 )
+ return;
+ d->typ = CString;
+ d->value.ptr = new TQCString( val );
+}
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Constructs a new variant with a string list value, \a val.
+*/
+TQVariant::TQVariant( const TQStringList& val )
+{
+ d = new Private;
+ d->typ = StringList;
+ d->value.ptr = new TQStringList( val );
+ d->is_null = FALSE;
+}
+#endif // TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a map of TQVariants, \a val.
+*/
+TQVariant::TQVariant( const TQMap<TQString,TQVariant>& val )
+{
+ d = new Private;
+ d->typ = Map;
+ d->value.ptr = new TQMap<TQString,TQVariant>( val );
+ d->is_null = FALSE;
+}
+#endif
+/*!
+ Constructs a new variant with a font value, \a val.
+*/
+TQVariant::TQVariant( const TQFont& val )
+{
+ d = new Private;
+ d->typ = Font;
+ d->value.ptr = new TQFont( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a pixmap value, \a val.
+*/
+TQVariant::TQVariant( const TQPixmap& val )
+{
+ d = new Private;
+ d->typ = Pixmap;
+ d->value.ptr = new TQPixmap( val );
+}
+
+
+/*!
+ Constructs a new variant with an image value, \a val.
+
+ Because TQImage is explicitly shared, you may need to pass a deep
+ copy to the variant using TQImage::copy(), e.g. if you intend
+ changing the image you've passed later on.
+*/
+TQVariant::TQVariant( const TQImage& val )
+{
+ d = new Private;
+ d->typ = Image;
+ d->value.ptr = new TQImage( val );
+}
+
+/*!
+ Constructs a new variant with a brush value, \a val.
+*/
+TQVariant::TQVariant( const TQBrush& val )
+{
+ d = new Private;
+ d->typ = Brush;
+ d->value.ptr = new TQBrush( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point value, \a val.
+*/
+TQVariant::TQVariant( const TQPoint& val )
+{
+ d = new Private;
+ d->typ = Point;
+ d->value.ptr = new TQPoint( val );
+}
+
+/*!
+ Constructs a new variant with a rect value, \a val.
+*/
+TQVariant::TQVariant( const TQRect& val )
+{
+ d = new Private;
+ d->typ = Rect;
+ d->value.ptr = new TQRect( val );
+}
+
+/*!
+ Constructs a new variant with a size value, \a val.
+*/
+TQVariant::TQVariant( const TQSize& val )
+{
+ d = new Private;
+ d->typ = Size;
+ d->value.ptr = new TQSize( val );
+}
+
+/*!
+ Constructs a new variant with a color value, \a val.
+*/
+TQVariant::TQVariant( const TQColor& val )
+{
+ d = new Private;
+ d->typ = Color;
+ d->value.ptr = new TQColor( val );
+ d->is_null = FALSE;
+}
+
+#ifndef TQT_NO_PALETTE
+/*!
+ Constructs a new variant with a color palette value, \a val.
+*/
+TQVariant::TQVariant( const TQPalette& val )
+{
+ d = new Private;
+ d->typ = Palette;
+ d->value.ptr = new TQPalette( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a color group value, \a val.
+*/
+TQVariant::TQVariant( const TQColorGroup& val )
+{
+ d = new Private;
+ d->typ = ColorGroup;
+ d->value.ptr = new TQColorGroup( val );
+ d->is_null = FALSE;
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Constructs a new variant with an icon set value, \a val.
+*/
+TQVariant::TQVariant( const TQIconSet& val )
+{
+ d = new Private;
+ d->typ = IconSet;
+ d->value.ptr = new TQIconSet( val );
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Constructs a new variant with a region value, \a val.
+*/
+TQVariant::TQVariant( const TQRegion& val )
+{
+ d = new Private;
+ d->typ = Region;
+ // ## Force a detach
+ d->value.ptr = new TQRegion( val );
+ ((TQRegion*)d->value.ptr)->translate( 0, 0 );
+}
+
+/*!
+ Constructs a new variant with a bitmap value, \a val.
+*/
+TQVariant::TQVariant( const TQBitmap& val )
+{
+ d = new Private;
+ d->typ = Bitmap;
+ d->value.ptr = new TQBitmap( val );
+}
+
+/*!
+ Constructs a new variant with a cursor value, \a val.
+*/
+TQVariant::TQVariant( const TQCursor& val )
+{
+ d = new Private;
+ d->typ = Cursor;
+ d->value.ptr = new TQCursor( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point array value, \a val.
+
+ Because TQPointArray is explicitly shared, you may need to pass a
+ deep copy to the variant using TQPointArray::copy(), e.g. if you
+ intend changing the point array you've passed later on.
+*/
+TQVariant::TQVariant( const TQPointArray& val )
+{
+ d = new Private;
+ d->typ = PointArray;
+ d->value.ptr = new TQPointArray( val );
+}
+
+/*!
+ Constructs a new variant with a date value, \a val.
+*/
+TQVariant::TQVariant( const TQDate& val )
+{
+ d = new Private;
+ d->typ = Date;
+ d->value.ptr = new TQDate( val );
+}
+
+/*!
+ Constructs a new variant with a time value, \a val.
+*/
+TQVariant::TQVariant( const TQTime& val )
+{
+ d = new Private;
+ d->typ = Time;
+ d->value.ptr = new TQTime( val );
+}
+
+/*!
+ Constructs a new variant with a date/time value, \a val.
+*/
+TQVariant::TQVariant( const TQDateTime& val )
+{
+ d = new Private;
+ d->typ = DateTime;
+ d->value.ptr = new TQDateTime( val );
+}
+
+/*!
+ Constructs a new variant with a bytearray value, \a val.
+*/
+TQVariant::TQVariant( const TQByteArray& val )
+{
+ d = new Private;
+ d->typ = ByteArray;
+ d->value.ptr = new TQByteArray( val );
+}
+
+/*!
+ Constructs a new variant with a bitarray value, \a val.
+*/
+TQVariant::TQVariant( const TQBitArray& val )
+{
+ d = new Private;
+ d->typ = BitArray;
+ d->value.ptr = new TQBitArray( val );
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Constructs a new variant with a key sequence value, \a val.
+*/
+TQVariant::TQVariant( const TQKeySequence& val )
+{
+ d = new Private;
+ d->typ = KeySequence;
+ d->value.ptr = new TQKeySequence( val );
+ d->is_null = FALSE;
+}
+
+#endif
+
+/*!
+ Constructs a new variant with a pen value, \a val.
+*/
+TQVariant::TQVariant( const TQPen& val )
+{
+ d = new Private;
+ d->typ = Pen;
+ d->value.ptr = new TQPen( val );
+}
+
+/*!
+ Constructs a new variant with an integer value, \a val.
+*/
+TQVariant::TQVariant( int val )
+{
+ d = new Private;
+ d->typ = Int;
+ d->value.i = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned integer value, \a val.
+*/
+TQVariant::TQVariant( uint val )
+{
+ d = new Private;
+ d->typ = UInt;
+ d->value.u = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a long long integer value, \a val.
+*/
+TQVariant::TQVariant( TQ_LLONG val )
+{
+ d = new Private;
+ d->typ = LongLong;
+ d->value.ll = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned long long integer value, \a val.
+*/
+
+TQVariant::TQVariant( TQ_ULLONG val )
+{
+ d = new Private;
+ d->typ = ULongLong;
+ d->value.ull = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a boolean value, \a val. The integer
+ argument is a dummy, necessary for compatibility with some
+ compilers.
+*/
+TQVariant::TQVariant( bool val, int )
+{ // this is the comment that does NOT name said compiler.
+ d = new Private;
+ d->typ = Bool;
+ d->value.b = val;
+ d->is_null = FALSE;
+}
+
+
+/*!
+ Constructs a new variant with a floating point value, \a val.
+*/
+TQVariant::TQVariant( double val )
+{
+ d = new Private;
+ d->typ = Double;
+ d->value.d = val;
+ d->is_null = FALSE;
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a list value, \a val.
+*/
+TQVariant::TQVariant( const TQValueList<TQVariant>& val )
+{
+ d = new Private;
+ d->typ = List;
+ d->value.ptr = new TQValueList<TQVariant>( val );
+ d->is_null = FALSE;
+}
+#endif
+
+/*!
+ Constructs a new variant with a size policy value, \a val.
+*/
+TQVariant::TQVariant( TQSizePolicy val )
+{
+ d = new Private;
+ d->typ = SizePolicy;
+ d->value.ptr = new TQSizePolicy( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Assigns the value of the variant \a variant to this variant.
+
+ This is a deep copy of the variant, but note that if the variant
+ holds an explicitly shared type such as TQImage, a shallow copy is
+ performed.
+*/
+TQVariant& TQVariant::operator= ( const TQVariant& variant )
+{
+ TQVariant& other = (TQVariant&)variant;
+
+ other.d->ref();
+ if ( d->deref() )
+ delete d;
+
+ d = other.d;
+
+ return *this;
+}
+
+/*!
+ \internal
+*/
+void TQVariant::detach()
+{
+ if ( d->count == 1 )
+ return;
+
+ d->deref();
+ d = new Private( d );
+}
+
+/*!
+ Returns the name of the type stored in the variant. The returned
+ strings describe the C++ datatype used to store the data: for
+ example, "TQFont", "TQString", or "TQValueList<TQVariant>". An Invalid
+ variant returns 0.
+*/
+const char* TQVariant::typeName() const
+{
+ return typeToName( (Type) d->typ );
+}
+
+/*!
+ Convert this variant to type Invalid and free up any resources
+ used.
+*/
+void TQVariant::clear()
+{
+ if ( d->count > 1 )
+ {
+ d->deref();
+ d = new Private;
+ return;
+ }
+
+ d->clear();
+}
+
+/* Attention!
+
+ For dependency reasons, this table is duplicated in tqmoc.y. If you
+ change one, change both.
+
+ (Search for the word 'Attention' in tqmoc.y.)
+*/
+static const int ntypes = 35;
+static const char* const type_map[ntypes] =
+{
+ 0,
+ "TQMap<TQString,TQVariant>",
+ "TQValueList<TQVariant>",
+ "TQString",
+ "TQStringList",
+ "TQFont",
+ "TQPixmap",
+ "TQBrush",
+ "TQRect",
+ "TQSize",
+ "TQColor",
+ "TQPalette",
+ "TQColorGroup",
+ "TQIconSet",
+ "TQPoint",
+ "TQImage",
+ "int",
+ "uint",
+ "bool",
+ "double",
+ "TQCString",
+ "TQPointArray",
+ "TQRegion",
+ "TQBitmap",
+ "TQCursor",
+ "TQSizePolicy",
+ "TQDate",
+ "TQTime",
+ "TQDateTime",
+ "TQByteArray",
+ "TQBitArray",
+ "TQKeySequence",
+ "TQPen",
+ "TQ_LLONG",
+ "TQ_ULLONG"
+};
+
+
+/*!
+ Converts the enum representation of the storage type, \a typ, to
+ its string representation.
+*/
+const char* TQVariant::typeToName( Type typ )
+{
+ if ( typ >= ntypes )
+ return 0;
+ return type_map[typ];
+}
+
+
+/*!
+ Converts the string representation of the storage type given in \a
+ name, to its enum representation.
+
+ If the string representation cannot be converted to any enum
+ representation, the variant is set to \c Invalid.
+*/
+TQVariant::Type TQVariant::nameToType( const char* name )
+{
+ for ( int i = 0; i < ntypes; i++ ) {
+ if ( !qstrcmp( type_map[i], name ) )
+ return (Type) i;
+ }
+ return Invalid;
+}
+
+#ifndef TQT_NO_DATASTREAM
+/*!
+ Internal function for loading a variant from stream \a s. Use the
+ stream operators instead.
+
+ \internal
+*/
+void TQVariant::load( TQDataStream& s )
+{
+ clear();
+ TQ_UINT32 u;
+ s >> u;
+ Type t = (Type)u;
+
+ switch( t ) {
+ case Invalid:
+ {
+ // Since we wrote something, we should read something
+ TQString x;
+ s >> x;
+ d->typ = t;
+ d->is_null = TRUE;
+ }
+ break;
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case Map:
+ {
+ TQMap<TQString,TQVariant>* x = new TQMap<TQString,TQVariant>;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case List:
+ {
+ TQValueList<TQVariant>* x = new TQValueList<TQVariant>;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif
+ case Cursor:
+ {
+#ifndef TQT_NO_CURSOR
+ TQCursor* x = new TQCursor;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+#endif
+ }
+ break;
+ case Bitmap:
+ {
+ TQBitmap* x = new TQBitmap;
+#ifndef TQT_NO_IMAGEIO
+ s >> *x;
+#endif
+ d->value.ptr = x;
+ }
+ break;
+ case Region:
+ {
+ TQRegion* x = new TQRegion;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case PointArray:
+ {
+ TQPointArray* x = new TQPointArray;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case String:
+ {
+ TQString* x = new TQString;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case CString:
+ {
+ TQCString* x = new TQCString;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case StringList:
+ {
+ TQStringList* x = new TQStringList;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif // TQT_NO_STRINGLIST
+ case Font:
+ {
+ TQFont* x = new TQFont;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case Pixmap:
+ {
+ TQPixmap* x = new TQPixmap;
+#ifndef TQT_NO_IMAGEIO
+ s >> *x;
+#endif
+ d->value.ptr = x;
+ }
+ break;
+ case Image:
+ {
+ TQImage* x = new TQImage;
+#ifndef TQT_NO_IMAGEIO
+ s >> *x;
+#endif
+ d->value.ptr = x;
+ }
+ break;
+ case Brush:
+ {
+ TQBrush* x = new TQBrush;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case Rect:
+ {
+ TQRect* x = new TQRect;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Point:
+ {
+ TQPoint* x = new TQPoint;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Size:
+ {
+ TQSize* x = new TQSize;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Color:
+ {
+ TQColor* x = new TQColor;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#ifndef TQT_NO_PALETTE
+ case Palette:
+ {
+ TQPalette* x = new TQPalette;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case ColorGroup:
+ {
+ TQColorGroup* x = new TQColorGroup;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case IconSet:
+ {
+ TQPixmap x;
+ s >> x;
+ d->value.ptr = new TQIconSet( x );
+ }
+ break;
+#endif
+ case Int:
+ {
+ int x;
+ s >> x;
+ d->value.i = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case UInt:
+ {
+ uint x;
+ s >> x;
+ d->value.u = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case LongLong:
+ {
+ TQ_LLONG x;
+ s >> x;
+ d->value.ll = x;
+ }
+ break;
+ case ULongLong:
+ {
+ TQ_ULLONG x;
+ s >> x;
+ d->value.ull = x;
+ }
+ break;
+ case Bool:
+ {
+ TQ_INT8 x;
+ s >> x;
+ d->value.b = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case Double:
+ {
+ double x;
+ s >> x;
+ d->value.d = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case SizePolicy:
+ {
+ int h,v;
+ TQ_INT8 hfw;
+ s >> h >> v >> hfw;
+ d->value.ptr = new TQSizePolicy( (TQSizePolicy::SizeType)h,
+ (TQSizePolicy::SizeType)v,
+ (bool) hfw);
+ d->is_null = FALSE;
+ }
+ break;
+ case Date:
+ {
+ TQDate* x = new TQDate;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Time:
+ {
+ TQTime* x = new TQTime;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case DateTime:
+ {
+ TQDateTime* x = new TQDateTime;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case ByteArray:
+ {
+ TQByteArray* x = new TQByteArray;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case BitArray:
+ {
+ TQBitArray* x = new TQBitArray;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ {
+ TQKeySequence* x = new TQKeySequence;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif // TQT_NO_ACCEL
+ case Pen:
+ {
+ TQPen* x = new TQPen;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ }
+ d->typ = t;
+}
+
+/*!
+ Internal function for saving a variant to the stream \a s. Use the
+ stream operators instead.
+
+ \internal
+*/
+void TQVariant::save( TQDataStream& s ) const
+{
+ s << (TQ_UINT32)type();
+
+ switch( d->typ ) {
+ case Cursor:
+ s << *((TQCursor*)d->value.ptr);
+ break;
+ case Bitmap:
+#ifndef TQT_NO_IMAGEIO
+ s << *((TQBitmap*)d->value.ptr);
+#endif
+ break;
+ case PointArray:
+ s << *((TQPointArray*)d->value.ptr);
+ break;
+ case Region:
+ s << *((TQRegion*)d->value.ptr);
+ break;
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ s << *((TQValueList<TQVariant>*)d->value.ptr);
+ break;
+ case Map:
+ s << *((TQMap<TQString,TQVariant>*)d->value.ptr);
+ break;
+#endif
+ case String:
+ s << *((TQString*)d->value.ptr);
+ break;
+ case CString:
+ s << *((TQCString*)d->value.ptr);
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case StringList:
+ s << *((TQStringList*)d->value.ptr);
+ break;
+#endif
+ case Font:
+ s << *((TQFont*)d->value.ptr);
+ break;
+ case Pixmap:
+#ifndef TQT_NO_IMAGEIO
+ s << *((TQPixmap*)d->value.ptr);
+#endif
+ break;
+ case Image:
+#ifndef TQT_NO_IMAGEIO
+ s << *((TQImage*)d->value.ptr);
+#endif
+ break;
+ case Brush:
+ s << *((TQBrush*)d->value.ptr);
+ break;
+ case Point:
+ s << *((TQPoint*)d->value.ptr);
+ break;
+ case Rect:
+ s << *((TQRect*)d->value.ptr);
+ break;
+ case Size:
+ s << *((TQSize*)d->value.ptr);
+ break;
+ case Color:
+ s << *((TQColor*)d->value.ptr);
+ break;
+#ifndef TQT_NO_PALETTE
+ case Palette:
+ s << *((TQPalette*)d->value.ptr);
+ break;
+ case ColorGroup:
+ s << *((TQColorGroup*)d->value.ptr);
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case IconSet:
+ //### add stream operator to iconset
+ s << ((TQIconSet*)d->value.ptr)->pixmap();
+ break;
+#endif
+ case Int:
+ s << d->value.i;
+ break;
+ case UInt:
+ s << d->value.u;
+ break;
+ case LongLong:
+ s << d->value.ll;
+ break;
+ case ULongLong:
+ s << d->value.ull;
+ break;
+ case Bool:
+ s << (TQ_INT8)d->value.b;
+ break;
+ case Double:
+ s << d->value.d;
+ break;
+ case SizePolicy:
+ {
+ TQSizePolicy p = toSizePolicy();
+ s << (int) p.horData() << (int) p.verData()
+ << (TQ_INT8) p.hasHeightForWidth();
+ }
+ break;
+ case Date:
+ s << *((TQDate*)d->value.ptr);
+ break;
+ case Time:
+ s << *((TQTime*)d->value.ptr);
+ break;
+ case DateTime:
+ s << *((TQDateTime*)d->value.ptr);
+ break;
+ case ByteArray:
+ s << *((TQByteArray*)d->value.ptr);
+ break;
+ case BitArray:
+ s << *((TQBitArray*)d->value.ptr);
+ break;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ s << *((TQKeySequence*)d->value.ptr);
+ break;
+#endif
+ case Pen:
+ s << *((TQPen*)d->value.ptr);
+ break;
+ case Invalid:
+ s << TQString(); // ### looks wrong.
+ break;
+ }
+}
+
+/*!
+ Reads a variant \a p from the stream \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream
+ operators \endlink
+*/
+TQDataStream& operator>> ( TQDataStream& s, TQVariant& p )
+{
+ p.load( s );
+ return s;
+}
+
+/*!
+ Writes a variant \a p to the stream \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream
+ operators \endlink
+*/
+TQDataStream& operator<< ( TQDataStream& s, const TQVariant& p )
+{
+ p.save( s );
+ return s;
+}
+
+/*!
+ Reads a variant type \a p in enum representation from the stream \a s.
+*/
+TQDataStream& operator>> ( TQDataStream& s, TQVariant::Type& p )
+{
+ TQ_UINT32 u;
+ s >> u;
+ p = (TQVariant::Type) u;
+
+ return s;
+}
+
+/*!
+ Writes a variant type \a p to the stream \a s.
+*/
+TQDataStream& operator<< ( TQDataStream& s, const TQVariant::Type p )
+{
+ s << (TQ_UINT32)p;
+
+ return s;
+}
+
+#endif //TQT_NO_DATASTREAM
+
+/*!
+ \fn Type TQVariant::type() const
+
+ Returns the storage type of the value stored in the variant.
+ Usually it's best to test with canCast() whether the variant can
+ deliver the data type you are interested in.
+*/
+
+/*!
+ \fn bool TQVariant::isValid() const
+
+ Returns TRUE if the storage type of this variant is not
+ TQVariant::Invalid; otherwise returns FALSE.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQString> TQVariant::stringListBegin() const
+ \obsolete
+
+ Returns an iterator to the first string in the list if the
+ variant's type is StringList; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQString> TQVariant::stringListEnd() const
+ \obsolete
+
+ Returns the end iterator for the list if the variant's type is
+ StringList; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQVariant> TQVariant::listBegin() const
+ \obsolete
+
+ Returns an iterator to the first item in the list if the variant's
+ type is appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQVariant> TQVariant::listEnd() const
+ \obsolete
+
+ Returns the end iterator for the list if the variant's type is
+ appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQMapConstIterator<TQString, TQVariant> TQVariant::mapBegin() const
+ \obsolete
+
+ Returns an iterator to the first item in the map, if the variant's
+ type is appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQMapConstIterator<TQString, TQVariant> TQVariant::mapEnd() const
+ \obsolete
+
+ Returns the end iterator for the map, if the variant's type is
+ appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQMapConstIterator<TQString, TQVariant> TQVariant::mapFind( const TQString& key ) const
+ \obsolete
+
+ Returns an iterator to the item in the map with \a key as key, if
+ the variant's type is appropriate and \a key is a valid key;
+ otherwise returns a null iterator.
+*/
+
+/*!
+ Returns the variant as a TQString if the variant can be cast to
+ String, otherwise returns TQString::null.
+
+ \sa asString(), canCast()
+*/
+const TQString TQVariant::toString() const
+{
+ switch( d->typ ) {
+ case CString:
+ return TQString::tqfromLatin1( toCString() );
+ case Int:
+ return TQString::number( toInt() );
+ case UInt:
+ return TQString::number( toUInt() );
+ case LongLong:
+ return TQString::number( toLongLong() );
+ case ULongLong:
+ return TQString::number( toULongLong() );
+ case Double:
+ return TQString::number( toDouble(), 'g', DBL_DIG );
+#if !defined(TQT_NO_SPRINTF) && !defined(TQT_NO_DATESTRING)
+ case Date:
+ return toDate().toString( TQt::ISODate );
+ case Time:
+ return toTime().toString( TQt::ISODate );
+ case DateTime:
+ return toDateTime().toString( TQt::ISODate );
+#endif
+ case Bool:
+ return toInt() ? "true" : "false";
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return (TQString) *( (TQKeySequence*)d->value.ptr );
+#endif
+ case ByteArray:
+ return TQString( *((TQByteArray*)d->value.ptr) );
+ case Font:
+ return toFont().toString();
+ case Color:
+ return toColor().name();
+ case String:
+ return *((TQString*)d->value.ptr);
+ default:
+ return TQString::null;
+ }
+}
+/*!
+ Returns the variant as a TQCString if the variant can be cast to a
+ CString; otherwise returns 0.
+
+ \sa asCString(), canCast()
+*/
+const TQCString TQVariant::toCString() const
+{
+ switch( d->typ ) {
+ case CString: return *((TQCString*)d->value.ptr);
+ case String: return ((TQString*)d->value.ptr)->latin1();
+ default: {
+ if (!canCast(String))
+ return 0;
+ TQString c = toString();
+ return TQCString(c.latin1());
+ }
+ }
+}
+
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Returns the variant as a TQStringList if the variant has type()
+ StringList or List of a type that can be converted to TQString;
+ otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myVariant.toStringList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asStringList()
+*/
+const TQStringList TQVariant::toStringList() const
+{
+ switch ( d->typ ) {
+ case StringList:
+ return *((TQStringList*)d->value.ptr);
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ {
+ TQStringList lst;
+ TQValueList<TQVariant>::ConstIterator it = listBegin();
+ TQValueList<TQVariant>::ConstIterator end = listEnd();
+ while( it != end ) {
+ TQString tmp = (*it).toString();
+ ++it;
+ lst.append( tmp );
+ }
+ return lst;
+ }
+#endif
+ default:
+ return TQStringList();
+ }
+}
+#endif //TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQMap<TQString,TQVariant> if the variant has
+ type() Map; otherwise returns an empty map.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.toMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asMap()
+*/
+const TQMap<TQString, TQVariant> TQVariant::toMap() const
+{
+ if ( d->typ != Map )
+ return TQMap<TQString,TQVariant>();
+
+ return *((TQMap<TQString,TQVariant>*)d->value.ptr);
+}
+#endif
+/*!
+ Returns the variant as a TQFont if the variant can be cast to Font;
+ otherwise returns the application's default font.
+
+ \sa asFont(), canCast()
+*/
+const TQFont TQVariant::toFont() const
+{
+ switch ( d->typ ) {
+ case CString:
+ case ByteArray:
+ case String:
+ {
+ TQFont fnt;
+ fnt.fromString( toString() );
+ return fnt;
+ }
+ case Font:
+ return *((TQFont*)d->value.ptr);
+ default:
+ return TQFont();
+ }
+}
+
+/*!
+ Returns the variant as a TQPixmap if the variant has type() Pixmap;
+ otherwise returns a null pixmap.
+
+ \sa asPixmap()
+*/
+const TQPixmap TQVariant::toPixmap() const
+{
+ if ( d->typ != Pixmap )
+ return TQPixmap();
+
+ return *((TQPixmap*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQImage if the variant has type() Image;
+ otherwise returns a null image.
+
+ \sa asImage()
+*/
+const TQImage TQVariant::toImage() const
+{
+ if ( d->typ != Image )
+ return TQImage();
+
+ return *((TQImage*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQBrush if the variant has type() Brush;
+ otherwise returns a default brush (with all black colors).
+
+ \sa asBrush()
+*/
+const TQBrush TQVariant::toBrush() const
+{
+ if( d->typ != Brush )
+ return TQBrush();
+
+ return *((TQBrush*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQPoint if the variant has type() Point;
+ otherwise returns a point (0, 0).
+
+ \sa asPoint()
+*/
+const TQPoint TQVariant::toPoint() const
+{
+ if ( d->typ != Point )
+ return TQPoint();
+
+ return *((TQPoint*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQRect if the variant has type() Rect;
+ otherwise returns an empty rectangle.
+
+ \sa asRect()
+*/
+const TQRect TQVariant::toRect() const
+{
+ if ( d->typ != Rect )
+ return TQRect();
+
+ return *((TQRect*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQSize if the variant has type() Size;
+ otherwise returns an invalid size.
+
+ \sa asSize()
+*/
+const TQSize TQVariant::toSize() const
+{
+ if ( d->typ != Size )
+ return TQSize();
+
+ return *((TQSize*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQColor if the variant can be cast to Color;
+ otherwise returns an invalid color.
+
+ \sa asColor(), canCast()
+*/
+const TQColor TQVariant::toColor() const
+{
+ switch ( d->typ ) {
+ case ByteArray:
+ case CString:
+ case String:
+ {
+ TQColor col;
+ col.setNamedColor( toString() );
+ return col;
+ }
+ case Color:
+ return *((TQColor*)d->value.ptr);
+ default:
+ return TQColor();
+ }
+}
+#ifndef TQT_NO_PALETTE
+/*!
+ Returns the variant as a TQPalette if the variant has type()
+ Palette; otherwise returns a completely black palette.
+
+ \sa asPalette()
+*/
+const TQPalette TQVariant::toPalette() const
+{
+ if ( d->typ != Palette )
+ return TQPalette();
+
+ return *((TQPalette*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQColorGroup if the variant has type()
+ ColorGroup; otherwise returns a completely black color group.
+
+ \sa asColorGroup()
+*/
+const TQColorGroup TQVariant::toColorGroup() const
+{
+ if ( d->typ != ColorGroup )
+ return TQColorGroup();
+
+ return *((TQColorGroup*)d->value.ptr);
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQIconSet if the variant has type()
+ IconSet; otherwise returns an icon set of null pixmaps.
+
+ \sa asIconSet()
+*/
+const TQIconSet TQVariant::toIconSet() const
+{
+ if ( d->typ != IconSet )
+ return TQIconSet();
+
+ return *((TQIconSet*)d->value.ptr);
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQPointArray if the variant has type()
+ PointArray; otherwise returns an empty TQPointArray.
+
+ \sa asPointArray()
+*/
+const TQPointArray TQVariant::toPointArray() const
+{
+ if ( d->typ != PointArray )
+ return TQPointArray();
+
+ return *((TQPointArray*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQBitmap if the variant has type() Bitmap;
+ otherwise returns a null TQBitmap.
+
+ \sa asBitmap()
+*/
+const TQBitmap TQVariant::toBitmap() const
+{
+ if ( d->typ != Bitmap )
+ return TQBitmap();
+
+ return *((TQBitmap*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQRegion if the variant has type() Region;
+ otherwise returns an empty TQRegion.
+
+ \sa asRegion()
+*/
+const TQRegion TQVariant::toRegion() const
+{
+ if ( d->typ != Region )
+ return TQRegion();
+
+ return *((TQRegion*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQCursor if the variant has type() Cursor;
+ otherwise returns the default arrow cursor.
+
+ \sa asCursor()
+*/
+const TQCursor TQVariant::toCursor() const
+{
+#ifndef TQT_NO_CURSOR
+ if ( d->typ != Cursor )
+ return TQCursor();
+#endif
+
+ return *((TQCursor*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQDate if the variant can be cast to Date;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ date will be returned if the string cannot be parsed as a
+ TQt::ISODate format date.
+
+ \sa asDate(), canCast()
+*/
+const TQDate TQVariant::toDate() const
+{
+ switch ( d->typ ) {
+ case Date:
+ return *((TQDate*)d->value.ptr);
+ case DateTime:
+ return ((TQDateTime*)d->value.ptr)->date();
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQDate::fromString( *((TQString*)d->value.ptr), TQt::ISODate );
+ case CString:
+ case ByteArray:
+ return TQDate::fromString(toString(), TQt::ISODate);
+#endif
+ default:
+ return TQDate();
+ }
+}
+
+/*!
+ Returns the variant as a TQTime if the variant can be cast to Time;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ time will be returned if the string cannot be parsed as a
+ TQt::ISODate format time.
+
+ \sa asTime()
+*/
+const TQTime TQVariant::toTime() const
+{
+ switch ( d->typ ) {
+ case Time:
+ return *((TQTime*)d->value.ptr);
+ case DateTime:
+ return ((TQDateTime*)d->value.ptr)->time();
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQTime::fromString( *((TQString*)d->value.ptr), TQt::ISODate );
+ case CString:
+ case ByteArray:
+ return TQTime::fromString(toString(), TQt::ISODate);
+#endif
+ default:
+ return TQTime();
+ }
+}
+
+/*!
+ Returns the variant as a TQDateTime if the variant can be cast to
+ DateTime; otherwise returns an invalid TQDateTime.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ TQDateTime will be returned if the string cannot be parsed as a
+ TQt::ISODate format date/time.
+
+ \sa asDateTime()
+*/
+const TQDateTime TQVariant::toDateTime() const
+{
+ switch ( d->typ ) {
+ case DateTime:
+ return *((TQDateTime*)d->value.ptr);
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQDateTime::fromString( *((TQString*)d->value.ptr), TQt::ISODate );
+ case CString:
+ case ByteArray:
+ return TQDateTime::fromString(toString(), TQt::ISODate);
+#endif
+ case Date:
+ return TQDateTime( *((TQDate*)d->value.ptr) );
+ default:
+ return TQDateTime();
+ }
+}
+
+/*!
+ Returns the variant as a TQByteArray if the variant can be cast to
+ a ByteArray; otherwise returns an empty bytearray.
+
+ \sa asByteArray(), canCast()
+*/
+const TQByteArray TQVariant::toByteArray() const
+{
+ switch(d->typ) {
+ case ByteArray: return *((TQByteArray*)d->value.ptr);
+ case CString: return *((TQByteArray*)d->value.ptr);
+ default: {
+ TQByteArray ret;
+ if (canCast(String)) {
+ TQString c = toString();
+ ret.duplicate(c.latin1(), c.length());
+ }
+ return ret;
+ }
+ }
+}
+
+/*!
+ Returns the variant as a TQBitArray if the variant has type()
+ BitArray; otherwise returns an empty bitarray.
+
+ \sa asBitArray()
+*/
+const TQBitArray TQVariant::toBitArray() const
+{
+ if ( d->typ == BitArray )
+ return *((TQBitArray*)d->value.ptr);
+ return TQBitArray();
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQKeySequence if the variant can be cast
+ to a KeySequence; otherwise returns an empty key sequence.
+
+ \sa asKeySequence(), canCast()
+*/
+const TQKeySequence TQVariant::toKeySequence() const
+{
+ switch ( d->typ ) {
+ case KeySequence:
+ return *((TQKeySequence*)d->value.ptr);
+ case String:
+ case ByteArray:
+ case CString:
+ return TQKeySequence( toString() );
+ case Int:
+ case UInt:
+ case Double:
+ case ULongLong:
+ case LongLong:
+ return TQKeySequence( toInt() );
+ default:
+ return TQKeySequence();
+ }
+}
+
+#endif // TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQPen if the variant has type()
+ Pen; otherwise returns an empty TQPen.
+
+ \sa asPen()
+*/
+const TQPen TQVariant::toPen() const
+{
+ if ( d->typ != Pen )
+ return TQPen();
+
+ return *((TQPen*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as an int if the variant can be cast to Int;
+ otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asInt(), canCast()
+*/
+int TQVariant::toInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Int );
+
+ switch ( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d->value.ptr)->toInt( ok );
+ case Int:
+ return d->value.i;
+ case UInt:
+ return (int)d->value.u;
+ case LongLong:
+ return (int)d->value.ll;
+ case ULongLong:
+ return (int)d->value.ull;
+ case Double:
+ return (int)d->value.d;
+ case Bool:
+ return (int)d->value.b;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return (int) *( (TQKeySequence*)d->value.ptr );
+#endif
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as an unsigned int if the variant can be cast
+ to UInt; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an unsigned int; otherwise \a *ok is set to FALSE.
+
+ \sa asUInt(), canCast()
+*/
+uint TQVariant::toUInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( UInt );
+
+ switch( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toUInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d->value.ptr)->toUInt( ok );
+ case Int:
+ return (uint)d->value.i;
+ case UInt:
+ return d->value.u;
+ case LongLong:
+ return (uint)d->value.ll;
+ case ULongLong:
+ return (uint)d->value.ull;
+ case Double:
+ return (uint)d->value.d;
+ case Bool:
+ return (uint)d->value.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a long long int if the variant can be cast
+ to LongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asLongLong(), canCast()
+*/
+TQ_LLONG TQVariant::toLongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( LongLong );
+
+ switch ( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toLongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d->value.ptr).toLongLong(ok);
+ case Int:
+ return (TQ_LLONG)d->value.i;
+ case UInt:
+ return (TQ_LLONG)d->value.u;
+ case LongLong:
+ return d->value.ll;
+ case ULongLong:
+ return (TQ_LLONG)d->value.ull;
+ case Double:
+ return (TQ_LLONG)d->value.d;
+ case Bool:
+ return (TQ_LLONG)d->value.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as as an unsigned long long int if the variant
+ can be cast to ULongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asULongLong(), canCast()
+*/
+TQ_ULLONG TQVariant::toULongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( ULongLong );
+
+ switch ( d->typ ) {
+ case Int:
+ return (TQ_ULLONG)d->value.i;
+ case UInt:
+ return (TQ_ULLONG)d->value.u;
+ case LongLong:
+ return (TQ_ULLONG)d->value.ll;
+ case ULongLong:
+ return d->value.ull;
+ case Double:
+ return (TQ_ULLONG)d->value.d;
+ case Bool:
+ return (TQ_ULLONG)d->value.b;
+ case String:
+ return ((TQString*)d->value.ptr)->toULongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d->value.ptr).toULongLong(ok);
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a bool if the variant can be cast to Bool;
+ otherWise returns FALSE.
+
+ Returns TRUE if the variant has a numeric type and its value is
+ non-zero, or if the variant has type String, ByteArray or CString
+ and its lower-case content is not empty, "0" or "false"; otherwise
+ returns FALSE.
+
+ \sa asBool(), canCast()
+*/
+bool TQVariant::toBool() const
+{
+ switch( d->typ ) {
+ case Bool:
+ return d->value.b;
+ case Double:
+ return d->value.d != 0.0;
+ case Int:
+ return d->value.i != 0;
+ case UInt:
+ return d->value.u != 0;
+ case LongLong:
+ return d->value.ll != 0;
+ case ULongLong:
+ return d->value.ull != 0;
+ case String:
+ case CString:
+ case ByteArray:
+ {
+ TQString str = toString().lower();
+ return !(str == "0" || str == "false" || str.isEmpty() );
+ }
+ default:
+ return FALSE;
+ }
+}
+
+/*!
+ Returns the variant as a double if the variant can be cast to
+ Double; otherwise returns 0.0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to a double; otherwise \a *ok is set to FALSE.
+
+ \sa asDouble(), canCast()
+*/
+double TQVariant::toDouble( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Double );
+
+ switch ( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toDouble( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d->value.ptr)->toDouble( ok );
+ case Double:
+ return d->value.d;
+ case Int:
+ return (double)d->value.i;
+ case Bool:
+ return (double)d->value.b;
+ case UInt:
+ return (double)d->value.u;
+ case LongLong:
+ return (double)d->value.ll;
+ case ULongLong:
+#if defined(TQ_CC_MSVC) && !defined(TQ_CC_MSVC_NET)
+ return (double)(TQ_LLONG)d->value.ull;
+#else
+ return (double)d->value.ull;
+#endif
+ default:
+ return 0.0;
+ }
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQValueList<TQVariant> if the variant has
+ type() List or StringList; otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.toList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asList()
+*/
+const TQValueList<TQVariant> TQVariant::toList() const
+{
+ if ( d->typ == List )
+ return *((TQValueList<TQVariant>*)d->value.ptr);
+#ifndef TQT_NO_STRINGLIST
+ if ( d->typ == StringList ) {
+ TQValueList<TQVariant> lst;
+ TQStringList::ConstIterator it = stringListBegin();
+ TQStringList::ConstIterator end = stringListEnd();
+ for( ; it != end; ++it )
+ lst.append( TQVariant( *it ) );
+ return lst;
+ }
+#endif //TQT_NO_STRINGLIST
+ return TQValueList<TQVariant>();
+}
+#endif
+
+/*!
+ Returns the variant as a TQSizePolicy if the variant has type()
+ SizePolicy; otherwise returns an undefined (but legal) size
+ policy.
+*/
+
+TQSizePolicy TQVariant::toSizePolicy() const
+{
+ if ( d->typ == SizePolicy )
+ return *((TQSizePolicy*)d->value.ptr);
+
+ return TQSizePolicy();
+}
+
+
+#define TQ_VARIANT_AS( f ) TQ##f& TQVariant::as##f() \
+{ \
+ bool b = isNull(); \
+ if ( d->typ != f ) \
+ *this = TQVariant( to##f() ); \
+ else \
+ detach(); \
+ d->is_null = b; \
+ return *((TQ##f*)d->value.ptr); \
+}
+
+TQ_VARIANT_AS(String)
+TQ_VARIANT_AS(CString)
+#ifndef TQT_NO_STRINGLIST
+TQ_VARIANT_AS(StringList)
+#endif
+TQ_VARIANT_AS(Font)
+TQ_VARIANT_AS(Pixmap)
+TQ_VARIANT_AS(Image)
+TQ_VARIANT_AS(Brush)
+TQ_VARIANT_AS(Point)
+TQ_VARIANT_AS(Rect)
+TQ_VARIANT_AS(Size)
+TQ_VARIANT_AS(Color)
+#ifndef TQT_NO_PALETTE
+TQ_VARIANT_AS(Palette)
+TQ_VARIANT_AS(ColorGroup)
+#endif
+#ifndef TQT_NO_ICONSET
+TQ_VARIANT_AS(IconSet)
+#endif
+TQ_VARIANT_AS(PointArray)
+TQ_VARIANT_AS(Bitmap)
+TQ_VARIANT_AS(Region)
+TQ_VARIANT_AS(Cursor)
+TQ_VARIANT_AS(SizePolicy)
+TQ_VARIANT_AS(Date)
+TQ_VARIANT_AS(Time)
+TQ_VARIANT_AS(DateTime)
+TQ_VARIANT_AS(ByteArray)
+TQ_VARIANT_AS(BitArray)
+#ifndef TQT_NO_ACCEL
+TQ_VARIANT_AS(KeySequence)
+#endif
+TQ_VARIANT_AS(Pen)
+
+/*!
+ \fn TQString& TQVariant::asString()
+
+ Tries to convert the variant to hold a string value. If that is
+ not possible the variant is set to an empty string.
+
+ Returns a reference to the stored string.
+
+ \sa toString()
+*/
+
+/*!
+ \fn TQCString& TQVariant::asCString()
+
+ Tries to convert the variant to hold a string value. If that is
+ not possible the variant is set to an empty string.
+
+ Returns a reference to the stored string.
+
+ \sa toCString()
+*/
+
+/*!
+ \fn TQStringList& TQVariant::asStringList()
+
+ Tries to convert the variant to hold a TQStringList value. If that
+ is not possible the variant is set to an empty string list.
+
+ Returns a reference to the stored string list.
+
+ Note that if you want to iterate over the list, you should
+ iterate over a copy, e.g.
+ \code
+ TQStringList list = myVariant.asStringList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa toStringList()
+*/
+
+/*!
+ \fn TQFont& TQVariant::asFont()
+
+ Tries to convert the variant to hold a TQFont. If that is not
+ possible the variant is set to the application's default font.
+
+ Returns a reference to the stored font.
+
+ \sa toFont()
+*/
+
+/*!
+ \fn TQPixmap& TQVariant::asPixmap()
+
+ Tries to convert the variant to hold a pixmap value. If that is
+ not possible the variant is set to a null pixmap.
+
+ Returns a reference to the stored pixmap.
+
+ \sa toPixmap()
+*/
+
+/*!
+ \fn TQImage& TQVariant::asImage()
+
+ Tries to convert the variant to hold an image value. If that is
+ not possible the variant is set to a null image.
+
+ Returns a reference to the stored image.
+
+ \sa toImage()
+*/
+
+/*!
+ \fn TQBrush& TQVariant::asBrush()
+
+ Tries to convert the variant to hold a brush value. If that is not
+ possible the variant is set to a default black brush.
+
+ Returns a reference to the stored brush.
+
+ \sa toBrush()
+*/
+
+/*!
+ \fn TQPoint& TQVariant::asPoint()
+
+ Tries to convert the variant to hold a point value. If that is not
+ possible the variant is set to a (0, 0) point.
+
+ Returns a reference to the stored point.
+
+ \sa toPoint()
+*/
+
+/*!
+ \fn TQRect& TQVariant::asRect()
+
+ Tries to convert the variant to hold a rectangle value. If that is
+ not possible the variant is set to an empty rectangle.
+
+ Returns a reference to the stored rectangle.
+
+ \sa toRect()
+*/
+
+/*!
+ \fn TQSize& TQVariant::asSize()
+
+ Tries to convert the variant to hold a TQSize value. If that is not
+ possible the variant is set to an invalid size.
+
+ Returns a reference to the stored size.
+
+ \sa toSize() TQSize::isValid()
+*/
+
+/*!
+ \fn TQSizePolicy& TQVariant::asSizePolicy()
+
+ Tries to convert the variant to hold a TQSizePolicy value. If that
+ fails, the variant is set to an arbitrary (valid) size policy.
+*/
+
+
+/*!
+ \fn TQColor& TQVariant::asColor()
+
+ Tries to convert the variant to hold a TQColor value. If that is
+ not possible the variant is set to an invalid color.
+
+ Returns a reference to the stored color.
+
+ \sa toColor() TQColor::isValid()
+*/
+
+/*!
+ \fn TQPalette& TQVariant::asPalette()
+
+ Tries to convert the variant to hold a TQPalette value. If that is
+ not possible the variant is set to a palette of black colors.
+
+ Returns a reference to the stored palette.
+
+ \sa toString()
+*/
+
+/*!
+ \fn TQColorGroup& TQVariant::asColorGroup()
+
+ Tries to convert the variant to hold a TQColorGroup value. If that
+ is not possible the variant is set to a color group of all black
+ colors.
+
+ Returns a reference to the stored color group.
+
+ \sa toColorGroup()
+*/
+
+/*!
+ \fn TQIconSet& TQVariant::asIconSet()
+
+ Tries to convert the variant to hold a TQIconSet value. If that is
+ not possible the variant is set to an empty iconset.
+
+ Returns a reference to the stored iconset.
+
+ \sa toIconSet()
+*/
+
+/*!
+ \fn TQPointArray& TQVariant::asPointArray()
+
+ Tries to convert the variant to hold a TQPointArray value. If that
+ is not possible the variant is set to an empty point array.
+
+ Returns a reference to the stored point array.
+
+ \sa toPointArray()
+*/
+
+/*!
+ \fn TQBitmap& TQVariant::asBitmap()
+
+ Tries to convert the variant to hold a bitmap value. If that is
+ not possible the variant is set to a null bitmap.
+
+ Returns a reference to the stored bitmap.
+
+ \sa toBitmap()
+*/
+
+/*!
+ \fn TQRegion& TQVariant::asRegion()
+
+ Tries to convert the variant to hold a TQRegion value. If that is
+ not possible the variant is set to a null region.
+
+ Returns a reference to the stored region.
+
+ \sa toRegion()
+*/
+
+/*!
+ \fn TQCursor& TQVariant::asCursor()
+
+ Tries to convert the variant to hold a TQCursor value. If that is
+ not possible the variant is set to a default arrow cursor.
+
+ Returns a reference to the stored cursor.
+
+ \sa toCursor()
+*/
+
+/*!
+ \fn TQDate& TQVariant::asDate()
+
+ Tries to convert the variant to hold a TQDate value. If that is not
+ possible then the variant is set to an invalid date.
+
+ Returns a reference to the stored date.
+
+ \sa toDate()
+*/
+
+/*!
+ \fn TQTime& TQVariant::asTime()
+
+ Tries to convert the variant to hold a TQTime value. If that is not
+ possible then the variant is set to an invalid time.
+
+ Returns a reference to the stored time.
+
+ \sa toTime()
+*/
+
+/*!
+ \fn TQDateTime& TQVariant::asDateTime()
+
+ Tries to convert the variant to hold a TQDateTime value. If that is
+ not possible then the variant is set to an invalid date/time.
+
+ Returns a reference to the stored date/time.
+
+ \sa toDateTime()
+*/
+
+/*!
+ \fn TQByteArray& TQVariant::asByteArray()
+
+ Tries to convert the variant to hold a TQByteArray value. If that
+ is not possible then the variant is set to an empty bytearray.
+
+ Returns a reference to the stored bytearray.
+
+ \sa toByteArray()
+*/
+
+/*!
+ \fn TQBitArray& TQVariant::asBitArray()
+
+ Tries to convert the variant to hold a TQBitArray value. If that is
+ not possible then the variant is set to an empty bitarray.
+
+ Returns a reference to the stored bitarray.
+
+ \sa toBitArray()
+*/
+
+/*!
+ \fn TQKeySequence& TQVariant::asKeySequence()
+
+ Tries to convert the variant to hold a TQKeySequence value. If that
+ is not possible then the variant is set to an empty key sequence.
+
+ Returns a reference to the stored key sequence.
+
+ \sa toKeySequence()
+*/
+
+/*! \fn TQPen& TQVariant::asPen()
+
+ Tries to convert the variant to hold a TQPen value. If that
+ is not possible then the variant is set to an empty pen.
+
+ Returns a reference to the stored pen.
+
+ \sa toPen()
+*/
+
+/*!
+ Returns the variant's value as int reference.
+*/
+int& TQVariant::asInt()
+{
+ detach();
+ if ( d->typ != Int ) {
+ int i = toInt();
+ bool b = isNull();
+ d->clear();
+ d->value.i = i;
+ d->typ = Int;
+ d->is_null = b;
+ }
+ return d->value.i;
+}
+
+/*!
+ Returns the variant's value as unsigned int reference.
+*/
+uint& TQVariant::asUInt()
+{
+ detach();
+ if ( d->typ != UInt ) {
+ uint u = toUInt();
+ bool b = isNull();
+ d->clear();
+ d->value.u = u;
+ d->typ = UInt;
+ d->is_null = b;
+ }
+ return d->value.u;
+}
+
+/*!
+ Returns the variant's value as long long reference.
+*/
+TQ_LLONG& TQVariant::asLongLong()
+{
+ detach();
+ if ( d->typ != LongLong ) {
+ TQ_LLONG ll = toLongLong();
+ bool b = isNull();
+ d->clear();
+ d->value.ll = ll;
+ d->typ = LongLong;
+ d->is_null = b;
+ }
+ return d->value.ll;
+}
+
+/*!
+ Returns the variant's value as unsigned long long reference.
+*/
+TQ_ULLONG& TQVariant::asULongLong()
+{
+ detach();
+ if ( d->typ != ULongLong ) {
+ TQ_ULLONG ull = toULongLong();
+ bool b = isNull();
+ d->clear();
+ d->value.ull = ull;
+ d->typ = ULongLong;
+ d->is_null = b;
+ }
+ return d->value.ull;
+}
+
+/*!
+ Returns the variant's value as bool reference.
+*/
+bool& TQVariant::asBool()
+{
+ detach();
+ if ( d->typ != Bool ) {
+ bool b = toBool();
+ bool nb = isNull();
+ d->clear();
+ d->value.b = b;
+ d->typ = Bool;
+ d->is_null = nb;
+ }
+ return d->value.b;
+}
+
+/*!
+ Returns the variant's value as double reference.
+*/
+double& TQVariant::asDouble()
+{
+ detach();
+ if ( d->typ != Double ) {
+ double dbl = toDouble();
+ bool b = isNull();
+ d->clear();
+ d->value.d = dbl;
+ d->typ = Double;
+ d->is_null = b;
+ }
+ return d->value.d;
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant's value as variant list reference.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.asList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQValueList<TQVariant>& TQVariant::asList()
+{
+ bool b = isNull();
+ if ( d->typ != List )
+ *this = TQVariant( toList() );
+ else
+ detach();
+ d->is_null = b;
+ return *((TQValueList<TQVariant>*)d->value.ptr);
+}
+
+/*!
+ Returns the variant's value as variant map reference.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.asMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQMap<TQString, TQVariant>& TQVariant::asMap()
+{
+ bool b = isNull();
+ if ( d->typ != Map )
+ *this = TQVariant( toMap() );
+ else
+ detach();
+ d->is_null = b;
+ return *((TQMap<TQString,TQVariant>*)d->value.ptr);
+}
+#endif
+
+/*!
+ Returns TRUE if the variant's type can be cast to the requested
+ type, \a t. Such casting is done automatically when calling the
+ toInt(), toBool(), ... or asInt(), asBool(), ... methods.
+
+ The following casts are done automatically:
+ \table
+ \header \i Type \i Automatically Cast To
+ \row \i Bool \i Double, Int, UInt, LongLong, ULongLong, String, CString, ByteArray
+ \row \i Color \i String. CString. ByteArray
+ \row \i Date \i String, CString, ByteArray, DateTime
+ \row \i DateTime \i String, CString, ByteArray, Date, Time
+ \row \i Double \i String, CString, ByteArray, Int, Bool, UInt, LongLong, ULongLong
+ \row \i Font \i String, CString, ByteArray
+ \row \i Int \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i LongLong \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i ULongLong \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i List \i StringList (if the list tqcontains only strings or
+ something that can be cast to a string)
+ \row \i String \i CString, ByteArray, CString, Int, UInt, Bool, Double, Date,
+ Time, DateTime, KeySequence, Font, Color
+ \row \i CString \i String, ByteArray, Int, UInt, Bool, Double, Date, ULongLong, LongLong
+ \row \i ByteArray \i String, CString, Int, UInt, Bool, Double, Date, ULongLong, LongLong
+ \row \i StringList \i List
+ \row \i Time \i String
+ \row \i Int \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i KeySequence \i String, CString, ByteArray, Int, UInt, LongLong, ULongLong
+ \endtable
+*/
+bool TQVariant::canCast( Type t ) const
+{
+ if ( Type( d->typ ) == t )
+ return TRUE;
+
+ switch ( t ) {
+ case Bool:
+ case Double:
+ if (d->typ == KeySequence)
+ break;
+ case Int:
+ case UInt:
+ case LongLong:
+ case ULongLong:
+ switch(d->typ) {
+ case Bool:
+ case ByteArray:
+ case CString:
+ case Double:
+ case Int:
+ case KeySequence:
+ case LongLong:
+ case String:
+ case UInt:
+ case ULongLong:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case CString:
+ case ByteArray:
+ case String:
+ switch(d->typ) {
+ case Bool:
+ case ByteArray:
+ case CString:
+ case Color:
+ case Date:
+ case DateTime:
+ case Double:
+ case Font:
+ case Int:
+ case KeySequence:
+ case LongLong:
+ case String:
+ case Time:
+ case UInt:
+ case ULongLong:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case Time:
+ if (d->typ == Date)
+ break;
+ case Date:
+ case DateTime:
+ switch(d->typ) {
+ case ByteArray:
+ case CString:
+ case Date:
+ case DateTime:
+ case String:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case KeySequence:
+ switch(d->typ) {
+ case ByteArray:
+ case CString:
+ case Int:
+ case UInt:
+ case LongLong:
+ case ULongLong:
+ case Double:
+ case String:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case Font:
+ case Color:
+ switch(d->typ) {
+ case ByteArray:
+ case CString:
+ case String:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+#ifndef TQT_NO_STRINGLIST
+ case List:
+ return d->typ == StringList;
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case StringList:
+ if ( d->typ == List ) {
+ TQValueList<TQVariant>::ConstIterator it = listBegin();
+ TQValueList<TQVariant>::ConstIterator end = listEnd();
+ for( ; it != end; ++it ) {
+ if ( !(*it).canCast( String ) )
+ return FALSE;
+ }
+ return TRUE;
+ }
+#endif
+ case Invalid:
+ case Map:
+ case Pixmap:
+ case Brush:
+ case Rect:
+ case Size:
+ case Palette:
+ case ColorGroup:
+ case IconSet:
+ case Point:
+ case Image:
+ case PointArray:
+ case Region:
+ case Bitmap:
+ case Cursor:
+ case SizePolicy:
+ case BitArray:
+ case Pen:
+ break;
+ }
+ return FALSE;
+}
+
+/*!
+ Casts the variant to the requested type. If the cast cannot be
+ done, the variant is set to the default value of the requested
+ type (e.g. an empty string if the requested type \a t is
+ TQVariant::String, an empty point array if the requested type \a t
+ is TQVariant::PointArray, etc). Returns TRUE if the current type of
+ the variant was successfully cast; otherwise returns FALSE.
+
+ \sa canCast()
+*/
+
+bool TQVariant::cast( Type t )
+{
+ switch ( t ) {
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ asMap();
+ break;
+ case TQVariant::List:
+ asList();
+ break;
+#endif
+ case TQVariant::String:
+ asString();
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+ asStringList();
+ break;
+#endif
+ case TQVariant::Font:
+ asFont();
+ break;
+ case TQVariant::Pixmap:
+ asPixmap();
+ break;
+ case TQVariant::Brush:
+ asBrush();
+ break;
+ case TQVariant::Rect:
+ asRect();
+ break;
+ case TQVariant::Size:
+ asSize();
+ break;
+ case TQVariant::Color:
+ asColor();
+ break;
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ asPalette();
+ break;
+ case TQVariant::ColorGroup:
+ asColorGroup();
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ asIconSet();
+ break;
+#endif
+ case TQVariant::Point:
+ asPoint();
+ break;
+ case TQVariant::Image:
+ asImage();
+ break;
+ case TQVariant::Int:
+ asInt();
+ break;
+ case TQVariant::UInt:
+ asUInt();
+ break;
+ case TQVariant::Bool:
+ asBool();
+ break;
+ case TQVariant::Double:
+ asDouble();
+ break;
+ case TQVariant::CString:
+ asCString();
+ break;
+ case TQVariant::PointArray:
+ asPointArray();
+ break;
+ case TQVariant::Region:
+ asRegion();
+ break;
+ case TQVariant::Bitmap:
+ asBitmap();
+ break;
+ case TQVariant::Cursor:
+ asCursor();
+ break;
+ case TQVariant::SizePolicy:
+ asSizePolicy();
+ break;
+ case TQVariant::Date:
+ asDate();
+ break;
+ case TQVariant::Time:
+ asTime();
+ break;
+ case TQVariant::DateTime:
+ asDateTime();
+ break;
+ case TQVariant::ByteArray:
+ asByteArray();
+ break;
+ case TQVariant::BitArray:
+ asBitArray();
+ break;
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+ asKeySequence();
+ break;
+#endif
+ case TQVariant::Pen:
+ asPen();
+ break;
+ case TQVariant::LongLong:
+ asLongLong();
+ break;
+ case TQVariant::ULongLong:
+ asULongLong();
+ break;
+ default:
+ case TQVariant::Invalid:
+ (*this) = TQVariant();
+ }
+ return canCast( t );
+}
+
+/*!
+ Compares this TQVariant with \a v and returns TRUE if they are
+ equal; otherwise returns FALSE.
+*/
+
+bool TQVariant::operator==( const TQVariant &v ) const
+{
+ if (isNumeric(v.type()) && canCast(v.type())) {
+ bool ok;
+ switch(v.type()) {
+ case Bool:
+ return toBool() == v.toBool();
+ case Int:
+ {
+ int val = toInt(&ok);
+ return (ok && val == v.toInt());
+ }
+ case UInt:
+ {
+ uint val = toUInt(&ok);
+ return (ok && val == v.toUInt());
+ }
+
+ case Double:
+ {
+ double val = toDouble(&ok);
+ return (ok && val == v.toDouble());
+ }
+
+ case LongLong:
+ {
+ TQ_LLONG val = toLongLong(&ok);
+ return (ok && val == v.toLongLong());
+ }
+
+ case ULongLong:
+ {
+ TQ_ULLONG val = toULongLong(&ok);
+ return (ok && val == v.toULongLong());
+ }
+
+ default:
+ TQ_ASSERT(FALSE);
+ }
+ }
+
+ if (!v.canCast(d->typ)) {
+ return FALSE;
+ }
+
+ switch( d->typ ) {
+ case Cursor:
+#ifndef TQT_NO_CURSOR
+ return v.toCursor().tqshape() == toCursor().tqshape();
+#endif
+ case Bitmap:
+ return v.toBitmap().serialNumber() == toBitmap().serialNumber();
+ case PointArray:
+ return v.toPointArray() == toPointArray();
+ case Region:
+ return v.toRegion() == toRegion();
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ return v.toList() == toList();
+ case Map: {
+ if ( v.toMap().count() != toMap().count() )
+ return FALSE;
+ TQMap<TQString, TQVariant>::ConstIterator it = v.toMap().begin();
+ TQMap<TQString, TQVariant>::ConstIterator it2 = toMap().begin();
+ while ( it != v.toMap().end() ) {
+ if ( *it != *it2 )
+ return FALSE;
+ ++it;
+ ++it2;
+ }
+ return TRUE;
+ }
+#endif
+ case String:
+ return v.toString() == toString();
+ case CString:
+ return v.toCString() == toCString();
+#ifndef TQT_NO_STRINGLIST
+ case StringList:
+ return v.toStringList() == toStringList();
+#endif
+ case Font:
+ return v.toFont() == toFont();
+ case Pixmap:
+ return v.toPixmap().serialNumber() == toPixmap().serialNumber();
+ case Image:
+ return v.toImage() == toImage();
+ case Brush:
+ return v.toBrush() == toBrush();
+ case Point:
+ return v.toPoint() == toPoint();
+ case Rect:
+ return v.toRect() == toRect();
+ case Size:
+ return v.toSize() == toSize();
+ case Color:
+ return v.toColor() == toColor();
+#ifndef TQT_NO_PALETTE
+ case Palette:
+ return v.toPalette() == toPalette();
+ case ColorGroup:
+ return v.toColorGroup() == toColorGroup();
+#endif
+#ifndef TQT_NO_ICONSET
+ case IconSet:
+ return v.toIconSet().pixmap().serialNumber()
+ == toIconSet().pixmap().serialNumber();
+#endif
+ case Int:
+ return v.toInt() == toInt();
+ case UInt:
+ return v.toUInt() == toUInt();
+ case LongLong:
+ return v.toLongLong() == toLongLong();
+ case ULongLong:
+ return v.toULongLong() == toULongLong();
+ case Bool:
+ return v.toBool() == toBool();
+ case Double:
+ return v.toDouble() == toDouble();
+ case SizePolicy:
+ return v.toSizePolicy() == toSizePolicy();
+ case Date:
+ return v.toDate() == toDate();
+ case Time:
+ return v.toTime() == toTime();
+ case DateTime:
+ return v.toDateTime() == toDateTime();
+ case ByteArray:
+ return v.toByteArray() == toByteArray();
+ case BitArray:
+ return v.toBitArray() == toBitArray();
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return v.toKeySequence() == toKeySequence();
+#endif
+ case Pen:
+ return v.toPen() == toPen();
+ case Invalid:
+ break;
+ }
+ return FALSE;
+}
+
+/*!
+ Compares this TQVariant with \a v and returns TRUE if they are not
+ equal; otherwise returns FALSE.
+*/
+
+bool TQVariant::operator!=( const TQVariant &v ) const
+{
+ return !( v == *this );
+}
+
+
+/*! \internal
+
+ Reads or sets the variant type and ptr
+ */
+void* TQVariant::rawAccess( void* ptr, Type typ, bool deepCopy )
+{
+ if ( ptr ) {
+ clear();
+ d->typ = typ;
+ d->value.ptr = ptr;
+ d->is_null = FALSE;
+ if ( deepCopy ) {
+ TQVariant::Private* p = new Private( d );
+ d->typ = Invalid;
+ delete d;
+ d = p;
+ }
+ }
+
+ if ( !deepCopy )
+ return d->value.ptr;
+ TQVariant::Private* p = new Private( d );
+ void *ret = (void*)p->value.ptr;
+ p->typ = Invalid;
+ delete p;
+ return ret;
+}
+
+/*!
+ Returns TRUE if this is a NULL variant, FALSE otherwise.
+*/
+bool TQVariant::isNull() const
+{
+ switch( d->typ )
+ {
+ case TQVariant::Bitmap:
+ return ((TQBitmap*) d->value.ptr)->isNull();
+ case TQVariant::Region:
+ return ((TQRegion*) d->value.ptr)->isNull();
+ case TQVariant::PointArray:
+ return ((TQPointArray*) d->value.ptr)->isNull();
+ case TQVariant::String:
+ return ((TQString*) d->value.ptr)->isNull();
+ case TQVariant::CString:
+ return ((TQCString*) d->value.ptr)->isNull();
+ case TQVariant::Pixmap:
+ return ((TQPixmap*) d->value.ptr)->isNull();
+ case TQVariant::Image:
+ return ((TQImage*) d->value.ptr)->isNull();
+ case TQVariant::Point:
+ return ((TQPoint*) d->value.ptr)->isNull();
+ case TQVariant::Rect:
+ return ((TQRect*) d->value.ptr)->isNull();
+ case TQVariant::Size:
+ return ((TQSize*) d->value.ptr)->isNull();
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ return ((TQIconSet*) d->value.ptr)->isNull();
+#endif
+ case TQVariant::Date:
+ return ((TQDate*) d->value.ptr)->isNull();
+ case TQVariant::Time:
+ return ((TQTime*) d->value.ptr)->isNull();
+ case TQVariant::DateTime:
+ return ((TQDateTime*) d->value.ptr)->isNull();
+ case TQVariant::ByteArray:
+ return ((TQByteArray*) d->value.ptr)->isNull();
+ case TQVariant::BitArray:
+ return ((TQBitArray*) d->value.ptr)->isNull();
+ case TQVariant::Cursor:
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+#endif //TQT_NO_STRINGLIST
+ case TQVariant::Font:
+ case TQVariant::Brush:
+ case TQVariant::Color:
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ case TQVariant::ColorGroup:
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ case TQVariant::List:
+#endif
+ case TQVariant::SizePolicy:
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+#endif
+ case TQVariant::Pen:
+ case TQVariant::Invalid:
+ case TQVariant::Int:
+ case TQVariant::UInt:
+ case TQVariant::LongLong:
+ case TQVariant::ULongLong:
+ case TQVariant::Bool:
+ case TQVariant::Double:
+ break;
+ }
+ return d->is_null;
+}
+#endif //TQT_NO_VARIANT
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqvariant.cpp.new b/tqtinterface/qt4/src/kernel/tqvariant.cpp.new
new file mode 100644
index 0000000..22c05b3
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqvariant.cpp.new
@@ -0,0 +1,4858 @@
+/****************************************************************************
+**
+** Implementation of TQVariant class
+**
+** Created : 990414
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include <float.h>
+
+#include "tqvariant.h"
+#ifndef TQT_NO_VARIANT
+#include "tqstring.h"
+#include "tqcstring.h"
+#include "tqfont.h"
+#include "tqpixmap.h"
+#include "tqimage.h"
+#include "tqbrush.h"
+#include "tqpoint.h"
+#include "tqrect.h"
+#include "tqsize.h"
+#include "tqcolor.h"
+#include "tqpalette.h"
+#include "tqiconset.h"
+#include "tqdatastream.h"
+#include "tqregion.h"
+#include "tqpointarray.h"
+#include "tqbitmap.h"
+#include "tqcursor.h"
+#include "tqdatetime.h"
+#include "tqsizepolicy.h"
+#include "tqshared.h"
+#include "tqbitarray.h"
+#include "tqkeysequence.h"
+#include "tqpen.h"
+
+#ifdef USE_QT4
+
+#define IconSet Icon
+#define CString ByteArray
+#define PointArray Polygon
+#define ColorGroup 63
+
+/*!
+ Constructs a copy of the variant, \a p, passed as the argument to
+ this constructor. Usually this is a deep copy, but a shallow copy
+ is made if the stored data type is explicitly shared, as e.g.
+ TQImage is.
+*/
+TQVariant::TQVariant( const TQVariant& p )
+ : QVariant(p)
+{
+// p.d.ref();
+ d = p.d;
+}
+
+#ifndef TQT_NO_DATASTREAM
+/*!
+ Reads the variant from the data stream, \a s.
+*/
+TQVariant::TQVariant( TQDataStream& s )
+{
+ s >> *this;
+}
+#endif //TQT_NO_DATASTREAM
+
+/*!
+ Constructs a new variant with a string value, \a val.
+*/
+TQVariant::TQVariant( const TQString& val )
+{
+ d.type = String;
+ d.data.ptr = new TQString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value, \a val.
+
+ If you want to modify the TQCString after you've passed it to this
+ constructor, we recommend passing a deep copy (see
+ TQCString::copy()).
+*/
+TQVariant::TQVariant( const TQCString& val )
+{
+ d.type = CString;
+ d.data.ptr = new TQCString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value of \a val if \a val
+ is non-null. The variant creates a deep copy of \a val.
+
+ If \a val is null, the resulting variant has type Invalid.
+*/
+TQVariant::TQVariant( const char* val )
+{
+ if ( val == 0 )
+ return;
+ d.type = CString;
+ d.data.ptr = new TQCString( val );
+}
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Constructs a new variant with a string list value, \a val.
+*/
+TQVariant::TQVariant( const TQStringList& val )
+{
+ d.type = StringList;
+ d.data.ptr = new TQStringList( val );
+ d.is_null = FALSE;
+}
+#endif // TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a map of TQVariants, \a val.
+*/
+TQVariant::TQVariant( const TQMap<TQString,TQVariant>& val )
+{
+ d.type = Map;
+ d.data.ptr = new TQMap<TQString,TQVariant>( val );
+ d.is_null = FALSE;
+}
+#endif
+/*!
+ Constructs a new variant with a font value, \a val.
+*/
+TQVariant::TQVariant( const TQFont& val )
+{
+ d.type = Font;
+ d.data.ptr = new TQFont( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a pixmap value, \a val.
+*/
+TQVariant::TQVariant( const TQPixmap& val )
+{
+ d.type = Pixmap;
+ d.data.ptr = new TQPixmap( val );
+}
+
+
+/*!
+ Constructs a new variant with an image value, \a val.
+
+ Because TQImage is explicitly shared, you may need to pass a deep
+ copy to the variant using TQImage::copy(), e.g. if you intend
+ changing the image you've passed later on.
+*/
+TQVariant::TQVariant( const TQImage& val )
+{
+ d.type = Image;
+ d.data.ptr = new TQImage( val );
+}
+
+/*!
+ Constructs a new variant with a brush value, \a val.
+*/
+TQVariant::TQVariant( const TQBrush& val )
+{
+ d.type = Brush;
+ d.data.ptr = new TQBrush( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point value, \a val.
+*/
+TQVariant::TQVariant( const TQPoint& val )
+{
+ d.type = Point;
+ d.data.ptr = new TQPoint( val );
+}
+
+/*!
+ Constructs a new variant with a rect value, \a val.
+*/
+TQVariant::TQVariant( const TQRect& val )
+{
+ d.type = Rect;
+ d.data.ptr = new TQRect( val );
+}
+
+/*!
+ Constructs a new variant with a size value, \a val.
+*/
+TQVariant::TQVariant( const TQSize& val )
+{
+ d.type = Size;
+ d.data.ptr = new TQSize( val );
+}
+
+/*!
+ Constructs a new variant with a color value, \a val.
+*/
+TQVariant::TQVariant( const TQColor& val )
+{
+ d.type = Color;
+ d.data.ptr = new TQColor( val );
+ d.is_null = FALSE;
+}
+
+#ifndef TQT_NO_PALETTE
+/*!
+ Constructs a new variant with a color palette value, \a val.
+*/
+TQVariant::TQVariant( const TQPalette& val )
+{
+ d.type = Palette;
+ d.data.ptr = new TQPalette( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a color group value, \a val.
+*/
+TQVariant::TQVariant( const TQColorGroup& val )
+{
+ d.type = ColorGroup;
+ d.data.ptr = new TQColorGroup( val );
+ d.is_null = FALSE;
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Constructs a new variant with an icon set value, \a val.
+*/
+TQVariant::TQVariant( const TQIconSet& val )
+{
+ d.type = IconSet;
+ d.data.ptr = new TQIconSet( val );
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Constructs a new variant with a region value, \a val.
+*/
+TQVariant::TQVariant( const TQRegion& val )
+{
+ d.type = Region;
+ // ## Force a detach
+ d.data.ptr = new TQRegion( val );
+ ((TQRegion*)d.data.ptr)->translate( 0, 0 );
+}
+
+/*!
+ Constructs a new variant with a bitmap value, \a val.
+*/
+TQVariant::TQVariant( const TQBitmap& val )
+{
+ d.type = Bitmap;
+ d.data.ptr = new TQBitmap( val );
+}
+
+/*!
+ Constructs a new variant with a cursor value, \a val.
+*/
+TQVariant::TQVariant( const TQCursor& val )
+{
+ d.type = Cursor;
+ d.data.ptr = new TQCursor( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point array value, \a val.
+
+ Because TQPointArray is explicitly shared, you may need to pass a
+ deep copy to the variant using TQPointArray::copy(), e.g. if you
+ intend changing the point array you've passed later on.
+*/
+TQVariant::TQVariant( const TQPointArray& val )
+{
+ d.type = PointArray;
+ d.data.ptr = new TQPointArray( val );
+}
+
+/*!
+ Constructs a new variant with a date value, \a val.
+*/
+TQVariant::TQVariant( const TQDate& val )
+{
+ d.type = Date;
+ d.data.ptr = new TQDate( val );
+}
+
+/*!
+ Constructs a new variant with a time value, \a val.
+*/
+TQVariant::TQVariant( const TQTime& val )
+{
+ d.type = Time;
+ d.data.ptr = new TQTime( val );
+}
+
+/*!
+ Constructs a new variant with a date/time value, \a val.
+*/
+TQVariant::TQVariant( const TQDateTime& val )
+{
+ d.type = DateTime;
+ d.data.ptr = new TQDateTime( val );
+}
+
+/*!
+ Constructs a new variant with a bytearray value, \a val.
+*/
+TQVariant::TQVariant( const TQByteArray& val )
+{
+ d.type = ByteArray;
+ d.data.ptr = new TQByteArray( val );
+}
+
+/*!
+ Constructs a new variant with a bitarray value, \a val.
+*/
+TQVariant::TQVariant( const TQBitArray& val )
+{
+ d.type = BitArray;
+ d.data.ptr = new TQBitArray( val );
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Constructs a new variant with a key sequence value, \a val.
+*/
+TQVariant::TQVariant( const TQKeySequence& val )
+{
+ d.type = KeySequence;
+ d.data.ptr = new TQKeySequence( val );
+ d.is_null = FALSE;
+}
+
+#endif
+
+/*!
+ Constructs a new variant with a pen value, \a val.
+*/
+TQVariant::TQVariant( const TQPen& val )
+{
+ d.type = Pen;
+ d.data.ptr = new TQPen( val );
+}
+
+#if 0
+
+/*!
+ Constructs a new variant with an integer value, \a val.
+*/
+TQVariant::TQVariant( int val )
+{
+ d = new Private;
+ d->typ = Int;
+ d->value.i = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned integer value, \a val.
+*/
+TQVariant::TQVariant( uint val )
+{
+ d = new Private;
+ d->typ = UInt;
+ d->value.u = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a long long integer value, \a val.
+*/
+TQVariant::TQVariant( TQ_LLONG val )
+{
+ d = new Private;
+ d->typ = LongLong;
+ d->value.ll = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned long long integer value, \a val.
+*/
+
+TQVariant::TQVariant( TQ_ULLONG val )
+{
+ d = new Private;
+ d->typ = ULongLong;
+ d->value.ull = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a boolean value, \a val. The integer
+ argument is a dummy, necessary for compatibility with some
+ compilers.
+*/
+TQVariant::TQVariant( bool val, int )
+{ // this is the comment that does NOT name said compiler.
+ d = new Private;
+ d->typ = Bool;
+ d->value.b = val;
+ d->is_null = FALSE;
+}
+
+
+/*!
+ Constructs a new variant with a floating point value, \a val.
+*/
+TQVariant::TQVariant( double val )
+{
+ d = new Private;
+ d->typ = Double;
+ d->value.d = val;
+ d->is_null = FALSE;
+}
+
+#endif
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a list value, \a val.
+*/
+TQVariant::TQVariant( const TQValueList<TQVariant>& val )
+{
+ d.type = List;
+ d.data.ptr = new TQValueList<TQVariant>( val );
+ d.is_null = FALSE;
+}
+#endif
+
+/*!
+ Constructs a new variant with a size policy value, \a val.
+*/
+TQVariant::TQVariant( TQSizePolicy val )
+{
+// d = new Private;
+ d.type = SizePolicy;
+// d.value.ptr = new TQSizePolicy( val );
+ d.data.ptr = new TQSizePolicy( val );
+ d.is_null = FALSE;
+}
+
+/*!
+ Assigns the value of the variant \a variant to this variant.
+
+ This is a deep copy of the variant, but note that if the variant
+ holds an explicitly shared type such as TQImage, a shallow copy is
+ performed.
+*/
+// TQVariant& TQVariant::operator= ( const TQVariant& variant )
+// {
+// TQVariant& other = (TQVariant&)variant;
+//
+// other.d->ref();
+// if ( d->deref() )
+// delete d;
+//
+// d = other.d;
+//
+// return *this;
+// }
+
+/*!
+ Returns the variant as a TQFont if the variant can be cast to Font;
+ otherwise returns the application's default font.
+
+ \sa asFont(), canCast()
+*/
+const TQFont TQVariant::toFont() const
+{
+ switch ( type() ) {
+// case CString:
+ case ByteArray:
+ case String:
+ {
+ TQFont fnt;
+ fnt.fromString( toString() );
+ return fnt;
+ }
+ case Font:
+ return *((TQFont*)d.data.ptr);
+ default:
+ return TQFont();
+ }
+}
+
+#define TQ_VARIANT_AS( f ) TQ##f& TQVariant::as##f() \
+{ \
+ bool b = isNull(); \
+ if ( d.type != f ) \
+ *this = TQVariant( to##f() ); \
+ else \
+ detach(); \
+ d.is_null = b; \
+ return *((TQ##f*)d.data.ptr); \
+}
+
+TQ_VARIANT_AS(String)
+TQ_VARIANT_AS(CString)
+#ifndef TQT_NO_STRINGLIST
+TQ_VARIANT_AS(StringList)
+#endif
+TQ_VARIANT_AS(Font)
+TQ_VARIANT_AS(Pixmap)
+TQ_VARIANT_AS(Image)
+TQ_VARIANT_AS(Brush)
+TQ_VARIANT_AS(Point)
+TQ_VARIANT_AS(Rect)
+TQ_VARIANT_AS(Size)
+TQ_VARIANT_AS(Color)
+#ifndef TQT_NO_PALETTE
+TQ_VARIANT_AS(Palette)
+TQ_VARIANT_AS(ColorGroup)
+#endif
+#ifndef TQT_NO_ICONSET
+TQ_VARIANT_AS(IconSet)
+#endif
+TQ_VARIANT_AS(PointArray)
+TQ_VARIANT_AS(Bitmap)
+TQ_VARIANT_AS(Region)
+TQ_VARIANT_AS(Cursor)
+TQ_VARIANT_AS(SizePolicy)
+TQ_VARIANT_AS(Date)
+TQ_VARIANT_AS(Time)
+TQ_VARIANT_AS(DateTime)
+TQ_VARIANT_AS(ByteArray)
+TQ_VARIANT_AS(BitArray)
+#ifndef TQT_NO_ACCEL
+TQ_VARIANT_AS(KeySequence)
+#endif
+TQ_VARIANT_AS(Pen)
+
+// #if 0
+
+/*!
+ Returns the variant's value as int reference.
+*/
+int& TQVariant::asInt()
+{
+ detach();
+ if ( d.type != Int ) {
+ int i = toInt();
+ bool b = isNull();
+// d.clear();
+ d.data.i = i;
+ d.type = Int;
+ d.is_null = b;
+ }
+ return d.data.i;
+}
+
+/*!
+ Returns the variant's value as unsigned int reference.
+*/
+uint& TQVariant::asUInt()
+{
+ detach();
+ if ( d.type != UInt ) {
+ uint u = toUInt();
+ bool b = isNull();
+// d.clear();
+ d.data.u = u;
+ d.type = UInt;
+ d.is_null = b;
+ }
+ return d.data.u;
+}
+
+/*!
+ Returns the variant's value as long long reference.
+*/
+TQ_LLONG& TQVariant::asLongLong()
+{
+ detach();
+ if ( d.type != LongLong ) {
+ TQ_LLONG ll = toLongLong();
+ bool b = isNull();
+// d.clear();
+ d.data.ll = ll;
+ d.type = LongLong;
+ d.is_null = b;
+ }
+ return d.data.ll;
+}
+
+/*!
+ Returns the variant's value as unsigned long long reference.
+*/
+TQ_ULLONG& TQVariant::asULongLong()
+{
+ detach();
+ if ( d.type != ULongLong ) {
+ TQ_ULLONG ull = toULongLong();
+ bool b = isNull();
+// d.clear();
+ d.data.ull = ull;
+ d.type = ULongLong;
+ d.is_null = b;
+ }
+ return d.data.ull;
+}
+
+/*!
+ Returns the variant's value as bool reference.
+*/
+bool& TQVariant::asBool()
+{
+ detach();
+ if ( d.type != Bool ) {
+ bool b = toBool();
+ bool nb = isNull();
+// d.clear();
+ d.data.b = b;
+ d.type = Bool;
+ d.is_null = nb;
+ }
+ return d.data.b;
+}
+
+/*!
+ Returns the variant's value as double reference.
+*/
+double& TQVariant::asDouble()
+{
+ detach();
+ if ( d.type != Double ) {
+ double dbl = toDouble();
+ bool b = isNull();
+// d.clear();
+ d.data.d = dbl;
+ d.type = Double;
+ d.is_null = b;
+ }
+ return d.data.d;
+}
+
+// #endif
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant's value as variant list reference.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.asList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQValueList<TQVariant>& TQVariant::asList()
+{
+ bool b = isNull();
+ if ( d.type != List )
+ *this = TQVariant( toList() );
+ else
+ detach();
+ d.is_null = b;
+ return *((TQValueList<TQVariant>*)d.data.ptr);
+}
+
+/*!
+ Returns the variant's value as variant map reference.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.asMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQMap<TQString, TQVariant>& TQVariant::asMap()
+{
+ bool b = isNull();
+ if ( d.type != Map )
+ *this = TQVariant( toMap() );
+ else
+ detach();
+ d.is_null = b;
+ return *((TQMap<TQString,TQVariant>*)d.data.ptr);
+}
+#endif
+
+/*!
+ Returns the variant as a TQString if the variant can be cast to
+ String, otherwise returns TQString::null.
+
+ \sa asString(), canCast()
+*/
+const TQString TQVariant::toString() const
+{
+ return TQT_TQSTRING_OBJECT(QVariant::toString());
+}
+/*!
+ Returns the variant as a TQCString if the variant can be cast to a
+ CString; otherwise returns 0.
+
+ \sa asCString(), canCast()
+*/
+const TQCString TQVariant::toCString() const
+{
+ switch( d.type ) {
+ case CString: return *((TQCString*)d.data.ptr);
+ case String: return ((TQString*)d.data.ptr)->latin1();
+ default: {
+ if (!canCast(String))
+ return 0;
+ TQString c = toString();
+ return TQCString(c.latin1());
+ }
+ }
+}
+
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Returns the variant as a TQStringList if the variant has type()
+ StringList or List of a type that can be converted to TQString;
+ otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myVariant.toStringList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asStringList()
+*/
+const TQStringList TQVariant::toStringList() const
+{
+ switch ( d.type ) {
+ case StringList:
+ return *((TQStringList*)d.data.ptr);
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ {
+ TQStringList lst;
+ TQValueList<TQVariant>::ConstIterator it = listBegin();
+ TQValueList<TQVariant>::ConstIterator end = listEnd();
+ while( it != end ) {
+ TQString tmp = (*it).toString();
+ ++it;
+ lst.append( tmp );
+ }
+ return lst;
+ }
+#endif
+ default:
+ return TQStringList();
+ }
+}
+#endif //TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQMap<TQString,TQVariant> if the variant has
+ type() Map; otherwise returns an empty map.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.toMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asMap()
+*/
+const TQMap<TQString, TQVariant> TQVariant::toMap() const
+{
+ if ( d.type != Map )
+ return TQMap<TQString,TQVariant>();
+
+ return *((TQMap<TQString,TQVariant>*)d.data.ptr);
+}
+#endif
+
+/*!
+ Returns the variant as a TQPixmap if the variant has type() Pixmap;
+ otherwise returns a null pixmap.
+
+ \sa asPixmap()
+*/
+const TQPixmap TQVariant::toPixmap() const
+{
+ if ( d.type != Pixmap )
+ return TQPixmap();
+
+ return *((TQPixmap*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQImage if the variant has type() Image;
+ otherwise returns a null image.
+
+ \sa asImage()
+*/
+const TQImage TQVariant::toImage() const
+{
+ if ( d.type != Image )
+ return TQImage();
+
+ return *((TQImage*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQBrush if the variant has type() Brush;
+ otherwise returns a default brush (with all black colors).
+
+ \sa asBrush()
+*/
+const TQBrush TQVariant::toBrush() const
+{
+ if( d.type != Brush )
+ return TQBrush();
+
+ return *((TQBrush*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQPoint if the variant has type() Point;
+ otherwise returns a point (0, 0).
+
+ \sa asPoint()
+*/
+const TQPoint TQVariant::toPoint() const
+{
+ return QVariant::toPoint();
+}
+
+/*!
+ Returns the variant as a TQRect if the variant has type() Rect;
+ otherwise returns an empty rectangle.
+
+ \sa asRect()
+*/
+const TQRect TQVariant::toRect() const
+{
+ if ( d.type != Rect )
+ return TQRect();
+
+ return *((TQRect*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQSize if the variant has type() Size;
+ otherwise returns an invalid size.
+
+ \sa asSize()
+*/
+const TQSize TQVariant::toSize() const
+{
+ return QVariant::toSize();
+}
+
+/*!
+ Returns the variant as a TQColor if the variant can be cast to Color;
+ otherwise returns an invalid color.
+
+ \sa asColor(), canCast()
+*/
+const TQColor TQVariant::toColor() const
+{
+ switch ( d.type ) {
+ case ByteArray:
+// case CString:
+ case String:
+ {
+ TQColor col;
+ col.setNamedColor( toString() );
+ return col;
+ }
+ case Color:
+ return *((TQColor*)d.data.ptr);
+ default:
+ return TQColor();
+ }
+}
+#ifndef TQT_NO_PALETTE
+/*!
+ Returns the variant as a TQPalette if the variant has type()
+ Palette; otherwise returns a completely black palette.
+
+ \sa asPalette()
+*/
+const TQPalette TQVariant::toPalette() const
+{
+ if ( d.type != Palette )
+ return TQPalette();
+
+ return *((TQPalette*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQColorGroup if the variant has type()
+ ColorGroup; otherwise returns a completely black color group.
+
+ \sa asColorGroup()
+*/
+const TQColorGroup TQVariant::toColorGroup() const
+{
+ if ( d.type != ColorGroup )
+ return TQColorGroup();
+
+ return *((TQColorGroup*)d.data.ptr);
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQIconSet if the variant has type()
+ IconSet; otherwise returns an icon set of null pixmaps.
+
+ \sa asIconSet()
+*/
+const TQIconSet TQVariant::toIconSet() const
+{
+ if ( d.type != IconSet )
+ return TQIconSet();
+
+ return *((TQIconSet*)d.data.ptr);
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQPointArray if the variant has type()
+ PointArray; otherwise returns an empty TQPointArray.
+
+ \sa asPointArray()
+*/
+const TQPointArray TQVariant::toPointArray() const
+{
+ if ( d.type != PointArray )
+ return TQPointArray();
+
+ return *((TQPointArray*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQBitmap if the variant has type() Bitmap;
+ otherwise returns a null TQBitmap.
+
+ \sa asBitmap()
+*/
+const TQBitmap TQVariant::toBitmap() const
+{
+ if ( d.type != Bitmap )
+ return TQBitmap();
+
+ return *((TQBitmap*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQRegion if the variant has type() Region;
+ otherwise returns an empty TQRegion.
+
+ \sa asRegion()
+*/
+const TQRegion TQVariant::toRegion() const
+{
+ if ( d.type != Region )
+ return TQRegion();
+
+ return *((TQRegion*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQCursor if the variant has type() Cursor;
+ otherwise returns the default arrow cursor.
+
+ \sa asCursor()
+*/
+const TQCursor TQVariant::toCursor() const
+{
+#ifndef TQT_NO_CURSOR
+ if ( d.type != Cursor )
+ return TQCursor();
+#endif
+
+ return *((TQCursor*)d.data.ptr);
+}
+
+/*!
+ Returns the variant as a TQDate if the variant can be cast to Date;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ date will be returned if the string cannot be parsed as a
+ Qt::ISODate format date.
+
+ \sa asDate(), canCast()
+*/
+const TQDate TQVariant::toDate() const
+{
+ return TQT_TQDATE_OBJECT(QVariant::toDate());
+}
+
+/*!
+ Returns the variant as a TQTime if the variant can be cast to Time;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ time will be returned if the string cannot be parsed as a
+ Qt::ISODate format time.
+
+ \sa asTime()
+*/
+const TQTime TQVariant::toTime() const
+{
+ return TQT_TQTIME_OBJECT(QVariant::toTime());
+}
+
+/*!
+ Returns the variant as a TQDateTime if the variant can be cast to
+ DateTime; otherwise returns an invalid TQDateTime.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ TQDateTime will be returned if the string cannot be parsed as a
+ Qt::ISODate format date/time.
+
+ \sa asDateTime()
+*/
+const TQDateTime TQVariant::toDateTime() const
+{
+ return TQT_TQDATETIME_OBJECT(QVariant::toDateTime());
+}
+
+/*!
+ Returns the variant as a TQByteArray if the variant can be cast to
+ a ByteArray; otherwise returns an empty bytearray.
+
+ \sa asByteArray(), canCast()
+*/
+const TQByteArray TQVariant::toByteArray() const
+{
+ return TQT_TQBYTEARRAY_OBJECT(QVariant::toByteArray());
+}
+
+/*!
+ Returns the variant as a TQBitArray if the variant has type()
+ BitArray; otherwise returns an empty bitarray.
+
+ \sa asBitArray()
+*/
+const TQBitArray TQVariant::toBitArray() const
+{
+ return QVariant::toBitArray();
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQKeySequence if the variant can be cast
+ to a KeySequence; otherwise returns an empty key sequence.
+
+ \sa asKeySequence(), canCast()
+*/
+const TQKeySequence TQVariant::toKeySequence() const
+{
+ switch ( d.type ) {
+ case KeySequence:
+ return *((TQKeySequence*)d.data.ptr);
+ case String:
+ case ByteArray:
+// case CString:
+ return TQKeySequence( toString() );
+ case Int:
+ case UInt:
+ case Double:
+ case ULongLong:
+ case LongLong:
+ return TQKeySequence( toInt() );
+ default:
+ return TQKeySequence();
+ }
+}
+
+#endif // TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQPen if the variant has type()
+ Pen; otherwise returns an empty TQPen.
+
+ \sa asPen()
+*/
+const TQPen TQVariant::toPen() const
+{
+ if ( d.type != Pen )
+ return TQPen();
+
+ return *((TQPen*)d.data.ptr);
+}
+
+#if 0
+
+/*!
+ Returns the variant as an int if the variant can be cast to Int;
+ otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asInt(), canCast()
+*/
+int TQVariant::toInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Int );
+
+ switch ( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d.data.ptr)->toInt( ok );
+ case Int:
+ return d.data.i;
+ case UInt:
+ return (int)d.data.u;
+ case LongLong:
+ return (int)d.data.ll;
+ case ULongLong:
+ return (int)d.data.ull;
+ case Double:
+ return (int)d.data.d;
+ case Bool:
+ return (int)d.data.b;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return (int) *( (TQKeySequence*)d.data.ptr );
+#endif
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as an unsigned int if the variant can be cast
+ to UInt; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an unsigned int; otherwise \a *ok is set to FALSE.
+
+ \sa asUInt(), canCast()
+*/
+uint TQVariant::toUInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( UInt );
+
+ switch( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toUInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d.data.ptr)->toUInt( ok );
+ case Int:
+ return (uint)d.data.i;
+ case UInt:
+ return d.data.u;
+ case LongLong:
+ return (uint)d.data.ll;
+ case ULongLong:
+ return (uint)d.data.ull;
+ case Double:
+ return (uint)d.data.d;
+ case Bool:
+ return (uint)d.data.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a long long int if the variant can be cast
+ to LongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asLongLong(), canCast()
+*/
+TQ_LLONG TQVariant::toLongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( LongLong );
+
+ switch ( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toLongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d.data.ptr).toLongLong(ok);
+ case Int:
+ return (TQ_LLONG)d.data.i;
+ case UInt:
+ return (TQ_LLONG)d.data.u;
+ case LongLong:
+ return d.data.ll;
+ case ULongLong:
+ return (TQ_LLONG)d.data.ull;
+ case Double:
+ return (TQ_LLONG)d.data.d;
+ case Bool:
+ return (TQ_LLONG)d.data.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as as an unsigned long long int if the variant
+ can be cast to ULongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asULongLong(), canCast()
+*/
+TQ_ULLONG TQVariant::toULongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( ULongLong );
+
+ switch ( d.type ) {
+ case Int:
+ return (TQ_ULLONG)d.data.i;
+ case UInt:
+ return (TQ_ULLONG)d.data.u;
+ case LongLong:
+ return (TQ_ULLONG)d.data.ll;
+ case ULongLong:
+ return d.data.ull;
+ case Double:
+ return (TQ_ULLONG)d.data.d;
+ case Bool:
+ return (TQ_ULLONG)d.data.b;
+ case String:
+ return ((TQString*)d.data.ptr)->toULongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d.data.ptr).toULongLong(ok);
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a bool if the variant can be cast to Bool;
+ otherWise returns FALSE.
+
+ Returns TRUE if the variant has a numeric type and its value is
+ non-zero, or if the variant has type String, ByteArray or CString
+ and its lower-case content is not empty, "0" or "false"; otherwise
+ returns FALSE.
+
+ \sa asBool(), canCast()
+*/
+bool TQVariant::toBool() const
+{
+ switch( d.type ) {
+ case Bool:
+ return d.data.b;
+ case Double:
+ return d.data.d != 0.0;
+ case Int:
+ return d.data.i != 0;
+ case UInt:
+ return d.data.u != 0;
+ case LongLong:
+ return d.data.ll != 0;
+ case ULongLong:
+ return d.data.ull != 0;
+ case String:
+ case CString:
+ case ByteArray:
+ {
+ TQString str = toString().lower();
+ return !(str == "0" || str == "false" || str.isEmpty() );
+ }
+ default:
+ return FALSE;
+ }
+}
+
+/*!
+ Returns the variant as a double if the variant can be cast to
+ Double; otherwise returns 0.0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to a double; otherwise \a *ok is set to FALSE.
+
+ \sa asDouble(), canCast()
+*/
+double TQVariant::toDouble( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Double );
+
+ switch ( d.type ) {
+ case String:
+ return ((TQString*)d.data.ptr)->toDouble( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d.data.ptr)->toDouble( ok );
+ case Double:
+ return d.data.d;
+ case Int:
+ return (double)d.data.i;
+ case Bool:
+ return (double)d.data.b;
+ case UInt:
+ return (double)d.data.u;
+ case LongLong:
+ return (double)d.data.ll;
+ case ULongLong:
+#if defined(TQ_CC_MSVC) && !defined(TQ_CC_MSVC_NET)
+ return (double)(TQ_LLONG)d.data.ull;
+#else
+ return (double)d.data.ull;
+#endif
+ default:
+ return 0.0;
+ }
+}
+
+#endif
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQValueList<TQVariant> if the variant has
+ type() List or StringList; otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.toList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asList()
+*/
+const TQValueList<TQVariant> TQVariant::toList() const
+{
+ if ( d.type == List )
+ return *((TQValueList<TQVariant>*)d.data.ptr);
+#ifndef TQT_NO_STRINGLIST
+ if ( d.type == StringList ) {
+ TQValueList<TQVariant> lst;
+ TQStringList::ConstIterator it = stringListBegin();
+ TQStringList::ConstIterator end = stringListEnd();
+ for( ; it != end; ++it )
+ lst.append( TQVariant( *it ) );
+ return lst;
+ }
+#endif //TQT_NO_STRINGLIST
+ return TQValueList<TQVariant>();
+}
+#endif
+
+/*!
+ Returns the variant as a TQSizePolicy if the variant has type()
+ SizePolicy; otherwise returns an undefined (but legal) size
+ policy.
+*/
+
+TQSizePolicy TQVariant::toSizePolicy() const
+{
+ if ( d.type == SizePolicy )
+ return *((TQSizePolicy*)d.data.ptr);
+
+ return TQSizePolicy();
+}
+
+#else // USE_QT4
+
+#ifndef DBL_DIG
+#define DBL_DIG 10
+#endif //DBL_DIG
+
+// Uncomment to test for memory leaks or to run qt/test/qvariant/main.cpp
+// #define TQVARIANT_DEBUG
+
+
+static bool isNumeric(TQVariant::Type type)
+{
+ return (type == TQVariant::Int || type == TQVariant::UInt
+ || type == TQVariant::Double || type == TQVariant::LongLong
+ || type == TQVariant::ULongLong || type == TQVariant::Bool);
+}
+
+
+#ifdef TQVARIANT_DEBUG
+int qv_count = 0;
+int get_qv_count() { return qv_count; }
+#endif
+
+TQVariant::Private::Private()
+{
+#ifdef TQVARIANT_DEBUG
+ qv_count++;
+#endif
+ typ = TQVariant::Invalid;
+ is_null = TRUE;
+}
+
+TQVariant::Private::Private( Private* d )
+{
+#ifdef TQVARIANT_DEBUG
+ qv_count++;
+#endif
+
+ switch( d->typ )
+ {
+ case TQVariant::Invalid:
+ break;
+ case TQVariant::Bitmap:
+ value.ptr = new TQBitmap( *((TQBitmap*)d->value.ptr) );
+ break;
+ case TQVariant::Region:
+ value.ptr = new TQRegion( *((TQRegion*)d->value.ptr) );
+ // ## Force a detach
+ // ((TQRegion*)value.ptr)->translate( 0, 0 );
+ break;
+ case TQVariant::PointArray:
+ // TQPointArray is explicit shared
+ value.ptr = new TQPointArray( *((TQPointArray*)d->value.ptr) );
+ break;
+ case TQVariant::String:
+ value.ptr = new TQString( *((TQString*)d->value.ptr) );
+ break;
+ case TQVariant::CString:
+ // TQCString is explicit shared
+ value.ptr = new TQCString( *((TQCString*)d->value.ptr) );
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+ value.ptr = new TQStringList( *((TQStringList*)d->value.ptr) );
+ break;
+#endif //TQT_NO_STRINGLIST
+ case TQVariant::Font:
+ value.ptr = new TQFont( *((TQFont*)d->value.ptr) );
+ break;
+ case TQVariant::Pixmap:
+ value.ptr = new TQPixmap( *((TQPixmap*)d->value.ptr) );
+ break;
+ case TQVariant::Image:
+ // TQImage is explicit shared
+ value.ptr = new TQImage( *((TQImage*)d->value.ptr) );
+ break;
+ case TQVariant::Brush:
+ value.ptr = new TQBrush( *((TQBrush*)d->value.ptr) );
+ // ## Force a detach
+ // ((TQBrush*)value.ptr)->setColor( ((TQBrush*)value.ptr)->color() );
+ break;
+ case TQVariant::Point:
+ value.ptr = new TQPoint( *((TQPoint*)d->value.ptr) );
+ break;
+ case TQVariant::Rect:
+ value.ptr = new TQRect( *((TQRect*)d->value.ptr) );
+ break;
+ case TQVariant::Size:
+ value.ptr = new TQSize( *((TQSize*)d->value.ptr) );
+ break;
+ case TQVariant::Color:
+ value.ptr = new TQColor( *((TQColor*)d->value.ptr) );
+ break;
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ value.ptr = new TQPalette( *((TQPalette*)d->value.ptr) );
+ break;
+ case TQVariant::ColorGroup:
+ value.ptr = new TQColorGroup( *((TQColorGroup*)d->value.ptr) );
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ value.ptr = new TQIconSet( *((TQIconSet*)d->value.ptr) );
+ break;
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ value.ptr = new TQMap<TQString,TQVariant>( *((TQMap<TQString,TQVariant>*)d->value.ptr) );
+ break;
+ case TQVariant::List:
+ value.ptr = new TQValueList<TQVariant>( *((TQValueList<TQVariant>*)d->value.ptr) );
+ break;
+#endif
+ case TQVariant::Date:
+ value.ptr = new TQDate( *((TQDate*)d->value.ptr) );
+ break;
+ case TQVariant::Time:
+ value.ptr = new TQTime( *((TQTime*)d->value.ptr) );
+ break;
+ case TQVariant::DateTime:
+ value.ptr = new TQDateTime( *((TQDateTime*)d->value.ptr) );
+ break;
+ case TQVariant::ByteArray:
+ value.ptr = new TQByteArray( *((TQByteArray*)d->value.ptr) );
+ break;
+ case TQVariant::BitArray:
+ value.ptr = new TQBitArray( *((TQBitArray*)d->value.ptr) );
+ break;
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+ value.ptr = new TQKeySequence( *((TQKeySequence*)d->value.ptr) );
+ break;
+#endif
+ case TQVariant::Pen:
+ value.ptr = new TQPen( *((TQPen*)d->value.ptr) );
+ break;
+ case TQVariant::Int:
+ value.i = d->value.i;
+ break;
+ case TQVariant::UInt:
+ value.u = d->value.u;
+ break;
+ case TQVariant::LongLong:
+ value.ll = d->value.ll;
+ break;
+ case TQVariant::ULongLong:
+ value.ull = d->value.ull;
+ break;
+ case TQVariant::Bool:
+ value.b = d->value.b;
+ break;
+ case TQVariant::Double:
+ value.d = d->value.d;
+ break;
+ case TQVariant::SizePolicy:
+ value.ptr = new TQSizePolicy( *((TQSizePolicy*)d->value.ptr) );
+ break;
+ case TQVariant::Cursor:
+ value.ptr = new TQCursor( *((TQCursor*)d->value.ptr) );
+ break;
+ default:
+ TQ_ASSERT( 0 );
+ }
+
+ typ = d->typ;
+ is_null = d->is_null;
+}
+
+TQVariant::Private::~Private()
+{
+#ifdef TQVARIANT_DEBUG
+ qv_count--;
+#endif
+ clear();
+}
+
+void TQVariant::Private::clear()
+{
+ switch( typ )
+ {
+ case TQVariant::Bitmap:
+ delete (TQBitmap*)value.ptr;
+ break;
+ case TQVariant::Cursor:
+ delete (TQCursor*)value.ptr;
+ break;
+ case TQVariant::Region:
+ delete (TQRegion*)value.ptr;
+ break;
+ case TQVariant::PointArray:
+ delete (TQPointArray*)value.ptr;
+ break;
+ case TQVariant::String:
+ delete (TQString*)value.ptr;
+ break;
+ case TQVariant::CString:
+ delete (TQCString*)value.ptr;
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+ delete (TQStringList*)value.ptr;
+ break;
+#endif //TQT_NO_STRINGLIST
+ case TQVariant::Font:
+ delete (TQFont*)value.ptr;
+ break;
+ case TQVariant::Pixmap:
+ delete (TQPixmap*)value.ptr;
+ break;
+ case TQVariant::Image:
+ delete (TQImage*)value.ptr;
+ break;
+ case TQVariant::Brush:
+ delete (TQBrush*)value.ptr;
+ break;
+ case TQVariant::Point:
+ delete (TQPoint*)value.ptr;
+ break;
+ case TQVariant::Rect:
+ delete (TQRect*)value.ptr;
+ break;
+ case TQVariant::Size:
+ delete (TQSize*)value.ptr;
+ break;
+ case TQVariant::Color:
+ delete (TQColor*)value.ptr;
+ break;
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ delete (TQPalette*)value.ptr;
+ break;
+ case TQVariant::ColorGroup:
+ delete (TQColorGroup*)value.ptr;
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ delete (TQIconSet*)value.ptr;
+ break;
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ delete (TQMap<TQString,TQVariant>*)value.ptr;
+ break;
+ case TQVariant::List:
+ delete (TQValueList<TQVariant>*)value.ptr;
+ break;
+#endif
+ case TQVariant::SizePolicy:
+ delete (TQSizePolicy*)value.ptr;
+ break;
+ case TQVariant::Date:
+ delete (TQDate*)value.ptr;
+ break;
+ case TQVariant::Time:
+ delete (TQTime*)value.ptr;
+ break;
+ case TQVariant::DateTime:
+ delete (TQDateTime*)value.ptr;
+ break;
+ case TQVariant::ByteArray:
+ delete (TQByteArray*)value.ptr;
+ break;
+ case TQVariant::BitArray:
+ delete (TQBitArray*)value.ptr;
+ break;
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+ delete (TQKeySequence*)value.ptr;
+ break;
+#endif
+ case TQVariant::Pen:
+ delete (TQPen*)value.ptr;
+ break;
+ case TQVariant::Invalid:
+ case TQVariant::Int:
+ case TQVariant::UInt:
+ case TQVariant::LongLong:
+ case TQVariant::ULongLong:
+ case TQVariant::Bool:
+ case TQVariant::Double:
+ break;
+ }
+
+ typ = TQVariant::Invalid;
+ is_null = TRUE;
+}
+
+/*!
+ \class TQVariant tqvariant.h
+ \brief The TQVariant class acts like a union for the most common TQt data types.
+
+ \ingroup objectmodel
+ \ingroup misc
+ \mainclass
+
+ Because C++ forbids unions from including types that have
+ non-default constructors or destructors, most interesting TQt
+ classes cannot be used in unions. Without TQVariant, this would be
+ a problem for TQObject::property() and for database work, etc.
+
+ A TQVariant object holds a single value of a single type() at a
+ time. (Some type()s are multi-valued, for example a string list.)
+ You can tqfind out what type, T, the variant holds, convert it to a
+ different type using one of the asT() functions, e.g. asSize(),
+ get its value using one of the toT() functions, e.g. toSize(), and
+ check whether the type can be converted to a particular type using
+ canCast().
+
+ The methods named toT() (for any supported T, see the \c Type
+ documentation for a list) are const. If you ask for the stored
+ type, they return a copy of the stored object. If you ask for a
+ type that can be generated from the stored type, toT() copies and
+ converts and leaves the object itself unchanged. If you ask for a
+ type that cannot be generated from the stored type, the result
+ depends on the type (see the function documentation for details).
+
+ Note that three data types supported by TQVariant are explicitly
+ shared, namely TQImage, TQPointArray, and TQCString, and in these
+ cases the toT() methods return a shallow copy. In almost all cases
+ you must make a deep copy of the returned values before modifying
+ them.
+
+ The asT() functions are not const. They do conversion like the
+ toT() methods, set the variant to hold the converted value, and
+ return a reference to the new contents of the variant.
+
+ Here is some example code to demonstrate the use of TQVariant:
+
+ \code
+ TQDataStream out(...);
+ TQVariant v(123); // The variant now tqcontains an int
+ int x = v.toInt(); // x = 123
+ out << v; // Writes a type tag and an int to out
+ v = TQVariant("hello"); // The variant now tqcontains a TQCString
+ v = TQVariant(tr("hello"));// The variant now tqcontains a TQString
+ int y = v.toInt(); // y = 0 since v cannot be converted to an int
+ TQString s = v.toString(); // s = tr("hello") (see TQObject::tr())
+ out << v; // Writes a type tag and a TQString to out
+ ...
+ TQDataStream in(...); // (opening the previously written stream)
+ in >> v; // Reads an Int variant
+ int z = v.toInt(); // z = 123
+ qDebug("Type is %s", // prints "Type is int"
+ v.typeName());
+ v.asInt() += 100; // The variant now hold the value 223.
+ v = TQVariant( TQStringList() );
+ v.asStringList().append( "Hello" );
+ \endcode
+
+ You can even store TQValueList<TQVariant>s and
+ TQMap<TQString,TQVariant>s in a variant, so you can easily construct
+ arbitrarily complex data structures of arbitrary types. This is
+ very powerful and versatile, but may prove less memory and speed
+ efficient than storing specific types in standard data structures.
+
+ TQVariant also supports the notion of NULL values, where you have a
+ defined type with no value set.
+ \code
+ TQVariant x, y( TQString() ), z( TQString("") );
+ x.asInt();
+ // x.isNull() == TRUE, y.isNull() == TRUE, z.isNull() == FALSE
+ \endcode
+
+ See the \link collection.html Collection Classes\endlink.
+*/
+
+/*!
+ \enum TQVariant::Type
+
+ This enum type defines the types of variable that a TQVariant can
+ contain.
+
+ \value Invalid no type
+ \value BitArray a TQBitArray
+ \value ByteArray a TQByteArray
+ \value Bitmap a TQBitmap
+ \value Bool a bool
+ \value Brush a TQBrush
+ \value Color a TQColor
+ \value ColorGroup a TQColorGroup
+ \value Cursor a TQCursor
+ \value Date a TQDate
+ \value DateTime a TQDateTime
+ \value Double a double
+ \value Font a TQFont
+ \value IconSet a TQIconSet
+ \value Image a TQImage
+ \value Int an int
+ \value KeySequence a TQKeySequence
+ \value List a TQValueList<TQVariant>
+ \value LongLong a long long
+ \value ULongLong an unsigned long long
+ \value Map a TQMap<TQString,TQVariant>
+ \value Palette a TQPalette
+ \value Pen a TQPen
+ \value Pixmap a TQPixmap
+ \value Point a TQPoint
+ \value PointArray a TQPointArray
+ \value Rect a TQRect
+ \value Region a TQRegion
+ \value Size a TQSize
+ \value SizePolicy a TQSizePolicy
+ \value String a TQString
+ \value CString a TQCString
+ \value StringList a TQStringList
+ \value Time a TQTime
+ \value UInt an unsigned int
+
+ Note that TQt's definition of bool depends on the compiler.
+ \c tqglobal.h has the system-dependent definition of bool.
+*/
+
+/*!
+ Constructs an invalid variant.
+*/
+TQVariant::TQVariant()
+{
+ d = new Private;
+}
+
+/*!
+ Destroys the TQVariant and the contained object.
+
+ Note that subclasses that reimplement clear() should reimplement
+ the destructor to call clear(). This destructor calls clear(), but
+ because it is the destructor, TQVariant::clear() is called rather
+ than a subclass's clear().
+*/
+TQVariant::~TQVariant()
+{
+ if ( d->deref() )
+ delete d;
+}
+
+/*!
+ Constructs a copy of the variant, \a p, passed as the argument to
+ this constructor. Usually this is a deep copy, but a shallow copy
+ is made if the stored data type is explicitly shared, as e.g.
+ TQImage is.
+*/
+TQVariant::TQVariant( const TQVariant& p )
+{
+ p.d->ref();
+ d = p.d;
+}
+
+#ifndef TQT_NO_DATASTREAM
+/*!
+ Reads the variant from the data stream, \a s.
+*/
+TQVariant::TQVariant( TQDataStream& s )
+{
+ d = new Private;
+ s >> *this;
+}
+#endif //TQT_NO_DATASTREAM
+
+/*!
+ Constructs a new variant with a string value, \a val.
+*/
+TQVariant::TQVariant( const TQString& val )
+{
+ d = new Private;
+ d->typ = String;
+ d->value.ptr = new TQString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value, \a val.
+
+ If you want to modify the TQCString after you've passed it to this
+ constructor, we recommend passing a deep copy (see
+ TQCString::copy()).
+*/
+TQVariant::TQVariant( const TQCString& val )
+{
+ d = new Private;
+ d->typ = CString;
+ d->value.ptr = new TQCString( val );
+}
+
+/*!
+ Constructs a new variant with a C-string value of \a val if \a val
+ is non-null. The variant creates a deep copy of \a val.
+
+ If \a val is null, the resulting variant has type Invalid.
+*/
+TQVariant::TQVariant( const char* val )
+{
+ d = new Private;
+ if ( val == 0 )
+ return;
+ d->typ = CString;
+ d->value.ptr = new TQCString( val );
+}
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Constructs a new variant with a string list value, \a val.
+*/
+TQVariant::TQVariant( const TQStringList& val )
+{
+ d = new Private;
+ d->typ = StringList;
+ d->value.ptr = new TQStringList( val );
+ d->is_null = FALSE;
+}
+#endif // TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a map of TQVariants, \a val.
+*/
+TQVariant::TQVariant( const TQMap<TQString,TQVariant>& val )
+{
+ d = new Private;
+ d->typ = Map;
+ d->value.ptr = new TQMap<TQString,TQVariant>( val );
+ d->is_null = FALSE;
+}
+#endif
+/*!
+ Constructs a new variant with a font value, \a val.
+*/
+TQVariant::TQVariant( const TQFont& val )
+{
+ d = new Private;
+ d->typ = Font;
+ d->value.ptr = new TQFont( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a pixmap value, \a val.
+*/
+TQVariant::TQVariant( const TQPixmap& val )
+{
+ d = new Private;
+ d->typ = Pixmap;
+ d->value.ptr = new TQPixmap( val );
+}
+
+
+/*!
+ Constructs a new variant with an image value, \a val.
+
+ Because TQImage is explicitly shared, you may need to pass a deep
+ copy to the variant using TQImage::copy(), e.g. if you intend
+ changing the image you've passed later on.
+*/
+TQVariant::TQVariant( const TQImage& val )
+{
+ d = new Private;
+ d->typ = Image;
+ d->value.ptr = new TQImage( val );
+}
+
+/*!
+ Constructs a new variant with a brush value, \a val.
+*/
+TQVariant::TQVariant( const TQBrush& val )
+{
+ d = new Private;
+ d->typ = Brush;
+ d->value.ptr = new TQBrush( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point value, \a val.
+*/
+TQVariant::TQVariant( const TQPoint& val )
+{
+ d = new Private;
+ d->typ = Point;
+ d->value.ptr = new TQPoint( val );
+}
+
+/*!
+ Constructs a new variant with a rect value, \a val.
+*/
+TQVariant::TQVariant( const TQRect& val )
+{
+ d = new Private;
+ d->typ = Rect;
+ d->value.ptr = new TQRect( val );
+}
+
+/*!
+ Constructs a new variant with a size value, \a val.
+*/
+TQVariant::TQVariant( const TQSize& val )
+{
+ d = new Private;
+ d->typ = Size;
+ d->value.ptr = new TQSize( val );
+}
+
+/*!
+ Constructs a new variant with a color value, \a val.
+*/
+TQVariant::TQVariant( const TQColor& val )
+{
+ d = new Private;
+ d->typ = Color;
+ d->value.ptr = new TQColor( val );
+ d->is_null = FALSE;
+}
+
+#ifndef TQT_NO_PALETTE
+/*!
+ Constructs a new variant with a color palette value, \a val.
+*/
+TQVariant::TQVariant( const TQPalette& val )
+{
+ d = new Private;
+ d->typ = Palette;
+ d->value.ptr = new TQPalette( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a color group value, \a val.
+*/
+TQVariant::TQVariant( const TQColorGroup& val )
+{
+ d = new Private;
+ d->typ = ColorGroup;
+ d->value.ptr = new TQColorGroup( val );
+ d->is_null = FALSE;
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Constructs a new variant with an icon set value, \a val.
+*/
+TQVariant::TQVariant( const TQIconSet& val )
+{
+ d = new Private;
+ d->typ = IconSet;
+ d->value.ptr = new TQIconSet( val );
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Constructs a new variant with a region value, \a val.
+*/
+TQVariant::TQVariant( const TQRegion& val )
+{
+ d = new Private;
+ d->typ = Region;
+ // ## Force a detach
+ d->value.ptr = new TQRegion( val );
+ ((TQRegion*)d->value.ptr)->translate( 0, 0 );
+}
+
+/*!
+ Constructs a new variant with a bitmap value, \a val.
+*/
+TQVariant::TQVariant( const TQBitmap& val )
+{
+ d = new Private;
+ d->typ = Bitmap;
+ d->value.ptr = new TQBitmap( val );
+}
+
+/*!
+ Constructs a new variant with a cursor value, \a val.
+*/
+TQVariant::TQVariant( const TQCursor& val )
+{
+ d = new Private;
+ d->typ = Cursor;
+ d->value.ptr = new TQCursor( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a point array value, \a val.
+
+ Because TQPointArray is explicitly shared, you may need to pass a
+ deep copy to the variant using TQPointArray::copy(), e.g. if you
+ intend changing the point array you've passed later on.
+*/
+TQVariant::TQVariant( const TQPointArray& val )
+{
+ d = new Private;
+ d->typ = PointArray;
+ d->value.ptr = new TQPointArray( val );
+}
+
+/*!
+ Constructs a new variant with a date value, \a val.
+*/
+TQVariant::TQVariant( const TQDate& val )
+{
+ d = new Private;
+ d->typ = Date;
+ d->value.ptr = new TQDate( val );
+}
+
+/*!
+ Constructs a new variant with a time value, \a val.
+*/
+TQVariant::TQVariant( const TQTime& val )
+{
+ d = new Private;
+ d->typ = Time;
+ d->value.ptr = new TQTime( val );
+}
+
+/*!
+ Constructs a new variant with a date/time value, \a val.
+*/
+TQVariant::TQVariant( const TQDateTime& val )
+{
+ d = new Private;
+ d->typ = DateTime;
+ d->value.ptr = new TQDateTime( val );
+}
+
+/*!
+ Constructs a new variant with a bytearray value, \a val.
+*/
+TQVariant::TQVariant( const TQByteArray& val )
+{
+ d = new Private;
+ d->typ = ByteArray;
+ d->value.ptr = new TQByteArray( val );
+}
+
+/*!
+ Constructs a new variant with a bitarray value, \a val.
+*/
+TQVariant::TQVariant( const TQBitArray& val )
+{
+ d = new Private;
+ d->typ = BitArray;
+ d->value.ptr = new TQBitArray( val );
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Constructs a new variant with a key sequence value, \a val.
+*/
+TQVariant::TQVariant( const TQKeySequence& val )
+{
+ d = new Private;
+ d->typ = KeySequence;
+ d->value.ptr = new TQKeySequence( val );
+ d->is_null = FALSE;
+}
+
+#endif
+
+/*!
+ Constructs a new variant with a pen value, \a val.
+*/
+TQVariant::TQVariant( const TQPen& val )
+{
+ d = new Private;
+ d->typ = Pen;
+ d->value.ptr = new TQPen( val );
+}
+
+/*!
+ Constructs a new variant with an integer value, \a val.
+*/
+TQVariant::TQVariant( int val )
+{
+ d = new Private;
+ d->typ = Int;
+ d->value.i = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned integer value, \a val.
+*/
+TQVariant::TQVariant( uint val )
+{
+ d = new Private;
+ d->typ = UInt;
+ d->value.u = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a long long integer value, \a val.
+*/
+TQVariant::TQVariant( TQ_LLONG val )
+{
+ d = new Private;
+ d->typ = LongLong;
+ d->value.ll = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with an unsigned long long integer value, \a val.
+*/
+
+TQVariant::TQVariant( TQ_ULLONG val )
+{
+ d = new Private;
+ d->typ = ULongLong;
+ d->value.ull = val;
+ d->is_null = FALSE;
+}
+
+/*!
+ Constructs a new variant with a boolean value, \a val. The integer
+ argument is a dummy, necessary for compatibility with some
+ compilers.
+*/
+TQVariant::TQVariant( bool val, int )
+{ // this is the comment that does NOT name said compiler.
+ d = new Private;
+ d->typ = Bool;
+ d->value.b = val;
+ d->is_null = FALSE;
+}
+
+
+/*!
+ Constructs a new variant with a floating point value, \a val.
+*/
+TQVariant::TQVariant( double val )
+{
+ d = new Private;
+ d->typ = Double;
+ d->value.d = val;
+ d->is_null = FALSE;
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Constructs a new variant with a list value, \a val.
+*/
+TQVariant::TQVariant( const TQValueList<TQVariant>& val )
+{
+ d = new Private;
+ d->typ = List;
+ d->value.ptr = new TQValueList<TQVariant>( val );
+ d->is_null = FALSE;
+}
+#endif
+
+/*!
+ Constructs a new variant with a size policy value, \a val.
+*/
+TQVariant::TQVariant( TQSizePolicy val )
+{
+ d = new Private;
+ d->typ = SizePolicy;
+ d->value.ptr = new TQSizePolicy( val );
+ d->is_null = FALSE;
+}
+
+/*!
+ Assigns the value of the variant \a variant to this variant.
+
+ This is a deep copy of the variant, but note that if the variant
+ holds an explicitly shared type such as TQImage, a shallow copy is
+ performed.
+*/
+TQVariant& TQVariant::operator= ( const TQVariant& variant )
+{
+ TQVariant& other = (TQVariant&)variant;
+
+ other.d->ref();
+ if ( d->deref() )
+ delete d;
+
+ d = other.d;
+
+ return *this;
+}
+
+/*!
+ \internal
+*/
+void TQVariant::detach()
+{
+ if ( d->count == 1 )
+ return;
+
+ d->deref();
+ d = new Private( d );
+}
+
+/*!
+ Returns the name of the type stored in the variant. The returned
+ strings describe the C++ datatype used to store the data: for
+ example, "TQFont", "TQString", or "TQValueList<TQVariant>". An Invalid
+ variant returns 0.
+*/
+const char* TQVariant::typeName() const
+{
+ return typeToName( (Type) d->typ );
+}
+
+/*!
+ Convert this variant to type Invalid and free up any resources
+ used.
+*/
+void TQVariant::clear()
+{
+ if ( d->count > 1 )
+ {
+ d->deref();
+ d = new Private;
+ return;
+ }
+
+ d->clear();
+}
+
+/* Attention!
+
+ For dependency reasons, this table is duplicated in tqmoc.y. If you
+ change one, change both.
+
+ (Search for the word 'Attention' in tqmoc.y.)
+*/
+static const int ntypes = 35;
+static const char* const type_map[ntypes] =
+{
+ 0,
+ "TQMap<TQString,TQVariant>",
+ "TQValueList<TQVariant>",
+ "TQString",
+ "TQStringList",
+ "TQFont",
+ "TQPixmap",
+ "TQBrush",
+ "TQRect",
+ "TQSize",
+ "TQColor",
+ "TQPalette",
+ "TQColorGroup",
+ "TQIconSet",
+ "TQPoint",
+ "TQImage",
+ "int",
+ "uint",
+ "bool",
+ "double",
+ "TQCString",
+ "TQPointArray",
+ "TQRegion",
+ "TQBitmap",
+ "TQCursor",
+ "TQSizePolicy",
+ "TQDate",
+ "TQTime",
+ "TQDateTime",
+ "TQByteArray",
+ "TQBitArray",
+ "TQKeySequence",
+ "TQPen",
+ "TQ_LLONG",
+ "TQ_ULLONG"
+};
+
+
+/*!
+ Converts the enum representation of the storage type, \a typ, to
+ its string representation.
+*/
+const char* TQVariant::typeToName( Type typ )
+{
+ if ( typ >= ntypes )
+ return 0;
+ return type_map[typ];
+}
+
+
+/*!
+ Converts the string representation of the storage type given in \a
+ name, to its enum representation.
+
+ If the string representation cannot be converted to any enum
+ representation, the variant is set to \c Invalid.
+*/
+TQVariant::Type TQVariant::nameToType( const char* name )
+{
+ for ( int i = 0; i < ntypes; i++ ) {
+ if ( !qstrcmp( type_map[i], name ) )
+ return (Type) i;
+ }
+ return Invalid;
+}
+
+#ifndef TQT_NO_DATASTREAM
+/*!
+ Internal function for loading a variant from stream \a s. Use the
+ stream operators instead.
+
+ \internal
+*/
+void TQVariant::load( TQDataStream& s )
+{
+ clear();
+ TQ_UINT32 u;
+ s >> u;
+ Type t = (Type)u;
+
+ switch( t ) {
+ case Invalid:
+ {
+ // Since we wrote something, we should read something
+ TQString x;
+ s >> x;
+ d->typ = t;
+ d->is_null = TRUE;
+ }
+ break;
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case Map:
+ {
+ TQMap<TQString,TQVariant>* x = new TQMap<TQString,TQVariant>;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case List:
+ {
+ TQValueList<TQVariant>* x = new TQValueList<TQVariant>;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif
+ case Cursor:
+ {
+#ifndef TQT_NO_CURSOR
+ TQCursor* x = new TQCursor;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+#endif
+ }
+ break;
+ case Bitmap:
+ {
+ TQBitmap* x = new TQBitmap;
+#ifndef TQT_NO_IMAGEIO
+ s >> *x;
+#endif
+ d->value.ptr = x;
+ }
+ break;
+ case Region:
+ {
+ TQRegion* x = new TQRegion;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case PointArray:
+ {
+ TQPointArray* x = new TQPointArray;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case String:
+ {
+ TQString* x = new TQString;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case CString:
+ {
+ TQCString* x = new TQCString;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case StringList:
+ {
+ TQStringList* x = new TQStringList;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif // TQT_NO_STRINGLIST
+ case Font:
+ {
+ TQFont* x = new TQFont;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case Pixmap:
+ {
+ TQPixmap* x = new TQPixmap;
+#ifndef TQT_NO_IMAGEIO
+ s >> *x;
+#endif
+ d->value.ptr = x;
+ }
+ break;
+ case Image:
+ {
+ TQImage* x = new TQImage;
+#ifndef TQT_NO_IMAGEIO
+ s >> *x;
+#endif
+ d->value.ptr = x;
+ }
+ break;
+ case Brush:
+ {
+ TQBrush* x = new TQBrush;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case Rect:
+ {
+ TQRect* x = new TQRect;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Point:
+ {
+ TQPoint* x = new TQPoint;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Size:
+ {
+ TQSize* x = new TQSize;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Color:
+ {
+ TQColor* x = new TQColor;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#ifndef TQT_NO_PALETTE
+ case Palette:
+ {
+ TQPalette* x = new TQPalette;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case ColorGroup:
+ {
+ TQColorGroup* x = new TQColorGroup;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case IconSet:
+ {
+ TQPixmap x;
+ s >> x;
+ d->value.ptr = new TQIconSet( x );
+ }
+ break;
+#endif
+ case Int:
+ {
+ int x;
+ s >> x;
+ d->value.i = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case UInt:
+ {
+ uint x;
+ s >> x;
+ d->value.u = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case LongLong:
+ {
+ TQ_LLONG x;
+ s >> x;
+ d->value.ll = x;
+ }
+ break;
+ case ULongLong:
+ {
+ TQ_ULLONG x;
+ s >> x;
+ d->value.ull = x;
+ }
+ break;
+ case Bool:
+ {
+ TQ_INT8 x;
+ s >> x;
+ d->value.b = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case Double:
+ {
+ double x;
+ s >> x;
+ d->value.d = x;
+ d->is_null = FALSE;
+ }
+ break;
+ case SizePolicy:
+ {
+ int h,v;
+ TQ_INT8 hfw;
+ s >> h >> v >> hfw;
+ d->value.ptr = new TQSizePolicy( (TQSizePolicy::SizeType)h,
+ (TQSizePolicy::SizeType)v,
+ (bool) hfw);
+ d->is_null = FALSE;
+ }
+ break;
+ case Date:
+ {
+ TQDate* x = new TQDate;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case Time:
+ {
+ TQTime* x = new TQTime;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case DateTime:
+ {
+ TQDateTime* x = new TQDateTime;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case ByteArray:
+ {
+ TQByteArray* x = new TQByteArray;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+ case BitArray:
+ {
+ TQBitArray* x = new TQBitArray;
+ s >> *x;
+ d->value.ptr = x;
+ }
+ break;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ {
+ TQKeySequence* x = new TQKeySequence;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+#endif // TQT_NO_ACCEL
+ case Pen:
+ {
+ TQPen* x = new TQPen;
+ s >> *x;
+ d->value.ptr = x;
+ d->is_null = FALSE;
+ }
+ break;
+ }
+ d->typ = t;
+}
+
+/*!
+ Internal function for saving a variant to the stream \a s. Use the
+ stream operators instead.
+
+ \internal
+*/
+void TQVariant::save( TQDataStream& s ) const
+{
+ s << (TQ_UINT32)type();
+
+ switch( d->typ ) {
+ case Cursor:
+ s << *((TQCursor*)d->value.ptr);
+ break;
+ case Bitmap:
+#ifndef TQT_NO_IMAGEIO
+ s << *((TQBitmap*)d->value.ptr);
+#endif
+ break;
+ case PointArray:
+ s << *((TQPointArray*)d->value.ptr);
+ break;
+ case Region:
+ s << *((TQRegion*)d->value.ptr);
+ break;
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ s << *((TQValueList<TQVariant>*)d->value.ptr);
+ break;
+ case Map:
+ s << *((TQMap<TQString,TQVariant>*)d->value.ptr);
+ break;
+#endif
+ case String:
+ s << *((TQString*)d->value.ptr);
+ break;
+ case CString:
+ s << *((TQCString*)d->value.ptr);
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case StringList:
+ s << *((TQStringList*)d->value.ptr);
+ break;
+#endif
+ case Font:
+ s << *((TQFont*)d->value.ptr);
+ break;
+ case Pixmap:
+#ifndef TQT_NO_IMAGEIO
+ s << *((TQPixmap*)d->value.ptr);
+#endif
+ break;
+ case Image:
+#ifndef TQT_NO_IMAGEIO
+ s << *((TQImage*)d->value.ptr);
+#endif
+ break;
+ case Brush:
+ s << *((TQBrush*)d->value.ptr);
+ break;
+ case Point:
+ s << *((TQPoint*)d->value.ptr);
+ break;
+ case Rect:
+ s << *((TQRect*)d->value.ptr);
+ break;
+ case Size:
+ s << *((TQSize*)d->value.ptr);
+ break;
+ case Color:
+ s << *((TQColor*)d->value.ptr);
+ break;
+#ifndef TQT_NO_PALETTE
+ case Palette:
+ s << *((TQPalette*)d->value.ptr);
+ break;
+ case ColorGroup:
+ s << *((TQColorGroup*)d->value.ptr);
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case IconSet:
+ //### add stream operator to iconset
+ s << ((TQIconSet*)d->value.ptr)->pixmap();
+ break;
+#endif
+ case Int:
+ s << d->value.i;
+ break;
+ case UInt:
+ s << d->value.u;
+ break;
+ case LongLong:
+ s << d->value.ll;
+ break;
+ case ULongLong:
+ s << d->value.ull;
+ break;
+ case Bool:
+ s << (TQ_INT8)d->value.b;
+ break;
+ case Double:
+ s << d->value.d;
+ break;
+ case SizePolicy:
+ {
+ TQSizePolicy p = toSizePolicy();
+ s << (int) p.horData() << (int) p.verData()
+ << (TQ_INT8) p.hasHeightForWidth();
+ }
+ break;
+ case Date:
+ s << *((TQDate*)d->value.ptr);
+ break;
+ case Time:
+ s << *((TQTime*)d->value.ptr);
+ break;
+ case DateTime:
+ s << *((TQDateTime*)d->value.ptr);
+ break;
+ case ByteArray:
+ s << *((TQByteArray*)d->value.ptr);
+ break;
+ case BitArray:
+ s << *((TQBitArray*)d->value.ptr);
+ break;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ s << *((TQKeySequence*)d->value.ptr);
+ break;
+#endif
+ case Pen:
+ s << *((TQPen*)d->value.ptr);
+ break;
+ case Invalid:
+ s << TQString(); // ### looks wrong.
+ break;
+ }
+}
+
+/*!
+ Reads a variant \a p from the stream \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream
+ operators \endlink
+*/
+TQDataStream& operator>> ( TQDataStream& s, TQVariant& p )
+{
+ p.load( s );
+ return s;
+}
+
+/*!
+ Writes a variant \a p to the stream \a s.
+
+ \sa \link datastreamformat.html Format of the TQDataStream
+ operators \endlink
+*/
+TQDataStream& operator<< ( TQDataStream& s, const TQVariant& p )
+{
+ p.save( s );
+ return s;
+}
+
+/*!
+ Reads a variant type \a p in enum representation from the stream \a s.
+*/
+TQDataStream& operator>> ( TQDataStream& s, TQVariant::Type& p )
+{
+ TQ_UINT32 u;
+ s >> u;
+ p = (TQVariant::Type) u;
+
+ return s;
+}
+
+/*!
+ Writes a variant type \a p to the stream \a s.
+*/
+TQDataStream& operator<< ( TQDataStream& s, const TQVariant::Type p )
+{
+ s << (TQ_UINT32)p;
+
+ return s;
+}
+
+#endif //TQT_NO_DATASTREAM
+
+/*!
+ \fn Type TQVariant::type() const
+
+ Returns the storage type of the value stored in the variant.
+ Usually it's best to test with canCast() whether the variant can
+ deliver the data type you are interested in.
+*/
+
+/*!
+ \fn bool TQVariant::isValid() const
+
+ Returns TRUE if the storage type of this variant is not
+ TQVariant::Invalid; otherwise returns FALSE.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQString> TQVariant::stringListBegin() const
+ \obsolete
+
+ Returns an iterator to the first string in the list if the
+ variant's type is StringList; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQString> TQVariant::stringListEnd() const
+ \obsolete
+
+ Returns the end iterator for the list if the variant's type is
+ StringList; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQVariant> TQVariant::listBegin() const
+ \obsolete
+
+ Returns an iterator to the first item in the list if the variant's
+ type is appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQValueListConstIterator<TQVariant> TQVariant::listEnd() const
+ \obsolete
+
+ Returns the end iterator for the list if the variant's type is
+ appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQMapConstIterator<TQString, TQVariant> TQVariant::mapBegin() const
+ \obsolete
+
+ Returns an iterator to the first item in the map, if the variant's
+ type is appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQMapConstIterator<TQString, TQVariant> TQVariant::mapEnd() const
+ \obsolete
+
+ Returns the end iterator for the map, if the variant's type is
+ appropriate; otherwise returns a null iterator.
+*/
+
+/*!
+ \fn TQMapConstIterator<TQString, TQVariant> TQVariant::mapFind( const TQString& key ) const
+ \obsolete
+
+ Returns an iterator to the item in the map with \a key as key, if
+ the variant's type is appropriate and \a key is a valid key;
+ otherwise returns a null iterator.
+*/
+
+/*!
+ Returns the variant as a TQString if the variant can be cast to
+ String, otherwise returns TQString::null.
+
+ \sa asString(), canCast()
+*/
+const TQString TQVariant::toString() const
+{
+ switch( d->typ ) {
+ case CString:
+ return TQString::tqfromLatin1( toCString() );
+ case Int:
+ return TQString::number( toInt() );
+ case UInt:
+ return TQString::number( toUInt() );
+ case LongLong:
+ return TQString::number( toLongLong() );
+ case ULongLong:
+ return TQString::number( toULongLong() );
+ case Double:
+ return TQString::number( toDouble(), 'g', DBL_DIG );
+#if !defined(TQT_NO_SPRINTF) && !defined(TQT_NO_DATESTRING)
+ case Date:
+ return toDate().toString( TQt::ISODate );
+ case Time:
+ return toTime().toString( TQt::ISODate );
+ case DateTime:
+ return toDateTime().toString( TQt::ISODate );
+#endif
+ case Bool:
+ return toInt() ? "true" : "false";
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return (TQString) *( (TQKeySequence*)d->value.ptr );
+#endif
+ case ByteArray:
+ return TQString( *((TQByteArray*)d->value.ptr) );
+ case Font:
+ return toFont().toString();
+ case Color:
+ return toColor().name();
+ case String:
+ return *((TQString*)d->value.ptr);
+ default:
+ return TQString::null;
+ }
+}
+/*!
+ Returns the variant as a TQCString if the variant can be cast to a
+ CString; otherwise returns 0.
+
+ \sa asCString(), canCast()
+*/
+const TQCString TQVariant::toCString() const
+{
+ switch( d->typ ) {
+ case CString: return *((TQCString*)d->value.ptr);
+ case String: return ((TQString*)d->value.ptr)->latin1();
+ default: {
+ if (!canCast(String))
+ return 0;
+ TQString c = toString();
+ return TQCString(c.latin1());
+ }
+ }
+}
+
+
+#ifndef TQT_NO_STRINGLIST
+/*!
+ Returns the variant as a TQStringList if the variant has type()
+ StringList or List of a type that can be converted to TQString;
+ otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQStringList list = myVariant.toStringList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asStringList()
+*/
+const TQStringList TQVariant::toStringList() const
+{
+ switch ( d->typ ) {
+ case StringList:
+ return *((TQStringList*)d->value.ptr);
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ {
+ TQStringList lst;
+ TQValueList<TQVariant>::ConstIterator it = listBegin();
+ TQValueList<TQVariant>::ConstIterator end = listEnd();
+ while( it != end ) {
+ TQString tmp = (*it).toString();
+ ++it;
+ lst.append( tmp );
+ }
+ return lst;
+ }
+#endif
+ default:
+ return TQStringList();
+ }
+}
+#endif //TQT_NO_STRINGLIST
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQMap<TQString,TQVariant> if the variant has
+ type() Map; otherwise returns an empty map.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.toMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asMap()
+*/
+const TQMap<TQString, TQVariant> TQVariant::toMap() const
+{
+ if ( d->typ != Map )
+ return TQMap<TQString,TQVariant>();
+
+ return *((TQMap<TQString,TQVariant>*)d->value.ptr);
+}
+#endif
+/*!
+ Returns the variant as a TQFont if the variant can be cast to Font;
+ otherwise returns the application's default font.
+
+ \sa asFont(), canCast()
+*/
+const TQFont TQVariant::toFont() const
+{
+ switch ( d->typ ) {
+ case CString:
+ case ByteArray:
+ case String:
+ {
+ TQFont fnt;
+ fnt.fromString( toString() );
+ return fnt;
+ }
+ case Font:
+ return *((TQFont*)d->value.ptr);
+ default:
+ return TQFont();
+ }
+}
+
+/*!
+ Returns the variant as a TQPixmap if the variant has type() Pixmap;
+ otherwise returns a null pixmap.
+
+ \sa asPixmap()
+*/
+const TQPixmap TQVariant::toPixmap() const
+{
+ if ( d->typ != Pixmap )
+ return TQPixmap();
+
+ return *((TQPixmap*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQImage if the variant has type() Image;
+ otherwise returns a null image.
+
+ \sa asImage()
+*/
+const TQImage TQVariant::toImage() const
+{
+ if ( d->typ != Image )
+ return TQImage();
+
+ return *((TQImage*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQBrush if the variant has type() Brush;
+ otherwise returns a default brush (with all black colors).
+
+ \sa asBrush()
+*/
+const TQBrush TQVariant::toBrush() const
+{
+ if( d->typ != Brush )
+ return TQBrush();
+
+ return *((TQBrush*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQPoint if the variant has type() Point;
+ otherwise returns a point (0, 0).
+
+ \sa asPoint()
+*/
+const TQPoint TQVariant::toPoint() const
+{
+ if ( d->typ != Point )
+ return TQPoint();
+
+ return *((TQPoint*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQRect if the variant has type() Rect;
+ otherwise returns an empty rectangle.
+
+ \sa asRect()
+*/
+const TQRect TQVariant::toRect() const
+{
+ if ( d->typ != Rect )
+ return TQRect();
+
+ return *((TQRect*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQSize if the variant has type() Size;
+ otherwise returns an invalid size.
+
+ \sa asSize()
+*/
+const TQSize TQVariant::toSize() const
+{
+ if ( d->typ != Size )
+ return TQSize();
+
+ return *((TQSize*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQColor if the variant can be cast to Color;
+ otherwise returns an invalid color.
+
+ \sa asColor(), canCast()
+*/
+const TQColor TQVariant::toColor() const
+{
+ switch ( d->typ ) {
+ case ByteArray:
+ case CString:
+ case String:
+ {
+ TQColor col;
+ col.setNamedColor( toString() );
+ return col;
+ }
+ case Color:
+ return *((TQColor*)d->value.ptr);
+ default:
+ return TQColor();
+ }
+}
+#ifndef TQT_NO_PALETTE
+/*!
+ Returns the variant as a TQPalette if the variant has type()
+ Palette; otherwise returns a completely black palette.
+
+ \sa asPalette()
+*/
+const TQPalette TQVariant::toPalette() const
+{
+ if ( d->typ != Palette )
+ return TQPalette();
+
+ return *((TQPalette*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQColorGroup if the variant has type()
+ ColorGroup; otherwise returns a completely black color group.
+
+ \sa asColorGroup()
+*/
+const TQColorGroup TQVariant::toColorGroup() const
+{
+ if ( d->typ != ColorGroup )
+ return TQColorGroup();
+
+ return *((TQColorGroup*)d->value.ptr);
+}
+#endif //TQT_NO_PALETTE
+#ifndef TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQIconSet if the variant has type()
+ IconSet; otherwise returns an icon set of null pixmaps.
+
+ \sa asIconSet()
+*/
+const TQIconSet TQVariant::toIconSet() const
+{
+ if ( d->typ != IconSet )
+ return TQIconSet();
+
+ return *((TQIconSet*)d->value.ptr);
+}
+#endif //TQT_NO_ICONSET
+/*!
+ Returns the variant as a TQPointArray if the variant has type()
+ PointArray; otherwise returns an empty TQPointArray.
+
+ \sa asPointArray()
+*/
+const TQPointArray TQVariant::toPointArray() const
+{
+ if ( d->typ != PointArray )
+ return TQPointArray();
+
+ return *((TQPointArray*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQBitmap if the variant has type() Bitmap;
+ otherwise returns a null TQBitmap.
+
+ \sa asBitmap()
+*/
+const TQBitmap TQVariant::toBitmap() const
+{
+ if ( d->typ != Bitmap )
+ return TQBitmap();
+
+ return *((TQBitmap*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQRegion if the variant has type() Region;
+ otherwise returns an empty TQRegion.
+
+ \sa asRegion()
+*/
+const TQRegion TQVariant::toRegion() const
+{
+ if ( d->typ != Region )
+ return TQRegion();
+
+ return *((TQRegion*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQCursor if the variant has type() Cursor;
+ otherwise returns the default arrow cursor.
+
+ \sa asCursor()
+*/
+const TQCursor TQVariant::toCursor() const
+{
+#ifndef TQT_NO_CURSOR
+ if ( d->typ != Cursor )
+ return TQCursor();
+#endif
+
+ return *((TQCursor*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as a TQDate if the variant can be cast to Date;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ date will be returned if the string cannot be parsed as a
+ TQt::ISODate format date.
+
+ \sa asDate(), canCast()
+*/
+const TQDate TQVariant::toDate() const
+{
+ switch ( d->typ ) {
+ case Date:
+ return *((TQDate*)d->value.ptr);
+ case DateTime:
+ return ((TQDateTime*)d->value.ptr)->date();
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQDate::fromString( *((TQString*)d->value.ptr), TQt::ISODate );
+ case CString:
+ case ByteArray:
+ return TQDate::fromString(toString(), TQt::ISODate);
+#endif
+ default:
+ return TQDate();
+ }
+}
+
+/*!
+ Returns the variant as a TQTime if the variant can be cast to Time;
+ otherwise returns an invalid date.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ time will be returned if the string cannot be parsed as a
+ TQt::ISODate format time.
+
+ \sa asTime()
+*/
+const TQTime TQVariant::toTime() const
+{
+ switch ( d->typ ) {
+ case Time:
+ return *((TQTime*)d->value.ptr);
+ case DateTime:
+ return ((TQDateTime*)d->value.ptr)->time();
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQTime::fromString( *((TQString*)d->value.ptr), TQt::ISODate );
+ case CString:
+ case ByteArray:
+ return TQTime::fromString(toString(), TQt::ISODate);
+#endif
+ default:
+ return TQTime();
+ }
+}
+
+/*!
+ Returns the variant as a TQDateTime if the variant can be cast to
+ DateTime; otherwise returns an invalid TQDateTime.
+
+ Note that if the type() is String, CString or ByteArray an invalid
+ TQDateTime will be returned if the string cannot be parsed as a
+ TQt::ISODate format date/time.
+
+ \sa asDateTime()
+*/
+const TQDateTime TQVariant::toDateTime() const
+{
+ switch ( d->typ ) {
+ case DateTime:
+ return *((TQDateTime*)d->value.ptr);
+#ifndef TQT_NO_DATESTRING
+ case String:
+ return TQDateTime::fromString( *((TQString*)d->value.ptr), TQt::ISODate );
+ case CString:
+ case ByteArray:
+ return TQDateTime::fromString(toString(), TQt::ISODate);
+#endif
+ case Date:
+ return TQDateTime( *((TQDate*)d->value.ptr) );
+ default:
+ return TQDateTime();
+ }
+}
+
+/*!
+ Returns the variant as a TQByteArray if the variant can be cast to
+ a ByteArray; otherwise returns an empty bytearray.
+
+ \sa asByteArray(), canCast()
+*/
+const TQByteArray TQVariant::toByteArray() const
+{
+ switch(d->typ) {
+ case ByteArray: return *((TQByteArray*)d->value.ptr);
+ case CString: return *((TQByteArray*)d->value.ptr);
+ default: {
+ TQByteArray ret;
+ if (canCast(String)) {
+ TQString c = toString();
+ ret.duplicate(c.latin1(), c.length());
+ }
+ return ret;
+ }
+ }
+}
+
+/*!
+ Returns the variant as a TQBitArray if the variant has type()
+ BitArray; otherwise returns an empty bitarray.
+
+ \sa asBitArray()
+*/
+const TQBitArray TQVariant::toBitArray() const
+{
+ if ( d->typ == BitArray )
+ return *((TQBitArray*)d->value.ptr);
+ return TQBitArray();
+}
+
+#ifndef TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQKeySequence if the variant can be cast
+ to a KeySequence; otherwise returns an empty key sequence.
+
+ \sa asKeySequence(), canCast()
+*/
+const TQKeySequence TQVariant::toKeySequence() const
+{
+ switch ( d->typ ) {
+ case KeySequence:
+ return *((TQKeySequence*)d->value.ptr);
+ case String:
+ case ByteArray:
+ case CString:
+ return TQKeySequence( toString() );
+ case Int:
+ case UInt:
+ case Double:
+ case ULongLong:
+ case LongLong:
+ return TQKeySequence( toInt() );
+ default:
+ return TQKeySequence();
+ }
+}
+
+#endif // TQT_NO_ACCEL
+
+/*!
+ Returns the variant as a TQPen if the variant has type()
+ Pen; otherwise returns an empty TQPen.
+
+ \sa asPen()
+*/
+const TQPen TQVariant::toPen() const
+{
+ if ( d->typ != Pen )
+ return TQPen();
+
+ return *((TQPen*)d->value.ptr);
+}
+
+/*!
+ Returns the variant as an int if the variant can be cast to Int;
+ otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asInt(), canCast()
+*/
+int TQVariant::toInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Int );
+
+ switch ( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d->value.ptr)->toInt( ok );
+ case Int:
+ return d->value.i;
+ case UInt:
+ return (int)d->value.u;
+ case LongLong:
+ return (int)d->value.ll;
+ case ULongLong:
+ return (int)d->value.ull;
+ case Double:
+ return (int)d->value.d;
+ case Bool:
+ return (int)d->value.b;
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return (int) *( (TQKeySequence*)d->value.ptr );
+#endif
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as an unsigned int if the variant can be cast
+ to UInt; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an unsigned int; otherwise \a *ok is set to FALSE.
+
+ \sa asUInt(), canCast()
+*/
+uint TQVariant::toUInt( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( UInt );
+
+ switch( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toUInt( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d->value.ptr)->toUInt( ok );
+ case Int:
+ return (uint)d->value.i;
+ case UInt:
+ return d->value.u;
+ case LongLong:
+ return (uint)d->value.ll;
+ case ULongLong:
+ return (uint)d->value.ull;
+ case Double:
+ return (uint)d->value.d;
+ case Bool:
+ return (uint)d->value.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a long long int if the variant can be cast
+ to LongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asLongLong(), canCast()
+*/
+TQ_LLONG TQVariant::toLongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( LongLong );
+
+ switch ( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toLongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d->value.ptr).toLongLong(ok);
+ case Int:
+ return (TQ_LLONG)d->value.i;
+ case UInt:
+ return (TQ_LLONG)d->value.u;
+ case LongLong:
+ return d->value.ll;
+ case ULongLong:
+ return (TQ_LLONG)d->value.ull;
+ case Double:
+ return (TQ_LLONG)d->value.d;
+ case Bool:
+ return (TQ_LLONG)d->value.b;
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as as an unsigned long long int if the variant
+ can be cast to ULongLong; otherwise returns 0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to an int; otherwise \a *ok is set to FALSE.
+
+ \sa asULongLong(), canCast()
+*/
+TQ_ULLONG TQVariant::toULongLong( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( ULongLong );
+
+ switch ( d->typ ) {
+ case Int:
+ return (TQ_ULLONG)d->value.i;
+ case UInt:
+ return (TQ_ULLONG)d->value.u;
+ case LongLong:
+ return (TQ_ULLONG)d->value.ll;
+ case ULongLong:
+ return d->value.ull;
+ case Double:
+ return (TQ_ULLONG)d->value.d;
+ case Bool:
+ return (TQ_ULLONG)d->value.b;
+ case String:
+ return ((TQString*)d->value.ptr)->toULongLong( ok );
+ case CString:
+ case ByteArray:
+ return TQString(*(TQCString*)d->value.ptr).toULongLong(ok);
+ default:
+ return 0;
+ }
+}
+
+/*!
+ Returns the variant as a bool if the variant can be cast to Bool;
+ otherWise returns FALSE.
+
+ Returns TRUE if the variant has a numeric type and its value is
+ non-zero, or if the variant has type String, ByteArray or CString
+ and its lower-case content is not empty, "0" or "false"; otherwise
+ returns FALSE.
+
+ \sa asBool(), canCast()
+*/
+bool TQVariant::toBool() const
+{
+ switch( d->typ ) {
+ case Bool:
+ return d->value.b;
+ case Double:
+ return d->value.d != 0.0;
+ case Int:
+ return d->value.i != 0;
+ case UInt:
+ return d->value.u != 0;
+ case LongLong:
+ return d->value.ll != 0;
+ case ULongLong:
+ return d->value.ull != 0;
+ case String:
+ case CString:
+ case ByteArray:
+ {
+ TQString str = toString().lower();
+ return !(str == "0" || str == "false" || str.isEmpty() );
+ }
+ default:
+ return FALSE;
+ }
+}
+
+/*!
+ Returns the variant as a double if the variant can be cast to
+ Double; otherwise returns 0.0.
+
+ If \a ok is non-null: \a *ok is set to TRUE if the value could be
+ converted to a double; otherwise \a *ok is set to FALSE.
+
+ \sa asDouble(), canCast()
+*/
+double TQVariant::toDouble( bool * ok ) const
+{
+ if ( ok )
+ *ok = canCast( Double );
+
+ switch ( d->typ ) {
+ case String:
+ return ((TQString*)d->value.ptr)->toDouble( ok );
+ case CString:
+ case ByteArray:
+ return ((TQCString*)d->value.ptr)->toDouble( ok );
+ case Double:
+ return d->value.d;
+ case Int:
+ return (double)d->value.i;
+ case Bool:
+ return (double)d->value.b;
+ case UInt:
+ return (double)d->value.u;
+ case LongLong:
+ return (double)d->value.ll;
+ case ULongLong:
+#if defined(TQ_CC_MSVC) && !defined(TQ_CC_MSVC_NET)
+ return (double)(TQ_LLONG)d->value.ull;
+#else
+ return (double)d->value.ull;
+#endif
+ default:
+ return 0.0;
+ }
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant as a TQValueList<TQVariant> if the variant has
+ type() List or StringList; otherwise returns an empty list.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.toList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa asList()
+*/
+const TQValueList<TQVariant> TQVariant::toList() const
+{
+ if ( d->typ == List )
+ return *((TQValueList<TQVariant>*)d->value.ptr);
+#ifndef TQT_NO_STRINGLIST
+ if ( d->typ == StringList ) {
+ TQValueList<TQVariant> lst;
+ TQStringList::ConstIterator it = stringListBegin();
+ TQStringList::ConstIterator end = stringListEnd();
+ for( ; it != end; ++it )
+ lst.append( TQVariant( *it ) );
+ return lst;
+ }
+#endif //TQT_NO_STRINGLIST
+ return TQValueList<TQVariant>();
+}
+#endif
+
+/*!
+ Returns the variant as a TQSizePolicy if the variant has type()
+ SizePolicy; otherwise returns an undefined (but legal) size
+ policy.
+*/
+
+TQSizePolicy TQVariant::toSizePolicy() const
+{
+ if ( d->typ == SizePolicy )
+ return *((TQSizePolicy*)d->value.ptr);
+
+ return TQSizePolicy();
+}
+
+
+#define TQ_VARIANT_AS( f ) TQ##f& TQVariant::as##f() \
+{ \
+ bool b = isNull(); \
+ if ( d->typ != f ) \
+ *this = TQVariant( to##f() ); \
+ else \
+ detach(); \
+ d->is_null = b; \
+ return *((TQ##f*)d->value.ptr); \
+}
+
+TQ_VARIANT_AS(String)
+TQ_VARIANT_AS(CString)
+#ifndef TQT_NO_STRINGLIST
+TQ_VARIANT_AS(StringList)
+#endif
+TQ_VARIANT_AS(Font)
+TQ_VARIANT_AS(Pixmap)
+TQ_VARIANT_AS(Image)
+TQ_VARIANT_AS(Brush)
+TQ_VARIANT_AS(Point)
+TQ_VARIANT_AS(Rect)
+TQ_VARIANT_AS(Size)
+TQ_VARIANT_AS(Color)
+#ifndef TQT_NO_PALETTE
+TQ_VARIANT_AS(Palette)
+TQ_VARIANT_AS(ColorGroup)
+#endif
+#ifndef TQT_NO_ICONSET
+TQ_VARIANT_AS(IconSet)
+#endif
+TQ_VARIANT_AS(PointArray)
+TQ_VARIANT_AS(Bitmap)
+TQ_VARIANT_AS(Region)
+TQ_VARIANT_AS(Cursor)
+TQ_VARIANT_AS(SizePolicy)
+TQ_VARIANT_AS(Date)
+TQ_VARIANT_AS(Time)
+TQ_VARIANT_AS(DateTime)
+TQ_VARIANT_AS(ByteArray)
+TQ_VARIANT_AS(BitArray)
+#ifndef TQT_NO_ACCEL
+TQ_VARIANT_AS(KeySequence)
+#endif
+TQ_VARIANT_AS(Pen)
+
+/*!
+ \fn TQString& TQVariant::asString()
+
+ Tries to convert the variant to hold a string value. If that is
+ not possible the variant is set to an empty string.
+
+ Returns a reference to the stored string.
+
+ \sa toString()
+*/
+
+/*!
+ \fn TQCString& TQVariant::asCString()
+
+ Tries to convert the variant to hold a string value. If that is
+ not possible the variant is set to an empty string.
+
+ Returns a reference to the stored string.
+
+ \sa toCString()
+*/
+
+/*!
+ \fn TQStringList& TQVariant::asStringList()
+
+ Tries to convert the variant to hold a TQStringList value. If that
+ is not possible the variant is set to an empty string list.
+
+ Returns a reference to the stored string list.
+
+ Note that if you want to iterate over the list, you should
+ iterate over a copy, e.g.
+ \code
+ TQStringList list = myVariant.asStringList();
+ TQStringList::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+
+ \sa toStringList()
+*/
+
+/*!
+ \fn TQFont& TQVariant::asFont()
+
+ Tries to convert the variant to hold a TQFont. If that is not
+ possible the variant is set to the application's default font.
+
+ Returns a reference to the stored font.
+
+ \sa toFont()
+*/
+
+/*!
+ \fn TQPixmap& TQVariant::asPixmap()
+
+ Tries to convert the variant to hold a pixmap value. If that is
+ not possible the variant is set to a null pixmap.
+
+ Returns a reference to the stored pixmap.
+
+ \sa toPixmap()
+*/
+
+/*!
+ \fn TQImage& TQVariant::asImage()
+
+ Tries to convert the variant to hold an image value. If that is
+ not possible the variant is set to a null image.
+
+ Returns a reference to the stored image.
+
+ \sa toImage()
+*/
+
+/*!
+ \fn TQBrush& TQVariant::asBrush()
+
+ Tries to convert the variant to hold a brush value. If that is not
+ possible the variant is set to a default black brush.
+
+ Returns a reference to the stored brush.
+
+ \sa toBrush()
+*/
+
+/*!
+ \fn TQPoint& TQVariant::asPoint()
+
+ Tries to convert the variant to hold a point value. If that is not
+ possible the variant is set to a (0, 0) point.
+
+ Returns a reference to the stored point.
+
+ \sa toPoint()
+*/
+
+/*!
+ \fn TQRect& TQVariant::asRect()
+
+ Tries to convert the variant to hold a rectangle value. If that is
+ not possible the variant is set to an empty rectangle.
+
+ Returns a reference to the stored rectangle.
+
+ \sa toRect()
+*/
+
+/*!
+ \fn TQSize& TQVariant::asSize()
+
+ Tries to convert the variant to hold a TQSize value. If that is not
+ possible the variant is set to an invalid size.
+
+ Returns a reference to the stored size.
+
+ \sa toSize() TQSize::isValid()
+*/
+
+/*!
+ \fn TQSizePolicy& TQVariant::asSizePolicy()
+
+ Tries to convert the variant to hold a TQSizePolicy value. If that
+ fails, the variant is set to an arbitrary (valid) size policy.
+*/
+
+
+/*!
+ \fn TQColor& TQVariant::asColor()
+
+ Tries to convert the variant to hold a TQColor value. If that is
+ not possible the variant is set to an invalid color.
+
+ Returns a reference to the stored color.
+
+ \sa toColor() TQColor::isValid()
+*/
+
+/*!
+ \fn TQPalette& TQVariant::asPalette()
+
+ Tries to convert the variant to hold a TQPalette value. If that is
+ not possible the variant is set to a palette of black colors.
+
+ Returns a reference to the stored palette.
+
+ \sa toString()
+*/
+
+/*!
+ \fn TQColorGroup& TQVariant::asColorGroup()
+
+ Tries to convert the variant to hold a TQColorGroup value. If that
+ is not possible the variant is set to a color group of all black
+ colors.
+
+ Returns a reference to the stored color group.
+
+ \sa toColorGroup()
+*/
+
+/*!
+ \fn TQIconSet& TQVariant::asIconSet()
+
+ Tries to convert the variant to hold a TQIconSet value. If that is
+ not possible the variant is set to an empty iconset.
+
+ Returns a reference to the stored iconset.
+
+ \sa toIconSet()
+*/
+
+/*!
+ \fn TQPointArray& TQVariant::asPointArray()
+
+ Tries to convert the variant to hold a TQPointArray value. If that
+ is not possible the variant is set to an empty point array.
+
+ Returns a reference to the stored point array.
+
+ \sa toPointArray()
+*/
+
+/*!
+ \fn TQBitmap& TQVariant::asBitmap()
+
+ Tries to convert the variant to hold a bitmap value. If that is
+ not possible the variant is set to a null bitmap.
+
+ Returns a reference to the stored bitmap.
+
+ \sa toBitmap()
+*/
+
+/*!
+ \fn TQRegion& TQVariant::asRegion()
+
+ Tries to convert the variant to hold a TQRegion value. If that is
+ not possible the variant is set to a null region.
+
+ Returns a reference to the stored region.
+
+ \sa toRegion()
+*/
+
+/*!
+ \fn TQCursor& TQVariant::asCursor()
+
+ Tries to convert the variant to hold a TQCursor value. If that is
+ not possible the variant is set to a default arrow cursor.
+
+ Returns a reference to the stored cursor.
+
+ \sa toCursor()
+*/
+
+/*!
+ \fn TQDate& TQVariant::asDate()
+
+ Tries to convert the variant to hold a TQDate value. If that is not
+ possible then the variant is set to an invalid date.
+
+ Returns a reference to the stored date.
+
+ \sa toDate()
+*/
+
+/*!
+ \fn TQTime& TQVariant::asTime()
+
+ Tries to convert the variant to hold a TQTime value. If that is not
+ possible then the variant is set to an invalid time.
+
+ Returns a reference to the stored time.
+
+ \sa toTime()
+*/
+
+/*!
+ \fn TQDateTime& TQVariant::asDateTime()
+
+ Tries to convert the variant to hold a TQDateTime value. If that is
+ not possible then the variant is set to an invalid date/time.
+
+ Returns a reference to the stored date/time.
+
+ \sa toDateTime()
+*/
+
+/*!
+ \fn TQByteArray& TQVariant::asByteArray()
+
+ Tries to convert the variant to hold a TQByteArray value. If that
+ is not possible then the variant is set to an empty bytearray.
+
+ Returns a reference to the stored bytearray.
+
+ \sa toByteArray()
+*/
+
+/*!
+ \fn TQBitArray& TQVariant::asBitArray()
+
+ Tries to convert the variant to hold a TQBitArray value. If that is
+ not possible then the variant is set to an empty bitarray.
+
+ Returns a reference to the stored bitarray.
+
+ \sa toBitArray()
+*/
+
+/*!
+ \fn TQKeySequence& TQVariant::asKeySequence()
+
+ Tries to convert the variant to hold a TQKeySequence value. If that
+ is not possible then the variant is set to an empty key sequence.
+
+ Returns a reference to the stored key sequence.
+
+ \sa toKeySequence()
+*/
+
+/*! \fn TQPen& TQVariant::asPen()
+
+ Tries to convert the variant to hold a TQPen value. If that
+ is not possible then the variant is set to an empty pen.
+
+ Returns a reference to the stored pen.
+
+ \sa toPen()
+*/
+
+/*!
+ Returns the variant's value as int reference.
+*/
+int& TQVariant::asInt()
+{
+ detach();
+ if ( d->typ != Int ) {
+ int i = toInt();
+ bool b = isNull();
+ d->clear();
+ d->value.i = i;
+ d->typ = Int;
+ d->is_null = b;
+ }
+ return d->value.i;
+}
+
+/*!
+ Returns the variant's value as unsigned int reference.
+*/
+uint& TQVariant::asUInt()
+{
+ detach();
+ if ( d->typ != UInt ) {
+ uint u = toUInt();
+ bool b = isNull();
+ d->clear();
+ d->value.u = u;
+ d->typ = UInt;
+ d->is_null = b;
+ }
+ return d->value.u;
+}
+
+/*!
+ Returns the variant's value as long long reference.
+*/
+TQ_LLONG& TQVariant::asLongLong()
+{
+ detach();
+ if ( d->typ != LongLong ) {
+ TQ_LLONG ll = toLongLong();
+ bool b = isNull();
+ d->clear();
+ d->value.ll = ll;
+ d->typ = LongLong;
+ d->is_null = b;
+ }
+ return d->value.ll;
+}
+
+/*!
+ Returns the variant's value as unsigned long long reference.
+*/
+TQ_ULLONG& TQVariant::asULongLong()
+{
+ detach();
+ if ( d->typ != ULongLong ) {
+ TQ_ULLONG ull = toULongLong();
+ bool b = isNull();
+ d->clear();
+ d->value.ull = ull;
+ d->typ = ULongLong;
+ d->is_null = b;
+ }
+ return d->value.ull;
+}
+
+/*!
+ Returns the variant's value as bool reference.
+*/
+bool& TQVariant::asBool()
+{
+ detach();
+ if ( d->typ != Bool ) {
+ bool b = toBool();
+ bool nb = isNull();
+ d->clear();
+ d->value.b = b;
+ d->typ = Bool;
+ d->is_null = nb;
+ }
+ return d->value.b;
+}
+
+/*!
+ Returns the variant's value as double reference.
+*/
+double& TQVariant::asDouble()
+{
+ detach();
+ if ( d->typ != Double ) {
+ double dbl = toDouble();
+ bool b = isNull();
+ d->clear();
+ d->value.d = dbl;
+ d->typ = Double;
+ d->is_null = b;
+ }
+ return d->value.d;
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+/*!
+ Returns the variant's value as variant list reference.
+
+ Note that if you want to iterate over the list, you should iterate
+ over a copy, e.g.
+ \code
+ TQValueList<TQVariant> list = myVariant.asList();
+ TQValueList<TQVariant>::Iterator it = list.begin();
+ while( it != list.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQValueList<TQVariant>& TQVariant::asList()
+{
+ bool b = isNull();
+ if ( d->typ != List )
+ *this = TQVariant( toList() );
+ else
+ detach();
+ d->is_null = b;
+ return *((TQValueList<TQVariant>*)d->value.ptr);
+}
+
+/*!
+ Returns the variant's value as variant map reference.
+
+ Note that if you want to iterate over the map, you should iterate
+ over a copy, e.g.
+ \code
+ TQMap<TQString, TQVariant> map = myVariant.asMap();
+ TQMap<TQString, TQVariant>::Iterator it = map.begin();
+ while( it != map.end() ) {
+ myProcessing( *it );
+ ++it;
+ }
+ \endcode
+*/
+TQMap<TQString, TQVariant>& TQVariant::asMap()
+{
+ bool b = isNull();
+ if ( d->typ != Map )
+ *this = TQVariant( toMap() );
+ else
+ detach();
+ d->is_null = b;
+ return *((TQMap<TQString,TQVariant>*)d->value.ptr);
+}
+#endif
+
+/*!
+ Returns TRUE if the variant's type can be cast to the requested
+ type, \a t. Such casting is done automatically when calling the
+ toInt(), toBool(), ... or asInt(), asBool(), ... methods.
+
+ The following casts are done automatically:
+ \table
+ \header \i Type \i Automatically Cast To
+ \row \i Bool \i Double, Int, UInt, LongLong, ULongLong, String, CString, ByteArray
+ \row \i Color \i String. CString. ByteArray
+ \row \i Date \i String, CString, ByteArray, DateTime
+ \row \i DateTime \i String, CString, ByteArray, Date, Time
+ \row \i Double \i String, CString, ByteArray, Int, Bool, UInt, LongLong, ULongLong
+ \row \i Font \i String, CString, ByteArray
+ \row \i Int \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i LongLong \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i ULongLong \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i List \i StringList (if the list tqcontains only strings or
+ something that can be cast to a string)
+ \row \i String \i CString, ByteArray, CString, Int, UInt, Bool, Double, Date,
+ Time, DateTime, KeySequence, Font, Color
+ \row \i CString \i String, ByteArray, Int, UInt, Bool, Double, Date, ULongLong, LongLong
+ \row \i ByteArray \i String, CString, Int, UInt, Bool, Double, Date, ULongLong, LongLong
+ \row \i StringList \i List
+ \row \i Time \i String
+ \row \i Int \i String, CString, ByteArray, Double, Bool, UInt, LongLong, ULongLong, KeySequence
+ \row \i KeySequence \i String, CString, ByteArray, Int, UInt, LongLong, ULongLong
+ \endtable
+*/
+bool TQVariant::canCast( Type t ) const
+{
+ if ( Type( d->typ ) == t )
+ return TRUE;
+
+ switch ( t ) {
+ case Bool:
+ case Double:
+ if (d->typ == KeySequence)
+ break;
+ case Int:
+ case UInt:
+ case LongLong:
+ case ULongLong:
+ switch(d->typ) {
+ case Bool:
+ case ByteArray:
+ case CString:
+ case Double:
+ case Int:
+ case KeySequence:
+ case LongLong:
+ case String:
+ case UInt:
+ case ULongLong:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case CString:
+ case ByteArray:
+ case String:
+ switch(d->typ) {
+ case Bool:
+ case ByteArray:
+ case CString:
+ case Color:
+ case Date:
+ case DateTime:
+ case Double:
+ case Font:
+ case Int:
+ case KeySequence:
+ case LongLong:
+ case String:
+ case Time:
+ case UInt:
+ case ULongLong:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case Time:
+ if (d->typ == Date)
+ break;
+ case Date:
+ case DateTime:
+ switch(d->typ) {
+ case ByteArray:
+ case CString:
+ case Date:
+ case DateTime:
+ case String:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case KeySequence:
+ switch(d->typ) {
+ case ByteArray:
+ case CString:
+ case Int:
+ case UInt:
+ case LongLong:
+ case ULongLong:
+ case Double:
+ case String:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+ case Font:
+ case Color:
+ switch(d->typ) {
+ case ByteArray:
+ case CString:
+ case String:
+ return TRUE;
+ default: break;
+ }
+ break;
+
+#ifndef TQT_NO_STRINGLIST
+ case List:
+ return d->typ == StringList;
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case StringList:
+ if ( d->typ == List ) {
+ TQValueList<TQVariant>::ConstIterator it = listBegin();
+ TQValueList<TQVariant>::ConstIterator end = listEnd();
+ for( ; it != end; ++it ) {
+ if ( !(*it).canCast( String ) )
+ return FALSE;
+ }
+ return TRUE;
+ }
+#endif
+ case Invalid:
+ case Map:
+ case Pixmap:
+ case Brush:
+ case Rect:
+ case Size:
+ case Palette:
+ case ColorGroup:
+ case IconSet:
+ case Point:
+ case Image:
+ case PointArray:
+ case Region:
+ case Bitmap:
+ case Cursor:
+ case SizePolicy:
+ case BitArray:
+ case Pen:
+ break;
+ }
+ return FALSE;
+}
+
+/*!
+ Casts the variant to the requested type. If the cast cannot be
+ done, the variant is set to the default value of the requested
+ type (e.g. an empty string if the requested type \a t is
+ TQVariant::String, an empty point array if the requested type \a t
+ is TQVariant::PointArray, etc). Returns TRUE if the current type of
+ the variant was successfully cast; otherwise returns FALSE.
+
+ \sa canCast()
+*/
+
+bool TQVariant::cast( Type t )
+{
+ switch ( t ) {
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ asMap();
+ break;
+ case TQVariant::List:
+ asList();
+ break;
+#endif
+ case TQVariant::String:
+ asString();
+ break;
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+ asStringList();
+ break;
+#endif
+ case TQVariant::Font:
+ asFont();
+ break;
+ case TQVariant::Pixmap:
+ asPixmap();
+ break;
+ case TQVariant::Brush:
+ asBrush();
+ break;
+ case TQVariant::Rect:
+ asRect();
+ break;
+ case TQVariant::Size:
+ asSize();
+ break;
+ case TQVariant::Color:
+ asColor();
+ break;
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ asPalette();
+ break;
+ case TQVariant::ColorGroup:
+ asColorGroup();
+ break;
+#endif
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ asIconSet();
+ break;
+#endif
+ case TQVariant::Point:
+ asPoint();
+ break;
+ case TQVariant::Image:
+ asImage();
+ break;
+ case TQVariant::Int:
+ asInt();
+ break;
+ case TQVariant::UInt:
+ asUInt();
+ break;
+ case TQVariant::Bool:
+ asBool();
+ break;
+ case TQVariant::Double:
+ asDouble();
+ break;
+ case TQVariant::CString:
+ asCString();
+ break;
+ case TQVariant::PointArray:
+ asPointArray();
+ break;
+ case TQVariant::Region:
+ asRegion();
+ break;
+ case TQVariant::Bitmap:
+ asBitmap();
+ break;
+ case TQVariant::Cursor:
+ asCursor();
+ break;
+ case TQVariant::SizePolicy:
+ asSizePolicy();
+ break;
+ case TQVariant::Date:
+ asDate();
+ break;
+ case TQVariant::Time:
+ asTime();
+ break;
+ case TQVariant::DateTime:
+ asDateTime();
+ break;
+ case TQVariant::ByteArray:
+ asByteArray();
+ break;
+ case TQVariant::BitArray:
+ asBitArray();
+ break;
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+ asKeySequence();
+ break;
+#endif
+ case TQVariant::Pen:
+ asPen();
+ break;
+ case TQVariant::LongLong:
+ asLongLong();
+ break;
+ case TQVariant::ULongLong:
+ asULongLong();
+ break;
+ default:
+ case TQVariant::Invalid:
+ (*this) = TQVariant();
+ }
+ return canCast( t );
+}
+
+/*!
+ Compares this TQVariant with \a v and returns TRUE if they are
+ equal; otherwise returns FALSE.
+*/
+
+bool TQVariant::operator==( const TQVariant &v ) const
+{
+ if (isNumeric(v.type()) && canCast(v.type())) {
+ bool ok;
+ switch(v.type()) {
+ case Bool:
+ return toBool() == v.toBool();
+ case Int:
+ {
+ int val = toInt(&ok);
+ return (ok && val == v.toInt());
+ }
+ case UInt:
+ {
+ uint val = toUInt(&ok);
+ return (ok && val == v.toUInt());
+ }
+
+ case Double:
+ {
+ double val = toDouble(&ok);
+ return (ok && val == v.toDouble());
+ }
+
+ case LongLong:
+ {
+ TQ_LLONG val = toLongLong(&ok);
+ return (ok && val == v.toLongLong());
+ }
+
+ case ULongLong:
+ {
+ TQ_ULLONG val = toULongLong(&ok);
+ return (ok && val == v.toULongLong());
+ }
+
+ default:
+ TQ_ASSERT(FALSE);
+ }
+ }
+
+ if (!v.canCast(d->typ)) {
+ return FALSE;
+ }
+
+ switch( d->typ ) {
+ case Cursor:
+#ifndef TQT_NO_CURSOR
+ return v.toCursor().tqshape() == toCursor().tqshape();
+#endif
+ case Bitmap:
+ return v.toBitmap().serialNumber() == toBitmap().serialNumber();
+ case PointArray:
+ return v.toPointArray() == toPointArray();
+ case Region:
+ return v.toRegion() == toRegion();
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case List:
+ return v.toList() == toList();
+ case Map: {
+ if ( v.toMap().count() != toMap().count() )
+ return FALSE;
+ TQMap<TQString, TQVariant>::ConstIterator it = v.toMap().begin();
+ TQMap<TQString, TQVariant>::ConstIterator it2 = toMap().begin();
+ while ( it != v.toMap().end() ) {
+ if ( *it != *it2 )
+ return FALSE;
+ ++it;
+ ++it2;
+ }
+ return TRUE;
+ }
+#endif
+ case String:
+ return v.toString() == toString();
+ case CString:
+ return v.toCString() == toCString();
+#ifndef TQT_NO_STRINGLIST
+ case StringList:
+ return v.toStringList() == toStringList();
+#endif
+ case Font:
+ return v.toFont() == toFont();
+ case Pixmap:
+ return v.toPixmap().serialNumber() == toPixmap().serialNumber();
+ case Image:
+ return v.toImage() == toImage();
+ case Brush:
+ return v.toBrush() == toBrush();
+ case Point:
+ return v.toPoint() == toPoint();
+ case Rect:
+ return v.toRect() == toRect();
+ case Size:
+ return v.toSize() == toSize();
+ case Color:
+ return v.toColor() == toColor();
+#ifndef TQT_NO_PALETTE
+ case Palette:
+ return v.toPalette() == toPalette();
+ case ColorGroup:
+ return v.toColorGroup() == toColorGroup();
+#endif
+#ifndef TQT_NO_ICONSET
+ case IconSet:
+ return v.toIconSet().pixmap().serialNumber()
+ == toIconSet().pixmap().serialNumber();
+#endif
+ case Int:
+ return v.toInt() == toInt();
+ case UInt:
+ return v.toUInt() == toUInt();
+ case LongLong:
+ return v.toLongLong() == toLongLong();
+ case ULongLong:
+ return v.toULongLong() == toULongLong();
+ case Bool:
+ return v.toBool() == toBool();
+ case Double:
+ return v.toDouble() == toDouble();
+ case SizePolicy:
+ return v.toSizePolicy() == toSizePolicy();
+ case Date:
+ return v.toDate() == toDate();
+ case Time:
+ return v.toTime() == toTime();
+ case DateTime:
+ return v.toDateTime() == toDateTime();
+ case ByteArray:
+ return v.toByteArray() == toByteArray();
+ case BitArray:
+ return v.toBitArray() == toBitArray();
+#ifndef TQT_NO_ACCEL
+ case KeySequence:
+ return v.toKeySequence() == toKeySequence();
+#endif
+ case Pen:
+ return v.toPen() == toPen();
+ case Invalid:
+ break;
+ }
+ return FALSE;
+}
+
+/*!
+ Compares this TQVariant with \a v and returns TRUE if they are not
+ equal; otherwise returns FALSE.
+*/
+
+bool TQVariant::operator!=( const TQVariant &v ) const
+{
+ return !( v == *this );
+}
+
+
+/*! \internal
+
+ Reads or sets the variant type and ptr
+ */
+void* TQVariant::rawAccess( void* ptr, Type typ, bool deepCopy )
+{
+ if ( ptr ) {
+ clear();
+ d->typ = typ;
+ d->value.ptr = ptr;
+ d->is_null = FALSE;
+ if ( deepCopy ) {
+ TQVariant::Private* p = new Private( d );
+ d->typ = Invalid;
+ delete d;
+ d = p;
+ }
+ }
+
+ if ( !deepCopy )
+ return d->value.ptr;
+ TQVariant::Private* p = new Private( d );
+ void *ret = (void*)p->value.ptr;
+ p->typ = Invalid;
+ delete p;
+ return ret;
+}
+
+/*!
+ Returns TRUE if this is a NULL variant, FALSE otherwise.
+*/
+bool TQVariant::isNull() const
+{
+ switch( d->typ )
+ {
+ case TQVariant::Bitmap:
+ return ((TQBitmap*) d->value.ptr)->isNull();
+ case TQVariant::Region:
+ return ((TQRegion*) d->value.ptr)->isNull();
+ case TQVariant::PointArray:
+ return ((TQPointArray*) d->value.ptr)->isNull();
+ case TQVariant::String:
+ return ((TQString*) d->value.ptr)->isNull();
+ case TQVariant::CString:
+ return ((TQCString*) d->value.ptr)->isNull();
+ case TQVariant::Pixmap:
+ return ((TQPixmap*) d->value.ptr)->isNull();
+ case TQVariant::Image:
+ return ((TQImage*) d->value.ptr)->isNull();
+ case TQVariant::Point:
+ return ((TQPoint*) d->value.ptr)->isNull();
+ case TQVariant::Rect:
+ return ((TQRect*) d->value.ptr)->isNull();
+ case TQVariant::Size:
+ return ((TQSize*) d->value.ptr)->isNull();
+#ifndef TQT_NO_ICONSET
+ case TQVariant::IconSet:
+ return ((TQIconSet*) d->value.ptr)->isNull();
+#endif
+ case TQVariant::Date:
+ return ((TQDate*) d->value.ptr)->isNull();
+ case TQVariant::Time:
+ return ((TQTime*) d->value.ptr)->isNull();
+ case TQVariant::DateTime:
+ return ((TQDateTime*) d->value.ptr)->isNull();
+ case TQVariant::ByteArray:
+ return ((TQByteArray*) d->value.ptr)->isNull();
+ case TQVariant::BitArray:
+ return ((TQBitArray*) d->value.ptr)->isNull();
+ case TQVariant::Cursor:
+#ifndef TQT_NO_STRINGLIST
+ case TQVariant::StringList:
+#endif //TQT_NO_STRINGLIST
+ case TQVariant::Font:
+ case TQVariant::Brush:
+ case TQVariant::Color:
+#ifndef TQT_NO_PALETTE
+ case TQVariant::Palette:
+ case TQVariant::ColorGroup:
+#endif
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ case TQVariant::Map:
+ case TQVariant::List:
+#endif
+ case TQVariant::SizePolicy:
+#ifndef TQT_NO_ACCEL
+ case TQVariant::KeySequence:
+#endif
+ case TQVariant::Pen:
+ case TQVariant::Invalid:
+ case TQVariant::Int:
+ case TQVariant::UInt:
+ case TQVariant::LongLong:
+ case TQVariant::ULongLong:
+ case TQVariant::Bool:
+ case TQVariant::Double:
+ break;
+ }
+ return d->is_null;
+}
+#endif //TQT_NO_VARIANT
+
+#endif // USE_QT4 \ No newline at end of file
diff --git a/tqtinterface/qt4/src/kernel/tqvariant.h b/tqtinterface/qt4/src/kernel/tqvariant.h
new file mode 100644
index 0000000..5fb5e65
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqvariant.h
@@ -0,0 +1,642 @@
+/****************************************************************************
+**
+** Definition of TQVariant class
+**
+** Created : 990414
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQVARIANT_H
+#define TQVARIANT_H
+
+#include "tqtglobaldefines.h"
+#include "tqnamespace.h"
+
+#ifndef TQT_H
+#include "tqstring.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+
+#include "tqvaluelist.h"
+#include "tqstringlist.h"
+#include "tqmap.h"
+#include <Qt/qvariant.h>
+
+#endif // USE_QT4
+
+#ifndef TQT_NO_VARIANT
+class TQString;
+class TQCString;
+class TQFont;
+class TQPixmap;
+class TQBrush;
+class TQRect;
+class TQPoint;
+class TQImage;
+class TQSize;
+class TQColor;
+class TQPalette;
+class TQColorGroup;
+class TQIconSet;
+class TQDataStream;
+class TQPointArray;
+class TQRegion;
+class TQBitmap;
+class TQCursor;
+class TQStringList;
+class TQSizePolicy;
+class TQDate;
+class TQTime;
+class TQDateTime;
+class TQBitArray;
+class TQKeySequence;
+class TQPen;
+// Some headers rejected after TQVariant declaration for GCC 2.7.* compatibility
+class TQVariant;
+#ifndef TQT_NO_TEMPLATE_VARIANT
+template <class T> class TQValueList;
+template <class T> class TQValueListConstIterator;
+template <class T> class TQValueListNode;
+template <class Key, class T> class TQMap;
+template <class Key, class T> class TQMapConstIterator;
+#endif
+
+#ifdef USE_QT4
+
+#include "tqtenuminheritance.h"
+
+class TQ_EXPORT TQVariant : public QVariant, virtual public TQt
+{
+public:
+ // [FIXME] Should these line up with a Qt4 structure?
+ // Also, make sure they don't collide with QVariant::Type!
+ enum TQV_NewTypes {
+ CString = (QVariant::Type)150,
+ ColorGroup = (QVariant::Type)151,
+ IconSet = (QVariant::Type)152,
+ PointArray = (QVariant::Type)153
+ };
+// typedef TQTInheritEnum< TQV_NewTypes, QVariant::Type > Type;
+ typedef TQTInheritEnum< TQV_NewTypes, QVariant::Type > TQType;
+
+ TQVariant() : QVariant() {}
+ TQVariant( const QVariant &s );
+#ifndef TQT_NO_DATASTREAM
+ TQVariant( TQDataStream &s );
+#endif
+ TQVariant( const TQString &s );
+ TQVariant( const TQCString &s );
+ TQVariant( const char *s );
+#ifndef TQT_NO_STRINGLIST
+ TQVariant( const TQStringList &s );
+#endif
+ TQVariant( const TQFont &s );
+ TQVariant( const TQPixmap &s );
+ TQVariant( const TQImage &s );
+ TQVariant( const TQBrush &s );
+ TQVariant( const TQPoint &s );
+ TQVariant( const TQRect &s );
+ TQVariant( const TQSize &s );
+ TQVariant( const TQColor &s );
+ TQVariant( const TQPalette &s );
+ TQVariant( const TQColorGroup &s );
+ TQVariant( const TQIconSet &s );
+ TQVariant( const TQPointArray &s );
+ TQVariant( const TQRegion &s );
+ TQVariant( const TQBitmap &s );
+ TQVariant( const TQCursor &s );
+ TQVariant( const TQDate &s );
+ TQVariant( const TQTime &s );
+ TQVariant( const TQDateTime &s );
+ TQVariant( const TQByteArray &s );
+ TQVariant( const TQBitArray &s );
+#ifndef TQT_NO_ACCEL
+ TQVariant( const TQKeySequence &s );
+#endif
+ TQVariant( const TQPen &s );
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ TQVariant( const TQValueList<TQVariant>&s );
+ TQVariant( const TQMap<TQString,TQVariant>&s );
+#endif
+ TQVariant( int s ) : QVariant( s ) {}
+ TQVariant( uint s ) : QVariant( s ) {}
+ TQVariant( TQ_LLONG s ) : QVariant( s ) {}
+ TQVariant( TQ_ULLONG s ) : QVariant( s ) {}
+// TQVariant( bool s, int t ) : QVariant( s, t ) {}
+ TQVariant( bool s, int t ) : QVariant( s ) { TQ_UNUSED(t); }
+ TQVariant( double s ) : QVariant( s ) {}
+ TQVariant( TQSizePolicy s );
+
+ const TQFont toFont() const;
+
+ inline bool canCast(Type t) const { return canConvert(t); }
+ inline bool cast(Type t) { return convert(t); }
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ TQValueListConstIterator<TQString> stringListBegin() const;
+ TQValueListConstIterator<TQString> stringListEnd() const;
+ TQValueListConstIterator<TQVariant> listBegin() const;
+ TQValueListConstIterator<TQVariant> listEnd() const;
+ TQMapConstIterator<TQString,TQVariant> mapBegin() const;
+ TQMapConstIterator<TQString,TQVariant> mapEnd() const;
+ TQMapConstIterator<TQString,TQVariant> mapFind( const TQString& ) const;
+#endif
+
+ TQString& asString();
+ TQCString& asCString();
+#ifndef TQT_NO_STRINGLIST
+ TQStringList& asStringList();
+#endif
+ TQFont& asFont();
+ TQPixmap& asPixmap();
+ TQImage& asImage();
+ TQBrush& asBrush();
+ TQPoint& asPoint();
+ TQRect& asRect();
+ TQSize& asSize();
+ TQColor& asColor();
+ TQPalette& asPalette();
+ TQColorGroup& asColorGroup();
+ TQIconSet& asIconSet();
+ TQPointArray& asPointArray();
+ TQBitmap& asBitmap();
+ TQRegion& asRegion();
+ TQCursor& asCursor();
+ TQDate& asDate();
+ TQTime& asTime();
+ TQDateTime& asDateTime();
+ TQByteArray& asByteArray();
+ TQBitArray& asBitArray();
+#ifndef TQT_NO_ACCEL
+ TQKeySequence& asKeySequence();
+#endif
+ TQPen& asPen();
+ int& asInt();
+ uint& asUInt();
+ TQ_LLONG& asLongLong();
+ TQ_ULLONG& asULongLong();
+ bool& asBool();
+ double& asDouble();
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ TQValueList<TQVariant>& asList();
+ TQMap<TQString,TQVariant>& asMap();
+#endif
+ TQSizePolicy& asSizePolicy();
+
+ const TQString toString() const;
+ const TQCString toCString() const;
+#ifndef TQT_NO_STRINGLIST
+ const TQStringList toStringList() const;
+#endif
+// const TQFont toFont() const;
+ const TQPixmap toPixmap() const;
+ const TQImage toImage() const;
+ const TQBrush toBrush() const;
+ const TQPoint toPoint() const;
+ const TQRect toRect() const;
+ const TQSize toSize() const;
+ const TQColor toColor() const;
+ const TQPalette toPalette() const;
+ const TQColorGroup toColorGroup() const;
+ const TQIconSet toIconSet() const;
+ const TQPointArray toPointArray() const;
+ const TQBitmap toBitmap() const;
+ const TQRegion toRegion() const;
+ const TQCursor toCursor() const;
+ const TQDate toDate() const;
+ const TQTime toTime() const;
+ const TQDateTime toDateTime() const;
+ const TQByteArray toByteArray() const;
+ const TQBitArray toBitArray() const;
+#ifndef TQT_NO_ACCEL
+ const TQKeySequence toKeySequence() const;
+#endif
+ const TQPen toPen() const;
+// int toInt( bool * ok=0 ) const;
+// uint toUInt( bool * ok=0 ) const;
+// TQ_LLONG toLongLong( bool * ok=0 ) const;
+// TQ_ULLONG toULongLong( bool * ok=0 ) const;
+// bool toBool() const;
+// double toDouble( bool * ok=0 ) const;
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ const TQValueList<TQVariant> toList() const;
+ const TQMap<TQString,TQVariant> toMap() const;
+#endif
+ TQSizePolicy toSizePolicy() const;
+
+// using QVariant::operator=;
+// TQVariant& operator= ( const QVariant& );
+// inline TQVariant& operator= ( const QVariant&v ) {
+// QVariant& ref = QVariant::operator=(v);
+// return static_cast<TQVariant*>(&ref);
+// }
+
+public:
+ // Interoperability
+ static const TQVariant& convertFromQVariant( QVariant& qvr );
+};
+
+// Interoperability
+inline static const TQVariant& convertFromQVariant( const QVariant& qvr ) {
+ return (*static_cast<const TQVariant*>(&qvr));
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+inline TQValueListConstIterator<TQString> TQVariant::stringListBegin() const
+{
+ if ( d.type != StringList )
+ return TQValueListConstIterator<TQString>();
+ return ((const TQStringList*)d.data.ptr)->begin();
+}
+
+inline TQValueListConstIterator<TQString> TQVariant::stringListEnd() const
+{
+ if ( d.type != StringList )
+ return TQValueListConstIterator<TQString>();
+ return ((const TQStringList*)d.data.ptr)->end();
+}
+
+inline TQValueListConstIterator<TQVariant> TQVariant::listBegin() const
+{
+ if ( d.type != List )
+ return TQValueListConstIterator<TQVariant>();
+ return ((const TQValueList<TQVariant>*)d.data.ptr)->begin();
+}
+
+inline TQValueListConstIterator<TQVariant> TQVariant::listEnd() const
+{
+ if ( d.type != List )
+ return TQValueListConstIterator<TQVariant>();
+ return ((const TQValueList<TQVariant>*)d.data.ptr)->end();
+}
+
+inline TQMapConstIterator<TQString,TQVariant> TQVariant::mapBegin() const
+{
+ if ( d.type != Map )
+ return TQMapConstIterator<TQString,TQVariant>();
+ return ((const TQMap<TQString,TQVariant>*)d.data.ptr)->begin();
+}
+
+inline TQMapConstIterator<TQString,TQVariant> TQVariant::mapEnd() const
+{
+ if ( d.type != Map )
+ return TQMapConstIterator<TQString,TQVariant>();
+ return ((const TQMap<TQString,TQVariant>*)d.data.ptr)->end();
+}
+
+inline TQMapConstIterator<TQString,TQVariant> TQVariant::mapFind( const TQString& key ) const
+{
+ if ( d.type != Map )
+ return TQMapConstIterator<TQString,TQVariant>();
+ return ((const TQMap<TQString,TQVariant>*)d.data.ptr)->tqfind( key );
+}
+#endif
+
+#else // USE_QT4
+
+class TQ_EXPORT TQVariant
+{
+public:
+ enum Type {
+ Invalid,
+ Map,
+ List,
+ String,
+ StringList,
+ Font,
+ Pixmap,
+ Brush,
+ Rect,
+ Size,
+ Color,
+ Palette,
+ ColorGroup,
+ IconSet,
+ Point,
+ Image,
+ Int,
+ UInt,
+ Bool,
+ Double,
+ CString,
+ PointArray,
+ Region,
+ Bitmap,
+ Cursor,
+ SizePolicy,
+ Date,
+ Time,
+ DateTime,
+ ByteArray,
+ BitArray,
+ KeySequence,
+ Pen,
+ LongLong,
+ ULongLong
+ };
+
+ TQVariant();
+ ~TQVariant();
+ TQVariant( const TQVariant& );
+#ifndef TQT_NO_DATASTREAM
+ TQVariant( TQDataStream& s );
+#endif
+ TQVariant( const TQString& );
+ TQVariant( const TQCString& );
+ TQVariant( const char* );
+#ifndef TQT_NO_STRINGLIST
+ TQVariant( const TQStringList& );
+#endif
+ TQVariant( const TQFont& );
+ TQVariant( const TQPixmap& );
+ TQVariant( const TQImage& );
+ TQVariant( const TQBrush& );
+ TQVariant( const TQPoint& );
+ TQVariant( const TQRect& );
+ TQVariant( const TQSize& );
+ TQVariant( const TQColor& );
+ TQVariant( const TQPalette& );
+ TQVariant( const TQColorGroup& );
+ TQVariant( const TQIconSet& );
+ TQVariant( const TQPointArray& );
+ TQVariant( const TQRegion& );
+ TQVariant( const TQBitmap& );
+ TQVariant( const TQCursor& );
+ TQVariant( const TQDate& );
+ TQVariant( const TQTime& );
+ TQVariant( const TQDateTime& );
+ TQVariant( const TQByteArray& );
+ TQVariant( const TQBitArray& );
+#ifndef TQT_NO_ACCEL
+ TQVariant( const TQKeySequence& );
+#endif
+ TQVariant( const TQPen& );
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ TQVariant( const TQValueList<TQVariant>& );
+ TQVariant( const TQMap<TQString,TQVariant>& );
+#endif
+ TQVariant( int );
+ TQVariant( uint );
+ TQVariant( TQ_LLONG );
+ TQVariant( TQ_ULLONG );
+ // ### Problems on some compilers ?
+ TQVariant( bool, int );
+ TQVariant( double );
+ TQVariant( TQSizePolicy );
+
+ TQVariant& operator= ( const TQVariant& );
+ bool operator==( const TQVariant& ) const;
+ bool operator!=( const TQVariant& ) const;
+
+ Type type() const;
+ const char* typeName() const;
+
+ bool canCast( Type ) const;
+ bool cast( Type );
+
+ bool isValid() const;
+ bool isNull() const;
+
+ void clear();
+
+ const TQString toString() const;
+ const TQCString toCString() const;
+#ifndef TQT_NO_STRINGLIST
+ const TQStringList toStringList() const;
+#endif
+ const TQFont toFont() const;
+ const TQPixmap toPixmap() const;
+ const TQImage toImage() const;
+ const TQBrush toBrush() const;
+ const TQPoint toPoint() const;
+ const TQRect toRect() const;
+ const TQSize toSize() const;
+ const TQColor toColor() const;
+ const TQPalette toPalette() const;
+ const TQColorGroup toColorGroup() const;
+ const TQIconSet toIconSet() const;
+ const TQPointArray toPointArray() const;
+ const TQBitmap toBitmap() const;
+ const TQRegion toRegion() const;
+ const TQCursor toCursor() const;
+ const TQDate toDate() const;
+ const TQTime toTime() const;
+ const TQDateTime toDateTime() const;
+ const TQByteArray toByteArray() const;
+ const TQBitArray toBitArray() const;
+#ifndef TQT_NO_ACCEL
+ const TQKeySequence toKeySequence() const;
+#endif
+ const TQPen toPen() const;
+ int toInt( bool * ok=0 ) const;
+ uint toUInt( bool * ok=0 ) const;
+ TQ_LLONG toLongLong( bool * ok=0 ) const;
+ TQ_ULLONG toULongLong( bool * ok=0 ) const;
+ bool toBool() const;
+ double toDouble( bool * ok=0 ) const;
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ const TQValueList<TQVariant> toList() const;
+ const TQMap<TQString,TQVariant> toMap() const;
+#endif
+ TQSizePolicy toSizePolicy() const;
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ TQValueListConstIterator<TQString> stringListBegin() const;
+ TQValueListConstIterator<TQString> stringListEnd() const;
+ TQValueListConstIterator<TQVariant> listBegin() const;
+ TQValueListConstIterator<TQVariant> listEnd() const;
+ TQMapConstIterator<TQString,TQVariant> mapBegin() const;
+ TQMapConstIterator<TQString,TQVariant> mapEnd() const;
+ TQMapConstIterator<TQString,TQVariant> mapFind( const TQString& ) const;
+#endif
+ TQString& asString();
+ TQCString& asCString();
+#ifndef TQT_NO_STRINGLIST
+ TQStringList& asStringList();
+#endif
+ TQFont& asFont();
+ TQPixmap& asPixmap();
+ TQImage& asImage();
+ TQBrush& asBrush();
+ TQPoint& asPoint();
+ TQRect& asRect();
+ TQSize& asSize();
+ TQColor& asColor();
+ TQPalette& asPalette();
+ TQColorGroup& asColorGroup();
+ TQIconSet& asIconSet();
+ TQPointArray& asPointArray();
+ TQBitmap& asBitmap();
+ TQRegion& asRegion();
+ TQCursor& asCursor();
+ TQDate& asDate();
+ TQTime& asTime();
+ TQDateTime& asDateTime();
+ TQByteArray& asByteArray();
+ TQBitArray& asBitArray();
+#ifndef TQT_NO_ACCEL
+ TQKeySequence& asKeySequence();
+#endif
+ TQPen& asPen();
+ int& asInt();
+ uint& asUInt();
+ TQ_LLONG& asLongLong();
+ TQ_ULLONG& asULongLong();
+ bool& asBool();
+ double& asDouble();
+#ifndef TQT_NO_TEMPLATE_VARIANT
+ TQValueList<TQVariant>& asList();
+ TQMap<TQString,TQVariant>& asMap();
+#endif
+ TQSizePolicy& asSizePolicy();
+
+#ifndef TQT_NO_DATASTREAM
+ void load( TQDataStream& );
+ void save( TQDataStream& ) const;
+#endif
+ static const char* typeToName( Type typ );
+ static Type nameToType( const char* name );
+
+private:
+ void detach();
+
+ class Private : public TQShared
+ {
+ public:
+ Private();
+ Private( Private* );
+ ~Private();
+
+ void clear();
+
+ Type typ;
+ union
+ {
+ uint u;
+ int i;
+ TQ_LLONG ll;
+ TQ_ULLONG ull;
+ bool b;
+ double d;
+ void *ptr;
+ } value;
+ uint is_null : 1; // ## 4.0 merge with typ
+ };
+
+ Private* d;
+
+public:
+ void* rawAccess( void* ptr = 0, Type typ = Invalid, bool deepCopy = FALSE );
+};
+
+// down here for GCC 2.7.* compatibility
+#ifndef TQT_H
+#include "tqvaluelist.h"
+#include "tqstringlist.h"
+#include "tqmap.h"
+#endif // TQT_H
+
+inline TQVariant::Type TQVariant::type() const
+{
+ return d->typ;
+}
+
+inline bool TQVariant::isValid() const
+{
+ return (d->typ != Invalid);
+}
+
+#ifndef TQT_NO_TEMPLATE_VARIANT
+inline TQValueListConstIterator<TQString> TQVariant::stringListBegin() const
+{
+ if ( d->typ != StringList )
+ return TQValueListConstIterator<TQString>();
+ return ((const TQStringList*)d->value.ptr)->begin();
+}
+
+inline TQValueListConstIterator<TQString> TQVariant::stringListEnd() const
+{
+ if ( d->typ != StringList )
+ return TQValueListConstIterator<TQString>();
+ return ((const TQStringList*)d->value.ptr)->end();
+}
+
+inline TQValueListConstIterator<TQVariant> TQVariant::listBegin() const
+{
+ if ( d->typ != List )
+ return TQValueListConstIterator<TQVariant>();
+ return ((const TQValueList<TQVariant>*)d->value.ptr)->begin();
+}
+
+inline TQValueListConstIterator<TQVariant> TQVariant::listEnd() const
+{
+ if ( d->typ != List )
+ return TQValueListConstIterator<TQVariant>();
+ return ((const TQValueList<TQVariant>*)d->value.ptr)->end();
+}
+
+inline TQMapConstIterator<TQString,TQVariant> TQVariant::mapBegin() const
+{
+ if ( d->typ != Map )
+ return TQMapConstIterator<TQString,TQVariant>();
+ return ((const TQMap<TQString,TQVariant>*)d->value.ptr)->begin();
+}
+
+inline TQMapConstIterator<TQString,TQVariant> TQVariant::mapEnd() const
+{
+ if ( d->typ != Map )
+ return TQMapConstIterator<TQString,TQVariant>();
+ return ((const TQMap<TQString,TQVariant>*)d->value.ptr)->end();
+}
+
+inline TQMapConstIterator<TQString,TQVariant> TQVariant::mapFind( const TQString& key ) const
+{
+ if ( d->typ != Map )
+ return TQMapConstIterator<TQString,TQVariant>();
+ return ((const TQMap<TQString,TQVariant>*)d->value.ptr)->tqfind( key );
+}
+#endif
+
+#ifndef TQT_NO_DATASTREAM
+TQ_EXPORT TQDataStream& operator>> ( TQDataStream& s, TQVariant& p );
+TQ_EXPORT TQDataStream& operator<< ( TQDataStream& s, const TQVariant& p );
+TQ_EXPORT TQDataStream& operator>> ( TQDataStream& s, TQVariant::Type& p );
+TQ_EXPORT TQDataStream& operator<< ( TQDataStream& s, const TQVariant::Type p );
+#endif
+
+#endif // TQT_NO_VARIANT
+#endif // USE_QT4
+#endif // TQVARIANT_H
diff --git a/tqtinterface/qt4/src/kernel/tqvfbhdr.h b/tqtinterface/qt4/src/kernel/tqvfbhdr.h
new file mode 100644
index 0000000..138a356
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqvfbhdr.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** TQt/Embedded virtual framebuffer
+**
+** Created : 20000605
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** Licensees holding valid TQt Commercial licenses may use this file in
+** accordance with the TQt Commercial License Agreement provided with
+** the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQVFBHDR_H
+#define TQVFBHDR_H
+
+#ifndef TQT_H
+#include "tqcolor.h"
+#include "tqrect.h"
+#endif // TQT_H
+
+#define TQT_VFB_MOUSE_PIPE "/tmp/.qtvfb_mouse-%1"
+#define TQT_VFB_KEYBOARD_PIPE "/tmp/.qtvfb_keyboard-%1"
+
+struct TQVFbHeader
+{
+ int width;
+ int height;
+ int depth;
+ int linestep;
+ int dataoffset;
+ TQRect update;
+ bool dirty;
+ int numcols;
+ TQRgb clut[256];
+};
+
+struct TQVFbKeyData
+{
+ unsigned int tqunicode;
+ unsigned int modifiers;
+ bool press;
+ bool repeat;
+};
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqwidget.cpp b/tqtinterface/qt4/src/kernel/tqwidget.cpp
new file mode 100644
index 0000000..3bfdd86
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwidget.cpp
@@ -0,0 +1,8728 @@
+/****************************************************************************
+**
+** Implementation of TQWidget class
+**
+** Created : 931031
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+
+#include "tqobjectlist.h"
+#include "tqwidget.h"
+#include "tqwidgetlist.h"
+#include "tqwidgetintdict.h"
+#include "tqptrdict.h"
+#include "tqfocusdata.h"
+#include "tqcursor.h"
+#include "tqpixmap.h"
+#include "tqapplication.h"
+#include "tqapplication_p.h"
+#include "tqbrush.h"
+#include "tqlayout.h"
+#include "tqstylefactory.h"
+#include "tqcleanuphandler.h"
+#include "tqstyle.h"
+#include "tqmetaobject.h"
+#include "tqguardedptr.h"
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+#include "tqaccessible.h"
+#endif
+#if defined(TQ_WS_WIN)
+#include "tqt_windows.h"
+#include "tqinputcontext_p.h"
+#endif
+#if defined(TQ_WS_TQWS)
+#include "tqwsmanager_qws.h"
+#endif
+#include "tqfontdata_p.h"
+
+#ifdef USE_QT4
+
+TQObject* convertFromTQT_BASE_OBJECT_NAMEPointer( TQT_BASE_OBJECT_NAME* x ) {
+ return static_cast<TQObject*>(static_cast<TQT_BASE_OBJECT_NAME*>(x));
+}
+
+const TQObject* convertFromTQT_BASE_OBJECT_NAMEPointerConst( const TQT_BASE_OBJECT_NAME* x ) {
+ return static_cast<const TQObject*>(static_cast<const TQT_BASE_OBJECT_NAME*>(x));
+}
+
+void TQWidget::reparent(QWidget *parent, const QPoint &p, bool showIt) {
+ setParent(parent, windowFlags() & ~Qt::WindowType_Mask);
+ setGeometry(p.x(),p.y(),width(),height());
+ if (showIt) show();
+}
+
+bool TQWidget::close(bool alsoDelete) {
+ QPointer<QWidget> that = this;
+ bool accepted = QWidget::close();
+ if (alsoDelete && accepted && that)
+ deleteLater();
+ return accepted;
+}
+
+// void TQWidget::showEvent(QShowEvent *e) {
+// // if (!testAttribute(Qt::WA_Resized) && (isWindow() || !layout())) // Logic taken from Qt4 qwidget.cpp tqsetVisible...
+// // if (!testAttribute(Qt::WA_Resized))
+// // if (!isVisible())
+// // adjustSize(); // NOTE: Qt4 does not allow adjustSize to be overridden, therefore it must be called here
+// if (isVisible()) {
+// // setAttribute(Qt::WA_Resized, TRUE); //not a user resize
+// if (tqt_internal_show_called_event == FALSE) show(); // NOTE: Qt4 does not allow show to be overridden, therefore it must be called here
+// // if ( !isTopLevel() && parentWidget() ) QApplication::postEvent( parentWidget(), new TQEvent( TQEvent::LayoutHint) ); // Needed for layouts to work
+// tqt_internal_show_called_event = FALSE;
+// }
+// showEvent(static_cast<TQShowEvent*>(e));
+// }
+
+uint TQWidget::windowState() const {
+ return (uint)(QWidget::windowState());
+}
+
+void TQWidget::setWindowState(uint newstate) {
+ QWidget::setWindowState((Qt::WindowStates)newstate);
+}
+
+void TQWidget::showEvent(QShowEvent *e) {
+ if (isVisible()) {
+ // Spontaneous event
+ if (tqt_internal_show_called_event == FALSE) show(); // NOTE: Qt4 does not allow show to be overridden, therefore it must be called here
+ showEvent(static_cast<TQShowEvent*>(e));
+ }
+ else {
+ // Non-spontaneous event
+ showEvent(static_cast<TQShowEvent*>(e));
+ if (tqt_internal_show_called_event == FALSE) show(); // NOTE: Qt4 does not allow show to be overridden, therefore it must be called here
+ }
+ tqt_internal_show_called_event = FALSE;
+}
+
+void TQWidget::hideEvent(QHideEvent *e) {
+ hideEvent(static_cast<TQHideEvent*>(e));
+ if ( !isTopLevel() && parentWidget() ) QApplication::postEvent( parentWidget(), new TQEvent( TQEvent::LayoutHint) ); // Needed for layouts to work
+}
+
+void TQWidget::show() {
+ if ( testWState(WState_Visible) )
+ return;
+ tqt_internal_show_called_event = TRUE;
+ if ( !isTopLevel() && parentWidget() )
+ QApplication::postEvent( parentWidget(), new TQEvent( TQEvent::LayoutHint) ); // Needed for layouts to work
+ if (parentWidget()) {
+ if ( !isTopLevel() && !parentWidget()->isVisible() ) {
+ // return;
+ }
+ }
+ else {
+ QApplication::sendPostedEvents( this, TQEvent::ChildInserted );
+ if ( parentWidget() )
+ QApplication::sendPostedEvents( parentWidget(), TQEvent::ChildInserted );
+ // Required for Mac, not sure whether we should always do that [this? see tqwidget.cpp ::show() for Qt3.3]
+ if( isTopLevel() )
+ QApplication::sendPostedEvents(0, TQEvent::LayoutHint);
+ }
+ QWidget::show();
+}
+
+TQWidget* TQWidget::tqt_ensure_valid_widget_painting(TQWidget* w) {
+ if (w) w->setAttribute(Qt::WA_PaintOutsidePaintEvent, TRUE);
+ return w;
+}
+
+void TQWidget::showWindow() {
+ printf("[FIXME] TQWidget::showWindow unimplemented\n\r");
+}
+
+void TQWidget::hideWindow() {
+ printf("[FIXME] TQWidget::hideWindow unimplemented\n\r");
+}
+
+void TQWidget::timerEvent(QTimerEvent *e) {
+ timerEvent(static_cast<TQTimerEvent*>(e));
+}
+
+void TQWidget::childEvent(QChildEvent *e) {
+ TQT_TQOBJECT_CHILDEVENT_CONDITIONAL childEvent(static_cast<TQChildEvent*>(e));
+}
+
+void TQWidget::customEvent(QEvent *e) {
+ customEvent(static_cast<TQCustomEvent*>(e));
+}
+
+void TQWidget::tqrepaint() {
+ repaint();
+}
+
+void TQWidget::setFocus() {
+ setFocus(Qt::OtherFocusReason);
+}
+
+void TQWidget::polish() {
+ QApplication::sendPostedEvents( this, TQEvent::ChildInserted );
+ ensurePolished();
+}
+
+void TQWidget::mousePressEvent(QMouseEvent *e) {
+ TQT_TQWIDGET_FIX_BROKEN_POPUP_MOUSE_FOCUS mousePressEvent(static_cast<TQMouseEvent*>(e));
+}
+
+void TQWidget::mouseReleaseEvent(QMouseEvent *e) {
+ TQT_TQWIDGET_FIX_BROKEN_POPUP_MOUSE_FOCUS mouseReleaseEvent(static_cast<TQMouseEvent*>(e));
+}
+
+void TQWidget::mouseDoubleClickEvent(QMouseEvent *e) {
+ TQT_TQWIDGET_FIX_BROKEN_POPUP_MOUSE_FOCUS mouseDoubleClickEvent(static_cast<TQMouseEvent*>(e));
+}
+
+void TQWidget::mouseMoveEvent(QMouseEvent *e) {
+ TQT_TQWIDGET_FIX_BROKEN_POPUP_MOUSE_FOCUS mouseMoveEvent(static_cast<TQMouseEvent*>(e));
+}
+
+void TQWidget::createTLSysExtra( void ) {
+ printf("[TQT UNIMPLEMENTED CALL] createTLSysExtra()\n\r");
+}
+
+void TQWidget::destroyInputContext( void ) {
+ printf("[TQT UNIMPLEMENTED CALL] destroyInputContext()\n\r");
+}
+
+TQWidget::TQWidget( QWidget* tqparent, const char* name, WFlags f ) : QWidget( tqparent, (Qt::WindowFlags)(f&(~WTQtFlagMask)) ), TQtUpperWidgetFlags((WFlags)0) {
+ TQtUpperWidgetFlags = f & WTQtFlagMask;
+ TQT_TQWIDGET_REQUIRED_INITIALIZATION
+ static_cast<QWidget*>(this)->setObjectName(QString::fromAscii(name));
+ TQT_TQOBJECT_REQUIRED_INITIALIZATION(tqparent)
+}
+
+void TQWidget::setActiveWindow( void ) {
+ activateWindow();
+}
+
+Display * TQWidget::x11Display( void ) {
+ return this->x11Info().display();
+}
+
+int TQWidget::x11Screen( void ) {
+ return this->x11Info().screen();
+}
+
+TQWidget * TQWidget::parentWidget( bool sameWindow ) const {
+ TQ_UNUSED(sameWindow);
+ return static_cast<TQWidget*>(parentWidget());
+}
+
+TQCString TQWidget::normalizeSignalSlot( const char *signalSlot ) {
+ return TQObject::normalizeSignalSlot(signalSlot);
+}
+
+TQMetaObject *TQWidget::tqmetaObject() const {
+ return TQT_TQOBJECT_CONST(this)->tqmetaObject();
+}
+
+TQWidget * TQWidget::tqfind( WId w ) {
+ return static_cast<TQWidget*>(find(w));
+}
+
+bool TQWidget::isShown() const {
+ return !isHidden();
+}
+
+TQWidget *TQWidget::tqchildAt( int x, int y, bool includeThis ) const {
+ TQ_UNUSED(includeThis);
+ return static_cast<TQWidget*>(childAt(x, y));
+}
+
+TQWidget *TQWidget::tqchildAt( const TQPoint &p, bool includeThis ) const {
+ TQ_UNUSED(includeThis);
+ return static_cast<TQWidget*>(childAt(p));
+}
+
+TQWidget *TQWidget::tqtopLevelWidget() const {
+ return static_cast<TQWidget*>(topLevelWidget());
+}
+
+TQWExtra *TQWidget::extraData() {
+ return extra;
+}
+
+TQTLWExtra *TQWidget::topData() {
+ createTLExtra();
+ return extra->topextra;
+}
+
+void TQWidget::setName(const char *aName) {
+ TQT_TQOBJECT(this)->setName(aName);
+}
+
+TQWidget *TQWidget::parentWidget( bool sameWindow ) {
+ TQ_UNUSED(sameWindow);
+ return static_cast<TQWidget*>(this->parent());
+}
+
+bool TQWidget::isDialog() const {
+ return (windowType() == Qt::Dialog);
+}
+
+TQObject *TQWidget::child( const char *objName, const char *inheritsClass, bool recursiveSearch ) {
+ return TQT_TQOBJECT(this)->child( objName, inheritsClass, recursiveSearch );
+}
+
+const TQRect TQWidget::tqgeometry() const {
+ return TQT_TQRECT_OBJECT(geometry());
+}
+
+QSize TQWidget::sizeHint() const {
+ return tqsizeHint();
+}
+
+QSize TQWidget::minimumSizeHint() const {
+ return tqminimumSizeHint();
+}
+
+TQSize TQWidget::tqminimumSize() const {
+ return QWidget::minimumSize();
+}
+
+TQSize TQWidget::tqmaximumSize() const {
+ return QWidget::maximumSize();
+}
+
+TQColorGroup TQWidget::tqcolorGroup() const {
+ return TQColorGroup(palette());
+}
+
+void TQWidget::iconify() {
+ showMinimized();
+}
+
+void TQWidget::constPolish() const {
+ ensurePolished();
+}
+
+bool TQWidget::hasMouse() const {
+ return testAttribute(Qt::WA_UnderMouse);
+}
+
+bool TQWidget::ownCursor() const {
+ return testAttribute(Qt::WA_SetCursor);
+}
+
+bool TQWidget::ownFont() const {
+ return testAttribute(Qt::WA_SetFont);
+}
+
+const TQPixmap *TQWidget::backgroundPixmap() const {
+ return erasePixmap();
+}
+
+void TQWidget::tqsetSizePolicy(QSizePolicy qsp) {
+ setSizePolicy(qsp);
+}
+
+void TQWidget::tqsetSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical) {
+ setSizePolicy(horizontal, vertical);
+}
+
+void TQWidget::tqsetSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw) {
+ QSizePolicy sp(hor, ver);
+ sp.setHeightForWidth(hfw);
+ setSizePolicy(sp);
+}
+
+void TQWidget::setInputMethodEnabled(bool b) {
+ setAttribute(Qt::WA_InputMethodEnabled, b);
+}
+
+bool TQWidget::isInputMethodEnabled() const {
+ return testAttribute(Qt::WA_InputMethodEnabled);
+}
+
+bool TQWidget::isPopup() const {
+ return windowType() == Qt::Popup;
+}
+
+TQString TQWidget::caption() const {
+ return windowTitle();
+}
+
+void TQWidget::setCaption(const QString &c) {
+ setWindowTitle(c);
+}
+
+TQRect TQWidget::tqchildrenRect() const {
+ return childrenRect();
+}
+
+TQRegion TQWidget::tqchildrenRegion() const {
+ return childrenRegion();
+}
+
+void TQWidget::unsetFont() {
+ setFont(QFont());
+}
+
+bool TQWidget::ownPalette() const {
+ return testAttribute(Qt::WA_SetPalette);
+}
+
+void TQWidget::unsetPalette() {
+ setPalette(QPalette());
+}
+
+const TQPalette &TQWidget::tqpalette() const {
+ return TQT_TQPALETTE_OBJECT(palette());
+}
+
+bool TQWidget::isUpdatesEnabled() const {
+ return updatesEnabled();
+}
+
+void TQWidget::tqrepaint(int x, int y, int w, int h) {
+ return repaint(x, y, w, h);
+}
+
+void TQWidget::tqrepaint(const QRect &r) {
+ return repaint(r);
+}
+
+void TQWidget::tqrepaint(const QRegion &r) {
+ return repaint(r);
+}
+
+void TQWidget::tqrepaint(bool eraseme) {
+ if (eraseme) erase();
+ repaint();
+}
+
+void TQWidget::tqrepaint(int x, int y, int w, int h, bool) {
+ repaint(x,y,w,h);
+}
+
+void TQWidget::tqrepaint(const QRect &r, bool) {
+ repaint(r);
+}
+
+void TQWidget::tqrepaint(const QRegion &rgn, bool) {
+ repaint(rgn);
+}
+
+TQSizePolicy TQWidget::tqsizePolicy() const {
+ return TQT_TQSIZEPOLICY_OBJECT(sizePolicy());
+}
+
+TQPoint TQWidget::backgroundOffset() const {
+ return TQPoint();
+}
+
+bool TQWidget::tqsignalsBlocked() const {
+ return signalsBlocked();
+}
+
+TQObjectList *TQWidget::queryList( const char *inheritsClass, const char *objName, bool regexpMatch, bool recursiveSearch ) const {
+ return TQT_TQOBJECT_CONST(this)->queryList(inheritsClass, objName, regexpMatch, recursiveSearch);
+}
+
+TQWidget *TQWidget::tqfocusWidget() const {
+ return TQT_TQWIDGET(focusWidget());
+}
+
+void TQWidget::setBackgroundOrigin(BackgroundOrigin) {
+}
+
+TQWidget::BackgroundOrigin TQWidget::backgroundOrigin() const {
+ return WindowOrigin;
+}
+
+void TQWidget::setIconText(const QString &it) {
+ setWindowIconText(it);
+}
+
+void TQWidget::insertChild( TQObject *object ) {
+ TQT_TQOBJECT(this)->insertChild(object);
+}
+
+void TQWidget::removeChild( TQObject *object ) {
+ TQT_TQOBJECT(this)->removeChild(object);
+}
+
+bool TQWidget::close() {
+ return QWidget::close();
+}
+
+void TQWidget::setFocus(Qt::FocusReason reason) {
+ return QWidget::setFocus(reason);
+}
+
+void TQWidget::setBackgroundMode( TQt::BackgroundMode tqbm ) {
+ setBackgroundMode(tqbm, TQt::PaletteBackground);
+}
+
+const QColor &TQWidget::paletteForegroundColor() const {
+ return palette().color(foregroundRole());
+}
+
+void TQWidget::setPaletteForegroundColor(const QColor &c) {
+ QPalette p = palette();
+ p.setColor(foregroundRole(), c);
+ setPalette(p);
+}
+
+const QColor &TQWidget::paletteBackgroundColor() const {
+ return palette().color(backgroundRole());
+}
+
+void TQWidget::setPaletteBackgroundColor(const QColor &c) {
+ QPalette p = palette();
+ p.setColor(backgroundRole(), c);
+ setPalette(p);
+}
+
+const TQPixmap *TQWidget::paletteBackgroundPixmap() const {
+ QPalette p = palette();
+ const QPixmap& pm = p.brush(backgroundRole()).texture();
+ if (pm.isNull())
+ return 0;
+ return TQT_TQPIXMAP_CONST(&pm);
+}
+
+void TQWidget::setPaletteBackgroundPixmap(const QPixmap &pm) {
+ QPalette p = palette();
+ p.setBrush(backgroundRole(), QBrush(pm));
+ setPalette(p);
+}
+
+const TQColor &TQWidget::backgroundColor() const {
+ return TQT_TQCOLOR_OBJECT(palette().color(backgroundRole()));
+}
+
+void TQWidget::setBackgroundColor(const QColor &c) {
+ QPalette p = palette();
+ p.setColor(backgroundRole(), c);
+ setPalette(p);
+}
+
+const TQColor &TQWidget::eraseColor() const {
+ return TQT_TQCOLOR_OBJECT(palette().color(backgroundRole()));
+}
+
+void TQWidget::setEraseColor(const QColor &c) {
+ QPalette p = palette();
+ p.setColor(backgroundRole(), c);
+ setPalette(p);
+}
+
+const TQPixmap *TQWidget::erasePixmap() const {
+ QPalette p = palette();
+ const QPixmap& pm = p.brush(backgroundRole()).texture();
+ if (pm.isNull())
+ return 0;
+ return TQT_TQPIXMAP_CONST(&pm);
+}
+
+void TQWidget::setErasePixmap(const QPixmap &pm) {
+ QPalette p = palette();
+ p.setBrush(backgroundRole(), QBrush(pm));
+ setPalette(p);
+}
+
+const TQColor &TQWidget::foregroundColor() const {
+ return TQT_TQCOLOR_OBJECT(palette().color(foregroundRole()));
+}
+
+void TQWidget::erase() {
+ erase_helper(0, 0, QWidget::width(), QWidget::height());
+}
+
+void TQWidget::erase(int x, int y, int w, int h) {
+ erase_helper(x, y, w, h);
+}
+
+void TQWidget::erase(const QRect &r) {
+ erase_helper(r.x(), r.y(), r.width(), r.height());
+}
+
+const char *TQWidget::name(const char *defaultName) const {
+ TQString s = objectName();
+ return s.isEmpty()?defaultName:s.latin1_helper();
+}
+
+void TQWidget::tqsetPalette( const TQPalette &p, bool ) {
+ setPalette( p );
+}
+
+bool TQWidget::isDesktop() const {
+ return testWFlags(WType_Desktop);
+}
+
+bool TQWidget::isFocusEnabled() const {
+ return focusPolicy() != Qt::NoFocus;
+}
+
+// Qt4 handler interface
+bool TQWidget::eventFilter( QObject *q, QEvent *e ) {
+ return eventFilter(static_cast<TQObject*>(q), static_cast<TQEvent*>(e));
+}
+
+bool TQWidget::event( QEvent *e ) {
+ return event(static_cast<TQEvent*>(e));
+}
+
+#ifndef QT_NO_WHEELEVENT
+void TQWidget::wheelEvent(QWheelEvent *e) {
+ wheelEvent(static_cast<TQWheelEvent*>(e));
+}
+#endif
+
+void TQWidget::keyPressEvent(QKeyEvent *e) {
+ keyPressEvent(static_cast<TQKeyEvent*>(e));
+}
+
+void TQWidget::keyReleaseEvent(QKeyEvent *e) {
+ keyReleaseEvent(static_cast<TQKeyEvent*>(e));
+}
+
+void TQWidget::focusInEvent(QFocusEvent *e) {
+ focusInEvent(static_cast<TQFocusEvent*>(e));
+}
+
+void TQWidget::focusOutEvent(QFocusEvent *e) {
+ focusOutEvent(static_cast<TQFocusEvent*>(e));
+}
+
+void TQWidget::enterEvent(QEvent *e) {
+ enterEvent(static_cast<TQEvent*>(e));
+}
+
+void TQWidget::leaveEvent(QEvent *e) {
+ leaveEvent(static_cast<TQEvent*>(e));
+}
+
+void TQWidget::paintEvent(QPaintEvent *e) {
+ paintEvent(static_cast<TQPaintEvent*>(e));
+}
+
+void TQWidget::moveEvent(QMoveEvent *e) {
+ moveEvent(static_cast<TQMoveEvent*>(e));
+}
+
+void TQWidget::resizeEvent(QResizeEvent *e) {
+ resizeEvent(static_cast<TQResizeEvent*>(e));
+}
+
+void TQWidget::closeEvent(QCloseEvent *e) {
+ closeEvent(static_cast<TQCloseEvent*>(e));
+}
+
+#ifndef QT_NO_CONTEXTMENU
+void TQWidget::contextMenuEvent(QContextMenuEvent *e) {
+ contextMenuEvent(static_cast<TQContextMenuEvent*>(e));
+}
+#endif
+
+#ifndef QT_NO_TABLETEVENT
+void TQWidget::tabletEvent(QTabletEvent *e) {
+ tabletEvent(static_cast<TQTabletEvent*>(e));
+}
+#endif
+
+TQConnectionList *TQWidget::tqreceivers( const char* signal ) const {
+ return TQT_TQOBJECT_CONST(this)->tqreceivers(signal);
+}
+
+TQConnectionList *TQWidget::tqreceivers( int signal ) const {
+ return TQT_TQOBJECT_CONST(this)->tqreceivers(signal);
+}
+
+void TQWidget::activate_signal( int signal ) {
+ TQT_TQOBJECT(this)->activate_signal(signal);
+}
+
+void TQWidget::activate_signal( TQConnectionList *clist, TQUObject *o ) {
+ TQT_TQOBJECT(this)->activate_signal(clist, o);
+}
+
+void TQWidget::tqt_handle_qt_destroyed(QObject* obj) {
+ emit destroyed(TQT_TQOBJECT(obj));
+}
+
+bool TQWidget::isVisibleToTLW() const {
+ return isVisible();
+}
+
+/*!
+ \property TQWidget::backgroundBrush
+ \brief the widget's background brush
+
+ The background brush depends on a widget's palette and its
+ background mode.
+
+ \sa backgroundColor(), backgroundPixmap(), eraseColor(), palette,
+ TQApplication::setPalette()
+*/
+const TQBrush& TQWidget::backgroundBrush() const
+{
+ static TQBrush noBrush;
+#ifndef TQT_NO_PALETTE
+ TQt::BackgroundMode mode = extra ? (TQt::BackgroundMode) extra->bg_mode_visual : TQt::PaletteBackground;
+ switch( mode ) {
+ case TQt::FixedColor:
+ case TQt::FixedPixmap :
+ case TQt::NoBackground:
+ case TQt::X11ParentRelative:
+ return noBrush;
+ default:
+ TQColorGroup::ColorRole role = TQPalette::backgroundRoleFromMode( mode );
+ return tqcolorGroup().tqbrush( role );
+ }
+#else
+ return noBrush;
+#endif
+}
+
+/*!
+ \internal
+ Creates the widget extra data.
+*/
+
+// [FIXME] Fix the commented out lines
+
+void TQWidget::createExtra()
+{
+ if ( !extra ) { // if not exists
+ extra = new TQWExtra;
+ TQ_CHECK_PTR( extra );
+ extra->minw = extra->minh = 0;
+ extra->maxw = extra->maxh = TQWIDGETSIZE_MAX;
+ extra->bg_pix = 0;
+ extra->focus_proxy = 0;
+#ifndef TQT_NO_CURSOR
+ extra->curs = 0;
+#endif
+ extra->topextra = 0;
+ extra->bg_mode = TQt::PaletteBackground;
+ extra->bg_mode_visual = TQt::PaletteBackground;
+// extra->bg_origin = TQt::WidgetOrigin;
+#ifndef TQT_NO_STYLE
+ extra->style = 0;
+#endif
+ extra->size_policy = TQSizePolicy( TQSizePolicy::Preferred,
+ TQSizePolicy::Preferred );
+// createSysExtra();
+ }
+}
+
+
+/*!
+ \internal
+ Deletes the widget extra data.
+*/
+
+// [FIXME] Fix the commented out lines
+
+void TQWidget::deleteExtra()
+{
+ if ( extra ) { // if exists
+ delete extra->bg_pix;
+#ifndef TQT_NO_CURSOR
+ delete extra->curs;
+#endif
+// deleteSysExtra();
+ if ( extra->topextra ) {
+// deleteTLSysExtra();
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ delete extra->topextra->icon;
+#endif
+// delete extra->topextra->focusData;
+#if defined(TQ_WS_TQWS) && !defined(TQT_NO_TQWS_MANAGER)
+ delete extra->topextra->qwsManager;
+#endif
+ delete extra->topextra;
+ }
+ delete extra;
+ // extra->xic destroyed in TQWidget::destroy()
+ extra = 0;
+ }
+}
+
+void TQWidget::setBackgroundPixmap(const QPixmap &pm) {
+ // Is this object really a TQWidget (or based on a TQWidget)? If so use the internal virtual function instead...
+ if (inherits("TQObject") == TRUE) {
+ tqsetBackgroundPixmap(pm);
+ }
+ else {
+ QPalette p = palette();
+ p.setBrush(backgroundRole(), QBrush(pm));
+ setPalette(p);
+ }
+}
+
+void TQWidget::tqsetBackgroundPixmap(const QPixmap &pm) {
+ QPalette p = palette();
+ p.setBrush(backgroundRole(), QBrush(pm));
+ setPalette(p);
+}
+
+void TQWidget::setWFlags( WFlags flags ) {
+ if (this->inherits("TQWidget"))
+ TQtUpperWidgetFlags = TQtUpperWidgetFlags | (flags & WTQtFlagMask);
+ overrideWindowFlags((Qt::WindowFlags) (windowFlags() | (flags&(~WTQtFlagMask))));
+ if (this->inherits("TQWidget"))
+ processUpperWidgetFlags();
+}
+
+void TQWidget::clearWFlags( WFlags flags ) {
+ unsigned long long upperflags = 0ULL;
+ if (this->inherits("TQWidget"))
+ upperflags = TQtUpperWidgetFlags;
+ unsigned long long oldFlags = windowFlags() | upperflags;
+ unsigned long long newFlags = (oldFlags &= (~flags));
+ if ( ((newFlags & (WType_Dialog & (~WType_TopLevel))) != 0)
+ || ((newFlags & (WType_Popup & (~WType_TopLevel))) != 0)
+ || ((newFlags & (WType_Desktop & (~WType_TopLevel))) != 0))
+ newFlags = newFlags | WType_TopLevel;
+ overrideWindowFlags((Qt::WindowFlags)(newFlags&(~WTQtFlagMask)));
+ if (this->inherits("TQWidget"))
+ processUpperWidgetFlags();
+}
+
+WFlags TQWidget::getWFlags() const {
+ unsigned long long upperflags = 0ULL;
+ if (this->inherits("TQWidget"))
+ upperflags = TQtUpperWidgetFlags;
+ return windowFlags() | upperflags;
+}
+
+WFlags TQWidget::testWFlags( WFlags f ) const {
+ unsigned long long upperflags = 0ULL;
+ if (this->inherits("TQWidget"))
+ upperflags = TQtUpperWidgetFlags;
+ return ((windowFlags() | upperflags) & f);
+}
+
+void TQWidget::reparent(QWidget *parent, WFlags f, const QPoint &p, bool showIt) {
+ if (this->inherits("TQWidget")) {
+ TQtUpperWidgetFlags = f & WTQtFlagMask;
+ processUpperWidgetFlags();
+ }
+ setParent(parent, (Qt::WindowFlags)(f&(~WTQtFlagMask)));
+ setGeometry(p.x(),p.y(),width(),height());
+ if (showIt) show();
+}
+
+void TQWidget::processUpperWidgetFlags() {
+ unsigned long long flags = TQtUpperWidgetFlags&WTQtFlagMask;
+
+ // Process each extended TQt window flag that was defined in tqnamespace.h
+ if (flags & WNoAutoErase)
+ setAutoFillBackground(false);
+ else
+ setAutoFillBackground(true);
+
+ if (flags & WMouseNoMask)
+ setAttribute(Qt::WA_MouseNoMask, true);
+ else
+ setAttribute(Qt::WA_MouseNoMask, false);
+
+ if ((flags & WPaintOnScreen) || (flags & WPaintUnclipped))
+ setAttribute(Qt::WA_PaintOnScreen, true);
+ else
+ setAttribute(Qt::WA_PaintOnScreen, false);
+
+ if (flags & WPaintUnclipped)
+ setAttribute(Qt::WA_PaintUnclipped, true);
+ else
+ setAttribute(Qt::WA_PaintUnclipped, false);
+}
+
+void TQWidget::setDefaultWidgetFlags() {
+ TQtUpperWidgetFlags = TQtUpperWidgetFlags | WPaintOnScreen;
+}
+
+/*!
+ Enables key event compression, if \a compress is TRUE, and
+ disables it if \a compress is FALSE.
+
+ Key compression is off by default (except for TQLineEdit and
+ TQTextEdit), so widgets receive one key press event for each key
+ press (or more, since autorepeat is usually on). If you turn it on
+ and your program doesn't keep up with key input, TQt may try to
+ compress key events so that more than one character can be
+ processed in each event.
+
+ For example, a word processor widget might receive 2, 3 or more
+ characters in each TQKeyEvent::text(), if the tqlayout recalculation
+ takes too long for the CPU.
+
+ If a widget supports multiple character tqunicode input, it is
+ always safe to turn the compression on.
+
+ TQt performs key event compression only for printable characters.
+ Modifier keys, cursor movement keys, function keys and
+ miscellaneous action keys (e.g. Escape, Enter, Backspace,
+ PrintScreen) will stop key event compression, even if there are
+ more compressible key events available.
+
+ Not all platforms support this compression, in which case turning
+ it on will have no effect.
+
+ \sa TQKeyEvent::text();
+*/
+
+void TQWidget::setKeyCompression(bool compress)
+{
+ if ( compress )
+ setWState( TQt::WState_CompressKeys );
+ else
+ clearWState( TQt::WState_CompressKeys );
+}
+
+/*!
+ Returns the focus data for this widget's top-level widget.
+
+ Focus data always belongs to the top-level widget. The focus data
+ list tqcontains all the widgets in this top-level widget that can
+ accept focus, in tab order. An iterator points to the current
+ focus widget (tqfocusWidget() returns a pointer to this widget).
+
+ This information is useful for implementing advanced versions of
+ focusNextPrevChild().
+*/
+TQFocusData * TQWidget::focusData()
+{
+ return focusData( TRUE );
+}
+
+/*!
+ \internal
+
+ Internal function which lets us ask for the focus data, creating
+ it if it doesn't exist and \a create is TRUE.
+*/
+TQFocusData * TQWidget::focusData( bool create )
+{
+ TQWidget * tlw = tqtopLevelWidget();
+ TQWExtra * ed = tlw->extraData();
+ if ( !ed || !ed->topextra ) {
+ if ( !create )
+ return 0;
+ tlw->createTLExtra();
+ ed = tlw->extraData();
+ }
+ if ( create && !ed->topextra->focusData )
+ ed->topextra->focusData = new TQFocusData;
+
+ return ed->topextra->focusData;
+
+ // [FIXME] What does this do and how can I do it in Qt4?
+ printf("[WARNING] TQWidget::focusData( bool create ) unimplemented\n\r");
+ return 0;
+}
+
+void TQWidget::createTLExtra()
+{
+ if ( !extra )
+ createExtra();
+ if ( !extra->topextra ) {
+ TQTLWExtra* x = extra->topextra = new TQTLWExtra;
+#if defined( TQ_WS_WIN ) || defined( TQ_WS_MAC )
+ x->opacity = 255;
+#endif
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ x->icon = 0;
+#endif
+ x->focusData = 0;
+ x->fleft = x->fright = x->ftop = x->fbottom = 0;
+ x->incw = x->inch = 0;
+ x->basew = x->baseh = 0;
+ x->normalGeometry = TQRect(0,0,-1,-1);
+#if defined(TQ_WS_X11)
+ x->embedded = 0;
+ x->parentWinId = 0;
+ x->spont_unmapped = 0;
+ x->dnd = 0;
+ x->uspos = 0;
+ x->ussize = 0;
+#endif
+ x->savedFlags = 0;
+#if defined(TQ_WS_TQWS) && !defined(TQT_NO_TQWS_MANAGER)
+ x->decor_allocated_region = TQRegion();
+ x->qwsManager = 0;
+#endif
+ createTLSysExtra();
+ }
+}
+
+/*!
+ \property TQWidget::autoMask
+ \brief whether the auto tqmask feature is enabled for the widget
+
+ Transtqparent widgets use a tqmask to define their visible region.
+ TQWidget has some built-in support to make the task of
+ recalculating the tqmask easier. When setting auto tqmask to TRUE,
+ updateMask() will be called whenever the widget is resized or
+ changes its focus state. Note that you must reimplement
+ updateMask() (which should include a call to setMask()) or nothing
+ will happen.
+
+ Note: when you re-implement resizeEvent(), focusInEvent() or
+ focusOutEvent() in your custom widgets and still want to ensure
+ that the auto tqmask calculation works, you should add:
+
+ \code
+ if ( autoMask() )
+ updateMask();
+ \endcode
+
+ at the end of your event handlers. This is true for all member
+ functions that change the appearance of the widget in a way that
+ requires a recalculation of the tqmask.
+
+ While being a technically appealing concept, masks have a big
+ drawback: when using complex masks that cannot be expressed easily
+ with relatively simple regions, they can be very slow on some
+ window systems. The classic example is a transtqparent label. The
+ complex tqshape of its contents makes it necessary to represent its
+ tqmask by a bitmap, which consumes both memory and time. If all you
+ want is to blend the background of several neighboring widgets
+ together seamlessly, you will probably want to use
+ setBackgroundOrigin() rather than a tqmask.
+
+ \sa autoMask() updateMask() setMask() clearMask() setBackgroundOrigin()
+*/
+
+// [FIXME]
+// Verify that (WState)TQt::WState_AutoMask is a valid window state in Qt4, or at least
+// does not conflict with any Qt4 window states (i.e. can live alone without stomping on anything!)
+
+bool TQWidget::autoMask() const
+{
+ return testWState((WState)TQt::WState_AutoMask);
+}
+
+void TQWidget::setAutoMask( bool enable )
+{
+ if ( enable == autoMask() )
+ return;
+
+ if ( enable ) {
+ setWState((WState)TQt::WState_AutoMask);
+ updateMask();
+ } else {
+ clearWState((WState)TQt::WState_AutoMask);
+ clearMask();
+ }
+}
+
+void TQWidget::setFocus(TQFocusEvent::Reason reason)
+{
+ setFocus((Qt::FocusReason)reason);
+}
+
+TQObject *TQWidget::tqparent() const {
+ return TQT_TQOBJECT(parent());
+}
+
+// const TQObjectList *TQWidget::childrenListObject() const {
+// QObjectList qlr;
+// TQObjectList* tqt_tqobject_list = new TQObjectList();
+// qlr = this->children();
+// tqt_tqobject_list->clear();
+// for (int i = 0; i < qlr.size(); ++i) {
+// tqt_tqobject_list->append(static_cast<TQObject*>(qlr.at(i)));
+// }
+// return tqt_tqobject_list;
+// }
+
+TQObjectList TQWidget::childrenListObject() {
+ QObjectList qlr;
+ TQObjectList tqt_tqobject_list;
+ qlr = this->children();
+ tqt_tqobject_list.clear();
+ for (int i = 0; i < qlr.size(); ++i) {
+ tqt_tqobject_list.append(static_cast<TQObject*>(qlr.at(i)));
+ }
+ return tqt_tqobject_list;
+}
+
+const TQObjectList TQWidget::childrenListObject() const {
+ QObjectList qlr;
+ TQObjectList tqt_tqobject_list;
+ qlr = this->children();
+ tqt_tqobject_list.clear();
+ for (int i = 0; i < qlr.size(); ++i) {
+ tqt_tqobject_list.append(static_cast<TQObject*>(qlr.at(i)));
+ }
+ return tqt_tqobject_list;
+}
+
+const char *TQWidget::tqname() const {
+ if (dynamic_cast<const TQWidget*>(static_cast<const QWidget*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQWidget::tqname() on an object without a constructed TQWidget object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+const char *TQWidget::name() const {
+ if (dynamic_cast<const TQWidget*>(static_cast<const QWidget*>(static_cast<const QObject*>(this)))) {
+ static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
+ return static_object_name.ascii();
+ }
+ else {
+ printf("[WARNING] Attempted to call TQWidget::name() on an object without a constructed TQWidget object or base object. Returning \"\"\n\r");
+ return "";
+ }
+}
+
+TQLayout *TQWidget::tqlayout() const {
+ return TQT_TQLAYOUT(QWidget::layout());
+}
+
+/*!
+ Clear the rectangle at point (\a x, \a y) of width \a w and height
+ \a h.
+
+ \warning This is best done in a paintEvent().
+*/
+void TQWidget::erase_helper(int x, int y, int w, int h)
+{
+// if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible))
+// return;
+ if (w < 0)
+// w = data->crect.width() - x;
+ w = QWidget::x() - x;
+ if (h < 0)
+// h = data->crect.height() - y;
+ h = QWidget::y() - y;
+ if (w != 0 && h != 0) {
+// if (paintingActive()) {
+ if (paintingActive() && paintEngine()->isActive()) {
+ QPainter* p = paintEngine()->painter();
+ if (p) {
+ printf("[WARNING] A painter was aready active when TQWidget::erase(...) was called. Attempting to use existing painter for erasure...\n\r");
+ p->eraseRect(QRect(x, y, w, h));
+ }
+ else {
+ printf("[WARNING] A painter was aready active when TQWidget::erase(...) was called. Attempted to use existing painter for erasure but that FAILED!\n\r");
+ }
+ }
+ else {
+ QPainter p(this);
+ p.eraseRect(QRect(x, y, w, h));
+ }
+ }
+}
+
+/*!
+ \overload
+
+ Clear the given region, \a rgn.
+
+ Drawing may only take place in a QPaintEvent. Overload
+ paintEvent() to do your erasing and call update() to schedule a
+ replaint whenever necessary. See also QPainter.
+*/
+void TQWidget::erase(const QRegion& rgn)
+{
+ if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible))
+ return;
+
+ QPainter p(this);
+ p.setClipRegion(rgn);
+ p.eraseRect(rgn.boundingRect());
+}
+
+/*!
+ Returns the color role used for painting the widget's background.
+
+ Use QPalette(backgroundRole(()) instead.
+*/
+TQt::BackgroundMode TQWidget::backgroundMode() const
+{
+ if (testAttribute(Qt::WA_NoSystemBackground))
+ return TQt::NoBackground;
+ switch(backgroundRole()) {
+ case QPalette::WindowText:
+ return TQt::PaletteForeground;
+ case QPalette::Button:
+ return TQt::PaletteButton;
+ case QPalette::Light:
+ return TQt::PaletteLight;
+ case QPalette::Midlight:
+ return TQt::PaletteMidlight;
+ case QPalette::Dark:
+ return TQt::PaletteDark;
+ case QPalette::Mid:
+ return TQt::PaletteMid;
+ case QPalette::Text:
+ return TQt::PaletteText;
+ case QPalette::BrightText:
+ return TQt::PaletteBrightText;
+ case QPalette::Base:
+ return TQt::PaletteBase;
+ case QPalette::Window:
+ return TQt::PaletteBackground;
+ case QPalette::Shadow:
+ return TQt::PaletteShadow;
+ case QPalette::Highlight:
+ return TQt::PaletteHighlight;
+ case QPalette::HighlightedText:
+ return TQt::PaletteHighlightedText;
+ case QPalette::ButtonText:
+ return TQt::PaletteButtonText;
+ case QPalette::Link:
+ return TQt::PaletteLink;
+ case QPalette::LinkVisited:
+ return TQt::PaletteLinkVisited;
+ default:
+ break;
+ }
+ return TQt::NoBackground;
+}
+
+/*!
+ \fn void QWidget::setBackgroundMode(Qt::BackgroundMode
+ widgetBackground, Qt::BackgroundMode paletteBackground)
+
+ Sets the color role used for painting the widget's background to
+ background mode \a widgetBackground. The \a paletteBackground mode
+ parameter is ignored.
+*/
+void TQWidget::setBackgroundMode(TQt::BackgroundMode m, TQt::BackgroundMode)
+{
+ if(m == TQt::NoBackground) {
+ setAttribute(Qt::WA_NoSystemBackground, true);
+ return;
+ }
+ setAttribute(Qt::WA_NoSystemBackground, false);
+ setForegroundRole(QPalette::NoRole);
+ QPalette::ColorRole role = backgroundRole();
+ switch(m) {
+ case TQt::FixedColor:
+ case TQt::FixedPixmap:
+ break;
+ case TQt::PaletteForeground:
+ role = QPalette::WindowText;
+ break;
+ case TQt::PaletteButton:
+ role = QPalette::Button;
+ break;
+ case TQt::PaletteLight:
+ role = QPalette::Light;
+ break;
+ case TQt::PaletteMidlight:
+ role = QPalette::Midlight;
+ break;
+ case TQt::PaletteDark:
+ role = QPalette::Dark;
+ break;
+ case TQt::PaletteMid:
+ role = QPalette::Mid;
+ break;
+ case TQt::PaletteText:
+ role = QPalette::Text;
+ break;
+ case TQt::PaletteBrightText:
+ role = QPalette::BrightText;
+ break;
+ case TQt::PaletteBase:
+ role = QPalette::Base;
+ break;
+ case TQt::PaletteBackground:
+ role = QPalette::Window;
+ break;
+ case TQt::PaletteShadow:
+ role = QPalette::Shadow;
+ break;
+ case TQt::PaletteHighlight:
+ role = QPalette::Highlight;
+ break;
+ case TQt::PaletteHighlightedText:
+ role = QPalette::HighlightedText;
+ break;
+ case TQt::PaletteButtonText:
+ role = QPalette::ButtonText;
+ break;
+ case TQt::PaletteLink:
+ role = QPalette::Link;
+ break;
+ case TQt::PaletteLinkVisited:
+ role = QPalette::LinkVisited;
+ break;
+ case TQt::X11ParentRelative:
+ role = QPalette::NoRole;
+ setForegroundRole(role);
+ default:
+ break;
+ }
+ setBackgroundRole(role);
+}
+/*
+TQRect TQWidget::tqeffectiveRectFor(const QRect &rect) const
+{
+// #ifndef QT_NO_GRAPHICSEFFECT
+// if (graphicsEffect() && graphicsEffect()->isEnabled())
+// return graphicsEffect()->boundingRectFor(rect).toAlignedRect();
+// #endif //QT_NO_GRAPHICSEFFECT
+ return rect;
+}*/
+
+/*
+ Returns the widget's clipping rectangle.
+*/
+TQRect TQWidget::tqclipRect() const
+{
+// Q_Q(const QWidget);
+ const QWidget * w = this;
+ if (!w->isVisible())
+ return QRect();
+// QRect r = tqeffectiveRectFor(this->rect()); // [FIXME]
+ QRect r = this->rect();
+ int ox = 0;
+ int oy = 0;
+ while (w
+ && w->isVisible()
+ && !w->isWindow()
+ && w->parentWidget()) {
+ ox -= w->x();
+ oy -= w->y();
+ w = w->parentWidget();
+ r &= QRect(ox, oy, w->width(), w->height());
+ }
+ return r;
+}
+
+/*!
+ Use visibleRegion() instead.
+*/
+TQRect TQWidget::visibleRect() const
+{
+ return tqclipRect();
+}
+
+/*!
+ Returns the unobscured region where paint events can occur.
+
+ For visible widgets, this is an approximation of the area not
+ covered by other widgets; otherwise, this is an empty region.
+
+ The tqrepaint() function calls this function if necessary, so in
+ general you do not need to call it.
+
+*/
+TQRegion TQWidget::clipRegion() const
+{
+ return visibleRect();
+}
+
+void TQWidget::setIcon(const QPixmap &i)
+{
+ setWindowIcon(i);
+}
+
+/*!
+ \property TQWidget::customWhatsThis
+ \brief whether the widget wants to handle What's This help manually
+
+ The default implementation of customWhatsThis() returns FALSE,
+ which means the widget will not receive any events in Whats This
+ mode.
+
+ The widget may leave What's This mode by calling
+ TQWhatsThis::leaveWhatsThisMode(), with or without actually
+ displaying any help text.
+
+ You can also reimplement customWhatsThis() if your widget is a
+ "passive interactor" supposed to work under all circumstances.
+ Simply don't call TQWhatsThis::leaveWhatsThisMode() in that case.
+
+ \sa TQWhatsThis::inWhatsThisMode() TQWhatsThis::leaveWhatsThisMode()
+*/
+bool TQWidget::customWhatsThis() const
+{
+ return FALSE;
+}
+
+const TQPixmap *TQWidget::icon() const {
+ const_cast<TQWidget*>(this)->setProperty("TQT_WIDGET_ICON", TQPixmap(windowIcon().pixmap(QSize(14, 14)))); // [FIXME] Is there any way around hardcoding these sizes??
+ const QPixmap& ptrRef = property("TQT_WIDGET_ICON").value<QPixmap>();
+ return TQT_TQPIXMAP_CONST(&ptrRef);
+}
+
+const TQPixmap TQWidget::iconPixmap() const {
+ return TQPixmap(windowIcon().pixmap(QSize(14, 14))); // [FIXME] Is there any way around hardcoding these sizes??
+}
+
+/*!
+ This function can be reimplemented in a subclass to support
+ transtqparent widgets. It should be called whenever a widget changes
+ state in a way that means that the tqshape tqmask must be recalculated.
+
+ \sa setAutoMask(), updateMask(), setMask(), clearMask()
+*/
+void TQWidget::updateMask()
+{
+}
+
+/*!
+ Returns the GUI style for this widget
+
+ \sa TQWidget::setStyle(), TQApplication::setStyle(), TQApplication::style()
+*/
+
+TQStyle& TQWidget::tqstyle() const
+{
+// if ( extra && extra->style )
+// return *extra->style;
+ TQStyle &ret = tqApp->tqstyle();
+ return ret;
+}
+
+/*!
+ Sets the widget's GUI style to \a style. Ownership of the style
+ object is not transferred.
+
+ If no style is set, the widget uses the application's style,
+ TQApplication::style() instead.
+
+ Setting a widget's style has no effect on existing or future child
+ widgets.
+
+ \warning This function is particularly useful for demonstration
+ purposes, where you want to show TQt's styling capabilities. Real
+ applications should avoid it and use one consistent GUI style
+ instead.
+
+ \sa style(), TQStyle, TQApplication::style(), TQApplication::setStyle()
+*/
+
+void TQWidget::setStyle( TQStyle *style )
+{
+ QWidget::setStyle(style);
+}
+
+/*!
+ \overload
+
+ Sets the widget's GUI style to \a style using the TQStyleFactory.
+*/
+TQStyle* TQWidget::setStyle( const TQString &style )
+{
+ TQStyle *s = TQStyleFactory::create( style );
+ setStyle( s );
+ return s;
+}
+
+/*!
+ \property TQWidget::tqsizeHint
+ \brief the recommended size for the widget
+
+ If the value of this property is an invalid size, no size is
+ recommended.
+
+ The default implementation of tqsizeHint() returns an invalid size
+ if there is no tqlayout for this widget, and returns the tqlayout's
+ preferred size otherwise.
+
+ \sa TQSize::isValid(), tqminimumSizeHint(), sizePolicy(),
+ setMinimumSize(), updateGeometry()
+*/
+
+TQSize TQWidget::tqsizeHint() const
+{
+#ifndef TQT_NO_LAYOUT
+ if ( tqlayout() )
+ return tqlayout()->totalSizeHint();
+#endif
+ return TQSize( -1, -1 );
+}
+
+/*!
+ \property TQWidget::tqminimumSizeHint
+ \brief the recommended minimum size for the widget
+
+ If the value of this property is an invalid size, no minimum size
+ is recommended.
+
+ The default implementation of tqminimumSizeHint() returns an invalid
+ size if there is no tqlayout for this widget, and returns the
+ tqlayout's minimum size otherwise. Most built-in widgets reimplement
+ tqminimumSizeHint().
+
+ \l TQLayout will never resize a widget to a size smaller than
+ tqminimumSizeHint.
+
+ \sa TQSize::isValid(), resize(), setMinimumSize(), sizePolicy()
+*/
+TQSize TQWidget::tqminimumSizeHint() const
+{
+#ifndef TQT_NO_LAYOUT
+ if ( tqlayout() )
+ return tqlayout()->totalMinimumSize();
+#endif
+ return TQSize( -1, -1 );
+}
+
+/*!
+ \property TQWidget::updatesEnabled
+ \brief whether updates are enabled
+
+ Calling update() and tqrepaint() has no effect if updates are
+ disabled. Paint events from the window system are processed
+ normally even if updates are disabled.
+
+ setUpdatesEnabled() is normally used to disable updates for a
+ short period of time, for instance to avoid screen flicker during
+ large changes.
+
+ Example:
+ \code
+ setUpdatesEnabled( FALSE );
+ bigVisualChanges();
+ setUpdatesEnabled( TRUE );
+ tqrepaint();
+ \endcode
+
+ \sa update(), tqrepaint(), paintEvent()
+*/
+void TQWidget::tqsetUpdatesEnabled( bool enable )
+{
+// if ( enable )
+// clearWState( WState_BlockUpdates );
+// else
+// setWState( WState_BlockUpdates );
+
+ // Borrowed from Qt4
+ if (enable && !isWindow() && parentWidget() && !parentWidget()->updatesEnabled())
+ return; // nothing we can do
+
+ if (enable != testAttribute(Qt::WA_UpdatesDisabled))
+ return; // nothing to do
+
+ setAttribute(Qt::WA_UpdatesDisabled, !enable);
+// if (enable)
+// update();
+
+ Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceUpdatesDisabled : Qt::WA_UpdatesDisabled;
+ for (int i = 0; i < children().size(); ++i) {
+ TQWidget *w = TQT_TQWIDGET(qobject_cast<QWidget *>(children().at(i)));
+ if (w && !w->isWindow() && !w->testAttribute(attribute))
+ w->tqsetUpdatesEnabled(enable);
+ }
+}
+
+// USE_QT4
+
+// PRIVATE API FROM QT4
+// THIS MAY HAVE TO BE SYNCED WITH QT4 ON OCCASION
+/*!
+ \internal
+ \class QWidgetBackingStoreTracker
+ \brief Class which allows tracking of which widgets are using a given backing store
+
+ QWidgetBackingStoreTracker is a thin wrapper around a QWidgetBackingStore pointer,
+ which maintains a list of the QWidgets which are currently using the backing
+ store. This list is modified via the registerWidget and unregisterWidget functions.
+ */
+
+QWidgetBackingStoreTracker::QWidgetBackingStoreTracker()
+ : m_ptr(0)
+{
+
+}
+
+QWidgetBackingStoreTracker::~QWidgetBackingStoreTracker()
+{
+ delete m_ptr;
+}
+
+#if 0
+
+/*!
+ \internal
+ Destroy the contained QWidgetBackingStore, if not null, and clear the list of
+ widgets using the backing store, then create a new QWidgetBackingStore, providing
+ the QWidget.
+ */
+void QWidgetBackingStoreTracker::create(QWidget *widget)
+{
+ destroy();
+ m_ptr = new QWidgetBackingStore(widget);
+}
+
+/*!
+ \internal
+ Destroy the contained QWidgetBackingStore, if not null, and clear the list of
+ widgets using the backing store.
+ */
+void QWidgetBackingStoreTracker::destroy()
+{
+ delete m_ptr;
+ m_ptr = 0;
+ m_widgets.clear();
+}
+
+/*!
+ \internal
+ Add the widget to the list of widgets currently using the backing store.
+ If the widget was already in the list, this function is a no-op.
+ */
+void QWidgetBackingStoreTracker::registerWidget(QWidget *w)
+{
+ Q_ASSERT(m_ptr);
+ Q_ASSERT(w->internalWinId());
+ Q_ASSERT(qt_widget_private(w)->maybeBackingStore() == m_ptr);
+ m_widgets.insert(w);
+}
+
+/*!
+ \internal
+ Remove the widget from the list of widgets currently using the backing store.
+ If the widget was in the list, and removing it causes the list to be empty,
+ the backing store is deleted.
+ If the widget was not in the list, this function is a no-op.
+ */
+void QWidgetBackingStoreTracker::unregisterWidget(QWidget *w)
+{
+ if (m_widgets.remove(w) && m_widgets.isEmpty()) {
+ delete m_ptr;
+ m_ptr = 0;
+ }
+}
+
+#endif
+
+// END PRIVATE API
+
+// TQMetaObject *TQWidget::tqstaticMetaObject() {
+// return const_cast<TQMetaObject*>(static_cast<const TQMetaObject*>(&TQT_BASE_OBJECT_NAME::staticMetaObject));
+// }
+
+/*!
+ This is the main event handler; it handles event \a e. You can
+ reimplement this function in a subclass, but we recommend using
+ one of the specialized event handlers instead.
+
+ The main event handler first passes an event through all \link
+ TQObject::installEventFilter() event filters\endlink that have been
+ installed. If none of the filters intercept the event, it calls
+ one of the specialized event handlers.
+
+ Key press and release events are treated differently from other
+ events. event() checks for Tab and Shift+Tab and tries to move the
+ focus appropriately. If there is no widget to move the focus to
+ (or the key press is not Tab or Shift+Tab), event() calls
+ keyPressEvent().
+
+ This function returns TRUE if it is able to pass the event over to
+ someone (i.e. someone wanted the event); otherwise returns FALSE.
+
+ \sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(),
+ keyPressEvent(), keyReleaseEvent(), leaveEvent(),
+ mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(),
+ mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(),
+ TQObject::event(), TQObject::timerEvent()
+*/
+
+bool TQWidget::event( TQEvent *e )
+{
+ switch ( e->type() ) {
+// case TQEvent::MouseMove:
+// mouseMoveEvent( (TQMouseEvent*)e );
+// if ( ! ((TQMouseEvent*)e)->isAccepted() )
+// return FALSE;
+// break;
+//
+// case TQEvent::MouseButtonPress:
+// resetInputContext();
+// mousePressEvent( (TQMouseEvent*)e );
+// if ( ! ((TQMouseEvent*)e)->isAccepted() )
+// return FALSE;
+// break;
+//
+// case TQEvent::MouseButtonRelease:
+// mouseReleaseEvent( (TQMouseEvent*)e );
+// if ( ! ((TQMouseEvent*)e)->isAccepted() )
+// return FALSE;
+// break;
+//
+// case TQEvent::MouseButtonDblClick:
+// mouseDoubleClickEvent( (TQMouseEvent*)e );
+// if ( ! ((TQMouseEvent*)e)->isAccepted() )
+// return FALSE;
+// break;
+// #ifndef TQT_NO_WHEELEVENT
+// case TQEvent::Wheel:
+// wheelEvent( (TQWheelEvent*)e );
+// if ( ! ((TQWheelEvent*)e)->isAccepted() )
+// return FALSE;
+// break;
+// #endif
+// // case TQEvent::TabletMove:
+// // case TQEvent::TabletPress:
+// // case TQEvent::TabletRelease:
+// // tabletEvent( (TQTabletEvent*)e );
+// // if ( ! ((TQTabletEvent*)e)->isAccepted() )
+// // return FALSE;
+// // break;
+// // case TQEvent::Accel:
+// // ((TQKeyEvent*)e)->ignore();
+// // return FALSE;
+// case TQEvent::KeyPress: {
+// TQKeyEvent *k = (TQKeyEvent *)e;
+// bool res = FALSE;
+// if ( !(k->state() & ControlButton || k->state() & TQt::AltButton) ) {
+// if ( k->key() == Qt::Key_Backtab ||
+// (k->key() == Qt::Key_Tab &&
+// (k->state() & ShiftButton)) ) {
+// res = focusNextPrevChild( FALSE );
+//
+// } else if ( k->key() == Qt::Key_Tab ) {
+// res = focusNextPrevChild( TRUE );
+// }
+// if ( res )
+// break;
+// }
+// keyPressEvent( k );
+// if ( !k->isAccepted() )
+// return FALSE;
+// }
+// break;
+//
+// case TQEvent::KeyRelease:
+// keyReleaseEvent( (TQKeyEvent*)e );
+// if ( ! ((TQKeyEvent*)e)->isAccepted() )
+// return FALSE;
+// break;
+// //
+// // case TQEvent::IMStart: {
+// // TQIMEvent *i = (TQIMEvent *) e;
+// // imStartEvent(i);
+// // if (! i->isAccepted())
+// // return FALSE;
+// // }
+// // break;
+// //
+// // case TQEvent::IMCompose: {
+// // TQIMEvent *i = (TQIMEvent *) e;
+// // imComposeEvent(i);
+// // if (! i->isAccepted())
+// // return FALSE;
+// // }
+// // break;
+// //
+// // case TQEvent::IMEnd: {
+// // TQIMEvent *i = (TQIMEvent *) e;
+// // imEndEvent(i);
+// // if (! i->isAccepted())
+// // return FALSE;
+// // }
+// // break;
+// //
+// // case TQEvent::FocusIn:
+// // focusInEvent( (TQFocusEvent*)e );
+// // setFontSys();
+// // break;
+//
+// case TQEvent::FocusOut:
+// focusOutEvent( (TQFocusEvent*)e );
+// break;
+//
+// case TQEvent::Enter:
+// enterEvent( e );
+// break;
+//
+// case TQEvent::Leave:
+// leaveEvent( e );
+// break;
+//
+// case TQEvent::Paint:
+// // At this point the event has to be delivered, regardless
+// // whether the widget isVisible() or not because it
+// // already went through the filters
+// paintEvent( (TQPaintEvent*)e );
+// break;
+//
+// case TQEvent::Move:
+// moveEvent( (TQMoveEvent*)e );
+// break;
+//
+// case TQEvent::Resize:
+// resizeEvent( (TQResizeEvent*)e );
+// break;
+//
+// case TQEvent::Close: {
+// TQCloseEvent *c = (TQCloseEvent *)e;
+// closeEvent( c );
+// if ( !c->isAccepted() )
+// return FALSE;
+// }
+// break;
+// //
+// // case TQEvent::ContextMenu: {
+// // TQContextMenuEvent *c = (TQContextMenuEvent *)e;
+// // contextMenuEvent( c );
+// // if ( !c->isAccepted() )
+// // return FALSE;
+// // }
+// // break;
+// //
+// // #ifndef TQT_NO_DRAGANDDROP
+// // case TQEvent::Drop:
+// // dropEvent( (TQDropEvent*) e);
+// // break;
+// //
+// // case TQEvent::DragEnter:
+// // dragEnterEvent( (TQDragEnterEvent*) e);
+// // break;
+// //
+// // case TQEvent::DragMove:
+// // dragMoveEvent( (TQDragMoveEvent*) e);
+// // break;
+// //
+// // case TQEvent::DragLeave:
+// // dragLeaveEvent( (TQDragLeaveEvent*) e);
+// // break;
+// // #endif
+// //
+// case TQEvent::Show:
+// showEvent( (TQShowEvent*) e);
+// break;
+//
+// case TQEvent::Hide:
+// hideEvent( (TQHideEvent*) e);
+// break;
+//
+// // case TQEvent::ShowWindowRequest:
+// // if ( isShown() )
+// // showWindow();
+// // break;
+// //
+// // case TQEvent::ParentFontChange:
+// // if ( isTopLevel() )
+// // break;
+// // // fall through
+// // case TQEvent::ApplicationFontChange:
+// // if ( own_font )
+// // setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
+// // else
+// // unsetFont();
+// // break;
+// //
+// // #ifndef TQT_NO_PALETTE
+// // case TQEvent::ParentPaletteChange:
+// // if ( isTopLevel() )
+// // break;
+// // // fall through
+// // case TQEvent::ApplicationPaletteChange:
+// // if ( !own_palette && !isDesktop() )
+// // unsetPalette();
+// // # if defined(TQ_WS_TQWS) && !defined (TQT_NO_TQWS_MANAGER)
+// // if ( isTopLevel() && topData()->qwsManager ) {
+// // TQRegion r( topData()->qwsManager->region() );
+// // TQApplication::postEvent(topData()->qwsManager, new TQPaintEvent(r, FALSE) );
+// // }
+// // # endif
+// // break;
+// // #endif
+// //
+// case TQEvent::WindowActivate:
+// case TQEvent::WindowDeactivate:
+// windowActivationChange( e->type() != TQEvent::WindowActivate );
+// if ( childrenListObject() ) {
+// TQObjectListIt it( *childrenListObject() );
+// TQObject *o;
+// while( ( o = it.current() ) != 0 ) {
+// ++it;
+// if ( o->isWidgetType() &&
+// ((TQWidget*)o)->isVisible() &&
+// !((TQWidget*)o)->isTopLevel() )
+// TQApplication::sendEvent( o, e );
+// }
+// }
+// break;
+// //
+// // case TQEvent::LanguageChange:
+// // case TQEvent::LocaleChange:
+// // if ( childrenListObject() ) {
+// // TQObjectListIt it( *childrenListObject() );
+// // TQObject *o;
+// // while( ( o = it.current() ) != 0 ) {
+// // ++it;
+// // TQApplication::sendEvent( o, e );
+// // }
+// // }
+// // if ( e->type() == TQEvent::LanguageChange ) {
+// // int index = tqmetaObject()->tqfindSlot( "languageChange()", TRUE );
+// // if ( index >= 0 )
+// // qt_invoke( index, 0 );
+// // }
+// // update();
+// // break;
+// // #ifndef TQT_NO_LAYOUT
+// // case TQEvent::LayoutDirectionChange:
+// // if ( tqlayout() ) {
+// // tqlayout()->activate();
+// // } else {
+// // TQObjectList* llist = queryList( "TQLayout", 0, TRUE, TRUE );
+// // TQObjectListIt lit( *llist );
+// // TQLayout *lay;
+// // while ( ( lay = (TQLayout*)lit.current() ) != 0 ) {
+// // ++lit;
+// // lay->activate();
+// // }
+// // delete llist;
+// // }
+// // update();
+// // break;
+// // #endif
+// //
+ case TQEvent::WindowStateChange:
+ {
+ if (tqt_internal_ignore_next_windowstatechange_event == FALSE) {
+ TQEvent::Type type;
+ if (isMinimized())
+ type = TQEvent::ShowMinimized;
+ else if (isFullScreen())
+ type = TQEvent::ShowFullScreen;
+ else if (isMaximized())
+ type = TQEvent::ShowMaximized;
+ else
+ type = TQEvent::ShowNormal;
+ TQApplication::postEvent(this, new TQEvent(type));
+ }
+ else {
+ tqt_internal_ignore_next_windowstatechange_event = FALSE;
+ }
+ break;
+ }
+
+// case TQEvent::WindowBlocked:
+// case TQEvent::WindowUnblocked:
+// if ( childrenListObject() ) {
+// TQObjectListIt it( *childrenListObject() );
+// TQObject *o;
+// while( ( o = it.current() ) != 0 ) {
+// ++it;
+// TQWidget *w = ::tqqt_cast<TQWidget*>(o);
+// if (w && !w->testWFlags(TQt::WShowModal))
+// TQApplication::sendEvent( o, e );
+// }
+// }
+// break;
+
+ case TQEvent::ChildInserted:
+// case TQEvent::ChildRemoved: // Causes a recursion loop if uncommented
+ childEvent( (TQChildEvent*)e );
+ return TRUE;
+
+ default:
+ if ( TQT_TQOBJECT(this)->TQObject::event( e ) )
+ return TRUE;
+ return QWidget::event(e);
+ }
+
+ return TRUE;
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse move events for the widget.
+
+ If mouse tracking is switched off, mouse move events only occur if
+ a mouse button is pressed while the mouse is being moved. If mouse
+ tracking is switched on, mouse move events occur even if no mouse
+ button is pressed.
+
+ TQMouseEvent::pos() reports the position of the mouse cursor,
+ relative to this widget. For press and release events, the
+ position is usually the same as the position of the last mouse
+ move event, but it might be different if the user's hand shakes.
+ This is a feature of the underlying window system, not TQt.
+
+ \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
+ mouseDoubleClickEvent(), event(), TQMouseEvent
+*/
+
+void TQWidget::mouseMoveEvent( TQMouseEvent * e)
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse press events for the widget.
+
+ If you create new widgets in the mousePressEvent() the
+ mouseReleaseEvent() may not end up where you expect, depending on
+ the underlying window system (or X11 window manager), the widgets'
+ location and maybe more.
+
+ The default implementation implements the closing of popup widgets
+ when you click outside the window. For other widget types it does
+ nothing.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQWidget::mousePressEvent( TQMouseEvent *e )
+{
+ e->ignore();
+ if ( isPopup() ) {
+ e->accept();
+ TQWidget* w;
+ while ( (w = TQT_TQWIDGET(tqApp->activePopupWidget()) ) && w != this ){
+ w->close();
+ if (tqApp->activePopupWidget() == w) // widget does not want to dissappear
+ w->hide(); // hide at least
+ }
+ if (!TQT_TQRECT_OBJECT(rect()).tqcontains(e->pos()) ){
+ close();
+ }
+ }
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse release events for the widget.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQWidget::mouseReleaseEvent( TQMouseEvent * e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse double click events for the widget.
+
+ The default implementation generates a normal mouse press event.
+
+ Note that the widgets gets a mousePressEvent() and a
+ mouseReleaseEvent() before the mouseDoubleClickEvent().
+
+ \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
+ event(), TQMouseEvent
+*/
+
+void TQWidget::mouseDoubleClickEvent( TQMouseEvent *e )
+{
+ mousePressEvent( e ); // try mouse press event
+}
+
+#ifndef TQT_NO_WHEELEVENT
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive wheel events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQWheelEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQWheelEvent::ignore(), TQWheelEvent::accept(), event(),
+ TQWheelEvent
+*/
+
+void TQWidget::wheelEvent( TQWheelEvent *e )
+{
+ e->ignore();
+}
+#endif
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive tablet events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQTabletEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQTabletEvent::ignore(), TQTabletEvent::accept(), event(),
+ TQTabletEvent
+*/
+
+void TQWidget::tabletEvent( TQTabletEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key press events for the widget.
+
+ A widget must call setFocusPolicy() to accept focus initially and
+ have focus in order to receive a key press event.
+
+ If you reimplement this handler, it is very important that you
+ explicitly \link TQKeyEvent::ignore() ignore\endlink the event
+ if you do not understand it, so that the widget's tqparent can
+ interpret it; otherwise, the event will be implicitly accepted.
+ Although top-level widgets are able to choose whether to accept
+ or ignore unknown events because they have no tqparent widgets that
+ could otherwise handle them, it is good practice to explicitly
+ ignore events to make widgets as reusable as possible.
+
+ The default implementation closes popup widgets if the user
+ presses <b>Esc</b>. Otherwise the event is ignored.
+
+ \sa keyReleaseEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQWidget::keyPressEvent( TQKeyEvent *e )
+{
+ if ( isPopup() && e->key() == Key_Escape ) {
+ e->accept();
+ close();
+ } else {
+ e->ignore();
+ }
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key release events for the widget.
+
+ A widget must \link setFocusPolicy() accept focus\endlink
+ initially and \link hasFocus() have focus\endlink in order to
+ receive a key release event.
+
+ If you reimplement this handler, it is very important that you
+ \link TQKeyEvent ignore()\endlink the release if you do not
+ understand it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa keyPressEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQWidget::keyReleaseEvent( TQKeyEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus received) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQWidget::focusInEvent( TQFocusEvent * )
+{
+ if ( focusPolicy() != Qt::NoFocus || !isTopLevel() ) {
+ update();
+ if ( testWState(TQt::WState_AutoMask) )
+ updateMask();
+ setMicroFocusHint(width()/2, 0, 1, height(), FALSE);
+ }
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus lost) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQWidget::focusOutEvent( TQFocusEvent * )
+{
+ if ( focusPolicy() != Qt::NoFocus || !isTopLevel() ){
+ update();
+ if ( testWState(TQt::WState_AutoMask) )
+ updateMask();
+ }
+}
+
+/*!
+ \property TQWidget::microFocusHint
+ \brief the currently set micro focus hint for this widget.
+
+ See the documentation of setMicroFocusHint() for more information.
+*/
+TQRect TQWidget::microFocusHint() const
+{
+ if ( !extra )
+ return TQRect(width()/2, 0, 1, height() );
+ else if ( extra->micro_focus_hint.isEmpty() )
+ return TQRect(width()/2, 0, 1, height() );
+ else
+ return extra->micro_focus_hint;
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget enter events.
+
+ An event is sent to the widget when the mouse cursor enters the
+ widget.
+
+ \sa leaveEvent(), mouseMoveEvent(), event()
+*/
+
+void TQWidget::enterEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget leave events.
+
+ A leave event is sent to the widget when the mouse cursor leaves
+ the widget.
+
+ \sa enterEvent(), mouseMoveEvent(), event()
+*/
+
+void TQWidget::leaveEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ paint events.
+
+ A paint event is a request to tqrepaint all or part of the widget.
+ It can happen as a result of tqrepaint() or update(), or because the
+ widget was obscured and has now been uncovered, or for many other
+ reasons.
+
+ Many widgets can simply tqrepaint their entire surface when asked
+ to, but some slow widgets need to optimize by painting only the
+ requested region: TQPaintEvent::region(). This speed optimization
+ does not change the result, as painting is clipped to that region
+ during event processing. TQListView and TQCanvas do this, for
+ example.
+
+ TQt also tries to speed up painting by merging multiple paint
+ events into one. When update() is called several times or the
+ window system sends several paint events, TQt merges these events
+ into one event with a larger region (see TQRegion::unite()).
+ tqrepaint() does not permit this optimization, so we suggest using
+ update() when possible.
+
+ When the paint event occurs, the update region has normally been
+ erased, so that you're painting on the widget's background. There
+ are a couple of exceptions and TQPaintEvent::erased() tells you
+ whether the widget has been erased or not.
+
+ The background can be set using setBackgroundMode(),
+ setPaletteBackgroundColor() or setBackgroundPixmap(). The
+ documentation for setBackgroundMode() elaborates on the
+ background; we recommend reading it.
+
+ \sa event(), tqrepaint(), update(), TQPainter, TQPixmap, TQPaintEvent
+*/
+
+void TQWidget::paintEvent( TQPaintEvent *e )
+{
+// // At least let Qt4 get a shot at painting it
+// QWidget::paintEvent(e);
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget move events. When the widget receives this event, it is
+ already at the new position.
+
+ The old position is accessible through TQMoveEvent::oldPos().
+
+ \sa resizeEvent(), event(), move(), TQMoveEvent
+*/
+
+void TQWidget::moveEvent( TQMoveEvent * )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget resize events. When resizeEvent() is called, the widget
+ already has its new tqgeometry. The old size is accessible through
+ TQResizeEvent::oldSize().
+
+ The widget will be erased and receive a paint event immediately
+ after processing the resize event. No drawing need be (or should
+ be) done inside this handler.
+
+ Widgets that have been created with the \c WNoAutoErase flag
+ will not be erased. Nevertheless, they will receive a paint event
+ for their entire area afterwards. Again, no drawing needs to be
+ done inside this handler.
+
+ The default implementation calls updateMask() if the widget has
+ \link TQWidget::setAutoMask() automatic masking\endlink enabled.
+
+ \sa moveEvent(), event(), resize(), TQResizeEvent, paintEvent()
+*/
+
+void TQWidget::resizeEvent( TQResizeEvent * )
+{
+ if ( testWState(TQt::WState_AutoMask) )
+ updateMask();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget close events.
+
+ The default implementation calls e->accept(), which hides this
+ widget. See the \l TQCloseEvent documentation for more details.
+
+ \sa event(), hide(), close(), TQCloseEvent
+*/
+
+void TQWidget::closeEvent( TQCloseEvent *e )
+{
+ e->accept();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget context menu events.
+
+ The default implementation calls e->ignore(), which rejects the
+ context event. See the \l TQContextMenuEvent documentation for
+ more details.
+
+ \sa event(), TQContextMenuEvent
+*/
+
+void TQWidget::contextMenuEvent( TQContextMenuEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user begins entering text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQWidget::imStartEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has entered some text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQWidget::imComposeEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has finished inputting text via an Input
+ Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQWidget::imEndEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+#ifndef TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragEnterEvent
+*/
+void TQWidget::dragEnterEvent( TQDragEnterEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget, and whenever it moves within the widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragMoveEvent
+*/
+void TQWidget::dragMoveEvent( TQDragMoveEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse leaves this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragLeaveEvent
+*/
+void TQWidget::dragLeaveEvent( TQDragLeaveEvent * )
+{
+}
+
+/*!
+ This event handler is called when the drag is dropped on this
+ widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDropEvent
+*/
+void TQWidget::dropEvent( TQDropEvent * )
+{
+}
+
+#endif // TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget show events.
+
+ Non-spontaneous show events are sent to widgets immediately before
+ they are shown. The spontaneous show events of top-level widgets
+ are delivered afterwards.
+
+ \sa event(), TQShowEvent
+*/
+void TQWidget::showEvent( TQShowEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget hide events.
+
+ Hide events are sent to widgets immediately after they have been
+ hidden.
+
+ \sa event(), TQHideEvent
+*/
+void TQWidget::hideEvent( TQHideEvent * )
+{
+}
+
+/*
+ \fn TQWidget::x11Event( MSG * )
+
+ This special event handler can be reimplemented in a subclass to
+ receive native X11 events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::x11EventFilter()
+*/
+
+
+#if defined(TQ_WS_MAC)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native Macintosh events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::macEventFilter()
+*/
+
+bool TQWidget::macEvent( MSG * )
+{
+ return FALSE;
+}
+
+#endif
+#if defined(TQ_WS_WIN)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native Windows events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::winEventFilter()
+*/
+bool TQWidget::winEvent( MSG * )
+{
+ return FALSE;
+}
+
+#endif
+#if defined(TQ_WS_X11)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native X11 events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::x11EventFilter()
+*/
+bool TQWidget::x11Event( XEvent * )
+{
+ return FALSE;
+}
+
+#endif
+#if defined(TQ_WS_TQWS)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native TQt/Embedded events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::qwsEventFilter()
+*/
+bool TQWidget::qwsEvent( TQWSEvent * )
+{
+ return FALSE;
+}
+
+#endif
+
+void TQWidget::timerEvent( TQTimerEvent * )
+{
+}
+
+void TQWidget::childEvent( TQChildEvent * )
+{
+}
+
+void TQWidget::customEvent( TQCustomEvent * )
+{
+}
+
+bool TQWidget::eventFilter( TQObject * /* watched */, TQEvent * /* e */ )
+{
+ return FALSE;
+}
+
+int TQWidget::x11Depth() const {
+ const QX11Info *info = &x11Info();
+ if (info)
+ return info->depth();
+ return QX11Info::appDepth();
+}
+
+/*!
+ Adjusts the size of the widget to fit the contents.
+
+ Uses tqsizeHint() if valid (i.e if the size hint's width and height
+ are \>= 0), otherwise sets the size to the tqchildren rectangle (the
+ union of all child widget geometries).
+
+ \sa tqsizeHint(), tqchildrenRect()
+*/
+
+void TQWidget::adjustSize()
+{
+ TQApplication::sendPostedEvents( 0, TQEvent::ChildInserted );
+ TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint );
+ if ( !testWState(WState_Polished) )
+ polish();
+ TQSize s = tqsizeHint();
+
+ if ( isTopLevel() ) {
+
+#if defined(TQ_WS_X11)
+ TQRect screen = TQApplication::desktop()->screenGeometry( x11Screen() );
+#else // all others
+ TQRect screen = TQApplication::desktop()->screenGeometry( pos() );
+#endif
+
+#ifndef TQT_NO_LAYOUT
+ if ( tqlayout() ) {
+ if ( tqlayout()->hasHeightForWidth() ) {
+ s = s.boundedTo( screen.size() );
+ s.setHeight( tqlayout()->totalHeightForWidth( s.width() ) );
+ }
+ } else
+#endif
+ {
+ if ( sizePolicy().hasHeightForWidth() ) {
+ s = s.boundedTo( screen.size() );
+ s.setHeight( heightForWidth( s.width() ) );
+ }
+ }
+ }
+ if ( s.isValid() ) {
+ resize( s );
+ return;
+ }
+ TQRect r = tqchildrenRect(); // get tqchildren rectangle
+ if ( r.isNull() ) // probably no widgets
+ return;
+ resize( r.width() + 2 * r.x(), r.height() + 2 * r.y() );
+}
+
+bool TQWidget::isA( const char *classname ) const
+{
+ if (tqstrcmp(classname, metaObject()->className()) == 0) return true;
+ else {
+ TQString cn = metaObject()->className();
+ if (cn[0] == 'T')
+ cn = cn.remove(0,1);
+ return (tqstrcmp(classname, cn.ascii()) == 0);
+ }
+}
+
+bool TQWidget::inherits( const char *classname ) const {
+ if (QWidget::inherits(classname)) return true;
+ else {
+ TQString cn = classname;
+ if (cn[0] != 'T')
+ cn = cn.prepend('T');
+ return QWidget::inherits(cn.ascii());
+ }
+}
+
+void TQWidget::setWState( uint state ) {
+ if (state == TQt::WState_OwnSizePolicy) setAttribute(Qt::WA_WState_OwnSizePolicy, true);
+ else if (state == TQt::WState_BlockUpdates) setAttribute(Qt::WA_ForceUpdatesDisabled, true);
+ else {
+ tqt_internal_ignore_next_windowstatechange_event = TRUE;
+ overrideWindowState((Qt::WindowState) (windowState() | state));
+ }
+}
+
+void TQWidget::clearWState( uint flags ) {
+ if (flags == TQt::WState_OwnSizePolicy)
+ setAttribute(Qt::WA_WState_OwnSizePolicy, false);
+ else if (flags == TQt::WState_BlockUpdates)
+ setAttribute(Qt::WA_ForceUpdatesDisabled, false);
+ else {
+ tqt_internal_ignore_next_windowstatechange_event = TRUE;
+ overrideWindowState((QWidget::windowState() &= (Qt::WindowState)(~flags)));
+ }
+}
+
+WState TQWidget::getWState() const {
+ return QWidget::windowState();
+}
+
+WState TQWidget::testWState( WState s ) const {
+ if (s == TQt::WState_OwnSizePolicy)
+ return (WState)(testAttribute(Qt::WA_WState_OwnSizePolicy) ? TQt::WState_OwnSizePolicy : 0);
+ else if (s == TQt::WState_BlockUpdates)
+ return (WState)(testAttribute(Qt::WA_ForceUpdatesDisabled) ? TQt::WState_BlockUpdates : 0);
+ else
+ return (QWidget::windowState() & s);
+}
+
+WState TQWidget::testWState( TQt::WidgetState s ) const {
+ if (s == TQt::WState_OwnSizePolicy)
+ return (WState)(testAttribute(Qt::WA_WState_OwnSizePolicy) ? TQt::WState_OwnSizePolicy : 0);
+ else if (s == TQt::WState_BlockUpdates)
+ return (WState)(testAttribute(Qt::WA_ForceUpdatesDisabled) ? TQt::WState_BlockUpdates : 0);
+ else
+ return (QWidget::windowState() & s);
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQWidget tqwidget.h
+ \brief The TQWidget class is the base class of all user interface objects.
+
+ \ingroup abstractwidgets
+ \mainclass
+
+ The widget is the atom of the user interface: it receives mouse,
+ keyboard and other events from the window system, and paints a
+ representation of itself on the screen. Every widget is
+ rectangular, and they are sorted in a Z-order. A widget is
+ clipped by its tqparent and by the widgets in front of it.
+
+ A widget that isn't embedded in a tqparent widget is called a
+ top-level widget. Usually, top-level widgets are windows with a
+ frame and a title bar (although it is also possible to create
+ top-level widgets without such decoration if suitable widget flags
+ are used). In TQt, TQMainWindow and the various subclasses of
+ TQDialog are the most common top-level windows.
+
+ A widget without a tqparent widget is always a top-level widget.
+
+ Non-top-level widgets are child widgets. These are child windows
+ in their tqparent widgets. You cannot usually distinguish a child
+ widget from its tqparent visually. Most other widgets in TQt are
+ useful only as child widgets. (It is possible to make, say, a
+ button into a top-level widget, but most people prefer to put
+ their buttons inside other widgets, e.g. TQDialog.)
+
+ If you want to use a TQWidget to hold child widgets you will
+ probably want to add a tqlayout to the tqparent TQWidget. (See \link
+ tqlayout.html Layouts\endlink.)
+
+ TQWidget has many member functions, but some of them have little
+ direct functionality: for example, TQWidget has a font property,
+ but never uses this itself. There are many subclasses which
+ provide real functionality, such as TQPushButton, TQListBox and
+ TQTabDialog, etc.
+
+ \section1 Groups of functions:
+
+ \table
+ \header \i Context \i Functions
+
+ \row \i Window functions \i
+ show(),
+ hide(),
+ raise(),
+ lower(),
+ close().
+
+ \row \i Top level windows \i
+ caption(),
+ setCaption(),
+ icon(),
+ setIcon(),
+ iconText(),
+ setIconText(),
+ isActiveWindow(),
+ setActiveWindow(),
+ showMinimized().
+ showMaximized(),
+ showFullScreen(),
+ showNormal().
+
+ \row \i Window contents \i
+ update(),
+ tqrepaint(),
+ erase(),
+ scroll(),
+ updateMask().
+
+ \row \i Geometry \i
+ pos(),
+ size(),
+ rect(),
+ x(),
+ y(),
+ width(),
+ height(),
+ sizePolicy(),
+ tqsetSizePolicy(),
+ tqsizeHint(),
+ updateGeometry(),
+ tqlayout(),
+ move(),
+ resize(),
+ setGeometry(),
+ frameGeometry(),
+ tqgeometry(),
+ tqchildrenRect(),
+ adjustSize(),
+ mapFromGlobal(),
+ mapFromParent()
+ mapToGlobal(),
+ mapToParent(),
+ tqmaximumSize(),
+ tqminimumSize(),
+ sizeIncrement(),
+ setMaximumSize(),
+ setMinimumSize(),
+ setSizeIncrement(),
+ setBaseSize(),
+ setFixedSize()
+
+ \row \i Mode \i
+ isVisible(),
+ isVisibleTo(),
+ isMinimized(),
+ isDesktop(),
+ isEnabled(),
+ isEnabledTo(),
+ isModal(),
+ isPopup(),
+ isTopLevel(),
+ setEnabled(),
+ hasMouseTracking(),
+ setMouseTracking(),
+ isUpdatesEnabled(),
+ setUpdatesEnabled(),
+ clipRegion().
+
+ \row \i Look and feel \i
+ style(),
+ setStyle(),
+ cursor(),
+ setCursor()
+ font(),
+ setFont(),
+ palette(),
+ setPalette(),
+ backgroundMode(),
+ setBackgroundMode(),
+ tqcolorGroup(),
+ fontMetrics(),
+ fontInfo().
+
+ \row \i Keyboard focus<br>functions \i
+ isFocusEnabled(),
+ setFocusPolicy(),
+ focusPolicy(),
+ hasFocus(),
+ setFocus(),
+ clearFocus(),
+ setTabOrder(),
+ setFocusProxy().
+
+ \row \i Mouse and<br>keyboard grabbing \i
+ grabMouse(),
+ releaseMouse(),
+ grabKeyboard(),
+ releaseKeyboard(),
+ mouseGrabber(),
+ keyboardGrabber().
+
+ \row \i Event handlers \i
+ event(),
+ mousePressEvent(),
+ mouseReleaseEvent(),
+ mouseDoubleClickEvent(),
+ mouseMoveEvent(),
+ keyPressEvent(),
+ keyReleaseEvent(),
+ focusInEvent(),
+ focusOutEvent(),
+ wheelEvent(),
+ enterEvent(),
+ leaveEvent(),
+ paintEvent(),
+ moveEvent(),
+ resizeEvent(),
+ closeEvent(),
+ dragEnterEvent(),
+ dragMoveEvent(),
+ dragLeaveEvent(),
+ dropEvent(),
+ childEvent(),
+ showEvent(),
+ hideEvent(),
+ customEvent().
+
+ \row \i Change handlers \i
+ enabledChange(),
+ fontChange(),
+ paletteChange(),
+ styleChange(),
+ windowActivationChange().
+
+ \row \i System functions \i
+ parentWidget(),
+ tqtopLevelWidget(),
+ reparent(),
+ polish(),
+ winId(),
+ tqfind(),
+ metric().
+
+ \row \i What's this help \i
+ customWhatsThis()
+
+ \row \i Internal kernel<br>functions \i
+ focusNextPrevChild(),
+ wmapper(),
+ clearWFlags(),
+ getWFlags(),
+ setWFlags(),
+ testWFlags().
+
+ \endtable
+
+ Every widget's constructor accepts two or three standard arguments:
+ \list 1
+ \i \c{TQWidget *tqparent = 0} is the tqparent of the new widget.
+ If it is 0 (the default), the new widget will be a top-level window.
+ If not, it will be a child of \e tqparent, and be constrained by \e
+ tqparent's tqgeometry (unless you specify \c WType_TopLevel as
+ widget flag).
+ \i \c{const char *name = 0} is the widget name of the new
+ widget. You can access it using name(). The widget name is little
+ used by programmers but is quite useful with GUI builders such as
+ \e{TQt Designer} (you can name a widget in \e{TQt Designer}, and
+ connect() to it using the name in your code). The dumpObjectTree()
+ debugging function also uses it.
+ \i \c{WFlags f = 0} (where available) sets the widget flags; the
+ default is suitable for almost all widgets, but to get, for
+ example, a top-level widget without a window system frame, you
+ must use special flags.
+ \endlist
+
+ The tictac/tictac.cpp example program is good example of a simple
+ widget. It tqcontains a few event handlers (as all widgets must), a
+ few custom routines that are specific to it (as all useful widgets
+ do), and has a few tqchildren and connections. Everything it does
+ is done in response to an event: this is by far the most common way
+ to design GUI applications.
+
+ You will need to supply the content for your widgets yourself, but
+ here is a brief run-down of the events, starting with the most common
+ ones:
+
+ \list
+
+ \i paintEvent() - called whenever the widget needs to be
+ repainted. Every widget which displays output must implement it,
+ and it is wise \e not to paint on the screen outside
+ paintEvent().
+
+ \i resizeEvent() - called when the widget has been resized.
+
+ \i mousePressEvent() - called when a mouse button is pressed.
+ There are six mouse-related events, but the mouse press and mouse
+ release events are by far the most important. A widget receives
+ mouse press events when the mouse is inside it, or when it has
+ grabbed the mouse using grabMouse().
+
+ \i mouseReleaseEvent() - called when a mouse button is released.
+ A widget receives mouse release events when it has received the
+ corresponding mouse press event. This means that if the user
+ presses the mouse inside \e your widget, then drags the mouse to
+ somewhere else, then releases, \e your widget receives the release
+ event. There is one exception: if a popup menu appears while the
+ mouse button is held down, this popup immediately steals the mouse
+ events.
+
+ \i mouseDoubleClickEvent() - not quite as obvious as it might seem.
+ If the user double-clicks, the widget receives a mouse press event
+ (perhaps a mouse move event or two if they don't hold the mouse
+ quite steady), a mouse release event and finally this event. It is
+ \e{not possible} to distinguish a click from a double click until you've
+ seen whether the second click arrives. (This is one reason why most GUI
+ books recommend that double clicks be an extension of single clicks,
+ rather than trigger a different action.)
+
+ \endlist
+
+ If your widget only tqcontains child widgets, you probably do not need to
+ implement any event handlers. If you want to detect a mouse click in
+ a child widget call the child's hasMouse() function inside the
+ tqparent widget's mousePressEvent().
+
+ Widgets that accept keyboard input need to reimplement a few more
+ event handlers:
+
+ \list
+
+ \i keyPressEvent() - called whenever a key is pressed, and again
+ when a key has been held down long enough for it to auto-repeat.
+ Note that the Tab and Shift+Tab keys are only passed to the widget
+ if they are not used by the focus-change mechanisms. To force those
+ keys to be processed by your widget, you must reimplement
+ TQWidget::event().
+
+ \i focusInEvent() - called when the widget gains keyboard focus
+ (assuming you have called setFocusPolicy()). Well written widgets
+ indicate that they own the keyboard focus in a clear but discreet
+ way.
+
+ \i focusOutEvent() - called when the widget loses keyboard focus.
+
+ \endlist
+
+ Some widgets will also need to reimplement some of the less common
+ event handlers:
+
+ \list
+
+ \i mouseMoveEvent() - called whenever the mouse moves while a
+ button is held down. This is useful for, for example, dragging. If
+ you call setMouseTracking(TRUE), you get mouse move events even
+ when no buttons are held down. (Note that applications which make
+ use of mouse tracking are often not very useful on low-bandwidth X
+ connections.) (See also the \link dnd.html drag and drop\endlink
+ information.)
+
+ \i keyReleaseEvent() - called whenever a key is released, and also
+ while it is held down if the key is auto-repeating. In that case
+ the widget receives a key release event and immediately a key press
+ event for every repeat. Note that the Tab and Shift+Tab keys are
+ only passed to the widget if they are not used by the focus-change
+ mechanisms. To force those keys to be processed by your widget, you
+ must reimplement TQWidget::event().
+
+ \i wheelEvent() -- called whenever the user turns the mouse wheel
+ while the widget has the focus.
+
+ \i enterEvent() - called when the mouse enters the widget's screen
+ space. (This excludes screen space owned by any tqchildren of the
+ widget.)
+
+ \i leaveEvent() - called when the mouse leaves the widget's screen
+ space.
+
+ \i moveEvent() - called when the widget has been moved relative to its
+ tqparent.
+
+ \i closeEvent() - called when the user closes the widget (or when
+ close() is called).
+
+ \endlist
+
+ There are also some rather obscure events. They are listed in
+ \c tqevent.h and you need to reimplement event() to handle them.
+ The default implementation of event() handles Tab and Shift+Tab
+ (to move the keyboard focus), and passes on most other events to
+ one of the more specialized handlers above.
+
+ When implementing a widget, there are a few more things to
+ consider.
+
+ \list
+
+ \i In the constructor, be sure to set up your member variables
+ early on, before there's any chance that you might receive an event.
+
+ \i It is almost always useful to reimplement tqsizeHint() and to set
+ the correct size policy with tqsetSizePolicy(), so users of your class
+ can set up tqlayout management more easily. A size policy lets you
+ supply good defaults for the tqlayout management handling, so that
+ other widgets can contain and manage yours easily. tqsizeHint()
+ indicates a "good" size for the widget.
+
+ \i If your widget is a top-level window, setCaption() and setIcon() set
+ the title bar and icon respectively.
+
+ \endlist
+
+ \sa TQEvent, TQPainter, TQGridLayout, TQBoxLayout
+*/
+
+
+/*****************************************************************************
+ Internal TQWidgetMapper class
+
+ The purpose of this class is to map widget identifiers to TQWidget objects.
+ All TQWidget objects register themselves in the TQWidgetMapper when they
+ get an identifier. Widgets unregister themselves when they change ident-
+ ifier or when they are destroyed. A widget identifier is really a window
+ handle.
+
+ The widget mapper is created and destroyed by the main application routines
+ in the file qapp_xxx.cpp.
+ *****************************************************************************/
+
+#if defined(TQ_WS_TQWS) || defined(TQ_OS_TEMP)
+static const int WDictSize = 163; // plenty for small tqdevices
+#else
+static const int WDictSize = 1123; // plenty for 5 big complex windows
+#endif
+
+class TQWidgetMapper : public TQWidgetIntDict
+{ // maps ids -> widgets
+public:
+ TQWidgetMapper();
+ ~TQWidgetMapper();
+ TQWidget *tqfind( WId id ); // tqfind widget
+ void insert( const TQWidget * ); // insert widget
+ bool remove( WId id ); // remove widget
+private:
+ WId cur_id;
+ TQWidget *cur_widget;
+};
+
+TQWidgetMapper *TQWidget::wmapper() = 0; // app global widget mapper
+
+
+TQWidgetMapper::TQWidgetMapper() : TQWidgetIntDict(WDictSize)
+{
+ cur_id = 0;
+ cur_widget = 0;
+}
+
+TQWidgetMapper::~TQWidgetMapper()
+{
+ clear();
+}
+
+inline TQWidget *TQWidgetMapper::tqfind( WId id )
+{
+ if ( id != cur_id ) { // need to lookup
+ cur_widget = TQWidgetIntDict::tqfind((long)id);
+ if ( cur_widget )
+ cur_id = id;
+ else
+ cur_id = 0;
+ }
+ return cur_widget;
+}
+
+inline void TQWidgetMapper::insert( const TQWidget *widget )
+{
+ TQWidgetIntDict::insert((long)widget->winId(),widget);
+}
+
+inline bool TQWidgetMapper::remove( WId id )
+{
+ if ( cur_id == id ) { // reset current widget
+ cur_id = 0;
+ cur_widget = 0;
+ }
+ return TQWidgetIntDict::remove((long)id);
+}
+
+
+/*****************************************************************************
+ TQWidget utility functions
+ *****************************************************************************/
+
+static TQFont qt_naturalWidgetFont( TQWidget* w ) {
+ TQFont naturalfont = TQApplication::font( w );
+ if ( ! w->isTopLevel() ) {
+ if ( ! naturalfont.isCopyOf( TQApplication::font() ) )
+ naturalfont = naturalfont.resolve( w->parentWidget()->font() );
+ else
+ naturalfont = w->parentWidget()->font();
+ }
+ return naturalfont;
+}
+
+#ifndef TQT_NO_PALETTE
+static TQPalette qt_naturalWidgetPalette( TQWidget* w ) {
+ TQPalette naturalpalette = TQApplication::palette( w );
+ if ( !w->isTopLevel() && naturalpalette.isCopyOf( TQApplication::palette() ) )
+ naturalpalette = w->parentWidget()->palette();
+ return naturalpalette;
+}
+#endif
+
+TQSize qt_naturalWidgetSize( TQWidget *w ) {
+ TQSize s = w->tqsizeHint();
+ TQ_SPExpandData exp;
+#ifndef TQT_NO_LAYOUT
+ if ( w->tqlayout() ) {
+ if ( w->tqlayout()->hasHeightForWidth() )
+ s.setHeight( w->tqlayout()->totalHeightForWidth( s.width() ) );
+ exp = w->tqlayout()->expandingDirections();
+ } else
+#endif
+ {
+ if ( w->sizePolicy().hasHeightForWidth() )
+ s.setHeight( w->heightForWidth( s.width() ) );
+ exp = w->sizePolicy().expandingDirections();
+ }
+ if ( exp & TQSizePolicy::Horizontally )
+ s.setWidth( TQMAX( s.width(), 200 ) );
+ if ( exp & TQSizePolicy::Vertically )
+ s.setHeight( TQMAX( s.height(), 150 ) );
+#if defined(TQ_WS_X11)
+ TQRect screen = TQApplication::desktop()->screenGeometry( w->x11Screen() );
+#else // all others
+ TQRect screen = TQApplication::desktop()->screenGeometry( w->pos() );
+#endif
+ s.setWidth( TQMIN( s.width(), screen.width()*2/3 ) );
+ s.setHeight( TQMIN( s.height(), screen.height()*2/3 ) );
+ return s;
+}
+
+/*****************************************************************************
+ TQWidget member functions
+ *****************************************************************************/
+
+/*
+ Widget state flags:
+ \list
+ \i WState_Created The widget has a valid winId().
+ \i WState_Disabled The widget does not receive any mouse or keyboard
+ events.
+ \i WState_ForceDisabled The widget is explicitly disabled, i.e. it
+ will remain disabled even when all its ancestors are set to the enabled
+ state. This implies WState_Disabled.
+ \i WState_Visible The widget is currently visible.
+ \i WState_ForceHide The widget is explicitly hidden, i.e. it won't
+ become visible unless you call show() on it. WState_ForceHide
+ implies !WState_Visible.
+ \i WState_OwnCursor A cursor has been set for this widget.
+ \i WState_MouseTracking Mouse tracking is enabled.
+ \i WState_CompressKeys Compress keyboard events.
+ \i WState_BlockUpdates Repaints and updates are disabled.
+ \i WState_InPaintEvent Currently processing a paint event.
+ \i WState_Reparented The widget has been reparented.
+ \i WState_ConfigPending A configuration (resize/move) event is pending.
+ \i WState_Resized The widget has been resized.
+ \i WState_AutoMask The widget has an automatic tqmask, see setAutoMask().
+ \i WState_Polished The widget has been "polished" (i.e. late
+ initialization) by a TQStyle.
+ \i WState_DND The widget supports drag and drop, see setAcceptDrops().
+ \i WState_Exposed the widget was finally exposed (X11 only,
+ helps avoid paint event doubling).
+ \i WState_HasMouse The widget is under the mouse cursor.
+ \endlist
+*/
+
+/*! \enum TQt::WFlags
+ \internal */
+/*! \enum TQt::WState
+ \internal */
+
+/*!
+ \enum TQt::WidgetFlags
+
+ \keyword widget flag
+
+ This enum type is used to specify various window-system properties
+ for the widget. They are fairly unusual but necessary in a few
+ cases. Some of these flags depend on whether the underlying window
+ manager supports them. (See the \link toplevel-example.html
+ toplevel example\endlink for an explanation and example of their
+ use.)
+
+ The main types are
+
+ \value WType_TopLevel indicates that this widget is a top-level
+ widget, usually with a window-system frame and so on.
+
+ \value WType_Dialog indicates that this widget is a top-level
+ window that should be decorated as a dialog (i.e. typically no
+ maximize or minimize buttons in the title bar). If you want to use
+ it as a modal dialog it should be launched from another window, or
+ have a tqparent and this flag should be combined with \c WShowModal.
+ If you make it modal, the dialog will prevent other top-level
+ windows in the application from getting any input. \c WType_Dialog
+ implies \c WType_TopLevel. We refer to a top-level window that has
+ a tqparent as a \e secondary window. (See also \c WGroupLeader.)
+
+ \value WType_Popup indicates that this widget is a popup
+ top-level window, i.e. that it is modal, but has a window system
+ frame appropriate for popup menus. \c WType_Popup implies
+ WType_TopLevel.
+
+ \value WType_Desktop indicates that this widget is the desktop.
+ See also \c WPaintDesktop below. \c WType_Desktop implies \c
+ WType_TopLevel.
+
+ There are also a number of flags which you can use to customize
+ the appearance of top-level windows. These have no effect on other
+ windows:
+
+ \value WStyle_Customize indicates that the \c WStyle_* flags
+ should be used to build the window instead of the default flags.
+
+ \value WStyle_NormalBorder gives the window a normal border.
+ This cannot be combined with \c WStyle_DialogBorder or \c
+ WStyle_NoBorder.
+
+ \value WStyle_DialogBorder gives the window a thin dialog border.
+ This cannot be combined with \c WStyle_NormalBorder or \c
+ WStyle_NoBorder.
+
+ \value WStyle_NoBorder produces a borderless window. Note that
+ the user cannot move or resize a borderless window via the window
+ system. This cannot be combined with \c WStyle_NormalBorder or \c
+ WStyle_DialogBorder. On Windows, the flag works fine. On X11, the
+ result of the flag is dependent on the window manager and its
+ ability to understand MOTIF and/or NETWM hints: most existing
+ modern window managers can handle this. With \c WX11BypassWM, you
+ can bypass the window manager completely. This results in a
+ borderless window that is not managed at all (i.e. no keyboard
+ input unless you call setActiveWindow() manually).
+
+ \value WStyle_NoBorderEx this value is obsolete. It has the same
+ effect as using \c WStyle_NoBorder.
+
+ \value WStyle_Title gives the window a title bar.
+
+ \value WStyle_SysMenu adds a window system menu.
+
+ \value WStyle_Minimize adds a minimize button. Note that on
+ Windows this has to be combined with \c WStyle_SysMenu for it to
+ work.
+
+ \value WStyle_Maximize adds a maximize button. Note that on
+ Windows this has to be combined with \c WStyle_SysMenu for it to work.
+
+ \value WStyle_MinMax is equal to \c
+ WStyle_Minimize|WStyle_Maximize. Note that on Windows this has to
+ be combined with \c WStyle_SysMenu to work.
+
+ \value WStyle_ContextHelp adds a context help button to dialogs.
+
+ \value WStyle_Tool makes the window a tool window. A tool window
+ is often a small window with a smaller than usual title bar and
+ decoration, typically used for collections of tool buttons. It
+ there is a tqparent, the tool window will always be kept on top of
+ it. If there isn't a tqparent, you may consider passing \c
+ WStyle_StaysOnTop as well. If the window system supports it, a
+ tool window can be decorated with a somewhat lighter frame. It can
+ also be combined with \c WStyle_NoBorder.
+
+ \value WStyle_StaysOnTop informs the window system that the
+ window should stay on top of all other windows. Note that on some
+ window managers on X11 you also have to pass \c WX11BypassWM for
+ this flag to work correctly.
+
+ \value WStyle_Dialog indicates that the window is a logical
+ subwindow of its tqparent (i.e. a dialog). The window will not get
+ its own taskbar entry and will be kept on top of its tqparent by the
+ window system. Usually it will also be minimized when the tqparent
+ is minimized. If not customized, the window is decorated with a
+ slightly simpler title bar. This is the flag TQDialog uses.
+
+ \value WStyle_Splash indicates that the window is a splash screen.
+ On X11, we try to follow NETWM standard for a splash screen window if the
+ window manager supports is otherwise it is equivalent to \c WX11BypassWM. On
+ other platforms, it is equivalent to \c WStyle_NoBorder \c | \c WMacNoSheet \c |
+ \c WStyle_Tool \c | \c WWinOwnDC
+
+ Modifier flags:
+
+ \value WDestructiveClose makes TQt delete this widget when the
+ widget has accepted closeEvent(), or when the widget tried to
+ ignore closeEvent() but could not.
+
+ \value WPaintDesktop gives this widget paint events for the
+ desktop.
+
+ \value WPaintUnclipped makes all painters operating on this
+ widget unclipped. Children of this widget or other widgets in
+ front of it do not clip the area the painter can paint on.
+
+ \value WPaintClever indicates that TQt should \e not try to
+ optimize repainting for the widget, but instead pass on window
+ system tqrepaint events directly. (This tends to produce more events
+ and smaller tqrepaint regions.)
+
+ \value WMouseNoMask indicates that even if the widget has a tqmask,
+ it wants mouse events for its entire rectangle.
+
+ \value WStaticContents indicates that the widget contents are
+ north-west aligned and static. On resize, such a widget will
+ receive paint events only for the newly visible part of itself.
+
+ \value WNoAutoErase indicates that the widget paints all its
+ pixels. Updating, resizing, scrolling and focus changes should
+ therefore not erase the widget. This allows smart-repainting to
+ avoid flicker.
+
+ \value WResizeNoErase this value is obsolete; use WNoAutoErase instead.
+ \value WRepaintNoErase this value is obsolete; use WNoAutoErase instead.
+ \value WGroupLeader makes this window a group leader. A group
+ leader should \e not have a tqparent (i.e. it should be a top-level
+ window). Any decendant windows (direct or indirect) of a group
+ leader are in its group; other windows are not. If you show a
+ secondary window from the group (i.e. show a window whose top-most
+ tqparent is a group leader), that window will be modal with respect
+ to the other windows in the group, but modeless with respect to
+ windows in other groups.
+
+ Miscellaneous flags
+
+ \value WShowModal see WType_Dialog
+
+ Internal flags.
+
+ \value WNoMousePropagation
+ \value WStaticContents
+ \value WStyle_Reserved
+ \value WSubWindow
+ \value WType_Modal
+ \value WWinOwnDC
+ \value WX11BypassWM
+ \value WMacNoSheet
+ \value WMacDrawer
+ \value WStyle_Mask
+ \value WType_Mask
+
+*/
+
+/*!
+ \enum TQt::WidgetState
+
+ Internal flags.
+
+ \value WState_Created
+ \value WState_Disabled
+ \value WState_Visible
+ \value WState_ForceHide
+ \value WState_OwnCursor
+ \value WState_MouseTracking
+ \value WState_CompressKeys
+ \value WState_BlockUpdates
+ \value WState_InPaintEvent
+ \value WState_Reparented
+ \value WState_ConfigPending
+ \value WState_Resized
+ \value WState_AutoMask
+ \value WState_Polished
+ \value WState_DND
+ \value WState_Reserved0 \e internal
+ \value WState_CreatedHidden
+ \value WState_Maximized
+ \value WState_Minimized
+ \value WState_ForceDisabled
+ \value WState_Exposed
+ \value WState_HasMouse
+ \value WState_CreatedHidden
+ \value WState_OwnSizePolicy
+ \value WState_FullScreen
+*/
+
+
+/*!
+ \enum TQt::WindowState
+
+ \keyword window state
+
+ This enum type is used to specify the current state of a top-level
+ window.
+
+ The states are
+
+ \value WindowNoState The window has no state set (in normal state).
+ \value WindowMinimized The window is minimized (i.e. iconified).
+ \value WindowMaximized The window is maximized with a frame around it.
+ \value WindowFullScreen The window fills the entire screen without any frame around it.
+ \value WindowActive The window is the active window, i.e. it has keyboard focus.
+
+*/
+
+/*!
+ Constructs a widget which is a child of \a tqparent, with the name
+ \a name and widget flags set to \a f.
+
+ If \a tqparent is 0, the new widget becomes a top-level window. If
+ \a tqparent is another widget, this widget becomes a child window
+ inside \a tqparent. The new widget is deleted when its \a tqparent is
+ deleted.
+
+ The \a name is sent to the TQObject constructor.
+
+ The widget flags argument, \a f, is normally 0, but it can be set
+ to customize the window frame of a top-level widget (i.e. \a
+ tqparent must be 0). To customize the frame, set the \c
+ WStyle_Customize flag OR'ed with any of the \l TQt::WidgetFlags.
+
+ If you add a child widget to an already visible widget you must
+ explicitly show the child to make it visible.
+
+ Note that the X11 version of TQt may not be able to deliver all
+ combinations of style flags on all systems. This is because on
+ X11, TQt can only ask the window manager, and the window manager
+ can override the application's settings. On Windows, TQt can set
+ whatever flags you want.
+
+ Example:
+ \code
+ TQLabel *splashScreen = new TQLabel( 0, "mySplashScreen",
+ WStyle_Customize | WStyle_Splash );
+ \endcode
+*/
+
+TQWidget::TQWidget( TQWidget *tqparent, const char *name, WFlags f )
+ : TQObject( tqparent, name ), TQPaintDevice( TQInternal::Widget )
+{
+#if defined(TQT_CHECK_STATE) && !defined(TQ_WS_WIN)
+ if ( tqApp->type() == TQApplication::Tty ) {
+ qWarning( "TQWidget: Cannot create a TQWidget when no GUI "
+ "is being used" );
+ }
+#endif
+
+ fstrut_dirty = 1;
+
+ isWidget = TRUE; // is a widget
+ winid = 0; // default attributes
+ widget_state = 0;
+ widget_flags = f;
+ focus_policy = 0;
+ own_font = 0;
+ own_palette = 0;
+ sizehint_forced = 0;
+ is_closing = 0;
+ in_show = 0;
+ in_show_maximized = 0;
+ im_enabled = FALSE;
+#ifndef TQT_NO_LAYOUT
+ lay_out = 0;
+#endif
+ extra = 0; // no extra widget info
+#ifndef TQT_NO_PALETTE
+ bg_col = pal.active().background(); // default background color
+#endif
+ create(); // platform-dependent init
+#ifndef TQT_NO_PALETTE
+ pal = isTopLevel() ? TQApplication::palette() : parentWidget()->palette();
+#endif
+ if ( ! isTopLevel() )
+ fnt = parentWidget()->font();
+#if defined(TQ_WS_X11)
+ fnt.x11SetScreen( x11Screen() );
+#endif // TQ_WS_X11
+
+ if ( !isDesktop() )
+ setBackgroundFromMode(); //### parts of this are done in create but not all (see reparent(...) )
+ // make sure move/resize events are sent to all widgets
+ TQApplication::postEvent( this, new TQMoveEvent( crect.topLeft(),
+ crect.topLeft() ) );
+ TQApplication::postEvent( this, new TQResizeEvent(crect.size(),
+ crect.size()) );
+ if ( isTopLevel() ) {
+ setWState( WState_ForceHide | WState_CreatedHidden );
+ TQFocusData *fd = focusData( TRUE );
+ if ( fd->tqfocusWidgets.tqfindRef(this) < 0 )
+ fd->tqfocusWidgets.append( this );
+ } else {
+ // propagate enabled state
+ if ( !parentWidget()->isEnabled() )
+ setWState( WState_Disabled );
+ // new widgets do not show up in already visible parents
+ if ( parentWidget()->isVisible() )
+ setWState( WState_ForceHide | WState_CreatedHidden );
+ }
+ if ( ++instanceCounter > maxInstances )
+ maxInstances = instanceCounter;
+}
+
+/*!
+ Destroys the widget.
+
+ All this widget's tqchildren are deleted first. The application
+ exits if this widget is the main widget.
+*/
+
+TQWidget::~TQWidget()
+{
+#if defined (TQT_CHECK_STATE)
+ if ( paintingActive() )
+ qWarning( "%s (%s): deleted while being painted", className(), name() );
+#endif
+
+ // Remove myself and all tqchildren from the can-take-focus list
+ TQFocusData *f = focusData( FALSE );
+ if ( f ) {
+ TQPtrListIterator<TQWidget> it(f->tqfocusWidgets);
+ TQWidget *w;
+ while ( (w = it.current()) ) {
+ ++it;
+ TQWidget * p = w;
+ while( p && p != this )
+ p = p->parentWidget();
+ if ( p ) // my descendant
+ f->tqfocusWidgets.removeRef( w );
+ }
+ }
+ --instanceCounter;
+
+ if ( TQApplication::main_widget == this ) { // reset main widget
+ TQApplication::main_widget = 0;
+ if (tqApp)
+ tqApp->quit();
+ }
+
+ if ( hasFocus() )
+ clearFocus();
+
+ if ( isTopLevel() && isShown() && winId() )
+ hide();
+
+ // A tqparent widget must destroy all its tqchildren before destroying itself
+ if ( childObjects ) { // delete tqchildren objects
+ TQObjectListIt it(*childObjects);
+ TQObject *obj;
+ while ( (obj=it.current()) ) {
+ ++it;
+ obj->parentObj = 0;
+ childObjects->removeRef( obj );
+ delete obj;
+ }
+ delete childObjects;
+ childObjects = 0;
+ }
+
+ TQApplication::removePostedEvents( this );
+
+ destroy(); // platform-dependent cleanup
+ if ( extra )
+ deleteExtra();
+}
+
+int TQWidget::instanceCounter = 0; // Current number of widget instances
+int TQWidget::maxInstances = 0; // Maximum number of widget instances
+
+/*!
+ \internal
+ Creates the global widget mapper.
+ The widget mapper converts window handles to widget pointers.
+ \sa destroyMapper()
+*/
+
+void TQWidget::createMapper()
+{
+ mapper = new TQWidgetMapper;
+ TQ_CHECK_PTR( mapper );
+}
+
+/*!
+ \internal
+ Destroys the global widget mapper.
+ \sa createMapper()
+*/
+
+void TQWidget::destroyMapper()
+{
+ if ( !mapper ) // already gone
+ return;
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)mapper) );
+ TQWidgetMapper * myMapper = mapper;
+ mapper = 0;
+ register TQWidget *w;
+ while ( (w=it.current()) ) { // remove parents widgets
+ ++it;
+ if ( !w->parentObj ) // widget is a tqparent
+ w->destroy( TRUE, TRUE );
+ }
+ delete myMapper;
+}
+
+
+static TQWidgetList *wListInternal( TQWidgetMapper *mapper, bool onlyTopLevel )
+{
+ TQWidgetList *list = new TQWidgetList;
+ TQ_CHECK_PTR( list );
+ if ( mapper ) {
+ TQWidget *w;
+ TQWidgetIntDictIt it( *((TQWidgetIntDict*)mapper) );
+ while ( (w=it.current()) ) {
+ ++it;
+ if ( !onlyTopLevel || w->isTopLevel() )
+ list->append( w );
+ }
+ }
+ return list;
+}
+
+/*!
+ \internal
+ Returns a list of all widgets.
+ \sa tlwList(), TQApplication::allWidgets()
+*/
+
+TQWidgetList *TQWidget::wList()
+{
+ return wListInternal( mapper, FALSE );
+}
+
+/*!
+ \internal
+ Returns a list of all top level widgets.
+ \sa wList(), TQApplication::tqtopLevelWidgets()
+*/
+
+TQWidgetList *TQWidget::tlwList()
+{
+ return wListInternal( mapper, TRUE );
+}
+
+
+void TQWidget::setWinId( WId id ) // set widget identifier
+{
+ if ( !mapper ) // mapper destroyed
+ return;
+ if ( winid )
+ mapper->remove( winid );
+ winid = id;
+#if defined(TQ_WS_X11)
+ hd = id; // X11: hd == ident
+#endif
+ if ( id )
+ mapper->insert( this );
+}
+
+
+/*!
+ \internal
+ Returns a pointer to the block of extra widget data.
+*/
+
+TQWExtra *TQWidget::extraData()
+{
+ return extra;
+}
+
+
+/*!
+ \internal
+ Returns a pointer to the block of extra top level widget data.
+
+ This data is guaranteed to exist for top level widgets.
+*/
+
+TQTLWExtra *TQWidget::topData()
+{
+ createTLExtra();
+ return extra->topextra;
+}
+
+
+void TQWidget::createTLExtra()
+{
+ if ( !extra )
+ createExtra();
+ if ( !extra->topextra ) {
+ TQTLWExtra* x = extra->topextra = new TQTLWExtra;
+#if defined( TQ_WS_WIN ) || defined( TQ_WS_MAC )
+ x->opacity = 255;
+#endif
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ x->icon = 0;
+#endif
+ x->focusData = 0;
+ x->fleft = x->fright = x->ftop = x->fbottom = 0;
+ x->incw = x->inch = 0;
+ x->basew = x->baseh = 0;
+ x->normalGeometry = TQRect(0,0,-1,-1);
+#if defined(TQ_WS_X11)
+ x->embedded = 0;
+ x->parentWinId = 0;
+ x->spont_unmapped = 0;
+ x->dnd = 0;
+ x->uspos = 0;
+ x->ussize = 0;
+#endif
+ x->savedFlags = 0;
+#if defined(TQ_WS_TQWS) && !defined(TQT_NO_TQWS_MANAGER)
+ x->decor_allocated_region = TQRegion();
+ x->qwsManager = 0;
+#endif
+ createTLSysExtra();
+ }
+}
+
+/*!
+ \internal
+ Creates the widget extra data.
+*/
+
+void TQWidget::createExtra()
+{
+ if ( !extra ) { // if not exists
+ extra = new TQWExtra;
+ TQ_CHECK_PTR( extra );
+ extra->minw = extra->minh = 0;
+ extra->maxw = extra->maxh = TQWIDGETSIZE_MAX;
+ extra->bg_pix = 0;
+ extra->focus_proxy = 0;
+#ifndef TQT_NO_CURSOR
+ extra->curs = 0;
+#endif
+ extra->topextra = 0;
+ extra->bg_mode = PaletteBackground;
+ extra->bg_mode_visual = PaletteBackground;
+ extra->bg_origin = WidgetOrigin;
+#ifndef TQT_NO_STYLE
+ extra->style = 0;
+#endif
+ extra->size_policy = TQSizePolicy( TQSizePolicy::Preferred,
+ TQSizePolicy::Preferred );
+ createSysExtra();
+ }
+}
+
+
+/*!
+ \internal
+ Deletes the widget extra data.
+*/
+
+void TQWidget::deleteExtra()
+{
+ if ( extra ) { // if exists
+ delete extra->bg_pix;
+#ifndef TQT_NO_CURSOR
+ delete extra->curs;
+#endif
+ deleteSysExtra();
+ if ( extra->topextra ) {
+ deleteTLSysExtra();
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ delete extra->topextra->icon;
+#endif
+ delete extra->topextra->focusData;
+#if defined(TQ_WS_TQWS) && !defined(TQT_NO_TQWS_MANAGER)
+ delete extra->topextra->qwsManager;
+#endif
+ delete extra->topextra;
+ }
+ delete extra;
+ // extra->xic destroyed in TQWidget::destroy()
+ extra = 0;
+ }
+}
+
+
+/*!
+ \internal
+ This function is called when a widget is hidden or destroyed.
+ It resets some application global pointers that should only refer active,
+ visible widgets.
+*/
+
+void TQWidget::deactivateWidgetCleanup()
+{
+ // If this was the active application window, reset it
+ if ( this == TQApplication::active_window )
+ tqApp->setActiveWindow( 0 );
+ // If the is the active mouse press widget, reset it
+#ifdef TQ_WS_MAC
+ extern TQGuardedPtr<TQWidget> qt_button_down;
+#else
+ extern TQWidget *qt_button_down;
+#endif
+ if ( this == (TQWidget *)qt_button_down )
+ qt_button_down = 0;
+}
+
+
+/*!
+ Returns a pointer to the widget with window identifer/handle \a
+ id.
+
+ The window identifier type depends on the underlying window
+ system, see \c tqwindowdefs.h for the actual definition. If there
+ is no widget with this identifier, 0 is returned.
+*/
+
+TQWidget *TQWidget::tqfind( WId id )
+{
+ return mapper ? mapper->tqfind( id ) : 0;
+}
+
+/*!
+ \fn TQWidgetMapper *TQWidget::wmapper()
+ \internal
+ Returns a pointer to the widget mapper.
+
+ The widget mapper is an internal dictionary that is used to map from
+ window identifiers/handles to widget pointers.
+ \sa tqfind(), id()
+*/
+
+/*!
+ \fn WFlags TQWidget::getWFlags() const
+
+ Returns the widget flags for this this widget.
+
+ Widget flags are a combination of \l{TQt::WidgetFlags}.
+
+ \sa testWFlags(), setWFlags(), clearWFlags()
+*/
+
+/*!
+ \fn void TQWidget::setWFlags( WFlags f )
+
+ Sets the widget flags \a f.
+
+ Widget flags are a combination of \l{TQt::WidgetFlags}.
+
+ \sa testWFlags(), getWFlags(), clearWFlags()
+*/
+
+/*!
+ \fn void TQWidget::clearWFlags( WFlags f )
+
+ Clears the widget flags \a f.
+
+ Widget flags are a combination of \l{TQt::WidgetFlags}.
+
+ \sa testWFlags(), getWFlags(), setWFlags()
+*/
+
+
+
+/*!
+ \fn WId TQWidget::winId() const
+
+ Returns the window system identifier of the widget.
+
+ Portable in principle, but if you use it you are probably about to
+ do something non-portable. Be careful.
+
+ \sa tqfind()
+*/
+
+#ifndef TQT_NO_STYLE
+/*!
+ Returns the GUI style for this widget
+
+ \sa TQWidget::setStyle(), TQApplication::setStyle(), TQApplication::style()
+*/
+
+TQStyle& TQWidget::style() const
+{
+ if ( extra && extra->style )
+ return *extra->style;
+ TQStyle &ret = tqApp->style();
+ return ret;
+}
+
+/*!
+ Sets the widget's GUI style to \a style. Ownership of the style
+ object is not transferred.
+
+ If no style is set, the widget uses the application's style,
+ TQApplication::style() instead.
+
+ Setting a widget's style has no effect on existing or future child
+ widgets.
+
+ \warning This function is particularly useful for demonstration
+ purposes, where you want to show TQt's styling capabilities. Real
+ applications should avoid it and use one consistent GUI style
+ instead.
+
+ \sa style(), TQStyle, TQApplication::style(), TQApplication::setStyle()
+*/
+
+void TQWidget::setStyle( TQStyle *style )
+{
+ TQStyle& old = TQWidget::style();
+ createExtra();
+ extra->style = style;
+ if ( !testWFlags(WType_Desktop) // (except desktop)
+ && testWState(WState_Polished)) { // (and have been polished)
+ old.unPolish( this );
+ TQWidget::style().polish( this );
+ }
+ styleChange( old );
+}
+
+/*!
+ \overload
+
+ Sets the widget's GUI style to \a style using the TQStyleFactory.
+*/
+TQStyle* TQWidget::setStyle( const TQString &style )
+{
+ TQStyle *s = TQStyleFactory::create( style );
+ setStyle( s );
+ return s;
+}
+
+/*!
+ This virtual function is called when the style of the widgets
+ changes. \a oldStyle is the previous GUI style; you can get the
+ new style from style().
+
+ Reimplement this function if your widget needs to know when its
+ GUI style changes. You will almost certainly need to update the
+ widget using update().
+
+ The default implementation updates the widget including its
+ tqgeometry.
+
+ \sa TQApplication::setStyle(), style(), update(), updateGeometry()
+*/
+
+void TQWidget::styleChange( TQStyle& /* oldStyle */ )
+{
+ update();
+ updateGeometry();
+}
+
+#endif
+
+/*!
+ \property TQWidget::isTopLevel
+ \brief whether the widget is a top-level widget
+
+ A top-level widget is a widget which usually has a frame and a
+ \link TQWidget::caption caption (title)\endlink. \link
+ TQWidget::isPopup() Popup\endlink and \link TQWidget::isDesktop()
+ desktop\endlink widgets are also top-level widgets.
+
+ A top-level widget can have a \link TQWidget::parentWidget() tqparent
+ widget\endlink. It will then be grouped with its tqparent and deleted
+ when the tqparent is deleted, minimized when the tqparent is minimized
+ etc. If supported by the window manager, it will also have a
+ common taskbar entry with its tqparent.
+
+ TQDialog and TQMainWindow widgets are by default top-level, even if
+ a tqparent widget is specified in the constructor. This behavior is
+ specified by the \c WType_TopLevel widget flag.
+
+ \sa tqtopLevelWidget(), isDialog(), isModal(), isPopup(), isDesktop(), parentWidget()
+*/
+
+/*!
+ \property TQWidget::isDialog
+ \brief whether the widget is a dialog widget
+
+ A dialog widget is a secondary top-level widget, i.e. a top-level
+ widget with a tqparent.
+
+ \sa isTopLevel(), TQDialog
+*/
+
+/*!
+ \property TQWidget::isPopup
+ \brief whether the widget is a popup widget
+
+ A popup widget is created by specifying the widget flag \c
+ WType_Popup to the widget constructor. A popup widget is also a
+ top-level widget.
+
+ \sa isTopLevel()
+*/
+
+/*!
+ \property TQWidget::isDesktop
+ \brief whether the widget is a desktop widget, i.e. represents the desktop
+
+ A desktop widget is also a top-level widget.
+
+ \sa isTopLevel(), TQApplication::desktop()
+*/
+
+/*!
+ \property TQWidget::isModal
+ \brief whether the widget is a modal widget
+
+ This property only makes sense for top-level widgets. A modal
+ widget prevents widgets in all other top-level widgets from
+ getting any input.
+
+ \sa isTopLevel(), isDialog(), TQDialog
+*/
+
+/*!
+ \property TQWidget::underMouse
+ \brief whether the widget is under the mouse cursor
+
+ This value is not updated properly during drag and drop
+ operations.
+
+ \sa TQEvent::Enter, TQEvent::Leave
+*/
+
+/*!
+ \property TQWidget::minimized
+ \brief whether this widget is minimized (iconified)
+
+ This property is only relevant for top-level widgets.
+
+ \sa showMinimized(), visible, show(), hide(), showNormal(), maximized
+*/
+bool TQWidget::isMinimized() const
+{ return testWState(WState_Minimized); }
+
+/*!
+ Shows the widget minimized, as an icon.
+
+ Calling this function only affects \link isTopLevel() top-level
+ widgets\endlink.
+
+ \sa showNormal(), showMaximized(), show(), hide(), isVisible(),
+ isMinimized()
+*/
+void TQWidget::showMinimized()
+{
+ bool isMin = isMinimized();
+ if (isMin && isVisible()) return;
+
+ if (!isMin)
+ setWindowState((windowState() & ~WindowActive) | WindowMinimized);
+ show();
+ if (!isTopLevel())
+ TQApplication::sendPostedEvents(this, TQEvent::ShowMinimized);
+}
+
+/*!
+ \property TQWidget::maximized
+ \brief whether this widget is maximized
+
+ This property is only relevant for top-level widgets.
+
+ Note that due to limitations in some window-systems, this does not
+ always report the expected results (e.g. if the user on X11
+ maximizes the window via the window manager, TQt has no way of
+ distinguishing this from any other resize). This is expected to
+ improve as window manager protocols evolve.
+
+ \sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized
+*/
+bool TQWidget::isMaximized() const
+{ return testWState(WState_Maximized); }
+
+
+
+/*! Returns the current window state. The window state is a OR'ed
+ combination of TQt::WindowState: \c WindowMinimized, \c
+ WindowMaximized, \c WindowFullScreen and \c WindowActive.
+
+ \sa TQt::WindowState setWindowState()
+ */
+uint TQWidget::windowState() const
+{
+ uint state = 0;
+ if (testWState(WState_Minimized))
+ state |= WindowMinimized;
+ if (testWState(WState_Maximized))
+ state |= WindowMaximized;
+ if (testWState(WState_FullScreen))
+ state |= WindowFullScreen;
+ if (isActiveWindow())
+ state |= WindowActive;
+ return state;
+}
+
+/*!
+ \fn void TQWidget::setWindowState(uint windowState)
+
+ Sets the window state to \a windowState. The window state is a OR'ed
+ combination of TQt::WindowState: \c WindowMinimized, \c
+ WindowMaximized, \c WindowFullScreen and \c WindowActive.
+
+ If the window is not visible (i.e. isVisible() returns FALSE), the
+ window state will take effect when show() is called. For visible
+ windows, the change is immediate. For example, to toggle between
+ full-screen and mormal mode, use the following code:
+
+ \code
+ w->setWindowState(w->windowState() ^ WindowFullScreen);
+ \endcode
+
+ In order to restore and activate a minimized window (while
+ preserving its maximized and/or full-screen state), use the following:
+
+ \code
+ w->setWindowState(w->windowState() & ~WindowMinimized | WindowActive);
+ \endcode
+
+ Note: On some window systems \c WindowActive is not immediate, and may be
+ ignored in certain cases.
+
+ \sa TQt::WindowState windowState()
+*/
+
+/*!
+ \property TQWidget::fullScreen
+ \brief whether the widget is full screen
+
+ \sa windowState(), minimized, maximized
+*/
+bool TQWidget::isFullScreen() const
+{ return testWState(WState_FullScreen); }
+
+/*!
+ Shows the widget in full-screen mode.
+
+ Calling this function only affects top-level widgets.
+
+ To return from full-screen mode, call showNormal().
+
+ Full-screen mode works fine under Windows, but has certain
+ problems under X. These problems are due to limitations of the
+ ICCCM protocol that specifies the communication between X11
+ clients and the window manager. ICCCM simply does not understand
+ the concept of non-decorated full-screen windows. Therefore, the
+ best we can do is to request a borderless window and place and
+ resize it to fill the entire screen. Depending on the window
+ manager, this may or may not work. The borderless window is
+ requested using MOTIF hints, which are at least partially
+ supported by virtually all modern window managers.
+
+ An alternative would be to bypass the window manager entirely and
+ create a window with the WX11BypassWM flag. This has other severe
+ problems though, like totally broken keyboard focus and very
+ strange effects on desktop changes or when the user raises other
+ windows.
+
+ X11 window managers that follow modern post-ICCCM specifications
+ support full-screen mode properly.
+
+ \sa showNormal(), showMaximized(), show(), hide(), isVisible()
+*/
+void TQWidget::showFullScreen()
+{
+ bool isFull = isFullScreen();
+ if (isFull && isVisible())
+ return;
+
+ if (!isFull)
+ setWindowState(windowState() | WindowFullScreen);
+ show();
+ if (!isTopLevel())
+ TQApplication::sendPostedEvents(this, TQEvent::ShowFullScreen);
+ setActiveWindow();
+}
+
+/*!
+ Shows the widget maximized.
+
+ Calling this function only affects \link isTopLevel() top-level
+ widgets\endlink.
+
+ On X11, this function may not work properly with certain window
+ managers. See the \link tqgeometry.html Window Geometry
+ documentation\endlink for an explanation.
+
+ \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
+*/
+void TQWidget::showMaximized()
+{
+ if (isMaximized() && isVisible() && !isMinimized())
+ return;
+
+ setWindowState((windowState() & ~WindowMinimized) | WindowMaximized);
+ show();
+ if (!isTopLevel())
+ TQApplication::sendPostedEvents(this, TQEvent::ShowMaximized);
+}
+
+/*!
+ Restores the widget after it has been maximized or minimized.
+
+ Calling this function only affects \link isTopLevel() top-level
+ widgets\endlink.
+
+ \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()
+*/
+void TQWidget::showNormal()
+{
+ setWindowState(WindowNoState);
+ show();
+ if (!isTopLevel())
+ TQApplication::sendPostedEvents(this, TQEvent::ShowNormal);
+}
+
+/*!
+ Returns TRUE if this widget would become enabled if \a ancestor is
+ enabled; otherwise returns FALSE.
+
+ This is the case if neither the widget itself nor every tqparent up
+ to but excluding \a ancestor has been explicitly disabled.
+
+ isEnabledTo(0) is equivalent to isEnabled().
+
+ \sa setEnabled() enabled
+*/
+
+bool TQWidget::isEnabledTo( TQWidget* ancestor ) const
+{
+ const TQWidget * w = this;
+ while ( w && !w->testWState(WState_ForceDisabled)
+ && !w->isTopLevel()
+ && w->parentWidget()
+ && w->parentWidget() != ancestor )
+ w = w->parentWidget();
+ return !w->testWState( WState_ForceDisabled );
+}
+
+
+/*!
+ \fn bool TQWidget::isEnabledToTLW() const
+ \obsolete
+
+ This function is deprecated. It is equivalent to isEnabled()
+*/
+
+/*!
+ \property TQWidget::enabled
+ \brief whether the widget is enabled
+
+ An enabled widget receives keyboard and mouse events; a disabled
+ widget does not. In fact, an enabled widget only receives keyboard
+ events when it is in focus.
+
+ Some widgets display themselves differently when they are
+ disabled. For example a button might draw its label grayed out. If
+ your widget needs to know when it becomes enabled or disabled, you
+ can reimplement the enabledChange() function.
+
+ Disabling a widget implicitly disables all its tqchildren. Enabling
+ respectively enables all child widgets unless they have been
+ explicitly disabled.
+
+ \sa isEnabled(), isEnabledTo(), TQKeyEvent, TQMouseEvent, enabledChange()
+*/
+void TQWidget::setEnabled( bool enable )
+{
+ if ( enable )
+ clearWState( WState_ForceDisabled );
+ else
+ setWState( WState_ForceDisabled );
+
+ if ( !isTopLevel() && parentWidget() &&
+ !parentWidget()->isEnabled() && enable )
+ return; // nothing we can do
+
+ if ( enable ) {
+ if ( testWState(WState_Disabled) ) {
+ clearWState( WState_Disabled );
+ setBackgroundFromMode();
+ enabledChange( !enable );
+ if ( childrenListObject() ) {
+ TQObjectListIt it( *childrenListObject() );
+ TQWidget *w;
+ while( (w = (TQWidget *)it.current()) != 0 ) {
+ ++it;
+ if ( w->isWidgetType() &&
+ !w->testWState( WState_ForceDisabled ) )
+ w->setEnabled( TRUE );
+ }
+ }
+ }
+ } else {
+ if ( !testWState(WState_Disabled) ) {
+ if (tqfocusWidget() == this) {
+ bool parentIsEnabled = (!parentWidget() || parentWidget()->isEnabled());
+ if (!parentIsEnabled || !focusNextPrevChild(TRUE))
+ clearFocus();
+ }
+ setWState( WState_Disabled );
+ setBackgroundFromMode();
+ enabledChange( !enable );
+ if ( childrenListObject() ) {
+ TQObjectListIt it( *childrenListObject() );
+ TQWidget *w;
+ while( (w = (TQWidget *)it.current()) != 0 ) {
+ ++it;
+ if ( w->isWidgetType() && w->isEnabled() ) {
+ w->setEnabled( FALSE );
+ w->clearWState( WState_ForceDisabled );
+ }
+ }
+ }
+ }
+ }
+#if defined(TQ_WS_X11)
+ if ( testWState( WState_OwnCursor ) ) {
+ // enforce the windows behavior of clearing the cursor on
+ // disabled widgets
+
+ extern void qt_x11_enforce_cursor( TQWidget * w ); // defined in qwidget_x11.cpp
+ qt_x11_enforce_cursor( this );
+ }
+#endif
+#ifdef TQ_WS_WIN
+ TQInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
+#endif
+}
+
+/*!
+ Disables widget input events if \a disable is TRUE; otherwise
+ enables input events.
+
+ See the \l enabled documentation for more information.
+
+ \sa isEnabledTo(), TQKeyEvent, TQMouseEvent, enabledChange()
+*/
+void TQWidget::setDisabled( bool disable )
+{
+ setEnabled( !disable );
+}
+
+/*!
+ \fn void TQWidget::enabledChange( bool oldEnabled )
+
+ This virtual function is called from setEnabled(). \a oldEnabled
+ is the previous setting; you can get the new setting from
+ isEnabled().
+
+ Reimplement this function if your widget needs to know when it
+ becomes enabled or disabled. You will almost certainly need to
+ update the widget using update().
+
+ The default implementation repaints the visible part of the
+ widget.
+
+ \sa setEnabled(), isEnabled(), tqrepaint(), update(), clipRegion()
+*/
+
+void TQWidget::enabledChange( bool )
+{
+ update();
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+ TQAccessible::updateAccessibility( this, 0, TQAccessible::StateChanged );
+#endif
+}
+
+/*!
+ \fn void TQWidget::windowActivationChange( bool oldActive )
+
+ This virtual function is called for a widget when its window is
+ activated or deactivated by the window system. \a oldActive is the
+ previous state; you can get the new setting from isActiveWindow().
+
+ Reimplement this function if your widget needs to know when its
+ window becomes activated or deactivated.
+
+ The default implementation updates the visible part of the widget
+ if the inactive and the active colorgroup are different for colors
+ other than the highlight and link colors.
+
+ \sa setActiveWindow(), isActiveWindow(), update(), palette()
+*/
+
+void TQWidget::windowActivationChange( bool )
+{
+#ifndef TQT_NO_PALETTE
+ if ( !isVisible() )
+ return;
+
+ const TQColorGroup &acg = palette().active();
+ const TQColorGroup &icg = palette().inactive();
+
+ if ( acg != icg ) {
+ BackgroundMode bm = backgroundMode();
+ TQColorGroup::ColorRole role = TQPalette::backgroundRoleFromMode(bm);
+ if ( bm > NoBackground && acg.brush(role) != icg.brush(role) )
+ setBackgroundFromMode();
+ else if ( acg.background() == icg.background() &&
+ acg.base() == icg.base() &&
+ acg.text() == icg.text() &&
+ acg.foreground() == icg.foreground() &&
+ acg.button() == icg.button() &&
+ acg.buttonText() == icg.buttonText() &&
+ acg.brightText() == icg.brightText() &&
+ acg.dark() == icg.dark() &&
+ acg.light() == icg.light() &&
+ acg.mid() == icg.mid() &&
+ acg.midlight() == icg.midlight() &&
+ acg.shadow() == icg.shadow() )
+ return;
+ update();
+ }
+#endif
+}
+
+/*!
+ \property TQWidget::frameGeometry
+ \brief tqgeometry of the widget relative to its tqparent including any
+ window frame
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of tqgeometry issues with top-level widgets.
+
+ \sa tqgeometry() x() y() pos()
+*/
+TQRect TQWidget::frameGeometry() const
+{
+ if (isTopLevel() && ! isPopup()) {
+ if (fstrut_dirty)
+ updateFrameStrut();
+ TQWidget *that = (TQWidget *) this;
+ TQTLWExtra *top = that->topData();
+ return TQRect(crect.x() - top->fleft,
+ crect.y() - top->ftop,
+ crect.width() + top->fleft + top->fright,
+ crect.height() + top->ftop + top->fbottom);
+ }
+ return crect;
+}
+
+/*! \property TQWidget::x
+ \brief the x coordinate of the widget relative to its tqparent including
+ any window frame
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of top-level widget tqgeometry.
+
+ \sa frameGeometry, y, pos
+*/
+int TQWidget::x() const
+{
+ if (isTopLevel() && ! isPopup()) {
+ if (fstrut_dirty)
+ updateFrameStrut();
+ TQWidget *that = (TQWidget *) this;
+ return crect.x() - that->topData()->fleft;
+ }
+ return crect.x();
+}
+
+/*!
+ \property TQWidget::y
+ \brief the y coordinate of the widget relative to its tqparent and
+ including any window frame
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of top-level widget tqgeometry.
+
+ \sa frameGeometry, x, pos
+*/
+int TQWidget::y() const
+{
+ if (isTopLevel() && ! isPopup()) {
+ if (fstrut_dirty)
+ updateFrameStrut();
+ TQWidget *that = (TQWidget *) this;
+ return crect.y() - that->topData()->ftop;
+ }
+ return crect.y();
+}
+
+/*!
+ \property TQWidget::pos
+ \brief the position of the widget within its tqparent widget
+
+ If the widget is a top-level widget, the position is that of the
+ widget on the desktop, including its frame.
+
+ When changing the position, the widget, if visible, receives a
+ move event (moveEvent()) immediately. If the widget is not
+ currently visible, it is guaranteed to receive an event before it
+ is shown.
+
+ move() is virtual, and all other overloaded move() implementations
+ in TQt call it.
+
+ \warning Calling move() or setGeometry() inside moveEvent() can
+ lead to infinite recursion.
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of top-level widget tqgeometry.
+
+ \sa frameGeometry, size x(), y()
+*/
+TQPoint TQWidget::pos() const
+{
+ if (isTopLevel() && ! isPopup()) {
+ if (fstrut_dirty)
+ updateFrameStrut();
+ TQWidget *that = (TQWidget *) this;
+ TQTLWExtra *top = that->topData();
+ return TQPoint(crect.x() - top->fleft, crect.y() - top->ftop);
+ }
+ return crect.topLeft();
+}
+
+/*!
+ \property TQWidget::tqgeometry
+ \brief the tqgeometry of the widget relative to its tqparent and
+ excluding the window frame
+
+ When changing the tqgeometry, the widget, if visible, receives a
+ move event (moveEvent()) and/or a resize event (resizeEvent())
+ immediately. If the widget is not currently visible, it is
+ guaranteed to receive appropriate events before it is shown.
+
+ The size component is adjusted if it lies outside the range
+ defined by tqminimumSize() and tqmaximumSize().
+
+ setGeometry() is virtual, and all other overloaded setGeometry()
+ implementations in TQt call it.
+
+ \warning Calling setGeometry() inside resizeEvent() or moveEvent()
+ can lead to infinite recursion.
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of top-level widget tqgeometry.
+
+ \sa frameGeometry(), rect(), move(), resize(), moveEvent(),
+ resizeEvent(), tqminimumSize(), tqmaximumSize()
+*/
+
+/*!
+ \property TQWidget::size
+ \brief the size of the widget excluding any window frame
+
+ When resizing, the widget, if visible, receives a resize event
+ (resizeEvent()) immediately. If the widget is not currently
+ visible, it is guaranteed to receive an event before it is shown.
+
+ The size is adjusted if it lies outside the range defined by
+ tqminimumSize() and tqmaximumSize(). Furthermore, the size is always
+ at least TQSize(1, 1). For toplevel widgets, the minimum size
+ might be larger, depending on the window manager.
+
+ If you want a top-level window to have a fixed size, call
+ setResizeMode( TQLayout::FreeResize ) on its tqlayout.
+
+ resize() is virtual, and all other overloaded resize()
+ implementations in TQt call it.
+
+ \warning Calling resize() or setGeometry() inside resizeEvent() can
+ lead to infinite recursion.
+
+ \sa pos, tqgeometry, tqminimumSize, tqmaximumSize, resizeEvent()
+*/
+
+/*!
+ \property TQWidget::width
+ \brief the width of the widget excluding any window frame
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of top-level widget tqgeometry.
+
+ \sa tqgeometry, height, size
+*/
+
+/*!
+ \property TQWidget::height
+ \brief the height of the widget excluding any window frame
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of top-level widget tqgeometry.
+
+ \sa tqgeometry, width, size
+*/
+
+/*!
+ \property TQWidget::rect
+ \brief the internal tqgeometry of the widget excluding any window
+ frame
+
+ The rect property equals TQRect(0, 0, width(), height()).
+
+ See the \link tqgeometry.html Window Geometry documentation\endlink
+ for an overview of top-level widget tqgeometry.
+
+ \sa size
+*/
+
+/*!
+ \property TQWidget::tqchildrenRect
+ \brief the bounding rectangle of the widget's tqchildren
+
+ Hidden tqchildren are excluded.
+
+ \sa tqchildrenRegion() tqgeometry()
+*/
+
+TQRect TQWidget::tqchildrenRect() const
+{
+ TQRect r( 0, 0, 0, 0 );
+ if ( !childrenListObject() )
+ return r;
+ TQObjectListIt it( *childrenListObject() );
+ TQObject *obj;
+ while ( (obj = it.current()) ) {
+ ++it;
+ if ( obj->isWidgetType() && !((TQWidget*)obj)->isHidden() && !((TQWidget*)obj)->isTopLevel())
+ r = r.unite( ((TQWidget*)obj)->tqgeometry() );
+ }
+ return r;
+}
+
+/*!
+ \property TQWidget::tqchildrenRegion
+ \brief the combined region occupied by the widget's tqchildren
+
+ Hidden tqchildren are excluded.
+
+ \sa tqchildrenRect() tqgeometry()
+*/
+
+TQRegion TQWidget::tqchildrenRegion() const
+{
+ TQRegion r;
+ if ( !childrenListObject() )
+ return r;
+ TQObjectListIt it( *childrenListObject() ); // iterate over all tqchildren
+ TQObject *obj;
+ while ( (obj=it.current()) ) {
+ ++it;
+ if ( obj->isWidgetType() && !((TQWidget*)obj)->isHidden() && !((TQWidget*)obj)->isTopLevel())
+ r = r.unite( ((TQWidget*)obj)->tqgeometry() );
+ }
+ return r;
+}
+
+
+/*!
+ \property TQWidget::tqminimumSize
+ \brief the widget's minimum size
+
+ The widget cannot be resized to a smaller size than the minimum
+ widget size. The widget's size is forced to the minimum size if
+ the current size is smaller.
+
+ If you use a tqlayout inside the widget, the minimum size will be
+ set by the tqlayout and not by setMinimumSize(), unless you set the
+ tqlayout's resize mode to TQLayout::FreeResize.
+
+ \sa minimumWidth, minimumHeight, tqmaximumSize, sizeIncrement
+ TQLayout::setResizeMode()
+*/
+
+TQSize TQWidget::tqminimumSize() const
+{
+ return extra ? TQSize( extra->minw, extra->minh ) : TQSize( 0, 0 );
+}
+
+/*!
+ \property TQWidget::tqmaximumSize
+ \brief the widget's maximum size
+
+ The widget cannot be resized to a larger size than the maximum
+ widget size.
+
+ \sa maximumWidth(), maximumHeight(), setMaximumSize(),
+ tqminimumSize(), sizeIncrement()
+*/
+
+TQSize TQWidget::tqmaximumSize() const
+{
+ return extra ? TQSize( extra->maxw, extra->maxh )
+ : TQSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX );
+}
+
+
+/*!
+ \property TQWidget::minimumWidth
+ \brief the widget's minimum width
+
+ This property corresponds to tqminimumSize().width().
+
+ \sa tqminimumSize, minimumHeight
+*/
+
+/*!
+ \property TQWidget::minimumHeight
+ \brief the widget's minimum height
+
+ This property corresponds to tqminimumSize().height().
+
+ \sa tqminimumSize, minimumWidth
+*/
+
+/*!
+ \property TQWidget::maximumWidth
+ \brief the widget's maximum width
+
+ This property corresponds to tqmaximumSize().width().
+
+ \sa tqmaximumSize, maximumHeight
+*/
+
+/*!
+ \property TQWidget::maximumHeight
+ \brief the widget's maximum height
+
+ This property corresponds to tqmaximumSize().height().
+
+ \sa tqmaximumSize, maximumWidth
+*/
+
+/*!
+ \property TQWidget::sizeIncrement
+ \brief the size increment of the widget
+
+ When the user resizes the window, the size will move in steps of
+ sizeIncrement().width() pixels horizontally and
+ sizeIncrement.height() pixels vertically, with baseSize() as the
+ basis. Preferred widget sizes are for non-negative integers \e i
+ and \e j:
+ \code
+ width = baseSize().width() + i * sizeIncrement().width();
+ height = baseSize().height() + j * sizeIncrement().height();
+ \endcode
+
+ Note that while you can set the size increment for all widgets, it
+ only affects top-level widgets.
+
+ \warning The size increment has no effect under Windows, and may
+ be disregarded by the window manager on X.
+
+ \sa size, tqminimumSize, tqmaximumSize
+*/
+TQSize TQWidget::sizeIncrement() const
+{
+ return ( extra && extra->topextra )
+ ? TQSize( extra->topextra->incw, extra->topextra->inch )
+ : TQSize( 0, 0 );
+}
+
+/*!
+ \property TQWidget::baseSize
+ \brief the base size of the widget
+
+ The base size is used to calculate a proper widget size if the
+ widget defines sizeIncrement().
+
+ \sa setSizeIncrement()
+*/
+
+TQSize TQWidget::baseSize() const
+{
+ return ( extra != 0 && extra->topextra != 0 )
+ ? TQSize( extra->topextra->basew, extra->topextra->baseh )
+ : TQSize( 0, 0 );
+}
+
+/*!
+ Sets both the minimum and maximum sizes of the widget to \a s,
+ thereby preventing it from ever growing or shrinking.
+
+ \sa setMaximumSize() setMinimumSize()
+*/
+
+void TQWidget::setFixedSize( const TQSize & s)
+{
+ setMinimumSize( s );
+ setMaximumSize( s );
+ resize( s );
+}
+
+
+/*!
+ \overload void TQWidget::setFixedSize( int w, int h )
+
+ Sets the width of the widget to \a w and the height to \a h.
+*/
+
+void TQWidget::setFixedSize( int w, int h )
+{
+ setMinimumSize( w, h );
+ setMaximumSize( w, h );
+ resize( w, h );
+}
+
+void TQWidget::setMinimumWidth( int w )
+{
+ setMinimumSize( w, tqminimumSize().height() );
+}
+
+void TQWidget::setMinimumHeight( int h )
+{
+ setMinimumSize( tqminimumSize().width(), h );
+}
+
+void TQWidget::setMaximumWidth( int w )
+{
+ setMaximumSize( w, tqmaximumSize().height() );
+}
+
+void TQWidget::setMaximumHeight( int h )
+{
+ setMaximumSize( tqmaximumSize().width(), h );
+}
+
+/*!
+ Sets both the minimum and maximum width of the widget to \a w
+ without changing the heights. Provided for convenience.
+
+ \sa tqsizeHint() tqminimumSize() tqmaximumSize() setFixedSize()
+*/
+
+void TQWidget::setFixedWidth( int w )
+{
+ setMinimumSize( w, tqminimumSize().height() );
+ setMaximumSize( w, tqmaximumSize().height() );
+}
+
+
+/*!
+ Sets both the minimum and maximum heights of the widget to \a h
+ without changing the widths. Provided for convenience.
+
+ \sa tqsizeHint() tqminimumSize() tqmaximumSize() setFixedSize()
+*/
+
+void TQWidget::setFixedHeight( int h )
+{
+ setMinimumSize( tqminimumSize().width(), h );
+ setMaximumSize( tqmaximumSize().width(), h );
+}
+
+
+/*!
+ Translates the widget coordinate \a pos to the coordinate system
+ of \a tqparent. The \a tqparent must not be 0 and must be a tqparent
+ of the calling widget.
+
+ \sa mapFrom() mapToParent() mapToGlobal() hasMouse()
+*/
+
+TQPoint TQWidget::mapTo( TQWidget * tqparent, const TQPoint & pos ) const
+{
+ TQPoint p = pos;
+ if ( tqparent ) {
+ const TQWidget * w = this;
+ while ( w != tqparent ) {
+ p = w->mapToParent( p );
+ w = w->parentWidget();
+ }
+ }
+ return p;
+}
+
+
+/*!
+ Translates the widget coordinate \a pos from the coordinate system
+ of \a tqparent to this widget's coordinate system. The \a tqparent
+ must not be 0 and must be a tqparent of the calling widget.
+
+ \sa mapTo() mapFromParent() mapFromGlobal() hasMouse()
+*/
+
+TQPoint TQWidget::mapFrom( TQWidget * tqparent, const TQPoint & pos ) const
+{
+ TQPoint p( pos );
+ if ( tqparent ) {
+ const TQWidget * w = this;
+ while ( w != tqparent ) {
+ p = w->mapFromParent( p );
+ w = w->parentWidget();
+ }
+ }
+ return p;
+}
+
+
+/*!
+ Translates the widget coordinate \a pos to a coordinate in the
+ tqparent widget.
+
+ Same as mapToGlobal() if the widget has no tqparent.
+
+ \sa mapFromParent() mapTo() mapToGlobal() hasMouse()
+*/
+
+TQPoint TQWidget::mapToParent( const TQPoint &pos ) const
+{
+ return pos + crect.topLeft();
+}
+
+/*!
+ Translates the tqparent widget coordinate \a pos to widget
+ coordinates.
+
+ Same as mapFromGlobal() if the widget has no tqparent.
+
+ \sa mapToParent() mapFrom() mapFromGlobal() hasMouse()
+*/
+
+TQPoint TQWidget::mapFromParent( const TQPoint &pos ) const
+{
+ return pos - crect.topLeft();
+}
+
+
+/*!
+ Returns the top-level widget for this widget, i.e. the next
+ ancestor widget that has (or could have) a window-system frame.
+
+ If the widget is a top-level, the widget itself is returned.
+
+ Typical usage is changing the window caption:
+
+ \code
+ aWidget->tqtopLevelWidget()->setCaption( "New Caption" );
+ \endcode
+
+ \sa isTopLevel()
+*/
+
+TQWidget *TQWidget::tqtopLevelWidget() const
+{
+ TQWidget *w = (TQWidget *)this;
+ TQWidget *p = w->parentWidget();
+ while ( !w->testWFlags(WType_TopLevel) && p ) {
+ w = p;
+ p = p->parentWidget();
+ }
+ return w;
+}
+
+
+/*!
+ \property TQWidget::paletteForegroundColor
+ \brief the foreground color of the widget
+
+ setPaletteForegroundColor() is a convenience function that creates
+ and sets a modified TQPalette with setPalette(). The palette is
+ modified according to the widget's \e {background mode}. For
+ example, if the background mode is \c PaletteButton the palette entry
+ \c TQColorGroup::ButtonText is set to color.
+
+ \sa setPalette() TQApplication::setPalette() backgroundMode()
+ foregroundColor() setBackgroundMode() setEraseColor()
+*/
+const TQColor &TQWidget::paletteForegroundColor() const
+{
+#ifndef TQT_NO_PALETTE
+ BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
+ return tqcolorGroup().color( TQPalette::foregroundRoleFromMode(mode) );
+#else
+ return TQt::black;
+#endif
+}
+
+void TQWidget::setPaletteForegroundColor( const TQColor & color )
+{
+#ifndef TQT_NO_PALETTE
+ BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
+ TQPalette pal = palette();
+ TQColorGroup::ColorRole role = TQPalette::foregroundRoleFromMode( mode );
+ pal.setColor( TQPalette::Active, role, color );
+ pal.setColor( TQPalette::Inactive, role, color );
+ pal.setColor( TQPalette::Disabled, role, color );
+ setPalette( pal );
+#endif
+}
+
+
+/*!
+ Same as paletteForegroundColor()
+ */
+const TQColor &TQWidget::foregroundColor() const
+{
+ return paletteForegroundColor();
+}
+
+
+/*!
+ \fn const TQColor& TQWidget::eraseColor() const
+
+ Returns the erase color of the widget.
+
+ \sa setEraseColor() setErasePixmap() backgroundColor()
+*/
+
+/*!
+ Sets the erase color of the widget to \a color.
+
+ The erase color is the color the widget is to be cleared to before
+ paintEvent() is called. If there is an erase pixmap (set using
+ setErasePixmap()), then this property has an indeterminate value.
+
+ \sa erasePixmap(), backgroundColor(), backgroundMode(), palette()
+*/
+void TQWidget::setEraseColor( const TQColor & color )
+{
+ setBackgroundModeDirect( FixedColor );
+ setBackgroundColorDirect( color );
+ update();
+}
+
+/*!
+ Returns the widget's erase pixmap.
+
+ \sa setErasePixmap() eraseColor()
+*/
+const TQPixmap *TQWidget::erasePixmap() const
+{
+ return ( extra && extra->bg_pix ) ? extra->bg_pix : 0;
+}
+
+/*!
+ Sets the widget's erase pixmap to \a pixmap.
+
+ This pixmap is used to clear the widget before paintEvent() is
+ called.
+*/
+void TQWidget::setErasePixmap( const TQPixmap &pixmap )
+{
+ // This function is called with a null pixmap by setBackgroundEmpty().
+ setBackgroundPixmapDirect( pixmap );
+ setBackgroundModeDirect( FixedPixmap );
+ update();
+}
+
+void TQWidget::setBackgroundFromMode()
+{
+#ifndef TQT_NO_PALETTE
+ TQColorGroup::ColorRole r = TQColorGroup::Background;
+ if ( extra ) {
+ int i = (BackgroundMode)extra->bg_mode;
+ if ( i == FixedColor || i == FixedPixmap || i == NoBackground ) {
+ // Mode is for fixed color, not one based on palette,
+ // so nothing to do.
+ return;
+ }
+ switch( i ) {
+ case PaletteForeground:
+ r = TQColorGroup::Foreground;
+ break;
+ case PaletteButton:
+ r = TQColorGroup::Button;
+ break;
+ case PaletteLight:
+ r = TQColorGroup::Light;
+ break;
+ case PaletteMidlight:
+ r = TQColorGroup::Midlight;
+ break;
+ case PaletteDark:
+ r = TQColorGroup::Dark;
+ break;
+ case PaletteMid:
+ r = TQColorGroup::Mid;
+ break;
+ case PaletteText:
+ r = TQColorGroup::Text;
+ break;
+ case PaletteBrightText:
+ r = TQColorGroup::BrightText;
+ break;
+ case PaletteBase:
+ r = TQColorGroup::Base;
+ break;
+ case PaletteBackground:
+ r = TQColorGroup::Background;
+ break;
+ case PaletteShadow:
+ r = TQColorGroup::Shadow;
+ break;
+ case PaletteHighlight:
+ r = TQColorGroup::Highlight;
+ break;
+ case PaletteHighlightedText:
+ r = TQColorGroup::HighlightedText;
+ break;
+ case PaletteButtonText:
+ r = TQColorGroup::ButtonText;
+ break;
+ case X11ParentRelative:
+#if defined(TQ_WS_X11)
+ setBackgroundX11Relative();
+#endif
+ return;
+ }
+ }
+ const TQColorGroup &cg = tqcolorGroup();
+ TQPixmap * p = cg.brush( r ).pixmap();
+ if ( p )
+ setBackgroundPixmapDirect( *p );
+ else
+ setBackgroundColorDirect( cg.color( r ) );
+#endif
+}
+
+/*!
+ \enum TQt::BackgroundMode
+
+ This enum describes how the background of a widget changes, as the
+ widget's palette changes.
+
+ The background is what the widget tqcontains when \link
+ TQWidget::paintEvent() paintEvent()\endlink is called. To minimize
+ flicker, this should be the most common color or pixmap in the
+ widget. For \c PaletteBackground, use tqcolorGroup().brush( \c
+ TQColorGroup::Background ), and so on.
+
+ \value PaletteForeground
+ \value PaletteBackground
+ \value PaletteButton
+ \value PaletteLight
+ \value PaletteMidlight
+ \value PaletteDark
+ \value PaletteMid
+ \value PaletteText
+ \value PaletteBrightText
+ \value PaletteButtonText
+ \value PaletteBase
+ \value PaletteShadow
+ \value PaletteHighlight
+ \value PaletteHighlightedText
+ \value PaletteLink
+ \value PaletteLinkVisited
+ \value X11ParentRelative (internal use only)
+
+ The final three values have special meaning:
+
+ \value NoBackground the widget is not cleared before paintEvent().
+ If the widget's paint event always draws on all the pixels, using
+ this mode can be both fast and flicker-free.
+ \value FixedColor the widget is cleared to a fixed color, normally
+ different from all the ones in the palette(). Set using \link
+ TQWidget::setPaletteBackgroundColor()
+ setPaletteBackgroundColor()\endlink.
+ \value FixedPixmap the widget is cleared to a fixed pixmap,
+ normally different from all the ones in the palette(). Set using
+ \link TQWidget::setPaletteBackgroundPixmap()
+ setPaletteBackgroundPixmap()\endlink.
+
+ Although \c FixedColor and \c FixedPixmap are sometimes just
+ right, if you use them, make sure that you test your application
+ when the desktop color scheme has been changed. (On X11, a quick
+ way to test this is e.g. "./myapp -bg paleblue". On Windows, you
+ must use the control panel.)
+
+ \sa TQWidget::setBackgroundMode() TQWidget::backgroundMode()
+ TQWidget::setBackgroundPixmap() TQWidget::setPaletteBackgroundColor()
+*/
+
+/*!
+ \property TQWidget::backgroundMode
+ \brief the color role used for painting the background of the widget
+
+ setPaletteBackgroundColor() reads this property to determine which
+ entry of the \link TQWidget::palette palette\endlink to set.
+
+ For most widgets the default suffices (\c PaletteBackground,
+ typically gray), but some need to use \c PaletteBase (the
+ background color for text output, typically white) or another
+ role.
+
+ TQListBox, which is "sunken" and uses the base color to contrast
+ with its environment, does this in its constructor:
+
+ \code
+ setBackgroundMode( PaletteBase );
+ \endcode
+
+ You will never need to set the background mode of a built-in
+ widget in TQt, but you might consider setting it in your custom
+ widgets, so that setPaletteBackgroundColor() works as expected.
+
+ Note that two of the BackgroundMode values make no sense for
+ setBackgroundMode(), namely \c FixedPixmap and \c FixedColor. You
+ must call setBackgroundPixmap() and setPaletteBackgroundColor()
+ instead.
+*/
+TQt::BackgroundMode TQWidget::backgroundMode() const
+{
+ return extra ? (BackgroundMode) extra->bg_mode : PaletteBackground;
+}
+
+void TQWidget::setBackgroundMode( BackgroundMode m )
+{
+ setBackgroundMode( m, m );
+ if ( (widget_state & (WState_Visible|WState_BlockUpdates)) ==
+ WState_Visible )
+ update();
+}
+
+
+/*!
+ \overload
+
+ Sets the widget's own background mode to \a m and the visual
+ background mode to \a visual. The visual background mode is used
+ with the designable properties \c backgroundColor, \c
+ foregroundColor and \c backgroundPixmap.
+
+ For complex controls, the logical background mode sometimes
+ differs from a widget's own background mode. A spinbox for example
+ has \c PaletteBackground as background mode (typically dark gray),
+ while it's embedded lineedit control uses \c PaletteBase
+ (typically white). Since the lineedit covers most of the visual
+ area of a spinbox, it defines \c PaletteBase to be its \a visual
+ background mode. Changing the \c backgroundColor property thus
+ changes the lineedit control's background, which is exactly what
+ the user expects in \e{TQt Designer}.
+*/
+void TQWidget::setBackgroundMode( BackgroundMode m, BackgroundMode visual )
+{
+ if ( m == NoBackground ) {
+ setBackgroundEmpty();
+ } else if ( m == FixedColor || m == FixedPixmap ) {
+#if defined(TQT_DEBUG)
+ qWarning( "TQWidget::setBackgroundMode: FixedColor or FixedPixmap makes"
+ " no sense" );
+#endif
+ return;
+ }
+ setBackgroundModeDirect(m);
+ if ( m != visual && !extra )
+ createExtra();
+ if ( extra )
+ extra->bg_mode_visual = visual;
+}
+
+
+/*!
+ \internal
+*/
+void TQWidget::setBackgroundModeDirect( BackgroundMode m )
+{
+ if ( m == PaletteBackground && !extra )
+ return;
+
+ createExtra();
+ if ( (BackgroundMode)extra->bg_mode != m ) {
+ extra->bg_mode = m;
+ extra->bg_mode_visual = m;
+ setBackgroundFromMode();
+ }
+}
+
+/*!
+ \property TQWidget::paletteBackgroundColor
+ \brief the background color of the widget
+
+ The palette background color is usually set implicitly by
+ setBackgroundMode(), although it can also be set explicitly by
+ setPaletteBackgroundColor(). setPaletteBackgroundColor() is a
+ convenience function that creates and sets a modified TQPalette
+ with setPalette(). The palette is modified according to the
+ widget's background mode. For example, if the background mode is
+ \c PaletteButton the color used for the palette's \c
+ TQColorGroup::Button color entry is set.
+
+ If there is a background pixmap (set using
+ setPaletteBackgroundPixmap()), then the return value of this
+ function is indeterminate.
+
+ \sa paletteBackgroundPixmap, paletteForegroundColor, palette, tqcolorGroup()
+*/
+const TQColor & TQWidget::paletteBackgroundColor() const
+{
+#ifndef TQT_NO_PALETTE
+ BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
+ switch( mode ) {
+ case FixedColor:
+ case FixedPixmap :
+ case NoBackground:
+ case X11ParentRelative:
+ return eraseColor();
+ default:
+ TQColorGroup::ColorRole role = TQPalette::backgroundRoleFromMode( mode );
+ return tqcolorGroup().color( role );
+ }
+#else
+ return eraseColor();
+#endif
+}
+
+void TQWidget::setPaletteBackgroundColor( const TQColor &color )
+{
+#ifndef TQT_NO_PALETTE
+ BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
+ switch( mode ) {
+ case FixedColor:
+ case FixedPixmap :
+ case NoBackground:
+ case X11ParentRelative:
+ setEraseColor( color );
+ break;
+ default:
+ TQPalette pal = palette();
+ TQColorGroup::ColorRole role = TQPalette::backgroundRoleFromMode( mode );
+ pal.setColor( TQPalette::Active, role, color );
+ pal.setColor( TQPalette::Inactive, role, color );
+ pal.setColor( TQPalette::Disabled, role, color );
+ setPalette( pal );
+ break;
+ }
+#else
+ setEraseColor( color );
+#endif
+}
+
+
+/*!
+ \property TQWidget::paletteBackgroundPixmap
+ \brief the background pixmap of the widget
+
+ The palette background pixmap is usually set implicitly by
+ setBackgroundMode(), although it can also be set explicitly by
+ setPaletteBackgroundPixmap(). setPaletteBackgroundPixmap() is a
+ convenience function that creates and sets a modified TQPalette
+ with setPalette(). The palette is modified according to the
+ widget's background mode. For example, if the background mode is
+ \c PaletteButton the pixmap used for the palette's
+ \c TQColorGroup::Button color entry is set.
+
+ If there is a plain background color (set using
+ setPaletteBackgroundColor()), then this function returns 0.
+
+ \sa paletteBackgroundColor, paletteForegroundColor, palette, tqcolorGroup()
+*/
+const TQPixmap *TQWidget::paletteBackgroundPixmap() const
+{
+#ifndef TQT_NO_PALETTE
+ BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
+ switch( mode ) {
+ case FixedColor:
+ case FixedPixmap :
+ case NoBackground:
+ case X11ParentRelative:
+ return erasePixmap();
+ default:
+ TQColorGroup::ColorRole role = TQPalette::backgroundRoleFromMode( mode );
+ return palette().brush( TQPalette::Active, role ).pixmap();
+ }
+#else
+ return erasePixmap();
+#endif
+}
+
+void TQWidget::setPaletteBackgroundPixmap( const TQPixmap &pixmap )
+{
+#ifndef TQT_NO_PALETTE
+ BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
+ switch( mode ) {
+ case FixedColor:
+ case FixedPixmap :
+ case NoBackground:
+ case X11ParentRelative:
+ setErasePixmap( pixmap );
+ break;
+ default:
+ TQPalette pal = palette();
+ TQColorGroup::ColorRole role = TQPalette::backgroundRoleFromMode( mode );
+ pal.setBrush( TQPalette::Active, role, TQBrush( pal.color( TQPalette::Active, role ), pixmap ) );
+ pal.setBrush( TQPalette::Inactive, role, TQBrush( pal.color( TQPalette::Inactive, role ), pixmap ) );
+ pal.setBrush( TQPalette::Disabled, role, TQBrush( pal.color( TQPalette::Disabled, role ), pixmap ) );
+ setPalette( pal );
+ break;
+ }
+#else
+ setErasePixmap( pixmap );
+#endif
+}
+
+
+/*!
+ \property TQWidget::backgroundBrush
+ \brief the widget's background brush
+
+ The background brush depends on a widget's palette and its
+ background mode.
+
+ \sa backgroundColor(), backgroundPixmap(), eraseColor(), palette,
+ TQApplication::setPalette()
+*/
+const TQBrush& TQWidget::backgroundBrush() const
+{
+ static TQBrush noBrush;
+#ifndef TQT_NO_PALETTE
+ BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
+ switch( mode ) {
+ case FixedColor:
+ case FixedPixmap :
+ case NoBackground:
+ case X11ParentRelative:
+ return noBrush;
+ default:
+ TQColorGroup::ColorRole role = TQPalette::backgroundRoleFromMode( mode );
+ return tqcolorGroup().brush( role );
+ }
+#else
+ return noBrush;
+#endif
+}
+
+
+/*!
+ \property TQWidget::tqcolorGroup
+ \brief the current color group of the widget palette
+
+ The color group is determined by the state of the widget. A
+ disabled widget has the TQPalette::disabled() color group, a widget
+ with keyboard focus has the TQPalette::active() color group, and an
+ inactive widget has the TQPalette::inactive() color group.
+
+ \sa palette
+*/
+#ifndef TQT_NO_PALETTE
+const TQColorGroup &TQWidget::tqcolorGroup() const
+{
+ if ( !isEnabled() )
+ return palette().disabled();
+ else if ( !isVisible() || isActiveWindow() )
+ return palette().active();
+ else
+ return palette().inactive();
+}
+#endif
+
+/*!
+ \property TQWidget::palette
+ \brief the widget's palette
+
+ As long as no special palette has been set, or after unsetPalette()
+ has been called, this is either a special palette for the widget
+ class, the tqparent's palette or (if this widget is a top level
+ widget), the default application palette.
+
+ Instead of defining an entirely new palette, you can also use the
+ \link TQWidget::paletteBackgroundColor paletteBackgroundColor\endlink,
+ \link TQWidget::paletteBackgroundPixmap paletteBackgroundPixmap\endlink and
+ \link TQWidget::paletteForegroundColor paletteForegroundColor\endlink
+ convenience properties to change a widget's
+ background and foreground appearance only.
+
+ \sa ownPalette, tqcolorGroup(), TQApplication::palette()
+*/
+
+#ifndef TQT_NO_PALETTE
+void TQWidget::setPalette( const TQPalette &palette )
+{
+ own_palette = TRUE;
+ if ( pal == palette )
+ return;
+ TQPalette old = pal;
+ pal = palette;
+ setBackgroundFromMode();
+ TQEvent ev( TQEvent::PaletteChange );
+ TQApplication::sendEvent( this, &ev );
+ if ( childrenListObject() ) {
+ TQEvent e( TQEvent::ParentPaletteChange );
+ TQObjectListIt it( *childrenListObject() );
+ TQWidget *w;
+ while( (w=(TQWidget *)it.current()) != 0 ) {
+ ++it;
+ if ( w->isWidgetType() )
+ TQApplication::sendEvent( w, &e );
+ }
+ }
+ paletteChange( old );
+ update();
+}
+
+void TQWidget::unsetPalette()
+{
+ // reset the palette
+ setPalette( qt_naturalWidgetPalette( this ) );
+ own_palette = FALSE;
+}
+
+/*!
+ \fn void TQWidget::setPalette( const TQPalette&, bool )
+ \obsolete
+
+ Use setPalette( const TQPalette& p ) instead.
+*/
+
+/*!
+ \fn void TQWidget::paletteChange( const TQPalette &oldPalette )
+
+ This virtual function is called from setPalette(). \a oldPalette
+ is the previous palette; you can get the new palette from
+ palette().
+
+ Reimplement this function if your widget needs to know when its
+ palette changes.
+
+ \sa setPalette(), palette()
+*/
+
+void TQWidget::paletteChange( const TQPalette & )
+{
+}
+#endif // TQT_NO_PALETTE
+
+/*!
+ \property TQWidget::font
+ \brief the font currently set for the widget
+
+ The fontInfo() function reports the actual font that is being used
+ by the widget.
+
+ As long as no special font has been set, or after unsetFont() is
+ called, this is either a special font for the widget class, the
+ tqparent's font or (if this widget is a top level widget), the
+ default application font.
+
+ This code fragment sets a 12 point helvetica bold font:
+ \code
+ TQFont f( "Helvetica", 12, TQFont::Bold );
+ setFont( f );
+ \endcode
+
+ In addition to setting the font, setFont() informs all tqchildren
+ about the change.
+
+ \sa fontChange() fontInfo() fontMetrics() ownFont()
+*/
+void TQWidget::setFont( const TQFont &font )
+{
+ own_font = TRUE;
+ if ( fnt == font && fnt.d->tqmask == font.d->tqmask )
+ return;
+ TQFont old = fnt;
+ fnt = font.resolve( qt_naturalWidgetFont( this ) );
+#if defined(TQ_WS_X11)
+ // make sure the font set on this widget is associated with the correct screen
+ fnt.x11SetScreen( x11Screen() );
+#endif
+ if ( childrenListObject() ) {
+ TQEvent e( TQEvent::ParentFontChange );
+ TQObjectListIt it( *childrenListObject() );
+ TQWidget *w;
+ while( (w=(TQWidget *)it.current()) != 0 ) {
+ ++it;
+ if ( w->isWidgetType() )
+ TQApplication::sendEvent( w, &e );
+ }
+ }
+ if ( hasFocus() )
+ setFontSys();
+ fontChange( old );
+}
+
+void TQWidget::unsetFont()
+{
+ // reset the font
+ setFont( qt_naturalWidgetFont( this ) );
+ own_font = FALSE;
+}
+
+/*!
+ \fn void TQWidget::setFont( const TQFont&, bool )
+ \obsolete
+
+ Use setFont(const TQFont& font) instead.
+*/
+
+/*!
+ \fn void TQWidget::fontChange( const TQFont &oldFont )
+
+ This virtual function is called from setFont(). \a oldFont is the
+ previous font; you can get the new font from font().
+
+ Reimplement this function if your widget needs to know when its
+ font changes. You will almost certainly need to update the widget
+ using update().
+
+ The default implementation updates the widget including its
+ tqgeometry.
+
+ \sa setFont(), font(), update(), updateGeometry()
+*/
+
+void TQWidget::fontChange( const TQFont & )
+{
+ update();
+ updateGeometry();
+}
+
+
+/*!
+ \fn TQFontMetrics TQWidget::fontMetrics() const
+
+ Returns the font metrics for the widget's current font.
+ Equivalent to TQFontMetrics(widget->font()).
+
+ \sa font(), fontInfo(), setFont()
+*/
+
+/*!
+ \fn TQFontInfo TQWidget::fontInfo() const
+
+ Returns the font info for the widget's current font.
+ Equivalent to TQFontInto(widget->font()).
+
+ \sa font(), fontMetrics(), setFont()
+*/
+
+
+/*!
+ \property TQWidget::cursor
+ \brief the cursor tqshape for this widget
+
+ The mouse cursor will assume this tqshape when it's over this
+ widget. See the \link TQt::tqCursorShape list of predefined cursor
+ objects\endlink for a range of useful tqshapes.
+
+ An editor widget might use an I-beam cursor:
+ \code
+ setCursor( IbeamCursor );
+ \endcode
+
+ If no cursor has been set, or after a call to unsetCursor(), the
+ tqparent's cursor is used. The function unsetCursor() has no effect
+ on top-level widgets.
+
+ \sa TQApplication::setOverrideCursor()
+*/
+
+#ifndef TQT_NO_CURSOR
+const TQCursor &TQWidget::cursor() const
+{
+ if ( testWState(WState_OwnCursor) )
+ return (extra && extra->curs)
+ ? *extra->curs
+ : arrowCursor;
+ else
+ return (isTopLevel() || !parentWidget()) ? arrowCursor : parentWidget()->cursor();
+}
+#endif
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+/*!
+ \property TQWidget::caption
+ \brief the window caption (title)
+
+ This property only makes sense for top-level widgets. If no
+ caption has been set, the caption is TQString::null.
+
+ \sa icon() iconText()
+*/
+TQString TQWidget::caption() const
+{
+ return extra && extra->topextra
+ ? extra->topextra->caption
+ : TQString::null;
+}
+
+/*!
+ \property TQWidget::icon
+ \brief the widget's icon
+
+ This property only makes sense for top-level widgets. If no icon
+ has been set, icon() returns 0.
+
+ \sa iconText, caption,
+ \link appicon.html Setting the Application Icon\endlink
+*/
+const TQPixmap *TQWidget::icon() const
+{
+ return ( extra && extra->topextra ) ? extra->topextra->icon : 0;
+}
+
+/*!
+ \property TQWidget::iconText
+ \brief the widget's icon text
+
+ This property only makes sense for top-level widgets. If no icon
+ text has been set, this functions returns TQString::null.
+
+ \sa icon, caption
+*/
+
+TQString TQWidget::iconText() const
+{
+ return ( extra && extra->topextra ) ? extra->topextra->iconText
+ : TQString::null;
+}
+#endif //TQT_NO_WIDGET_TOPEXTRA
+
+/*!
+ \property TQWidget::mouseTracking
+ \brief whether mouse tracking is enabled for the widget
+
+ If mouse tracking is disabled (the default), the widget only
+ receives mouse move events when at least one mouse button is
+ pressed while the mouse is being moved.
+
+ If mouse tracking is enabled, the widget receives mouse move
+ events even if no buttons are pressed.
+
+ \sa mouseMoveEvent(), TQApplication::setGlobalMouseTracking()
+*/
+
+
+/*!
+ Sets the widget's focus proxy to widget \a w. If \a w is 0, the
+ function resets this widget to have no focus proxy.
+
+ Some widgets, such as TQComboBox, can "have focus", but create a
+ child widget to actually handle the focus. TQComboBox, for example,
+ creates a TQLineEdit which handles the focus.
+
+ setFocusProxy() sets the widget which will actually get focus when
+ "this widget" gets it. If there is a focus proxy, focusPolicy(),
+ setFocusPolicy(), setFocus() and hasFocus() all operate on the
+ focus proxy.
+
+ \sa focusProxy()
+*/
+
+void TQWidget::setFocusProxy( TQWidget * w )
+{
+ if ( !w && !extra )
+ return;
+
+ for ( TQWidget* fp = w; fp; fp = fp->focusProxy() ) {
+ if ( fp == this ) {
+#if defined (TQT_CHECK_STATE)
+ qWarning( "%s (%s): already in focus proxy chain", className(), name() );
+#endif
+ return;
+ }
+ }
+
+ createExtra();
+
+ if ( extra->focus_proxy ) {
+ disconnect( extra->focus_proxy, TQT_SIGNAL(destroyed()),
+ this, TQT_SLOT(focusProxyDestroyed()) );
+ extra->focus_proxy = 0;
+ }
+
+ if ( w ) {
+ setFocusPolicy( w->focusPolicy() );
+ connect( w, TQT_SIGNAL(destroyed()),
+ this, TQT_SLOT(focusProxyDestroyed()) );
+ }
+ extra->focus_proxy = w;
+}
+
+
+/*!
+ Returns the focus proxy, or 0 if there is no focus proxy.
+
+ \sa setFocusProxy()
+*/
+
+TQWidget * TQWidget::focusProxy() const
+{
+ return extra ? extra->focus_proxy : 0;
+}
+
+
+/*!
+ \internal
+
+ Internal slot used to clean up if the focus proxy is destroyed.
+
+ \sa setFocusProxy()
+*/
+
+void TQWidget::focusProxyDestroyed()
+{
+ if ( extra )
+ extra->focus_proxy = 0;
+ setFocusPolicy( NoFocus );
+}
+
+/*!
+ \property TQWidget::focus
+ \brief whether this widget (or its focus proxy) has the keyboard
+ input focus
+
+ Effectively equivalent to \c {tqApp->tqfocusWidget() == this}.
+
+ \sa setFocus(), clearFocus(), setFocusPolicy(), TQApplication::tqfocusWidget()
+*/
+bool TQWidget::hasFocus() const
+{
+ const TQWidget* w = this;
+ while ( w->focusProxy() )
+ w = w->focusProxy();
+ return tqApp->tqfocusWidget() == w;
+}
+
+/*!
+ Gives the keyboard input focus to this widget (or its focus
+ proxy) if this widget or one of its parents is the \link
+ isActiveWindow() active window\endlink.
+
+ First, a focus out event is sent to the focus widget (if any) to
+ tell it that it is about to lose the focus. Then a focus in event
+ is sent to this widget to tell it that it just received the focus.
+ (Nothing happens if the focus in and focus out widgets are the
+ same.)
+
+ setFocus() gives focus to a widget regardless of its focus policy,
+ but does not clear any keyboard grab (see grabKeyboard()).
+
+ Be aware that if the widget is hidden, it will not accept focus.
+
+ \warning If you call setFocus() in a function which may itself be
+ called from focusOutEvent() or focusInEvent(), you may get an
+ infinite recursion.
+
+ \sa hasFocus() clearFocus() focusInEvent() focusOutEvent()
+ setFocusPolicy() TQApplication::tqfocusWidget() grabKeyboard()
+ grabMouse()
+*/
+
+void TQWidget::setFocus()
+{
+ if ( !isEnabled() )
+ return;
+
+ if ( focusProxy() ) {
+ focusProxy()->setFocus();
+ return;
+ }
+
+ TQFocusData * f = focusData( TRUE );
+ if ( f->it.current() == this && tqApp->tqfocusWidget() == this
+#if defined(TQ_WS_WIN)
+ && GetFocus() == winId()
+#endif
+ )
+ return;
+
+ f->it.toFirst();
+ while ( f->it.current() != this && !f->it.atLast() )
+ ++f->it;
+ // at this point, the iterator should point to 'this'. if it
+ // does not, 'this' must not be in the list - an error, but
+ // perhaps possible. fix it.
+ if ( f->it.current() != this ) {
+ f->tqfocusWidgets.append( this );
+ f->it.toLast();
+ }
+
+ if ( isActiveWindow() ) {
+ TQWidget * prev = tqApp->focus_widget;
+ if ( prev ) {
+ if ( prev != this )
+ prev->resetInputContext();
+ }
+#if defined(TQ_WS_WIN)
+ else {
+ TQInputContext::endComposition();
+ }
+#endif
+ tqApp->focus_widget = this;
+#if defined(TQ_WS_X11)
+ focusInputContext();
+#endif
+
+#if defined(TQ_WS_WIN)
+ if ( !tqtopLevelWidget()->isPopup() )
+ SetFocus( winId() );
+ else {
+#endif
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+ TQAccessible::updateAccessibility( this, 0, TQAccessible::Focus );
+#endif
+#if defined(TQ_WS_WIN)
+ }
+#endif
+
+ if ( prev != this ) {
+ if ( prev ) {
+ TQFocusEvent out( TQEvent::FocusOut );
+ TQApplication::sendEvent( prev, &out );
+ }
+
+ if ( tqApp->focus_widget == this ) {
+ TQFocusEvent in( TQEvent::FocusIn );
+ TQApplication::sendEvent( this, &in );
+ }
+ }
+ }
+}
+
+/*!
+ Takes keyboard input focus from the widget.
+
+ If the widget has active focus, a \link focusOutEvent() focus out
+ event\endlink is sent to this widget to tell it that it is about
+ to lose the focus.
+
+ This widget must enable focus setting in order to get the keyboard
+ input focus, i.e. it must call setFocusPolicy().
+
+ \sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(),
+ setFocusPolicy(), TQApplication::tqfocusWidget()
+*/
+
+void TQWidget::clearFocus()
+{
+ if ( focusProxy() ) {
+ focusProxy()->clearFocus();
+ return;
+ } else if ( hasFocus() ) {
+ resetInputContext();
+ TQWidget* w = tqApp->tqfocusWidget();
+ // clear active focus
+ tqApp->focus_widget = 0;
+ TQFocusEvent out( TQEvent::FocusOut );
+ TQApplication::sendEvent( w, &out );
+#if defined(TQ_WS_WIN)
+ if ( !isPopup() && GetFocus() == winId() )
+ SetFocus( 0 );
+ else {
+#endif
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+ TQAccessible::updateAccessibility( this, 0, TQAccessible::Focus );
+#endif
+#if defined(TQ_WS_WIN)
+ }
+#endif
+ }
+}
+
+
+/*!
+ Finds a new widget to give the keyboard focus to, as appropriate
+ for Tab and Shift+Tab, and returns TRUE if is can tqfind a new
+ widget and FALSE if it can't,
+
+ If \a next is TRUE, this function searches "forwards", if \a next
+ is FALSE, it searches "backwards".
+
+ Sometimes, you will want to reimplement this function. For
+ example, a web browser might reimplement it to move its "current
+ active link" forwards or backwards, and call
+ TQWidget::focusNextPrevChild() only when it reaches the last or
+ first link on the "page".
+
+ Child widgets call focusNextPrevChild() on their tqparent widgets,
+ but only the top-level widget decides where to redirect focus. By
+ overriding this method for an object, you thus gain control of
+ focus traversal for all child widgets.
+
+ \warning TQScrollView uses it own logic for this function, which
+ does the right thing in most cases. But if you are using a
+ TQScrollView and want complete control of the focus chain you'll
+ need to override TQScrollView::focusNextPrevChild() and your
+ top-level widgets' focusNextPrevChild() functions.
+
+ \sa focusData()
+*/
+
+bool TQWidget::focusNextPrevChild( bool next )
+{
+ TQWidget* p = parentWidget();
+ if ( !isTopLevel() && p )
+ return p->focusNextPrevChild(next);
+
+ TQFocusData *f = focusData( TRUE );
+
+ TQWidget *startingPoint = f->it.current();
+ TQWidget *candidate = 0;
+ TQWidget *w = next ? f->tqfocusWidgets.last() : f->tqfocusWidgets.first();
+ extern bool qt_tab_all_widgets;
+ uint focus_flag = qt_tab_all_widgets ? TabFocus : StrongFocus;
+ do {
+ if ( w && w != startingPoint &&
+ ( ( w->focusPolicy() & focus_flag ) == focus_flag )
+ && !w->focusProxy() && w->isVisibleTo(this) && w->isEnabled())
+ candidate = w;
+ w = next ? f->tqfocusWidgets.prev() : f->tqfocusWidgets.next();
+ } while( w && !(candidate && w==startingPoint) );
+
+ if ( !candidate )
+ return FALSE;
+
+ candidate->setFocus();
+ return TRUE;
+}
+
+/*!
+ Returns the focus widget in this widget's window. This is not the
+ same as TQApplication::tqfocusWidget(), which returns the focus
+ widget in the currently active window.
+*/
+
+TQWidget *TQWidget::tqfocusWidget() const
+{
+ TQWidget *that = (TQWidget *)this; // mutable
+ TQFocusData *f = that->focusData( FALSE );
+ if ( f && f->tqfocusWidgets.count() && f->it.current() == 0 )
+ f->it.toFirst();
+ return ( f && f->it.current() ) ? f->it.current() : 0;
+}
+
+
+/*!
+ Returns the focus data for this widget's top-level widget.
+
+ Focus data always belongs to the top-level widget. The focus data
+ list tqcontains all the widgets in this top-level widget that can
+ accept focus, in tab order. An iterator points to the current
+ focus widget (tqfocusWidget() returns a pointer to this widget).
+
+ This information is useful for implementing advanced versions of
+ focusNextPrevChild().
+*/
+TQFocusData * TQWidget::focusData()
+{
+ return focusData( TRUE );
+}
+
+/*!
+ \internal
+
+ Internal function which lets us ask for the focus data, creating
+ it if it doesn't exist and \a create is TRUE.
+*/
+TQFocusData * TQWidget::focusData( bool create )
+{
+ TQWidget * tlw = tqtopLevelWidget();
+ TQWExtra * ed = tlw->extraData();
+ if ( !ed || !ed->topextra ) {
+ if ( !create )
+ return 0;
+ tlw->createTLExtra();
+ ed = tlw->extraData();
+ }
+ if ( create && !ed->topextra->focusData )
+ ed->topextra->focusData = new TQFocusData;
+
+ return ed->topextra->focusData;
+}
+
+/*!
+ \property TQWidget::inputMethodEnabled
+ \brief enables or disables the use of input methods for this widget.
+
+ Most Widgets (as eg. buttons) that do not handle text input should have
+ the input method disabled if they have focus. This is the default.
+
+ If a widget handles text input it should set this property to TRUE.
+*/
+
+void TQWidget::setInputMethodEnabled( bool b )
+{
+ im_enabled = b;
+#ifdef TQ_WS_WIN
+ TQInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
+#endif
+}
+
+
+/*!
+ Enables key event compression, if \a compress is TRUE, and
+ disables it if \a compress is FALSE.
+
+ Key compression is off by default (except for TQLineEdit and
+ TQTextEdit), so widgets receive one key press event for each key
+ press (or more, since autorepeat is usually on). If you turn it on
+ and your program doesn't keep up with key input, TQt may try to
+ compress key events so that more than one character can be
+ processed in each event.
+
+ For example, a word processor widget might receive 2, 3 or more
+ characters in each TQKeyEvent::text(), if the tqlayout recalculation
+ takes too long for the CPU.
+
+ If a widget supports multiple character tqunicode input, it is
+ always safe to turn the compression on.
+
+ TQt performs key event compression only for printable characters.
+ Modifier keys, cursor movement keys, function keys and
+ miscellaneous action keys (e.g. Escape, Enter, Backspace,
+ PrintScreen) will stop key event compression, even if there are
+ more compressible key events available.
+
+ Not all platforms support this compression, in which case turning
+ it on will have no effect.
+
+ \sa TQKeyEvent::text();
+*/
+
+void TQWidget::setKeyCompression(bool compress)
+{
+ if ( compress )
+ setWState( WState_CompressKeys );
+ else
+ clearWState( WState_CompressKeys );
+}
+
+/*!
+ \property TQWidget::isActiveWindow
+ \brief whether this widget is the active window
+
+ The active window is the window that tqcontains the widget
+ that has keyboard focus.
+
+ When popup windows are visible, this property is TRUE for both the
+ active window \e and for the popup.
+
+ \sa setActiveWindow(), TQApplication::activeWindow()
+*/
+bool TQWidget::isActiveWindow() const
+{
+ TQWidget *tlw = tqtopLevelWidget();
+ if(testWFlags(WSubWindow) && parentWidget())
+ tlw = parentWidget()->tqtopLevelWidget();
+ if(tlw == tqApp->activeWindow() || ( isVisible() && tlw->isPopup() ))
+ return TRUE;
+#ifndef TQT_NO_STYLE
+ if(style().tqstyleHint(TQStyle::SH_Widget_ShareActivation, this )) {
+ if((tlw->isDialog() || (tlw->testWFlags(TQt::WStyle_Tool) && !tlw->isPopup())) &&
+ !tlw->testWFlags(TQt::WShowModal) &&
+ (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
+ return TRUE;
+ TQWidget *w = tqApp->activeWindow();
+ if( !testWFlags(WSubWindow) && w && w->testWFlags(WSubWindow) &&
+ w->parentWidget()->tqtopLevelWidget() == tlw)
+ return TRUE;
+ while(w && (tlw->isDialog() || tlw->testWFlags(TQt::WStyle_Tool)) &&
+ !w->testWFlags(TQt::WShowModal) && w->parentWidget()) {
+ w = w->parentWidget()->tqtopLevelWidget();
+ if( w == tlw )
+ return TRUE;
+ }
+ }
+#endif
+#if defined(TQ_WS_WIN32)
+ HWND tqparent = tlw->winId();
+ HWND toptqparent = GetActiveWindow();
+ while ( tqparent ) {
+ tqparent = ::GetParent( tqparent );
+ if ( tqparent && tqparent == toptqparent )
+ return TRUE;
+ }
+#endif
+
+ return FALSE;
+}
+
+/*!
+ Moves the \a second widget around the ring of focus widgets so
+ that keyboard focus moves from the \a first widget to the \a
+ second widget when the Tab key is pressed.
+
+ Note that since the tab order of the \a second widget is changed,
+ you should order a chain like this:
+
+ \code
+ setTabOrder( a, b ); // a to b
+ setTabOrder( b, c ); // a to b to c
+ setTabOrder( c, d ); // a to b to c to d
+ \endcode
+
+ \e not like this:
+
+ \code
+ setTabOrder( c, d ); // c to d WRONG
+ setTabOrder( a, b ); // a to b AND c to d
+ setTabOrder( b, c ); // a to b to c, but not c to d
+ \endcode
+
+ If \a first or \a second has a focus proxy, setTabOrder()
+ correctly substitutes the proxy.
+
+ \sa setFocusPolicy(), setFocusProxy()
+*/
+void TQWidget::setTabOrder( TQWidget* first, TQWidget *second )
+{
+ if ( !first || !second ||
+ first->focusPolicy() == NoFocus || second->focusPolicy() == NoFocus )
+ return;
+
+ // If first is redirected, set first to the last child of first
+ // that can take keyboard focus so that second is inserted after
+ // that last child, and the focus order within first is (more
+ // likely to be) preserved.
+ if ( first->focusProxy() ) {
+ TQObjectList *l = first->queryList( "TQWidget" );
+ if ( l && l->count() ) {
+ TQObjectListIt it(*l);
+ it.toLast();
+ while (it.current()) {
+ if (((TQWidget*)it.current())->tqtopLevelWidget() == first->tqtopLevelWidget()) {
+ first = (TQWidget*)it.current();
+ if (first->focusPolicy() != NoFocus)
+ break;
+ }
+ --it;
+ }
+ }
+ delete l;
+ }
+ while ( first->focusProxy() )
+ first = first->focusProxy();
+ while ( second->focusProxy() )
+ second = second->focusProxy();
+
+ TQFocusData *f = first->focusData( TRUE );
+ bool focusThere = (f->it.current() == second );
+ f->tqfocusWidgets.removeRef( second );
+ if ( f->tqfocusWidgets.tqfindRef( first ) >= 0 )
+ f->tqfocusWidgets.insert( f->tqfocusWidgets.at() + 1, second );
+ else
+ f->tqfocusWidgets.append( second );
+ if ( focusThere ) { // reset iterator so tab will work appropriately
+ f->it.toFirst();
+ while( f->it.current() && f->it.current() != second )
+ ++f->it;
+ }
+}
+
+/*!\internal
+
+ Moves the relevant subwidgets of this widget from the \a oldtlw's
+ tab chain to that of the new tqparent, if there's anything to move and
+ we're really moving
+
+ This function is called from TQWidget::reparent() *after* the widget
+ has been reparented.
+
+ \sa reparent()
+*/
+
+void TQWidget::reparentFocusWidgets( TQWidget * oldtlw )
+{
+ if ( oldtlw == tqtopLevelWidget() )
+ return; // nothing to do
+
+ TQFocusData * from = oldtlw ? oldtlw->topData()->focusData : 0;
+ TQFocusData * to;
+ to = focusData();
+
+ if ( from ) {
+ from->tqfocusWidgets.first();
+ do {
+ TQWidget * pw = from->tqfocusWidgets.current();
+ while( pw && pw != this )
+ pw = pw->parentWidget();
+ if ( pw == this ) {
+ TQWidget * w = from->tqfocusWidgets.take();
+ if ( w == from->it.current() )
+ // probably best to clear keyboard focus, or
+ // the user might become rather confused
+ w->clearFocus();
+ if ( !isTopLevel() )
+ to->tqfocusWidgets.append( w );
+ } else {
+ from->tqfocusWidgets.next();
+ }
+ } while( from->tqfocusWidgets.current() );
+ }
+
+ if ( to->tqfocusWidgets.tqfindRef(this) < 0 )
+ to->tqfocusWidgets.append( this );
+
+ if ( !isTopLevel() && extra && extra->topextra && extra->topextra->focusData ) {
+ // this widget is no longer a top-level widget, so get rid
+ // of old focus data
+ delete extra->topextra->focusData;
+ extra->topextra->focusData = 0;
+ }
+}
+
+/*!
+ \fn void TQWidget::recreate( TQWidget *tqparent, WFlags f, const TQPoint & p, bool showIt )
+
+ \obsolete
+
+ This method is provided to aid porting from TQt 1.0 to 2.0. It has
+ been renamed reparent() in TQt 2.0.
+*/
+
+/*!
+ \property TQWidget::frameSize
+ \brief the size of the widget including any window frame
+*/
+TQSize TQWidget::frameSize() const
+{
+ if ( isTopLevel() && !isPopup() ) {
+ if ( fstrut_dirty )
+ updateFrameStrut();
+ TQWidget *that = (TQWidget *) this;
+ TQTLWExtra *top = that->topData();
+ return TQSize( crect.width() + top->fleft + top->fright,
+ crect.height() + top->ftop + top->fbottom );
+ }
+ return crect.size();
+}
+
+/*!
+ \internal
+
+ Recursive function that updates \a widget and all its tqchildren,
+ if they have some tqparent background origin.
+*/
+static void qt_update_bg_recursive( TQWidget *widget )
+{
+ if ( !widget || widget->isHidden() || widget->backgroundOrigin() == TQWidget::WidgetOrigin || !widget->backgroundPixmap() )
+ return;
+
+ const TQObjectList *lst = widget->childrenListObject();
+
+ if ( lst ) {
+ TQObjectListIterator it( *lst );
+ TQWidget *widget;
+ while ( (widget = (TQWidget*)it.current()) ) {
+ ++it;
+ if ( widget->isWidgetType() && !widget->isHidden() && !widget->isTopLevel() && !widget->testWFlags(TQt::WSubWindow) )
+ qt_update_bg_recursive( widget );
+ }
+ }
+ TQApplication::postEvent( widget, new TQPaintEvent( widget->clipRegion(), !widget->testWFlags(TQt::WRepaintNoErase) ) );
+}
+
+/*!
+ \overload
+
+ This corresponds to move( TQPoint(\a x, \a y) ).
+*/
+
+void TQWidget::move( int x, int y )
+{
+ TQPoint oldp(pos());
+ internalSetGeometry( x + tqgeometry().x() - TQWidget::x(),
+ y + tqgeometry().y() - TQWidget::y(),
+ width(), height(), TRUE );
+ if ( isVisible() && oldp != pos() )
+ qt_update_bg_recursive( this );
+}
+
+/*!
+ \overload
+
+ This corresponds to resize( TQSize(\a w, \a h) ).
+*/
+void TQWidget::resize( int w, int h )
+{
+ internalSetGeometry( tqgeometry().x(), tqgeometry().y(), w, h, FALSE );
+ setWState( WState_Resized );
+}
+
+/*!
+ \overload
+
+ This corresponds to setGeometry( TQRect(\a x, \a y, \a w, \a h) ).
+*/
+void TQWidget::setGeometry( int x, int y, int w, int h )
+{
+ TQPoint oldp( pos( ));
+ internalSetGeometry( x, y, w, h, TRUE );
+ setWState( WState_Resized );
+ if ( isVisible() && oldp != pos() )
+ qt_update_bg_recursive( this );
+}
+
+/*!
+ \property TQWidget::focusEnabled
+ \brief whether the widget accepts keyboard focus
+
+ Keyboard focus is initially disabled (i.e. focusPolicy() ==
+ \c TQWidget::NoFocus).
+
+ You must enable keyboard focus for a widget if it processes
+ keyboard events. This is normally done from the widget's
+ constructor. For instance, the TQLineEdit constructor calls
+ setFocusPolicy(TQWidget::StrongFocus).
+
+ \sa setFocusPolicy(), focusInEvent(), focusOutEvent(), keyPressEvent(),
+ keyReleaseEvent(), isEnabled()
+*/
+
+/*!
+ \enum TQWidget::FocusPolicy
+
+ This enum type defines the various policies a widget can have with
+ respect to acquiring keyboard focus.
+
+ \value TabFocus the widget accepts focus by tabbing.
+ \value ClickFocus the widget accepts focus by clicking.
+ \value StrongFocus the widget accepts focus by both tabbing
+ and clicking. On Mac OS X this will also
+ be indicate that the widget accepts tab focus
+ when in 'Text/List focus mode'.
+ \value WheelFocus like StrongFocus plus the widget accepts
+ focus by using the mouse wheel.
+ \value NoFocus the widget does not accept focus.
+
+*/
+
+/*!
+ \property TQWidget::focusPolicy
+ \brief the way the widget accepts keyboard focus
+
+ The policy is \c TQWidget::TabFocus if the widget accepts keyboard
+ focus by tabbing, \c TQWidget::ClickFocus if the widget accepts
+ focus by clicking, \c TQWidget::StrongFocus if it accepts both, and
+ \c TQWidget::NoFocus (the default) if it does not accept focus at
+ all.
+
+ You must enable keyboard focus for a widget if it processes
+ keyboard events. This is normally done from the widget's
+ constructor. For instance, the TQLineEdit constructor calls
+ setFocusPolicy(TQWidget::StrongFocus).
+
+ \sa focusEnabled, focusInEvent(), focusOutEvent(), keyPressEvent(),
+ keyReleaseEvent(), enabled
+*/
+
+void TQWidget::setFocusPolicy( FocusPolicy policy )
+{
+ if ( focusProxy() )
+ focusProxy()->setFocusPolicy( policy );
+ if ( policy != NoFocus ) {
+ TQFocusData * f = focusData( TRUE );
+ if ( f->tqfocusWidgets.tqfindRef( this ) < 0 )
+ f->tqfocusWidgets.append( this );
+ }
+ focus_policy = (uint) policy;
+}
+
+/*!
+ \property TQWidget::updatesEnabled
+ \brief whether updates are enabled
+
+ Calling update() and tqrepaint() has no effect if updates are
+ disabled. Paint events from the window system are processed
+ normally even if updates are disabled.
+
+ setUpdatesEnabled() is normally used to disable updates for a
+ short period of time, for instance to avoid screen flicker during
+ large changes.
+
+ Example:
+ \code
+ setUpdatesEnabled( FALSE );
+ bigVisualChanges();
+ setUpdatesEnabled( TRUE );
+ tqrepaint();
+ \endcode
+
+ \sa update(), tqrepaint(), paintEvent()
+*/
+void TQWidget::setUpdatesEnabled( bool enable )
+{
+ if ( enable )
+ clearWState( WState_BlockUpdates );
+ else
+ setWState( WState_BlockUpdates );
+}
+
+/*!
+ Shows the widget and its child widgets.
+
+ If its size or position has changed, TQt guarantees that a widget
+ gets move and resize events just before it is shown.
+
+ You almost never have to reimplement this function. If you need to
+ change some settings before a widget is shown, use showEvent()
+ instead. If you need to do some delayed initialization use
+ polish().
+
+ \sa showEvent(), hide(), showMinimized(), showMaximized(),
+ showNormal(), isVisible(), polish()
+*/
+
+void TQWidget::show()
+{
+ if ( testWState(WState_Visible) )
+ return;
+
+ bool wasHidden = isHidden();
+ bool postLayoutHint = !isTopLevel() && wasHidden;
+ clearWState( WState_ForceHide | WState_CreatedHidden );
+
+ if ( !isTopLevel() && !parentWidget()->isVisible() ) {
+ // we should become visible, but one of our ancestors is
+ // explicitly hidden. Since we cleared the ForceHide flag, our
+ // immediate tqparent will call show() on us again during its
+ // own processing of show().
+ if ( wasHidden ) {
+ TQEvent showToParentEvent( TQEvent::ShowToParent );
+ TQApplication::sendEvent( this, &showToParentEvent );
+ }
+ if ( postLayoutHint )
+ TQApplication::postEvent( parentWidget(),
+ new TQEvent(TQEvent::LayoutHint) );
+ return;
+ }
+
+ in_show = TRUE; // set qws recursion watch
+
+ TQApplication::sendPostedEvents( this, TQEvent::ChildInserted );
+
+ uint state = isTopLevel() ? windowState() : 0;
+#ifndef TQ_OS_TEMP
+ if ( isTopLevel() && !testWState( WState_Resized ) ) {
+ // do this before sending the posted resize events. Otherwise
+ // the tqlayout would catch the resize event and may expand the
+ // minimum size.
+ TQSize s = qt_naturalWidgetSize( this );
+ if ( !s.isEmpty() )
+ resize( s );
+ }
+#endif // TQ_OS_TEMP
+
+ TQApplication::sendPostedEvents( this, TQEvent::Move );
+ TQApplication::sendPostedEvents( this, TQEvent::Resize );
+
+ // the resizing and layouting might have changed the window state
+ if (isTopLevel() && windowState() != state)
+ setWindowState(state);
+
+ setWState( WState_Visible );
+
+ if ( parentWidget() )
+ TQApplication::sendPostedEvents( parentWidget(),
+ TQEvent::ChildInserted );
+
+ if ( extra ) {
+ int w = crect.width();
+ int h = crect.height();
+ if ( w < extra->minw || h < extra->minh ||
+ w > extra->maxw || h > extra->maxh ) {
+ w = TQMAX( extra->minw, TQMIN( w, extra->maxw ));
+ h = TQMAX( extra->minh, TQMIN( h, extra->maxh ));
+ resize( w, h ); // deferred resize
+ }
+ }
+
+ if ( testWFlags(WStyle_Tool) || isPopup() ) {
+ raise();
+ } else if ( testWFlags(WType_TopLevel) ) {
+ while ( TQApplication::activePopupWidget() ) {
+ if ( !TQApplication::activePopupWidget()->close() )
+ break;
+ }
+ }
+
+ if ( !testWState(WState_Polished) )
+ polish();
+
+ showChildren( FALSE );
+
+ if ( postLayoutHint )
+ TQApplication::postEvent( parentWidget(),
+ new TQEvent(TQEvent::LayoutHint) );
+
+ // Required for Mac, not sure whether we should always do that
+ if( isTopLevel() )
+ TQApplication::sendPostedEvents(0, TQEvent::LayoutHint);
+
+ // On Windows, show the popup now so that our own focus handling
+ // stores the correct old focus widget even if it's stolen in the showevent
+#if defined(TQ_WS_WIN)
+ if ( testWFlags(WType_Popup) )
+ tqApp->openPopup( this );
+#endif
+
+ TQShowEvent showEvent;
+ TQApplication::sendEvent( this, &showEvent );
+
+ if ( testWFlags(WShowModal) ) {
+ // qt_enter_modal *before* show, otherwise the initial
+ // stacking might be wrong
+ qt_enter_modal( this );
+ }
+
+ // do not show the window directly, but post a show-window request
+ // to reduce flicker with widgets in layouts
+ if ( postLayoutHint )
+ TQApplication::postEvent( this, new TQEvent( TQEvent::ShowWindowRequest ) );
+ else
+ showWindow();
+
+#if !defined(TQ_WS_WIN)
+ if ( testWFlags(WType_Popup) )
+ tqApp->openPopup( this );
+#endif
+
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+ TQAccessible::updateAccessibility( this, 0, TQAccessible::ObjectShow );
+#endif
+
+ in_show = FALSE; // reset qws recursion watch
+}
+
+/*! \fn void TQWidget::iconify()
+ \obsolete
+*/
+
+/*!
+ Hides the widget.
+
+ You almost never have to reimplement this function. If you need to
+ do something after a widget is hidden, use hideEvent() instead.
+
+ \sa hideEvent(), isHidden(), show(), showMinimized(), isVisible(), close()
+*/
+
+void TQWidget::hide()
+{
+ clearWState( WState_CreatedHidden );
+ if ( testWState(WState_ForceHide) )
+ return;
+
+ setWState( WState_ForceHide );
+
+ if ( testWFlags(WType_Popup) )
+ tqApp->closePopup( this );
+
+ // Move test modal here. Otherwise, a modal dialog could get
+ // destroyed and we lose all access to its tqparent because we haven't
+ // left modality. (Eg. modal Progress Dialog)
+ if ( testWFlags(WShowModal) )
+ qt_leave_modal( this );
+
+#if defined(TQ_WS_WIN)
+ if ( isTopLevel() && !isPopup() && parentWidget() && isActiveWindow() )
+ parentWidget()->setActiveWindow(); // Activate tqparent
+#endif
+
+ hideWindow();
+
+ if ( testWState(WState_Visible) ) {
+ clearWState( WState_Visible );
+
+ // next bit tries to move the focus if the focus widget is now
+ // hidden.
+ if ( tqApp && tqApp->tqfocusWidget() == this )
+ focusNextPrevChild( TRUE );
+ TQHideEvent hideEvent;
+ TQApplication::sendEvent( this, &hideEvent );
+ hideChildren( FALSE );
+
+#if defined(TQT_ACCESSIBILITY_SUPPORT)
+ TQAccessible::updateAccessibility( this, 0, TQAccessible::ObjectHide );
+#endif
+ } else {
+ TQEvent hideToParentEvent( TQEvent::HideToParent );
+ TQApplication::sendEvent( this, &hideToParentEvent );
+ }
+
+ // post tqlayout hint for non toplevels. The tqparent widget check is
+ // necessary since the function is called in the destructor
+ if ( !isTopLevel() && parentWidget() )
+ TQApplication::postEvent( parentWidget(),
+ new TQEvent( TQEvent::LayoutHint) );
+}
+
+void TQWidget::setShown( bool show )
+{
+ if ( show )
+ this->show();
+ else
+ hide();
+}
+
+void TQWidget::setHidden( bool hide )
+{
+ if ( hide )
+ this->hide();
+ else
+ show();
+}
+
+void TQWidget::showChildren( bool spontaneous )
+{
+ if ( childrenListObject() ) {
+ TQObjectListIt it(*childrenListObject());
+ register TQObject *object;
+ TQWidget *widget;
+ while ( it ) {
+ object = it.current();
+ ++it;
+ if ( object->isWidgetType() ) {
+ widget = (TQWidget*)object;
+ if ( !widget->isTopLevel() && widget->isShown() ) {
+ if ( spontaneous ) {
+ widget->showChildren( spontaneous );
+ TQShowEvent e;
+ TQApplication::sendSpontaneousEvent( widget, &e );
+ } else {
+ widget->show();
+ }
+ }
+ }
+ }
+ }
+}
+
+void TQWidget::hideChildren( bool spontaneous )
+{
+ if ( childrenListObject() ) {
+ TQObjectListIt it(*childrenListObject());
+ register TQObject *object;
+ TQWidget *widget;
+ while ( it ) {
+ object = it.current();
+ ++it;
+ if ( object->isWidgetType() ) {
+ widget = (TQWidget*)object;
+ if ( !widget->isTopLevel() && widget->isShown() ) {
+ if ( !spontaneous )
+ widget->clearWState( WState_Visible );
+ widget->hideChildren( spontaneous );
+ TQHideEvent e;
+ if ( spontaneous )
+ TQApplication::sendSpontaneousEvent( widget, &e );
+ else
+ TQApplication::sendEvent( widget, &e );
+ }
+ }
+ }
+ }
+}
+
+
+/*!
+ Delayed initialization of a widget.
+
+ This function will be called \e after a widget has been fully
+ created and \e before it is shown the very first time.
+
+ Polishing is useful for final initialization which depends on
+ having an instantiated widget. This is something a constructor
+ cannot guarantee since the initialization of the subclasses might
+ not be finished.
+
+ After this function, the widget has a proper font and palette and
+ TQApplication::polish() has been called.
+
+ Remember to call TQWidget's implementation first when reimplementing this
+ function to ensure that your program does not end up in infinite recursion.
+
+ \sa constPolish(), TQApplication::polish()
+*/
+
+void TQWidget::polish()
+{
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ if ( isTopLevel() ) {
+ const TQPixmap *pm = icon();
+ if ( !pm || pm->isNull() ) {
+ TQWidget *mw = (TQWidget *)tqparent();
+ pm = mw ? mw->icon() : 0;
+ if ( pm && !pm->isNull() )
+ setIcon( *pm );
+ else {
+ mw = mw ? mw->tqtopLevelWidget() : 0;
+ pm = mw ? mw->icon() : 0;
+ if ( pm && !pm->isNull() )
+ setIcon( *pm );
+ else {
+ mw = tqApp ? tqApp->mainWidget() : 0;
+ pm = mw ? mw->icon() : 0;
+ if ( pm && !pm->isNull() )
+ setIcon( *pm );
+ }
+ }
+ }
+ }
+#endif
+ if ( !testWState(WState_Polished) ) {
+ if ( ! own_font &&
+ ! TQApplication::font( this ).isCopyOf( TQApplication::font() ) )
+ unsetFont();
+#ifndef TQT_NO_PALETTE
+ if ( ! own_palette &&
+ ! TQApplication::palette( this ).isCopyOf( TQApplication::palette() ) )
+ unsetPalette();
+#endif
+ setWState(WState_Polished);
+ tqApp->polish( this );
+ TQApplication::sendPostedEvents( this, TQEvent::ChildInserted );
+ }
+}
+
+
+/*!
+ \fn void TQWidget::constPolish() const
+
+ Ensures that the widget is properly initialized by calling
+ polish().
+
+ Call constPolish() from functions like tqsizeHint() that depends on
+ the widget being initialized, and that may be called before
+ show().
+
+ \warning Do not call constPolish() on a widget from inside that
+ widget's constructor.
+
+ \sa polish()
+*/
+
+/*!
+ \overload
+
+ Closes this widget. Returns TRUE if the widget was closed;
+ otherwise returns FALSE.
+
+ If \a alsoDelete is TRUE or the widget has the \c
+ WDestructiveClose widget flag, the widget is also deleted. The
+ widget can prevent itself from being closed by rejecting the
+ \l TQCloseEvent it gets. A close events is delivered to the widget
+ no matter if the widget is visible or not.
+
+ The TQApplication::lastWindowClosed() signal is emitted when the
+ last visible top level widget is closed.
+
+ Note that closing the \l TQApplication::mainWidget() terminates the
+ application.
+
+ \sa closeEvent(), TQCloseEvent, hide(), TQApplication::quit(),
+ TQApplication::setMainWidget(), TQApplication::lastWindowClosed()
+*/
+
+bool TQWidget::close( bool alsoDelete )
+{
+ if ( is_closing )
+ return TRUE;
+ is_closing = 1;
+ WId id = winId();
+ bool isMain = tqApp->mainWidget() == this;
+ bool checkLastWindowClosed = isTopLevel() && !isPopup();
+ bool deleted = FALSE;
+ TQCloseEvent e;
+ TQApplication::sendEvent( this, &e );
+ deleted = !TQWidget::tqfind(id);
+ if ( !deleted && !e.isAccepted() ) {
+ is_closing = 0;
+ return FALSE;
+ }
+ if ( !deleted && !isHidden() )
+ hide();
+ if ( checkLastWindowClosed
+ && tqApp->tqreceivers(TQT_SIGNAL(lastWindowClosed())) ) {
+ /* if there is no non-withdrawn top level window left (except
+ the desktop, popups, or dialogs with parents), we emit the
+ lastWindowClosed signal */
+ TQWidgetList *list = tqApp->tqtopLevelWidgets();
+ TQWidget *widget = list->first();
+ while ( widget ) {
+ if ( !widget->isHidden()
+ && !widget->isDesktop()
+ && !widget->isPopup()
+ && (!widget->isDialog() || !widget->parentWidget()))
+ break;
+ widget = list->next();
+ }
+ delete list;
+ if ( widget == 0 )
+ emit tqApp->lastWindowClosed();
+ }
+ if ( isMain )
+ tqApp->quit();
+ if ( deleted )
+ return TRUE;
+ is_closing = 0;
+ if ( alsoDelete )
+ delete this;
+ else if ( testWFlags(WDestructiveClose) ) {
+ clearWFlags(WDestructiveClose);
+ deleteLater();
+ }
+ return TRUE;
+}
+
+
+/*!
+ \fn bool TQWidget::close()
+
+ Closes this widget. Returns TRUE if the widget was closed;
+ otherwise returns FALSE.
+
+ First it sends the widget a TQCloseEvent. The widget is \link
+ hide() hidden\endlink if it \link TQCloseEvent::accept()
+ accepts\endlink the close event. The default implementation of
+ TQWidget::closeEvent() accepts the close event.
+
+ The \l TQApplication::lastWindowClosed() signal is emitted when the
+ last visible top level widget is closed.
+
+*/
+
+/*!
+ \property TQWidget::visible
+ \brief whether the widget is visible
+
+ Calling show() sets the widget to visible status if all its tqparent
+ widgets up to the top-level widget are visible. If an ancestor is
+ not visible, the widget won't become visible until all its
+ ancestors are shown.
+
+ Calling hide() hides a widget explicitly. An explicitly hidden
+ widget will never become visible, even if all its ancestors become
+ visible, unless you show it.
+
+ A widget receives show and hide events when its visibility status
+ changes. Between a hide and a show event, there is no need to
+ waste CPU cycles preparing or displaying information to the user.
+ A video application, for example, might simply stop generating new
+ frames.
+
+ A widget that happens to be obscured by other windows on the
+ screen is considered to be visible. The same applies to iconified
+ top-level widgets and windows that exist on another virtual
+ desktop (on platforms that support this concept). A widget
+ receives spontaneous show and hide events when its mapping status
+ is changed by the window system, e.g. a spontaneous hide event
+ when the user minimizes the window, and a spontaneous show event
+ when the window is restored again.
+
+ \sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(),
+ showEvent(), hideEvent()
+*/
+
+
+/*!
+ Returns TRUE if this widget would become visible if \a ancestor is
+ shown; otherwise returns FALSE.
+
+ The TRUE case occurs if neither the widget itself nor any tqparent
+ up to but excluding \a ancestor has been explicitly hidden.
+
+ This function will still return TRUE if the widget is obscured by
+ other windows on the screen, but could be physically visible if it
+ or they were to be moved.
+
+ isVisibleTo(0) is identical to isVisible().
+
+ \sa show() hide() isVisible()
+*/
+
+bool TQWidget::isVisibleTo(TQWidget* ancestor) const
+{
+ if ( !ancestor )
+ return isVisible();
+ const TQWidget * w = this;
+ while ( w
+ && w->isShown()
+ && !w->isTopLevel()
+ && w->parentWidget()
+ && w->parentWidget() != ancestor )
+ w = w->parentWidget();
+ return w->isShown();
+}
+
+
+/*!
+ \fn bool TQWidget::isVisibleToTLW() const
+ \obsolete
+
+ This function is deprecated. It is equivalent to isVisible()
+*/
+
+/*!
+ \property TQWidget::hidden
+ \brief whether the widget is explicitly hidden
+
+ If FALSE, the widget is visible or would become visible if all its
+ ancestors became visible.
+
+ \sa hide(), show(), isVisible(), isVisibleTo(), shown
+*/
+
+/*!
+ \property TQWidget::shown
+ \brief whether the widget is shown
+
+ If TRUE, the widget is visible or would become visible if all its
+ ancestors became visible.
+
+ \sa hide(), show(), isVisible(), isVisibleTo(), hidden
+*/
+
+/*!
+ \property TQWidget::visibleRect
+ \brief the visible rectangle
+
+ \obsolete
+
+ No longer necessary, you can simply call tqrepaint(). If you do not
+ need the rectangle for tqrepaint(), use clipRegion() instead.
+*/
+TQRect TQWidget::visibleRect() const
+{
+ TQRect r = rect();
+ const TQWidget * w = this;
+ int ox = 0;
+ int oy = 0;
+ while ( w
+ && w->isVisible()
+ && !w->isTopLevel()
+ && w->parentWidget() ) {
+ ox -= w->x();
+ oy -= w->y();
+ w = w->parentWidget();
+ r = r.intersect( TQRect( ox, oy, w->width(), w->height() ) );
+ }
+ if ( !w->isVisible() )
+ return TQRect();
+ return r;
+}
+
+/*!
+ Returns the unobscured region where paint events can occur.
+
+ For visible widgets, this is an approximation of the area not
+ covered by other widgets; otherwise, this is an empty region.
+
+ The tqrepaint() function calls this function if necessary, so in
+ general you do not need to call it.
+
+*/
+TQRegion TQWidget::clipRegion() const
+{
+ return visibleRect();
+}
+
+
+/*!
+ Adjusts the size of the widget to fit the contents.
+
+ Uses tqsizeHint() if valid (i.e if the size hint's width and height
+ are \>= 0), otherwise sets the size to the tqchildren rectangle (the
+ union of all child widget geometries).
+
+ \sa tqsizeHint(), tqchildrenRect()
+*/
+
+void TQWidget::adjustSize()
+{
+ TQApplication::sendPostedEvents( 0, TQEvent::ChildInserted );
+ TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint );
+ if ( !testWState(WState_Polished) )
+ polish();
+ TQSize s = tqsizeHint();
+
+ if ( isTopLevel() ) {
+
+#if defined(TQ_WS_X11)
+ TQRect screen = TQApplication::desktop()->screenGeometry( x11Screen() );
+#else // all others
+ TQRect screen = TQApplication::desktop()->screenGeometry( pos() );
+#endif
+
+#ifndef TQT_NO_LAYOUT
+ if ( tqlayout() ) {
+ if ( tqlayout()->hasHeightForWidth() ) {
+ s = s.boundedTo( screen.size() );
+ s.setHeight( tqlayout()->totalHeightForWidth( s.width() ) );
+ }
+ } else
+#endif
+ {
+ if ( sizePolicy().hasHeightForWidth() ) {
+ s = s.boundedTo( screen.size() );
+ s.setHeight( heightForWidth( s.width() ) );
+ }
+ }
+ }
+ if ( s.isValid() ) {
+ resize( s );
+ return;
+ }
+ TQRect r = tqchildrenRect(); // get tqchildren rectangle
+ if ( r.isNull() ) // probably no widgets
+ return;
+ resize( r.width() + 2 * r.x(), r.height() + 2 * r.y() );
+}
+
+
+/*!
+ \property TQWidget::tqsizeHint
+ \brief the recommended size for the widget
+
+ If the value of this property is an invalid size, no size is
+ recommended.
+
+ The default implementation of tqsizeHint() returns an invalid size
+ if there is no tqlayout for this widget, and returns the tqlayout's
+ preferred size otherwise.
+
+ \sa TQSize::isValid(), tqminimumSizeHint(), sizePolicy(),
+ setMinimumSize(), updateGeometry()
+*/
+
+TQSize TQWidget::tqsizeHint() const
+{
+#ifndef TQT_NO_LAYOUT
+ if ( tqlayout() )
+ return tqlayout()->totalSizeHint();
+#endif
+ return TQSize( -1, -1 );
+}
+
+/*!
+ \property TQWidget::tqminimumSizeHint
+ \brief the recommended minimum size for the widget
+
+ If the value of this property is an invalid size, no minimum size
+ is recommended.
+
+ The default implementation of tqminimumSizeHint() returns an invalid
+ size if there is no tqlayout for this widget, and returns the
+ tqlayout's minimum size otherwise. Most built-in widgets reimplement
+ tqminimumSizeHint().
+
+ \l TQLayout will never resize a widget to a size smaller than
+ tqminimumSizeHint.
+
+ \sa TQSize::isValid(), resize(), setMinimumSize(), sizePolicy()
+*/
+TQSize TQWidget::tqminimumSizeHint() const
+{
+#ifndef TQT_NO_LAYOUT
+ if ( tqlayout() )
+ return tqlayout()->totalMinimumSize();
+#endif
+ return TQSize( -1, -1 );
+}
+
+
+/*!
+ \fn TQWidget *TQWidget::parentWidget( bool sameWindow ) const
+
+ Returns the tqparent of this widget, or 0 if it does not have any
+ tqparent widget. If \a sameWindow is TRUE and the widget is top
+ level returns 0; otherwise returns the widget's tqparent.
+*/
+
+/*!
+ \fn WFlags TQWidget::testWFlags( WFlags f ) const
+
+ Returns the bitwise AND of the widget flags and \a f.
+
+ Widget flags are a combination of \l{TQt::WidgetFlags}.
+
+ If you want to test for the presence of multiple flags (or
+ composite flags such as \c WStyle_Splash), test the
+ return value for equality against the argument. For example:
+
+ \code
+ int flags = WStyle_Tool | WStyle_NoBorder;
+ if ( testWFlags(flags) )
+ ... // WStyle_Tool or WStyle_NoBorder or both are set
+ if ( testWFlags(flags) == flags )
+ ... // both WStyle_Tool and WStyle_NoBorder are set
+ \endcode
+
+ \sa getWFlags(), setWFlags(), clearWFlags()
+*/
+
+/*!
+ \fn WState TQWidget::testWState( WState s ) const
+ \internal
+
+ Returns the bitwise AND of the widget states and \a s.
+*/
+
+/*!
+ \fn uint TQWidget::getWState() const
+
+ \internal
+
+ Returns the current widget state.
+*/
+/*!
+ \fn void TQWidget::clearWState( uint n )
+
+ \internal
+
+ Clears the widgets states \a n.
+*/
+/*!
+ \fn void TQWidget::setWState( uint n )
+
+ \internal
+
+ Sets the widgets states \a n.
+*/
+
+
+
+/*****************************************************************************
+ TQWidget event handling
+ *****************************************************************************/
+
+/*!
+ This is the main event handler; it handles event \a e. You can
+ reimplement this function in a subclass, but we recommend using
+ one of the specialized event handlers instead.
+
+ The main event handler first passes an event through all \link
+ TQObject::installEventFilter() event filters\endlink that have been
+ installed. If none of the filters intercept the event, it calls
+ one of the specialized event handlers.
+
+ Key press and release events are treated differently from other
+ events. event() checks for Tab and Shift+Tab and tries to move the
+ focus appropriately. If there is no widget to move the focus to
+ (or the key press is not Tab or Shift+Tab), event() calls
+ keyPressEvent().
+
+ This function returns TRUE if it is able to pass the event over to
+ someone (i.e. someone wanted the event); otherwise returns FALSE.
+
+ \sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(),
+ keyPressEvent(), keyReleaseEvent(), leaveEvent(),
+ mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(),
+ mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(),
+ TQObject::event(), TQObject::timerEvent()
+*/
+
+bool TQWidget::event( TQEvent *e )
+{
+ if ( TQObject::event( e ) )
+ return TRUE;
+
+ switch ( e->type() ) {
+ case TQEvent::MouseMove:
+ mouseMoveEvent( (TQMouseEvent*)e );
+ if ( ! ((TQMouseEvent*)e)->isAccepted() )
+ return FALSE;
+ break;
+
+ case TQEvent::MouseButtonPress:
+ resetInputContext();
+ mousePressEvent( (TQMouseEvent*)e );
+ if ( ! ((TQMouseEvent*)e)->isAccepted() )
+ return FALSE;
+ break;
+
+ case TQEvent::MouseButtonRelease:
+ mouseReleaseEvent( (TQMouseEvent*)e );
+ if ( ! ((TQMouseEvent*)e)->isAccepted() )
+ return FALSE;
+ break;
+
+ case TQEvent::MouseButtonDblClick:
+ mouseDoubleClickEvent( (TQMouseEvent*)e );
+ if ( ! ((TQMouseEvent*)e)->isAccepted() )
+ return FALSE;
+ break;
+#ifndef TQT_NO_WHEELEVENT
+ case TQEvent::Wheel:
+ wheelEvent( (TQWheelEvent*)e );
+ if ( ! ((TQWheelEvent*)e)->isAccepted() )
+ return FALSE;
+ break;
+#endif
+ case TQEvent::TabletMove:
+ case TQEvent::TabletPress:
+ case TQEvent::TabletRelease:
+ tabletEvent( (TQTabletEvent*)e );
+ if ( ! ((TQTabletEvent*)e)->isAccepted() )
+ return FALSE;
+ break;
+ case TQEvent::Accel:
+ ((TQKeyEvent*)e)->ignore();
+ return FALSE;
+ case TQEvent::KeyPress: {
+ TQKeyEvent *k = (TQKeyEvent *)e;
+ bool res = FALSE;
+ if ( !(k->state() & ControlButton || k->state() & AltButton) ) {
+ if ( k->key() == Key_Backtab ||
+ (k->key() == Key_Tab &&
+ (k->state() & ShiftButton)) ) {
+ TQFocusEvent::setReason( TQFocusEvent::Backtab );
+ res = focusNextPrevChild( FALSE );
+ TQFocusEvent::resetReason();
+
+ } else if ( k->key() == Key_Tab ) {
+ TQFocusEvent::setReason( TQFocusEvent::Tab );
+ res = focusNextPrevChild( TRUE );
+ TQFocusEvent::resetReason();
+ }
+ if ( res )
+ break;
+ }
+ keyPressEvent( k );
+ if ( !k->isAccepted() )
+ return FALSE;
+ }
+ break;
+
+ case TQEvent::KeyRelease:
+ keyReleaseEvent( (TQKeyEvent*)e );
+ if ( ! ((TQKeyEvent*)e)->isAccepted() )
+ return FALSE;
+ break;
+
+ case TQEvent::IMStart: {
+ TQIMEvent *i = (TQIMEvent *) e;
+ imStartEvent(i);
+ if (! i->isAccepted())
+ return FALSE;
+ }
+ break;
+
+ case TQEvent::IMCompose: {
+ TQIMEvent *i = (TQIMEvent *) e;
+ imComposeEvent(i);
+ if (! i->isAccepted())
+ return FALSE;
+ }
+ break;
+
+ case TQEvent::IMEnd: {
+ TQIMEvent *i = (TQIMEvent *) e;
+ imEndEvent(i);
+ if (! i->isAccepted())
+ return FALSE;
+ }
+ break;
+
+ case TQEvent::FocusIn:
+ focusInEvent( (TQFocusEvent*)e );
+ setFontSys();
+ break;
+
+ case TQEvent::FocusOut:
+ focusOutEvent( (TQFocusEvent*)e );
+ break;
+
+ case TQEvent::Enter:
+ enterEvent( e );
+ break;
+
+ case TQEvent::Leave:
+ leaveEvent( e );
+ break;
+
+ case TQEvent::Paint:
+ // At this point the event has to be delivered, regardless
+ // whether the widget isVisible() or not because it
+ // already went through the filters
+ paintEvent( (TQPaintEvent*)e );
+ break;
+
+ case TQEvent::Move:
+ moveEvent( (TQMoveEvent*)e );
+ break;
+
+ case TQEvent::Resize:
+ resizeEvent( (TQResizeEvent*)e );
+ break;
+
+ case TQEvent::Close: {
+ TQCloseEvent *c = (TQCloseEvent *)e;
+ closeEvent( c );
+ if ( !c->isAccepted() )
+ return FALSE;
+ }
+ break;
+
+ case TQEvent::ContextMenu: {
+ TQContextMenuEvent *c = (TQContextMenuEvent *)e;
+ contextMenuEvent( c );
+ if ( !c->isAccepted() )
+ return FALSE;
+ }
+ break;
+
+#ifndef TQT_NO_DRAGANDDROP
+ case TQEvent::Drop:
+ dropEvent( (TQDropEvent*) e);
+ break;
+
+ case TQEvent::DragEnter:
+ dragEnterEvent( (TQDragEnterEvent*) e);
+ break;
+
+ case TQEvent::DragMove:
+ dragMoveEvent( (TQDragMoveEvent*) e);
+ break;
+
+ case TQEvent::DragLeave:
+ dragLeaveEvent( (TQDragLeaveEvent*) e);
+ break;
+#endif
+
+ case TQEvent::Show:
+ showEvent( (TQShowEvent*) e);
+ break;
+
+ case TQEvent::Hide:
+ hideEvent( (TQHideEvent*) e);
+ break;
+
+ case TQEvent::ShowWindowRequest:
+ if ( isShown() )
+ showWindow();
+ break;
+
+ case TQEvent::ParentFontChange:
+ if ( isTopLevel() )
+ break;
+ // fall through
+ case TQEvent::ApplicationFontChange:
+ if ( own_font )
+ setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
+ else
+ unsetFont();
+ break;
+
+#ifndef TQT_NO_PALETTE
+ case TQEvent::ParentPaletteChange:
+ if ( isTopLevel() )
+ break;
+ // fall through
+ case TQEvent::ApplicationPaletteChange:
+ if ( !own_palette && !isDesktop() )
+ unsetPalette();
+# if defined(TQ_WS_TQWS) && !defined (TQT_NO_TQWS_MANAGER)
+ if ( isTopLevel() && topData()->qwsManager ) {
+ TQRegion r( topData()->qwsManager->region() );
+ TQApplication::postEvent(topData()->qwsManager, new TQPaintEvent(r, FALSE) );
+ }
+# endif
+ break;
+#endif
+
+ case TQEvent::WindowActivate:
+ case TQEvent::WindowDeactivate:
+ windowActivationChange( e->type() != TQEvent::WindowActivate );
+ if ( childrenListObject() ) {
+ TQObjectListIt it( *childrenListObject() );
+ TQObject *o;
+ while( ( o = it.current() ) != 0 ) {
+ ++it;
+ if ( o->isWidgetType() &&
+ ((TQWidget*)o)->isVisible() &&
+ !((TQWidget*)o)->isTopLevel() )
+ TQApplication::sendEvent( o, e );
+ }
+ }
+ break;
+
+ case TQEvent::LanguageChange:
+ case TQEvent::LocaleChange:
+ if ( childrenListObject() ) {
+ TQObjectListIt it( *childrenListObject() );
+ TQObject *o;
+ while( ( o = it.current() ) != 0 ) {
+ ++it;
+ TQApplication::sendEvent( o, e );
+ }
+ }
+ if ( e->type() == TQEvent::LanguageChange ) {
+ int index = tqmetaObject()->tqfindSlot( "languageChange()", TRUE );
+ if ( index >= 0 )
+ qt_invoke( index, 0 );
+ }
+ update();
+ break;
+#ifndef TQT_NO_LAYOUT
+ case TQEvent::LayoutDirectionChange:
+ if ( tqlayout() ) {
+ tqlayout()->activate();
+ } else {
+ TQObjectList* llist = queryList( "TQLayout", 0, TRUE, TRUE );
+ TQObjectListIt lit( *llist );
+ TQLayout *lay;
+ while ( ( lay = (TQLayout*)lit.current() ) != 0 ) {
+ ++lit;
+ lay->activate();
+ }
+ delete llist;
+ }
+ update();
+ break;
+#endif
+
+ case TQEvent::WindowStateChange:
+ {
+ TQEvent::Type type;
+ if (isMinimized())
+ type = TQEvent::ShowMinimized;
+ else if (isFullScreen())
+ type = TQEvent::ShowFullScreen;
+ else if (isMaximized())
+ type = TQEvent::ShowMaximized;
+ else
+ type = TQEvent::ShowNormal;
+
+ TQApplication::postEvent(this, new TQEvent(type));
+ break;
+ }
+
+ case TQEvent::WindowBlocked:
+ case TQEvent::WindowUnblocked:
+ if ( childrenListObject() ) {
+ TQObjectListIt it( *childrenListObject() );
+ TQObject *o;
+ while( ( o = it.current() ) != 0 ) {
+ ++it;
+ TQWidget *w = ::tqqt_cast<TQWidget*>(o);
+ if (w && !w->testWFlags(TQt::WShowModal))
+ TQApplication::sendEvent( o, e );
+ }
+ }
+ break;
+
+ default:
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse move events for the widget.
+
+ If mouse tracking is switched off, mouse move events only occur if
+ a mouse button is pressed while the mouse is being moved. If mouse
+ tracking is switched on, mouse move events occur even if no mouse
+ button is pressed.
+
+ TQMouseEvent::pos() reports the position of the mouse cursor,
+ relative to this widget. For press and release events, the
+ position is usually the same as the position of the last mouse
+ move event, but it might be different if the user's hand shakes.
+ This is a feature of the underlying window system, not TQt.
+
+ \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
+ mouseDoubleClickEvent(), event(), TQMouseEvent
+*/
+
+void TQWidget::mouseMoveEvent( TQMouseEvent * e)
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse press events for the widget.
+
+ If you create new widgets in the mousePressEvent() the
+ mouseReleaseEvent() may not end up where you expect, depending on
+ the underlying window system (or X11 window manager), the widgets'
+ location and maybe more.
+
+ The default implementation implements the closing of popup widgets
+ when you click outside the window. For other widget types it does
+ nothing.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQWidget::mousePressEvent( TQMouseEvent *e )
+{
+ e->ignore();
+ if ( isPopup() ) {
+ e->accept();
+ TQWidget* w;
+ while ( (w = tqApp->activePopupWidget() ) && w != this ){
+ w->close();
+ if (tqApp->activePopupWidget() == w) // widget does not want to dissappear
+ w->hide(); // hide at least
+ }
+ if (!rect().tqcontains(e->pos()) ){
+ close();
+ }
+ }
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse release events for the widget.
+
+ \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
+ mouseMoveEvent(), event(), TQMouseEvent
+*/
+
+void TQWidget::mouseReleaseEvent( TQMouseEvent * e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive mouse double click events for the widget.
+
+ The default implementation generates a normal mouse press event.
+
+ Note that the widgets gets a mousePressEvent() and a
+ mouseReleaseEvent() before the mouseDoubleClickEvent().
+
+ \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
+ event(), TQMouseEvent
+*/
+
+void TQWidget::mouseDoubleClickEvent( TQMouseEvent *e )
+{
+ mousePressEvent( e ); // try mouse press event
+}
+
+#ifndef TQT_NO_WHEELEVENT
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive wheel events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQWheelEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQWheelEvent::ignore(), TQWheelEvent::accept(), event(),
+ TQWheelEvent
+*/
+
+void TQWidget::wheelEvent( TQWheelEvent *e )
+{
+ e->ignore();
+}
+#endif
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive tablet events for the widget.
+
+ If you reimplement this handler, it is very important that you
+ \link TQTabletEvent ignore()\endlink the event if you do not handle
+ it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa TQTabletEvent::ignore(), TQTabletEvent::accept(), event(),
+ TQTabletEvent
+*/
+
+void TQWidget::tabletEvent( TQTabletEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key press events for the widget.
+
+ A widget must call setFocusPolicy() to accept focus initially and
+ have focus in order to receive a key press event.
+
+ If you reimplement this handler, it is very important that you
+ explicitly \link TQKeyEvent::ignore() ignore\endlink the event
+ if you do not understand it, so that the widget's tqparent can
+ interpret it; otherwise, the event will be implicitly accepted.
+ Although top-level widgets are able to choose whether to accept
+ or ignore unknown events because they have no tqparent widgets that
+ could otherwise handle them, it is good practice to explicitly
+ ignore events to make widgets as reusable as possible.
+
+ The default implementation closes popup widgets if the user
+ presses <b>Esc</b>. Otherwise the event is ignored.
+
+ \sa keyReleaseEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQWidget::keyPressEvent( TQKeyEvent *e )
+{
+ if ( isPopup() && e->key() == Key_Escape ) {
+ e->accept();
+ close();
+ } else {
+ e->ignore();
+ }
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive key release events for the widget.
+
+ A widget must \link setFocusPolicy() accept focus\endlink
+ initially and \link hasFocus() have focus\endlink in order to
+ receive a key release event.
+
+ If you reimplement this handler, it is very important that you
+ \link TQKeyEvent ignore()\endlink the release if you do not
+ understand it, so that the widget's tqparent can interpret it.
+
+ The default implementation ignores the event.
+
+ \sa keyPressEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
+ focusInEvent(), focusOutEvent(), event(), TQKeyEvent
+*/
+
+void TQWidget::keyReleaseEvent( TQKeyEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus received) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQWidget::focusInEvent( TQFocusEvent * )
+{
+ if ( focusPolicy() != NoFocus || !isTopLevel() ) {
+ update();
+ if ( testWState(WState_AutoMask) )
+ updateMask();
+ setMicroFocusHint(width()/2, 0, 1, height(), FALSE);
+ }
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ keyboard focus events (focus lost) for the widget.
+
+ A widget normally must setFocusPolicy() to something other than
+ \c NoFocus in order to receive focus events. (Note that the
+ application programmer can call setFocus() on any widget, even
+ those that do not normally accept focus.)
+
+ The default implementation updates the widget (except for toplevel
+ widgets that do not specify a focusPolicy() ). It also calls
+ setMicroFocusHint(), hinting any system-specific input tools about
+ the focus of the user's attention.
+
+ \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
+ keyReleaseEvent(), event(), TQFocusEvent
+*/
+
+void TQWidget::focusOutEvent( TQFocusEvent * )
+{
+ if ( focusPolicy() != NoFocus || !isTopLevel() ){
+ update();
+ if ( testWState(WState_AutoMask) )
+ updateMask();
+ }
+}
+
+/*!
+ \property TQWidget::microFocusHint
+ \brief the currently set micro focus hint for this widget.
+
+ See the documentation of setMicroFocusHint() for more information.
+*/
+TQRect TQWidget::microFocusHint() const
+{
+ if ( !extra )
+ return TQRect(width()/2, 0, 1, height() );
+ else if ( extra->micro_focus_hint.isEmpty() )
+ return TQRect(width()/2, 0, 1, height() );
+ else
+ return extra->micro_focus_hint;
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget enter events.
+
+ An event is sent to the widget when the mouse cursor enters the
+ widget.
+
+ \sa leaveEvent(), mouseMoveEvent(), event()
+*/
+
+void TQWidget::enterEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget leave events.
+
+ A leave event is sent to the widget when the mouse cursor leaves
+ the widget.
+
+ \sa enterEvent(), mouseMoveEvent(), event()
+*/
+
+void TQWidget::leaveEvent( TQEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ paint events.
+
+ A paint event is a request to tqrepaint all or part of the widget.
+ It can happen as a result of tqrepaint() or update(), or because the
+ widget was obscured and has now been uncovered, or for many other
+ reasons.
+
+ Many widgets can simply tqrepaint their entire surface when asked
+ to, but some slow widgets need to optimize by painting only the
+ requested region: TQPaintEvent::region(). This speed optimization
+ does not change the result, as painting is clipped to that region
+ during event processing. TQListView and TQCanvas do this, for
+ example.
+
+ TQt also tries to speed up painting by merging multiple paint
+ events into one. When update() is called several times or the
+ window system sends several paint events, TQt merges these events
+ into one event with a larger region (see TQRegion::unite()).
+ tqrepaint() does not permit this optimization, so we suggest using
+ update() when possible.
+
+ When the paint event occurs, the update region has normally been
+ erased, so that you're painting on the widget's background. There
+ are a couple of exceptions and TQPaintEvent::erased() tells you
+ whether the widget has been erased or not.
+
+ The background can be set using setBackgroundMode(),
+ setPaletteBackgroundColor() or setBackgroundPixmap(). The
+ documentation for setBackgroundMode() elaborates on the
+ background; we recommend reading it.
+
+ \sa event(), tqrepaint(), update(), TQPainter, TQPixmap, TQPaintEvent
+*/
+
+void TQWidget::paintEvent( TQPaintEvent * )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget move events. When the widget receives this event, it is
+ already at the new position.
+
+ The old position is accessible through TQMoveEvent::oldPos().
+
+ \sa resizeEvent(), event(), move(), TQMoveEvent
+*/
+
+void TQWidget::moveEvent( TQMoveEvent * )
+{
+}
+
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget resize events. When resizeEvent() is called, the widget
+ already has its new tqgeometry. The old size is accessible through
+ TQResizeEvent::oldSize().
+
+ The widget will be erased and receive a paint event immediately
+ after processing the resize event. No drawing need be (or should
+ be) done inside this handler.
+
+ Widgets that have been created with the \c WNoAutoErase flag
+ will not be erased. Nevertheless, they will receive a paint event
+ for their entire area afterwards. Again, no drawing needs to be
+ done inside this handler.
+
+ The default implementation calls updateMask() if the widget has
+ \link TQWidget::setAutoMask() automatic masking\endlink enabled.
+
+ \sa moveEvent(), event(), resize(), TQResizeEvent, paintEvent()
+*/
+
+void TQWidget::resizeEvent( TQResizeEvent * )
+{
+ if ( testWState(WState_AutoMask) )
+ updateMask();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget close events.
+
+ The default implementation calls e->accept(), which hides this
+ widget. See the \l TQCloseEvent documentation for more details.
+
+ \sa event(), hide(), close(), TQCloseEvent
+*/
+
+void TQWidget::closeEvent( TQCloseEvent *e )
+{
+ e->accept();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive widget context menu events.
+
+ The default implementation calls e->ignore(), which rejects the
+ context event. See the \l TQContextMenuEvent documentation for
+ more details.
+
+ \sa event(), TQContextMenuEvent
+*/
+
+void TQWidget::contextMenuEvent( TQContextMenuEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user begins entering text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQWidget::imStartEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has entered some text using an Input Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQWidget::imComposeEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+/*!
+ This event handler, for event \a e, can be reimplemented in a
+ subclass to receive Input Method composition events. This handler
+ is called when the user has finished inputting text via an Input
+ Method.
+
+ The default implementation calls e->ignore(), which rejects the
+ Input Method event. See the \l TQIMEvent documentation for more
+ details.
+
+ \sa event(), TQIMEvent
+*/
+void TQWidget::imEndEvent( TQIMEvent *e )
+{
+ e->ignore();
+}
+
+
+#ifndef TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragEnterEvent
+*/
+void TQWidget::dragEnterEvent( TQDragEnterEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse enters this widget, and whenever it moves within the widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragMoveEvent
+*/
+void TQWidget::dragMoveEvent( TQDragMoveEvent * )
+{
+}
+
+/*!
+ This event handler is called when a drag is in progress and the
+ mouse leaves this widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDragLeaveEvent
+*/
+void TQWidget::dragLeaveEvent( TQDragLeaveEvent * )
+{
+}
+
+/*!
+ This event handler is called when the drag is dropped on this
+ widget.
+
+ See the \link dnd.html Drag-and-drop documentation\endlink for an
+ overview of how to provide drag-and-drop in your application.
+
+ \sa TQTextDrag, TQImageDrag, TQDropEvent
+*/
+void TQWidget::dropEvent( TQDropEvent * )
+{
+}
+
+#endif // TQT_NO_DRAGANDDROP
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget show events.
+
+ Non-spontaneous show events are sent to widgets immediately before
+ they are shown. The spontaneous show events of top-level widgets
+ are delivered afterwards.
+
+ \sa event(), TQShowEvent
+*/
+void TQWidget::showEvent( TQShowEvent * )
+{
+}
+
+/*!
+ This event handler can be reimplemented in a subclass to receive
+ widget hide events.
+
+ Hide events are sent to widgets immediately after they have been
+ hidden.
+
+ \sa event(), TQHideEvent
+*/
+void TQWidget::hideEvent( TQHideEvent * )
+{
+}
+
+/*
+ \fn TQWidget::x11Event( MSG * )
+
+ This special event handler can be reimplemented in a subclass to
+ receive native X11 events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::x11EventFilter()
+*/
+
+
+#if defined(TQ_WS_MAC)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native Macintosh events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::macEventFilter()
+*/
+
+bool TQWidget::macEvent( MSG * )
+{
+ return FALSE;
+}
+
+#endif
+#if defined(TQ_WS_WIN)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native Windows events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::winEventFilter()
+*/
+bool TQWidget::winEvent( MSG * )
+{
+ return FALSE;
+}
+
+#endif
+#if defined(TQ_WS_X11)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native X11 events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::x11EventFilter()
+*/
+bool TQWidget::x11Event( XEvent * )
+{
+ return FALSE;
+}
+
+#endif
+#if defined(TQ_WS_TQWS)
+
+/*!
+ This special event handler can be reimplemented in a subclass to
+ receive native TQt/Embedded events.
+
+ In your reimplementation of this function, if you want to stop the
+ event being handled by TQt, return TRUE. If you return FALSE, this
+ native event is passed back to TQt, which translates the event into
+ a TQt event and sends it to the widget.
+
+ \warning This function is not portable.
+
+ \sa TQApplication::qwsEventFilter()
+*/
+bool TQWidget::qwsEvent( TQWSEvent * )
+{
+ return FALSE;
+}
+
+#endif
+
+/*!
+ \property TQWidget::autoMask
+ \brief whether the auto tqmask feature is enabled for the widget
+
+ Transtqparent widgets use a tqmask to define their visible region.
+ TQWidget has some built-in support to make the task of
+ recalculating the tqmask easier. When setting auto tqmask to TRUE,
+ updateMask() will be called whenever the widget is resized or
+ changes its focus state. Note that you must reimplement
+ updateMask() (which should include a call to setMask()) or nothing
+ will happen.
+
+ Note: when you re-implement resizeEvent(), focusInEvent() or
+ focusOutEvent() in your custom widgets and still want to ensure
+ that the auto tqmask calculation works, you should add:
+
+ \code
+ if ( autoMask() )
+ updateMask();
+ \endcode
+
+ at the end of your event handlers. This is true for all member
+ functions that change the appearance of the widget in a way that
+ requires a recalculation of the tqmask.
+
+ While being a technically appealing concept, masks have a big
+ drawback: when using complex masks that cannot be expressed easily
+ with relatively simple regions, they can be very slow on some
+ window systems. The classic example is a transtqparent label. The
+ complex tqshape of its contents makes it necessary to represent its
+ tqmask by a bitmap, which consumes both memory and time. If all you
+ want is to blend the background of several neighboring widgets
+ together seamlessly, you will probably want to use
+ setBackgroundOrigin() rather than a tqmask.
+
+ \sa autoMask() updateMask() setMask() clearMask() setBackgroundOrigin()
+*/
+
+bool TQWidget::autoMask() const
+{
+ return testWState(WState_AutoMask);
+}
+
+void TQWidget::setAutoMask( bool enable )
+{
+ if ( enable == autoMask() )
+ return;
+
+ if ( enable ) {
+ setWState(WState_AutoMask);
+ updateMask();
+ } else {
+ clearWState(WState_AutoMask);
+ clearMask();
+ }
+}
+
+/*!
+ \enum TQWidget::BackgroundOrigin
+
+ This enum defines the origin used to draw a widget's background
+ pixmap.
+
+ The pixmap is drawn using the:
+ \value WidgetOrigin widget's coordinate system.
+ \value ParentOrigin tqparent's coordinate system.
+ \value WindowOrigin top-level window's coordinate system.
+ \value AncestorOrigin same origin as the tqparent uses.
+*/
+
+/*!
+ \property TQWidget::backgroundOrigin
+ \brief the origin of the widget's background
+
+ The origin is either WidgetOrigin (the default), ParentOrigin,
+ WindowOrigin or AncestorOrigin.
+
+ This only makes a difference if the widget has a background
+ pixmap, in which case positioning matters. Using \c WindowOrigin
+ for several neighboring widgets makes the background blend
+ together seamlessly. \c AncestorOrigin allows blending backgrounds
+ seamlessly when an ancestor of the widget has an origin other than
+ \c WindowOrigin.
+
+ \sa backgroundPixmap(), setBackgroundMode()
+*/
+TQWidget::BackgroundOrigin TQWidget::backgroundOrigin() const
+{
+ return extra ? (BackgroundOrigin)extra->bg_origin : WidgetOrigin;
+}
+
+void TQWidget::setBackgroundOrigin( BackgroundOrigin origin )
+{
+ if ( origin == backgroundOrigin() )
+ return;
+ createExtra();
+ extra->bg_origin = origin;
+ update();
+}
+
+/*!
+ This function can be reimplemented in a subclass to support
+ transtqparent widgets. It should be called whenever a widget changes
+ state in a way that means that the tqshape tqmask must be recalculated.
+
+ \sa setAutoMask(), updateMask(), setMask(), clearMask()
+*/
+void TQWidget::updateMask()
+{
+}
+
+/*!
+ \internal
+ Returns the offset of the widget from the backgroundOrigin.
+
+ \sa setBackgroundMode(), backgroundMode(),
+*/
+TQPoint TQWidget::backgroundOffset() const
+{
+ if (!isTopLevel()) {
+ switch(backgroundOrigin()) {
+ case WidgetOrigin:
+ break;
+ case ParentOrigin:
+ return pos();
+ case WindowOrigin:
+ {
+ const TQWidget *topl = this;
+ while(topl && !topl->isTopLevel() && !topl->testWFlags(TQt::WSubWindow))
+ topl = topl->parentWidget(TRUE);
+ return mapTo((TQWidget *)topl, TQPoint(0, 0) );
+ }
+ case AncestorOrigin:
+ {
+ const TQWidget *topl = this;
+ bool ancestorIsWindowOrigin = FALSE;
+ while(topl && !topl->isTopLevel() && !topl->testWFlags(TQt::WSubWindow))
+ {
+ if (!ancestorIsWindowOrigin) {
+ if (topl->backgroundOrigin() == TQWidget::WidgetOrigin)
+ break;
+ if (topl->backgroundOrigin() == TQWidget::ParentOrigin)
+ {
+ topl = topl->parentWidget(TRUE);
+ break;
+ }
+ if (topl->backgroundOrigin() == TQWidget::WindowOrigin)
+ ancestorIsWindowOrigin = TRUE;
+ }
+ topl = topl->parentWidget(TRUE);
+ }
+
+ return mapTo((TQWidget *) topl, TQPoint(0,0) );
+ }
+ }
+ }
+ // fall back
+ return TQPoint(0,0);
+}
+
+/*!
+ \fn TQLayout* TQWidget::tqlayout () const
+
+ Returns the tqlayout engine that manages the tqgeometry of this
+ widget's tqchildren.
+
+ If the widget does not have a tqlayout, tqlayout() returns 0.
+
+ \sa sizePolicy()
+*/
+
+
+/* Sets this widget to use tqlayout \a l to manage the tqgeometry of its
+ tqchildren.
+
+ If the widget already had a tqlayout, the old tqlayout is
+ forgotten. (Note that it is not deleted.)
+
+ \sa tqlayout() TQLayout sizePolicy()
+*/
+#ifndef TQT_NO_LAYOUT
+void TQWidget::setLayout( TQLayout *l )
+{
+ lay_out = l;
+}
+#endif
+
+/*!
+ \property TQWidget::sizePolicy
+ \brief the default tqlayout behavior of the widget
+
+ If there is a TQLayout that manages this widget's tqchildren, the
+ size policy specified by that tqlayout is used. If there is no such
+ TQLayout, the result of this function is used.
+
+ The default policy is Preferred/Preferred, which means that the
+ widget can be freely resized, but prefers to be the size
+ tqsizeHint() returns. Button-like widgets set the size policy to
+ specify that they may stretch horizontally, but are fixed
+ vertically. The same applies to lineedit controls (such as
+ TQLineEdit, TQSpinBox or an editable TQComboBox) and other
+ horizontally orientated widgets (such as TQProgressBar).
+ TQToolButton's are normally square, so they allow growth in both
+ directions. Widgets that support different directions (such as
+ TQSlider, TQScrollBar or TQHeader) specify stretching in the
+ respective direction only. Widgets that can provide scrollbars
+ (usually subclasses of TQScrollView) tend to specify that they can
+ use additional space, and that they can make do with less than
+ tqsizeHint().
+
+ \sa tqsizeHint() TQLayout TQSizePolicy updateGeometry()
+*/
+TQSizePolicy TQWidget::sizePolicy() const
+{
+ return extra ? extra->size_policy
+ : TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred );
+}
+
+void TQWidget::tqsetSizePolicy( TQSizePolicy policy )
+{
+ setWState( WState_OwnSizePolicy );
+ if ( policy == sizePolicy() )
+ return;
+ createExtra();
+ extra->size_policy = policy;
+ updateGeometry();
+}
+
+/*!
+ \overload void TQWidget::tqsetSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw )
+
+ Sets the size policy of the widget to \a hor, \a ver and \a hfw
+ (height for width).
+
+ \sa TQSizePolicy::TQSizePolicy()
+*/
+
+/*!
+ Returns the preferred height for this widget, given the width \a
+ w. The default implementation returns 0, indicating that the
+ preferred height does not depend on the width.
+
+ \warning Does not look at the widget's tqlayout.
+*/
+
+int TQWidget::heightForWidth( int w ) const
+{
+ (void)w;
+ return 0;
+}
+
+/*!
+ \property TQWidget::customWhatsThis
+ \brief whether the widget wants to handle What's This help manually
+
+ The default implementation of customWhatsThis() returns FALSE,
+ which means the widget will not receive any events in Whats This
+ mode.
+
+ The widget may leave What's This mode by calling
+ TQWhatsThis::leaveWhatsThisMode(), with or without actually
+ displaying any help text.
+
+ You can also reimplement customWhatsThis() if your widget is a
+ "passive interactor" supposed to work under all circumstances.
+ Simply don't call TQWhatsThis::leaveWhatsThisMode() in that case.
+
+ \sa TQWhatsThis::inWhatsThisMode() TQWhatsThis::leaveWhatsThisMode()
+*/
+bool TQWidget::customWhatsThis() const
+{
+ return FALSE;
+}
+
+/*!
+ Returns the visible child widget at pixel position \a (x, y) in
+ the widget's own coordinate system.
+
+ If \a includeThis is TRUE, and there is no child visible at \a (x,
+ y), the widget itself is returned.
+*/
+TQWidget *TQWidget::tqchildAt( int x, int y, bool includeThis ) const
+{
+ if ( !rect().tqcontains( x, y ) )
+ return 0;
+ if ( childrenListObject() ) {
+ TQObjectListIt it( *childrenListObject() );
+ it.toLast();
+ TQWidget *w, *t;
+ while( (w=(TQWidget *)it.current()) != 0 ) {
+ --it;
+ if ( w->isWidgetType() && !w->isTopLevel() && !w->isHidden() ) {
+ if ( ( t = w->tqchildAt( x - w->x(), y - w->y(), TRUE ) ) )
+ return t;
+ }
+ }
+ }
+ if ( includeThis )
+ return (TQWidget*)this;
+ return 0;
+}
+
+/*!
+ \overload
+
+ Returns the visible child widget at point \a p in the widget's own
+ coordinate system.
+
+ If \a includeThis is TRUE, and there is no child visible at \a p,
+ the widget itself is returned.
+
+*/
+TQWidget *TQWidget::tqchildAt( const TQPoint & p, bool includeThis ) const
+{
+ return tqchildAt( p.x(), p.y(), includeThis );
+}
+
+
+/*!
+ Notifies the tqlayout system that this widget has changed and may
+ need to change tqgeometry.
+
+ Call this function if the tqsizeHint() or sizePolicy() have changed.
+
+ For explicitly hidden widgets, updateGeometry() is a no-op. The
+ tqlayout system will be notified as soon as the widget is shown.
+*/
+
+void TQWidget::updateGeometry()
+{
+ if ( !isTopLevel() && isShown() )
+ TQApplication::postEvent( parentWidget(),
+ new TQEvent( TQEvent::LayoutHint ) );
+}
+
+
+/*!
+ Reparents the widget. The widget gets a new \a tqparent, new widget
+ flags (\a f, but as usual, use 0) at a new position in its new
+ tqparent (\a p).
+
+ If \a showIt is TRUE, show() is called once the widget has been
+ reparented.
+
+ If the new tqparent widget is in a different top-level widget, the
+ reparented widget and its tqchildren are appended to the end of the
+ \link setFocusPolicy() tab chain \endlink of the new tqparent
+ widget, in the same internal order as before. If one of the moved
+ widgets had keyboard focus, reparent() calls clearFocus() for that
+ widget.
+
+ If the new tqparent widget is in the same top-level widget as the
+ old tqparent, reparent doesn't change the tab order or keyboard
+ focus.
+
+ \warning It is extremely unlikely that you will ever need this
+ function. If you have a widget that changes its content
+ dynamically, it is far easier to use \l TQWidgetStack or \l
+ TQWizard.
+
+ \sa getWFlags()
+*/
+
+void TQWidget::reparent( TQWidget *tqparent, WFlags f, const TQPoint &p,
+ bool showIt )
+{
+ reparentSys( tqparent, f, p, showIt );
+ TQEvent e( TQEvent::Retqparent );
+ TQApplication::sendEvent( this, &e );
+ if (!own_font)
+ unsetFont();
+ else
+ setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
+#ifndef TQT_NO_PALETTE
+ if (!own_palette)
+ unsetPalette();
+#endif
+}
+
+/*!
+ \overload
+
+ A convenience version of reparent that does not take widget flags
+ as argument.
+
+ Calls reparent(\a tqparent, getWFlags() \& ~\l WType_Mask, \a p, \a
+ showIt).
+*/
+void TQWidget::reparent( TQWidget *tqparent, const TQPoint & p,
+ bool showIt )
+{
+ reparent( tqparent, getWFlags() & ~WType_Mask, p, showIt );
+}
+
+/*!
+ \property TQWidget::ownCursor
+ \brief whether the widget uses its own cursor
+
+ If FALSE, the widget uses its tqparent widget's cursor.
+
+ \sa cursor
+*/
+
+/*!
+ \property TQWidget::ownFont
+ \brief whether the widget uses its own font
+
+ If FALSE, the widget uses its tqparent widget's font.
+
+ \sa font
+*/
+
+/*!
+ \property TQWidget::ownPalette
+ \brief whether the widget uses its own palette
+
+ If FALSE, the widget uses its tqparent widget's palette.
+
+ \sa palette
+*/
+
+
+void TQWidget::tqrepaint( bool erase )
+{
+ tqrepaint( visibleRect(), erase );
+}
+
+
+
+
+/*!\obsolete Use paletteBackgroundColor() or eraseColor() instead. */
+const TQColor & TQWidget::backgroundColor() const { return eraseColor(); }
+/*!\obsolete Use setPaletteBackgroundColor() or setEraseColor() instead. */
+void TQWidget::setBackgroundColor( const TQColor &c ) { setEraseColor( c ); }
+/*!\obsolete Use paletteBackgroundPixmap() or erasePixmap() instead. */
+const TQPixmap *TQWidget::backgroundPixmap() const { return erasePixmap(); }
+/*!\obsolete Use setPaletteBackgroundPixmap() or setErasePixmap() instead. */
+void TQWidget::setBackgroundPixmap( const TQPixmap &pm ) { setErasePixmap( pm ); }
+
+
+// documentation in qdesktopwidget_win.cpp
+void TQDesktopWidget::insertChild( TQObject *obj )
+{
+ if ( obj->isWidgetType() )
+ return;
+ TQWidget::insertChild( obj );
+}
+
+/*!
+ \property TQWidget::windowOpacity
+
+ \brief The level of opacity for the window.
+
+ The valid range of opacity is from 1.0 (completely opaque) to
+ 0.0 (completely transtqparent).
+
+ By default the value of this property is 1.0.
+
+ This feature is only present on Mac OS X and Windows 2000 and up.
+
+ \warning Changing this property from opaque to transtqparent might issue a
+ paint event that needs to be processed before the window is displayed
+ correctly. This affects mainly the use of TQPixmap::grabWindow(). Also note
+ that semi-transtqparent windows update and resize significantely slower than
+ opaque windows.
+*/
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqwidget.h b/tqtinterface/qt4/src/kernel/tqwidget.h
new file mode 100644
index 0000000..c027464
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwidget.h
@@ -0,0 +1,1547 @@
+/****************************************************************************
+**
+** Definition of TQWidget class
+**
+** Created : 931029
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWIDGET_H
+#define TQWIDGET_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqobject.h"
+#include "tqpaintdevice.h"
+#include "tqpalette.h"
+#include "tqfont.h"
+#include "tqfontmetrics.h"
+#include "tqfontinfo.h"
+#include "tqsizepolicy.h"
+#include "tqbitmap.h"
+#endif // TQT_H
+
+#ifdef USE_QT4
+#ifndef TQFONTENGINE_P_H
+
+#include <Qt/qwidget.h>
+#include <private/qt4_qwidget_p.h>
+
+#endif // TQFONTENGINE_P_H
+#endif // USE_QT4
+
+class TQLayout;
+
+#ifdef USE_QT4
+
+// FIXME
+// Neither TQTLWExtra nor TQWExtra are fully Qt4 compatible!
+
+class TQFocusData;
+
+// typedef struct QTLWExtra TQTLWExtra;
+
+struct TQTLWExtra : public QTLWExtra, virtual public TQt
+{
+ TQFocusData *focusData; // focus data (for TLW)
+ ulong fleft, fright, ftop, fbottom;
+ uint uspos : 1; // User defined position
+ uint ussize : 1; // User defined size
+
+#if defined(TQ_WS_X11)
+ WId parentWinId; // tqparent window Id (valid after reparenting)
+#endif
+};
+
+// typedef struct QWExtra TQWExtra;
+
+struct TQWExtra : public QWExtra, virtual public TQt
+{
+ TQRect micro_focus_hint; // micro focus hint
+ TQPixmap *bg_pix; // background pixmap
+ char bg_mode; // background mode
+ char bg_mode_visual; // visual background mode
+ uint bg_origin : 2;
+ TQSizePolicy size_policy;
+ TQTLWExtra *topextra; // only useful for TLWs // WARNING: This is overriding the Qt4 builtin topextra with unknown consequences.....
+};
+
+#else // USE_QT4
+
+struct TQWExtra;
+struct TQTLWExtra;
+
+#endif // USE_QT4
+
+class TQFocusData;
+class TQCursor;
+class TQWSRegionManager;
+class TQStyle;
+
+#ifdef USE_QT4
+
+#include <Qt/qx11info_x11.h>
+#include <private/qt4_qwidget_p.h>
+
+typedef unsigned long long WFlags;
+typedef QFlags<Qt::WindowState> WState;
+
+// #define WType_Desktop Qt::Desktop
+//
+// #define Key_Escape Qt::Key_Escape
+// #define ShiftButton Qt::ShiftModifier
+// #define ControlButton Qt::ControlModifier
+//
+// #define WStyle_Customize 0
+// #define WType_Popup Qt::Popup
+// #define WX11BypassWM Qt::X11BypassWindowManagerHint
+
+// #define TQWIDGETSIZE_MAX 32767
+#define TQWIDGETSIZE_MAX QWIDGETSIZE_MAX
+
+#define TQT_TQWIDGET_INDEPENDENT_REQUIRED_INITIALIZATION \
+ setAttribute(Qt::WA_PaintOutsidePaintEvent, TRUE); \
+ setAutoFillBackground(true);
+
+#define TQT_TQWIDGET_REQUIRED_INITIALIZATION \
+ extra = 0; \
+ tqt_internal_ignore_next_windowstatechange_event = FALSE; \
+ tqt_internal_show_called_event = FALSE; \
+ if (testWFlags(WType_Popup) && testWFlags(WType_Dialog)) \
+ clearWFlags((WType_Dialog & (~WType_TopLevel))); \
+ TQT_TQWIDGET_INDEPENDENT_REQUIRED_INITIALIZATION \
+ setDefaultWidgetFlags(); \
+ processUpperWidgetFlags();
+
+#define TQT_TQWIDGET_FIX_BROKEN_POPUP_MOUSE_FOCUS \
+ bool new_receiver_found = FALSE; \
+ QWidget *popup = qApp->activePopupWidget(); \
+ QWidget *newreceiver = this; \
+ QPoint gpos = mapToGlobal(e->pos()); \
+ QPoint npos = newreceiver->mapFromGlobal(gpos); \
+ if (popup) { \
+ while (!TQT_TQRECT_OBJECT(newreceiver->rect()).tqcontains(npos)) { \
+ new_receiver_found = TRUE; \
+ newreceiver = tqwidget_parent_popup_menu(newreceiver); \
+ if (newreceiver) { \
+ npos = newreceiver->mapFromGlobal(gpos); \
+ } \
+ else { \
+ break; \
+ } \
+ } \
+ if ((newreceiver) && (new_receiver_found)) { \
+ if (TQT_TQRECT_OBJECT(newreceiver->rect()).tqcontains(npos)) { \
+ if (tqwidget_is_popup_menu(newreceiver)) { \
+ npos = newreceiver->mapFromGlobal(gpos); \
+ QMouseEvent fixedevent(e->type(), npos, e->globalPos(), e->button(), e->buttons(), e->modifiers()); \
+ QApplication::sendEvent(newreceiver, &fixedevent); \
+ e->accept(); \
+ } \
+ } \
+ } \
+ } \
+ if (!((newreceiver) && (new_receiver_found)))
+
+extern bool tqwidget_is_popup_menu(QWidget*);
+extern QWidget* tqwidget_parent_popup_menu(QWidget*);
+
+// class TQ_EXPORT TQWidget : public TQObject, public QWidget
+class TQ_EXPORT TQWidget : public QWidget, virtual public TQt
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TQObject *tqparent() const;
+ TQObjectList childrenListObject();
+ const TQObjectList childrenListObject() const;
+
+public:
+// enum FocusPolicy {
+// NoFocus = 0,
+// TabFocus = 0x1,
+// ClickFocus = 0x2,
+// StrongFocus = TabFocus | ClickFocus | 0x8,
+// WheelFocus = StrongFocus | 0x4
+// };
+
+ enum BackgroundOrigin { WidgetOrigin, ParentOrigin, WindowOrigin, AncestorOrigin };
+
+// TQWidget methods
+public:
+ TQWidget( QWidget* tqparent=0, const char* name=0, WFlags f=0 );
+
+ void setWState( uint state );
+ void clearWState( uint flags );
+ WState getWState() const;
+ WState testWState( WState s ) const;
+ WState testWState( TQt::WidgetState s ) const;
+
+ void setWFlags( WFlags flags );
+ void clearWFlags( WFlags flags );
+ WFlags getWFlags() const;
+ WFlags testWFlags( WFlags f ) const;
+
+ uint windowState() const;
+ void setWindowState(uint windowState);
+
+ void setActiveWindow( void );
+ Display * x11Display( void );
+ int x11Depth() const;
+ int x11Screen( void );
+ TQWidget * parentWidget( bool sameWindow = FALSE ) const;
+ static TQCString normalizeSignalSlot( const char *signalSlot );
+ TQMetaObject *tqmetaObject() const;
+ static TQWidget * tqfind( WId w );
+ bool isShown() const;
+ TQWidget *tqchildAt( int x, int y, bool includeThis = FALSE ) const;
+ TQWidget *tqchildAt( const TQPoint &p, bool includeThis = FALSE ) const;
+ TQWidget *tqtopLevelWidget() const;
+ bool isA(const char *classname) const;
+ bool inherits( const char * ) const;
+// virtual bool close( bool alsoDelete ) { TQ_UNUSED(alsoDelete); return QWidget::close(); }
+// TQWExtra *extraData() { return TQT_TQWEXTRA(qt_widget_private(this)->extraData()); }
+ TQWExtra *extraData();
+// TQTLWExtra *topData() { return qt_widget_private(this)->topData(); }
+ TQTLWExtra *topData();
+ void setName(const char *aName);
+ TQWidget *parentWidget( bool sameWindow = FALSE );
+ bool isDialog() const;
+ TQObject *child( const char *objName, const char *inheritsClass = 0, bool recursiveSearch = TRUE );
+ const TQRect tqgeometry() const;
+ TQLayout *tqlayout() const;
+ virtual TQSize tqsizeHint() const;
+ virtual TQSize tqminimumSizeHint() const;
+ virtual QSize sizeHint() const;
+ virtual QSize minimumSizeHint() const;
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+ TQColorGroup tqcolorGroup() const;
+ TQStyle &tqstyle() const;
+ void reparent(QWidget *parent, WFlags f, const QPoint &p, bool showIt=false);
+ void reparent(QWidget *parent, const QPoint &p, bool showIt=false);
+ void iconify();
+ void constPolish() const;
+ bool hasMouse() const;
+#ifndef QT_NO_CURSOR
+ bool ownCursor() const;
+#endif
+ bool ownFont() const;
+ void setBackgroundPixmap(const QPixmap &pm);
+ virtual void tqsetBackgroundPixmap(const QPixmap &pm);
+ const TQPixmap *backgroundPixmap() const;
+ void tqsetSizePolicy(QSizePolicy qsp);
+ void tqsetSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical);
+ void tqsetSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw);
+ void setInputMethodEnabled(bool b);
+ bool isInputMethodEnabled() const;
+ bool isPopup() const;
+ TQString caption() const;
+ void setCaption(const QString &c);
+ TQRect tqchildrenRect() const;
+ TQRegion tqchildrenRegion() const;
+ void unsetFont();
+ bool ownPalette() const;
+ void unsetPalette();
+ const TQPalette &tqpalette() const;
+ bool isUpdatesEnabled() const;
+ void tqrepaint(int x, int y, int w, int h);
+ void tqrepaint(const QRect &r);
+ void tqrepaint(const QRegion &r);
+ void tqrepaint(bool eraseme);
+ void tqrepaint(int x, int y, int w, int h, bool);
+ void tqrepaint(const QRect &r, bool);
+ void tqrepaint(const QRegion &rgn, bool);
+ TQSizePolicy tqsizePolicy() const;
+ TQPoint backgroundOffset() const;
+ bool tqsignalsBlocked() const;
+ TQObjectList *queryList( const char *inheritsClass = 0, const char *objName = 0, bool regexpMatch = TRUE, bool recursiveSearch = TRUE ) const;
+ TQWidget *tqfocusWidget() const;
+ void setBackgroundOrigin(BackgroundOrigin);
+ BackgroundOrigin backgroundOrigin() const;
+ void setIconText(const QString &it);
+ void insertChild( TQObject *object );
+ void removeChild( TQObject *object );
+
+ bool close();
+ bool close(bool alsoDelete);
+
+ void setFocus(Qt::FocusReason reason);
+ void setFocus(TQFocusEvent::Reason reason);
+
+ TQt::BackgroundMode backgroundMode() const;
+ /*virtual*/ void setBackgroundMode( TQt::BackgroundMode tqbm );
+ void setBackgroundMode(TQt::BackgroundMode, TQt::BackgroundMode);
+ const QColor &paletteForegroundColor() const;
+ void setPaletteForegroundColor(const QColor &c);
+ const QColor &paletteBackgroundColor() const;
+ /*virtual*/ void setPaletteBackgroundColor(const QColor &c);
+ const TQPixmap *paletteBackgroundPixmap() const;
+ /*virtual*/ void setPaletteBackgroundPixmap(const QPixmap &pm);
+ const TQColor &backgroundColor() const;
+ /*virtual*/ void setBackgroundColor(const QColor &c);
+ const TQColor &eraseColor() const;
+ /*virtual*/ void setEraseColor(const QColor &c);
+ const TQPixmap *erasePixmap() const;
+ /*virtual*/ void setErasePixmap(const QPixmap &pm);
+ const TQColor &foregroundColor() const;
+
+ virtual void setAutoMask(bool);
+ bool autoMask() const;
+ virtual void updateMask();
+
+ void erase();
+ void erase(int x, int y, int w, int h);
+ void erase(const QRect &r);
+ void erase(const QRegion &r);
+
+ void drawText( int x, int y, const TQString &);
+ void drawText( const TQPoint &, const TQString &);
+
+ const TQBrush& backgroundBrush() const;
+ void setIcon(const QPixmap &i);
+ const TQPixmap *icon() const;
+ const TQPixmap iconPixmap() const;
+
+ const char *tqname() const;
+ const char *name() const;
+ const char *name(const char *defaultName) const;
+
+ bool isVisibleToTLW() const; // obsolete
+ static TQWidget* tqt_ensure_valid_widget_painting(TQWidget* w);
+
+ void setMask( const QBitmap );
+ void setMask( const QRegion );
+
+#ifndef TQT_NO_STYLE
+ void setStyle( TQStyle * );
+ TQStyle* setStyle( const TQString& );
+#endif
+
+#ifndef TQT_NO_PALETTE
+ void tqsetPalette( const TQPalette &p, bool );
+#endif
+
+// static TQWidgetMapper *wmapper( void ) { return QWidgetPrivate::mapper; }
+
+// TQWExtra *extraData();
+// TQTLWExtra *topData();
+// TQFocusData *focusData();
+
+ bool isDesktop() const;
+
+ void createTLSysExtra( void );
+ void destroyInputContext( void );
+
+ void createExtra();
+ void deleteExtra();
+
+ bool isFocusEnabled() const;
+
+// TQRect tqeffectiveRectFor(const QRect &rect);
+ TQRect tqclipRect() const;
+ TQRect visibleRect() const;
+ TQRegion clipRegion() const;
+
+ virtual bool customWhatsThis() const;
+
+ virtual void setKeyCompression(bool);
+ TQRect microFocusHint() const;
+ virtual void setMicroFocusHint(int x, int y, int w, int h, bool text=TRUE, TQFont *f = 0);
+
+// // Interoperability
+// TQWidget* operator= (QWidget* a)
+// {
+// return static_cast<TQWidget*>(a);
+// }
+
+ operator TQObject*() const { return TQT_TQOBJECT(const_cast<TQWidget*>(this)); } // This implicit pointer converter doesn't work for some reason
+
+public:
+ // TQt handler
+ virtual bool eventFilter( TQObject *, TQEvent * );
+
+ // Qt4 handler interface
+ virtual bool eventFilter( QObject *q, QEvent *e );
+ bool event( QEvent *e );
+
+protected:
+ inline bool checkConnectArgs(const char *signal, const TQT_BASE_OBJECT_NAME *name, const char *member) { return TQT_TQOBJECT(this)->checkConnectArgs(signal, name, member); }
+
+// TQt event handlers
+protected:
+ TQFocusData *focusData();
+// virtual bool event( QEvent *e ); // NOTE: All event handlers that can be subclassed must be declared here, and
+ // declared virtual, so that run time dynamic call resolution will occur
+ virtual bool event( TQEvent *e );
+ virtual void mousePressEvent( TQMouseEvent * );
+ virtual void mouseReleaseEvent( TQMouseEvent * );
+ virtual void mouseDoubleClickEvent( TQMouseEvent * );
+ virtual void mouseMoveEvent( TQMouseEvent * );
+#ifndef TQT_NO_WHEELEVENT
+ virtual void wheelEvent( TQWheelEvent * );
+#endif
+ virtual void keyPressEvent( TQKeyEvent * );
+ virtual void keyReleaseEvent( TQKeyEvent * );
+ virtual void focusInEvent( TQFocusEvent * );
+ virtual void focusOutEvent( TQFocusEvent * );
+ virtual void enterEvent( TQEvent * );
+ virtual void leaveEvent( TQEvent * );
+ virtual void paintEvent( TQPaintEvent * );
+ virtual void moveEvent( TQMoveEvent * );
+ virtual void resizeEvent( TQResizeEvent * );
+ virtual void closeEvent( TQCloseEvent * );
+ virtual void contextMenuEvent( TQContextMenuEvent * );
+ virtual void imStartEvent( TQIMEvent * );
+ virtual void imComposeEvent( TQIMEvent * );
+ virtual void imEndEvent( TQIMEvent * );
+ virtual void tabletEvent( TQTabletEvent * );
+
+#ifndef TQT_NO_DRAGANDDROP
+ virtual void dragEnterEvent( TQDragEnterEvent * );
+ virtual void dragMoveEvent( TQDragMoveEvent * );
+ virtual void dragLeaveEvent( TQDragLeaveEvent * );
+ virtual void dropEvent( TQDropEvent * );
+#endif
+
+ virtual void showEvent( TQShowEvent * );
+ virtual void hideEvent( TQHideEvent * );
+
+#if defined(TQ_WS_MAC)
+ virtual bool macEvent( MSG * );
+#endif
+#if defined(TQ_WS_WIN)
+ virtual bool winEvent( MSG * );
+#endif
+#if defined(TQ_WS_X11)
+ virtual bool x11Event( XEvent * );
+#endif
+#if defined(TQ_WS_TQWS)
+ virtual bool qwsEvent( TQWSEvent * );
+#endif
+
+// Qt4 event handler interface
+protected:
+ virtual void mousePressEvent(QMouseEvent *e);
+ virtual void mouseReleaseEvent(QMouseEvent *e);
+ virtual void mouseDoubleClickEvent(QMouseEvent *e);
+ virtual void mouseMoveEvent(QMouseEvent *e);
+#ifndef QT_NO_WHEELEVENT
+ virtual void wheelEvent(QWheelEvent *e);
+#endif
+ virtual void keyPressEvent(QKeyEvent *e);
+ virtual void keyReleaseEvent(QKeyEvent *e);
+ virtual void focusInEvent(QFocusEvent *e);
+ virtual void focusOutEvent(QFocusEvent *e);
+ virtual void enterEvent(QEvent *e);
+ virtual void leaveEvent(QEvent *e);
+ virtual void paintEvent(QPaintEvent *e);
+ virtual void moveEvent(QMoveEvent *e);
+ virtual void resizeEvent(QResizeEvent *e);
+ virtual void closeEvent(QCloseEvent *e);
+#ifndef QT_NO_CONTEXTMENU
+ virtual void contextMenuEvent(QContextMenuEvent *e);
+#endif
+#ifndef QT_NO_TABLETEVENT
+ virtual void tabletEvent(QTabletEvent *e);
+#endif
+#ifndef QT_NO_ACTION
+// inline virtual void actionEvent(QActionEvent *e) { actionEvent(static_cast<TQActionEvent*>(e)); }
+#endif
+
+// #ifndef QT_NO_DRAGANDDROP
+// inline virtual void dragEnterEvent(QDragEnterEvent *e) { dragEnterEvent(static_cast<TQDragEnterEvent*>(e)); }
+// inline virtual void dragMoveEvent(QDragMoveEvent *e) { dragMoveEvent(static_cast<TQDragMoveEvent*>(e)); }
+// inline virtual void dragLeaveEvent(QDragLeaveEvent *e) { dragLeaveEvent(static_cast<TQDragLeaveEvent*>(e)); }
+// inline virtual void dropEvent(QDropEvent *e) { dropEvent(static_cast<TQDropEvent*>(e)); }
+// #endif
+
+ virtual void showEvent(QShowEvent *e);
+ virtual void hideEvent(QHideEvent *e);
+
+// #if defined(Q_WS_MAC)
+// inline virtual bool macEvent(EventHandlerCallRef e, EventRef r);
+// #endif
+// #if defined(Q_WS_WIN)
+// inline virtual bool winEvent(MSG *message, long *result);
+// #endif
+// #if defined(Q_WS_X11)
+// inline virtual bool x11Event(XEvent *e)
+// #endif
+// #if defined(Q_WS_QWS)
+// inline virtual bool qwsEvent(QWSEvent *e);
+// #endif
+
+// TQt event handlers
+protected:
+ virtual void timerEvent( TQTimerEvent * );
+ virtual void childEvent( TQChildEvent * );
+ virtual void customEvent( TQCustomEvent * );
+
+// Qt4 event handler interface
+protected:
+ virtual void timerEvent(QTimerEvent *e);
+ virtual void childEvent(QChildEvent *e);
+ virtual void customEvent(QEvent *e);
+
+private:
+ mutable TQStyle* tqt_internal_stylePointer;
+ void erase_helper(int x, int y, int w, int h);
+ TQWExtra *extra;
+ TQFocusData *focusData( bool create );
+ void createTLExtra();
+ bool tqt_internal_show_called_event;
+ mutable bool tqt_internal_ignore_next_windowstatechange_event;
+ mutable TQString static_object_name;
+
+ void showWindow();
+ void hideWindow();
+
+ WFlags TQtUpperWidgetFlags;
+ void processUpperWidgetFlags();
+ void setDefaultWidgetFlags();
+
+ friend class TQObject;
+
+public Q_SLOTS:
+ virtual void tqsetUpdatesEnabled( bool enable );
+ void tqrepaint();
+ virtual void setFocus();
+ virtual void show();
+ virtual void adjustSize();
+// inline virtual void adjustSize() {
+// QApplication::sendPostedEvents( 0, TQEvent::ChildInserted );
+// QWidget::adjustSize();
+// }
+ virtual void polish();
+// inline virtual void setGeometry( int x, int y, int w, int h ) { return QWidget::setGeometry(x, y, w, h); }
+// inline virtual void setGeometry( const TQRect &r ) { return QWidget::setGeometry(r); }
+
+// protected:
+ TQConnectionList *tqreceivers( const char* signal ) const;
+ TQConnectionList *tqreceivers( int signal ) const;
+//
+ void activate_signal( int signal );
+// void activate_signal( int signal, int second ) { TQT_TQOBJECT(this)->activate_signal(signal, second); }
+// void activate_signal( int signal, double second ) { TQT_TQOBJECT(this)->activate_signal(signal, second); }
+// void activate_signal( int signal, TQString second ) { TQT_TQOBJECT(this)->activate_signal(signal, second); }
+// void activate_signal_bool( int signal, bool second ) { TQT_TQOBJECT(this)->activate_signal(signal, second); }
+ void activate_signal( TQConnectionList *clist, TQUObject *o );
+
+ void tqt_handle_qt_destroyed(QObject* obj);
+
+Q_SIGNALS:
+ void destroyed( TQObject* obj );
+};
+
+inline void TQWidget::drawText( const TQPoint &p, const TQString &s )
+{ drawText( p.x(), p.y(), s ); }
+
+#else // USE_QT4
+
+class TQ_EXPORT TQWidget : public TQObject, public TQPaintDevice
+{
+ TQ_OBJECT
+ TQ_ENUMS( BackgroundMode FocusPolicy BackgroundOrigin )
+ Q_PROPERTY( bool isTopLevel READ isTopLevel )
+ Q_PROPERTY( bool isDialog READ isDialog )
+ Q_PROPERTY( bool isModal READ isModal )
+ Q_PROPERTY( bool isPopup READ isPopup )
+ Q_PROPERTY( bool isDesktop READ isDesktop )
+ Q_PROPERTY( bool enabled READ isEnabled WRITE setEnabled )
+ Q_PROPERTY( TQRect tqgeometry READ tqgeometry WRITE setGeometry )
+ Q_PROPERTY( TQRect frameGeometry READ frameGeometry )
+ Q_PROPERTY( int x READ x )
+ Q_PROPERTY( int y READ y )
+ Q_PROPERTY( TQPoint pos READ pos WRITE move DESIGNABLE false STORED false )
+ Q_PROPERTY( TQSize frameSize READ frameSize )
+ Q_PROPERTY( TQSize size READ size WRITE resize DESIGNABLE false STORED false )
+ Q_PROPERTY( int width READ width )
+ Q_PROPERTY( int height READ height )
+ Q_PROPERTY( TQRect rect READ rect )
+ Q_PROPERTY( TQRect tqchildrenRect READ tqchildrenRect )
+ Q_PROPERTY( TQRegion tqchildrenRegion READ tqchildrenRegion )
+ Q_PROPERTY( TQSizePolicy sizePolicy READ sizePolicy WRITE tqsetSizePolicy )
+ Q_PROPERTY( TQSize tqminimumSize READ tqminimumSize WRITE setMinimumSize )
+ Q_PROPERTY( TQSize tqmaximumSize READ tqmaximumSize WRITE setMaximumSize )
+ Q_PROPERTY( int minimumWidth READ minimumWidth WRITE setMinimumWidth STORED false DESIGNABLE false )
+ Q_PROPERTY( int minimumHeight READ minimumHeight WRITE setMinimumHeight STORED false DESIGNABLE false )
+ Q_PROPERTY( int maximumWidth READ maximumWidth WRITE setMaximumWidth STORED false DESIGNABLE false )
+ Q_PROPERTY( int maximumHeight READ maximumHeight WRITE setMaximumHeight STORED false DESIGNABLE false )
+ Q_PROPERTY( TQSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement )
+ Q_PROPERTY( TQSize baseSize READ baseSize WRITE setBaseSize )
+ Q_PROPERTY( BackgroundMode backgroundMode READ backgroundMode WRITE setBackgroundMode DESIGNABLE false )
+ Q_PROPERTY( TQColor paletteForegroundColor READ paletteForegroundColor WRITE setPaletteForegroundColor RESET unsetPalette )
+ Q_PROPERTY( TQColor paletteBackgroundColor READ paletteBackgroundColor WRITE setPaletteBackgroundColor RESET unsetPalette )
+ Q_PROPERTY( TQPixmap paletteBackgroundPixmap READ paletteBackgroundPixmap WRITE setPaletteBackgroundPixmap RESET unsetPalette )
+ Q_PROPERTY( TQBrush backgroundBrush READ backgroundBrush )
+ Q_PROPERTY( TQColorGroup tqcolorGroup READ tqcolorGroup )
+ Q_PROPERTY( TQPalette palette READ palette WRITE setPalette RESET unsetPalette STORED ownPalette )
+ Q_PROPERTY( BackgroundOrigin backgroundOrigin READ backgroundOrigin WRITE setBackgroundOrigin )
+ Q_PROPERTY( bool ownPalette READ ownPalette )
+ Q_PROPERTY( TQFont font READ font WRITE setFont RESET unsetFont STORED ownFont )
+ Q_PROPERTY( bool ownFont READ ownFont )
+#ifndef TQT_NO_CURSOR
+ Q_PROPERTY( TQCursor cursor READ cursor WRITE setCursor RESET unsetCursor STORED ownCursor )
+ Q_PROPERTY( bool ownCursor READ ownCursor )
+#endif
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ Q_PROPERTY( TQString caption READ caption WRITE setCaption )
+ Q_PROPERTY( TQPixmap icon READ icon WRITE setIcon )
+ Q_PROPERTY( TQString iconText READ iconText WRITE setIconText )
+#endif
+ Q_PROPERTY( bool mouseTracking READ hasMouseTracking WRITE setMouseTracking )
+ Q_PROPERTY( bool underMouse READ hasMouse )
+ Q_PROPERTY( bool isActiveWindow READ isActiveWindow )
+ Q_PROPERTY( bool focusEnabled READ isFocusEnabled )
+ Q_PROPERTY( FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy )
+ Q_PROPERTY( bool focus READ hasFocus )
+ Q_PROPERTY( bool updatesEnabled READ isUpdatesEnabled WRITE setUpdatesEnabled DESIGNABLE false )
+ Q_PROPERTY( bool visible READ isVisible )
+ Q_PROPERTY( TQRect visibleRect READ visibleRect ) // obsolete
+ Q_PROPERTY( bool hidden READ isHidden WRITE setHidden DESIGNABLE false SCRIPTABLE false )
+ Q_PROPERTY( bool shown READ isShown WRITE setShown DESIGNABLE false SCRIPTABLE false )
+ Q_PROPERTY( bool minimized READ isMinimized )
+ Q_PROPERTY( bool maximized READ isMaximized )
+ Q_PROPERTY( bool fullScreen READ isFullScreen )
+ Q_PROPERTY( TQSize tqsizeHint READ tqsizeHint )
+ Q_PROPERTY( TQSize tqminimumSizeHint READ tqminimumSizeHint )
+ Q_PROPERTY( TQRect microFocusHint READ microFocusHint )
+ Q_PROPERTY( bool acceptDrops READ acceptDrops WRITE setAcceptDrops )
+ Q_PROPERTY( bool autoMask READ autoMask WRITE setAutoMask DESIGNABLE false SCRIPTABLE false )
+ Q_PROPERTY( bool customWhatsThis READ customWhatsThis )
+ Q_PROPERTY( bool inputMethodEnabled READ isInputMethodEnabled WRITE setInputMethodEnabled DESIGNABLE false SCRIPTABLE false )
+ Q_PROPERTY( double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE false )
+
+public:
+ TQ_EXPLICIT TQWidget( TQWidget* tqparent=0, const char* name=0, WFlags f=0 );
+ ~TQWidget();
+
+ WId winId() const;
+ void setName( const char *name );
+#ifndef TQT_NO_STYLE
+ // GUI style setting
+
+ TQStyle &style() const;
+ void setStyle( TQStyle * );
+ TQStyle* setStyle( const TQString& );
+#endif
+ // Widget types and states
+
+ bool isTopLevel() const;
+ bool isDialog() const;
+ bool isPopup() const;
+ bool isDesktop() const;
+ bool isModal() const;
+
+ bool isEnabled() const;
+ bool isEnabledTo(TQWidget*) const;
+ bool isEnabledToTLW() const;
+
+public Q_SLOTS:
+ virtual void setEnabled( bool );
+ void setDisabled( bool );
+
+ // Widget coordinates
+
+public:
+ TQRect frameGeometry() const;
+ const TQRect &tqgeometry() const;
+ int x() const;
+ int y() const;
+ TQPoint pos() const;
+ TQSize frameSize() const;
+ TQSize size() const;
+ int width() const;
+ int height() const;
+ TQRect rect() const;
+ TQRect tqchildrenRect() const;
+ TQRegion tqchildrenRegion() const;
+
+ TQSize tqminimumSize() const;
+ TQSize tqmaximumSize() const;
+ int minimumWidth() const;
+ int minimumHeight() const;
+ int maximumWidth() const;
+ int maximumHeight() const;
+ void setMinimumSize( const TQSize & );
+ virtual void setMinimumSize( int minw, int minh );
+ void setMaximumSize( const TQSize & );
+ virtual void setMaximumSize( int maxw, int maxh );
+ void setMinimumWidth( int minw );
+ void setMinimumHeight( int minh );
+ void setMaximumWidth( int maxw );
+ void setMaximumHeight( int maxh );
+
+ TQSize sizeIncrement() const;
+ void setSizeIncrement( const TQSize & );
+ virtual void setSizeIncrement( int w, int h );
+ TQSize baseSize() const;
+ void setBaseSize( const TQSize & );
+ void setBaseSize( int basew, int baseh );
+
+ void setFixedSize( const TQSize & );
+ void setFixedSize( int w, int h );
+ void setFixedWidth( int w );
+ void setFixedHeight( int h );
+
+ // Widget coordinate mapping
+
+ TQPoint mapToGlobal( const TQPoint & ) const;
+ TQPoint mapFromGlobal( const TQPoint & ) const;
+ TQPoint mapToParent( const TQPoint & ) const;
+ TQPoint mapFromParent( const TQPoint & ) const;
+ TQPoint mapTo( TQWidget *, const TQPoint & ) const;
+ TQPoint mapFrom( TQWidget *, const TQPoint & ) const;
+
+ TQWidget *tqtopLevelWidget() const;
+
+ // Widget attribute functions
+
+ BackgroundMode backgroundMode() const;
+ virtual void setBackgroundMode( BackgroundMode );
+ void setBackgroundMode( BackgroundMode, BackgroundMode );
+
+ const TQColor & foregroundColor() const;
+
+ const TQColor & eraseColor() const;
+ virtual void setEraseColor( const TQColor & );
+
+ const TQPixmap * erasePixmap() const;
+ virtual void setErasePixmap( const TQPixmap & );
+
+#ifndef TQT_NO_PALETTE
+ const TQColorGroup & tqcolorGroup() const;
+ const TQPalette & palette() const;
+ bool ownPalette() const;
+ virtual void setPalette( const TQPalette & );
+ void unsetPalette();
+#endif
+
+ const TQColor & paletteForegroundColor() const;
+ void setPaletteForegroundColor( const TQColor & );
+
+ const TQColor & paletteBackgroundColor() const;
+ virtual void setPaletteBackgroundColor( const TQColor & );
+
+ const TQPixmap * paletteBackgroundPixmap() const;
+ virtual void setPaletteBackgroundPixmap( const TQPixmap & );
+
+ const TQBrush& backgroundBrush() const;
+
+ TQFont font() const;
+ bool ownFont() const;
+ virtual void setFont( const TQFont & );
+ void unsetFont();
+ TQFontMetrics fontMetrics() const;
+ TQFontInfo fontInfo() const;
+
+#ifndef TQT_NO_CURSOR
+ const TQCursor &cursor() const;
+ bool ownCursor() const;
+ virtual void setCursor( const TQCursor & );
+ virtual void unsetCursor();
+#endif
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ TQString caption() const;
+ const TQPixmap *icon() const;
+ TQString iconText() const;
+#endif
+ bool hasMouseTracking() const;
+ bool hasMouse() const;
+
+ virtual void setMask( const TQBitmap & );
+ virtual void setMask( const TQRegion & );
+ void clearMask();
+
+ const TQColor & backgroundColor() const; // obsolete, use eraseColor()
+ virtual void setBackgroundColor( const TQColor & ); // obsolete, use setEraseColor()
+ const TQPixmap * backgroundPixmap() const; // obsolete, use erasePixmap()
+ virtual void setBackgroundPixmap( const TQPixmap & ); // obsolete, use setErasePixmap()
+
+public Q_SLOTS:
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ virtual void setCaption( const TQString &);
+ virtual void setIcon( const TQPixmap & );
+ virtual void setIconText( const TQString &);
+#endif
+ virtual void setMouseTracking( bool enable );
+
+ // Keyboard input focus functions
+
+ virtual void setFocus();
+ void clearFocus();
+
+public:
+ enum FocusPolicy {
+ NoFocus = 0,
+ TabFocus = 0x1,
+ ClickFocus = 0x2,
+ StrongFocus = TabFocus | ClickFocus | 0x8,
+ WheelFocus = StrongFocus | 0x4
+ };
+
+ bool isActiveWindow() const;
+ virtual void setActiveWindow();
+ bool isFocusEnabled() const;
+
+ FocusPolicy focusPolicy() const;
+ virtual void setFocusPolicy( FocusPolicy );
+ bool hasFocus() const;
+ static void setTabOrder( TQWidget *, TQWidget * );
+ virtual void setFocusProxy( TQWidget * );
+ TQWidget * focusProxy() const;
+
+ void setInputMethodEnabled( bool b );
+ bool isInputMethodEnabled() const;
+ // Grab functions
+
+ void grabMouse();
+#ifndef TQT_NO_CURSOR
+ void grabMouse( const TQCursor & );
+#endif
+ void releaseMouse();
+ void grabKeyboard();
+ void releaseKeyboard();
+ static TQWidget * mouseGrabber();
+ static TQWidget * keyboardGrabber();
+
+ // Update/refresh functions
+
+ bool isUpdatesEnabled() const;
+
+#if 0 //def TQ_WS_TQWS
+ void repaintUnclipped( const TQRegion &, bool erase = TRUE );
+#endif
+public Q_SLOTS:
+ virtual void setUpdatesEnabled( bool enable );
+ void update();
+ void update( int x, int y, int w, int h );
+ void update( const TQRect& );
+ void tqrepaint();
+ void tqrepaint( bool erase );
+ void tqrepaint( int x, int y, int w, int h, bool erase=TRUE );
+ void tqrepaint( const TQRect &, bool erase = TRUE );
+ void tqrepaint( const TQRegion &, bool erase = TRUE );
+
+ // Widget management functions
+
+ virtual void show();
+ virtual void hide();
+ void setShown( bool show );
+ void setHidden( bool hide );
+#ifndef TQT_NO_COMPAT
+ void iconify() { showMinimized(); }
+#endif
+ virtual void showMinimized();
+ virtual void showMaximized();
+ void showFullScreen();
+ virtual void showNormal();
+ virtual void polish();
+ void constPolish() const;
+ bool close();
+
+ void raise();
+ void lower();
+ void stackUnder( TQWidget* );
+ virtual void move( int x, int y );
+ void move( const TQPoint & );
+ virtual void resize( int w, int h );
+ void resize( const TQSize & );
+ virtual void setGeometry( int x, int y, int w, int h );
+ virtual void setGeometry( const TQRect & ); // ### make non virtual in TQt 4?
+
+public:
+ virtual bool close( bool alsoDelete );
+ bool isVisible() const;
+ bool isVisibleTo(TQWidget*) const;
+ bool isVisibleToTLW() const; // obsolete
+ TQRect visibleRect() const; // obsolete
+ bool isHidden() const;
+ bool isShown() const;
+ bool isMinimized() const;
+ bool isMaximized() const;
+ bool isFullScreen() const;
+
+ uint windowState() const;
+ void setWindowState(uint windowState);
+
+ virtual TQSize tqsizeHint() const;
+ virtual TQSize tqminimumSizeHint() const;
+ virtual TQSizePolicy sizePolicy() const;
+ virtual void tqsetSizePolicy( TQSizePolicy );
+ void tqsetSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw = FALSE );
+ virtual int heightForWidth(int) const;
+
+ TQRegion clipRegion() const;
+
+// ### move together with other Q_SLOTS in TQt 4.0
+public Q_SLOTS:
+ virtual void adjustSize();
+
+public:
+#ifndef TQT_NO_LAYOUT
+ TQLayout * tqlayout() const { return lay_out; }
+#endif
+ void updateGeometry();
+ virtual void reparent( TQWidget *tqparent, WFlags, const TQPoint &,
+ bool showIt=FALSE );
+ void reparent( TQWidget *tqparent, const TQPoint &,
+ bool showIt=FALSE );
+#ifndef TQT_NO_COMPAT
+ void recreate( TQWidget *tqparent, WFlags f, const TQPoint & p,
+ bool showIt=FALSE ) { reparent(tqparent,f,p,showIt); }
+#endif
+
+ void erase();
+ void erase( int x, int y, int w, int h );
+ void erase( const TQRect & );
+ void erase( const TQRegion & );
+ void scroll( int dx, int dy );
+ void scroll( int dx, int dy, const TQRect& );
+
+ void drawText( int x, int y, const TQString &);
+ void drawText( const TQPoint &, const TQString &);
+
+ // Misc. functions
+
+ TQWidget * tqfocusWidget() const;
+ TQRect microFocusHint() const;
+
+ // drag and drop
+
+ bool acceptDrops() const;
+ virtual void setAcceptDrops( bool on );
+
+ // transparency and pseudo transparency
+
+ virtual void setAutoMask(bool);
+ bool autoMask() const;
+
+ enum BackgroundOrigin { WidgetOrigin, ParentOrigin, WindowOrigin, AncestorOrigin };
+
+ virtual void setBackgroundOrigin( BackgroundOrigin );
+ BackgroundOrigin backgroundOrigin() const;
+ TQPoint backgroundOffset() const;
+
+ // whats this help
+ virtual bool customWhatsThis() const;
+
+ TQWidget * parentWidget( bool sameWindow = FALSE ) const;
+ WState testWState( WState s ) const;
+ WFlags testWFlags( WFlags f ) const;
+ static TQWidget * tqfind( WId );
+ static TQWidgetMapper *wmapper();
+
+ TQWidget *tqchildAt( int x, int y, bool includeThis = FALSE ) const;
+ TQWidget *tqchildAt( const TQPoint &, bool includeThis = FALSE ) const;
+
+#if defined(TQ_WS_TQWS)
+ virtual TQGfx * graphicsContext(bool clip_tqchildren=TRUE) const;
+#endif
+#if defined(TQ_WS_MAC)
+ TQRegion clippedRegion(bool do_tqchildren=TRUE);
+ uint clippedSerial(bool do_tqchildren=TRUE);
+#ifndef TQMAC_NO_TQUARTZ
+ CGContextRef macCGContext(bool clipped=TRUE) const;
+#endif
+#endif
+
+ void setWindowOpacity(double level);
+ double windowOpacity() const;
+
+protected:
+ // Event handlers
+ virtual bool event( TQEvent * );
+ virtual void mousePressEvent( TQMouseEvent * );
+ virtual void mouseReleaseEvent( TQMouseEvent * );
+ virtual void mouseDoubleClickEvent( TQMouseEvent * );
+ virtual void mouseMoveEvent( TQMouseEvent * );
+#ifndef TQT_NO_WHEELEVENT
+ virtual void wheelEvent( TQWheelEvent * );
+#endif
+ virtual void keyPressEvent( TQKeyEvent * );
+ virtual void keyReleaseEvent( TQKeyEvent * );
+ virtual void focusInEvent( TQFocusEvent * );
+ virtual void focusOutEvent( TQFocusEvent * );
+ virtual void enterEvent( TQEvent * );
+ virtual void leaveEvent( TQEvent * );
+ virtual void paintEvent( TQPaintEvent * );
+ virtual void moveEvent( TQMoveEvent * );
+ virtual void resizeEvent( TQResizeEvent * );
+ virtual void closeEvent( TQCloseEvent * );
+ virtual void contextMenuEvent( TQContextMenuEvent * );
+ virtual void imStartEvent( TQIMEvent * );
+ virtual void imComposeEvent( TQIMEvent * );
+ virtual void imEndEvent( TQIMEvent * );
+ virtual void tabletEvent( TQTabletEvent * );
+
+#ifndef TQT_NO_DRAGANDDROP
+ virtual void dragEnterEvent( TQDragEnterEvent * );
+ virtual void dragMoveEvent( TQDragMoveEvent * );
+ virtual void dragLeaveEvent( TQDragLeaveEvent * );
+ virtual void dropEvent( TQDropEvent * );
+#endif
+
+ virtual void showEvent( TQShowEvent * );
+ virtual void hideEvent( TQHideEvent * );
+
+#if defined(TQ_WS_MAC)
+ virtual bool macEvent( MSG * );
+#endif
+#if defined(TQ_WS_WIN)
+ virtual bool winEvent( MSG * );
+#endif
+#if defined(TQ_WS_X11)
+ virtual bool x11Event( XEvent * );
+#endif
+#if defined(TQ_WS_TQWS)
+ virtual bool qwsEvent( TQWSEvent * );
+ virtual unsigned char *scanLine( int ) const;
+ virtual int bytesPerLine() const;
+#endif
+
+ virtual void updateMask();
+
+ // Misc. protected functions
+
+#ifndef TQT_NO_STYLE
+ virtual void styleChange( TQStyle& );
+#endif
+ virtual void enabledChange( bool oldEnabled );
+#ifndef TQT_NO_PALETTE
+ virtual void paletteChange( const TQPalette & );
+#endif
+ virtual void fontChange( const TQFont & );
+ virtual void windowActivationChange( bool oldActive );
+
+ int metric( int ) const;
+
+ void resetInputContext();
+
+ virtual void create( WId = 0, bool initializeWindow = TRUE,
+ bool destroyOldWindow = TRUE );
+ virtual void destroy( bool destroyWindow = TRUE,
+ bool destroySubWindows = TRUE );
+ uint getWState() const;
+ virtual void setWState( uint );
+ void clearWState( uint n );
+ WFlags getWFlags() const;
+ virtual void setWFlags( WFlags );
+ void clearWFlags( WFlags n );
+
+ virtual bool focusNextPrevChild( bool next );
+
+ TQWExtra *extraData();
+ TQTLWExtra *topData();
+ TQFocusData *focusData();
+
+ virtual void setKeyCompression(bool);
+ virtual void setMicroFocusHint(int x, int y, int w, int h, bool text=TRUE, TQFont *f = 0);
+
+#if defined(TQ_WS_MAC)
+ void dirtyClippedRegion(bool);
+ bool isClippedRegionDirty();
+ virtual void setRegionDirty(bool);
+ virtual void macWidgetChangedWindow();
+#endif
+
+private Q_SLOTS:
+ void focusProxyDestroyed();
+
+private:
+ void setFontSys( TQFont *f = 0 );
+#if defined(TQ_WS_X11)
+ void createInputContext();
+ void destroyInputContext();
+ void focusInputContext();
+ void checkChildrenDnd();
+#elif defined(TQ_WS_MAC)
+ uint own_id : 1, macDropEnabled : 1;
+ EventHandlerRef window_event;
+ //mac event functions
+ void propagateUpdates(bool update_rgn=TRUE);
+ void update( const TQRegion& );
+ //friends, way too many - fix this immediately!
+ friend void qt_clean_root_win();
+ friend bool qt_recreate_root_win();
+ friend TQPoint posInWindow(TQWidget *);
+ friend bool qt_mac_update_sizer(TQWidget *, int);
+ friend TQWidget *qt_recursive_match(TQWidget *widg, int x, int y);
+ friend bool qt_paint_childrenListObject(TQWidget *,TQRegion &, uchar ops);
+ friend TQMAC_PASCAL OStqStatus qt_window_event(EventHandlerCallRef er, EventRef event, void *);
+ friend void qt_event_request_updates(TQWidget *, const TQRegion &, bool subtract);
+ friend bool qt_window_rgn(WId, short, RgnHandle, bool);
+ friend class TQDragManager;
+#endif
+
+#ifndef TQT_NO_LAYOUT
+ void setLayout( TQLayout *l );
+#endif
+ void setWinId( WId );
+ void showWindow();
+ void hideWindow();
+ void showChildren( bool spontaneous );
+ void hideChildren( bool spontaneous );
+ void reparentSys( TQWidget *tqparent, WFlags, const TQPoint &, bool showIt);
+ void createTLExtra();
+ void createExtra();
+ void deleteExtra();
+ void createSysExtra();
+ void deleteSysExtra();
+ void createTLSysExtra();
+ void deleteTLSysExtra();
+ void deactivateWidgetCleanup();
+ void internalSetGeometry( int, int, int, int, bool );
+ void reparentFocusWidgets( TQWidget * );
+ TQFocusData *focusData( bool create );
+ void setBackgroundFromMode();
+ void setBackgroundColorDirect( const TQColor & );
+ void setBackgroundPixmapDirect( const TQPixmap & );
+ void setBackgroundModeDirect( BackgroundMode );
+ void setBackgroundEmpty();
+ void updateFrameStrut() const;
+#if defined(TQ_WS_X11)
+ void setBackgroundX11Relative();
+#endif
+
+ WId winid;
+ uint widget_state;
+ uint widget_flags;
+ uint focus_policy : 4;
+ uint own_font :1;
+ uint own_palette :1;
+ uint sizehint_forced :1;
+ uint is_closing :1;
+ uint in_show : 1;
+ uint in_show_maximized : 1;
+ uint fstrut_dirty : 1;
+ uint im_enabled : 1;
+ TQRect crect;
+ TQColor bg_col;
+#ifndef TQT_NO_PALETTE
+ TQPalette pal;
+#endif
+ TQFont fnt;
+#ifndef TQT_NO_LAYOUT
+ TQLayout *lay_out;
+#endif
+ TQWExtra *extra;
+#if defined(TQ_WS_TQWS)
+ TQRegion req_region; // Requested region
+ mutable TQRegion paintable_region; // Paintable region
+ mutable bool paintable_region_dirty;// needs to be recalculated
+ mutable TQRegion alloc_region; // Allocated region
+ mutable bool alloc_region_dirty; // needs to be recalculated
+ mutable int overlapping_tqchildren; // Handle overlapping tqchildren
+
+ int alloc_region_index;
+ int alloc_region_revision;
+
+ void updateOverlappingChildren() const;
+ void setChildrenAllocatedDirty();
+ void setChildrenAllocatedDirty( const TQRegion &r, const TQWidget *dirty=0 );
+ bool isAllocatedRegionDirty() const;
+ void updateRequestedRegion( const TQPoint &gpos );
+ TQRegion requestedRegion() const;
+ TQRegion allocatedRegion() const;
+ TQRegion paintableRegion() const;
+
+ void updateGraphicsContext( TQGfx *qgfx_qws, bool clip_tqchildren ) const;
+#ifndef TQT_NO_CURSOR
+ void updateCursor( const TQRegion &r ) const;
+#endif
+
+ // used to accumulate dirty region when tqchildren moved/resized.
+ TQRegion dirtyChildren;
+ bool isSettingGeometry;
+ friend class TQWSManager;
+#endif
+ static int instanceCounter; // Current number of widget instances
+ static int maxInstances; // Maximum number of widget instances
+
+ static void createMapper();
+ static void destroyMapper();
+ static TQWidgetList *wList();
+ static TQWidgetList *tlwList();
+ static TQWidgetMapper *mapper;
+ friend class TQApplication;
+ friend class TQBaseApplication;
+ friend class TQPainter;
+ friend class TQFontMetrics;
+ friend class TQFontInfo;
+ friend class TQETWidget;
+ friend class TQLayout;
+
+private: // Disabled copy constructor and operator=
+#if defined(TQ_DISABLE_COPY)
+ TQWidget( const TQWidget & );
+ TQWidget &operator=( const TQWidget & );
+#endif
+
+public: // obsolete functions to dissappear or to become inline in 3.0
+#ifndef TQT_NO_PALETTE
+ void setPalette( const TQPalette &p, bool ) { setPalette( p ); }
+#endif
+ void setFont( const TQFont &f, bool ) { setFont( f ); }
+};
+
+
+inline TQt::WState TQWidget::testWState( WState s ) const
+{ return (widget_state & s); }
+
+inline TQt::WFlags TQWidget::testWFlags( WFlags f ) const
+{ return (widget_flags & f); }
+
+
+inline WId TQWidget::winId() const
+{ return winid; }
+
+inline bool TQWidget::isTopLevel() const
+{ return testWFlags(WType_TopLevel); }
+
+inline bool TQWidget::isDialog() const
+{ return testWFlags(WType_Dialog); }
+
+inline bool TQWidget::isPopup() const
+{ return testWFlags(WType_Popup); }
+
+inline bool TQWidget::isDesktop() const
+{ return testWFlags(WType_Desktop); }
+
+inline bool TQWidget::isEnabled() const
+{ return !testWState(WState_Disabled); }
+
+inline bool TQWidget::isModal() const
+{ return testWFlags(WShowModal); }
+
+inline bool TQWidget::isEnabledToTLW() const
+{ return isEnabled(); }
+
+inline const TQRect &TQWidget::tqgeometry() const
+{ return crect; }
+
+inline TQSize TQWidget::size() const
+{ return crect.size(); }
+
+inline int TQWidget::width() const
+{ return crect.width(); }
+
+inline int TQWidget::height() const
+{ return crect.height(); }
+
+inline TQRect TQWidget::rect() const
+{ return TQRect(0,0,crect.width(),crect.height()); }
+
+inline int TQWidget::minimumWidth() const
+{ return tqminimumSize().width(); }
+
+inline int TQWidget::minimumHeight() const
+{ return tqminimumSize().height(); }
+
+inline int TQWidget::maximumWidth() const
+{ return tqmaximumSize().width(); }
+
+inline int TQWidget::maximumHeight() const
+{ return tqmaximumSize().height(); }
+
+inline void TQWidget::setMinimumSize( const TQSize &s )
+{ setMinimumSize(s.width(),s.height()); }
+
+inline void TQWidget::setMaximumSize( const TQSize &s )
+{ setMaximumSize(s.width(),s.height()); }
+
+inline void TQWidget::setSizeIncrement( const TQSize &s )
+{ setSizeIncrement(s.width(),s.height()); }
+
+inline void TQWidget::setBaseSize( const TQSize &s )
+{ setBaseSize(s.width(),s.height()); }
+
+inline const TQColor &TQWidget::eraseColor() const
+{ return bg_col; }
+
+#ifndef TQT_NO_PALETTE
+inline const TQPalette &TQWidget::palette() const
+{ return pal; }
+#endif
+
+inline TQFont TQWidget::font() const
+{ return fnt; }
+
+inline TQFontMetrics TQWidget::fontMetrics() const
+{ return TQFontMetrics(font()); }
+
+inline TQFontInfo TQWidget::fontInfo() const
+{ return TQFontInfo(font()); }
+
+inline bool TQWidget::hasMouseTracking() const
+{ return testWState(WState_MouseTracking); }
+
+inline bool TQWidget::hasMouse() const
+{ return testWState(WState_HasMouse); }
+
+inline bool TQWidget::isFocusEnabled() const
+{ return (FocusPolicy)focus_policy != NoFocus; }
+
+inline TQWidget::FocusPolicy TQWidget::focusPolicy() const
+{ return (FocusPolicy)focus_policy; }
+
+inline bool TQWidget::isUpdatesEnabled() const
+{ return !testWState(WState_BlockUpdates); }
+
+inline void TQWidget::update( const TQRect &r )
+{ update( r.x(), r.y(), r.width(), r.height() ); }
+
+inline void TQWidget::tqrepaint()
+{ tqrepaint( TRUE ); }
+
+inline void TQWidget::tqrepaint( const TQRect &r, bool erase )
+{ tqrepaint( r.x(), r.y(), r.width(), r.height(), erase ); }
+
+inline void TQWidget::erase()
+{ erase( 0, 0, crect.width(), crect.height() ); }
+
+inline void TQWidget::erase( const TQRect &r )
+{ erase( r.x(), r.y(), r.width(), r.height() ); }
+
+inline bool TQWidget::close()
+{ return close( FALSE ); }
+
+inline bool TQWidget::isVisible() const
+{ return testWState(WState_Visible); }
+
+inline bool TQWidget::isVisibleToTLW() const // obsolete
+{ return isVisible(); }
+
+inline bool TQWidget::isHidden() const
+{ return testWState(WState_ForceHide); }
+
+inline bool TQWidget::isShown() const
+{ return !testWState(WState_ForceHide); }
+
+inline void TQWidget::move( const TQPoint &p )
+{ move( p.x(), p.y() ); }
+
+inline void TQWidget::resize( const TQSize &s )
+{ resize( s.width(), s.height()); }
+
+inline void TQWidget::setGeometry( const TQRect &r )
+{ setGeometry( r.left(), r.top(), r.width(), r.height() ); }
+
+inline void TQWidget::drawText( const TQPoint &p, const TQString &s )
+{ drawText( p.x(), p.y(), s ); }
+
+inline TQWidget *TQWidget::parentWidget( bool sameWindow ) const
+{
+ if ( sameWindow )
+ return isTopLevel() ? 0 : (TQWidget *)TQObject::tqparent();
+ return (TQWidget *)TQObject::tqparent();
+}
+
+inline TQWidgetMapper *TQWidget::wmapper()
+{ return mapper; }
+
+inline uint TQWidget::getWState() const
+{ return widget_state; }
+
+inline void TQWidget::setWState( uint f )
+{ widget_state |= f; }
+
+inline void TQWidget::clearWState( uint f )
+{ widget_state &= ~f; }
+
+inline TQt::WFlags TQWidget::getWFlags() const
+{ return widget_flags; }
+
+inline void TQWidget::setWFlags( WFlags f )
+{ widget_flags |= f; }
+
+inline void TQWidget::clearWFlags( WFlags f )
+{ widget_flags &= ~f; }
+
+inline void TQWidget::constPolish() const
+{
+ if ( !testWState(WState_Polished) ) {
+ TQWidget* that = (TQWidget*) this;
+ that->polish();
+ that->setWState(WState_Polished); // be on the safe side...
+ }
+}
+#ifndef TQT_NO_CURSOR
+inline bool TQWidget::ownCursor() const
+{
+ return testWState( WState_OwnCursor );
+}
+#endif
+inline bool TQWidget::ownFont() const
+{
+ return own_font;
+}
+#ifndef TQT_NO_PALETTE
+inline bool TQWidget::ownPalette() const
+{
+ return own_palette;
+}
+#endif
+
+inline void TQWidget::tqsetSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw )
+{
+ tqsetSizePolicy( TQSizePolicy( hor, ver, hfw) );
+}
+
+inline bool TQWidget::isInputMethodEnabled() const
+{
+ return (bool)im_enabled;
+}
+
+// Extra TQWidget data
+// - to minimize memory usage for members that are seldom used.
+// - top-level widgets have extra extra data to reduce cost further
+
+class TQFocusData;
+class TQWSManager;
+#if defined(TQ_WS_WIN)
+class TQOleDropTarget;
+#endif
+#if defined(TQ_WS_MAC)
+class TQMacDndExtra;
+#endif
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+#else // USE_QT4
+
+struct TQ_EXPORT TQTLWExtra {
+#ifndef TQT_NO_WIDGET_TOPEXTRA
+ TQString caption; // widget caption
+ TQString iconText; // widget icon text
+ TQPixmap *icon; // widget icon
+#endif
+ TQFocusData *focusData; // focus data (for TLW)
+ short incw, inch; // size increments
+ // frame strut
+ ulong fleft, fright, ftop, fbottom;
+ uint unused : 8; // not used at this point...
+#if defined( TQ_WS_WIN ) || defined( TQ_WS_MAC )
+ uint opacity : 8; // Stores opacity level on Windows/Mac OS X.
+#endif
+ uint savedFlags; // Save widgetflags while showing fullscreen
+ short basew, baseh; // base sizes
+#if defined(TQ_WS_X11)
+ WId parentWinId; // tqparent window Id (valid after reparenting)
+ uint embedded : 1; // window is embedded in another TQt application
+ uint spont_unmapped: 1; // window was spontaneously unmapped
+ uint reserved: 1; // reserved
+ uint dnd : 1; // DND properties installed
+ uint uspos : 1; // User defined position
+ uint ussize : 1; // User defined size
+ void *xic; // XIM Input Context
+#endif
+#if defined(TQ_WS_MAC)
+ WindowGroupRef group;
+ uint is_moved: 1;
+ uint resizer : 4;
+#endif
+#if defined(TQ_WS_TQWS) && !defined ( TQT_NO_TQWS_MANAGER )
+ TQRegion decor_allocated_region; // decoration allocated region
+ TQWSManager *qwsManager;
+#endif
+#if defined(TQ_WS_WIN)
+ HICON winIcon; // internal Windows icon
+#endif
+ TQRect normalGeometry; // used by showMin/maximized/FullScreen
+#ifdef TQ_WS_WIN
+ uint style, exstyle;
+#endif
+};
+
+
+#define TQWIDGETSIZE_MAX 32767
+
+// dear user: you can see this struct, but it is internal. do not touch.
+
+struct TQ_EXPORT TQWExtra {
+ TQ_INT16 minw, minh; // minimum size
+ TQ_INT16 maxw, maxh; // maximum size
+ TQPixmap *bg_pix; // background pixmap
+ TQWidget *focus_proxy;
+#ifndef TQT_NO_CURSOR
+ TQCursor *curs;
+#endif
+ TQTLWExtra *topextra; // only useful for TLWs
+#if defined(TQ_WS_WIN)
+ TQOleDropTarget *dropTarget; // drop target
+#endif
+#if defined(TQ_WS_X11)
+ WId xDndProxy; // XDND forwarding to embedded windows
+#endif
+#if defined(TQ_WS_MAC)
+ TQRegion clip_saved, clip_sibs, clip_tqchildren;
+ TQMacDndExtra *macDndExtra;
+ TQRegion dirty_area;
+ uint clip_dirty : 1, clip_serial : 15;
+ uint child_dirty : 1, child_serial : 15;
+#ifndef TQMAC_NO_TQUARTZ
+ uint ctx_tqchildren_clipped:1;
+#endif // TQMAC_NO_TQUARTZ
+ uint has_dirty_area:1;
+#endif // TQ_WS_MAC
+ uint bg_origin : 2;
+#if defined(TQ_WS_X11)
+ uint tqchildren_use_dnd : 1;
+ uint compress_events : 1;
+#endif
+#if defined(TQ_WS_TQWS) || defined(TQ_WS_MAC)
+ TQRegion tqmask; // widget tqmask
+#endif
+ char bg_mode; // background mode
+ char bg_mode_visual; // visual background mode
+#ifndef TQT_NO_STYLE
+ TQStyle* style;
+#endif
+ TQRect micro_focus_hint; // micro focus hint
+ TQSizePolicy size_policy;
+};
+
+#endif // USE_QT4
+
+#define TQ_DEFINED_TQWIDGET
+#include "tqwinexport.h"
+
+#endif // TQWIDGET_H
diff --git a/tqtinterface/qt4/src/kernel/tqwidget_p.h b/tqtinterface/qt4/src/kernel/tqwidget_p.h
new file mode 100644
index 0000000..0450ac0
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwidget_p.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Definition of some TQt private functions.
+**
+** Created : 000903
+**
+** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWIDGET_P_H
+#define TQWIDGET_P_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the TQt API. It exists for the convenience
+// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
+// file may change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#ifndef TQT_H
+#endif // TQT_H
+
+#if defined (TQ_WS_X11) || defined (TQ_WS_TQWS)
+extern int qt_widget_tlw_gravity;
+#endif
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqwidget_x11.cpp b/tqtinterface/qt4/src/kernel/tqwidget_x11.cpp
new file mode 100644
index 0000000..f8c605a
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwidget_x11.cpp
@@ -0,0 +1,2980 @@
+/****************************************************************************
+**
+** Implementation of TQWidget and TQWindow classes for X11
+**
+** Created : 931031
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqapplication.h"
+#include "tqapplication_p.h"
+#include "tqnamespace.h"
+#include "tqpaintdevicemetrics.h"
+#include "tqpainter.h"
+#include "tqbitmap.h"
+#include "tqobjectlist.h"
+#include "tqlayout.h"
+#include "tqtextcodec.h"
+#include "tqdatetime.h"
+#include "tqcursor.h"
+#include "tqt_x11_p.h"
+#include <stdlib.h>
+
+#ifdef USE_QT4
+
+// defined in qapplication_x11.cpp
+extern Atom qt_wm_state;
+extern Atom qt_wm_change_state;
+extern Atom qt_wm_delete_window;
+extern Atom qt_wm_take_focus;
+extern Atom qt_wm_client_leader;
+extern Atom qt_window_role;
+extern Atom qt_sm_client_id;
+extern Atom qt_utf8_string;
+extern Atom qt_net_wm_context_help;
+extern Atom qt_net_wm_ping;
+extern Atom qt_xa_motif_wm_hints;
+extern Atom qt_net_wm_name;
+extern Atom qt_net_wm_icon_name;
+extern Atom qt_net_wm_state;
+extern Atom qt_net_wm_state_modal;
+extern Atom qt_net_wm_state_max_v;
+extern Atom qt_net_wm_state_max_h;
+extern Atom qt_net_wm_state_fullscreen;
+extern Atom qt_net_wm_state_above;
+extern Atom qt_net_wm_state_stays_on_top;
+extern Atom qt_net_wm_window_type;
+extern Atom qt_net_wm_window_type_normal;
+extern Atom qt_net_wm_window_type_dialog;
+extern Atom qt_net_wm_window_type_toolbar;
+extern Atom qt_net_wm_window_type_menu;
+extern Atom qt_net_wm_window_type_utility;
+extern Atom qt_net_wm_window_type_splash;
+extern Atom qt_net_wm_window_type_override;
+extern Atom qt_net_wm_pid;
+extern Atom qt_net_wm_user_time;
+extern Atom qt_enlightenment_desktop;
+extern Atom qt_net_virtual_roots;
+extern bool qt_broken_wm;
+
+// defined in qapplication_x11.cpp
+extern bool qt_net_supports(Atom);
+extern unsigned long *qt_net_virtual_root_list;
+
+TQ_EXPORT void qt_wait_for_window_manager( TQWidget* w )
+{
+ TQApplication::flushX();
+ XEvent ev;
+ TQTime t;
+ t.start();
+ while ( !XCheckTypedWindowEvent( w->x11Display(), w->winId(), ReparentNotify, &ev ) ) {
+ if ( XCheckTypedWindowEvent( w->x11Display(), w->winId(), MapNotify, &ev ) )
+ break;
+ if ( t.elapsed() > 500 )
+ return; // give up, no event available
+ tqApp->syncX(); // non-busy wait
+ }
+ tqApp->x11ProcessEvent( &ev );
+ if ( XCheckTypedWindowEvent( w->x11Display(), w->winId(), ConfigureNotify, &ev ) )
+ tqApp->x11ProcessEvent( &ev );
+}
+
+static void qt_net_change_wm_state(const TQWidget* w, bool set, Atom one, Atom two = 0)
+{
+ if (w->isShown()) {
+ // managed by WM
+ XEvent e;
+ e.xclient.type = ClientMessage;
+ e.xclient.message_type = qt_net_wm_state;
+ e.xclient.display = const_cast<TQWidget*>(w)->x11Display();
+ e.xclient.window = w->winId();
+ e.xclient.format = 32;
+ e.xclient.data.l[ 0 ] = set ? 1 : 0;
+ e.xclient.data.l[ 1 ] = one;
+ e.xclient.data.l[ 2 ] = two;
+ e.xclient.data.l[ 3 ] = 0;
+ e.xclient.data.l[ 4 ] = 0;
+ XSendEvent(const_cast<TQWidget*>(w)->x11Display(), RootWindow(const_cast<TQWidget*>(w)->x11Display(), const_cast<TQWidget*>(w)->x11Screen()),
+ False, (SubstructureNotifyMask|SubstructureRedirectMask), &e);
+ } else {
+ Atom ret;
+ int format = 0, status;
+ unsigned char *data = 0;
+ unsigned long nitems = 0, after = 0;
+ Atom *old_states = 0;
+ status = XGetWindowProperty(const_cast<TQWidget*>(w)->x11Display(), w->winId(),
+ qt_net_wm_state, 0, 1024, False,
+ XA_ATOM, &ret, &format, &nitems,
+ &after, &data);
+ if (status == Success && ret == XA_ATOM && format == 32 && nitems > 0)
+ old_states = (Atom *) data;
+ else
+ nitems = 0;
+
+ Atom *new_states = new Atom[nitems + 2];
+ int i, j = 0;
+ for (i = 0; i < (int)nitems; ++i) {
+ if (old_states[i] && old_states[i] != one && old_states[i] != two)
+ new_states[j++] = old_states[i];
+ }
+
+ if (set) {
+ if (one) new_states[j++] = one;
+ if (two) new_states[j++] = two;
+ }
+
+ if (j)
+ XChangeProperty(const_cast<TQWidget*>(w)->x11Display(), w->winId(), qt_net_wm_state, XA_ATOM, 32,
+ PropModeReplace, (uchar *) new_states, j);
+ else
+ XDeleteProperty(const_cast<TQWidget*>(w)->x11Display(), w->winId(), qt_net_wm_state);
+
+ delete [] new_states;
+ if (data) XFree(data);
+ }
+}
+
+void TQWidget::setMask( const QRegion region )
+{
+ QWidget::setMask(region);
+}
+
+void TQWidget::setMask( const QBitmap bitmap )
+{
+ // Work around a bug in Qt4.x (including Qt4.7) where setting any pixel in either
+ // the bottom row or rightmost column of a QBitmap to Qt::color0 (i.e., transparent)
+ // will cause the entire mask to beome opaque
+ TQBitmap fixedBitmap = bitmap;
+ fixedBitmap.resize(bitmap.width()+1, bitmap.height()+1);
+ TQPainter fixerUpper(&fixedBitmap);
+ fixerUpper.setBrush(Qt::color1);
+ fixerUpper.setBackgroundMode(Qt::TransparentMode);
+ fixerUpper.drawLine(0, fixedBitmap.height()-1, fixedBitmap.width()-1, fixedBitmap.height()-1);
+ fixerUpper.drawLine(fixedBitmap.width()-1, 0, fixedBitmap.width()-1, fixedBitmap.height()-1);
+ fixerUpper.end();
+ QWidget::setMask(fixedBitmap.mask());
+}
+
+/*!
+ When a widget gets focus, it should call setMicroFocusHint() with
+ some appropriate position and size, \a x, \a y, \a width and \a
+ height. This has no \e visual effect, it just provides hints to
+ any system-specific input handling tools.
+
+ The \a text argument should be TRUE if this is a position for text
+ input.
+
+ In the Windows version of TQt, this method sets the system caret,
+ which is used for user Accessibility focus handling. If \a text
+ is TRUE, it also sets the IME composition window in Far East Asian
+ language input systems.
+
+ In the X11 version of TQt, if \a text is TRUE, this method sets the
+ XIM "spot" point for complex language input handling.
+
+ The font \a f is a rendering hint to the currently active input method.
+ If \a f is 0 the widget's font is used.
+
+ \sa microFocusHint()
+*/
+void TQWidget::setMicroFocusHint(int x, int y, int width, int height,
+ bool text, TQFont *f )
+{
+// #ifndef TQT_NO_XIM
+// if ( text ) {
+// TQWidget* tlw = tqtopLevelWidget();
+// TQTLWExtra *topdata = tlw->topData();
+//
+// // trigger input context creation if it hasn't happened already
+// createInputContext();
+// TQInputContext *qic = (TQInputContext *) topdata->xic;
+//
+// if ( qt_xim && qic ) {
+// TQPoint p( x, y );
+// TQPoint p2 = mapTo( tqtopLevelWidget(), TQPoint( 0, 0 ) );
+// p = mapTo( tqtopLevelWidget(), p);
+// qic->setXFontSet( f ? *f : fnt );
+// qic->setComposePosition(p.x(), p.y() + height);
+// qic->setComposeArea(p2.x(), p2.y(), this->width(), this->height());
+// }
+// }
+// #endif
+
+ if ( TQRect( x, y, width, height ) != microFocusHint() ) {
+ createExtra();
+ extraData()->micro_focus_hint.setRect( x, y, width, height );
+ }
+}
+
+// void TQWidget::createInputContext()
+// {
+// TQWidget *tlw = tqtopLevelWidget();
+// TQTLWExtra *topdata = tlw->topData();
+//
+// #ifndef TQT_NO_XIM
+// if (qt_xim) {
+// if (! topdata->xic) {
+// TQInputContext *qic = new TQInputContext(tlw);
+// topdata->xic = (void *) qic;
+// }
+// } else
+// #endif // TQT_NO_XIM
+// {
+// // qDebug("TQWidget::createInputContext: no xim");
+// topdata->xic = 0;
+// }
+// }
+
+/*!
+ \overload void TQWidget::drawText( const TQPoint &pos, const TQString& str )
+
+ Draws the string \a str at position \a pos.
+*/
+
+/*!
+ Draws the string \a str at position \a(x, y).
+
+ The \a y position is the base line position of the text. The text
+ is drawn using the default font and the default foreground color.
+
+ This function is provided for convenience. You will generally get
+ more flexible results and often higher speed by using a a \link
+ TQPainter painter\endlink instead.
+
+ \sa setFont(), foregroundColor(), TQPainter::drawText()
+*/
+
+void TQWidget::drawText( int x, int y, const TQString &str )
+{
+ if ( testWState(WState_Visible) ) {
+ TQPainter paint;
+ paint.begin( this );
+ paint.drawText( x, y, str );
+ paint.end();
+ }
+}
+
+#else // USE_QT4
+
+// NOT REVISED
+
+// defined in qapplication_x11.cpp
+extern Window qt_x11_wm_client_leader;
+extern void qt_x11_create_wm_client_leader();
+
+// defined in qapplication_x11.cpp
+void qt_insert_sip( TQWidget*, int, int );
+int qt_sip_count( TQWidget* );
+bool qt_wstate_iconified( WId );
+void qt_updated_rootinfo();
+
+#ifndef TQT_NO_XIM
+#include "tqinputcontext_p.h"
+
+extern XIM qt_xim;
+extern XIMStyle qt_xim_style;
+#endif
+
+// Paint event clipping magic
+extern void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region);
+extern void qt_clear_paintevent_clipping();
+
+extern bool qt_dnd_enable( TQWidget* w, bool on );
+extern bool qt_nograb();
+
+// defined in qapplication_x11.cpp
+extern void qt_deferred_map_add( TQWidget* );
+extern void qt_deferred_map_take( TQWidget* );
+extern bool qt_deferred_map_tqcontains(TQWidget *);
+
+static TQWidget *mouseGrb = 0;
+static TQWidget *keyboardGrb = 0;
+
+// defined in qfont_x11.cpp
+extern bool qt_has_xft;
+
+int qt_x11_create_desktop_on_screen = -1;
+
+/*****************************************************************************
+ TQWidget member functions
+ *****************************************************************************/
+
+// defined in qapplication_x11.cpp
+extern Atom qt_wm_state;
+extern Atom qt_wm_change_state;
+extern Atom qt_wm_delete_window;
+extern Atom qt_wm_take_focus;
+extern Atom qt_wm_client_leader;
+extern Atom qt_window_role;
+extern Atom qt_sm_client_id;
+extern Atom qt_utf8_string;
+extern Atom qt_net_wm_context_help;
+extern Atom qt_net_wm_ping;
+extern Atom qt_xa_motif_wm_hints;
+extern Atom qt_net_wm_name;
+extern Atom qt_net_wm_icon_name;
+extern Atom qt_net_wm_state;
+extern Atom qt_net_wm_state_modal;
+extern Atom qt_net_wm_state_max_v;
+extern Atom qt_net_wm_state_max_h;
+extern Atom qt_net_wm_state_fullscreen;
+extern Atom qt_net_wm_state_above;
+extern Atom qt_net_wm_state_stays_on_top;
+extern Atom qt_net_wm_window_type;
+extern Atom qt_net_wm_window_type_normal;
+extern Atom qt_net_wm_window_type_dialog;
+extern Atom qt_net_wm_window_type_toolbar;
+extern Atom qt_net_wm_window_type_menu;
+extern Atom qt_net_wm_window_type_utility;
+extern Atom qt_net_wm_window_type_splash;
+extern Atom qt_net_wm_window_type_override;
+extern Atom qt_net_wm_pid;
+extern Atom qt_net_wm_user_time;
+extern Atom qt_enlightenment_desktop;
+extern Atom qt_net_virtual_roots;
+extern bool qt_broken_wm;
+
+// defined in qapplication_x11.cpp
+extern bool qt_net_supports(Atom);
+extern unsigned long *qt_net_virtual_root_list;
+
+#if defined (TQT_TABLET_SUPPORT)
+extern XDevice *devStylus;
+extern XDevice *devEraser;
+extern XEventClass event_list_stylus[7];
+extern XEventClass event_list_eraser[7];
+extern int qt_curr_events_stylus;
+extern int qt_curr_events_eraser;
+#endif
+
+const uint stdWidgetEventMask = // X event tqmask
+ (uint)(
+ KeyPressMask | KeyReleaseMask |
+ ButtonPressMask | ButtonReleaseMask |
+ KeymapStateMask |
+ ButtonMotionMask |
+ EnterWindowMask | LeaveWindowMask |
+ FocusChangeMask |
+ ExposureMask |
+ PropertyChangeMask |
+ StructureNotifyMask
+ );
+
+const uint stdDesktopEventMask = // X event tqmask
+ (uint)(
+ KeymapStateMask |
+ EnterWindowMask | LeaveWindowMask |
+ PropertyChangeMask
+ );
+
+
+/*
+ The qt_ functions below are implemented in qwidgetcreate_x11.cpp.
+*/
+
+Window qt_XCreateWindow( const TQWidget *creator,
+ Display *display, Window tqparent,
+ int x, int y, uint w, uint h,
+ int borderwidth, int depth,
+ uint windowclass, Visual *visual,
+ ulong valuetqmask, XSetWindowAttributes *attributes );
+Window qt_XCreateSimpleWindow( const TQWidget *creator,
+ Display *display, Window tqparent,
+ int x, int y, uint w, uint h, int borderwidth,
+ ulong border, ulong background );
+void qt_XDestroyWindow( const TQWidget *destroyer,
+ Display *display, Window window );
+
+TQ_EXPORT void qt_x11_enforce_cursor( TQWidget * w )
+{
+ if ( w->testWState( TQt::WState_OwnCursor ) ) {
+ TQCursor * oc = TQApplication::overrideCursor();
+ if ( oc ) {
+ XDefineCursor( w->x11Display(), w->winId(), oc->handle() );
+ } else if ( w->isEnabled() ) {
+ XDefineCursor( w->x11Display(), w->winId(), w->cursor().handle() );
+ } else {
+ // enforce the windows behavior of clearing the cursor on
+ // disabled widgets
+ XDefineCursor( w->x11Display(), w->winId(), None );
+ }
+ } else {
+ XDefineCursor( w->x11Display(), w->winId(), None );
+ }
+}
+
+TQ_EXPORT void qt_wait_for_window_manager( TQWidget* w )
+{
+ TQApplication::flushX();
+ XEvent ev;
+ TQTime t;
+ t.start();
+ while ( !XCheckTypedWindowEvent( w->x11Display(), w->winId(), ReparentNotify, &ev ) ) {
+ if ( XCheckTypedWindowEvent( w->x11Display(), w->winId(), MapNotify, &ev ) )
+ break;
+ if ( t.elapsed() > 500 )
+ return; // give up, no event available
+ tqApp->syncX(); // non-busy wait
+ }
+ tqApp->x11ProcessEvent( &ev );
+ if ( XCheckTypedWindowEvent( w->x11Display(), w->winId(), ConfigureNotify, &ev ) )
+ tqApp->x11ProcessEvent( &ev );
+}
+
+static void qt_net_change_wm_state(const TQWidget* w, bool set, Atom one, Atom two = 0)
+{
+ if (w->isShown()) {
+ // managed by WM
+ XEvent e;
+ e.xclient.type = ClientMessage;
+ e.xclient.message_type = qt_net_wm_state;
+ e.xclient.display = w->x11Display();
+ e.xclient.window = w->winId();
+ e.xclient.format = 32;
+ e.xclient.data.l[ 0 ] = set ? 1 : 0;
+ e.xclient.data.l[ 1 ] = one;
+ e.xclient.data.l[ 2 ] = two;
+ e.xclient.data.l[ 3 ] = 0;
+ e.xclient.data.l[ 4 ] = 0;
+ XSendEvent(w->x11Display(), RootWindow(w->x11Display(), w->x11Screen()),
+ False, (SubstructureNotifyMask|SubstructureRedirectMask), &e);
+ } else {
+ Atom ret;
+ int format = 0, status;
+ unsigned char *data = 0;
+ unsigned long nitems = 0, after = 0;
+ Atom *old_states = 0;
+ status = XGetWindowProperty(w->x11Display(), w->winId(),
+ qt_net_wm_state, 0, 1024, False,
+ XA_ATOM, &ret, &format, &nitems,
+ &after, &data);
+ if (status == Success && ret == XA_ATOM && format == 32 && nitems > 0)
+ old_states = (Atom *) data;
+ else
+ nitems = 0;
+
+ Atom *new_states = new Atom[nitems + 2];
+ int i, j = 0;
+ for (i = 0; i < (int)nitems; ++i) {
+ if (old_states[i] && old_states[i] != one && old_states[i] != two)
+ new_states[j++] = old_states[i];
+ }
+
+ if (set) {
+ if (one) new_states[j++] = one;
+ if (two) new_states[j++] = two;
+ }
+
+ if (j)
+ XChangeProperty(w->x11Display(), w->winId(), qt_net_wm_state, XA_ATOM, 32,
+ PropModeReplace, (uchar *) new_states, j);
+ else
+ XDeleteProperty(w->x11Display(), w->winId(), qt_net_wm_state);
+
+ delete [] new_states;
+ if (data) XFree(data);
+ }
+}
+
+/*!
+ Creates a new widget window if \a window is 0, otherwise sets the
+ widget's window to \a window.
+
+ Initializes the window (sets the tqgeometry etc.) if \a
+ initializeWindow is TRUE. If \a initializeWindow is FALSE, no
+ initialization is performed. This parameter only makes sense if \a
+ window is a valid window.
+
+ Destroys the old window if \a destroyOldWindow is TRUE. If \a
+ destroyOldWindow is FALSE, you are responsible for destroying the
+ window yourself (using platform native code).
+
+ The TQWidget constructor calls create(0,TRUE,TRUE) to create a
+ window for this widget.
+*/
+
+void TQWidget::create( WId window, bool initializeWindow, bool destroyOldWindow)
+{
+ if ( testWState(WState_Created) && window == 0 )
+ return;
+
+ // set created flag
+ setWState( WState_Created );
+
+ bool popup = testWFlags(WType_Popup);
+ bool dialog = testWFlags(WType_Dialog);
+ bool desktop = testWFlags(WType_Desktop);
+
+ // top-level widget
+ if ( !parentWidget() || parentWidget()->isDesktop() )
+ setWFlags( WType_TopLevel );
+
+ // these are top-level, too
+ if ( dialog || popup || desktop || testWFlags(WStyle_Splash))
+ setWFlags( WType_TopLevel );
+
+ // a popup stays on top
+ if ( popup )
+ setWFlags(WStyle_StaysOnTop);
+
+ bool topLevel = testWFlags(WType_TopLevel);
+ Window parentw, destroyw = 0;
+ WId id;
+
+ // always initialize
+ if ( !window )
+ initializeWindow = TRUE;
+
+ if ( desktop &&
+ qt_x11_create_desktop_on_screen >= 0 &&
+ qt_x11_create_desktop_on_screen != x11Screen() ) {
+ // desktop on a certain screen other than the default requested
+ TQPaintDeviceX11Data* xd = getX11Data( TRUE );
+ xd->x_screen = qt_x11_create_desktop_on_screen;
+ xd->x_depth = TQPaintDevice::x11AppDepth( xd->x_screen );
+ xd->x_cells = TQPaintDevice::x11AppCells( xd->x_screen );
+ xd->x_colormap = TQPaintDevice::x11AppColormap( xd->x_screen );
+ xd->x_defcolormap = TQPaintDevice::x11AppDefaultColormap( xd->x_screen );
+ xd->x_visual = TQPaintDevice::x11AppVisual( xd->x_screen );
+ xd->x_defvisual = TQPaintDevice::x11AppDefaultVisual( xd->x_screen );
+ setX11Data( xd );
+ } else if ( parentWidget() && parentWidget()->x11Screen() != x11Screen() ) {
+ // if we have a tqparent widget, move to its screen if necessary
+ TQPaintDeviceX11Data* xd = getX11Data( TRUE );
+ xd->x_screen = parentWidget()->x11Screen();
+ xd->x_depth = TQPaintDevice::x11AppDepth( xd->x_screen );
+ xd->x_cells = TQPaintDevice::x11AppCells( xd->x_screen );
+ xd->x_colormap = TQPaintDevice::x11AppColormap( xd->x_screen );
+ xd->x_defcolormap = TQPaintDevice::x11AppDefaultColormap( xd->x_screen );
+ xd->x_visual = TQPaintDevice::x11AppVisual( xd->x_screen );
+ xd->x_defvisual = TQPaintDevice::x11AppDefaultVisual( xd->x_screen );
+ setX11Data( xd );
+ }
+
+ //get display, screen number, root window and desktop tqgeometry for
+ //the current screen
+ Display *dpy = x11Display();
+ int scr = x11Screen();
+ Window root_win = RootWindow( dpy, scr );
+ int sw = DisplayWidth(dpy,scr);
+ int sh = DisplayHeight(dpy,scr);
+
+ if ( desktop ) { // desktop widget
+ dialog = popup = FALSE; // force these flags off
+ crect.setRect( 0, 0, sw, sh );
+ } else if ( topLevel ) { // calc pos/size from screen
+ crect.setRect( sw/4, 3*sh/10, sw/2, 4*sh/10 );
+ } else { // child widget
+ crect.setRect( 0, 0, 100, 30 );
+ }
+
+ parentw = topLevel ? root_win : parentWidget()->winId();
+
+ XSetWindowAttributes wsa;
+
+ if ( window ) { // override the old window
+ if ( destroyOldWindow )
+ destroyw = winid;
+ id = window;
+ setWinId( window );
+ XWindowAttributes a;
+ XGetWindowAttributes( dpy, window, &a );
+ crect.setRect( a.x, a.y, a.width, a.height );
+
+ if ( a.map_state == IsUnmapped )
+ clearWState( WState_Visible );
+ else
+ setWState( WState_Visible );
+
+ TQPaintDeviceX11Data* xd = getX11Data( TRUE );
+
+ // tqfind which screen the window is on...
+ xd->x_screen = TQPaintDevice::x11AppScreen(); // by default, use the default :)
+ int i;
+ for ( i = 0; i < ScreenCount( dpy ); i++ ) {
+ if ( RootWindow( dpy, i ) == a.root ) {
+ xd->x_screen = i;
+ break;
+ }
+ }
+
+ xd->x_depth = a.depth;
+ xd->x_cells = DisplayCells( dpy, xd->x_screen );
+ xd->x_visual = a.visual;
+ xd->x_defvisual = ( XVisualIDFromVisual( a.visual ) ==
+ XVisualIDFromVisual( (Visual*)x11AppVisual(x11Screen()) ) );
+ xd->x_colormap = a.colormap;
+ xd->x_defcolormap = ( a.colormap == x11AppColormap( x11Screen() ) );
+ setX11Data( xd );
+ } else if ( desktop ) { // desktop widget
+ id = (WId)parentw; // id = root window
+ TQWidget *otherDesktop = tqfind( id ); // is there another desktop?
+ if ( otherDesktop && otherDesktop->testWFlags(WPaintDesktop) ) {
+ otherDesktop->setWinId( 0 ); // remove id from widget mapper
+ setWinId( id ); // make sure otherDesktop is
+ otherDesktop->setWinId( id ); // found first
+ } else {
+ setWinId( id );
+ }
+ } else {
+ if ( x11DefaultVisual() && x11DefaultColormap() ) {
+ id = (WId)qt_XCreateSimpleWindow( this, dpy, parentw,
+ crect.left(), crect.top(),
+ crect.width(), crect.height(),
+ 0,
+ black.pixel(x11Screen()),
+ bg_col.pixel(x11Screen()) );
+ } else {
+ wsa.background_pixel = bg_col.pixel(x11Screen());
+ wsa.border_pixel = black.pixel(x11Screen());
+ wsa.colormap = (Colormap)x11Colormap();
+ id = (WId)qt_XCreateWindow( this, dpy, parentw,
+ crect.left(), crect.top(),
+ crect.width(), crect.height(),
+ 0, x11Depth(), InputOutput,
+ (Visual*)x11Visual(),
+ CWBackPixel|CWBorderPixel|CWColormap,
+ &wsa );
+ }
+
+ setWinId( id ); // set widget id/handle + hd
+ }
+
+#ifndef TQT_NO_XFTFREETYPE
+ if (rendhd) {
+ XftDrawDestroy( (XftDraw *) rendhd );
+ rendhd = 0;
+ }
+
+ if ( qt_has_xft )
+ rendhd = (HANDLE) XftDrawCreate( dpy, id, (Visual *) x11Visual(),
+ x11Colormap() );
+#endif // TQT_NO_XFTFREETYPE
+
+ // NET window types
+ long net_wintypes[7] = { 0, 0, 0, 0, 0, 0, 0 };
+ int curr_wintype = 0;
+
+ // NET window states
+ long net_winstates[6] = { 0, 0, 0, 0, 0, 0 };
+ int curr_winstate = 0;
+
+ struct {
+ ulong flags, functions, decorations;
+ long input_mode;
+ ulong status;
+ } mwmhints;
+
+ mwmhints.flags = mwmhints.functions = 0L;
+ mwmhints.decorations = (1L << 0); // MWM_DECOR_ALL
+ mwmhints.input_mode = 0L;
+ mwmhints.status = 0L;
+
+ if (topLevel && ! (desktop || popup)) {
+ ulong wsa_mask = 0;
+
+ if ( testWFlags(WStyle_Splash) ) {
+ if (qt_net_supports(qt_net_wm_window_type_splash)) {
+ clearWFlags( WX11BypassWM );
+ net_wintypes[curr_wintype++] = qt_net_wm_window_type_splash;
+ } else {
+ setWFlags( WX11BypassWM | WStyle_Tool | WStyle_NoBorder );
+ }
+ }
+ if (testWFlags(WStyle_Customize)) {
+ mwmhints.decorations = 0L;
+ mwmhints.flags |= (1L << 1); // MWM_HINTS_DECORATIONS
+
+ if ( testWFlags( WStyle_NoBorder ) ) {
+ // override netwm type - quick and easy for KDE noborder
+ net_wintypes[curr_wintype++] = qt_net_wm_window_type_override;
+ } else {
+ if ( testWFlags( WStyle_NormalBorder | WStyle_DialogBorder ) ) {
+ mwmhints.decorations |= (1L << 1); // MWM_DECOR_BORDER
+ mwmhints.decorations |= (1L << 2); // MWM_DECOR_RESIZEH
+ }
+
+ if ( testWFlags( WStyle_Title ) )
+ mwmhints.decorations |= (1L << 3); // MWM_DECOR_TITLE
+
+ if ( testWFlags( WStyle_SysMenu ) )
+ mwmhints.decorations |= (1L << 4); // MWM_DECOR_MENU
+
+ if ( testWFlags( WStyle_Minimize ) )
+ mwmhints.decorations |= (1L << 5); // MWM_DECOR_MINIMIZE
+
+ if ( testWFlags( WStyle_Maximize ) )
+ mwmhints.decorations |= (1L << 6); // MWM_DECOR_MAXIMIZE
+ }
+
+ if (testWFlags(WStyle_Tool)) {
+ wsa.save_under = True;
+ wsa_mask |= CWSaveUnder;
+ }
+ } else if (testWFlags(WType_Dialog)) {
+ setWFlags(WStyle_NormalBorder | WStyle_Title |
+ WStyle_SysMenu | WStyle_ContextHelp);
+ } else {
+ setWFlags(WStyle_NormalBorder | WStyle_Title |
+ WStyle_MinMax | WStyle_SysMenu);
+
+ // maximized netwm state
+ if (testWFlags(WState_Maximized)) {
+ net_winstates[curr_winstate++] = qt_net_wm_state_max_v;
+ net_winstates[curr_winstate++] = qt_net_wm_state_max_h;
+ }
+ }
+
+ // ### need a better way to do this
+ if (inherits("TQPopupMenu")) {
+ // menu netwm type
+ net_wintypes[curr_wintype++] = qt_net_wm_window_type_menu;
+ } else if (inherits("TQToolBar")) {
+ // toolbar netwm type
+ net_wintypes[curr_wintype++] = qt_net_wm_window_type_toolbar;
+ } else if (testWFlags(WStyle_Customize) && testWFlags(WStyle_Tool)) {
+ // utility netwm type
+ net_wintypes[curr_wintype++] = qt_net_wm_window_type_utility;
+ }
+
+ if (dialog) // dialog netwm type
+ net_wintypes[curr_wintype++] = qt_net_wm_window_type_dialog;
+ // normal netwm type - default
+ net_wintypes[curr_wintype++] = qt_net_wm_window_type_normal;
+
+ // stays on top
+ if (testWFlags(WStyle_StaysOnTop)) {
+ net_winstates[curr_winstate++] = qt_net_wm_state_above;
+ net_winstates[curr_winstate++] = qt_net_wm_state_stays_on_top;
+ }
+
+ if (testWFlags(WShowModal)) {
+ mwmhints.input_mode = 3L; // MWM_INPUT_FULL_APPLICATION_MODAL
+ mwmhints.flags |= (1L << 2); // MWM_HINTS_INPUT_MODE
+
+ net_winstates[curr_winstate++] = qt_net_wm_state_modal;
+ }
+
+ if ( testWFlags( WX11BypassWM ) ) {
+ wsa.override_redirect = True;
+ wsa_mask |= CWOverrideRedirect;
+ }
+
+ if ( wsa_mask && initializeWindow )
+ XChangeWindowAttributes( dpy, id, wsa_mask, &wsa );
+ } else {
+ if (! testWFlags(WStyle_Customize))
+ setWFlags(WStyle_NormalBorder | WStyle_Title |
+ WStyle_MinMax | WStyle_SysMenu);
+ }
+
+
+ if ( !initializeWindow ) {
+ // do no initialization
+ } else if ( popup ) { // popup widget
+ wsa.override_redirect = True;
+ wsa.save_under = True;
+ XChangeWindowAttributes( dpy, id, CWOverrideRedirect | CWSaveUnder,
+ &wsa );
+ } else if ( topLevel && !desktop ) { // top-level widget
+ TQWidget *p = parentWidget(); // real tqparent
+ if (p)
+ p = p->tqtopLevelWidget();
+
+ if (dialog || testWFlags(WStyle_DialogBorder) || testWFlags(WStyle_Tool)) {
+ if ( p )
+ XSetTransientForHint( dpy, id, p->winId() );
+ else // application-modal
+ XSetTransientForHint( dpy, id, root_win );
+ }
+
+ // tqfind the real client leader, i.e. a toplevel without tqparent
+ while ( p && p->parentWidget())
+ p = p->parentWidget()->tqtopLevelWidget();
+
+ XSizeHints size_hints;
+ size_hints.flags = USSize | PSize | PWinGravity;
+ size_hints.x = crect.left();
+ size_hints.y = crect.top();
+ size_hints.width = crect.width();
+ size_hints.height = crect.height();
+ size_hints.win_gravity =
+ TQApplication::reverseLayout() ? NorthEastGravity : NorthWestGravity;
+
+ XWMHints wm_hints; // window manager hints
+ wm_hints.input = True;
+ wm_hints.initial_state = NormalState;
+ wm_hints.flags = InputHint | StateHint;
+ if ( !qt_x11_wm_client_leader )
+ qt_x11_create_wm_client_leader();
+
+ wm_hints.window_group = qt_x11_wm_client_leader;
+ wm_hints.flags |= WindowGroupHint;
+
+ XClassHint class_hint;
+ class_hint.res_name = (char *) tqAppName(); // application name
+ class_hint.res_class = (char *) tqAppClass(); // application class
+
+ XSetWMProperties( dpy, id, 0, 0, 0, 0, &size_hints, &wm_hints, &class_hint );
+
+ XResizeWindow( dpy, id, crect.width(), crect.height() );
+ XStoreName( dpy, id, tqAppName() );
+ Atom protocols[4];
+ int n = 0;
+ protocols[n++] = qt_wm_delete_window; // support del window protocol
+ protocols[n++] = qt_wm_take_focus; // support take focus window protocol
+ protocols[n++] = qt_net_wm_ping; // support _NET_WM_PING protocol
+ if ( testWFlags( WStyle_ContextHelp ) )
+ protocols[n++] = qt_net_wm_context_help;
+ XSetWMProtocols( dpy, id, protocols, n );
+
+ // set mwm hints
+ if ( mwmhints.flags != 0l )
+ XChangeProperty(dpy, id, qt_xa_motif_wm_hints, qt_xa_motif_wm_hints, 32,
+ PropModeReplace, (unsigned char *) &mwmhints, 5);
+ else
+ XDeleteProperty(dpy, id, qt_xa_motif_wm_hints);
+
+ // set _NET_WM_WINDOW_TYPE
+ if (curr_wintype > 0)
+ XChangeProperty(dpy, id, qt_net_wm_window_type, XA_ATOM, 32, PropModeReplace,
+ (unsigned char *) net_wintypes, curr_wintype);
+ else
+ XDeleteProperty(dpy, id, qt_net_wm_window_type);
+
+ // set _NET_WM_WINDOW_STATE
+ if (curr_winstate > 0)
+ XChangeProperty(dpy, id, qt_net_wm_state, XA_ATOM, 32, PropModeReplace,
+ (unsigned char *) net_winstates, curr_winstate);
+ else
+ XDeleteProperty(dpy, id, qt_net_wm_state);
+
+ // set _NET_WM_PID
+ long curr_pid = getpid();
+ XChangeProperty(dpy, id, qt_net_wm_pid, XA_CARDINAL, 32, PropModeReplace,
+ (unsigned char *) &curr_pid, 1);
+
+ // when we create a toplevel widget, the frame strut should be dirty
+ fstrut_dirty = 1;
+
+ // declare the widget's object name as window role
+ XChangeProperty( dpy, id,
+ qt_window_role, XA_STRING, 8, PropModeReplace,
+ (unsigned char *)name(), tqstrlen( name() ) );
+
+ // set client leader property
+ XChangeProperty( dpy, id, qt_wm_client_leader,
+ XA_WINDOW, 32, PropModeReplace,
+ (unsigned char *)&qt_x11_wm_client_leader, 1 );
+ } else {
+ // non-toplevel widgets don't have a frame, so no need to
+ // update the strut
+ fstrut_dirty = 0;
+ }
+
+ if ( initializeWindow ) {
+ // don't erase when resizing
+ wsa.bit_gravity =
+ TQApplication::reverseLayout() ? NorthEastGravity : NorthWestGravity;
+ XChangeWindowAttributes( dpy, id, CWBitGravity, &wsa );
+ }
+
+ setWState( WState_MouseTracking );
+ setMouseTracking( FALSE ); // also sets event tqmask
+ if ( desktop ) {
+ setWState( WState_Visible );
+ } else if ( topLevel ) { // set X cursor
+ setWState( WState_OwnCursor );
+ if ( initializeWindow )
+ qt_x11_enforce_cursor( this );
+ }
+
+ if ( destroyw )
+ qt_XDestroyWindow( this, dpy, destroyw );
+}
+
+
+/*!
+ Frees up window system resources. Destroys the widget window if \a
+ destroyWindow is TRUE.
+
+ destroy() calls itself recursively for all the child widgets,
+ passing \a destroySubWindows for the \a destroyWindow parameter.
+ To have more control over destruction of subwidgets, destroy
+ subwidgets selectively first.
+
+ This function is usually called from the TQWidget destructor.
+*/
+
+void TQWidget::destroy( bool destroyWindow, bool destroySubWindows )
+{
+ deactivateWidgetCleanup();
+ if ( testWState(WState_Created) ) {
+ clearWState( WState_Created );
+ if ( childrenListObject() ) {
+ TQObjectListIt it(*childrenListObject());
+ register TQObject *obj;
+ while ( (obj=it.current()) ) { // destroy all widget tqchildren
+ ++it;
+ if ( obj->isWidgetType() )
+ ((TQWidget*)obj)->destroy(destroySubWindows,
+ destroySubWindows);
+ }
+ }
+ if ( mouseGrb == this )
+ releaseMouse();
+ if ( keyboardGrb == this )
+ releaseKeyboard();
+ if ( isTopLevel() )
+ qt_deferred_map_take( this );
+ if ( testWFlags(WShowModal) ) // just be sure we leave modal
+ qt_leave_modal( this );
+ else if ( testWFlags(WType_Popup) )
+ tqApp->closePopup( this );
+
+#ifndef TQT_NO_XFTFREETYPE
+ if ( rendhd) {
+ if ( destroyWindow )
+ XftDrawDestroy( (XftDraw *) rendhd );
+ else
+ free( (void*) rendhd );
+ rendhd = 0;
+ }
+#endif // TQT_NO_XFTFREETYPE
+
+ if ( testWFlags(WType_Desktop) ) {
+ if ( acceptDrops() )
+ qt_dnd_enable( this, FALSE );
+ } else {
+ if ( destroyWindow )
+ qt_XDestroyWindow( this, x11Display(), winid );
+ }
+ setWinId( 0 );
+
+ extern void qPRCleanup( TQWidget *widget ); // from qapplication_x11.cpp
+ if ( testWState(WState_Reparented) )
+ qPRCleanup(this);
+ }
+}
+
+void TQWidget::reparentSys( TQWidget *tqparent, WFlags f, const TQPoint &p, bool showIt )
+{
+ extern void qPRCreate( const TQWidget *, Window );
+
+ Display *dpy = x11Display();
+ TQCursor oldcurs;
+ bool setcurs = testWState(WState_OwnCursor);
+ if ( setcurs ) {
+ oldcurs = cursor();
+ unsetCursor();
+ }
+
+ // dnd unregister (we will register again below)
+ bool accept_drops = acceptDrops();
+ setAcceptDrops( FALSE );
+
+ // clear mouse tracking, re-enabled below
+ bool mouse_tracking = hasMouseTracking();
+ clearWState(WState_MouseTracking);
+
+ TQWidget* oldtlw = tqtopLevelWidget();
+ TQWidget *oldtqparent = parentWidget();
+ WId old_winid = winid;
+ if ( testWFlags(WType_Desktop) )
+ old_winid = 0;
+ setWinId( 0 );
+
+ // hide and reparent our own window away. Otherwise we might get
+ // destroyed when emitting the child remove event below. See TQWorkspace.
+ XUnmapWindow( x11Display(), old_winid );
+ XReparentWindow( x11Display(), old_winid,
+ RootWindow( x11Display(), x11Screen() ), 0, 0 );
+
+ if ( isTopLevel() ) {
+ // input contexts are associated with toplevel widgets, so we need
+ // destroy the context here. if we are reparenting back to toplevel,
+ // then we will have another context created, otherwise we will
+ // use our new toplevel's context
+ destroyInputContext();
+ }
+
+ if ( isTopLevel() || !tqparent ) // we are toplevel, or reparenting to toplevel
+ topData()->parentWinId = 0;
+
+ if ( tqparent != parentObj ) {
+ if ( parentObj ) // remove from tqparent
+ parentObj->removeChild( this );
+ if ( tqparent ) // insert into new tqparent
+ tqparent->insertChild( this );
+ }
+ bool enable = isEnabled(); // remember status
+ FocusPolicy fp = focusPolicy();
+ TQSize s = size();
+ TQPixmap *bgp = (TQPixmap *)backgroundPixmap();
+ TQColor bgc = bg_col; // save colors
+ TQString capt= caption();
+ widget_flags = f;
+ clearWState( WState_Created | WState_Visible | WState_ForceHide );
+ create();
+ if ( isTopLevel() || (!tqparent || tqparent->isVisible() ) )
+ setWState( WState_ForceHide ); // new widgets do not show up in already visible parents
+
+ const TQObjectList *chlist = childrenListObject();
+ if ( chlist ) { // reparent tqchildren
+ TQObjectList childList(*chlist);
+ TQObjectListIt it(childList); // iterate over copy
+ TQObject *obj;
+ while ( (obj=it.current()) ) {
+ if ( obj->isWidgetType() ) {
+ TQWidget *w = (TQWidget *)obj;
+ if ( !w->isTopLevel() ) {
+ XReparentWindow( x11Display(), w->winId(), winId(),
+ w->tqgeometry().x(), w->tqgeometry().y() );
+ } else if ( w->isPopup()
+ || w->testWFlags(WStyle_DialogBorder)
+ || w->testWFlags(WType_Dialog)
+ || w->testWFlags(WStyle_Tool) ) {
+ /*
+ when reparenting toplevel windows with toplevel-transient tqchildren,
+ we need to make sure that the window manager gets the updated
+ WM_TRANSIENT_FOR information... unfortunately, some window managers
+ don't handle changing WM_TRANSIENT_FOR before the toplevel window is
+ visible, so we unmap and remap all toplevel-transient tqchildren *after*
+ the toplevel tqparent has been mapped. thankfully, this is easy in TQt :)
+ */
+ XUnmapWindow(w->x11Display(), w->winId());
+ XSetTransientForHint(w->x11Display(), w->winId(), winId());
+ TQApplication::postEvent(w, new TQEvent(TQEvent::ShowWindowRequest));
+ }
+ }
+ ++it;
+ }
+ }
+ qPRCreate( this, old_winid );
+ if ( bgp )
+ XSetWindowBackgroundPixmap( dpy, winid, bgp->handle() );
+ else
+ XSetWindowBackground( dpy, winid, bgc.pixel(x11Screen()) );
+
+ if (isTopLevel()) {
+ // preserve maximized/fullscreen flags and the normal tqgeometry
+ uint save_state = widget_state & (WState_Maximized | WState_FullScreen);
+ const TQRect r = topData()->normalGeometry;
+ setGeometry(p.x(), p.y(), s.width(), s.height());
+ widget_state |= save_state;
+ topData()->normalGeometry = r;
+ } else {
+ setGeometry(p.x(), p.y(), s.width(), s.height());
+ }
+
+ setEnabled( enable );
+ setFocusPolicy( fp );
+ if ( !capt.isNull() ) {
+ extra->topextra->caption = TQString::null;
+ setCaption( capt );
+ }
+ if ( showIt )
+ show();
+ if ( old_winid )
+ qt_XDestroyWindow( this, dpy, old_winid );
+ if ( setcurs )
+ setCursor(oldcurs);
+
+ reparentFocusWidgets( oldtlw );
+
+ // re-register dnd
+ if (oldtqparent)
+ oldtqparent->checkChildrenDnd();
+
+ if ( accept_drops )
+ setAcceptDrops( TRUE );
+ else {
+ checkChildrenDnd();
+ topData()->dnd = 0;
+ qt_dnd_enable(this, (extra && extra->tqchildren_use_dnd));
+ }
+
+ // re-enable mouse tracking
+ if (mouse_tracking)
+ setMouseTracking(mouse_tracking);
+}
+
+
+/*!
+ Translates the widget coordinate \a pos to global screen
+ coordinates. For example, \c{mapToGlobal(TQPoint(0,0))} would give
+ the global coordinates of the top-left pixel of the widget.
+
+ \sa mapFromGlobal() mapTo() mapToParent()
+*/
+
+TQPoint TQWidget::mapToGlobal( const TQPoint &pos ) const
+{
+ int x, y;
+ Window child;
+ XTranslateCoordinates( x11Display(), winId(),
+ TQApplication::desktop()->screen(x11Screen())->winId(),
+ pos.x(), pos.y(), &x, &y, &child );
+ return TQPoint( x, y );
+}
+
+/*!
+ Translates the global screen coordinate \a pos to widget
+ coordinates.
+
+ \sa mapToGlobal() mapFrom() mapFromParent()
+*/
+
+TQPoint TQWidget::mapFromGlobal( const TQPoint &pos ) const
+{
+ int x, y;
+ Window child;
+ XTranslateCoordinates( x11Display(),
+ TQApplication::desktop()->screen(x11Screen())->winId(),
+ winId(), pos.x(), pos.y(), &x, &y, &child );
+ return TQPoint( x, y );
+}
+
+/*!
+ When a widget gets focus, it should call setMicroFocusHint() with
+ some appropriate position and size, \a x, \a y, \a width and \a
+ height. This has no \e visual effect, it just provides hints to
+ any system-specific input handling tools.
+
+ The \a text argument should be TRUE if this is a position for text
+ input.
+
+ In the Windows version of TQt, this method sets the system caret,
+ which is used for user Accessibility focus handling. If \a text
+ is TRUE, it also sets the IME composition window in Far East Asian
+ language input systems.
+
+ In the X11 version of TQt, if \a text is TRUE, this method sets the
+ XIM "spot" point for complex language input handling.
+
+ The font \a f is a rendering hint to the currently active input method.
+ If \a f is 0 the widget's font is used.
+
+ \sa microFocusHint()
+*/
+void TQWidget::setMicroFocusHint(int x, int y, int width, int height,
+ bool text, TQFont *f )
+{
+#ifndef TQT_NO_XIM
+ if ( text ) {
+ TQWidget* tlw = tqtopLevelWidget();
+ TQTLWExtra *topdata = tlw->topData();
+
+ // trigger input context creation if it hasn't happened already
+ createInputContext();
+ TQInputContext *qic = (TQInputContext *) topdata->xic;
+
+ if ( qt_xim && qic ) {
+ TQPoint p( x, y );
+ TQPoint p2 = mapTo( tqtopLevelWidget(), TQPoint( 0, 0 ) );
+ p = mapTo( tqtopLevelWidget(), p);
+ qic->setXFontSet( f ? *f : fnt );
+ qic->setComposePosition(p.x(), p.y() + height);
+ qic->setComposeArea(p2.x(), p2.y(), this->width(), this->height());
+ }
+ }
+#endif
+
+ if ( TQRect( x, y, width, height ) != microFocusHint() ) {
+ createExtra();
+ extraData()->micro_focus_hint.setRect( x, y, width, height );
+ }
+}
+
+
+void TQWidget::setFontSys( TQFont * )
+{
+ // Nothing
+}
+
+
+void TQWidget::setBackgroundColorDirect( const TQColor &color )
+{
+ bg_col = color;
+ if ( extra && extra->bg_pix ) { // kill the background pixmap
+ delete extra->bg_pix;
+ extra->bg_pix = 0;
+ }
+ XSetWindowBackground( x11Display(), winId(), bg_col.pixel(x11Screen()) );
+}
+
+static int allow_null_pixmaps = 0;
+
+
+void TQWidget::setBackgroundPixmapDirect( const TQPixmap &pixmap )
+{
+ TQPixmap old;
+ if ( extra && extra->bg_pix )
+ old = *extra->bg_pix;
+ if ( !allow_null_pixmaps && pixmap.isNull() ) {
+ XSetWindowBackground( x11Display(), winId(), bg_col.pixel(x11Screen()) );
+ if ( extra && extra->bg_pix ) {
+ delete extra->bg_pix;
+ extra->bg_pix = 0;
+ }
+ } else {
+ TQPixmap pm = pixmap;
+ if (!pm.isNull()) {
+ if ( pm.depth() == 1 && TQPixmap::defaultDepth() > 1 ) {
+ pm = TQPixmap( pixmap.size() );
+ bitBlt( &pm, 0, 0, &pixmap, 0, 0, pm.width(), pm.height() );
+ }
+ }
+ if ( extra && extra->bg_pix )
+ delete extra->bg_pix;
+ else
+ createExtra();
+ extra->bg_pix = new TQPixmap( pm );
+ TQ_CHECK_PTR( extra->bg_pix );
+ extra->bg_pix->x11SetScreen( x11Screen() );
+ XSetWindowBackgroundPixmap( x11Display(), winId(), extra->bg_pix->handle() );
+ if ( testWFlags(WType_Desktop) ) // save rootinfo later
+ qt_updated_rootinfo();
+ }
+}
+
+
+/*!
+ Sets the window-system background of the widget to nothing.
+
+ Note that "nothing" is actually a pixmap that isNull(), thus you
+ can check for an empty background by checking backgroundPixmap().
+
+ \sa setBackgroundPixmap(), setBackgroundColor()
+*/
+void TQWidget::setBackgroundEmpty()
+{
+ allow_null_pixmaps++;
+ setErasePixmap(TQPixmap());
+ allow_null_pixmaps--;
+}
+
+
+void TQWidget::setBackgroundX11Relative()
+{
+ XSetWindowBackgroundPixmap( x11Display(), winId(), ParentRelative );
+}
+
+void TQWidget::setCursor( const TQCursor &cursor )
+{
+ if ( cursor.handle() != arrowCursor.handle()
+ || (extra && extra->curs) ) {
+ createExtra();
+ delete extra->curs;
+ extra->curs = new TQCursor(cursor);
+ }
+ setWState( WState_OwnCursor );
+ qt_x11_enforce_cursor( this );
+ XFlush( x11Display() );
+}
+
+void TQWidget::unsetCursor()
+{
+ if ( extra ) {
+ delete extra->curs;
+ extra->curs = 0;
+ }
+ if ( !isTopLevel() )
+ clearWState( WState_OwnCursor );
+ qt_x11_enforce_cursor( this );
+ XFlush( x11Display() );
+}
+
+static XTextProperty*
+qstring_to_xtp( const TQString& s )
+{
+ static XTextProperty tp = { 0, 0, 0, 0 };
+ static bool free_prop = TRUE; // we can't free tp.value in case it references
+ // the data of the static TQCString below.
+ if ( tp.value ) {
+ if ( free_prop )
+ XFree( tp.value );
+ tp.value = 0;
+ free_prop = TRUE;
+ }
+
+ static const TQTextCodec* mapper = TQTextCodec::codecForLocale();
+ int errCode = 0;
+ if ( mapper ) {
+ TQCString mapped = mapper->fromUnicode(s);
+ char* tl[2];
+ tl[0] = mapped.data();
+ tl[1] = 0;
+ errCode = XmbTextListToTextProperty( TQPaintDevice::x11AppDisplay(),
+ tl, 1, XStdICCTextStyle, &tp );
+#if defined(TQT_DEBUG)
+ if ( errCode < 0 )
+ qDebug( "qstring_to_xtp result code %d", errCode );
+#endif
+ }
+ if ( !mapper || errCode < 0 ) {
+ static TQCString qcs;
+ qcs = s.ascii();
+ tp.value = (uchar*)qcs.data();
+ tp.encoding = XA_STRING;
+ tp.format = 8;
+ tp.nitems = qcs.length();
+ free_prop = FALSE;
+ }
+
+ // ### If we knew WM could understand tqunicode, we could use
+ // ### a much simpler, cheaper encoding...
+ /*
+ tp.value = (XChar2b*)s.tqunicode();
+ tp.encoding = XA_UNICODE; // wish
+ tp.format = 16;
+ tp.nitems = s.length();
+ */
+
+ return &tp;
+}
+
+void TQWidget::setCaption( const TQString &caption )
+{
+ if ( TQWidget::caption() == caption )
+ return;
+
+ topData()->caption = caption;
+ XSetWMName( x11Display(), winId(), qstring_to_xtp(caption) );
+
+ TQCString net_wm_name = caption.utf8();
+ XChangeProperty(x11Display(), winId(), qt_net_wm_name, qt_utf8_string, 8,
+ PropModeReplace, (unsigned char *)net_wm_name.data(),
+ net_wm_name.length());
+
+ TQEvent e( TQEvent::CaptionChange );
+ TQApplication::sendEvent( this, &e );
+}
+
+void TQWidget::setIcon( const TQPixmap &pixmap )
+{
+ if ( extra && extra->topextra ) {
+ delete extra->topextra->icon;
+ extra->topextra->icon = 0;
+ } else {
+ createTLExtra();
+ }
+ Pixmap icon_pixmap = 0;
+ Pixmap mask_pixmap = 0;
+ if ( !pixmap.isNull() ) {
+ TQPixmap* pm = new TQPixmap( pixmap );
+ extra->topextra->icon = pm;
+ if ( !pm->tqmask() )
+ pm->setMask( pm->createHeuristicMask() ); // may do detach()
+ icon_pixmap = pm->handle();
+ if ( pm->tqmask() )
+ mask_pixmap = pm->tqmask()->handle();
+ }
+ XWMHints *h = XGetWMHints( x11Display(), winId() );
+ XWMHints wm_hints;
+ bool got_hints = h != 0;
+ if ( !got_hints ) {
+ h = &wm_hints;
+ h->flags = 0;
+ }
+ h->icon_pixmap = icon_pixmap;
+ h->icon_mask = mask_pixmap;
+ h->flags |= IconPixmapHint | IconMaskHint;
+ XSetWMHints( x11Display(), winId(), h );
+ if ( got_hints )
+ XFree( (char *)h );
+ TQEvent e( TQEvent::IconChange );
+ TQApplication::sendEvent( this, &e );
+}
+
+void TQWidget::setIconText( const TQString &iconText )
+{
+ if (TQWidget::iconText() == iconText)
+ return;
+
+ topData()->iconText = iconText;
+ XSetWMIconName( x11Display(), winId(), qstring_to_xtp(iconText) );
+
+ TQCString net_wm_icon_name = iconText.utf8();
+ XChangeProperty(x11Display(), winId(), qt_net_wm_icon_name, qt_utf8_string, 8, PropModeReplace,
+ (unsigned char *) net_wm_icon_name.data(), net_wm_icon_name.length());
+}
+
+void TQWidget::setMouseTracking( bool enable )
+{
+ bool gmt = TQApplication::hasGlobalMouseTracking();
+ if ( !enable == !testWState(WState_MouseTracking) && !gmt )
+ return;
+ uint m = (enable || gmt) ? (uint)PointerMotionMask : 0;
+ if ( enable )
+ setWState( WState_MouseTracking );
+ else
+ clearWState( WState_MouseTracking );
+ if ( testWFlags(WType_Desktop) ) { // desktop widget?
+ TQWidget* main_desktop = tqfind( winId() );
+ if ( main_desktop->testWFlags(WPaintDesktop) )
+ XSelectInput( x11Display(), winId(),
+ stdDesktopEventMask | ExposureMask );
+ else
+ XSelectInput( x11Display(), winId(), stdDesktopEventMask );
+ } else {
+ XSelectInput( x11Display(), winId(),
+ m | stdWidgetEventMask );
+#if defined (TQT_TABLET_SUPPORT)
+ if ( devStylus != NULL ) {
+ XSelectExtensionEvent( x11Display(), winId(), event_list_stylus,
+ qt_curr_events_stylus );
+ }
+ if ( devEraser != NULL ) {
+ XSelectExtensionEvent( x11Display(), winId(), event_list_eraser,
+ qt_curr_events_eraser );
+ }
+#endif
+ }
+}
+
+
+/*!
+ Grabs the mouse input.
+
+ This widget receives all mouse events until releaseMouse() is
+ called; other widgets get no mouse events at all. Keyboard
+ events are not affected. Use grabKeyboard() if you want to grab
+ that.
+
+ \warning Bugs in mouse-grabbing applications very often lock the
+ terminal. Use this function with extreme caution, and consider
+ using the \c -nograb command line option while debugging.
+
+ It is almost never necessary to grab the mouse when using TQt, as
+ TQt grabs and releases it sensibly. In particular, TQt grabs the
+ mouse when a mouse button is pressed and keeps it until the last
+ button is released.
+
+ Note that only visible widgets can grab mouse input. If
+ isVisible() returns FALSE for a widget, that widget cannot call
+ grabMouse().
+
+ \sa releaseMouse() grabKeyboard() releaseKeyboard() grabKeyboard()
+ tqfocusWidget()
+*/
+
+void TQWidget::grabMouse()
+{
+ if ( isVisible() && !qt_nograb() ) {
+ if ( mouseGrb )
+ mouseGrb->releaseMouse();
+#if defined(TQT_CHECK_STATE)
+ int status =
+#endif
+ XGrabPointer( x11Display(), winId(), False,
+ (uint)( ButtonPressMask | ButtonReleaseMask |
+ PointerMotionMask | EnterWindowMask |
+ LeaveWindowMask ),
+ GrabModeAsync, GrabModeAsync,
+ None, None, GET_QT_X_TIME() );
+#if defined(TQT_CHECK_STATE)
+ if ( status ) {
+ const char *s =
+ status == GrabNotViewable ? "\"GrabNotViewable\"" :
+ status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" :
+ status == GrabFrozen ? "\"GrabFrozen\"" :
+ status == GrabInvalidTime ? "\"GrabInvalidTime\"" :
+ "<?>";
+ qWarning( "Grabbing the mouse failed with %s", s );
+ }
+#endif
+ mouseGrb = this;
+ }
+}
+
+/*!
+ \overload
+
+ Grabs the mouse input and changes the cursor tqshape.
+
+ The cursor will assume tqshape \a cursor (for as long as the mouse
+ focus is grabbed) and this widget will be the only one to receive
+ mouse events until releaseMouse() is called().
+
+ \warning Grabbing the mouse might lock the terminal.
+
+ \sa releaseMouse(), grabKeyboard(), releaseKeyboard(), setCursor()
+*/
+
+void TQWidget::grabMouse( const TQCursor &cursor )
+{
+ if ( !qt_nograb() ) {
+ if ( mouseGrb )
+ mouseGrb->releaseMouse();
+#if defined(TQT_CHECK_STATE)
+ int status =
+#endif
+ XGrabPointer( x11Display(), winId(), False,
+ (uint)(ButtonPressMask | ButtonReleaseMask |
+ PointerMotionMask | EnterWindowMask | LeaveWindowMask),
+ GrabModeAsync, GrabModeAsync,
+ None, cursor.handle(), GET_QT_X_TIME() );
+#if defined(TQT_CHECK_STATE)
+ if ( status ) {
+ const char *s =
+ status == GrabNotViewable ? "\"GrabNotViewable\"" :
+ status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" :
+ status == GrabFrozen ? "\"GrabFrozen\"" :
+ status == GrabInvalidTime ? "\"GrabInvalidTime\"" :
+ "<?>";
+ qWarning( "Grabbing the mouse failed with %s", s );
+ }
+#endif
+ mouseGrb = this;
+ }
+}
+
+/*!
+ Releases the mouse grab.
+
+ \sa grabMouse(), grabKeyboard(), releaseKeyboard()
+*/
+
+void TQWidget::releaseMouse()
+{
+ if ( !qt_nograb() && mouseGrb == this ) {
+ XUngrabPointer( x11Display(), GET_QT_X_TIME() );
+ XFlush( x11Display() );
+ mouseGrb = 0;
+ }
+}
+
+/*!
+ Grabs the keyboard input.
+
+ This widget reveives all keyboard events until releaseKeyboard()
+ is called; other widgets get no keyboard events at all. Mouse
+ events are not affected. Use grabMouse() if you want to grab that.
+
+ The focus widget is not affected, except that it doesn't receive
+ any keyboard events. setFocus() moves the focus as usual, but the
+ new focus widget receives keyboard events only after
+ releaseKeyboard() is called.
+
+ If a different widget is currently grabbing keyboard input, that
+ widget's grab is released first.
+
+ \sa releaseKeyboard() grabMouse() releaseMouse() tqfocusWidget()
+*/
+
+void TQWidget::grabKeyboard()
+{
+ if ( !qt_nograb() ) {
+ if ( keyboardGrb )
+ keyboardGrb->releaseKeyboard();
+ XGrabKeyboard( x11Display(), winid, False, GrabModeAsync, GrabModeAsync,
+ GET_QT_X_TIME() );
+ keyboardGrb = this;
+ }
+}
+
+/*!
+ Releases the keyboard grab.
+
+ \sa grabKeyboard(), grabMouse(), releaseMouse()
+*/
+
+void TQWidget::releaseKeyboard()
+{
+ if ( !qt_nograb() && keyboardGrb == this ) {
+ XUngrabKeyboard( x11Display(), GET_QT_X_TIME() );
+ keyboardGrb = 0;
+ }
+}
+
+
+/*!
+ Returns the widget that is currently grabbing the mouse input.
+
+ If no widget in this application is currently grabbing the mouse,
+ 0 is returned.
+
+ \sa grabMouse(), keyboardGrabber()
+*/
+
+TQWidget *TQWidget::mouseGrabber()
+{
+ return mouseGrb;
+}
+
+/*!
+ Returns the widget that is currently grabbing the keyboard input.
+
+ If no widget in this application is currently grabbing the
+ keyboard, 0 is returned.
+
+ \sa grabMouse(), mouseGrabber()
+*/
+
+TQWidget *TQWidget::keyboardGrabber()
+{
+ return keyboardGrb;
+}
+
+/*!
+ Sets the top-level widget containing this widget to be the active
+ window.
+
+ An active window is a visible top-level window that has the
+ keyboard input focus.
+
+ This function performs the same operation as clicking the mouse on
+ the title bar of a top-level window. On X11, the result depends on
+ the Window Manager. If you want to ensure that the window is
+ stacked on top as well you should also call raise(). Note that the
+ window must be visible, otherwise setActiveWindow() has no effect.
+
+ On Windows, if you are calling this when the application is not
+ currently the active one then it will not make it the active
+ window. It will flash the task bar entry blue to indicate that
+ the window has done something. This is because Microsoft do not
+ allow an application to interrupt what the user is currently doing
+ in another application.
+
+ \sa isActiveWindow(), tqtopLevelWidget(), show()
+*/
+
+void TQWidget::setActiveWindow()
+{
+ TQWidget *tlw = tqtopLevelWidget();
+ if ( tlw->isVisible() && !tlw->topData()->embedded && !qt_deferred_map_tqcontains(tlw) ) {
+ XSetInputFocus( x11Display(), tlw->winId(), RevertToNone, GET_QT_X_TIME());
+ focusInputContext();
+ }
+}
+
+
+/*!
+ Updates the widget unless updates are disabled or the widget is
+ hidden.
+
+ This function does not cause an immediate tqrepaint; instead it
+ schedules a paint event for processing when TQt returns to the main
+ event loop. This permits TQt to optimize for more speed and less
+ flicker than a call to tqrepaint() does.
+
+ Calling update() several times normally results in just one
+ paintEvent() call.
+
+ TQt normally erases the widget's area before the paintEvent() call.
+ If the \c WRepaintNoErase widget flag is set, the widget is
+ responsible for painting all its pixels itself.
+
+ \sa tqrepaint(), paintEvent(), setUpdatesEnabled(), erase(),
+ setWFlags()
+*/
+
+void TQWidget::update()
+{
+ if ( (widget_state & (WState_Visible|WState_BlockUpdates)) ==
+ WState_Visible )
+ TQApplication::postEvent( this, new TQPaintEvent( clipRegion(), !testWFlags(WRepaintNoErase) ) );
+}
+
+/*!
+ \overload
+
+ Updates a rectangle (\a x, \a y, \a w, \a h) inside the widget
+ unless updates are disabled or the widget is hidden.
+
+ This function does not cause an immediate tqrepaint; instead it
+ schedules a paint event for processing when TQt returns to the main
+ event loop. This permits TQt to optimize for more speed and less
+ flicker and a call to tqrepaint() does.
+
+ Calling update() several times normally results in just one
+ paintEvent() call.
+
+ If \a w is negative, it is tqreplaced with \c{width() - x}. If \a h
+ is negative, it is tqreplaced width \c{height() - y}.
+
+ TQt normally erases the specified area before the paintEvent()
+ call. If the \c WRepaintNoErase widget flag is set, the widget is
+ responsible for painting all its pixels itself.
+
+ \sa tqrepaint(), paintEvent(), setUpdatesEnabled(), erase()
+*/
+
+void TQWidget::update( int x, int y, int w, int h )
+{
+ if ( w && h &&
+ (widget_state & (WState_Visible|WState_BlockUpdates)) == WState_Visible ) {
+ if ( w < 0 )
+ w = crect.width() - x;
+ if ( h < 0 )
+ h = crect.height() - y;
+ if ( w != 0 && h != 0 )
+ TQApplication::postEvent( this,
+ new TQPaintEvent( clipRegion().intersect(TQRect(x,y,w,h)),
+ !testWFlags( WRepaintNoErase ) ) );
+ }
+}
+
+/*!
+ \overload void TQWidget::update( const TQRect &r )
+
+ Updates a rectangle \a r inside the widget unless updates are
+ disabled or the widget is hidden.
+
+ This function does not cause an immediate tqrepaint; instead it
+ schedules a paint event for processing when TQt returns to the main
+ event loop. This permits TQt to optimize for more speed and less
+ flicker and a call to tqrepaint() does.
+
+ Calling update() several times normally results in just one
+ paintEvent() call.
+*/
+
+/*!
+ \overload void TQWidget::tqrepaint( bool erase )
+
+ This version repaints the entire widget.
+*/
+
+/*!
+ \overload void TQWidget::tqrepaint()
+
+ This version erases and repaints the entire widget.
+*/
+
+/*!
+ Repaints the widget directly by calling paintEvent() immediately,
+ unless updates are disabled or the widget is hidden.
+
+ If \a erase is TRUE, TQt erases the area \a (x, y, w, h) before the
+ paintEvent() call.
+
+ If \a w is negative, it is tqreplaced with \c{width() - x}, and if
+ \a h is negative, it is tqreplaced width \c{height() - y}.
+
+ We suggest only using tqrepaint() if you need an immediate tqrepaint,
+ for example during animation. In almost all circumstances update()
+ is better, as it permits TQt to optimize for speed and minimize
+ flicker.
+
+ \warning If you call tqrepaint() in a function which may itself be
+ called from paintEvent(), you may get infinite recursion. The
+ update() function never causes recursion.
+
+ \sa update(), paintEvent(), setUpdatesEnabled(), erase()
+*/
+
+void TQWidget::tqrepaint( int x, int y, int w, int h, bool erase )
+{
+ if ( (widget_state & (WState_Visible|WState_BlockUpdates)) == WState_Visible ) {
+ if ( x > crect.width() || y > crect.height() )
+ return;
+ if ( w < 0 )
+ w = crect.width() - x;
+ if ( h < 0 )
+ h = crect.height() - y;
+ TQRect r(x,y,w,h);
+ if ( r.isEmpty() )
+ return; // nothing to do
+ TQPaintEvent e( r, erase );
+ if ( r != rect() )
+ qt_set_paintevent_clipping( this, r );
+ if ( erase && w != 0 && h != 0 ) {
+ if ( backgroundOrigin() == WidgetOrigin )
+ XClearArea( x11Display(), winId(), x, y, w, h, False );
+ else
+ this->erase( x, y, w, h);
+ }
+ TQApplication::sendEvent( this, &e );
+ qt_clear_paintevent_clipping();
+ }
+}
+
+/*!
+ \overload
+
+ Repaints the widget directly by calling paintEvent() directly,
+ unless updates are disabled or the widget is hidden.
+
+ Erases the widget region \a reg if \a erase is TRUE.
+
+ Only use tqrepaint if your widget needs to be repainted immediately,
+ for example when doing some animation. In all other cases, use
+ update(). Calling update() many times in a row will generate a
+ single paint event.
+
+ \warning If you call tqrepaint() in a function which may itself be
+ called from paintEvent(), you may get infinite recursion. The
+ update() function never causes recursion.
+
+ \sa update(), paintEvent(), setUpdatesEnabled(), erase()
+*/
+
+void TQWidget::tqrepaint( const TQRegion& reg, bool erase )
+{
+ if ( (widget_state & (WState_Visible|WState_BlockUpdates)) == WState_Visible ) {
+ TQPaintEvent e( reg, erase );
+ qt_set_paintevent_clipping( this, reg );
+ if ( erase )
+ this->erase(reg);
+ TQApplication::sendEvent( this, &e );
+ qt_clear_paintevent_clipping();
+ }
+}
+
+/*!
+ \overload void TQWidget::tqrepaint( const TQRect &r, bool erase )
+
+ Repaints the widget directly by calling paintEvent() directly,
+ unless updates are disabled or the widget is hidden.
+
+ Erases the widget region \a r if \a erase is TRUE.
+*/
+
+void TQWidget::setWindowState(uint newstate)
+{
+ bool needShow = FALSE;
+ uint oldstate = windowState();
+ if (isTopLevel()) {
+ TQTLWExtra *top = topData();
+
+ if ((oldstate & WindowMaximized) != (newstate & WindowMaximized)) {
+ if (qt_net_supports(qt_net_wm_state_max_h) && qt_net_supports(qt_net_wm_state_max_v)) {
+ qt_net_change_wm_state(this, (newstate & WindowMaximized),
+ qt_net_wm_state_max_h, qt_net_wm_state_max_v);
+ } else if (! (newstate & WindowFullScreen)) {
+ if (newstate & WindowMaximized) {
+ // save original tqgeometry
+ const TQRect normalGeometry = tqgeometry();
+
+ if (isVisible()) {
+ updateFrameStrut();
+ const TQRect maxRect = TQApplication::desktop()->availableGeometry(this);
+ const TQRect r = top->normalGeometry;
+ setGeometry(maxRect.x() + top->fleft,
+ maxRect.y() + top->ftop,
+ maxRect.width() - top->fleft - top->fright,
+ maxRect.height() - top->ftop - top->fbottom);
+ top->normalGeometry = r;
+ }
+
+ if (top->normalGeometry.width() < 0)
+ top->normalGeometry = normalGeometry;
+ } else {
+ // restore original tqgeometry
+ setGeometry(top->normalGeometry);
+ }
+ }
+ }
+
+ if ((oldstate & WindowFullScreen) != (newstate & WindowFullScreen)) {
+ if (qt_net_supports(qt_net_wm_state_fullscreen)) {
+ qt_net_change_wm_state(this, (newstate & WindowFullScreen),
+ qt_net_wm_state_fullscreen);
+ } else {
+ needShow = isVisible();
+
+ if (newstate & WindowFullScreen) {
+ const TQRect normalGeometry = TQRect(pos(), size());
+
+ top->savedFlags = getWFlags();
+ reparent(0, WType_TopLevel | WStyle_Customize | WStyle_NoBorder |
+ // preserve some widget flags
+ (getWFlags() & 0xffff0000),
+ mapToGlobal(TQPoint(0, 0)));
+ const TQRect r = top->normalGeometry;
+ setGeometry(tqApp->desktop()->screenGeometry(this));
+ top->normalGeometry = r;
+
+ if ( top->normalGeometry.width() < 0 )
+ top->normalGeometry = normalGeometry;
+ } else {
+ reparent( 0, top->savedFlags, mapToGlobal(TQPoint(0, 0)) );
+
+ if (newstate & WindowMaximized) {
+ // from fullscreen to maximized
+ updateFrameStrut();
+ const TQRect maxRect = TQApplication::desktop()->availableGeometry(this);
+ const TQRect r = top->normalGeometry;
+ setGeometry(maxRect.x() + top->fleft,
+ maxRect.y() + top->ftop,
+ maxRect.width() - top->fleft - top->fright,
+ maxRect.height() - top->ftop - top->fbottom);
+ top->normalGeometry = r;
+ } else {
+ // restore original tqgeometry
+ setGeometry(top->normalGeometry);
+ }
+ }
+ }
+ }
+
+ if ((oldstate & WindowMinimized) != (newstate & WindowMinimized)) {
+ if (isVisible()) {
+ if (newstate & WindowMinimized) {
+ XEvent e;
+ e.xclient.type = ClientMessage;
+ e.xclient.message_type = qt_wm_change_state;
+ e.xclient.display = x11Display();
+ e.xclient.window = winid;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = IconicState;
+ e.xclient.data.l[1] = 0;
+ e.xclient.data.l[2] = 0;
+ e.xclient.data.l[3] = 0;
+ e.xclient.data.l[4] = 0;
+ XSendEvent(x11Display(), RootWindow(x11Display(), x11Screen()),
+ False, (SubstructureNotifyMask|SubstructureRedirectMask), &e);
+ } else {
+ XMapWindow(x11Display(), winId());
+ }
+ }
+
+ needShow = FALSE;
+ }
+ }
+
+ widget_state &= ~(WState_Minimized | WState_Maximized | WState_FullScreen);
+ if (newstate & WindowMinimized)
+ widget_state |= WState_Minimized;
+ if (newstate & WindowMaximized)
+ widget_state |= WState_Maximized;
+ if (newstate & WindowFullScreen)
+ widget_state |= WState_FullScreen;
+
+ if (needShow)
+ show();
+
+ if (newstate & WindowActive)
+ setActiveWindow();
+
+ TQEvent e(TQEvent::WindowStateChange);
+ TQApplication::sendEvent(this, &e);
+}
+
+/*!
+ \internal
+ Platform-specific part of TQWidget::show().
+*/
+
+void TQWidget::showWindow()
+{
+ if ( isTopLevel() ) {
+ XWMHints *h = XGetWMHints( x11Display(), winId() );
+ XWMHints wm_hints;
+ bool got_hints = h != 0;
+ if ( !got_hints ) {
+ h = &wm_hints;
+ h->flags = 0;
+ }
+ h->initial_state = testWState(WState_Minimized) ? IconicState : NormalState;
+ h->flags |= StateHint;
+ XSetWMHints( x11Display(), winId(), h );
+ if ( got_hints )
+ XFree( (char *)h );
+
+ if (GET_QT_X_USER_TIME() != CurrentTime) {
+ Time my_tqx_user_time = GET_QT_X_USER_TIME();
+ XChangeProperty(x11Display(), winId(), qt_net_wm_user_time, XA_CARDINAL,
+ 32, PropModeReplace, (unsigned char *) &my_tqx_user_time, 1);
+ SET_QT_X_USER_TIME(my_tqx_user_time);
+ }
+
+ if (!topData()->embedded &&
+ topData()->parentWinId &&
+ topData()->parentWinId != TQPaintDevice::x11AppRootWindow(x11Screen()) &&
+ !isMinimized() ) {
+ qt_deferred_map_add( this );
+ return;
+ }
+
+ if (isMaximized() && !isFullScreen()
+ && !(qt_net_supports(qt_net_wm_state_max_h)
+ && qt_net_supports(qt_net_wm_state_max_v))) {
+ XMapWindow( x11Display(), winId() );
+ qt_wait_for_window_manager(this);
+
+ // if the wm was not smart enough to adjust our size, do that manually
+ updateFrameStrut();
+ TQRect maxRect = TQApplication::desktop()->availableGeometry(this);
+
+ TQTLWExtra *top = topData();
+ TQRect normalRect = top->normalGeometry;
+
+ setGeometry(maxRect.x() + top->fleft,
+ maxRect.y() + top->ftop,
+ maxRect.width() - top->fleft - top->fright,
+ maxRect.height() - top->ftop - top->fbottom);
+
+ // restore the original normalGeometry
+ top->normalGeometry = normalRect;
+ // internalSetGeometry() clears the maximized flag... make sure we set it back
+ setWState(WState_Maximized);
+
+ return;
+ }
+
+ if (isFullScreen() && !qt_net_supports(qt_net_wm_state_fullscreen)) {
+ XMapWindow(x11Display(), winId());
+ qt_wait_for_window_manager(this);
+ return;
+ }
+ }
+ XMapWindow( x11Display(), winId() );
+}
+
+
+/*!
+ \internal
+ Platform-specific part of TQWidget::hide().
+*/
+
+void TQWidget::hideWindow()
+{
+ clearWState( WState_Exposed );
+ deactivateWidgetCleanup();
+ if ( isTopLevel() ) {
+ qt_deferred_map_take( this );
+ if ( winId() ) // in nsplugin, may be 0
+ XWithdrawWindow( x11Display(), winId(), x11Screen() );
+
+ TQTLWExtra *top = topData();
+ crect.moveTopLeft( TQPoint(crect.x() - top->fleft, crect.y() - top->ftop ) );
+
+ // zero the frame strut and mark it dirty
+ top->fleft = top->fright = top->ftop = top->fbottom = 0;
+ fstrut_dirty = TRUE;
+
+ XFlush( x11Display() );
+ } else {
+ if ( winId() ) // in nsplugin, may be 0
+ XUnmapWindow( x11Display(), winId() );
+ }
+}
+
+/*!
+ Raises this widget to the top of the tqparent widget's stack.
+
+ After this call the widget will be visually in front of any
+ overlapping sibling widgets.
+
+ \sa lower(), stackUnder()
+*/
+
+void TQWidget::raise()
+{
+ TQWidget *p = parentWidget();
+ if ( p && p->childObjects && p->childObjects->tqfindRef(this) >= 0 )
+ p->childObjects->append( p->childObjects->take() );
+ XRaiseWindow( x11Display(), winId() );
+}
+
+/*!
+ Lowers the widget to the bottom of the tqparent widget's stack.
+
+ After this call the widget will be visually behind (and therefore
+ obscured by) any overlapping sibling widgets.
+
+ \sa raise(), stackUnder()
+*/
+
+void TQWidget::lower()
+{
+ TQWidget *p = parentWidget();
+ if ( p && p->childObjects && p->childObjects->tqfindRef(this) >= 0 )
+ p->childObjects->insert( 0, p->childObjects->take() );
+ XLowerWindow( x11Display(), winId() );
+}
+
+
+/*!
+ Places the widget under \a w in the tqparent widget's stack.
+
+ To make this work, the widget itself and \a w must be siblings.
+
+ \sa raise(), lower()
+*/
+void TQWidget::stackUnder( TQWidget* w)
+{
+ TQWidget *p = parentWidget();
+ if ( !w || isTopLevel() || p != w->parentWidget() || this == w )
+ return;
+ if ( p && p->childObjects && p->childObjects->tqfindRef(w) >= 0 && p->childObjects->tqfindRef(this) >= 0 ) {
+ p->childObjects->take();
+ p->childObjects->insert( p->childObjects->tqfindRef(w), this );
+ }
+ Window stack[2];
+ stack[0] = w->winId();;
+ stack[1] = winId();
+ XRestackWindows( x11Display(), stack, 2 );
+}
+
+
+
+/*
+ The global variable qt_widget_tlw_gravity defines the window gravity of
+ the next top level window to be created. We do this when setting the
+ main widget's tqgeometry and the "-tqgeometry" command line option tqcontains
+ a negative position.
+*/
+
+int qt_widget_tlw_gravity = NorthWestGravity;
+
+static void do_size_hints( TQWidget* widget, TQWExtra *x )
+{
+ XSizeHints s;
+ s.flags = 0;
+ if ( x ) {
+ s.x = widget->x();
+ s.y = widget->y();
+ s.width = widget->width();
+ s.height = widget->height();
+ if ( x->minw > 0 || x->minh > 0 ) { // add minimum size hints
+ s.flags |= PMinSize;
+ s.min_width = x->minw;
+ s.min_height = x->minh;
+ }
+ if ( x->maxw < TQWIDGETSIZE_MAX || x->maxh < TQWIDGETSIZE_MAX ) {
+ s.flags |= PMaxSize; // add maximum size hints
+ s.max_width = x->maxw;
+ s.max_height = x->maxh;
+ }
+ if ( x->topextra &&
+ (x->topextra->incw > 0 || x->topextra->inch > 0) )
+ { // add resize increment hints
+ s.flags |= PResizeInc | PBaseSize;
+ s.width_inc = x->topextra->incw;
+ s.height_inc = x->topextra->inch;
+ s.base_width = x->topextra->basew;
+ s.base_height = x->topextra->baseh;
+ }
+
+ if ( x->topextra && x->topextra->uspos) {
+ s.flags |= USPosition;
+ s.flags |= PPosition;
+ }
+ if ( x->topextra && x->topextra->ussize) {
+ s.flags |= USSize;
+ s.flags |= PSize;
+ }
+ }
+ s.flags |= PWinGravity;
+ s.win_gravity = qt_widget_tlw_gravity; // usually NorthWest
+ // reset in case it was set
+ qt_widget_tlw_gravity =
+ TQApplication::reverseLayout() ? NorthEastGravity : NorthWestGravity;
+ XSetWMNormalHints( widget->x11Display(), widget->winId(), &s );
+}
+
+
+void TQWidget::internalSetGeometry( int x, int y, int w, int h, bool isMove )
+{
+ Display *dpy = x11Display();
+
+ if ( testWFlags(WType_Desktop) )
+ return;
+ if (isTopLevel()) {
+ if (!qt_net_supports(qt_net_wm_state_max_h)
+ && !qt_net_supports(qt_net_wm_state_max_v))
+ clearWState(WState_Maximized);
+ if (!qt_net_supports(qt_net_wm_state_fullscreen))
+ clearWState(WState_FullScreen);
+ topData()->normalGeometry = TQRect(0, 0, -1, -1);
+ } else {
+ // for TQWorkspace
+ clearWState(WState_Maximized);
+ clearWState(WState_FullScreen);
+ }
+ if ( extra ) { // any size restrictions?
+ w = TQMIN(w,extra->maxw);
+ h = TQMIN(h,extra->maxh);
+ w = TQMAX(w,extra->minw);
+ h = TQMAX(h,extra->minh);
+ }
+ if ( w < 1 ) // invalid size
+ w = 1;
+ if ( h < 1 )
+ h = 1;
+ TQPoint oldPos( pos() );
+ TQSize oldSize( size() );
+ TQRect oldGeom( crect );
+ TQRect r( x, y, w, h );
+
+ // We only care about stuff that changes the tqgeometry, or may
+ // cause the window manager to change its state
+ if ( !isTopLevel() && oldGeom == r )
+ return;
+
+ crect = r;
+ bool isResize = size() != oldSize;
+
+ if ( isTopLevel() ) {
+ if ( isMove )
+ topData()->uspos = 1;
+ if ( isResize )
+ topData()->ussize = 1;
+ do_size_hints( this, extra );
+ }
+
+ if ( isMove ) {
+ if (! qt_broken_wm)
+ // pos() is right according to ICCCM 4.1.5
+ XMoveResizeWindow( dpy, winid, pos().x(), pos().y(), w, h );
+ else
+ // work around 4Dwm's incompliance with ICCCM 4.1.5
+ XMoveResizeWindow( dpy, winid, x, y, w, h );
+ } else if ( isResize )
+ XResizeWindow( dpy, winid, w, h );
+
+ if ( isVisible() ) {
+ if ( isMove && pos() != oldPos ) {
+ if ( ! qt_broken_wm ) {
+ // pos() is right according to ICCCM 4.1.5
+ TQMoveEvent e( pos(), oldPos );
+ TQApplication::sendEvent( this, &e );
+ } else {
+ // work around 4Dwm's incompliance with ICCCM 4.1.5
+ TQMoveEvent e( crect.topLeft(), oldGeom.topLeft() );
+ TQApplication::sendEvent( this, &e );
+ }
+ }
+ if ( isResize ) {
+
+ // set config pending only on resize, see qapplication_x11.cpp, translateConfigEvent()
+ setWState( WState_ConfigPending );
+
+ TQResizeEvent e( size(), oldSize );
+ TQApplication::sendEvent( this, &e );
+ }
+ } else {
+ if ( isMove && pos() != oldPos ) {
+ if ( ! qt_broken_wm )
+ // pos() is right according to ICCCM 4.1.5
+ TQApplication::postEvent( this, new TQMoveEvent( pos(), oldPos ) );
+ else
+ // work around 4Dwm's incompliance with ICCCM 4.1.5
+ TQApplication::postEvent( this, new TQMoveEvent( crect.topLeft(),
+ oldGeom.topLeft() ) );
+ }
+ if ( isResize )
+ TQApplication::postEvent( this,
+ new TQResizeEvent( size(), oldSize ) );
+ }
+}
+
+
+/*!
+ \overload
+
+ This function corresponds to setMinimumSize( TQSize(minw, minh) ).
+ Sets the minimum width to \a minw and the minimum height to \a
+ minh.
+*/
+
+void TQWidget::setMinimumSize( int minw, int minh )
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( minw < 0 || minh < 0 )
+ qWarning("TQWidget::setMinimumSize: The smallest allowed size is (0,0)");
+#endif
+ createExtra();
+ if ( extra->minw == minw && extra->minh == minh )
+ return;
+ extra->minw = minw;
+ extra->minh = minh;
+ if ( minw > width() || minh > height() ) {
+ bool resized = testWState( WState_Resized );
+ resize( TQMAX(minw,width()), TQMAX(minh,height()) );
+ if ( !resized )
+ clearWState( WState_Resized ); // not a user resize
+ }
+ if ( testWFlags(WType_TopLevel) )
+ do_size_hints( this, extra );
+ updateGeometry();
+}
+
+/*!
+ \overload
+
+ This function corresponds to setMaximumSize( TQSize(\a maxw, \a
+ maxh) ). Sets the maximum width to \a maxw and the maximum height
+ to \a maxh.
+*/
+void TQWidget::setMaximumSize( int maxw, int maxh )
+{
+#if defined(TQT_CHECK_RANGE)
+ if ( maxw > TQWIDGETSIZE_MAX || maxh > TQWIDGETSIZE_MAX ) {
+ qWarning("TQWidget::setMaximumSize: (%s/%s) "
+ "The largest allowed size is (%d,%d)",
+ name( "unnamed" ), className(), TQWIDGETSIZE_MAX,
+ TQWIDGETSIZE_MAX );
+ maxw = TQMIN( maxw, TQWIDGETSIZE_MAX );
+ maxh = TQMIN( maxh, TQWIDGETSIZE_MAX );
+ }
+ if ( maxw < 0 || maxh < 0 ) {
+ qWarning("TQWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
+ "are not possible",
+ name( "unnamed" ), className(), maxw, maxh );
+ maxw = TQMAX( maxw, 0 );
+ maxh = TQMAX( maxh, 0 );
+ }
+#endif
+ createExtra();
+ if ( extra->maxw == maxw && extra->maxh == maxh )
+ return;
+ extra->maxw = maxw;
+ extra->maxh = maxh;
+ if ( maxw < width() || maxh < height() ) {
+ bool resized = testWState( WState_Resized );
+ resize( TQMIN(maxw,width()), TQMIN(maxh,height()) );
+ if ( !resized )
+ clearWState( WState_Resized ); // not a user resize
+ }
+ if ( testWFlags(WType_TopLevel) )
+ do_size_hints( this, extra );
+ updateGeometry();
+}
+
+/*!
+ \overload
+
+ Sets the x (width) size increment to \a w and the y (height) size
+ increment to \a h.
+*/
+void TQWidget::setSizeIncrement( int w, int h )
+{
+ TQTLWExtra* x = topData();
+ if ( x->incw == w && x->inch == h )
+ return;
+ x->incw = w;
+ x->inch = h;
+ if ( testWFlags(WType_TopLevel) )
+ do_size_hints( this, extra );
+}
+
+/*!
+ \overload
+
+ This corresponds to setBaseSize( TQSize(\a basew, \a baseh) ). Sets
+ the widgets base size to width \a basew and height \a baseh.
+*/
+void TQWidget::setBaseSize( int basew, int baseh )
+{
+ createTLExtra();
+ TQTLWExtra* x = topData();
+ if ( x->basew == basew && x->baseh == baseh )
+ return;
+ x->basew = basew;
+ x->baseh = baseh;
+ if ( testWFlags(WType_TopLevel) )
+ do_size_hints( this, extra );
+}
+
+/*!
+ \overload void TQWidget::erase()
+
+ This version erases the entire widget.
+*/
+
+/*!
+ \overload void TQWidget::erase( const TQRect &r )
+
+ Erases the specified area \a r in the widget without generating a
+ \link paintEvent() paint event\endlink.
+*/
+
+/*!
+ Erases the specified area \a (x, y, w, h) in the widget without
+ generating a \link paintEvent() paint event\endlink.
+
+ If \a w is negative, it is tqreplaced with \c{width() - x}. If \a h
+ is negative, it is tqreplaced width \c{height() - y}.
+
+ Child widgets are not affected.
+
+ \sa tqrepaint()
+*/
+
+void TQWidget::erase( int x, int y, int w, int h )
+{
+ extern void qt_erase_rect( TQWidget*, const TQRect& ); // in qpainer_x11.cpp
+ if ( w < 0 )
+ w = crect.width() - x;
+ if ( h < 0 )
+ h = crect.height() - y;
+ if ( w != 0 && h != 0 )
+ qt_erase_rect( this, TQRect(x, y, w, h ) );
+}
+
+/*!
+ \overload
+
+ Erases the area defined by \a reg, without generating a \link
+ paintEvent() paint event\endlink.
+
+ Child widgets are not affected.
+*/
+
+void TQWidget::erase( const TQRegion& reg )
+{
+ extern void qt_erase_region( TQWidget*, const TQRegion& ); // in qpainer_x11.cpp
+ qt_erase_region( this, reg );
+}
+
+/*!
+ Scrolls the widget including its tqchildren \a dx pixels to the
+ right and \a dy downwards. Both \a dx and \a dy may be negative.
+
+ After scrolling, scroll() sends a paint event for the the part
+ that is read but not written. For example, when scrolling 10
+ pixels rightwards, the leftmost ten pixels of the widget need
+ repainting. The paint event may be delivered immediately or later,
+ depending on some heuristics (note that you might have to force
+ processing of paint events using TQApplication::sendPostedEvents()
+ when using scroll() and move() in combination).
+
+ \sa TQScrollView erase() bitBlt()
+*/
+
+void TQWidget::scroll( int dx, int dy )
+{
+ scroll( dx, dy, TQRect() );
+}
+
+/*!
+ \overload
+
+ This version only scrolls \a r and does not move the tqchildren of
+ the widget.
+
+ If \a r is empty or invalid, the result is undefined.
+
+ \sa TQScrollView erase() bitBlt()
+*/
+void TQWidget::scroll( int dx, int dy, const TQRect& r )
+{
+ if ( testWState( WState_BlockUpdates ) && !childrenListObject() )
+ return;
+ bool valid_rect = r.isValid();
+ bool just_update = TQABS( dx ) > width() || TQABS( dy ) > height();
+ if ( just_update )
+ update();
+ TQRect sr = valid_rect?r:clipRegion().boundingRect();
+ int x1, y1, x2, y2, w=sr.width(), h=sr.height();
+ if ( dx > 0 ) {
+ x1 = sr.x();
+ x2 = x1+dx;
+ w -= dx;
+ } else {
+ x2 = sr.x();
+ x1 = x2-dx;
+ w += dx;
+ }
+ if ( dy > 0 ) {
+ y1 = sr.y();
+ y2 = y1+dy;
+ h -= dy;
+ } else {
+ y2 = sr.y();
+ y1 = y2-dy;
+ h += dy;
+ }
+
+ if ( dx == 0 && dy == 0 )
+ return;
+
+ Display *dpy = x11Display();
+ GC gc = qt_xget_readonly_gc( x11Screen(), FALSE );
+ // Want expose events
+ if ( w > 0 && h > 0 && !just_update ) {
+ XSetGraphicsExposures( dpy, gc, True );
+ XCopyArea( dpy, winId(), winId(), gc, x1, y1, w, h, x2, y2);
+ XSetGraphicsExposures( dpy, gc, False );
+ }
+
+ if ( !valid_rect && childrenListObject() ) { // scroll tqchildren
+ TQPoint pd( dx, dy );
+ TQObjectListIt it(*childrenListObject());
+ register TQObject *object;
+ while ( it ) { // move all tqchildren
+ object = it.current();
+ if ( object->isWidgetType() ) {
+ TQWidget *w = (TQWidget *)object;
+ w->move( w->pos() + pd );
+ }
+ ++it;
+ }
+ }
+
+ if ( just_update )
+ return;
+
+ // Don't let the server be bogged-down with tqrepaint events
+ bool repaint_immediately = qt_sip_count( this ) < 3;
+
+ if ( dx ) {
+ int x = x2 == sr.x() ? sr.x()+w : sr.x();
+ if ( repaint_immediately )
+ tqrepaint( x, sr.y(), TQABS(dx), sr.height(), !testWFlags(WRepaintNoErase) );
+ else
+ XClearArea( dpy, winid, x, sr.y(), TQABS(dx), sr.height(), True );
+ }
+ if ( dy ) {
+ int y = y2 == sr.y() ? sr.y()+h : sr.y();
+ if ( repaint_immediately )
+ tqrepaint( sr.x(), y, sr.width(), TQABS(dy), !testWFlags(WRepaintNoErase) );
+ else
+ XClearArea( dpy, winid, sr.x(), y, sr.width(), TQABS(dy), True );
+ }
+
+ qt_insert_sip( this, dx, dy ); // #### ignores r
+}
+
+
+/*!
+ \overload void TQWidget::drawText( const TQPoint &pos, const TQString& str )
+
+ Draws the string \a str at position \a pos.
+*/
+
+/*!
+ Draws the string \a str at position \a(x, y).
+
+ The \a y position is the base line position of the text. The text
+ is drawn using the default font and the default foreground color.
+
+ This function is provided for convenience. You will generally get
+ more flexible results and often higher speed by using a a \link
+ TQPainter painter\endlink instead.
+
+ \sa setFont(), foregroundColor(), TQPainter::drawText()
+*/
+
+void TQWidget::drawText( int x, int y, const TQString &str )
+{
+ if ( testWState(WState_Visible) ) {
+ TQPainter paint;
+ paint.begin( this );
+ paint.drawText( x, y, str );
+ paint.end();
+ }
+}
+
+
+/*!
+ Internal implementation of the virtual TQPaintDevice::metric()
+ function.
+
+ Use the TQPaintDeviceMetrics class instead.
+
+ \a m is the metric to get.
+*/
+
+int TQWidget::metric( int m ) const
+{
+ int val;
+ if ( m == TQPaintDeviceMetrics::PdmWidth ) {
+ val = crect.width();
+ } else if ( m == TQPaintDeviceMetrics::PdmHeight ) {
+ val = crect.height();
+ } else {
+ Display *dpy = x11Display();
+ int scr = x11Screen();
+ switch ( m ) {
+ case TQPaintDeviceMetrics::PdmDpiX:
+ case TQPaintDeviceMetrics::PdmPhysicalDpiX:
+ val = TQPaintDevice::x11AppDpiX( scr );
+ break;
+ case TQPaintDeviceMetrics::PdmDpiY:
+ case TQPaintDeviceMetrics::PdmPhysicalDpiY:
+ val = TQPaintDevice::x11AppDpiY( scr );
+ break;
+ case TQPaintDeviceMetrics::PdmWidthMM:
+ val = (DisplayWidthMM(dpy,scr)*crect.width())/
+ DisplayWidth(dpy,scr);
+ break;
+ case TQPaintDeviceMetrics::PdmHeightMM:
+ val = (DisplayHeightMM(dpy,scr)*crect.height())/
+ DisplayHeight(dpy,scr);
+ break;
+ case TQPaintDeviceMetrics::PdmNumColors:
+ val = x11Cells();
+ break;
+ case TQPaintDeviceMetrics::PdmDepth:
+ val = x11Depth();
+ break;
+ default:
+ val = 0;
+#if defined(TQT_CHECK_RANGE)
+ qWarning( "TQWidget::metric: Invalid metric command" );
+#endif
+ }
+ }
+ return val;
+}
+
+void TQWidget::createSysExtra()
+{
+ extra->xDndProxy = 0;
+ extra->tqchildren_use_dnd = FALSE;
+ extra->compress_events = TRUE;
+}
+
+void TQWidget::deleteSysExtra()
+{
+}
+
+void TQWidget::createTLSysExtra()
+{
+ // created lazily
+ extra->topextra->xic = 0;
+}
+
+void TQWidget::deleteTLSysExtra()
+{
+ destroyInputContext();
+}
+
+/*
+ examine the tqchildren of our tqparent up the tree and set the
+ tqchildren_use_dnd extra data appropriately... this is used to keep DND enabled
+ for widgets that are reparented and don't have DND enabled, BUT *DO* have
+ tqchildren (or tqchildren of tqchildren ...) with DND enabled...
+*/
+void TQWidget::checkChildrenDnd()
+{
+ TQWidget *widget = this;
+ const TQObjectList *tqchildren;
+ const TQObject *object;
+ const TQWidget *child;
+ while (widget && ! widget->isDesktop()) {
+ // note: this isn't done for the desktop widget
+
+ bool tqchildren_use_dnd = FALSE;
+ tqchildren = widget->childrenListObject();
+ if ( tqchildren ) {
+ TQObjectListIt it(*tqchildren);
+ while ( (object = it.current()) ) {
+ ++it;
+ if ( object->isWidgetType() ) {
+ child = (const TQWidget *) object;
+ tqchildren_use_dnd = (tqchildren_use_dnd ||
+ child->acceptDrops() ||
+ (child->extra &&
+ child->extra->tqchildren_use_dnd));
+ }
+ }
+ }
+
+ widget->createExtra();
+ widget->extra->tqchildren_use_dnd = tqchildren_use_dnd;
+
+ widget = widget->parentWidget();
+ }
+}
+
+/*!
+ \property TQWidget::acceptDrops
+ \brief whether drop events are enabled for this widget
+
+ Setting this property to TRUE announces to the system that this
+ widget \e may be able to accept drop events.
+
+ If the widget is the desktop (TQWidget::isDesktop()), this may
+ fail if another application is using the desktop; you can call
+ acceptDrops() to test if this occurs.
+
+ \warning
+ Do not modify this property in a Drag&Drop event handler.
+*/
+bool TQWidget::acceptDrops() const
+{
+ return testWState( WState_DND );
+}
+
+void TQWidget::setAcceptDrops( bool on )
+{
+ if ( testWState(WState_DND) != on ) {
+ if ( qt_dnd_enable( this, on ) ) {
+ if ( on )
+ setWState( WState_DND );
+ else
+ clearWState( WState_DND );
+ }
+
+ checkChildrenDnd();
+ }
+}
+
+/*!
+ \overload
+
+ Causes only the parts of the widget which overlap \a region to be
+ visible. If the region includes pixels outside the rect() of the
+ widget, window system controls in that area may or may not be
+ visible, depending on the platform.
+
+ Note that this effect can be slow if the region is particularly
+ complex.
+
+ \sa setMask(), clearMask()
+*/
+
+void TQWidget::setMask( const TQRegion& region )
+{
+ XShapeCombineRegion( x11Display(), winId(), ShapeBounding, 0, 0,
+ region.handle(), ShapeSet );
+}
+
+/*!
+ Causes only the pixels of the widget for which \a bitmap has a
+ corresponding 1 bit to be visible. Use TQt::color0 to draw
+ transtqparent regions and TQt::color1 to draw opaque regions of the
+ bitmap.
+
+ If the region includes pixels outside the rect() of the widget,
+ window system controls in that area may or may not be visible,
+ depending on the platform.
+
+ Note that this effect can be slow if the region is particularly
+ complex.
+
+ See \c examples/tux for an example of masking for transparency.
+
+ \sa setMask(), clearMask()
+*/
+
+void TQWidget::setMask( const TQBitmap &bitmap )
+{
+ TQBitmap bm = bitmap;
+ if ( bm.x11Screen() != x11Screen() )
+ bm.x11SetScreen( x11Screen() );
+ XShapeCombineMask( x11Display(), winId(), ShapeBounding, 0, 0,
+ bm.handle(), ShapeSet );
+}
+
+/*!
+ Removes any tqmask set by setMask().
+
+ \sa setMask()
+*/
+
+void TQWidget::clearMask()
+{
+ XShapeCombineMask( x11Display(), winId(), ShapeBounding, 0, 0,
+ None, ShapeSet );
+}
+
+/*!\reimp
+ */
+void TQWidget::setName( const char *name )
+{
+ TQObject::setName( name );
+ if ( isTopLevel() ) {
+ XChangeProperty( x11Display(), winId(),
+ qt_window_role, XA_STRING, 8, PropModeReplace,
+ (unsigned char *)name, tqstrlen( name ) );
+ }
+}
+
+
+/*!
+ \internal
+
+ Computes the frame rectangle when needed. This is an internal function, you
+ should never call this.
+*/
+
+void TQWidget::updateFrameStrut() const
+{
+ TQWidget *that = (TQWidget *) this;
+
+ if (! isVisible() || isDesktop()) {
+ that->fstrut_dirty = (! isVisible());
+ return;
+ }
+
+ Atom type_ret;
+ Window l = winId(), w = winId(), p, r; // target window, it's tqparent, root
+ Window *c;
+ int i_unused;
+ unsigned int nc;
+ unsigned char *data_ret;
+ unsigned long l_unused;
+
+ while (XQueryTree(TQPaintDevice::x11AppDisplay(), w, &r, &p, &c, &nc)) {
+ if (c && nc > 0)
+ XFree(c);
+
+ if (! p) {
+ qWarning("TQWidget::updateFrameStrut(): ERROR - no tqparent");
+ return;
+ }
+
+ // if the tqparent window is the root window, an Enlightenment virtual root or
+ // a NET WM virtual root window, stop here
+ data_ret = 0;
+ if (p == r ||
+ (XGetWindowProperty(TQPaintDevice::x11AppDisplay(), p,
+ qt_enlightenment_desktop, 0, 1, False, XA_CARDINAL,
+ &type_ret, &i_unused, &l_unused, &l_unused,
+ &data_ret) == Success &&
+ type_ret == XA_CARDINAL)) {
+ if (data_ret)
+ XFree(data_ret);
+
+ break;
+ } else if (qt_net_supports(qt_net_virtual_roots) && qt_net_virtual_root_list) {
+ int i = 0;
+ while (qt_net_virtual_root_list[i] != 0) {
+ if (qt_net_virtual_root_list[i++] == p)
+ break;
+ }
+ }
+
+ l = w;
+ w = p;
+ }
+
+ // we have our window
+ int transx, transy;
+ XWindowAttributes wattr;
+ if (XTranslateCoordinates(TQPaintDevice::x11AppDisplay(), l, w,
+ 0, 0, &transx, &transy, &p) &&
+ XGetWindowAttributes(TQPaintDevice::x11AppDisplay(), w, &wattr)) {
+ TQTLWExtra *top = that->topData();
+ top->fleft = transx;
+ top->ftop = transy;
+ top->fright = wattr.width - crect.width() - top->fleft;
+ top->fbottom = wattr.height - crect.height() - top->ftop;
+
+ // add the border_width for the window managers frame... some window managers
+ // do not use a border_width of zero for their frames, and if we the left and
+ // top strut, we ensure that pos() is absolutely correct. frameGeometry()
+ // will still be incorrect though... perhaps i should have foffset as well, to
+ // indicate the frame offset (equal to the border_width on X).
+ // - Brad
+ top->fleft += wattr.border_width;
+ top->fright += wattr.border_width;
+ top->ftop += wattr.border_width;
+ top->fbottom += wattr.border_width;
+ }
+
+ that->fstrut_dirty = 0;
+}
+
+
+void TQWidget::createInputContext()
+{
+ TQWidget *tlw = tqtopLevelWidget();
+ TQTLWExtra *topdata = tlw->topData();
+
+#ifndef TQT_NO_XIM
+ if (qt_xim) {
+ if (! topdata->xic) {
+ TQInputContext *qic = new TQInputContext(tlw);
+ topdata->xic = (void *) qic;
+ }
+ } else
+#endif // TQT_NO_XIM
+ {
+ // qDebug("TQWidget::createInputContext: no xim");
+ topdata->xic = 0;
+ }
+}
+
+
+void TQWidget::destroyInputContext()
+{
+#ifndef TQT_NO_XIM
+ TQInputContext *qic = (TQInputContext *) extra->topextra->xic;
+ delete qic;
+#endif // TQT_NO_XIM
+ extra->topextra->xic = 0;
+}
+
+
+/*!
+ This function is called when the user finishes input composition,
+ e.g. changes focus to another widget, moves the cursor, etc.
+*/
+void TQWidget::resetInputContext()
+{
+#ifndef TQT_NO_XIM
+ if ((qt_xim_style & XIMPreeditCallbacks) && hasFocus()) {
+ TQWidget *tlw = tqtopLevelWidget();
+ TQTLWExtra *topdata = tlw->topData();
+
+ // trigger input context creation if it hasn't happened already
+ createInputContext();
+
+ if (topdata->xic) {
+ TQInputContext *qic = (TQInputContext *) topdata->xic;
+ qic->reset();
+ }
+ }
+#endif // TQT_NO_XIM
+}
+
+
+void TQWidget::focusInputContext()
+{
+#ifndef TQT_NO_XIM
+ TQWidget *tlw = tqtopLevelWidget();
+ if (!tlw->isPopup() || isInputMethodEnabled()) {
+ TQTLWExtra *topdata = tlw->topData();
+
+ // trigger input context creation if it hasn't happened already
+ createInputContext();
+
+ if (topdata->xic) {
+ TQInputContext *qic = (TQInputContext *) topdata->xic;
+ qic->setFocus();
+ }
+ }
+#endif // TQT_NO_XIM
+}
+
+void TQWidget::setWindowOpacity(double)
+{
+}
+
+double TQWidget::windowOpacity() const
+{
+ return 1.0;
+}
+
+#endif // USE_QT4
diff --git a/tqtinterface/qt4/src/kernel/tqwidgetcreate_x11.cpp b/tqtinterface/qt4/src/kernel/tqwidgetcreate_x11.cpp
new file mode 100644
index 0000000..574374d
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwidgetcreate_x11.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Implementation of TQt calls to X11
+**
+** Created : 970529
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqwidget.h"
+#include "tqt_x11_p.h"
+
+
+/*
+ Internal TQt functions to create X windows. We have put them in
+ separate functions to allow the programmer to reimplement them by
+ custom versions.
+*/
+
+Window qt_XCreateWindow( const TQWidget*, Display *display, Window tqparent,
+ int x, int y, uint w, uint h,
+ int borderwidth, int depth,
+ uint windowclass, Visual *visual,
+ ulong valuetqmask, XSetWindowAttributes *attributes )
+{
+ return XCreateWindow( display, tqparent, x, y, w, h, borderwidth, depth,
+ windowclass, visual, valuetqmask, attributes );
+}
+
+
+Window qt_XCreateSimpleWindow( const TQWidget*, Display *display, Window tqparent,
+ int x, int y, uint w, uint h, int borderwidth,
+ ulong border, ulong background )
+{
+ return XCreateSimpleWindow( display, tqparent, x, y, w, h, borderwidth,
+ border, background );
+}
+
+
+void qt_XDestroyWindow( const TQWidget*, Display *display, Window window )
+{
+ XDestroyWindow( display, window );
+}
diff --git a/tqtinterface/qt4/src/kernel/tqwidgetintdict.h b/tqtinterface/qt4/src/kernel/tqwidgetintdict.h
new file mode 100644
index 0000000..751c950
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwidgetintdict.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Definition of TQWidgetIntDict
+**
+** Created : 950116
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWIDGETINTDICT_H
+#define TQWIDGETINTDICT_H
+
+#ifndef TQT_H
+#include "tqwidget.h"
+#include "tqintdict.h"
+#endif // TQT_H
+
+
+#if defined(TQ_TEMPLATEDLL)
+//TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQIntDict<TQWidget>;
+//TQ_TEMPLATE_EXTERN template class TQ_EXPORT TQIntDictIterator<TQWidget>;
+#endif
+
+
+class TQ_EXPORT TQWidgetIntDict : public TQIntDict<TQWidget>
+{
+public:
+ TQWidgetIntDict(int size=17) : TQIntDict<TQWidget>(size) {}
+ TQWidgetIntDict( const TQWidgetIntDict &dict ) : TQIntDict<TQWidget>(dict) {}
+ ~TQWidgetIntDict() { clear(); }
+ TQWidgetIntDict &operator=(const TQWidgetIntDict &dict)
+ { return (TQWidgetIntDict&)TQIntDict<TQWidget>::operator=(dict); }
+};
+
+class TQ_EXPORT TQWidgetIntDictIt : public TQIntDictIterator<TQWidget>
+{
+public:
+ TQWidgetIntDictIt( const TQWidgetIntDict &d ) : TQIntDictIterator<TQWidget>(d) {}
+ TQWidgetIntDictIt &operator=(const TQWidgetIntDictIt &i)
+ { return (TQWidgetIntDictIt&)TQIntDictIterator<TQWidget>::operator=(i); }
+};
+
+
+#endif
diff --git a/tqtinterface/qt4/src/kernel/tqwidgetlist.h b/tqtinterface/qt4/src/kernel/tqwidgetlist.h
new file mode 100644
index 0000000..19505a8
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwidgetlist.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Definition of TQWidgetList
+**
+** Created : 950116
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWIDGETLIST_H
+#define TQWIDGETLIST_H
+
+#ifndef TQT_H
+#include "tqwidget.h"
+#include "tqptrlist.h"
+#endif // TQT_H
+
+class TQ_EXPORT TQWidgetList : public TQPtrList<TQWidget>
+{
+public:
+ TQWidgetList() : TQPtrList<TQWidget>() {}
+ TQWidgetList( const TQWidgetList &list ) : TQPtrList<TQWidget>(list) {}
+ ~TQWidgetList() { clear(); }
+ TQWidgetList &operator=(const TQWidgetList &list)
+ { return (TQWidgetList&)TQPtrList<TQWidget>::operator=(list); }
+};
+
+class TQ_EXPORT TQWidgetListIt : public TQPtrListIterator<TQWidget>
+{
+public:
+ TQWidgetListIt( const TQWidgetList &l ) : TQPtrListIterator<TQWidget>(l) {}
+ TQWidgetListIt &operator=(const TQWidgetListIt &i)
+ { return (TQWidgetListIt&)TQPtrListIterator<TQWidget>::operator=(i); }
+};
+
+#endif // TQWIDGETLIST_H
diff --git a/tqtinterface/qt4/src/kernel/tqwindow.cpp b/tqtinterface/qt4/src/kernel/tqwindow.cpp
new file mode 100644
index 0000000..d41de4b
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwindow.cpp
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Implementation of TQWindow class
+**
+** Created : 931211
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
diff --git a/tqtinterface/qt4/src/kernel/tqwindow.h b/tqtinterface/qt4/src/kernel/tqwindow.h
new file mode 100644
index 0000000..8ed306a
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwindow.h
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Definition of TQWindow class
+**
+** Created : 931112
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWINDOW_H
+#define TQWINDOW_H
+
+#error "TQWindow has gone away"
+
+#endif // TQWINDOW_H
diff --git a/tqtinterface/qt4/src/kernel/tqwindowdefs.h b/tqtinterface/qt4/src/kernel/tqwindowdefs.h
new file mode 100644
index 0000000..e6218f3
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwindowdefs.h
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Definition of general window system dependent functions, types and
+** constants
+**
+** Created : 931029
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWINDOWDEFS_H
+#define TQWINDOWDEFS_H
+
+#ifndef TQT_H
+#include "tqobjectdefs.h"
+#include "tqstring.h"
+#include "tqnamespace.h"
+#endif // TQT_H
+
+// Class forward definitions
+
+class TQPaintDevice;
+class TQPaintDeviceMetrics;
+class TQWidget;
+class TQWidgetMapper;
+class TQDialog;
+class TQColor;
+class TQColorGroup;
+class TQPalette;
+class TQCursor;
+class TQPoint;
+class TQSize;
+class TQRect;
+class TQPointArray;
+class TQPainter;
+class TQRegion;
+class TQFont;
+class TQFontMetrics;
+class TQFontInfo;
+class TQPen;
+class TQBrush;
+class TQWMatrix;
+class TQPixmap;
+class TQBitmap;
+class TQMovie;
+class TQImage;
+class TQImageIO;
+class TQPicture;
+class TQPrinter;
+class TQAccel;
+class TQTimer;
+class TQTime;
+class TQClipboard;
+
+
+// Widget list (defined in tqwidgetlist.h)
+
+class TQWidgetList;
+class TQWidgetListIt;
+
+
+// Window system dependent definitions
+
+#if defined(TQ_WS_MAC)
+#if TQT_MACOSX_VERSION < 0x1020
+typedef struct OpaqueEventLoopTimerRef* EventLoopTimerRef;
+typedef struct OpaqueMenuHandle *MenuRef;
+#else
+typedef struct __EventLoopTimer* EventLoopTimerRef;
+typedef struct OpaqueMenuRef* MenuRef;
+#endif
+
+#ifndef TQ_WS_MACX
+typedef struct CGContext *CGContextRef;
+#endif
+typedef struct OpaqueWindowGroupRef *WindowGroupRef;
+typedef struct OpaqueGrafPtr *CGrafPtr;
+typedef struct OpaquePMPrintSession *PMPrintSession;
+typedef struct OpaquePMPrintSettings *PMPrintSettings;
+typedef struct OpaquePMPageFormat *PMPageFormat;
+typedef struct Point Point;
+typedef struct OpaqueEventHandlerRef* EventHandlerRef;
+typedef struct OpaqueEventHandlerCallRef* EventHandlerCallRef;
+typedef struct OpaqueEventRef* EventRef;
+typedef long int OStqStatus;
+typedef struct OpaqueScrapRef *ScrapRef;
+typedef struct OpaqueRgnHandle *RgnHandle;
+typedef struct OpaqueWindowPtr *WindowPtr;
+typedef WindowPtr WindowRef;
+typedef struct OpaqueGrafPtr *GWorldPtr;
+typedef GWorldPtr GrafPtr;
+typedef struct GDevice **GDHandle;
+typedef struct ColorTable ColorTable;
+typedef struct BitMap BitMap;
+typedef struct EventRecord EventRecord;
+typedef void * MSG;
+typedef int WId;
+typedef struct AEDesc AppleEvent;
+
+#endif // TQ_WS_MAC
+
+#if defined(TQ_WS_WIN)
+#include "tqwindowdefs_win.h"
+#endif // TQ_WS_WIN
+
+
+#if defined(TQ_OS_TEMP)
+#include "tqwinfunctions_wce.h"
+#endif // TQ_OS_TEMP
+
+#if defined(TQ_WS_X11)
+
+typedef struct _XDisplay Display;
+typedef union _XEvent XEvent;
+typedef struct _XGC *GC;
+typedef struct _XRegion *Region;
+typedef unsigned long WId;
+
+TQ_EXPORT Display *qt_xdisplay();
+TQ_EXPORT int qt_xscreen();
+TQ_EXPORT WId qt_xrootwin(); // ### REMOVE 4.0
+TQ_EXPORT WId qt_xrootwin( int scrn ); // ### 4.0 add default arg of -1
+TQ_EXPORT GC qt_xget_readonly_gc( int scrn, bool monochrome );
+TQ_EXPORT GC qt_xget_temp_gc( int scrn, bool monochrome );
+
+TQ_EXPORT const char *tqAppClass(); // get application class
+
+#endif // TQ_WS_X11
+
+#if defined(TQ_WS_TQWS)
+
+typedef unsigned long WId;
+struct TQWSEvent;
+class TQGfx;
+
+#endif // TQ_WS_TQWS
+
+class TQApplication;
+
+#if defined(NEEDS_TQMAIN)
+#define main qMain
+#endif
+
+// Global platform-independent types and functions
+
+typedef TQ_INT32 TQCOORD; // coordinate type
+const TQCOORD TQCOORD_MAX = 2147483647;
+const TQCOORD TQCOORD_MIN = -TQCOORD_MAX - 1;
+
+typedef unsigned int TQRgb; // RGB triplet
+
+TQ_EXPORT const char *tqAppName(); // get application name
+
+// Misc functions
+
+typedef void (*TQtCleanUpFunction)();
+TQ_EXPORT void qAddPostRoutine( TQtCleanUpFunction );
+TQ_EXPORT void qRemovePostRoutine( TQtCleanUpFunction );
+
+#if !defined(TQT_CLEAN_NAMESPACE)
+// source compatibility with TQt 2.x
+typedef TQtCleanUpFunction TQ_CleanUpFunction;
+#endif
+
+
+#endif // TQWINDOWDEFS_H
diff --git a/tqtinterface/qt4/src/kernel/tqwmatrix.cpp b/tqtinterface/qt4/src/kernel/tqwmatrix.cpp
new file mode 100644
index 0000000..ffa0388
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwmatrix.cpp
@@ -0,0 +1,1204 @@
+/****************************************************************************
+**
+** Implementation of TQWMatrix class
+**
+** Created : 941020
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqwmatrix.h"
+#include "tqdatastream.h"
+#include "tqregion.h"
+#if defined(TQ_WS_X11)
+double qsincos( double, bool calcCos ); // defined in qpainter_x11.cpp
+#else
+#include <math.h>
+#endif
+
+#include <limits.h>
+
+#ifndef TQT_NO_WMATRIX
+
+#ifdef USE_QT4
+
+// some defines to inline some code
+#define MAPDOUBLE( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = m11()*fx + m21()*fy + dx(); \
+ ny = m12()*fx + m22()*fy + dy(); \
+}
+
+#define MAPINT( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = tqRound(m11()*fx + m21()*fy + dx()); \
+ ny = tqRound(m12()*fx + m22()*fy + dy()); \
+}
+
+struct TQWMDoublePoint {
+ double x;
+ double y;
+};
+
+bool qt_old_transformations = TRUE;
+
+// TQWMatrix TQWMatrix::invert(bool *invertible=0) {
+// return convertFromQMatrix(inverted(invertible));
+// }
+
+/*!
+ Sets the transformation mode that TQWMatrix and painter
+ transformations use to \a m.
+
+ \sa TQWMatrix::TransformationMode
+*/
+void TQWMatrix::setTransformationMode( TQWMatrix::TransformationMode m )
+{
+ printf("[WARNING] TQWMatrix::setTransformationMode has no effect!\n\r");
+
+ if ( m == TQWMatrix::Points )
+ qt_old_transformations = TRUE;
+ else
+ qt_old_transformations = FALSE;
+}
+
+
+/*!
+ Returns the current transformation mode.
+
+ \sa TQWMatrix::TransformationMode
+*/
+TQWMatrix::TransformationMode TQWMatrix::transformationMode()
+{
+ return (qt_old_transformations ? TQWMatrix::Points : TQWMatrix::Areas );
+}
+
+/*!
+ \internal
+*/
+TQPointArray TQWMatrix::operator *( const TQPointArray &a ) const
+{
+ if( qt_old_transformations ) {
+ TQPointArray result = a.copy();
+ int x, y;
+ for ( int i=0; i<(int)result.size(); i++ ) {
+ result.point( i, &x, &y );
+ MAPINT( x, y, x, y );
+ result.setPoint( i, x, y );
+ }
+ return result;
+ } else {
+ int size = a.size();
+ int i;
+ TQMemArray<TQWMDoublePoint> p( size );
+ const TQPoint *da = TQT_TQPOINT_CONST(a.data());
+ TQWMDoublePoint *dp = p.data();
+ double xmin = INT_MAX;
+ double ymin = xmin;
+ double xmax = INT_MIN;
+ double ymax = xmax;
+ int xminp = 0;
+ int yminp = 0;
+ for( i = 0; i < size; i++ ) {
+ dp[i].x = da[i].x();
+ dp[i].y = da[i].y();
+ if ( dp[i].x < xmin ) {
+ xmin = dp[i].x;
+ xminp = i;
+ }
+ if ( dp[i].y < ymin ) {
+ ymin = dp[i].y;
+ yminp = i;
+ }
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ double w = TQMAX( xmax - xmin, 1 );
+ double h = TQMAX( ymax - ymin, 1 );
+ for( i = 0; i < size; i++ ) {
+ dp[i].x += (dp[i].x - xmin)/w;
+ dp[i].y += (dp[i].y - ymin)/h;
+ MAPDOUBLE( dp[i].x, dp[i].y, dp[i].x, dp[i].y );
+ }
+
+ // now apply correction back for transformed values...
+ xmin = INT_MAX;
+ ymin = xmin;
+ xmax = INT_MIN;
+ ymax = xmax;
+ for( i = 0; i < size; i++ ) {
+ xmin = TQMIN( xmin, dp[i].x );
+ ymin = TQMIN( ymin, dp[i].y );
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ w = TQMAX( xmax - xmin, 1 );
+ h = TQMAX( ymax - ymin, 1 );
+
+ TQPointArray result( size );
+ TQPoint *dr = TQT_TQPOINT(result.data());
+ for( i = 0; i < size; i++ ) {
+ dr[i].setX( tqRound( dp[i].x - (dp[i].x - dp[xminp].x)/w ) );
+ dr[i].setY( tqRound( dp[i].y - (dp[i].y - dp[yminp].y)/h ) );
+ }
+ return result;
+ }
+}
+
+/*!
+ Returns the result of multiplying this matrix by matrix \a m.
+*/
+
+TQWMatrix &TQWMatrix::operator*=( const TQWMatrix &m )
+{
+ double tm11 = m11()*m.m11() + m12()*m.m21();
+ double tm12 = m11()*m.m12() + m12()*m.m22();
+ double tm21 = m21()*m.m11() + m22()*m.m21();
+ double tm22 = m21()*m.m12() + m22()*m.m22();
+
+ double tdx = dx()*m.m11() + dy()*m.m21() + m.dx();
+ double tdy = dx()*m.m12() + dy()*m.m22() + m.dy();
+
+ *this = TQWMatrix(tm11, tm12, tm21, tm22, tdx, tdy);
+
+ return *this;
+}
+
+/*!
+ \overload
+ \relates TQWMatrix
+ Returns the product of \a m1 * \a m2.
+
+ Note that matrix multiplication is not commutative, i.e. a*b !=
+ b*a.
+*/
+
+TQWMatrix operator*( const TQWMatrix &m1, const TQWMatrix &m2 )
+{
+ TQWMatrix result = m1;
+ result *= m2;
+ return result;
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQWMatrix tqwmatrix.h
+ \brief The TQWMatrix class specifies 2D transformations of a
+ coordinate system.
+
+ \ingroup graphics
+ \ingroup images
+
+ The standard coordinate system of a \link TQPaintDevice paint
+ tqdevice\endlink has the origin located at the top-left position. X
+ values increase to the right; Y values increase downward.
+
+ This coordinate system is the default for the TQPainter, which
+ renders graphics in a paint tqdevice. A user-defined coordinate
+ system can be specified by setting a TQWMatrix for the painter.
+
+ Example:
+ \code
+ MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p; // our painter
+ TQWMatrix m; // our transformation matrix
+ m.rotate( 22.5 ); // rotated coordinate system
+ p.begin( this ); // start painting
+ p.setWorldMatrix( m ); // use rotated coordinate system
+ p.drawText( 30,20, "detator" ); // draw rotated text at 30,20
+ p.end(); // painting done
+ }
+ \endcode
+
+ A matrix specifies how to translate, scale, shear or rotate the
+ graphics; the actual transformation is performed by the drawing
+ routines in TQPainter and by TQPixmap::xForm().
+
+ The TQWMatrix class tqcontains a 3x3 matrix of the form:
+ <table align=center border=1 cellpadding=1 cellspacing=0>
+ <tr align=center><td>m11</td><td>m12</td><td>&nbsp;0 </td></tr>
+ <tr align=center><td>m21</td><td>m22</td><td>&nbsp;0 </td></tr>
+ <tr align=center><td>dx</td> <td>dy</td> <td>&nbsp;1 </td></tr>
+ </table>
+
+ A matrix transforms a point in the plane to another point:
+ \code
+ x' = m11*x + m21*y + dx
+ y' = m22*y + m12*x + dy
+ \endcode
+
+ The point \e (x, y) is the original point, and \e (x', y') is the
+ transformed point. \e (x', y') can be transformed back to \e (x,
+ y) by performing the same operation on the \link
+ TQWMatrix::invert() inverted matrix\endlink.
+
+ The elements \e dx and \e dy specify horizontal and vertical
+ translation. The elements \e m11 and \e m22 specify horizontal and
+ vertical scaling. The elements \e m12 and \e m21 specify
+ horizontal and vertical shearing.
+
+ The identity matrix has \e m11 and \e m22 set to 1; all others are
+ set to 0. This matrix maps a point to itself.
+
+ Translation is the simplest transformation. Setting \e dx and \e
+ dy will move the coordinate system \e dx units along the X axis
+ and \e dy units along the Y axis.
+
+ Scaling can be done by setting \e m11 and \e m22. For example,
+ setting \e m11 to 2 and \e m22 to 1.5 will double the height and
+ increase the width by 50%.
+
+ Shearing is controlled by \e m12 and \e m21. Setting these
+ elements to values different from zero will twist the coordinate
+ system.
+
+ Rotation is achieved by carefully setting both the shearing
+ factors and the scaling factors. The TQWMatrix also has a function
+ that sets \link rotate() rotation \endlink directly.
+
+ TQWMatrix lets you combine transformations like this:
+ \code
+ TQWMatrix m; // identity matrix
+ m.translate(10, -20); // first translate (10,-20)
+ m.rotate(25); // then rotate 25 degrees
+ m.scale(1.2, 0.7); // finally scale it
+ \endcode
+
+ Here's the same example using basic matrix operations:
+ \code
+ double a = pi/180 * 25; // convert 25 to radians
+ double sina = sin(a);
+ double cosa = cos(a);
+ TQWMatrix m1(1, 0, 0, 1, 10, -20); // translation matrix
+ TQWMatrix m2( cosa, sina, // rotation matrix
+ -sina, cosa, 0, 0 );
+ TQWMatrix m3(1.2, 0, 0, 0.7, 0, 0); // scaling matrix
+ TQWMatrix m;
+ m = m3 * m2 * m1; // combine all transformations
+ \endcode
+
+ \l TQPainter has functions to translate, scale, shear and rotate the
+ coordinate system without using a TQWMatrix. Although these
+ functions are very convenient, it can be more efficient to build a
+ TQWMatrix and call TQPainter::setWorldMatrix() if you want to perform
+ more than a single transform operation.
+
+ \sa TQPainter::setWorldMatrix(), TQPixmap::xForm()
+*/
+
+bool qt_old_transformations = TRUE;
+
+/*!
+ \enum TQWMatrix::TransformationMode
+
+ \keyword transformation matrix
+
+ TQWMatrix offers two transformation modes. Calculations can either
+ be done in terms of points (Points mode, the default), or in
+ terms of area (Area mode).
+
+ In Points mode the transformation is applied to the points that
+ mark out the tqshape's bounding line. In Areas mode the
+ transformation is applied in such a way that the area of the
+ contained region is correctly transformed under the matrix.
+
+ \value Points transformations are applied to the tqshape's points.
+ \value Areas transformations are applied (e.g. to the width and
+ height) so that the area is transformed.
+
+ Example:
+
+ Suppose we have a rectangle,
+ \c{TQRect( 10, 20, 30, 40 )} and a transformation matrix
+ \c{TQWMatrix( 2, 0, 0, 2, 0, 0 )} to double the rectangle's size.
+
+ In Points mode, the matrix will transform the top-left (10,20) and
+ the bottom-right (39,59) points producing a rectangle with its
+ top-left point at (20,40) and its bottom-right point at (78,118),
+ i.e. with a width of 59 and a height of 79.
+
+ In Areas mode, the matrix will transform the top-left point in
+ the same way as in Points mode to (20/40), and double the width
+ and height, so the bottom-right will become (69,99), i.e. a width
+ of 60 and a height of 80.
+
+ Because integer arithmetic is used (for speed), rounding
+ differences mean that the modes will produce slightly different
+ results given the same tqshape and the same transformation,
+ especially when scaling up. This also means that some operations
+ are not commutative.
+
+ Under Points mode, \c{matrix * ( region1 | region2 )} is not equal to
+ \c{matrix * region1 | matrix * region2}. Under Area mode, \c{matrix *
+ (pointarray[i])} is not neccesarily equal to
+ \c{(matrix * pointarry)[i]}.
+
+ \img xform.png Comparison of Points and Areas TransformationModes
+*/
+
+/*!
+ Sets the transformation mode that TQWMatrix and painter
+ transformations use to \a m.
+
+ \sa TQWMatrix::TransformationMode
+*/
+void TQWMatrix::setTransformationMode( TQWMatrix::TransformationMode m )
+{
+ if ( m == TQWMatrix::Points )
+ qt_old_transformations = TRUE;
+ else
+ qt_old_transformations = FALSE;
+}
+
+
+/*!
+ Returns the current transformation mode.
+
+ \sa TQWMatrix::TransformationMode
+*/
+TQWMatrix::TransformationMode TQWMatrix::transformationMode()
+{
+ return (qt_old_transformations ? TQWMatrix::Points : TQWMatrix::Areas );
+}
+
+
+// some defines to inline some code
+#define MAPDOUBLE( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = _m11*fx + _m21*fy + _dx; \
+ ny = _m12*fx + _m22*fy + _dy; \
+}
+
+#define MAPINT( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = tqRound(_m11*fx + _m21*fy + _dx); \
+ ny = tqRound(_m12*fx + _m22*fy + _dy); \
+}
+
+/*****************************************************************************
+ TQWMatrix member functions
+ *****************************************************************************/
+
+/*!
+ Constructs an identity matrix. All elements are set to zero except
+ \e m11 and \e m22 (scaling), which are set to 1.
+*/
+
+TQWMatrix::TQWMatrix()
+{
+ _m11 = _m22 = 1.0;
+ _m12 = _m21 = _dx = _dy = 0.0;
+}
+
+/*!
+ Constructs a matrix with the elements, \a m11, \a m12, \a m21, \a
+ m22, \a dx and \a dy.
+*/
+
+TQWMatrix::TQWMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy )
+{
+ _m11 = m11; _m12 = m12;
+ _m21 = m21; _m22 = m22;
+ _dx = dx; _dy = dy;
+}
+
+
+/*!
+ Sets the matrix elements to the specified values, \a m11, \a m12,
+ \a m21, \a m22, \a dx and \a dy.
+*/
+
+void TQWMatrix::setMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy )
+{
+ _m11 = m11; _m12 = m12;
+ _m21 = m21; _m22 = m22;
+ _dx = dx; _dy = dy;
+}
+
+
+/*!
+ \fn double TQWMatrix::m11() const
+
+ Returns the X scaling factor.
+*/
+
+/*!
+ \fn double TQWMatrix::m12() const
+
+ Returns the vertical shearing factor.
+*/
+
+/*!
+ \fn double TQWMatrix::m21() const
+
+ Returns the horizontal shearing factor.
+*/
+
+/*!
+ \fn double TQWMatrix::m22() const
+
+ Returns the Y scaling factor.
+*/
+
+/*!
+ \fn double TQWMatrix::dx() const
+
+ Returns the horizontal translation.
+*/
+
+/*!
+ \fn double TQWMatrix::dy() const
+
+ Returns the vertical translation.
+*/
+
+
+/*!
+ \overload
+
+ Transforms ( \a x, \a y ) to ( \a *tx, \a *ty ) using the
+ following formulae:
+
+ \code
+ *tx = m11*x + m21*y + dx
+ *ty = m22*y + m12*x + dy
+ \endcode
+*/
+
+void TQWMatrix::map( double x, double y, double *tx, double *ty ) const
+{
+ MAPDOUBLE( x, y, *tx, *ty );
+}
+
+/*!
+ Transforms ( \a x, \a y ) to ( \a *tx, \a *ty ) using the formulae:
+
+ \code
+ *tx = m11*x + m21*y + dx (rounded to the nearest integer)
+ *ty = m22*y + m12*x + dy (rounded to the nearest integer)
+ \endcode
+*/
+
+void TQWMatrix::map( int x, int y, int *tx, int *ty ) const
+{
+ MAPINT( x, y, *tx, *ty );
+}
+
+/*!
+ \fn TQPoint TQWMatrix::map( const TQPoint &p ) const
+
+ \overload
+
+ Transforms \a p to using the formulae:
+
+ \code
+ retx = m11*px + m21*py + dx (rounded to the nearest integer)
+ rety = m22*py + m12*px + dy (rounded to the nearest integer)
+ \endcode
+*/
+
+/*!
+ \fn TQRect TQWMatrix::map( const TQRect &r ) const
+
+ \obsolete
+
+ Please use \l TQWMatrix::mapRect() instead.
+
+ Note that this method does return the bounding rectangle of the \a r, when
+ shearing or rotations are used.
+*/
+
+/*!
+ \fn TQPointArray TQWMatrix::map( const TQPointArray &a ) const
+
+ \overload
+
+ Returns the point array \a a transformed by calling map for each point.
+*/
+
+
+/*!
+ \fn TQRegion TQWMatrix::map( const TQRegion &r ) const
+
+ \overload
+
+ Transforms the region \a r.
+
+ Calling this method can be rather expensive, if rotations or
+ shearing are used.
+*/
+
+/*!
+ \fn TQRegion TQWMatrix::mapToRegion( const TQRect &rect ) const
+
+ Returns the transformed rectangle \a rect.
+
+ A rectangle which has been rotated or sheared may result in a
+ non-rectangular region being returned.
+
+ Calling this method can be expensive, if rotations or shearing are
+ used. If you just need to know the bounding rectangle of the
+ returned region, use mapRect() which is a lot faster than this
+ function.
+
+ \sa TQWMatrix::mapRect()
+*/
+
+
+/*!
+ Returns the transformed rectangle \a rect.
+
+ The bounding rectangle is returned if rotation or shearing has
+ been specified.
+
+ If you need to know the exact region \a rect maps to use \l
+ operator*().
+
+ \sa operator*()
+*/
+
+TQRect TQWMatrix::mapRect( const TQRect &rect ) const
+{
+ TQRect result;
+ if( qt_old_transformations ) {
+ if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ result = TQRect( map(rect.topLeft()), map(rect.bottomRight()) ).normalize();
+ } else {
+ TQPointArray a( rect );
+ a = map( a );
+ result = a.boundingRect();
+ }
+ } else {
+ if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ int x = tqRound( _m11*rect.x() + _dx );
+ int y = tqRound( _m22*rect.y() + _dy );
+ int w = tqRound( _m11*rect.width() );
+ int h = tqRound( _m22*rect.height() );
+ if ( w < 0 ) {
+ w = -w;
+ x -= w-1;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y -= h-1;
+ }
+ result = TQRect( x, y, w, h );
+ } else {
+
+ // see mapToPolygon for explanations of the algorithm.
+ double x0, y0;
+ double x, y;
+ MAPDOUBLE( rect.left(), rect.top(), x0, y0 );
+ double xmin = x0;
+ double ymin = y0;
+ double xmax = x0;
+ double ymax = y0;
+ MAPDOUBLE( rect.right() + 1, rect.top(), x, y );
+ xmin = TQMIN( xmin, x );
+ ymin = TQMIN( ymin, y );
+ xmax = TQMAX( xmax, x );
+ ymax = TQMAX( ymax, y );
+ MAPDOUBLE( rect.right() + 1, rect.bottom() + 1, x, y );
+ xmin = TQMIN( xmin, x );
+ ymin = TQMIN( ymin, y );
+ xmax = TQMAX( xmax, x );
+ ymax = TQMAX( ymax, y );
+ MAPDOUBLE( rect.left(), rect.bottom() + 1, x, y );
+ xmin = TQMIN( xmin, x );
+ ymin = TQMIN( ymin, y );
+ xmax = TQMAX( xmax, x );
+ ymax = TQMAX( ymax, y );
+ double w = xmax - xmin;
+ double h = ymax - ymin;
+ xmin -= ( xmin - x0 ) / w;
+ ymin -= ( ymin - y0 ) / h;
+ xmax -= ( xmax - x0 ) / w;
+ ymax -= ( ymax - y0 ) / h;
+ result = TQRect( tqRound(xmin), tqRound(ymin), tqRound(xmax)-tqRound(xmin)+1, tqRound(ymax)-tqRound(ymin)+1 );
+ }
+ }
+ return result;
+}
+
+
+/*!
+ \internal
+*/
+TQPoint TQWMatrix::operator *( const TQPoint &p ) const
+{
+ double fx = p.x();
+ double fy = p.y();
+ return TQPoint( tqRound(_m11*fx + _m21*fy + _dx),
+ tqRound(_m12*fx + _m22*fy + _dy) );
+}
+
+
+struct TQWMDoublePoint {
+ double x;
+ double y;
+};
+
+/*!
+ \internal
+*/
+TQPointArray TQWMatrix::operator *( const TQPointArray &a ) const
+{
+ if( qt_old_transformations ) {
+ TQPointArray result = a.copy();
+ int x, y;
+ for ( int i=0; i<(int)result.size(); i++ ) {
+ result.point( i, &x, &y );
+ MAPINT( x, y, x, y );
+ result.setPoint( i, x, y );
+ }
+ return result;
+ } else {
+ int size = a.size();
+ int i;
+ TQMemArray<TQWMDoublePoint> p( size );
+ TQPoint *da = a.data();
+ TQWMDoublePoint *dp = p.data();
+ double xmin = INT_MAX;
+ double ymin = xmin;
+ double xmax = INT_MIN;
+ double ymax = xmax;
+ int xminp = 0;
+ int yminp = 0;
+ for( i = 0; i < size; i++ ) {
+ dp[i].x = da[i].x();
+ dp[i].y = da[i].y();
+ if ( dp[i].x < xmin ) {
+ xmin = dp[i].x;
+ xminp = i;
+ }
+ if ( dp[i].y < ymin ) {
+ ymin = dp[i].y;
+ yminp = i;
+ }
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ double w = TQMAX( xmax - xmin, 1 );
+ double h = TQMAX( ymax - ymin, 1 );
+ for( i = 0; i < size; i++ ) {
+ dp[i].x += (dp[i].x - xmin)/w;
+ dp[i].y += (dp[i].y - ymin)/h;
+ MAPDOUBLE( dp[i].x, dp[i].y, dp[i].x, dp[i].y );
+ }
+
+ // now apply correction back for transformed values...
+ xmin = INT_MAX;
+ ymin = xmin;
+ xmax = INT_MIN;
+ ymax = xmax;
+ for( i = 0; i < size; i++ ) {
+ xmin = TQMIN( xmin, dp[i].x );
+ ymin = TQMIN( ymin, dp[i].y );
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ w = TQMAX( xmax - xmin, 1 );
+ h = TQMAX( ymax - ymin, 1 );
+
+ TQPointArray result( size );
+ TQPoint *dr = result.data();
+ for( i = 0; i < size; i++ ) {
+ dr[i].setX( tqRound( dp[i].x - (dp[i].x - dp[xminp].x)/w ) );
+ dr[i].setY( tqRound( dp[i].y - (dp[i].y - dp[yminp].y)/h ) );
+ }
+ return result;
+ }
+}
+
+/*!
+\internal
+*/
+TQRegion TQWMatrix::operator * (const TQRect &rect ) const
+{
+ TQRegion result;
+ if ( isIdentity() ) {
+ result = rect;
+ } else if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ if( qt_old_transformations ) {
+ result = TQRect( map(rect.topLeft()), map(rect.bottomRight()) ).normalize();
+ } else {
+ int x = tqRound( _m11*rect.x() + _dx );
+ int y = tqRound( _m22*rect.y() + _dy );
+ int w = tqRound( _m11*rect.width() );
+ int h = tqRound( _m22*rect.height() );
+ if ( w < 0 ) {
+ w = -w;
+ x -= w - 1;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y -= h - 1;
+ }
+ result = TQRect( x, y, w, h );
+ }
+ } else {
+ result = TQRegion( mapToPolygon( rect ) );
+ }
+ return result;
+
+}
+
+/*!
+ Returns the transformed rectangle \a rect as a polygon.
+
+ Polygons and rectangles behave slightly differently
+ when transformed (due to integer rounding), so
+ \c{matrix.map( TQPointArray( rect ) )} is not always the same as
+ \c{matrix.mapToPolygon( rect )}.
+*/
+TQPointArray TQWMatrix::mapToPolygon( const TQRect &rect ) const
+{
+ TQPointArray a( 4 );
+ if ( qt_old_transformations ) {
+ a = TQPointArray( rect );
+ return operator *( a );
+ }
+ double x[4], y[4];
+ if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ x[0] = tqRound( _m11*rect.x() + _dx );
+ y[0] = tqRound( _m22*rect.y() + _dy );
+ double w = tqRound( _m11*rect.width() );
+ double h = tqRound( _m22*rect.height() );
+ if ( w < 0 ) {
+ w = -w;
+ x[0] -= w - 1.;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y[0] -= h - 1.;
+ }
+ x[1] = x[0]+w-1;
+ x[2] = x[1];
+ x[3] = x[0];
+ y[1] = y[0];
+ y[2] = y[0]+h-1;
+ y[3] = y[2];
+ } else {
+ MAPINT( rect.left(), rect.top(), x[0], y[0] );
+ MAPINT( rect.right() + 1, rect.top(), x[1], y[1] );
+ MAPINT( rect.right() + 1, rect.bottom() + 1, x[2], y[2] );
+ MAPINT( rect.left(), rect.bottom() + 1, x[3], y[3] );
+
+ /*
+ Including rectangles as we have are evil.
+
+ We now have a rectangle that is one pixel to wide and one to
+ high. the tranformed position of the top-left corner is
+ correct. All other points need some adjustments.
+
+ Doing this mathematically exact would force us to calculate some square roots,
+ something we don't want for the sake of speed.
+
+ Instead we use an approximation, that converts to the correct
+ answer when m12 -> 0 and m21 -> 0, and accept smaller
+ errors in the general transformation case.
+
+ The solution is to calculate the width and height of the
+ bounding rect, and scale the points 1/2/3 by (xp-x0)/xw pixel direction
+ to point 0.
+ */
+
+ double xmin = x[0];
+ double ymin = y[0];
+ double xmax = x[0];
+ double ymax = y[0];
+ int i;
+ for( i = 1; i< 4; i++ ) {
+ xmin = TQMIN( xmin, x[i] );
+ ymin = TQMIN( ymin, y[i] );
+ xmax = TQMAX( xmax, x[i] );
+ ymax = TQMAX( ymax, y[i] );
+ }
+ double w = xmax - xmin;
+ double h = ymax - ymin;
+
+ for( i = 1; i < 4; i++ ) {
+ x[i] -= (x[i] - x[0])/w;
+ y[i] -= (y[i] - y[0])/h;
+ }
+ }
+#if 0
+ int i;
+ for( i = 0; i< 4; i++ )
+ qDebug("coords(%d) = (%f/%f) (%d/%d)", i, x[i], y[i], tqRound(x[i]), tqRound(y[i]) );
+ qDebug( "width=%f, height=%f", sqrt( (x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]) ),
+ sqrt( (x[0]-x[3])*(x[0]-x[3]) + (y[0]-y[3])*(y[0]-y[3]) ) );
+#endif
+ // all coordinates are correctly, tranform to a pointarray
+ // (rounding to the next integer)
+ a.setPoints( 4, tqRound( x[0] ), tqRound( y[0] ),
+ tqRound( x[1] ), tqRound( y[1] ),
+ tqRound( x[2] ), tqRound( y[2] ),
+ tqRound( x[3] ), tqRound( y[3] ) );
+ return a;
+}
+
+/*!
+\internal
+*/
+TQRegion TQWMatrix::operator * (const TQRegion &r ) const
+{
+ if ( isIdentity() )
+ return r;
+ TQMemArray<TQRect> rects = r.rects();
+ TQRegion result;
+ register TQRect *rect = rects.data();
+ register int i = rects.size();
+ if ( _m12 == 0.0F && _m21 == 0.0F && _m11 > 1.0F && _m22 > 1.0F ) {
+ // simple case, no rotation
+ while ( i ) {
+ int x = tqRound( _m11*rect->x() + _dx );
+ int y = tqRound( _m22*rect->y() + _dy );
+ int w = tqRound( _m11*rect->width() );
+ int h = tqRound( _m22*rect->height() );
+ if ( w < 0 ) {
+ w = -w;
+ x -= w-1;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y -= h-1;
+ }
+ *rect = TQRect( x, y, w, h );
+ rect++;
+ i--;
+ }
+ result.setRects( rects.data(), rects.size() );
+ } else {
+ while ( i ) {
+ result |= operator *( *rect );
+ rect++;
+ i--;
+ }
+ }
+ return result;
+}
+
+/*!
+ Resets the matrix to an identity matrix.
+
+ All elements are set to zero, except \e m11 and \e m22 (scaling)
+ which are set to 1.
+
+ \sa isIdentity()
+*/
+
+void TQWMatrix::reset()
+{
+ _m11 = _m22 = 1.0;
+ _m12 = _m21 = _dx = _dy = 0.0;
+}
+
+/*!
+ Returns TRUE if the matrix is the identity matrix; otherwise returns FALSE.
+
+ \sa reset()
+*/
+bool TQWMatrix::isIdentity() const
+{
+ return _m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0
+ && _dx == 0.0 && _dy == 0.0;
+}
+
+/*!
+ Moves the coordinate system \a dx along the X-axis and \a dy along
+ the Y-axis.
+
+ Returns a reference to the matrix.
+
+ \sa scale(), shear(), rotate()
+*/
+
+TQWMatrix &TQWMatrix::translate( double dx, double dy )
+{
+ _dx += dx*_m11 + dy*_m21;
+ _dy += dy*_m22 + dx*_m12;
+ return *this;
+}
+
+/*!
+ Scales the coordinate system unit by \a sx horizontally and \a sy
+ vertically.
+
+ Returns a reference to the matrix.
+
+ \sa translate(), shear(), rotate()
+*/
+
+TQWMatrix &TQWMatrix::scale( double sx, double sy )
+{
+ _m11 *= sx;
+ _m12 *= sx;
+ _m21 *= sy;
+ _m22 *= sy;
+ return *this;
+}
+
+/*!
+ Shears the coordinate system by \a sh horizontally and \a sv
+ vertically.
+
+ Returns a reference to the matrix.
+
+ \sa translate(), scale(), rotate()
+*/
+
+TQWMatrix &TQWMatrix::shear( double sh, double sv )
+{
+ double tm11 = sv*_m21;
+ double tm12 = sv*_m22;
+ double tm21 = sh*_m11;
+ double tm22 = sh*_m12;
+ _m11 += tm11;
+ _m12 += tm12;
+ _m21 += tm21;
+ _m22 += tm22;
+ return *this;
+}
+
+const double deg2rad = 0.017453292519943295769; // pi/180
+
+/*!
+ Rotates the coordinate system \a a degrees counterclockwise.
+
+ Returns a reference to the matrix.
+
+ \sa translate(), scale(), shear()
+*/
+
+TQWMatrix &TQWMatrix::rotate( double a )
+{
+ double b = deg2rad*a; // convert to radians
+#if defined(TQ_WS_X11)
+ double sina = qsincos(b,FALSE); // fast and convenient
+ double cosa = qsincos(b,TRUE);
+#else
+ double sina = sin(b);
+ double cosa = cos(b);
+#endif
+ double tm11 = cosa*_m11 + sina*_m21;
+ double tm12 = cosa*_m12 + sina*_m22;
+ double tm21 = -sina*_m11 + cosa*_m21;
+ double tm22 = -sina*_m12 + cosa*_m22;
+ _m11 = tm11; _m12 = tm12;
+ _m21 = tm21; _m22 = tm22;
+ return *this;
+}
+
+/*!
+ \fn bool TQWMatrix::isInvertible() const
+
+ Returns TRUE if the matrix is invertible; otherwise returns FALSE.
+
+ \sa invert()
+*/
+
+/*!
+ \fn double TQWMatrix::det() const
+
+ Returns the matrix's determinant.
+*/
+
+
+/*!
+ Returns the inverted matrix.
+
+ If the matrix is singular (not invertible), the identity matrix is
+ returned.
+
+ If \a invertible is not 0: the value of \a *invertible is set
+ to TRUE if the matrix is invertible; otherwise \a *invertible is
+ set to FALSE.
+
+ \sa isInvertible()
+*/
+
+TQWMatrix TQWMatrix::invert( bool *invertible ) const
+{
+ double determinant = det();
+ if ( determinant == 0.0 ) {
+ if ( invertible )
+ *invertible = FALSE; // singular matrix
+ TQWMatrix defaultMatrix;
+ return defaultMatrix;
+ }
+ else { // invertible matrix
+ if ( invertible )
+ *invertible = TRUE;
+ double dinv = 1.0/determinant;
+ TQWMatrix imatrix( (_m22*dinv), (-_m12*dinv),
+ (-_m21*dinv), ( _m11*dinv),
+ ((_m21*_dy - _m22*_dx)*dinv),
+ ((_m12*_dx - _m11*_dy)*dinv) );
+ return imatrix;
+ }
+}
+
+
+/*!
+ Returns TRUE if this matrix is equal to \a m; otherwise returns FALSE.
+*/
+
+bool TQWMatrix::operator==( const TQWMatrix &m ) const
+{
+ return _m11 == m._m11 &&
+ _m12 == m._m12 &&
+ _m21 == m._m21 &&
+ _m22 == m._m22 &&
+ _dx == m._dx &&
+ _dy == m._dy;
+}
+
+/*!
+ Returns TRUE if this matrix is not equal to \a m; otherwise returns FALSE.
+*/
+
+bool TQWMatrix::operator!=( const TQWMatrix &m ) const
+{
+ return _m11 != m._m11 ||
+ _m12 != m._m12 ||
+ _m21 != m._m21 ||
+ _m22 != m._m22 ||
+ _dx != m._dx ||
+ _dy != m._dy;
+}
+
+/*!
+ Returns the result of multiplying this matrix by matrix \a m.
+*/
+
+TQWMatrix &TQWMatrix::operator*=( const TQWMatrix &m )
+{
+ double tm11 = _m11*m._m11 + _m12*m._m21;
+ double tm12 = _m11*m._m12 + _m12*m._m22;
+ double tm21 = _m21*m._m11 + _m22*m._m21;
+ double tm22 = _m21*m._m12 + _m22*m._m22;
+
+ double tdx = _dx*m._m11 + _dy*m._m21 + m._dx;
+ double tdy = _dx*m._m12 + _dy*m._m22 + m._dy;
+
+ _m11 = tm11; _m12 = tm12;
+ _m21 = tm21; _m22 = tm22;
+ _dx = tdx; _dy = tdy;
+ return *this;
+}
+
+/*!
+ \overload
+ \relates TQWMatrix
+ Returns the product of \a m1 * \a m2.
+
+ Note that matrix multiplication is not commutative, i.e. a*b !=
+ b*a.
+*/
+
+TQWMatrix operator*( const TQWMatrix &m1, const TQWMatrix &m2 )
+{
+ TQWMatrix result = m1;
+ result *= m2;
+ return result;
+}
+
+/*****************************************************************************
+ TQWMatrix stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQWMatrix
+
+ Writes the matrix \a m to the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQWMatrix &m )
+{
+ if ( s.version() == 1 )
+ s << (float)m.m11() << (float)m.m12() << (float)m.m21()
+ << (float)m.m22() << (float)m.dx() << (float)m.dy();
+ else
+ s << m.m11() << m.m12() << m.m21() << m.m22()
+ << m.dx() << m.dy();
+ return s;
+}
+
+/*!
+ \relates TQWMatrix
+
+ Reads the matrix \a m from the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQWMatrix &m )
+{
+ if ( s.version() == 1 ) {
+ float m11, m12, m21, m22, dx, dy;
+ s >> m11; s >> m12; s >> m21; s >> m22;
+ s >> dx; s >> dy;
+ m.setMatrix( m11, m12, m21, m22, dx, dy );
+ }
+ else {
+ double m11, m12, m21, m22, dx, dy;
+ s >> m11; s >> m12; s >> m21; s >> m22;
+ s >> dx; s >> dy;
+ m.setMatrix( m11, m12, m21, m22, dx, dy );
+ }
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+
+#endif // USE_QT4
+
+#endif // TQT_NO_WMATRIX
+
diff --git a/tqtinterface/qt4/src/kernel/tqwmatrix.cpp~ b/tqtinterface/qt4/src/kernel/tqwmatrix.cpp~
new file mode 100644
index 0000000..f95b660
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwmatrix.cpp~
@@ -0,0 +1,1204 @@
+/****************************************************************************
+**
+** Implementation of TQWMatrix class
+**
+** Created : 941020
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#include "tqwmatrix.h"
+#include "tqdatastream.h"
+#include "tqregion.h"
+#if defined(TQ_WS_X11)
+double qsincos( double, bool calcCos ); // defined in qpainter_x11.cpp
+#else
+#include <math.h>
+#endif
+
+#include <limits.h>
+
+#ifndef TQT_NO_WMATRIX
+
+#ifdef USE_QT4
+
+// some defines to inline some code
+#define MAPDOUBLE( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = m11()*fx + m21()*fy + dx(); \
+ ny = m12()*fx + m22()*fy + dy(); \
+}
+
+#define MAPINT( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = tqRound(m11()*fx + m21()*fy + dx()); \
+ ny = tqRound(m12()*fx + m22()*fy + dy()); \
+}
+
+struct TQWMDoublePoint {
+ double x;
+ double y;
+};
+
+bool qt_old_transformations = TRUE;
+
+// TQWMatrix TQWMatrix::invert(bool *invertible=0) {
+// return convertFromQMatrix(inverted(invertible));
+// }
+
+/*!
+ Sets the transformation mode that TQWMatrix and painter
+ transformations use to \a m.
+
+ \sa TQWMatrix::TransformationMode
+*/
+void TQWMatrix::setTransformationMode( TQWMatrix::TransformationMode m )
+{
+ printf("[WARNING] TQWMatrix::setTransformationMode has no effect!\n\r");
+
+ if ( m == TQWMatrix::Points )
+ qt_old_transformations = TRUE;
+ else
+ qt_old_transformations = FALSE;
+}
+
+
+/*!
+ Returns the current transformation mode.
+
+ \sa TQWMatrix::TransformationMode
+*/
+TQWMatrix::TransformationMode TQWMatrix::transformationMode()
+{
+ return (qt_old_transformations ? TQWMatrix::Points : TQWMatrix::Areas );
+}
+
+/*!
+ \internal
+*/
+TQPointArray TQWMatrix::operator *( const TQPointArray &a ) const
+{
+ if( qt_old_transformations ) {
+ TQPointArray result = a.copy();
+ int x, y;
+ for ( int i=0; i<(int)result.size(); i++ ) {
+ result.point( i, &x, &y );
+ MAPINT( x, y, x, y );
+ result.setPoint( i, x, y );
+ }
+ return result;
+ } else {
+ int size = a.size();
+ int i;
+ TQMemArray<TQWMDoublePoint> p( size );
+ TQPoint *da = TQT_TQPOINT_CONST(a.data());
+ TQWMDoublePoint *dp = p.data();
+ double xmin = INT_MAX;
+ double ymin = xmin;
+ double xmax = INT_MIN;
+ double ymax = xmax;
+ int xminp = 0;
+ int yminp = 0;
+ for( i = 0; i < size; i++ ) {
+ dp[i].x = da[i].x();
+ dp[i].y = da[i].y();
+ if ( dp[i].x < xmin ) {
+ xmin = dp[i].x;
+ xminp = i;
+ }
+ if ( dp[i].y < ymin ) {
+ ymin = dp[i].y;
+ yminp = i;
+ }
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ double w = TQMAX( xmax - xmin, 1 );
+ double h = TQMAX( ymax - ymin, 1 );
+ for( i = 0; i < size; i++ ) {
+ dp[i].x += (dp[i].x - xmin)/w;
+ dp[i].y += (dp[i].y - ymin)/h;
+ MAPDOUBLE( dp[i].x, dp[i].y, dp[i].x, dp[i].y );
+ }
+
+ // now apply correction back for transformed values...
+ xmin = INT_MAX;
+ ymin = xmin;
+ xmax = INT_MIN;
+ ymax = xmax;
+ for( i = 0; i < size; i++ ) {
+ xmin = TQMIN( xmin, dp[i].x );
+ ymin = TQMIN( ymin, dp[i].y );
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ w = TQMAX( xmax - xmin, 1 );
+ h = TQMAX( ymax - ymin, 1 );
+
+ TQPointArray result( size );
+ TQPoint *dr = TQT_TQPOINT(result.data());
+ for( i = 0; i < size; i++ ) {
+ dr[i].setX( tqRound( dp[i].x - (dp[i].x - dp[xminp].x)/w ) );
+ dr[i].setY( tqRound( dp[i].y - (dp[i].y - dp[yminp].y)/h ) );
+ }
+ return result;
+ }
+}
+
+/*!
+ Returns the result of multiplying this matrix by matrix \a m.
+*/
+
+TQWMatrix &TQWMatrix::operator*=( const TQWMatrix &m )
+{
+ double tm11 = m11()*m.m11() + m12()*m.m21();
+ double tm12 = m11()*m.m12() + m12()*m.m22();
+ double tm21 = m21()*m.m11() + m22()*m.m21();
+ double tm22 = m21()*m.m12() + m22()*m.m22();
+
+ double tdx = dx()*m.m11() + dy()*m.m21() + m.dx();
+ double tdy = dx()*m.m12() + dy()*m.m22() + m.dy();
+
+ *this = TQWMatrix(tm11, tm12, tm21, tm22, tdx, tdy);
+
+ return *this;
+}
+
+/*!
+ \overload
+ \relates TQWMatrix
+ Returns the product of \a m1 * \a m2.
+
+ Note that matrix multiplication is not commutative, i.e. a*b !=
+ b*a.
+*/
+
+TQWMatrix operator*( const TQWMatrix &m1, const TQWMatrix &m2 )
+{
+ TQWMatrix result = m1;
+ result *= m2;
+ return result;
+}
+
+#else // USE_QT4
+
+/*!
+ \class TQWMatrix tqwmatrix.h
+ \brief The TQWMatrix class specifies 2D transformations of a
+ coordinate system.
+
+ \ingroup graphics
+ \ingroup images
+
+ The standard coordinate system of a \link TQPaintDevice paint
+ tqdevice\endlink has the origin located at the top-left position. X
+ values increase to the right; Y values increase downward.
+
+ This coordinate system is the default for the TQPainter, which
+ renders graphics in a paint tqdevice. A user-defined coordinate
+ system can be specified by setting a TQWMatrix for the painter.
+
+ Example:
+ \code
+ MyWidget::paintEvent( TQPaintEvent * )
+ {
+ TQPainter p; // our painter
+ TQWMatrix m; // our transformation matrix
+ m.rotate( 22.5 ); // rotated coordinate system
+ p.begin( this ); // start painting
+ p.setWorldMatrix( m ); // use rotated coordinate system
+ p.drawText( 30,20, "detator" ); // draw rotated text at 30,20
+ p.end(); // painting done
+ }
+ \endcode
+
+ A matrix specifies how to translate, scale, shear or rotate the
+ graphics; the actual transformation is performed by the drawing
+ routines in TQPainter and by TQPixmap::xForm().
+
+ The TQWMatrix class tqcontains a 3x3 matrix of the form:
+ <table align=center border=1 cellpadding=1 cellspacing=0>
+ <tr align=center><td>m11</td><td>m12</td><td>&nbsp;0 </td></tr>
+ <tr align=center><td>m21</td><td>m22</td><td>&nbsp;0 </td></tr>
+ <tr align=center><td>dx</td> <td>dy</td> <td>&nbsp;1 </td></tr>
+ </table>
+
+ A matrix transforms a point in the plane to another point:
+ \code
+ x' = m11*x + m21*y + dx
+ y' = m22*y + m12*x + dy
+ \endcode
+
+ The point \e (x, y) is the original point, and \e (x', y') is the
+ transformed point. \e (x', y') can be transformed back to \e (x,
+ y) by performing the same operation on the \link
+ TQWMatrix::invert() inverted matrix\endlink.
+
+ The elements \e dx and \e dy specify horizontal and vertical
+ translation. The elements \e m11 and \e m22 specify horizontal and
+ vertical scaling. The elements \e m12 and \e m21 specify
+ horizontal and vertical shearing.
+
+ The identity matrix has \e m11 and \e m22 set to 1; all others are
+ set to 0. This matrix maps a point to itself.
+
+ Translation is the simplest transformation. Setting \e dx and \e
+ dy will move the coordinate system \e dx units along the X axis
+ and \e dy units along the Y axis.
+
+ Scaling can be done by setting \e m11 and \e m22. For example,
+ setting \e m11 to 2 and \e m22 to 1.5 will double the height and
+ increase the width by 50%.
+
+ Shearing is controlled by \e m12 and \e m21. Setting these
+ elements to values different from zero will twist the coordinate
+ system.
+
+ Rotation is achieved by carefully setting both the shearing
+ factors and the scaling factors. The TQWMatrix also has a function
+ that sets \link rotate() rotation \endlink directly.
+
+ TQWMatrix lets you combine transformations like this:
+ \code
+ TQWMatrix m; // identity matrix
+ m.translate(10, -20); // first translate (10,-20)
+ m.rotate(25); // then rotate 25 degrees
+ m.scale(1.2, 0.7); // finally scale it
+ \endcode
+
+ Here's the same example using basic matrix operations:
+ \code
+ double a = pi/180 * 25; // convert 25 to radians
+ double sina = sin(a);
+ double cosa = cos(a);
+ TQWMatrix m1(1, 0, 0, 1, 10, -20); // translation matrix
+ TQWMatrix m2( cosa, sina, // rotation matrix
+ -sina, cosa, 0, 0 );
+ TQWMatrix m3(1.2, 0, 0, 0.7, 0, 0); // scaling matrix
+ TQWMatrix m;
+ m = m3 * m2 * m1; // combine all transformations
+ \endcode
+
+ \l TQPainter has functions to translate, scale, shear and rotate the
+ coordinate system without using a TQWMatrix. Although these
+ functions are very convenient, it can be more efficient to build a
+ TQWMatrix and call TQPainter::setWorldMatrix() if you want to perform
+ more than a single transform operation.
+
+ \sa TQPainter::setWorldMatrix(), TQPixmap::xForm()
+*/
+
+bool qt_old_transformations = TRUE;
+
+/*!
+ \enum TQWMatrix::TransformationMode
+
+ \keyword transformation matrix
+
+ TQWMatrix offers two transformation modes. Calculations can either
+ be done in terms of points (Points mode, the default), or in
+ terms of area (Area mode).
+
+ In Points mode the transformation is applied to the points that
+ mark out the tqshape's bounding line. In Areas mode the
+ transformation is applied in such a way that the area of the
+ contained region is correctly transformed under the matrix.
+
+ \value Points transformations are applied to the tqshape's points.
+ \value Areas transformations are applied (e.g. to the width and
+ height) so that the area is transformed.
+
+ Example:
+
+ Suppose we have a rectangle,
+ \c{TQRect( 10, 20, 30, 40 )} and a transformation matrix
+ \c{TQWMatrix( 2, 0, 0, 2, 0, 0 )} to double the rectangle's size.
+
+ In Points mode, the matrix will transform the top-left (10,20) and
+ the bottom-right (39,59) points producing a rectangle with its
+ top-left point at (20,40) and its bottom-right point at (78,118),
+ i.e. with a width of 59 and a height of 79.
+
+ In Areas mode, the matrix will transform the top-left point in
+ the same way as in Points mode to (20/40), and double the width
+ and height, so the bottom-right will become (69,99), i.e. a width
+ of 60 and a height of 80.
+
+ Because integer arithmetic is used (for speed), rounding
+ differences mean that the modes will produce slightly different
+ results given the same tqshape and the same transformation,
+ especially when scaling up. This also means that some operations
+ are not commutative.
+
+ Under Points mode, \c{matrix * ( region1 | region2 )} is not equal to
+ \c{matrix * region1 | matrix * region2}. Under Area mode, \c{matrix *
+ (pointarray[i])} is not neccesarily equal to
+ \c{(matrix * pointarry)[i]}.
+
+ \img xform.png Comparison of Points and Areas TransformationModes
+*/
+
+/*!
+ Sets the transformation mode that TQWMatrix and painter
+ transformations use to \a m.
+
+ \sa TQWMatrix::TransformationMode
+*/
+void TQWMatrix::setTransformationMode( TQWMatrix::TransformationMode m )
+{
+ if ( m == TQWMatrix::Points )
+ qt_old_transformations = TRUE;
+ else
+ qt_old_transformations = FALSE;
+}
+
+
+/*!
+ Returns the current transformation mode.
+
+ \sa TQWMatrix::TransformationMode
+*/
+TQWMatrix::TransformationMode TQWMatrix::transformationMode()
+{
+ return (qt_old_transformations ? TQWMatrix::Points : TQWMatrix::Areas );
+}
+
+
+// some defines to inline some code
+#define MAPDOUBLE( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = _m11*fx + _m21*fy + _dx; \
+ ny = _m12*fx + _m22*fy + _dy; \
+}
+
+#define MAPINT( x, y, nx, ny ) \
+{ \
+ double fx = x; \
+ double fy = y; \
+ nx = tqRound(_m11*fx + _m21*fy + _dx); \
+ ny = tqRound(_m12*fx + _m22*fy + _dy); \
+}
+
+/*****************************************************************************
+ TQWMatrix member functions
+ *****************************************************************************/
+
+/*!
+ Constructs an identity matrix. All elements are set to zero except
+ \e m11 and \e m22 (scaling), which are set to 1.
+*/
+
+TQWMatrix::TQWMatrix()
+{
+ _m11 = _m22 = 1.0;
+ _m12 = _m21 = _dx = _dy = 0.0;
+}
+
+/*!
+ Constructs a matrix with the elements, \a m11, \a m12, \a m21, \a
+ m22, \a dx and \a dy.
+*/
+
+TQWMatrix::TQWMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy )
+{
+ _m11 = m11; _m12 = m12;
+ _m21 = m21; _m22 = m22;
+ _dx = dx; _dy = dy;
+}
+
+
+/*!
+ Sets the matrix elements to the specified values, \a m11, \a m12,
+ \a m21, \a m22, \a dx and \a dy.
+*/
+
+void TQWMatrix::setMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy )
+{
+ _m11 = m11; _m12 = m12;
+ _m21 = m21; _m22 = m22;
+ _dx = dx; _dy = dy;
+}
+
+
+/*!
+ \fn double TQWMatrix::m11() const
+
+ Returns the X scaling factor.
+*/
+
+/*!
+ \fn double TQWMatrix::m12() const
+
+ Returns the vertical shearing factor.
+*/
+
+/*!
+ \fn double TQWMatrix::m21() const
+
+ Returns the horizontal shearing factor.
+*/
+
+/*!
+ \fn double TQWMatrix::m22() const
+
+ Returns the Y scaling factor.
+*/
+
+/*!
+ \fn double TQWMatrix::dx() const
+
+ Returns the horizontal translation.
+*/
+
+/*!
+ \fn double TQWMatrix::dy() const
+
+ Returns the vertical translation.
+*/
+
+
+/*!
+ \overload
+
+ Transforms ( \a x, \a y ) to ( \a *tx, \a *ty ) using the
+ following formulae:
+
+ \code
+ *tx = m11*x + m21*y + dx
+ *ty = m22*y + m12*x + dy
+ \endcode
+*/
+
+void TQWMatrix::map( double x, double y, double *tx, double *ty ) const
+{
+ MAPDOUBLE( x, y, *tx, *ty );
+}
+
+/*!
+ Transforms ( \a x, \a y ) to ( \a *tx, \a *ty ) using the formulae:
+
+ \code
+ *tx = m11*x + m21*y + dx (rounded to the nearest integer)
+ *ty = m22*y + m12*x + dy (rounded to the nearest integer)
+ \endcode
+*/
+
+void TQWMatrix::map( int x, int y, int *tx, int *ty ) const
+{
+ MAPINT( x, y, *tx, *ty );
+}
+
+/*!
+ \fn TQPoint TQWMatrix::map( const TQPoint &p ) const
+
+ \overload
+
+ Transforms \a p to using the formulae:
+
+ \code
+ retx = m11*px + m21*py + dx (rounded to the nearest integer)
+ rety = m22*py + m12*px + dy (rounded to the nearest integer)
+ \endcode
+*/
+
+/*!
+ \fn TQRect TQWMatrix::map( const TQRect &r ) const
+
+ \obsolete
+
+ Please use \l TQWMatrix::mapRect() instead.
+
+ Note that this method does return the bounding rectangle of the \a r, when
+ shearing or rotations are used.
+*/
+
+/*!
+ \fn TQPointArray TQWMatrix::map( const TQPointArray &a ) const
+
+ \overload
+
+ Returns the point array \a a transformed by calling map for each point.
+*/
+
+
+/*!
+ \fn TQRegion TQWMatrix::map( const TQRegion &r ) const
+
+ \overload
+
+ Transforms the region \a r.
+
+ Calling this method can be rather expensive, if rotations or
+ shearing are used.
+*/
+
+/*!
+ \fn TQRegion TQWMatrix::mapToRegion( const TQRect &rect ) const
+
+ Returns the transformed rectangle \a rect.
+
+ A rectangle which has been rotated or sheared may result in a
+ non-rectangular region being returned.
+
+ Calling this method can be expensive, if rotations or shearing are
+ used. If you just need to know the bounding rectangle of the
+ returned region, use mapRect() which is a lot faster than this
+ function.
+
+ \sa TQWMatrix::mapRect()
+*/
+
+
+/*!
+ Returns the transformed rectangle \a rect.
+
+ The bounding rectangle is returned if rotation or shearing has
+ been specified.
+
+ If you need to know the exact region \a rect maps to use \l
+ operator*().
+
+ \sa operator*()
+*/
+
+TQRect TQWMatrix::mapRect( const TQRect &rect ) const
+{
+ TQRect result;
+ if( qt_old_transformations ) {
+ if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ result = TQRect( map(rect.topLeft()), map(rect.bottomRight()) ).normalize();
+ } else {
+ TQPointArray a( rect );
+ a = map( a );
+ result = a.boundingRect();
+ }
+ } else {
+ if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ int x = tqRound( _m11*rect.x() + _dx );
+ int y = tqRound( _m22*rect.y() + _dy );
+ int w = tqRound( _m11*rect.width() );
+ int h = tqRound( _m22*rect.height() );
+ if ( w < 0 ) {
+ w = -w;
+ x -= w-1;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y -= h-1;
+ }
+ result = TQRect( x, y, w, h );
+ } else {
+
+ // see mapToPolygon for explanations of the algorithm.
+ double x0, y0;
+ double x, y;
+ MAPDOUBLE( rect.left(), rect.top(), x0, y0 );
+ double xmin = x0;
+ double ymin = y0;
+ double xmax = x0;
+ double ymax = y0;
+ MAPDOUBLE( rect.right() + 1, rect.top(), x, y );
+ xmin = TQMIN( xmin, x );
+ ymin = TQMIN( ymin, y );
+ xmax = TQMAX( xmax, x );
+ ymax = TQMAX( ymax, y );
+ MAPDOUBLE( rect.right() + 1, rect.bottom() + 1, x, y );
+ xmin = TQMIN( xmin, x );
+ ymin = TQMIN( ymin, y );
+ xmax = TQMAX( xmax, x );
+ ymax = TQMAX( ymax, y );
+ MAPDOUBLE( rect.left(), rect.bottom() + 1, x, y );
+ xmin = TQMIN( xmin, x );
+ ymin = TQMIN( ymin, y );
+ xmax = TQMAX( xmax, x );
+ ymax = TQMAX( ymax, y );
+ double w = xmax - xmin;
+ double h = ymax - ymin;
+ xmin -= ( xmin - x0 ) / w;
+ ymin -= ( ymin - y0 ) / h;
+ xmax -= ( xmax - x0 ) / w;
+ ymax -= ( ymax - y0 ) / h;
+ result = TQRect( tqRound(xmin), tqRound(ymin), tqRound(xmax)-tqRound(xmin)+1, tqRound(ymax)-tqRound(ymin)+1 );
+ }
+ }
+ return result;
+}
+
+
+/*!
+ \internal
+*/
+TQPoint TQWMatrix::operator *( const TQPoint &p ) const
+{
+ double fx = p.x();
+ double fy = p.y();
+ return TQPoint( tqRound(_m11*fx + _m21*fy + _dx),
+ tqRound(_m12*fx + _m22*fy + _dy) );
+}
+
+
+struct TQWMDoublePoint {
+ double x;
+ double y;
+};
+
+/*!
+ \internal
+*/
+TQPointArray TQWMatrix::operator *( const TQPointArray &a ) const
+{
+ if( qt_old_transformations ) {
+ TQPointArray result = a.copy();
+ int x, y;
+ for ( int i=0; i<(int)result.size(); i++ ) {
+ result.point( i, &x, &y );
+ MAPINT( x, y, x, y );
+ result.setPoint( i, x, y );
+ }
+ return result;
+ } else {
+ int size = a.size();
+ int i;
+ TQMemArray<TQWMDoublePoint> p( size );
+ TQPoint *da = a.data();
+ TQWMDoublePoint *dp = p.data();
+ double xmin = INT_MAX;
+ double ymin = xmin;
+ double xmax = INT_MIN;
+ double ymax = xmax;
+ int xminp = 0;
+ int yminp = 0;
+ for( i = 0; i < size; i++ ) {
+ dp[i].x = da[i].x();
+ dp[i].y = da[i].y();
+ if ( dp[i].x < xmin ) {
+ xmin = dp[i].x;
+ xminp = i;
+ }
+ if ( dp[i].y < ymin ) {
+ ymin = dp[i].y;
+ yminp = i;
+ }
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ double w = TQMAX( xmax - xmin, 1 );
+ double h = TQMAX( ymax - ymin, 1 );
+ for( i = 0; i < size; i++ ) {
+ dp[i].x += (dp[i].x - xmin)/w;
+ dp[i].y += (dp[i].y - ymin)/h;
+ MAPDOUBLE( dp[i].x, dp[i].y, dp[i].x, dp[i].y );
+ }
+
+ // now apply correction back for transformed values...
+ xmin = INT_MAX;
+ ymin = xmin;
+ xmax = INT_MIN;
+ ymax = xmax;
+ for( i = 0; i < size; i++ ) {
+ xmin = TQMIN( xmin, dp[i].x );
+ ymin = TQMIN( ymin, dp[i].y );
+ xmax = TQMAX( xmax, dp[i].x );
+ ymax = TQMAX( ymax, dp[i].y );
+ }
+ w = TQMAX( xmax - xmin, 1 );
+ h = TQMAX( ymax - ymin, 1 );
+
+ TQPointArray result( size );
+ TQPoint *dr = result.data();
+ for( i = 0; i < size; i++ ) {
+ dr[i].setX( tqRound( dp[i].x - (dp[i].x - dp[xminp].x)/w ) );
+ dr[i].setY( tqRound( dp[i].y - (dp[i].y - dp[yminp].y)/h ) );
+ }
+ return result;
+ }
+}
+
+/*!
+\internal
+*/
+TQRegion TQWMatrix::operator * (const TQRect &rect ) const
+{
+ TQRegion result;
+ if ( isIdentity() ) {
+ result = rect;
+ } else if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ if( qt_old_transformations ) {
+ result = TQRect( map(rect.topLeft()), map(rect.bottomRight()) ).normalize();
+ } else {
+ int x = tqRound( _m11*rect.x() + _dx );
+ int y = tqRound( _m22*rect.y() + _dy );
+ int w = tqRound( _m11*rect.width() );
+ int h = tqRound( _m22*rect.height() );
+ if ( w < 0 ) {
+ w = -w;
+ x -= w - 1;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y -= h - 1;
+ }
+ result = TQRect( x, y, w, h );
+ }
+ } else {
+ result = TQRegion( mapToPolygon( rect ) );
+ }
+ return result;
+
+}
+
+/*!
+ Returns the transformed rectangle \a rect as a polygon.
+
+ Polygons and rectangles behave slightly differently
+ when transformed (due to integer rounding), so
+ \c{matrix.map( TQPointArray( rect ) )} is not always the same as
+ \c{matrix.mapToPolygon( rect )}.
+*/
+TQPointArray TQWMatrix::mapToPolygon( const TQRect &rect ) const
+{
+ TQPointArray a( 4 );
+ if ( qt_old_transformations ) {
+ a = TQPointArray( rect );
+ return operator *( a );
+ }
+ double x[4], y[4];
+ if ( _m12 == 0.0F && _m21 == 0.0F ) {
+ x[0] = tqRound( _m11*rect.x() + _dx );
+ y[0] = tqRound( _m22*rect.y() + _dy );
+ double w = tqRound( _m11*rect.width() );
+ double h = tqRound( _m22*rect.height() );
+ if ( w < 0 ) {
+ w = -w;
+ x[0] -= w - 1.;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y[0] -= h - 1.;
+ }
+ x[1] = x[0]+w-1;
+ x[2] = x[1];
+ x[3] = x[0];
+ y[1] = y[0];
+ y[2] = y[0]+h-1;
+ y[3] = y[2];
+ } else {
+ MAPINT( rect.left(), rect.top(), x[0], y[0] );
+ MAPINT( rect.right() + 1, rect.top(), x[1], y[1] );
+ MAPINT( rect.right() + 1, rect.bottom() + 1, x[2], y[2] );
+ MAPINT( rect.left(), rect.bottom() + 1, x[3], y[3] );
+
+ /*
+ Including rectangles as we have are evil.
+
+ We now have a rectangle that is one pixel to wide and one to
+ high. the tranformed position of the top-left corner is
+ correct. All other points need some adjustments.
+
+ Doing this mathematically exact would force us to calculate some square roots,
+ something we don't want for the sake of speed.
+
+ Instead we use an approximation, that converts to the correct
+ answer when m12 -> 0 and m21 -> 0, and accept smaller
+ errors in the general transformation case.
+
+ The solution is to calculate the width and height of the
+ bounding rect, and scale the points 1/2/3 by (xp-x0)/xw pixel direction
+ to point 0.
+ */
+
+ double xmin = x[0];
+ double ymin = y[0];
+ double xmax = x[0];
+ double ymax = y[0];
+ int i;
+ for( i = 1; i< 4; i++ ) {
+ xmin = TQMIN( xmin, x[i] );
+ ymin = TQMIN( ymin, y[i] );
+ xmax = TQMAX( xmax, x[i] );
+ ymax = TQMAX( ymax, y[i] );
+ }
+ double w = xmax - xmin;
+ double h = ymax - ymin;
+
+ for( i = 1; i < 4; i++ ) {
+ x[i] -= (x[i] - x[0])/w;
+ y[i] -= (y[i] - y[0])/h;
+ }
+ }
+#if 0
+ int i;
+ for( i = 0; i< 4; i++ )
+ qDebug("coords(%d) = (%f/%f) (%d/%d)", i, x[i], y[i], tqRound(x[i]), tqRound(y[i]) );
+ qDebug( "width=%f, height=%f", sqrt( (x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]) ),
+ sqrt( (x[0]-x[3])*(x[0]-x[3]) + (y[0]-y[3])*(y[0]-y[3]) ) );
+#endif
+ // all coordinates are correctly, tranform to a pointarray
+ // (rounding to the next integer)
+ a.setPoints( 4, tqRound( x[0] ), tqRound( y[0] ),
+ tqRound( x[1] ), tqRound( y[1] ),
+ tqRound( x[2] ), tqRound( y[2] ),
+ tqRound( x[3] ), tqRound( y[3] ) );
+ return a;
+}
+
+/*!
+\internal
+*/
+TQRegion TQWMatrix::operator * (const TQRegion &r ) const
+{
+ if ( isIdentity() )
+ return r;
+ TQMemArray<TQRect> rects = r.rects();
+ TQRegion result;
+ register TQRect *rect = rects.data();
+ register int i = rects.size();
+ if ( _m12 == 0.0F && _m21 == 0.0F && _m11 > 1.0F && _m22 > 1.0F ) {
+ // simple case, no rotation
+ while ( i ) {
+ int x = tqRound( _m11*rect->x() + _dx );
+ int y = tqRound( _m22*rect->y() + _dy );
+ int w = tqRound( _m11*rect->width() );
+ int h = tqRound( _m22*rect->height() );
+ if ( w < 0 ) {
+ w = -w;
+ x -= w-1;
+ }
+ if ( h < 0 ) {
+ h = -h;
+ y -= h-1;
+ }
+ *rect = TQRect( x, y, w, h );
+ rect++;
+ i--;
+ }
+ result.setRects( rects.data(), rects.size() );
+ } else {
+ while ( i ) {
+ result |= operator *( *rect );
+ rect++;
+ i--;
+ }
+ }
+ return result;
+}
+
+/*!
+ Resets the matrix to an identity matrix.
+
+ All elements are set to zero, except \e m11 and \e m22 (scaling)
+ which are set to 1.
+
+ \sa isIdentity()
+*/
+
+void TQWMatrix::reset()
+{
+ _m11 = _m22 = 1.0;
+ _m12 = _m21 = _dx = _dy = 0.0;
+}
+
+/*!
+ Returns TRUE if the matrix is the identity matrix; otherwise returns FALSE.
+
+ \sa reset()
+*/
+bool TQWMatrix::isIdentity() const
+{
+ return _m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0
+ && _dx == 0.0 && _dy == 0.0;
+}
+
+/*!
+ Moves the coordinate system \a dx along the X-axis and \a dy along
+ the Y-axis.
+
+ Returns a reference to the matrix.
+
+ \sa scale(), shear(), rotate()
+*/
+
+TQWMatrix &TQWMatrix::translate( double dx, double dy )
+{
+ _dx += dx*_m11 + dy*_m21;
+ _dy += dy*_m22 + dx*_m12;
+ return *this;
+}
+
+/*!
+ Scales the coordinate system unit by \a sx horizontally and \a sy
+ vertically.
+
+ Returns a reference to the matrix.
+
+ \sa translate(), shear(), rotate()
+*/
+
+TQWMatrix &TQWMatrix::scale( double sx, double sy )
+{
+ _m11 *= sx;
+ _m12 *= sx;
+ _m21 *= sy;
+ _m22 *= sy;
+ return *this;
+}
+
+/*!
+ Shears the coordinate system by \a sh horizontally and \a sv
+ vertically.
+
+ Returns a reference to the matrix.
+
+ \sa translate(), scale(), rotate()
+*/
+
+TQWMatrix &TQWMatrix::shear( double sh, double sv )
+{
+ double tm11 = sv*_m21;
+ double tm12 = sv*_m22;
+ double tm21 = sh*_m11;
+ double tm22 = sh*_m12;
+ _m11 += tm11;
+ _m12 += tm12;
+ _m21 += tm21;
+ _m22 += tm22;
+ return *this;
+}
+
+const double deg2rad = 0.017453292519943295769; // pi/180
+
+/*!
+ Rotates the coordinate system \a a degrees counterclockwise.
+
+ Returns a reference to the matrix.
+
+ \sa translate(), scale(), shear()
+*/
+
+TQWMatrix &TQWMatrix::rotate( double a )
+{
+ double b = deg2rad*a; // convert to radians
+#if defined(TQ_WS_X11)
+ double sina = qsincos(b,FALSE); // fast and convenient
+ double cosa = qsincos(b,TRUE);
+#else
+ double sina = sin(b);
+ double cosa = cos(b);
+#endif
+ double tm11 = cosa*_m11 + sina*_m21;
+ double tm12 = cosa*_m12 + sina*_m22;
+ double tm21 = -sina*_m11 + cosa*_m21;
+ double tm22 = -sina*_m12 + cosa*_m22;
+ _m11 = tm11; _m12 = tm12;
+ _m21 = tm21; _m22 = tm22;
+ return *this;
+}
+
+/*!
+ \fn bool TQWMatrix::isInvertible() const
+
+ Returns TRUE if the matrix is invertible; otherwise returns FALSE.
+
+ \sa invert()
+*/
+
+/*!
+ \fn double TQWMatrix::det() const
+
+ Returns the matrix's determinant.
+*/
+
+
+/*!
+ Returns the inverted matrix.
+
+ If the matrix is singular (not invertible), the identity matrix is
+ returned.
+
+ If \a invertible is not 0: the value of \a *invertible is set
+ to TRUE if the matrix is invertible; otherwise \a *invertible is
+ set to FALSE.
+
+ \sa isInvertible()
+*/
+
+TQWMatrix TQWMatrix::invert( bool *invertible ) const
+{
+ double determinant = det();
+ if ( determinant == 0.0 ) {
+ if ( invertible )
+ *invertible = FALSE; // singular matrix
+ TQWMatrix defaultMatrix;
+ return defaultMatrix;
+ }
+ else { // invertible matrix
+ if ( invertible )
+ *invertible = TRUE;
+ double dinv = 1.0/determinant;
+ TQWMatrix imatrix( (_m22*dinv), (-_m12*dinv),
+ (-_m21*dinv), ( _m11*dinv),
+ ((_m21*_dy - _m22*_dx)*dinv),
+ ((_m12*_dx - _m11*_dy)*dinv) );
+ return imatrix;
+ }
+}
+
+
+/*!
+ Returns TRUE if this matrix is equal to \a m; otherwise returns FALSE.
+*/
+
+bool TQWMatrix::operator==( const TQWMatrix &m ) const
+{
+ return _m11 == m._m11 &&
+ _m12 == m._m12 &&
+ _m21 == m._m21 &&
+ _m22 == m._m22 &&
+ _dx == m._dx &&
+ _dy == m._dy;
+}
+
+/*!
+ Returns TRUE if this matrix is not equal to \a m; otherwise returns FALSE.
+*/
+
+bool TQWMatrix::operator!=( const TQWMatrix &m ) const
+{
+ return _m11 != m._m11 ||
+ _m12 != m._m12 ||
+ _m21 != m._m21 ||
+ _m22 != m._m22 ||
+ _dx != m._dx ||
+ _dy != m._dy;
+}
+
+/*!
+ Returns the result of multiplying this matrix by matrix \a m.
+*/
+
+TQWMatrix &TQWMatrix::operator*=( const TQWMatrix &m )
+{
+ double tm11 = _m11*m._m11 + _m12*m._m21;
+ double tm12 = _m11*m._m12 + _m12*m._m22;
+ double tm21 = _m21*m._m11 + _m22*m._m21;
+ double tm22 = _m21*m._m12 + _m22*m._m22;
+
+ double tdx = _dx*m._m11 + _dy*m._m21 + m._dx;
+ double tdy = _dx*m._m12 + _dy*m._m22 + m._dy;
+
+ _m11 = tm11; _m12 = tm12;
+ _m21 = tm21; _m22 = tm22;
+ _dx = tdx; _dy = tdy;
+ return *this;
+}
+
+/*!
+ \overload
+ \relates TQWMatrix
+ Returns the product of \a m1 * \a m2.
+
+ Note that matrix multiplication is not commutative, i.e. a*b !=
+ b*a.
+*/
+
+TQWMatrix operator*( const TQWMatrix &m1, const TQWMatrix &m2 )
+{
+ TQWMatrix result = m1;
+ result *= m2;
+ return result;
+}
+
+/*****************************************************************************
+ TQWMatrix stream functions
+ *****************************************************************************/
+#ifndef TQT_NO_DATASTREAM
+/*!
+ \relates TQWMatrix
+
+ Writes the matrix \a m to the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator<<( TQDataStream &s, const TQWMatrix &m )
+{
+ if ( s.version() == 1 )
+ s << (float)m.m11() << (float)m.m12() << (float)m.m21()
+ << (float)m.m22() << (float)m.dx() << (float)m.dy();
+ else
+ s << m.m11() << m.m12() << m.m21() << m.m22()
+ << m.dx() << m.dy();
+ return s;
+}
+
+/*!
+ \relates TQWMatrix
+
+ Reads the matrix \a m from the stream \a s and returns a reference
+ to the stream.
+
+ \sa \link datastreamformat.html Format of the TQDataStream operators \endlink
+*/
+
+TQDataStream &operator>>( TQDataStream &s, TQWMatrix &m )
+{
+ if ( s.version() == 1 ) {
+ float m11, m12, m21, m22, dx, dy;
+ s >> m11; s >> m12; s >> m21; s >> m22;
+ s >> dx; s >> dy;
+ m.setMatrix( m11, m12, m21, m22, dx, dy );
+ }
+ else {
+ double m11, m12, m21, m22, dx, dy;
+ s >> m11; s >> m12; s >> m21; s >> m22;
+ s >> dx; s >> dy;
+ m.setMatrix( m11, m12, m21, m22, dx, dy );
+ }
+ return s;
+}
+#endif // TQT_NO_DATASTREAM
+
+#endif // USE_QT4
+
+#endif // TQT_NO_WMATRIX
+
diff --git a/tqtinterface/qt4/src/kernel/tqwmatrix.h b/tqtinterface/qt4/src/kernel/tqwmatrix.h
new file mode 100644
index 0000000..81d3734
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwmatrix.h
@@ -0,0 +1,194 @@
+/****************************************************************************
+**
+** Definition of TQWMatrix class
+**
+** Created : 941020
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWMATRIX_H
+#define TQWMATRIX_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqpointarray.h"
+#include "tqrect.h"
+#include "tqregion.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_WMATRIX
+
+#ifdef USE_QT4
+
+#include <Qt/qpixmap.h>
+#include <Qt/qbitmap.h>
+
+// #include "tqimage.h"
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQWMatrix : public QMatrix, virtual public TQt
+{
+public:
+ TQWMatrix() : QMatrix() {}
+ TQWMatrix( double m11, double m12, double m21, double m22, double dx, double dy ) : QMatrix( m11, m12, m21, m22, dx, dy ) {}
+
+ //TQWMatrix invert(bool *invertible=0);
+ inline TQWMatrix invert(bool *invertible=0) const { const QMatrix &ref = inverted(invertible); return (*static_cast<const TQWMatrix*>(&ref)); }
+ inline TQWMatrix translate( double dx, double dy ) { const QMatrix &ref = this->translate(dx, dy); return (*static_cast<const TQWMatrix*>(&ref)); }
+
+ inline TQRect map(const QRect &r) const { return mapRect(r); }
+
+ inline void map( int x, int y, int *tx, int *ty ) const { return QMatrix::map(x, y, tx, ty); }
+ inline void map( double x, double y, double *tx, double *ty ) const { return QMatrix::map(x, y, tx, ty); }
+ inline TQPoint map( const QPoint &p ) const { return QMatrix::map(p); }
+ inline TQRegion map( const QRegion &r ) const { return QMatrix::map(r); }
+ inline TQPointArray map( const TQPointArray &a ) const { return operator * ( a ); }
+
+ TQRegion mapToRegion(const QRect &r) const;
+
+ enum TransformationMode {
+ Points, Areas
+ };
+ static void setTransformationMode( TQWMatrix::TransformationMode m );
+ static TransformationMode transformationMode();
+
+ TQPointArray operator * ( const TQPointArray &a ) const;
+
+ TQWMatrix &operator*=( const TQWMatrix & );
+
+ // Interoperability
+ inline TQWMatrix &operator=( const QMatrix &qm ) { return *this = qm; }
+
+// TQWMatrix(QMatrix a) {
+// setMatrix(a.m11(), a.m12()
+// }
+
+// inline operator QMatrix() const { return *this; }
+
+ // Interoperability
+ static const TQWMatrix& convertFromQMatrix( QMatrix& qs );
+};
+
+// Interoperability
+inline static const TQWMatrix& convertFromQMatrix( const QMatrix& qs ) {
+ return (*static_cast<const TQWMatrix*>(&qs));
+}
+
+TQ_EXPORT TQWMatrix operator*( const TQWMatrix &, const TQWMatrix & );
+
+#else // USE_QT4
+
+class TQ_EXPORT TQWMatrix // 2D transform matrix
+{
+public:
+ TQWMatrix();
+ TQWMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy );
+
+ void setMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy );
+
+ double m11() const { return _m11; }
+ double m12() const { return _m12; }
+ double m21() const { return _m21; }
+ double m22() const { return _m22; }
+ double dx() const { return _dx; }
+ double dy() const { return _dy; }
+
+ void map( int x, int y, int *tx, int *ty ) const;
+ void map( double x, double y, double *tx, double *ty ) const;
+ TQRect mapRect( const TQRect & ) const;
+
+ TQPoint map( const TQPoint &p ) const { return operator *( p ); }
+ TQRect map( const TQRect &r ) const { return mapRect ( r ); }
+ TQPointArray map( const TQPointArray &a ) const { return operator * ( a ); }
+ TQRegion map( const TQRegion &r ) const { return operator *( r ); }
+ TQRegion mapToRegion( const TQRect &r ) const { return operator *( r ); }
+ TQPointArray mapToPolygon( const TQRect &r ) const;
+
+ void reset();
+ bool isIdentity() const;
+
+ TQWMatrix &translate( double dx, double dy );
+ TQWMatrix &scale( double sx, double sy );
+ TQWMatrix &shear( double sh, double sv );
+ TQWMatrix &rotate( double a );
+
+ bool isInvertible() const { return (_m11*_m22 - _m12*_m21) != 0; }
+ double det() const { return _m11*_m22 - _m12*_m21; }
+
+ TQWMatrix invert( bool * = 0 ) const;
+
+ bool operator==( const TQWMatrix & ) const;
+ bool operator!=( const TQWMatrix & ) const;
+ TQWMatrix &operator*=( const TQWMatrix & );
+
+ /* we use matrix multiplication semantics here */
+ TQPoint operator * (const TQPoint & ) const;
+ TQRegion operator * (const TQRect & ) const;
+ TQRegion operator * (const TQRegion & ) const;
+ TQPointArray operator * ( const TQPointArray &a ) const;
+
+ enum TransformationMode {
+ Points, Areas
+ };
+ static void setTransformationMode( TQWMatrix::TransformationMode m );
+ static TransformationMode transformationMode();
+private:
+ double _m11, _m12;
+ double _m21, _m22;
+ double _dx, _dy;
+};
+
+TQ_EXPORT TQWMatrix operator*( const TQWMatrix &, const TQWMatrix & );
+
+
+/*****************************************************************************
+ TQWMatrix stream functions
+ *****************************************************************************/
+
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQWMatrix & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQWMatrix & );
+
+#endif // USE_QT4
+
+#endif // TQT_NO_WMATRIX
+
+#endif // TQWMATRIX_H
diff --git a/tqtinterface/qt4/src/kernel/tqwmatrix.h~ b/tqtinterface/qt4/src/kernel/tqwmatrix.h~
new file mode 100644
index 0000000..0ce4085
--- /dev/null
+++ b/tqtinterface/qt4/src/kernel/tqwmatrix.h~
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Definition of TQWMatrix class
+**
+** Created : 941020
+**
+** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
+**
+** This file is part of the kernel module of the TQt GUI Toolkit.
+**
+** This file may be used under the terms of the GNU General
+** Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the files LICENSE.GPL2
+** and LICENSE.GPL3 included in the packaging of this file.
+** Alternatively you may (at your option) use any later version
+** of the GNU General Public License if such license has been
+** publicly approved by Trolltech ASA (or its successors, if any)
+** and the KDE Free TQt Foundation.
+**
+** Please review the following information to ensure GNU General
+** Public Licensing requirements will be met:
+** http://trolltech.com/products/qt/licenses/licensing/opensource/.
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
+** or contact the sales department at sales@trolltech.com.
+**
+** This file may be used under the terms of the Q Public License as
+** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
+** included in the packaging of this file. Licensees holding valid TQt
+** Commercial licenses may use this file in accordance with the TQt
+** Commercial License Agreement provided with the Software.
+**
+** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
+** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
+** herein.
+**
+**********************************************************************/
+
+#ifndef TQWMATRIX_H
+#define TQWMATRIX_H
+
+#include "tqtglobaldefines.h"
+
+#ifndef TQT_H
+#include "tqwindowdefs.h"
+#include "tqpointarray.h"
+#include "tqrect.h"
+#include "tqregion.h"
+#endif // TQT_H
+
+#ifndef TQT_NO_WMATRIX
+
+#ifdef USE_QT4
+
+#include <Qt/qpixmap.h>
+#include <Qt/qbitmap.h>
+
+// #include "tqimage.h"
+
+#endif // USE_QT4
+
+#ifdef USE_QT4
+
+class TQ_EXPORT TQWMatrix : public QMatrix, virtual public TQt
+{
+public:
+ TQWMatrix() : QMatrix() {}
+ TQWMatrix( double m11, double m12, double m21, double m22, double dx, double dy ) : QMatrix( m11, m12, m21, m22, dx, dy ) {}
+
+ //TQWMatrix invert(bool *invertible=0);
+ inline TQWMatrix invert(bool *invertible=0) const { const QMatrix &ref = inverted(invertible); return (*static_cast<const TQWMatrix*>(&ref)); }
+
+ inline TQRect map(const QRect &r) const { return mapRect(r); }
+
+ inline void map( int x, int y, int *tx, int *ty ) const { return QMatrix::map(x, y, tx, ty); }
+ inline void map( double x, double y, double *tx, double *ty ) const { return QMatrix::map(x, y, tx, ty); }
+ inline TQPoint map( const QPoint &p ) const { return QMatrix::map(p); }
+ inline TQRegion map( const QRegion &r ) const { return QMatrix::map(r); }
+ TQPointArray map( const TQPointArray &a ) const;
+
+ TQRegion mapToRegion(const QRect &r) const;
+
+ enum TransformationMode {
+ Points, Areas
+ };
+ static void setTransformationMode( TQWMatrix::TransformationMode m );
+ static TransformationMode transformationMode();
+
+ TQPointArray operator * ( const TQPointArray &a ) const;
+
+ TQWMatrix &operator*=( const TQWMatrix & );
+
+ // Interoperability
+ inline TQWMatrix &operator=( const QMatrix &qm ) { return *this = qm; }
+
+// TQWMatrix(QMatrix a) {
+// setMatrix(a.m11(), a.m12()
+// }
+
+// inline operator QMatrix() const { return *this; }
+
+ // Interoperability
+ static const TQWMatrix& convertFromQMatrix( QMatrix& qs );
+};
+
+// Interoperability
+inline static const TQWMatrix& convertFromQMatrix( const QMatrix& qs ) {
+ return (*static_cast<const TQWMatrix*>(&qs));
+}
+
+TQ_EXPORT TQWMatrix operator*( const TQWMatrix &, const TQWMatrix & );
+
+#else // USE_QT4
+
+class TQ_EXPORT TQWMatrix // 2D transform matrix
+{
+public:
+ TQWMatrix();
+ TQWMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy );
+
+ void setMatrix( double m11, double m12, double m21, double m22,
+ double dx, double dy );
+
+ double m11() const { return _m11; }
+ double m12() const { return _m12; }
+ double m21() const { return _m21; }
+ double m22() const { return _m22; }
+ double dx() const { return _dx; }
+ double dy() const { return _dy; }
+
+ void map( int x, int y, int *tx, int *ty ) const;
+ void map( double x, double y, double *tx, double *ty ) const;
+ TQRect mapRect( const TQRect & ) const;
+
+ TQPoint map( const TQPoint &p ) const { return operator *( p ); }
+ TQRect map( const TQRect &r ) const { return mapRect ( r ); }
+ TQPointArray map( const TQPointArray &a ) const { return operator * ( a ); }
+ TQRegion map( const TQRegion &r ) const { return operator *( r ); }
+ TQRegion mapToRegion( const TQRect &r ) const { return operator *( r ); }
+ TQPointArray mapToPolygon( const TQRect &r ) const;
+
+ void reset();
+ bool isIdentity() const;
+
+ TQWMatrix &translate( double dx, double dy );
+ TQWMatrix &scale( double sx, double sy );
+ TQWMatrix &shear( double sh, double sv );
+ TQWMatrix &rotate( double a );
+
+ bool isInvertible() const { return (_m11*_m22 - _m12*_m21) != 0; }
+ double det() const { return _m11*_m22 - _m12*_m21; }
+
+ TQWMatrix invert( bool * = 0 ) const;
+
+ bool operator==( const TQWMatrix & ) const;
+ bool operator!=( const TQWMatrix & ) const;
+ TQWMatrix &operator*=( const TQWMatrix & );
+
+ /* we use matrix multiplication semantics here */
+ TQPoint operator * (const TQPoint & ) const;
+ TQRegion operator * (const TQRect & ) const;
+ TQRegion operator * (const TQRegion & ) const;
+ TQPointArray operator * ( const TQPointArray &a ) const;
+
+ enum TransformationMode {
+ Points, Areas
+ };
+ static void setTransformationMode( TQWMatrix::TransformationMode m );
+ static TransformationMode transformationMode();
+private:
+ double _m11, _m12;
+ double _m21, _m22;
+ double _dx, _dy;
+};
+
+TQ_EXPORT TQWMatrix operator*( const TQWMatrix &, const TQWMatrix & );
+
+
+/*****************************************************************************
+ TQWMatrix stream functions
+ *****************************************************************************/
+
+TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQWMatrix & );
+TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQWMatrix & );
+
+#endif // USE_QT4
+
+#endif // TQT_NO_WMATRIX
+
+#endif // TQWMATRIX_H